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 DEVICEPROFILE_H
41 #define DEVICEPROFILE_H
42 
43 #include "shared_global_p.h"
44 
45 #include <QtCore/qstring.h>
46 #include <QtCore/qshareddata.h>
47 
48 QT_BEGIN_NAMESPACE
49 
50 class QDesignerFormEditorInterface;
51 class QWidget;
52 class QStyle;
53 
54 namespace qdesigner_internal {
55 
56 class DeviceProfileData;
57 
58 /* DeviceProfile for embedded design. They influence
59  * default properties (for example, fonts), dpi and
60  * style of the form. This class represents a device
61  * profile. */
62 
63 class QDESIGNER_SHARED_EXPORT DeviceProfile {
64 public:
65     DeviceProfile();
66 
67     DeviceProfile(const DeviceProfile&);
68     DeviceProfile& operator=(const DeviceProfile&);
69     ~DeviceProfile();
70 
71     void clear();
72 
73     // Device name
74     QString name() const;
75     void setName(const QString &);
76 
77     // System settings active
78     bool isEmpty() const;
79 
80     // Default font family of the embedded system
81     QString fontFamily() const;
82     void setFontFamily(const QString &);
83 
84     // Default font size of the embedded system
85     int fontPointSize() const;
86     void setFontPointSize(int p);
87 
88     // Display resolution of the embedded system
89     int dpiX() const;
90     void setDpiX(int d);
91     int dpiY() const;
92     void setDpiY(int d);
93 
94     // Style
95     QString style() const;
96     void setStyle(const QString &);
97 
98     // Initialize from desktop system
99     void fromSystem();
100 
101     static void systemResolution(int *dpiX, int *dpiY);
102     static void widgetResolution(const QWidget *w, int *dpiX, int *dpiY);
103 
104     bool equals(const DeviceProfile& rhs) const;
105 
106     // Apply to form/preview (using font inheritance)
107     enum ApplyMode {
108         /* Pre-Apply to parent widget of form being edited: Apply font
109          * and make use of property inheritance to be able to modify the
110          * font property freely. */
111         ApplyFormParent,
112         /* Post-Apply to preview widget: Change only inherited font
113          * sub properties. */
114         ApplyPreview
115     };
116     void apply(const QDesignerFormEditorInterface *core, QWidget *widget, ApplyMode am) const;
117 
118     static void applyDPI(int dpiX, int dpiY, QWidget *widget);
119 
120     QString toString() const;
121 
122     QString toXml() const;
123     bool fromXml(const QString &xml, QString *errorMessage);
124 
125 private:
126     QSharedDataPointer<DeviceProfileData> m_d;
127 };
128 
129 inline bool operator==(const DeviceProfile &s1, const DeviceProfile &s2)
130     { return s1.equals(s2); }
131 inline bool operator!=(const DeviceProfile &s1, const DeviceProfile &s2)
132     { return !s1.equals(s2); }
133 
134 }
135 
136 
137 QT_END_NAMESPACE
138 
139 #endif // DEVICEPROFILE_H
140