Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
285 andreas 1
/*
2
 * Copyright (C) 2023 by Andreas Theofilu <andreas@theosys.at>
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
 
19
#include <QWidget>
20
#include <QScrollArea>
21
#include <QPixmap>
22
#include <QColor>
23
#include <QPainter>
24
#include <QVBoxLayout>
25
#include <QHBoxLayout>
26
#include <QLabel>
27
#include <QPoint>
28
#include <QMouseEvent>
29
#include <QScrollBar>
289 andreas 30
#include <QTimer>
285 andreas 31
 
32
#include "tqscrollarea.h"
33
#include "terror.h"
34
#include "tresources.h"
35
 
36
using std::vector;
37
 
288 andreas 38
/**
39
 * @brief TQScrollArea::TQScrollArea
40
 * Constructor for the class.
41
 */
285 andreas 42
TQScrollArea::TQScrollArea()
43
{
44
    DECL_TRACER("TQScrollArea::TQScrollArea()");
45
}
46
 
288 andreas 47
/**
48
 * @brief TQScrollArea::TQScrollArea
49
 * @param parent    The parent widget
50
 */
285 andreas 51
TQScrollArea::TQScrollArea(QWidget* parent)
52
    : mParent(parent)
53
{
54
    DECL_TRACER("TQScrollArea::TQScrollArea(QWidget* parent)");
55
 
56
    if (parent)
57
    {
58
        mWidth = parent->geometry().width();
59
        mHeight = parent->geometry().height();
60
    }
61
 
62
    init();
63
}
64
 
288 andreas 65
/**
66
 * @brief TQScrollArea::TQScrollArea
67
 * @param parent        Parent widget
68
 * @param w             Visible width in pixels
69
 * @param h             Visible height in pixels
70
 * @param vertical      TRUE: Scrolling in vertical direction
71
 */
285 andreas 72
TQScrollArea::TQScrollArea(QWidget* parent, int w, int h, bool vertical)
73
    : mParent(parent),
74
      mVertical(vertical)
75
{
76
    DECL_TRACER("TQScrollArea::TQScrollArea(QWidget* parent, int w, int h, bool vertical)");
77
 
78
    if (w > 0)
79
        mWidth = w;
80
 
81
    if (h > 0)
82
        mHeight = h;
83
 
84
    init();
85
}
86
 
288 andreas 87
/**
88
 * @brief TQScrollArea::TQScrollArea
89
 * @param parent    Parent widget
90
 * @param size      Size (width and height) of visible area
91
 * @param vertical  TRUE: Scrolling in vertical direction
92
 */
285 andreas 93
TQScrollArea::TQScrollArea(QWidget* parent, const QSize& size, bool vertical)
94
    : mParent(parent),
95
      mVertical(vertical)
96
{
97
    DECL_TRACER("TQScrollArea::TQScrollArea(QWidget* parent, const QSize& size, bool vertical)");
98
 
99
    if (size.width() > 0)
100
        mWidth = size.width();
101
 
102
    if (size.height() > 0)
103
        mHeight = size.height();
104
 
105
    init();
106
}
107
 
108
TQScrollArea::~TQScrollArea()
109
{
110
    DECL_TRACER("TQScrollArea::~TQScrollArea()");
288 andreas 111
 
112
    if (mMain)
113
        mMain->close();
289 andreas 114
 
115
    if (mMousePressTimer)
116
    {
117
        if (mMousePressTimer->isActive())
118
            mMousePressTimer->stop();
119
 
296 andreas 120
        disconnect(mMousePressTimer, &QTimer::timeout, this, &TQScrollArea::mouseTimerEvent);
289 andreas 121
        delete mMousePressTimer;
122
        mMousePressTimer = nullptr;
123
    }
285 andreas 124
}
125
 
126
void TQScrollArea::init()
127
{
128
    DECL_TRACER("TQScrollArea::init()");
129
 
130
    QScrollArea::setParent(mParent);
293 andreas 131
    QScrollArea::setViewportMargins(0, 0, 0, 0);
132
 
133
    if (mWidth > 0 || mHeight > 0)
134
        QScrollArea::setFixedSize(mWidth, mHeight);
135
 
285 andreas 136
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
137
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
138
    // Set a transparent background
286 andreas 139
    QPalette palette(this->palette());
319 andreas 140
    palette.setColor(QPalette::Window, Qt::transparent);
286 andreas 141
    setPalette(palette);
285 andreas 142
 
143
    if (!mMain)
289 andreas 144
        mMain = new QWidget(this);
285 andreas 145
 
289 andreas 146
    mMain->move(0, 0);
293 andreas 147
    mMain->setContentsMargins(0, 0, 0, 0);
289 andreas 148
 
285 andreas 149
    if (mWidth && mHeight)
150
        setFixedSize(mWidth, mHeight);
151
 
152
    setWidget(mMain);
153
 
154
    if (mVertical && !mVLayout)
295 andreas 155
    {
285 andreas 156
        mVLayout = new QVBoxLayout(mMain);
295 andreas 157
        mVLayout->setSpacing(0);
158
        mVLayout->setContentsMargins(0, 0, 0, 0);
159
    }
288 andreas 160
    else if (!mVertical && !mHLayout)
295 andreas 161
    {
285 andreas 162
        mHLayout = new QHBoxLayout(mMain);
295 andreas 163
        mHLayout->setSpacing(0);
164
        mHLayout->setContentsMargins(0, 0, 0, 0);
165
    }
289 andreas 166
 
295 andreas 167
 
289 andreas 168
    if (!mTotalWidth)
169
        mTotalWidth = mWidth;
170
 
171
    if (!mTotalHeight)
172
        mTotalHeight = mHeight;
285 andreas 173
}
174
 
288 andreas 175
/**
176
 * @brief TQScrollArea::setObjectName
177
 * This sets the object name of the internal main QWidget.
178
 *
179
 * @param name  The name of the object.
180
 */
285 andreas 181
void TQScrollArea::setObjectName(const QString& name)
182
{
183
    DECL_TRACER("TQScrollArea::setObjectName(const QString& name)");
184
 
185
    if (mMain)
186
        mMain->setObjectName(name);
187
}
188
 
288 andreas 189
/**
190
 * @brief TQScrollArea::setSize
191
 * Sets the size of the visible area of the object.
192
 *
193
 * @param w     The width in pixels
194
 * @param h     The height in pixels
195
 */
