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

tdeutils

  • tdeutils
tdemultitabbar.cpp
1 /***************************************************************************
2  tdemultitabbar.cpp - description
3  -------------------
4  begin : 2001
5  copyright : (C) 2001,2002,2003 by Joseph Wenninger <jowenn@kde.org>
6  ***************************************************************************/
7 
8 /***************************************************************************
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Library General Public
11  License as published by the Free Software Foundation; either
12  version 2 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Library General Public License for more details.
18 
19  You should have received a copy of the GNU Library General Public License
20  along with this library; see the file COPYING.LIB. If not, write to
21  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  Boston, MA 02110-1301, USA.
23  ***************************************************************************/
24 
25 #include "tdemultitabbar.h"
26 #include "tdemultitabbar.moc"
27 #include "tdemultitabbar_p.h"
28 #include "tdemultitabbar_p.moc"
29 #include <tqbutton.h>
30 #include <tqpopupmenu.h>
31 #include <tqlayout.h>
32 #include <tqpainter.h>
33 #include <tqtooltip.h>
34 #include <tqfontmetrics.h>
35 #include <tqstyle.h>
36 
37 #include <kiconloader.h>
38 #include <kdebug.h>
39 #include <tqapplication.h>
40 #include <math.h>
41 
42 #define NEARBYINT(i) ((int(float(i) + 0.5)))
43 
44 class KMultiTabBarTabPrivate {
45 public:
46  TQPixmap pix;
47 };
48 
49 
50 KMultiTabBarInternal::KMultiTabBarInternal(TQWidget *parent, KMultiTabBar::KMultiTabBarMode bm):TQScrollView(parent)
51 {
52  m_expandedTabSize=-1;
53  m_showActiveTabTexts=false;
54  m_tabs.setAutoDelete(true);
55  m_barMode=bm;
56  setHScrollBarMode(AlwaysOff);
57  setVScrollBarMode(AlwaysOff);
58  if (bm==KMultiTabBar::Vertical)
59  {
60  box=new TQWidget(viewport());
61  mainLayout=new TQVBoxLayout(box);
62  mainLayout->setAutoAdd(true);
63  box->setFixedWidth(24);
64  setFixedWidth(24);
65  }
66  else
67  {
68  box=new TQWidget(viewport());
69  mainLayout=new TQHBoxLayout(box);
70  mainLayout->setAutoAdd(true);
71  box->setFixedHeight(24);
72  setFixedHeight(24);
73  }
74  addChild(box);
75  setFrameStyle(NoFrame);
76  viewport()->setBackgroundMode(TQt::PaletteBackground);
77 /* box->setPaletteBackgroundColor(TQt::red);
78  setPaletteBackgroundColor(TQt::green);*/
79 }
80 
81 void KMultiTabBarInternal::setStyle(enum KMultiTabBar::KMultiTabBarStyle style)
82 {
83  m_style=style;
84  for (uint i=0;i<m_tabs.count();i++)
85  m_tabs.at(i)->setStyle(m_style);
86 
87  if ( (m_style==KMultiTabBar::KDEV3) ||
88  (m_style==KMultiTabBar::KDEV3ICON ) ) {
89  delete mainLayout;
90  mainLayout=0;
91  resizeEvent(0);
92  } else if (mainLayout==0) {
93  if (m_barMode==KMultiTabBar::Vertical)
94  {
95  box=new TQWidget(viewport());
96  mainLayout=new TQVBoxLayout(box);
97  box->setFixedWidth(24);
98  setFixedWidth(24);
99  }
100  else
101  {
102  box=new TQWidget(viewport());
103  mainLayout=new TQHBoxLayout(box);
104  box->setFixedHeight(24);
105  setFixedHeight(24);
106  }
107  addChild(box);
108  for (uint i=0;i<m_tabs.count();i++)
109  mainLayout->add(m_tabs.at(i));
110  mainLayout->setAutoAdd(true);
111 
112  }
113  viewport()->repaint();
114 }
115 
116 void KMultiTabBarInternal::drawContents ( TQPainter * paint, int clipx, int clipy, int clipw, int cliph )
117 {
118  TQScrollView::drawContents (paint , clipx, clipy, clipw, cliph );
119 
120  if (m_position==KMultiTabBar::Right)
121  {
122 
123  paint->setPen(colorGroup().shadow());
124  paint->drawLine(0,0,0,viewport()->height());
125  paint->setPen(colorGroup().background().dark(120));
126  paint->drawLine(1,0,1,viewport()->height());
127 
128 
129  }
130  else
131  if (m_position==KMultiTabBar::Left)
132  {
133  paint->setPen(colorGroup().light());
134  paint->drawLine(23,0,23,viewport()->height());
135  paint->drawLine(22,0,22,viewport()->height());
136 
137  paint->setPen(colorGroup().shadow());
138  paint->drawLine(0,0,0,viewport()->height());
139  }
140  else
141  if (m_position==KMultiTabBar::Bottom)
142  {
143  paint->setPen(colorGroup().shadow());
144  paint->drawLine(0,0,viewport()->width(),0);
145  paint->setPen(colorGroup().background().dark(120));
146  paint->drawLine(0,1,viewport()->width(),1);
147  }
148  else
149  {
150  paint->setPen(colorGroup().light());
151  paint->drawLine(0,23,viewport()->width(),23);
152  paint->drawLine(0,22,viewport()->width(),22);
153 
154 /* paint->setPen(colorGroup().shadow());
155  paint->drawLine(0,0,0,viewport()->height());*/
156 
157  }
158 
159 
160 }
161 
162 void KMultiTabBarInternal::contentsMousePressEvent(TQMouseEvent *ev)
163 {
164  ev->ignore();
165 }
166 
167 void KMultiTabBarInternal::mousePressEvent(TQMouseEvent *ev)
168 {
169  ev->ignore();
170 }
171 
172 
173 #define CALCDIFF(m_tabs,diff,i) if (m_lines>(int)lines) {\
174  /*kdDebug()<<"i="<<i<<" tabCount="<<tabCount<<" space="<<space<<endl;*/ \
175  uint ulen=0;\
176  diff=0; \
177  for (uint i2=i;i2<tabCount;i2++) {\
178  uint l1=m_tabs.at(i2)->neededSize();\
179  if ((ulen+l1)>space){\
180  if (ulen==0) diff=0;\
181  else diff=((float)(space-ulen))/(i2-i);\
182  break;\
183  }\
184  ulen+=l1;\
185  }\
186  } else {diff=0; }
187 
188 
189 void KMultiTabBarInternal::resizeEvent(TQResizeEvent *ev) {
190 /* kdDebug()<<"KMultiTabBarInternal::resizeEvent"<<endl;
191  kdDebug()<<"KMultiTabBarInternal::resizeEvent - box geometry"<<box->geometry()<<endl;
192  kdDebug()<<"KMultiTabBarInternal::resizeEvent - geometry"<<geometry()<<endl;*/
193  if (ev) TQScrollView::resizeEvent(ev);
194 
195  if ( (m_style==KMultiTabBar::KDEV3) ||
196  (m_style==KMultiTabBar::KDEV3ICON) ){
197  box->setGeometry(0,0,width(),height());
198  int lines=1;
199  uint space;
200  float tmp=0;
201  if ((m_position==KMultiTabBar::Bottom) || (m_position==KMultiTabBar::Top))
202  space=width();
203  else
204  space=height();
205 
206  int cnt=0;
207 //CALCULATE LINES
208  const uint tabCount=m_tabs.count();
209  for (uint i=0;i<tabCount;i++) {
210  cnt++;
211  tmp+=m_tabs.at(i)->neededSize();
212  if (tmp>space) {
213  if (cnt>1)i--;
214  else if (i==(tabCount-1)) break;
215  cnt=0;
216  tmp=0;
217  lines++;
218  }
219  }
220 //SET SIZE & PLACE
221  float diff=0;
222  cnt=0;
223 
224  if ((m_position==KMultiTabBar::Bottom) || (m_position==KMultiTabBar::Top)) {
225 
226  setFixedHeight(lines*24);
227  box->setFixedHeight(lines*24);
228  m_lines=height()/24-1;
229  lines=0;
230  CALCDIFF(m_tabs,diff,0)
231  tmp=-diff;
232 
233  //kdDebug()<<"m_lines recalculated="<<m_lines<<endl;
234  for (uint i=0;i<tabCount;i++) {
235  KMultiTabBarTab *tab=m_tabs.at(i);
236  cnt++;
237  tmp+=tab->neededSize()+diff;
238  if (tmp>space) {
239  //kdDebug()<<"about to start new line"<<endl;
240  if (cnt>1) {
241  CALCDIFF(m_tabs,diff,i)
242  i--;
243  }
244  else {
245  //kdDebug()<<"placing line on old line"<<endl;
246  kdDebug()<<"diff="<<diff<<endl;
247  tab->removeEventFilter(this);
248  tab->move(NEARBYINT(tmp-tab->neededSize()),lines*24);
249 // tab->setFixedWidth(tab->neededSize()+diff);
250  tab->setFixedWidth(NEARBYINT(tmp+diff)-tab->x());;
251  tab->installEventFilter(this);
252  CALCDIFF(m_tabs,diff,(i+1))
253 
254  }
255  tmp=-diff;
256  cnt=0;
257  lines++;
258  //kdDebug()<<"starting new line:"<<lines<<endl;
259 
260  } else {
261  //kdDebug()<<"Placing line on line:"<<lines<<" pos: (x/y)=("<<tmp-m_tabs.at(i)->neededSize()<<"/"<<lines*24<<")"<<endl;
262  //kdDebug()<<"diff="<<diff<<endl;
263  tab->removeEventFilter(this);
264  tab->move(NEARBYINT(tmp-tab->neededSize()),lines*24);
265  tab->setFixedWidth(NEARBYINT(tmp+diff)-tab->x());;
266 
267  //tab->setFixedWidth(tab->neededSize()+diff);
268  tab->installEventFilter(this);
269 
270  }
271  }
272  }
273  else {
274  setFixedWidth(lines*24);
275  box->setFixedWidth(lines*24);
276  m_lines=lines=width()/24;
277  lines=0;
278  CALCDIFF(m_tabs,diff,0)
279  tmp=-diff;
280 
281  for (uint i=0;i<tabCount;i++) {
282  KMultiTabBarTab *tab=m_tabs.at(i);
283  cnt++;
284  tmp+=tab->neededSize()+diff;
285  if (tmp>space) {
286  if (cnt>1) {
287  CALCDIFF(m_tabs,diff,i);
288  tmp=-diff;
289  i--;
290  }
291  else {
292  tab->removeEventFilter(this);
293  tab->move(lines*24,NEARBYINT(tmp-tab->neededSize()));
294  tab->setFixedHeight(NEARBYINT(tmp+diff)-tab->y());;
295  tab->installEventFilter(this);
296  }
297  cnt=0;
298  tmp=-diff;
299  lines++;
300  } else {
301  tab->removeEventFilter(this);
302  tab->move(lines*24,NEARBYINT(tmp-tab->neededSize()));
303  tab->setFixedHeight(NEARBYINT(tmp+diff)-tab->y());;
304  tab->installEventFilter(this);
305  }
306  }
307  }
308 
309 
310  //kdDebug()<<"needed lines:"<<m_lines<<endl;
311  } else {
312  int size=0; /*move the calculation into another function and call it only on add tab and tab click events*/
313  for (int i=0;i<(int)m_tabs.count();i++)
314  size+=(m_barMode==KMultiTabBar::Vertical?m_tabs.at(i)->height():m_tabs.at(i)->width());
315  if ((m_position==KMultiTabBar::Bottom) || (m_position==KMultiTabBar::Top))
316  box->setGeometry(0,0,size,height());
317  else box->setGeometry(0,0,width(),size);
318 
319  }
320 }
321 
322 
323 void KMultiTabBarInternal::showActiveTabTexts(bool show)
324 {
325  m_showActiveTabTexts=show;
326 }
327 
328 
329 KMultiTabBarTab* KMultiTabBarInternal::tab(int id) const
330 {
331  for (TQPtrListIterator<KMultiTabBarTab> it(m_tabs);it.current();++it){
332  if (it.current()->id()==id) return it.current();
333  }
334  return 0;
335 }
336 
337 bool KMultiTabBarInternal::eventFilter(TQObject *, TQEvent *e) {
338  if (e->type()==TQEvent::Resize) resizeEvent(0);
339  return false;
340 }
341 
342 int KMultiTabBarInternal::appendTab(const TQPixmap &pic ,int id,const TQString& text)
343 {
344  KMultiTabBarTab *tab;
345  m_tabs.append(tab= new KMultiTabBarTab(pic,text,id,box,m_position,m_style));
346  tab->installEventFilter(this);
347  tab->showActiveTabText(m_showActiveTabTexts);
348 
349  if (m_style==KMultiTabBar::KONQSBC)
350  {
351  if (m_expandedTabSize<tab->neededSize()) {
352  m_expandedTabSize=tab->neededSize();
353  for (uint i=0;i<m_tabs.count();i++)
354  m_tabs.at(i)->setSize(m_expandedTabSize);
355 
356  } else tab->setSize(m_expandedTabSize);
357  } else tab->updateState();
358  tab->show();
359  resizeEvent(0);
360  return 0;
361 }
362 
363 void KMultiTabBarInternal::removeTab(int id)
364 {
365  for (uint pos=0;pos<m_tabs.count();pos++)
366  {
367  if (m_tabs.at(pos)->id()==id)
368  {
369  m_tabs.remove(pos);
370  resizeEvent(0);
371  break;
372  }
373  }
374 }
375 
376 void KMultiTabBarInternal::setPosition(enum KMultiTabBar::KMultiTabBarPosition pos)
377 {
378  m_position=pos;
379  for (uint i=0;i<m_tabs.count();i++)
380  m_tabs.at(i)->setTabsPosition(m_position);
381  viewport()->repaint();
382 }
383 
384 KMultiTabBarButton::KMultiTabBarButton(const TQPixmap& pic,const TQString& text, TQPopupMenu *popup,
385  int id,TQWidget *parent,KMultiTabBar::KMultiTabBarPosition pos,KMultiTabBar::KMultiTabBarStyle style)
386  :TQPushButton(TQIconSet(),text,parent),m_style(style)
387 {
388  setIconSet(pic);
389  setText(text);
390  m_position=pos;
391  if (popup) setPopup(popup);
392  setFlat(true);
393  setFixedHeight(24);
394  setFixedWidth(24);
395  m_id=id;
396  TQToolTip::add(this,text);
397  connect(this,TQ_SIGNAL(clicked()),this,TQ_SLOT(slotClicked()));
398 }
399 
400 KMultiTabBarButton::KMultiTabBarButton(const TQString& text, TQPopupMenu *popup,
401  int id,TQWidget *parent,KMultiTabBar::KMultiTabBarPosition pos,KMultiTabBar::KMultiTabBarStyle style)
402  :TQPushButton(TQIconSet(),text,parent),m_style(style)
403 {
404  setText(text);
405  m_position=pos;
406  if (popup) setPopup(popup);
407  setFlat(true);
408  setFixedHeight(24);
409  setFixedWidth(24);
410  m_id=id;
411  TQToolTip::add(this,text);
412  connect(this,TQ_SIGNAL(clicked()),this,TQ_SLOT(slotClicked()));
413 }
414 
415 KMultiTabBarButton::~KMultiTabBarButton() {
416 }
417 
418 int KMultiTabBarButton::id() const{
419  return m_id;
420 }
421 
422 void KMultiTabBarButton::setText(const TQString& text)
423 {
424  TQPushButton::setText(text);
425  m_text=text;
426  TQToolTip::add(this,text);
427 }
428 
429 void KMultiTabBarButton::slotClicked()
430 {
431  emit clicked(m_id);
432 }
433 
434 void KMultiTabBarButton::setPosition(KMultiTabBar::KMultiTabBarPosition pos)
435 {
436  m_position=pos;
437  repaint();
438 }
439 
440 void KMultiTabBarButton::setStyle(KMultiTabBar::KMultiTabBarStyle style)
441 {
442  m_style=style;
443  repaint();
444 }
445 
446 void KMultiTabBarButton::hideEvent( TQHideEvent* he) {
447  TQPushButton::hideEvent(he);
448  KMultiTabBar *tb=dynamic_cast<KMultiTabBar*>(parentWidget());
449  if (tb) tb->updateSeparator();
450 }
451 
452 void KMultiTabBarButton::showEvent( TQShowEvent* he) {
453  TQPushButton::showEvent(he);
454  KMultiTabBar *tb=dynamic_cast<KMultiTabBar*>(parentWidget());
455  if (tb) tb->updateSeparator();
456 }
457 
458 
459 TQSize KMultiTabBarButton::sizeHint() const
460 {
461  constPolish();
462 
463  int w = 0, h = 0;
464 
465  // calculate contents size...
466 #ifndef TQT_NO_ICONSET
467  if ( iconSet() && !iconSet()->isNull() ) {
468  int iw = iconSet()->pixmap( TQIconSet::Small, TQIconSet::Normal ).width() + 4;
469  int ih = iconSet()->pixmap( TQIconSet::Small, TQIconSet::Normal ).height();
470  w += iw;
471  h = TQMAX( h, ih );
472  }
473 #endif
474  if ( isMenuButton() )
475  w += style().pixelMetric(TQStyle::PM_MenuButtonIndicator, this);
476 
477  if ( pixmap() ) {
478  TQPixmap *pm = (TQPixmap *)pixmap();
479  w += pm->width();
480  h += pm->height();
481  } else {
482  TQString s( text() );
483  bool empty = s.isEmpty();
484  if ( empty )
485  s = TQString::fromLatin1("XXXX");
486  TQFontMetrics fm = fontMetrics();
487  TQSize sz = fm.size( ShowPrefix, s );
488  if(!empty || !w)
489  w += sz.width();
490  if(!empty || !h)
491  h = TQMAX(h, sz.height());
492  }
493 
494  return (style().sizeFromContents(TQStyle::CT_ToolButton, this, TQSize(w, h)).
495  expandedTo(TQApplication::globalStrut()));
496 }
497 
498 
499 KMultiTabBarTab::KMultiTabBarTab(const TQPixmap& pic, const TQString& text,
500  int id,TQWidget *parent,KMultiTabBar::KMultiTabBarPosition pos,
501  KMultiTabBar::KMultiTabBarStyle style)
502  :KMultiTabBarButton(text,0,id,parent,pos,style),
503  m_showActiveTabText(false)
504 {
505  d=new KMultiTabBarTabPrivate();
506  setIcon(pic);
507  m_expandedSize=24;
508  setToggleButton(true);
509 }
510 
511 KMultiTabBarTab::~KMultiTabBarTab() {
512  delete d;
513 }
514 
515 
516 void KMultiTabBarTab::setTabsPosition(KMultiTabBar::KMultiTabBarPosition pos)
517 {
518  if ((pos!=m_position) && ((pos==KMultiTabBar::Left) || (pos==KMultiTabBar::Right))) {
519  if (!d->pix.isNull()) {
520  TQWMatrix temp;// (1.0F, 0.0F, 0.0F, -1.0F, 0.0F, 0.0F);
521  temp.rotate(180);
522  d->pix=d->pix.xForm(temp);
523  setIconSet(d->pix);
524  }
525  }
526 
527  setPosition(pos);
528 // repaint();
529 }
530 
531 void KMultiTabBarTab::setIcon(const TQString& icon)
532 {
533  TQPixmap pic=SmallIcon(icon);
534  setIcon(pic);
535 }
536 
537 void KMultiTabBarTab::setIcon(const TQPixmap& icon)
538 {
539 
540  if (m_style!=KMultiTabBar::KDEV3) {
541  if ((m_position==KMultiTabBar::Left) || (m_position==KMultiTabBar::Right)) {
542  TQWMatrix rotateMatrix;
543  if (m_position==KMultiTabBar::Left)
544  rotateMatrix.rotate(90);
545  else
546  rotateMatrix.rotate(-90);
547  TQPixmap pic=icon.xForm(rotateMatrix); //TODO FIX THIS, THIS SHOWS WINDOW
548  d->pix=pic;
549  setIconSet(pic);
550  } else setIconSet(icon);
551  }
552 }
553 
554 void KMultiTabBarTab::slotClicked()
555 {
556  updateState();
557  KMultiTabBarButton::slotClicked();
558 }
559 
560 void KMultiTabBarTab::setState(bool b)
561 {
562  setOn(b);
563  updateState();
564 }
565 
566 void KMultiTabBarTab::updateState()
567 {
568 
569  if (m_style!=KMultiTabBar::KONQSBC) {
570  if ((m_style==KMultiTabBar::KDEV3) || (m_style==KMultiTabBar::KDEV3ICON) || (isOn())) {
571  TQPushButton::setText(m_text);
572  } else {
573  kdDebug()<<"KMultiTabBarTab::updateState(): setting text to an empty TQString***************"<<endl;
574  TQPushButton::setText(TQString::null);
575  }
576 
577  if ((m_position==KMultiTabBar::Right || m_position==KMultiTabBar::Left)) {
578  setFixedWidth(24);
579  if ((m_style==KMultiTabBar::KDEV3) || (m_style==KMultiTabBar::KDEV3ICON) || (isOn())) {
580  setFixedHeight(KMultiTabBarButton::sizeHint().width());
581  } else setFixedHeight(36);
582  } else {
583  setFixedHeight(24);
584  if ((m_style==KMultiTabBar::KDEV3) || (m_style==KMultiTabBar::KDEV3ICON) || (isOn())) {
585  setFixedWidth(KMultiTabBarButton::sizeHint().width());
586  } else setFixedWidth(36);
587  }
588  } else {
589  if ((!isOn()) || (!m_showActiveTabText))
590  {
591  setFixedWidth(24);
592  setFixedHeight(24);
593  return;
594  }
595  if ((m_position==KMultiTabBar::Right || m_position==KMultiTabBar::Left))
596  setFixedHeight(m_expandedSize);
597  else
598  setFixedWidth(m_expandedSize);
599  }
600  TQApplication::sendPostedEvents(0,TQEvent::Paint | TQEvent::Move | TQEvent::Resize | TQEvent::LayoutHint);
601  TQApplication::flush();
602 }
603 
604 int KMultiTabBarTab::neededSize()
605 {
606  return (((m_style!=KMultiTabBar::KDEV3)?24:0)+TQFontMetrics(TQFont()).width(m_text)+6);
607 }
608 
609 void KMultiTabBarTab::setSize(int size)
610 {
611  m_expandedSize=size;
612  updateState();
613 }
614 
615 void KMultiTabBarTab::showActiveTabText(bool show)
616 {
617  m_showActiveTabText=show;
618 }
619 
620 void KMultiTabBarTab::drawButtonLabel(TQPainter *p) {
621  drawButton(p);
622 }
623 void KMultiTabBarTab::drawButton(TQPainter *paint)
624 {
625  if (m_style!=KMultiTabBar::KONQSBC) drawButtonStyled(paint);
626  else drawButtonClassic(paint);
627 }
628 
629 void KMultiTabBarTab::drawButtonStyled(TQPainter *paint) {
630 
631  TQSize sh;
632  const int width = 36; // rotated
633  const int height = 24;
634  if ((m_style==KMultiTabBar::KDEV3) || (m_style==KMultiTabBar::KDEV3ICON) || (isOn())) {
635  if ((m_position==KMultiTabBar::Left) || (m_position==KMultiTabBar::Right))
636  sh=TQSize(this->height(),this->width());//KMultiTabBarButton::sizeHint();
637  else sh=TQSize(this->width(),this->height());
638  }
639  else
640  sh=TQSize(width,height);
641 
642  TQPixmap pixmap( sh.width(),height);
643  pixmap.fill(eraseColor());
644  TQPainter painter(&pixmap);
645 
646 
647  TQStyle::SFlags st=TQStyle::Style_Default;
648 
649  st|=TQStyle::Style_Enabled;
650 
651  if (isOn()) st|=TQStyle::Style_On;
652 
653  style().drawControl(TQStyle::CE_PushButton,&painter,this, TQRect(0,0,pixmap.width(),pixmap.height()), colorGroup(),st);
654  style().drawControl(TQStyle::CE_PushButtonLabel,&painter,this, TQRect(0,0,pixmap.width(),pixmap.height()), colorGroup(),st);
655 
656  switch (m_position) {
657  case KMultiTabBar::Left:
658  paint->rotate(-90);
659  paint->drawPixmap(1-pixmap.width(),0,pixmap);
660  break;
661  case KMultiTabBar::Right:
662  paint->rotate(90);
663  paint->drawPixmap(0,1-pixmap.height(),pixmap);
664  break;
665 
666  default:
667  paint->drawPixmap(0,0,pixmap);
668  break;
669  }
670 // style().drawControl(TQStyle::CE_PushButtonLabel,painter,this, TQRect(0,0,pixmap.width(),pixmap.height()),
671 // colorGroup(),TQStyle::Style_Enabled);
672 
673 
674 }
675 
676 void KMultiTabBarTab::drawButtonClassic(TQPainter *paint)
677 {
678  TQPixmap pixmap;
679  if ( iconSet())
680  pixmap = iconSet()->pixmap( TQIconSet::Small, TQIconSet::Normal );
681  paint->fillRect(0, 0, 24, 24, colorGroup().background());
682 
683  if (!isOn())
684  {
685 
686  if (m_position==KMultiTabBar::Right)
687  {
688  paint->fillRect(0,0,21,21,TQBrush(colorGroup().background()));
689 
690  paint->setPen(colorGroup().background().dark(150));
691  paint->drawLine(0,22,23,22);
692 
693  paint->drawPixmap(12-pixmap.width()/2,12-pixmap.height()/2,pixmap);
694 
695  paint->setPen(colorGroup().shadow());
696  paint->drawLine(0,0,0,23);
697  paint->setPen(colorGroup().background().dark(120));
698  paint->drawLine(1,0,1,23);
699 
700  }
701  else
702  if ((m_position==KMultiTabBar::Bottom) || (m_position==KMultiTabBar::Top))
703  {
704  paint->fillRect(0,1,23,22,TQBrush(colorGroup().background()));
705 
706  paint->drawPixmap(12-pixmap.width()/2,12-pixmap.height()/2,pixmap);
707 
708  paint->setPen(colorGroup().background().dark(120));
709  paint->drawLine(23,0,23,23);
710 
711 
712  paint->setPen(colorGroup().light());
713  paint->drawLine(0,22,23,22);
714  paint->drawLine(0,23,23,23);
715  paint->setPen(colorGroup().shadow());
716  paint->drawLine(0,0,23,0);
717  paint->setPen(colorGroup().background().dark(120));
718  paint->drawLine(0,1,23,1);
719 
720  }
721  else
722  {
723  paint->setPen(colorGroup().background().dark(120));
724  paint->drawLine(0,23,23,23);
725  paint->fillRect(0,0,23,21,TQBrush(colorGroup().background()));
726  paint->drawPixmap(12-pixmap.width()/2,12-pixmap.height()/2,pixmap);
727 
728  paint->setPen(colorGroup().light());
729  paint->drawLine(23,0,23,23);
730  paint->drawLine(22,0,22,23);
731 
732  paint->setPen(colorGroup().shadow());
733  paint->drawLine(0,0,0,23);
734 
735  }
736 
737 
738  }
739  else
740  {
741  if (m_position==KMultiTabBar::Right)
742  {
743  paint->setPen(colorGroup().shadow());
744  paint->drawLine(0,height()-1,23,height()-1);
745  paint->drawLine(0,height()-2,23,height()-2);
746  paint->drawLine(23,0,23,height()-1);
747  paint->drawLine(22,0,22,height()-1);
748  paint->fillRect(0,0,21,height()-3,TQBrush(colorGroup().light()));
749  paint->drawPixmap(10-pixmap.width()/2,10-pixmap.height()/2,pixmap);
750 
751  if (m_showActiveTabText)
752  {
753  if (height()<25+4) return;
754 
755  TQPixmap tpixmap(height()-25-3, width()-2);
756  TQPainter painter(&tpixmap);
757 
758  painter.fillRect(0,0,tpixmap.width(),tpixmap.height(),TQBrush(colorGroup().light()));
759 
760  painter.setPen(colorGroup().text());
761  painter.drawText(0,+width()/2+TQFontMetrics(TQFont()).height()/2,m_text);
762 
763  paint->rotate(90);
764  kdDebug()<<"tpixmap.width:"<<tpixmap.width()<<endl;
765  paint->drawPixmap(25,-tpixmap.height()+1,tpixmap);
766  }
767 
768  }
769  else
770  if (m_position==KMultiTabBar::Top)
771  {
772  paint->fillRect(0,0,width()-1,23,TQBrush(colorGroup().light()));
773  paint->drawPixmap(10-pixmap.width()/2,10-pixmap.height()/2,pixmap);
774  if (m_showActiveTabText)
775  {
776  paint->setPen(colorGroup().text());
777  paint->drawText(25,height()/2+TQFontMetrics(TQFont()).height()/2,m_text);
778  }
779  }
780  else
781  if (m_position==KMultiTabBar::Bottom)
782  {
783  paint->setPen(colorGroup().shadow());
784  paint->drawLine(0,23,width()-1,23);
785  paint->drawLine(0,22,width()-1,22);
786  paint->fillRect(0,0,width()-1,21,TQBrush(colorGroup().light()));
787  paint->drawPixmap(10-pixmap.width()/2,10-pixmap.height()/2,pixmap);
788  if (m_showActiveTabText)
789  {
790  paint->setPen(colorGroup().text());
791  paint->drawText(25,height()/2+TQFontMetrics(TQFont()).height()/2,m_text);
792  }
793 
794  }
795  else
796  {
797 
798 
799  paint->setPen(colorGroup().shadow());
800  paint->drawLine(0,height()-1,23,height()-1);
801  paint->drawLine(0,height()-2,23,height()-2);
802  paint->fillRect(0,0,23,height()-3,TQBrush(colorGroup().light()));
803  paint->drawPixmap(10-pixmap.width()/2,10-pixmap.height()/2,pixmap);
804  if (m_showActiveTabText)
805  {
806 
807  if (height()<25+4) return;
808 
809  TQPixmap tpixmap(height()-25-3, width()-2);
810  TQPainter painter(&tpixmap);
811 
812  painter.fillRect(0,0,tpixmap.width(),tpixmap.height(),TQBrush(colorGroup().light()));
813 
814  painter.setPen(colorGroup().text());
815  painter.drawText(tpixmap.width()-TQFontMetrics(TQFont()).width(m_text),+width()/2+TQFontMetrics(TQFont()).height()/2,m_text);
816 
817  paint->rotate(-90);
818  kdDebug()<<"tpixmap.width:"<<tpixmap.width()<<endl;
819 
820  paint->drawPixmap(-24-tpixmap.width(),2,tpixmap);
821 
822  }
823 
824  }
825 
826  }
827 }
828 
829 
830 
831 
832 
833 
834 
835 KMultiTabBar::KMultiTabBar(KMultiTabBarMode bm, TQWidget *parent,const char *name):TQWidget(parent,name)
836 {
837  m_buttons.setAutoDelete(false);
838  if (bm==Vertical)
839  {
840  m_l=new TQVBoxLayout(this);
841  setSizePolicy(TQSizePolicy::Fixed, TQSizePolicy::Expanding, true);
842 // setFixedWidth(24);
843  }
844  else
845  {
846  m_l=new TQHBoxLayout(this);
847  setSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Fixed, true);
848 // setFixedHeight(24);
849  }
850  m_l->setMargin(0);
851  m_l->setAutoAdd(false);
852 
853  m_internal=new KMultiTabBarInternal(this,bm);
854  setPosition((bm==KMultiTabBar::Vertical)?KMultiTabBar::Right:KMultiTabBar::Bottom);
855  setStyle(VSNET);
856  // setStyle(KDEV3);
857  //setStyle(KONQSBC);
858  m_l->insertWidget(0,m_internal);
859  m_l->insertWidget(0,m_btnTabSep=new TQFrame(this));
860  m_btnTabSep->setFixedHeight(4);
861  m_btnTabSep->setFrameStyle(TQFrame::Panel | TQFrame::Sunken);
862  m_btnTabSep->setLineWidth(2);
863  m_btnTabSep->hide();
864 
865  updateGeometry();
866 }
867 
868 KMultiTabBar::~KMultiTabBar() {
869 }
870 
871 /*int KMultiTabBar::insertButton(TQPixmap pic,int id ,const TQString&)
872 {
873  (new TDEToolbarButton(pic,id,m_internal))->show();
874  return 0;
875 }*/
876 
877 int KMultiTabBar::appendButton(const TQPixmap &pic ,int id,TQPopupMenu *popup,const TQString&)
878 {
879  KMultiTabBarButton *btn;
880  m_buttons.append(btn= new KMultiTabBarButton(pic,TQString::null,
881  popup,id,this,m_position,m_internal->m_style));
882  m_l->insertWidget(0,btn);
883  btn->show();
884  m_btnTabSep->show();
885  return 0;
886 }
887 
888 void KMultiTabBar::updateSeparator() {
889  bool hideSep=true;
890  for (TQPtrListIterator<KMultiTabBarButton> it(m_buttons);it.current();++it){
891  if (it.current()->isVisibleTo(this)) {
892  hideSep=false;
893  break;
894  }
895  }
896  if (hideSep) m_btnTabSep->hide();
897  else m_btnTabSep->show();
898 
899 }
900 
901 int KMultiTabBar::appendTab(const TQPixmap &pic ,int id ,const TQString& text)
902 {
903  m_internal->appendTab(pic,id,text);
904  return 0;
905 }
906 
907 KMultiTabBarButton* KMultiTabBar::button(int id) const
908 {
909  for (TQPtrListIterator<KMultiTabBarButton> it(m_buttons);it.current();++it){
910  if (it.current()->id()==id) return it.current();
911  }
912  return 0;
913 }
914 
915 KMultiTabBarTab* KMultiTabBar::tab(int id) const
916 {
917  return m_internal->tab(id);
918 }
919 
920 
921 
922 void KMultiTabBar::removeButton(int id)
923 {
924  for (uint pos=0;pos<m_buttons.count();pos++)
925  {
926  if (m_buttons.at(pos)->id()==id)
927  {
928  m_buttons.take(pos)->deleteLater();
929  break;
930  }
931  }
932  if (m_buttons.count()==0) m_btnTabSep->hide();
933 }
934 
935 void KMultiTabBar::removeTab(int id)
936 {
937  m_internal->removeTab(id);
938 }
939 
940 void KMultiTabBar::setTab(int id,bool state)
941 {
942  KMultiTabBarTab *ttab=tab(id);
943  if (ttab)
944  {
945  ttab->setState(state);
946  }
947 }
948 
949 bool KMultiTabBar::isTabRaised(int id) const
950 {
951  KMultiTabBarTab *ttab=tab(id);
952  if (ttab)
953  {
954  return ttab->isOn();
955  }
956 
957  return false;
958 }
959 
960 
961 void KMultiTabBar::showActiveTabTexts(bool show)
962 {
963  m_internal->showActiveTabTexts(show);
964 }
965 
966 void KMultiTabBar::setStyle(KMultiTabBarStyle style)
967 {
968  m_internal->setStyle(style);
969 }
970 
971 KMultiTabBar::KMultiTabBarStyle KMultiTabBar::tabStyle() const
972 {
973  return m_internal->m_style;
974 }
975 
976 void KMultiTabBar::setPosition(KMultiTabBarPosition pos)
977 {
978  m_position=pos;
979  m_internal->setPosition(pos);
980  for (uint i=0;i<m_buttons.count();i++)
981  m_buttons.at(i)->setPosition(pos);
982 }
983 
984 KMultiTabBar::KMultiTabBarPosition KMultiTabBar::position() const
985 {
986  return m_position;
987 }
988 void KMultiTabBar::fontChange(const TQFont& /* oldFont */)
989 {
990  for (uint i=0;i<tabs()->count();i++)
991  tabs()->at(i)->resize();
992  repaint();
993 }
994 
995 TQPtrList<KMultiTabBarTab>* KMultiTabBar::tabs() {return m_internal->tabs();}
996 TQPtrList<KMultiTabBarButton>* KMultiTabBar::buttons() {return &m_buttons;}
997 
KMultiTabBarButton
This class represents a tab bar button in a KMultiTabBarWidget.
Definition: tdemultitabbar.h:206
KMultiTabBarButton::setPosition
void setPosition(KMultiTabBar::KMultiTabBarPosition)
this is used internaly, but can be used by the user, if (s)he wants to It the according call of KMult...
Definition: tdemultitabbar.cpp:434
KMultiTabBarButton::setStyle
void setStyle(KMultiTabBar::KMultiTabBarStyle)
this is used internaly, but can be used by the user, if (s)he wants to It the according call of KMult...
Definition: tdemultitabbar.cpp:440
KMultiTabBarButton::clicked
void clicked(int id)
this is emitted if the button is clicked
KMultiTabBarButton::~KMultiTabBarButton
virtual ~KMultiTabBarButton()
Destructor.
Definition: tdemultitabbar.cpp:415
KMultiTabBarButton::setText
void setText(const TQString &)
modify the text of the button
Definition: tdemultitabbar.cpp:422
KMultiTabBarButton::id
int id() const
Returns the tab's ID.
Definition: tdemultitabbar.cpp:418
KMultiTabBarTab
This class represents a tab bar's tab in a KMultiTabBarWidget.
Definition: tdemultitabbar.h:269
KMultiTabBarTab::showActiveTabText
void showActiveTabText(bool show)
choose if the text should always be displayed this is only used in classic mode if at all
Definition: tdemultitabbar.cpp:615
KMultiTabBarTab::setState
void setState(bool state)
set the active state of the tab
Definition: tdemultitabbar.cpp:560
KMultiTabBarTab::~KMultiTabBarTab
virtual ~KMultiTabBarTab()
Destructor.
Definition: tdemultitabbar.cpp:511
KMultiTabBarTab::drawButtonStyled
void drawButtonStyled(TQPainter *)
Definition: tdemultitabbar.cpp:629
KMultiTabBar
A Widget for horizontal and vertical tabs.
Definition: tdemultitabbar.h:57
KMultiTabBar::setStyle
void setStyle(KMultiTabBarStyle style)
set the display style of the tabs
Definition: tdemultitabbar.cpp:966
KMultiTabBar::KMultiTabBarMode
KMultiTabBarMode
The tab bar's orientation.
Definition: tdemultitabbar.h:63
KMultiTabBar::Vertical
@ Vertical
Vertical orientation (i.e. on the left or right hand side)
Definition: tdemultitabbar.h:65
KMultiTabBar::KMultiTabBar
KMultiTabBar(KMultiTabBarMode bm, TQWidget *parent=0, const char *name=0)
Constructor.
Definition: tdemultitabbar.cpp:835
KMultiTabBar::KMultiTabBarStyle
KMultiTabBarStyle
The list of available styles for KMultiTabBar.
Definition: tdemultitabbar.h:81
KMultiTabBar::KDEV3
@ KDEV3
KDevelop 3 like (always show the text)
Definition: tdemultitabbar.h:83
KMultiTabBar::KDEV3ICON
@ KDEV3ICON
KDevelop 3 like with icons.
Definition: tdemultitabbar.h:85
KMultiTabBar::VSNET
@ VSNET
Visual Studio .Net like (only show the text of active tabs)
Definition: tdemultitabbar.h:82
KMultiTabBar::KONQSBC
@ KONQSBC
Konqueror's classic sidebar style (unthemed) (currently disabled)
Definition: tdemultitabbar.h:84
KMultiTabBar::appendButton
int appendButton(const TQPixmap &pic, int id=-1, TQPopupMenu *popup=0, const TQString &not_used_yet=TQString::null)
append a new button to the button area.
Definition: tdemultitabbar.cpp:877
KMultiTabBar::tabStyle
KMultiTabBarStyle tabStyle() const
get the display style of the tabs
Definition: tdemultitabbar.cpp:971
KMultiTabBar::showActiveTabTexts
void showActiveTabTexts(bool show=true)
might vanish, not sure yet
Definition: tdemultitabbar.cpp:961
KMultiTabBar::tabs
TQPtrList< KMultiTabBarTab > * tabs()
Returns the list of pointers to the tabs of type KMultiTabBarTab.
Definition: tdemultitabbar.cpp:995
KMultiTabBar::removeTab
void removeTab(int id)
remove a tab with a given ID
Definition: tdemultitabbar.cpp:935
KMultiTabBar::~KMultiTabBar
virtual ~KMultiTabBar()
Destructor.
Definition: tdemultitabbar.cpp:868
KMultiTabBar::appendTab
int appendTab(const TQPixmap &pic, int id=-1, const TQString &text=TQString::null)
append a new tab to the tab area.
Definition: tdemultitabbar.cpp:901
KMultiTabBar::removeButton
void removeButton(int id)
remove a button with the given ID
Definition: tdemultitabbar.cpp:922
KMultiTabBar::setTab
void setTab(int id, bool state)
set a tab to "raised"
Definition: tdemultitabbar.cpp:940
KMultiTabBar::KMultiTabBarPosition
KMultiTabBarPosition
The tab bar's position.
Definition: tdemultitabbar.h:71
KMultiTabBar::Top
@ Top
On top.
Definition: tdemultitabbar.h:74
KMultiTabBar::Left
@ Left
Left hand side.
Definition: tdemultitabbar.h:72
KMultiTabBar::Bottom
@ Bottom
On bottom.
Definition: tdemultitabbar.h:75
KMultiTabBar::Right
@ Right
Right hand side.
Definition: tdemultitabbar.h:73
KMultiTabBar::button
class KMultiTabBarButton * button(int id) const
get a pointer to a button within the button area identified by its ID
Definition: tdemultitabbar.cpp:907
KMultiTabBar::tab
class KMultiTabBarTab * tab(int id) const
get a pointer to a tab within the tab area, identified by its ID
Definition: tdemultitabbar.cpp:915
KMultiTabBar::isTabRaised
bool isTabRaised(int id) const
return the state of a tab, identified by it's ID
Definition: tdemultitabbar.cpp:949
KMultiTabBar::position
KMultiTabBarPosition position() const
get the tabbar position.
Definition: tdemultitabbar.cpp:984
KMultiTabBar::buttons
TQPtrList< KMultiTabBarButton > * buttons()
Returns the list of pointers to the tab buttons of type KMultiTabBarButton.
Definition: tdemultitabbar.cpp:996
KMultiTabBar::setPosition
void setPosition(KMultiTabBarPosition pos)
set the real position of the widget.
Definition: tdemultitabbar.cpp:976
endl
kndbgstream & endl(kndbgstream &s)
kdDebug
kdbgstream kdDebug(int area=0)
flush
kndbgstream & flush(kndbgstream &s)

tdeutils

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

tdeutils

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