Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 andreas 1
/*
101 andreas 2
 * Copyright (C) 2020 to 2022 by Andreas Theofilu <andreas@theosys.at>
2 andreas 3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software Foundation,
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
17
 */
18
#ifndef __TQTMAIN_H__
19
#define __TQTMAIN_H__
20
 
21
#include <QMainWindow>
14 andreas 22
#include <QMetaType>
2 andreas 23
 
3 andreas 24
#include "tpagemanager.h"
5 andreas 25
#include "tobject.h"
61 andreas 26
#include "tqemitqueue.h"
2 andreas 27
 
21 andreas 28
extern bool prg_stopped;
34 andreas 29
extern std::atomic<bool> killed;
21 andreas 30
 
2 andreas 31
QT_BEGIN_NAMESPACE
32
class QAction;
33
class QMenu;
34
class QSessionManager;
5 andreas 35
class QLabel;
36
class QWidget;
14 andreas 37
class QByteArray;
10 andreas 38
class QMouseEvent;
15 andreas 39
class QMoveEvent;
190 andreas 40
class QGestureEvent;
15 andreas 41
class QEvent;
141 andreas 42
class QSound;
43
class QMediaPlayer;
181 andreas 44
#ifdef QT6_LINUX
45
class QAudioOutput;
46
#endif
23 andreas 47
class TQtSettings;
63 andreas 48
class TQKeyboard;
49
class TQKeypad;
120 andreas 50
class TQBusy;
179 andreas 51
class TqDownload;
140 andreas 52
class TQtPhone;
205 andreas 53
class QListWidgetItem;
2 andreas 54
QT_END_NAMESPACE
247 andreas 55
#ifdef Q_OS_IOS
56
class TIOSBattery;
57
#endif
2 andreas 58
 
14 andreas 59
Q_DECLARE_METATYPE(size_t)
60
 
3 andreas 61
int qtmain(int argc, char **argv, TPageManager *pmanager);
2 andreas 62
 
