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

KDEUI

  • 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
37class KActionMenuPrivate
38{
39public:
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
52KActionMenu::KActionMenu(QObject *parent)
53 : KAction(parent)
54 , d(new KActionMenuPrivate)
55{
56 setShortcutConfigurable( false );
57}
58
59KActionMenu::KActionMenu(const QString &text, QObject *parent)
60 : KAction(parent)
61 , d(new KActionMenuPrivate)
62{
63 setShortcutConfigurable( false );
64 setText(text);
65}
66
67KActionMenu::KActionMenu(const KIcon & icon, const QString & text, QObject *parent)
68 : KAction(icon, text, parent)
69 , d(new KActionMenuPrivate)
70{
71 setShortcutConfigurable( false );
72}
73
74KActionMenu::~KActionMenu()
75{
76 delete d;
77 delete menu();
78}
79
80QWidget * 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
108void KActionMenu::remove( KAction* cmd )
109{
110 if ( cmd )
111 menu()->removeAction(cmd);
112}
113#endif
114
115void KActionMenu::addAction( QAction * action )
116{
117 menu()->addAction(action);
118}
119
120QAction* KActionMenu::addSeparator()
121{
122 QAction* separator = new QAction(this);
123 separator->setSeparator(true);
124 addAction(separator);
125 return separator;
126}
127
128QAction* KActionMenu::insertSeparator(QAction* before)
129{
130 QAction* separator = new QAction(this);
131 separator->setSeparator(true);
132 insertAction(before, separator);
133 return separator;
134}
135
136void KActionMenu::insertAction( QAction * before, QAction * action )
137{
138 menu()->insertAction(before, action);
139}
140
141void KActionMenu::removeAction( QAction * action )
142{
143 menu()->removeAction(action);
144}
145
146bool KActionMenu::delayed() const {
147 return d->m_delayed;
148}
149
150void KActionMenu::setDelayed(bool _delayed) {
151 d->m_delayed = _delayed;
152}
153
154bool KActionMenu::stickyMenu() const {
155 return d->m_stickyMenu;
156}
157
158void KActionMenu::setStickyMenu(bool sticky) {
159 d->m_stickyMenu = sticky;
160}
161
162KMenu* KActionMenu::menu()
163{
164 if (!KAction::menu())
165 setMenu(new KMenu());
166
167 return qobject_cast<KMenu*>(KAction::menu());
168}
169
170void KActionMenu::setMenu(KMenu *menu)
171{
172 KAction::setMenu( menu );
173}
174
175/* vim: et sw=2 ts=2
176 */
177
178#include "kactionmenu.moc"
KActionMenu::insertAction
void insertAction(QAction *before, QAction *action)
Definition: kactionmenu.cpp:136
KActionMenu::insertSeparator
QAction * insertSeparator(QAction *before)
Definition: kactionmenu.cpp:128
KActionMenu::createWidget
virtual QWidget * createWidget(QWidget *parent)
Definition: kactionmenu.cpp:80
KActionMenu::KActionMenu
KActionMenu(QObject *parent)
Definition: kactionmenu.cpp:52
KActionMenu::setMenu
void setMenu(KMenu *menu)
Definition: kactionmenu.cpp:170
KActionMenu::removeAction
void removeAction(QAction *action)
Definition: kactionmenu.cpp:141
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
KActionMenu::addSeparator
QAction * addSeparator()
Definition: kactionmenu.cpp:120
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
KActionMenu::delayed
bool delayed
Definition: kactionmenu.h:50
KActionMenu::stickyMenu
bool stickyMenu
Definition: kactionmenu.h:51
KActionMenu::~KActionMenu
virtual ~KActionMenu()
Definition: kactionmenu.cpp:74
KActionMenu::menu
KMenu * menu()
Returns this action's menu as a KMenu, if it is one.
Definition: kactionmenu.cpp:162
KActionMenu::addAction
void addAction(QAction *action)
Definition: kactionmenu.cpp:115
KActionMenu::remove
void remove(KAction *)
Definition: kactionmenu.cpp:108
KAction
Class to encapsulate user-driven action or event.
Definition: kaction.h:217
KAction::triggered
void triggered(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
Emitted when the action is triggered.
KAction::setShortcutConfigurable
void setShortcutConfigurable(bool configurable)
Indicate whether the user may configure the action's shortcut.
Definition: kaction.cpp:178
KIcon
A wrapper around QIcon that provides KDE icon features.
Definition: kicon.h:41
KMenu
A menu with keyboard searching.
Definition: kmenu.h:42
QAction
QObject
QToolBar
QToolButton
QWidget
kactionmenu.h
kdebug.h
klocale.h
kmenu.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 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
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