Libksieve

sievetreewidgetitem.cpp
1 /*
2  Copyright (C) 2013-2020 Laurent Montel <[email protected]>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License, version 2, as
6  published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "sievetreewidgetitem.h"
19 
20 #include <KIconLoader>
21 
22 #include <QTimer>
23 
24 using namespace KSieveUi;
25 SieveTreeWidgetProgress::SieveTreeWidgetProgress(SieveTreeWidgetItem *item, QObject *parent)
26  : QObject(parent)
27  , mItem(item)
28 {
29  KIconLoader loader;
30  mProgressPix = loader.loadPixmapSequence(QStringLiteral("process-working"), KIconLoader::SizeSmallMedium);
31  mProgressTimer = new QTimer(this);
32  connect(mProgressTimer, &QTimer::timeout, this, &SieveTreeWidgetProgress::slotTimerDone);
33 }
34 
35 SieveTreeWidgetProgress::~SieveTreeWidgetProgress()
36 {
37 }
38 
39 void SieveTreeWidgetProgress::slotTimerDone()
40 {
41  mItem->setProgressAnimation(mProgressPix.frameAt(mProgressCount));
42  ++mProgressCount;
43  if (mProgressCount == 8) {
44  mProgressCount = 0;
45  }
46 
47  mProgressTimer->start(300);
48 }
49 
50 void SieveTreeWidgetProgress::startAnimation()
51 {
52  mProgressCount = 0;
53  mProgressTimer->start(300);
54 }
55 
56 void SieveTreeWidgetProgress::stopAnimation()
57 {
58  if (mProgressTimer->isActive()) {
59  mProgressTimer->stop();
60  }
61  mItem->setDefaultIcon();
62 }
63 
64 class KSieveUi::SieveTreeWidgetItemPrivate
65 {
66 public:
67  SieveTreeWidgetItemPrivate()
68  {
69  }
70 
71  ~SieveTreeWidgetItemPrivate()
72  {
73  delete mProgress;
74  }
75 
76  SieveTreeWidgetProgress *mProgress = nullptr;
77 };
78 
79 SieveTreeWidgetItem::SieveTreeWidgetItem(QTreeWidget *treeWidget, QTreeWidgetItem *item)
80  : QTreeWidgetItem(treeWidget, item)
81  , d(new KSieveUi::SieveTreeWidgetItemPrivate)
82 {
83  d->mProgress = new SieveTreeWidgetProgress(this);
84 }
85 
86 SieveTreeWidgetItem::~SieveTreeWidgetItem()
87 {
88  delete d;
89 }
90 
91 void SieveTreeWidgetItem::startAnimation()
92 {
93  d->mProgress->startAnimation();
94 }
95 
96 void SieveTreeWidgetItem::stopAnimation()
97 {
98  d->mProgress->stopAnimation();
99 }
100 
101 void SieveTreeWidgetItem::setProgressAnimation(const QPixmap &pix)
102 {
103  setIcon(0, QIcon(pix));
104 }
105 
106 void SieveTreeWidgetItem::setDefaultIcon()
107 {
108  setIcon(0, QIcon::fromTheme(QStringLiteral("network-server")));
109 }
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-2020 The KDE developers.
Generated on Mon Jun 1 2020 23:08:21 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.