1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef SKIN_H
5#define SKIN_H
6
7#include <QtWidgets/QWidget>
8
9#include <QtGui/QPixmap>
10#include <QtGui/QPolygon>
11#include <QtGui/QRegion>
12
13#include <QtCore/QList>
14
15QT_BEGIN_NAMESPACE
16
17namespace qvfb_internal {
18 class CursorWindow;
19}
20
21class QTextStream;
22
23// ------- Button Area
24struct DeviceSkinButtonArea {
25 QString name;
26 int keyCode{0};
27 QPolygon area;
28 QString text;
29 bool activeWhenClosed{false};
30 bool toggleArea{false};
31 bool toggleActiveArea{false};
32};
33
34// -------- Parameters
35struct DeviceSkinParameters {
36 enum ReadMode { ReadAll, ReadSizeOnly };
37 bool read(const QString &skinDirectory, ReadMode rm, QString *errorMessage);
38 bool read(QTextStream &ts, ReadMode rm, QString *errorMessage);
39
40 QSize screenSize() const { return screenRect.size(); }
41 QSize secondaryScreenSize() const;
42 bool hasSecondaryScreen() const;
43
44 QString skinImageUpFileName;
45 QString skinImageDownFileName;
46 QString skinImageClosedFileName;
47 QString skinCursorFileName;
48
49 QImage skinImageUp;
50 QImage skinImageDown;
51 QImage skinImageClosed;
52 QImage skinCursor;
53
54 QRect screenRect;
55 QRect backScreenRect;
56 QRect closedScreenRect;
57 int screenDepth;
58 QPoint cursorHot;
59 QList<DeviceSkinButtonArea> buttonAreas;
60 QList<int> toggleAreaList;
61
62 int joystick;
63 QString prefix;
64 bool hasMouseHover;
65};
66
67// --------- Skin Widget
68class DeviceSkin : public QWidget
69{
70 Q_OBJECT
71public:
72 explicit DeviceSkin(const DeviceSkinParameters &parameters, QWidget *p );
73 ~DeviceSkin( );
74
75 QWidget *view() const { return m_view; }
76 void setView( QWidget *v );
77
78 QWidget *secondaryView() const { return m_secondaryView; }
79 void setSecondaryView( QWidget *v );
80
81 void setZoom( double );
82 void setTransform(const QTransform &);
83
84 bool hasCursor() const;
85
86 QString prefix() const {return m_parameters.prefix;}
87
88signals:
89 void popupMenu();
90 void skinKeyPressEvent(int code, const QString& text, bool autorep);
91 void skinKeyReleaseEvent(int code, const QString& text, bool autorep);
92
93protected slots:
94 void skinKeyRepeat();
95 void moveParent();
96
97protected:
98 void paintEvent(QPaintEvent *) override;
99 void mousePressEvent(QMouseEvent *e) override;
100 void mouseMoveEvent(QMouseEvent *e) override;
101 void mouseReleaseEvent(QMouseEvent *) override;
102
103private:
104 void calcRegions();
105 void flip(bool open);
106 void updateSecondaryScreen();
107 void loadImages();
108 void startPress(int);
109 void endPress();
110
111 const DeviceSkinParameters m_parameters;
112 QList<QRegion> buttonRegions;
113 QPixmap skinImageUp;
114 QPixmap skinImageDown;
115 QPixmap skinImageClosed;
116 QPixmap skinCursor;
117 QWidget *parent;
118 QWidget *m_view;
119 QWidget *m_secondaryView;
120 QPoint parentpos;
121 QPoint clickPos;
122 bool buttonPressed;
123 int buttonIndex;
124 QTransform transform;
125 qvfb_internal::CursorWindow *cursorw;
126
127 bool joydown;
128 QTimer *t_skinkey;
129 QTimer *t_parentmove;
130 int onjoyrelease;
131
132 bool flipped_open;
133};
134
135QT_END_NAMESPACE
136
137#endif
138

source code of qttools/src/shared/deviceskin/deviceskin.h