# kdeui Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# ktoolbarbutton.cpp

    00001 /* This file is part of the KDE libraries
    00002     Copyright (C) 1997, 1998 Stephan Kulow (coolo@kde.org)
    00003               (C) 1997, 1998 Mark Donohoe (donohoe@kde.org)
    00004               (C) 1997, 1998 Sven Radej (radej@kde.org)
    00005               (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org)
    00006               (C) 1999 Chris Schlaeger (cs@kde.org)
    00007               (C) 1999 Kurt Granroth (granroth@kde.org)
    00008
    00009     This library is free software; you can redistribute it and/or
    00010     modify it under the terms of the GNU Library General Public
    00011     License version 2 as published by the Free Software Foundation.
    00012
    00013     This library is distributed in the hope that it will be useful,
    00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00016     Library General Public License for more details.
    00017
    00018     You should have received a copy of the GNU Library General Public License
    00019     along with this library; see the file COPYING.LIB.  If not, write to
    00020     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00021     Boston, MA 02111-1307, USA.
    00022 */
    00023
    00024 #include <config.h>
    00025 #include <string.h>
    00026
    00027 #include "ktoolbarbutton.h"
    00028 #include "ktoolbar.h"
    00029
    00030 #include <qstyle.h>
    00031 #include <qimage.h>
    00032 #include <qtimer.h>
    00033 #include <qdrawutil.h>
    00034 #include <qtooltip.h>
    00035 #include <qbitmap.h>
    00036 #include <qpopupmenu.h>
    00037 #include <qcursor.h>
    00038 #include <qpainter.h>
    00039 #include <qlayout.h>
    00040
    00041 #include <kapplication.h>
    00042 #include <kdebug.h>
    00043 #include <kglobal.h>
    00044 #include <kglobalsettings.h>
    00045 #include <kiconeffect.h>
    00046 #include <kiconloader.h>
    00047
    00048 // needed to get our instance
    00049 #include <kmainwindow.h>
    00050
    00051 template class QIntDict<KToolBarButton>;
    00052
    00053 class KToolBarButtonPrivate
    00054 {
    00055 public:
    00056   KToolBarButtonPrivate()
    00057   {
    00058     m_noStyle     = false;
    00059     m_isSeparator = false;
    00060     m_isPopup     = false;
    00061     m_isToggle    = false;
    00062     m_isRadio     = false;
    00063     m_highlight   = false;
    00064     m_isRaised    = false;
    00065     m_isActive    = false;
    00066
    00067     m_iconName    = QString::null;
    00068     m_iconText    = KToolBar::IconOnly;
    00069     m_iconSize    = 0;
    00070     m_delayTimer  = 0L;
    00071     m_popup       = 0L;
    00072
    00073     m_instance = KGlobal::instance();
    00074   }
    00075   ~KToolBarButtonPrivate()
    00076   {
    00077     delete m_delayTimer; m_delayTimer = 0;
    00078   }
    00079
    00080   int     m_id;
    00081   bool    m_noStyle: 1;
    00082   bool    m_isSeparator: 1;
    00083   bool    m_isPopup: 1;
    00084   bool    m_isToggle: 1;
    00085   bool    m_isRadio: 1;
    00086   bool    m_highlight: 1;
    00087   bool    m_isRaised: 1;
    00088   bool    m_isActive: 1;
    00089
    00090   QString m_iconName;
    00091
    00092   KToolBar *m_parent;
    00093   KToolBar::IconText m_iconText;
    00094   int m_iconSize;
    00095   QSize size;
    00096
    00097   QTimer     *m_delayTimer;
    00098   QPopupMenu *m_popup;
    00099
    00100   QPoint m_mousePressPos;
    00101
    00102   KInstance  *m_instance;
    00103 };
    00104
    00105 // This will construct a separator
    00106 KToolBarButton::KToolBarButton( QWidget *_parent, const char *_name )
    00107   : QToolButton( _parent , _name)
    00108 {
    00109   d = new KToolBarButtonPrivate;
    00110
    00111   resize(6,6);
    00112   hide();
    00113   d->m_isSeparator = true;
    00114 }
    00115
    00116 KToolBarButton::KToolBarButton( const QString& _icon, int _id,
    00117                                 QWidget *_parent, const char *_name,
    00118                                 const QString &_txt, KInstance *_instance )
    00119     : QToolButton( _parent, _name ), d( 0 )
    00120 {
    00121   d = new KToolBarButtonPrivate;
    00122
    00123   d->m_id     = _id;
    00124   d->m_parent = (KToolBar*)_parent;
    00125   QToolButton::setTextLabel(_txt);
    00126   d->m_instance = _instance;
    00127
    00128   setFocusPolicy( NoFocus );
    00129
    00130   // connect all of our slots and start trapping events
    00131   connect(d->m_parent, SIGNAL( modechange() ),
    00132           this,         SLOT( modeChange() ));
    00133
    00134   connect(this, SIGNAL( clicked() ),
    00135           this, SLOT( slotClicked() ) );
    00136   connect(this, SIGNAL( pressed() ),
    00137           this, SLOT( slotPressed() ) );
    00138   connect(this, SIGNAL( released() ),
    00139           this, SLOT( slotReleased() ) );
    00140   installEventFilter(this);
    00141
    00142   d->m_iconName = _icon;
    00143
    00144   // do our initial setup
    00145   modeChange();
    00146 }
    00147
    00148 KToolBarButton::KToolBarButton( const QPixmap& pixmap, int _id,
    00149                                 QWidget *_parent, const char *name,
    00150                                 const QString& txt)
    00151     : QToolButton( _parent, name ), d( 0 )
    00152 {
    00153   d = new KToolBarButtonPrivate;
    00154
    00155   d->m_id       = _id;
    00156   d->m_parent   = (KToolBar *) _parent;
    00157   QToolButton::setTextLabel(txt);
    00158
    00159   setFocusPolicy( NoFocus );
    00160
    00161   // connect all of our slots and start trapping events
    00162   connect(d->m_parent, SIGNAL( modechange()),
    00163           this,        SLOT(modeChange()));
    00164
    00165   connect(this, SIGNAL( clicked() ),
    00166           this, SLOT( slotClicked() ));
    00167   connect(this, SIGNAL( pressed() ),
    00168           this, SLOT( slotPressed() ));
    00169   connect(this, SIGNAL( released() ),
    00170           this, SLOT( slotReleased() ));
    00171   installEventFilter(this);
    00172
    00173   // set our pixmap and do our initial setup
    00174   setIconSet( QIconSet( pixmap ));
    00175   modeChange();
    00176 }
    00177
    00178 KToolBarButton::~KToolBarButton()
    00179 {
    00180   delete d; d = 0;
    00181 }
    00182
    00183 void KToolBarButton::modeChange()
    00184 {
    00185   QSize mysize;
    00186
    00187   // grab a few global variables for use in this function and others
    00188   d->m_highlight = d->m_parent->highlight();
    00189   d->m_iconText  = d->m_parent->iconText();
    00190
    00191   d->m_iconSize = d->m_parent->iconSize();
    00192   if (!d->m_iconName.isNull())
    00193     setIcon(d->m_iconName);
    00194
    00195   // we'll start with the size of our pixmap
    00196   int pix_width  = d->m_iconSize;
    00197   if ( d->m_iconSize == 0 ) {
    00198       if (!strcmp(d->m_parent->name(), "mainToolBar"))
    00199           pix_width = IconSize( KIcon::MainToolbar );
    00200       else
    00201           pix_width = IconSize( KIcon::Toolbar );
    00202   }
    00203   int pix_height = pix_width;
    00204
    00205   int text_height = 0;
    00206   int text_width = 0;
    00207
    00208   QToolTip::remove(this);
    00209   if (d->m_iconText != KToolBar::IconOnly)
    00210   {
    00211     // okay, we have to deal with fonts.  let's get our information now
    00212     QFont tmp_font = KGlobalSettings::toolBarFont();
    00213
    00214     // now parse out our font sizes from our chosen font
    00215     QFontMetrics fm(tmp_font);
    00216
    00217     text_height = fm.lineSpacing();
    00218     text_width  = fm.width(textLabel());
    00219
    00220     // none of the other modes want tooltips
    00221   }
    00222   else
    00223   {
    00224     QToolTip::add(this, textLabel());
    00225   }
    00226
    00227   switch (d->m_iconText)
    00228   {
    00229   case KToolBar::IconOnly:
    00230     mysize = QSize(pix_width, pix_height);
    00231     break;
    00232
    00233   case KToolBar::IconTextRight:
    00234     mysize = QSize(pix_width + text_width + 4, pix_height);
    00235     break;
    00236
    00237   case KToolBar::TextOnly:
    00238     mysize = QSize(text_width + 4, text_height);
    00239     break;
    00240
    00241   case KToolBar::IconTextBottom:
    00242     mysize = QSize((text_width + 4 > pix_width) ? text_width + 4 : pix_width, pix_height + text_height);
    00243     break;
    00244
    00245   default:
    00246     break;
    00247   }
    00248
    00249   mysize = style().sizeFromContents(QStyle::CT_ToolButton, this, mysize).
    00250                expandedTo(QApplication::globalStrut());
    00251
    00252   // make sure that this isn't taller then it is wide
    00253   if (mysize.height() > mysize.width())
    00254     mysize.setWidth(mysize.height());
    00255
    00256   d->size = mysize;
    00257   updateGeometry();
    00258 }
    00259
    00260 void KToolBarButton::setTextLabel( const QString& text, bool tipToo)
    00261 {
    00262   if (text.isNull())
    00263     return;
    00264
    00265   QString txt(text);
    00266   if (txt.right(3) == QString::fromLatin1("..."))
    00267     txt.truncate(txt.length() - 3);
    00268
    00269   QToolButton::setTextLabel(txt, tipToo);
    00270   update();
    00271 }
    00272
    00273 void KToolBarButton::setText( const QString& text)
    00274 {
    00275   setTextLabel(text, true);
    00276   modeChange();
    00277 }
    00278
    00279 void KToolBarButton::setIcon( const QString &icon )
    00280 {
    00281   d->m_iconName = icon;
    00282   d->m_iconSize = d->m_parent->iconSize();
    00283   // QObject::name() return "const char *" instead of QString.
    00284   if (!strcmp(d->m_parent->name(), "mainToolBar"))
    00285     QToolButton::setIconSet( d->m_instance->iconLoader()->loadIconSet(
    00286         d->m_iconName, KIcon::MainToolbar, d->m_iconSize ));
    00287   else
    00288     QToolButton::setIconSet( d->m_instance->iconLoader()->loadIconSet(
    00289         d->m_iconName, KIcon::Toolbar, d->m_iconSize ));
    00290 }
    00291
    00292 void KToolBarButton::setIconSet( const QIconSet &iconset )
    00293 {
    00294   QToolButton::setIconSet( iconset );
    00295 }
    00296
    00297 // remove?
    00298 void KToolBarButton::setPixmap( const QPixmap &pixmap )
    00299 {
    00300   if( pixmap.isNull()) // called by QToolButton
    00301   {
    00302     QToolButton::setPixmap( pixmap );
    00303     return;
    00304   }
    00305   QIconSet set = iconSet();
    00306   set.setPixmap( pixmap, QIconSet::Automatic, QIconSet::Active );
    00307   QToolButton::setIconSet( set );
    00308 }
    00309
    00310 void KToolBarButton::setDefaultPixmap( const QPixmap &pixmap )
    00311 {
    00312   QIconSet set = iconSet();
    00313   set.setPixmap( pixmap, QIconSet::Automatic, QIconSet::Normal );
    00314   QToolButton::setIconSet( set );
    00315 }
    00316
    00317 void KToolBarButton::setDisabledPixmap( const QPixmap &pixmap )
    00318 {
    00319   QIconSet set = iconSet();
    00320   set.setPixmap( pixmap, QIconSet::Automatic, QIconSet::Disabled );
    00321   QToolButton::setIconSet( set );
    00322 }
    00323
    00324 void KToolBarButton::setDefaultIcon( const QString& icon )
    00325 {
    00326   QIconSet set = iconSet();
    00327   QPixmap pm;
    00328   if (!strcmp(d->m_parent->name(), "mainToolBar"))
    00329     pm = d->m_instance->iconLoader()->loadIcon( icon, KIcon::MainToolbar,
    00330         d->m_iconSize );
    00331   else
    00332     pm = d->m_instance->iconLoader()->loadIcon( icon, KIcon::Toolbar,
    00333         d->m_iconSize );
    00334   set.setPixmap( pm, QIconSet::Automatic, QIconSet::Normal );
    00335   QToolButton::setIconSet( set );
    00336 }
    00337
    00338 void KToolBarButton::setDisabledIcon( const QString& icon )
    00339 {
    00340   QIconSet set = iconSet();
    00341   QPixmap pm;
    00342   if (!strcmp(d->m_parent->name(), "mainToolBar"))
    00343     pm = d->m_instance->iconLoader()->loadIcon( icon, KIcon::MainToolbar,
    00344         d->m_iconSize );
    00345   else
    00346     pm = d->m_instance->iconLoader()->loadIcon( icon, KIcon::Toolbar,
    00347         d->m_iconSize );
    00348   set.setPixmap( pm, QIconSet::Automatic, QIconSet::Disabled );
    00349   QToolButton::setIconSet( set );
    00350 }
    00351
    00352 void KToolBarButton::setPopup(QPopupMenu *p, bool toggle)
    00353 {
    00354   d->m_popup = p;
    00355   d->m_isToggle  = toggle;
    00356   p->installEventFilter(this);
    00357 }
    00358
    00359 QPopupMenu *KToolBarButton::popup()
    00360 {
    00361   return d->m_popup;
    00362 }
    00363
    00364 void KToolBarButton::setDelayedPopup (QPopupMenu *p, bool toggle )
    00365 {
    00366   d->m_isPopup   = true;
    00367
    00368   if (!d->m_delayTimer)
    00369   {
    00370     d->m_delayTimer = new QTimer(this);
    00371     connect(d->m_delayTimer, SIGNAL(timeout()),
    00372            this,             SLOT(slotDelayTimeout()));
    00373   }
    00374
    00375   setPopup(p, toggle);
    00376 }
    00377
    00378 void KToolBarButton::leaveEvent(QEvent *)
    00379 {
    00380   if( d->m_isRaised || d->m_isActive )
    00381   {
    00382     d->m_isRaised = false;
    00383     d->m_isActive = false;
    00384     repaint(false);
    00385   }
    00386
    00387   if (d->m_isPopup)
    00388     d->m_delayTimer->stop();
    00389
    00390   emit highlighted(d->m_id, false);
    00391 }
    00392
    00393 void KToolBarButton::enterEvent(QEvent *)
    00394 {
    00395   if (d->m_highlight)
    00396   {
    00397     if (isEnabled())
    00398     {
    00399       d->m_isActive = true;
    00400       if (!isToggleButton())
    00401         d->m_isRaised = true;
    00402     }
    00403     else
    00404     {
    00405       d->m_isRaised = false;
    00406       d->m_isActive = false;
    00407     }
    00408
    00409     repaint(false);
    00410   }
    00411   emit highlighted(d->m_id, true);
    00412 }
    00413
    00414 bool KToolBarButton::eventFilter(QObject *o, QEvent *ev)
    00415 {
    00416   if ((KToolBarButton *)o == this)
    00417   {
    00418     // From Kai-Uwe Sattler <kus@iti.CS.Uni-Magdeburg.De>
    00419     if (ev->type() == QEvent::MouseButtonDblClick)
    00420     {
    00421       emit doubleClicked(d->m_id);
    00422       return true;
    00423     }
    00424
    00425     if ((ev->type() == QEvent::MouseButtonPress ||
    00426          ev->type() == QEvent::MouseButtonRelease ||
    00427          ev->type() == QEvent::MouseButtonDblClick) && d->m_isRadio && isOn())
    00428       return true;
    00429
    00430     // Popup the menu when the left mousebutton is pressed and the mouse
    00431     // is moved by a small distance.
    00432     if (d->m_isPopup)
    00433     {
    00434       if (ev->type() == QEvent::MouseButtonPress)
    00435       {
    00436         QMouseEvent* mev = static_cast<QMouseEvent*>(ev);
    00437         d->m_mousePressPos = mev->pos();
    00438       }
    00439
    00440       if (ev->type() == QEvent::MouseMove)
    00441       {
    00442         QMouseEvent* mev = static_cast<QMouseEvent*>(ev);
    00443         if (d->m_delayTimer && d->m_delayTimer->isActive()
    00444          && (mev->pos() - d->m_mousePressPos).manhattanLength()
    00445               > KGlobalSettings::dndEventDelay())
    00446           slotDelayTimeout();
    00447       }
    00448     }
    00449   }
    00450
    00451   if ((QPopupMenu *) o != d->m_popup)
    00452     return false; // just in case
    00453
    00454   switch (ev->type())
    00455   {
    00456     case QEvent::MouseButtonDblClick:
    00457     case QEvent::MouseButtonPress:
    00458     {
    00459       // If I get this, it means that popup is visible
    00460       QRect r(geometry());
    00461       r.moveTopLeft(d->m_parent->mapToGlobal(pos()));
    00462       if (r.contains(QCursor::pos()))   // on button
    00463         return true; // ignore
    00464       break;
    00465     }
    00466
    00467     case QEvent::MouseButtonRelease:
    00468       if (!d->m_popup->geometry().contains(QCursor::pos())) // not in menu...
    00469       {
    00470         QRect r(geometry());
    00471         r.moveTopLeft(d->m_parent->mapToGlobal(pos()));
    00472
    00473         if (r.contains(QCursor::pos()))   // but on button
    00474         {
    00475           if( !isToggleButton() )
    00476             d->m_popup->hide();        //Sven: proposed by Carsten Pfeiffer
    00477           // Make the button normal again :) Dawit A.
    00478           if( d->m_isToggle )
    00479             setToggle( false );
    00480           emit clicked( d->m_id );
    00481           return true;  // ignore release
    00482         }
    00483       }
    00484       if ( d->m_isToggle )
    00485         setToggle( false );  //Change the button to normal mode (DA)
    00486       break;
    00487
    00488     case QEvent::Hide:
    00489       on(false);
    00490       setDown(false);
    00491       return false;
    00492   default:
    00493       break;
    00494   }
    00495   return false;
    00496 }
    00497
    00498 void KToolBarButton::drawButton( QPainter *_painter )
    00499 {
    00500   QStyle::SFlags flags   = QStyle::Style_Default;
    00501   QStyle::SCFlags active = QStyle::SC_None;
    00502
    00503   if (isDown()) {
    00504     flags  |= QStyle::Style_Down;
    00505     active |= QStyle::SC_ToolButton;
    00506   }
    00507   if (isEnabled())      flags |= QStyle::Style_Enabled;
    00508   if (isOn())           flags |= QStyle::Style_On;
    00509   if (isEnabled() && d->m_isRaised)     flags |= QStyle::Style_Raised;
    00510   if (hasFocus())       flags |= QStyle::Style_HasFocus;
    00511
    00512   // Draw a styled toolbutton
    00513   style().drawComplexControl(QStyle::CC_ToolButton, _painter, this, rect(),
    00514         colorGroup(), flags, QStyle::SC_ToolButton, active, QStyleOption());
    00515
    00516   int dx, dy;
    00517   QFont tmp_font(KGlobalSettings::toolBarFont());
    00518   QFontMetrics fm(tmp_font);
    00519   QRect textRect;
    00520   int textFlags = 0;
    00521
    00522   if (d->m_iconText == KToolBar::IconOnly) // icon only
    00523   {
    00524     QPixmap pixmap = iconSet().pixmap( QIconSet::Automatic,
    00525         isEnabled() ? (d->m_isActive ? QIconSet::Active : QIconSet::Normal) :
    00526                 QIconSet::Disabled,
    00527         isOn() ? QIconSet::On : QIconSet::Off );
    00528     if( !pixmap.isNull())
    00529     {
    00530       dx = ( width() - pixmap.width() ) / 2;
    00531       dy = ( height() - pixmap.height() ) / 2;
    00532       if ( isDown() && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle )
    00533       {
    00534         ++dx;
    00535         ++dy;
    00536       }
    00537       _painter->drawPixmap( dx, dy, pixmap );
    00538     }
    00539   }
    00540   else if (d->m_iconText == KToolBar::IconTextRight) // icon and text (if any)
    00541   {
    00542     QPixmap pixmap = iconSet().pixmap( QIconSet::Automatic,
    00543         isEnabled() ? (d->m_isActive ? QIconSet::Active : QIconSet::Normal) :
    00544                 QIconSet::Disabled,
    00545         isOn() ? QIconSet::On : QIconSet::Off );
    00546     if( !pixmap.isNull())
    00547     {
    00548       dx = 4;
    00549       dy = ( height() - pixmap.height() ) / 2;
    00550       if ( isDown() && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle )
    00551       {
    00552         ++dx;
    00553         ++dy;
    00554       }
    00555       _painter->drawPixmap( dx, dy, pixmap );
    00556     }
    00557
    00558     if (!textLabel().isNull())
    00559     {
    00560       textFlags = AlignVCenter|AlignLeft;
    00561       if (!pixmap.isNull())
    00562         dx = 4 + pixmap.width() + 2;
    00563       else
    00564         dx = 4;
    00565       dy = 0;
    00566       if ( isDown() && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle )
    00567       {
    00568         ++dx;
    00569         ++dy;
    00570       }
    00571       textRect = QRect(dx, dy, width()-dx, height());
    00572     }
    00573   }
    00574   else if (d->m_iconText == KToolBar::TextOnly)
    00575   {
    00576     if (!textLabel().isNull())
    00577     {
    00578       textFlags = AlignVCenter|AlignLeft;
    00579       dx = (width() - fm.width(textLabel())) / 2;
    00580       dy = (height() - fm.lineSpacing()) / 2;
    00581       if ( isDown() && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle )
    00582       {
    00583         ++dx;
    00584         ++dy;
    00585       }
    00586       textRect = QRect( dx, dy, fm.width(textLabel()), fm.lineSpacing() );
    00587     }
    00588   }
    00589   else if (d->m_iconText == KToolBar::IconTextBottom)
    00590   {
    00591     QPixmap pixmap = iconSet().pixmap( QIconSet::Automatic,
    00592         isEnabled() ? (d->m_isActive ? QIconSet::Active : QIconSet::Normal) :
    00593                 QIconSet::Disabled,
    00594         isOn() ? QIconSet::On : QIconSet::Off );
    00595     if( !pixmap.isNull())
    00596     {
    00597       dx = (width() - pixmap.width()) / 2;
    00598       dy = (height() - fm.lineSpacing() - pixmap.height()) / 2;
    00599       if ( isDown() && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle )
    00600       {
    00601         ++dx;
    00602         ++dy;
    00603       }
    00604       _painter->drawPixmap( dx, dy, pixmap );
    00605     }
    00606
    00607     if (!textLabel().isNull())
    00608     {
    00609       textFlags = AlignBottom|AlignHCenter;
    00610       dx = (width() - fm.width(textLabel())) / 2;
    00611       dy = height() - fm.lineSpacing() - 4;
    00612
    00613       if ( isDown() && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle )
    00614       {
    00615         ++dx;
    00616         ++dy;
    00617       }
    00618       textRect = QRect( dx, dy, fm.width(textLabel()), fm.lineSpacing() );
    00619     }
    00620   }
    00621
    00622   // Draw the text at the position given by textRect, and using textFlags
    00623   if (!textLabel().isNull() && !textRect.isNull())
    00624   {
    00625       _painter->setFont(KGlobalSettings::toolBarFont());
    00626       if (!isEnabled())
    00627         _painter->setPen(palette().disabled().dark());
    00628       else if(d->m_isRaised)
    00629         _painter->setPen(KGlobalSettings::toolBarHighlightColor());
    00630       else
    00631         _painter->setPen( colorGroup().buttonText() );
    00632       _painter->drawText(textRect, textFlags, textLabel());
    00633   }
    00634
    00635   if (d->m_popup)
    00636   {
    00637     QStyle::SFlags arrowFlags = QStyle::Style_Default;
    00638
    00639     if (isDown())       arrowFlags |= QStyle::Style_Down;
    00640     if (isEnabled())    arrowFlags |= QStyle::Style_Enabled;
    00641
    00642       style().drawPrimitive(QStyle::PE_ArrowDown, _painter,
    00643           QRect(width()-7, height()-7, 7, 7), colorGroup(),
    00644           arrowFlags, QStyleOption() );
    00645   }
    00646 }
    00647
    00648 void KToolBarButton::paletteChange(const QPalette &)
    00649 {
    00650   if(!d->m_isSeparator)
    00651   {
    00652     modeChange();
    00653     repaint(false); // no need to delete it first therefore only false
    00654   }
    00655 }
    00656
    00657 void KToolBarButton::showMenu()
    00658 {
    00659   // calculate that position carefully!!
    00660   d->m_isRaised = true;
    00661   repaint (false);
    00662
    00663   QPoint p;
    00664   // Calculate position from the toolbar button, only if the button is in the toolbar !
    00665   // If we are in the overflow menu, use the mouse position (as Qt does)
    00666   bool bInToolbar = QRect( 0, 0, d->m_parent->width(), d->m_parent->height() ).intersects( QRect( pos(), size() ) );
    00667   if (bInToolbar)
    00668   {
    00669     p = mapToGlobal( QPoint( 0, 0 ) );
    00670     if ( p.y() + height() + d->m_popup->sizeHint().height() > KApplication::desktop()->height() )
    00671         p.setY( p.y() - d->m_popup->sizeHint().height() );
    00672     else
    00673         p.setY( p.y() + height( ));
    00674     if (QApplication::reverseLayout()) p.setX(p.x() -d->m_popup->sizeHint().width() + width() );
    00675   }
    00676   else
    00677     p = QCursor::pos();
    00678
    00679   if ( d->m_isToggle )
    00680       setToggle( true ); // Turns the button into a ToggleButton ...
    00681   d->m_popup->popup(p);
    00682 }
    00683
    00684 void KToolBarButton::slotDelayTimeout()
    00685 {
    00686   d->m_delayTimer->stop();
    00687   showMenu();
    00688 }
    00689
    00690 void KToolBarButton::slotClicked()
    00691 {
    00692   if (d->m_popup && !d->m_isPopup)
    00693     showMenu();
    00694   else
    00695     emit clicked( d->m_id );
    00696 }
    00697
    00698 void KToolBarButton::slotPressed()
    00699 {
    00700   if (d->m_popup)
    00701   {
    00702     if (d->m_isPopup)
    00703     {
    00704       d->m_delayTimer->stop(); // just in case?
    00705       d->m_delayTimer->start( QApplication::startDragTime() , true);
    00706       return;
    00707     }
    00708     else
    00709       showMenu();
    00710   }
    00711   else
    00712     emit pressed( d->m_id );
    00713 }
    00714
    00715 void KToolBarButton::slotReleased()
    00716 {
    00717   if (d->m_popup && d->m_isPopup)
    00718     d->m_delayTimer->stop();
    00719
    00720   emit released( d->m_id );
    00721 }
    00722
    00723 void KToolBarButton::slotToggled()
    00724 {
    00725   emit toggled( d->m_id );
    00726 }
    00727
    00728 void KToolBarButton::setNoStyle(bool no_style)
    00729 {
    00730     d->m_noStyle = no_style;
    00731
    00732     modeChange();
    00733     d->m_iconText = KToolBar::IconTextRight;
    00734     repaint(false);
    00735 }
    00736
    00737 void KToolBarButton::setRadio (bool f)
    00738 {
    00739     if ( d )
    00740         d->m_isRadio = f;
    00741 }
    00742
    00743 void KToolBarButton::on(bool flag)
    00744 {
    00745   if(isToggleButton() == true)
    00746     setOn(flag);
    00747   else
    00748   {
    00749     setDown(flag);
    00750     leaveEvent((QEvent *) 0);
    00751   }
    00752   repaint();
    00753 }
    00754
    00755 void KToolBarButton::toggle()
    00756 {
    00757   setOn(!isOn());
    00758   repaint();
    00759 }
    00760
    00761 void KToolBarButton::setToggle(bool flag)
    00762 {
    00763   setToggleButton(flag);
    00764   if (flag == true)
    00765     connect(this, SIGNAL(toggled(bool)), this, SLOT(slotToggled()));
    00766   else
    00767     disconnect(this, SIGNAL(toggled(bool)), this, SLOT(slotToggled()));
    00768 }
    00769
    00770 QSize KToolBarButton::sizeHint() const
    00771 {
    00772    return d->size;
    00773 }
    00774
    00775 QSize KToolBarButton::minimumSizeHint() const
    00776 {
    00777    return d->size;
    00778 }
    00779
    00780 QSize KToolBarButton::minimumSize() const
    00781 {
    00782    return d->size;
    00783 }
    00784
    00785 bool KToolBarButton::isRaised() const
    00786 {
    00787     return d->m_isRaised;
    00788 }
    00789
    00790 bool KToolBarButton::isActive() const
    00791 {
    00792     return d->m_isActive;
    00793 }
    00794
    00795 int KToolBarButton::iconTextMode() const
    00796 {
    00797     return static_cast<int>( d->m_iconText );
    00798 }
    00799
    00800
    00801 // KToolBarButtonList
    00802 KToolBarButtonList::KToolBarButtonList()
    00803 {
    00804    setAutoDelete(false);
    00805 }
    00806
    00807 void KToolBarButton::virtual_hook( int, void* )
    00808 { /*BASE::virtual_hook( id, data );*/ }
    00809
    00810 #include "ktoolbarbutton.moc"

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:57:56 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001