Libksieve

sievetreewidgetitem.cpp
1/*
2 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-only
5*/
6
7#include "sievetreewidgetitem.h"
8
9#include <KIconLoader>
10#include <KPixmapSequenceLoader>
11
12#include <QTimer>
13
14using namespace KSieveUi;
15SieveTreeWidgetProgress::SieveTreeWidgetProgress(SieveTreeWidgetItem *item, QObject *parent)
16 : QObject(parent)
17 , mItem(item)
18{
19 mProgressPix = KPixmapSequenceLoader::load(QStringLiteral("process-working"), KIconLoader::SizeSmallMedium);
20 mProgressTimer = new QTimer(this);
21 connect(mProgressTimer, &QTimer::timeout, this, &SieveTreeWidgetProgress::slotTimerDone);
22}
23
24SieveTreeWidgetProgress::~SieveTreeWidgetProgress() = default;
25
26void SieveTreeWidgetProgress::slotTimerDone()
27{
28 mItem->setProgressAnimation(mProgressPix.frameAt(mProgressCount));
29 ++mProgressCount;
30 if (mProgressCount == 8) {
31 mProgressCount = 0;
32 }
33
34 mProgressTimer->start(300);
35}
36
37void SieveTreeWidgetProgress::startAnimation()
38{
39 mProgressCount = 0;
40 mProgressTimer->start(300);
41}
42
43void SieveTreeWidgetProgress::stopAnimation()
44{
45 if (mProgressTimer->isActive()) {
46 mProgressTimer->stop();
47 }
48 mItem->setDefaultIcon();
49}
50
51class KSieveUi::SieveTreeWidgetItemPrivate
52{
53public:
54 SieveTreeWidgetItemPrivate() = default;
55
56 ~SieveTreeWidgetItemPrivate()
57 {
58 delete mProgress;
59 }
60
61 SieveTreeWidgetProgress *mProgress = nullptr;
62};
63
64SieveTreeWidgetItem::SieveTreeWidgetItem(QTreeWidget *treeWidget, QTreeWidgetItem *item)
65 : QTreeWidgetItem(treeWidget, item)
66 , d(new KSieveUi::SieveTreeWidgetItemPrivate)
67{
68 d->mProgress = new SieveTreeWidgetProgress(this);
69}
70
71SieveTreeWidgetItem::~SieveTreeWidgetItem() = default;
72
73void SieveTreeWidgetItem::startAnimation()
74{
75 d->mProgress->startAnimation();
76}
77
78void SieveTreeWidgetItem::stopAnimation()
79{
80 d->mProgress->stopAnimation();
81}
82
83void SieveTreeWidgetItem::setProgressAnimation(const QPixmap &pix)
84{
85 setIcon(0, QIcon(pix));
86}
87
88void SieveTreeWidgetItem::setDefaultIcon()
89{
90 setIcon(0, QIcon::fromTheme(QStringLiteral("network-server")));
91}
92
93#include "moc_sievetreewidgetitem.cpp"
QPixmap frameAt(int index) const
The SieveTreeWidgetItem class.
QIcon fromTheme(const QString &name)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
bool isActive() const const
void start()
void stop()
void timeout()
void setIcon(int column, const QIcon &icon)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.