| 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 tools applications of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 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 Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #ifndef SKIN_H |
| 41 | #define SKIN_H |
| 42 | |
| 43 | #include <QtWidgets/QWidget> |
| 44 | #include <QtGui/QPolygon> |
| 45 | #include <QtGui/QRegion> |
| 46 | #include <QtGui/QPixmap> |
| 47 | #include <QtCore/QVector> |
| 48 | |
| 49 | QT_BEGIN_NAMESPACE |
| 50 | |
| 51 | namespace qvfb_internal { |
| 52 | class CursorWindow; |
| 53 | } |
| 54 | |
| 55 | class QTextStream; |
| 56 | |
| 57 | // ------- Button Area |
| 58 | struct DeviceSkinButtonArea { |
| 59 | QString name; |
| 60 | int keyCode{0}; |
| 61 | QPolygon area; |
| 62 | QString text; |
| 63 | bool activeWhenClosed{false}; |
| 64 | bool toggleArea{false}; |
| 65 | bool toggleActiveArea{false}; |
| 66 | }; |
| 67 | |
| 68 | // -------- Parameters |
| 69 | struct DeviceSkinParameters { |
| 70 | enum ReadMode { ReadAll, ReadSizeOnly }; |
| 71 | bool read(const QString &skinDirectory, ReadMode rm, QString *errorMessage); |
| 72 | bool read(QTextStream &ts, ReadMode rm, QString *errorMessage); |
| 73 | |
| 74 | QSize screenSize() const { return screenRect.size(); } |
| 75 | QSize secondaryScreenSize() const; |
| 76 | bool hasSecondaryScreen() const; |
| 77 | |
| 78 | QString skinImageUpFileName; |
| 79 | QString skinImageDownFileName; |
| 80 | QString skinImageClosedFileName; |
| 81 | QString skinCursorFileName; |
| 82 | |
| 83 | QImage skinImageUp; |
| 84 | QImage skinImageDown; |
| 85 | QImage skinImageClosed; |
| 86 | QImage skinCursor; |
| 87 | |
| 88 | QRect screenRect; |
| 89 | QRect backScreenRect; |
| 90 | QRect closedScreenRect; |
| 91 | int screenDepth; |
| 92 | QPoint cursorHot; |
| 93 | QVector<DeviceSkinButtonArea> buttonAreas; |
| 94 | QList<int> toggleAreaList; |
| 95 | |
| 96 | int joystick; |
| 97 | QString prefix; |
| 98 | bool hasMouseHover; |
| 99 | }; |
| 100 | |
| 101 | // --------- Skin Widget |
| 102 | class DeviceSkin : public QWidget |
| 103 | { |
| 104 | Q_OBJECT |
| 105 | public: |
| 106 | explicit DeviceSkin(const DeviceSkinParameters ¶meters, QWidget *p ); |
| 107 | ~DeviceSkin( ); |
| 108 | |
| 109 | QWidget *view() const { return m_view; } |
| 110 | void setView( QWidget *v ); |
| 111 | |
| 112 | QWidget *secondaryView() const { return m_secondaryView; } |
| 113 | void setSecondaryView( QWidget *v ); |
| 114 | |
| 115 | void setZoom( double ); |
| 116 | void setTransform(const QTransform &); |
| 117 | |
| 118 | bool hasCursor() const; |
| 119 | |
| 120 | QString prefix() const {return m_parameters.prefix;} |
| 121 | |
| 122 | signals: |
| 123 | void (); |
| 124 | void skinKeyPressEvent(int code, const QString& text, bool autorep); |
| 125 | void skinKeyReleaseEvent(int code, const QString& text, bool autorep); |
| 126 | |
| 127 | protected slots: |
| 128 | void skinKeyRepeat(); |
| 129 | void moveParent(); |
| 130 | |
| 131 | protected: |
| 132 | void paintEvent(QPaintEvent *) override; |
| 133 | void mousePressEvent(QMouseEvent *e) override; |
| 134 | void mouseMoveEvent(QMouseEvent *e) override; |
| 135 | void mouseReleaseEvent(QMouseEvent *) override; |
| 136 | |
| 137 | private: |
| 138 | void calcRegions(); |
| 139 | void flip(bool open); |
| 140 | void updateSecondaryScreen(); |
| 141 | void loadImages(); |
| 142 | void startPress(int); |
| 143 | void endPress(); |
| 144 | |
| 145 | const DeviceSkinParameters m_parameters; |
| 146 | QVector<QRegion> buttonRegions; |
| 147 | QPixmap skinImageUp; |
| 148 | QPixmap skinImageDown; |
| 149 | QPixmap skinImageClosed; |
| 150 | QPixmap skinCursor; |
| 151 | QWidget *parent; |
| 152 | QWidget *m_view; |
| 153 | QWidget *m_secondaryView; |
| 154 | QPoint parentpos; |
| 155 | QPoint clickPos; |
| 156 | bool buttonPressed; |
| 157 | int buttonIndex; |
| 158 | QTransform transform; |
| 159 | qvfb_internal::CursorWindow *cursorw; |
| 160 | |
| 161 | bool joydown; |
| 162 | QTimer *t_skinkey; |
| 163 | QTimer *t_parentmove; |
| 164 | int onjoyrelease; |
| 165 | |
| 166 | bool flipped_open; |
| 167 | }; |
| 168 | |
| 169 | QT_END_NAMESPACE |
| 170 | |
| 171 | #endif |
| 172 | |