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();
14 andreas 102
 
5 andreas 103
    protected:
57 andreas 104
        bool event(QEvent *event) override;
5 andreas 105
        void closeEvent(QCloseEvent *event) override;
10 andreas 106
        void mousePressEvent(QMouseEvent* event) override;
107
        void mouseReleaseEvent(QMouseEvent* event) override;
15 andreas 108
        bool eventFilter(QObject *obj, QEvent *ev) override;
2 andreas 109
 
5 andreas 110
    private slots:
111
        void settings();
112
        void about();
2 andreas 113
#ifndef QT_NO_SESSIONMANAGER
5 andreas 114
        void commitData(QSessionManager &);
2 andreas 115
#endif
14 andreas 116
        void displayButton(ulong handle, ulong parent, QByteArray buffer, int width, int height, int pixline, int left, int top);
98 andreas 117
        void SetVisible(ulong handle, bool state);
5 andreas 118
        void setPage(ulong handle, int width, int height);
41 andreas 119
        void setSubPage(ulong hanlde, int left, int top, int width, int height, ANIMATION_t animate);
38 andreas 120
        void setBackground(ulong handle, QByteArray image, size_t rowBytes, int width, int height, ulong color);
11 andreas 121
        void dropPage(ulong handle);
122
        void dropSubPage(ulong handle);
98 andreas 123
        void dropButton(ulong handle);
21 andreas 124
        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 125
        void inputText(Button::TButton *button, QByteArray buffer, int width, int height, size_t pixline);
63 andreas 126
        void showKeyboard(const std::string& init, const std::string& prompt, bool priv);
127
        void showKeypad(const std::string& init, const std::string& prompt, bool priv);
111 andreas 128
        void sendVirtualKeys(const std::string& str);
63 andreas 129
        void resetKeyboard();
64 andreas 130
        void showSetup();
71 andreas 131
        void playSound(const std::string& file);
141 andreas 132
        void stopSound();
133
        void muteSound(bool state);
31 andreas 134
        void appStateChanged(Qt::ApplicationState state);
130 andreas 135
        void onScreenOrientationChanged(Qt::ScreenOrientation ori);
140 andreas 136
        // Slots for the phone dialog
137
        void showPhoneDialog(bool state);
138
        void setPhoneNumber(const std::string& number);
139
        void setPhoneStatus(const std::string& msg);
141 andreas 140
        void setPhoneState(int state, int id);
130 andreas 141
        // Slots for the toolbar buttons.
32 andreas 142
        void arrowLeft();
143
        void arrowRight();
144
        void arrowUp();
145
        void arrowDown();
146
        void selectOk();
33 andreas 147
        void volumeUpPressed();
148
        void volumeUpReleased();
149
        void volumeDownPressed();
150
        void volumeDownReleased();
38 andreas 151
//        void volumeMute();
130 andreas 152
        // Slots for widget actions and button element actions
42 andreas 153
        void animationFinished();
51 andreas 154
        void textChangedMultiLine();
155
        void textSingleLineReturn();
142 andreas 156
        void repaintWindows();
44 andreas 157
 
14 andreas 158
    private:
57 andreas 159
        bool gestureEvent(QGestureEvent *event);
14 andreas 160
        void createActions();
161
        void writeSettings();
31 andreas 162
        void playShowList();
38 andreas 163
        int scale(int value);
164
        bool isScaled() { return (mScaleFactor != 1.0); }
107 andreas 165
        void startAnimation(TObject::OBJECT_t *obj, ANIMATION_t& ani, bool in = true);
120 andreas 166
        void busyIndicator(const std::string& msg, QWidget *parent);
167
        void runEvents();
14 andreas 168
 
169
        void _displayButton(ulong handle, ulong parent, unsigned char* buffer, int width, int height, int pixline, int left, int top);
98 andreas 170
        void _setVisible(ulong handle, bool state);
14 andreas 171
        void _setPage(ulong handle, int width, int height);
41 andreas 172
        void _setSubPage(ulong handle, int left, int top, int width, int height, ANIMATION_t animate);
