Subversion Repositories tpanel

Rev

Rev 449 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
446 andreas 1
/*
2
 * Copyright (C) 2020 to 2023 by Andreas Theofilu <andreas@theosys.at>
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>
22
#include <QMetaType>
23
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
24
#include <QGeoPositionInfoSource>
25
#endif
26
#include "QMediaPlayer"
27
 
28
#include "tpagemanager.h"
29
#include "tobject.h"
30
//#include "tqemitqueue.h"
31
#include "tpagelist.h"
32
#include "tqgesturefilter.h"
458 andreas 33
#include "tqintercom.h"
446 andreas 34
 
35
extern bool prg_stopped;
36
extern std::atomic<bool> killed;
37
 
38
QT_BEGIN_NAMESPACE
39
class QAction;
40
class QMenu;
41
class QSessionManager;
42
class QLabel;
43
class QWidget;
44
class QByteArray;
45
class QMouseEvent;
46
class QMoveEvent;
47
class QGestureEvent;
48
class QEvent;
49
class QSound;
50
//class QMediaPlayer;
51
class QOrientationSensor;
52
class QStackedWidget;
53
class QListWidgetItem;
54
#ifdef Q_OS_IOS
55
class QGeoPositionInfo;
56
#endif
57
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
58
class QAudioOutput;
59
#endif
60
class TQtSettings;
61
class TQKeyboard;
62
class TQKeypad;
63
class TQBusy;
64
class TqDownload;
65
class TQtPhone;
66
class TBitmap;
67
class TQScrollArea;
68
QT_END_NAMESPACE
69
#ifdef Q_OS_IOS
70
class TIOSBattery;
71
class TIOSRotate;
72
#endif
73
class TQtWait;
74
 
75
Q_DECLARE_METATYPE(size_t)
76
 
77
int qtmain(int argc, char **argv, TPageManager *pmanager);
78
 
79
class MainWindow : public QMainWindow, public TObject
80
{
81
    Q_OBJECT
82
 
83
    public:
84
        typedef enum J_ORIENTATION
85
        {
86
            O_UNDEFINED = -1,
87
            O_LANDSCAPE = 0,
88
            O_PORTRAIT = 1,
89
            O_REVERSE_LANDSCAPE = 8,
90
            O_REVERSE_PORTRAIT = 9,
91
            O_FACE_UP = 15,
92
            O_FACE_DOWN = 16
93
        }J_ORIENTATION;
94
 
95
        MainWindow();
96
        ~MainWindow();
97
        void setConfigFile(const std::string& file) { mFileConfig = file; }
98
        void setSetChange(bool state) { settingsChanged = state; }
99
        void setScaleFactor(double scale) { mScaleFactor = scale; }
100
        double getScaleFactor() { return mScaleFactor; }
101
        void setOrientation(Qt::ScreenOrientation ori) { mOrientation = ori; }
102
        void disconnectArea(TQScrollArea *area);
103
        void disconnectList(QListWidget *list);
104
        void reconnectArea(TQScrollArea *area);
105
        void reconnectList(QListWidget *list);
106
#if defined(QT_DEBUG) && (defined(Q_OS_IOS) || defined(Q_OS_ANDROID))
107
        static std::string orientationToString(Qt::ScreenOrientation ori);
108
#endif
109
    signals:
110
        void sigDisplayButton(ulong handle, ulong parent, TBitmap buffer, int width, int height, int left, int top, bool passthrough, int marqtype, int marq);
111
        void sigSetMarqueeText(Button::TButton* button);
112
        void sigDisplayViewButton(ulong handle, ulong parent, bool vertical, TBitmap buffer, int width, int height, int left, int top, int space, TColor::COLOR_T fillColor);
113
        void sigAddViewButtonItems(ulong parent, std::vector<PGSUBVIEWITEM_T> items);
114
        void sigUpdateViewButton(ulong handle, ulong parent, TBitmap buffer, TColor::COLOR_T fillColor);
115
        void sigUpdateViewButtonItem(PGSUBVIEWITEM_T& item, ulong parent);
116
        void sigShowViewButtonItem(ulong handle, ulong parent, int position, int timer);
117
        void sigToggleViewButtonItem(ulong handle, ulong parent, int position, int timer);
118
        void sigHideAllViewItems(ulong handle);
119
        void sigHideViewItem(ulong handle, ulong parent);
120
        void sigSetSubViewPadding(ulong handle, int padding);
121
        void sigSetVisible(ulong handle, bool state);
122
        void sigSetPage(ulong handle, int width, int height);
123
        void sigSetSubPage(ulong handle, ulong parent, int left, int top, int width, int height, ANIMATION_t animate, bool modal);
124
#ifndef _OPAQUE_SKIA_
125
        void sigSetBackground(ulong handle, TBitmap image, int width, int height, ulong color, int opacity=255);
126
#else
127
        void sigSetBackground(ulong handle, TBitmap image, int width, int height, ulong color);
128
#endif
129
        void sigDropPage(ulong handle);
130
        void sigDropSubPage(ulong handle, ulong parent);
131
        void sigDropButton(ulong handle);
132
        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);
133
        void sigInputText(Button::TButton *button, QByteArray buffer, int width, int height, int frame, size_t pixline);
134
        void sigListBox(Button::TButton *button, QByteArray buffer, int width, int height, int frame, size_t pixline);
135
        void sigKeyboard(const std::string& init, const std::string& prompt, bool priv);
136
        void sigKeypad(const std::string& init, const std::string& prompt, bool priv);
137
        void sigResetKeyboard();
138
        void sigShowSetup();
139
        void sigPlaySound(const std::string& file);
140
        void sigStopSound();
141
        void sigMuteSound(bool state);
142
        void sigSetVolume(int volume);
143
        void sigSendVirtualKeys(const std::string& str);
144
        void sigShowPhoneDialog(bool state);
145
        void sigSetPhoneNumber(const std::string& number);
146
        void sigSetPhoneStatus(const std::string& msg);
147
        void sigSetPhoneState(int state, int id);
148
        void sigRepaintWindows();
149
        void sigToFront(ulong handle);
150
        void sigDownloadSurface(const std::string& file, size_t size);
151
        void sigOnProgressChanged(int percent);
152
        void sigDisplayMessage(const std::string& msg, const std::string& title);
153
        void sigAskPassword(ulong handle, const std::string& msg, const std::string& title, int x, int y);
154
        void sigFileDialog(ulong handle, const std::string& path, const std::string& extension, const std::string& suffix);
155
        void sigSetSizeMainWindow(int width, int height);
156
        void sigStartWait(const std::string& text);
157
        void sigStopWait();
158
        void sigPageFinished(uint handle);
159
        void sigListViewArea(ulong handle, ulong parent, Button::TButton& button, SUBVIEWLIST_T& list);
458 andreas 160
        void sigInitializeIntercom(INTERCOM_t ic);
161
        void sigIntercomStart();
162
        void sigIntercomStop();
163
        void sigIntercomSpkLevel(int level);
164
        void sigIintercomMicLevel(int level);
165
        void sigIntercomMicMute(bool mute);
446 andreas 166
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
167
        void sigActivateSettings(const std::string& oldNetlinx, int oldPort, int oldChannelID, const std::string& oldSurface, bool oldToolbarSuppress, bool oldToolbarForce);
168
#endif
169
    protected:
170
        bool event(QEvent *event) override;
171
        void closeEvent(QCloseEvent *event) override;
172
        void mousePressEvent(QMouseEvent* event) override;
173
        void mouseReleaseEvent(QMouseEvent* event) override;
174
        void mouseMoveEvent(QMouseEvent* event) override;
175
        void keyPressEvent(QKeyEvent *event) override;
176
        void keyReleaseEvent(QKeyEvent *event) override;
177
 
178
    private slots:
179
        void settings();
180
        void about();
181
#ifndef QT_NO_SESSIONMANAGER
182
        void commitData(QSessionManager &);
183
#endif
184
        void displayButton(ulong handle, ulong parent, TBitmap buffer, int width, int height, int left, int top, bool passthrough, int marqtype, int marq);
185
        void setMarqueeText(Button::TButton *button);
186
        void displayViewButton(ulong handle, ulong parent, bool vertical, TBitmap buffer, int width, int height, int left, int top, int space, TColor::COLOR_T fillColor);
187
        void addViewButtonItems(ulong parent, std::vector<PGSUBVIEWITEM_T> items);
188
        void updateViewButton(ulong handle, ulong parent, TBitmap buffer, TColor::COLOR_T fillColor);
189
        void updateViewButtonItem(PGSUBVIEWITEM_T& item, ulong parent);
190
        void showViewButtonItem(ulong handle, ulong parent, int position, int timer);
191
        void toggleViewButtonItem(ulong handle, ulong parent, int position, int timer);
192
        void hideAllViewItems(ulong handle);
193
        void hideViewItem(ulong handle, ulong parent);
194
        void setSubViewPadding(ulong handle, int padding);
195
        void SetVisible(ulong handle, bool state);
196
        void setPage(ulong handle, int width, int height);
197
        void setSubPage(ulong hanlde, ulong parent, int left, int top, int width, int height, ANIMATION_t animate, bool modal=false);
198
#ifdef _OPAQUE_SKIA_
199
        void setBackground(ulong handle, TBitmap image, int width, int height, ulong color);
200
#else
201
        void setBackground(ulong handle, TBitnap image, int width, int height, ulong color, int opacity=255);
202
#endif  // _OPAQUE_SKIA_
203
        void dropPage(ulong handle);
204
        void dropSubPage(ulong handle, ulong parent);
205
        void dropButton(ulong handle);
206
        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);
207
        void inputText(Button::TButton *button, QByteArray buffer, int width, int height, int frame, size_t pixline);
208
        void listBox(Button::TButton *button, QByteArray buffer, int width, int height, int frame, size_t pixline);
209
        void showKeyboard(const std::string& init, const std::string& prompt, bool priv);
210
        void showKeypad(const std::string& init, const std::string& prompt, bool priv);
211
        void sendVirtualKeys(const std::string& str);
212
        void resetKeyboard();
213
        void showSetup();
214
        void playSound(const std::string& file);
215
        void stopSound();
216
        void muteSound(bool state);
217
        void setVolume(int volume);
218
        void onAppStateChanged(Qt::ApplicationState state);
219
        void onScreenOrientationChanged(Qt::ScreenOrientation ori);
220
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
221
        void activateSettings(const std::string& oldNetlinx, int oldPort, int oldChannelID, const std::string& oldSurface, bool oldToolbarSuppress, bool oldToolbarForce);
222
#ifdef Q_OS_IOS
223
        void onPositionUpdated(const QGeoPositionInfo &update);
224
        void onErrorOccurred(QGeoPositionInfoSource::Error positioningError);
225
#endif  // Q_OS_IOS
226
#endif  // defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
227
        void onTListCallbackCurrentItemChanged(QListWidgetItem *current, QListWidgetItem *previous);
228
        void setSizeMainWindow(int width, int height);
229
        // Slots for the phone dialog
230
        void showPhoneDialog(bool state);
231
        void setPhoneNumber(const std::string& number);
232
        void setPhoneStatus(const std::string& msg);
233
        void setPhoneState(int state, int id);
234
        // Slots for the toolbar buttons.
235
        void arrowLeft();
236
        void arrowRight();
237
        void arrowUp();
238
        void arrowDown();
239
        void selectOk();
240
        void volumeUpPressed();
241
        void volumeUpReleased();
242
        void volumeDownPressed();
243
        void volumeDownReleased();
244
//        void volumeMute();
245
        // Slots for widget actions and button element actions
246
        void animationFinished();
247
        void animationInFinished();
248
        void repaintWindows();
249
        void toFront(ulong handle);
250
        void downloadSurface(const std::string& file, size_t size);
251
        void displayMessage(const std::string& msg, const std::string& title);
252
        void askPassword(ulong handle, const std::string msg, const std::string& title, int x, int y);
253
        void fileDialog(ulong handle, const std::string& path, const std::string& extension, const std::string& suffix);
254
        // Progress bar (busy indicator)
255
        void onProgressChanged(int percent);
256
        void startWait(const std::string& text);
257
        void stopWait();
258
        void pageFinished(ulong handle);
259
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
260
        void onPlayingChanged(bool plying);
261
#endif
262
        void onPlayerError(QMediaPlayer::Error error, const QString &errorString);
263
        void onMediaStatusChanged(QMediaPlayer::MediaStatus status);
458 andreas 264
        void initializeIntercom(INTERCOM_t ic);
265
        void intercomStart();
266
        void intercomStop();
267
        void intercomSpkLevel(int level);
268
        void intercomMicLevel(int level);
269
        void intercomMicMute(bool mute);
446 andreas 270
 
271
    private:
272
        bool gestureEvent(QGestureEvent *event);
273
        void createActions();
274
        void writeSettings();
275
//        void playShowList();
276
        int scale(int value);
277
        bool isScaled();
278
        bool startAnimation(TObject::OBJECT_t *obj, ANIMATION_t& ani, bool in = true);
279
        void downloadBar(const std::string& msg, QWidget *parent);
280
        void runEvents();
281
        void onSubViewItemClicked(ulong handle, bool pressed);
282
        void onInputChanged(ulong handle, std::string& text);
283
        void onFocusChanged(ulong handle, bool in);
284
        void onCursorChanged(ulong handle, int oldPos, int newPos);
285
        void onGestureEvent(QObject *obj, QGestureEvent *event);
286
        QPixmap scaleImage(QPixmap& pix);
287
        QPixmap scaleImage(unsigned char *buffer, int width, int height, int pixline);
288
 
289
        void _displayButton(ulong handle, ulong parent, TBitmap buffer, int width, int height, int left, int top, bool passthrough, int marqtype, int marq);
290
        void _setMarqueeText(Button::TButton *button);
291
        void _displayViewButton(ulong handle, ulong parent, bool vertical, TBitmap buffer, int width, int height, int left, int top, int space, TColor::COLOR_T fillColor);
292
        void _addViewButtonItems(ulong parent, std::vector<PGSUBVIEWITEM_T> items);
293
        void _updateViewButton(ulong handle, ulong parent, TBitmap buffer, TColor::COLOR_T fillColor);
294
        void _updateViewButtonItem(PGSUBVIEWITEM_T& item, ulong parent);
295
        void _showViewButtonItem(ulong handle, ulong parent, int position, int timer);
296
        void _toggleViewButtonItem(ulong handle, ulong parent, int position, int timer);
297
        void _hideAllViewItems(ulong handle);
298
        void _hideViewItem(ulong handle, ulong parent);
299
        void _setSubViewPadding(ulong handle, int padding);
300
        void _setVisible(ulong handle, bool state);
301
        void _setPage(ulong handle, int width, int height);
302
        void _setSubPage(ulong handle, ulong parent, int left, int top, int width, int height, ANIMATION_t animate, bool modal=false);
303
#ifdef _OPAQUE_SKIA_
304
        void _setBackground(ulong handle, TBitmap image, int width, int height, ulong color);
305
#else
306
        void _setBackground(ulong handle, TBitmap image, int width, int height, ulong color, int opacity=255);
307
#endif  // _OPAQUE_SKIA_
308
        void _dropPage(ulong handle);
309
        void _dropSubPage(ulong handle, ulong parent);
310
        void _dropButton(ulong handle);
311
        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);
312
        void _inputText(Button::TButton *button, Button::BITMAP_t& bm, int frame);
313
        void _listBox(Button::TButton *button, Button::BITMAP_t& bm, int frame);
314
        void _showKeyboard(const std::string& init, const std::string& prompt, bool priv=false);
315
        void _showKeypad(const std::string& init, const std::string& prompt, bool priv=false);
316
        void _resetKeyboard();
317
        void _showSetup();
318
        void _resetSurface();
319
        void _shutdown();
320
        void _playSound(const std::string& file);
321
        void _stopSound();
322
        void _muteSound(bool state);
323
        void _setVolume(int volume);
324
        void _setOrientation(J_ORIENTATION ori);
325
        void _sendVirtualKeys(const std::string& str);
326
        void _showPhoneDialog(bool state);
327
        void _setPhoneNumber(const std::string& number);
328
        void _setPhoneStatus(const std::string& msg);
329
        void _setPhoneState(int state, int id);
330
        void _onProgressChanged(int percent);
331
        void _displayMessage(const std::string& msg, const std::string& title);
332
        void _askPassword(ulong handle, const std::string& msg, const std::string& title, int x, int y);
333
        void _fileDialog(ulong handle, const std::string& path, const std::string& extension, const std::string& suffix);
334
        void _setSizeMainWindow(int width, int height);
335
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
336
        void _signalState(Qt::ApplicationState state);
337
        void _orientationChanged(int orientation);
338
        void _activateSettings(const std::string& oldNetlinx, int oldPort, int oldChannelID, const std::string& oldSurface, bool oldToolbarSuppress, bool oldToolbarForce);
339
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
340
        void _freezeWorkaround();
341
#endif  // QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
342
#endif  // defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
343
        void _repaintWindows();
344
        void _toFront(ulong handle);
345
        void _downloadSurface(const std::string& file, size_t size);
346
        void _startWait(const std::string& text);
347
        void _stopWait();
348
        void _pageFinished(uint handle);
349
        void _listViewArea(ulong handle, ulong parent, Button::TButton& button, SUBVIEWLIST_T& list);
458 andreas 350
        void _initializeIntercom(INTERCOM_t ic);
351
        void _intercomStart();
352
        void _intercomStop();
353
        void _intercomSpkLevel(int level);
354
        void _intercomMicLevel(int level);
355
        void _intercomMicMute(bool mute);
446 andreas 356
        void doReleaseButton();
357
        void repaintObjects();
358
        void refresh(ulong handle);
359
        void markDirty(ulong handle);
360
        QFont loadFont(int number, const FONT_T& f, const FONT_STYLE fs);
361
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
362
        int calcVolume(int value);
363
#else
364
        double calcVolume(int value);
365
#endif
366
        std::string convertMask(const std::string& mask);
367
#ifdef Q_OS_ANDROID
368
        void hideAndroidBars();
369
#endif  // Q_OS_ANDROID
370
#ifdef Q_OS_IOS
371
        void setNotch();
372
        void initGeoLocation();
373
        Qt::ScreenOrientation getRealOrientation();
374
#endif  // Q_OS_IOS
375
 
376
        std::mutex draw_mutex;              // We're using threads and need to block execution sometimes
377
        std::mutex click_mutex;
378
        std::mutex anim_mutex;
379
 
380
        bool mWasInactive{false};           // If the application was inactive this is set to true until everything was repainted.
381
        bool mDoRepaint{false};             // This is set to TRUE whenever a reconnection to the controller happened.
382
        TQtSettings *mSettings{nullptr};    // The pointer to the settings dialog
383
        bool settingsChanged{false};        // true = settings have changed
384
 
385
        QToolBar *mToolbar{nullptr};        // The toolbar, if there is any
386
        QStackedWidget *mCentralWidget{nullptr};        // A stacked widget where all pages are stored
387
        bool mCentralInitialized{false};    // True = The central widget and all dependencies are initialized
388
        std::string mVideoURL;              // If the button is a video, this is the URL where it plays from.
389
        std::string mFileConfig;            // Path and file name of the config file
390
        bool mHasFocus{true};               // If this is FALSE, no output to sceen is allowed.
391
        std::atomic<double> mScaleFactor{1.0}; // The actual scale factor
392
        OBJECT_t *mLastObject{nullptr};     // This is for the hide effect of widgets.
393
        std::map<ulong, OBJECT_t *> mAnimObjects;   // List of started animations
394
        ulong mActualPageHandle{0};         // Holds the handle of the active page.
395
        std::atomic<bool> mBusy{false};     // If TRUE the busy indicator is active
396
        TqDownload *mDownloadBar{nullptr};  // Pointer to a dialog showing a progress bar
397
        TQKeyboard *mQKeyboard{nullptr};    // Pointer to an active virtual keyboard
398
        TQKeypad *mQKeypad{nullptr};        // Pointer to an active virtual keypad
399
        bool mKeyboard{false};              // TRUE = keyboard is visible
400
        bool mKeypad{false};                // TRUE = keypad is visible
401
        TQtPhone *mPhoneDialog{nullptr};    // Points to the internal phone dialog
402
        // Mouse
403
        int mLastPressX{-1};                // Remember the last mouse press X coordinate
404
        int mLastPressY{-1};                // Remember the last mouse press Y coordinate
405
        Qt::ScreenOrientation mOrientation{Qt::PrimaryOrientation};
406
        QOrientationSensor *mSensor{nullptr};   // Basic sensor for orientation
407
        QMediaPlayer *mMediaPlayer{nullptr};// Class to play sound files.
408
        TQtWait *mWaitBox{nullptr};         // This is a wait dialog.
409
        TQGestureFilter *mGestureFilter{nullptr};   // This handles the pinch and swipe gestures
410
        std::atomic<bool>mRunRedraw{false};
411
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
412
        QGeoPositionInfoSource *mSource{nullptr};   // The geo location is used on IOS to keep app running in background
413
        QAudioOutput *mAudioOutput{nullptr};
414
#endif
415
#ifdef Q_OS_IOS
416
        TIOSBattery *mIosBattery{nullptr};  // Class to retrive the battery status on an iPhone or iPad
417
        TIOSRotate *mIosRotate{nullptr};    // Class to control rotation
418
        bool mIOSSettingsActive{false};     // TRUE: IOS settings are active.
419
        QMargins mNotchPortrait;            // The margins (notch, if any) for portrait orientation
420
        QMargins mNotchLandscape;           // The margins (notch, if any) for landscape orientation
421
        bool mHaveNotchPortrait{false};     // TRUE = Notch was already fetched for portrait orientation
422
        bool mHaveNotchLandscape{false};    // TRUE = Notch was already fetched for landscape orientation
423
        bool mGeoHavePermission{false};     // TRUE = The app has permission for geo location
424
#endif
425
        std::chrono::steady_clock::time_point mTouchStart;  // Time in micro seconds of the start of a touch event
426
        int mTouchX{0};                        // The X coordinate of the mouse pointer
427
        int mTouchY{0};                        // The Y coordinate of the mouse pointer
458 andreas 428
        TQIntercom mIntercom;               // Class to handle intercom connections
446 andreas 429
};
430
 
431
#endif