• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDEUI

kactionmenu.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 "kactionmenu.h"
00029 
00030 #include <QToolButton>
00031 #include <QToolBar>
00032 
00033 #include <kdebug.h>
00034 #include <klocale.h>
00035 #include <kmenu.h>
00036 
00037 class KActionMenuPrivate
00038 {
00039 public:
00040   KActionMenuPrivate()
00041   {
00042     m_delayed = true;
00043     m_stickyMenu = true;
00044   }
00045   ~KActionMenuPrivate()
00046   {
00047   }
00048   bool m_delayed;
00049   bool m_stickyMenu;
00050 };
00051 
00052 KActionMenu::KActionMenu(QObject *parent)
00053   : KAction(parent)
00054   , d(new KActionMenuPrivate)
00055 {
00056   setShortcutConfigurable( false );
00057 }
00058 
00059 KActionMenu::KActionMenu(const QString &text, QObject *parent)
00060   : KAction(parent)
00061   , d(new KActionMenuPrivate)
00062 {
00063   setShortcutConfigurable( false );
00064   setText(text);
00065 }
00066 
00067 KActionMenu::KActionMenu(const KIcon & icon, const QString & text, QObject *parent)
00068   : KAction(icon, text, parent)
00069   , d(new KActionMenuPrivate)
00070 {
00071   setShortcutConfigurable( false );
00072 }
00073 
00074 KActionMenu::~KActionMenu()
00075 {
00076     delete d;
00077     delete menu();
00078 }
00079 
00080 QWidget * KActionMenu::createWidget( QWidget * _parent )
00081 {
00082   QToolBar *parent = qobject_cast<QToolBar *>(_parent);
00083   if (!parent)
00084     return KAction::createWidget(_parent);
00085   QToolButton* button = new QToolButton(parent);
00086   button->setAutoRaise(true);
00087   button->setFocusPolicy(Qt::NoFocus);
00088   button->setIconSize(parent->iconSize());
00089   button->setToolButtonStyle(parent->toolButtonStyle());
00090   QObject::connect(parent, SIGNAL(iconSizeChanged(const QSize&)),
00091                    button, SLOT(setIconSize(const QSize&)));
00092   QObject::connect(parent, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)),
00093                    button, SLOT(setToolButtonStyle(Qt::ToolButtonStyle)));
00094   button->setDefaultAction(this);
00095   QObject::connect(button, SIGNAL(triggered(QAction*)), parent, SIGNAL(actionTriggered(QAction*)));
00096 
00097   if (delayed())
00098     button->setPopupMode(QToolButton::DelayedPopup);
00099   else if (stickyMenu())
00100     button->setPopupMode(QToolButton::InstantPopup);
00101   else
00102     button->setPopupMode(QToolButton::MenuButtonPopup);
00103 
00104   return button;
00105 }
00106 
00107 void KActionMenu::remove( KAction* cmd )
00108 {
00109   if ( cmd )
00110     menu()->removeAction(cmd);
00111 }
00112 
00113 void KActionMenu::addAction( QAction * action )
00114 {
00115   menu()->addAction(action);
00116 }
00117 
00118 QAction* KActionMenu::addSeparator()
00119 {
00120   QAction* separator = new QAction(this);
00121   separator->setSeparator(true);
00122   addAction(separator);
00123   return separator;
00124 }
00125 
00126 QAction* KActionMenu::insertSeparator(QAction* before)
00127 {
00128   QAction* separator = new QAction(this);
00129   separator->setSeparator(true);
00130   insertAction(before, separator);
00131   return separator;
00132 }
00133 
00134 void KActionMenu::insertAction( QAction * before, QAction * action )
00135 {
00136   menu()->insertAction(before, action);
00137 }
00138 
00139 void KActionMenu::removeAction( QAction * action )
00140 {
00141   menu()->removeAction(action);
00142 }
00143 
00144 bool KActionMenu::delayed() const {
00145     return d->m_delayed;
00146 }
00147 
00148 void KActionMenu::setDelayed(bool _delayed) {
00149     d->m_delayed = _delayed;
00150 }
00151 
00152 bool KActionMenu::stickyMenu() const {
00153     return d->m_stickyMenu;
00154 }
00155 
00156 void KActionMenu::setStickyMenu(bool sticky) {
00157     d->m_stickyMenu = sticky;
00158 }
00159 
00160 KMenu* KActionMenu::menu()
00161 {
00162   if (!KAction::menu())
00163     setMenu(new KMenu());
00164 
00165   return qobject_cast<KMenu*>(KAction::menu());
00166 }
00167 
00168 void KActionMenu::setMenu(KMenu *menu)
00169 {
00170     KAction::setMenu( menu );
00171 }
00172 
00173 /* vim: et sw=2 ts=2
00174  */
00175 
00176 #include "kactionmenu.moc"

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal