25 #include "tdemultitabbar.h" 26 #include "tdemultitabbar.moc" 27 #include "tdemultitabbar_p.h" 28 #include "tdemultitabbar_p.moc" 30 #include <tqpopupmenu.h> 32 #include <tqpainter.h> 33 #include <tqtooltip.h> 34 #include <tqfontmetrics.h> 37 #include <kiconloader.h> 39 #include <tqapplication.h> 42 #define NEARBYINT(i) ((int(float(i) + 0.5))) 44 class KMultiTabBarTabPrivate {
53 m_showActiveTabTexts=
false;
54 m_tabs.setAutoDelete(
true);
56 setHScrollBarMode(AlwaysOff);
57 setVScrollBarMode(AlwaysOff);
60 box=
new TQWidget(viewport());
61 mainLayout=
new TQVBoxLayout(box);
62 mainLayout->setAutoAdd(
true);
63 box->setFixedWidth(24);
68 box=
new TQWidget(viewport());
69 mainLayout=
new TQHBoxLayout(box);
70 mainLayout->setAutoAdd(
true);
71 box->setFixedHeight(24);
75 setFrameStyle(NoFrame);
76 viewport()->setBackgroundMode(TQt::PaletteBackground);
84 for (uint i=0;i<m_tabs.count();i++)
85 m_tabs.at(i)->setStyle(m_style);
92 }
else if (mainLayout==0) {
95 box=
new TQWidget(viewport());
96 mainLayout=
new TQVBoxLayout(box);
97 box->setFixedWidth(24);
102 box=
new TQWidget(viewport());
103 mainLayout=
new TQHBoxLayout(box);
104 box->setFixedHeight(24);
108 for (uint i=0;i<m_tabs.count();i++)
109 mainLayout->add(m_tabs.at(i));
110 mainLayout->setAutoAdd(
true);
113 viewport()->repaint();
116 void KMultiTabBarInternal::drawContents ( TQPainter * paint,
int clipx,
int clipy,
int clipw,
int cliph )
118 TQScrollView::drawContents (paint , clipx, clipy, clipw, cliph );
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());
133 paint->setPen(colorGroup().light());
134 paint->drawLine(23,0,23,viewport()->height());
135 paint->drawLine(22,0,22,viewport()->height());
137 paint->setPen(colorGroup().shadow());
138 paint->drawLine(0,0,0,viewport()->height());
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);
150 paint->setPen(colorGroup().light());
151 paint->drawLine(0,23,viewport()->width(),23);
152 paint->drawLine(0,22,viewport()->width(),22);
162 void KMultiTabBarInternal::contentsMousePressEvent(TQMouseEvent *ev)
167 void KMultiTabBarInternal::mousePressEvent(TQMouseEvent *ev)
173 #define CALCDIFF(m_tabs,diff,i) if (m_lines>(int)lines) {\ 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);\ 189 void KMultiTabBarInternal::resizeEvent(TQResizeEvent *ev) {
193 if (ev) TQScrollView::resizeEvent(ev);
197 box->setGeometry(0,0,width(),height());
208 const uint tabCount=m_tabs.count();
209 for (uint i=0;i<tabCount;i++) {
211 tmp+=m_tabs.at(i)->neededSize();
214 else if (i==(tabCount-1))
break;
226 setFixedHeight(lines*24);
227 box->setFixedHeight(lines*24);
228 m_lines=height()/24-1;
230 CALCDIFF(m_tabs,diff,0)
234 for (uint i=0;i<tabCount;i++) {
237 tmp+=tab->neededSize()+diff;
241 CALCDIFF(m_tabs,diff,i)
247 tab->removeEventFilter(
this);
248 tab->move(NEARBYINT(tmp-tab->neededSize()),lines*24);
250 tab->setFixedWidth(NEARBYINT(tmp+diff)-tab->x());;
251 tab->installEventFilter(
this);
252 CALCDIFF(m_tabs,diff,(i+1))
263 tab->removeEventFilter(
this);
264 tab->move(NEARBYINT(tmp-tab->neededSize()),lines*24);
265 tab->setFixedWidth(NEARBYINT(tmp+diff)-tab->x());;
268 tab->installEventFilter(
this);
274 setFixedWidth(lines*24);
275 box->setFixedWidth(lines*24);
276 m_lines=lines=width()/24;
278 CALCDIFF(m_tabs,diff,0)
281 for (uint i=0;i<tabCount;i++) {
284 tmp+=tab->neededSize()+diff;
287 CALCDIFF(m_tabs,diff,i);
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);
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);
313 for (
int i=0;i<(int)m_tabs.count();i++)
316 box->setGeometry(0,0,size,height());
317 else box->setGeometry(0,0,width(),size);
323 void KMultiTabBarInternal::showActiveTabTexts(
bool show)
325 m_showActiveTabTexts=show;
331 for (TQPtrListIterator<KMultiTabBarTab> it(m_tabs);it.current();++it){
332 if (it.current()->id()==id)
return it.current();
337 bool KMultiTabBarInternal::eventFilter(TQObject *, TQEvent *e) {
338 if (e->type()==TQEvent::Resize) resizeEvent(0);
342 int KMultiTabBarInternal::appendTab(
const TQPixmap &pic ,
int id,
const TQString& text)
345 m_tabs.append(tab=
new KMultiTabBarTab(pic,text,
id,box,m_position,m_style));
346 tab->installEventFilter(
this);
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);
356 }
else tab->setSize(m_expandedTabSize);
357 }
else tab->updateState();
363 void KMultiTabBarInternal::removeTab(
int id)
365 for (uint pos=0;pos<m_tabs.count();pos++)
367 if (m_tabs.at(pos)->id()==id)
379 for (uint i=0;i<m_tabs.count();i++)
380 m_tabs.at(i)->setTabsPosition(m_position);
381 viewport()->repaint();
384 KMultiTabBarButton::KMultiTabBarButton(
const TQPixmap& pic,
const TQString& text, TQPopupMenu *popup,
386 :TQPushButton(TQIconSet(),text,parent),m_style(style)
391 if (popup) setPopup(popup);
396 TQToolTip::add(
this,text);
397 connect(
this,TQT_SIGNAL(clicked()),
this,TQT_SLOT(slotClicked()));
400 KMultiTabBarButton::KMultiTabBarButton(
const TQString& text, TQPopupMenu *popup,
402 :TQPushButton(TQIconSet(),text,parent),m_style(style)
406 if (popup) setPopup(popup);
411 TQToolTip::add(
this,text);
412 connect(
this,TQT_SIGNAL(clicked()),
this,TQT_SLOT(slotClicked()));
424 TQPushButton::setText(text);
426 TQToolTip::add(
this,text);
429 void KMultiTabBarButton::slotClicked()
446 void KMultiTabBarButton::hideEvent( TQHideEvent* he) {
447 TQPushButton::hideEvent(he);
449 if (tb) tb->updateSeparator();
452 void KMultiTabBarButton::showEvent( TQShowEvent* he) {
453 TQPushButton::showEvent(he);
455 if (tb) tb->updateSeparator();
459 TQSize KMultiTabBarButton::sizeHint()
const 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();
474 if ( isMenuButton() )
475 w += style().pixelMetric(TQStyle::PM_MenuButtonIndicator,
this);
478 TQPixmap *pm = (TQPixmap *)pixmap();
482 TQString s( text() );
483 bool empty = s.isEmpty();
485 s = TQString::fromLatin1(
"XXXX");
486 TQFontMetrics fm = fontMetrics();
487 TQSize sz = fm.size( ShowPrefix, s );
491 h = TQMAX(h, sz.height());
494 return (style().tqsizeFromContents(TQStyle::CT_ToolButton,
this, TQSize(w, h)).
495 expandedTo(TQApplication::globalStrut()));
499 KMultiTabBarTab::KMultiTabBarTab(
const TQPixmap& pic,
const TQString& text,
503 m_showActiveTabText(
false)
505 d=
new KMultiTabBarTabPrivate();
508 setToggleButton(
true);
519 if (!d->pix.isNull()) {
522 d->pix=d->pix.xForm(temp);
531 void KMultiTabBarTab::setIcon(
const TQString& icon)
533 TQPixmap pic=SmallIcon(icon);
537 void KMultiTabBarTab::setIcon(
const TQPixmap& icon)
542 TQWMatrix rotateMatrix;
544 rotateMatrix.rotate(90);
546 rotateMatrix.rotate(-90);
547 TQPixmap pic=icon.xForm(rotateMatrix);
550 }
else setIconSet(icon);
554 void KMultiTabBarTab::slotClicked()
557 KMultiTabBarButton::slotClicked();
566 void KMultiTabBarTab::updateState()
571 TQPushButton::setText(m_text);
573 kdDebug()<<
"KMultiTabBarTab::updateState(): setting text to an empty TQString***************"<<
endl;
574 TQPushButton::setText(TQString::null);
580 setFixedHeight(KMultiTabBarButton::sizeHint().width());
581 }
else setFixedHeight(36);
585 setFixedWidth(KMultiTabBarButton::sizeHint().width());
586 }
else setFixedWidth(36);
589 if ((!isOn()) || (!m_showActiveTabText))
596 setFixedHeight(m_expandedSize);
598 setFixedWidth(m_expandedSize);
600 TQApplication::sendPostedEvents(0,TQEvent::Paint | TQEvent::Move | TQEvent::Resize | TQEvent::LayoutHint);
604 int KMultiTabBarTab::neededSize()
609 void KMultiTabBarTab::setSize(
int size)
617 m_showActiveTabText=show;
620 void KMultiTabBarTab::drawButtonLabel(TQPainter *p) {
623 void KMultiTabBarTab::drawButton(TQPainter *paint)
626 else drawButtonClassic(paint);
632 const int width = 36;
633 const int height = 24;
636 sh=TQSize(this->height(),this->width());
637 else sh=TQSize(this->width(),this->height());
640 sh=TQSize(width,height);
642 TQPixmap pixmap( sh.width(),height);
643 pixmap.fill(eraseColor());
644 TQPainter painter(&pixmap);
647 TQStyle::SFlags st=TQStyle::Style_Default;
649 st|=TQStyle::Style_Enabled;
651 if (isOn()) st|=TQStyle::Style_On;
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);
656 switch (m_position) {
659 paint->drawPixmap(1-pixmap.width(),0,pixmap);
663 paint->drawPixmap(0,1-pixmap.height(),pixmap);
667 paint->drawPixmap(0,0,pixmap);
676 void KMultiTabBarTab::drawButtonClassic(TQPainter *paint)
680 pixmap = iconSet()->pixmap( TQIconSet::Small, TQIconSet::Normal );
681 paint->fillRect(0, 0, 24, 24, colorGroup().background());
688 paint->fillRect(0,0,21,21,TQBrush(colorGroup().background()));
690 paint->setPen(colorGroup().background().dark(150));
691 paint->drawLine(0,22,23,22);
693 paint->drawPixmap(12-pixmap.width()/2,12-pixmap.height()/2,pixmap);
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);
704 paint->fillRect(0,1,23,22,TQBrush(colorGroup().background()));
706 paint->drawPixmap(12-pixmap.width()/2,12-pixmap.height()/2,pixmap);
708 paint->setPen(colorGroup().background().dark(120));
709 paint->drawLine(23,0,23,23);
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);
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);
728 paint->setPen(colorGroup().light());
729 paint->drawLine(23,0,23,23);
730 paint->drawLine(22,0,22,23);
732 paint->setPen(colorGroup().shadow());
733 paint->drawLine(0,0,0,23);
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);
751 if (m_showActiveTabText)
753 if (height()<25+4)
return;
755 TQPixmap tpixmap(height()-25-3, width()-2);
756 TQPainter painter(&tpixmap);
758 painter.fillRect(0,0,tpixmap.width(),tpixmap.height(),TQBrush(colorGroup().light()));
760 painter.setPen(colorGroup().text());
761 painter.drawText(0,+width()/2+TQFontMetrics(TQFont()).height()/2,m_text);
764 kdDebug()<<
"tpixmap.width:"<<tpixmap.width()<<
endl;
765 paint->drawPixmap(25,-tpixmap.height()+1,tpixmap);
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)
776 paint->setPen(colorGroup().text());
777 paint->drawText(25,height()/2+TQFontMetrics(TQFont()).height()/2,m_text);
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)
790 paint->setPen(colorGroup().text());
791 paint->drawText(25,height()/2+TQFontMetrics(TQFont()).height()/2,m_text);
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)
807 if (height()<25+4)
return;
809 TQPixmap tpixmap(height()-25-3, width()-2);
810 TQPainter painter(&tpixmap);
812 painter.fillRect(0,0,tpixmap.width(),tpixmap.height(),TQBrush(colorGroup().light()));
814 painter.setPen(colorGroup().text());
815 painter.drawText(tpixmap.width()-TQFontMetrics(TQFont()).width(m_text),+width()/2+TQFontMetrics(TQFont()).height()/2,m_text);
818 kdDebug()<<
"tpixmap.width:"<<tpixmap.width()<<
endl;
820 paint->drawPixmap(-24-tpixmap.width(),2,tpixmap);
837 m_buttons.setAutoDelete(
false);
840 m_l=
new TQVBoxLayout(
this);
841 setSizePolicy(TQSizePolicy::Fixed, TQSizePolicy::Expanding,
true);
846 m_l=
new TQHBoxLayout(
this);
847 setSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Fixed,
true);
851 m_l->setAutoAdd(
false);
853 m_internal=
new KMultiTabBarInternal(
this,bm);
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);
881 popup,
id,
this,m_position,m_internal->m_style));
882 m_l->insertWidget(0,btn);
888 void KMultiTabBar::updateSeparator() {
890 for (TQPtrListIterator<KMultiTabBarButton> it(m_buttons);it.current();++it){
891 if (it.current()->isVisibleTo(
this)) {
896 if (hideSep) m_btnTabSep->hide();
897 else m_btnTabSep->show();
903 m_internal->appendTab(pic,
id,text);
909 for (TQPtrListIterator<KMultiTabBarButton> it(m_buttons);it.current();++it){
910 if (it.current()->id()==id)
return it.current();
917 return m_internal->tab(
id);
924 for (uint pos=0;pos<m_buttons.count();pos++)
926 if (m_buttons.at(pos)->id()==id)
928 m_buttons.take(pos)->deleteLater();
932 if (m_buttons.count()==0) m_btnTabSep->hide();
937 m_internal->removeTab(
id);
963 m_internal->showActiveTabTexts(show);
968 m_internal->setStyle(style);
973 return m_internal->m_style;
979 m_internal->setPosition(pos);
980 for (uint i=0;i<m_buttons.count();i++)
981 m_buttons.at(i)->setPosition(pos);
988 void KMultiTabBar::fontChange(
const TQFont& )
990 for (uint i=0;i<
tabs()->count();i++)
991 tabs()->at(i)->resize();
KDevelop 3 like (always show the text)
Konqueror's classic sidebar style (unthemed) (currently disabled)
virtual ~KMultiTabBar()
Destructor.
KMultiTabBarStyle tabStyle() const
get the display style of the tabs
KMultiTabBarPosition
The tab bar's position.
bool isTabRaised(int id) const
return the state of a tab, identified by it's ID
kndbgstream & flush(kndbgstream &s)
class KMultiTabBarTab * tab(int id) const
get a pointer to a tab within the tab area, identified by its ID
virtual ~KMultiTabBarTab()
Destructor.
void showActiveTabText(bool show)
choose if the text should always be displayed this is only used in classic mode if at all ...
kdbgstream kdDebug(int area=0)
Vertical orientation (i.e. on the left or right hand side)
KDevelop 3 like with icons.
Visual Studio .Net like (only show the text of active tabs)
TQPtrList< KMultiTabBarTab > * tabs()
Returns the list of pointers to the tabs of type KMultiTabBarTab.
This class represents a tab bar's tab in a KMultiTabBarWidget.
void showActiveTabTexts(bool show=true)
might vanish, not sure yet
int appendTab(const TQPixmap &pic, int id=-1, const TQString &text=TQString::null)
append a new tab to the tab area.
void setPosition(KMultiTabBarPosition pos)
set the real position of the widget.
A Widget for horizontal and vertical tabs.
KMultiTabBarPosition position() const
get the tabbar position.
class KMultiTabBarButton * button(int id) const
get a pointer to a button within the button area identified by its ID
int appendButton(const TQPixmap &pic, int id=-1, TQPopupMenu *popup=0, const TQString ¬_used_yet=TQString::null)
append a new button to the button area.
void setState(bool state)
set the active state of the tab
KMultiTabBarMode
The tab bar's orientation.
KMultiTabBar(KMultiTabBarMode bm, TQWidget *parent=0, const char *name=0)
Constructor.
void removeTab(int id)
remove a tab with a given ID
KMultiTabBarStyle
The list of available styles for KMultiTabBar.
void setTab(int id, bool state)
set a tab to "raised"
kndbgstream & endl(kndbgstream &s)
void setStyle(KMultiTabBarStyle style)
set the display style of the tabs
void removeButton(int id)
remove a button with the given ID
TQPtrList< KMultiTabBarButton > * buttons()
Returns the list of pointers to the tab buttons of type KMultiTabBarButton.
void drawButtonStyled(TQPainter *)