KDevelop API Documentation

lib/widgets/ktabzoombarlayout.cpp

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * Copyright (C) 2001-2003 * 00003 * The KDevelop Team * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 ***************************************************************************/ 00011 00012 #include "ktabzoombarlayout.h" 00013 00014 00015 class KTabZoomBarLayoutIterator : public QGLayoutIterator 00016 { 00017 public: 00018 00019 KTabZoomBarLayoutIterator(QPtrList<QLayoutItem> *l) 00020 : idx(0), list(l) 00021 { 00022 } 00023 00024 QLayoutItem *current() 00025 { 00026 return idx < int(list->count()) ? list->at(idx) : 0; 00027 } 00028 00029 QLayoutItem *next() 00030 { 00031 idx++; 00032 return current(); 00033 } 00034 00035 QLayoutItem *takeCurrent() 00036 { 00037 return list->take(idx); 00038 } 00039 00040 private: 00041 00042 int idx; 00043 QPtrList<QLayoutItem> *list; 00044 00045 }; 00046 00047 00048 KTabZoomBarLayout::KTabZoomBarLayout(QWidget *parent, KTabZoomPosition::Position pos) 00049 : QLayout(parent, 0, 2), m_pos(pos) 00050 { 00051 m_fontHeight = parent->fontMetrics().height(); 00052 } 00053 00054 KTabZoomBarLayout::KTabZoomBarLayout(QLayout *parent, KTabZoomPosition::Position pos) 00055 : QLayout(parent, 2), m_pos(pos), m_fontHeight(10) 00056 { 00057 } 00058 00059 00060 KTabZoomBarLayout::KTabZoomBarLayout(KTabZoomPosition::Position pos) 00061 : QLayout(2), m_pos(pos), m_fontHeight(10) 00062 { 00063 } 00064 00065 00066 KTabZoomBarLayout::~KTabZoomBarLayout() 00067 { 00068 deleteAllItems(); 00069 } 00070 00071 00072 void KTabZoomBarLayout::addItem(QLayoutItem *item) 00073 { 00074 m_list.append(item); 00075 } 00076 00077 00078 QSize KTabZoomBarLayout::sizeHint() const 00079 { 00080 QSize sh(100,100); 00081 if ((m_pos == KTabZoomPosition::Top) || (m_pos == KTabZoomPosition::Bottom)) 00082 sh = QSize(completeSize(), m_fontHeight + 2); 00083 else 00084 sh = QSize(m_fontHeight + 2, completeSize()); 00085 00086 return sh; 00087 } 00088 00089 00090 QSize KTabZoomBarLayout::minimumSize() const 00091 { 00092 if ((m_pos == KTabZoomPosition::Top) || (m_pos == KTabZoomPosition::Bottom)) 00093 return QSize(completeSize(), m_fontHeight + 2); 00094 else 00095 return QSize(m_fontHeight + 2, completeSize()); 00096 } 00097 00098 00099 QLayoutIterator KTabZoomBarLayout::iterator() 00100 { 00101 return QLayoutIterator(new KTabZoomBarLayoutIterator(&m_list)); 00102 } 00103 00104 00105 void KTabZoomBarLayout::setGeometry(const QRect &rect) 00106 { 00107 QLayout::setGeometry(rect); 00108 00109 QPtrListIterator<QLayoutItem> it(m_list); 00110 if (it.count() == 0) 00111 return; 00112 00113 QLayoutItem *o; 00114 int i = 0; 00115 00116 if ((m_pos == KTabZoomPosition::Top) || (m_pos == KTabZoomPosition::Bottom)) 00117 { 00118 int w=0, h=0; 00119 00120 while ((o = it.current()) != 0) 00121 { 00122 ++it; 00123 00124 QSize sh = o->sizeHint(); 00125 00126 if (w + sh.width() > rect.width()) 00127 { 00128 w = 0; 00129 h = h + m_fontHeight + 2; 00130 } 00131 00132 o->setGeometry(QRect(w, h, sh.width(), sh.height())); 00133 w = w + sh.width() + spacing(); 00134 00135 ++i; 00136 } 00137 } 00138 else 00139 { 00140 int h=0; 00141 00142 while ((o = it.current()) != 0) 00143 { 00144 ++it; 00145 00146 QSize sh = o->sizeHint(); 00147 00148 o->setGeometry(QRect(0, h, sh.width(), sh.height())); 00149 h = h + sh.height() + spacing(); 00150 00151 ++i; 00152 } 00153 } 00154 } 00155 00156 00157 bool KTabZoomBarLayout::hasHeightForWidth () const 00158 { 00159 return (m_pos == KTabZoomPosition::Top) || (m_pos == KTabZoomPosition::Bottom); 00160 } 00161 00162 00163 int KTabZoomBarLayout::heightForWidth (int width) const 00164 { 00165 if ((m_pos == KTabZoomPosition::Left) || (m_pos == KTabZoomPosition::Right)) 00166 return -1; 00167 00168 int height = m_fontHeight + 2; 00169 00170 int w = 0; 00171 00172 QPtrListIterator<QLayoutItem> it(m_list); 00173 QLayoutItem *o; 00174 while ((o = it.current()) != 0) 00175 { 00176 ++it; 00177 00178 QSize sh = o->sizeHint(); 00179 00180 if ((w + sh.width()) < width) 00181 w = w + sh.width() + spacing(); 00182 else 00183 { 00184 height = height + m_fontHeight + 2; 00185 w = sh.width() + spacing(); 00186 } 00187 } 00188 00189 return height; 00190 } 00191 00192 00193 int KTabZoomBarLayout::completeSize() const 00194 { 00195 QPtrListIterator<QLayoutItem> it(m_list); 00196 00197 int s = spacing() * (it.count() - 1); 00198 00199 QLayoutItem *o; 00200 while ((o = it.current()) != 0) 00201 { 00202 ++it; 00203 00204 QSize sh = o->sizeHint(); 00205 00206 if ((m_pos == KTabZoomPosition::Left) || (m_pos == KTabZoomPosition::Right)) 00207 s += sh.width(); 00208 else 00209 s += sh.height(); 00210 } 00211 00212 return s; 00213 }
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Oct 6 17:39:08 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003