00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "kmultitabbar.h"
00026 #include "kmultitabbar.moc"
00027 #include "kmultitabbar_p.h"
00028 #include "kmultitabbar_p.moc"
00029 #include <qbutton.h>
00030 #include <qpopupmenu.h>
00031 #include <qlayout.h>
00032 #include <qpainter.h>
00033 #include <qtooltip.h>
00034 #include <qfontmetrics.h>
00035 #include <qstyle.h>
00036
00037 #include <kiconloader.h>
00038 #include <kdebug.h>
00039 #include <qapplication.h>
00040 #include <math.h>
00041
00042 #define NEARBYINT(i) ((int(float(i) + 0.5)))
00043
00044 class KMultiTabBarTabPrivate {
00045 public:
00046 QPixmap pix;
00047 };
00048
00049
00050 KMultiTabBarInternal::KMultiTabBarInternal(QWidget *parent, KMultiTabBar::KMultiTabBarMode bm):QScrollView(parent)
00051 {
00052 m_expandedTabSize=-1;
00053 m_showActiveTabTexts=false;
00054 m_tabs.setAutoDelete(true);
00055 m_barMode=bm;
00056 setHScrollBarMode(AlwaysOff);
00057 setVScrollBarMode(AlwaysOff);
00058 if (bm==KMultiTabBar::Vertical)
00059 {
00060 box=new QWidget(viewport());
00061 mainLayout=new QVBoxLayout(box);
00062 mainLayout->setAutoAdd(true);
00063 box->setFixedWidth(24);
00064 setFixedWidth(24);
00065 }
00066 else
00067 {
00068 box=new QWidget(viewport());
00069 mainLayout=new QHBoxLayout(box);
00070 mainLayout->setAutoAdd(true);
00071 box->setFixedHeight(24);
00072 setFixedHeight(24);
00073 }
00074 addChild(box);
00075 setFrameStyle(NoFrame);
00076 viewport()->setBackgroundMode(Qt::PaletteBackground);
00077
00078
00079 }
00080
00081 void KMultiTabBarInternal::setStyle(enum KMultiTabBar::KMultiTabBarStyle style)
00082 {
00083 m_style=style;
00084 for (uint i=0;i<m_tabs.count();i++)
00085 m_tabs.at(i)->setStyle(m_style);
00086
00087 if ( (m_style==KMultiTabBar::KDEV3) ||
00088 (m_style==KMultiTabBar::KDEV3ICON ) ) {
00089 delete mainLayout;
00090 mainLayout=0;
00091 resizeEvent(0);
00092 } else if (mainLayout==0) {
00093 if (m_barMode==KMultiTabBar::Vertical)
00094 {
00095 box=new QWidget(viewport());
00096 mainLayout=new QVBoxLayout(box);
00097 box->setFixedWidth(24);
00098 setFixedWidth(24);
00099 }
00100 else
00101 {
00102 box=new QWidget(viewport());
00103 mainLayout=new QHBoxLayout(box);
00104 box->setFixedHeight(24);
00105 setFixedHeight(24);
00106 }
00107 addChild(box);
00108 for (uint i=0;i<m_tabs.count();i++)
00109 mainLayout->add(m_tabs.at(i));
00110 mainLayout->setAutoAdd(true);
00111
00112 }
00113 viewport()->repaint();
00114 }
00115
00116 void KMultiTabBarInternal::drawContents ( QPainter * paint, int clipx, int clipy, int clipw, int cliph )
00117 {
00118 QScrollView::drawContents (paint , clipx, clipy, clipw, cliph );
00119
00120 if (m_position==KMultiTabBar::Right)
00121 {
00122
00123 paint->setPen(colorGroup().shadow());
00124 paint->drawLine(0,0,0,viewport()->height());
00125 paint->setPen(colorGroup().background().dark(120));
00126 paint->drawLine(1,0,1,viewport()->height());
00127
00128
00129 }
00130 else
00131 if (m_position==KMultiTabBar::Left)
00132 {
00133 paint->setPen(colorGroup().light());
00134 paint->drawLine(23,0,23,viewport()->height());
00135 paint->drawLine(22,0,22,viewport()->height());
00136
00137 paint->setPen(colorGroup().shadow());
00138 paint->drawLine(0,0,0,viewport()->height());
00139 }
00140 else
00141 if (m_position==KMultiTabBar::Bottom)
00142 {
00143 paint->setPen(colorGroup().shadow());
00144 paint->drawLine(0,0,viewport()->width(),0);
00145 paint->setPen(colorGroup().background().dark(120));
00146 paint->drawLine(0,1,viewport()->width(),1);
00147 }
00148 else
00149 {
00150 paint->setPen(colorGroup().light());
00151 paint->drawLine(0,23,viewport()->width(),23);
00152 paint->drawLine(0,22,viewport()->width(),22);
00153
00154
00155
00156
00157 }
00158
00159
00160 }
00161
00162 void KMultiTabBarInternal::contentsMousePressEvent(QMouseEvent *ev)
00163 {
00164 ev->ignore();
00165 }
00166
00167 void KMultiTabBarInternal::mousePressEvent(QMouseEvent *ev)
00168 {
00169 ev->ignore();
00170 }
00171
00172
00173 #define CALCDIFF(m_tabs,diff,i) if (m_lines>(int)lines) {\
00174 \
00175 uint ulen=0;\
00176 diff=0; \
00177 for (uint i2=i;i2<tabCount;i2++) {\
00178 uint l1=m_tabs.at(i2)->neededSize();\
00179 if ((ulen+l1)>space){\
00180 if (ulen==0) diff=0;\
00181 else diff=((float)(space-ulen))/(i2-i);\
00182 break;\
00183 }\
00184 ulen+=l1;\
00185 }\
00186 } else {diff=0; }
00187
00188
00189 void KMultiTabBarInternal::resizeEvent(QResizeEvent *ev) {
00190
00191
00192
00193 if (ev) QScrollView::resizeEvent(ev);
00194
00195 if ( (m_style==KMultiTabBar::KDEV3) ||
00196 (m_style==KMultiTabBar::KDEV3ICON) ){
00197 box->setGeometry(0,0,width(),height());
00198 int lines=1;
00199 uint space;
00200 float tmp=0;
00201 if ((m_position==KMultiTabBar::Bottom) || (m_position==KMultiTabBar::Top))
00202 space=width();
00203 else
00204 space=height();
00205
00206 int cnt=0;
00207
00208 const uint tabCount=m_tabs.count();
00209 for (uint i=0;i<tabCount;i++) {
00210 cnt++;
00211 tmp+=m_tabs.at(i)->neededSize();
00212 if (tmp>space) {
00213 if (cnt>1)i--;
00214 else if (i==(tabCount-1)) break;
00215 cnt=0;
00216 tmp=0;
00217 lines++;
00218 }
00219 }
00220
00221 float diff=0;
00222 cnt=0;
00223
00224 if ((m_position==KMultiTabBar::Bottom) || (m_position==KMultiTabBar::Top)) {
00225
00226 setFixedHeight(lines*24);
00227 box->setFixedHeight(lines*24);
00228 m_lines=height()/24-1;
00229 lines=0;
00230 CALCDIFF(m_tabs,diff,0)
00231 tmp=-diff;
00232
00233
00234 for (uint i=0;i<tabCount;i++) {
00235 KMultiTabBarTab *tab=m_tabs.at(i);
00236 cnt++;
00237 tmp+=tab->neededSize()+diff;
00238 if (tmp>space) {
00239
00240 if (cnt>1) {
00241 CALCDIFF(m_tabs,diff,i)
00242 i--;
00243 }
00244 else {
00245
00246 kdDebug()<<"diff="<<diff<<endl;
00247 tab->removeEventFilter(this);
00248 tab->move(NEARBYINT(tmp-tab->neededSize()),lines*24);
00249
00250 tab->setFixedWidth(NEARBYINT(tmp+diff)-tab->x());;
00251 tab->installEventFilter(this);
00252 CALCDIFF(m_tabs,diff,(i+1))
00253
00254 }
00255 tmp=-diff;
00256 cnt=0;
00257 lines++;
00258
00259
00260 } else {
00261
00262
00263 tab->removeEventFilter(this);
00264 tab->move(NEARBYINT(tmp-tab->neededSize()),lines*24);
00265 tab->setFixedWidth(NEARBYINT(tmp+diff)-tab->x());;
00266
00267
00268 tab->installEventFilter(this);
00269
00270 }
00271 }
00272 }
00273 else {
00274 setFixedWidth(lines*24);
00275 box->setFixedWidth(lines*24);
00276 m_lines=lines=width()/24;
00277 lines=0;
00278 CALCDIFF(m_tabs,diff,0)
00279 tmp=-diff;
00280
00281 for (uint i=0;i<tabCount;i++) {
00282 KMultiTabBarTab *tab=m_tabs.at(i);
00283 cnt++;
00284 tmp+=tab->neededSize()+diff;
00285 if (tmp>space) {
00286 if (cnt>1) {
00287 CALCDIFF(m_tabs,diff,i);
00288 tmp=-diff;
00289 i--;
00290 }
00291 else {
00292 tab->removeEventFilter(this);
00293 tab->move(lines*24,NEARBYINT(tmp-tab->neededSize()));
00294 tab->setFixedHeight(NEARBYINT(tmp+diff)-tab->y());;
00295 tab->installEventFilter(this);
00296 }
00297 cnt=0;
00298 tmp=-diff;
00299 lines++;
00300 } else {
00301 tab->removeEventFilter(this);
00302 tab->move(lines*24,NEARBYINT(tmp-tab->neededSize()));
00303 tab->setFixedHeight(NEARBYINT(tmp+diff)-tab->y());;
00304 tab->installEventFilter(this);
00305 }
00306 }
00307 }
00308
00309
00310
00311 } else {
00312 int size=0;
00313 for (int i=0;i<(int)m_tabs.count();i++)
00314 size+=(m_barMode==KMultiTabBar::Vertical?m_tabs.at(i)->height():m_tabs.at(i)->width());
00315 if ((m_position==KMultiTabBar::Bottom) || (m_position==KMultiTabBar::Top))
00316 box->setGeometry(0,0,size,height());
00317 else box->setGeometry(0,0,width(),size);
00318
00319 }
00320 }
00321
00322
00323 void KMultiTabBarInternal::showActiveTabTexts(bool show)
00324 {
00325 m_showActiveTabTexts=show;
00326 }
00327
00328
00329 KMultiTabBarTab* KMultiTabBarInternal::tab(int id) const
00330 {
00331 for (QPtrListIterator<KMultiTabBarTab> it(m_tabs);it.current();++it){
00332 if (it.current()->id()==id) return it.current();
00333 }
00334 return 0;
00335 }
00336
00337 bool KMultiTabBarInternal::eventFilter(QObject *, QEvent *e) {
00338 if (e->type()==QEvent::Resize) resizeEvent(0);
00339 return false;
00340 }
00341
00342 int KMultiTabBarInternal::appendTab(const QPixmap &pic ,int id,const QString& text)
00343 {
00344 KMultiTabBarTab *tab;
00345 m_tabs.append(tab= new KMultiTabBarTab(pic,text,id,box,m_position,m_style));
00346 tab->installEventFilter(this);
00347 tab->showActiveTabText(m_showActiveTabTexts);
00348
00349 if (m_style==KMultiTabBar::KONQSBC)
00350 {
00351 if (m_expandedTabSize<tab->neededSize()) {
00352 m_expandedTabSize=tab->neededSize();
00353 for (uint i=0;i<m_tabs.count();i++)
00354 m_tabs.at(i)->setSize(m_expandedTabSize);
00355
00356 } else tab->setSize(m_expandedTabSize);
00357 } else tab->updateState();
00358 tab->show();
00359 resizeEvent(0);
00360 return 0;
00361 }
00362
00363 void KMultiTabBarInternal::removeTab(int id)
00364 {
00365 for (uint pos=0;pos<m_tabs.count();pos++)
00366 {
00367 if (m_tabs.at(pos)->id()==id)
00368 {
00369 m_tabs.remove(pos);
00370 resizeEvent(0);
00371 break;
00372 }
00373 }
00374 }
00375
00376 void KMultiTabBarInternal::setPosition(enum KMultiTabBar::KMultiTabBarPosition pos)
00377 {
00378 m_position=pos;
00379 for (uint i=0;i<m_tabs.count();i++)
00380 m_tabs.at(i)->setTabsPosition(m_position);
00381 viewport()->repaint();
00382 }
00383
00384 KMultiTabBarButton::KMultiTabBarButton(const QPixmap& pic,const QString& text, QPopupMenu *popup,
00385 int id,QWidget *parent,KMultiTabBar::KMultiTabBarPosition pos,KMultiTabBar::KMultiTabBarStyle style)
00386 :QPushButton(QIconSet(),text,parent),m_style(style)
00387 {
00388 setIconSet(pic);
00389 setText(text);
00390 m_position=pos;
00391 if (popup) setPopup(popup);
00392 setFlat(true);
00393 setFixedHeight(24);
00394 setFixedWidth(24);
00395 m_id=id;
00396 QToolTip::add(this,text);
00397 connect(this,SIGNAL(clicked()),this,SLOT(slotClicked()));
00398 }
00399
00400 KMultiTabBarButton::KMultiTabBarButton(const QString& text, QPopupMenu *popup,
00401 int id,QWidget *parent,KMultiTabBar::KMultiTabBarPosition pos,KMultiTabBar::KMultiTabBarStyle style)
00402 :QPushButton(QIconSet(),text,parent),m_style(style)
00403 {
00404 setText(text);
00405 m_position=pos;
00406 if (popup) setPopup(popup);
00407 setFlat(true);
00408 setFixedHeight(24);
00409 setFixedWidth(24);
00410 m_id=id;
00411 QToolTip::add(this,text);
00412 connect(this,SIGNAL(clicked()),this,SLOT(slotClicked()));
00413 }
00414
00415 KMultiTabBarButton::~KMultiTabBarButton() {
00416 }
00417
00418 int KMultiTabBarButton::id() const{
00419 return m_id;
00420 }
00421
00422 void KMultiTabBarButton::setText(const QString& text)
00423 {
00424 QPushButton::setText(text);
00425 m_text=text;
00426 QToolTip::add(this,text);
00427 }
00428
00429 void KMultiTabBarButton::slotClicked()
00430 {
00431 emit clicked(m_id);
00432 }
00433
00434 void KMultiTabBarButton::setPosition(KMultiTabBar::KMultiTabBarPosition pos)
00435 {
00436 m_position=pos;
00437 repaint();
00438 }
00439
00440 void KMultiTabBarButton::setStyle(KMultiTabBar::KMultiTabBarStyle style)
00441 {
00442 m_style=style;
00443 repaint();
00444 }
00445
00446 void KMultiTabBarButton::hideEvent( QHideEvent* he) {
00447 QPushButton::hideEvent(he);
00448 KMultiTabBar *tb=dynamic_cast<KMultiTabBar*>(parentWidget());
00449 if (tb) tb->updateSeparator();
00450 }
00451
00452 void KMultiTabBarButton::showEvent( QShowEvent* he) {
00453 QPushButton::showEvent(he);
00454 KMultiTabBar *tb=dynamic_cast<KMultiTabBar*>(parentWidget());
00455 if (tb) tb->updateSeparator();
00456 }
00457
00458
00459 QSize KMultiTabBarButton::sizeHint() const
00460 {
00461 constPolish();
00462
00463 int w = 0, h = 0;
00464
00465
00466 #ifndef QT_NO_ICONSET
00467 if ( iconSet() && !iconSet()->isNull() ) {
00468 int iw = iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width() + 4;
00469 int ih = iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height();
00470 w += iw;
00471 h = QMAX( h, ih );
00472 }
00473 #endif
00474 if ( isMenuButton() )
00475 w += style().pixelMetric(QStyle::PM_MenuButtonIndicator, this);
00476
00477 if ( pixmap() ) {
00478 QPixmap *pm = (QPixmap *)pixmap();
00479 w += pm->width();
00480 h += pm->height();
00481 } else {
00482 QString s( text() );
00483 bool empty = s.isEmpty();
00484 if ( empty )
00485 s = QString::fromLatin1("XXXX");
00486 QFontMetrics fm = fontMetrics();
00487 QSize sz = fm.size( ShowPrefix, s );
00488 if(!empty || !w)
00489 w += sz.width();
00490 if(!empty || !h)
00491 h = QMAX(h, sz.height());
00492 }
00493
00494 return (style().sizeFromContents(QStyle::CT_ToolButton, this, QSize(w, h)).
00495 expandedTo(QApplication::globalStrut()));
00496 }
00497
00498
00499 KMultiTabBarTab::KMultiTabBarTab(const QPixmap& pic, const QString& text,
00500 int id,QWidget *parent,KMultiTabBar::KMultiTabBarPosition pos,
00501 KMultiTabBar::KMultiTabBarStyle style)
00502 :KMultiTabBarButton(text,0,id,parent,pos,style),
00503 m_showActiveTabText(false)
00504 {
00505 d=new KMultiTabBarTabPrivate();
00506 setIcon(pic);
00507 m_expandedSize=24;
00508 setToggleButton(true);
00509 }
00510
00511 KMultiTabBarTab::~KMultiTabBarTab() {
00512 delete d;
00513 }
00514
00515
00516 void KMultiTabBarTab::setTabsPosition(KMultiTabBar::KMultiTabBarPosition pos)
00517 {
00518 if ((pos!=m_position) && ((pos==KMultiTabBar::Left) || (pos==KMultiTabBar::Right))) {
00519 if (!d->pix.isNull()) {
00520 QWMatrix temp;
00521 temp.rotate(180);
00522 d->pix=d->pix.xForm(temp);
00523 setIconSet(d->pix);
00524 }
00525 }
00526
00527 setPosition(pos);
00528
00529 }
00530
00531 void KMultiTabBarTab::setIcon(const QString& icon)
00532 {
00533 QPixmap pic=SmallIcon(icon);
00534 setIcon(pic);
00535 }
00536
00537 void KMultiTabBarTab::setIcon(const QPixmap& icon)
00538 {
00539
00540 if (m_style!=KMultiTabBar::KDEV3) {
00541 if ((m_position==KMultiTabBar::Left) || (m_position==KMultiTabBar::Right)) {
00542 QWMatrix rotateMatrix;
00543 if (m_position==KMultiTabBar::Left)
00544 rotateMatrix.rotate(90);
00545 else
00546 rotateMatrix.rotate(-90);
00547 QPixmap pic=icon.xForm(rotateMatrix);
00548 d->pix=pic;
00549 setIconSet(pic);
00550 } else setIconSet(icon);
00551 }
00552 }
00553
00554 void KMultiTabBarTab::slotClicked()
00555 {
00556 updateState();
00557 KMultiTabBarButton::slotClicked();
00558 }
00559
00560 void KMultiTabBarTab::setState(bool b)
00561 {
00562 setOn(b);
00563 updateState();
00564 }
00565
00566 void KMultiTabBarTab::updateState()
00567 {
00568
00569 if (m_style!=KMultiTabBar::KONQSBC) {
00570 if ((m_style==KMultiTabBar::KDEV3) || (m_style==KMultiTabBar::KDEV3ICON) || (isOn())) {
00571 QPushButton::setText(m_text);
00572 } else {
00573 kdDebug()<<"KMultiTabBarTab::updateState(): setting text to an empty QString***************"<<endl;
00574 QPushButton::setText(QString::null);
00575 }
00576
00577 if ((m_position==KMultiTabBar::Right || m_position==KMultiTabBar::Left)) {
00578 setFixedWidth(24);
00579 if ((m_style==KMultiTabBar::KDEV3) || (m_style==KMultiTabBar::KDEV3ICON) || (isOn())) {
00580 setFixedHeight(KMultiTabBarButton::sizeHint().width());
00581 } else setFixedHeight(36);
00582 } else {
00583 setFixedHeight(24);
00584 if ((m_style==KMultiTabBar::KDEV3) || (m_style==KMultiTabBar::KDEV3ICON) || (isOn())) {
00585 setFixedWidth(KMultiTabBarButton::sizeHint().width());
00586 } else setFixedWidth(36);
00587 }
00588 } else {
00589 if ((!isOn()) || (!m_showActiveTabText))
00590 {
00591 setFixedWidth(24);
00592 setFixedHeight(24);
00593 return;
00594 }
00595 if ((m_position==KMultiTabBar::Right || m_position==KMultiTabBar::Left))
00596 setFixedHeight(m_expandedSize);
00597 else
00598 setFixedWidth(m_expandedSize);
00599 }
00600 QApplication::sendPostedEvents(0,QEvent::Paint | QEvent::Move | QEvent::Resize | QEvent::LayoutHint);
00601 QApplication::flush();
00602 }
00603
00604 int KMultiTabBarTab::neededSize()
00605 {
00606 return (((m_style!=KMultiTabBar::KDEV3)?24:0)+QFontMetrics(QFont()).width(m_text)+6);
00607 }
00608
00609 void KMultiTabBarTab::setSize(int size)
00610 {
00611 m_expandedSize=size;
00612 updateState();
00613 }
00614
00615 void KMultiTabBarTab::showActiveTabText(bool show)
00616 {
00617 m_showActiveTabText=show;
00618 }
00619
00620 void KMultiTabBarTab::drawButtonLabel(QPainter *p) {
00621 drawButton(p);
00622 }
00623 void KMultiTabBarTab::drawButton(QPainter *paint)
00624 {
00625 if (m_style!=KMultiTabBar::KONQSBC) drawButtonStyled(paint);
00626 else drawButtonClassic(paint);
00627 }
00628
00629 void KMultiTabBarTab::drawButtonStyled(QPainter *paint) {
00630
00631 QSize sh;
00632 const int width = 36;
00633 const int height = 24;
00634 if ((m_style==KMultiTabBar::KDEV3) || (m_style==KMultiTabBar::KDEV3ICON) || (isOn())) {
00635 if ((m_position==KMultiTabBar::Left) || (m_position==KMultiTabBar::Right))
00636 sh=QSize(this->height(),this->width());
00637 else sh=QSize(this->width(),this->height());
00638 }
00639 else
00640 sh=QSize(width,height);
00641
00642 QPixmap pixmap( sh.width(),height);
00643 pixmap.fill(eraseColor());
00644 QPainter painter(&pixmap);
00645
00646
00647 QStyle::SFlags st=QStyle::Style_Default;
00648
00649 st|=QStyle::Style_Enabled;
00650
00651 if (isOn()) st|=QStyle::Style_On;
00652
00653 style().drawControl(QStyle::CE_PushButton,&painter,this, QRect(0,0,pixmap.width(),pixmap.height()), colorGroup(),st);
00654 style().drawControl(QStyle::CE_PushButtonLabel,&painter,this, QRect(0,0,pixmap.width(),pixmap.height()), colorGroup(),st);
00655
00656 switch (m_position) {
00657 case KMultiTabBar::Left:
00658 paint->rotate(-90);
00659 paint->drawPixmap(1-pixmap.width(),0,pixmap);
00660 break;
00661 case KMultiTabBar::Right:
00662 paint->rotate(90);
00663 paint->drawPixmap(0,1-pixmap.height(),pixmap);
00664 break;
00665
00666 default:
00667 paint->drawPixmap(0,0,pixmap);
00668 break;
00669 }
00670
00671
00672
00673
00674 }
00675
00676 void KMultiTabBarTab::drawButtonClassic(QPainter *paint)
00677 {
00678 QPixmap pixmap;
00679 if ( iconSet())
00680 pixmap = iconSet()->pixmap( QIconSet::Small, QIconSet::Normal );
00681 paint->fillRect(0, 0, 24, 24, colorGroup().background());
00682
00683 if (!isOn())
00684 {
00685
00686 if (m_position==KMultiTabBar::Right)
00687 {
00688 paint->fillRect(0,0,21,21,QBrush(colorGroup().background()));
00689
00690 paint->setPen(colorGroup().background().dark(150));
00691 paint->drawLine(0,22,23,22);
00692
00693 paint->drawPixmap(12-pixmap.width()/2,12-pixmap.height()/2,pixmap);
00694
00695 paint->setPen(colorGroup().shadow());
00696 paint->drawLine(0,0,0,23);
00697 paint->setPen(colorGroup().background().dark(120));
00698 paint->drawLine(1,0,1,23);
00699
00700 }
00701 else
00702 if ((m_position==KMultiTabBar::Bottom) || (m_position==KMultiTabBar::Top))
00703 {
00704 paint->fillRect(0,1,23,22,QBrush(colorGroup().background()));
00705
00706 paint->drawPixmap(12-pixmap.width()/2,12-pixmap.height()/2,pixmap);
00707
00708 paint->setPen(colorGroup().background().dark(120));
00709 paint->drawLine(23,0,23,23);
00710
00711
00712 paint->setPen(colorGroup().light());
00713 paint->drawLine(0,22,23,22);
00714 paint->drawLine(0,23,23,23);
00715 paint->setPen(colorGroup().shadow());
00716 paint->drawLine(0,0,23,0);
00717 paint->setPen(colorGroup().background().dark(120));
00718 paint->drawLine(0,1,23,1);
00719
00720 }
00721 else
00722 {
00723 paint->setPen(colorGroup().background().dark(120));
00724 paint->drawLine(0,23,23,23);
00725 paint->fillRect(0,0,23,21,QBrush(colorGroup().background()));
00726 paint->drawPixmap(12-pixmap.width()/2,12-pixmap.height()/2,pixmap);
00727
00728 paint->setPen(colorGroup().light());
00729 paint->drawLine(23,0,23,23);
00730 paint->drawLine(22,0,22,23);
00731
00732 paint->setPen(colorGroup().shadow());
00733 paint->drawLine(0,0,0,23);
00734
00735 }
00736
00737
00738 }
00739 else
00740 {
00741 if (m_position==KMultiTabBar::Right)
00742 {
00743 paint->setPen(colorGroup().shadow());
00744 paint->drawLine(0,height()-1,23,height()-1);
00745 paint->drawLine(0,height()-2,23,height()-2);
00746 paint->drawLine(23,0,23,height()-1);
00747 paint->drawLine(22,0,22,height()-1);
00748 paint->fillRect(0,0,21,height()-3,QBrush(colorGroup().light()));
00749 paint->drawPixmap(10-pixmap.width()/2,10-pixmap.height()/2,pixmap);
00750
00751 if (m_showActiveTabText)
00752 {
00753 if (height()<25+4) return;
00754
00755 QPixmap tpixmap(height()-25-3, width()-2);
00756 QPainter painter(&tpixmap);
00757
00758 painter.fillRect(0,0,tpixmap.width(),tpixmap.height(),QBrush(colorGroup().light()));
00759
00760 painter.setPen(colorGroup().text());
00761 painter.drawText(0,+width()/2+QFontMetrics(QFont()).height()/2,m_text);
00762
00763 paint->rotate(90);
00764 kdDebug()<<"tpixmap.width:"<<tpixmap.width()<<endl;
00765 paint->drawPixmap(25,-tpixmap.height()+1,tpixmap);
00766 }
00767
00768 }
00769 else
00770 if (m_position==KMultiTabBar::Top)
00771 {
00772 paint->fillRect(0,0,width()-1,23,QBrush(colorGroup().light()));
00773 paint->drawPixmap(10-pixmap.width()/2,10-pixmap.height()/2,pixmap);
00774 if (m_showActiveTabText)
00775 {
00776 paint->setPen(colorGroup().text());
00777 paint->drawText(25,height()/2+QFontMetrics(QFont()).height()/2,m_text);
00778 }
00779 }
00780 else
00781 if (m_position==KMultiTabBar::Bottom)
00782 {
00783 paint->setPen(colorGroup().shadow());
00784 paint->drawLine(0,23,width()-1,23);
00785 paint->drawLine(0,22,width()-1,22);
00786 paint->fillRect(0,0,width()-1,21,QBrush(colorGroup().light()));
00787 paint->drawPixmap(10-pixmap.width()/2,10-pixmap.height()/2,pixmap);
00788 if (m_showActiveTabText)
00789 {
00790 paint->setPen(colorGroup().text());
00791 paint->drawText(25,height()/2+QFontMetrics(QFont()).height()/2,m_text);
00792 }
00793
00794 }
00795 else
00796 {
00797
00798
00799 paint->setPen(colorGroup().shadow());
00800 paint->drawLine(0,height()-1,23,height()-1);
00801 paint->drawLine(0,height()-2,23,height()-2);
00802 paint->fillRect(0,0,23,height()-3,QBrush(colorGroup().light()));
00803 paint->drawPixmap(10-pixmap.width()/2,10-pixmap.height()/2,pixmap);
00804 if (m_showActiveTabText)
00805 {
00806
00807 if (height()<25+4) return;
00808
00809 QPixmap tpixmap(height()-25-3, width()-2);
00810 QPainter painter(&tpixmap);
00811
00812 painter.fillRect(0,0,tpixmap.width(),tpixmap.height(),QBrush(colorGroup().light()));
00813
00814 painter.setPen(colorGroup().text());
00815 painter.drawText(tpixmap.width()-QFontMetrics(QFont()).width(m_text),+width()/2+QFontMetrics(QFont()).height()/2,m_text);
00816
00817 paint->rotate(-90);
00818 kdDebug()<<"tpixmap.width:"<<tpixmap.width()<<endl;
00819
00820 paint->drawPixmap(-24-tpixmap.width(),2,tpixmap);
00821
00822 }
00823
00824 }
00825
00826 }
00827 }
00828
00829
00830
00831
00832
00833
00834
00835 KMultiTabBar::KMultiTabBar(KMultiTabBarMode bm, QWidget *parent,const char *name):QWidget(parent,name)
00836 {
00837 m_buttons.setAutoDelete(false);
00838 if (bm==Vertical)
00839 {
00840 m_l=new QVBoxLayout(this);
00841 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding, true);
00842
00843 }
00844 else
00845 {
00846 m_l=new QHBoxLayout(this);
00847 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed, true);
00848
00849 }
00850 m_l->setMargin(0);
00851 m_l->setAutoAdd(false);
00852
00853 m_internal=new KMultiTabBarInternal(this,bm);
00854 setPosition((bm==KMultiTabBar::Vertical)?KMultiTabBar::Right:KMultiTabBar::Bottom);
00855 setStyle(VSNET);
00856
00857
00858 m_l->insertWidget(0,m_internal);
00859 m_l->insertWidget(0,m_btnTabSep=new QFrame(this));
00860 m_btnTabSep->setFixedHeight(4);
00861 m_btnTabSep->setFrameStyle(QFrame::Panel | QFrame::Sunken);
00862 m_btnTabSep->setLineWidth(2);
00863 m_btnTabSep->hide();
00864
00865 updateGeometry();
00866 }
00867
00868 KMultiTabBar::~KMultiTabBar() {
00869 }
00870
00871
00872
00873
00874
00875
00876
00877 int KMultiTabBar::appendButton(const QPixmap &pic ,int id,QPopupMenu *popup,const QString&)
00878 {
00879 KMultiTabBarButton *btn;
00880 m_buttons.append(btn= new KMultiTabBarButton(pic,QString::null,
00881 popup,id,this,m_position,m_internal->m_style));
00882 m_l->insertWidget(0,btn);
00883 btn->show();
00884 m_btnTabSep->show();
00885 return 0;
00886 }
00887
00888 void KMultiTabBar::updateSeparator() {
00889 bool hideSep=true;
00890 for (QPtrListIterator<KMultiTabBarButton> it(m_buttons);it.current();++it){
00891 if (it.current()->isVisibleTo(this)) {
00892 hideSep=false;
00893 break;
00894 }
00895 }
00896 if (hideSep) m_btnTabSep->hide();
00897 else m_btnTabSep->show();
00898
00899 }
00900
00901 int KMultiTabBar::appendTab(const QPixmap &pic ,int id ,const QString& text)
00902 {
00903 m_internal->appendTab(pic,id,text);
00904 return 0;
00905 }
00906
00907 KMultiTabBarButton* KMultiTabBar::button(int id) const
00908 {
00909 for (QPtrListIterator<KMultiTabBarButton> it(m_buttons);it.current();++it){
00910 if (it.current()->id()==id) return it.current();
00911 }
00912 return 0;
00913 }
00914
00915 KMultiTabBarTab* KMultiTabBar::tab(int id) const
00916 {
00917 return m_internal->tab(id);
00918 }
00919
00920
00921
00922 void KMultiTabBar::removeButton(int id)
00923 {
00924 for (uint pos=0;pos<m_buttons.count();pos++)
00925 {
00926 if (m_buttons.at(pos)->id()==id)
00927 {
00928 m_buttons.take(pos)->deleteLater();
00929 break;
00930 }
00931 }
00932 if (m_buttons.count()==0) m_btnTabSep->hide();
00933 }
00934
00935 void KMultiTabBar::removeTab(int id)
00936 {
00937 m_internal->removeTab(id);
00938 }
00939
00940 void KMultiTabBar::setTab(int id,bool state)
00941 {
00942 KMultiTabBarTab *ttab=tab(id);
00943 if (ttab)
00944 {
00945 ttab->setState(state);
00946 }
00947 }
00948
00949 bool KMultiTabBar::isTabRaised(int id) const
00950 {
00951 KMultiTabBarTab *ttab=tab(id);
00952 if (ttab)
00953 {
00954 return ttab->isOn();
00955 }
00956
00957 return false;
00958 }
00959
00960
00961 void KMultiTabBar::showActiveTabTexts(bool show)
00962 {
00963 m_internal->showActiveTabTexts(show);
00964 }
00965
00966 void KMultiTabBar::setStyle(KMultiTabBarStyle style)
00967 {
00968 m_internal->setStyle(style);
00969 }
00970
00971 KMultiTabBar::KMultiTabBarStyle KMultiTabBar::tabStyle() const
00972 {
00973 return m_internal->m_style;
00974 }
00975
00976 void KMultiTabBar::setPosition(KMultiTabBarPosition pos)
00977 {
00978 m_position=pos;
00979 m_internal->setPosition(pos);
00980 for (uint i=0;i<m_buttons.count();i++)
00981 m_buttons.at(i)->setPosition(pos);
00982 }
00983
00984 KMultiTabBar::KMultiTabBarPosition KMultiTabBar::position() const
00985 {
00986 return m_position;
00987 }
00988 void KMultiTabBar::fontChange(const QFont& )
00989 {
00990 for (uint i=0;i<tabs()->count();i++)
00991 tabs()->at(i)->resize();
00992 repaint();
00993 }
00994
00995 QPtrList<KMultiTabBarTab>* KMultiTabBar::tabs() {return m_internal->tabs();}
00996 QPtrList<KMultiTabBarButton>* KMultiTabBar::buttons() {return &m_buttons;}
00997