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 PREVIEWMANAGER_H
41#define PREVIEWMANAGER_H
42
43#include "shared_global_p.h"
44
45#include <QtCore/qobject.h>
46#include <QtCore/qstring.h>
47#include <QtCore/qshareddata.h>
48
49QT_BEGIN_NAMESPACE
50
51class QDesignerFormWindowInterface;
52class QWidget;
53class QPixmap;
54class QAction;
55class QActionGroup;
56class QMenu;
57class QWidget;
58class QDesignerSettingsInterface;
59
60namespace qdesigner_internal {
61
62// ----------- PreviewConfiguration
63
64class PreviewConfigurationData;
65
66class QDESIGNER_SHARED_EXPORT PreviewConfiguration {
67public:
68 PreviewConfiguration();
69 explicit PreviewConfiguration(const QString &style,
70 const QString &applicationStyleSheet = QString(),
71 const QString &deviceSkin = QString());
72
73 PreviewConfiguration(const PreviewConfiguration&);
74 PreviewConfiguration& operator=(const PreviewConfiguration&);
75 ~PreviewConfiguration();
76
77 QString style() const;
78 void setStyle(const QString &);
79
80 // Style sheet to prepend (to simulate the effect od QApplication::setSyleSheet()).
81 QString applicationStyleSheet() const;
82 void setApplicationStyleSheet(const QString &);
83
84 QString deviceSkin() const;
85 void setDeviceSkin(const QString &);
86
87 void clear();
88 void toSettings(const QString &prefix, QDesignerSettingsInterface *settings) const;
89 void fromSettings(const QString &prefix, const QDesignerSettingsInterface *settings);
90
91private:
92 QSharedDataPointer<PreviewConfigurationData> m_d;
93};
94
95QDESIGNER_SHARED_EXPORT bool operator<(const PreviewConfiguration &pc1, const PreviewConfiguration &pc2);
96QDESIGNER_SHARED_EXPORT bool operator==(const PreviewConfiguration &pc1, const PreviewConfiguration &pc2);
97QDESIGNER_SHARED_EXPORT bool operator!=(const PreviewConfiguration &pc1, const PreviewConfiguration &pc2);
98
99// ----------- Preview window manager.
100// Maintains a list of preview widgets with their associated form windows and configuration.
101
102class PreviewManagerPrivate;
103
104class QDESIGNER_SHARED_EXPORT PreviewManager : public QObject
105{
106 Q_OBJECT
107public:
108
109 enum PreviewMode {
110 // Modal preview. Do not use on Macs as dialogs would have no close button
111 ApplicationModalPreview,
112 // Non modal previewing of one form in different configurations (closes if form window changes)
113 SingleFormNonModalPreview,
114 // Non modal previewing of several forms in different configurations
115 MultipleFormNonModalPreview };
116
117 explicit PreviewManager(PreviewMode mode, QObject *parent);
118 ~PreviewManager() override;
119
120 // Show preview. Raise existing preview window if there is one with a matching
121 // configuration, else create a new preview.
122 QWidget *showPreview(const QDesignerFormWindowInterface *, const PreviewConfiguration &pc, int deviceProfileIndex /*=-1*/, QString *errorMessage);
123 // Convenience that creates a preview using a configuration taken from the settings.
124 QWidget *showPreview(const QDesignerFormWindowInterface *, const QString &style, int deviceProfileIndex /*=-1*/, QString *errorMessage);
125 QWidget *showPreview(const QDesignerFormWindowInterface *, const QString &style, QString *errorMessage);
126
127 int previewCount() const;
128
129 // Create a pixmap for printing.
130 QPixmap createPreviewPixmap(const QDesignerFormWindowInterface *fw, const PreviewConfiguration &pc, int deviceProfileIndex /*=-1*/, QString *errorMessage);
131 // Convenience that creates a pixmap using a configuration taken from the settings.
132 QPixmap createPreviewPixmap(const QDesignerFormWindowInterface *fw, const QString &style, int deviceProfileIndex /*=-1*/, QString *errorMessage);
133 QPixmap createPreviewPixmap(const QDesignerFormWindowInterface *fw, const QString &style, QString *errorMessage);
134
135 bool eventFilter(QObject *watched, QEvent *event) override;
136
137public slots:
138 void closeAllPreviews();
139
140signals:
141 void firstPreviewOpened();
142 void lastPreviewClosed();
143
144private slots:
145 void slotZoomChanged(int);
146
147private:
148
149 virtual Qt::WindowFlags previewWindowFlags(const QWidget *widget) const;
150 virtual QWidget *createDeviceSkinContainer(const QDesignerFormWindowInterface *) const;
151
152 QWidget *raise(const QDesignerFormWindowInterface *, const PreviewConfiguration &pc);
153 QWidget *createPreview(const QDesignerFormWindowInterface *,
154 const PreviewConfiguration &pc,
155 int deviceProfileIndex /* = -1 */,
156 QString *errorMessage,
157 /*Disabled by default, <0 */
158 int initialZoom = -1);
159
160 void updatePreviewClosed(QWidget *w);
161
162 PreviewManagerPrivate *d;
163
164 PreviewManager(const PreviewManager &other);
165 PreviewManager &operator =(const PreviewManager &other);
166};
167}
168
169QT_END_NAMESPACE
170
171#endif // PREVIEWMANAGER_H
172

source code of qttools/src/designer/src/lib/shared/previewmanager_p.h