• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

  • tdeui
ktabctl.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 1997 Alexander Sanda (alex@darkstar.ping.at)
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
27 #include <tqtabbar.h>
28 #include <tqpushbutton.h>
29 #include <tqpainter.h>
30 #include <tqpixmap.h>
31 
32 #include "ktabctl.h"
33 
34 KTabCtl::KTabCtl(TQWidget *parent, const char *name)
35  : TQWidget(parent, name)
36 {
37  tabs = new TQTabBar(this, "_tabbar");
38  connect(tabs, TQT_SIGNAL(selected(int)), this, TQT_SLOT(showTab(int)));
39  tabs->move(2, 1);
40 
41  blBorder = true;
42 
43 }
44 
45 KTabCtl::~KTabCtl()
46 {
47  delete tabs;
48 }
49 
50 void KTabCtl::resizeEvent(TQResizeEvent *)
51 {
52  int i;
53  TQRect r = getChildRect();
54 
55  if (tabs) {
56  for (i=0; i<(int)pages.size(); i++) {
57  pages[i]->setGeometry(r);
58  }
59  if( ( tabs->shape() == TQTabBar::RoundedBelow ) ||
60  ( tabs->shape() == TQTabBar::TriangularBelow ) ) {
61  tabs->move( 0, height()-tabs->height()-4 );
62  }
63  }
64 }
65 
66 void KTabCtl::setFont(const TQFont & font)
67 {
68  TQFont f(font);
69  f.setWeight(TQFont::Light);
70  TQWidget::setFont(f);
71 
72  setSizes();
73 }
74 
75 void KTabCtl::setTabFont(const TQFont & font)
76 {
77  TQFont f(font);
78 // f.setWeight(TQFont::Light);
79  tabs->setFont(f);
80 
81  setSizes();
82 }
83 
84 void KTabCtl::show()
85 {
86  unsigned int i;
87 
88  if(isVisible())
89  return;
90 
91  setSizes();
92 
93  for(i = 0; i < pages.size(); i++)
94  pages[i]->hide();
95 
96  TQResizeEvent r(size(), size());
97  resizeEvent(&r);
98 
99  TQWidget::show();
100 }
101 
102 bool KTabCtl::isTabEnabled(const TQString& name)
103 {
104  unsigned int i;
105 
106  for(i = 0; i < pages.size(); i++)
107  if (TQString::fromLatin1(pages[i]->name()) == name)
108  return tabs->isTabEnabled(i); /* return the enabled status */
109  return false; /* tab does not exist */
110 }
111 
112 void KTabCtl::setTabEnabled(const TQString& name, bool state)
113 {
114  unsigned i;
115 
116  if (name.isEmpty())
117  return;
118 
119  for (i = 0; i < pages.size(); i++)
120  if (TQString::fromLatin1(pages[i]->name()) == name)
121  tabs->setTabEnabled(i, state);
122 }
123 
124 void KTabCtl::setSizes()
125 {
126  unsigned i;
127 
128  TQSize min(tabs->sizeHint()); /* the minimum required size for the tabbar */
129  tabs->resize(min); /* make sure that the tabbar does not require more space than actually needed. */
130 
131 
132  TQSize max(TQCOORD_MAX,TQCOORD_MAX);
133  //int th = min.height(); /* the height of the tabbar itself (without pages and stuff) */
134 
135  for (i = 0; i < pages.size(); i++) {
136 
137  /*
138  * check the actual minimum and maximum sizes
139  */
140 
141  if (pages[i]->maximumSize().height() < max.height())
142  max.setHeight(pages[i]->maximumSize().height());
143  if (pages[i]->maximumSize().width() < max.width())
144  max.setWidth( pages[i]->maximumSize().width());
145  if ( pages[i]->minimumSize().height() > min.height())
146  min.setHeight( pages[i]->minimumSize().height());
147  if ( pages[i]->minimumSize().width() > min.width())
148  min.setWidth( pages[i]->minimumSize().width());
149  }
150 
151  // BL: min and max are sizes of children, not tabcontrol
152  // min.setHeight(min.height() + th);
153 
154  if (max.width() < min.width())
155  max.setWidth(min.width());
156  if (max.height() < min.height())
157  max.setHeight(min.height());
158 
159  /*
160  * now, apply the calculated size values to all of the pages
161  */
162 
163  for( i=0; i<(uint)pages.size(); i++ ) {
164  pages[i]->setMinimumSize(min);
165  pages[i]->setMaximumSize(max);
166  }
167 
168 
169  // BL: set minimum size of tabcontrol
170  setMinimumSize(min.width()+4, min.height()+tabs->height()+4);
171 
172  /*
173  * generate a resizeEvent, if we're visible
174  */
175 
176  if(isVisible()) {
177  TQResizeEvent r(size(), size());
178  resizeEvent(&r);
179  }
180 }
181 
182 void KTabCtl::setBorder( bool state )
183 {
184  blBorder = state;
185 }
186 
187 void KTabCtl::setShape( TQTabBar::Shape shape )
188 {
189  tabs->setShape( shape );
190 }
191 
192 TQSize
193 KTabCtl::sizeHint() const
194 {
195  /* desired size of the tabbar */
196  TQSize hint(tabs->sizeHint());
197 
198  /* overall desired size of all pages */
199  TQSize pageHint;
200  for (unsigned int i = 0; i < pages.size(); i++)
201  {
202  TQSize sizeI(pages[i]->sizeHint());
203 
204  if (sizeI.isValid())
205  {
206  /* only pages with valid size are used */
207  if (sizeI.width() > pageHint.width())
208  pageHint.setWidth(sizeI.width());
209 
210  if (sizeI.height() > pageHint.height())
211  pageHint.setHeight(sizeI.height());
212  }
213  }
214 
215  if (pageHint.isValid())
216  {
217  /* use maximum of width of tabbar and pages */
218  if (pageHint.width() > hint.width())
219  hint.setWidth(pageHint.width());
220 
221  /* heights must just be added */
222  hint.setHeight(hint.height() + pageHint.height());
223 
224  /* 1999-09-18: Espen Sand
225  I cannot get the size to be correct unless the total
226  border size is included: ie 2*2 pixels.
227  */
228  return (hint + TQSize(4,4));
229  }
230 
231  /*
232  * If not at least a one page has a valid sizeHint we have to return
233  * an invalid size as well.
234  */
235  return (pageHint);
236 }
237 
238 void KTabCtl::paintEvent(TQPaintEvent *)
239 {
240  if (!tabs)
241  return;
242 
243  if( !blBorder )
244  return;
245 
246  TQPainter p;
247  p.begin(this);
248 
249  int y0 = getChildRect().top() - 1;
250  int y1 = getChildRect().bottom() + 2;
251  int x1 = getChildRect().right() + 2;
252  int x0 = getChildRect().left() - 1;
253 
254  p.setPen(colorGroup().light());
255  p.drawLine(x0, y0 - 1, x1 - 1, y0 - 1); /* 1st top line */
256  p.setPen(colorGroup().midlight());
257  p.drawLine(x0, y0, x1 - 1, y0); /* 2nd top line */
258  p.setPen(colorGroup().light());
259  p.drawLine(x0, y0 + 1, x0, y1); /* left line */
260  p.setPen(black);
261  p.drawLine(x1, y1, x0, y1); /* bottom line */
262  p.drawLine(x1, y1 - 1, x1, y0);
263  p.setPen(colorGroup().dark());
264  p.drawLine(x0 + 1, y1 - 1, x1 - 1, y1 - 1); /* bottom */
265  p.drawLine(x1 - 1, y1 - 2, x1 - 1, y0 + 1);
266  p.end();
267 }
268 
269 /*
270  * return the client rect. This is the maximum size for any child
271  * widget (page).
272  */
273 
274 TQRect KTabCtl::getChildRect() const
275 {
276  if( ( tabs->shape() == TQTabBar::RoundedBelow ) ||
277  ( tabs->shape() == TQTabBar::TriangularBelow ) ) {
278  return TQRect(2, 1, width() - 4,
279  height() - tabs->height() - 4);
280  } else {
281  return TQRect(2, tabs->height() + 1, width() - 4,
282  height() - tabs->height() - 4);
283  }
284 }
285 
286 /*
287  * show a single page, depending on the selected tab
288  * emit tabSelected(new_pagenumber) BEFORE the page is shown
289  */
290 
291 void KTabCtl::showTab(int i)
292 {
293  unsigned int j;
294  for (j = 0; j < pages.size(); j++) {
295  if (j != (unsigned)i) {
296  pages[j]->hide();
297  }
298  }
299 
300  if((unsigned)i < pages.size()) {
301  emit(tabSelected(i));
302  if( pages.size() >= 2 ) {
303  pages[i]->raise();
304  }
305  tabs->setCurrentTab(i);
306  pages[i]->setGeometry(getChildRect());
307  pages[i]->show();
308  }
309 }
310 
311 /*
312  * add a tab to the control. This tab will manage the given Widget w.
313  * in most cases, w will be a TQWidget and will only act as parent for the
314  * actual widgets on this page
315  * NOTE: w is not required to be of class TQWidget, but expect strange results with
316  * other types of widgets
317  */
318 
319 void KTabCtl::addTab(TQWidget *w, const TQString& name)
320 {
321  TQTab *t = new TQTab();
322  t->setText( name );
323  t->setEnabled( true );
324  int id = tabs->addTab(t); /* add the tab itself to the tabbar */
325  if (id == (int)pages.size()) {
326  pages.resize(id + 1);
327  pages[id] = w; /* remember the widget to manage by this tab */
328  }
329  // BL: compute sizes
330  setSizes();
331 }
332 
333 void KTabCtl::virtual_hook( int, void* )
334 { /*BASE::virtual_hook( id, data );*/ }
335 
336 #include "ktabctl.moc"
KTabCtl::KTabCtl
KTabCtl(TQWidget *parent=0, const char *name=0)
KTabCtl provides a universal tab control.
Definition: ktabctl.cpp:34

tdeui

Skip menu "tdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.8.8
This website is maintained by Timothy Pearson.