1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Designer of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#ifndef BUTTON_TASKMENU_H
30#define BUTTON_TASKMENU_H
31
32#include <QtWidgets/qabstractbutton.h>
33#include <QtWidgets/qcommandlinkbutton.h>
34#include <QtWidgets/qbuttongroup.h>
35
36#include <qdesigner_taskmenu_p.h>
37#include <extensionfactory_p.h>
38
39QT_BEGIN_NAMESPACE
40
41class QMenu;
42class QActionGroup;
43class QDesignerFormWindowCursorInterface;
44
45namespace qdesigner_internal {
46
47// ButtonGroupMenu: Mixin menu for the 'select members'/'break group' options of
48// the task menu of buttons and button group
49class ButtonGroupMenu : public QObject
50{
51 Q_OBJECT
52 Q_DISABLE_COPY_MOVE(ButtonGroupMenu)
53public:
54 ButtonGroupMenu(QObject *parent = nullptr);
55
56 void initialize(QDesignerFormWindowInterface *formWindow,
57 QButtonGroup *buttonGroup = nullptr,
58 /* Current button for selection in ButtonMode */
59 QAbstractButton *currentButton = nullptr);
60
61 QAction *selectGroupAction() const { return m_selectGroupAction; }
62 QAction *breakGroupAction() const { return m_breakGroupAction; }
63
64private slots:
65 void selectGroup();
66 void breakGroup();
67
68private:
69 QAction *m_selectGroupAction;
70 QAction *m_breakGroupAction;
71
72 QDesignerFormWindowInterface *m_formWindow = nullptr;
73 QButtonGroup *m_buttonGroup = nullptr;
74 QAbstractButton *m_currentButton = nullptr;
75};
76
77// Task menu extension of a QButtonGroup
78class ButtonGroupTaskMenu : public QObject, public QDesignerTaskMenuExtension
79{
80 Q_OBJECT
81 Q_DISABLE_COPY_MOVE(ButtonGroupTaskMenu)
82 Q_INTERFACES(QDesignerTaskMenuExtension)
83public:
84 explicit ButtonGroupTaskMenu(QButtonGroup *buttonGroup, QObject *parent = nullptr);
85
86 QAction *preferredEditAction() const override;
87 QList<QAction*> taskActions() const override;
88
89private:
90 QButtonGroup *m_buttonGroup;
91 QList<QAction*> m_taskActions;
92 mutable ButtonGroupMenu m_menu;
93};
94
95// Task menu extension of a QAbstractButton
96class ButtonTaskMenu: public QDesignerTaskMenu
97{
98 Q_OBJECT
99 Q_DISABLE_COPY_MOVE(ButtonTaskMenu)
100public:
101 explicit ButtonTaskMenu(QAbstractButton *button, QObject *parent = nullptr);
102 ~ButtonTaskMenu() override;
103
104 QAction *preferredEditAction() const override;
105 QList<QAction*> taskActions() const override;
106
107 QAbstractButton *button() const;
108
109protected:
110 void insertAction(int index, QAction *a);
111
112private slots:
113 void createGroup();
114 void addToGroup(QAction *a);
115 void removeFromGroup();
116
117private:
118 enum SelectionType {
119 OtherSelection,
120 UngroupedButtonSelection,
121 GroupedButtonSelection
122 };
123
124 SelectionType selectionType(const QDesignerFormWindowCursorInterface *cursor, QButtonGroup ** ptrToGroup = nullptr) const;
125 bool refreshAssignMenu(const QDesignerFormWindowInterface *fw, int buttonCount, SelectionType st, QButtonGroup *currentGroup);
126 QMenu *createGroupSelectionMenu(const QDesignerFormWindowInterface *fw);
127
128 QList<QAction*> m_taskActions;
129 mutable ButtonGroupMenu m_groupMenu;
130 QMenu *m_assignGroupSubMenu;
131 QActionGroup *m_assignActionGroup;
132 QAction *m_assignToGroupSubMenuAction;
133 QMenu *m_currentGroupSubMenu;
134 QAction *m_currentGroupSubMenuAction;
135
136 QAction *m_createGroupAction;
137 QAction *m_preferredEditAction;
138 QAction *m_removeFromGroupAction;
139};
140
141// Task menu extension of a QCommandLinkButton
142class CommandLinkButtonTaskMenu: public ButtonTaskMenu
143{
144 Q_OBJECT
145 Q_DISABLE_COPY_MOVE(CommandLinkButtonTaskMenu)
146public:
147 explicit CommandLinkButtonTaskMenu(QCommandLinkButton *button, QObject *parent = nullptr);
148};
149
150using ButtonGroupTaskMenuFactory = ExtensionFactory<QDesignerTaskMenuExtension, QButtonGroup, ButtonGroupTaskMenu>;
151using CommandLinkButtonTaskMenuFactory = ExtensionFactory<QDesignerTaskMenuExtension, QCommandLinkButton, CommandLinkButtonTaskMenu>;
152using ButtonTaskMenuFactory = ExtensionFactory<QDesignerTaskMenuExtension, QAbstractButton, ButtonTaskMenu>;
153} // namespace qdesigner_internal
154
155QT_END_NAMESPACE
156
157#endif // BUTTON_TASKMENU_H
158

source code of qttools/src/designer/src/components/taskmenu/button_taskmenu.h