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
#include "terror.h"
28
 
21 andreas 29
extern bool prg_stopped;
34 andreas 30
extern std::atomic<bool> killed;
21 andreas 31
 
2 andreas 32
QT_BEGIN_NAMESPACE
33
class QAction;
34
class QMenu;
35
class QSessionManager;
5 andreas 36
class QLabel;
37
class QWidget;
14 andreas 38
class QByteArray;
10 andreas 39
class QMouseEvent;
15 andreas 40
class QMoveEvent;
41
class QEvent;
141 andreas 42
class QSound;
43
class QMediaPlayer;
23 andreas 44
class TQtSettings;
63 andreas 45
class TQKeyboard;
46
class TQKeypad;
120 andreas 47
class TQBusy;
140 andreas 48
class TQtPhone;
2 andreas 49
QT_END_NAMESPACE
50
 
14 andreas 51
Q_DECLARE_METATYPE(size_t)
52
 
3 andreas 53
int qtmain(int argc, char **argv, TPageManager *pmanager);
2 andreas 54
 
107 andreas 55
class MainWindow : public QMainWindow, TQManageQueue
2 andreas 56
{
14 andreas 57
    Q_OBJECT
2 andreas 58
 
5 andreas 59
    public:
88 andreas 60
        typedef enum J_ORIENTATION
61
        {
62
            O_UNDEFINED = -1,
63
            O_LANDSCAPE = 0,
130 andreas 64
            O_PORTRAIT = 1,
65
            O_REVERSE_LANDSCAPE = 8,
134 andreas 66
            O_REVERSE_PORTRAIT = 9,
67
            O_FACE_UP = 15,
68
            O_FACE_DOWN = 16
88 andreas 69
        }J_ORIENTATION;
70
 
5 andreas 71
        MainWindow();
34 andreas 72
        ~MainWindow();
22 andreas 73
        void setConfigFile(const std::string& file) { mFileConfig = file; }
23 andreas 74
        void setSetChange(bool state) { settingsChanged = state; }
38 andreas 75
        void setScaleFactor(double scale) { mScaleFactor = scale; }
76
        double getScaleFactor() { return mScaleFactor; }
2 andreas 77
 
14 andreas 78
    signals:
79
        void sigDisplayButton(ulong handle, ulong parent, QByteArray buffer, int width, int height, int pixline, int left, int top);
98 andreas 80
        void sigSetVisible(ulong handle, bool state);
14 andreas 81
        void sigSetPage(ulong handle, int width, int height);
41 andreas 82
        void sigSetSubPage(ulong handle, int left, int top, int width, int height, ANIMATION_t animate);
38 andreas 83
        void sigSetBackground(ulong handle, QByteArray image, size_t rowBytes, int width, int height, ulong color);
14 andreas 84
        void sigDropPage(ulong handle);
85
        void sigDropSubPage(ulong handle);
98 andreas 86
        void sigDropButton(ulong handle);
21 andreas 87
        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);
52 andreas 88
        void sigInputText(Button::TButton * button, QByteArray buffer, int width, int height, size_t pixline);
63 andreas 89
        void sigKeyboard(const std::string& init, const std::string& prompt, bool priv);
90
        void sigKeypad(const std::string& init, const std::string& prompt, bool priv);
91
        void sigResetKeyboard();
64 andreas 92
        void sigShowSetup();
71 andreas 93
        void sigPlaySound(const std::string& file);
141 andreas 94
        void sigStopSound();
95
        void sigMuteSound(bool state);
111 andreas 96
        void sigSendVirtualKeys(const std::string& str);
140 andreas 97
        void sigShowPhoneDialog(bool state);
98
        void sigSetPhoneNumber(const std::string& number);
99
        void sigSetPhoneStatus(const std::string& msg);
141 andreas 100
        void sigSetPhoneState(int state, int id);
142 andreas 101
        void sigRepaintWindows();
151 andreas 102
        void sigToFront(ulong handle);
14 andreas 103
 
5 andreas 104
    protected:
57 andreas 105
        bool event(QEvent *event) override;
5 andreas 106
        void closeEvent(QCloseEvent *event) override;
