All Classes Namespaces Functions Variables Enumerations Properties Pages
doubleprogressdialog.cpp
1 /*
2 
3 Pencil2D - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2020 Matthew Chiawen Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 */
17 
18 #include "doubleprogressdialog.h"
19 #include "ui_doubleprogressdialog.h"
20 
21 #include <QtMath>
22 
23 DoubleProgressDialog::DoubleProgressDialog(QWidget *parent) :
24  QDialog(parent),
25  ui(new Ui::DoubleProgressDialog)
26 {
27  ui->setupUi(this);
28 
29  major = new ProgressBarControl(ui->majorProgressBar);
30  minor = new ProgressBarControl(ui->minorProgressBar);
31 
32  connect(ui->cancelButton, &QPushButton::pressed, this, &DoubleProgressDialog::canceled);
33 }
34 
35 DoubleProgressDialog::~DoubleProgressDialog()
36 {
37  delete ui;
38 }
39 
40 QString DoubleProgressDialog::getStatus() {
41  return ui->progressStatus->text();
42 }
43 
44 void DoubleProgressDialog::setStatus(QString msg)
45 {
46  ui->progressStatus->setText(msg);
47 }
48 
49 DoubleProgressDialog::ProgressBarControl::ProgressBarControl(QProgressBar *b)
50 {
51  bar = b;
52 }
53 
54 void DoubleProgressDialog::ProgressBarControl::setMin(float minimum)
55 {
56  min = minimum;
57  if(max < min) setMax(min);
58  bar->setMinimum(convertUnits(min));
59 }
60 
61 void DoubleProgressDialog::ProgressBarControl::setMax(float maximum)
62 {
63  max = maximum;
64  if(min > max) setMin(max);
65  bar->setMaximum(convertUnits(max));
66 }
67 
68 void DoubleProgressDialog::ProgressBarControl::setValue(float value)
69 {
70  val = qBound(min, value, max);
71  bar->setValue(convertUnits(val));
72 }
73 
74 int DoubleProgressDialog::ProgressBarControl::getPrecision()
75 {
76  return static_cast<int>(qLn(unitFactor) / qLn(10));
77 }
78 
79 void DoubleProgressDialog::ProgressBarControl::setPrecision(int e)
80 {
81  int oldFactor = unitFactor;
82  unitFactor = static_cast<int>(qPow(10, e));
83 
84  min *= unitFactor / static_cast<float>(oldFactor);
85  max *= unitFactor / static_cast<float>(oldFactor);
86  val *= unitFactor / static_cast<float>(oldFactor);
87 }
88 
89 int DoubleProgressDialog::ProgressBarControl::convertUnits(float value)
90 {
91  return qRound(value * unitFactor);
92 }
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)