File indexing completed on 2024-06-23 05:16:27
0001 /* 0002 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "progressindicatorlabel.h" 0008 #include <KBusyIndicatorWidget> 0009 0010 #include <QHBoxLayout> 0011 #include <QLabel> 0012 0013 using namespace KPIM; 0014 class KPIM::ProgressIndicatorLabelPrivate 0015 { 0016 public: 0017 ProgressIndicatorLabelPrivate(const QString &_label, ProgressIndicatorLabel *qq) 0018 : labelStr(_label) 0019 , q(qq) 0020 { 0021 auto lay = new QHBoxLayout(q); 0022 lay->setContentsMargins(0, 0, 0, 0); 0023 indicator = new KBusyIndicatorWidget(q); 0024 lay->addWidget(indicator); 0025 label = new QLabel(q); 0026 lay->addWidget(label); 0027 } 0028 0029 ~ProgressIndicatorLabelPrivate() = default; 0030 0031 void setActiveLabel(const QString &str) 0032 { 0033 if (!indicator->isHidden()) { 0034 label->setText(str); 0035 } 0036 } 0037 0038 void start() 0039 { 0040 indicator->show(); 0041 label->setText(labelStr); 0042 } 0043 0044 void stop() 0045 { 0046 indicator->hide(); 0047 label->clear(); 0048 } 0049 0050 QString labelStr; 0051 QLabel *label = nullptr; 0052 KBusyIndicatorWidget *indicator = nullptr; 0053 ProgressIndicatorLabel *const q; 0054 }; 0055 0056 ProgressIndicatorLabel::ProgressIndicatorLabel(const QString &label, QWidget *parent) 0057 : QWidget(parent) 0058 , d(new ProgressIndicatorLabelPrivate(label, this)) 0059 { 0060 d->stop(); 0061 } 0062 0063 ProgressIndicatorLabel::ProgressIndicatorLabel(QWidget *parent) 0064 : QWidget(parent) 0065 , d(new ProgressIndicatorLabelPrivate(QString(), this)) 0066 { 0067 d->stop(); 0068 } 0069 0070 ProgressIndicatorLabel::~ProgressIndicatorLabel() = default; 0071 0072 void ProgressIndicatorLabel::start() 0073 { 0074 d->start(); 0075 } 0076 0077 void ProgressIndicatorLabel::stop() 0078 { 0079 d->stop(); 0080 } 0081 0082 void ProgressIndicatorLabel::setActiveLabel(const QString &label) 0083 { 0084 d->setActiveLabel(label); 0085 } 0086 0087 #include "moc_progressindicatorlabel.cpp"