KDEUI
ktoolbarpopupaction.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 1999 Reginald Stadlbauer <reggie@kde.org> 00003 (C) 1999 Simon Hausmann <hausmann@kde.org> 00004 (C) 2000 Nicolas Hadacek <haadcek@kde.org> 00005 (C) 2000 Kurt Granroth <granroth@kde.org> 00006 (C) 2000 Michael Koch <koch@kde.org> 00007 (C) 2001 Holger Freyther <freyther@kde.org> 00008 (C) 2002 Ellis Whitehead <ellis@kde.org> 00009 (C) 2002 Joseph Wenninger <jowenn@kde.org> 00010 (C) 2003 Andras Mantia <amantia@kde.org> 00011 (C) 2005-2006 Hamish Rodda <rodda@kde.org> 00012 00013 This library is free software; you can redistribute it and/or 00014 modify it under the terms of the GNU Library General Public 00015 License version 2 as published by the Free Software Foundation. 00016 00017 This library is distributed in the hope that it will be useful, 00018 but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00020 Library General Public License for more details. 00021 00022 You should have received a copy of the GNU Library General Public License 00023 along with this library; see the file COPYING.LIB. If not, write to 00024 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00025 Boston, MA 02110-1301, USA. 00026 */ 00027 00028 #include "ktoolbarpopupaction.h" 00029 #include "kmenu.h" 00030 00031 #include <QtGui/QToolBar> 00032 #include <QtGui/QToolButton> 00033 00034 #include <kdebug.h> 00035 #include <klocale.h> 00036 #include <kicon.h> 00037 00038 class KToolBarPopupAction::Private 00039 { 00040 public: 00041 Private() 00042 : delayed( true ), stickyMenu( true ) 00043 { 00044 } 00045 00046 bool delayed:1; 00047 bool stickyMenu:1; 00048 }; 00049 00050 KToolBarPopupAction::KToolBarPopupAction(const KIcon& icon, const QString& text, QObject *parent) 00051 : KAction(icon, text, parent), 00052 d( new Private ) 00053 { 00054 setMenu( new KMenu ); 00055 } 00056 00057 KToolBarPopupAction::~KToolBarPopupAction() 00058 { 00059 delete d; 00060 delete menu(); 00061 } 00062 00063 #ifndef KDE_NO_DEPRECATED 00064 KMenu* KToolBarPopupAction::popupMenu() const 00065 { 00066 return qobject_cast<KMenu*>( menu() ); 00067 } 00068 #endif 00069 00070 QWidget * KToolBarPopupAction::createWidget( QWidget * _parent ) 00071 { 00072 QToolBar *parent = qobject_cast<QToolBar *>(_parent); 00073 if (!parent) 00074 return KAction::createWidget(_parent); 00075 QToolButton* button = new QToolButton( parent ); 00076 button->setAutoRaise( true ); 00077 button->setFocusPolicy( Qt::NoFocus ); 00078 button->setIconSize( parent->iconSize() ); 00079 button->setToolButtonStyle( parent->toolButtonStyle() ); 00080 button->setDefaultAction( this ); 00081 00082 connect( parent, SIGNAL( iconSizeChanged( const QSize& ) ), 00083 button, SLOT( setIconSize( const QSize& ) ) ); 00084 connect( parent, SIGNAL( toolButtonStyleChanged( Qt::ToolButtonStyle ) ), 00085 button, SLOT( setToolButtonStyle( Qt::ToolButtonStyle ) ) ); 00086 connect( button, SIGNAL( triggered( QAction* ) ), 00087 parent, SIGNAL( actionTriggered( QAction* ) ) ); 00088 00089 if ( d->delayed ) 00090 if ( d->stickyMenu ) 00091 button->setPopupMode( QToolButton::MenuButtonPopup ); 00092 else 00093 button->setPopupMode( QToolButton::DelayedPopup ); 00094 else 00095 button->setPopupMode( QToolButton::InstantPopup ); 00096 00097 return button; 00098 } 00099 00100 bool KToolBarPopupAction::delayed() const 00101 { 00102 return d->delayed; 00103 } 00104 00105 void KToolBarPopupAction::setDelayed( bool delayed ) 00106 { 00107 d->delayed = delayed; 00108 } 00109 00110 bool KToolBarPopupAction::stickyMenu() const 00111 { 00112 return d->stickyMenu; 00113 } 00114 00115 void KToolBarPopupAction::setStickyMenu( bool sticky ) 00116 { 00117 d->stickyMenu = sticky; 00118 } 00119 00120 #include "ktoolbarpopupaction.moc"
KDE 4.6 API Reference