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 QDESIGNER_STACKEDBOX_H
41 #define QDESIGNER_STACKEDBOX_H
42 
43 #include "shared_global_p.h"
44 #include "qdesigner_propertysheet_p.h"
45 
46 QT_BEGIN_NAMESPACE
47 
48 class QStackedWidget;
49 class QWidget;
50 class QAction;
51 class QMenu;
52 class QToolButton;
53 
54 namespace qdesigner_internal {
55     class PromotionTaskMenu;
56 }
57 
58 // Event filter to be installed on a QStackedWidget in preview mode.
59 // Create two buttons to switch pages.
60 
61 class QDESIGNER_SHARED_EXPORT QStackedWidgetPreviewEventFilter : public QObject
62 {
63     Q_OBJECT
64 public:
65     explicit QStackedWidgetPreviewEventFilter(QStackedWidget *parent);
66 
67     // Install helper on QStackedWidget
68     static void install(QStackedWidget *stackedWidget);
69     bool eventFilter(QObject *watched, QEvent *event) override;
70 
setButtonToolTipEnabled(bool v)71     void setButtonToolTipEnabled(bool v) { m_buttonToolTipEnabled = v; }
buttonToolTipEnabled()72     bool buttonToolTipEnabled() const    { return m_buttonToolTipEnabled; }
73 
74 public slots:
75     void updateButtons();
76     void prevPage();
77     void nextPage();
78 
79 protected:
stackedWidget()80     QStackedWidget *stackedWidget() const { return m_stackedWidget; }
81     virtual void gotoPage(int page);
82 
83 private:
84     void updateButtonToolTip(QObject *o);
85 
86     bool m_buttonToolTipEnabled;
87     QStackedWidget *m_stackedWidget;
88     QToolButton *m_prev;
89     QToolButton *m_next;
90 };
91 
92 // Event filter to be installed on a QStackedWidget in editing mode.
93 //  In addition to the browse buttons, handles context menu and everything
94 
95 class QDESIGNER_SHARED_EXPORT QStackedWidgetEventFilter : public QStackedWidgetPreviewEventFilter
96 {
97     Q_OBJECT
98 public:
99     explicit QStackedWidgetEventFilter(QStackedWidget *parent);
100 
101     // Install helper on QStackedWidget
102     static void install(QStackedWidget *stackedWidget);
103     static QStackedWidgetEventFilter *eventFilterOf(const QStackedWidget *stackedWidget);
104     // Convenience to add a menu on a tackedWidget
105     static QMenu *addStackedWidgetContextMenuActions(const QStackedWidget *stackedWidget, QMenu *popup);
106 
107     // Add context menu and return page submenu or 0.
108     QMenu *addContextMenuActions(QMenu *popup);
109 
110 private slots:
111     void removeCurrentPage();
112     void addPage();
113     void addPageAfter();
114     void changeOrder();
115 
116 protected:
117     void gotoPage(int page) override;
118 
119 private:
120     QAction *m_actionPreviousPage;
121     QAction *m_actionNextPage;
122     QAction *m_actionDeletePage;
123     QAction *m_actionInsertPage;
124     QAction *m_actionInsertPageAfter;
125     QAction *m_actionChangePageOrder;
126     qdesigner_internal::PromotionTaskMenu* m_pagePromotionTaskMenu;
127 };
128 
129 // PropertySheet to handle the "currentPageName" property
130 class QDESIGNER_SHARED_EXPORT QStackedWidgetPropertySheet : public QDesignerPropertySheet {
131 public:
132     explicit QStackedWidgetPropertySheet(QStackedWidget *object, QObject *parent = nullptr);
133 
134     void setProperty(int index, const QVariant &value) override;
135     QVariant property(int index) const override;
136     bool reset(int index) override;
137     bool isEnabled(int index) const override;
138 
139     // Check whether the property is to be saved. Returns false for the page
140     // properties (as the property sheet has no concept of 'stored')
141     static bool checkProperty(const QString &propertyName);
142 
143 private:
144     QStackedWidget *m_stackedWidget;
145 };
146 
147 using QStackedWidgetPropertySheetFactory = QDesignerPropertySheetFactory<QStackedWidget, QStackedWidgetPropertySheet>;
148 
149 QT_END_NAMESPACE
150 
151 #endif // QDESIGNER_STACKEDBOX_H
152