Subversion Repositories tpanel

Rev

Rev 101 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 101 Rev 107
Line 76... Line 76...
76
extern amx::TAmxNet *gAmxNet;                   //!< Pointer to the class running the thread which handles the communication with the controller.
76
extern amx::TAmxNet *gAmxNet;                   //!< Pointer to the class running the thread which handles the communication with the controller.
77
extern bool _restart_;                          //!< If this is set to true then the whole program will start over.
77
extern bool _restart_;                          //!< If this is set to true then the whole program will start over.
78
extern TPageManager *gPageManager;              //!< The pointer to the global defined main class.
78
extern TPageManager *gPageManager;              //!< The pointer to the global defined main class.
79
std::mutex draw_mutex;                          //!< We're using threads and need to block execution sometimes
79
std::mutex draw_mutex;                          //!< We're using threads and need to block execution sometimes
80
static bool isRunning = false;                  //!< TRUE = the pageManager was started.
80
static bool isRunning = false;                  //!< TRUE = the pageManager was started.
-
 
81
TObject *gObject = nullptr;                     //!< Internal used pointer to a TObject class. (Necessary because of threads!)
81
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
82
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
82
static double gScale = 1.0;                     //!< Global variable holding the scale factor.
83
static double gScale = 1.0;                     //!< Global variable holding the scale factor.
83
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.
84
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.
84
#endif
85
#endif
85
 
86
 
86
using std::bind;
87
using std::bind;
87
using std::pair;
88
using std::pair;
88
using std::string;
89
using std::string;
89
using std::vector;
90
using std::vector;
90
 
91
 
-
 
92
string _NO_OBJECT = "The global class TObject is not available!";
-
 
93
 
91
/**
94
/**
92
 * @brief qtmain is used here as the entry point for the surface.
95
 * @brief qtmain is used here as the entry point for the surface.
93
 *
96
 *
94
 * The main entry function parses the command line parameters, if there were
97
 * The main entry function parses the command line parameters, if there were
95
 * any and sets the basic attributes. It creates the main window and starts the
98
 * any and sets the basic attributes. It creates the main window and starts the
Line 247... Line 250...
247
 */
250
 */
248
MainWindow::MainWindow()
251
MainWindow::MainWindow()
249
{
252
{
250
    DECL_TRACER("MainWindow::MainWindow()");
253
    DECL_TRACER("MainWindow::MainWindow()");
251
 
254
 
-
 
255
    gObject = new TObject;
-
 
256
 
252
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
257
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
253
    setAttribute(Qt::WA_AcceptTouchEvents, true);   // We accept touch events
258
    setAttribute(Qt::WA_AcceptTouchEvents, true);   // We accept touch events
254
    grabGesture(Qt::PinchGesture);                  // We use a pinch gesture to open the settings dialog
259
    grabGesture(Qt::PinchGesture);                  // We use a pinch gesture to open the settings dialog
255
 
260
 
256
    if (gPageManager && gPageManager->getSettings()->getRotate() == 1)  // portrait?
261
    if (gPageManager && gPageManager->getSettings()->getRotate() == 1)  // portrait?
Line 261... Line 266...
261
    else
266
    else
262
    {
267
    {
263
        MSG_INFO("Orientation set to landscape mode.");
268
        MSG_INFO("Orientation set to landscape mode.");
264
        _setOrientation(O_LANDSCAPE);
269
        _setOrientation(O_LANDSCAPE);
265
    }
270
    }
-
 
271
#else
-
 
272
    setWindowIcon(QIcon("logo.png"));
266
#endif
273
#endif
267
    if (!gPageManager)
274
    if (!gPageManager)
268
    {
275
    {
269
        EXCEPTFATALMSG("The class TPageManager was not initialized!");
276
        EXCEPTFATALMSG("The class TPageManager was not initialized!");
270
    }
277
    }
Line 418... Line 425...
418
    {
425
    {
419
        removeToolBar(mToolbar);
426
        removeToolBar(mToolbar);
420
        mToolbar = nullptr;
427
        mToolbar = nullptr;
421
    }
428
    }
422
 
429
 
-
 
430
    if (gObject)
-
 
431
    {
-
 
432
        delete gObject;
-
 
433
        gObject = nullptr;
-
 
434
    }
-
 
435
 
423
    isRunning = false;
436
    isRunning = false;
424
}
437
}
425
 
438
 
