kdeui Library API Documentation

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