Libksieve

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

KDE's Doxygen guidelines are available online.