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

KDEUI

  • sources
  • kde-4.14
  • kdelibs
  • kdeui
  • actions
kactionmenu.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 1999 Reginald Stadlbauer <reggie@kde.org>
3  (C) 1999 Simon Hausmann <hausmann@kde.org>
4  (C) 2000 Nicolas Hadacek <haadcek@kde.org>
5  (C) 2000 Kurt Granroth <granroth@kde.org>
6  (C) 2000 Michael Koch <koch@kde.org>
7  (C) 2001 Holger Freyther <freyther@kde.org>
8  (C) 2002 Ellis Whitehead <ellis@kde.org>
9  (C) 2002 Joseph Wenninger <jowenn@kde.org>
10  (C) 2003 Andras Mantia <amantia@kde.org>
11  (C) 2005-2006 Hamish Rodda <rodda@kde.org>
12 
13  This library is free software; you can redistribute it and/or
14  modify it under the terms of the GNU Library General Public
15  License version 2 as published by the Free Software Foundation.
16 
17  This library is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  Library General Public License for more details.
21 
22  You should have received a copy of the GNU Library General Public License
23  along with this library; see the file COPYING.LIB. If not, write to
24  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25  Boston, MA 02110-1301, USA.
26 */
27 
28 #include "kactionmenu.h"
29 
30 #include <QToolButton>
31 #include <QToolBar>
32 
33 #include <kdebug.h>
34 #include <klocale.h>
35 #include <kmenu.h>
36 
37 class KActionMenuPrivate
38 {
39 public:
40  KActionMenuPrivate()
41  {
42  m_delayed = true;
43  m_stickyMenu = true;
44  }
45  ~KActionMenuPrivate()
46  {
47  }
48  bool m_delayed;
49  bool m_stickyMenu;
50 };
51 
52 KActionMenu::KActionMenu(QObject *parent)
53  : KAction(parent)
54  , d(new KActionMenuPrivate)
55 {
56  setShortcutConfigurable( false );
57 }
58 
59 KActionMenu::KActionMenu(const QString &text, QObject *parent)
60  : KAction(parent)
61  , d(new KActionMenuPrivate)
62 {
63  setShortcutConfigurable( false );
64  setText(text);
65 }
66 
67 KActionMenu::KActionMenu(const KIcon & icon, const QString & text, QObject *parent)
68  : KAction(icon, text, parent)
69  , d(new KActionMenuPrivate)
70 {
71  setShortcutConfigurable( false );
72 }
73 
74 KActionMenu::~KActionMenu()
75 {
76  delete d;
77  delete menu();
78 }
79 
80 QWidget * KActionMenu::createWidget( QWidget * _parent )
81 {
82  QToolBar *parent = qobject_cast<QToolBar *>(_parent);
83  if (!parent)
84  return KAction::createWidget(_parent);
85  QToolButton* button = new QToolButton(parent);
86  button->setAutoRaise(true);
87  button->setFocusPolicy(Qt::NoFocus);
88  button->setIconSize(parent->iconSize());
89  button->setToolButtonStyle(parent->toolButtonStyle());
90  QObject::connect(parent, SIGNAL(iconSizeChanged(QSize)),
91  button, SLOT(setIconSize(QSize)));
92  QObject::connect(parent, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)),
93  button, SLOT(setToolButtonStyle(Qt::ToolButtonStyle)));
94  button->setDefaultAction(this);
95  QObject::connect(button, SIGNAL(triggered(QAction*)), parent, SIGNAL(actionTriggered(QAction*)));
96 
97  if (delayed())
98  button->setPopupMode(QToolButton::DelayedPopup);
99  else if (stickyMenu())
100  button->setPopupMode(QToolButton::InstantPopup);
101  else
102  button->setPopupMode(QToolButton::MenuButtonPopup);
103 
104  return button;
105 }
106 
107 #ifndef KDE_NO_DEPRECATED
108 void KActionMenu::remove( KAction* cmd )
109 {
110  if ( cmd )
111  menu()->removeAction(cmd);
112 }
113 #endif
114 
115 void KActionMenu::addAction( QAction * action )
116 {
117  menu()->addAction(action);
118 }
119 
120 QAction* KActionMenu::addSeparator()
121 {
122  QAction* separator = new QAction(this);
123  separator->setSeparator(true);
124  addAction(separator);
125  return separator;
126 }
127 
128 QAction* KActionMenu::insertSeparator(QAction* before)
129 {
130  QAction* separator = new QAction(this);
131  separator->setSeparator(true);
132  insertAction(before, separator);
133  return separator;
134 }
135 
136 void KActionMenu::insertAction( QAction * before, QAction * action )
137 {
138  menu()->insertAction(before, action);
139 }
140 
141 void KActionMenu::removeAction( QAction * action )
142 {
143  menu()->removeAction(action);
144 }
145 
146 bool KActionMenu::delayed() const {
147  return d->m_delayed;
148 }
149 
150 void KActionMenu::setDelayed(bool _delayed) {
151  d->m_delayed = _delayed;
152 }
153 
154 bool KActionMenu::stickyMenu() const {
155  return d->m_stickyMenu;
156 }
157 
158 void KActionMenu::setStickyMenu(bool sticky) {
159  d->m_stickyMenu = sticky;
160 }
161 
162 KMenu* KActionMenu::menu()
163 {
164  if (!KAction::menu())
165  setMenu(new KMenu());
166 
167  return qobject_cast<KMenu*>(KAction::menu());
168 }
169 
170 void KActionMenu::setMenu(KMenu *menu)
171 {
172  KAction::setMenu( menu );
173 }
174 
175 /* vim: et sw=2 ts=2
176  */
177 
178 #include "kactionmenu.moc"
QAction::setText
void setText(const QString &text)
QWidget
KActionMenu::remove
void remove(KAction *)
Definition: kactionmenu.cpp:108
kdebug.h
QAction::setSeparator
void setSeparator(bool b)
KActionMenu::addAction
void addAction(QAction *action)
Definition: kactionmenu.cpp:115
QToolButton::setDefaultAction
void setDefaultAction(QAction *action)
QWidget::setFocusPolicy
void setFocusPolicy(Qt::FocusPolicy policy)
KMenu
A menu with keyboard searching.
Definition: kmenu.h:42
QMenu::addAction
void addAction(QAction *action)
QAction::setMenu
void setMenu(QMenu *menu)
KActionMenu::KActionMenu
KActionMenu(QObject *parent)
Definition: kactionmenu.cpp:52
klocale.h
QToolBar::toolButtonStyle
toolButtonStyle
KActionMenu::setStickyMenu
void setStickyMenu(bool sticky)
If set to true, this action will create a sticky popup menu when plugged in a KToolBar.
Definition: kactionmenu.cpp:158
QWidget::insertAction
void insertAction(QAction *before, QAction *action)
KAction::setShortcutConfigurable
void setShortcutConfigurable(bool configurable)
Indicate whether the user may configure the action's shortcut.
Definition: kaction.cpp:178
kmenu.h
QObject
QAbstractButton::setIconSize
void setIconSize(const QSize &size)
KActionMenu::insertSeparator
QAction * insertSeparator(QAction *before)
Definition: kactionmenu.cpp:128
KIcon
A wrapper around QIcon that provides KDE icon features.
Definition: kicon.h:40
kactionmenu.h
QString
KActionMenu::delayed
bool delayed() const
Returns true if this action creates a delayed popup menu when plugged in a KToolBar.
QToolButton::setAutoRaise
void setAutoRaise(bool enable)
KActionMenu::stickyMenu
bool stickyMenu() const
Returns true if this action creates a sticky popup menu.
KActionMenu::menu
KMenu * menu()
Returns this action's menu as a KMenu, if it is one.
Definition: kactionmenu.cpp:162
QToolButton
QSize
KActionMenu::createWidget
virtual QWidget * createWidget(QWidget *parent)
Definition: kactionmenu.cpp:80
KAction::triggered
void triggered(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
Emitted when the action is triggered.
KActionMenu::~KActionMenu
virtual ~KActionMenu()
Definition: kactionmenu.cpp:74
QWidgetAction::createWidget
virtual QWidget * createWidget(QWidget *parent)
KActionMenu::addSeparator
QAction * addSeparator()
Definition: kactionmenu.cpp:120
QAction
KAction
Class to encapsulate user-driven action or event.
Definition: kaction.h:216
KActionMenu::insertAction
void insertAction(QAction *before, QAction *action)
Definition: kactionmenu.cpp:136
QToolButton::setPopupMode
void setPopupMode(ToolButtonPopupMode mode)
QWidget::removeAction
void removeAction(QAction *action)
QToolBar
KActionMenu::removeAction
void removeAction(QAction *action)
Definition: kactionmenu.cpp:141
QToolBar::iconSize
iconSize
QAction::QAction
QAction(QObject *parent)
KActionMenu::setMenu
void setMenu(KMenu *menu)
Definition: kactionmenu.cpp:170
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QAction::menu
QMenu * menu() const
QObject::parent
QObject * parent() const
QToolButton::setToolButtonStyle
void setToolButtonStyle(Qt::ToolButtonStyle style)
KActionMenu::setDelayed
void setDelayed(bool delayed)
If set to true, this action will create a delayed popup menu when plugged in a KToolBar.
Definition: kactionmenu.cpp:150
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:23:58 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • 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

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal