File indexing completed on 2025-01-19 03:53:52
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2006-30-08 0007 * Description : a progress dialog for digiKam 0008 * 0009 * SPDX-FileCopyrightText: 2006-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "dprogressdlg.h" 0016 0017 // Qt includes 0018 0019 #include <QHeaderView> 0020 #include <QStyle> 0021 #include <QLabel> 0022 #include <QImage> 0023 #include <QGridLayout> 0024 #include <QProgressBar> 0025 #include <QTreeWidget> 0026 #include <QStandardPaths> 0027 #include <QDialogButtonBox> 0028 #include <QVBoxLayout> 0029 #include <QPushButton> 0030 0031 // Local includes 0032 0033 #include "dexpanderbox.h" 0034 0035 namespace Digikam 0036 { 0037 0038 class Q_DECL_HIDDEN DProgressDlg::Private 0039 { 0040 public: 0041 0042 explicit Private() 0043 : logo (nullptr), 0044 title (nullptr), 0045 label (nullptr), 0046 actionPix (nullptr), 0047 actionLabel(nullptr), 0048 progress (nullptr), 0049 buttons (nullptr) 0050 { 0051 } 0052 0053 QLabel* logo; 0054 QLabel* title; 0055 QLabel* label; 0056 0057 QLabel* actionPix; 0058 DAdjustableLabel* actionLabel; 0059 0060 QProgressBar* progress; 0061 0062 QDialogButtonBox* buttons; 0063 }; 0064 0065 DProgressDlg::DProgressDlg(QWidget* const parent, const QString& caption) 0066 : QDialog(parent), 0067 d (new Private) 0068 { 0069 setModal(true); 0070 setWindowTitle(caption); 0071 0072 d->buttons = new QDialogButtonBox(QDialogButtonBox::Cancel, this); 0073 d->buttons->button(QDialogButtonBox::Cancel)->setDefault(true); 0074 0075 QWidget* const page = new QWidget(this); 0076 QGridLayout* const grid = new QGridLayout(page); 0077 0078 d->actionPix = new QLabel(page); 0079 d->actionLabel = new DAdjustableLabel(page); 0080 d->logo = new QLabel(page); 0081 d->progress = new QProgressBar(page); 0082 d->title = new QLabel(page); 0083 d->label = new QLabel(page); 0084 d->actionPix->setFixedSize(QSize(32, 32)); 0085 0086 d->logo->setPixmap(QIcon::fromTheme(QLatin1String("digikam")).pixmap(QSize(48,48))); 0087 0088 grid->addWidget(d->logo, 0, 0, 3, 1); 0089 grid->addWidget(d->label, 0, 1, 1, 2); 0090 grid->addWidget(d->actionPix, 1, 1, 1, 1); 0091 grid->addWidget(d->actionLabel, 1, 2, 1, 1); 0092 grid->addWidget(d->progress, 2, 1, 1, 2); 0093 grid->addWidget(d->title, 3, 1, 1, 2); 0094 grid->setSpacing(qMin(style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing), 0095 style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing))); 0096 grid->setContentsMargins(QMargins()); 0097 grid->setColumnStretch(2, 10); 0098 0099 QVBoxLayout* const vbx = new QVBoxLayout(this); 0100 vbx->addWidget(page); 0101 vbx->addWidget(d->buttons); 0102 setLayout(vbx); 0103 0104 connect(d->buttons->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), 0105 this, SLOT(slotCancel())); 0106 0107 adjustSize(); 0108 reset(); 0109 } 0110 0111 DProgressDlg::~DProgressDlg() 0112 { 0113 delete d; 0114 } 0115 0116 void DProgressDlg::slotCancel() 0117 { 0118 Q_EMIT signalCancelPressed(); 0119 0120 close(); 0121 } 0122 0123 void DProgressDlg::setButtonText(const QString& text) 0124 { 0125 d->buttons->button(QDialogButtonBox::Cancel)->setText(text); 0126 } 0127 0128 void DProgressDlg::addedAction(const QPixmap& itemPix, const QString& text) 0129 { 0130 QPixmap pix = itemPix; 0131 0132 if (pix.isNull()) 0133 { 0134 pix = QIcon::fromTheme(QLatin1String("image-missing")).pixmap(32); 0135 } 0136 else 0137 { 0138 pix = pix.scaled(32, 32, Qt::KeepAspectRatio, Qt::SmoothTransformation); 0139 } 0140 0141 d->actionPix->setPixmap(pix); 0142 d->actionLabel->setAdjustedText(text); 0143 } 0144 0145 void DProgressDlg::reset() 0146 { 0147 d->progress->setValue(0); 0148 } 0149 0150 void DProgressDlg::setMaximum(int max) 0151 { 0152 d->progress->setMaximum(max); 0153 } 0154 0155 void DProgressDlg::incrementMaximum(int added) 0156 { 0157 d->progress->setMaximum(d->progress->maximum() + added); 0158 } 0159 0160 void DProgressDlg::setValue(int value) 0161 { 0162 d->progress->setValue(value); 0163 } 0164 0165 void DProgressDlg::advance(int offset) 0166 { 0167 d->progress->setValue(d->progress->value() + offset); 0168 } 0169 0170 int DProgressDlg::value() const 0171 { 0172 return d->progress->value(); 0173 } 0174 0175 void DProgressDlg::setLabel(const QString& text) 0176 { 0177 d->label->setText(text); 0178 } 0179 0180 void DProgressDlg::setTitle(const QString& text) 0181 { 0182 d->title->setText(text); 0183 } 0184 0185 } // namespace Digikam 0186 0187 #include "moc_dprogressdlg.cpp"