426
#ifdef __ANDROID__
439
#ifdef __ANDROID__
427
/**
440
/**
Line 898... Line 911...
898
*/
911
*/
899
void MainWindow::animationFinished()
912
void MainWindow::animationFinished()
900
{
913
{
901
    DECL_TRACER("MainWindow::animationFinished()");
914
    DECL_TRACER("MainWindow::animationFinished()");
902
 
915
 
-
 
916
    if (!gObject)
-
 
917
    {
-
 
918
        MSG_ERROR(_NO_OBJECT);
-
 
919
        return;
-
 
920
    }
-
 
921
 
903
    OBJECT_t *obj = getMarkedRemove();
922
    TObject::OBJECT_t *obj = gObject->getMarkedRemove();
904
 
923
 
905
    while (obj)
924
    while (obj)
906
    {
925
    {
907
        if (obj->animation && obj->animation->state() != QAbstractAnimation::Running)
926
        if (obj->animation && obj->animation->state() != QAbstractAnimation::Running)
908
            break;
927
            break;
909
 
928
 
910
        obj = getNextMarkedRemove(obj);
929
        obj = gObject->getNextMarkedRemove(obj);
911
    }
930
    }
912
 
931
 
913
    if (obj && obj->animation)
932
    if (obj && obj->animation)
914
    {
933
    {
915
        MSG_DEBUG("Dropping object " << handleToString(obj->handle));
934
        MSG_DEBUG("Dropping object " << TObject::handleToString(obj->handle));
916
        delete obj->animation;
935
        delete obj->animation;
917
        obj->animation = nullptr;
936
        obj->animation = nullptr;
918
        dropContent(obj);
937
        gObject->dropContent(obj);
919
 
938
 
920
        if (mLastObject == obj)
939
        if (mLastObject == obj)
921
            mLastObject = nullptr;
940
            mLastObject = nullptr;
922
 
941
 
923
        removeObject(obj->handle);
942
        gObject->removeObject(obj->handle);
924
    }
943
    }
925
    else
944
    else
926
    {
945
    {
927
        MSG_WARNING("No or invalid object to delete!");
946
        MSG_WARNING("No or invalid object to delete!");
928
    }
947
    }
Line 938... Line 957...
938
    {
957
    {
939
        MSG_ERROR("No QTextEdit widget found! External sender?");
958
        MSG_ERROR("No QTextEdit widget found! External sender?");
940
        return;
959
        return;
941
    }
960
    }
942
 
961
 
-
 
962
    if (!gObject)
-
 
963
    {
-
 
964
        MSG_ERROR(_NO_OBJECT);
-
 
965
        return;
-
 
966
    }
-
 
967
 
943
    QString text = edit->toPlainText();
968
    QString text = edit->toPlainText();
944
    WId id = edit->winId();
969
    WId id = edit->winId();
945
    OBJECT_t *obj = findObject(id);
970
    TObject::OBJECT_t *obj = gObject->findObject(id);
946
 
971
 
947
    if (!obj)
972
    if (!obj)
948
    {
973
    {
949
        MSG_ERROR("No object witb WId " << id << " found!");
974
        MSG_ERROR("No object witb WId " << id << " found!");
950
        return;
975
        return;
Line 965... Line 990...
965
    {
990
    {
966
        MSG_ERROR("No QLineEdit widget found! External sender?");
991
        MSG_ERROR("No QLineEdit widget found! External sender?");
967
        return;
992
        return;
968
    }
993
    }
969
 
994
 
-
 
995
    if (!gObject)
-
 
996
    {
-
 
997
        MSG_ERROR(_NO_OBJECT);
-
 
998
        return;
-
 
999
    }
-
 
1000
 
970
    QString text = edit->text();
1001
    QString text = edit->text();
971
    WId id = edit->winId();
1002
    WId id = edit->winId();
972
    OBJECT_t *obj = findObject(id);
1003
    TObject::OBJECT_t *obj = gObject->findObject(id);
973
 
1004
 
974
    if (!obj)
1005
    if (!obj)
975
    {
1006
    {
976
        MSG_ERROR("No object with WId " << id << " found!");
1007
        MSG_ERROR("No object with WId " << id << " found!");
977
        return;
1008
        return;
Line 1111... Line 1142...
1111
    DECL_TRACER("MainWindow::_setVisible(ulong handle, bool state)");
1142
    DECL_TRACER("MainWindow::_setVisible(ulong handle, bool state)");
1112
 
1143
 
1113
    if (prg_stopped)
1144
    if (prg_stopped)
1114
        return;
1145
        return;
1115
 
1146
 
1116
    MSG_DEBUG("Object " << handleToString(handle) << " marked for " << (state ? "VISIBLE" : "INVISIBLE") << " state.");
1147
    MSG_DEBUG("Object " << TObject::handleToString(handle) << " marked for " << (state ? "VISIBLE" : "INVISIBLE") << " state.");
1117
    emit sigSetVisible(handle, state);
1148
    emit sigSetVisible(handle, state);
1118
}
1149
}
1119
 
1150
 
1120
void MainWindow::_setPage(ulong handle, int width, int height)
1151
void MainWindow::_setPage(ulong handle, int width, int height)
1121
{
1152
{
Line 1360... Line 1391...
1360
 
1391
 
1361
/******************* Draw elements *************************/
1392
/******************* Draw elements *************************/
1362
 
1393
 
1363
void MainWindow::displayButton(ulong handle, ulong parent, QByteArray buffer, int width, int height, int pixline, int left, int top)
1394
void MainWindow::displayButton(ulong handle, ulong parent, QByteArray buffer, int width, int height, int pixline, int left, int top)
1364
{
1395
{
1365
    draw_mutex.lock();
-
 
1366
    DECL_TRACER("MainWindow::displayButton(ulong handle, unsigned char* buffer, size_t size, int width, int height, int pixline, int left, int top)");
1396
    DECL_TRACER("MainWindow::displayButton(ulong handle, unsigned char* buffer, size_t size, int width, int height, int pixline, int left, int top)");
1367
 
1397
 
-
 
1398
    if (!gObject)
-
 
1399
    {
-
 
1400
        MSG_ERROR(_NO_OBJECT);
-
 
1401
        return;
-
 
1402
    }
-
 
1403
 
-
 
1404
    draw_mutex.lock();
-
 
1405
 
1368
    if (isScaled())
1406
    if (isScaled())
1369
    {
1407
    {
1370
        MSG_DEBUG("Scaling to factor " << mScaleFactor);
1408
        MSG_DEBUG("Scaling to factor " << mScaleFactor);
1371
    }
1409
    }
1372
 
1410
 
1373
    OBJECT_t *obj = findObject(handle);
1411
    TObject::OBJECT_t *obj = gObject->findObject(handle);
1374
    OBJECT_t *par = findObject(parent);
1412
    TObject::OBJECT_t *par = gObject->findObject(parent);
1375
    MSG_TRACE("Processing button " << handleToString(handle) << " from parent " << handleToString(parent));
1413
    MSG_TRACE("Processing button " << TObject::handleToString(handle) << " from parent " << TObject::handleToString(parent));
1376
 
1414
 
1377
    if (!par)
1415
    if (!par)
1378
    {
1416
    {
1379
        if (TStreamError::checkFilter(HLOG_DEBUG))
1417
        if (TStreamError::checkFilter(HLOG_DEBUG))
1380
            MSG_WARNING("Button " << handleToString(handle) << " has no parent (" << handleToString(parent) << ")! Ignoring it.");
1418
            MSG_WARNING("Button " << TObject::handleToString(handle) << " has no parent (" << TObject::handleToString(parent) << ")! Ignoring it.");
1381
 
1419
 
1382
        draw_mutex.unlock();
1420
        draw_mutex.unlock();
1383
        return;
1421
        return;
1384
    }
1422
    }
1385
 
1423
 
-
 
1424
    if (par->animation && !par->aniDirection)
-
 
1425
    {
-
 
1426
        if (par->animation->state() == QAbstractAnimation::Running)
-
 
1427
        {
-
 
1428
            MSG_WARNING("Object " << TObject::handleToString(parent) << " is busy with an animation!");
-
 
1429
            par->animation->stop();
-
 
1430
        }
-
 
1431
        else
-
 
1432
        {
-
 
1433
            MSG_WARNING("Object " << TObject::handleToString(parent) << " has not finished the animation!");
-
 
1434
        }
-
 
1435
 
-
 
1436
        draw_mutex.unlock();
-
 
1437
        return;
-
 
1438
    }
-
 
1439
    else if (par->remove)
-
 
1440
    {
-
 
1441
        MSG_WARNING("Object " << TObject::handleToString(parent) << " is marked for remove. Will not draw image!");
-
 
1442
        draw_mutex.unlock();
-
 
1443
        return;
-
 
1444
    }
-
 
1445
 
1386
    if (!obj)
1446
    if (!obj)
1387
    {
1447
    {
1388
        MSG_DEBUG("Adding new object " << handleToString(handle) << " ...");
1448
        MSG_DEBUG("Adding new object " << TObject::handleToString(handle) << " ...");
1389
        obj = addObject();
1449
        obj = gObject->addObject();
1390
 
1450
 
1391
        if (!obj)
1451
        if (!obj)
1392
        {
1452
        {
1393
            MSG_ERROR("Error creating an object!");
1453
            MSG_ERROR("Error creating an object!");
1394
            TError::setError();
1454
            TError::setError();
1395
            draw_mutex.unlock();
1455
            draw_mutex.unlock();
1396
            return;
1456
            return;
1397
        }
1457
        }
1398
 
1458
 
1399
        obj->type = OBJ_BUTTON;
1459
        obj->type = TObject::OBJ_BUTTON;
1400
        obj->handle = handle;
1460
        obj->handle = handle;
1401
        obj->width = scale(width);
1461
        obj->width = scale(width);
1402
        obj->height = scale(height);
1462
        obj->height = scale(height);
1403
        obj->left = scale(left);
1463
        obj->left = scale(left);
1404
        obj->top = scale(top);
1464
        obj->top = scale(top);
1405
 
1465
 
1406
        if (par->type == OBJ_PAGE)
1466
        if (par->type == TObject::OBJ_PAGE)
1407
            obj->object.label = new QLabel("", mBackground);
1467
            obj->object.label = new QLabel("", mBackground);
1408
        else
1468
        else
1409
            obj->object.label = new QLabel("", par->object.widget);
1469
            obj->object.label = new QLabel("", par->object.widget);
1410
 
1470
 
1411
        obj->object.label->installEventFilter(this);
1471
        obj->object.label->installEventFilter(this);
Line 1413... Line 1473...
1413
        obj->object.label->setFixedSize(obj->width, obj->height);
1473
        obj->object.label->setFixedSize(obj->width, obj->height);
1414
        obj->object.label->move(obj->left, obj->top);
1474
        obj->object.label->move(obj->left, obj->top);
1415
        obj->object.label->setAttribute(Qt::WA_TransparentForMouseEvents);
1475
        obj->object.label->setAttribute(Qt::WA_TransparentForMouseEvents);
1416
    }
1476
    }
1417
    else
1477
    else
1418
        MSG_DEBUG("Object " << handleToString(handle) << " of type " << objectToString(obj->type) << " found!");
1478
        MSG_DEBUG("Object " << TObject::handleToString(handle) << " of type " << TObject::objectToString(obj->type) << " found!");
1419
 
-
 
1420
//    MSG_DEBUG("Geometry: l:" << obj->left << ", t:" << obj->top << ", w:" << obj->width << ", h:" << obj->height);
-
 
1421
 
1479
 
1422
    try
1480
    try
1423
    {
1481
    {
1424
        if (buffer.size() > 0 && pixline > 0)
1482
        if (buffer.size() > 0 && pixline > 0)
1425
        {
1483
        {
1426
            MSG_DEBUG("Setting image for " << handleToString(handle) << " ...");
1484
            MSG_DEBUG("Setting image for " << TObject::handleToString(handle) << " ...");
1427
            QImage img((unsigned char *)buffer.data(), width, height, pixline, QImage::Format_ARGB32);  // Original size
1485
            QImage img((unsigned char *)buffer.data(), width, height, pixline, QImage::Format_ARGB32);  // Original size
-
 
1486
 
-
 
1487
            if (img.isNull() || !img.valid(width-1, height-1))
-
 
1488
            {
-
 
1489
                MSG_ERROR("Unable to create a valid image!");
-
 
1490
                draw_mutex.unlock();
-
 
1491
                return;
-
 
1492
            }
-
 
1493
 
1428
            QSize size(obj->width, obj->height);
1494
            QSize size(obj->width, obj->height);
1429
            QPixmap pixmap(size);
1495
            QPixmap pixmap;
-
 
1496
            bool ret = false;
1430
 
1497
 
1431
            if (isScaled())
1498
            if (isScaled())
1432
                pixmap.convertFromImage(img.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); // Scaled size
1499
                ret = pixmap.convertFromImage(img.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); // Scaled size
1433
            else
1500
            else
1434
                pixmap.convertFromImage(img);
1501
                ret = pixmap.convertFromImage(img);
1435
 
1502
 
-
 
1503
            if (!ret || pixmap.isNull())
-
 
1504
            {
-
 
1505
                MSG_ERROR("Unable to create a pixmap out of an image!");
-
 
1506
                draw_mutex.unlock();
-
 
1507
                return;
-
 
1508
            }
-
 
1509
 
-
 
1510
            if (obj->object.label)
1436
            obj->object.label->setPixmap(pixmap);
1511
                obj->object.label->setPixmap(pixmap);
-
 
1512
            else
-
 
1513
            {
-
 
1514
                MSG_WARNING("Object " << TObject::handleToString(handle) << " does not exist any more!");
-
 
1515
            }
1437
        }
1516
        }
1438
 
1517
 
1439
    //    if (mHasFocus)
1518
        if (obj->object.label)
1440
            obj->object.label->show();
1519
            obj->object.label->show();
1441
    /*    else
-
 
1442
        {
-
 
1443
            if (par->type == OBJ_PAGE || par->type == OBJ_SUBPAGE)
-
 
1444
                mToShow.insert(std::pair<ulong, QWidget *>(par->handle, par->object.widget));
-
 
1445
        }
-
 
1446
    */
-
 
1447
    }
1520
    }
1448
    catch(std::exception& e)
1521
    catch(std::exception& e)
1449
    {
1522
    {
1450
        MSG_ERROR("Error drawing button " << handleToString(handle) << ": " << e.what());
1523
        MSG_ERROR("Error drawing button " << TObject::handleToString(handle) << ": " << e.what());
1451
    }
1524
    }
1452
    catch(...)
1525
    catch(...)
1453
    {
1526
    {
1454
        MSG_ERROR("Unexpected exception occured [MainWindow::displayButton()]");
1527
        MSG_ERROR("Unexpected exception occured [MainWindow::displayButton()]");
1455
    }
1528
    }
1456
 
1529
 
-
 
1530
    gObject->cleanMarked();     // We want to be sure to have no dead entries.
1457
    draw_mutex.unlock();
1531
    draw_mutex.unlock();
1458
}
1532
}
1459
 
1533
 
1460
void MainWindow::SetVisible(ulong handle, bool state)
1534
void MainWindow::SetVisible(ulong handle, bool state)
1461
{
1535
{
1462
    DECL_TRACER("MainWindow::SetVisible(ulong handle, bool state)");
1536
    DECL_TRACER("MainWindow::SetVisible(ulong handle, bool state)");
1463
 
1537
 
-
 
1538
    if (!gObject)
-
 
1539
    {
-
 
1540
        MSG_ERROR(_NO_OBJECT);
-
 
1541
        return;
-
 
1542
    }
-
 
1543
 
1464
    OBJECT_t *obj = findObject(handle);
1544
    TObject::OBJECT_t *obj = gObject->findObject(handle);
1465
 
1545
 
1466
    if (!obj)
1546
    if (!obj)
1467
    {
1547
    {
1468
        MSG_ERROR("Object " << handleToString(handle) << " not found!");
1548
        MSG_ERROR("Object " << TObject::handleToString(handle) << " not found!");
1469
        return;
1549
        return;
1470
    }
1550
    }
1471
 
1551
 
1472
    if (obj->type == OBJ_BUTTON && obj->object.label)
1552
    if (obj->type == TObject::OBJ_BUTTON && obj->object.label)
1473
    {
1553
    {
1474
        MSG_DEBUG("Setting object " << handleToString(handle) << " visibility to " << (state ? "TRUE" : "FALSE"));
1554
        MSG_DEBUG("Setting object " << TObject::handleToString(handle) << " visibility to " << (state ? "TRUE" : "FALSE"));
1475
        obj->object.label->setVisible(state);
1555
        obj->object.label->setVisible(state);
1476
    }
1556
    }
1477
    else
1557
    else
1478
    {
1558
    {
1479
        MSG_DEBUG("Ignoring non button object " << handleToString(handle));
1559
        MSG_DEBUG("Ignoring non button object " << TObject::handleToString(handle));
1480
    }
1560
    }
1481
}
1561
}
1482
 
1562
 
1483
void MainWindow::setPage(ulong handle, int width, int height)
1563
void MainWindow::setPage(ulong handle, int width, int height)
1484
{
1564
{
1485
    draw_mutex.lock();
-
 
1486
    DECL_TRACER("MainWindow::setPage(ulong handle, int width, int height)");
1565
    DECL_TRACER("MainWindow::setPage(ulong handle, int width, int height)");
1487
 
1566
 
-
 
1567
    if (!gObject)
-
 
1568
    {
-
 
1569
        MSG_ERROR(_NO_OBJECT);
-
 
1570
        return;
-
 
1571
    }
-
 
1572
 
-
 
1573
    draw_mutex.lock();
-
 
1574
 
1488
    QSize qs = menuBar()->sizeHint();
1575
    QSize qs = menuBar()->sizeHint();
1489
    this->setMinimumSize(scale(width), scale(height) + qs.height());
1576
    this->setMinimumSize(scale(width), scale(height) + qs.height());
1490
    OBJECT_t *obj = findObject(handle);
1577
    TObject::OBJECT_t *obj = gObject->findObject(handle);
1491
 
1578
 
1492
    if (!obj)
1579
    if (!obj)
1493
    {
1580
    {
1494
        obj = addObject();
1581
        obj = gObject->addObject();
1495
 
1582
 
1496
        if (!obj)
1583
        if (!obj)
1497
        {
1584
        {
1498
            MSG_ERROR("Error crating an object for handle " << handleToString(handle));
1585
            MSG_ERROR("Error crating an object for handle " << TObject::handleToString(handle));
1499
            TError::setError();
1586
            TError::setError();
1500
            draw_mutex.unlock();
1587
            draw_mutex.unlock();
1501
            return;
1588
            return;
1502
        }
1589
        }
1503
 
1590
 
1504
        obj->handle = handle;
1591
        obj->handle = handle;
1505
        obj->height = scale(height);
1592
        obj->height = scale(height);
1506
        obj->width = scale(width);
1593
        obj->width = scale(width);
1507
        obj->type = OBJ_PAGE;
1594
        obj->type = TObject::OBJ_PAGE;
1508
    }
1595
    }
1509
 
1596
 
1510
    bool newBackground = false;
1597
    bool newBackground = false;
1511
 
1598
 
1512
    if (!mBackground)
1599
    if (!mBackground)
Line 1552... Line 1639...
1552
void MainWindow::setSubPage(ulong handle, int left, int top, int width, int height, ANIMATION_t animate)
1639
void MainWindow::setSubPage(ulong handle, int left, int top, int width, int height, ANIMATION_t animate)
1553
{
1640
{
1554
    draw_mutex.lock();
1641
    draw_mutex.lock();
1555
    DECL_TRACER("MainWindow::setSubPage(ulong handle, int left, int top, int width, int height)");
1642
    DECL_TRACER("MainWindow::setSubPage(ulong handle, int left, int top, int width, int height)");
1556
 
1643
 
-
 
1644
    if (!gObject)
-
 
1645
    {
-
 
1646
        MSG_ERROR(_NO_OBJECT);
-
 
1647
        draw_mutex.unlock();
-
 
1648
        return;
-
 
1649
    }
-
 
1650
 
1557
    if (isScaled())
1651
    if (isScaled())
1558
    {
1652
    {
1559
        MSG_DEBUG("Scaling to factor " << mScaleFactor);
1653
        MSG_DEBUG("Scaling to factor " << mScaleFactor);
1560
    }
1654
    }
1561
 
1655
 
1562
    OBJECT_t *obj = addObject();
1656
    TObject::OBJECT_t *obj = gObject->addObject();
1563
 
1657
 
1564
    if (!obj)
1658
    if (!obj)
1565
    {
1659
    {
1566
        MSG_ERROR("Error adding an object!");
1660
        MSG_ERROR("Error adding an object!");
1567
        TError::setError();
1661
        TError::setError();
Line 1572... Line 1666...
1572
    int scLeft = scale(left);
1666
    int scLeft = scale(left);
1573
    int scTop = scale(top);
1667
    int scTop = scale(top);
1574
    int scWidth = scale(width);
1668
    int scWidth = scale(width);
1575
    int scHeight = scale(height);
1669
    int scHeight = scale(height);
1576
 
1670
 
1577
    obj->type = OBJ_SUBPAGE;
1671
    obj->type = TObject::OBJ_SUBPAGE;
1578
    obj->handle = handle;
1672
    obj->handle = handle;
1579
    obj->object.widget = new QWidget(centralWidget());
1673
    obj->object.widget = new QWidget(centralWidget());
1580
    obj->object.widget->setAutoFillBackground(true);
1674
    obj->object.widget->setAutoFillBackground(true);
1581
    obj->object.widget->setFixedSize(scWidth, scHeight);
1675
    obj->object.widget->setFixedSize(scWidth, scHeight);
1582
    obj->object.widget->move(scLeft, scTop);
1676
    obj->object.widget->move(scLeft, scTop);
Line 1591... Line 1685...
1591
    QPixmap pix(scWidth, scHeight);
1685
    QPixmap pix(scWidth, scHeight);
1592
    pix.fill(QColor::fromRgba(qRgba(0,0,0,0xff)));
1686
    pix.fill(QColor::fromRgba(qRgba(0,0,0,0xff)));
1593
    QPalette palette;
1687
    QPalette palette;
1594
    palette.setBrush(QPalette::Window, QBrush(pix));
1688
    palette.setBrush(QPalette::Window, QBrush(pix));
1595
    obj->object.widget->setPalette(palette);
1689
    obj->object.widget->setPalette(palette);
-
 
1690
    obj->aniDirection = true;
1596
 
1691
 
1597
//    if (mHasFocus)
-
 
1598
//    {
-
 
1599
        startAnimation(obj, animate);
1692
    startAnimation(obj, animate);
1600
//        obj->object.widget->show();
-
 
1601
/*    }
-
 
1602
    else
-
 
1603
        mToShow.insert(std::pair<ulong, QWidget *>(handle, obj->object.widget));
-
 
1604
*/
-
 
1605
    draw_mutex.unlock();
1693
    draw_mutex.unlock();
1606
}
1694
}
1607
 
1695
 
1608
void MainWindow::setBackground(ulong handle, QByteArray image, size_t rowBytes, int width, int height, ulong color)
1696
void MainWindow::setBackground(ulong handle, QByteArray image, size_t rowBytes, int width, int height, ulong color)
1609
{
1697
{
1610
    draw_mutex.lock();
1698
    draw_mutex.lock();
1611
    DECL_TRACER("MainWindow::setBackground(ulong handle, QByteArray image, size_t rowBytes, ulong color)");
1699
    DECL_TRACER("MainWindow::setBackground(ulong handle, QByteArray image, size_t rowBytes, ulong color)");
1612
 
1700
 
-
 
1701
    if (!gObject)
-
 
1702
    {
-
 
1703
        MSG_ERROR(_NO_OBJECT);
-
 
1704
        draw_mutex.unlock();
-
 
1705
        return;
-
 
1706
    }
-
 
1707
 
-
 
1708
 
1613
    OBJECT_t *obj = findObject(handle);
1709
    TObject::OBJECT_t *obj = gObject->findObject(handle);
1614
 
1710
 
1615
    if (!obj)
1711
    if (!obj)
1616
    {
1712
    {
1617
        MSG_WARNING("No object " << handleToString(handle) << " found!");
1713
        MSG_WARNING("No object " << TObject::handleToString(handle) << " found!");
1618
        draw_mutex.unlock();
1714
        draw_mutex.unlock();
1619
        return;
1715
        return;
1620
    }
1716
    }
1621
 
1717
 
1622
    MSG_TRACE("Object " << handleToString(handle) << " of type " << objectToString(obj->type) << " found!");
1718
    MSG_TRACE("Object " << TObject::handleToString(handle) << " of type " << gObject->objectToString(obj->type) << " found!");
1623
 
1719
 
1624
    if (obj->type == OBJ_BUTTON || obj->type == OBJ_SUBPAGE)
1720
    if (obj->type == TObject::OBJ_BUTTON || obj->type == TObject::OBJ_SUBPAGE)
1625
    {
1721
    {
1626
        MSG_DEBUG("Processing object " << objectToString(obj->type));
1722
        MSG_DEBUG("Processing object " << gObject->objectToString(obj->type));
1627
        QPixmap pix(obj->width, obj->height);
1723
        QPixmap pix(obj->width, obj->height);
1628
        pix.fill(QColor::fromRgba(qRgba(TColor::getRed(color),TColor::getGreen(color),TColor::getBlue(color),TColor::getAlpha(color))));
1724
        pix.fill(QColor::fromRgba(qRgba(TColor::getRed(color),TColor::getGreen(color),TColor::getBlue(color),TColor::getAlpha(color))));
1629
 
1725
 
1630
        if (image.size() > 0)
1726
        if (image.size() > 0)
1631
        {
1727
        {
Line 1639... Line 1735...
1639
            }
1735
            }
1640
            else
1736
            else
1641
                pix.convertFromImage(img);
1737
                pix.convertFromImage(img);
1642
        }
1738
        }
1643
 
1739
 
1644
        if (obj->type == OBJ_BUTTON)
1740
        if (obj->type == TObject::OBJ_BUTTON)
1645
        {
1741
        {
1646
            obj->object.label->setPixmap(pix);
1742
            obj->object.label->setPixmap(pix);
1647
 
1743
 
1648
            if (mHasFocus)
1744
            if (mHasFocus)
1649
                obj->object.label->show();
1745
                obj->object.label->show();
Line 1653... Line 1749...
1653
            MSG_DEBUG("Setting image as background for page " << ((handle >> 16) & 0x0000ffff));
1749
            MSG_DEBUG("Setting image as background for page " << ((handle >> 16) & 0x0000ffff));
1654
            QPalette palette;
1750
            QPalette palette;
1655
            palette.setBrush(QPalette::Window, QBrush(pix));
1751
            palette.setBrush(QPalette::Window, QBrush(pix));
1656
            obj->object.widget->setPalette(palette);
1752
            obj->object.widget->setPalette(palette);
1657
 
1753
 
1658
//            if (mHasFocus)
-
 
1659
                obj->object.widget->show();
1754
            obj->object.widget->show();
1660
//            else
-
 
1661
//                mToShow.insert(std::pair<ulong, QWidget *>(handle, obj->object.widget));
-
 
1662
        }
1755
        }
1663
    }
1756
    }
1664
    else if (obj->type == OBJ_PAGE)
1757
    else if (obj->type == TObject::OBJ_PAGE)
1665
    {
1758
    {
1666
        bool newBackground = false;
1759
        bool newBackground = false;
1667
 
1760
 
1668
        if (!mBackground)
1761
        if (!mBackground)
1669
        {
1762
        {
Line 1709... Line 1802...
1709
void MainWindow::dropPage(ulong handle)
1802
void MainWindow::dropPage(ulong handle)
1710
{
1803
{
1711
    draw_mutex.lock();
1804
    draw_mutex.lock();
1712
    DECL_TRACER("MainWindow::dropPage(ulong handle)");
1805
    DECL_TRACER("MainWindow::dropPage(ulong handle)");
1713
 
1806
 
-
 
1807
    if (!gObject)
-
 
1808
    {
-
 
1809
        MSG_ERROR(_NO_OBJECT);
-
 
1810
        draw_mutex.unlock();
-
 
1811
        return;
-
 
1812
    }
-
 
1813
 
1714
    removeAllChilds(handle);
1814
    gObject->removeAllChilds(handle);
1715
    removeObject(handle);
1815
    gObject->removeObject(handle);
1716
 
1816
 
1717
    if (mBackground)
1817
    if (mBackground)
1718
    {
1818
    {
1719
        delete mBackground;
1819
        delete mBackground;
1720
        mBackground = nullptr;
1820
        mBackground = nullptr;
Line 1726... Line 1826...
1726
void MainWindow::dropSubPage(ulong handle)
1826
void MainWindow::dropSubPage(ulong handle)
1727
{
1827
{
1728
    draw_mutex.lock();
1828
    draw_mutex.lock();
1729
    DECL_TRACER("MainWindow::dropSubPage(ulong handle)");
1829
    DECL_TRACER("MainWindow::dropSubPage(ulong handle)");
1730
 
1830
 
-
 
1831
    if (!gObject)
-
 
1832
    {
-
 
1833
        MSG_ERROR(_NO_OBJECT);
-
 
1834
        draw_mutex.unlock();
-
 
1835
        return;
-
 
1836
    }
-
 
1837
 
1731
    removeAllChilds(handle);
1838
    gObject->removeAllChilds(handle);
1732
    OBJECT_t *obj = findObject(handle);
1839
    TObject::OBJECT_t *obj = gObject->findObject(handle);
1733
 
1840
 
1734
    if (!obj)
1841
    if (!obj)
1735
    {
1842
    {
1736
        MSG_WARNING("Object " << handleToString(handle) << " does not exist. Ignoring!");
1843
        MSG_WARNING("Object " << TObject::handleToString(handle) << " does not exist. Ignoring!");
1737
        draw_mutex.unlock();
1844
        draw_mutex.unlock();
1738
        return;
1845
        return;
1739
    }
1846
    }
1740
 
1847
 
-
 
1848
    obj->aniDirection = false;
1741
    startAnimation(obj, obj->animate, false);
1849
    startAnimation(obj, obj->animate, false);
1742
    OBJECT_t *o = mLastObject;
1850
    TObject::OBJECT_t *o = mLastObject;
1743
 
1851
 
1744
    if (obj->animate.hideEffect == SE_NONE || !o)
1852
    if (obj->animate.hideEffect == SE_NONE || !o)
1745
    {
1853
    {
1746
        dropContent(obj);
1854
        gObject->dropContent(obj);
1747
        removeObject(handle);
1855
        gObject->removeObject(handle);
1748
    }
1856
    }
1749
 
1857
 
1750
    draw_mutex.unlock();
1858
    draw_mutex.unlock();
1751
}
1859
}
1752
 
1860
 
1753
void MainWindow::dropButton(ulong handle)
1861
void MainWindow::dropButton(ulong handle)
1754
{
1862
{
1755
    draw_mutex.lock();
1863
    draw_mutex.lock();
1756
    DECL_TRACER("MainWindow::dropButton(ulong handle)");
1864
    DECL_TRACER("MainWindow::dropButton(ulong handle)");
1757
 
1865
 
-
 
1866
    if (!gObject)
-
 
1867
    {
-
 
1868
        MSG_ERROR(_NO_OBJECT);
-
 
1869
        draw_mutex.unlock();
-
 
1870
        return;
-
 
1871
    }
-
 
1872
 
1758
    OBJECT_t *obj = findObject(handle);
1873
    TObject::OBJECT_t *obj = gObject->findObject(handle);
1759
 
1874
 
1760
    if (!obj)
1875
    if (!obj)
1761
    {
1876
    {
1762
        MSG_WARNING("Object " << handleToString(handle) << " does not exist. Ignoring!");
1877
        MSG_WARNING("Object " << TObject::handleToString(handle) << " does not exist. Ignoring!");
1763
        draw_mutex.unlock();
1878
        draw_mutex.unlock();
1764
        return;
1879
        return;
1765
    }
1880
    }
1766
 
1881
 
1767
    if (obj->type == OBJ_BUTTON && obj->object.label)
1882
    if (obj->type == TObject::OBJ_BUTTON && obj->object.label)
1768
    {
1883
    {
1769
        obj->object.label->close();
1884
        obj->object.label->close();
1770
        obj->object.label = nullptr;
1885
        obj->object.label = nullptr;
1771
    }
1886
    }
1772
 
1887
 
1773
    removeObject(handle);
1888
    gObject->removeObject(handle);
1774
    draw_mutex.unlock();
1889
    draw_mutex.unlock();
1775
}
1890
}
1776
 
1891
 
1777
void MainWindow::playVideo(ulong handle, ulong parent, int left, int top, int width, int height, const string& url, const string& user, const string& pw)
1892
void MainWindow::playVideo(ulong handle, ulong parent, int left, int top, int width, int height, const string& url, const string& user, const string& pw)
1778
{
1893
{
1779
    draw_mutex.lock();
1894
    draw_mutex.lock();
1780
    DECL_TRACER("MainWindow::playVideo(ulong handle, const string& url, const string& user, const string& pw))");
1895
    DECL_TRACER("MainWindow::playVideo(ulong handle, const string& url, const string& user, const string& pw))");
1781
 
1896
 
-
 
1897
    if (!gObject)
-
 
1898
    {
-
 
1899
        MSG_ERROR(_NO_OBJECT);
-
 
1900
        draw_mutex.unlock();
-
 
1901
        return;
-
 
1902
    }
-
 
1903
 
1782
    OBJECT_t *obj = findObject(handle);
1904
    TObject::OBJECT_t *obj = gObject->findObject(handle);
1783
    OBJECT_t *par = findObject(parent);
1905
    TObject::OBJECT_t *par = gObject->findObject(parent);
1784
    MSG_TRACE("Processing button " << handleToString(handle) << " from parent " << handleToString(parent));
1906
    MSG_TRACE("Processing button " << TObject::handleToString(handle) << " from parent " << TObject::handleToString(parent));
1785
 
1907
 
1786
    if (!par)
1908
    if (!par)
1787
    {
1909
    {
1788
        MSG_WARNING("Button has no parent! Ignoring it.");
1910
        MSG_WARNING("Button has no parent! Ignoring it.");
1789
        draw_mutex.unlock();
1911
        draw_mutex.unlock();
Line 1791... Line 1913...
1791
    }
1913
    }
1792
 
1914
 
1793
    if (!obj)
1915
    if (!obj)
1794
    {
1916
    {
1795
        MSG_DEBUG("Adding new video object ...");
1917
        MSG_DEBUG("Adding new video object ...");
1796
        obj = addObject();
1918
        obj = gObject->addObject();
1797
 
1919
 
1798
        if (!obj)
1920
        if (!obj)
1799
        {
1921
        {
1800
            MSG_ERROR("Error creating a video object!");
1922
            MSG_ERROR("Error creating a video object!");
1801
            TError::setError();
1923
            TError::setError();
1802
            draw_mutex.unlock();
1924
            draw_mutex.unlock();
1803
            return;
1925
            return;
1804
        }
1926
        }
1805
 
1927
 
1806
        obj->type = OBJ_VIDEO;
1928
        obj->type = TObject::OBJ_VIDEO;
1807
        obj->handle = handle;
1929
        obj->handle = handle;
1808
        obj->width = width;
1930
        obj->width = width;
1809
        obj->height = height;
1931
        obj->height = height;
1810
        obj->left = left;
1932
        obj->left = left;
1811
        obj->top = top;
1933
        obj->top = top;
1812
        obj->object.vwidget = new QVideoWidget(par->object.widget);
1934
        obj->object.vwidget = new QVideoWidget(par->object.widget);
1813
        obj->object.vwidget->installEventFilter(this);
1935
        obj->object.vwidget->installEventFilter(this);
1814
    }
1936
    }
1815
    else
1937
    else
1816
        MSG_DEBUG("Object " << handleToString(handle) << " of type " << objectToString(obj->type) << " found!");
1938
        MSG_DEBUG("Object " << TObject::handleToString(handle) << " of type " << gObject->objectToString(obj->type) << " found!");
1817
 
1939
 
1818
    QMediaPlaylist *playlist = new QMediaPlaylist;
1940
    QMediaPlaylist *playlist = new QMediaPlaylist;
1819
    QUrl qurl(url.c_str());
1941
    QUrl qurl(url.c_str());
1820
 
1942
 
1821
    if (!user.empty())
1943
    if (!user.empty())
Line 1827... Line 1949...
1827
    playlist->addMedia(qurl);
1949
    playlist->addMedia(qurl);
1828
    obj->player = new QMediaPlayer;
1950
    obj->player = new QMediaPlayer;
1829
    obj->player->setPlaylist(playlist);
1951
    obj->player->setPlaylist(playlist);
1830
    obj->player->setVideoOutput(obj->object.vwidget);
1952
    obj->player->setVideoOutput(obj->object.vwidget);
1831
 
1953
 
1832
//    if (mHasFocus)
-
 
1833
//    {
-
 
1834
        obj->object.vwidget->show();
1954
    obj->object.vwidget->show();
1835
        obj->player->play();
1955
    obj->player->play();
1836
//    }
-
 
1837
}
1956
}
1838
 
1957
 
1839
void MainWindow::inputText(Button::TButton* button, QByteArray buf, int width, int height, size_t pixline)
1958
void MainWindow::inputText(Button::TButton* button, QByteArray buf, int width, int height, size_t pixline)
1840
{
1959
{
1841
    DECL_TRACER("MainWindow::inputText(Button::TButton* button)");
1960
    DECL_TRACER("MainWindow::inputText(Button::TButton* button)");
1842
 
1961
 
-
 
1962
    if (!gObject)
-
 
1963
    {
-
 
1964
        MSG_ERROR(_NO_OBJECT);
-
 
1965
        return;
-
 
1966
    }
-
 
1967
 
1843
    if (!button)
1968
    if (!button)
1844
    {
1969
    {
1845
        MSG_WARNING("No valid button!");
1970
        MSG_WARNING("No valid button!");
1846
        return;
1971
        return;
1847
    }
1972
    }
1848
 
1973
 
1849
    ulong handle = button->getHandle();
1974
    ulong handle = button->getHandle();
1850
    ulong parent = button->getParent();
1975
    ulong parent = button->getParent();
1851
    OBJECT_t *obj = findObject(handle);
1976
    TObject::OBJECT_t *obj = gObject->findObject(handle);
1852
    OBJECT_t *par = findObject(parent);
1977
    TObject::OBJECT_t *par = gObject->findObject(parent);
1853
    MSG_TRACE("Processing button " << handleToString(handle) << " from parent " << handleToString(parent));
1978
    MSG_TRACE("Processing button " << TObject::handleToString(handle) << " from parent " << gObject->handleToString(parent));
1854
 
1979
 
1855
    if (!par)
1980
    if (!par)
1856
    {
1981
    {
1857
        MSG_WARNING("Button has no parent! Ignoring it.");
1982
        MSG_WARNING("Button has no parent! Ignoring it.");
1858
        return;
1983
        return;
1859
    }
1984
    }
1860
 
1985
 
1861
    if (!obj)
1986
    if (!obj)
1862
    {
1987
    {
1863
        MSG_DEBUG("Adding new input object ...");
1988
        MSG_DEBUG("Adding new input object ...");
1864
        obj = addObject();
1989
        obj = gObject->addObject();
1865
 
1990
 
1866
        if (!obj)
1991
        if (!obj)
1867
        {
1992
        {
1868
            MSG_ERROR("Error creating an input object!");
1993
            MSG_ERROR("Error creating an input object!");
1869
            TError::setError();
1994
            TError::setError();
1870
            return;
1995
            return;
1871
        }
1996
        }
1872
 
1997
 
1873
        obj->type = OBJ_INPUT;
1998
        obj->type = TObject::OBJ_INPUT;
1874
        obj->handle = handle;
1999
        obj->handle = handle;
1875
        obj->width = scale(width);
2000
        obj->width = scale(width);
1876
        obj->height = scale(height);
2001
        obj->height = scale(height);
1877
        obj->left = scale(button->getLeftPosition());
2002
        obj->left = scale(button->getLeftPosition());
1878
        obj->top = scale(button->getTopPosition());
2003
        obj->top = scale(button->getTopPosition());
Line 2000... Line 2125...
2000
 
2125
 
2001
            obj->object.multitext->show();
2126
            obj->object.multitext->show();
2002
        }
2127
        }
2003
    }
2128
    }
2004
    else
2129
    else
2005
        MSG_DEBUG("Object " << handleToString(handle) << " of type " << objectToString(obj->type) << " found!");
2130
        MSG_DEBUG("Object " << TObject::handleToString(handle) << " of type " << gObject->objectToString(obj->type) << " found!");
2006
}
2131
}
2007
 
2132
 
2008
void MainWindow::showKeyboard(const std::string& init, const std::string& prompt, bool priv)
2133
void MainWindow::showKeyboard(const std::string& init, const std::string& prompt, bool priv)
2009
{
2134
{
2010
    DECL_TRACER("MainWindow::showKeyboard(std::string &init, std::string &prompt, bool priv)");
2135
    DECL_TRACER("MainWindow::showKeyboard(std::string &init, std::string &prompt, bool priv)");
Line 2235... Line 2360...
2235
        return value;
2360
        return value;
2236
 
2361
 
2237
    return (int)((double)value * mScaleFactor);
2362
    return (int)((double)value * mScaleFactor);
2238
}
2363
}
2239
 
2364
 
2240
void MainWindow::startAnimation(OBJECT_t* obj, ANIMATION_t& ani, bool in)
2365
void MainWindow::startAnimation(TObject::OBJECT_t* obj, ANIMATION_t& ani, bool in)
2241
{
2366
{
2242
    DECL_TRACER("MainWindow::startAnimation(OBJECT_t* obj, ANIMATION_t& ani)");
2367
    DECL_TRACER("MainWindow::startAnimation(OBJECT_t* obj, ANIMATION_t& ani)");
2243
 
2368
 
-
 
2369
    if (!obj)
-
 
2370
    {
-
 
2371
        MSG_ERROR("Got no object to start the animation!");
-
 
2372
        return;
-
 
2373
    }
-
 
2374
 
2244
    SHOWEFFECT_t effect;
2375
    SHOWEFFECT_t effect;
2245
    int scLeft = obj->left;
2376
    int scLeft = obj->left;
2246
    int scTop = obj->top;
2377
    int scTop = obj->top;
2247
    int scWidth = obj->width;
2378
    int scWidth = obj->width;
2248
    int scHeight = obj->height;
2379
    int scHeight = obj->height;
Line 2258... Line 2389...
2258
    if (effect == SE_NONE)
2389
    if (effect == SE_NONE)
2259
        return;
2390
        return;
2260
 
2391
 
2261
    if (effect == SE_FADE)
2392
    if (effect == SE_FADE)
2262
    {
2393
    {
-
 
2394
        MSG_DEBUG("Fading object " << TObject::handleToString(obj->handle) << (in ? " IN" : " OUT"));
2263
        QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect(obj->object.widget);
2395
        QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect(obj->object.widget);
2264
        obj->object.widget->setGraphicsEffect(effect);
2396
        obj->object.widget->setGraphicsEffect(effect);
2265
        obj->animation = new QPropertyAnimation(effect, "opacity");
2397
        obj->animation = new QPropertyAnimation(effect, "opacity");
2266
    }
2398
    }
2267
    else
2399
    else
2268
    {
2400
    {
-
 
2401
        MSG_DEBUG("Moving object " << TObject::handleToString(obj->handle) << (in ? " IN" : " OUT"));
2269
        obj->animation = new QPropertyAnimation(obj->object.widget);
2402
        obj->animation = new QPropertyAnimation(obj->object.widget);
2270
        obj->animation->setTargetObject(obj->object.widget);
2403
        obj->animation->setTargetObject(obj->object.widget);
2271
    }
2404
    }
2272
 
2405
 
2273
    if (in)
2406
    if (in)