Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 andreas 1
/*
258 andreas 2
 * Copyright (C) 2020 to 2023 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
 
21 andreas 19
/** @file tqtmain.cpp
20
 * @brief Implements the surface of the application.
21
 *
22
 * This file implements the callback functions of the suface. While the most
23
 * classes are drawing the elements, the methods here take the ready elements
24
 * and display them. This file makes the surface completely independent of
25
 * the rest of the application which makes it easy to change the surface by
26
 * any other technology.
27
 */
2 andreas 28
#include <QApplication>
23 andreas 29
#include <QGuiApplication>
14 andreas 30
#include <QByteArray>
2 andreas 31
#include <QCommandLineParser>
32
#include <QCommandLineOption>
9 andreas 33
#include <QLabel>
2 andreas 34
#include <QtWidgets>
264 andreas 35
#include <QStackedWidget>
10 andreas 36
#include <QMouseEvent>
15 andreas 37
#include <QMoveEvent>
59 andreas 38
#include <QTouchEvent>
5 andreas 39
#include <QPalette>
9 andreas 40
#include <QPixmap>
7 andreas 41
#include <QFont>
42
#include <QFontDatabase>
21 andreas 43
#include <QtMultimediaWidgets/QVideoWidget>
44
#include <QtMultimedia/QMediaPlayer>
264 andreas 45
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
181 andreas 46
#   include <QtMultimedia/QMediaPlaylist>
47
#else
48
#   include <QAudioOutput>
49
#endif
205 andreas 50
#include <QListWidget>
24 andreas 51
#include <QLayout>
40 andreas 52
#include <QSizePolicy>
21 andreas 53
#include <QUrl>
13 andreas 54
#include <QThread>
258 andreas 55
#ifdef Q_OS_IOS
252 andreas 56
#include <QOrientationSensor>
253 andreas 57
#endif
264 andreas 58
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
181 andreas 59
#   include <QSound>
267 andreas 60
#if defined(Q_OS_IOS) || defined(Q_OS_ANDROID)
181 andreas 61
#   include <QtSensors/QOrientationSensor>
217 andreas 62
#   include <qpa/qplatformscreen.h>
267 andreas 63
#endif
187 andreas 64
#else
267 andreas 65
#   include <QPlainTextEdit>
66
#if defined(Q_OS_IOS) || defined(Q_OS_ANDROID)
254 andreas 67
#   include <QGeoPositionInfoSource>
217 andreas 68
#   include <QtSensors/QOrientationReading>
181 andreas 69
#endif
267 andreas 70
#endif
264 andreas 71
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) && defined(Q_OS_ANDROID)
183 andreas 72
#include <QtAndroidExtras/QAndroidJniObject>
211 andreas 73
#include <QtAndroidExtras/QtAndroid>
88 andreas 74
#endif
5 andreas 75
#include <functional>
14 andreas 76
#include <mutex>
255 andreas 77
#ifdef Q_OS_ANDROID
23 andreas 78
#include <android/log.h>
79
#endif
4 andreas 80
#include "tpagemanager.h"
2 andreas 81
#include "tqtmain.h"
82
#include "tconfig.h"
251 andreas 83
#if !defined(Q_OS_IOS) && !defined(Q_OS_ANDROID)
2 andreas 84
#include "tqtsettings.h"
213 andreas 85
#endif
62 andreas 86
#include "tqkeyboard.h"
87
#include "tqkeypad.h"
5 andreas 88
#include "tcolor.h"
92 andreas 89
#include "texcept.h"
118 andreas 90
#include "ttpinit.h"
179 andreas 91
#include "tqdownload.h"
140 andreas 92
#include "tqtphone.h"
190 andreas 93
#include "tqeditline.h"
260 andreas 94
#include "tqtwait.h"
211 andreas 95
#include "terror.h"
270 andreas 96
#include "tresources.h"
285 andreas 97
#include "tqscrollarea.h"
292 andreas 98
#include "tlock.h"
243 andreas 99
#ifdef Q_OS_IOS
250 andreas 100
#include "ios/QASettings.h"
101
#include "ios/tiosrotate.h"
102
#include "ios/tiosbattery.h"
243 andreas 103
#endif
326 andreas 104
#if TESTMODE == 1
105
#include "testmode.h"
106
#endif
2 andreas 107
 
209 andreas 108
#if __cplusplus < 201402L
109
#   error "This module requires at least C++14 standard!"
110
#else
111
#   if __cplusplus < 201703L
112
#       include <experimental/filesystem>
113
namespace fs = std::experimental::filesystem;
114
#       warning "Support for C++14 and experimental filesystem will be removed in a future version!"
115
#   else
116
#       include <filesystem>
117
#       ifdef __ANDROID__
118
namespace fs = std::__fs::filesystem;
119
#       else
120
namespace fs = std::filesystem;
121
#       endif
122
#   endif
123
#endif
124
 
21 andreas 125
/**
44 andreas 126
 * @def THREAD_WAIT
127
 * This defines a time in milliseconds. It is used in the callbacks for the
128
 * functions to draw the elements. Qt need a little time to do it's work.
129
 * Therefore we're waiting a little bit. Otherwise it may result in missing
130
 * elements or black areas on the screen.
21 andreas 131
 */
100 andreas 132
#define THREAD_WAIT     1
44 andreas 133
 
134
extern amx::TAmxNet *gAmxNet;                   //!< Pointer to the class running the thread which handles the communication with the controller.
90 andreas 135
extern bool _restart_;                          //!< If this is set to true then the whole program will start over.
92 andreas 136
extern TPageManager *gPageManager;              //!< The pointer to the global defined main class.
38 andreas 137
static bool isRunning = false;                  //!< TRUE = the pageManager was started.
100 andreas 138
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
44 andreas 139
static double gScale = 1.0;                     //!< Global variable holding the scale factor.
140
static int gFullWidth = 0;                      //!< Global variable holding the width of the AMX screen. This is used to calculate the scale factor for the settings dialog.
155 andreas 141
std::atomic<double> mScaleFactorW{1.0};
142
std::atomic<double> mScaleFactorH{1.0};
143
int gScreenWidth{0};
144
int gScreenHeight{0};
264 andreas 145
bool isPortrait{false};
100 andreas 146
#endif
21 andreas 147
 
5 andreas 148
using std::bind;
296 andreas 149
using std::map;
61 andreas 150
using std::pair;
21 andreas 151
using std::string;
51 andreas 152
using std::vector;
5 andreas 153
 
107 andreas 154
string _NO_OBJECT = "The global class TObject is not available!";
155
 
21 andreas 156
/**
157
 * @brief qtmain is used here as the entry point for the surface.
158
 *
159
 * The main entry function parses the command line parameters, if there were
160
 * any and sets the basic attributes. It creates the main window and starts the
161
 * application.
162
 *
163
 * @param argc      The number of command line arguments
164
 * @param argv      A pointer to a 2 dimensional array containing the command
165
 *                  line parameters.
166
 * @param pmanager  A pointer to the page manager class which is the main class
167
 *                  managing everything.
168
 *
169
 * @return If no errors occured it returns 0.
170
 */
3 andreas 171
int qtmain(int argc, char **argv, TPageManager *pmanager)
2 andreas 172
{
31 andreas 173
    DECL_TRACER("qtmain(int argc, char **argv, TPageManager *pmanager)");
2 andreas 174
 
58 andreas 175
    if (!pmanager)
176
    {
177
        MSG_ERROR("Fatal: No pointer to the page manager received!");
178
        return 1;
179
    }
180
 
299 andreas 181
    gPageManager = pmanager;
88 andreas 182
#ifdef __ANDROID__
183
    MSG_INFO("Android API version: " << __ANDROID_API__);
3 andreas 184
 
256 andreas 185
#if __ANDROID_API__ < 30
258 andreas 186
#warning "The Android API version is less than 30! Some functions may not work!"
256 andreas 187
#endif  // __ANDROID_API__
264 andreas 188
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
256 andreas 189
    QAndroidJniObject activity = QtAndroid::androidActivity();
190
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/HideToolbar", "hide", "(Landroid/app/Activity;Z)V", activity.object(), true);
191
#else
192
    QJniObject activity = QNativeInterface::QAndroidApplication::context();
193
    QJniObject::callStaticMethod<void>("org/qtproject/theosys/HideToolbar", "hide", "(Landroid/app/Activity;Z)V", activity.object(), true);
194
#endif  // QT5_LINUX
195
#endif  // __ANDROID__
196
 
264 andreas 197
#if defined(Q_OS_ANDROID)
38 andreas 198
    QApplication::setAttribute(Qt::AA_ForceRasterWidgets);
264 andreas 199
//    QApplication::setAttribute(Qt::AA_Use96Dpi);
178 andreas 200
//    QApplication::setAttribute(Qt::AA_DontUseNativeDialogs);
2 andreas 201
#endif
202
 
5 andreas 203
    QApplication app(argc, argv);
58 andreas 204
    // Set the orientation
205
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
206
    QScreen *screen = QGuiApplication::primaryScreen();
207
 
208
    if (!screen)
209
    {
210
        MSG_ERROR("Couldn't determine the primary screen!")
211
        return 1;
212
    }
264 andreas 213
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
151 andreas 214
    if (pmanager->getSettings()->isPortrait())  // portrait?
88 andreas 215
    {
216
        MSG_INFO("Orientation set to portrait mode.");
264 andreas 217
        screen->setOrientationUpdateMask(Qt::PortraitOrientation);
88 andreas 218
    }
219
    else
220
    {
221
        MSG_INFO("Orientation set to landscape mode.");
264 andreas 222
        screen->setOrientationUpdateMask(Qt::LandscapeOrientation);
88 andreas 223
    }
264 andreas 224
#endif  // QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
38 andreas 225
    double scale = 1.0;
212 andreas 226
    double setupScaleFactor = 1.0;
24 andreas 227
    // Calculate the scale factor
228
    if (TConfig::getScale())
229
    {
43 andreas 230
        // Because we've no window here we can not know on which screen, if
231
        // there are more than one, the application will start. Because on a
232
        // mobile mostly no external screen is connected, we take always the
233
        // resolution of the first (built in) screen.
234
        // TODO: Find a way to get the screen the application will start and
235
        // take this screen to calculate the scale factor.
264 andreas 236
        QRect screenGeometry = screen->availableGeometry();
88 andreas 237
        double width = 0.0;
238
        double height = 0.0;
212 andreas 239
        double sysWidth = 0.0;
240
        double sysHeight = 0.0;
264 andreas 241
        gScreenWidth = std::max(screenGeometry.width(), screenGeometry.height());
242
        gScreenHeight = std::min(screenGeometry.height(), screenGeometry.width());
217 andreas 243
 
264 andreas 244
        if (screenGeometry.width() > screenGeometry.height())
245
            isPortrait = false;
246
        else
247
            isPortrait = true;
217 andreas 248
 
249
        int minWidth = pmanager->getSettings()->getWidth();
24 andreas 250
        int minHeight = pmanager->getSettings()->getHeight();
217 andreas 251
        int minSysWidth = pmanager->getSystemSettings()->getWidth();
212 andreas 252
        int minSysHeight = pmanager->getSystemSettings()->getHeight();
88 andreas 253
 
151 andreas 254
        if (pmanager->getSettings()->isPortrait())  // portrait?
88 andreas 255
        {
217 andreas 256
            width = std::min(gScreenWidth, gScreenHeight);
257
            height = std::max(gScreenHeight, gScreenWidth);
88 andreas 258
        }
259
        else
260
        {
217 andreas 261
            width = std::max(gScreenWidth, gScreenHeight);
262
            height = std::min(gScreenHeight, gScreenWidth);
88 andreas 263
        }
212 andreas 264
        // The setup pages are always landscape
217 andreas 265
        sysWidth = std::max(gScreenWidth, gScreenHeight);
266
        sysHeight = std::min(gScreenHeight, gScreenWidth);
88 andreas 267
 
156 andreas 268
        if (!TConfig::getToolbarSuppress() && TConfig::getToolbarForce())
120 andreas 269
            minWidth += 48;
270
 
31 andreas 271
        MSG_INFO("Dimension of AMX screen:" << minWidth << " x " << minHeight);
88 andreas 272
        MSG_INFO("Screen size: " << width << " x " << height);
43 andreas 273
        // The scale factor is always calculated in difference to the prefered
274
        // size of the original AMX panel.
212 andreas 275
        mScaleFactorW = width / (double)minWidth;
276
        mScaleFactorH = height / (double)minHeight;
217 andreas 277
        double scaleFactorW = sysWidth / (double)minSysWidth;
278
        double scaleFactorH = sysHeight / (double)minSysHeight;
155 andreas 279
        scale = std::min(mScaleFactorW, mScaleFactorH);
212 andreas 280
        setupScaleFactor = std::min(scaleFactorW, scaleFactorH);
235 andreas 281
#ifdef __ANDROID__
212 andreas 282
        __android_log_print(ANDROID_LOG_DEBUG, "tpanel", "scale: %f (Screen: %1.0fx%1.0f, Page: %dx%d)", scale, width, height, minWidth, minHeight);
283
        __android_log_print(ANDROID_LOG_DEBUG, "tpanel", "setupScaleFactor: %f (Screen: %1.0fx%1.0f, Page: %dx%d)", setupScaleFactor, sysWidth, sysHeight, minSysWidth, minSysHeight);
235 andreas 284
#endif
43 andreas 285
        gScale = scale;     // The calculated scale factor
88 andreas 286
        gFullWidth = width;
155 andreas 287
        MSG_INFO("Calculated scale factor: " << scale);
43 andreas 288
        // This preprocessor variable allows the scaling to be done by the Skia
289
        // library, which is used to draw everything. In comparison to Qt this
290
        // library is a bit slower and sometimes does not honor the aspect ratio
44 andreas 291
        // correct. But in case there is another framework than Qt in use, this
43 andreas 292
        // could be necessary.
293
#ifdef _SCALE_SKIA_
26 andreas 294
        if (scale != 0.0)
295
        {
296
            pmanager->setScaleFactor(scale);
31 andreas 297
            MSG_INFO("Scale factor: " << scale);
26 andreas 298
        }
31 andreas 299
 
300
        if (scaleW != 0.0)
301
            pmanager->setScaleFactorWidth(scaleW);
302
 
303
        if (scaleH != 0.0)
304
            pmanager->setScaleFactorHeight(scaleH);
58 andreas 305
#endif  // _SCALE_SKIA_
24 andreas 306
    }
58 andreas 307
#endif  // defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
235 andreas 308
#if not defined(Q_OS_ANDROID) && not defined(Q_OS_IOS)
213 andreas 309
    double setupScaleFactor = 1.0;
222 andreas 310
 
311
    if (pmanager->getSettings() != pmanager->getSystemSettings())
211 andreas 312
    {
212 andreas 313
        double width = 0.0;
314
        double height = 0.0;
217 andreas 315
        int minWidth = pmanager->getSystemSettings()->getWidth();
212 andreas 316
        int minHeight = pmanager->getSystemSettings()->getHeight();
317
 
318
        if (!TConfig::getToolbarSuppress() && TConfig::getToolbarForce())
319
            minWidth += 48;
320
 
219 andreas 321
        width = std::max(pmanager->getSettings()->getWidth(), pmanager->getSettings()->getHeight());
322
        height = std::min(pmanager->getSettings()->getHeight(), pmanager->getSettings()->getWidth());
222 andreas 323
 
212 andreas 324
        MSG_INFO("Dimension of AMX screen:" << minWidth << " x " << minHeight);
325
        MSG_INFO("Screen size: " << width << " x " << height);
326
        // The scale factor is always calculated in difference to the prefered
327
        // size of the original AMX panel.
328
        double scaleFactorW = width / (double)minWidth;
329
        double scaleFactorH = height / (double)minHeight;
330
        setupScaleFactor = std::min(scaleFactorW, scaleFactorH);
265 andreas 331
        MSG_DEBUG("Scale factor for setup screen: " << setupScaleFactor);
198 andreas 332
    }
222 andreas 333
#endif
24 andreas 334
    // Initialize the application
164 andreas 335
    pmanager->setDPI(QGuiApplication::primaryScreen()->logicalDotsPerInch());
5 andreas 336
    QCoreApplication::setOrganizationName(TConfig::getProgName().c_str());
164 andreas 337
    QCoreApplication::setApplicationName("TPanel");
24 andreas 338
    QCoreApplication::setApplicationVersion(VERSION_STRING());
5 andreas 339
    QCommandLineParser parser;
340
    parser.setApplicationDescription(QCoreApplication::applicationName());
341
    parser.addHelpOption();
342
    parser.addVersionOption();
343
    parser.process(app);
2 andreas 344
 
5 andreas 345
    MainWindow mainWin;
58 andreas 346
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
347
#   ifndef _SCALE_SKIA_
43 andreas 348
    if (TConfig::getScale() && scale != 1.0)
38 andreas 349
        mainWin.setScaleFactor(scale);
58 andreas 350
#   endif   // _SCALE_SKIA_
351
#endif  // defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
22 andreas 352
    mainWin.setConfigFile(TConfig::getConfigPath() + "/" + TConfig::getConfigFileName());
299 andreas 353
    QPalette palette(mainWin.palette());
354
    palette.setColor(QPalette::Window, Qt::black);  // Keep the background black. Helps to save battery on OLED displays.
355
    mainWin.setPalette(palette);
58 andreas 356
    mainWin.grabGesture(Qt::PinchGesture);
153 andreas 357
    mainWin.grabGesture(Qt::SwipeGesture);
264 andreas 358
    mainWin.setOrientation(Qt::PrimaryOrientation);
359
//#ifdef Q_OS_IOS
360
 //   mainWin.setWindowFlag(Qt::MaximizeUsingFullscreenGeometryHint, true);
361
//#endif
198 andreas 362
    if (setupScaleFactor != 1.0 && setupScaleFactor > 0.0)
363
        mainWin.setSetupScaleFactor(setupScaleFactor);
364
 
5 andreas 365
    mainWin.show();
366
    return app.exec();
2 andreas 367
}
368
 
21 andreas 369
/**
370
 * @brief MainWindow::MainWindow constructor
371
 *
372
 * This method is the constructor for this class. It registers the callback
373
 * functions to the class TPageManager and starts the main run loop.
43 andreas 374
 *
375
 * Qt is used only to manage widgets to handle pages and subpages. A page as
376
 * well as a subpage may contain a background graphic and some elements. The
377
 * elements could be buttons, bargraphs and other objects. The underlying layer
378
 * draw every element as a ready graphic image and call a callback function to
379
 * let Qt display the graphic.
380
 * If there are some animations on a subpage defined, this is also handled by
381
 * Qt. Especialy sliding and fading.
21 andreas 382
 */
2 andreas 383
MainWindow::MainWindow()
384
{
5 andreas 385
    DECL_TRACER("MainWindow::MainWindow()");
59 andreas 386
 
296 andreas 387
    TObject::setParent(this);
388
 
264 andreas 389
    if (!gPageManager)
390
    {
391
        EXCEPTFATALMSG("The class TPageManager was not initialized!");
392
    }
393
 
323 andreas 394
    mGestureFilter = new TQGestureFilter(this);
395
    connect(mGestureFilter, &TQGestureFilter::gestureEvent, this, &MainWindow::onGestureEvent);
59 andreas 396
    setAttribute(Qt::WA_AcceptTouchEvents, true);   // We accept touch events
397
    grabGesture(Qt::PinchGesture);                  // We use a pinch gesture to open the settings dialog
153 andreas 398
    grabGesture(Qt::SwipeGesture);                  // We support swiping also
88 andreas 399
 
252 andreas 400
#ifdef Q_OS_IOS                                     // Block autorotate on IOS
401
    initGeoLocation();
263 andreas 402
    mIosRotate = new TIOSRotate;
403
    mIosRotate->automaticRotation(false);           // FIXME: This doesn't work!
252 andreas 404
 
405
    if (!mSensor)
406
    {
407
        mSensor = new QOrientationSensor(this);
408
 
409
        if (mSensor)
410
        {
411
            connect(mSensor, &QSensor::currentOrientationChanged, this, &MainWindow::onCurrentOrientationChanged);
263 andreas 412
            mSensor->setAxesOrientationMode(QSensor::UserOrientation);
413
            mSensor->setUserOrientation(180);
414
 
415
            if (gPageManager && gPageManager->getSettings()->isPortrait())
416
                mSensor->setCurrentOrientation(Qt::PortraitOrientation);
417
            else
418
                mSensor->setCurrentOrientation(Qt::LandscapeOrientation);
252 andreas 419
        }
420
    }
263 andreas 421
#endif  // Q_OS_IOS
264 andreas 422
 
423
    // We create the central widget here to make sure the application
424
    // initializes correct. On mobiles the whole screen is used while on
425
    // desktops a window with the necessary size is created.
266 andreas 426
    QWidget *central = new QWidget;
264 andreas 427
    central->setObjectName("centralWidget");
428
    central->setBackgroundRole(QPalette::Window);
271 andreas 429
#if defined(Q_OS_IOS) || defined(Q_OS_ANDROID)
277 andreas 430
//    central->setAutoFillBackground(false);
264 andreas 431
    central->setFixedSize(gScreenWidth, gScreenHeight);
432
#endif  // defined(Q_OS_IOS) || defined(Q_OSANDROID)
275 andreas 433
    setCentralWidget(central);      // Here we set the central widget
434
    central->show();
264 andreas 435
    // This is a stacked widget used to hold all pages. With it we can also
436
    // simply manage the objects bound to a page.
437
    mCentralWidget = new QStackedWidget(central);
266 andreas 438
    mCentralWidget->setObjectName("stackedPageWidgets");
265 andreas 439
#if defined(Q_OS_IOS) || defined(Q_OS_ANDROID)
264 andreas 440
    MSG_DEBUG("Size will be set for " << (isPortrait ? "PORTRAIT" : "LANDSCAPE"));
441
 
442
    if (gPageManager && gPageManager->getSettings()->isLandscape())
88 andreas 443
    {
264 andreas 444
        if (!isPortrait)
445
            mCentralWidget->setFixedSize((mToolbar ? gScreenWidth - mToolbar->width() : gScreenWidth), gScreenHeight);
446
        else
447
            mCentralWidget->setFixedSize(gScreenWidth, gScreenHeight);
448
    }
449
    else
450
    {
451
        if (isPortrait)
452
            mCentralWidget->setFixedSize((mToolbar ? gScreenHeight - mToolbar->width() : gScreenHeight), gScreenWidth);
453
        else
454
            mCentralWidget->setFixedSize(gScreenHeight, gScreenWidth);
455
    }
266 andreas 456
#else
270 andreas 457
    QSize qs = menuBar()->sizeHint();
266 andreas 458
    QSize icSize =  iconSize();
459
    int lwidth = gPageManager->getSettings()->getWidth() + icSize.width() + 16;
270 andreas 460
    int lheight = gPageManager->getSettings()->getHeight() + qs.height();
461
    mCentralWidget->setFixedSize(gPageManager->getSettings()->getWidth(), gPageManager->getSettings()->getHeight());
265 andreas 462
#endif  // defined(Q_OS_IOS) || defined(Q_OS_ANDROID)
275 andreas 463
 
266 andreas 464
#if defined(Q_OS_IOS) || defined(Q_OS_ANDROID)
264 andreas 465
    if (gPageManager->getSettings()->isPortrait())  // portrait?
466
    {
88 andreas 467
        MSG_INFO("Orientation set to portrait mode.");
468
        _setOrientation(O_PORTRAIT);
264 andreas 469
        mOrientation = Qt::PortraitOrientation;
88 andreas 470
    }
471
    else
472
    {
473
        MSG_INFO("Orientation set to landscape mode.");
474
        _setOrientation(O_LANDSCAPE);
264 andreas 475
        mOrientation = Qt::LandscapeOrientation;
88 andreas 476
    }
266 andreas 477
#else
478
    QRect rectMain = geometry();
479
    rectMain.setWidth(lwidth);
480
    rectMain.setHeight(lheight);
270 andreas 481
    setGeometry(rectMain);
266 andreas 482
    MSG_DEBUG("Height of main window:  " << rectMain.height());
483
    MSG_DEBUG("Height of panel screen: " << lheight);
484
    // If our first top pixel is not 0, maybe because of a menu, window
485
    // decorations or a toolbar, we must add this extra height to the
486
    // positions of widgets and mouse presses.
487
    int avHeight = rectMain.height() - gPageManager->getSettings()->getHeight();
488
    MSG_DEBUG("Difference in height:   " << avHeight);
489
    gPageManager->setFirstTopPixel(avHeight);
264 andreas 490
#endif
113 andreas 491
    setWindowIcon(QIcon(":images/icon.png"));
92 andreas 492
 
43 andreas 493
    // First we register all our surface callbacks to the underlying work
494
    // layer. All the graphics are drawn by the Skia library. The layer below
495
    // call the following functions to let Qt display the graphics on the
496
    // screen let it manage the widgets containing the graphics.
92 andreas 497
    gPageManager->registerCallbackDB(bind(&MainWindow::_displayButton, this,
5 andreas 498
                                       std::placeholders::_1,
499
                                       std::placeholders::_2,
500
                                       std::placeholders::_3,
501
                                       std::placeholders::_4,
502
                                       std::placeholders::_5,
503
                                       std::placeholders::_6,
298 andreas 504
                                       std::placeholders::_7,
505
                                       std::placeholders::_8));
5 andreas 506
 
280 andreas 507
    gPageManager->regDisplayViewButton(bind(&MainWindow::_displayViewButton, this,
508
                                          std::placeholders::_1,
509
                                          std::placeholders::_2,
510
                                          std::placeholders::_3,
511
                                          std::placeholders::_4,
512
                                          std::placeholders::_5,
513
                                          std::placeholders::_6,
514
                                          std::placeholders::_7,
515
                                          std::placeholders::_8,
285 andreas 516
                                          std::placeholders::_9,
517
                                          std::placeholders::_10));
280 andreas 518
 
281 andreas 519
    gPageManager->regAddViewButtonItems(bind(&MainWindow::_addViewButtonItems, this,
285 andreas 520
                                             std::placeholders::_1,
521
                                             std::placeholders::_2));
281 andreas 522
 
300 andreas 523
    gPageManager->regUpdateViewButton(bind(&MainWindow::_updateViewButton, this,
524
                                           std::placeholders::_1,
525
                                           std::placeholders::_2,
526
                                           std::placeholders::_3,
527
                                           std::placeholders::_4));
528
 
529
    gPageManager->regUpdateViewButtonItem(bind(&MainWindow::_updateViewButtonItem, this,
530
                                               std::placeholders::_1,
531
                                               std::placeholders::_2));
532
 
533
    gPageManager->regShowSubViewItem(bind(&MainWindow::_showViewButtonItem, this,
534
                                          std::placeholders::_1,
535
                                          std::placeholders::_2,
536
                                          std::placeholders::_3,
537
                                          std::placeholders::_4));
538
 
318 andreas 539
    gPageManager->regHideAllSubViewItems(bind(&MainWindow::_hideAllViewItems, this, std::placeholders::_1));
540
    gPageManager->regHideSubViewItem(bind(&MainWindow::_hideViewItem, this, std::placeholders::_1, std::placeholders::_2));
541
    gPageManager->regSetSubViewPadding(bind(&MainWindow::_setSubViewPadding, this, std::placeholders::_1, std::placeholders::_2));
542
 
92 andreas 543
    gPageManager->registerCallbackSP(bind(&MainWindow::_setPage, this,
5 andreas 544
                                         std::placeholders::_1,
545
                                         std::placeholders::_2,
546
                                         std::placeholders::_3));
547
 
92 andreas 548
    gPageManager->registerCallbackSSP(bind(&MainWindow::_setSubPage, this,
5 andreas 549
                                          std::placeholders::_1,
550
                                          std::placeholders::_2,
551
                                          std::placeholders::_3,
552
                                          std::placeholders::_4,
41 andreas 553
                                          std::placeholders::_5,
217 andreas 554
                                          std::placeholders::_6,
555
                                          std::placeholders::_7));
5 andreas 556
 
92 andreas 557
    gPageManager->registerCallbackSB(bind(&MainWindow::_setBackground, this,
5 andreas 558
                                         std::placeholders::_1,
559
                                         std::placeholders::_2,
560
                                         std::placeholders::_3,
561
                                         std::placeholders::_4,
262 andreas 562
#ifdef _OPAQUE_SKIA_
289 andreas 563
                                         std::placeholders::_5));
262 andreas 564
#else
289 andreas 565
                                         std::placeholders::_5,
566
                                         std::placeholders::_6));
262 andreas 567
#endif
92 andreas 568
    gPageManager->regCallDropPage(bind(&MainWindow::_dropPage, this, std::placeholders::_1));
569
    gPageManager->regCallDropSubPage(bind(&MainWindow::_dropSubPage, this, std::placeholders::_1));
570
    gPageManager->regCallPlayVideo(bind(&MainWindow::_playVideo, this,
21 andreas 571
                                       std::placeholders::_1,
572
                                       std::placeholders::_2,
573
                                       std::placeholders::_3,
574
                                       std::placeholders::_4,
575
                                       std::placeholders::_5,
576
                                       std::placeholders::_6,
577
                                       std::placeholders::_7,
578
                                       std::placeholders::_8,
579
                                       std::placeholders::_9));