285 andreas 196
void TQScrollArea::setSize(int w, int h)
197
{
198
    DECL_TRACER("TQScrollArea::setSize(int w, int h)");
199
 
200
    if (w < 1 || h < 1)
201
        return;
202
 
203
    mWidth = w;
204
    mHeight = h;
288 andreas 205
    setFixedSize(mWidth, mHeight);
285 andreas 206
}
207
 
288 andreas 208
/**
209
 * @brief TQScrollArea::setSize
210
 * Sets the size of the visible area of the object.
211
 *
212
 * @param size  The size (width and height)
213
 */
285 andreas 214
void TQScrollArea::setSize(QSize size)
215
{
216
    DECL_TRACER("TQScrollArea::setSize(QSize size)");
217
 
218
    mWidth = size.width();
219
    mHeight = size.height();
220
    setFixedSize(mWidth, mHeight);
221
}
222
 
288 andreas 223
/**
224
 * @brief TQScrollArea::getSize
225
 * Returns the size of the visible area.
226
 *
227
 * @return A QSize object containg the size in pixels.
228
 */
285 andreas 229
QSize TQScrollArea::getSize()
230
{
231
    DECL_TRACER("TQScrollArea::getSize()");
232
 
233
    return QSize(mWidth, mHeight);
234
}
235
 
318 andreas 236
/**
237
 * @brief TQScrollArea::setScrollbar
238
 * Makes the scrollbar visible or invisible.
239
 *
240
 * @param sb    TRUE: The scrollbar is set to visible. It depends on the type
241
 *              of scroll area. On vertical areas the bottom scrollbar may
242
 *              become visible and on horizontal areas the right one.
243
 */
300 andreas 244
void TQScrollArea::setScrollbar(bool sb)
245
{
246
    DECL_TRACER("TQScrollArea::setScrollbar(bool sb)");
247
 
248
    if (sb == mScrollbar)
249
        return;
250
 
251
    mScrollbar = sb;
252
 
253
    if (sb)
254
    {
255
        if (mVertical)
256
            setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
257
        else
258
            setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
259
    }
260
    else
261
    {
262
        if (mVertical)
263
            setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
264
        else
265
            setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
266
    }
267
}
268
 
318 andreas 269
/**
270
 * @brief TQScrollArea::setScrollbarOffset
271
 * Positions the scrollbar to the \b offset position. On a vertical scroll
272
 * area the offset is alway the top visible pixel line and on horizontal
273
 * scroll areas it is the left visible pixel.
274
 *
275
 * @param offset    The offset position. If this is less then 0 or grater then
276
 *                  the whole size, the value is ignored.
277
 */
300 andreas 278
void TQScrollArea::setScrollbarOffset(int offset)
279
{
280
    DECL_TRACER("TQScrollArea::setScrollbarOffset(int offset)");
281
 
282
    if (!mScrollbar)
283
        return;
284
 
319 andreas 285
    if (offset <= 0)
300 andreas 286
        mScrollbarOffset = 0;
319 andreas 287
    else
288
        mScrollbarOffset = scale(offset);
300 andreas 289
 
290
    QScrollBar *sbar = nullptr;
291
 
292
    if (mVertical)
293
        sbar = verticalScrollBar();
294
    else
295
        sbar = horizontalScrollBar();
296
 
297
    if (sbar)
319 andreas 298
    {
299
        if (mScrollbarOffset > (mVertical ? sbar->pos().y() : sbar->pos().x()))
300
            mScrollbarOffset = (mVertical ? sbar->pos().y() : sbar->pos().x());
301
 
300 andreas 302
        sbar->setSliderPosition(mScrollbarOffset);
319 andreas 303
    }
300 andreas 304
}
305
 
318 andreas 306
/**
307
 * @brief TQScrollArea::setAnchor
308
 * Sets the anchor position. This can be left, center or right for horizontal
309
 * scroll areas or top, center or bottom for vertical.
310
 * The anchor position is the one the items scroll to if they should appear at
311
 * this position. The center position is the default one.
312
 *
313
 * @param position  Defines the anchor position.
314
 */
300 andreas 315
void TQScrollArea::setAnchor(Button::SUBVIEW_POSITION_t position)
316
{
317
    DECL_TRACER("TQScrollArea::setAnchor(Button::SUBVIEW_POSITION_t position)");
318
 
319
    mPosition = position;
319 andreas 320
 
321
    if (!mWrapItems)
322
    {
323
        QWidget *w = mMain->childAt(mWidth / 2, mHeight / 2);
324
 
325
        if (w)
326
            setPosition(w, 0);
327
    }
328
    else
329
        setPosition();
300 andreas 330
}
331
 
318 andreas 332
/**
333
 * @brief TQScrollArea::show
334
 * Shows all items in the scroll area. If some were invisible or not enabled,
335
 * they are visible and enabled. Depending on the set anchor position the
336
 * whole area is set to it. This means for example, that the center item is
337
 * moved into the view area if the anchor position is set to SVP_CENTER.
338
 */
297 andreas 339
void TQScrollArea::show()
340
{
341
    DECL_TRACER("TQScrollArea::show()");
342
 
298 andreas 343
    if (!QScrollArea::isEnabled())
344
        QScrollArea::setEnabled(true);
345
 
297 andreas 346
    QScrollArea::show();
347
 
348
    if (mMain)
298 andreas 349
    {
350
        if (!mMain->isEnabled())
351
            mMain->setEnabled(true);
352
 
353
        if (!mMain->isVisible())
354
            mMain->show();
355
    }
302 andreas 356
 
319 andreas 357
    if (mWrapItems)
358
        setPosition();
297 andreas 359
}
360
 
288 andreas 361
/**
362
 * @brief TQScrollArea::setTotalWidth
363
 * Sets the total width of the scrolling area. This must be equal or grater
364
 * then the width of the visible area.
365
 *
366
 * @param w The width in pixels.
367
 */
285 andreas 368
void TQScrollArea::setTotalWidth(int w)
369
{
370
    DECL_TRACER("TQScrollArea::setTotalWidth(int w)");
371
 
372
    if (!mMain || w < mWidth)
373
        return;
374
 
375
    mTotalWidth = w;
288 andreas 376
    mMain->setFixedWidth(mTotalWidth);
285 andreas 377
}
378
 
288 andreas 379
/**
380
 * @brief TQScrollArea::setTotalHeight
381
 * Sets the total height of the scrolling area. This must be equal or grater
382
 * then the height of the visible area.
383
 *
384
 * @param h  The height in pixels.
385
 */
