• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • 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 #ifndef KDE_NO_DEPRECATED
00108 void KActionMenu::remove( KAction* cmd )
00109 {
00110   if ( cmd )
00111     menu()->removeAction(cmd);
00112 }
00113 #endif
00114 
00115 void KActionMenu::addAction( QAction * action )
00116 {
00117   menu()->addAction(action);
00118 }
00119 
00120 QAction* KActionMenu::addSeparator()
00121 {
00122   QAction* separator = new QAction(this);
00123   separator->setSeparator(true);
00124   addAction(separator);
00125   return separator;
00126 }
00127 
00128 QAction* KActionMenu::insertSeparator(QAction* before)
00129 {
00130   QAction* separator = new QAction(this);
00131   separator->setSeparator(true);
00132   insertAction(before, separator);
00133   return separator;
00134 }
00135 
00136 void KActionMenu::insertAction( QAction * before, QAction * action )
00137 {
00138   menu()->insertAction(before, action);
00139 }
00140 
00141 void KActionMenu::removeAction( QAction * action )
00142 {
00143   menu()->removeAction(action);
00144 }
00145 
00146 bool KActionMenu::delayed() const {
00147     return d->m_delayed;
00148 }
00149 
00150 void KActionMenu::setDelayed(bool _delayed) {
00151     d->m_delayed = _delayed;
00152 }
00153 
00154 bool KActionMenu::stickyMenu() const {
00155     return d->m_stickyMenu;
00156 }
00157 
00158 void KActionMenu::setStickyMenu(bool sticky) {
00159     d->m_stickyMenu = sticky;
00160 }
00161 
00162 KMenu* KActionMenu::menu()
00163 {
00164   if (!KAction::menu())
00165     setMenu(new KMenu());
00166 
00167   return qobject_cast<KMenu*>(KAction::menu());
00168 }
00169 
00170 void KActionMenu::setMenu(KMenu *menu)
00171 {
00172     KAction::setMenu( menu );
00173 }
00174 
00175 /* vim: et sw=2 ts=2
00176  */
00177 
00178 #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
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
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