diff --git a/kdeui/ktoolbarbutton.cpp b/kdeui/ktoolbarbutton.cpp index 4ea6e6f1dd..965740cf08 100644 --- a/kdeui/ktoolbarbutton.cpp +++ b/kdeui/ktoolbarbutton.cpp @@ -1,745 +1,710 @@ /* This file is part of the KDE libraries Copyright (C) 1997, 1998 Stephan Kulow (coolo@kde.org) (C) 1997, 1998 Mark Donohoe (donohoe@kde.org) (C) 1997, 1998 Sven Radej (radej@kde.org) (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org) (C) 1999 Chris Schlaeger (cs@kde.org) (C) 1999 Kurt Granroth (granroth@kde.org) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include "ktoolbarbutton.h" #include "ktoolbar.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // needed to get our instance #include template class QIntDict; class KToolBarButtonPrivate { public: KToolBarButtonPrivate() { m_noStyle = false; m_isSeparator = false; m_isRadio = false; m_highlight = false; m_isRaised = false; m_isActive = false; - m_isDelayedPopup = false; m_iconName = QString::null; m_iconText = KToolBar::IconOnly; m_iconSize = 0; m_instance = KGlobal::instance(); } ~KToolBarButtonPrivate() { } int m_id; bool m_noStyle: 1; bool m_isSeparator: 1; bool m_isRadio: 1; bool m_highlight: 1; bool m_isRaised: 1; bool m_isActive: 1; - bool m_isDelayedPopup: 1; QString m_iconName; KToolBar *m_parent; KToolBar::IconText m_iconText; int m_iconSize; QSize size; QPoint m_mousePressPos; KInstance *m_instance; }; // This will construct a separator KToolBarButton::KToolBarButton( QWidget *_parent, const char *_name ) : QToolButton( _parent , _name) { d = new KToolBarButtonPrivate; resize(6,6); hide(); d->m_isSeparator = true; } KToolBarButton::KToolBarButton( const QString& _icon, int _id, QWidget *_parent, const char *_name, const QString &_txt, KInstance *_instance ) : QToolButton( _parent, _name ), d( 0 ) { d = new KToolBarButtonPrivate; d->m_id = _id; d->m_parent = (KToolBar*)_parent; QToolButton::setTextLabel(_txt); d->m_instance = _instance; setFocusPolicy( NoFocus ); // connect all of our slots and start trapping events connect(d->m_parent, SIGNAL( modechange() ), this, SLOT( modeChange() )); connect(this, SIGNAL( clicked() ), this, SLOT( slotClicked() ) ); connect(this, SIGNAL( pressed() ), this, SLOT( slotPressed() ) ); connect(this, SIGNAL( released() ), this, SLOT( slotReleased() ) ); installEventFilter(this); d->m_iconName = _icon; // do our initial setup modeChange(); } KToolBarButton::KToolBarButton( const QPixmap& pixmap, int _id, QWidget *_parent, const char *name, const QString& txt) : QToolButton( _parent, name ), d( 0 ) { d = new KToolBarButtonPrivate; d->m_id = _id; d->m_parent = (KToolBar *) _parent; QToolButton::setTextLabel(txt); setFocusPolicy( NoFocus ); // connect all of our slots and start trapping events connect(d->m_parent, SIGNAL( modechange()), this, SLOT(modeChange())); connect(this, SIGNAL( clicked() ), this, SLOT( slotClicked() )); connect(this, SIGNAL( pressed() ), this, SLOT( slotPressed() )); connect(this, SIGNAL( released() ), this, SLOT( slotReleased() )); installEventFilter(this); // set our pixmap and do our initial setup setIconSet( QIconSet( pixmap )); modeChange(); } KToolBarButton::~KToolBarButton() { delete d; d = 0; } void KToolBarButton::modeChange() { QSize mysize; // grab a few global variables for use in this function and others d->m_highlight = d->m_parent->highlight(); d->m_iconText = d->m_parent->iconText(); d->m_iconSize = d->m_parent->iconSize(); if (!d->m_iconName.isNull()) setIcon(d->m_iconName); // we'll start with the size of our pixmap int pix_width = d->m_iconSize; if ( d->m_iconSize == 0 ) { if (!strcmp(d->m_parent->name(), "mainToolBar")) pix_width = IconSize( KIcon::MainToolbar ); else pix_width = IconSize( KIcon::Toolbar ); } int pix_height = pix_width; int text_height = 0; int text_width = 0; QToolTip::remove(this); if (d->m_iconText != KToolBar::IconOnly) { // okay, we have to deal with fonts. let's get our information now QFont tmp_font = KGlobalSettings::toolBarFont(); // now parse out our font sizes from our chosen font QFontMetrics fm(tmp_font); text_height = fm.lineSpacing(); text_width = fm.width(textLabel()); // none of the other modes want tooltips } else { QToolTip::add(this, textLabel()); } switch (d->m_iconText) { case KToolBar::IconOnly: mysize = QSize(pix_width, pix_height); break; case KToolBar::IconTextRight: mysize = QSize(pix_width + text_width + 4, pix_height); break; case KToolBar::TextOnly: mysize = QSize(text_width + 4, text_height); break; case KToolBar::IconTextBottom: mysize = QSize((text_width + 4 > pix_width) ? text_width + 4 : pix_width, pix_height + text_height); break; default: break; } mysize = style().sizeFromContents(QStyle::CT_ToolButton, this, mysize). expandedTo(QApplication::globalStrut()); // make sure that this isn't taller then it is wide if (mysize.height() > mysize.width()) mysize.setWidth(mysize.height()); d->size = mysize; updateGeometry(); } void KToolBarButton::setTextLabel( const QString& text, bool tipToo) { if (text.isNull()) return; QString txt(text); if (txt.right(3) == QString::fromLatin1("...")) txt.truncate(txt.length() - 3); QToolButton::setTextLabel(txt, tipToo); update(); } void KToolBarButton::setText( const QString& text) { setTextLabel(text, true); modeChange(); } void KToolBarButton::setIcon( const QString &icon ) { d->m_iconName = icon; d->m_iconSize = d->m_parent->iconSize(); // QObject::name() return "const char *" instead of QString. if (!strcmp(d->m_parent->name(), "mainToolBar")) QToolButton::setIconSet( d->m_instance->iconLoader()->loadIconSet( d->m_iconName, KIcon::MainToolbar, d->m_iconSize )); else QToolButton::setIconSet( d->m_instance->iconLoader()->loadIconSet( d->m_iconName, KIcon::Toolbar, d->m_iconSize )); } void KToolBarButton::setIconSet( const QIconSet &iconset ) { QToolButton::setIconSet( iconset ); } // remove? void KToolBarButton::setPixmap( const QPixmap &pixmap ) { if( pixmap.isNull()) // called by QToolButton { QToolButton::setPixmap( pixmap ); return; } QIconSet set = iconSet(); set.setPixmap( pixmap, QIconSet::Automatic, QIconSet::Active ); QToolButton::setIconSet( set ); } void KToolBarButton::setDefaultPixmap( const QPixmap &pixmap ) { QIconSet set = iconSet(); set.setPixmap( pixmap, QIconSet::Automatic, QIconSet::Normal ); QToolButton::setIconSet( set ); } void KToolBarButton::setDisabledPixmap( const QPixmap &pixmap ) { QIconSet set = iconSet(); set.setPixmap( pixmap, QIconSet::Automatic, QIconSet::Disabled ); QToolButton::setIconSet( set ); } void KToolBarButton::setDefaultIcon( const QString& icon ) { QIconSet set = iconSet(); QPixmap pm; if (!strcmp(d->m_parent->name(), "mainToolBar")) pm = d->m_instance->iconLoader()->loadIcon( icon, KIcon::MainToolbar, d->m_iconSize ); else pm = d->m_instance->iconLoader()->loadIcon( icon, KIcon::Toolbar, d->m_iconSize ); set.setPixmap( pm, QIconSet::Automatic, QIconSet::Normal ); QToolButton::setIconSet( set ); } void KToolBarButton::setDisabledIcon( const QString& icon ) { QIconSet set = iconSet(); QPixmap pm; if (!strcmp(d->m_parent->name(), "mainToolBar")) pm = d->m_instance->iconLoader()->loadIcon( icon, KIcon::MainToolbar, d->m_iconSize ); else pm = d->m_instance->iconLoader()->loadIcon( icon, KIcon::Toolbar, d->m_iconSize ); set.setPixmap( pm, QIconSet::Automatic, QIconSet::Disabled ); QToolButton::setIconSet( set ); } QPopupMenu *KToolBarButton::popup() { // obsolete // KDE4: remove me return QToolButton::popup(); } void KToolBarButton::setPopup(QPopupMenu *p, bool) { QToolButton::setPopup(p); - QToolButton::setPopupDelay(QApplication::startDragTime()); - d->m_isDelayedPopup = false; - // BEGIN HACK - // The following hack is needed because QToolButton::openPopup() - // does not stop the timer for the delayed popup. - // It can be removed when QToolButton::openPopup() - // contains d->popupTimer->stop(); - if (p) - { - disconnect( this, SIGNAL( pressed() ), this, SLOT( popupPressed() ) ); - } - // END HACK + QToolButton::setPopupDelay(1); } void KToolBarButton::setDelayedPopup (QPopupMenu *p, bool) { QToolButton::setPopup(p); QToolButton::setPopupDelay(QApplication::startDragTime()); - d->m_isDelayedPopup = true; - // BEGIN HACK - // The following hack is needed because QToolButton::openPopup() - // does not stop the timer for the delayed popup. - // It can be removed when QToolButton::openPopup() - // contains d->popupTimer->stop(); - if (p) - { - disconnect( this, SIGNAL( pressed() ), this, SLOT( popupPressed() ) ); - connect( this, SIGNAL( pressed() ), this, SLOT( popupPressed() ) ); - } - // END HACK } void KToolBarButton::leaveEvent(QEvent *) { if( d->m_isRaised || d->m_isActive ) { d->m_isRaised = false; d->m_isActive = false; repaint(false); } emit highlighted(d->m_id, false); } void KToolBarButton::enterEvent(QEvent *) { if (d->m_highlight) { if (isEnabled()) { d->m_isActive = true; if (!isToggleButton()) d->m_isRaised = true; } else { d->m_isRaised = false; d->m_isActive = false; } repaint(false); } emit highlighted(d->m_id, true); } - -void KToolBarButton::mousePressEvent( QMouseEvent *e ) -{ - QToolButton::mousePressEvent( e ); - if (QToolButton::popup()) - { - d->m_mousePressPos = e->pos(); - if (!d->m_isDelayedPopup) - { - openPopup(); - } - } -} - - - bool KToolBarButton::eventFilter(QObject *o, QEvent *ev) { if ((KToolBarButton *)o == this) { - // From Kai-Uwe Sattler - if (ev->type() == QEvent::MouseButtonDblClick) - { - emit doubleClicked(d->m_id); - return true; - } - - if ((ev->type() == QEvent::MouseButtonPress || - ev->type() == QEvent::MouseButtonRelease || - ev->type() == QEvent::MouseButtonDblClick) && d->m_isRadio && isOn()) - return true; // Popup the menu when the left mousebutton is pressed and the mouse // is moved by a small distance. if (QToolButton::popup()) { - if (ev->type() == QEvent::MouseMove) + if (ev->type() == QEvent::MouseButtonPress) + { + QMouseEvent* mev = static_cast(ev); + d->m_mousePressPos = mev->pos(); + } + else if (ev->type() == QEvent::MouseMove) { QMouseEvent* mev = static_cast(ev); if ((mev->pos() - d->m_mousePressPos).manhattanLength() > KGlobalSettings::dndEventDelay()) { openPopup(); return true; } } } + + if ((ev->type() == QEvent::MouseButtonPress || + ev->type() == QEvent::MouseButtonRelease || + ev->type() == QEvent::MouseButtonDblClick) && d->m_isRadio && isOn()) + return true; + + // From Kai-Uwe Sattler + if (ev->type() == QEvent::MouseButtonDblClick) + { + emit doubleClicked(d->m_id); + return true; + } } return QToolButton::eventFilter(o, ev); } void KToolBarButton::drawButton( QPainter *_painter ) { QStyle::SFlags flags = QStyle::Style_Default; QStyle::SCFlags active = QStyle::SC_None; if (isDown()) { flags |= QStyle::Style_Down; active |= QStyle::SC_ToolButton; } if (isEnabled()) flags |= QStyle::Style_Enabled; if (isOn()) flags |= QStyle::Style_On; if (isEnabled() && d->m_isRaised) flags |= QStyle::Style_Raised; if (hasFocus()) flags |= QStyle::Style_HasFocus; // Draw a styled toolbutton style().drawComplexControl(QStyle::CC_ToolButton, _painter, this, rect(), colorGroup(), flags, QStyle::SC_ToolButton, active, QStyleOption()); int dx, dy; QFont tmp_font(KGlobalSettings::toolBarFont()); QFontMetrics fm(tmp_font); QRect textRect; int textFlags = 0; if (d->m_iconText == KToolBar::IconOnly) // icon only { QPixmap pixmap = iconSet().pixmap( QIconSet::Automatic, isEnabled() ? (d->m_isActive ? QIconSet::Active : QIconSet::Normal) : QIconSet::Disabled, isOn() ? QIconSet::On : QIconSet::Off ); if( !pixmap.isNull()) { dx = ( width() - pixmap.width() ) / 2; dy = ( height() - pixmap.height() ) / 2; if ( isDown() && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle ) { ++dx; ++dy; } _painter->drawPixmap( dx, dy, pixmap ); } } else if (d->m_iconText == KToolBar::IconTextRight) // icon and text (if any) { QPixmap pixmap = iconSet().pixmap( QIconSet::Automatic, isEnabled() ? (d->m_isActive ? QIconSet::Active : QIconSet::Normal) : QIconSet::Disabled, isOn() ? QIconSet::On : QIconSet::Off ); if( !pixmap.isNull()) { dx = 4; dy = ( height() - pixmap.height() ) / 2; if ( isDown() && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle ) { ++dx; ++dy; } _painter->drawPixmap( dx, dy, pixmap ); } if (!textLabel().isNull()) { textFlags = AlignVCenter|AlignLeft; if (!pixmap.isNull()) dx = 4 + pixmap.width() + 2; else dx = 4; dy = 0; if ( isDown() && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle ) { ++dx; ++dy; } textRect = QRect(dx, dy, width()-dx, height()); } } else if (d->m_iconText == KToolBar::TextOnly) { if (!textLabel().isNull()) { textFlags = AlignVCenter|AlignLeft; dx = (width() - fm.width(textLabel())) / 2; dy = (height() - fm.lineSpacing()) / 2; if ( isDown() && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle ) { ++dx; ++dy; } textRect = QRect( dx, dy, fm.width(textLabel()), fm.lineSpacing() ); } } else if (d->m_iconText == KToolBar::IconTextBottom) { QPixmap pixmap = iconSet().pixmap( QIconSet::Automatic, isEnabled() ? (d->m_isActive ? QIconSet::Active : QIconSet::Normal) : QIconSet::Disabled, isOn() ? QIconSet::On : QIconSet::Off ); if( !pixmap.isNull()) { dx = (width() - pixmap.width()) / 2; dy = (height() - fm.lineSpacing() - pixmap.height()) / 2; if ( isDown() && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle ) { ++dx; ++dy; } _painter->drawPixmap( dx, dy, pixmap ); } if (!textLabel().isNull()) { textFlags = AlignBottom|AlignHCenter; dx = (width() - fm.width(textLabel())) / 2; dy = height() - fm.lineSpacing() - 4; if ( isDown() && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle ) { ++dx; ++dy; } textRect = QRect( dx, dy, fm.width(textLabel()), fm.lineSpacing() ); } } // Draw the text at the position given by textRect, and using textFlags if (!textLabel().isNull() && !textRect.isNull()) { _painter->setFont(KGlobalSettings::toolBarFont()); if (!isEnabled()) _painter->setPen(palette().disabled().dark()); else if(d->m_isRaised) _painter->setPen(KGlobalSettings::toolBarHighlightColor()); else _painter->setPen( colorGroup().buttonText() ); _painter->drawText(textRect, textFlags, textLabel()); } if (QToolButton::popup()) { QStyle::SFlags arrowFlags = QStyle::Style_Default; if (isDown()) arrowFlags |= QStyle::Style_Down; if (isEnabled()) arrowFlags |= QStyle::Style_Enabled; style().drawPrimitive(QStyle::PE_ArrowDown, _painter, QRect(width()-7, height()-7, 7, 7), colorGroup(), arrowFlags, QStyleOption() ); } } void KToolBarButton::paletteChange(const QPalette &) { if(!d->m_isSeparator) { modeChange(); repaint(false); // no need to delete it first therefore only false } } void KToolBarButton::showMenu() { // obsolete // KDE4: remove me } void KToolBarButton::slotDelayTimeout() { // obsolete // KDE4: remove me } void KToolBarButton::slotClicked() { emit clicked( d->m_id ); } void KToolBarButton::slotPressed() { emit pressed( d->m_id ); } void KToolBarButton::slotReleased() { emit released( d->m_id ); } void KToolBarButton::slotToggled() { emit toggled( d->m_id ); } void KToolBarButton::setNoStyle(bool no_style) { d->m_noStyle = no_style; modeChange(); d->m_iconText = KToolBar::IconTextRight; repaint(false); } void KToolBarButton::setRadio (bool f) { if ( d ) d->m_isRadio = f; } void KToolBarButton::on(bool flag) { if(isToggleButton() == true) setOn(flag); else { setDown(flag); leaveEvent((QEvent *) 0); } repaint(); } void KToolBarButton::toggle() { setOn(!isOn()); repaint(); } void KToolBarButton::setToggle(bool flag) { setToggleButton(flag); if (flag == true) connect(this, SIGNAL(toggled(bool)), this, SLOT(slotToggled())); else disconnect(this, SIGNAL(toggled(bool)), this, SLOT(slotToggled())); } QSize KToolBarButton::sizeHint() const { return d->size; } QSize KToolBarButton::minimumSizeHint() const { return d->size; } QSize KToolBarButton::minimumSize() const { return d->size; } bool KToolBarButton::isRaised() const { return d->m_isRaised; } bool KToolBarButton::isActive() const { return d->m_isActive; } int KToolBarButton::iconTextMode() const { return static_cast( d->m_iconText ); } // KToolBarButtonList KToolBarButtonList::KToolBarButtonList() { setAutoDelete(false); } void KToolBarButton::virtual_hook( int, void* ) { /*BASE::virtual_hook( id, data );*/ } #include "ktoolbarbutton.moc" diff --git a/kdeui/ktoolbarbutton.h b/kdeui/ktoolbarbutton.h index a62a71f125..1940b04fbc 100644 --- a/kdeui/ktoolbarbutton.h +++ b/kdeui/ktoolbarbutton.h @@ -1,308 +1,307 @@ /* This file is part of the KDE libraries Copyright (C) 1997, 1998 Stephan Kulow (coolo@kde.org) (C) 1997, 1998 Sven Radej (radej@kde.org) (C) 1997, 1998 Mark Donohoe (donohoe@kde.org) (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org) (C) 2000 Kurt Granroth (granroth@kde.org) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // $Id$ #ifndef _KTOOLBARBUTTON_H #define _KTOOLBARBUTTON_H #include #include #include #include #include class KToolBar; class KToolBarButtonPrivate; class KInstance; class QEvent; class QPopupMenu; class QPainter; /** * A toolbar button. This is used internally by @ref KToolBar, use the * KToolBar methods instead. * @internal */ class KToolBarButton : public QToolButton { Q_OBJECT public: /** * Construct a button with an icon loaded by the button itself. * This will trust the button to load the correct icon with the * correct size. * * @param icon Name of icon to load (may be absolute or relative) * @param id Id of this button * @param parent This button's parent * @param name This button's internal name * @param txt This button's text (in a tooltip or otherwise) */ KToolBarButton(const QString& icon, int id, QWidget *parent, const char *name=0L, const QString &txt=QString::null, KInstance *_instance = KGlobal::instance()); /** * Construct a button with an existing pixmap. It is not * recommended that you use this as the internal icon loading code * will almost always get it "right". * * @param icon Name of icon to load (may be absolute or relative) * @param id Id of this button * @param parent This button's parent * @param name This button's internal name * @param txt This button's text (in a tooltip or otherwise) */ KToolBarButton(const QPixmap& pixmap, int id, QWidget *parent, const char *name=0L, const QString &txt=QString::null); /** * Construct a separator button * * @param parent This button's parent * @param name This button's internal name */ KToolBarButton(QWidget *parent=0L, const char *name=0L); /** * Standard destructor */ ~KToolBarButton(); #ifndef KDE_NO_COMPAT /** * @deprecated * Set the pixmap directly for this button. This pixmap should be * the active one... the dimmed and disabled pixmaps are constructed * based on this one. However, don't use this function unless you * are positive that you don't want to use @ref setIcon. * * @param pixmap The active pixmap */ // this one is from QButton, so #ifdef-ing it out doesn't break BC virtual void setPixmap(const QPixmap &pixmap); /** * @deprecated * Force the button to use this pixmap as the default one rather * then generating it using effects. * * @param pixmap The pixmap to use as the default (normal) one */ void setDefaultPixmap(const QPixmap& pixmap); /** * @deprecated * Force the button to use this pixmap when disabled one rather then * generating it using effects. * * @param pixmap The pixmap to use when disabled */ void setDisabledPixmap(const QPixmap& pixmap); #endif /** * Set the text for this button. The text will be either used as a * tooltip (IconOnly) or will be along side the icon * * @param text The button (or tooltip) text */ virtual void setText(const QString &text); /** * Set the icon for this button. The icon will be loaded internally * with the correct size. This function is preferred over @ref setIconSet * * @param icon The name of the icon */ virtual void setIcon(const QString &icon); /// @since 3.1 virtual void setIcon( const QPixmap &pixmap ) { QToolButton::setIcon( pixmap ); } /** * Set the pixmaps for this toolbar button from a QIconSet. * If you call this you don't need to call any of the other methods * that set icons or pixmaps. * @param iconset The iconset to use */ virtual void setIconSet( const QIconSet &iconset ); #ifndef KDE_NO_COMPAT /** * @deprecated * Set the active icon for this button. The pixmap itself is loaded * internally based on the icon size... .. the disabled and default * pixmaps, however will only be constructed if @ref #generate is * true. This function is preferred over @ref setPixmap * * @param icon The name of the active icon * @param generate If true, then the other icons are automagically * generated from this one */ void setIcon(const QString &icon, bool /*generate*/ ) { setIcon( icon ); } /** * @deprecated * Force the button to use this icon as the default one rather * then generating it using effects. * * @param icon The icon to use as the default (normal) one */ void setDefaultIcon(const QString& icon); /** * @deprecated * Force the button to use this icon when disabled one rather then * generating it using effects. * * @param icon The icon to use when disabled */ void setDisabledIcon(const QString& icon); #endif /** * Turn this button on or off * * @param flag true or false */ void on(bool flag = true); /** * Toggle this button */ void toggle(); /** * Turn this button into a toggle button or disable the toggle * aspects of it. This does not toggle the button itself. * Use @ref toggle() for that. * * @param toggle true or false */ void setToggle(bool toggle = true); /** * Return a pointer to this button's popup menu (if it exists) */ QPopupMenu *popup(); /** * Give this button a popup menu. There will not be a delay when * you press the button. Use @ref setDelayedPopup if you want that * behavior. * * @param p The new popup menu */ void setPopup (QPopupMenu *p, bool unused = false); /** * Gives this button a delayed popup menu. * * This function allows you to add a delayed popup menu to the button. * The popup menu is then only displayed when the button is pressed and * held down for about half a second. * * @param p the new popup menu */ void setDelayedPopup(QPopupMenu *p, bool unused = false); /** * Turn this button into a radio button * * @param f true or false */ void setRadio(bool f = true); /** * Toolbar buttons naturally will assume the global styles * concerning icons, icons sizes, etc. You can use this function to * explicitely turn this off, if you like. * * @param no_style Will disable styles if true */ void setNoStyle(bool no_style = true); signals: void clicked(int); void doubleClicked(int); void pressed(int); void released(int); void toggled(int); void highlighted(int, bool); public slots: /** * This slot should be called whenever the toolbar mode has * potentially changed. This includes such events as text changing, * orientation changing, etc. */ void modeChange(); virtual void setTextLabel(const QString&, bool tipToo); protected: void paletteChange(const QPalette &); void leaveEvent(QEvent *e); void enterEvent(QEvent *e); - void mousePressEvent( QMouseEvent *e ); void drawButton(QPainter *p); bool eventFilter (QObject *o, QEvent *e); void showMenu(); QSize sizeHint() const; QSize minimumSizeHint() const; QSize minimumSize() const; /// @since 3.1 bool isRaised() const; /// @since 3.1 bool isActive() const; /// @since 3.1 int iconTextMode() const; protected slots: void slotClicked(); void slotPressed(); void slotReleased(); void slotToggled(); void slotDelayTimeout(); protected: virtual void virtual_hook( int id, void* data ); private: KToolBarButtonPrivate *d; }; /** * List of @ref KToolBarButton objects. * @internal * @version $Id$ */ class KToolBarButtonList : public QIntDict { public: KToolBarButtonList(); ~KToolBarButtonList() {} }; #endif