285 andreas 386
void TQScrollArea::setTotalHeight(int h)
387
{
388
    DECL_TRACER("TQScrollArea::setTotalHeight(int h)");
389
 
390
    if (!mMain || h < mHeight)
391
        return;
392
 
393
    mTotalHeight = h;
288 andreas 394
    mMain->setFixedHeight(mTotalHeight);
285 andreas 395
}
396
 
288 andreas 397
/**
398
 * @brief TQScrollArea::setTotalSize
399
 * Sets the total size of the scrolling area. The width and height must be
400
 * equal or grater then the width and height of the visible area.
401
 *
402
 * @param w  The width in pixels.
403
 * @param h  The height in pixels.
404
 */
285 andreas 405
void TQScrollArea::setTotalSize(int w, int h)
406
{
407
    DECL_TRACER("TQScrollArea::setTotalSize(int w, int h)");
408
 
409
    if (!mMain || w < mWidth || h < mHeight)
410
        return;
411
 
412
    mTotalWidth = w;
413
    mTotalHeight = h;
288 andreas 414
    mMain->setFixedSize(mTotalWidth, mTotalHeight);
285 andreas 415
}
416
 
288 andreas 417
/**
418
 * @brief TQScrollArea::setTotalSize
419
 * Sets the total size of the scrolling area in pixels.
420
 *
421
 * @param size  The total size of the scrolling area.
422
 */
285 andreas 423
void TQScrollArea::setTotalSize(QSize& size)
424
{
425
    DECL_TRACER("TQScrollArea::setTotalSize(QSize& size)");
426
 
427
    if (!mMain || size.width() < mWidth || size.height() < mHeight)
428
        return;
429
 
430
    mTotalWidth = size.width();
431
    mTotalHeight = size.height();
288 andreas 432
    mMain->setFixedSize(mTotalWidth, mTotalHeight);
285 andreas 433
}
434
 
288 andreas 435
/**
436
 * @brief TQScrollArea::setBackgroundImage
437
 * This sets the background image of the scroll area. If the pixmap is smaller
438
 * then the total size, the image is painted in tiles.
439
 *
440
 * @param pix       The pixmap.
441
 */
285 andreas 442
void TQScrollArea::setBackgroundImage(const QPixmap& pix)
443
{
444
    DECL_TRACER("TQScrollArea::setBackgroundImage(const QPixmap& pix)");
445
 
446
    if (!mMain || pix.isNull())
447
        return;
448
 
449
    QPalette palette(mMain->palette());
450
    palette.setBrush(QPalette::Window, QBrush(pix));
451
    mMain->setPalette(palette);
452
}
453
 
288 andreas 454
/**
455
 * @brief TQScrollArea::setBackGroundColor
456
 * Sets the background color of the scroll area.
457
 *
458
 * @param color     The color
459
 */
285 andreas 460
void TQScrollArea::setBackGroundColor(QColor color)
461
{
462
    DECL_TRACER("TQScrollArea::setBackGroundColor(QColor color)");
463
 
464
    if (!mMain)
465
        return;
466
 
467
    QPalette palette(mMain->palette());
468
    palette.setColor(QPalette::Window, color);
469
    mMain->setPalette(palette);
470
}
471
 
288 andreas 472
/**
473
 * @brief TQScrollArea::setSpace
474
 * Sets the space between the items in percent. The pixels are calculated
475
 * from the total size of the scroll area. Then the spce is inserted.
476
 *
477
 * @param s     A value between 0 and 99. 0 Removes the space.
478
 */
285 andreas 479
void TQScrollArea::setSpace(int s)
480
{
481
    DECL_TRACER("TQScrollArea::setSpace(double s)");
482
 
318 andreas 483
    if (s < 0 || s > 99 || mSpace == s)
285 andreas 484
        return;
485
 
486
    mSpace = s;
318 andreas 487
    refresh();
285 andreas 488
}
489
 
288 andreas 490
/**
491
 * @brief TQScrollArea::addItem
492
 * Adds one item to the list of items.
493
 *
494
 * @param item  Item to add
495
 */
285 andreas 496
void TQScrollArea::addItem(PGSUBVIEWITEM_T& item)
497
{
498
    DECL_TRACER("TQScrollArea::addItem(PGSUBVIEWITEM_T& item)");
499
 
319 andreas 500
    _clearAllItems();
501
    resetSlider();
318 andreas 502
    mItems.push_back(subViewItemToItem(item));
503
    _addItems(mItems, true);
288 andreas 504
}
285 andreas 505
 
318 andreas 506
/**
507
 * @brief TQScrollArea::addItems
508
 * Adds one or more items to the scroll area and sizes the scroll area large
509
 * enough to hold all items. It calculates also the space between the items.
510
 * If there were already some items visible, they are deleted first. Then they
511
 * are displayed again.
512
 *
513
 * @param items     A list of items to be displayed
514
 * @param intern    TRUE: The list of items is not stored internal.
515
 */
288 andreas 516
void TQScrollArea::addItems(std::vector<PGSUBVIEWITEM_T>& items)
517
{
318 andreas 518
    DECL_TRACER("TQScrollArea::addItems(std::vector<PGSUBVIEWITEM_T>& items, bool intern)");
285 andreas 519
 
288 andreas 520
    if (items.empty())
521
        return;
285 andreas 522
 
319 andreas 523
    _clearAllItems();
524
    resetSlider();
525
    mItems.clear();
285 andreas 526
 
318 andreas 527
    vector<PGSUBVIEWITEM_T>::iterator iter;
285 andreas 528
 
318 andreas 529
    for (iter = items.begin(); iter != items.end(); ++iter)
530
        mItems.push_back(subViewItemToItem(*iter));
531
 
532
    _addItems(mItems, true);
533
}
534
 
