Libkleo

progressbar.cpp
1/*
2 progressbar.cpp
3
4 This file is part of libkleopatra, the KDE keymanagement library
5 SPDX-FileCopyrightText: 2004 Klarälvdalens Datakonsult AB
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9
10#include <config-libkleo.h>
11
12#include "progressbar.h"
13
14#include <kleo_ui_debug.h>
15
16#include <QTimer>
17
18static const int busyTimerTickInterval = 100;
19static const int busyTimerTickIncrement = 5;
20
21Kleo::ProgressBar::ProgressBar(QWidget *parent)
22 : QProgressBar(parent)
23 , mRealProgress(-1)
24{
25 mBusyTimer = new QTimer(this);
26 connect(mBusyTimer, &QTimer::timeout, this, &ProgressBar::slotBusyTimerTick);
27 fixup(true);
28}
29
30void Kleo::ProgressBar::slotProgress(const QString &, int cur, int tot)
31{
32 setRange(cur, tot);
33}
34
35void Kleo::ProgressBar::slotProgress(const QString &, int, int cur, int tot)
36{
37 setRange(cur, tot);
38}
39
41{
42 qCDebug(KLEO_UI_LOG) << "Kleo::ProgressBar::setMaximum(" << total << " )";
43 if (total == maximum()) {
44 return;
45 }
47 fixup(false);
48}
49
51{
52 qCDebug(KLEO_UI_LOG) << "Kleo::ProgressBar::setValue(" << p << " )";
53 mRealProgress = p;
54 fixup(true);
55}
56
58{
59 mRealProgress = -1;
60 fixup(true);
61}
62
63void Kleo::ProgressBar::slotBusyTimerTick()
64{
65 fixup(false);
66 if (mBusyTimer->isActive()) {
67 QProgressBar::setValue(QProgressBar::value() + busyTimerTickIncrement);
68 }
69}
70
71void Kleo::ProgressBar::fixup(bool newValue)
72{
73 const int cur = QProgressBar::value();
74 const int tot = QProgressBar::maximum();
75
76 qCDebug(KLEO_UI_LOG) << "Kleo::ProgressBar::startStopBusyTimer() cur =" << cur << "; tot =" << tot << "; real =" << mRealProgress;
77
78 if ((newValue && mRealProgress < 0) || (!newValue && cur < 0)) {
79 qCDebug(KLEO_UI_LOG) << "(new value) switch to reset";
80 mBusyTimer->stop();
81 if (newValue) {
83 }
84 mRealProgress = -1;
85 } else if (tot == 0) {
86 qCDebug(KLEO_UI_LOG) << "(new value) switch or stay in busy";
87 if (!mBusyTimer->isActive()) {
88 mBusyTimer->start(busyTimerTickInterval);
89 if (newValue) {
90 QProgressBar::setValue(mRealProgress);
91 }
92 }
93 } else {
94 qCDebug(KLEO_UI_LOG) << "(new value) normal progress";
95 mBusyTimer->stop();
96 if (QProgressBar::value() != mRealProgress) {
97 QProgressBar::setValue(mRealProgress);
98 }
99 }
100}
101
102#include "moc_progressbar.cpp"
void setValue(int progress)
void setMaximum(int total)
void setRange(int cur, int tot)
Definition progressbar.h:40
void setMaximum(int maximum)
void setValue(int value)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void timeout()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:14:12 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.