Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
119 andreas 1
/*
2
 * Copyright (C) 2022 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 <QLabel>
20
#include <QUrl>
21
#include <QtQuickWidgets/QQuickWidget>
22
 
23
#include "tqtbusy.h"
24
#include "ui_busy.h"
25
#include "terror.h"
26
 
120 andreas 27
TQBusy::TQBusy(const std::string& msg, QWidget* parent)
119 andreas 28
    : QDialog(parent),
29
      ui(new Ui::TQBusy)
30
{
31
    DECL_TRACER("TQBusy::TQBusy(const std::string& init, const std::string& prompt, QWidget* parent, bool priv)");
32
 
33
    ui->setupUi(this);
34
    ui->quickWidget->setSource(QUrl("qrc:qrc/BusyIndicator.qml"));
35
    ui->label_Download->setText(msg.c_str());
36
}
37
 
120 andreas 38
TQBusy::~TQBusy()
119 andreas 39
{
40
    DECL_TRACER("TQBusy::~TQBusy()");
120 andreas 41
 
42
    delete ui;
119 andreas 43
}
44
 
120 andreas 45
void TQBusy::doResize()
119 andreas 46
{
120 andreas 47
    DECL_TRACER("TQBusy::doResize()");
119 andreas 48
 
49
    if (mScaleFactor == 0.0 || mScaleFactor == 1.0)
50
        return;
51
 
52
    QRect rect = this->geometry();
53
    QSize size = this->size();
54
    size.scale(scale(size.width()), scale(size.height()), Qt::KeepAspectRatio);
55
    this->resize(size);
56
    this->move(scale(rect.left()), scale(rect.top()));
57
    QWidget *parent = this->parentWidget();
58
 
59
    if (parent)
60
    {
61
        rect = parent->geometry();
62
        this->move(rect.center() - this->rect().center());
63
    }
64
 
65
    // Iterate through childs and resize them
66
    QObjectList childs = children();
67
    QList<QObject *>::Iterator iter;
68
 
69
    for (iter = childs.begin(); iter != childs.end(); ++iter)
70
    {
71
        QString name = iter.i->t()->objectName();
72
        QObject *obj = iter.i->t();
73
 
74
        if (name.startsWith("quick"))
75
        {
76
            QQuickWidget *bt = dynamic_cast<QQuickWidget *>(obj);
77
            size = bt->size();
78
            size.scale(scale(size.width()), scale(size.height()), Qt::KeepAspectRatio);
79
            bt->resize(size);
80
            rect = bt->geometry();
81
            bt->move(scale(rect.left()), scale(rect.top()));
82
        }
83
        else if (name.startsWith("label"))   // It's a label
84
        {
85
            QLabel *lb = dynamic_cast<QLabel *>(obj);
86
            size = lb->size();
87
            size.scale(scale(size.width()), scale(size.height()), Qt::KeepAspectRatio);
88
            lb->resize(size);
89
            rect = lb->geometry();
90
            lb->move(scale(rect.left()), scale(rect.top()));
91
        }
92
    }
93
}
94
 
120 andreas 95
int TQBusy::scale(int value)
119 andreas 96
{
97
    if (value <= 0 || mScaleFactor == 1.0)
98
        return value;
99
 
100
    return (int)((double)value * mScaleFactor);
101
}