10 andreas 107
        void mousePressEvent(QMouseEvent* event) override;
108
        void mouseReleaseEvent(QMouseEvent* event) override;
15 andreas 109
        bool eventFilter(QObject *obj, QEvent *ev) override;
2 andreas 110
 
5 andreas 111
    private slots:
112
        void settings();
113
        void about();
2 andreas 114
#ifndef QT_NO_SESSIONMANAGER
5 andreas 115
        void commitData(QSessionManager &);
2 andreas 116
#endif
14 andreas 117
        void displayButton(ulong handle, ulong parent, QByteArray buffer, int width, int height, int pixline, int left, int top);
98 andreas 118
        void SetVisible(ulong handle, bool state);
5 andreas 119
        void setPage(ulong handle, int width, int height);
41 andreas 120
        void setSubPage(ulong hanlde, int left, int top, int width, int height, ANIMATION_t animate);
38 andreas 121
        void setBackground(ulong handle, QByteArray image, size_t rowBytes, int width, int height, ulong color);
11 andreas 122
        void dropPage(ulong handle);
123
        void dropSubPage(ulong handle);
98 andreas 124
        void dropButton(ulong handle);
21 andreas 125
        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);
52 andreas 126
        void inputText(Button::TButton *button, QByteArray buffer, int width, int height, size_t pixline);
63 andreas 127
        void showKeyboard(const std::string& init, const std::string& prompt, bool priv);
128
        void showKeypad(const std::string& init, const std::string& prompt, bool priv);
111 andreas 129
        void sendVirtualKeys(const std::string& str);
63 andreas 130
        void resetKeyboard();
64 andreas 131
        void showSetup();
71 andreas 132
        void playSound(const std::string& file);
141 andreas 133
        void stopSound();
134
        void muteSound(bool state);
31 andreas 135
        void appStateChanged(Qt::ApplicationState state);
130 andreas 136
        void onScreenOrientationChanged(Qt::ScreenOrientation ori);
140 andreas 137
        // Slots for the phone dialog
138
        void showPhoneDialog(bool state);
139
        void setPhoneNumber(const std::string& number);
140
        void setPhoneStatus(const std::string& msg);
141 andreas 141
        void setPhoneState(int state, int id);
130 andreas 142
        // Slots for the toolbar buttons.
32 andreas 143
        void arrowLeft();
144
        void arrowRight();
145
        void arrowUp();
146
        void arrowDown();
147
        void selectOk();
33 andreas 148
        void volumeUpPressed();
149
        void volumeUpReleased();
150
        void volumeDownPressed();
151
        void volumeDownReleased();
38 andreas 152
//        void volumeMute();
130 andreas 153
        // Slots for widget actions and button element actions
42 andreas 154
        void animationFinished();
51 andreas 155
        void textChangedMultiLine();
156
        void textSingleLineReturn();
142 andreas 157
        void repaintWindows();
151 andreas 158
        void toFront(ulong handle);
44 andreas 159
 
14 andreas 160
    private:
57 andreas 161
        bool gestureEvent(QGestureEvent *event);
14 andreas 162
        void createActions();
163
        void writeSettings();
31 andreas 164
        void playShowList();
38 andreas 165
        int scale(int value);
166
        bool isScaled() { return (mScaleFactor != 1.0); }
107 andreas 167
        void startAnimation(TObject::OBJECT_t *obj, ANIMATION_t& ani, bool in = true);
120 andreas 168
        void busyIndicator(const std::string& msg, QWidget *parent);
169
        void runEvents();
14 andreas 170
 
171
        void _displayButton(ulong handle, ulong parent, unsigned char* buffer, int width, int height, int pixline, int left, int top);
98 andreas 172
        void _setVisible(ulong handle, bool state);
14 andreas 173
        void _setPage(ulong handle, int width, int height);
41 andreas 174
        void _setSubPage(ulong handle, int left, int top, int width, int height, ANIMATION_t animate);
38 andreas 175
        void _setBackground(ulong handle, unsigned char *image, size_t size, size_t rowBytes, int width, int height, ulong color);
14 andreas 176
        void _dropPage(ulong handle);
177
        void _dropSubPage(ulong handle);
