Subversion Repositories tpanel

Rev

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

Rev 319 Rev 320
Line 1148... Line 1148...
1148
 
1148
 
1149
/*****************************************************************************
1149
/*****************************************************************************
1150
 * Signals and overwritten functions start here
1150
 * Signals and overwritten functions start here
1151
 *****************************************************************************/
1151
 *****************************************************************************/
1152
 
1152
 
-
 
1153
void TQScrollArea::scrollContentsBy(int dx, int dy)
-
 
1154
{
-
 
1155
    DECL_TRACER("TQScrollArea::scrollContentsBy(int dx, int dy)");
-
 
1156
 
-
 
1157
    QScrollArea::scrollContentsBy(dx, dy);      // First let the original class do it's job.
-
 
1158
    QScrollBar *sbar = nullptr;
-
 
1159
 
-
 
1160
    if (mVertical)
-
 
1161
        sbar = verticalScrollBar();
-
 
1162
    else
-
 
1163
        sbar = horizontalScrollBar();
-
 
1164
 
-
 
1165
    if (sbar)
-
 
1166
    {
-
 
1167
        mActPosition = sbar->value();
-
 
1168
        MSG_DEBUG("Actual slider position: " << mActPosition);
-
 
1169
 
-
 
1170
        if (mScrollbar && mScrollbarOffset > 0 && mActPosition < mScrollbarOffset)
-
 
1171
        {
-
 
1172
            sbar->setSliderPosition(mScrollbarOffset);
-
 
1173
            mActPosition = sbar->value();
-
 
1174
        }
-
 
1175
    }
-
 
1176
}
-
 
1177
 
1153
void TQScrollArea::mouseMoveEvent(QMouseEvent* event)
1178
void TQScrollArea::mouseMoveEvent(QMouseEvent* event)
1154
{
1179
{
1155
    DECL_TRACER("TQScrollArea::mouseMoveEvent(QMouseEvent* event)");
1180
    DECL_TRACER("TQScrollArea::mouseMoveEvent(QMouseEvent* event)");
1156
 
1181
 
1157
    mMousePress = false;
1182
    mMousePress = false;
1158
    mMouseScroll = true;
1183
    mMouseScroll = true;
-
 
1184
    mDoMouseEvent = false;
1159
 
1185
 
1160
    if (mMousePressTimer && mMousePressTimer->isActive())
1186
    if (mMousePressTimer && mMousePressTimer->isActive())
1161
        mMousePressTimer->stop();
1187
        mMousePressTimer->stop();
1162
 
1188
 
1163
    int move = 0;
1189
    int move = 0;
Line 1201... Line 1227...
1201
                int value = bar->value();
1227
                int value = bar->value();
1202
                int newValue = value + (move * -1);
1228
                int newValue = value + (move * -1);
1203
 
1229
 
1204
                if (newValue >= 0 && newValue != value)
1230
                if (newValue >= 0 && newValue != value)
1205
                    bar->setValue(newValue);
1231
                    bar->setValue(newValue);
1206
 
-
 
1207
                MSG_DEBUG("Moving mouse to value " << newValue << " (old: " << value << "). Step is " << move);
-
 
1208
            }
1232
            }
1209
        }
1233
        }
1210
    }
1234
    }
1211
 
1235
 
1212
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
1236
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
Line 1218... Line 1242...
1218
 
1242
 
