1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262 | /* ============================================================
*
* This file is a part of digiKam project
* https://www.digikam.org
*
* Date : 2007-01-24
* Description : a progress bar used to display action
* progress or a text in status bar.
* Progress events are dispatched to ProgressManager.
*
* SPDX-FileCopyrightText: 2007-2026 by Gilles Caulier <caulier dot gilles at gmail dot com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* ============================================================ */
#include "statusprogressbar.h"
// Qt includes
#include <QWidget>
#include <QPushButton>
#include <QHBoxLayout>
#include <QProgressBar>
#include <QIcon>
// Local includes
#include "digikam_debug.h"
#include "progressmanager.h"
#include "dexpanderbox.h"
namespace Digikam
{
class Q_DECL_HIDDEN StatusProgressBar::Private
{
public:
enum WidgetStackEnum
{
TextLabel = 0,
ProgressBar
};
public:
Private() = default;
public:
// For Progress Manager item
bool notify = false;
QString progressId;
QString title;
QIcon icon;
QWidget* progressWidget = nullptr;
QPushButton* cancelButton = nullptr;
QProgressBar* progressBar = nullptr;
DAdjustableLabel* textLabel = nullptr;
};
StatusProgressBar::StatusProgressBar(QWidget* const parent)
: QStackedWidget(parent),
d (new Private)
{
setAttribute(Qt::WA_DeleteOnClose);
setFocusPolicy(Qt::NoFocus);
d->textLabel = new DAdjustableLabel(this);
d->progressWidget = new QWidget(this);
QHBoxLayout* const hBox = new QHBoxLayout(d->progressWidget);
d->progressBar = new QProgressBar(d->progressWidget);
d->cancelButton = new QPushButton(d->progressWidget);
d->cancelButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
d->cancelButton->setFocusPolicy(Qt::NoFocus);
d->cancelButton->setIcon(QIcon::fromTheme(QLatin1String("dialog-cancel")));
setProgressTotalSteps(100);
// Parent widget will probably have the wait cursor set.
// Set arrow cursor to indicate the button can be clicked.
d->cancelButton->setCursor(Qt::ArrowCursor);
hBox->addWidget(d->progressBar);
hBox->addWidget(d->cancelButton);
hBox->setContentsMargins(QMargins());
hBox->setSpacing(0);
insertWidget(Private::TextLabel, d->textLabel);
insertWidget(Private::ProgressBar, d->progressWidget);
connect(d->cancelButton, SIGNAL(clicked()),
this, SIGNAL(signalCancelButtonPressed()) );
setProgressBarMode(TextMode);
}
StatusProgressBar::~StatusProgressBar()
{
delete d;
}
void StatusProgressBar::setNotify(bool b)
{
d->notify = b;
}
void StatusProgressBar::setNotificationTitle(const QString& title, const QIcon& icon)
{
d->title = title;
d->icon = icon;
}
void StatusProgressBar::setText(const QString& text)<--- Shadow argument
{
d->textLabel->setAdjustedText(text);
}
QString StatusProgressBar::text() const
{
return d->textLabel->adjustedText();
}
void StatusProgressBar::setAlignment(Qt::Alignment a)
{
d->textLabel->setAlignment(a);
}
int StatusProgressBar::progressValue() const
{
return d->progressBar->value();
}
void StatusProgressBar::setProgressValue(int v)
{
d->progressBar->setValue(v);
if (d->notify)
{
ProgressItem* const item = currentProgressItem();
if (item)
{
item->setCompletedItems(v);
item->updateProgress();
}
}
}
int StatusProgressBar::progressTotalSteps() const
{
return d->progressBar->maximum();
}
void StatusProgressBar::setProgressTotalSteps(int v)
{
d->progressBar->setMaximum(v);
if (d->notify)
{
ProgressItem* const item = currentProgressItem();
if (item)
{
item->setTotalItems(v);
}
}
}
void StatusProgressBar::setProgressText(const QString& text)<--- Shadow argument
{
d->progressBar->setFormat(text + QLatin1String(" %p%"));
d->progressBar->update();
if (d->notify)
{
ProgressItem* const item = currentProgressItem();
if (item)
{
item->setStatus(text);
}
}
}
void StatusProgressBar::setProgressBarMode(int mode, const QString& text)<--- Shadow argument
{
if (mode == TextMode)
{
setCurrentIndex(Private::TextLabel);
setProgressValue(0);
setText(text);
if (d->notify)
{
ProgressItem* const item = currentProgressItem();
if (item)
{
item->setComplete();
}
}
}
else if (mode == ProgressBarMode)
{
d->cancelButton->hide();
setCurrentIndex(Private::ProgressBar);
setProgressText(text);
if (d->notify)
{
ProgressItem* const item = ProgressManager::createProgressItem(d->title, QString(), false, !d->icon.isNull());
item->setTotalItems(d->progressBar->maximum());
item->setCompletedItems(d->progressBar->value());
if (!d->icon.isNull())
{
item->setThumbnail(d->icon);
}
connect(item, SIGNAL(progressItemCanceled(ProgressItem*)),
this, SIGNAL(signalCancelButtonPressed()));
d->progressId = item->id();
}
}
else // CancelProgressBarMode
{
d->cancelButton->show();
setCurrentIndex(Private::ProgressBar);
setProgressText(text);
if (d->notify)
{
ProgressItem* const item = ProgressManager::createProgressItem(d->title, QString(), true, !d->icon.isNull());
item->setTotalItems(d->progressBar->maximum());
item->setCompletedItems(d->progressBar->value());
if (!d->icon.isNull())
{
item->setThumbnail(d->icon);
}
connect(item, SIGNAL(progressItemCanceled(ProgressItem*)),
this, SIGNAL(signalCancelButtonPressed()));
d->progressId = item->id();
}
}
}
ProgressItem* StatusProgressBar::currentProgressItem() const
{
return (ProgressManager::instance()->findItembyId(d->progressId));
}
} // namespace Digikam
#include "moc_statusprogressbar.cpp"
|