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 }
31 QToolButton::ToolButtonPopupMode m_popupMode = QToolButton::DelayedPopup;
32};
33
34KActionMenu::KActionMenu(QObject *parent)
35 : QWidgetAction(parent)
36 , d(new KActionMenuPrivate)
37{
38 setMenu(new QMenu);
39 setProperty(name: "isShortcutConfigurable", value: false);
40}
41
42KActionMenu::KActionMenu(const QString &text, QObject *parent)
43 : QWidgetAction(parent)
44 , d(new KActionMenuPrivate)
45{
46 setMenu(new QMenu);
47 setProperty(name: "isShortcutConfigurable", value: 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(name: "isShortcutConfigurable", value: false);
57 setIcon(icon);
58 setText(text);
59}
60
61KActionMenu::~KActionMenu()
62{
63 delete menu();
64}
65
66QWidget *KActionMenu::createWidget(QWidget *_parent)
67{
68 QToolBar *parent = qobject_cast<QToolBar *>(object: _parent);
69 if (!parent) {
70 return QWidgetAction::createWidget(parent: _parent);
71 }
72 QToolButton *button = new QToolButton(parent);
73 button->setAutoRaise(true);
74 button->setFocusPolicy(Qt::NoFocus);
75 button->setIconSize(parent->iconSize());
76 button->setToolButtonStyle(parent->toolButtonStyle());
77 QObject::connect(sender: parent, signal: &QToolBar::iconSizeChanged, context: button, slot: &QAbstractButton::setIconSize);
78 QObject::connect(sender: parent, signal: &QToolBar::toolButtonStyleChanged, context: button, slot: &QToolButton::setToolButtonStyle);
79 button->setDefaultAction(this);
80 button->setPopupMode(popupMode());
81 QObject::connect(sender: button, signal: &QToolButton::triggered, context: parent, slot: &QToolBar::actionTriggered);
82
83 return button;
84}
85
86void KActionMenu::addAction(QAction *action)
87{
88 menu()->addAction(action);
89}
90
91QAction *KActionMenu::addSeparator()
92{
93 QAction *separator = new QAction(this);
94 separator->setSeparator(true);
95 addAction(action: 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, action: 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
122void KActionMenu::setPopupMode(QToolButton::ToolButtonPopupMode popupMode)
123{
124 d->m_popupMode = popupMode;
125}
126
127#include "moc_kactionmenu.cpp"
128

source code of kwidgetsaddons/src/kactionmenu.cpp