98 andreas 178
        void _dropButton(ulong handle);
21 andreas 179
        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);
52 andreas 180
        void _inputText(Button::TButton *button, Button::BITMAP_t& bm);
63 andreas 181
        void _showKeyboard(const std::string& init, const std::string& prompt, bool priv=false);
182
        void _showKeypad(const std::string& init, const std::string& prompt, bool priv=false);
183
        void _resetKeyboard();
64 andreas 184
        void _showSetup();
44 andreas 185
        void _resetSurface();
64 andreas 186
        void _shutdown();
71 andreas 187
        void _playSound(const std::string& file);
141 andreas 188
        void _stopSound();
189
        void _muteSound(bool state);
88 andreas 190
        void _setOrientation(J_ORIENTATION ori);
111 andreas 191
        void _sendVirtualKeys(const std::string& str);
140 andreas 192
        void _showPhoneDialog(bool state);
193
        void _setPhoneNumber(const std::string& number);
194
        void _setPhoneStatus(const std::string& msg);
141 andreas 195
        void _setPhoneState(int state, int id);
93 andreas 196
#ifdef __ANDROID__
197
        void _signalState(Qt::ApplicationState state);
130 andreas 198
        void _orientationChanged(int orientation);
93 andreas 199
#endif
142 andreas 200
        void _repaintWindows();
151 andreas 201
        void _toFront(ulong handle);
70 andreas 202
        void doReleaseButton();
142 andreas 203
        void repaintObjects();
141 andreas 204
        int calcVolume(int value);
70 andreas 205
 
142 andreas 206
        bool mWasInactive{false};           // If the application was inactive this is set to true until everything was repainted.
207
        bool mDoRepaint{false};             // This is set to TRUE whenever a reconnection to the controller happened.
23 andreas 208
        TQtSettings *mSettings{nullptr};    // The pointer to the settings dialog
22 andreas 209
        bool settingsChanged{false};        // true = settings have changed
13 andreas 210
        QWidget *mBackground{nullptr};      // The background of the visible page
88 andreas 211
        QToolBar *mToolbar{nullptr};        // The toolbar, if there is any
21 andreas 212
        std::string mVideoURL;              // If the button is a video, this is the URL where it plays from.
22 andreas 213
        std::string mFileConfig;            // Path and file name of the config file
31 andreas 214
        bool mHasFocus{true};               // If this is FALSE, no output to sceen is allowed.
38 andreas 215
        std::atomic<double> mScaleFactor{1.0}; // The actual scale factor
107 andreas 216
        std::atomic<TObject::OBJECT_t *> mLastObject{nullptr};     // This is for the hide effect of widgets.
120 andreas 217
        std::atomic<bool> mBusy{false};     // If TRUE the busy indicator is active
218
        TQBusy *mBusyDialog{nullptr};       // Pointer to busy indicator dialog window
63 andreas 219
        TQKeyboard *mQKeyboard{nullptr};    // Pointer to an active virtual keyboard
220
        TQKeypad *mQKeypad{nullptr};        // Pointer to an active virtual keypad
120 andreas 221
//        std::thread mThreadBusy;            // The thread of the busy indicator.
65 andreas 222
        bool mKeyboard{false};              // TRUE = keyboard is visible
223
        bool mKeypad{false};                // TRUE = keypad is visible
140 andreas 224
        TQtPhone *mPhoneDialog{nullptr};    // Points to the internal phone dialog
70 andreas 225
        // Mouse
226
        int mLastPressX{-1};                // Remember the last mouse press X coordinate
227
        int mLastPressY{-1};                // Remember the last mouse press Y coordinate
130 andreas 228
        Qt::ScreenOrientations mOrientation{Qt::PrimaryOrientation};
141 andreas 229
        QMediaPlayer *mMediaPlayer{nullptr};// Class to play sound files.
153 andreas 230
        std::chrono::steady_clock::time_point mTouchStart;           // Time in micro seconds of the start of a touch event
231
        int mTouchX{0};                        // The X coordinate of the mouse pointer
232
        int mTouchY{0};                        // The Y coordinate of the mouse pointer
2 andreas 233
};
234
 
235
#endif