Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
446 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 <QProgressBar>
21
 
22
#include "tqdownload.h"
23
#include "ui_download.h"
24
#include "terror.h"
25
 
26
TqDownload::TqDownload(const std::string &msg, QWidget *parent)
27
    : QDialog(parent),
28
      ui(new Ui::TqDownload)
29
{
30
    DECL_TRACER("TqDownload::TqDownload(const std::string& msg, QWidget* parent)");
31
 
32
    ui->setupUi(this);
33
    ui->labelInfo->setText(msg.c_str());
34
    ui->progressBar->setRange(0, 100);
35
    ui->progressBar->setValue(0);
36
}
37
 
38
TqDownload::~TqDownload()
39
{
40
    DECL_TRACER("TqDownload::~TqDownload()");
41
 
42
    delete ui;
43
}
44
 
45
void TqDownload::setProgress(int percent)
46
{
47
    DECL_TRACER("TqDownload::setProgress(int percent)");
48
 
49
    int p = percent;
50
 
51
    if (p < 0)
52
        p = 0;
53
    else if (p > 100)
54
        p = 100;
55
 
56
    ui->progressBar->setValue(p);
57
}
58
 
59
void TqDownload::doResize()
60
{
61
    DECL_TRACER("TqDownload::doResize()");
62
 
63
    if (mScaleFactor <= 0.0 || mScaleFactor == 1.0)
64
        return;
65
 
66
    QRect rect = this->geometry();
67
    QSize size = this->size();
68
    size.scale(scale(size.width()), scale(size.height()), Qt::KeepAspectRatio);
69
    this->resize(size);
70
    this->move(scale(rect.left()), scale(rect.top()));
71
    QWidget *parent = this->parentWidget();
72
 
73
    if (parent)
74
    {
75
        rect = parent->geometry();
76
        this->move(rect.center() - this->rect().center());
77
    }
78
 
79
    // Iterate through childs and resize them
80
    QObjectList childs = children();
81
    QList<QObject *>::Iterator iter;
82
 
83
    for (iter = childs.begin(); iter != childs.end(); ++iter)
84
    {
85
        QObject *obj = *iter;
86
        QString name = obj->objectName();
87
 
88
        if (name.startsWith("progressBar"))
89
        {
90
            QProgressBar *pb = dynamic_cast<QProgressBar *>(obj);
91
            size = pb->size();
92
            size.scale(scale(size.width()), scale(size.height()), Qt::KeepAspectRatio);
93
            pb->resize(size);
94
            rect = pb->geometry();
95
            pb->move(scale(rect.left()), scale(rect.top()));
96
            pb->setStyleSheet("{background-color: #97be0d;color: #000000;text-align: center;}");
97
        }
98
        else if (name.startsWith("label"))   // It's a label
99
        {
100
            QLabel *lb = dynamic_cast<QLabel *>(obj);
101
            size = lb->size();
102
            size.scale(scale(size.width()), scale(size.height()), Qt::KeepAspectRatio);
103
            lb->resize(size);
104
            rect = lb->geometry();
105
            lb->move(scale(rect.left()), scale(rect.top()));
106
            QFont font = lb->font();
107
            int pixelSize = lb->size().height() - 2;
108
            font.setPixelSize(pixelSize);
109
            lb->setFont(font);
110
        }
111
    }
112
}
113
 
114
int TqDownload::scale(int value)
115
{
116
    if (value <= 0 || mScaleFactor == 1.0)
117
        return value;
118
 
119
    return (int)((double)value * mScaleFactor);
120
}