Diffstat (limited to 'microkde/kdeui/ktoolbarbutton.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | microkde/kdeui/ktoolbarbutton.cpp | 106 |
1 files changed, 60 insertions, 46 deletions
diff --git a/microkde/kdeui/ktoolbarbutton.cpp b/microkde/kdeui/ktoolbarbutton.cpp index 1d5d0e5..7b98b32 100644 --- a/microkde/kdeui/ktoolbarbutton.cpp +++ b/microkde/kdeui/ktoolbarbutton.cpp @@ -20,48 +20,52 @@ the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ //US #include <config.h> #include <string.h> #include "ktoolbarbutton.h" #include "ktoolbar.h" #include <qstyle.h> #include <qimage.h> #include <qtimer.h> #include <qdrawutil.h> #include <qtooltip.h> #include <qbitmap.h> -#include <qpopupmenu.h> +#include <q3popupmenu.h> #include <qcursor.h> #include <qpainter.h> #include <qlayout.h> +//Added by qt3to4: +#include <QPixmap> +#include <QMouseEvent> +#include <QEvent> #include <kapplication.h> #include <kdebug.h> #include <kglobal.h> #include <kglobalsettings.h> //US #include <kiconeffect.h> #include <kiconloader.h> // needed to get our instance #include <kmainwindow.h> -template class QIntDict<KToolBarButton>; +template class Q3IntDict<KToolBarButton>; class KToolBarButtonPrivate { public: KToolBarButtonPrivate() { m_noStyle = false; m_isSeparator = false; m_isRadio = false; m_highlight = false; m_isRaised = false; m_isActive = false; m_iconName = QString::null; m_iconText = KToolBar::IconOnly; m_iconSize = 0; @@ -102,79 +106,79 @@ KToolBarButton::KToolBarButton( QWidget *_parent, const char *_name ) hide(); d->m_isSeparator = true; } KToolBarButton::KToolBarButton( const QString& _icon, int _id, QWidget *_parent, const char *_name, const QString &_txt/*US, KInstance *_instance*/ ) : QToolButton( _parent, _name ), d( 0 ) { d = new KToolBarButtonPrivate; d->m_id = _id; d->m_parent = (KToolBar*)_parent; QToolButton::setTextLabel(_txt); //US d->m_instance = _instance; - setFocusPolicy( NoFocus ); + setFocusPolicy( Qt::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 ); + setFocusPolicy( Qt::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 )); + setIconSet( QIcon( 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(); @@ -279,107 +283,107 @@ 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")) /*US QToolButton::setIconSet( d->m_instance->iconLoader()->loadIconSet( d->m_iconName, KIcon::MainToolbar, d->m_iconSize )); */ QToolButton::setIconSet( KGlobal::iconLoader()->loadIconSet(d->m_iconName )); else /*US QToolButton::setIconSet(d->m_instance->iconLoader()->loadIconSet( d->m_iconName, KIcon::Toolbar, d->m_iconSize )); */ QToolButton::setIconSet(KGlobal::iconLoader()->loadIconSet(d->m_iconName)); } -void KToolBarButton::setIconSet( const QIconSet &iconset ) +void KToolBarButton::setIconSet( const QIcon &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 ); + QIcon set = iconSet(); + set.setPixmap( pixmap, QIcon::Automatic, QIcon::Active ); QToolButton::setIconSet( set ); } void KToolBarButton::setDefaultPixmap( const QPixmap &pixmap ) { - QIconSet set = iconSet(); - set.setPixmap( pixmap, QIconSet::Automatic, QIconSet::Normal ); + QIcon set = iconSet(); + set.setPixmap( pixmap, QIcon::Automatic, QIcon::Normal ); QToolButton::setIconSet( set ); } void KToolBarButton::setDisabledPixmap( const QPixmap &pixmap ) { - QIconSet set = iconSet(); - set.setPixmap( pixmap, QIconSet::Automatic, QIconSet::Disabled ); + QIcon set = iconSet(); + set.setPixmap( pixmap, QIcon::Automatic, QIcon::Disabled ); QToolButton::setIconSet( set ); } void KToolBarButton::setDefaultIcon( const QString& icon ) { - QIconSet set = iconSet(); + QIcon set = iconSet(); QPixmap pm; if (!strcmp(d->m_parent->name(), "mainToolBar")) pm = /*US d->m_instance->iconLoader()*/KGlobal::iconLoader()->loadIcon( icon, KIcon::MainToolbar, d->m_iconSize ); else pm = /*US d->m_instance->iconLoader()*/KGlobal::iconLoader()->loadIcon( icon, KIcon::Toolbar, d->m_iconSize ); - set.setPixmap( pm, QIconSet::Automatic, QIconSet::Normal ); + set.setPixmap( pm, QIcon::Automatic, QIcon::Normal ); QToolButton::setIconSet( set ); } void KToolBarButton::setDisabledIcon( const QString& icon ) { - QIconSet set = iconSet(); + QIcon set = iconSet(); QPixmap pm; if (!strcmp(d->m_parent->name(), "mainToolBar")) pm = /*US d->m_instance->iconLoader()*/ KGlobal::iconLoader()->loadIcon( icon, KIcon::MainToolbar, d->m_iconSize ); else pm = /*US d->m_instance->iconLoader()*/ KGlobal::iconLoader()->loadIcon( icon, KIcon::Toolbar, d->m_iconSize ); - set.setPixmap( pm, QIconSet::Automatic, QIconSet::Disabled ); + set.setPixmap( pm, QIcon::Automatic, QIcon::Disabled ); QToolButton::setIconSet( set ); } -QPopupMenu *KToolBarButton::popup() +QMenu *KToolBarButton::popup() { // obsolete // KDE4: remove me return QToolButton::popup(); } -void KToolBarButton::setPopup(QPopupMenu *p, bool) +void KToolBarButton::setPopup(Q3PopupMenu *p, bool) { QToolButton::setPopup(p); QToolButton::setPopupDelay(1); } -void KToolBarButton::setDelayedPopup (QPopupMenu *p, bool) +void KToolBarButton::setDelayedPopup (Q3PopupMenu *p, bool) { QToolButton::setPopup(p); //US QToolButton::setPopupDelay(QApplication::startDragTime()); } 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); } @@ -438,199 +442,209 @@ bool KToolBarButton::eventFilter(QObject *o, QEvent *ev) return true; // From Kai-Uwe Sattler <kus@iti.CS.Uni-Magdeburg.De> if (ev->type() == QEvent::MouseButtonDblClick) { emit doubleClicked(d->m_id); return true; } } return QToolButton::eventFilter(o, ev); } void KToolBarButton::drawButton( QPainter *_painter ) { #ifdef DESKTOP_VERSION - QStyle::SFlags flags = QStyle::Style_Default; - QStyle::SCFlags active = QStyle::SC_None; + QStyle::State flags = QStyle::State_None; + QStyle::SubControls active = QStyle::SC_None; if (isDown()) { - flags |= QStyle::Style_Down; + flags |= QStyle::State_DownArrow; 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; + if (isEnabled()) flags |= QStyle::State_Enabled; + if (isOn()) flags |= QStyle::State_On; + if (isEnabled() && d->m_isRaised) flags |= QStyle::State_Raised; + if (hasFocus()) flags |= QStyle::State_HasFocus; + + QStyleOptionToolButton qsotb; + qsotb.initFrom(this); + qsotb.state = flags; + qsotb.activeSubControls = active; + qsotb.rect = rect(); + qsotb.palette = palette(); // Draw a styled toolbutton - style().drawComplexControl(QStyle::CC_ToolButton, _painter, this, rect(), - colorGroup(), flags, QStyle::SC_ToolButton, active, QStyleOption()); + style()->drawComplexControl(QStyle::CC_ToolButton, &qsotb, _painter, this); #else style().drawToolButton(_painter, rect().x(), rect().y(), rect().width(), rect().height(), colorGroup()); #endif 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 { /*US QPixmap pixmap = iconSet().pixmap( QIconSet::Automatic, isEnabled() ? (d->m_isActive ? QIconSet::Active : QIconSet::Normal) : QIconSet::Disabled, isOn() ? QIconSet::On : QIconSet::Off ); */ - QPixmap pixmap = iconSet().pixmap( QIconSet::Automatic, - isEnabled() ? (d->m_isActive ? QIconSet::Active : QIconSet::Normal) : - QIconSet::Disabled); + QPixmap pixmap = iconSet().pixmap( QIcon::Automatic, + isEnabled() ? (d->m_isActive ? QIcon::Active : QIcon::Normal) : + QIcon::Disabled); if( !pixmap.isNull()) { dx = ( width() - pixmap.width() ) / 2; dy = ( height() - pixmap.height() ) / 2; if ( isDown() /*US && 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) { /*US QPixmap pixmap = iconSet().pixmap( QIconSet::Automatic, isEnabled() ? (d->m_isActive ? QIconSet::Active : QIconSet::Normal) : QIconSet::Disabled, isOn() ? QIconSet::On : QIconSet::Off ); */ - QPixmap pixmap = iconSet().pixmap( QIconSet::Automatic, - isEnabled() ? (d->m_isActive ? QIconSet::Active : QIconSet::Normal) : - QIconSet::Disabled); + QPixmap pixmap = iconSet().pixmap( QIcon::Automatic, + isEnabled() ? (d->m_isActive ? QIcon::Active : QIcon::Normal) : + QIcon::Disabled); if( !pixmap.isNull()) { dx = 4; dy = ( height() - pixmap.height() ) / 2; if ( isDown() /*US && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle*/ ) { ++dx; ++dy; } _painter->drawPixmap( dx, dy, pixmap ); } if (!textLabel().isNull()) { - textFlags = AlignVCenter|AlignLeft; + textFlags = Qt::AlignVCenter|Qt::AlignLeft; if (!pixmap.isNull()) dx = 4 + pixmap.width() + 2; else dx = 4; dy = 0; if ( isDown() /*US && 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; + textFlags = Qt::AlignVCenter|Qt::AlignLeft; dx = (width() - fm.width(textLabel())) / 2; dy = (height() - fm.lineSpacing()) / 2; if ( isDown() /*US && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle*/ ) { ++dx; ++dy; } textRect = QRect( dx, dy, fm.width(textLabel()), fm.lineSpacing() ); } } else if (d->m_iconText == KToolBar::IconTextBottom) { /*US QPixmap pixmap = iconSet().pixmap( QIconSet::Automatic, isEnabled() ? (d->m_isActive ? QIconSet::Active : QIconSet::Normal) : QIconSet::Disabled, isOn() ? QIconSet::On : QIconSet::Off ); */ - QPixmap pixmap = iconSet().pixmap( QIconSet::Automatic, - isEnabled() ? (d->m_isActive ? QIconSet::Active : QIconSet::Normal) : - QIconSet::Disabled); + QPixmap pixmap = iconSet().pixmap( QIcon::Automatic, + isEnabled() ? (d->m_isActive ? QIcon::Active : QIcon::Normal) : + QIcon::Disabled); if( !pixmap.isNull()) { dx = (width() - pixmap.width()) / 2; dy = (height() - fm.lineSpacing() - pixmap.height()) / 2; if ( isDown() /*US && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle*/ ) { ++dx; ++dy; } _painter->drawPixmap( dx, dy, pixmap ); } if (!textLabel().isNull()) { - textFlags = AlignBottom|AlignHCenter; + textFlags = Qt::AlignBottom|Qt::AlignHCenter; dx = (width() - fm.width(textLabel())) / 2; dy = height() - fm.lineSpacing() - 4; if ( isDown() /*US && 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()) { #ifdef DESKTOP_VERSION - QStyle::SFlags arrowFlags = QStyle::Style_Default; + QStyle::State arrowFlags = QStyle::State_None; + + if (isDown()) arrowFlags |= QStyle::State_DownArrow; + if (isEnabled()) arrowFlags |= QStyle::State_Enabled; - if (isDown()) arrowFlags |= QStyle::Style_Down; - if (isEnabled()) arrowFlags |= QStyle::Style_Enabled; + QStyleOption qso; + qso.initFrom(this); + qso.state = arrowFlags; + qso.rect = QRect(width()-7, height()-7, 7, 7); + qso.palette = palette(); - style().drawPrimitive(QStyle::PE_ArrowDown, _painter, - QRect(width()-7, height()-7, 7, 7), colorGroup(), - arrowFlags, QStyleOption() ); + style()->drawPrimitive(QStyle::PE_IndicatorArrowDown, &qso, _painter); #else style().drawArrow(_painter, Qt::DownArrow, isDown(), width()-7, height()-7, 7, 7, colorGroup(), isEnabled() ); #endif } } void KToolBarButton::paletteChange(const QPalette &) { if(!d->m_isSeparator) { modeChange(); repaint(false); // no need to delete it first therefore only false } } |