535
void TQScrollArea::_addItems(std::vector<_ITEMS_T>& items, bool intern)
536
{
537
    DECL_TRACER("_addItems(std::vector<ITEMS_T>& items, bool intern)");
538
 
319 andreas 539
    mWrapItems = items[0].wrap;     // Endless scroll
318 andreas 540
 
541
    if (!intern)
319 andreas 542
        mItems = items;             // Store the items to the internal vector array
318 andreas 543
 
288 andreas 544
    if (mVertical)
545
        mTotalHeight = 0;
285 andreas 546
    else
288 andreas 547
        mTotalWidth = 0;
285 andreas 548
 
319 andreas 549
    int total = 0;                  // The total width or height
318 andreas 550
    vector<_ITEMS_T>::iterator iter;
285 andreas 551
    // First calculate the total width and height if it was not set by a previous call
552
    if ((mTotalWidth <= 0 && !mVertical) || (mTotalHeight <= 0 && mVertical))
553
    {
554
        if (mTotalWidth <= 0)
555
            mTotalWidth = mWidth;
556
 
557
        if (mTotalHeight <= 0)
558
            mTotalHeight = mHeight;
559
 
560
        if (!mVertical || mTotalWidth <= 0)
561
            mTotalWidth = 0;
562
 
563
        if (mVertical || mTotalHeight <= 0)
564
            mTotalHeight = 0;
565
 
289 andreas 566
        int num = 0;
567
 
285 andreas 568
        for (iter = items.begin(); iter != items.end(); ++iter)
569
        {
570
            if (!mVertical)
571
                mTotalWidth += iter->width;
572
            else
573
                mTotalHeight += iter->height;
289 andreas 574
 
575
            num++;
285 andreas 576
        }
577
 
578
        if (mVertical)
288 andreas 579
        {
580
            mTotalHeight = scale(mTotalHeight);
285 andreas 581
            total = mTotalHeight;
288 andreas 582
        }
285 andreas 583
        else
288 andreas 584
        {
585
            mTotalWidth = scale(mTotalWidth);
285 andreas 586
            total = mTotalWidth;
288 andreas 587
        }
285 andreas 588
 
288 andreas 589
        if (mMain)
590
            mMain->setFixedSize(mTotalWidth, mTotalHeight);
285 andreas 591
    }
592
 
289 andreas 593
    MSG_DEBUG("Number of items: " << items.size());
594
 
285 andreas 595
    if (mSpace > 0)
596
    {
597
        int space = (int)((double)total / 100.0 * (double)mSpace);
598
 
288 andreas 599
        if (space > 0 && mVertical && mVLayout && mMain)
600
        {
289 andreas 601
            int newHeight = space + mTotalHeight;
602
            mMain->setFixedHeight(newHeight);
603
            MSG_DEBUG("Calculated space: " << space << " (" << mSpace << "%). Total height: " << newHeight << ", Old total height: " << mTotalHeight);
604
            mTotalHeight = newHeight;
288 andreas 605
        }
606
        else if (space > 0 && !mVertical && mHLayout && mMain)
607
        {
289 andreas 608
            int newWidth = space + mTotalWidth;
609
            mMain->setFixedWidth(newWidth);
610
            MSG_DEBUG("Calculated space: " << space << " (" << mSpace << "%). Total width: " << newWidth << ", Old total width: " << mTotalWidth);
611
            mTotalWidth = newWidth;
288 andreas 612
        }
285 andreas 613
    }
614
 
615
    for (iter = items.begin(); iter != items.end(); ++iter)
616
    {
287 andreas 617
        int iWidth = scale(iter->width);
618
        int iHeight = scale(iter->height);
289 andreas 619
        QWidget *item = new QWidget;
285 andreas 620
        item->setObjectName(QString("Item_%1").arg(handleToString(iter->handle).c_str()));
287 andreas 621
        item->setFixedSize(iWidth, iHeight);
285 andreas 622
        item->setAutoFillBackground(true);
289 andreas 623
        QColor bgcolor(qRgba(iter->bgcolor.red, iter->bgcolor.green, iter->bgcolor.blue, iter->bgcolor.alpha));
285 andreas 624
 
625
        if (iter->image.getSize() > 0)
626
        {
287 andreas 627
            QPixmap pixmap(iWidth, iHeight);
289 andreas 628
 
629
            if (iter->bgcolor.alpha == 0)
630
                pixmap.fill(Qt::transparent);
631
            else
632
                pixmap.fill(bgcolor);
633
 
287 andreas 634
            QImage img(iter->image.getBitmap(), iter->image.getWidth(), iter->image.getHeight(), iter->image.getPixline(), QImage::Format_ARGB32);  // Original size
285 andreas 635
            bool ret = false;
636
 
287 andreas 637
            if (mScaleFactor != 1.0)
638
            {
289 andreas 639
                QSize size(iWidth, iHeight);
640
                ret = pixmap.convertFromImage(img.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));   // Scaled size
287 andreas 641
            }
642
            else
643
                ret = pixmap.convertFromImage(img);
285 andreas 644
 
645
            if (!ret || pixmap.isNull())
646
            {
647
                MSG_ERROR("Unable to create a pixmap out of an image!");
648
                return;
649
            }
650
 
651
            QPalette palette(item->palette());
652
            palette.setBrush(QPalette::Window, QBrush(pixmap));
653
            item->setPalette(palette);
654
        }
655
        else
289 andreas 656
        {
657
            QPalette palette(item->palette());
658
 
659
            if (iter->bgcolor.alpha == 0)
660
                palette.setColor(QPalette::Window, Qt::transparent);
661
            else
662
                palette.setColor(QPalette::Window, bgcolor);
663
 
664
            item->setPalette(palette);
665
        }
666
 
285 andreas 667
        // Add the buttons to the item widget
668
        if (iter->atoms.empty())
669
        {
670
            delete item;
671
            continue;
672
        }
673
 
674
        vector<PGSUBVIEWATOM_T>::iterator itAtom;
675
 
676
        for (itAtom = iter->atoms.begin(); itAtom != iter->atoms.end(); ++itAtom)
677
        {
287 andreas 678
            int scaWidth = scale(itAtom->width);
679
            int scaHeight = scale(itAtom->height);
285 andreas 680
 
681
            QLabel *label = new QLabel(item);
287 andreas 682
            label->move(scale(itAtom->left), scale(itAtom->top));
285 andreas 683
            label->setFixedSize(scaWidth, scaHeight);
684
            label->setObjectName(QString("Label_%1").arg(handleToString(itAtom->handle).c_str()));
300 andreas 685
            setAtom(*itAtom, label);
686
        }
285 andreas 687
 
318 andreas 688
        iter->item = item;
289 andreas 689
 
300 andreas 690
        if (mVertical && mVLayout)
691
            mVLayout->addWidget(item);
692
        else if (!mVertical && mHLayout)
693
            mHLayout->addWidget(item);
694
        else
695
        {
696
            MSG_ERROR("Layout not initialized!");
697
        }
698
    }
319 andreas 699
 
700
    if (mOldActPosition > 0)
701
    {
702
        MSG_DEBUG("Setting position to old value " << mOldActPosition);
703
        resetSlider(mOldActPosition);
704
        mOldActPosition = 0;
705
    }
