KWidgetsAddons

kactionmenu.cpp
1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 1999 Reginald Stadlbauer <reggie@kde.org>
4 SPDX-FileCopyrightText: 1999 Simon Hausmann <hausmann@kde.org>
5 SPDX-FileCopyrightText: 2000 Nicolas Hadacek <haadcek@kde.org>
6 SPDX-FileCopyrightText: 2000 Kurt Granroth <granroth@kde.org>
7 SPDX-FileCopyrightText: 2000 Michael Koch <koch@kde.org>
8 SPDX-FileCopyrightText: 2001 Holger Freyther <freyther@kde.org>
9 SPDX-FileCopyrightText: 2002 Ellis Whitehead <ellis@kde.org>
10 SPDX-FileCopyrightText: 2002 Joseph Wenninger <jowenn@kde.org>
11 SPDX-FileCopyrightText: 2003 Andras Mantia <amantia@kde.org>
12 SPDX-FileCopyrightText: 2005-2006 Hamish Rodda <rodda@kde.org>
13
14 SPDX-License-Identifier: LGPL-2.0-only
15*/
16
17#include "kactionmenu.h"
18
19#include <QMenu>
20#include <QToolBar>
21
22class KActionMenuPrivate
23{
24public:
25 KActionMenuPrivate()
26 {
27 }
28 ~KActionMenuPrivate()
29 {
30 }
32};
33
34KActionMenu::KActionMenu(QObject *parent)
35 : QWidgetAction(parent)
36 , d(new KActionMenuPrivate)
37{
38 setMenu(new QMenu);
39 setProperty("isShortcutConfigurable", false);
40}
41
42KActionMenu::KActionMenu(const QString &text, QObject *parent)
43 : QWidgetAction(parent)
44 , d(new KActionMenuPrivate)
45{
46 setMenu(new QMenu);
47 setProperty("isShortcutConfigurable", false);
48 setText(text);
49}
50
51KActionMenu::KActionMenu(const QIcon &icon, const QString &text, QObject *parent)
52 : QWidgetAction(parent)
53 , d(new KActionMenuPrivate)
54{
55 setMenu(new QMenu);
56 setProperty("isShortcutConfigurable", false);
57 setIcon(icon);
58 setText(text);
59}
60
61KActionMenu::~KActionMenu()
62{
63 delete menu();
64}
65
66QWidget *KActionMenu::createWidget(QWidget *_parent)
67{
69 if (!parent) {
70 return QWidgetAction::createWidget(_parent);
71 }
72 QToolButton *button = new QToolButton(parent);
73 button->setAutoRaise(true);
75 button->setIconSize(parent->iconSize());
76 button->setToolButtonStyle(parent->toolButtonStyle());
79 button->setDefaultAction(this);
80 button->setPopupMode(popupMode());
82
83 return button;
84}
85
87{
88 menu()->addAction(action);
89}
90
91QAction *KActionMenu::addSeparator()
92{
93 QAction *separator = new QAction(this);
94 separator->setSeparator(true);
95 addAction(separator);
96 return separator;
97}
98
99QAction *KActionMenu::insertSeparator(QAction *before)
100{
101 QAction *separator = new QAction(this);
102 separator->setSeparator(true);
103 insertAction(before, separator);
104 return separator;
105}
106
107void KActionMenu::insertAction(QAction *before, QAction *action)
108{
109 menu()->insertAction(before, action);
110}
111
112void KActionMenu::removeAction(QAction *action)
113{
114 menu()->removeAction(action);
115}
116
117QToolButton::ToolButtonPopupMode KActionMenu::popupMode() const
118{
119 return d->m_popupMode;
120}
121
123{
124 d->m_popupMode = popupMode;
125}
126
127#include "moc_kactionmenu.cpp"
void setPopupMode(QToolButton::ToolButtonPopupMode popupMode)
Determines the popup mode when plugged in a KToolBar.
void addAction(QAction *action)
Adds action to this KActionMenu.
QCA_EXPORT void setProperty(const QString &name, const QVariant &value)
void setIconSize(const QSize &size)
QAction(QObject *parent)
QMenu * menu() const const
void setSeparator(bool b)
QAction * addAction(const QIcon &icon, const QString &text, Functor functor, const QKeySequence &shortcut)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
T qobject_cast(QObject *object)
void actionTriggered(QAction *action)
void iconSizeChanged(const QSize &iconSize)
void toolButtonStyleChanged(Qt::ToolButtonStyle toolButtonStyle)
void setAutoRaise(bool enable)
void setPopupMode(ToolButtonPopupMode mode)
void setDefaultAction(QAction *action)
void setToolButtonStyle(Qt::ToolButtonStyle style)
void triggered(QAction *action)
void setFocusPolicy(Qt::FocusPolicy policy)
void insertAction(QAction *before, QAction *action)
void removeAction(QAction *action)
virtual QWidget * createWidget(QWidget *parent)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:19:04 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.