1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
3 | |
4 | // |
5 | // W A R N I N G |
6 | // ------------- |
7 | // |
8 | // This file is not part of the Qt API. It exists for the convenience |
9 | // of Qt Designer. This header |
10 | // file may change from version to version without notice, or even be removed. |
11 | // |
12 | // We mean it. |
13 | // |
14 | |
15 | #ifndef PREVIEWMANAGER_H |
16 | #define PREVIEWMANAGER_H |
17 | |
18 | #include "shared_global_p.h" |
19 | |
20 | #include <QtCore/qobject.h> |
21 | #include <QtCore/qstring.h> |
22 | #include <QtCore/qshareddata.h> |
23 | |
24 | QT_BEGIN_NAMESPACE |
25 | |
26 | class QDesignerFormWindowInterface; |
27 | class QWidget; |
28 | class QPixmap; |
29 | class QAction; |
30 | class QActionGroup; |
31 | class ; |
32 | class QWidget; |
33 | class QDesignerSettingsInterface; |
34 | |
35 | namespace qdesigner_internal { |
36 | |
37 | // ----------- PreviewConfiguration |
38 | |
39 | class PreviewConfigurationData; |
40 | |
41 | class QDESIGNER_SHARED_EXPORT PreviewConfiguration { |
42 | public: |
43 | PreviewConfiguration(); |
44 | explicit PreviewConfiguration(const QString &style, |
45 | const QString &applicationStyleSheet = QString(), |
46 | const QString &deviceSkin = QString()); |
47 | |
48 | PreviewConfiguration(const PreviewConfiguration&); |
49 | PreviewConfiguration& operator=(const PreviewConfiguration&); |
50 | ~PreviewConfiguration(); |
51 | |
52 | QString style() const; |
53 | void setStyle(const QString &); |
54 | |
55 | // Style sheet to prepend (to simulate the effect od QApplication::setSyleSheet()). |
56 | QString applicationStyleSheet() const; |
57 | void setApplicationStyleSheet(const QString &); |
58 | |
59 | QString deviceSkin() const; |
60 | void setDeviceSkin(const QString &); |
61 | |
62 | void clear(); |
63 | void toSettings(const QString &prefix, QDesignerSettingsInterface *settings) const; |
64 | void fromSettings(const QString &prefix, const QDesignerSettingsInterface *settings); |
65 | |
66 | private: |
67 | QSharedDataPointer<PreviewConfigurationData> m_d; |
68 | }; |
69 | |
70 | QDESIGNER_SHARED_EXPORT bool operator<(const PreviewConfiguration &pc1, const PreviewConfiguration &pc2); |
71 | QDESIGNER_SHARED_EXPORT bool operator==(const PreviewConfiguration &pc1, const PreviewConfiguration &pc2); |
72 | QDESIGNER_SHARED_EXPORT bool operator!=(const PreviewConfiguration &pc1, const PreviewConfiguration &pc2); |
73 | |
74 | // ----------- Preview window manager. |
75 | // Maintains a list of preview widgets with their associated form windows and configuration. |
76 | |
77 | class PreviewManagerPrivate; |
78 | |
79 | class QDESIGNER_SHARED_EXPORT PreviewManager : public QObject |
80 | { |
81 | Q_OBJECT |
82 | public: |
83 | |
84 | enum PreviewMode { |
85 | // Modal preview. Do not use on Macs as dialogs would have no close button |
86 | ApplicationModalPreview, |
87 | // Non modal previewing of one form in different configurations (closes if form window changes) |
88 | SingleFormNonModalPreview, |
89 | // Non modal previewing of several forms in different configurations |
90 | MultipleFormNonModalPreview }; |
91 | |
92 | explicit PreviewManager(PreviewMode mode, QObject *parent); |
93 | ~PreviewManager() override; |
94 | |
95 | // Show preview. Raise existing preview window if there is one with a matching |
96 | // configuration, else create a new preview. |
97 | QWidget *showPreview(const QDesignerFormWindowInterface *, const PreviewConfiguration &pc, int deviceProfileIndex /*=-1*/, QString *errorMessage); |
98 | // Convenience that creates a preview using a configuration taken from the settings. |
99 | QWidget *showPreview(const QDesignerFormWindowInterface *, const QString &style, int deviceProfileIndex /*=-1*/, QString *errorMessage); |
100 | QWidget *showPreview(const QDesignerFormWindowInterface *, const QString &style, QString *errorMessage); |
101 | |
102 | int previewCount() const; |
103 | |
104 | // Create a pixmap for printing. |
105 | QPixmap createPreviewPixmap(const QDesignerFormWindowInterface *fw, const PreviewConfiguration &pc, int deviceProfileIndex /*=-1*/, QString *errorMessage); |
106 | // Convenience that creates a pixmap using a configuration taken from the settings. |
107 | QPixmap createPreviewPixmap(const QDesignerFormWindowInterface *fw, const QString &style, int deviceProfileIndex /*=-1*/, QString *errorMessage); |
108 | QPixmap createPreviewPixmap(const QDesignerFormWindowInterface *fw, const QString &style, QString *errorMessage); |
109 | |
110 | bool eventFilter(QObject *watched, QEvent *event) override; |
111 | |
112 | public slots: |
113 | void closeAllPreviews(); |
114 | |
115 | signals: |
116 | void firstPreviewOpened(); |
117 | void lastPreviewClosed(); |
118 | |
119 | private slots: |
120 | void slotZoomChanged(int); |
121 | |
122 | private: |
123 | |
124 | virtual Qt::WindowFlags previewWindowFlags(const QWidget *widget) const; |
125 | virtual QWidget *createDeviceSkinContainer(const QDesignerFormWindowInterface *) const; |
126 | |
127 | QWidget *raise(const QDesignerFormWindowInterface *, const PreviewConfiguration &pc); |
128 | QWidget *createPreview(const QDesignerFormWindowInterface *, |
129 | const PreviewConfiguration &pc, |
130 | int deviceProfileIndex /* = -1 */, |
131 | QString *errorMessage, |
132 | /*Disabled by default, <0 */ |
133 | int initialZoom = -1); |
134 | |
135 | void updatePreviewClosed(QWidget *w); |
136 | |
137 | PreviewManagerPrivate *d; |
138 | |
139 | PreviewManager(const PreviewManager &other); |
140 | PreviewManager &operator =(const PreviewManager &other); |
141 | }; |
142 | } |
143 | |
144 | QT_END_NAMESPACE |
145 | |
146 | #endif // PREVIEWMANAGER_H |
147 | |