300 andreas 706
}
289 andreas 707
 
318 andreas 708
/**
709
 * @brief TQScrollArea::updateItem
710
 * Updates one item.
711
 *
712
 * @param item  The item to update.
713
 */
300 andreas 714
void TQScrollArea::updateItem(PGSUBVIEWITEM_T& item)
715
{
716
    DECL_TRACER("TQScrollArea::updateItem(PGSUBVIEWITEM_T& item)");
285 andreas 717
 
300 andreas 718
    if (mItems.empty())
719
        return;
285 andreas 720
 
318 andreas 721
    vector<_ITEMS_T>::iterator iter;
289 andreas 722
 
300 andreas 723
    for (iter = mItems.begin(); iter != mItems.end(); ++iter)
724
    {
725
        if (iter->handle == item.handle)
726
        {
727
            iter->bgcolor = item.bgcolor;
728
            iter->bounding = item.bounding;
729
            iter->image = item.image;
318 andreas 730
            iter->atoms = item.atoms;
300 andreas 731
 
318 andreas 732
            if (!iter->atoms.empty())
289 andreas 733
            {
318 andreas 734
                QObjectList list = iter->item->children();
735
                QList<QObject *>::Iterator obit;
736
                vector<PGSUBVIEWATOM_T>::iterator atit;
285 andreas 737
 
318 andreas 738
                for (atit = iter->atoms.begin(); atit != iter->atoms.end(); ++atit)
300 andreas 739
                {
318 andreas 740
                    for (obit = list.begin(); obit != list.end(); ++obit)
741
                    {
742
                        QObject *o = *obit;
743
                        QString obname = o->objectName();
744
                        ulong atHandle = extractHandle(obname.toStdString());
289 andreas 745
 
318 andreas 746
                        if (atit->handle == atHandle && obname.startsWith("Label_"))
300 andreas 747
                        {
318 andreas 748
                            QLabel *lbl = dynamic_cast<QLabel *>(o);
749
                            setAtom(*atit, lbl);
750
                            break;
300 andreas 751
                        }
752
                    }
753
                }
319 andreas 754
 
755
                iter->item->show();
289 andreas 756
            }
300 andreas 757
 
758
            break;
285 andreas 759
        }
300 andreas 760
    }
761
}
285 andreas 762
 
300 andreas 763
void TQScrollArea::showItem(ulong handle, int position)
764
{
765
    DECL_TRACER("TQScrollArea::showItem(ulong handle, int position)");
288 andreas 766
 
318 andreas 767
    if (mItems.empty())
301 andreas 768
        return;
769
 
318 andreas 770
    vector<_ITEMS_T>::iterator iter;
300 andreas 771
 
318 andreas 772
    for (iter = mItems.begin(); iter != mItems.end(); ++iter)
300 andreas 773
    {
318 andreas 774
        if (!iter->item)
775
            continue;
776
 
319 andreas 777
        if (iter->handle == handle)
285 andreas 778
        {
318 andreas 779
            if (!iter->item->isVisible())
780
                iter->item->setVisible(true);
300 andreas 781
 
318 andreas 782
            setPosition(iter->item, position);
783
            break;
784
        }
785
    }
786
}
301 andreas 787
 
318 andreas 788
void TQScrollArea::toggleItem(ulong handle, int position)
789
{
790
    DECL_TRACER("TQScrollArea::toggleItem(ulong handle, int position)");
302 andreas 791
 
318 andreas 792
    if (mItems.empty())
793
        return;
302 andreas 794
 
318 andreas 795
    vector<_ITEMS_T>::iterator iter;
302 andreas 796
 
318 andreas 797
    for (iter = mItems.begin(); iter != mItems.end(); ++iter)
798
    {
799
        if (iter->handle == handle && iter->item)
800
        {
801
            if (iter->item->isVisible())
802
                iter->item->setVisible(false);
803
            else
319 andreas 804
            {
318 andreas 805
                iter->item->setVisible(true);
319 andreas 806
                setPosition(iter->item, position);
807
            }
302 andreas 808
 
319 andreas 809
            break;
318 andreas 810
        }
811
    }
812
}
302 andreas 813
 
318 andreas 814
void TQScrollArea::hideAllItems()
815
{
816
    DECL_TRACER("TQScrollArea::hideAllItems()");
302 andreas 817
 
318 andreas 818
    if (mItems.empty())
819
        return;
300 andreas 820
 
319 andreas 821
    resetSlider();
318 andreas 822
    vector<_ITEMS_T>::iterator iter;
823
 
824
    for (iter = mItems.begin(); iter != mItems.end(); ++iter)
825
    {
826
        if (iter->item)
827
            iter->item->setVisible(false);
828
    }
829
}
830
 
831
void TQScrollArea::hideItem(ulong handle)
832
{
833
    DECL_TRACER("TQScrollArea::hideItem(ulong handle)");
834
 
835
    if (mItems.empty())
836
        return;
837
 
838
    vector<_ITEMS_T>::iterator iter;
839
 
840
    for (iter = mItems.begin(); iter != mItems.end(); ++iter)
841
    {
842
        if (iter->handle == handle && iter->item)
843
        {
844
            iter->item->setVisible(false);
845
            return;
285 andreas 846
        }
847
    }
848
}
849
 
287 andreas 850
int TQScrollArea::scale(int value)
851
{
439 andreas 852
//    DECL_TRACER("TQScrollArea::scale(int value)");
287 andreas 853
 
854
    if (mScaleFactor != 1.0)
855
        return (int)((double)value * mScaleFactor);
856
 
857
    return value;
858
}
859
 
860
void TQScrollArea::setScaleFactor(const double& factor)
861
{
862
    DECL_TRACER("TQScrollArea::setScaleFactor(const double& factor)");
863
 
864
    if (factor > 0.0 && factor != 1.0)
865
        mScaleFactor = factor;
866
}
867
 
