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 //
30 //  W A R N I N G
31 //  -------------
32 //
33 // This file is not part of the Qt API.  It exists for the convenience
34 // of Qt Designer.  This header
35 // file may change from version to version without notice, or even be removed.
36 //
37 // We mean it.
38 //
39 
40 #ifndef PROMOTIONTASKMENU_H
41 #define PROMOTIONTASKMENU_H
42 
43 #include "shared_global_p.h"
44 
45 #include <QtCore/qobject.h>
46 #include <QtCore/qpointer.h>
47 #include <QtCore/qlist.h>
48 #include <QtCore/qvector.h>
49 
50 QT_BEGIN_NAMESPACE
51 
52 class QDesignerFormWindowInterface;
53 class QDesignerFormEditorInterface;
54 
55 class QAction;
56 class QMenu;
57 class QWidget;
58 
59 namespace qdesigner_internal {
60 
61 // A helper class for creating promotion context menus and handling promotion actions.
62 
63 class QDESIGNER_SHARED_EXPORT PromotionTaskMenu: public QObject
64 {
65     Q_OBJECT
66 public:
67     enum Mode {
68         ModeSingleWidget,
69         ModeManagedMultiSelection,
70         ModeUnmanagedMultiSelection
71     };
72 
73     explicit PromotionTaskMenu(QWidget *widget,Mode mode = ModeManagedMultiSelection, QObject *parent = nullptr);
74 
75     Mode mode() const;
76     void setMode(Mode m);
77 
78     void setWidget(QWidget *widget);
79 
80     // Set menu labels
81     void setPromoteLabel(const QString &promoteLabel);
82     void setEditPromoteToLabel(const QString &promoteEditLabel);
83     // Defaults to "Demote to %1".arg(class).
84     void setDemoteLabel(const QString &demoteLabel);
85 
86     using ActionList = QList<QAction *>;
87 
88     enum AddFlags { LeadingSeparator = 1, TrailingSeparator = 2, SuppressGlobalEdit = 4};
89 
90     // Adds a list of promotion actions according to the current promotion state of the widget.
91     void addActions(QDesignerFormWindowInterface *fw, unsigned flags, ActionList &actionList);
92     // Convenience that finds the form window.
93     void addActions(unsigned flags, ActionList &actionList);
94 
95     void addActions(QDesignerFormWindowInterface *fw, unsigned flags, QMenu *menu);
96     void addActions(unsigned flags, QMenu *menu);
97 
98     // Pop up the editor in a global context.
99     static void editPromotedWidgets(QDesignerFormEditorInterface *core, QWidget* parent);
100 
101 private slots:
102     void slotPromoteToCustomWidget(const QString &customClassName);
103     void slotDemoteFromCustomWidget();
104     void slotEditPromotedWidgets();
105     void slotEditPromoteTo();
106     void slotEditSignalsSlots();
107 
108 private:
109     void promoteTo(QDesignerFormWindowInterface *fw, const QString &customClassName);
110 
111     enum PromotionState { NotApplicable, NoHomogenousSelection, CanPromote, CanDemote };
112     PromotionState createPromotionActions(QDesignerFormWindowInterface *formWindow);
113     QDesignerFormWindowInterface *formWindow() const;
114 
115     using PromotionSelectionList = QVector<QPointer<QWidget> >;
116     PromotionSelectionList promotionSelectionList(QDesignerFormWindowInterface *formWindow) const;
117 
118     Mode m_mode;
119 
120     QPointer<QWidget> m_widget;
121 
122     // Per-Widget actions
123     QList<QAction *> m_promotionActions;
124 
125     QAction *m_globalEditAction;
126     QAction *m_EditPromoteToAction;
127     QAction *m_EditSignalsSlotsAction;
128 
129     QString m_promoteLabel;
130     QString m_demoteLabel;
131 };
132 
133 } // namespace qdesigner_internal
134 
135 QT_END_NAMESPACE
136 
137 #endif // PROMOTIONTASKMENU_H
138