192 andreas 580
    gPageManager->regCallInputText(bind(&MainWindow::_inputText, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
200 andreas 581
    gPageManager->regCallListBox(bind(&MainWindow::_listBox, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
190 andreas 582
    gPageManager->registerDropButton(bind(&MainWindow::_dropButton, this, std::placeholders::_1));
92 andreas 583
    gPageManager->regCallbackKeyboard(bind(&MainWindow::_showKeyboard, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
584
    gPageManager->regCallbackKeypad(bind(&MainWindow::_showKeypad, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
585
    gPageManager->regCallResetKeyboard(bind(&MainWindow::_resetKeyboard, this));
586
    gPageManager->regCallShowSetup(bind(&MainWindow::_showSetup, this));
587
    gPageManager->regCallbackResetSurface(bind(&MainWindow::_resetSurface, this));
588
    gPageManager->regCallbackShutdown(bind(&MainWindow::_shutdown, this));
589
    gPageManager->regCallbackPlaySound(bind(&MainWindow::_playSound, this, std::placeholders::_1));
141 andreas 590
    gPageManager->regCallbackStopSound(bind(&MainWindow::_stopSound, this));
591
    gPageManager->regCallbackMuteSound(bind(&MainWindow::_muteSound, this, std::placeholders::_1));
98 andreas 592
    gPageManager->registerCBsetVisible(bind(&MainWindow::_setVisible, this, std::placeholders::_1, std::placeholders::_2));
111 andreas 593
    gPageManager->regSendVirtualKeys(bind(&MainWindow::_sendVirtualKeys, this, std::placeholders::_1));
140 andreas 594
    gPageManager->regShowPhoneDialog(bind(&MainWindow::_showPhoneDialog, this, std::placeholders::_1));
595
    gPageManager->regSetPhoneNumber(bind(&MainWindow::_setPhoneNumber, this, std::placeholders::_1));
596
    gPageManager->regSetPhoneStatus(bind(&MainWindow::_setPhoneStatus, this, std::placeholders::_1));
141 andreas 597
    gPageManager->regSetPhoneState(bind(&MainWindow::_setPhoneState, this, std::placeholders::_1, std::placeholders::_2));
130 andreas 598
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
599
    gPageManager->regOnOrientationChange(bind(&MainWindow::_orientationChanged, this, std::placeholders::_1));
259 andreas 600
    gPageManager->regOnSettingsChanged(bind(&MainWindow::_activateSettings, this, std::placeholders::_1,
601
                                            std::placeholders::_2,
602
                                            std::placeholders::_3,
603
                                            std::placeholders::_4,
604
                                            std::placeholders::_5,
605
                                            std::placeholders::_6));
130 andreas 606
#endif
142 andreas 607
    gPageManager->regRepaintWindows(bind(&MainWindow::_repaintWindows, this));
151 andreas 608
    gPageManager->regToFront(bind(&MainWindow::_toFront, this, std::placeholders::_1));
252 andreas 609
#if !defined (Q_OS_ANDROID) && !defined(Q_OS_IOS)
197 andreas 610
    gPageManager->regSetMainWindowSize(bind(&MainWindow::_setSizeMainWindow, this, std::placeholders::_1, std::placeholders::_2));
211 andreas 611
#endif
206 andreas 612
    gPageManager->regDownloadSurface(bind(&MainWindow::_downloadSurface, this, std::placeholders::_1, std::placeholders::_2));
613
    gPageManager->regDisplayMessage(bind(&MainWindow::_displayMessage, this, std::placeholders::_1, std::placeholders::_2));
209 andreas 614
    gPageManager->regFileDialogFunction(bind(&MainWindow::_fileDialog, this,
615
                                             std::placeholders::_1,
616
                                             std::placeholders::_2,
617
                                             std::placeholders::_3,
618
                                             std::placeholders::_4));
260 andreas 619
    gPageManager->regStartWait(bind(&MainWindow::_startWait, this, std::placeholders::_1));
620
    gPageManager->regStopWait(bind(&MainWindow::_stopWait, this));
271 andreas 621
    gPageManager->regPageFinished(bind(&MainWindow::_pageFinished, this, std::placeholders::_1));
92 andreas 622
    gPageManager->deployCallbacks();
5 andreas 623
 
264 andreas 624
    createActions();        // Create the toolbar, if enabled by settings.
625
 
2 andreas 626
#ifndef QT_NO_SESSIONMANAGER
264 andreas 627
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
5 andreas 628
    QGuiApplication::setFallbackSessionManagementEnabled(false);
629
    connect(qApp, &QGuiApplication::commitDataRequest,
630
            this, &MainWindow::writeSettings);
264 andreas 631
#endif  // QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
632
#endif  // QT_NO_SESSIONMANAGER
633
 
43 andreas 634
    // Some types used to transport data from the layer below.
14 andreas 635
    qRegisterMetaType<size_t>("size_t");
636
    qRegisterMetaType<QByteArray>("QByteArray");
41 andreas 637
    qRegisterMetaType<ANIMATION_t>("ANIMATION_t");
291 andreas 638
    qRegisterMetaType<Button::TButton*>("Button::TButton*");
62 andreas 639
    qRegisterMetaType<std::string>("std::string");
279 andreas 640
    qRegisterMetaType<SUBVIEWLIST_T>("SUBVIEWLIST_T");
283 andreas 641
    qRegisterMetaType<PGSUBVIEWITEM_T>("PGSUBVIEWITEM_T");
303 andreas 642
    qRegisterMetaType<PGSUBVIEWITEM_T>("PGSUBVIEWITEM_T&");
283 andreas 643
    qRegisterMetaType<PGSUBVIEWATOM_T>("PGSUBVIEWATOM_T");
644
    qRegisterMetaType<TBitmap>("TBitmap");
14 andreas 645
 
43 andreas 646
    // All the callback functions doesn't act directly. Instead they emit an
647
    // event. Then Qt decides whether the real function is started directly and
648
    // immediately or if the call is queued and called later in a thread. To
649
    // handle this we're "connecting" the real functions to some signals.
15 andreas 650
    try
651
    {
652
        connect(this, &MainWindow::sigDisplayButton, this, &MainWindow::displayButton);
280 andreas 653
        connect(this, &MainWindow::sigDisplayViewButton, this, &MainWindow::displayViewButton);
654
        connect(this, &MainWindow::sigAddViewButtonItems, this, &MainWindow::addViewButtonItems);
303 andreas 655
        connect(this, &MainWindow::sigShowViewButtonItem, this, &MainWindow::showViewButtonItem);
656
        connect(this, &MainWindow::sigUpdateViewButton, this, &MainWindow::updateViewButton);
657
        connect(this, &MainWindow::sigUpdateViewButtonItem, this, &MainWindow::updateViewButtonItem);
15 andreas 658
        connect(this, &MainWindow::sigSetPage, this, &MainWindow::setPage);
659
        connect(this, &MainWindow::sigSetSubPage, this, &MainWindow::setSubPage);
660
        connect(this, &MainWindow::sigSetBackground, this, &MainWindow::setBackground);
661
        connect(this, &MainWindow::sigDropPage, this, &MainWindow::dropPage);
662
        connect(this, &MainWindow::sigDropSubPage, this, &MainWindow::dropSubPage);
21 andreas 663
        connect(this, &MainWindow::sigPlayVideo, this, &MainWindow::playVideo);
50 andreas 664
        connect(this, &MainWindow::sigInputText, this, &MainWindow::inputText);
200 andreas 665
        connect(this, &MainWindow::sigListBox, this, &MainWindow::listBox);
62 andreas 666
        connect(this, &MainWindow::sigKeyboard, this, &MainWindow::showKeyboard);
667
        connect(this, &MainWindow::sigKeypad, this, &MainWindow::showKeypad);
64 andreas 668
        connect(this, &MainWindow::sigShowSetup, this, &MainWindow::showSetup);
71 andreas 669
        connect(this, &MainWindow::sigPlaySound, this, &MainWindow::playSound);
98 andreas 670
        connect(this, &MainWindow::sigDropButton, this, &MainWindow::dropButton);
671
        connect(this, &MainWindow::sigSetVisible, this, &MainWindow::SetVisible);
111 andreas 672
        connect(this, &MainWindow::sigSendVirtualKeys, this, &MainWindow::sendVirtualKeys);
140 andreas 673
        connect(this, &MainWindow::sigShowPhoneDialog, this, &MainWindow::showPhoneDialog);
674
        connect(this, &MainWindow::sigSetPhoneNumber, this, &MainWindow::setPhoneNumber);
675
        connect(this, &MainWindow::sigSetPhoneStatus, this, &MainWindow::setPhoneStatus);
141 andreas 676
        connect(this, &MainWindow::sigSetPhoneState, this, &MainWindow::setPhoneState);
142 andreas 677
        connect(this, &MainWindow::sigRepaintWindows, this, &MainWindow::repaintWindows);
151 andreas 678
        connect(this, &MainWindow::sigToFront, this, &MainWindow::toFront);
179 andreas 679
        connect(this, &MainWindow::sigOnProgressChanged, this, &MainWindow::onProgressChanged);
252 andreas 680
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
197 andreas 681
        connect(this, &MainWindow::sigSetSizeMainWindow, this, &MainWindow::setSizeMainWindow);
211 andreas 682
#endif
206 andreas 683
        connect(this, &MainWindow::sigDownloadSurface, this, &MainWindow::downloadSurface);
684
        connect(this, &MainWindow::sigDisplayMessage, this, &MainWindow::displayMessage);
209 andreas 685
        connect(this, &MainWindow::sigFileDialog, this, &MainWindow::fileDialog);
260 andreas 686
        connect(this, &MainWindow::sigStartWait, this, &MainWindow::startWait);
687
        connect(this, &MainWindow::sigStopWait, this, &MainWindow::stopWait);
271 andreas 688
        connect(this, &MainWindow::sigPageFinished, this, &MainWindow::pageFinished);
213 andreas 689
        connect(qApp, &QGuiApplication::applicationStateChanged, this, &MainWindow::onAppStateChanged);
130 andreas 690
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
691
        QScreen *screen = QGuiApplication::primaryScreen();
692
        connect(screen, &QScreen::orientationChanged, this, &MainWindow::onScreenOrientationChanged);
259 andreas 693
        connect(this, &MainWindow::sigActivateSettings, this, &MainWindow::activateSettings);
130 andreas 694
#endif
15 andreas 695
    }
696
    catch (std::exception& e)
697
    {
698
        MSG_ERROR("Connection error: " << e.what());
699
    }
93 andreas 700
    catch(...)
701
    {
702
        MSG_ERROR("Unexpected exception occured [MainWindow::MainWindow()]");
703
    }
15 andreas 704
 
5 andreas 705
    setUnifiedTitleAndToolBarOnMac(true);
182 andreas 706
#ifdef Q_OS_ANDROID
61 andreas 707
    // At least initialize the phone call listener
708
    if (gPageManager)
709
        gPageManager->initPhoneState();
92 andreas 710
 
93 andreas 711
    /*
712
     * In case this class was created not the first time, we initiate a small
713
     * thread to send the signal ApplicationActive to initiate the communication
714
     * with the controller again. This also starts the page manager thread
715
     * (TPageManager), which handles all elements of the surface.
716
     */
92 andreas 717
    if (_restart_ && gPageManager)
718
    {
93 andreas 719
        try
720
        {
721
            std::thread mThread = std::thread([=] { this->_signalState(Qt::ApplicationActive); });
722
            mThread.detach();   // We detach immediately to leave this method.
723
        }
724
        catch (std::exception& e)
725
        {
726
            MSG_ERROR("Error starting the thread to reinvoke communication!");
727
        }
728
        catch(...)
729
        {
730
            MSG_ERROR("Unexpected exception occured [MainWindow::MainWindow()]");
731
        }
92 andreas 732
    }
93 andreas 733
#endif
247 andreas 734
#ifdef Q_OS_IOS
735
    // To get the battery level periodicaly we setup a timer.
736
    if (!mIosBattery)
737
        mIosBattery = new TIOSBattery;
738
 
739
    mIosBattery->update();
740
 
264 andreas 741
    int left = mIosBattery->getBatteryLeft();
742
    int state = mIosBattery->getBatteryState();
743
    // At this point no buttons are registered and therefore the battery
744
    // state will not be visible. To have the state at the moment a button
745
    // is registered, we tell the page manager to store the values.
746
    gPageManager->setBattery(left, state);
747
    MSG_DEBUG("Battery state was set to " << left << "% and state " << state);
748
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
749
    if (gPageManager->getSettings()->isPortrait())
750
        QGuiApplication::primaryScreen()->setOrientationUpdateMask(Qt::PortraitOrientation | Qt::InvertedPortraitOrientation);
751
    else
752
        QGuiApplication::primaryScreen()->setOrientationUpdateMask(Qt::LandscapeOrientation | Qt::InvertedLandscapeOrientation);
753
#endif  // QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
247 andreas 754
#endif  // Q_OS_IOS
755
 
92 andreas 756
    _restart_ = false;
2 andreas 757
}
758
 
34 andreas 759
MainWindow::~MainWindow()
760
{
761
    DECL_TRACER("MainWindow::~MainWindow()");
40 andreas 762
 
34 andreas 763
    killed = true;
764
    prg_stopped = true;
296 andreas 765
 
766
    disconnect(this, &MainWindow::sigDisplayButton, this, &MainWindow::displayButton);
767
    disconnect(this, &MainWindow::sigDisplayViewButton, this, &MainWindow::displayViewButton);
768
    disconnect(this, &MainWindow::sigAddViewButtonItems, this, &MainWindow::addViewButtonItems);
769
    disconnect(this, &MainWindow::sigSetPage, this, &MainWindow::setPage);
770
    disconnect(this, &MainWindow::sigSetSubPage, this, &MainWindow::setSubPage);
771
    disconnect(this, &MainWindow::sigSetBackground, this, &MainWindow::setBackground);
772
    disconnect(this, &MainWindow::sigDropPage, this, &MainWindow::dropPage);
773
    disconnect(this, &MainWindow::sigDropSubPage, this, &MainWindow::dropSubPage);
774
    disconnect(this, &MainWindow::sigPlayVideo, this, &MainWindow::playVideo);
775
    disconnect(this, &MainWindow::sigInputText, this, &MainWindow::inputText);
776
    disconnect(this, &MainWindow::sigListBox, this, &MainWindow::listBox);
777
    disconnect(this, &MainWindow::sigKeyboard, this, &MainWindow::showKeyboard);
778
    disconnect(this, &MainWindow::sigKeypad, this, &MainWindow::showKeypad);
779
    disconnect(this, &MainWindow::sigShowSetup, this, &MainWindow::showSetup);
780
    disconnect(this, &MainWindow::sigPlaySound, this, &MainWindow::playSound);
781
    disconnect(this, &MainWindow::sigDropButton, this, &MainWindow::dropButton);
782
    disconnect(this, &MainWindow::sigSetVisible, this, &MainWindow::SetVisible);
783
    disconnect(this, &MainWindow::sigSendVirtualKeys, this, &MainWindow::sendVirtualKeys);
784
    disconnect(this, &MainWindow::sigShowPhoneDialog, this, &MainWindow::showPhoneDialog);
785
    disconnect(this, &MainWindow::sigSetPhoneNumber, this, &MainWindow::setPhoneNumber);
786
    disconnect(this, &MainWindow::sigSetPhoneStatus, this, &MainWindow::setPhoneStatus);
787
    disconnect(this, &MainWindow::sigSetPhoneState, this, &MainWindow::setPhoneState);
788
    disconnect(this, &MainWindow::sigRepaintWindows, this, &MainWindow::repaintWindows);
789
    disconnect(this, &MainWindow::sigToFront, this, &MainWindow::toFront);
790
    disconnect(this, &MainWindow::sigOnProgressChanged, this, &MainWindow::onProgressChanged);
791
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
792
    disconnect(this, &MainWindow::sigSetSizeMainWindow, this, &MainWindow::setSizeMainWindow);
793
#endif
794
    disconnect(this, &MainWindow::sigDownloadSurface, this, &MainWindow::downloadSurface);
795
    disconnect(this, &MainWindow::sigDisplayMessage, this, &MainWindow::displayMessage);
796
    disconnect(this, &MainWindow::sigFileDialog, this, &MainWindow::fileDialog);
797
    disconnect(this, &MainWindow::sigStartWait, this, &MainWindow::startWait);
798
    disconnect(this, &MainWindow::sigStopWait, this, &MainWindow::stopWait);
799
    disconnect(this, &MainWindow::sigPageFinished, this, &MainWindow::pageFinished);
800
    disconnect(qApp, &QGuiApplication::applicationStateChanged, this, &MainWindow::onAppStateChanged);
801
 
254 andreas 802
#ifdef Q_OS_IOS
252 andreas 803
    if (mSource)
804
    {
805
        delete mSource;
806
        mSource = nullptr;
807
    }
254 andreas 808
#endif
141 andreas 809
    if (mMediaPlayer)
181 andreas 810
    {
264 andreas 811
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
181 andreas 812
        delete mAudioOutput;
813
#endif
141 andreas 814
        delete mMediaPlayer;
181 andreas 815
    }
141 andreas 816
 
34 andreas 817
    if (gAmxNet && !gAmxNet->isStopped())
818
        gAmxNet->stop();
90 andreas 819
 
820
    if (mToolbar)
821
    {
822
        removeToolBar(mToolbar);
823
        mToolbar = nullptr;
824
    }
825
 
826
    isRunning = false;
247 andreas 827
#ifdef Q_OS_IOS
252 andreas 828
    if (mIosRotate)
829
        mIosRotate->automaticRotation(true);
247 andreas 830
 
831
    if (mIosBattery)
832
    {
833
        delete mIosBattery;
834
        mIosBattery = nullptr;
835
    }
252 andreas 836
 
837
    if (mIosRotate)
838
        delete mIosRotate;
247 andreas 839
#endif
323 andreas 840
 
841
    if (mGestureFilter)
842
    {
843
        disconnect(mGestureFilter, &TQGestureFilter::gestureEvent, this, &MainWindow::onGestureEvent);
844
        delete mGestureFilter;
845
    }
34 andreas 846
}
847
 
235 andreas 848
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
21 andreas 849
/**
93 andreas 850
 * @brief Small thread to invoke the initialization on an Android device.
851
 *
852
 * On Android devices the signal ApplicationActive is not send if the class
853
 * \p MainWindow is destroyed and recreated. Therefore we need this little
854
 * helper to send the signal when the class is initialized.
855
 *
856
 * @param state     This defines the signal to send.
857
 */
858
void MainWindow::_signalState(Qt::ApplicationState state)
859
{
860
    DECL_TRACER("MainWindow::_signalState(Qt::ApplicationState state)");
861
 
862
    std::this_thread::sleep_for(std::chrono::seconds(1));   // Wait a second
213 andreas 863
    onAppStateChanged(state);
93 andreas 864
}
130 andreas 865
 
866
void MainWindow::_orientationChanged(int orientation)
867
{
868
    DECL_TRACER("MainWindow::_orientationChanged(int orientation)");
869
 
264 andreas 870
    if (gPageManager && gPageManager->getSettings()->isPortrait())  // portrait?
131 andreas 871
    {
872
        if (orientation == O_REVERSE_PORTRAIT && mOrientation != Qt::InvertedPortraitOrientation)
245 andreas 873
        {
131 andreas 874
            _setOrientation((J_ORIENTATION)orientation);
245 andreas 875
            mOrientation = Qt::InvertedPortraitOrientation;
876
        }
131 andreas 877
        else if (orientation == O_PORTRAIT && mOrientation != Qt::PortraitOrientation)
245 andreas 878
        {
131 andreas 879
            _setOrientation((J_ORIENTATION)orientation);
245 andreas 880
            mOrientation = Qt::PortraitOrientation;
881
        }
131 andreas 882
    }
883
    else
884
    {
885
        if (orientation == O_REVERSE_LANDSCAPE && mOrientation != Qt::InvertedLandscapeOrientation)
245 andreas 886
        {
131 andreas 887
            _setOrientation((J_ORIENTATION)orientation);
245 andreas 888
            mOrientation = Qt::InvertedLandscapeOrientation;
889
        }
131 andreas 890
        else if (orientation == O_LANDSCAPE && mOrientation != Qt::LandscapeOrientation)
245 andreas 891
        {
131 andreas 892
            _setOrientation((J_ORIENTATION)orientation);
245 andreas 893
            mOrientation = Qt::LandscapeOrientation;
894
        }
131 andreas 895
    }
130 andreas 896
}
93 andreas 897
 
259 andreas 898
void MainWindow::_activateSettings(const std::string& oldNetlinx, int oldPort, int oldChannelID, const std::string& oldSurface, bool oldToolbarSuppress, bool oldToolbarForce)
899
{
900
    DECL_TRACER("MainWindow::_activateSettings(const std::string& oldNetlinx, int oldPort, int oldChannelID, const std::string& oldSurface, bool oldToolbarSuppress, bool oldToolbarForce)");
901
 
902
    emit sigActivateSettings(oldNetlinx, oldPort, oldChannelID, oldSurface, oldToolbarSuppress, oldToolbarForce);
903
}
904
 
217 andreas 905
/**
259 andreas 906
 * @brief MainWindow::activateSettings
907
 * This method activates some urgent settings. It is called on Android and IOS
908
 * after the setup dialog was closed. The method expects some values taken
909
 * immediately before the setup dialog was started. If takes some actions like
910
 * downloading a surface when the setting for it changed or removes the
911
 * toolbar on the right if the user reuqsted it.
912
 *
913
 * @param oldNetlinx        The IP or name of the Netlinx
914
 * @param oldPort           The network port number used to connect to Netlinx
915
 * @param oldChannelID      The channel ID TPanel uses to identify against the
916
 *                          Netlinx.
917
 * @param oldSurface        The name of theprevious TP4 file.
918
 * @param oldToolbarSuppress    State of toolbar suppress switch
919
 * @param oldToolbarForce   The state of toolbar force switch
920
 */
921
void MainWindow::activateSettings(const std::string& oldNetlinx, int oldPort, int oldChannelID, const std::string& oldSurface, bool oldToolbarSuppress, bool oldToolbarForce)
922
{
923
    DECL_TRACER("MainWindow::activateSettings(const std::string& oldNetlinx, int oldPort, int oldChannelID, const std::string& oldSurface, bool oldToolbarSuppress, bool oldToolbarForce)");
924
 
925
#ifdef Q_OS_IOS
926
    TConfig cf(TConfig::getConfigPath() + "/" + TConfig::getConfigFileName());
927
#endif
928
    bool rebootAnyway = false;
260 andreas 929
    bool doDownload = false;
259 andreas 930
    string newSurface = TConfig::getFtpSurface();
931
 
932
    if (!TConfig::getToolbarSuppress() && oldToolbarForce != TConfig::getToolbarForce())
933
    {
934
        QMessageBox msgBox(this);
935
        msgBox.setText("The change for the visibility of the toolbar will be active on the next start of TPanel!");
936
        msgBox.exec();
937
    }
938
    else if (oldToolbarSuppress != TConfig::getToolbarSuppress() && TConfig::getToolbarSuppress())
939
    {
940
        if (mToolbar)
941
        {
942
            mToolbar->close();
943
            delete mToolbar;
944
            mToolbar = nullptr;
945
        }
946
    }
260 andreas 947
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
259 andreas 948
    if (newSurface != oldSurface || TTPInit::haveSystemMarker())
949
#else
262 andreas 950
    time_t dlTime = TConfig::getFtpDownloadTime();
951
    time_t actTime = time(NULL);
952
 
259 andreas 953
    if (newSurface != oldSurface || dlTime == 0 || dlTime < (actTime - 60))
954
#endif
955
    {
956
        MSG_DEBUG("Surface should be downloaded (Old: " << oldSurface << ", New: " << newSurface << ")");
957
 
958
        QMessageBox msgBox(this);
959
        msgBox.setText(QString("Should the surface <b>") + newSurface.c_str() + "</b> be installed?");
960
        msgBox.addButton(QMessageBox::Yes);
961
        msgBox.addButton(QMessageBox::No);
962
        int ret = msgBox.exec();
963
 
964
        if (ret == QMessageBox::Yes)
965
        {
260 andreas 966
            doDownload = true;
259 andreas 967
            TTPInit tpinit;
968
            std::vector<TTPInit::FILELIST_t> mFileList;
969
            // Get the list of TP4 files from NetLinx, if there are any.
260 andreas 970
            TQtWait waitBox(this, string("Please wait while I'm looking at the disc of Netlinx (") + TConfig::getController().c_str() + ") for TP4 files ...");
971
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
972
            waitBox.setScaleFactor(mScaleFactor);
973
            waitBox.doResize();
974
            waitBox.start();
975
#endif
259 andreas 976
            tpinit.setPath(TConfig::getProjectPath());
977
            tpinit.regCallbackProcessEvents(bind(&MainWindow::runEvents, this));
978
            tpinit.regCallbackProgressBar(bind(&MainWindow::_onProgressChanged, this, std::placeholders::_1));
979
            mFileList = tpinit.getFileList(".tp4");
980
            bool found = false;
981
 
982
            if (mFileList.size() > 0)
983
            {
984
                vector<TTPInit::FILELIST_t>::iterator iter;
985
 
986
                for (iter = mFileList.begin(); iter != mFileList.end(); ++iter)
987
                {
988
                    if (iter->fname == newSurface)
989
                    {
990
                        tpinit.setFileSize(iter->size);
991
                        found = true;
992
                        break;
993
                    }
994
                }
995
            }
996
 
260 andreas 997
            waitBox.end();
259 andreas 998
 
999
            if (found)
1000
            {
1001
                string msg = "Loading file <b>" + newSurface + "</b>.";
1002
                MSG_DEBUG("Download of surface " << newSurface << " was forced!");
1003
 
1004
                downloadBar(msg, this);
1005
 
1006
                if (tpinit.loadSurfaceFromController(true))
1007
                    rebootAnyway = true;
1008
 
1009
                mDownloadBar->close();
1010
                mBusy = false;
1011
            }
1012
            else
1013
            {
1014
                MSG_PROTOCOL("The surface " << newSurface << " does not exist on NetLinx or the NetLinx " << TConfig::getController() << " was not found!");
1015
                displayMessage("The surface " + newSurface + " does not exist on NetLinx or the NetLinx " + TConfig::getController() + " was not found!", "Information");
1016
            }
1017
        }
1018
    }
1019
 
260 andreas 1020
    if (doDownload &&
1021
        (TConfig::getController() != oldNetlinx ||
259 andreas 1022
        TConfig::getChannel() != oldChannelID ||
260 andreas 1023
        TConfig::getPort() != oldPort || rebootAnyway))
259 andreas 1024
    {
1025
        // Start over by exiting this class
1026
        MSG_INFO("Program will start over!");
1027
        _restart_ = true;
1028
        prg_stopped = true;
1029
        killed = true;
1030
 
1031
        if (gAmxNet)
1032
            gAmxNet->stop();
1033
 
1034
        close();
1035
    }
1036
#ifdef Q_OS_ANDROID
1037
    else
1038
    {
1039
        TConfig cf(TConfig::getConfigPath() + "/" + TConfig::getConfigFileName());
1040
    }
1041
#endif
1042
}
1043
 
1044
/**
217 andreas 1045
 * @brief MainWindow::_freezeWorkaround: A workaround for the screen freeze.
271 andreas 1046
 * On Mobiles the screen sometimes stay frozen after the application state
1047
 * changes to ACTIVE or some yet unidentified things happened.
217 andreas 1048
 * The workaround produces a faked geometry change which makes the Qt framework
271 andreas 1049
 * to reattach to the screen.
1050
 * There may be situations where this workaround could trigger a repaint of all
1051
 * objects on the screen but then the surface is still frozen. At the moment of
1052
 * writing this comment I have no workaround or even an explanation for this.
217 andreas 1053
 */
264 andreas 1054
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
271 andreas 1055
/**
1056
 * @brief MainWindow::_freezeWorkaround
1057
 * This hack was made from Thomas Andersen. You'll find it at:
1058
 * https://bugreports.qt.io/browse/QTBUG-76142
1059
 */
217 andreas 1060
void MainWindow::_freezeWorkaround()
1061
{
1062
    DECL_TRACER("MainWindow::_freezeWorkaround()");
1063
 
1064
    QScreen* scr = QGuiApplication::screens().first();
1065
    QPlatformScreen* l_pScr = scr->handle(); /*QAndroidPlatformScreen*/
1066
    QRect l_geomHackAdjustedRect = l_pScr->availableGeometry();
1067
    QRect l_geomHackRect = l_geomHackAdjustedRect;
271 andreas 1068
    l_geomHackAdjustedRect.adjust(0, 0, 0, 5);
217 andreas 1069
    QMetaObject::invokeMethod(dynamic_cast<QObject*>(l_pScr), "setAvailableGeometry", Qt::DirectConnection, Q_ARG( const QRect &, l_geomHackAdjustedRect ));
1070
    QMetaObject::invokeMethod(dynamic_cast<QObject*>(l_pScr), "setAvailableGeometry", Qt::QueuedConnection, Q_ARG( const QRect &, l_geomHackRect ));
1071
}
271 andreas 1072
#endif  // QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
235 andreas 1073
#endif  // Q_OS_ANDROID || Q_OS_IOS
217 andreas 1074
 
142 andreas 1075
void MainWindow::_repaintWindows()
1076
{
1077
    DECL_TRACER("MainWindow::_repaintWindows()");
1078
 
156 andreas 1079
    emit sigRepaintWindows();
142 andreas 1080
}
151 andreas 1081
 
1082
void MainWindow::_toFront(ulong handle)
1083
{
1084
    DECL_TRACER("MainWindow::_toFront(ulong handle)");
1085
 
156 andreas 1086
    emit sigToFront(handle);
151 andreas 1087
}
1088
 
206 andreas 1089
void MainWindow::_downloadSurface(const string &file, size_t size)
1090
{
1091
    DECL_TRACER("MainWindow::_downloadSurface(const string &file, size_t size)");
1092
 
1093
    emit sigDownloadSurface(file, size);
1094
}
1095
 
260 andreas 1096
void MainWindow::_startWait(const string& text)
1097
{
1098
    DECL_TRACER("MainWindow::_startWait(const string& text)");
1099
 
1100
    emit sigStartWait(text);
1101
}
1102
 
1103
void MainWindow::_stopWait()
1104
{
1105
    DECL_TRACER("MainWindow::_stopWait()");
1106
 
1107
    emit sigStopWait();
1108
}
1109
 
271 andreas 1110
void MainWindow::_pageFinished(uint handle)
1111
{
1112
    DECL_TRACER("MainWindow::_pageFinished(uint handle)");
1113
 
1114
    emit sigPageFinished(handle);
1115
}
1116
 
93 andreas 1117
/**
21 andreas 1118
 * @brief MainWindow::closeEvent called when the application receives an exit event.
1119
 *
1120
 * If the user clicks on the exit icon or on the menu point _Exit_ this method
1121
 * is called. It makes sure everything is written to the configuration file
1122
 * and accepts the evernt.
1123
 *
1124
 * @param event The exit event
1125
 */
2 andreas 1126
void MainWindow::closeEvent(QCloseEvent *event)
1127
{
5 andreas 1128
    DECL_TRACER("MainWindow::closeEvent(QCloseEvent *event)");
24 andreas 1129
#ifdef __ANDROID__
23 andreas 1130
    __android_log_print(ANDROID_LOG_DEBUG,"tpanel","Close event; settingsChanged=%s", (settingsChanged ? "true":"false"));
24 andreas 1131
#endif
5 andreas 1132
    if (settingsChanged)
1133
    {
1134
        writeSettings();
1135
        event->accept();
1136
    }
1137
    else
1138
    {
21 andreas 1139
        prg_stopped = true;
34 andreas 1140
        killed = true;
36 andreas 1141
        MSG_INFO("Program will stop!");
37 andreas 1142
#ifdef __ANDROID__
92 andreas 1143
        if (gPageManager)
1144
            gPageManager->stopNetworkState();
37 andreas 1145
#endif
5 andreas 1146
        event->accept();
1147
    }
2 andreas 1148
}
1149
 
21 andreas 1150
/**
57 andreas 1151
 * @brief MainWindow::event Looks for a gesture
1152
 * @param event The event occured
1153
 * @return TRUE if event was accepted
1154
 */
1155
bool MainWindow::event(QEvent* event)
1156
{
1157
    if (event->type() == QEvent::Gesture)
1158
        return gestureEvent(static_cast<QGestureEvent*>(event));
1159
 
323 andreas 1160
    return QMainWindow::event(event);
57 andreas 1161
}
1162
 
1163
/**
1164
 * @brief MainWindow::gestureEvent handles a pinch event
1165
 * If a pinch event occured where the scale factor increased, the settings
1166
 * dialog is called. This exists for devices, where the left toolbox is not
1167
 * visible.
1168
 * @param event The guesture occured
130 andreas 1169
 * @return FALSE
57 andreas 1170
 */
1171
bool MainWindow::gestureEvent(QGestureEvent* event)
1172
{
1173
    DECL_TRACER("MainWindow::gestureEvent(QGestureEvent* event)");
59 andreas 1174
 
57 andreas 1175
    if (QGesture *pinch = event->gesture(Qt::PinchGesture))
1176
    {
323 andreas 1177
        QPinchGesture *pg = static_cast<QPinchGesture *>(pinch);
298 andreas 1178
#ifdef QT_DEBUG
57 andreas 1179
        string gs;
323 andreas 1180
 
57 andreas 1181
        switch(pg->state())
1182
        {
1183
            case Qt::NoGesture:         gs.assign("no gesture"); break;
1184
            case Qt::GestureStarted:    gs.assign("gesture started"); break;
1185
            case Qt::GestureUpdated:    gs.assign("gesture updated"); break;
1186
            case Qt::GestureFinished:   gs.assign("gesture finished"); break;
1187
            case Qt::GestureCanceled:   gs.assign("gesture canceled"); break;
1188
        }
1189
 
59 andreas 1190
        MSG_DEBUG("PinchGesture state " << gs << " detected");
298 andreas 1191
#endif
57 andreas 1192
        if (pg->state() == Qt::GestureFinished)
1193
        {
59 andreas 1194
            MSG_DEBUG("total scale: " << pg->totalScaleFactor() << ", scale: " << pg->scaleFactor() << ", last scale: " << pg->lastScaleFactor());
1195
 
57 andreas 1196
            if (pg->totalScaleFactor() > pg->scaleFactor())
1197
                settings();
323 andreas 1198
 
1199
            return true;
57 andreas 1200
        }
1201
    }
153 andreas 1202
    else if (QGesture *swipe = event->gesture(Qt::SwipeGesture))
1203
    {
1204
        if (!gPageManager)
1205
            return false;
1206
 
1207
        QSwipeGesture *sw = static_cast<QSwipeGesture *>(swipe);
1208
        MSG_DEBUG("Swipe gesture detected.");
1209
 
1210
        if (sw->state() == Qt::GestureFinished)
1211
        {
1212
            if (sw->horizontalDirection() == QSwipeGesture::Left)
1213
                gPageManager->onSwipeEvent(TPageManager::SW_LEFT);
1214
            else if (sw->horizontalDirection() == QSwipeGesture::Right)
1215
                gPageManager->onSwipeEvent(TPageManager::SW_RIGHT);
1216
            else if (sw->verticalDirection() == QSwipeGesture::Up)
1217
                gPageManager->onSwipeEvent(TPageManager::SW_UP);
1218
            else if (sw->verticalDirection() == QSwipeGesture::Down)
1219
                gPageManager->onSwipeEvent(TPageManager::SW_DOWN);
323 andreas 1220
 
1221
            return true;
153 andreas 1222
        }
1223
    }
1224
 
57 andreas 1225
    return false;
1226
}
1227
 
1228
/**
319 andreas 1229
 * @brief MainWindow::mousePressEvent catches the event Qt::LeftButton.
1230
 *
1231
 * If the user presses the left mouse button somewhere in the main window, this
1232
 * method is triggered. It retrieves the position of the mouse pointer and
1233
 * sends it to the page manager TPageManager.
1234
 *
1235
 * @param event The event
1236
 */
1237
void MainWindow::mousePressEvent(QMouseEvent* event)
1238
{
1239
    DECL_TRACER("MainWindow::mousePressEvent(QMouseEvent* event)");
1240
 
1241
    if (!gPageManager)
1242
        return;
1243
 
1244
    if(event->button() == Qt::LeftButton)
1245
    {
1246
        int nx = 0, ny = 0;
320 andreas 1247
#ifdef Q_OS_IOS
319 andreas 1248
        if (mHaveNotchPortrait && gPageManager->getSettings()->isPortrait())
1249
        {
1250
            nx = mNotchPortrait.left();
1251
            ny = mNotchPortrait.top();
1252
        }
1253
        else if (mHaveNotchLandscape && gPageManager->getSettings()->isLandscape())
1254
        {
1255
            nx = mNotchLandscape.left();
1256
            ny = mNotchLandscape.top();
1257
        }
1258
        else
1259
        {
1260
            MSG_WARNING("Have no notch distances!");
1261
        }
320 andreas 1262
#endif
319 andreas 1263
        int x = event->x() - nx;
1264
        int y = event->y() - ny;
1265
        MSG_DEBUG("Mouse press coordinates: x: " << event->x() << ", y: " << event->y() << " [new x: " << x << ", y: " << y << " -- \"notch\" nx: " << nx << ", ny: " << ny << "]");
320 andreas 1266
#ifdef Q_OS_IOS
319 andreas 1267
        MSG_DEBUG("Mouse press coords alt.: pos.x: " << event->position().x() << ", pos.y: " << event->position().y() << ", local.x: " << event->localPos().x() << ", local.y: " << event->localPos().y());
320 andreas 1268
#elif defined Q_OS_ANDROID
319 andreas 1269
        MSG_DEBUG("Mouse press coords alt.: pos.x: " << event->pos().x() << ", pos.y: " << event->pos().y() << ", local.x: " << event->localPos().x() << ", local.y: " << event->localPos().y());
320 andreas 1270
#endif
319 andreas 1271
        mLastPressX = x;
1272
        mLastPressY = y;
320 andreas 1273
/*
319 andreas 1274
        QWidget *w = childAt(event->x(), event->y());
1275
 
1276
        if (w)
1277
        {
1278
            MSG_DEBUG("Object " << w->objectName().toStdString() << " is under mouse cursor.");
1279
            QObject *par = w->parent();
1280
 
1281
            if (par)
1282
            {
1283
                MSG_DEBUG("The parent is " << par->objectName().toStdString());
1284
 
1285
                if (par->objectName().startsWith("Item_"))
1286
                {
1287
                    QObject *ppar = par->parent();
1288
 
1289
                    if (ppar)
1290
                    {
1291
                        MSG_DEBUG("The pparent is " << ppar->objectName().toStdString());
1292
 
1293
                        if (ppar->objectName().startsWith("View_"))
1294
                        {
1295
                            QMouseEvent *mev = new QMouseEvent(event->type(), event->localPos(), event->globalPos(), event->button(), event->buttons(), event->modifiers());
1296
                            QApplication::postEvent(ppar, mev);
1297
                            return;
1298
                        }
1299
                    }
1300
                }
1301
            }
1302
        }
320 andreas 1303
*/
319 andreas 1304
        if (gPageManager->isSetupActive() && isSetupScaled())
1305
        {
1306
            x = (int)((double)x / mSetupScaleFactor);
1307
            y = (int)((double)y / mSetupScaleFactor);
1308
        }
1309
        else if (isScaled())
1310
        {
1311
            x = (int)((double)x / mScaleFactor);
1312
            y = (int)((double)y / mScaleFactor);
1313
        }
1314
 
1315
        gPageManager->mouseEvent(x, y, true);
1316
        mTouchStart = std::chrono::steady_clock::now();
1317
        mTouchX = mLastPressX;
1318
        mTouchY = mLastPressY;
1319
    }
1320
    else if (event->button() == Qt::MiddleButton)
1321
        settings();
1322
}
1323
 
1324
/**
1325
 * @brief MainWindow::mouseReleaseEvent catches the event Qt::LeftButton.
1326
 *
1327
 * If the user releases the left mouse button somewhere in the main window, this
1328
 * method is triggered. It retrieves the position of the mouse pointer and
1329
 * sends it to the page manager TPageManager.
1330
 *
1331
 * @param event The event
1332
 */
1333
void MainWindow::mouseReleaseEvent(QMouseEvent* event)
1334
{
1335
    DECL_TRACER("MainWindow::mouseReleaseEvent(QMouseEvent* event)");
1336
 
1337
    if (!gPageManager)
1338
        return;
1339
 
1340
    if(event->button() == Qt::LeftButton)
1341
    {
1342
        int nx = 0, ny = 0;
320 andreas 1343
#ifdef Q_OS_IOS
319 andreas 1344
        if (mHaveNotchPortrait && gPageManager->getSettings()->isPortrait())
1345
        {
1346
            nx = mNotchPortrait.left();
1347
            ny = mNotchPortrait.top();
1348
        }
1349
        else if (mHaveNotchLandscape && gPageManager->getSettings()->isLandscape())
1350
        {
1351
            nx = mNotchLandscape.left();
1352
            ny = mNotchLandscape.top();
1353
        }
320 andreas 1354
#endif
319 andreas 1355
        int x = ((mLastPressX >= 0) ? mLastPressX : (event->x() - nx));
1356
        int y = ((mLastPressY >= 0) ? mLastPressY : (event->y() - ny));
1357
        MSG_DEBUG("Mouse press coordinates: x: " << event->x() << ", y: " << event->y());
1358
        mLastPressX = mLastPressY = -1;
320 andreas 1359
/*
319 andreas 1360
        QWidget *w = childAt(event->x(), event->y());
1361
 
1362
        if (w)
1363
        {
1364
            MSG_DEBUG("Object " << w->objectName().toStdString() << " is under mouse cursor.");
1365
            QObject *par = w->parent();
1366
 
1367
            if (par)
1368
            {
1369
                MSG_DEBUG("The parent is " << par->objectName().toStdString());
1370
 
1371
                if (par->objectName().startsWith("Item_"))
1372
                {
1373
                    QObject *ppar = par->parent();
1374
 
1375
                    if (ppar)
1376
                    {
1377
                        MSG_DEBUG("The pparent is " << ppar->objectName().toStdString());
1378
 
1379
                        if (ppar->objectName().startsWith("View_"))
1380
                        {
1381
                            QMouseEvent *mev = new QMouseEvent(event->type(), event->localPos(), event->globalPos(), event->button(), event->buttons(), event->modifiers());
1382
                            QApplication::postEvent(ppar, mev);
1383
                            return;
1384
                        }
1385
                    }
1386
                }
1387
            }
1388
        }
320 andreas 1389
*/
319 andreas 1390
        if (gPageManager->isSetupActive() && isSetupScaled())
1391
        {
1392
            x = (int)((double)x / mSetupScaleFactor);
1393
            y = (int)((double)y / mSetupScaleFactor);
1394
        }
1395
        else if (isScaled())
1396
        {
1397
            x = (int)((double)x / mScaleFactor);
1398
            y = (int)((double)y / mScaleFactor);
1399
        }
1400
 
1401
        gPageManager->mouseEvent(x, y, false);
1402
        std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
1403
        std::chrono::nanoseconds difftime = end - mTouchStart;
1404
        std::chrono::milliseconds msecs = std::chrono::duration_cast<std::chrono::milliseconds>(difftime);
1405
 
1406
        if (msecs.count() < 100)    // 1/10 of a second
1407
        {
1408
            MSG_DEBUG("Time was too short: " << msecs.count());
1409
            return;
1410
        }
1411
 
1412
        x = event->x();
1413
        y = event->y();
1414
        bool setupActive = gPageManager->isSetupActive();
1415
        int width = (setupActive ? scaleSetup(gPageManager->getSystemSettings()->getWidth()) : scale(gPageManager->getSettings()->getWidth()));
1416
        int height = (setupActive ? scaleSetup(gPageManager->getSystemSettings()->getHeight()) : scale(gPageManager->getSettings()->getHeight()));
1417
        MSG_DEBUG("Coordinates: x1=" << mTouchX << ", y1=" << mTouchY << ", x2=" << x << ", y2=" << y << ", width=" << width << ", height=" << height);
1418
 
1419
        if (mTouchX < x && (x - mTouchX) > (width / 3))
1420
            gPageManager->onSwipeEvent(TPageManager::SW_RIGHT);
1421
        else if (x < mTouchX && (mTouchX - x) > (width / 3))
1422
            gPageManager->onSwipeEvent(TPageManager::SW_LEFT);
1423
        else if (mTouchY < y && (y - mTouchY) > (height / 3))
1424
            gPageManager->onSwipeEvent(TPageManager::SW_DOWN);
1425
        else if (y < mTouchY && (mTouchY - y) > (height / 3))
1426
            gPageManager->onSwipeEvent(TPageManager::SW_UP);
1427
    }
1428
}
1429
 
1430
void MainWindow::mouseMoveEvent(QMouseEvent* event)
1431
{
1432
    DECL_TRACER("MainWindow::mouseMoveEvent(QMouseEvent* event)");
323 andreas 1433
 
1434
    Q_UNUSED(event);
320 andreas 1435
/*
319 andreas 1436
    QWidget *w = childAt(event->x(), event->y());
1437
 
1438
    if (w)
1439
    {
1440
        MSG_DEBUG("Object " << w->objectName().toStdString() << " is under mouse cursor.");
1441
        QObject *par = w->parent();
1442
 
1443
        if (par)
1444
        {
1445
            MSG_DEBUG("The parent is " << par->objectName().toStdString());
1446
 
1447
            if (par->objectName().startsWith("Item_"))
1448
            {
1449
                QObject *ppar = par->parent();
1450
 
1451
                if (ppar)
1452
                {
1453
                    MSG_DEBUG("The pparent is " << ppar->objectName().toStdString());
1454
 
1455
                    if (ppar->objectName().startsWith("View_"))
1456
                    {
1457
                        QMouseEvent *mev = new QMouseEvent(event->type(), event->localPos(), event->globalPos(), event->button(), event->buttons(), event->modifiers());
1458
                        QApplication::postEvent(ppar, mev);
1459
                        return;
1460
                    }
1461
                }
1462
            }
1463
        }
1464
    }
320 andreas 1465
*/
319 andreas 1466
}
1467
 
1468
void MainWindow::keyPressEvent(QKeyEvent *event)
1469
{
1470
    DECL_TRACER("MainWindow::keyPressEvent(QKeyEvent *event)");
1471
 
1472
    if (event && event->key() == Qt::Key_Back && !mToolbar)
1473
    {
1474
        QMessageBox msgBox(this);
1475
        msgBox.setText("Select what to do next:");
1476
        msgBox.addButton("Quit", QMessageBox::AcceptRole);
1477
        msgBox.addButton("Setup", QMessageBox::RejectRole);
1478
        msgBox.addButton("Cancel", QMessageBox::ResetRole);
1479
        int ret = msgBox.exec();
1480
 
1481
        if (ret == QMessageBox::Accepted)   // This is correct! QT seems to change here the buttons.
1482
        {
1483
            showSetup();
1484
            return;
1485
        }
1486
        else if (ret == QMessageBox::Rejected)  // This is correct! QT seems to change here the buttons.
1487
            close();
1488
    }
1489
}
1490
 
1491
void MainWindow::keyReleaseEvent(QKeyEvent *event)
1492
{
1493
    DECL_TRACER("MainWindow::keyReleaseEvent(QKeyEvent *event)");
1494
 
323 andreas 1495
    Q_UNUSED(event);
319 andreas 1496
}
1497
 
1498
/**
130 andreas 1499
 * @brief MainWindow::onScreenOrientationChanged sets invers or normal orientation.
1500
 * This method sets according to the actual set orientation the invers
1501
 * orientations or switches back to normal orientation.
1502
 * For example: When the orientation is set to portrait and the device is turned
1503
 * to top down, then the orientation is set to invers portrait.
1504
 * @param ori   The detected orientation
1505
 */
1506
void MainWindow::onScreenOrientationChanged(Qt::ScreenOrientation ori)
1507
{
1508
    DECL_TRACER("MainWindow::onScreenOrientationChanged(int ori)");
265 andreas 1509
#if defined(QT_DEBUG) && (defined(Q_OS_IOS) || defined(Q_OS_ANDROID))
298 andreas 1510
    MSG_DEBUG("Orientation changed to " << orientationToString(ori) << " (mOrientation: " << orientationToString(mOrientation) << ")");
263 andreas 1511
#endif
249 andreas 1512
    if (!gPageManager)
130 andreas 1513
        return;
1514
 
249 andreas 1515
    if (gPageManager->getSettings()->isPortrait())
1516
    {
263 andreas 1517
#ifdef Q_OS_IOS
1518
        if (!mHaveNotchPortrait)
1519
            setNotch();
1520
#endif
249 andreas 1521
        if (ori == Qt::PortraitOrientation || ori == Qt::InvertedPortraitOrientation)
1522
        {
264 andreas 1523
#ifdef Q_OS_IOS
1524
            if (mSensor)
1525
                mSensor->setCurrentOrientation(ori);
1526
#endif
249 andreas 1527
            if (mOrientation == ori)
1528
                return;
130 andreas 1529
 
249 andreas 1530
            mOrientation = ori;
1531
        }
1532
        else if (mOrientation != Qt::PortraitOrientation && mOrientation != Qt::InvertedPortraitOrientation)
1533
            mOrientation = Qt::PortraitOrientation;
1534
    }
1535
    else
1536
    {
263 andreas 1537
#ifdef Q_OS_IOS
1538
        if (!mHaveNotchLandscape)
1539
            setNotch();
1540
#endif
249 andreas 1541
        if (ori == Qt::LandscapeOrientation || ori == Qt::InvertedLandscapeOrientation)
1542
        {
264 andreas 1543
#ifdef Q_OS_IOS
1544
            if (mSensor)
1545
                mSensor->setCurrentOrientation(ori);
1546
#endif
249 andreas 1547
            if (mOrientation == ori)
1548
                return;
130 andreas 1549
 
249 andreas 1550
            mOrientation = ori;
1551
        }
1552
        else if (mOrientation != Qt::LandscapeOrientation && mOrientation != Qt::InvertedLandscapeOrientation)
1553
            mOrientation = Qt::LandscapeOrientation;
1554
    }
1555
 
130 andreas 1556
    J_ORIENTATION jori = O_UNDEFINED;
1557
 
249 andreas 1558
    switch(mOrientation)
130 andreas 1559
    {
1560
        case Qt::LandscapeOrientation:          jori = O_LANDSCAPE; break;
1561
        case Qt::InvertedLandscapeOrientation:  jori = O_REVERSE_LANDSCAPE; break;
1562
        case Qt::PortraitOrientation:           jori = O_PORTRAIT; break;
1563
        case Qt::InvertedPortraitOrientation:   jori = O_REVERSE_PORTRAIT; break;
1564
        default:
1565
            return;
1566
    }
1567
 
1568
    _setOrientation(jori);
249 andreas 1569
#ifdef Q_OS_IOS
252 andreas 1570
    setNotch();
1571
#endif
1572
}
249 andreas 1573
 
252 andreas 1574
void MainWindow::onCurrentOrientationChanged(int currentOrientation)
1575
{
1576
    DECL_TRACER("MainWindow::onCurrentOrientationChanged(int currentOrientation)");
265 andreas 1577
#if defined(QT_DEBUG) && (defined(Q_OS_IOS) || defined(Q_OS_ANDROID))
264 andreas 1578
    MSG_DEBUG("User orientation: " << orientationToString((Qt::ScreenOrientation)currentOrientation));
1579
#else
1580
    Q_UNUSED(currentOrientation);
1581
#endif
252 andreas 1582
}
1583
/**
1584
 * @brief MainWindow::onPositionUpdated
1585
 * This method is a callback function for the Qt framework. It is called
1586
 * whenever the geo position changes. The position information is never really
1587
 * used and is implemented only to keep the application on IOS running in the
1588
 * background.
1589
 *
1590
 * @param update    A structure containing the geo position information.
1591
 */
254 andreas 1592
#ifdef Q_OS_IOS
252 andreas 1593
void MainWindow::onPositionUpdated(const QGeoPositionInfo &update)
1594
{
1595
    DECL_TRACER("MainWindow::onPositionUpdated(const QGeoPositionInfo &update)");
249 andreas 1596
 
252 andreas 1597
    QGeoCoordinate coord = update.coordinate();
1598
    MSG_DEBUG("Geo location: " << coord.toString().toStdString());
130 andreas 1599
}
1600
 
252 andreas 1601
void MainWindow::onErrorOccurred(QGeoPositionInfoSource::Error positioningError)
1602
{
1603
    DECL_TRACER("MainWindow::onErrorOccurred(QGeoPositionInfoSource::Error positioningError)");
1604
 
1605
    switch(positioningError)
1606
    {
1607
        case QGeoPositionInfoSource::AccessError:   MSG_ERROR("The connection setup to the remote positioning backend failed because the application lacked the required privileges."); break;
1608
        case QGeoPositionInfoSource::ClosedError:   MSG_ERROR("The remote positioning backend closed the connection, which happens for example in case the user is switching location services to off. As soon as the location service is re-enabled regular updates will resume."); break;
1609
        case QGeoPositionInfoSource::UnknownSourceError: MSG_ERROR("An unidentified error occurred."); break;
264 andreas 1610
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
252 andreas 1611
        case QGeoPositionInfoSource::UpdateTimeoutError: MSG_ERROR("Current position could not be retrieved within the specified timeout."); break;
1612
#endif
1613
        default:
1614
            return;
1615
    }
1616
}
254 andreas 1617
#endif
130 andreas 1618
/**
140 andreas 1619
 * @brief Displays or hides a phone dialog window.
1620
 * This method creates and displays a phone dialog window containing everything
1621
 * a simple phone needs. Depending on the parameter \p state the dialog is
1622
 * created or an exeisting dialog is closed.
1623
 * @param state     If TRUE the dialog is created or if it is not visible
1624
 * brought to front and is made visible.
1625
 * If this is FALSE an existing dialog window is destroid and disappears. If
1626
 * the window didn't exist nothing happens.
1627
 */
1628
void MainWindow::showPhoneDialog(bool state)
1629
{
1630
    DECL_TRACER("MainWindow::showPhoneDialog(bool state)");
1631
 
1632
    if (mPhoneDialog)
1633
    {
1634
        if (!state)
1635
        {
1636
            mPhoneDialog->close();
1637
            delete mPhoneDialog;
1638
            mPhoneDialog = nullptr;
1639
            return;
1640
        }
1641
 
1642
        if (!mPhoneDialog->isVisible())
1643
            mPhoneDialog->setVisible(true);
1644
 
1645
        return;
1646
    }
1647
 
1648
    if (!state)
1649
        return;
1650
 
1651
    mPhoneDialog = new TQtPhone(this);
243 andreas 1652
#if defined(Q_OS_ANDROID)
140 andreas 1653
    // On mobile devices we set the scale factor always because otherwise the
1654
    // dialog will be unusable.
1655
    mPhoneDialog->setScaleFactor(gScale);
1656
    mPhoneDialog->doResize();
1657
#endif
1658
    mPhoneDialog->open();
1659
}
1660
 
1661
/**
1662
 * Displays a phone number (can also be an URL) on a label in the phone dialog
1663
 * window.
1664
 * @param number    The string contains the phone number to display.
1665
 */
1666
void MainWindow::setPhoneNumber(const std::string& number)
1667
{
1668
    DECL_TRACER("MainWindow::setPhoneNumber(const std::string& number)");
1669
 
1670
    if (!mPhoneDialog)
1671
        return;
1672
 
1673
    mPhoneDialog->setPhoneNumber(number);
1674
}
1675
 
1676
/**
1677
 * Displays a message in the status line on the bottom of the phone dialog
1678
 * window.
1679
 * @param msg   The string conaining a message.
1680
 */
1681
void MainWindow::setPhoneStatus(const std::string& msg)
1682
{
1683
    DECL_TRACER("MainWindow::setPhoneStatus(const std::string& msg)");
1684
 
1685
    if (!mPhoneDialog)
1686
        return;
1687
 
1688
    mPhoneDialog->setPhoneStatus(msg);
1689
}
1690
 
1691
void MainWindow::setPhoneState(int state, int id)
1692
{
1693
    DECL_TRACER("MainWindow::setPhoneState(int state)");
1694
 
1695
    if (mPhoneDialog)
1696
        mPhoneDialog->setPhoneState(state, id);
1697
}
1698
 
1699
/**
39 andreas 1700
 * @brief MainWindow::createActions creates the toolbar on the right side.
21 andreas 1701
 */
2 andreas 1702
void MainWindow::createActions()
1703
{
5 andreas 1704
    DECL_TRACER("MainWindow::createActions()");
2 andreas 1705
 
151 andreas 1706
    // If the toolbar should not be visible at all we return here immediately.
1707
    if (TConfig::getToolbarSuppress())
1708
        return;
1709
 
88 andreas 1710
    // Add a mToolbar (on the right side)
1711
    mToolbar = new QToolBar(this);
300 andreas 1712
    QPalette palette(mToolbar->palette());
1713
    palette.setColor(QPalette::Window, QColorConstants::Svg::honeydew);
1714
    mToolbar->setPalette(palette);
58 andreas 1715
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
88 andreas 1716
    mToolbar->setAllowedAreas(Qt::RightToolBarArea);
1717
    mToolbar->setFloatable(false);
1718
    mToolbar->setMovable(false);
243 andreas 1719
#ifdef Q_OS_ANDROID
259 andreas 1720
    if (isScaled())
38 andreas 1721
    {
217 andreas 1722
        int width = (int)((double)gPageManager->getSettings()->getWidth() * gScale);
38 andreas 1723
        int tbWidth = (int)(48.0 * gScale);
1724
        int icWidth = (int)(40.0 * gScale);
1725
 
120 andreas 1726
        if ((gFullWidth - width) < tbWidth && !TConfig::getToolbarForce())
38 andreas 1727
        {
88 andreas 1728
            delete mToolbar;
1729
            mToolbar = nullptr;
38 andreas 1730
            return;
1731
        }
1732
 
262 andreas 1733
        MSG_DEBUG("Icon size: " << icWidth << "x" << icWidth << ", Toolbar width: " << tbWidth);
38 andreas 1734
        QSize iSize(icWidth, icWidth);
88 andreas 1735
        mToolbar->setIconSize(iSize);
38 andreas 1736
    }
243 andreas 1737
#endif  // Q_OS_ANDROID
39 andreas 1738
#else
88 andreas 1739
    mToolbar->setFloatable(true);
1740
    mToolbar->setMovable(true);
1741
    mToolbar->setAllowedAreas(Qt::RightToolBarArea | Qt::BottomToolBarArea);
243 andreas 1742
#endif  // defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
32 andreas 1743
    QAction *arrowUpAct = new QAction(QIcon(":/images/arrow_up.png"), tr("Up"), this);
1744
    connect(arrowUpAct, &QAction::triggered, this, &MainWindow::arrowUp);
88 andreas 1745
    mToolbar->addAction(arrowUpAct);
31 andreas 1746
 
32 andreas 1747
    QAction *arrowLeftAct = new QAction(QIcon(":/images/arrow_left.png"), tr("Left"), this);
1748
    connect(arrowLeftAct, &QAction::triggered, this, &MainWindow::arrowLeft);
88 andreas 1749
    mToolbar->addAction(arrowLeftAct);
31 andreas 1750
 
32 andreas 1751
    QAction *arrowRightAct = new QAction(QIcon(":/images/arrow_right.png"), tr("Right"), this);
1752
    connect(arrowRightAct, &QAction::triggered, this, &MainWindow::arrowRight);
88 andreas 1753
    mToolbar->addAction(arrowRightAct);
31 andreas 1754
 
32 andreas 1755
    QAction *arrowDownAct = new QAction(QIcon(":/images/arrow_down.png"), tr("Down"), this);
1756
    connect(arrowDownAct, &QAction::triggered, this, &MainWindow::arrowDown);
88 andreas 1757
    mToolbar->addAction(arrowDownAct);
31 andreas 1758
 
32 andreas 1759
    QAction *selectOkAct = new QAction(QIcon(":/images/ok.png"), tr("Ok"), this);
1760
    connect(selectOkAct, &QAction::triggered, this, &MainWindow::selectOk);
88 andreas 1761
    mToolbar->addAction(selectOkAct);
31 andreas 1762
 
88 andreas 1763
    mToolbar->addSeparator();
31 andreas 1764
 
35 andreas 1765
    QToolButton *btVolUp = new QToolButton(this);
1766
    btVolUp->setIcon(QIcon(":/images/vol_up.png"));
1767
    connect(btVolUp, &QToolButton::pressed, this, &MainWindow::volumeUpPressed);
1768
    connect(btVolUp, &QToolButton::released, this, &MainWindow::volumeUpReleased);
88 andreas 1769
    mToolbar->addWidget(btVolUp);
40 andreas 1770
 
35 andreas 1771
    QToolButton *btVolDown = new QToolButton(this);
1772
    btVolDown->setIcon(QIcon(":/images/vol_down.png"));
1773
    connect(btVolDown, &QToolButton::pressed, this, &MainWindow::volumeDownPressed);
1774
    connect(btVolDown, &QToolButton::released, this, &MainWindow::volumeDownReleased);
88 andreas 1775
    mToolbar->addWidget(btVolDown);
38 andreas 1776
/*
33 andreas 1777
    QAction *volMute = new QAction(QIcon(":/images/vol_mute.png"), tr("X"), this);
1778
    connect(volMute, &QAction::triggered, this, &MainWindow::volumeMute);
88 andreas 1779
    mToolbar->addAction(volMute);
38 andreas 1780
*/
88 andreas 1781
    mToolbar->addSeparator();
36 andreas 1782
    const QIcon settingsIcon = QIcon::fromTheme("settings-configure", QIcon(":/images/settings.png"));
5 andreas 1783
    QAction *settingsAct = new QAction(settingsIcon, tr("&Settings..."), this);
1784
    settingsAct->setStatusTip(tr("Change the settings"));
1785
    connect(settingsAct, &QAction::triggered, this, &MainWindow::settings);
88 andreas 1786
    mToolbar->addAction(settingsAct);
250 andreas 1787
 
38 andreas 1788
    const QIcon aboutIcon = QIcon::fromTheme("help-about", QIcon(":/images/info.png"));
5 andreas 1789
    QAction *aboutAct = new QAction(aboutIcon, tr("&About..."), this);
1790
    aboutAct->setShortcuts(QKeySequence::Open);
1791
    aboutAct->setStatusTip(tr("About this program"));
1792
    connect(aboutAct, &QAction::triggered, this, &MainWindow::about);
88 andreas 1793
    mToolbar->addAction(aboutAct);
2 andreas 1794
 
33 andreas 1795
    const QIcon exitIcon = QIcon::fromTheme("application-exit", QIcon(":/images/off.png"));
88 andreas 1796
    QAction *exitAct = mToolbar->addAction(exitIcon, tr("E&xit"), this, &QWidget::close);
5 andreas 1797
    exitAct->setShortcuts(QKeySequence::Quit);
1798
    exitAct->setStatusTip(tr("Exit the application"));
31 andreas 1799
 
88 andreas 1800
    addToolBar(Qt::RightToolBarArea, mToolbar);
2 andreas 1801
}
1802
 
21 andreas 1803
/**
1804
 * @brief MainWindow::settings initiates the configuration dialog.
1805
 */
2 andreas 1806
void MainWindow::settings()
1807
{
5 andreas 1808
    DECL_TRACER("MainWindow::settings()");
251 andreas 1809
#if defined(Q_OS_IOS) || defined(Q_OS_ANDROID)
259 andreas 1810
#ifdef Q_OS_ANDROID
197 andreas 1811
    if (gPageManager)
1812
    {
1813
        gPageManager->showSetup();
1814
        return;
1815
    }
211 andreas 1816
    else    // This "else" should never be executed!
1817
        displayMessage("<b>Fatal error</b>: An internal mandatory class was not initialized!<br>Unable to show setup dialog!", "Fatal error");
1818
#else
259 andreas 1819
    mIOSSettingsActive = true;
250 andreas 1820
    QASettings::openSettings();
238 andreas 1821
#endif
1822
#else
90 andreas 1823
    // Save some old values to decide whether to start over or not.
1824
    string oldHost = TConfig::getController();
1825
    int oldPort = TConfig::getPort();
1826
    int oldChannelID = TConfig::getChannel();
118 andreas 1827
    string oldSurface = TConfig::getFtpSurface();
120 andreas 1828
    bool oldToolbar = TConfig::getToolbarForce();
151 andreas 1829
    bool oldToolbarSuppress = TConfig::getToolbarSuppress();
90 andreas 1830
    // Initialize and open the settings dialog.
5 andreas 1831
    TQtSettings *dlg_settings = new TQtSettings(this);
23 andreas 1832
    int ret = dlg_settings->exec();
118 andreas 1833
    bool rebootAnyway = false;
23 andreas 1834
 
179 andreas 1835
    if ((ret && dlg_settings->hasChanged()) || (ret && dlg_settings->downloadForce()))
89 andreas 1836
    {
23 andreas 1837
        writeSettings();
89 andreas 1838
 
151 andreas 1839
        if (!TConfig::getToolbarSuppress() && oldToolbar != TConfig::getToolbarForce())
120 andreas 1840
        {
122 andreas 1841
            QMessageBox msgBox(this);
120 andreas 1842
            msgBox.setText("The change for the visibility of the toolbar will be active on the next start of TPanel!");
1843
            msgBox.exec();
1844
        }
151 andreas 1845
        else if (oldToolbarSuppress != TConfig::getToolbarSuppress() && TConfig::getToolbarSuppress())
1846
        {
1847
            if (mToolbar)
1848
            {
1849
                mToolbar->close();
1850
                delete mToolbar;
1851
                mToolbar = nullptr;
1852
            }
1853
        }
120 andreas 1854
 
122 andreas 1855
        if (TConfig::getFtpSurface() != oldSurface || dlg_settings->downloadForce())
118 andreas 1856
        {
122 andreas 1857
            bool dlYes = true;
118 andreas 1858
 
179 andreas 1859
            MSG_DEBUG("Surface should be downloaded (Old: " << oldSurface << ", New: " << TConfig::getFtpSurface() << ")");
1860
 
122 andreas 1861
            if (!dlg_settings->downloadForce())
1862
            {
1863
                QMessageBox msgBox(this);
1864
                msgBox.setText(QString("Should the surface <b>") + TConfig::getFtpSurface().c_str() + "</b> be installed?");
1865
                msgBox.addButton(QMessageBox::Yes);
1866
                msgBox.addButton(QMessageBox::No);
1867
                int ret = msgBox.exec();
120 andreas 1868
 
122 andreas 1869
                if (ret == QMessageBox::No)
1870
                    dlYes = false;
1871
            }
119 andreas 1872
 
122 andreas 1873
            if (dlYes)
1874
            {
1875
                TTPInit tpinit;
1876
                tpinit.regCallbackProcessEvents(bind(&MainWindow::runEvents, this));
179 andreas 1877
                tpinit.regCallbackProgressBar(bind(&MainWindow::_onProgressChanged, this, std::placeholders::_1));
122 andreas 1878
                tpinit.setPath(TConfig::getProjectPath());
179 andreas 1879
                tpinit.setFileSize(dlg_settings->getSelectedFtpFileSize());
1880
                string msg = "Loading file <b>" + TConfig::getFtpSurface() + "</b>.";
1881
                MSG_DEBUG("Download of surface " << TConfig::getFtpSurface() << " was forced!");
122 andreas 1882
 
179 andreas 1883
                downloadBar(msg, this);
122 andreas 1884
 
1885
                if (tpinit.loadSurfaceFromController(true))
1886
                    rebootAnyway = true;
1887
 
179 andreas 1888
                mDownloadBar->close();
122 andreas 1889
                mBusy = false;
1890
            }
1891
            else
1892
            {
179 andreas 1893
                MSG_DEBUG("No change of surface. Old surface " << oldSurface << " was saved again.");
122 andreas 1894
                TConfig::saveFtpSurface(oldSurface);
1895
                writeSettings();
1896
            }
118 andreas 1897
        }
1898
 
90 andreas 1899
        if (TConfig::getController() != oldHost ||
1900
            TConfig::getChannel() != oldChannelID ||
118 andreas 1901
            TConfig::getPort() != oldPort || rebootAnyway)
89 andreas 1902
        {
90 andreas 1903
            // Start over by exiting this class
1904
            MSG_INFO("Program will start over!");
1905
            _restart_ = true;
1906
            prg_stopped = true;
1907
            killed = true;
1908
 
1909
            if (gAmxNet)
1910
                gAmxNet->stop();
1911
 
1912
            close();
89 andreas 1913
        }
1914
    }
23 andreas 1915
    else if (!ret && dlg_settings->hasChanged())
1916
    {
1917
        TConfig cf(TConfig::getConfigPath() + "/" + TConfig::getConfigFileName());
1918
    }
44 andreas 1919
 
1920
    delete dlg_settings;
251 andreas 1921
#endif  // defined(Q_OS_IOS) || defined(Q_OS_ANDROID)
2 andreas 1922
}
1923
 
21 andreas 1924
/**
1925
 * @brief MainWindow::writeSettings Writes the settings into the configuration file.
1926
 */
2 andreas 1927
void MainWindow::writeSettings()
1928
{
5 andreas 1929
    DECL_TRACER("MainWindow::writeSettings()");
23 andreas 1930
 
1931
    TConfig::saveSettings();
43 andreas 1932
    MSG_INFO("Wrote settings.");
2 andreas 1933
}
1934
 
21 andreas 1935
/**
1936
 * @brief MainWindow::about displays the _about_ dialog.
1937
 */
2 andreas 1938
void MainWindow::about()
1939
{
5 andreas 1940
    DECL_TRACER("MainWindow::about()");
2 andreas 1941
 
259 andreas 1942
#ifdef Q_OS_IOS
1943
    // On IOS the explicit about dialog is shown over the whole screen with
1944
    // the text in a small stripe on the left. This looks ugly and therefor
1945
    // we construct our own about dialog.
1946
    std::string msg = "About TPanel\n\n";
1947
    msg.append("Simulation of an AMX G4 panel\n");
1948
    msg.append("Version v").append(VERSION_STRING()).append("\n");
260 andreas 1949
    msg.append("(C) Copyright 2020 to 2023 by Andreas Theofilu (andreas@theosys.at)\n");
259 andreas 1950
 
1951
    QMessageBox about(this);
1952
    about.addButton(QMessageBox::Ok);
1953
    about.setWindowTitle(tr("About TPanel"));
1954
    about.setIconPixmap(QPixmap(":images/icon.png"));
1955
    about.setTextFormat(Qt::PlainText);
1956
    about.setText(tr(msg.c_str()));
1957
    about.setInformativeText(tr("This program is under the terms of GPL version 3!"));
1958
    about.exec();
1959
#else
82 andreas 1960
    std::string msg = "Simulation of an AMX G4 panel\n";
1961
    msg.append("Version v").append(VERSION_STRING()).append("\n");
259 andreas 1962
    msg.append("(C) Copyright 2020 to 2023 by Andreas Theofilu <andreas@theosys.at>\n");
1963
    msg.append("This program is under the terms of GPL version 3!");
1964
    QMessageBox::about(this, tr("About TPanel"), tr(msg.c_str()));
1965
#endif
2 andreas 1966
}
1967
 
32 andreas 1968
void MainWindow::arrowUp()
1969
{
1970
    DECL_TRACER("MainWindow::arrowUp()");
35 andreas 1971
 
1972
    extButtons_t btType = EXT_CURSOR_UP;
1973
 
1974
    if (TConfig::getPanelType().find("Android") != string::npos)
1975
        btType = EXT_GESTURE_UP;
1976
 
92 andreas 1977
    gPageManager->externalButton(btType, true);
1978
    gPageManager->externalButton(btType, false);
32 andreas 1979
}
14 andreas 1980
 
32 andreas 1981
void MainWindow::arrowLeft()
1982
{
1983
    DECL_TRACER("MainWindow::arrowLeft()");
35 andreas 1984
    extButtons_t btType = EXT_CURSOR_LEFT;
1985
 
1986
    if (TConfig::getPanelType().find("Android") != string::npos)
1987
        btType = EXT_GESTURE_LEFT;
1988
 
92 andreas 1989
    gPageManager->externalButton(btType, true);
1990
    gPageManager->externalButton(btType, false);
32 andreas 1991
}
1992
 
1993
void MainWindow::arrowRight()
1994
{
1995
    DECL_TRACER("MainWindow::arrowRight()");
35 andreas 1996
    extButtons_t btType = EXT_CURSOR_RIGHT;
1997
 
1998
    if (TConfig::getPanelType().find("Android") != string::npos)
1999
        btType = EXT_GESTURE_RIGHT;
2000
 
92 andreas 2001
    gPageManager->externalButton(btType, true);
2002
    gPageManager->externalButton(btType, false);
32 andreas 2003
}
2004
 
2005
void MainWindow::arrowDown()
2006
{
2007
    DECL_TRACER("MainWindow::arrowDown()");
35 andreas 2008
    extButtons_t btType = EXT_CURSOR_DOWN;
2009
 
2010
    if (TConfig::getPanelType().find("Android") != string::npos)
2011
        btType = EXT_GESTURE_DOWN;
2012
 
92 andreas 2013
    gPageManager->externalButton(btType, true);
2014
    gPageManager->externalButton(btType, false);
32 andreas 2015
}
2016
 
2017
void MainWindow::selectOk()
2018
{
2019
    DECL_TRACER("MainWindow::selectOk()");
35 andreas 2020
    extButtons_t btType = EXT_CURSOR_SELECT;
2021
 
2022
    if (TConfig::getPanelType().find("Android") != string::npos)
2023
        btType = EXT_GESTURE_DOUBLE_PRESS;
2024
 
92 andreas 2025
    gPageManager->externalButton(btType, true);
2026
    gPageManager->externalButton(btType, false);
32 andreas 2027
}
2028
 
33 andreas 2029
void MainWindow::volumeUpPressed()
2030
{
2031
    DECL_TRACER("MainWindow::volumeUpPressed()");
35 andreas 2032
    extButtons_t btType = EXT_CURSOR_ROTATE_RIGHT;
2033
 
2034
    if (TConfig::getPanelType().find("Android") != string::npos)
2035
        btType = EXT_GESTURE_ROTATE_RIGHT;
2036
 
92 andreas 2037
    gPageManager->externalButton(btType, true);
33 andreas 2038
}
2039
 
2040
void MainWindow::volumeUpReleased()
2041
{
2042
    DECL_TRACER("MainWindow::volumeUpReleased()");
35 andreas 2043
    extButtons_t btType = EXT_CURSOR_ROTATE_RIGHT;
2044
 
2045
    if (TConfig::getPanelType().find("Android") != string::npos)
2046
        btType = EXT_GESTURE_ROTATE_RIGHT;
2047
 
92 andreas 2048
    gPageManager->externalButton(btType, false);
33 andreas 2049
}
2050
 
2051
void MainWindow::volumeDownPressed()
2052
{
2053
    DECL_TRACER("MainWindow::volumeDownPressed()");
35 andreas 2054
    extButtons_t btType = EXT_CURSOR_ROTATE_LEFT;
2055
 
2056
    if (TConfig::getPanelType().find("Android") != string::npos)
2057
        btType = EXT_GESTURE_ROTATE_LEFT;
2058
 
92 andreas 2059
    gPageManager->externalButton(btType, true);
33 andreas 2060
}
2061
 
2062
void MainWindow::volumeDownReleased()
2063
{
2064
    DECL_TRACER("MainWindow::volumeDownReleased()");
35 andreas 2065
    extButtons_t btType = EXT_CURSOR_ROTATE_LEFT;
2066
 
2067
    if (TConfig::getPanelType().find("Android") != string::npos)
2068
        btType = EXT_GESTURE_ROTATE_LEFT;
2069
 
92 andreas 2070
    gPageManager->externalButton(btType, false);
33 andreas 2071
}
38 andreas 2072
/*
33 andreas 2073
void MainWindow::volumeMute()
2074
{
2075
    DECL_TRACER("MainWindow::volumeMute()");
92 andreas 2076
    gPageManager->externalButton(EXT_GENERAL, true);
2077
    gPageManager->externalButton(EXT_GENERAL, false);
33 andreas 2078
}
38 andreas 2079
*/
295 andreas 2080
 
2081
void MainWindow::animationInFinished()
2082
{
2083
    DECL_TRACER("MainWindow::animationInFinished()");
2084
 
296 andreas 2085
    TLOCKER(anim_mutex);
2086
    map<ulong, OBJECT_t *>::iterator iter;
2087
 
2088
    for (iter = mAnimObjects.begin(); iter != mAnimObjects.end(); ++iter)
295 andreas 2089
    {
296 andreas 2090
        if (!iter->second->animation)
2091
            continue;
295 andreas 2092
 
297 andreas 2093
        if (!iter->second->invalid && iter->second->type == OBJ_SUBPAGE && iter->second->animation->state() == QAbstractAnimation::Stopped)
295 andreas 2094
        {
296 andreas 2095
            if (iter->second->object.widget)
2096
            {
2097
                iter->second->object.widget->lower();
2098
                iter->second->object.widget->show();
2099
                iter->second->object.widget->raise();
2100
            }
2101
 
2102
            disconnect(iter->second->animation, &QPropertyAnimation::finished, this, &MainWindow::animationInFinished);
2103
            delete iter->second->animation;
2104
            iter->second->animation = nullptr;
295 andreas 2105
        }
296 andreas 2106
    }
295 andreas 2107
 
296 andreas 2108
    // Delete all empty/finished animations
2109
    bool repeat = false;
2110
 
2111
    do
2112
    {
2113
        repeat = false;
2114
 
2115
        for (iter = mAnimObjects.begin(); iter != mAnimObjects.end(); ++iter)
2116
        {
2117
            if (!iter->second->remove && !iter->second->animation)
2118
            {
2119
                mAnimObjects.erase(iter);
2120
                repeat = true;
2121
                break;
2122
            }
2123
        }
295 andreas 2124
    }
296 andreas 2125
    while (repeat);
295 andreas 2126
}
2127
 
42 andreas 2128
void MainWindow::animationFinished()
2129
{
2130
    DECL_TRACER("MainWindow::animationFinished()");
43 andreas 2131
 
296 andreas 2132
    TLOCKER(anim_mutex);
2133
    map<ulong, OBJECT_t *>::iterator iter;
43 andreas 2134
 
296 andreas 2135
    for (iter = mAnimObjects.begin(); iter != mAnimObjects.end(); ++iter)
42 andreas 2136
    {
297 andreas 2137
        OBJECT_t *obj = findObject(iter->first);
2138
 
2139
        if (obj && obj->remove && obj->animation && obj->animation->state() == QAbstractAnimation::Stopped)
296 andreas 2140
        {
2141
            MSG_DEBUG("Invalidating object " << handleToString(iter->first));
297 andreas 2142
            disconnect(obj->animation, &QPropertyAnimation::finished, this, &MainWindow::animationFinished);
2143
            delete obj->animation;
2144
            obj->animation = nullptr;
296 andreas 2145
            invalidateAllSubObjects(iter->first);
2146
            invalidateObject(iter->first);
43 andreas 2147
 
297 andreas 2148
            if (obj->type == OBJ_SUBPAGE && obj->object.widget)
2149
                obj->object.widget->hide();
296 andreas 2150
        }
42 andreas 2151
    }
296 andreas 2152
    // Delete all empty/finished animations
2153
    bool repeat = false;
43 andreas 2154
 
296 andreas 2155
    do
42 andreas 2156
    {
296 andreas 2157
        repeat = false;
101 andreas 2158
 
296 andreas 2159
        for (iter = mAnimObjects.begin(); iter != mAnimObjects.end(); ++iter)
2160
        {
2161
            if (iter->second->remove && !iter->second->animation)
2162
            {
2163
                mAnimObjects.erase(iter);
2164
                repeat = true;
2165
                break;
2166
            }
2167
        }
42 andreas 2168
    }
296 andreas 2169
    while (repeat);
42 andreas 2170
}
2171
 
142 andreas 2172
void MainWindow::repaintWindows()
2173
{
2174
    DECL_TRACER("MainWindow::repaintWindows()");
2175
 
2176
    if (mWasInactive)
148 andreas 2177
    {
2178
        MSG_INFO("Refreshing of visible popups will be requested.");
142 andreas 2179
        mDoRepaint = true;
148 andreas 2180
    }
142 andreas 2181
}
2182
 
151 andreas 2183
void MainWindow::toFront(ulong handle)
2184
{
2185
    DECL_TRACER("MainWindow::toFront(ulong handle)");
2186
 
277 andreas 2187
    TObject::OBJECT_t *obj = findObject(handle);
151 andreas 2188
 
2189
    if (!obj)
2190
    {
271 andreas 2191
        MSG_WARNING("Object with " << handleToString(handle) << " not found!");
151 andreas 2192
        return;
2193
    }
2194
 
2195
    if (obj->type == TObject::OBJ_SUBPAGE && obj->object.widget)
2196
        obj->object.widget->raise();
2197
}
2198
 
206 andreas 2199
void MainWindow::downloadSurface(const string &file, size_t size)
205 andreas 2200
{
206 andreas 2201
    DECL_TRACER("MainWindow::downloadSurface(const string &file, size_t size)");
205 andreas 2202
 
206 andreas 2203
    if (mBusy)
205 andreas 2204
        return;
2205
 
206 andreas 2206
    QMessageBox msgBox(this);
208 andreas 2207
    msgBox.setText(QString("Should the surface <b>") + file.c_str() + "</b> be installed?<br><i><u>Hint</u>: This will also save all current made settings.</i>");
206 andreas 2208
    msgBox.addButton(QMessageBox::Yes);
2209
    msgBox.addButton(QMessageBox::No);
2210
    int ret = msgBox.exec();
2211
 
2212
    if (ret == QMessageBox::Yes)
2213
    {
2214
        TTPInit tpinit;
2215
        tpinit.regCallbackProcessEvents(bind(&MainWindow::runEvents, this));
2216
        tpinit.regCallbackProgressBar(bind(&MainWindow::_onProgressChanged, this, std::placeholders::_1));
2217
        tpinit.setPath(TConfig::getProjectPath());
208 andreas 2218
 
2219
        if (size)
2220
            tpinit.setFileSize(size);
2221
        else
2222
        {
2223
            size = tpinit.getFileSize(file);
2224
 
2225
            if (!size)
2226
            {
2227
                displayMessage("File <b>" + file + "</b> either doesn't exist on " + TConfig::getController() + " or the NetLinx is not reachable!", "Error");
2228
                return;
2229
            }
2230
 
2231
            tpinit.setFileSize(size);
2232
        }
2233
 
206 andreas 2234
        string msg = "Loading file <b>" + file + "</b>.";
2235
 
2236
        downloadBar(msg, this);
2237
        bool reboot = false;
2238
 
2239
        if (tpinit.loadSurfaceFromController(true))
2240
            reboot = true;
2241
        else
2242
            displayMessage("Error downloading file <b>" + file + "</b>!", "Error");
2243
 
2244
        mDownloadBar->close();
208 andreas 2245
        TConfig::setTemporary(true);
2246
        TConfig::saveSettings();
206 andreas 2247
 
2248
        if (reboot)
2249
        {
2250
            // Start over by exiting this class
2251
            MSG_INFO("Program will start over!");
2252
            _restart_ = true;
2253
            prg_stopped = true;
2254
            killed = true;
2255
 
2256
            if (gAmxNet)
2257
                gAmxNet->stop();
2258
 
2259
            close();
2260
        }
2261
    }
2262
 
2263
    mBusy = false;
2264
}
2265
 
2266
void MainWindow::displayMessage(const string &msg, const string &title)
2267
{
2268
    DECL_TRACER("MainWindow::displayMessage(const string &msg, const string &title)");
2269
 
2270
    QMessageBox msgBox(this);
259 andreas 2271
    msgBox.setText(msg.c_str());
206 andreas 2272
 
2273
    if (!title.empty())
2274
        msgBox.setWindowTitle(title.c_str());
2275
 
259 andreas 2276
    msgBox.setWindowModality(Qt::WindowModality::ApplicationModal);
206 andreas 2277
    msgBox.addButton(QMessageBox::Ok);
2278
    msgBox.exec();
2279
}
2280
 
209 andreas 2281
void MainWindow::fileDialog(ulong handle, const string &path, const std::string& extension, const std::string& suffix)
2282
{
2283
    DECL_TRACER("MainWindow::fileDialog(ulong handle, const string &path, const std::string& extension, const std::string& suffix)");
2284
 
2285
    std::string pt = path;
2286
 
2287
    if (fs::exists(path) && fs::is_regular_file(path))
2288
    {
2289
        size_t pos = pt.find_last_of("/");
2290
 
2291
        if (pos != std::string::npos)
2292
            pt = pt.substr(0, pos);
2293
        else
2294
        {
2295
            char hv0[4096];
2296
            getcwd(hv0, sizeof(hv0));
2297
            pt = hv0;
2298
        }
2299
    }
2300
 
2301
    QString actPath(pt.c_str());
2302
    QFileDialog fdialog(this, tr("File"), actPath, tr(extension.c_str()));
2303
    fdialog.setAcceptMode(QFileDialog::AcceptSave);
2304
 
2305
    if (!suffix.empty())
2306
        fdialog.setDefaultSuffix(suffix.c_str());
2307
 
2308
    fdialog.setOption(QFileDialog::DontConfirmOverwrite);
2309
    QString fname;
2310
 
2311
    if (fdialog.exec())
2312
    {
2313
        QDir dir = fdialog.directory();
2314
        QStringList list = fdialog.selectedFiles();
2315
 
2316
        if (list.size() > 0)
2317
            fname = dir.absoluteFilePath(list.at(0));
2318
        else
2319
            return;
2320
    }
2321
    else
2322
        return;
2323
 
2324
#ifdef Q_OS_ANDROID
247 andreas 2325
    // In case of Android we get some kind of URL instead of a clear
209 andreas 2326
    // path. Because of this we must call some Java API functions to find the
2327
    // real path.
2328
    QString fileName = fname;
2329
 
2330
    if (fileName.contains("content://"))
2331
    {
264 andreas 2332
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
209 andreas 2333
        QAndroidJniObject uri = QAndroidJniObject::callStaticObjectMethod(
2334
            "android/net/Uri", "parse", "(Ljava/lang/String;)Landroid/net/Uri;",
2335
            QAndroidJniObject::fromString(fileName).object<jstring>());
2336
 
2337
        fileName = QAndroidJniObject::callStaticObjectMethod(
2338
            "org/qtproject/theosys/UriToPath", "getFileName",
2339
            "(Landroid/net/Uri;Landroid/content/Context;)Ljava/lang/String;",
2340
            uri.object(), QtAndroid::androidContext().object()).toString();
2341
#else   // QT5_LINUX
2342
        // For QT6 the API has slightly changed. Especialy the class name to
2343
        // call Java objects.
2344
        QJniObject uri = QJniObject::callStaticObjectMethod(
2345
            "android/net/Uri", "parse", "(Ljava/lang/String;)Landroid/net/Uri;",
2346
            QJniObject::fromString(fileName).object<jstring>());
2347
 
2348
        fileName = QJniObject::callStaticObjectMethod(
2349
            "org/qtproject/theosys/UriToPath", "getFileName",
2350
            "(Landroid/net/Uri;Landroid/content/Context;)Ljava/lang/String;",
2351
            uri.object(), QNativeInterface::QAndroidApplication::context()).toString();
2352
#endif  // QT5_LINUX
2353
        if (fileName.length() > 0)
2354
            fname = fileName;
2355
    }
2356
    else
2357
    {
2358
        MSG_WARNING("Not an Uri? (" << fname.toStdString() << ")");
2359
    }
2360
#endif  // Q_OS_ANDROID
2361
 
2362
    if (gPageManager)
2363
        gPageManager->setTextToButton(handle, fname.toStdString(), true);
2364
}
2365
 
213 andreas 2366
void MainWindow::onTListCallbackCurrentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
206 andreas 2367
{
2368
    DECL_TRACER("MainWindow::on_tlistCallback_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)");
2369
 
2370
    if (!current || current == previous)
2371
        return;
2372
 
205 andreas 2373
    QListWidget *w = current->listWidget();
277 andreas 2374
    TObject::OBJECT_t *objWindow = findFirstWindow();
205 andreas 2375
 
2376
    while(objWindow)
2377
    {
277 andreas 2378
        TObject::OBJECT_t *objItem = findFirstChild(objWindow->handle);
205 andreas 2379
 
206 andreas 2380
        while (objItem)
205 andreas 2381
        {
206 andreas 2382
            if (objItem->type == TObject::OBJ_LIST && objItem->object.list == w)
2383
            {
2384
                int row = objItem->object.list->currentRow();
2385
                gPageManager->setSelectedRow(objItem->handle, row + 1, current->text().toStdString());
2386
                return;
2387
            }
2388
 
277 andreas 2389
            objItem = findNextChild(objItem->handle);
205 andreas 2390
        }
206 andreas 2391
 
277 andreas 2392
        objWindow = findNextWindow(objWindow);
205 andreas 2393
    }
2394
}
2395
 
179 andreas 2396
void MainWindow::onProgressChanged(int percent)
2397
{
2398
    DECL_TRACER("MainWindow::onProgressChanged(int percent)");
2399
 
2400
    if (!mDownloadBar || !mBusy)
2401
        return;
2402
 
2403
    mDownloadBar->setProgress(percent);
2404
}
2405
 
260 andreas 2406
void MainWindow::startWait(const string& text)
2407
{
2408
    DECL_TRACER("MainWindow::startWait(const string& text)");
2409
 
2410
    if (mWaitBox)
2411
    {
2412
        mWaitBox->setText(text);
2413
        return;
2414
    }
2415
 
2416
    mWaitBox = new TQtWait(this, text);
2417
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
2418
    mWaitBox->setScaleFactor(mScaleFactor);
2419
    mWaitBox->doResize();
2420
    mWaitBox->start();
2421
#endif
2422
}
2423
 
2424
void MainWindow::stopWait()
2425
{
2426
    DECL_TRACER("MainWindow::stopWait()");
2427
 
2428
    if (!mWaitBox)
2429
        return;
2430
 
2431
    mWaitBox->end();
2432
    delete mWaitBox;
2433
    mWaitBox = nullptr;
2434
}
2435
 
273 andreas 2436
void MainWindow::pageFinished(ulong handle)
271 andreas 2437
{
2438
    DECL_TRACER("MainWindow::pageFinished(uint handle)");
2439
 
277 andreas 2440
    TObject::OBJECT_t *obj = findObject(handle);
273 andreas 2441
 
279 andreas 2442
    if (obj)
2443
    {
298 andreas 2444
        if (obj->type == TObject::OBJ_SUBPAGE && (obj->animate.showEffect == SE_NONE || obj->animate.showTime <= 0) && obj->object.widget)
295 andreas 2445
        {
297 andreas 2446
            if (!obj->object.widget->isEnabled())
2447
                obj->object.widget->setEnabled(true);
2448
 
295 andreas 2449
            obj->object.widget->lower();
279 andreas 2450
            obj->object.widget->show();
295 andreas 2451
            obj->object.widget->raise();
2452
        }
297 andreas 2453
 
295 andreas 2454
        if (obj->type == TObject::OBJ_SUBPAGE && obj->animate.showEffect != SE_NONE && obj->object.widget)
2455
        {
298 andreas 2456
            if (startAnimation(obj, obj->animate))
2457
                return;
295 andreas 2458
        }
279 andreas 2459
 
2460
        if ((obj->type == TObject::OBJ_PAGE || obj->type == TObject::OBJ_SUBPAGE) && obj->object.widget)
2461
        {
2462
            QObjectList list = obj->object.widget->children();
2463
            QObjectList::Iterator iter;
2464
 
2465
            for (iter = list.begin(); iter != list.end(); ++iter)
2466
            {
2467
                QObject *o = *iter;
297 andreas 2468
                ulong child = extractHandle(o->objectName().toStdString());
2469
                OBJECT_t *obj = nullptr;
279 andreas 2470
 
297 andreas 2471
                if (child && (obj = findObject(child)) != nullptr)
279 andreas 2472
                {
297 andreas 2473
                    if (obj->invalid && obj->type != OBJ_SUBPAGE)
2474
                        obj->invalid = false;
279 andreas 2475
 
297 andreas 2476
                    if (obj->remove)
2477
                        obj->remove = false;
2478
 
2479
                    switch (obj->type)
279 andreas 2480
                    {
297 andreas 2481
                        case OBJ_PAGE:
2482
                        case OBJ_SUBPAGE:
2483
                            if (obj->object.widget && !obj->invalid && obj->object.widget->isHidden())
2484
                            {
2485
                                if (!obj->object.widget->isEnabled())
2486
                                    obj->object.widget->setEnabled(true);
2487
 
298 andreas 2488
                                obj->object.widget->lower();
297 andreas 2489
                                obj->object.widget->show();
298 andreas 2490
                                obj->object.widget->raise();
297 andreas 2491
                            }
2492
                        break;
2493
 
2494
                        case OBJ_BUTTON:
2495
                            if (obj->object.label && obj->object.label->isHidden())
2496
                                obj->object.label->show();
2497
                        break;
2498
 
2499
                        case OBJ_INPUT:
2500
                        case OBJ_TEXT:
2501
                            if (obj->object.plaintext && obj->object.plaintext->isHidden())
2502
                                obj->object.plaintext->show();
2503
                        break;
2504
 
2505
                        case OBJ_LIST:
2506
                            if (obj->object.list && obj->object.list->isHidden())
2507
                                obj->object.list->show();
2508
                        break;
2509
 
2510
                        case OBJ_SUBVIEW:
2511
                            if (obj->object.area && obj->object.area->isHidden())
298 andreas 2512
                            {
2513
                                obj->object.area->lower();
297 andreas 2514
                                obj->object.area->show();
298 andreas 2515
                                obj->object.area->raise();
2516
                            }
297 andreas 2517
                        break;
2518
 
2519
                        case OBJ_VIDEO:
2520
                            if (obj->object.vwidget && obj->object.vwidget->isHidden())
2521
                                obj->object.vwidget->show();
2522
                        break;
2523
 
2524
                        default:
2525
                            MSG_WARNING("Object " << handleToString(child) << " is an invalid type!");
279 andreas 2526
                    }
2527
                }
297 andreas 2528
                else
2529
                {
2530
                    QString obName = o->objectName();
2531
 
2532
                    if (obName.startsWith("Label_"))
2533
                    {
2534
                        QLabel *l = dynamic_cast<QLabel *>(o);
2535
 
2536
                        if (l->isHidden())
2537
                            l->show();
2538
                    }
2539
                }
279 andreas 2540
            }
2541
        }
284 andreas 2542
 
296 andreas 2543
        if (obj->type == OBJ_SUBVIEW && obj->object.area)
285 andreas 2544
            obj->object.area->show();
279 andreas 2545
    }
297 andreas 2546
#ifdef QT_DEBUG
2547
    else
2548
    {
2549
        MSG_WARNING("Object " << handleToString(handle) << " not found!");
2550
    }
2551
#endif
2552
//    cleanMarked();
271 andreas 2553
}
2554
 
61 andreas 2555
/**
2556
 * @brief MainWindow::appStateChanged - Is called whenever the state of the app changes.
2557
 * This callback method is called whenever the state of the application
2558
 * changes. This is mostly usefull on mobile devices. Whenever the main window
2559
 * looses the focus (screen closed, application is put into background, ...)
2560
 * this method is called and updates a flag. If the application is not able
2561
 * to draw to the screen (suspended) all events are cached. At the moment the
2562
 * application becomes active, all queued messages are applied.
2563
 * @param state     The new state of the application.
2564
 */
213 andreas 2565
void MainWindow::onAppStateChanged(Qt::ApplicationState state)
31 andreas 2566
{
265 andreas 2567
    DECL_TRACER("MainWindow::onAppStateChanged(Qt::ApplicationState state)");
31 andreas 2568
 
2569
    switch (state)
2570
    {
61 andreas 2571
        case Qt::ApplicationSuspended:              // Should not occure on a normal desktop
36 andreas 2572
            MSG_INFO("Switched to mode SUSPEND");
31 andreas 2573
            mHasFocus = false;
131 andreas 2574
#ifdef Q_OS_ANDROID
264 andreas 2575
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
131 andreas 2576
            QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/Orientation", "pauseOrientationListener", "()V");
182 andreas 2577
#else
2578
            QJniObject::callStaticMethod<void>("org/qtproject/theosys/Orientation", "pauseOrientationListener", "()V");
2579
#endif
252 andreas 2580
//#elif defined(Q_OS_IOS)
2581
//            if (mIosRotate)
2582
//                mIosRotate->automaticRotation(false);
183 andreas 2583
#endif
31 andreas 2584
        break;
61 andreas 2585
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)      // On a normal desktop we can ignore this signals
31 andreas 2586
        case Qt::ApplicationInactive:
36 andreas 2587
            MSG_INFO("Switched to mode INACTIVE");
31 andreas 2588
            mHasFocus = false;
142 andreas 2589
            mWasInactive = true;
235 andreas 2590
#ifdef Q_OS_ANDROID
264 andreas 2591
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
131 andreas 2592
            QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/Orientation", "pauseOrientationListener", "()V");
182 andreas 2593
#else
2594
            QJniObject::callStaticMethod<void>("org/qtproject/theosys/Orientation", "pauseOrientationListener", "()V");
2595
#endif
235 andreas 2596
#endif
31 andreas 2597
        break;
2598
 
2599
        case Qt::ApplicationHidden:
36 andreas 2600
            MSG_INFO("Switched to mode HIDDEN");
31 andreas 2601
            mHasFocus = false;
235 andreas 2602
#ifdef Q_OS_ANDROID
264 andreas 2603
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
131 andreas 2604
            QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/Orientation", "pauseOrientationListener", "()V");
182 andreas 2605
#else
2606
            QJniObject::callStaticMethod<void>("org/qtproject/theosys/Orientation", "pauseOrientationListener", "()V");
2607
#endif
235 andreas 2608
#endif
31 andreas 2609
        break;
61 andreas 2610
#endif
31 andreas 2611
        case Qt::ApplicationActive:
36 andreas 2612
            MSG_INFO("Switched to mode ACTIVE");
31 andreas 2613
            mHasFocus = true;
38 andreas 2614
 
92 andreas 2615
            if (!isRunning && gPageManager)
38 andreas 2616
            {
2617
                // Start the core application
92 andreas 2618
                gPageManager->startUp();
2619
                gPageManager->run();
38 andreas 2620
                isRunning = true;
142 andreas 2621
                mWasInactive = false;
252 andreas 2622
#ifdef Q_OS_IOS
2623
                if (!mSource)
2624
                    initGeoLocation();
2625
 
2626
                if (mSource)
2627
                {
2628
                    mSource->startUpdates();
2629
                    MSG_DEBUG("Geo location updates started.");
2630
                }
2631
                else
2632
                {
2633
                    MSG_WARNING("Geo location is not available!");
2634
                }
2635
 
2636
                if (mSensor)
2637
                {
263 andreas 2638
                    if (mIosRotate && mOrientation == Qt::PrimaryOrientation) // Unknown?
2639
                    {
2640
                        switch(mIosRotate->getCurrentOrientation())
2641
                        {
2642
                            case O_PORTRAIT:            mOrientation = Qt::PortraitOrientation; break;
2643
                            case O_REVERSE_PORTRAIT:    mOrientation = Qt::InvertedPortraitOrientation; break;
2644
                            case O_REVERSE_LANDSCAPE:   mOrientation = Qt::InvertedLandscapeOrientation; break;
2645
                            case O_LANDSCAPE:           mOrientation = Qt::LandscapeOrientation; break;
2646
                        }
2647
                    }
2648
#ifdef QT_DEBUG
2649
                    MSG_DEBUG("Orientation after activate: " << orientationToString(mOrientation));
2650
#endif
2651
                    if (gPageManager && mIosRotate && gPageManager->getSettings()->isPortrait() &&
2652
                        mOrientation != Qt::PortraitOrientation)
264 andreas 2653
                    {
263 andreas 2654
                        mIosRotate->rotate(O_PORTRAIT);
264 andreas 2655
                        mOrientation = Qt::PortraitOrientation;
2656
                    }
263 andreas 2657
                    else if (gPageManager && mIosRotate && mOrientation != Qt::LandscapeOrientation)
264 andreas 2658
                    {
263 andreas 2659
                        mIosRotate->rotate(O_LANDSCAPE);
264 andreas 2660
                        mOrientation = Qt::LandscapeOrientation;
2661
                    }
263 andreas 2662
 
2663
                    setNotch();
252 andreas 2664
                }
2665
#endif
38 andreas 2666
            }
2667
            else
142 andreas 2668
            {
264 andreas 2669
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) && defined(Q_OS_ANDROID)
217 andreas 2670
                _freezeWorkaround();
2671
#endif
38 andreas 2672
                playShowList();
142 andreas 2673
 
2674
                if (mDoRepaint && mWasInactive)
2675
                    repaintObjects();
2676
 
2677
                mDoRepaint = false;
2678
                mWasInactive = false;
2679
            }
131 andreas 2680
#ifdef Q_OS_ANDROID
264 andreas 2681
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
271 andreas 2682
            QAndroidJniObject activity = QtAndroid::androidActivity();
2683
            QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/HideToolbar", "hide", "(Landroid/app/Activity;Z)V", activity.object(), true);
131 andreas 2684
            QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/Orientation", "resumeOrientationListener", "()V");
182 andreas 2685
#else
271 andreas 2686
            QJniObject activity = QNativeInterface::QAndroidApplication::context();
2687
            QJniObject::callStaticMethod<void>("org/qtproject/theosys/HideToolbar", "hide", "(Landroid/app/Activity;Z)V", activity.object(), true);
182 andreas 2688
            QJniObject::callStaticMethod<void>("org/qtproject/theosys/Orientation", "resumeOrientationListener", "()V");
131 andreas 2689
#endif
182 andreas 2690
#endif
249 andreas 2691
#ifdef Q_OS_IOS
259 andreas 2692
            if (mIOSSettingsActive)
2693
            {
2694
                mIOSSettingsActive = false;
2695
                MSG_DEBUG("Activating settings");
2696
                activateSettings(QASettings::getOldNetlinx(),
2697
                                  QASettings::getOldPort(),
2698
                                  QASettings::getOoldChannelID(),
2699
                                  QASettings::getOldSurface(),
2700
                                  QASettings::getOldToolbarSuppress(),
2701
                                  QASettings::getOldToolbarForce());
2702
            }
249 andreas 2703
#endif
326 andreas 2704
#if TESTMODE == 1
2705
            {
2706
                if (_gTestMode)
2707
                    _gTestMode->run();
2708
            }
2709
#endif
31 andreas 2710
        break;
264 andreas 2711
#if not defined(Q_OS_IOS) && not defined(Q_OS_ANDROID)
61 andreas 2712
        default:
2713
            mHasFocus = true;
2714
#endif
31 andreas 2715
    }
235 andreas 2716
#if defined(Q_OS_ANDROID)
92 andreas 2717
    if (mHasFocus && gPageManager)
38 andreas 2718
    {
92 andreas 2719
        gPageManager->initNetworkState();
2720
        gPageManager->initBatteryState();
38 andreas 2721
    }
92 andreas 2722
    else if (gPageManager)
38 andreas 2723
    {
92 andreas 2724
        gPageManager->stopNetworkState();
2725
        gPageManager->stopBatteryState();
38 andreas 2726
    }
37 andreas 2727
#endif
31 andreas 2728
}
2729
 
64 andreas 2730
void MainWindow::_shutdown()
2731
{
2732
    DECL_TRACER("MainWindow::_shutdown()")
2733
 
2734
    close();
2735
}
2736
 
32 andreas 2737
/******************* Signal handling *************************/
2738
 
44 andreas 2739
void MainWindow::_resetSurface()
2740
{
2741
    DECL_TRACER("MainWindow::_resetSurface()");
2742
 
90 andreas 2743
    // Start over by exiting this class
2744
    MSG_INFO("Program will start over!");
2745
    _restart_ = true;
2746
    prg_stopped = true;
2747
    killed = true;
88 andreas 2748
 
90 andreas 2749
    if (gAmxNet)
2750
        gAmxNet->stop();
88 andreas 2751
 
90 andreas 2752
    close();
44 andreas 2753
}
2754
 
298 andreas 2755
void MainWindow::_displayButton(ulong handle, ulong parent, TBitmap buffer, int width, int height, int left, int top, bool passthrough)
4 andreas 2756
{
298 andreas 2757
    DECL_TRACER("MainWindow::_displayButton(ulong handle, ulong parent, TBitmap buffer, int width, int height, int left, int top, bool passthrough)");
14 andreas 2758
 
21 andreas 2759
    if (prg_stopped)
2760
        return;
2761
 
61 andreas 2762
    if (!mHasFocus)     // Suspended?
2763
    {
298 andreas 2764
        addButton(handle, parent, buffer, left, top, width, height, passthrough);
61 andreas 2765
        return;
2766
    }
2767
 
298 andreas 2768
    emit sigDisplayButton(handle, parent, buffer, width, height, left, top, passthrough);
14 andreas 2769
}
2770
 
289 andreas 2771
void MainWindow::_displayViewButton(ulong handle, ulong parent, bool vertical, TBitmap buffer, int width, int height, int left, int top, int space, TColor::COLOR_T fillColor)
279 andreas 2772
{
289 andreas 2773
    DECL_TRACER("MainWindow::_displayViewButton(ulong handle, ulong parent, TBitmap buffer, int width, int height, int left, int top)");
279 andreas 2774
 
2775
    if (prg_stopped)
2776
        return;
2777
 
2778
    if (!mHasFocus)     // Suspended?
2779
    {
289 andreas 2780
        addViewButton(handle, parent, vertical, buffer, left, top, width, height, space, fillColor);
279 andreas 2781
        return;
2782
    }
2783
 
289 andreas 2784
    emit sigDisplayViewButton(handle, parent, vertical, buffer, width, height, left, top, space, fillColor);
279 andreas 2785
}
2786
 
285 andreas 2787
void MainWindow::_addViewButtonItems(ulong parent, vector<PGSUBVIEWITEM_T> items)
279 andreas 2788
{
285 andreas 2789
    DECL_TRACER("MainWindow::_addViewButtonItems(ulong parent, vector<PGSUBVIEWITEM_T> items)");
279 andreas 2790
 
2791
    if (prg_stopped)
2792
        return;
2793
 
2794
    try
2795
    {
285 andreas 2796
        emit sigAddViewButtonItems(parent, items);
279 andreas 2797
    }
280 andreas 2798
    catch(std::exception& e)
2799
    {
2800
        MSG_ERROR("Error triggering function \"addViewButtonItems()\": " << e.what());
2801
    }
2802
}
2803
 
300 andreas 2804
void MainWindow::_updateViewButton(ulong handle, ulong parent, TBitmap buffer, TColor::COLOR_T fillColor)
2805
{
2806
    DECL_TRACER("MainWindow::_updateViewButton(ulong handle, ulong parent, TBitmap buffer, TColor::COLOR_T fillColor)");
2807
 
2808
    if (prg_stopped)
2809
        return;
2810
 
2811
    try
2812
    {
2813
        emit sigUpdateViewButton(handle, parent, buffer, fillColor);
2814
    }
2815
    catch (std::exception& e)
2816
    {
2817
        MSG_ERROR("Error triggering function \"updateViewButton()\": " << e.what());
2818
    }
2819
}
2820
 
2821
void MainWindow::_updateViewButtonItem(PGSUBVIEWITEM_T& item, ulong parent)
2822
{
2823
    DECL_TRACER("MainWindow::_updateViewButtonItem(PGSUBVIEWITEM_T& item, ulong parent)");
2824
 
2825
    if (prg_stopped)
2826
        return;
2827
 
2828
    try
2829
    {
2830
        emit sigUpdateViewButtonItem(item, parent);
2831
    }
2832
    catch (std::exception& e)
2833
    {
2834
        MSG_ERROR("Error triggering function \"updateViewButtonItem()\": " << e.what());
2835
    }
2836
}
2837
 
2838
void MainWindow::_showViewButtonItem(ulong handle, ulong parent, int position, int timer)
2839
{
2840
    DECL_TRACER("MainWindow::_showViewButtonItem(ulong handle, ulong parent, int position, int timer)");
2841
 
2842
    if (prg_stopped)
2843
        return;
2844
 
2845
    try
2846
    {
303 andreas 2847
        emit sigShowViewButtonItem(handle, parent, position, timer);
300 andreas 2848
    }
2849
    catch (std::exception& e)
2850
    {
2851
        MSG_ERROR("Error triggering function \"showViewButtonItem()\": " << e.what());
2852
    }
2853
}
2854
 
318 andreas 2855
void MainWindow::_hideAllViewItems(ulong handle)
2856
{
2857
    DECL_TRACER("MainWindow::_hideAllViewItems(ulong handle)");
2858
 
2859
    if (prg_stopped)
2860
        return;
2861
 
2862
    emit sigHideAllViewItems(handle);
2863
}
2864
 
2865
void MainWindow::_toggleViewButtonItem(ulong handle, ulong parent, int position, int timer)
2866
{
2867
    DECL_TRACER("MainWindow::_toggleViewButtonItem(ulong handle, ulong parent, int position, int timer)");
2868
 
2869
    if (prg_stopped)
2870
        return;
2871
 
2872
    emit sigToggleViewButtonItem(handle, parent, position, timer);
2873
}
2874
 
2875
void MainWindow::_hideViewItem(ulong handle, ulong parent)
2876
{
2877
    DECL_TRACER("MainWindow::_hideViewItem(ulong handle, ulong parent)");
2878
 
2879
    if (prg_stopped)
2880
        return;
2881
 
2882
    emit sigHideViewItem(handle, parent);
2883
}
2884
 
98 andreas 2885
void MainWindow::_setVisible(ulong handle, bool state)
2886
{
2887
    DECL_TRACER("MainWindow::_setVisible(ulong handle, bool state)");
2888
 
2889
    if (prg_stopped)
2890
        return;
2891
 
2892
    emit sigSetVisible(handle, state);
2893
}
2894
 
318 andreas 2895
void MainWindow::_setSubViewPadding(ulong handle, int padding)
2896
{
2897
    DECL_TRACER("MainWindow::_setSubViewPadding(ulong handle, int padding)");
2898
 
2899
    if (prg_stopped)
2900
        return;
2901
 
2902
    emit sigSetSubViewPadding(handle, padding);
2903
}
2904
 
14 andreas 2905
void MainWindow::_setPage(ulong handle, int width, int height)
2906
{
2907
    DECL_TRACER("MainWindow::_setPage(ulong handle, int width, int height)");
2908
 
21 andreas 2909
    if (prg_stopped)
2910
        return;
2911
 
61 andreas 2912
    if (!mHasFocus)
2913
    {
2914
        addPage(handle, width, height);
2915
        return;
2916
    }
2917
 
14 andreas 2918
    emit sigSetPage(handle, width, height);
2919
}
2920
 
217 andreas 2921
void MainWindow::_setSubPage(ulong handle, ulong parent, int left, int top, int width, int height, ANIMATION_t animate)
14 andreas 2922
{
217 andreas 2923
    DECL_TRACER("MainWindow::_setSubPage(ulong handle, ulong parent, int left, int top, int width, int height)");
14 andreas 2924
 
21 andreas 2925
    if (prg_stopped)
2926
        return;
2927
 
61 andreas 2928
    if (!mHasFocus)
2929
    {
217 andreas 2930
        addSubPage(handle, parent, left, top, width, height, animate);
61 andreas 2931
        return;
2932
    }
2933
 
217 andreas 2934
    emit sigSetSubPage(handle, parent, left, top, width, height, animate);
298 andreas 2935
//#ifndef Q_OS_ANDROID
2936
//    std::this_thread::sleep_for(std::chrono::milliseconds(THREAD_WAIT));
2937
//#endif
14 andreas 2938
}
2939
 
262 andreas 2940
#ifdef _OPAQUE_SKIA_
289 andreas 2941
void MainWindow::_setBackground(ulong handle, TBitmap image, int width, int height, ulong color)
262 andreas 2942
#else
289 andreas 2943
void MainWindow::_setBackground(ulong handle, TBitmap image, int width, int height, ulong color, int opacity)
262 andreas 2944
#endif
14 andreas 2945
{
289 andreas 2946
    DECL_TRACER("MainWindow::_setBackground(ulong handle, TBitmap image, int width, int height, ulong color [, int opacity])");
14 andreas 2947
 
21 andreas 2948
    if (prg_stopped)
2949
        return;
2950
 
61 andreas 2951
    if (!mHasFocus)
2952
    {
262 andreas 2953
#ifdef _OPAQUE_SKIA_
289 andreas 2954
        addBackground(handle, image, width, height, color);
262 andreas 2955
#else
289 andreas 2956
        addBackground(handle, image, width, height, color, opacity);
262 andreas 2957
#endif
61 andreas 2958
        return;
2959
    }
2960
 
262 andreas 2961
#ifdef _OPAQUE_SKIA_
289 andreas 2962
    emit sigSetBackground(handle, image, width, height, color);
262 andreas 2963
#else
289 andreas 2964
    emit sigSetBackground(handle, image, width, height, color, opacity);
57 andreas 2965
#endif
14 andreas 2966
}
2967
 
2968
void MainWindow::_dropPage(ulong handle)
2969
{
2970
    DECL_TRACER("MainWindow::_dropPage(ulong handle)");
2971
 
70 andreas 2972
    doReleaseButton();
2973
 
61 andreas 2974
    if (!mHasFocus)
2975
    {
2976
        markDrop(handle);
2977
        return;
2978
    }
2979
 
14 andreas 2980
    emit sigDropPage(handle);
70 andreas 2981
 
298 andreas 2982
//#ifndef Q_OS_ANDROID
2983
//    std::this_thread::sleep_for(std::chrono::milliseconds(THREAD_WAIT));
2984
//#endif
14 andreas 2985
}
2986
 
2987
void MainWindow::_dropSubPage(ulong handle)
2988
{
2989
    DECL_TRACER("MainWindow::_dropSubPage(ulong handle)");
2990
 
70 andreas 2991
    doReleaseButton();
2992
 
61 andreas 2993
    if (!mHasFocus)
2994
    {
2995
        markDrop(handle);
2996
        return;
2997
    }
2998
 
14 andreas 2999
    emit sigDropSubPage(handle);
70 andreas 3000
 
298 andreas 3001
//#ifndef Q_OS_ANDROID
3002
//    std::this_thread::sleep_for(std::chrono::milliseconds(THREAD_WAIT));
3003
//#endif
14 andreas 3004
}
3005
 
98 andreas 3006
void MainWindow::_dropButton(ulong handle)
3007
{
3008
    DECL_TRACER("MainWindow::_dropButton(ulong handle)");
3009
 
3010
    if (!mHasFocus)
3011
    {
3012
        markDrop(handle);
3013
        return;
3014
    }
3015
 
3016
    emit sigDropButton(handle);
3017
}
3018
 
21 andreas 3019
void MainWindow::_playVideo(ulong handle, ulong parent, int left, int top, int width, int height, const string& url, const string& user, const string& pw)
3020
{
3021
    DECL_TRACER("MainWindow::_playVideo(ulong handle, const string& url)");
3022
 
3023
    if (prg_stopped)
3024
        return;
3025
 
61 andreas 3026
    if (!mHasFocus)
3027
    {
3028
        addVideo(handle, parent, left, top, width, height, url, user, pw);
3029
        return;
3030
    }
3031
 
21 andreas 3032
    emit sigPlayVideo(handle, parent, left, top, width, height, url, user, pw);
298 andreas 3033
//#ifndef Q_OS_ANDROID
3034
//    std::this_thread::sleep_for(std::chrono::milliseconds(THREAD_WAIT));
3035
//#endif
21 andreas 3036
}
3037
 
291 andreas 3038
void MainWindow::_inputText(Button::TButton *button, Button::BITMAP_t& bm, int frame)
50 andreas 3039
{
291 andreas 3040
    DECL_TRACER("MainWindow::_inputText(Button::TButton *button, Button::BITMAP_t& bm, int frame)");
50 andreas 3041
 
291 andreas 3042
    if (prg_stopped || !button)
50 andreas 3043
        return;
3044
 
61 andreas 3045
    if (!mHasFocus)
3046
    {
291 andreas 3047
        addInText(button->getHandle(), button, bm, frame);
61 andreas 3048
        return;
3049
    }
3050
 
52 andreas 3051
    QByteArray buf;
3052
 
3053
    if (bm.buffer && bm.rowBytes > 0)
3054
    {
3055
        size_t size = bm.width * bm.height * (bm.rowBytes / bm.width);
3056
        buf.insert(0, (const char *)bm.buffer, size);
3057
    }
57 andreas 3058
 
192 andreas 3059
    emit sigInputText(button, buf, bm.width, bm.height, frame, bm.rowBytes);
298 andreas 3060
//#ifndef Q_OS_ANDROID
3061
//    std::this_thread::sleep_for(std::chrono::milliseconds(THREAD_WAIT));
3062
//#endif
50 andreas 3063
}
3064
 
291 andreas 3065
void MainWindow::_listBox(Button::TButton *button, Button::BITMAP_t& bm, int frame)
200 andreas 3066
{
279 andreas 3067
    DECL_TRACER("MainWindow::_listBox(Button::TButton& button, Button::BITMAP_t& bm, int frame)");
200 andreas 3068
 
279 andreas 3069
    if (prg_stopped)
200 andreas 3070
        return;
3071
 
3072
    if (!mHasFocus)
3073
    {
291 andreas 3074
        addListBox(button, bm, frame);
200 andreas 3075
        return;
3076
    }
3077
 
3078
    QByteArray buf;
3079
 
3080
    if (bm.buffer && bm.rowBytes > 0)
3081
    {
3082
        size_t size = bm.width * bm.height * (bm.rowBytes / bm.width);
3083
        buf.insert(0, (const char *)bm.buffer, size);
3084
    }
3085
 
3086
    emit sigListBox(button, buf, bm.width, bm.height, frame, bm.rowBytes);
3087
}
3088
 
63 andreas 3089
void MainWindow::_showKeyboard(const std::string& init, const std::string& prompt, bool priv)
62 andreas 3090
{
63 andreas 3091
    DECL_TRACER("MainWindow::_showKeyboard(std::string &init, std::string &prompt, bool priv)");
62 andreas 3092
 
3093
    if (prg_stopped)
3094
        return;
3095
 
70 andreas 3096
    doReleaseButton();
63 andreas 3097
    emit sigKeyboard(init, prompt, priv);
62 andreas 3098
}
3099
 
63 andreas 3100
void MainWindow::_showKeypad(const std::string& init, const std::string& prompt, bool priv)
62 andreas 3101
{
63 andreas 3102
    DECL_TRACER("MainWindow::_showKeypad(std::string &init, std::string &prompt, bool priv)");
62 andreas 3103
 
3104
    if (prg_stopped)
3105
        return;
3106
 
70 andreas 3107
    doReleaseButton();
63 andreas 3108
    emit sigKeypad(init, prompt, priv);
62 andreas 3109
}
3110
 
63 andreas 3111
void MainWindow::_resetKeyboard()
3112
{
3113
    DECL_TRACER("MainWindow::_resetKeyboard()");
3114
 
3115
    emit sigResetKeyboard();
3116
}
3117
 
64 andreas 3118
void MainWindow::_showSetup()
3119
{
3120
    DECL_TRACER("MainWindow::_showSetup()");
3121
 
3122
    emit sigShowSetup();
3123
}
3124
 
71 andreas 3125
void MainWindow::_playSound(const string& file)
3126
{
3127
    DECL_TRACER("MainWindow::_playSound(const string& file)");
3128
 
3129
    emit sigPlaySound(file);
3130
}
3131
 
141 andreas 3132
void MainWindow::_stopSound()
3133
{
3134
    DECL_TRACER("MainWindow::_stopSound()");
3135
 
3136
    emit sigStopSound();
3137
}
3138
 
3139
void MainWindow::_muteSound(bool state)
3140
{
3141
    DECL_TRACER("MainWindow::_muteSound(bool state)");
3142
 
156 andreas 3143
    emit sigMuteSound(state);
141 andreas 3144
}
3145
 
88 andreas 3146
void MainWindow::_setOrientation(J_ORIENTATION ori)
3147
{
182 andreas 3148
#ifdef Q_OS_ANDROID
88 andreas 3149
    DECL_TRACER("MainWindow::_setOriantation(J_ORIENTATION ori)");
3150
 
134 andreas 3151
    if (ori == O_FACE_UP || ori == O_FACE_DOWN)
3152
        return;
264 andreas 3153
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
88 andreas 3154
    QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;");
182 andreas 3155
#else
183 andreas 3156
    QJniObject activity = QJniObject::callStaticObjectMethod("org/qtproject/qt/android/QtNative", "activity", "()Landroid/app/Activity;");
182 andreas 3157
#endif
88 andreas 3158
    if ( activity.isValid() )
3159
    {
3160
        activity.callMethod<void>
3161
                ("setRequestedOrientation"  // method name
3162
                 , "(I)V"                   // signature
3163
                 , ori);
131 andreas 3164
 
3165
        switch(ori)
3166
        {
3167
            case O_LANDSCAPE:           mOrientation = Qt::LandscapeOrientation; break;
3168
            case O_PORTRAIT:            mOrientation = Qt::PortraitOrientation; break;
3169
            case O_REVERSE_LANDSCAPE:   mOrientation = Qt::InvertedLandscapeOrientation; break;
3170
            case O_REVERSE_PORTRAIT:    mOrientation = Qt::InvertedPortraitOrientation; break;
3171
            default:
3172
                MSG_WARNING("Orientation is undefined!");
3173
                mOrientation = Qt::PrimaryOrientation;
3174
        }
88 andreas 3175
    }
243 andreas 3176
#elif defined(Q_OS_IOS)
252 andreas 3177
    if (mIosRotate)
264 andreas 3178
    {
252 andreas 3179
        mIosRotate->rotate(ori);
264 andreas 3180
#ifdef QT_DEBUG
3181
        string msg;
3182
 
3183
        switch(ori)
3184
        {
3185
            case O_LANDSCAPE:           msg = "LANDSCAPE"; break;
3186
            case O_PORTRAIT:            msg = "PORTRAIT"; break;
3187
            case O_REVERSE_PORTRAIT:    msg = "INVERTED PORTRAIT"; break;
3188
            case O_REVERSE_LANDSCAPE:   msg = "INVERTED LANDSCAPE"; break;
3189
            default:
3190
                msg = "unknown";
3191
        }
3192
 
3193
        MSG_DEBUG("Rotated to " << msg);
3194
#endif
3195
    }
237 andreas 3196
#else
3197
    Q_UNUSED(ori);
88 andreas 3198
#endif
3199
}
3200
 
111 andreas 3201
void MainWindow::_sendVirtualKeys(const string& str)
3202
{
3203
    DECL_TRACER("MainWindow::_sendVirtualKeys(const string& str)");
3204
 
3205
    emit sigSendVirtualKeys(str);
3206
}
3207
 
140 andreas 3208
void MainWindow::_showPhoneDialog(bool state)
3209
{
3210
    DECL_TRACER("MainWindow::_showPhoneDialog(bool state)");
3211
 
3212
    emit sigShowPhoneDialog(state);
3213
}
3214
 
3215
void MainWindow::_setPhoneNumber(const std::string& number)
3216
{
3217
    DECL_TRACER("MainWindow::_setPhoneNumber(const std::string& number)");
3218
 
3219
    emit sigSetPhoneNumber(number);
3220
}
3221
 
3222
void MainWindow::_setPhoneStatus(const std::string& msg)
3223
{
3224
    DECL_TRACER("MainWindow::_setPhoneStatus(const std::string& msg)");
3225
 
3226
    emit sigSetPhoneStatus(msg);
3227
}
3228
 
141 andreas 3229
void MainWindow::_setPhoneState(int state, int id)
3230
{
3231
    DECL_TRACER("MainWindow::_setPhoneState(int state, int id)");
3232
 
3233
    emit sigSetPhoneState(state, id);
3234
}
3235
 
179 andreas 3236
void MainWindow::_onProgressChanged(int percent)
3237
{
3238
    DECL_TRACER("MainWindow::_onProgressChanged(int percent)");
3239
 
3240
    emit sigOnProgressChanged(percent);
3241
}
3242
 
206 andreas 3243
void MainWindow::_displayMessage(const string &msg, const string &title)
3244
{
3245
    DECL_TRACER("MainWindow::_displayMessage(const string &msg, const string &title)");
3246
 
3247
    emit sigDisplayMessage(msg, title);
3248
}
3249
 
209 andreas 3250
void MainWindow::_fileDialog(ulong handle, const string &path, const std::string& extension, const std::string& suffix)
3251
{
3252
    DECL_TRACER("MainWindow::_fileDialog(ulong handle, const string &path, const std::string& extension, const std::string& suffix)");
3253
 
3254
    if (!handle || path.empty())
3255
    {
3256
        MSG_WARNING("Invalid parameter handle or no path!");
3257
        return;
3258
    }
3259
 
3260
    emit sigFileDialog(handle, path, extension, suffix);
3261
}
252 andreas 3262
 
197 andreas 3263
void MainWindow::_setSizeMainWindow(int width, int height)
3264
{
252 andreas 3265
#if !defined (Q_OS_ANDROID) && !defined(Q_OS_IOS)
197 andreas 3266
    DECL_TRACER("MainWindow::_setSizeMainWindow(int width, int height)");
3267
 
3268
    emit sigSetSizeMainWindow(width, height);
252 andreas 3269
#else
3270
    Q_UNUSED(width);
3271
    Q_UNUSED(height);
3272
#endif
197 andreas 3273
}
252 andreas 3274
 
279 andreas 3275
void MainWindow::_listViewArea(ulong handle, ulong parent, Button::TButton& button, SUBVIEWLIST_T& list)
3276
{
3277
    DECL_TRACER("MainWindow::_listViewArea(ulong handle, ulong parent, Button::TButton *button, SUBVIEWLIST_T& list)");
3278
 
3279
    if (!handle || !parent || list.id <= 0)
3280
    {
3281
        MSG_WARNING("Invalid parameters for scroll area!");
3282
        return;
3283
    }
3284
 
3285
    emit sigListViewArea(handle, parent, button, list);
3286
}
3287
 
70 andreas 3288
void MainWindow::doReleaseButton()
3289
{
3290
    DECL_TRACER("MainWindow::doReleaseButton()");
3291
 
92 andreas 3292
    if (mLastPressX >= 0 && mLastPressX >= 0 && gPageManager)
70 andreas 3293
    {
3294
        MSG_DEBUG("Sending outstanding mouse release event for coordinates x" << mLastPressX << ", y" << mLastPressY);
3295
        int x = mLastPressX;
3296
        int y = mLastPressY;
3297
 
3298
        if (isScaled())
3299
        {
3300
            x = (int)((double)x / mScaleFactor);
3301
            y = (int)((double)y / mScaleFactor);
3302
        }
3303
 
92 andreas 3304
        gPageManager->mouseEvent(x, y, false);
70 andreas 3305
    }
3306
 
3307
    mLastPressX = mLastPressY = -1;
3308
}
3309
 
142 andreas 3310
/**
3311
 * @brief MainWindow::repaintObjects
3312
 * On a mobile device it is possible that the content, mostly the background, of
3313
 * a window becomes destroyed and it is not repainted. This may be the case at
3314
 * the moment where the device was disconnected from the controller and
3315
 * reconnected while the application was inactive. In such a case usualy the
3316
 * surface is completely repainted. But because of inactivity this was not
3317
 * possible and some components may look destroyed. They are still functional
3318
 * allthough.
3319
 */
3320
void MainWindow::repaintObjects()
3321
{
3322
    DECL_TRACER("MainWindow::repaintObjects()");
3323
 
292 andreas 3324
    TLOCKER(draw_mutex);
154 andreas 3325
#ifdef Q_OS_ANDROID
3326
    std::this_thread::sleep_for(std::chrono::milliseconds(200));    // Necessary for slow devices
3327
#endif
277 andreas 3328
    TObject::OBJECT_t *obj = findFirstWindow();
142 andreas 3329
 
3330
    while (obj)
3331
    {
297 andreas 3332
        if (!obj->remove && !obj->invalid && obj->object.widget)
148 andreas 3333
        {
271 andreas 3334
            MSG_PROTOCOL("Refreshing widget " << handleToString (obj->handle));
154 andreas 3335
            obj->object.widget->repaint();
148 andreas 3336
        }
142 andreas 3337
 
277 andreas 3338
        obj = findNextWindow(obj);
142 andreas 3339
    }
3340
}
3341
 
297 andreas 3342
void MainWindow::refresh(ulong handle)
3343
{
3344
    DECL_TRACER("MainWindow::refresh(ulong handle)");
3345
 
3346
    if (!handle)
3347
        return;
3348
 
3349
    OBJECT_t *obj = findFirstChild(handle);
3350
 
3351
    while (obj)
3352
    {
3353
        MSG_DEBUG("Object " << handleToString(obj->handle) << " of type " << objectToString(obj->type) << ". Invalid: " << (obj->invalid ? "YES" : "NO") << ", Pointer: " << (obj->object.widget ? "YES" : "NO"));
3354
 
3355
        if (obj->type == OBJ_SUBVIEW && !obj->invalid && obj->object.area)
3356
        {
3357
            obj->object.area->setHidden(true);
3358
            obj->object.area->setHidden(false);
3359
            obj->object.area->setEnabled(true);
3360
            MSG_DEBUG("Subview refreshed");
3361
        }
3362
        else if (obj->type == OBJ_LIST && !obj->invalid && obj->object.list)
3363
        {
3364
            if (!obj->object.list->isEnabled())
3365
                obj->object.list->setEnabled(true);
3366
        }
3367
        else if (obj->type == OBJ_BUTTON && !obj->invalid && obj->object.label)
3368
        {
3369
            if (!obj->object.label->isEnabled())
3370
                obj->object.label->setEnabled(true);
3371
        }
3372
        else if ((obj->type == OBJ_SUBPAGE || obj->type == OBJ_PAGE) && !obj->invalid && obj->object.widget)
3373
        {
3374
            if (!obj->object.widget->isEnabled())
3375
                obj->object.widget->setEnabled(true);
3376
        }
3377
 
3378
        obj = findNextChild(obj->handle);
3379
    }
3380
}
3381
 
141 andreas 3382
int MainWindow::calcVolume(int value)
3383
{
3384
    DECL_TRACER("TQtSettings::calcVolume(int value)");
3385
 
3386
    // volumeSliderValue is in the range [0..100]
264 andreas 3387
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
141 andreas 3388
    qreal linearVolume = QAudio::convertVolume(value / qreal(100.0),
3389
                                               QAudio::LogarithmicVolumeScale,
3390
                                               QAudio::LinearVolumeScale);
3391
 
3392
    return qRound(linearVolume * 100);
181 andreas 3393
#else
3394
    return value;
3395
#endif
141 andreas 3396
}
197 andreas 3397
 
263 andreas 3398
/**
3399
 * @brief MainWindow::convertMask
3400
 * Converts the AMX mask for input lines into Qt mask sympols for input lines.
3401
 *
3402
 * @param mask  A string containing the AMX mask symbols.
3403
 *
3404
 * @return The converted mask string for Qt input lines.
3405
 */
224 andreas 3406
string MainWindow::convertMask(const string& mask)
3407
{
3408
    DECL_TRACER("MainWindow::convertMask(const string& mask)");
3409
 
3410
    string qMask;
3411
 
3412
    for (size_t i = 0; i < mask.length(); ++i)
3413
    {
3414
        switch (mask[i])
3415
        {
3416
            case '0': qMask += "9"; break;
3417
            case '9': qMask += "0"; break;
3418
            case 'A': qMask += "N"; break;
3419
            case 'a': qMask += "n"; break;
3420
            case 'L': qMask += "X"; break;
3421
            case '?': qMask += "x"; break;
3422
            case '&': qMask += "A"; break;
3423
            case 'C': qMask += "a"; break;
3424
            case '^': qMask += ";"; break;
3425
 
3426
            default:
3427
                qMask += mask[i];
3428
        }
3429
    }
3430
 
3431
    return qMask;
3432
}
3433
 
266 andreas 3434
#ifdef Q_OS_ANDROID
3435
void MainWindow::hideAndroidBars()
3436
{
3437
    DECL_TRACER("MainWindow::hideAndroidBars()");
3438
}
3439
#endif
252 andreas 3440
#ifdef Q_OS_IOS
3441
void MainWindow::setNotch()
3442
{
3443
    DECL_TRACER("MainWindow::setNotch()");
3444
 
264 andreas 3445
    Qt::ScreenOrientation so = getRealOrientation();
3446
 
3447
    if (so == Qt::PrimaryOrientation)
263 andreas 3448
        return;
3449
 
3450
    QMargins margins;
3451
 
264 andreas 3452
    if (mHaveNotchPortrait && (so == Qt::PortraitOrientation || so == Qt::InvertedPortraitOrientation))
263 andreas 3453
        margins = mNotchPortrait;
264 andreas 3454
    else if (mHaveNotchLandscape && (so == Qt::LandscapeOrientation || so == Qt::InvertedLandscapeOrientation))
263 andreas 3455
        margins = mNotchLandscape;
3456
    else
252 andreas 3457
    {
263 andreas 3458
        margins = QASettings::getNotchSize();
3459
 
3460
        if (gPageManager && gPageManager->getSettings()->isPortrait())
3461
        {
264 andreas 3462
            if (so == Qt::LandscapeOrientation)
263 andreas 3463
            {
3464
                int left = margins.left();
3465
                int top = margins.top();
3466
                margins.setTop(margins.right());
3467
                margins.setLeft(top);
3468
                margins.setRight(margins.bottom());
3469
                margins.setBottom(left);
3470
            }
264 andreas 3471
            else if (so == Qt::InvertedLandscapeOrientation)
263 andreas 3472
            {
3473
                int right = margins.right();
3474
                int top = margins.top();
3475
                margins.setTop(margins.left());
3476
                margins.setLeft(top);
3477
                margins.setRight(margins.bottom());
3478
                margins.setBottom(right);
3479
            }
3480
        }
264 andreas 3481
        else if (gPageManager && gPageManager->getSettings()->isLandscape())
263 andreas 3482
        {
264 andreas 3483
            if (so == Qt::PortraitOrientation)
3484
            {
3485
                int top = margins.top();
3486
                int right = margins.right();
3487
                margins.setTop(margins.left());
3488
                margins.setLeft(top);
3489
                margins.setRight(margins.bottom());
3490
                margins.setBottom(right);
3491
            }
3492
            else if (so == Qt::InvertedPortraitOrientation)
3493
            {
3494
                int top = margins.top();
3495
                int left = margins.left();
3496
                margins.setTop(margins.right());
3497
                margins.setLeft(margins.bottom());
3498
                margins.setRight(top);
3499
                margins.setBottom(left);
3500
            }
263 andreas 3501
        }
252 andreas 3502
    }
263 andreas 3503
#ifdef QT_DEBUG
264 andreas 3504
    MSG_DEBUG("Notch top: " << margins.top() << ", bottom: " << margins.bottom() << ", left: " << margins.left() << ", right: " << margins.right() << ", Orientation real: " << orientationToString(so) << ", estimated: " << orientationToString(mOrientation));
263 andreas 3505
#endif
3506
    if (gPageManager)
252 andreas 3507
    {
264 andreas 3508
        // If the real orientation "so" differs from "mOrientation" then
3509
        // "mOrientation" contains the wanted orientation and not the real one!
263 andreas 3510
        if (gPageManager->getSettings()->isPortrait() &&
3511
            (mOrientation == Qt::PortraitOrientation || mOrientation == Qt::InvertedPortraitOrientation))
3512
        {
3513
            mNotchPortrait = margins;
3514
            mHaveNotchPortrait = true;
3515
        }
3516
        else if (gPageManager->getSettings()->isLandscape() &&
3517
            (mOrientation == Qt::LandscapeOrientation || mOrientation == Qt::InvertedLandscapeOrientation))
3518
        {
3519
            mNotchLandscape = margins;
3520
            mHaveNotchLandscape = true;
3521
        }
252 andreas 3522
    }
3523
}
3524
 
3525
/**
3526
 * @brief MainWindow::initGeoLocation
3527
 * This method is only used on IOS to let the application run in the background.
3528
 * It is necessary because it is the only way to let an application run in
3529
 * the background.
3530
 * The method initializes the geo position module of Qt. If the app doesn't
3531
 * have the permissions to retrieve the geo positions, it will not run in the
3532
 * background. It stops at the moment the app is not in front or the display is
3533
 * closed. This makes it stop communicate with the NetLinx and looses the
3534
 * network connection. When the app gets the focus again, it must reconnect to
3535
 * the NetLinx.
3536
 */
3537
void MainWindow::initGeoLocation()
3538
{
3539
    DECL_TRACER("MainWindow::initGeoLocation()");
3540
 
3541
    if (mSource)
3542
        return;
3543
 
3544
    mSource = QGeoPositionInfoSource::createDefaultSource(this);
3545
 
3546
    if (mSource)
3547
    {
3548
        connect(mSource, &QGeoPositionInfoSource::positionUpdated, this, &MainWindow::onPositionUpdated);
3549
        connect(mSource, &QGeoPositionInfoSource::errorOccurred, this, &MainWindow::onErrorOccurred);
3550
    }
3551
    else
3552
    {
3553
        MSG_WARNING("Error creating geo positioning source!");
3554
    }
3555
}
263 andreas 3556
 
264 andreas 3557
#ifdef Q_OS_IOS
3558
Qt::ScreenOrientation MainWindow::getRealOrientation()
3559
{
3560
    DECL_TRACER("MainWindow::getRealOrientation()");
3561
 
3562
    QScreen *screen = QGuiApplication::primaryScreen();
3563
 
3564
    if (!screen)
3565
    {
3566
        MSG_ERROR("Couldn't determine the primary screen!")
3567
        return Qt::PrimaryOrientation;
3568
    }
3569
 
3570
    QRect rect = screen->availableGeometry();
3571
 
3572
    if (rect.width() > rect.height())
3573
        return Qt::LandscapeOrientation;
3574
 
3575
    return Qt::PortraitOrientation;
3576
}
3577
#endif
270 andreas 3578
#endif
264 andreas 3579
 
270 andreas 3580
#if defined(QT_DEBUG) && (defined(Q_OS_IOS) || defined(Q_OS_ANDROID))
264 andreas 3581
string MainWindow::orientationToString(Qt::ScreenOrientation ori)
263 andreas 3582
{
3583
    string sori;
3584
 
3585
    switch(ori)
3586
    {
3587
        case Qt::PortraitOrientation:           sori = "PORTRAIT"; break;
3588
        case Qt::InvertedPortraitOrientation:   sori = "INVERTED PORTRAIT"; break;
3589
        case Qt::LandscapeOrientation:          sori = "LANDSCAPE"; break;
3590
        case Qt::InvertedLandscapeOrientation:  sori = "INVERTED LANDSCAPE"; break;
3591
        default:
3592
            sori = "Unknown: ";
3593
            sori.append(intToString(ori));
3594
    }
3595
 
3596
    return sori;
3597
}
252 andreas 3598
#endif
3599
 
14 andreas 3600
/******************* Draw elements *************************/
3601
 
217 andreas 3602
/**
3603
 * @brief Displays an image.
3604
 * The method is a callback function and is called whenever an image should be
3605
 * displayed. It defines a label, set it to the (scaled) \b width and \b height
3606
 * and moves it to the (scaled) position \b left and \b top.
3607
 *
3608
 * @param handle    The unique handle of the object
3609
 * @param parent    The unique handle of the parent object.
3610
 * @param buffer    A byte array containing the image.
3611
 * @param width     The width of the object
3612
 * @param height    The height of the object
3613
 * @param pixline   The number of pixels in one line of the image.
3614
 * @param left      The prosition from the left.
3615
 * @param top       The position from the top.
3616
 */
298 andreas 3617
void MainWindow::displayButton(ulong handle, ulong parent, TBitmap buffer, int width, int height, int left, int top, bool passthrough)
14 andreas 3618
{
298 andreas 3619
    DECL_TRACER("MainWindow::displayButton(ulong handle, TBitmap buffer, size_t size, int width, int height, int left, int top, bool passthrough)");
4 andreas 3620
 
298 andreas 3621
    TLOCKER(draw_mutex);
107 andreas 3622
 
277 andreas 3623
    TObject::OBJECT_t *obj = findObject(handle);
3624
    TObject::OBJECT_t *par = findObject(parent);
271 andreas 3625
    MSG_TRACE("Processing button " << handleToString(handle) << " from parent " << handleToString(parent));
5 andreas 3626
 
6 andreas 3627
    if (!par)
3628
    {
59 andreas 3629
        if (TStreamError::checkFilter(HLOG_DEBUG))
271 andreas 3630
            MSG_WARNING("Button " << handleToString(handle) << " has no parent (" << handleToString(parent) << ")! Ignoring it.");
59 andreas 3631
 
6 andreas 3632
        return;
3633
    }
3634
 
107 andreas 3635
    if (par->animation && !par->aniDirection)
3636
    {
3637
        if (par->animation->state() == QAbstractAnimation::Running)
3638
        {
271 andreas 3639
            MSG_WARNING("Object " << handleToString(parent) << " is busy with an animation!");
107 andreas 3640
            par->animation->stop();
3641
        }
3642
        else
3643
        {
271 andreas 3644
            MSG_WARNING("Object " << handleToString(parent) << " has not finished the animation!");
107 andreas 3645
        }
3646
 
3647
        return;
3648
    }
3649
    else if (par->remove)
3650
    {
271 andreas 3651
        MSG_WARNING("Object " << handleToString(parent) << " is marked for remove. Will not draw image!");
107 andreas 3652
        return;
3653
    }
3654
 
5 andreas 3655
    if (!obj)
3656
    {
271 andreas 3657
        MSG_DEBUG("Adding new object " << handleToString(handle) << " ...");
296 andreas 3658
        OBJECT_t nobj;
5 andreas 3659
 
296 andreas 3660
        nobj.type = TObject::OBJ_BUTTON;
3661
        nobj.handle = handle;
5 andreas 3662
 
198 andreas 3663
        if (gPageManager->isSetupActive())
3664
        {
296 andreas 3665
            nobj.width = scaleSetup(width);
3666
            nobj.height = scaleSetup(height);
3667
            nobj.left = scaleSetup(left);
3668
            nobj.top = scaleSetup(top);
198 andreas 3669
        }
3670
        else
3671
        {
296 andreas 3672
            nobj.width = scale(width);
3673
            nobj.height = scale(height);
3674
            nobj.left = scale(left);
3675
            nobj.top = scale(top);
198 andreas 3676
        }
3677
 
296 andreas 3678
        nobj.object.label = new QLabel("", par->object.widget);
3679
        nobj.object.label->setObjectName(QString("Label_") + handleToString(handle).c_str());
323 andreas 3680
 
3681
        if (mGestureFilter)
3682
        {
3683
            nobj.object.label->installEventFilter(mGestureFilter);
3684
            nobj.object.label->grabGesture(Qt::PinchGesture);
3685
            nobj.object.label->grabGesture(Qt::SwipeGesture);
3686
        }
3687
 
296 andreas 3688
        nobj.object.label->move(nobj.left, nobj.top);
3689
        nobj.object.label->setFixedSize(nobj.width, nobj.height);
3690
 
298 andreas 3691
        if (passthrough)
3692
            nobj.object.label->setAttribute(Qt::WA_TransparentForMouseEvents);
3693
 
296 andreas 3694
        if (!addObject(nobj))
3695
        {
3696
            MSG_ERROR("Unable to add the new object " << handleToString(handle) << "!");
3697
            return;
3698
        }
3699
 
3700
        obj = findObject(handle);
6 andreas 3701
    }
14 andreas 3702
    else
297 andreas 3703
    {
271 andreas 3704
        MSG_DEBUG("Object " << handleToString(handle) << " of type " << TObject::objectToString(obj->type) << " found!");
5 andreas 3705
 
298 andreas 3706
        if (passthrough && obj->object.label)
3707
            obj->object.label->setAttribute(Qt::WA_TransparentForMouseEvents);
3708
 
297 andreas 3709
        if (!enableObject(handle))
3710
        {
3711
            MSG_ERROR("Object " << handleToString(handle) << " of type " << objectToString(obj->type) << " couldn't be enabled!");
3712
            return;
3713
        }
3714
    }
3715
 
187 andreas 3716
    if (obj->type != TObject::OBJ_INPUT)
6 andreas 3717
    {
187 andreas 3718
        try
75 andreas 3719
        {
289 andreas 3720
            if (buffer.getSize() > 0 && buffer.getPixline() > 0)
107 andreas 3721
            {
271 andreas 3722
                MSG_DEBUG("Setting image for " << handleToString(handle) << " ...");
289 andreas 3723
                QPixmap pixmap = scaleImage((unsigned char *)buffer.getBitmap(), buffer.getWidth(), buffer.getHeight(), buffer.getPixline());
107 andreas 3724
 
187 andreas 3725
                if (obj->object.label)
3726
                    obj->object.label->setPixmap(pixmap);
3727
                else
3728
                {
271 andreas 3729
                    MSG_WARNING("Object " << handleToString(handle) << " does not exist any more!");
187 andreas 3730
                }
107 andreas 3731
            }
75 andreas 3732
        }
187 andreas 3733
        catch(std::exception& e)
3734
        {
271 andreas 3735
            MSG_ERROR("Error drawing button " << handleToString(handle) << ": " << e.what());
187 andreas 3736
        }
3737
        catch(...)
3738
        {
3739
            MSG_ERROR("Unexpected exception occured [MainWindow::displayButton()]");
3740
        }
5 andreas 3741
    }
4 andreas 3742
}
3743
 
289 andreas 3744
void MainWindow::displayViewButton(ulong handle, ulong parent, bool vertical, TBitmap buffer, int width, int height, int left, int top, int space, TColor::COLOR_T fillColor)
279 andreas 3745
{
289 andreas 3746
    DECL_TRACER("MainWindow::displayViewButton(ulong handle, TBitmap buffer, size_t size, int width, int height, int left, int top)");
279 andreas 3747
 
292 andreas 3748
    TLOCKER(draw_mutex);
279 andreas 3749
 
3750
    TObject::OBJECT_t *obj = findObject(handle);
3751
    TObject::OBJECT_t *par = findObject(parent);
3752
    MSG_TRACE("Processing button " << handleToString(handle) << " from parent " << handleToString(parent));
3753
 
3754
    if (!par)
3755
    {
3756
        if (TStreamError::checkFilter(HLOG_DEBUG))
3757
            MSG_WARNING("Button " << handleToString(handle) << " has no parent (" << handleToString(parent) << ")! Ignoring it.");
3758
 
3759
        return;
3760
    }
3761
 
3762
    if (par->animation && !par->aniDirection)
3763
    {
3764
        if (par->animation->state() == QAbstractAnimation::Running)
3765
        {
3766
            MSG_WARNING("Object " << handleToString(parent) << " is busy with an animation!");
3767
            par->animation->stop();
3768
        }
3769
        else
3770
        {
3771
            MSG_WARNING("Object " << handleToString(parent) << " has not finished the animation!");
3772
        }
3773
 
3774
        return;
3775
    }
3776
    else if (par->remove)
3777
    {
3778
        MSG_WARNING("Object " << handleToString(parent) << " is marked for remove. Will not draw image!");
3779
        return;
3780
    }
3781
 
3782
    if (!obj)
3783
    {
3784
        MSG_DEBUG("Adding new object " << handleToString(handle) << " ...");
296 andreas 3785
        OBJECT_t nobj;
279 andreas 3786
 
296 andreas 3787
        nobj.type = OBJ_SUBVIEW;
3788
        nobj.handle = handle;
3789
 
3790
        nobj.width = scale(width);
3791
        nobj.height = scale(height);
3792
        nobj.left = scale(left);
3793
        nobj.top = scale(top);
3794
 
3795
        nobj.object.area = new TQScrollArea(par->object.widget, nobj.width, nobj.height, vertical);
3796
        nobj.object.area->setObjectName(QString("View_") + handleToString(handle).c_str());
3797
        nobj.object.area->setScaleFactor(mScaleFactor);
3798
        nobj.object.area->setSpace(space);
3799
        nobj.object.area->move(nobj.left, nobj.top);
321 andreas 3800
        nobj.connected = true;
296 andreas 3801
        connect(nobj.object.area, &TQScrollArea::objectClicked, this, &MainWindow::onSubViewItemClicked);
3802
 
3803
        if (!addObject(nobj))
279 andreas 3804
        {
296 andreas 3805
            MSG_ERROR("Couldn't add the object " << handleToString(handle) << "!");
279 andreas 3806
            return;
3807
        }
3808
 
296 andreas 3809
        obj = findObject(handle);
279 andreas 3810
    }
3811
    else if (obj->type != OBJ_SUBVIEW)
3812
    {
3813
        MSG_ERROR("Object " << handleToString(handle) << " is of wrong type " << objectToString(obj->type) << "!");
3814
        return;
3815
    }
3816
    else
297 andreas 3817
    {
279 andreas 3818
        MSG_DEBUG("Object " << handleToString(handle) << " of type " << TObject::objectToString(obj->type) << " found!");
3819
 
321 andreas 3820
        if (obj->object.area && !obj->connected)
297 andreas 3821
            reconnectArea(obj->object.area);
3822
    }
3823
 
279 andreas 3824
    try
3825
    {
289 andreas 3826
        // Set background color
286 andreas 3827
        if (obj->object.area)
289 andreas 3828
        {
297 andreas 3829
            QColor color;
3830
 
3831
            if (fillColor.alpha == 0)
3832
                color = Qt::transparent;
3833
            else
3834
                color = qRgba(fillColor.red, fillColor.green, fillColor.blue, fillColor.alpha);
3835
 
289 andreas 3836
            obj->object.area->setBackGroundColor(color);
3837
        }
286 andreas 3838
 
289 andreas 3839
        if (buffer.getSize() > 0 && buffer.getPixline() > 0)
279 andreas 3840
        {
3841
            MSG_DEBUG("Setting image for " << handleToString(handle) << " ...");
289 andreas 3842
            QPixmap pixmap = scaleImage((unsigned char *)buffer.getBitmap(), buffer.getWidth(), buffer.getHeight(), buffer.getPixline());
279 andreas 3843
 
285 andreas 3844
            if (pixmap.isNull())
279 andreas 3845
            {
3846
                MSG_ERROR("Unable to create a pixmap out of an image!");
3847
                return;
3848
            }
3849
 
285 andreas 3850
            if (obj->object.area)
279 andreas 3851
            {
285 andreas 3852
                obj->object.area->setBackgroundImage(pixmap);
279 andreas 3853
            }
3854
            else
3855
            {
3856
                MSG_WARNING("Object " << handleToString(handle) << " does not exist any more!");
3857
            }
3858
        }
3859
    }
3860
    catch(std::exception& e)
3861
    {
3862
        MSG_ERROR("Error drawing button " << handleToString(handle) << ": " << e.what());
3863
    }
3864
    catch(...)
3865
    {
3866
        MSG_ERROR("Unexpected exception occured [MainWindow::displayViewButton()]");
3867
    }
3868
}
3869
 
285 andreas 3870
void MainWindow::addViewButtonItems(ulong parent, vector<PGSUBVIEWITEM_T> items)
279 andreas 3871
{
285 andreas 3872
    DECL_TRACER("MainWindow::addViewButtonItems(ulong parent, vector<PGSUBVIEWITEM_T> items)");
279 andreas 3873
 
285 andreas 3874
    if (items.empty())
3875
        return;
279 andreas 3876
 
285 andreas 3877
    OBJECT_t *par = findObject(parent);
279 andreas 3878
 
285 andreas 3879
    if (!par || par->type != OBJ_SUBVIEW || !par->object.area)
279 andreas 3880
    {
285 andreas 3881
        MSG_ERROR("No object with handle " << handleToString(parent) << " found or object is not a subview list!");
279 andreas 3882
        return;
3883
    }
3884
 
297 andreas 3885
    if (par->invalid)
3886
    {
3887
        if (!enableObject(parent))
3888
        {
3889
            MSG_ERROR("Object " << handleToString(parent) << " of type " << objectToString(par->type) << " couldn't be enabled!");
3890
            return;
3891
        }
3892
    }
3893
 
300 andreas 3894
    if (!items.empty())
3895
    {
3896
        par->object.area->setScrollbar(items[0].scrollbar);
3897
        par->object.area->setScrollbarOffset(items[0].scrollbarOffset);
3898
        par->object.area->setAnchor(items[0].position);
3899
    }
3900
 
285 andreas 3901
    par->object.area->addItems(items);
280 andreas 3902
}
3903
 
300 andreas 3904
void MainWindow::updateViewButton(ulong handle, ulong parent, TBitmap buffer, TColor::COLOR_T fillColor)
3905
{
3906
    DECL_TRACER("MainWindow::updateViewButton(ulong handle, ulong parent, TBitmap buffer, TColor::COLOR_T fillColor)");
3907
 
3908
    OBJECT_t *par = findObject(parent);
3909
 
3910
    if (!par || par->type != OBJ_SUBVIEW || !par->object.area)
3911
    {
3912
        MSG_ERROR("No object with handle " << handleToString(parent) << " found for update or object is not a subview list!");
3913
        return;
3914
    }
3915
 
3916
    PGSUBVIEWITEM_T item;
3917
    item.handle = handle;
3918
    item.parent = parent;
3919
    item.image = buffer;
3920
    item.bgcolor = fillColor;
3921
    par->object.area->updateItem(item);
3922
}
3923
 
3924
void MainWindow::updateViewButtonItem(PGSUBVIEWITEM_T& item, ulong parent)
3925
{
3926
    DECL_TRACER("MainWindow::updateViewButtonItem(PGSUBVIEWITEM_T& item, ulong parent)");
3927
 
3928
    OBJECT_t *par = findObject(parent);
3929
 
3930
    if (!par || par->type != OBJ_SUBVIEW || !par->object.area)
3931
    {
3932
        MSG_ERROR("No object with handle " << handleToString(parent) << " found for update or object is not a subview list!");
3933
        return;
3934
    }
3935
 
3936
    par->object.area->updateItem(item);
3937
}
3938
 
3939
void MainWindow::showViewButtonItem(ulong handle, ulong parent, int position, int timer)
3940
{
3941
    DECL_TRACER("MainWindow::showViewButtonItem(ulong handle, ulong parent, int position, int timer)");
3942
 
3943
    Q_UNUSED(timer);
3944
 
3945
    OBJECT_t *par = findObject(parent);
3946
 
3947
    if (!par || par->type != OBJ_SUBVIEW || !par->object.area)
3948
    {
3949
        MSG_ERROR("No object with handle " << handleToString(parent) << " found for update or object is not a subview list!");
3950
        return;
3951
    }
3952
 
3953
    par->object.area->showItem(handle, position);
3954
}
3955
 
318 andreas 3956
void MainWindow::toggleViewButtonItem(ulong handle, ulong parent, int position, int timer)
3957
{
3958
    DECL_TRACER("MainWindow::toggleViewButtonItem(ulong handle, ulong parent, int position, int timer)");
3959
 
3960
    Q_UNUSED(timer);
3961
 
3962
    OBJECT_t *par = findObject(parent);
3963
 
3964
    if (!par || par->type != OBJ_SUBVIEW || !par->object.area)
3965
    {
3966
        MSG_ERROR("No object with handle " << handleToString(parent) << " found for update or object is not a subview list!");
3967
        return;
3968
    }
3969
 
3970
    par->object.area->showItem(handle, position);
3971
}
3972
 
3973
void MainWindow::hideAllViewItems(ulong handle)
3974
{
3975
    DECL_TRACER("MainWindow::hideAllViewItems(ulong handle)");
3976
 
3977
    OBJECT_t *obj = findObject(handle);
3978
 
3979
    if (!obj || obj->type != OBJ_SUBVIEW || !obj->object.area)
3980
        return;
3981
 
3982
    obj->object.area->hideAllItems();
3983
}
3984
 
3985
void MainWindow::hideViewItem(ulong handle, ulong parent)
3986
{
3987
    DECL_TRACER("MainWindow::hideViewItem(ulong handle, ulong parent)");
3988
 
3989
    OBJECT_t *obj = findObject(parent);
3990
 
3991
    if (!obj || obj->type != OBJ_SUBVIEW || !obj->object.area)
3992
        return;
3993
 
3994
    obj->object.area->hideItem(handle);
3995
}
3996
 
98 andreas 3997
void MainWindow::SetVisible(ulong handle, bool state)
3998
{
3999
    DECL_TRACER("MainWindow::SetVisible(ulong handle, bool state)");
4000
 
318 andreas 4001
    OBJECT_t *obj = findObject(handle);
98 andreas 4002
 
4003
    if (!obj)
4004
    {
271 andreas 4005
        MSG_ERROR("Object " << handleToString(handle) << " not found!");
98 andreas 4006
        return;
4007
    }
4008
 
318 andreas 4009
    if (obj->type == OBJ_BUTTON && obj->object.label)
99 andreas 4010
    {
98 andreas 4011
        obj->object.label->setVisible(state);
297 andreas 4012
        obj->invalid = false;
4013
        obj->remove = false;
99 andreas 4014
    }
318 andreas 4015
    else if (obj->type == OBJ_SUBVIEW && obj->object.area)
4016
    {
4017
        obj->object.area->setVisible(state);
4018
        obj->invalid = false;
4019
        obj->remove = false;
4020
    }
99 andreas 4021
    else
4022
    {
271 andreas 4023
        MSG_DEBUG("Ignoring non button object " << handleToString(handle));
99 andreas 4024
    }
98 andreas 4025
}
4026
 
318 andreas 4027
void MainWindow::setSubViewPadding(ulong handle, int padding)
4028
{
4029
    DECL_TRACER("MainWindow::setSubViewPadding(ulong handle, int padding)");
4030
 
4031
    OBJECT_t *obj = findObject(handle);
4032
 
4033
    if (!obj)
4034
    {
4035
        MSG_ERROR("Object " << handleToString(handle) << " not found!");
4036
        return;
4037
    }
4038
 
4039
    if (obj->type != OBJ_SUBVIEW || !obj->object.area)
4040
        return;
4041
 
4042
    obj->object.area->setSpace(padding);
4043
}
4044
 
215 andreas 4045
/**
217 andreas 4046
 * @brief Prepares a new object.
215 andreas 4047
 * The method first checks whether there exists a background widget or not. If
4048
 * not it creates a background widget with a black background. On Android this
4049
 * image is the size of the whole screen while on a desktop it is only the size
4050
 * of a page plus the task bar, if any.
217 andreas 4051
 * If the background image (centralWidget()) already exists, it set's only the
4052
 * credentials of the object.
4053
 * It makes sure that all child objects of the central widget are destroyed.
215 andreas 4054
 *
4055
 * @param handle    The handle of the new widget
4056
 * @param width     The original width of the page
4057
 * @param heoght    The original height of the page
4058
 */
5 andreas 4059
void MainWindow::setPage(ulong handle, int width, int height)
4060
{
4061
    DECL_TRACER("MainWindow::setPage(ulong handle, int width, int height)");
4 andreas 4062
 
277 andreas 4063
    if (handle == mActualPageHandle)
4064
        return;
4065
 
292 andreas 4066
    TLOCKER(draw_mutex);
277 andreas 4067
    QWidget *wBackground = centralWidget();
4068
 
4069
    if (!wBackground)
107 andreas 4070
    {
277 andreas 4071
        MSG_ERROR("No central widget!");
107 andreas 4072
        return;
4073
    }
4074
 
277 andreas 4075
    if (!mCentralWidget)
4076
    {
4077
        MSG_ERROR("Stack for pages not initialized!");
215 andreas 4078
        return;
277 andreas 4079
    }
215 andreas 4080
 
4081
    // The following should be true only for the first time this method is called.
277 andreas 4082
    if (!mCentralInitialized)
215 andreas 4083
    {
4084
        QSize qs = menuBar()->sizeHint();
198 andreas 4085
 
215 andreas 4086
        if (gPageManager && gPageManager->isSetupActive())
4087
            setMinimumSize(scaleSetup(width), scaleSetup(height) + qs.height());
4088
        else
4089
            setMinimumSize(scale(width), scale(height) + qs.height());
265 andreas 4090
 
4091
        mCentralInitialized = true;
215 andreas 4092
    }
198 andreas 4093
 
296 andreas 4094
    OBJECT_t *obj = findObject(handle);
5 andreas 4095
 
4096
    if (!obj)
4097
    {
271 andreas 4098
        MSG_DEBUG("Adding new object " << handleToString(handle));
296 andreas 4099
        OBJECT_t nobj;
5 andreas 4100
 
296 andreas 4101
        nobj.handle = handle;
4102
        nobj.type = OBJ_PAGE;
4103
        nobj.object.widget = nullptr;
5 andreas 4104
 
217 andreas 4105
        if (gPageManager && gPageManager->isSetupActive())
4106
        {
296 andreas 4107
            nobj.height = scaleSetup(height);
4108
            nobj.width = scaleSetup(width);
217 andreas 4109
        }
4110
        else
4111
        {
296 andreas 4112
            nobj.height = scale(height);
4113
            nobj.width = scale(width);
217 andreas 4114
        }
296 andreas 4115
 
4116
        if (!addObject(nobj))
4117
        {
4118
            MSG_ERROR("Error crating an object for handle " << handleToString(handle));
4119
            return;
4120
        }
4121
 
4122
        obj = findObject(handle);
5 andreas 4123
    }
296 andreas 4124
    else
271 andreas 4125
    {
296 andreas 4126
        if (obj->type != OBJ_PAGE)
4127
        {
4128
            MSG_WARNING("Object " << handleToString(handle) << " is not a page! Will not reuse it as a page.");
4129
            return;
4130
        }
4131
 
4132
        if (obj->object.widget && obj->object.widget->isHidden() && mCentralWidget->indexOf(obj->object.widget) >= 0)
271 andreas 4133
            obj->object.widget->setParent(wBackground);
220 andreas 4134
 
277 andreas 4135
        obj->invalid = false;
296 andreas 4136
        obj->remove = false;
277 andreas 4137
        MSG_DEBUG("Hidden object " << handleToString(handle) << " was reactivated.");
217 andreas 4138
    }
227 andreas 4139
 
277 andreas 4140
    if (!obj->object.widget)
264 andreas 4141
    {
277 andreas 4142
        obj->object.widget = new QWidget;
271 andreas 4143
        obj->object.widget->setObjectName(QString("Page_") + handleToString(handle).c_str());
323 andreas 4144
 
4145
        if (mGestureFilter)
4146
        {
4147
            obj->object.widget->installEventFilter(mGestureFilter);
4148
            obj->object.widget->grabGesture(Qt::PinchGesture);
4149
            obj->object.widget->grabGesture(Qt::SwipeGesture);
4150
        }
4151
 
277 andreas 4152
        obj->object.widget->setAutoFillBackground(true);
271 andreas 4153
        obj->invalid = false;
275 andreas 4154
        obj->object.widget->move(0, 0);
266 andreas 4155
#if defined(Q_OS_IOS) || defined(Q_OS_ANDROID)
275 andreas 4156
        obj->object.widget->setFixedSize(obj->width, obj->height);
266 andreas 4157
#else
4158
        obj->object.widget->setGeometry(geometry());
4159
#endif
277 andreas 4160
        mCentralWidget->addWidget(obj->object.widget);
264 andreas 4161
    }
4162
 
213 andreas 4163
    mActualPageHandle = handle;
271 andreas 4164
    MSG_PROTOCOL("Current page: " << handleToString(handle));
5 andreas 4165
}
4166
 
217 andreas 4167
void MainWindow::setSubPage(ulong handle, ulong parent, int left, int top, int width, int height, ANIMATION_t animate)
5 andreas 4168
{
4169
    DECL_TRACER("MainWindow::setSubPage(ulong handle, int left, int top, int width, int height)");
38 andreas 4170
 
296 andreas 4171
    TLOCKER(draw_mutex);
4172
    OBJECT_t *par = findObject(parent);
107 andreas 4173
 
296 andreas 4174
    if (!par || par->type != OBJ_PAGE)
38 andreas 4175
    {
264 andreas 4176
        if (!par)
4177
        {
271 andreas 4178
            MSG_ERROR("Subpage " << handleToString(handle) << " has no parent! Ignoring it.");
264 andreas 4179
        }
4180
        else
4181
        {
271 andreas 4182
            MSG_ERROR("Subpage " << handleToString(handle) << " has invalid parent " << handleToString(parent) << " which is no page! Ignoring it.");
264 andreas 4183
        }
4184
 
217 andreas 4185
        return;
38 andreas 4186
    }
4187
 
278 andreas 4188
    if (!par->object.widget)
4189
    {
297 andreas 4190
        MSG_ERROR("Parent page " << handleToString(parent) << " has no widget defined!");
278 andreas 4191
        return;
4192
    }
4193
 
4194
    if (mCentralWidget && mCentralWidget->currentWidget() != par->object.widget)
4195
    {
4196
        MSG_WARNING("The parent page " << handleToString(parent) << " is not the current page " << handleToString(handle) << "!");
4197
        return;
4198
    }
4199
 
296 andreas 4200
    OBJECT_t *obj = findObject(handle);
4201
    OBJECT_t nobj;
4202
    bool shouldAdd = false;
272 andreas 4203
 
296 andreas 4204
    if (obj && obj->type != OBJ_SUBPAGE)
271 andreas 4205
    {
4206
        MSG_WARNING("Object " << handleToString(handle) << " exists but is not a subpage! Refusing to create a new page with this handle.");
4207
        return;
4208
    }
4209
    else if (!obj)
5 andreas 4210
    {
296 andreas 4211
        obj = &nobj;
4212
        shouldAdd = true;
5 andreas 4213
    }
297 andreas 4214
    else
4215
    {
4216
        obj->invalid = false;
4217
        obj->remove = false;
4218
    }
5 andreas 4219
 
296 andreas 4220
    int scLeft = 0;
4221
    int scTop = 0;
4222
    int scWidth = 0;
4223
    int scHeight = 0;
38 andreas 4224
 
198 andreas 4225
    if (gPageManager && gPageManager->isSetupActive())
4226
    {
4227
        scLeft = scaleSetup(left);
4228
        scTop = scaleSetup(top);
4229
        scWidth = scaleSetup(width);
4230
        scHeight = scaleSetup(height);
4231
    }
4232
    else
4233
    {
4234
        scLeft = scale(left);
4235
        scTop = scale(top);
4236
        scWidth = scale(width);
4237
        scHeight = scale(height);
4238
    }
4239
 
296 andreas 4240
    obj->type = OBJ_SUBPAGE;
5 andreas 4241
    obj->handle = handle;
271 andreas 4242
 
4243
    if (!obj->object.widget)
278 andreas 4244
    {
4245
        obj->object.widget = new QWidget(par->object.widget);
4246
        obj->object.widget->setObjectName(QString("Subpage_%1").arg(handleToString(handle).c_str()));
4247
    }
271 andreas 4248
    else
278 andreas 4249
        obj->object.widget->setParent(par->object.widget);
271 andreas 4250
 
6 andreas 4251
    obj->object.widget->setAutoFillBackground(true);
275 andreas 4252
    obj->object.widget->move(scLeft, scTop);
38 andreas 4253
    obj->object.widget->setFixedSize(scWidth, scHeight);
4254
    obj->left = scLeft;
4255
    obj->top = scTop;
4256
    obj->width = scWidth;
4257
    obj->height = scHeight;
271 andreas 4258
    obj->invalid = false;
296 andreas 4259
    obj->remove = false;
15 andreas 4260
    // filter move event
323 andreas 4261
    if (mGestureFilter)
4262
    {
4263
        obj->object.widget->installEventFilter(mGestureFilter);
4264
        obj->object.widget->grabGesture(Qt::PinchGesture);
4265
        obj->object.widget->grabGesture(Qt::SwipeGesture);
4266
    }
4267
 
107 andreas 4268
    obj->aniDirection = true;
277 andreas 4269
    obj->animate = animate;
296 andreas 4270
 
4271
    if (shouldAdd)
4272
    {
4273
        if (!addObject(nobj))
4274
        {
4275
            MSG_ERROR("Couldn't add the object " << handleToString(handle) << "!");
4276
            nobj.object.widget->close();
4277
        }
4278
    }
5 andreas 4279
}
4280
 
265 andreas 4281
#ifdef _OPAQUE_SKIA_
289 andreas 4282
void MainWindow::setBackground(ulong handle, TBitmap image, int width, int height, ulong color)
262 andreas 4283
#else
289 andreas 4284
void MainWindow::setBackground(ulong handle, TBitmap image, int width, int height, ulong color, int opacity)
262 andreas 4285
#endif
5 andreas 4286
{
292 andreas 4287
    TLOCKER(draw_mutex);
289 andreas 4288
    DECL_TRACER("MainWindow::setBackground(ulong handle, TBitmap image, ulong color [, int opacity])");
5 andreas 4289
 
277 andreas 4290
    if (!mCentralWidget)
107 andreas 4291
    {
277 andreas 4292
        MSG_ERROR("The internal page stack is not initialized!");
107 andreas 4293
        return;
4294
    }
5 andreas 4295
 
296 andreas 4296
    OBJECT_t *obj = findObject(handle);
107 andreas 4297
 
296 andreas 4298
    if (!obj || obj->remove)
5 andreas 4299
    {
271 andreas 4300
#ifdef QT_DEBUG
296 andreas 4301
        MSG_WARNING("No object " << handleToString(handle) << " found! (Flag remove: " << (obj->remove ? "TRUE" : "FALSE") << ")");
271 andreas 4302
#else
4303
        MSG_WARNING("No object " << handleToString(handle) << " found!");
4304
#endif
5 andreas 4305
        return;
4306
    }
296 andreas 4307
    else if (obj->invalid)
297 andreas 4308
    {
4309
        if (!enableObject(handle))
4310
        {
4311
            MSG_ERROR("Object " << handleToString(handle) << " of type " << objectToString(obj->type) << " couldn't be anabled!");
4312
            return;
4313
        }
4314
    }
5 andreas 4315
 
297 andreas 4316
    if (obj->type != OBJ_SUBPAGE && obj->type != OBJ_BUTTON && obj->type != OBJ_PAGE)
4317
    {
4318
        MSG_ERROR("Method does not support object type " << objectToString(obj->type) << " for object " << handleToString(handle) << "!");
4319
        return;
4320
    }
4321
 
277 andreas 4322
    MSG_DEBUG("Object " << handleToString(handle) << " of type " << objectToString(obj->type) << " found!");
5 andreas 4323
 
296 andreas 4324
    if (obj->type == OBJ_BUTTON || obj->type == OBJ_SUBPAGE)
5 andreas 4325
    {
277 andreas 4326
        MSG_DEBUG("Processing object " << objectToString(obj->type));
198 andreas 4327
 
296 andreas 4328
        if (obj->type == OBJ_BUTTON && !obj->object.label)
198 andreas 4329
        {
271 andreas 4330
            MSG_ERROR("The label of the object " << handleToString(handle) << " was not initialized!");
198 andreas 4331
            return;
4332
        }
296 andreas 4333
        else if (obj->type == OBJ_SUBPAGE && !obj->object.widget)
198 andreas 4334
        {
271 andreas 4335
            MSG_ERROR("The widget of the object " << handleToString(handle) << " was not initialized!");
198 andreas 4336
            return;
4337
        }
4338
 
6 andreas 4339
        QPixmap pix(obj->width, obj->height);
5 andreas 4340
 
291 andreas 4341
        if (TColor::getAlpha(color) == 0)
4342
            pix.fill(Qt::transparent);
4343
        else
4344
            pix.fill(QColor::fromRgba(qRgba(TColor::getRed(color),TColor::getGreen(color),TColor::getBlue(color),TColor::getAlpha(color))));
4345
 
289 andreas 4346
        if (image.isValid() > 0)
5 andreas 4347
        {
289 andreas 4348
            MSG_DEBUG("Setting image of size " << image.getSize() << " (" << image.getWidth() << " x " << image.getHeight() << ")");
4349
            QImage img(image.getBitmap(), image.getWidth(), image.getHeight(), image.getPixline(), QImage::Format_ARGB32);
38 andreas 4350
 
198 andreas 4351
            if (isScaled() || (gPageManager && gPageManager->isSetupActive()))
38 andreas 4352
            {
4353
                QSize size(obj->width, obj->height);
4354
                pix.convertFromImage(img.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
4355
            }
4356
            else
4357
                pix.convertFromImage(img);
6 andreas 4358
        }
4359
 
107 andreas 4360
        if (obj->type == TObject::OBJ_BUTTON)
5 andreas 4361
            obj->object.label->setPixmap(pix);
6 andreas 4362
        else
5 andreas 4363
        {
271 andreas 4364
            MSG_DEBUG("Setting image as background for subpage " << handleToString(handle));
296 andreas 4365
            QPalette palette(obj->object.widget->palette());
262 andreas 4366
#ifndef _OPAQUE_SKIA_
4367
            qreal oo;
4368
 
4369
            if (opacity < 0)
4370
                oo = 0.0;
4371
            else if (opacity > 255)
4372
                oo = 1.0;
4373
            else
4374
                oo = 1.0 / 255.0 * (qreal)opacity;
4375
 
4376
            if (oo < 1.0)
4377
            {
272 andreas 4378
                QPixmap image(pix.size());      //Image with given size and format.
4379
                image.fill(Qt::transparent);    //fills with transparent
262 andreas 4380
                QPainter p(&image);
272 andreas 4381
                p.setOpacity(oo);               // set opacity from 0.0 to 1.0, where 0.0 is fully transparent and 1.0 is fully opaque.
4382
                p.drawPixmap(0, 0, pix);        // given pixmap into the paint device.
278 andreas 4383
                p.end();
277 andreas 4384
                palette.setBrush(QPalette::Window, QBrush(image));
262 andreas 4385
                MSG_DEBUG("Opacity was set to " << oo);
4386
            }
277 andreas 4387
            else
4388
                palette.setBrush(QPalette::Window, QBrush(pix));
4389
#else
4390
            palette.setBrush(QPalette::Window, QBrush(pix));
262 andreas 4391
#endif
198 andreas 4392
            obj->object.widget->setPalette(palette);
5 andreas 4393
        }
4394
    }
107 andreas 4395
    else if (obj->type == TObject::OBJ_PAGE)
5 andreas 4396
    {
297 andreas 4397
        MSG_DEBUG("Processing object of type PAGE ...");
277 andreas 4398
        QWidget *central = obj->object.widget;
222 andreas 4399
 
265 andreas 4400
        if (!central)
5 andreas 4401
        {
271 andreas 4402
            MSG_ERROR("There is no page widget initialized for page " << handleToString(handle));
215 andreas 4403
            displayMessage("Can't set a background without an active page!", "Internal error");
4404
            return;
5 andreas 4405
        }
264 andreas 4406
 
277 andreas 4407
        QWidget *current = mCentralWidget->currentWidget();
272 andreas 4408
        int index = -1;
4409
 
4410
        if (current && central != current)
264 andreas 4411
        {
272 andreas 4412
            if ((index = mCentralWidget->indexOf(central)) < 0)
4413
            {
277 andreas 4414
                QString obName = QString("Page_%1").arg(handleToString(handle).c_str());
4415
 
4416
                for (int i = 0; i < mCentralWidget->count(); ++i)
4417
                {
4418
                    QWidget *w = mCentralWidget->widget(i);
4419
                    MSG_DEBUG("Checking widget " << w->objectName().toStdString());
4420
 
4421
                    if (w->objectName() == obName)
4422
                    {
4423
                        index = i;
4424
                        break;
4425
                    }
4426
                }
4427
 
4428
                if (index < 0)
4429
                {
291 andreas 4430
                    MSG_WARNING("Missing page " << handleToString(handle) << " on stack! Will add it to the stack.");
277 andreas 4431
                    index = mCentralWidget->addWidget(central);
4432
                    MSG_DEBUG("Number pages on stack: " << mCentralWidget->count());
4433
                    QRect geomMain = geometry();
4434
                    QRect geomCent = mCentralWidget->geometry();
4435
                    MSG_DEBUG("Geometry MainWindow: left: " << geomMain.left() << ", right: " << geomMain.right() << ", top: " << geomMain.top() << ", bottom: " << geomMain.bottom());
4436
                    MSG_DEBUG("Geometry CentWindow: left: " << geomCent.left() << ", right: " << geomCent.right() << ", top: " << geomCent.top() << ", bottom: " << geomCent.bottom());
4437
                }
272 andreas 4438
            }
264 andreas 4439
        }
277 andreas 4440
        else
272 andreas 4441
            index = mCentralWidget->indexOf(central);
4442
 
6 andreas 4443
        QPixmap pix(obj->width, obj->height);
291 andreas 4444
        QColor backgroundColor;
4445
 
4446
        if (TColor::getAlpha(color) == 0)
4447
            backgroundColor = Qt::transparent;
4448
        else
4449
            backgroundColor = QColor::fromRgba(qRgba(TColor::getRed(color),TColor::getGreen(color),TColor::getBlue(color),TColor::getAlpha(color)));
4450
 
221 andreas 4451
        pix.fill(backgroundColor);
265 andreas 4452
        MSG_DEBUG("Filled background of size " << pix.width() << "x" << pix.height() << " with color #" << std::setfill('0') << std::setw(8) << std::hex << color);
6 andreas 4453
 
289 andreas 4454
        if (width > 0 && image.isValid())
5 andreas 4455
        {
289 andreas 4456
            QImage img(image.getBitmap(), image.getWidth(), image.getHeight(), image.getPixline(), QImage::Format_ARGB32);
221 andreas 4457
            bool valid = false;
38 andreas 4458
 
222 andreas 4459
            if (!img.isNull())
4460
            {
4461
                if (isScaled())
4462
                {
296 andreas 4463
                    QImage bgImage = img.scaled(obj->width, obj->height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
223 andreas 4464
                    valid = pix.convertFromImage(bgImage);
277 andreas 4465
                    MSG_DEBUG("Scaled image from " << width << "x" << height << " to " << obj->width << "x" << obj->height);
222 andreas 4466
                }
4467
                else
4468
                {
4469
                    valid = pix.convertFromImage(img);
277 andreas 4470
                    MSG_DEBUG("Converted image to pixmap.");
222 andreas 4471
                }
4472
            }
221 andreas 4473
 
4474
            if (!valid || pix.isNull())
4475
            {
222 andreas 4476
                if (pix.isNull())
4477
                    pix = QPixmap(obj->width, obj->height);
4478
 
221 andreas 4479
                pix.fill(backgroundColor);
289 andreas 4480
                MSG_WARNING("Error converting an image! Size raw data: " << image.getSize() << ", Width: " << image.getWidth() << ", Height: " << image.getHeight() << ", Bytes per row: " << image.getPixline());
221 andreas 4481
            }
6 andreas 4482
        }
5 andreas 4483
 
223 andreas 4484
        QPalette palette(central->palette());
222 andreas 4485
        palette.setBrush(QPalette::Window, QBrush(pix));
4486
        central->setPalette(palette);
6 andreas 4487
 
272 andreas 4488
        if (index >= 0)
4489
            mCentralWidget->setCurrentIndex(index);
275 andreas 4490
        else if (mCentralWidget)
4491
        {
4492
            index = mCentralWidget->addWidget(central);
4493
            mCentralWidget->setCurrentIndex(index);
4494
            MSG_DEBUG("Page widget " << handleToString(handle) << " was added at index " << index);
4495
        }
272 andreas 4496
 
6 andreas 4497
        MSG_DEBUG("Background set");
5 andreas 4498
    }
4499
}
4500
 
296 andreas 4501
void MainWindow::disconnectArea(TQScrollArea* area)
4502
{
4503
    DECL_TRACER("MainWindow::disconnectArea(TQScrollArea* area)");
4504
 
297 andreas 4505
    if (!area)
4506
        return;
4507
 
296 andreas 4508
    disconnect(area, &TQScrollArea::objectClicked, this, &MainWindow::onSubViewItemClicked);
4509
}
4510
 
4511
void MainWindow::disconnectList(QListWidget* list)
4512
{
4513
    DECL_TRACER("MainWindow::disconnectList(QListWidget* list)");
4514
 
297 andreas 4515
    if (!list)
4516
        return;
4517
 
296 andreas 4518
    disconnect(list, &QListWidget::currentItemChanged, this, &MainWindow::onTListCallbackCurrentItemChanged);
4519
}
4520
 
297 andreas 4521
void MainWindow::reconnectArea(TQScrollArea * area)
4522
{
4523
    DECL_TRACER("MainWindow::reconnectArea(TQScrollArea * area)");
4524
 
4525
    if (!area)
4526
        return;
4527
 
4528
    connect(area, &TQScrollArea::objectClicked, this, &MainWindow::onSubViewItemClicked);
4529
}
4530
 
4531
void MainWindow::reconnectList(QListWidget *list)
4532
{
4533
    DECL_TRACER("MainWindow::reconnectList(QListWidget *list)");
4534
 
4535
    if (!list)
4536
        return;
4537
 
4538
    connect(list, &QListWidget::currentItemChanged, this, &MainWindow::onTListCallbackCurrentItemChanged);
4539
}
4540
 
296 andreas 4541
/**
4542
 * @brief MainWindow::dropPage - Marks a page invalid
4543
 * This method marks a page and all the object on the page as invalid. They are
4544
 * not deleted. Instead the page, a QWidget representing a page, is set hidden.
4545
 * With it all childs of the QWidget are also hidden. So the page can be
4546
 * displayed later when it is used again.
4547
 *
4548
 * @param handle    The handle of the page.
4549
 */
11 andreas 4550
void MainWindow::dropPage(ulong handle)
4551
{
292 andreas 4552
    TLOCKER(draw_mutex);
11 andreas 4553
    DECL_TRACER("MainWindow::dropPage(ulong handle)");
7 andreas 4554
 
271 andreas 4555
    MSG_PROTOCOL("Dropping page " << handleToString(handle));
265 andreas 4556
 
294 andreas 4557
    OBJECT_t *obj = findObject(handle);
264 andreas 4558
 
296 andreas 4559
    if (!obj)
4560
    {
4561
        MSG_WARNING("Object " << handleToString(handle) << " (Page) does not exist. Ignoring!");
4562
        return;
4563
    }
271 andreas 4564
 
296 andreas 4565
    if (obj->type != OBJ_PAGE)
271 andreas 4566
    {
296 andreas 4567
        MSG_WARNING("Object " << handleToString(handle) << " is not a page!");
4568
        return;
271 andreas 4569
    }
296 andreas 4570
 
4571
    MSG_DEBUG("Dropping page " << handleToString(handle));
4572
    invalidateAllSubObjects(handle);
4573
 
297 andreas 4574
    if (obj->object.widget)
296 andreas 4575
        obj->object.widget->setHidden(true);
11 andreas 4576
}
4577
 
4578
void MainWindow::dropSubPage(ulong handle)
4579
{
4580
    DECL_TRACER("MainWindow::dropSubPage(ulong handle)");
4581
 
294 andreas 4582
    OBJECT_t *obj = findObject(handle);
11 andreas 4583
 
4584
    if (!obj)
4585
    {
296 andreas 4586
        MSG_WARNING("Object " << handleToString(handle) << " (SubPage) does not exist. Ignoring!");
11 andreas 4587
        return;
4588
    }
4589
 
297 andreas 4590
    if (obj->type != OBJ_SUBPAGE)
296 andreas 4591
    {
4592
        MSG_WARNING("Object " << handleToString(handle) << " is not a SubPage!");
217 andreas 4593
        return;
296 andreas 4594
    }
217 andreas 4595
 
296 andreas 4596
    MSG_DEBUG("Dropping subpage " << handleToString(handle));
4597
    invalidateAllSubObjects(handle);
107 andreas 4598
    obj->aniDirection = false;
217 andreas 4599
 
4600
    if (gPageManager && gPageManager->isSetupActive())
4601
        obj->animate.hideEffect = SE_NONE;
4602
 
298 andreas 4603
    bool ret = startAnimation(obj, obj->animate, false);
43 andreas 4604
 
298 andreas 4605
    if (obj->animate.hideEffect == SE_NONE || !ret || !mLastObject)
42 andreas 4606
    {
297 andreas 4607
        obj->invalid = true;
4608
        obj->remove = false;
296 andreas 4609
 
4610
        if (obj->object.widget)
297 andreas 4611
            obj->object.widget->hide();
42 andreas 4612
    }
11 andreas 4613
}
4614
 
98 andreas 4615
void MainWindow::dropButton(ulong handle)
4616
{
292 andreas 4617
    TLOCKER(draw_mutex);
98 andreas 4618
    DECL_TRACER("MainWindow::dropButton(ulong handle)");
4619
 
294 andreas 4620
    OBJECT_t *obj = findObject(handle);
98 andreas 4621
 
4622
    if (!obj)
4623
    {
271 andreas 4624
        MSG_WARNING("Object " << handleToString(handle) << " does not exist. Ignoring!");
98 andreas 4625
        return;
4626
    }
4627
 
294 andreas 4628
    if (obj->type == OBJ_PAGE || obj->type == OBJ_SUBPAGE)
217 andreas 4629
        return;
4630
 
296 andreas 4631
    invalidateObject(handle);
98 andreas 4632
}
252 andreas 4633
 
197 andreas 4634
void MainWindow::setSizeMainWindow(int width, int height)
4635
{
252 andreas 4636
#if !defined (Q_OS_ANDROID) && !defined(Q_OS_IOS)
197 andreas 4637
    DECL_TRACER("MainWindow::setSizeMainWindow(int width, int height)");
4638
 
198 andreas 4639
    QRect geo = geometry();
4640
    setGeometry(geo.x(), geo.y(), width, height + menuBar()->height());
252 andreas 4641
#else
4642
    Q_UNUSED(width);
4643
    Q_UNUSED(height);
4644
#endif
197 andreas 4645
}
252 andreas 4646
 
21 andreas 4647
void MainWindow::playVideo(ulong handle, ulong parent, int left, int top, int width, int height, const string& url, const string& user, const string& pw)
4648
{
292 andreas 4649
    TLOCKER(draw_mutex);
21 andreas 4650
    DECL_TRACER("MainWindow::playVideo(ulong handle, const string& url, const string& user, const string& pw))");
4651
 
277 andreas 4652
    TObject::OBJECT_t *obj = findObject(handle);
4653
    TObject::OBJECT_t *par = findObject(parent);
271 andreas 4654
    MSG_TRACE("Processing button " << handleToString(handle) << " from parent " << handleToString(parent));
107 andreas 4655
 
21 andreas 4656
    if (!par)
4657
    {
4658
        MSG_WARNING("Button has no parent! Ignoring it.");
4659
        return;
4660
    }
4661
 
4662
    if (!obj)
4663
    {
4664
        MSG_DEBUG("Adding new video object ...");
296 andreas 4665
        OBJECT_t nobj;
21 andreas 4666
 
296 andreas 4667
        nobj.type = TObject::OBJ_VIDEO;
4668
        nobj.handle = handle;
21 andreas 4669
 
198 andreas 4670
        if (gPageManager && gPageManager->isSetupActive())
4671
        {
296 andreas 4672
            nobj.width = scaleSetup(width);
4673
            nobj.height = scaleSetup(height);
4674
            nobj.left = scaleSetup(left);
4675
            nobj.top = scaleSetup(top);
198 andreas 4676
        }
4677
        else
4678
        {
296 andreas 4679
            nobj.width = scale(width);
4680
            nobj.height = scale(height);
4681
            nobj.left = scale(left);
4682
            nobj.top = scale(top);
198 andreas 4683
        }
4684
 
296 andreas 4685
        nobj.object.vwidget = new QVideoWidget(par->object.widget);
4686
        nobj.object.vwidget->installEventFilter(this);
4687
 
4688
        if (!addObject(nobj))
4689
        {
4690
            MSG_ERROR("Error creating a video object!");
4691
            return;
4692
        }
4693
 
4694
        obj = findObject(handle);
21 andreas 4695
    }
4696
    else
277 andreas 4697
        MSG_DEBUG("Object " << handleToString(handle) << " of type " << objectToString(obj->type) << " found!");
21 andreas 4698
 
264 andreas 4699
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
21 andreas 4700
    QMediaPlaylist *playlist = new QMediaPlaylist;
181 andreas 4701
#endif
21 andreas 4702
    QUrl qurl(url.c_str());
4703
 
4704
    if (!user.empty())
4705
        qurl.setUserName(user.c_str());
4706
 
4707
    if (!pw.empty())
4708
        qurl.setPassword(pw.c_str());
4709
 
264 andreas 4710
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
21 andreas 4711
    playlist->addMedia(qurl);
181 andreas 4712
#endif
21 andreas 4713
    obj->player = new QMediaPlayer;
264 andreas 4714
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
21 andreas 4715
    obj->player->setPlaylist(playlist);
181 andreas 4716
#else
4717
    obj->player->setSource(qurl);
4718
#endif
21 andreas 4719
    obj->player->setVideoOutput(obj->object.vwidget);
31 andreas 4720
 
107 andreas 4721
    obj->object.vwidget->show();
4722
    obj->player->play();
21 andreas 4723
}
4724
 
291 andreas 4725
void MainWindow::inputText(Button::TButton *button, QByteArray buf, int width, int height, int frame, size_t pixline)
50 andreas 4726
{
279 andreas 4727
    DECL_TRACER("MainWindow::inputText(Button::TButton& button, QByteArray buf, int width, int height, int frame, size_t pixline)");
50 andreas 4728
 
310 andreas 4729
    if (!button)
4730
    {
4731
        MSG_WARNING("Method was called with no button!");
4732
        return;
4733
    }
4734
 
292 andreas 4735
    TLOCKER(draw_mutex);
291 andreas 4736
    ulong handle = button->getHandle();
4737
    ulong parent = button->getParent();
277 andreas 4738
    TObject::OBJECT_t *obj = findObject(handle);
4739
    TObject::OBJECT_t *par = findObject(parent);
271 andreas 4740
    MSG_TRACE("Processing button " << handleToString(handle) << " from parent " << handleToString(parent) << " with frame width " << frame);
50 andreas 4741
 
4742
    if (!par)
4743
    {
4744
        MSG_WARNING("Button has no parent! Ignoring it.");
4745
        return;
4746
    }
4747
 
310 andreas 4748
    int instance = button->getActiveInstance();
4749
    MSG_DEBUG("Instance: " << instance);
4750
 
50 andreas 4751
    if (!obj)
4752
    {
4753
        MSG_DEBUG("Adding new input object ...");
296 andreas 4754
        OBJECT_t nobj;
50 andreas 4755
 
296 andreas 4756
        nobj.type = TObject::OBJ_INPUT;
4757
        nobj.handle = handle;
50 andreas 4758
 
198 andreas 4759
        if (gPageManager && gPageManager->isSetupActive())
4760
        {
296 andreas 4761
            nobj.width = scaleSetup(width);
4762
            nobj.height = scaleSetup(height);
4763
            nobj.left = scaleSetup(button->getLeftPosition());
4764
            nobj.top = scaleSetup(button->getTopPosition());
198 andreas 4765
        }
4766
        else
4767
        {
296 andreas 4768
            nobj.width = scale(width);
4769
            nobj.height = scale(height);
4770
            nobj.left = scale(button->getLeftPosition());
4771
            nobj.top = scale(button->getTopPosition());
198 andreas 4772
        }
4773
 
310 andreas 4774
        string text = button->getText(instance);
291 andreas 4775
        string mask = button->getInputMask();
191 andreas 4776
 
296 andreas 4777
        nobj.object.plaintext = new TQEditLine(text, par->object.widget, button->isMultiLine());
4778
        nobj.object.plaintext->setObjectName(string("EditLine_") + handleToString(handle));
4779
        nobj.object.plaintext->setHandle(handle);
4780
        nobj.object.plaintext->move(nobj.left, nobj.top);
4781
        nobj.object.plaintext->setFixedSize(nobj.width, nobj.height);
4782
        nobj.object.plaintext->setPadding(frame, frame, frame, frame);
4783
        nobj.object.plaintext->setWordWrapMode(button->getTextWordWrap());
4784
        nobj.object.plaintext->setPasswordChar(button->getPasswordChar());
4785
        nobj.wid = nobj.object.plaintext->winId();
192 andreas 4786
 
213 andreas 4787
        if (gPageManager->isSetupActive())
4788
        {
4789
            int ch = 0;
4790
 
291 andreas 4791
            if (button->getAddressPort() == 0 && button->getAddressChannel() > 0)
4792
                ch = button->getAddressChannel();
4793
            else if (button->getChannelPort() == 0 && button->getChannelNumber() > 0)
4794
                ch = button->getChannelNumber();
213 andreas 4795
 
4796
            switch(ch)
4797
            {
4798
                case SYSTEM_ITEM_SIPPORT:
4799
                case SYSTEM_ITEM_NETLINX_PORT:
296 andreas 4800
                    nobj.object.plaintext->setInputMask("000000");
4801
                    nobj.object.plaintext->setNumericInput();
213 andreas 4802
                break;
4803
 
4804
                case SYSTEM_ITEM_NETLINX_CHANNEL:
296 andreas 4805
                    nobj.object.plaintext->setInputMask("99999");
4806
                    nobj.object.plaintext->setNumericInput();
213 andreas 4807
                break;
4808
            }
4809
        }
224 andreas 4810
        else if (!mask.empty())
296 andreas 4811
            nobj.object.plaintext->setInputMask(convertMask(mask));
213 andreas 4812
 
52 andreas 4813
        if (!buf.size() || pixline == 0)
51 andreas 4814
        {
4815
            MSG_ERROR("No image!");
4816
            TError::setError();
4817
            return;
4818
        }
4819
 
52 andreas 4820
        MSG_DEBUG("Background image size: " << width << " x " << height << ", rowBytes: " << pixline);
4821
        QPixmap pix(width, height);
4822
        QImage img((uchar *)buf.data(), width, height, QImage::Format_ARGB32);
50 andreas 4823
 
198 andreas 4824
        if (gPageManager && gPageManager->isSetupActive())
4825
            pix.convertFromImage(img.scaled(scaleSetup(width), scaleSetup(height), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
4826
        else if (isScaled())
52 andreas 4827
            pix.convertFromImage(img.scaled(scale(width), scale(height), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
50 andreas 4828
        else
4829
            pix.convertFromImage(img);
4830
 
4831
        // Load the font
291 andreas 4832
        FONT_T font = button->getFont();
51 andreas 4833
        vector<string> fontList = TFont::getFontPathList();
4834
        vector<string>::iterator iter;
4835
        string ffile;
50 andreas 4836
 
51 andreas 4837
        for (iter = fontList.begin(); iter != fontList.end(); ++iter)
50 andreas 4838
        {
51 andreas 4839
            TValidateFile vf;
50 andreas 4840
 
51 andreas 4841
            if (!vf.isValidFile(*iter + "/" + font.file))
4842
                continue;
4843
 
4844
            ffile = *iter + "/" + font.file;
4845
            break;
50 andreas 4846
        }
4847
 
51 andreas 4848
        if (ffile.empty())
4849
        {
4850
            MSG_ERROR("Font " << font.file << " doesn't exists!");
4851
            return;
4852
        }
4853
 
213 andreas 4854
        if (QFontDatabase::addApplicationFont(ffile.c_str()) == -1)
50 andreas 4855
        {
4856
            MSG_ERROR("Font " << ffile << " could not be loaded!");
4857
            TError::setError();
4858
            return;
4859
        }
4860
 
4861
        QFont ft;
4862
        ft.setFamily(font.name.c_str());
198 andreas 4863
 
4864
        if (gPageManager && gPageManager->isSetupActive())
303 andreas 4865
        {
4866
            int eighty = (int)((double)button->getHeight() / 100.0 * 85.0);
213 andreas 4867
            ft.setPixelSize(scaleSetup(eighty - frame * 2));
303 andreas 4868
        }
198 andreas 4869
        else
303 andreas 4870
            ft.setPixelSize(scale(font.size));
198 andreas 4871
 
213 andreas 4872
        MSG_DEBUG("Using font \"" << font.name << "\" with size " << font.size << "px.");
50 andreas 4873
 
291 andreas 4874
        switch (button->getFontStyle())
50 andreas 4875
        {
4876
            case FONT_BOLD:     ft.setBold(true); break;
4877
            case FONT_ITALIC:   ft.setItalic(true); break;
4878
            case FONT_BOLD_ITALIC:
4879
                ft.setBold(true);
4880
                ft.setItalic(true);
4881
                break;
4882
 
4883
            default:
4884
                ft.setBold(false);
4885
                ft.setItalic(false);
4886
        }
4887
 
303 andreas 4888
        QPalette palette(this->palette());
310 andreas 4889
        TColor::COLOR_T textColor = TColor::getAMXColor(button->getTextColor(instance));
4890
        TColor::COLOR_T fillColor = TColor::getAMXColor(button->getFillColor(instance));
51 andreas 4891
        QColor txcolor(QColor::fromRgba(qRgba(textColor.red, textColor.green, textColor.blue, textColor.alpha)));
52 andreas 4892
        QColor cfcolor(QColor::fromRgba(qRgba(fillColor.red, fillColor.green, fillColor.blue, fillColor.alpha)));
303 andreas 4893
        palette.setColor(QPalette::Window, cfcolor);
52 andreas 4894
        palette.setColor(QPalette::Base, cfcolor);
51 andreas 4895
        palette.setColor(QPalette::Text, txcolor);
303 andreas 4896
        palette.setBrush(QPalette::Window, QBrush(pix));
188 andreas 4897
 
296 andreas 4898
        nobj.object.plaintext->setFont(ft);
4899
        nobj.object.plaintext->setPalette(palette);
310 andreas 4900
        nobj.object.plaintext->setTextColor(txcolor);
296 andreas 4901
 
4902
        if (!addObject(nobj))
4903
        {
4904
            MSG_ERROR("Error creating an input object!");
4905
            return;
4906
        }
303 andreas 4907
 
4908
        connect(nobj.object.plaintext, &TQEditLine::inputChanged, this, &MainWindow::onInputChanged);
309 andreas 4909
        connect(nobj.object.plaintext, &TQEditLine::cursorPositionChanged, this, &MainWindow::onCursorChanged);
4910
        connect(nobj.object.plaintext, &TQEditLine::focusChanged, this, &MainWindow::onFocusChanged);
50 andreas 4911
    }
4912
    else
206 andreas 4913
    {
277 andreas 4914
        MSG_DEBUG("Object " << handleToString(handle) << " of type " << objectToString(obj->type) << " found!");
206 andreas 4915
 
310 andreas 4916
        string text = button->getText(instance);
291 andreas 4917
        string mask = button->getInputMask();
206 andreas 4918
        obj->object.plaintext->setText(text);
224 andreas 4919
 
4920
        if (!mask.empty())
4921
            obj->object.plaintext->setInputMask(convertMask(mask));
4922
 
310 andreas 4923
        QPixmap pix(obj->width, obj->height);
4924
        QImage img((uchar *)buf.data(), width, height, QImage::Format_ARGB32);
4925
 
4926
        if (isScaled())
4927
            pix.convertFromImage(img.scaled(obj->width, obj->height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
4928
        else
4929
            pix.convertFromImage(img);
4930
 
4931
        QPalette palette(this->palette());
4932
        TColor::COLOR_T textColor = TColor::getAMXColor(button->getTextColor(instance));
4933
        TColor::COLOR_T fillColor = TColor::getAMXColor(button->getFillColor(instance));
4934
        QColor txcolor(QColor::fromRgba(qRgba(textColor.red, textColor.green, textColor.blue, textColor.alpha)));
4935
        QColor cfcolor(QColor::fromRgba(qRgba(fillColor.red, fillColor.green, fillColor.blue, fillColor.alpha)));
4936
        palette.setColor(QPalette::Window, cfcolor);
4937
        palette.setColor(QPalette::Base, cfcolor);
4938
        palette.setColor(QPalette::Text, txcolor);
4939
        palette.setBrush(QPalette::Window, QBrush(pix));
4940
 
4941
        obj->object.plaintext->setPalette(palette);
4942
        obj->object.plaintext->setTextColor(txcolor);
206 andreas 4943
    }
50 andreas 4944
}
62 andreas 4945
 
291 andreas 4946
void MainWindow::listBox(Button::TButton *button, QByteArray buffer, int width, int height, int frame, size_t pixline)
200 andreas 4947
{
279 andreas 4948
    DECL_TRACER("MainWindow::listBox(Button::TButton& button, QByteArray buffer, int width, int height, int frame, size_t pixline)");
200 andreas 4949
 
291 andreas 4950
    ulong handle = button->getHandle();
4951
    ulong parent = button->getParent();
277 andreas 4952
    TObject::OBJECT_t *obj = findObject(handle);
4953
    TObject::OBJECT_t *par = findObject(parent);
271 andreas 4954
    MSG_TRACE("Processing list " << handleToString(handle) << " from parent " << handleToString(parent) << " with frame width " << frame);
200 andreas 4955
 
4956
    if (!par)
4957
    {
4958
        MSG_WARNING("List has no parent! Ignoring it.");
4959
        return;
4960
    }
4961
 
4962
    if (!obj)
4963
    {
4964
        MSG_DEBUG("Adding new list object ...");
296 andreas 4965
        OBJECT_t nobj;
200 andreas 4966
 
296 andreas 4967
        nobj.type = TObject::OBJ_LIST;
4968
        nobj.handle = handle;
4969
        nobj.rows = button->getListNumRows();
4970
        nobj.cols = button->getListNumCols();
200 andreas 4971
 
4972
        if (gPageManager && gPageManager->isSetupActive())
4973
        {
296 andreas 4974
            nobj.width = scaleSetup(width);
4975
            nobj.height = scaleSetup(height);
4976
            nobj.left = scaleSetup(button->getLeftPosition());
4977
            nobj.top = scaleSetup(button->getTopPosition());
200 andreas 4978
        }
4979
        else
4980
        {
296 andreas 4981
            nobj.width = scale(width);
4982
            nobj.height = scale(height);
4983
            nobj.left = scale(button->getLeftPosition());
4984
            nobj.top = scale(button->getTopPosition());
200 andreas 4985
        }
4986
 
291 andreas 4987
        vector<string> listContent = button->getListContent();
200 andreas 4988
 
217 andreas 4989
        if (par->type == TObject::OBJ_PAGE)
296 andreas 4990
            nobj.object.list = new QListWidget(par->object.widget ? par->object.widget : centralWidget());
217 andreas 4991
        else
296 andreas 4992
            nobj.object.list = new QListWidget(par->object.widget);
200 andreas 4993
 
296 andreas 4994
        nobj.object.list->move(nobj.left, nobj.top);
4995
        nobj.object.list->setFixedSize(nobj.width, nobj.height);
4996
        connect(nobj.object.list, &QListWidget::currentItemChanged, this, &MainWindow::onTListCallbackCurrentItemChanged);
200 andreas 4997
 
4998
        if (!buffer.size() || pixline == 0)
4999
        {
5000
            MSG_ERROR("No image!");
5001
            TError::setError();
5002
            return;
5003
        }
5004
 
5005
        MSG_DEBUG("Background image size: " << width << " x " << height << ", rowBytes: " << pixline);
5006
        QPixmap pix(width, height);
5007
        QImage img((uchar *)buffer.data(), width, height, QImage::Format_ARGB32);
5008
 
5009
        if (gPageManager && gPageManager->isSetupActive())
5010
            pix.convertFromImage(img.scaled(scaleSetup(width), scaleSetup(height), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
5011
        else if (isScaled())
5012
            pix.convertFromImage(img.scaled(scale(width), scale(height), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
5013
        else
5014
            pix.convertFromImage(img);
5015
 
5016
        // Load the font
291 andreas 5017
        FONT_T font = button->getFont();
200 andreas 5018
        vector<string> fontList = TFont::getFontPathList();
5019
        vector<string>::iterator iter;
5020
        string ffile;
5021
 
5022
        for (iter = fontList.begin(); iter != fontList.end(); ++iter)
5023
        {
5024
            TValidateFile vf;
5025
 
5026
            if (!vf.isValidFile(*iter + "/" + font.file))
5027
                continue;
5028
 
5029
            ffile = *iter + "/" + font.file;
5030
            break;
5031
        }
5032
 
5033
        if (ffile.empty())
5034
        {
5035
            MSG_ERROR("Font " << font.file << " doesn't exists!");
5036
            return;
5037
        }
5038
 
213 andreas 5039
        if (QFontDatabase::addApplicationFont(ffile.c_str()) == -1)
200 andreas 5040
        {
5041
            MSG_ERROR("Font " << ffile << " could not be loaded!");
5042
            TError::setError();
5043
            return;
5044
        }
5045
 
5046
        QFont ft;
5047
        ft.setFamily(font.name.c_str());
5048
 
213 andreas 5049
        if (gPageManager && gPageManager->isSetupActive())
5050
            ft.setPointSize(scaleSetup(font.size));
5051
        else
200 andreas 5052
            ft.setPointSize(font.size);
5053
 
5054
        MSG_DEBUG("Using font \"" << font.name << "\" with size " << font.size << "pt.");
5055
 
291 andreas 5056
        switch (button->getFontStyle())
200 andreas 5057
        {
5058
            case FONT_BOLD:     ft.setBold(true); break;
5059
            case FONT_ITALIC:   ft.setItalic(true); break;
5060
            case FONT_BOLD_ITALIC:
5061
                ft.setBold(true);
5062
                ft.setItalic(true);
5063
            break;
5064
 
5065
            default:
5066
                ft.setBold(false);
5067
                ft.setItalic(false);
5068
        }
5069
 
5070
        QPalette palette;
291 andreas 5071
        TColor::COLOR_T textColor = TColor::getAMXColor(button->getTextColor());
5072
        TColor::COLOR_T fillColor = TColor::getAMXColor(button->getFillColor());
200 andreas 5073
        QColor txcolor(QColor::fromRgba(qRgba(textColor.red, textColor.green, textColor.blue, textColor.alpha)));
5074
        QColor cfcolor(QColor::fromRgba(qRgba(fillColor.red, fillColor.green, fillColor.blue, fillColor.alpha)));
5075
        palette.setColor(QPalette::Base, cfcolor);
5076
        palette.setColor(QPalette::Text, txcolor);
217 andreas 5077
//        pix.save("frame.png");
200 andreas 5078
        palette.setBrush(QPalette::Base, QBrush(pix));
5079
 
296 andreas 5080
        nobj.object.list->setFont(ft);
5081
        nobj.object.list->setPalette(palette);
200 andreas 5082
        // Add content
5083
        if (!listContent.empty())
5084
        {
5085
            vector<string>::iterator iter;
5086
 
296 andreas 5087
            if (nobj.object.list->count() > 0)
5088
                nobj.object.list->clear();
205 andreas 5089
 
5090
            MSG_DEBUG("Adding " << listContent.size() << " entries to list.");
5091
            string selected = gPageManager->getSelectedItem(handle);
5092
            int index = 0;
5093
 
200 andreas 5094
            for (iter = listContent.begin(); iter != listContent.end(); ++iter)
205 andreas 5095
            {
296 andreas 5096
                nobj.object.list->addItem(iter->c_str());
205 andreas 5097
 
5098
                if (selected == *iter)
296 andreas 5099
                    nobj.object.list->setCurrentRow(index);
205 andreas 5100
 
5101
                index++;
5102
            }
200 andreas 5103
        }
205 andreas 5104
        else
5105
            MSG_DEBUG("No items for list!");
200 andreas 5106
 
296 andreas 5107
//        nobj.object.list->show();
5108
 
5109
        if (!addObject(nobj))
5110
        {
5111
            MSG_ERROR("Error creating a list object!");
5112
            return;
5113
        }
200 andreas 5114
    }
5115
    else
297 andreas 5116
    {
277 andreas 5117
        MSG_DEBUG("Object " << handleToString(handle) << " of type " << objectToString(obj->type) << " found!");
297 andreas 5118
        enableObject(handle);
5119
    }
200 andreas 5120
}
5121
 
63 andreas 5122
void MainWindow::showKeyboard(const std::string& init, const std::string& prompt, bool priv)
31 andreas 5123
{
63 andreas 5124
    DECL_TRACER("MainWindow::showKeyboard(std::string &init, std::string &prompt, bool priv)");
31 andreas 5125
 
63 andreas 5126
    if (mKeyboard)
5127
        return;
5128
 
5129
    mQKeyboard = new TQKeyboard(init, prompt, this);
5130
    mKeyboard = true;
62 andreas 5131
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
65 andreas 5132
    mQKeyboard->setScaleFactor(mScaleFactor);
62 andreas 5133
#endif
63 andreas 5134
    mQKeyboard->setPrivate(priv);
5135
    mQKeyboard->doResize();
5136
    mQKeyboard->setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::FramelessWindowHint);
5137
    int ret = mQKeyboard->exec();
120 andreas 5138
    string text = "KEYB-";
31 andreas 5139
 
62 andreas 5140
    if (ret == QDialog::Accepted)
63 andreas 5141
        text.append(mQKeyboard->getText());
62 andreas 5142
    else
120 andreas 5143
        text = "KEYB-ABORT";
62 andreas 5144
 
120 andreas 5145
    if (gPageManager)
5146
        gPageManager->sendKeyboard(text);
62 andreas 5147
 
63 andreas 5148
    delete mQKeyboard;
5149
    mQKeyboard = nullptr;
5150
    mKeyboard = false;
31 andreas 5151
}
62 andreas 5152
 
63 andreas 5153
void MainWindow::showKeypad(const std::string& init, const std::string& prompt, bool priv)
62 andreas 5154
{
63 andreas 5155
    DECL_TRACER("MainWindow::showKeypad(std::string& init, std::string& prompt, bool priv)");
62 andreas 5156
 
65 andreas 5157
    if (mKeypad)
63 andreas 5158
        return;
5159
 
5160
    mQKeypad = new TQKeypad(init, prompt, this);
65 andreas 5161
    mKeypad = true;
62 andreas 5162
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
63 andreas 5163
    mQKeypad->setScaleFactor(mScaleFactor);
65 andreas 5164
#endif
5165
    mQKeypad->setPrivate(priv);
111 andreas 5166
    mQKeypad->setMaxLength(50);     // Standard maximum length
63 andreas 5167
    mQKeypad->doResize();
5168
    mQKeypad->setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::FramelessWindowHint);
65 andreas 5169
    int ret = mQKeypad->exec();
62 andreas 5170
 
5171
    if (ret == QDialog::Accepted)
5172
    {
5173
        string text = "KEYP-";
63 andreas 5174
        text.append(mQKeypad->getText());
62 andreas 5175
 
5176
        if (gPageManager)
5177
            gPageManager->sendKeypad(text);
5178
    }
5179
    else
5180
    {
5181
        string text = "KEYP-ABORT";
5182
 
5183
        if (gPageManager)
5184
            gPageManager->sendKeypad(text);
5185
    }
5186
 
63 andreas 5187
    delete mQKeypad;
5188
    mQKeypad = nullptr;
65 andreas 5189
    mKeypad = false;
62 andreas 5190
}
5191
 
63 andreas 5192
void MainWindow::resetKeyboard()
5193
{
5194
    DECL_TRACER("MainWindow::resetKeyboard()");
5195
 
5196
    if (mQKeyboard)
5197
        mQKeyboard->reject();
5198
 
5199
    if (mQKeypad)
211 andreas 5200
        mQKeypad->reject();
63 andreas 5201
}
5202
 
111 andreas 5203
void MainWindow::sendVirtualKeys(const string& str)
5204
{
5205
    DECL_TRACER("MainWindow::sendVirtualKeys(const string& str)");
5206
 
5207
    if (mKeyboard && mQKeyboard)
5208
        mQKeyboard->setString(str);
5209
    else if (mKeypad && mQKeypad)
5210
        mQKeypad->setString(str);
5211
}
5212
 
64 andreas 5213
void MainWindow::showSetup()
5214
{
5215
    DECL_TRACER("MainWindow::showSetup()");
251 andreas 5216
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
211 andreas 5217
    settings();
5218
#else
250 andreas 5219
#ifndef Q_OS_IOS
197 andreas 5220
    if (gPageManager)
5221
        gPageManager->showSetup();
250 andreas 5222
#else
259 andreas 5223
    mIOSSettingsActive = true;
250 andreas 5224
    QASettings::openSettings();
5225
#endif  // Q_OS_IOS
251 andreas 5226
#endif  // !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
64 andreas 5227
}
5228
 
71 andreas 5229
void MainWindow::playSound(const string& file)
5230
{
5231
    DECL_TRACER("MainWindow::playSound(const string& file)");
5232
 
5233
    MSG_DEBUG("Playing file " << file);
141 andreas 5234
 
5235
    if (TConfig::getMuteState())
326 andreas 5236
    {
5237
#if TESTMODE == 1
5238
        __success = true;
5239
        __done = true;
5240
#endif
141 andreas 5241
        return;
326 andreas 5242
    }
141 andreas 5243
 
5244
    if (!mMediaPlayer)
181 andreas 5245
    {
141 andreas 5246
        mMediaPlayer = new QMediaPlayer;
264 andreas 5247
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
181 andreas 5248
        mAudioOutput = new QAudioOutput;
5249
#endif
5250
    }
141 andreas 5251
 
264 andreas 5252
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
141 andreas 5253
    mMediaPlayer->setMedia(QUrl::fromLocalFile(file.c_str()));
5254
    mMediaPlayer->setVolume(calcVolume(TConfig::getSystemVolume()));
181 andreas 5255
#else
5256
    mMediaPlayer->setSource(QUrl::fromLocalFile(file.c_str()));
5257
    mAudioOutput->setVolume(TConfig::getSystemVolume());
5258
#endif
141 andreas 5259
    mMediaPlayer->play();
326 andreas 5260
#if TESTMODE == 1
5261
    __success = true;
5262
    __done = true;
5263
#endif
71 andreas 5264
}
5265
 
141 andreas 5266
void MainWindow::stopSound()
5267
{
5268
    DECL_TRACER("MainWindow::stopSound()");
5269
 
5270
    if (mMediaPlayer)
5271
        mMediaPlayer->stop();
5272
}
5273
 
5274
void MainWindow::muteSound(bool state)
5275
{
5276
    DECL_TRACER("MainWindow::muteSound(bool state)");
5277
 
264 andreas 5278
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
141 andreas 5279
    if (mMediaPlayer)
5280
        mMediaPlayer->setMuted(state);
181 andreas 5281
#else
5282
    if (mAudioOutput)
5283
        mAudioOutput->setMuted(state);
5284
#endif
141 andreas 5285
}
5286
 
31 andreas 5287
void MainWindow::playShowList()
5288
{
5289
    DECL_TRACER("MainWindow::playShowList()");
5290
 
61 andreas 5291
    _EMIT_TYPE_t etype = getNextType();
5292
 
5293
    while (etype != ET_NONE)
5294
    {
5295
        ulong handle = 0;
5296
        ulong parent = 0;
5297
        int left = 0;
5298
        int top = 0;
5299
        int width = 0;
5300
        int height = 0;
192 andreas 5301
        int frame = 0;
289 andreas 5302
        TBitmap image;
61 andreas 5303
        ulong color = 0;
289 andreas 5304
        int space{0};
5305
        bool vertical = false;
5306
        TColor::COLOR_T fillColor;
298 andreas 5307
        bool pth = false;
262 andreas 5308
#ifndef _OPAQUE_SKIA_
5309
        int opacity = 255;
5310
#endif
61 andreas 5311
        ANIMATION_t animate;
5312
        std::string url;
5313
        std::string user;
5314
        std::string pw;
5315
        Button::TButton *button;
5316
        Button::BITMAP_t bm;
5317
 
5318
        switch(etype)
5319
        {
5320
            case ET_BACKGROUND:
262 andreas 5321
#ifdef _OPAQUE_SKIA_
289 andreas 5322
                if (getBackground(&handle, &image, &width, &height, &color))
262 andreas 5323
#else
289 andreas 5324
                if (getBackground(&handle, &image, &width, &height, &color, &opacity))
262 andreas 5325
#endif
61 andreas 5326
                {
271 andreas 5327
                    MSG_PROTOCOL("Replay: BACKGROUND of object " << handleToString(handle));
262 andreas 5328
#ifdef _OPAQUE_SKIA_
289 andreas 5329
                    emit sigSetBackground(handle, image, width, height, color);
262 andreas 5330
#else
289 andreas 5331
                    emit sigSetBackground(handle, image, width, height, color, opacity);
262 andreas 5332
#endif
61 andreas 5333
                }
5334
            break;
5335
 
5336
            case ET_BUTTON:
298 andreas 5337
                if (getButton(&handle, &parent, &image, &left, &top, &width, &height, &pth))
61 andreas 5338
                {
271 andreas 5339
                    MSG_PROTOCOL("Replay: BUTTON object " << handleToString(handle));
298 andreas 5340
                    emit sigDisplayButton(handle, parent, image, width, height, left, top, pth);
61 andreas 5341
                }
5342
            break;
5343
 
5344
            case ET_INTEXT:
192 andreas 5345
                if (getInText(&handle, &button, &bm, &frame))
61 andreas 5346
                {
5347
                    QByteArray buf;
5348
 
5349
                    if (bm.buffer && bm.rowBytes > 0)
5350
                    {
286 andreas 5351
                        size_t s = bm.width * bm.height * (bm.rowBytes / bm.width);
5352
                        buf.insert(0, (const char *)bm.buffer, s);
61 andreas 5353
                    }
5354
 
271 andreas 5355
                    MSG_PROTOCOL("Replay: INTEXT object " << handleToString(handle));
291 andreas 5356
                    emit sigInputText(button, buf, bm.width, bm.height, bm.rowBytes, frame);
61 andreas 5357
                }
5358
            break;
5359
 
5360
            case ET_PAGE:
5361
                if (getPage(&handle, &width, &height))
5362
                {
271 andreas 5363
                    MSG_PROTOCOL("Replay: PAGE object " << handleToString(handle));
217 andreas 5364
 
61 andreas 5365
                    if (isDeleted())
5366
                        emit sigDropPage(handle);
5367
                    else
5368
                        emit sigSetPage(handle, width, height);
5369
                }
5370
            break;
5371
 
5372
            case ET_SUBPAGE:
217 andreas 5373
                if (getSubPage(&handle, &parent, &left, &top, &width, &height, &animate))
61 andreas 5374
                {
271 andreas 5375
                    MSG_PROTOCOL("Replay: SUBPAGE object " << handleToString(handle));
217 andreas 5376
 
61 andreas 5377
                    if (isDeleted())
5378
                        emit sigDropSubPage(handle);
5379
                    else
217 andreas 5380
                        emit sigSetSubPage(handle, parent, left, top, width, height, animate);
61 andreas 5381
                }
5382
            break;
5383
 
289 andreas 5384
            case ET_SUBVIEW:
5385
                if (getViewButton(&handle, &parent, &vertical, &image, &left, &top, &width, &height, &space, &fillColor))
5386
                {
5387
                    MSG_PROTOCOL("Replay: SUBVIEW object " << handleToString(handle));
5388
                    emit sigDisplayViewButton(handle, parent, vertical, image, width, height, left, top, space, fillColor);
5389
                }
5390
            break;
5391
 
61 andreas 5392
            case ET_VIDEO:
5393
                if (getVideo(&handle, &parent, &left, &top, &width, &height, &url, &user, &pw))
5394
                {
271 andreas 5395
                    MSG_PROTOCOL("Replay: VIDEO object " << handleToString(handle));
61 andreas 5396
                    emit sigPlayVideo(handle, parent, left, top, width, height, url, user, pw);
5397
                }
5398
            break;
5399
 
5400
            default:
5401
                MSG_WARNING("Type " << etype << " is currently not supported!");
5402
        }
5403
 
5404
        dropType(etype);
5405
        etype = getNextType();
5406
    }
5407
/*
31 andreas 5408
    std::map<ulong, QWidget *>::iterator iter;
5409
 
5410
    for (iter = mToShow.begin(); iter != mToShow.end(); ++iter)
5411
    {
5412
        OBJECT_t *obj = findObject(iter->first);
5413
 
5414
        if (obj)
5415
            iter->second->show();
5416
    }
5417
 
5418
    mToShow.clear();
61 andreas 5419
*/
31 andreas 5420
}
5421
 
42 andreas 5422
 
38 andreas 5423
int MainWindow::scale(int value)
5424
{
262 andreas 5425
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
5426
    double s = gScale;
5427
#else
5428
    double s = mScaleFactor;
5429
#endif
5430
    if (value <= 0 || s == 1.0 || s < 0.0)
38 andreas 5431
        return value;
5432
 
262 andreas 5433
    return (int)((double)value * s);
38 andreas 5434
}
5435
 
198 andreas 5436
int MainWindow::scaleSetup(int value)
5437
{
5438
    DECL_TRACER("MainWindow::scaleSetup(int value)");
5439
 
212 andreas 5440
    if (value <= 0 || mSetupScaleFactor == 1.0 || mSetupScaleFactor <= 0.0)
198 andreas 5441
        return value;
5442
 
5443
    double val = (double)value * mSetupScaleFactor;
5444
 
5445
    return (int)val;
5446
}
5447
 
259 andreas 5448
bool MainWindow::isScaled()
5449
{
275 andreas 5450
    DECL_TRACER("MainWindow::isScaled()");
5451
 
262 andreas 5452
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
5453
    double s = gScale;
5454
#else
5455
    double s = mScaleFactor;
5456
#endif
5457
    if (s > 0.0 && s != 1.0 && gPageManager && TConfig::getScale())
259 andreas 5458
        return true;
5459
 
5460
    return false;
5461
}
5462
 
198 andreas 5463
bool MainWindow::isSetupScaled()
5464
{
5465
    DECL_TRACER("MainWindow::isSetupScaled()");
5466
 
5467
    return (mSetupScaleFactor > 0.0 && mSetupScaleFactor != 1.0);
5468
}
5469
 
298 andreas 5470
bool MainWindow::startAnimation(TObject::OBJECT_t* obj, ANIMATION_t& ani, bool in)
42 andreas 5471
{
5472
    DECL_TRACER("MainWindow::startAnimation(OBJECT_t* obj, ANIMATION_t& ani)");
43 andreas 5473
 
107 andreas 5474
    if (!obj)
5475
    {
5476
        MSG_ERROR("Got no object to start the animation!");
298 andreas 5477
        return false;
107 andreas 5478
    }
5479
 
296 andreas 5480
    TLOCKER(anim_mutex);
42 andreas 5481
    int scLeft = obj->left;
5482
    int scTop = obj->top;
5483
    int scWidth = obj->width;
5484
    int scHeight = obj->height;
298 andreas 5485
    int duration = (in ? ani.showTime : ani.hideTime);
5486
    SHOWEFFECT_t effect = (in ? ani.showEffect : ani.hideEffect);
42 andreas 5487
    mLastObject = nullptr;
43 andreas 5488
 
298 andreas 5489
    if (effect == SE_NONE || duration <= 0 || (obj->type != OBJ_SUBPAGE && obj->type != OBJ_PAGE))
5490
        return false;
42 andreas 5491
 
298 andreas 5492
    if (!obj->object.widget)
5493
    {
5494
        MSG_WARNING("Object " << handleToString(obj->handle) << " has no widget defined! Ignoring fade effect.");
5495
        return false;
5496
    }
43 andreas 5497
 
58 andreas 5498
    if (effect == SE_FADE)
5499
    {
271 andreas 5500
        MSG_DEBUG("Fading object " << handleToString(obj->handle) << (in ? " IN" : " OUT"));
58 andreas 5501
        QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect(obj->object.widget);
289 andreas 5502
 
5503
        if (effect)
5504
        {
298 andreas 5505
            obj->object.widget->setGraphicsEffect(effect);
289 andreas 5506
            obj->animation = new QPropertyAnimation(effect, "opacity");
5507
        }
58 andreas 5508
    }
5509
    else
5510
    {
271 andreas 5511
        MSG_DEBUG("Moving object " << handleToString(obj->handle) << (in ? " IN" : " OUT"));
58 andreas 5512
        obj->animation = new QPropertyAnimation(obj->object.widget);
5513
        obj->animation->setTargetObject(obj->object.widget);
5514
    }
42 andreas 5515
 
298 andreas 5516
    obj->animation->setDuration(duration * 100);    // convert 10th of seconds into milliseconds
296 andreas 5517
    MSG_DEBUG("Processing animation effect " << effect << " with a duration of " << obj->animation->duration() << "ms");
43 andreas 5518
 
54 andreas 5519
    switch(effect)
5520
    {
5521
        case SE_SLIDE_BOTTOM_FADE:
5522
        case SE_SLIDE_BOTTOM:
5523
            obj->animation->setPropertyName("geometry");
42 andreas 5524
 
54 andreas 5525
            if (in)
5526
            {
5527
                obj->animation->setStartValue(QRect(scLeft, scTop + (scHeight * 2), scWidth, scHeight));
5528
                obj->animation->setEndValue(QRect(scLeft, scTop, scWidth, scHeight));
295 andreas 5529
                connect(obj->animation, &QPropertyAnimation::finished, this, &MainWindow::animationInFinished);
296 andreas 5530
                obj->object.widget->show();
54 andreas 5531
            }
5532
            else
5533
            {
5534
                obj->animation->setStartValue(QRect(scLeft, scTop, scWidth, scHeight));
5535
                obj->animation->setEndValue(QRect(scLeft, scTop + (scHeight * 2), scWidth, scHeight));
5536
                obj->remove = true;
5537
                connect(obj->animation, &QPropertyAnimation::finished, this, &MainWindow::animationFinished);
5538
            }
42 andreas 5539
 
296 andreas 5540
            mLastObject = obj;
5541
            mAnimObjects.insert(pair<ulong, OBJECT_t *>(obj->handle, obj));
54 andreas 5542
            obj->animation->start();
295 andreas 5543
            MSG_DEBUG("Animation SLIDE BOTTOM started.");
54 andreas 5544
        break;
43 andreas 5545
 
54 andreas 5546
        case SE_SLIDE_LEFT_FADE:
5547
        case SE_SLIDE_LEFT:
5548
            obj->animation->setPropertyName("geometry");
43 andreas 5549
 
54 andreas 5550
            if (in)
5551
            {
5552
                obj->animation->setStartValue(QRect(scLeft - scWidth, scTop, scWidth, scHeight));
5553
                obj->animation->setEndValue(QRect(scLeft, scTop, scWidth, scHeight));
295 andreas 5554
                connect(obj->animation, &QPropertyAnimation::finished, this, &MainWindow::animationInFinished);
296 andreas 5555
                obj->object.widget->show();
54 andreas 5556
            }
5557
            else
5558
            {
5559
                obj->animation->setStartValue(QRect(scLeft, scTop, scWidth, scHeight));
5560
                obj->animation->setEndValue(QRect(scLeft - scWidth, scTop, scWidth, scHeight));
5561
                obj->remove = true;
5562
                connect(obj->animation, &QPropertyAnimation::finished, this, &MainWindow::animationFinished);
5563
            }
42 andreas 5564
 
296 andreas 5565
            mLastObject = obj;
5566
            mAnimObjects.insert(pair<ulong, OBJECT_t *>(obj->handle, obj));
54 andreas 5567
            obj->animation->start();
5568
        break;
43 andreas 5569
 
54 andreas 5570
        case SE_SLIDE_RIGHT_FADE:
5571
        case SE_SLIDE_RIGHT:
5572
            obj->animation->setPropertyName("geometry");
43 andreas 5573
 
54 andreas 5574
            if (in)
5575
            {
5576
                obj->animation->setStartValue(QRect(scLeft + scWidth, scTop, scWidth, scHeight));
5577
                obj->animation->setEndValue(QRect(scLeft, scTop, scWidth, scHeight));
295 andreas 5578
                connect(obj->animation, &QPropertyAnimation::finished, this, &MainWindow::animationInFinished);
296 andreas 5579
                obj->object.widget->show();
54 andreas 5580
            }
5581
            else
5582
            {
5583
                obj->animation->setStartValue(QRect(scLeft, scTop, scWidth, scHeight));
5584
                obj->animation->setEndValue(QRect(scLeft + scWidth, scTop, scWidth, scHeight));
5585
                obj->remove = true;
5586
                connect(obj->animation, &QPropertyAnimation::finished, this, &MainWindow::animationFinished);
5587
            }
42 andreas 5588
 
296 andreas 5589
            mLastObject = obj;
5590
            mAnimObjects.insert(pair<ulong, OBJECT_t *>(obj->handle, obj));
54 andreas 5591
            obj->animation->start();
5592
        break;
43 andreas 5593
 
54 andreas 5594
        case SE_SLIDE_TOP_FADE:
5595
        case SE_SLIDE_TOP:
5596
            obj->animation->setPropertyName("geometry");
43 andreas 5597
 
54 andreas 5598
            if (in)
5599
            {
5600
                obj->animation->setStartValue(QRect(scLeft, scTop - scHeight, scWidth, scHeight));
5601
                obj->animation->setEndValue(QRect(scLeft, scTop, scWidth, scHeight));
295 andreas 5602
                connect(obj->animation, &QPropertyAnimation::finished, this, &MainWindow::animationInFinished);
296 andreas 5603
                obj->object.widget->show();
54 andreas 5604
            }
5605
            else
5606
            {
5607
                obj->animation->setStartValue(QRect(scLeft, scTop, scWidth, scHeight));
5608
                obj->animation->setEndValue(QRect(scLeft, scTop - scHeight, scWidth, scHeight));
5609
                obj->remove = true;
5610
                connect(obj->animation, &QPropertyAnimation::finished, this, &MainWindow::animationFinished);
5611
            }
43 andreas 5612
 
296 andreas 5613
            mLastObject = obj;
5614
            mAnimObjects.insert(pair<ulong, OBJECT_t *>(obj->handle, obj));
54 andreas 5615
            obj->animation->start();
5616
        break;
5617
 
58 andreas 5618
        case SE_FADE:
5619
            if (in)
5620
            {
289 andreas 5621
                if (obj->object.widget)
5622
                {
5623
                    obj->object.widget->setWindowOpacity(0.0);
5624
                    obj->object.widget->show();
5625
                }
5626
 
58 andreas 5627
                obj->animation->setStartValue(0.0);
5628
                obj->animation->setEndValue(1.0);
295 andreas 5629
                connect(obj->animation, &QPropertyAnimation::finished, this, &MainWindow::animationInFinished);
296 andreas 5630
                obj->object.widget->show();
58 andreas 5631
            }
5632
            else
5633
            {
5634
                obj->animation->setStartValue(1.0);
5635
                obj->animation->setEndValue(0.0);
5636
                obj->remove = true;
5637
                connect(obj->animation, &QPropertyAnimation::finished, this, &MainWindow::animationFinished);
5638
            }
5639
 
296 andreas 5640
            mLastObject = obj;
5641
            mAnimObjects.insert(pair<ulong, OBJECT_t *>(obj->handle, obj));
58 andreas 5642
            obj->animation->setEasingCurve(QEasingCurve::Linear);
5643
            obj->animation->start();
5644
        break;
5645
 
54 andreas 5646
        default:
5647
            MSG_WARNING("Subpage effect " << ani.showEffect << " is not supported.");
298 andreas 5648
            delete obj->animation;
5649
            obj->animation = nullptr;
5650
            return false;
42 andreas 5651
    }
298 andreas 5652
 
5653
    return true;
42 andreas 5654
}
5655
 
179 andreas 5656
void MainWindow::downloadBar(const string &msg, QWidget *parent)
5657
{
5658
    DECL_TRACER("void MainWindow::downloadBar(const string &msg, QWidget *parent)");
5659
 
5660
    if (mBusy)
5661
        return;
5662
 
5663
    mBusy = true;
5664
    mDownloadBar = new TqDownload(msg, parent);
5665
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
5666
    mDownloadBar->setScaleFactor(gScale);
5667
    mDownloadBar->doResize();
5668
#endif
5669
    mDownloadBar->show();
5670
}
5671
 
120 andreas 5672
void MainWindow::runEvents()
5673
{
5674
    DECL_TRACER("MainWindow::runEvents()");
5675
 
5676
    QApplication::processEvents();
5677
}
5678
 
289 andreas 5679
void MainWindow::onSubViewItemClicked(ulong handle, bool pressed)
5680
{
5681
    DECL_TRACER("MainWindow::onSubViewItemClicked(ulong handle)");
5682
 
5683
    if (!handle)
5684
        return;
5685
 
5686
    // Create a thread and call the base program function.
5687
    // We create a thread to not interrupt the QT framework longer then
5688
    // necessary.
5689
    if (gPageManager)
299 andreas 5690
        gPageManager->mouseEvent(handle, pressed);
289 andreas 5691
}
5692
 
303 andreas 5693
void MainWindow::onInputChanged(ulong handle, string& text)
5694
{
5695
    DECL_TRACER("MainWindow::onInputChanged(ulong handle, string& text)");
5696
 
5697
    try
5698
    {
5699
        std::thread thr = std::thread([=] {
5700
            if (gPageManager)
5701
                gPageManager->inputButtonFinished(handle, text);
5702
        });
5703
 
5704
        thr.detach();
5705
    }
5706
    catch (std::exception& e)
5707
    {
5708
        MSG_ERROR("Error starting a thread to handle input line finish: " << e.what());
5709
    }
5710
}
5711
 
309 andreas 5712
void MainWindow::onFocusChanged(ulong handle, bool in)
5713
{
5714
    DECL_TRACER("MainWindow::onFocusChanged(ulong handle, bool in)");
5715
 
5716
    if (gPageManager)
5717
        gPageManager->inputFocusChanged(handle, in);
5718
}
5719
 
5720
void MainWindow::onCursorChanged(ulong handle, int oldPos, int newPos)
5721
{
5722
    DECL_TRACER("MainWindow::onCursorChanged(ulong handle, int oldPos, int newPos)");
5723
 
5724
    if (gPageManager)
5725
        gPageManager->inputCursorPositionChanged(handle, oldPos, newPos);
5726
}
5727
 
323 andreas 5728
void MainWindow::onGestureEvent(QObject *obj, QGestureEvent *event)
5729
{
5730
    DECL_TRACER("MainWindow::onGestureEvent(QObject *obj, QGestureEvent *event)");
5731
 
5732
    Q_UNUSED(obj);
5733
    gestureEvent(event);
5734
}
5735
 
285 andreas 5736
QPixmap MainWindow::scaleImage(QPixmap& pix)
5737
{
5738
    DECL_TRACER("MainWindow::scaleImage(QPixmap& pix)");
5739
 
5740
    int width = scale(pix.width());
5741
    int height = scale(pix.height());
5742
 
5743
    return pix.scaled(width, height);
5744
}
5745
 
5746
QPixmap MainWindow::scaleImage(unsigned char* buffer, int width, int height, int pixline)
5747
{
5748
    DECL_TRACER("MainWindow::scaleImage(unsigned char* buffer, int width, int height, int pixline)");
5749
 
300 andreas 5750
    if (!buffer || width < 1 || height < 1 || pixline < (width * 4))
5751
    {
5752
        MSG_ERROR("Invalid image for scaling!");
5753
        return QPixmap();
5754
    }
5755
 
285 andreas 5756
    QImage img(buffer, width, height, pixline, QImage::Format_ARGB32);  // Original size
5757
 
5758
    if (img.isNull() || !img.valid(width-1, height-1))
5759
    {
5760
        MSG_ERROR("Unable to create a valid image!");
5761
        return QPixmap();
5762
    }
5763
 
5764
    QSize size(scale(width), scale(height));
5765
    QPixmap pixmap;
5766
    bool ret = false;
5767
 
5768
    if (isScaled())
5769
        ret = pixmap.convertFromImage(img.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); // Scaled size
5770
    else
5771
        ret = pixmap.convertFromImage(img);
5772
 
5773
    if (!ret || pixmap.isNull())
5774
    {
5775
        MSG_ERROR("Unable to create a pixmap out of an image!");
5776
    }
5777
 
5778
    return pixmap;
5779
}
5780
 
2 andreas 5781
#ifndef QT_NO_SESSIONMANAGER
5782
void MainWindow::commitData(QSessionManager &manager)
5783
{
5 andreas 5784
    if (manager.allowsInteraction())
5785
    {
5786
        if (!settingsChanged)
5787
            manager.cancel();
5788
    }
5789
    else
5790
    {
5791
        if (settingsChanged)
5792
            writeSettings();
5793
    }
2 andreas 5794
}
5 andreas 5795
#endif