300 andreas 868
void TQScrollArea::setAtom(PGSUBVIEWATOM_T& atom, QLabel *label)
869
{
870
    DECL_TRACER("TQScrollArea::setAtom(PGSUBVIEWATOM_T& atom, QLabel *label)");
871
 
872
    if (!label)
873
        return;
874
 
875
    int scaWidth = scale(atom.width);
876
    int scaHeight = scale(atom.height);
877
    QColor bg(qRgba(atom.bgcolor.red, atom.bgcolor.green, atom.bgcolor.blue, atom.bgcolor.alpha));
878
 
879
    if (atom.image.isValid())
880
    {
881
        QPixmap pix(scaWidth, scaHeight);
882
 
883
        if (atom.bgcolor.alpha == 0)
884
            pix.fill(Qt::transparent);
885
        else
886
            pix.fill(bg);
887
 
888
        QImage img(atom.image.getBitmap(), atom.image.getWidth(), atom.image.getHeight(), atom.image.getPixline(), QImage::Format_ARGB32);
889
        bool ret = false;
890
 
891
        if (mScaleFactor != 1.0)
892
        {
893
            QSize size(scaWidth, scaHeight);
894
            ret = pix.convertFromImage(img.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); // Scaled size
895
        }
896
        else
897
            ret = pix.convertFromImage(img);
898
 
899
        if (!ret || pix.isNull())
900
        {
901
            MSG_ERROR("Unable to create a pixmap out of an image!");
902
            return;
903
        }
904
 
905
        label->setPixmap(pix);
906
    }
907
    else
908
    {
909
        QPalette palette(label->palette());
910
 
911
        if (atom.bgcolor.alpha == 0)
912
            palette.setColor(QPalette::Window, Qt::transparent);
913
        else
914
            palette.setColor(QPalette::Window, bg);
915
 
916
        label->setPalette(palette);
917
    }
318 andreas 918
}
300 andreas 919
 
318 andreas 920
void TQScrollArea::refresh()
921
{
922
    DECL_TRACER("TQScrollArea::refresh()");
923
 
924
    if (!mMain || mItems.empty())
925
        return;
926
 
319 andreas 927
    resetSlider();
928
    _clearAllItems();
929
    _addItems(mItems, true);
930
}
318 andreas 931
 
319 andreas 932
void TQScrollArea::setPosition()
933
{
934
    DECL_TRACER("TQScrollArea::setPosition()");
935
 
936
    if (mItems.empty())
937
        return;
938
 
939
    QWidget *anchor = nullptr;
940
    size_t pos = 0;
941
    MSG_DEBUG("Wrap items: " << (mWrapItems ? "TRUE" : "FALSE") << ", number items: " << mItems.size());
942
 
943
    switch (mPosition)
318 andreas 944
    {
319 andreas 945
        case Button::SVP_LEFT_TOP:
946
            anchor = mItems[0].item;
947
        break;
948
 
949
        case Button::SVP_CENTER:
950
            pos = mItems.size() / 2;
951
            anchor = mItems[pos].item;
952
        break;
953
 
954
        case Button::SVP_RIGHT_BOTTOM:
955
            pos = mItems.size() - 1;
956
            anchor = mItems[pos].item;
957
        break;
958
    }
959
 
960
    if (anchor)
961
    {
962
        QRect geom = anchor->geometry();
963
        bool makeVisible = false;
964
 
965
        if (mVertical)
318 andreas 966
        {
319 andreas 967
            if ((geom.y() + geom.height()) < mActPosition ||
968
                    geom.y() > (mActPosition + mHeight))
969
                makeVisible = true;
318 andreas 970
        }
319 andreas 971
        else
972
        {
973
            if ((geom.x() + geom.width()) < mActPosition ||
974
                    geom.x() > (mActPosition + mWidth))
975
                makeVisible = true;
976
        }
977
 
978
        ulong handle = extractHandle(anchor->objectName().toStdString());
979
 
980
        if (makeVisible)
981
        {
982
            ensureWidgetVisible(anchor);
983
            MSG_DEBUG("Item number " << pos << " (" << handleToString(handle) << ") was moved to position.");
984
        }
985
        else
986
        {
987
            MSG_DEBUG("Item number " << pos << " (" << handleToString(handle) << ") is already at visible position.");
988
        }
318 andreas 989
    }
300 andreas 990
}
991
 
318 andreas 992
void TQScrollArea::setPosition(QWidget* w, int position)
285 andreas 993
{
318 andreas 994
    DECL_TRACER("TQScrollArea::setPosition(QWidget* w, int position)");
995
 
996
    int defPosX = 50;
997
    int defPosY = 50;
998
 
999
    if (position > 0 && position < 65535)
285 andreas 1000
    {
318 andreas 1001
        if (mVertical)
289 andreas 1002
        {
318 andreas 1003
            defPosY = position;
1004
            defPosX = 0;
289 andreas 1005
        }
318 andreas 1006
        else
1007
        {
439 andreas 1008
            defPosY = 0;
1009
            defPosX = position;
318 andreas 1010
        }
289 andreas 1011
 
318 andreas 1012
        ensureWidgetVisible(w, defPosX, defPosY);
1013
    }
1014
    else if (mPosition == Button::SVP_LEFT_TOP)
1015
    {
1016
        if (mVertical)
1017
        {
1018
            int top = w->geometry().y();
1019
            QScrollBar *bar = verticalScrollBar();
285 andreas 1020
 
318 andreas 1021
            if (bar)
1022
                bar->setSliderPosition(top);
1023
        }
1024
        else
1025
        {
1026
            int left = w->geometry().x();
1027
            QScrollBar *bar = horizontalScrollBar();
1028
 
1029
            if (bar)
1030
                bar->setSliderPosition(left);
1031
        }
1032
    }
1033
    else if (mPosition == Button::SVP_CENTER)
1034
    {
285 andreas 1035
        if (mVertical)
1036
        {
318 andreas 1037
            int topMargin = (mHeight - w->geometry().height()) / 2;
1038
            int top = w->geometry().y() - topMargin;
1039
            QScrollBar *bar = verticalScrollBar();
285 andreas 1040
 
318 andreas 1041
            if (bar)
1042
                bar->setSliderPosition(top);
285 andreas 1043
        }
1044
        else
1045
        {
318 andreas 1046
            int leftMargin = (mWidth - w->geometry().width()) / 2;
1047
            int left = w->geometry().x() - leftMargin;
1048
            QScrollBar *bar = horizontalScrollBar();
285 andreas 1049
 
318 andreas 1050
            if (bar)
1051
                bar->setSliderPosition(left);
285 andreas 1052
        }
1053
    }
318 andreas 1054
    else if (mPosition == Button::SVP_RIGHT_BOTTOM)
1055
    {
1056
        if (mVertical)
1057
        {
1058
            int bottom = w->geometry().y() + w->geometry().height();
1059
            QScrollBar *bar = verticalScrollBar();
285 andreas 1060
 
318 andreas 1061
            if (bar)
1062
                bar->setSliderPosition(bottom);
1063
        }
1064
        else
1065
        {
1066
            int right = w->geometry().x() + w->geometry().width();
1067
            QScrollBar *bar = horizontalScrollBar();
1068
 
1069
            if (bar)
1070
                bar->setSliderPosition(right);
1071
        }
1072
    }
285 andreas 1073
}
318 andreas 1074
 