107 andreas 63
class MainWindow : public QMainWindow, TQManageQueue
2 andreas 64
{
14 andreas 65
    Q_OBJECT
2 andreas 66
 
5 andreas 67
    public:
88 andreas 68
        typedef enum J_ORIENTATION
69
        {
70
            O_UNDEFINED = -1,
71
            O_LANDSCAPE = 0,
130 andreas 72
            O_PORTRAIT = 1,
73
            O_REVERSE_LANDSCAPE = 8,
134 andreas 74
            O_REVERSE_PORTRAIT = 9,
75
            O_FACE_UP = 15,
76
            O_FACE_DOWN = 16
88 andreas 77
        }J_ORIENTATION;
78
 
5 andreas 79
        MainWindow();
34 andreas 80
        ~MainWindow();
22 andreas 81
        void setConfigFile(const std::string& file) { mFileConfig = file; }
23 andreas 82
        void setSetChange(bool state) { settingsChanged = state; }
38 andreas 83
        void setScaleFactor(double scale) { mScaleFactor = scale; }
198 andreas 84
        void setSetupScaleFactor(double scale) { mSetupScaleFactor = scale; }
38 andreas 85
        double getScaleFactor() { return mScaleFactor; }
2 andreas 86
 
14 andreas 87
    signals:
88
        void sigDisplayButton(ulong handle, ulong parent, QByteArray buffer, int width, int height, int pixline, int left, int top);
98 andreas 89
        void sigSetVisible(ulong handle, bool state);
14 andreas 90
        void sigSetPage(ulong handle, int width, int height);
217 andreas 91
        void sigSetSubPage(ulong handle, ulong parent, int left, int top, int width, int height, ANIMATION_t animate);
38 andreas 92
        void sigSetBackground(ulong handle, QByteArray image, size_t rowBytes, int width, int height, ulong color);
14 andreas 93
        void sigDropPage(ulong handle);
94
        void sigDropSubPage(ulong handle);
98 andreas 95
        void sigDropButton(ulong handle);
21 andreas 96
        void sigPlayVideo(ulong handle, ulong parent, int left, int top, int width, int height, const std::string& url, const std::string& user, const std::string& pw);
200 andreas 97
        void sigInputText(Button::TButton *button, QByteArray buffer, int width, int height, int frame, size_t pixline);
98
        void sigListBox(Button::TButton *button, QByteArray buffer, int width, int height, int frame, size_t pixline);
63 andreas 99
        void sigKeyboard(const std::string& init, const std::string& prompt, bool priv);
100
        void sigKeypad(const std::string& init, const std::string& prompt, bool priv);
101
        void sigResetKeyboard();
64 andreas 102
        void sigShowSetup();
71 andreas 103
        void sigPlaySound(const std::string& file);
141 andreas 104
        void sigStopSound();
105
        void sigMuteSound(bool state);
111 andreas 106
        void sigSendVirtualKeys(const std::string& str);
140 andreas 107
        void sigShowPhoneDialog(bool state);
108
        void sigSetPhoneNumber(const std::string& number);
109
        void sigSetPhoneStatus(const std::string& msg);
141 andreas 110
        void sigSetPhoneState(int state, int id);
142 andreas 111
        void sigRepaintWindows();
151 andreas 112
        void sigToFront(ulong handle);
206 andreas 113
        void sigDownloadSurface(const std::string& file, size_t size);
179 andreas 114
        void sigOnProgressChanged(int percent);
206 andreas 115
        void sigDisplayMessage(const std::string& msg, const std::string& title);
209 andreas 116
        void sigFileDialog(ulong handle, const std::string& path, const std::string& extension, const std::string& suffix);
197 andreas 117
#ifndef __ANDROID__
118
        void sigSetSizeMainWindow(int width, int height);
119
#endif
14 andreas 120
 
5 andreas 121
    protected:
57 andreas 122
        bool event(QEvent *event) override;
5 andreas 123
        void closeEvent(QCloseEvent *event) override;
10 andreas 124
        void mousePressEvent(QMouseEvent* event) override;
125
        void mouseReleaseEvent(QMouseEvent* event) override;
217 andreas 126
        bool eventFilter(QObject *, QEvent *ev) override;
2 andreas 127
 
5 andreas 128
    private slots:
129
        void settings();
130
        void about();
2 andreas 131
#ifndef QT_NO_SESSIONMANAGER
5 andreas 132
        void commitData(QSessionManager &);
2 andreas 133
#endif
14 andreas 134
        void displayButton(ulong handle, ulong parent, QByteArray buffer, int width, int height, int pixline, int left, int top);
98 andreas 135
        void SetVisible(ulong handle, bool state);
5 andreas 136
        void setPage(ulong handle, int width, int height);
217 andreas 137
        void setSubPage(ulong hanlde, ulong parent, int left, int top, int width, int height, ANIMATION_t animate);
38 andreas 138
        void setBackground(ulong handle, QByteArray image, size_t rowBytes, int width, int height, ulong color);
11 andreas 139
        void dropPage(ulong handle);
140
        void dropSubPage(ulong handle);
98 andreas 141
        void dropButton(ulong handle);
21 andreas 142
        void playVideo(ulong handle, ulong parent, int left, int top, int width, int height, const std::string& url, const std::string& user, const std::string& pw);
192 andreas 143
        void inputText(Button::TButton *button, QByteArray buffer, int width, int height, int frame, size_t pixline);
200 andreas 144
        void listBox(Button::TButton *button, QByteArray buffer, int width, int height, int frame, size_t pixline);
63 andreas 145
        void showKeyboard(const std::string& init, const std::string& prompt, bool priv);
146
        void showKeypad(const std::string& init, const std::string& prompt, bool priv);
111 andreas 147
        void sendVirtualKeys(const std::string& str);
63 andreas 148
        void resetKeyboard();
64 andreas 149
        void showSetup();
71 andreas 150
        void playSound(const std::string& file);
141 andreas 151
        void stopSound();
152
        void muteSound(bool state);
213 andreas 153
        void onAppStateChanged(Qt::ApplicationState state);
130 andreas 154
        void onScreenOrientationChanged(Qt::ScreenOrientation ori);
213 andreas 155
        void onTListCallbackCurrentItemChanged(QListWidgetItem *current, QListWidgetItem *previous);
247 andreas 156
#if not defined(Q_OS_ANDROID) && not defined(Q_OS_IOS)
197 andreas 157
        void setSizeMainWindow(int width, int height);
158
#endif
140 andreas 159
        // Slots for the phone dialog
160
        void showPhoneDialog(bool state);
161
        void setPhoneNumber(const std::string& number);
162
        void setPhoneStatus(const std::string& msg);
141 andreas 163
        void setPhoneState(int state, int id);
130 andreas 164
        // Slots for the toolbar buttons.
32 andreas 165
        void arrowLeft();
166
        void arrowRight();
167
        void arrowUp();
168
        void arrowDown();
169
        void selectOk();
33 andreas 170
        void volumeUpPressed();
171
        void volumeUpReleased();
172
        void volumeDownPressed();
173
        void volumeDownReleased();
38 andreas 174
//        void volumeMute();
130 andreas 175
        // Slots for widget actions and button element actions
42 andreas 176
        void animationFinished();
142 andreas 177
        void repaintWindows();
151 andreas 178
        void toFront(ulong handle);
206 andreas 179
        void downloadSurface(const std::string& file, size_t size);
180
        void displayMessage(const std::string& msg, const std::string& title);
209 andreas 181
        void fileDialog(ulong handle, const std::string& path, const std::string& extension, const std::string& suffix);
179 andreas 182
        // Progress bar (busy indicator)
183
        void onProgressChanged(int percent);
247 andreas 184
#ifdef Q_OS_IOS
185
        void onBatteryTimeout();
186
#endif
44 andreas 187
 
14 andreas 188
    private:
57 andreas 189
        bool gestureEvent(QGestureEvent *event);
14 andreas 190
        void createActions();
191
        void writeSettings();
31 andreas 192
        void playShowList();
38 andreas 193
        int scale(int value);
198 andreas 194
        int scaleSetup(int value);
208 andreas 195
        bool isScaled() { return (mScaleFactor > 0.0 && mScaleFactor != 1.0); }
198 andreas 196
        bool isSetupScaled();
107 andreas 197
        void startAnimation(TObject::OBJECT_t *obj, ANIMATION_t& ani, bool in = true);
179 andreas 198
        void downloadBar(const std::string& msg, QWidget *parent);
120 andreas 199
        void runEvents();
14 andreas 200
 
201
        void _displayButton(ulong handle, ulong parent, unsigned char* buffer, int width, int height, int pixline, int left, int top);
98 andreas 202
        void _setVisible(ulong handle, bool state);
14 andreas 203
        void _setPage(ulong handle, int width, int height);
217 andreas 204
        void _setSubPage(ulong handle, ulong parent, int left, int top, int width, int height, ANIMATION_t animate);
38 andreas 205
        void _setBackground(ulong handle, unsigned char *image, size_t size, size_t rowBytes, int width, int height, ulong color);
14 andreas 206
        void _dropPage(ulong handle);
207
        void _dropSubPage(ulong handle);
98 andreas 208
        void _dropButton(ulong handle);
21 andreas 209
        void _playVideo(ulong handle, ulong parent, int left, int top, int width, int height, const std::string& url, const std::string& user, const std::string& pw);
192 andreas 210
        void _inputText(Button::TButton *button, Button::BITMAP_t& bm, int frame);
200 andreas 211
        void _listBox(Button::TButton *button, Button::BITMAP_t& bm, int frame);
63 andreas 212
        void _showKeyboard(const std::string& init, const std::string& prompt, bool priv=false);
213
        void _showKeypad(const std::string& init, const std::string& prompt, bool priv=false);
214
        void _resetKeyboard();
64 andreas 215
        void _showSetup();
44 andreas 216
        void _resetSurface();
64 andreas 217
        void _shutdown();
71 andreas 218
        void _playSound(const std::string& file);
141 andreas 219
        void _stopSound();
220
        void _muteSound(bool state);
88 andreas 221
        void _setOrientation(J_ORIENTATION ori);
111 andreas 222
        void _sendVirtualKeys(const std::string& str);
140 andreas 223
        void _showPhoneDialog(bool state);
224
        void _setPhoneNumber(const std::string& number);
225
        void _setPhoneStatus(const std::string& msg);
141 andreas 226
        void _setPhoneState(int state, int id);
179 andreas 227
        void _onProgressChanged(int percent);
206 andreas 228
        void _displayMessage(const std::string& msg, const std::string& title);
209 andreas 229
        void _fileDialog(ulong handle, const std::string& path, const std::string& extension, const std::string& suffix);
197 andreas 230
#ifndef __ANDROID__
231
        void _setSizeMainWindow(int width, int height);
232
#endif
235 andreas 233
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
93 andreas 234
        void _signalState(Qt::ApplicationState state);
130 andreas 235
        void _orientationChanged(int orientation);
217 andreas 236
#ifdef QT5_LINUX
237
        void _freezeWorkaround();
238
#endif  // QT5_LINUX
239
#endif  // __ANDROID__
142 andreas 240
        void _repaintWindows();
151 andreas 241
        void _toFront(ulong handle);
206 andreas 242
        void _downloadSurface(const std::string& file, size_t size);
70 andreas 243
        void doReleaseButton();
142 andreas 244
        void repaintObjects();
141 andreas 245
        int calcVolume(int value);
224 andreas 246
        std::string convertMask(const std::string& mask);
70 andreas 247
 
142 andreas 248
        bool mWasInactive{false};           // If the application was inactive this is set to true until everything was repainted.
249
        bool mDoRepaint{false};             // This is set to TRUE whenever a reconnection to the controller happened.
23 andreas 250
        TQtSettings *mSettings{nullptr};    // The pointer to the settings dialog
22 andreas 251
        bool settingsChanged{false};        // true = settings have changed
218 andreas 252
 
88 andreas 253
        QToolBar *mToolbar{nullptr};        // The toolbar, if there is any
218 andreas 254
        QPixmap mBackground;                // The background pixmap
255
        QColor mBackgroundColor;            // The base background color
21 andreas 256
        std::string mVideoURL;              // If the button is a video, this is the URL where it plays from.
22 andreas 257
        std::string mFileConfig;            // Path and file name of the config file
31 andreas 258
        bool mHasFocus{true};               // If this is FALSE, no output to sceen is allowed.
38 andreas 259
        std::atomic<double> mScaleFactor{1.0}; // The actual scale factor
198 andreas 260
        std::atomic<double> mSetupScaleFactor{1.0};     // The scale factor for the setup pages
107 andreas 261
        std::atomic<TObject::OBJECT_t *> mLastObject{nullptr};     // This is for the hide effect of widgets.
213 andreas 262
        ulong mActualPageHandle{0};         // Holds the handle of the active page.
120 andreas 263
        std::atomic<bool> mBusy{false};     // If TRUE the busy indicator is active
179 andreas 264
        TqDownload *mDownloadBar{nullptr};  // Pointer to a dialog showing a progress bar
63 andreas 265
        TQKeyboard *mQKeyboard{nullptr};    // Pointer to an active virtual keyboard
266
        TQKeypad *mQKeypad{nullptr};        // Pointer to an active virtual keypad
120 andreas 267
//        std::thread mThreadBusy;            // The thread of the busy indicator.
65 andreas 268
        bool mKeyboard{false};              // TRUE = keyboard is visible
269
        bool mKeypad{false};                // TRUE = keypad is visible
140 andreas 270
        TQtPhone *mPhoneDialog{nullptr};    // Points to the internal phone dialog
70 andreas 271
        // Mouse
272
        int mLastPressX{-1};                // Remember the last mouse press X coordinate
273
        int mLastPressY{-1};                // Remember the last mouse press Y coordinate
130 andreas 274
        Qt::ScreenOrientations mOrientation{Qt::PrimaryOrientation};
141 andreas 275
        QMediaPlayer *mMediaPlayer{nullptr};// Class to play sound files.
181 andreas 276
#ifdef QT6_LINUX
277
        QAudioOutput *mAudioOutput{nullptr};
278
#endif
247 andreas 279
#ifdef Q_OS_IOS
280
        TIOSBattery *mIosBattery{nullptr};  // Class to retrive the battery status on an iPhone or iPad
281
        QTimer *mBatTimer{nullptr};         // Timer used to periodically get battery state
282
#endif
213 andreas 283
        std::chrono::steady_clock::time_point mTouchStart;  // Time in micro seconds of the start of a touch event
153 andreas 284
        int mTouchX{0};                        // The X coordinate of the mouse pointer
285
        int mTouchY{0};                        // The Y coordinate of the mouse pointer
2 andreas 286
};
287
 
288
#endif