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
55
 
14 andreas 56
Q_DECLARE_METATYPE(size_t)
57
 
3 andreas 58
int qtmain(int argc, char **argv, TPageManager *pmanager);
2 andreas 59
 
107 andreas 60
class MainWindow : public QMainWindow, TQManageQueue
2 andreas 61
{
14 andreas 62
    Q_OBJECT
2 andreas 63
 
5 andreas 64
    public:
88 andreas 65
        typedef enum J_ORIENTATION
66
        {
67
            O_UNDEFINED = -1,
68
            O_LANDSCAPE = 0,
130 andreas 69
            O_PORTRAIT = 1,
70
            O_REVERSE_LANDSCAPE = 8,
134 andreas 71
            O_REVERSE_PORTRAIT = 9,
72
            O_FACE_UP = 15,
73
            O_FACE_DOWN = 16
88 andreas 74
        }J_ORIENTATION;
75
 
5 andreas 76
        MainWindow();
34 andreas 77
        ~MainWindow();
22 andreas 78
        void setConfigFile(const std::string& file) { mFileConfig = file; }
23 andreas 79
        void setSetChange(bool state) { settingsChanged = state; }
38 andreas 80
        void setScaleFactor(double scale) { mScaleFactor = scale; }
198 andreas 81
        void setSetupScaleFactor(double scale) { mSetupScaleFactor = scale; }
38 andreas 82
        double getScaleFactor() { return mScaleFactor; }
2 andreas 83
 
14 andreas 84
    signals:
85
        void sigDisplayButton(ulong handle, ulong parent, QByteArray buffer, int width, int height, int pixline, int left, int top);
98 andreas 86
        void sigSetVisible(ulong handle, bool state);
14 andreas 87
        void sigSetPage(ulong handle, int width, int height);
217 andreas 88
        void sigSetSubPage(ulong handle, ulong parent, int left, int top, int width, int height, ANIMATION_t animate);
38 andreas 89
        void sigSetBackground(ulong handle, QByteArray image, size_t rowBytes, int width, int height, ulong color);
14 andreas 90
        void sigDropPage(ulong handle);
91
        void sigDropSubPage(ulong handle);
98 andreas 92
        void sigDropButton(ulong handle);
21 andreas 93
        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 94
        void sigInputText(Button::TButton *button, QByteArray buffer, int width, int height, int frame, size_t pixline);
95
        void sigListBox(Button::TButton *button, QByteArray buffer, int width, int height, int frame, size_t pixline);
63 andreas 96
        void sigKeyboard(const std::string& init, const std::string& prompt, bool priv);
97
        void sigKeypad(const std::string& init, const std::string& prompt, bool priv);
98
        void sigResetKeyboard();
64 andreas 99
        void sigShowSetup();
71 andreas 100
        void sigPlaySound(const std::string& file);
141 andreas 101
        void sigStopSound();
102
        void sigMuteSound(bool state);
111 andreas 103
        void sigSendVirtualKeys(const std::string& str);
140 andreas 104
        void sigShowPhoneDialog(bool state);
105
        void sigSetPhoneNumber(const std::string& number);
106
        void sigSetPhoneStatus(const std::string& msg);
141 andreas 107
        void sigSetPhoneState(int state, int id);
142 andreas 108
        void sigRepaintWindows();
151 andreas 109
        void sigToFront(ulong handle);
206 andreas 110
        void sigDownloadSurface(const std::string& file, size_t size);
179 andreas 111
        void sigOnProgressChanged(int percent);
206 andreas 112
        void sigDisplayMessage(const std::string& msg, const std::string& title);
209 andreas 113
        void sigFileDialog(ulong handle, const std::string& path, const std::string& extension, const std::string& suffix);
197 andreas 114
#ifndef __ANDROID__
115
        void sigSetSizeMainWindow(int width, int height);
116
#endif
14 andreas 117
 
5 andreas 118
    protected:
57 andreas 119
        bool event(QEvent *event) override;
5 andreas 120
        void closeEvent(QCloseEvent *event) override;
10 andreas 121
        void mousePressEvent(QMouseEvent* event) override;
122
        void mouseReleaseEvent(QMouseEvent* event) override;
217 andreas 123
        bool eventFilter(QObject *, QEvent *ev) override;
2 andreas 124
 
5 andreas 125
    private slots:
126
        void settings();
127
        void about();
2 andreas 128
#ifndef QT_NO_SESSIONMANAGER
5 andreas 129
        void commitData(QSessionManager &);
2 andreas 130
#endif
14 andreas 131
        void displayButton(ulong handle, ulong parent, QByteArray buffer, int width, int height, int pixline, int left, int top);
98 andreas 132
        void SetVisible(ulong handle, bool state);
5 andreas 133
        void setPage(ulong handle, int width, int height);
217 andreas 134
        void setSubPage(ulong hanlde, ulong parent, int left, int top, int width, int height, ANIMATION_t animate);
38 andreas 135
        void setBackground(ulong handle, QByteArray image, size_t rowBytes, int width, int height, ulong color);
11 andreas 136
        void dropPage(ulong handle);
137
        void dropSubPage(ulong handle);
98 andreas 138
        void dropButton(ulong handle);
21 andreas 139
        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 140
        void inputText(Button::TButton *button, QByteArray buffer, int width, int height, int frame, size_t pixline);
200 andreas 141
        void listBox(Button::TButton *button, QByteArray buffer, int width, int height, int frame, size_t pixline);
63 andreas 142
        void showKeyboard(const std::string& init, const std::string& prompt, bool priv);
143
        void showKeypad(const std::string& init, const std::string& prompt, bool priv);
111 andreas 144
        void sendVirtualKeys(const std::string& str);
63 andreas 145
        void resetKeyboard();
64 andreas 146
        void showSetup();
71 andreas 147
        void playSound(const std::string& file);
141 andreas 148
        void stopSound();
149
        void muteSound(bool state);
213 andreas 150
        void onAppStateChanged(Qt::ApplicationState state);
130 andreas 151
        void onScreenOrientationChanged(Qt::ScreenOrientation ori);
213 andreas 152
        void onTListCallbackCurrentItemChanged(QListWidgetItem *current, QListWidgetItem *previous);
197 andreas 153
#ifndef __ANDROID__
154
        void setSizeMainWindow(int width, int height);
155
#endif
140 andreas 156
        // Slots for the phone dialog
157
        void showPhoneDialog(bool state);
158
        void setPhoneNumber(const std::string& number);
159
        void setPhoneStatus(const std::string& msg);
141 andreas 160
        void setPhoneState(int state, int id);
130 andreas 161
        // Slots for the toolbar buttons.
32 andreas 162
        void arrowLeft();
163
        void arrowRight();
164
        void arrowUp();
165
        void arrowDown();
166
        void selectOk();
33 andreas 167
        void volumeUpPressed();
168
        void volumeUpReleased();
169
        void volumeDownPressed();
170
        void volumeDownReleased();
38 andreas 171
//        void volumeMute();
130 andreas 172
        // Slots for widget actions and button element actions
42 andreas 173
        void animationFinished();
142 andreas 174
        void repaintWindows();
151 andreas 175
        void toFront(ulong handle);
206 andreas 176
        void downloadSurface(const std::string& file, size_t size);
177
        void displayMessage(const std::string& msg, const std::string& title);
209 andreas 178
        void fileDialog(ulong handle, const std::string& path, const std::string& extension, const std::string& suffix);
179 andreas 179
        // Progress bar (busy indicator)
180
        void onProgressChanged(int percent);
44 andreas 181
 
14 andreas 182
    private:
57 andreas 183
        bool gestureEvent(QGestureEvent *event);
14 andreas 184
        void createActions();
185
        void writeSettings();
31 andreas 186
        void playShowList();
38 andreas 187
        int scale(int value);
198 andreas 188
        int scaleSetup(int value);
208 andreas 189
        bool isScaled() { return (mScaleFactor > 0.0 && mScaleFactor != 1.0); }
198 andreas 190
        bool isSetupScaled();
107 andreas 191
        void startAnimation(TObject::OBJECT_t *obj, ANIMATION_t& ani, bool in = true);
179 andreas 192
        void downloadBar(const std::string& msg, QWidget *parent);
120 andreas 193
        void runEvents();
14 andreas 194
 
195
        void _displayButton(ulong handle, ulong parent, unsigned char* buffer, int width, int height, int pixline, int left, int top);
98 andreas 196
        void _setVisible(ulong handle, bool state);
14 andreas 197
        void _setPage(ulong handle, int width, int height);
217 andreas 198
        void _setSubPage(ulong handle, ulong parent, int left, int top, int width, int height, ANIMATION_t animate);
38 andreas 199
        void _setBackground(ulong handle, unsigned char *image, size_t size, size_t rowBytes, int width, int height, ulong color);
14 andreas 200
        void _dropPage(ulong handle);
201
        void _dropSubPage(ulong handle);
98 andreas 202
        void _dropButton(ulong handle);
21 andreas 203
        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 204
        void _inputText(Button::TButton *button, Button::BITMAP_t& bm, int frame);
200 andreas 205
        void _listBox(Button::TButton *button, Button::BITMAP_t& bm, int frame);
63 andreas 206
        void _showKeyboard(const std::string& init, const std::string& prompt, bool priv=false);
207
        void _showKeypad(const std::string& init, const std::string& prompt, bool priv=false);
208
        void _resetKeyboard();
64 andreas 209
        void _showSetup();
44 andreas 210
        void _resetSurface();
64 andreas 211
        void _shutdown();
71 andreas 212
        void _playSound(const std::string& file);
141 andreas 213
        void _stopSound();
214
        void _muteSound(bool state);
88 andreas 215
        void _setOrientation(J_ORIENTATION ori);
111 andreas 216
        void _sendVirtualKeys(const std::string& str);
140 andreas 217
        void _showPhoneDialog(bool state);
218
        void _setPhoneNumber(const std::string& number);
219
        void _setPhoneStatus(const std::string& msg);
141 andreas 220
        void _setPhoneState(int state, int id);
179 andreas 221
        void _onProgressChanged(int percent);
206 andreas 222
        void _displayMessage(const std::string& msg, const std::string& title);
209 andreas 223
        void _fileDialog(ulong handle, const std::string& path, const std::string& extension, const std::string& suffix);
197 andreas 224
#ifndef __ANDROID__
225
        void _setSizeMainWindow(int width, int height);
226
#endif
235 andreas 227
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
93 andreas 228
        void _signalState(Qt::ApplicationState state);
130 andreas 229
        void _orientationChanged(int orientation);
217 andreas 230
#ifdef QT5_LINUX
231
        void _freezeWorkaround();
232
#endif  // QT5_LINUX
233
#endif  // __ANDROID__
142 andreas 234
        void _repaintWindows();
151 andreas 235
        void _toFront(ulong handle);
206 andreas 236
        void _downloadSurface(const std::string& file, size_t size);
70 andreas 237
        void doReleaseButton();
142 andreas 238
        void repaintObjects();
141 andreas 239
        int calcVolume(int value);
224 andreas 240
        std::string convertMask(const std::string& mask);
70 andreas 241
 
142 andreas 242
        bool mWasInactive{false};           // If the application was inactive this is set to true until everything was repainted.
243
        bool mDoRepaint{false};             // This is set to TRUE whenever a reconnection to the controller happened.
23 andreas 244
        TQtSettings *mSettings{nullptr};    // The pointer to the settings dialog
22 andreas 245
        bool settingsChanged{false};        // true = settings have changed
218 andreas 246
 
88 andreas 247
        QToolBar *mToolbar{nullptr};        // The toolbar, if there is any
218 andreas 248
        QPixmap mBackground;                // The background pixmap
249
        QColor mBackgroundColor;            // The base background color
21 andreas 250
        std::string mVideoURL;              // If the button is a video, this is the URL where it plays from.
22 andreas 251
        std::string mFileConfig;            // Path and file name of the config file
31 andreas 252
        bool mHasFocus{true};               // If this is FALSE, no output to sceen is allowed.
38 andreas 253
        std::atomic<double> mScaleFactor{1.0}; // The actual scale factor
198 andreas 254
        std::atomic<double> mSetupScaleFactor{1.0};     // The scale factor for the setup pages
107 andreas 255
        std::atomic<TObject::OBJECT_t *> mLastObject{nullptr};     // This is for the hide effect of widgets.
213 andreas 256
        ulong mActualPageHandle{0};         // Holds the handle of the active page.
120 andreas 257
        std::atomic<bool> mBusy{false};     // If TRUE the busy indicator is active
179 andreas 258
        TqDownload *mDownloadBar{nullptr};  // Pointer to a dialog showing a progress bar
63 andreas 259
        TQKeyboard *mQKeyboard{nullptr};    // Pointer to an active virtual keyboard
260
        TQKeypad *mQKeypad{nullptr};        // Pointer to an active virtual keypad
120 andreas 261
//        std::thread mThreadBusy;            // The thread of the busy indicator.
65 andreas 262
        bool mKeyboard{false};              // TRUE = keyboard is visible
263
        bool mKeypad{false};                // TRUE = keypad is visible
140 andreas 264
        TQtPhone *mPhoneDialog{nullptr};    // Points to the internal phone dialog
70 andreas 265
        // Mouse
266
        int mLastPressX{-1};                // Remember the last mouse press X coordinate
267
        int mLastPressY{-1};                // Remember the last mouse press Y coordinate
130 andreas 268
        Qt::ScreenOrientations mOrientation{Qt::PrimaryOrientation};
141 andreas 269
        QMediaPlayer *mMediaPlayer{nullptr};// Class to play sound files.
181 andreas 270
#ifdef QT6_LINUX
271
        QAudioOutput *mAudioOutput{nullptr};
272
#endif
213 andreas 273
        std::chrono::steady_clock::time_point mTouchStart;  // Time in micro seconds of the start of a touch event
153 andreas 274
        int mTouchX{0};                        // The X coordinate of the mouse pointer
275
        int mTouchY{0};                        // The Y coordinate of the mouse pointer
2 andreas 276
};
277
 
278
#endif