1219
void TQScrollArea::mousePressEvent(QMouseEvent* event)
1243
void TQScrollArea::mousePressEvent(QMouseEvent* event)
1220
{
1244
{
1221
    DECL_TRACER("TQScrollArea::mousePressEvent(QMouseEvent* event)");
1245
    DECL_TRACER("TQScrollArea::mousePressEvent(QMouseEvent* event)");
1222
 
1246
 
1223
    if (!event || mMouseScroll)
1247
    if (!event || mMouseScroll || event->button() != Qt::LeftButton)
1224
        return;
1248
        return;
1225
 
1249
 
1226
    if (event->button() == Qt::LeftButton)
-
 
1227
    {
-
 
1228
        mMousePress = true;
1250
    mMousePress = true;
1229
        mOldPoint.setX(0.0);
1251
    mOldPoint.setX(0.0);
1230
        mOldPoint.setY(0.0);
1252
    mOldPoint.setY(0.0);
1231
 
1253
 
1232
        int x = 0, y = 0;
1254
    int x = 0, y = 0;
1233
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
1255
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
1234
        x = event->pos().x();
1256
    x = event->pos().x();
1235
        y = event->pos().y();
1257
    y = event->pos().y();
1236
#else
1258
#else
1237
        x = event->position().x();
1259
    x = event->position().x();
1238
        y = event->position().y();
1260
    y = event->position().y();
1239
#endif
1261
#endif
1240
        mLastMousePress.setX(x);
1262
    mLastMousePress.setX(x);
1241
        mLastMousePress.setY(y);
1263
    mLastMousePress.setY(y);
1242
 
-
 
1243
        MSG_DEBUG("Mouse press event at " << x << " x " << y << " // " << event->globalX() << " x " << event->globalY());
-
 
1244
        /*
-
 
1245
         * Here we're starting a timer with 200 ms. If after this time the
-
 
1246
         * mouse button is still pressed and no scroll event was detected,
-
 
1247
         * then we've a real click.
-
 
1248
         * In case of a real click the method mouseTimerEvent() will call a
-
 
1249
         * signal to inform the parent about the click.
-
 
1250
         */
-
 
1251
        mClick = true;
-
 
1252
 
-
 
1253
        if (!mMousePressTimer)
-
 
1254
        {
-
 
1255
            mMousePressTimer = new QTimer(this);
-
 
1256
            connect(mMousePressTimer, &QTimer::timeout, this, &TQScrollArea::mouseTimerEvent);
-
 
1257
        }
-
 
1258
 
1264
 
-
 
1265
    MSG_DEBUG("Mouse press event at " << x << " x " << y << " // " << event->globalX() << " x " << event->globalY());
-
 
1266
    /*
-
 
1267
        * Here we're starting a timer with 200 ms. If after this time the
-
 
1268
        * mouse button is still pressed and no scroll event was detected,
1259
        mMousePressTimer->start(200);
1269
        * then we've a real click.
-
 
1270
        * In case of a real click the method mouseTimerEvent() will call a
-
 
1271
        * signal to inform the parent about the click.
1260
    }
1272
        */
-
 
1273
    mClick = true;  // This means PRESSED state
-
 
1274
    mMouseTmEventActive = true;
-
 
1275
    mDoMouseEvent = true;
-
 
1276
    QTimer::singleShot(200, this, &TQScrollArea::mouseTimerEvent);
1261
}
1277
}
1262
 
1278
 
1263
void TQScrollArea::mouseReleaseEvent(QMouseEvent* event)
1279
void TQScrollArea::mouseReleaseEvent(QMouseEvent* event)
1264
{
1280
{
1265
    DECL_TRACER("TQScrollArea::mouseReleaseEvent(QMouseEvent* event)");
1281
    DECL_TRACER("TQScrollArea::mouseReleaseEvent(QMouseEvent* event)");
1266
 
1282
 
1267
    if (!event)
1283
    if (!event || event->button() != Qt::LeftButton)
1268
        return;
1284
        return;
1269
 
1285
 
1270
    if(event->button() == Qt::LeftButton)
-
 
1271
    {
-
 
1272
        if (mMousePressTimer && mMousePressTimer->isActive())
-
 
1273
        {
-
 
1274
            mMousePressTimer->stop();
1286
    mDoMouseEvent = false;
1275
 
1287
 
1276
            if (!mMouseScroll)
-
 
1277
            {
-
 
1278
                mClick = true;
-
 
1279
                mouseTimerEvent();
1288
    if (mMouseTmEventActive)
1280
                mClick = false;
-
 
1281
                mouseTimerEvent();
-
 
1282
            }
-
 
1283
        }
1289
    {
1284
        else if (!mMouseScroll && mClick)
1290
        if (!mMouseScroll)
1285
        {
1291
        {
-
 
1292
            mClick = true;      // This means PRESSED state
1286
            mClick = false;
1293
            doMouseEvent();
-
 
1294
            mClick = false;     // This means RELEASED state
1287
            mouseTimerEvent();
1295
            doMouseEvent();
1288
        }
1296
        }
1289
 
-
 
1290
        mMousePress = false;
-
 
1291
        mMouseScroll = false;
-
 
1292
        mOldPoint.setX(0.0);
-
 
1293
        mOldPoint.setY(0.0);
-
 
1294
    }
1297
    }
1295
}
-
 
1296
 
-
 
1297
void TQScrollArea::scrollContentsBy(int dx, int dy)
-
 
1298
{
-
 
1299
    DECL_TRACER("TQScrollArea::scrollContentsBy(int dx, int dy)");
-
 
1300
 
-
 
1301
    QScrollArea::scrollContentsBy(dx, dy);      // First let the original class do it's job.
-
 
1302
    QScrollBar *sbar = nullptr;
-
 
1303
 
-
 
1304
    if (mVertical)
-
 
1305
        sbar = verticalScrollBar();
1298
    else if (!mMouseScroll && mClick)
1306
    else
-
 
1307
        sbar = horizontalScrollBar();
-
 
1308
 
-
 
1309
    if (sbar)
-
 
1310
    {
1299
    {
1311
        mActPosition = sbar->value();
-
 
1312
        MSG_DEBUG("Actual slider position: " << mActPosition);
1300
        mClick = false;         // This means RELEASED state
1313
 
-
 
1314
        if (mScrollbar && mScrollbarOffset > 0 && mActPosition < mScrollbarOffset)
-
 
1315
        {
-
 
1316
            sbar->setSliderPosition(mScrollbarOffset);
-
 
1317
            mActPosition = sbar->value();
1301
        doMouseEvent();
1318
        }
-
 
1319
    }
1302
    }
-
 
1303
 
-
 
1304
    mMousePress = false;
-
 
1305
    mMouseScroll = false;
-
 
1306
    mOldPoint.setX(0.0);
-
 
1307
    mOldPoint.setY(0.0);
1320
}
1308
}
1321
 
1309
 
1322
void TQScrollArea::mouseTimerEvent()
1310
void TQScrollArea::doMouseEvent()
1323
{
1311
{
1324
    DECL_TRACER("TQScrollArea::mouseTimerEvent()");
1312
    DECL_TRACER("TQScrollArea::doMouseEvent()");
1325
 
-
 
1326
    if (mMousePressTimer && mMousePressTimer->isActive())
-
 
1327
        mMousePressTimer->stop();
-
 
1328
 
1313
 
1329
    if (!mMousePress || mMouseScroll)
1314
    if (!mMousePress || mMouseScroll || !mMain)
1330
        return;
1315
        return;
1331
 
1316
 
-
 
1317
    QWidget *w = nullptr;
-
 
1318
 
1332
    if (mMain)
1319
    if (mVertical)
-
 
1320
        w = mMain->childAt(mLastMousePress.x(), mActPosition + mLastMousePress.y());
1333
    {
1321
    else
1334
        QWidget *w = nullptr;
1322
        w = mMain->childAt(mActPosition + mLastMousePress.x(), mLastMousePress.y());
1335
 
1323
 
1336
        if (mVertical)
1324
    if (!w)
1337
            w = mMain->childAt(mLastMousePress.x(), mActPosition + mLastMousePress.y());
-
 
1338
        else
1325
        return;
1339
            w = mMain->childAt(mActPosition + mLastMousePress.x(), mLastMousePress.y());
-
 
1340
 
1326
 
1341
        if (w)
-
 
1342
        {
-
 
1343
            QString obname = w->objectName();
1327
    QString obname = w->objectName();
1344
            ulong handle = extractHandle(obname.toStdString());
1328
    ulong handle = extractHandle(obname.toStdString());
1345
 
1329
 
1346
            if (!handle)
1330
    if (!handle)
1347
                return;
1331
        return;
1348
 
1332
 
1349
            // We must make sure the found object is not marked as pass through.
1333
    // We must make sure the found object is not marked as pass through.
1350
            // Because of this we'll scan the items for the handle and if we
1334
    // Because of this we'll scan the items for the handle and if we
1351
            // find that it is marked as pass through we must look for another
1335
    // find that it is marked as pass through we must look for another
1352
            // one on the same position. If there is none, the click is ignored.
1336
    // one on the same position. If there is none, the click is ignored.
1353
            //
1337
    //
1354
            // Find the object in our list
1338
    // Find the object in our list
1355
            vector<_ITEMS_T>::iterator iter;
1339
    vector<_ITEMS_T>::iterator iter;
1356
            QRect rect;
1340
    QRect rect;
1357
            bool call = true;
1341
    bool call = true;
1358
 
1342
 
1359
            for (iter = mItems.begin(); iter != mItems.end(); ++iter)
1343
    for (iter = mItems.begin(); iter != mItems.end(); ++iter)
1360
            {
1344
    {
1361
                if (iter->handle == handle)     // Handle found?
1345
        if (iter->handle == handle)     // Handle found?
1362
                {                               // Yes, then ...
1346
        {                               // Yes, then ...
1363
                    if (iter->bounding == "passThru")   // Item marked as pass through?
1347
            if (iter->bounding == "passThru")   // Item marked as pass through?
1364
                    {                                   // Yes, then start to search for another item
1348
            {                                   // Yes, then start to search for another item
1365
                        rect = w->rect();
1349
                rect = w->rect();
1366
                        call = false;
1350
                call = false;
1367
                        // Walk through the childs to find another one on the
1351
                // Walk through the childs to find another one on the
1368
                        // clicked position.
1352
                // clicked position.
1369
                        QObjectList ol = mMain->children(); // Get list of all objects
1353
                QObjectList ol = mMain->children(); // Get list of all objects
1370
                        QList<QObject *>::iterator obiter;  // Define an iterator
1354
                QList<QObject *>::iterator obiter;  // Define an iterator
1371
                        // Loop through all objects
1355
                // Loop through all objects
1372
                        for (obiter = ol.begin(); obiter != ol.end(); ++obiter)
1356
                for (obiter = ol.begin(); obiter != ol.end(); ++obiter)
1373
                        {
1357
                {
1374
                            QObject *object = *obiter;
1358
                    QObject *object = *obiter;
1375
 
1359
 
1376
                            if (object->objectName() != obname && object->objectName().startsWith("Label_"))    // Have we found a QLabel object?
1360
                    if (object->objectName() != obname && object->objectName().startsWith("Label_"))    // Have we found a QLabel object?
1377
                            {                                                                                   // Yes, then test it's position
1361
                    {                                                                                   // Yes, then test it's position
1378
                                QLabel *lb = dynamic_cast<QLabel *>(object);    // Cast the object to a QLabel
1362
                        QLabel *lb = dynamic_cast<QLabel *>(object);    // Cast the object to a QLabel
1379
 
1363
 
1380
                                if (lb->rect().contains(mLastMousePress))       // Is the QLabel under the mouse coordinates?
1364
                        if (lb->rect().contains(mLastMousePress))       // Is the QLabel under the mouse coordinates?
1381
                                {                                               // Yes, then select it.
1365
                        {                                               // Yes, then select it.
1382
                                    ulong h = extractHandle(lb->objectName().toStdString());  // Get the handle
1366
                            ulong h = extractHandle(lb->objectName().toStdString());  // Get the handle
1383
 
1367
 
1384
                                    if (!h)
1368
                            if (!h)
1385
                                        break;
1369
                                break;
1386
 
1370
 
1387
                                    handle = h;
1371
                            handle = h;
1388
                                    // Reset the main loop
1372
                            // Reset the main loop
1389
                                    iter = mItems.begin();
1373
                            iter = mItems.begin();
1390
                                    break;
-
 
1391
                                }
1374
                            break;
1392
                            }
-
 
1393
                        }
1375
                        }
1394
                    }
1376
                    }
1395
                    else
-
 
1396
                        call = true;
-
 
1397
                }
1377
                }
1398
            }
1378
            }
1399
 
-
 
1400
            if (call)
1379
            else
1401
            {
1380
            {
1402
                MSG_DEBUG("Calling signal with handle " << (handle >> 16 & 0x0000ffff) << ":" << (handle & 0x0000ffff) << ": STATE=" << (mClick ? "PRESSED" : "RELEASED"));
1381
                call = true;
1403
                emit objectClicked(handle, mClick);
1382
                break;
1404
            }
1383
            }
1405
        }
1384
        }
1406
    }
1385
    }
-
 
1386
 
-
 
1387
    if (call)
-
 
1388
    {
-
 
1389
        MSG_DEBUG("Calling signal with handle " << (handle >> 16 & 0x0000ffff) << ":" << (handle & 0x0000ffff) << ": STATE=" << (mClick ? "PRESSED" : "RELEASED"));
-
 
1390
        emit objectClicked(handle, mClick);
-
 
1391
        mClick = false;
-
 
1392
    }
-
 
1393
}
-
 
1394
 
-
 
1395
void TQScrollArea::mouseTimerEvent()
-
 
1396
{
-
 
1397
    DECL_TRACER("TQScrollArea::mouseTimerEvent()");
-
 
1398
 
-
 
1399
    if (!mDoMouseEvent)
-
 
1400
        return;
-
 
1401
 
-
 
1402
    mDoMouseEvent = false;
-
 
1403
 
-
 
1404
    if (mClick)         // Only if PRESSED
-
 
1405
        doMouseEvent();
-
 
1406
 
-
 
1407
    mMouseTmEventActive = false;
1407
}
1408
}
1408
 
1409