38 andreas 173
        void _setBackground(ulong handle, unsigned char *image, size_t size, size_t rowBytes, int width, int height, ulong color);
14 andreas 174
        void _dropPage(ulong handle);
175
        void _dropSubPage(ulong handle);
98 andreas 176
        void _dropButton(ulong handle);
21 andreas 177
        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 178
        void _inputText(Button::TButton *button, Button::BITMAP_t& bm);
63 andreas 179
        void _showKeyboard(const std::string& init, const std::string& prompt, bool priv=false);
180
        void _showKeypad(const std::string& init, const std::string& prompt, bool priv=false);
181
        void _resetKeyboard();
64 andreas 182
        void _showSetup();
44 andreas 183
        void _resetSurface();
64 andreas 184
        void _shutdown();
71 andreas 185
        void _playSound(const std::string& file);
141 andreas 186
        void _stopSound();
187
        void _muteSound(bool state);
88 andreas 188
        void _setOrientation(J_ORIENTATION ori);
111 andreas 189
        void _sendVirtualKeys(const std::string& str);
140 andreas 190
        void _showPhoneDialog(bool state);
191
        void _setPhoneNumber(const std::string& number);
192
        void _setPhoneStatus(const std::string& msg);
141 andreas 193
        void _setPhoneState(int state, int id);
93 andreas 194
#ifdef __ANDROID__
195
        void _signalState(Qt::ApplicationState state);
130 andreas 196
        void _orientationChanged(int orientation);
93 andreas 197
#endif
142 andreas 198
        void _repaintWindows();
70 andreas 199
        void doReleaseButton();
142 andreas 200
        void repaintObjects();
141 andreas 201
        int calcVolume(int value);
70 andreas 202
 
142 andreas 203
        bool mWasInactive{false};           // If the application was inactive this is set to true until everything was repainted.
204
        bool mDoRepaint{false};             // This is set to TRUE whenever a reconnection to the controller happened.
23 andreas 205
        TQtSettings *mSettings{nullptr};    // The pointer to the settings dialog
22 andreas 206
        bool settingsChanged{false};        // true = settings have changed
13 andreas 207
        QWidget *mBackground{nullptr};      // The background of the visible page
88 andreas 208
        QToolBar *mToolbar{nullptr};        // The toolbar, if there is any
21 andreas 209
        std::string mVideoURL;              // If the button is a video, this is the URL where it plays from.
22 andreas 210
        std::string mFileConfig;            // Path and file name of the config file
31 andreas 211
        bool mHasFocus{true};               // If this is FALSE, no output to sceen is allowed.
38 andreas 212
        std::atomic<double> mScaleFactor{1.0}; // The actual scale factor
107 andreas 213
        std::atomic<TObject::OBJECT_t *> mLastObject{nullptr};     // This is for the hide effect of widgets.
120 andreas 214
        std::atomic<bool> mBusy{false};     // If TRUE the busy indicator is active
215
        TQBusy *mBusyDialog{nullptr};       // Pointer to busy indicator dialog window
63 andreas 216
        TQKeyboard *mQKeyboard{nullptr};    // Pointer to an active virtual keyboard
217
        TQKeypad *mQKeypad{nullptr};        // Pointer to an active virtual keypad
120 andreas 218
//        std::thread mThreadBusy;            // The thread of the busy indicator.
65 andreas 219
        bool mKeyboard{false};              // TRUE = keyboard is visible
220
        bool mKeypad{false};                // TRUE = keypad is visible
140 andreas 221
        TQtPhone *mPhoneDialog{nullptr};    // Points to the internal phone dialog
70 andreas 222
        // Mouse
223
        int mLastPressX{-1};                // Remember the last mouse press X coordinate
224
        int mLastPressY{-1};                // Remember the last mouse press Y coordinate
130 andreas 225
        Qt::ScreenOrientations mOrientation{Qt::PrimaryOrientation};
141 andreas 226
        QMediaPlayer *mMediaPlayer{nullptr};// Class to play sound files.
2 andreas 227
};
228
 
229
#endif