1075
TQScrollArea::_ITEMS_T TQScrollArea::subViewItemToItem(PGSUBVIEWITEM_T& item)
1076
{
1077
    DECL_TRACER("TQScrollArea::subViewItemToItem(PGSUBVIEWITEM_T& item)");
1078
 
1079
    _ITEMS_T it;
319 andreas 1080
    it.handle = item.handle;
1081
    it.parent = item.parent;
1082
    it.width = item.width;
1083
    it.height = item.height;
318 andreas 1084
    it.bgcolor = item.bgcolor;
1085
    it.bounding = item.bounding;
1086
    it.image = item.image;
1087
    it.position = item.position;
1088
    it.scrollbar = item.scrollbar;
1089
    it.scrollbarOffset = item.scrollbarOffset;
1090
    it.wrap = item.wrap;
1091
    it.atoms = item.atoms;
1092
 
1093
    return it;
1094
}
1095
 
319 andreas 1096
void TQScrollArea::_clearAllItems()
1097
{
1098
    DECL_TRACER("TQScrollArea::_clearAllItems()");
1099
 
1100
    if (mItems.empty())
1101
        return;
1102
 
1103
    vector<_ITEMS_T>::iterator clIter;
1104
 
1105
    for (clIter = mItems.begin(); clIter != mItems.end(); ++clIter)
1106
    {
1107
        if (clIter->item)
1108
        {
1109
            if (mVertical)
1110
            {
1111
                if (mVLayout)
1112
                    mVLayout->removeWidget(clIter->item);
1113
            }
1114
            else
1115
            {
1116
                if (mHLayout)
1117
                    mHLayout->removeWidget(clIter->item);
1118
            }
1119
 
1120
            clIter->item->close();
1121
            clIter->item = nullptr;
1122
        }
1123
    }
1124
}
1125
 
1126
void TQScrollArea::resetSlider(int position)
1127
{
1128
    DECL_TRACER("TQScrollArea::resetSlider(int position)");
1129
 
1130
    if (mActPosition <= 0)
1131
        return;
1132
 
1133
    QScrollBar *sbar = nullptr;
1134
 
1135
    if (mVertical)
1136
        sbar = verticalScrollBar();
1137
    else
1138
        sbar = horizontalScrollBar();
1139
 
1140
    if (sbar)
1141
    {
1142
        mOldActPosition = sbar->value();
1143
        sbar->setSliderPosition(position);
1144
    }
1145
    else
1146
        mOldActPosition = mActPosition;
1147
}
1148
 
318 andreas 1149
/*****************************************************************************
1150
 * Signals and overwritten functions start here
1151
 *****************************************************************************/
1152
 
320 andreas 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
 
300 andreas 1178
void TQScrollArea::mouseMoveEvent(QMouseEvent* event)
1179
{
1180
    DECL_TRACER("TQScrollArea::mouseMoveEvent(QMouseEvent* event)");
285 andreas 1181
 
300 andreas 1182
    mMousePress = false;
1183
    mMouseScroll = true;
320 andreas 1184
    mDoMouseEvent = false;
301 andreas 1185
 
1186
    if (mMousePressTimer && mMousePressTimer->isActive())
1187
        mMousePressTimer->stop();
1188
 
300 andreas 1189
    int move = 0;
315 andreas 1190
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
1191
    MSG_DEBUG("Scroll event at " << event->pos().x() << "x" << event->pos().y() << ", old point at " << mOldPoint.x() << "x" << mOldPoint.y());
1192
#else
300 andreas 1193
    MSG_DEBUG("Scroll event at " << event->position().x() << "x" << event->position().y() << ", old point at " << mOldPoint.x() << "x" << mOldPoint.y());
315 andreas 1194
#endif
300 andreas 1195
    if (mVertical)
1196
    {
1197
        if (mOldPoint.y() != 0)
1198
        {
1199
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
315 andreas 1200
            move = event->pos().y() - mOldPoint.y();
300 andreas 1201
#else
1202
            move = event->position().y() - mOldPoint.y();
1203
#endif
1204
            QScrollBar *bar = verticalScrollBar();
1205
 
1206
            if (bar)
1207
            {
1208
                int value = bar->value();
1209
                value += (move * -1);
1210
                bar->setValue(value);
1211
            }
1212
        }
1213
    }
1214
    else
1215
    {
1216
        if (mOldPoint.x() != 0)
1217
        {
1218
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
315 andreas 1219
            move = event->pos().x() - mOldPoint.x();
300 andreas 1220
#else
1221
            move = event->position().x() - mOldPoint.x();
1222
#endif
1223
            QScrollBar *bar = horizontalScrollBar();
1224
 
1225
            if (bar)
1226
            {
1227
                int value = bar->value();
301 andreas 1228
                int newValue = value + (move * -1);
1229
 
1230
                if (newValue >= 0 && newValue != value)
1231
                    bar->setValue(newValue);
300 andreas 1232
            }
1233
        }
1234
    }
301 andreas 1235
 
300 andreas 1236
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
315 andreas 1237
    mOldPoint = event->pos();
300 andreas 1238
#else
1239
    mOldPoint = event->position();
1240
#endif
1241
}
1242
 
285 andreas 1243
void TQScrollArea::mousePressEvent(QMouseEvent* event)
1244
{
294 andreas 1245
    DECL_TRACER("TQScrollArea::mousePressEvent(QMouseEvent* event)");
1246
 
320 andreas 1247
    if (!event || mMouseScroll || event->button() != Qt::LeftButton)
289 andreas 1248
        return;
1249
 
320 andreas 1250
    mMousePress = true;
1251
    mOldPoint.setX(0.0);
1252
    mOldPoint.setY(0.0);
289 andreas 1253
 
320 andreas 1254
    int x = 0, y = 0;
289 andreas 1255
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
320 andreas 1256
    x = event->pos().x();
1257
    y = event->pos().y();
289 andreas 1258
#else
320 andreas 1259
    x = event->position().x();
1260
    y = event->position().y();
289 andreas 1261
#endif
320 andreas 1262
    mLastMousePress.setX(x);
1263
    mLastMousePress.setY(y);
361 andreas 1264
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
320 andreas 1265
    MSG_DEBUG("Mouse press event at " << x << " x " << y << " // " << event->globalX() << " x " << event->globalY());
361 andreas 1266
#else
1267
    MSG_DEBUG("Mouse press event at " << x << " x " << y << " // " << event->globalPosition().x() << " x " << event->globalPosition().y());
1268
#endif
320 andreas 1269
    /*
1270
        * Here we're starting a timer with 200 ms. If after this time the
1271
        * mouse button is still pressed and no scroll event was detected,
1272
        * then we've a real click.
1273
        * In case of a real click the method mouseTimerEvent() will call a
1274
        * signal to inform the parent about the click.
1275
        */
1276
    mClick = true;  // This means PRESSED state
1277
    mMouseTmEventActive = true;
1278
    mDoMouseEvent = true;
1279
    QTimer::singleShot(200, this, &TQScrollArea::mouseTimerEvent);
285 andreas 1280
}
1281
 
1282
void TQScrollArea::mouseReleaseEvent(QMouseEvent* event)
1283
{
294 andreas 1284
    DECL_TRACER("TQScrollArea::mouseReleaseEvent(QMouseEvent* event)");
1285
 
320 andreas 1286
    if (!event || event->button() != Qt::LeftButton)
289 andreas 1287
        return;
1288
 
320 andreas 1289
    mDoMouseEvent = false;
1290
 
1291
    if (mMouseTmEventActive)
289 andreas 1292
    {
320 andreas 1293
        if (!mMouseScroll)
289 andreas 1294
        {
320 andreas 1295
            mClick = true;      // This means PRESSED state
1296
            doMouseEvent();
1297
            mClick = false;     // This means RELEASED state
1298
            doMouseEvent();
289 andreas 1299
        }
320 andreas 1300
    }
1301
    else if (!mMouseScroll && mClick)
1302
    {
1303
        mClick = false;         // This means RELEASED state
1304
        doMouseEvent();
1305
    }
301 andreas 1306
 
320 andreas 1307
    mMousePress = false;
1308
    mMouseScroll = false;
1309
    mOldPoint.setX(0.0);
1310
    mOldPoint.setY(0.0);
285 andreas 1311
}
289 andreas 1312
 
320 andreas 1313
void TQScrollArea::doMouseEvent()
289 andreas 1314
{
320 andreas 1315
    DECL_TRACER("TQScrollArea::doMouseEvent()");
294 andreas 1316
 
320 andreas 1317
    if (!mMousePress || mMouseScroll || !mMain)
1318
        return;
289 andreas 1319
 
320 andreas 1320
    QWidget *w = nullptr;
1321
 
289 andreas 1322
    if (mVertical)
320 andreas 1323
        w = mMain->childAt(mLastMousePress.x(), mActPosition + mLastMousePress.y());
289 andreas 1324
    else
320 andreas 1325
        w = mMain->childAt(mActPosition + mLastMousePress.x(), mLastMousePress.y());
289 andreas 1326
 
320 andreas 1327
    if (!w)
1328
        return;
300 andreas 1329
 
320 andreas 1330
    QString obname = w->objectName();
1331
    ulong handle = extractHandle(obname.toStdString());
289 andreas 1332
 
320 andreas 1333
    if (!handle)
1334
        return;
294 andreas 1335
 
320 andreas 1336
    // We must make sure the found object is not marked as pass through.
1337
    // Because of this we'll scan the items for the handle and if we
1338
    // find that it is marked as pass through we must look for another
1339
    // one on the same position. If there is none, the click is ignored.
1340
    //
1341
    // Find the object in our list
1342
    vector<_ITEMS_T>::iterator iter;
1343
    QRect rect;
1344
    bool call = true;
289 andreas 1345
 
320 andreas 1346
    for (iter = mItems.begin(); iter != mItems.end(); ++iter)
289 andreas 1347
    {
320 andreas 1348
        if (iter->handle == handle)     // Handle found?
1349
        {                               // Yes, then ...
1350
            if (iter->bounding == "passThru")   // Item marked as pass through?
1351
            {                                   // Yes, then start to search for another item
1352
                rect = w->rect();
1353
                call = false;
1354
                // Walk through the childs to find another one on the
1355
                // clicked position.
1356
                QObjectList ol = mMain->children(); // Get list of all objects
1357
                QList<QObject *>::iterator obiter;  // Define an iterator
1358
                // Loop through all objects
1359
                for (obiter = ol.begin(); obiter != ol.end(); ++obiter)
1360
                {
1361
                    QObject *object = *obiter;
289 andreas 1362
 
320 andreas 1363
                    if (object->objectName() != obname && object->objectName().startsWith("Label_"))    // Have we found a QLabel object?
1364
                    {                                                                                   // Yes, then test it's position
1365
                        QLabel *lb = dynamic_cast<QLabel *>(object);    // Cast the object to a QLabel
289 andreas 1366
 
320 andreas 1367
                        if (lb->rect().contains(mLastMousePress))       // Is the QLabel under the mouse coordinates?
1368
                        {                                               // Yes, then select it.
1369
                            ulong h = extractHandle(lb->objectName().toStdString());  // Get the handle
289 andreas 1370
 
320 andreas 1371
                            if (!h)
1372
                                break;
289 andreas 1373
 
320 andreas 1374
                            handle = h;
1375
                            // Reset the main loop
1376
                            iter = mItems.begin();
1377
                            break;
293 andreas 1378
                        }
1379
                    }
1380
                }
1381
            }
320 andreas 1382
            else
293 andreas 1383
            {
320 andreas 1384
                call = true;
1385
                break;
293 andreas 1386
            }
289 andreas 1387
        }
1388
    }
320 andreas 1389
 
1390
    if (call)
1391
    {
1392
        MSG_DEBUG("Calling signal with handle " << (handle >> 16 & 0x0000ffff) << ":" << (handle & 0x0000ffff) << ": STATE=" << (mClick ? "PRESSED" : "RELEASED"));
1393
        emit objectClicked(handle, mClick);
1394
        mClick = false;
1395
    }
289 andreas 1396
}
293 andreas 1397
 
320 andreas 1398
void TQScrollArea::mouseTimerEvent()
1399
{
1400
    DECL_TRACER("TQScrollArea::mouseTimerEvent()");
1401
 
1402
    if (!mDoMouseEvent)
1403
        return;
1404
 
1405
    mDoMouseEvent = false;
1406
 
1407
    if (mClick)         // Only if PRESSED
1408
        doMouseEvent();
1409
 
1410
    mMouseTmEventActive = false;
1411
}
1412