2
* Copyright 2010 Marco Martin <mart@kde.org>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Library General Public License as
6
* published by the Free Software Foundation; either version 2, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details
14
* You should have received a copy of the GNU Library General Public
15
* License along with this program; if not, write to the
16
* Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
#include "dragcountdown.h"
24
#include <QStyleOptionGraphicsItem>
28
#include <KIconLoader>
31
#include <Plasma/Theme>
33
DragCountdown::DragCountdown(QGraphicsItem *parent)
34
: QGraphicsWidget(parent),
39
setFlag(QGraphicsItem::ItemHasNoContents, false);
40
m_animationTimer = new QTimer(this);
42
m_countdownTimer = new QTimer(this);
43
m_countdownTimer->setSingleShot(true);
44
connect(m_countdownTimer, SIGNAL(timeout()), this, SIGNAL(dragRequested()));
46
m_animationTimer = new QTimer(this);
47
m_animationTimer->setSingleShot(false);
48
connect(m_animationTimer, SIGNAL(timeout()), this, SLOT(updateProgress()));
50
resize(KIconLoader::SizeLarge, KIconLoader::SizeLarge);
52
m_icons = new Plasma::Svg(this);
53
m_icons->setImagePath("widgets/configuration-icons");
54
m_icons->setContainsMultipleImages(true);
57
DragCountdown::~DragCountdown()
61
void DragCountdown::start(const int timeout)
65
m_increment = (qreal)40/timeout;
66
m_animationTimer->start(40);
73
void DragCountdown::stop()
75
m_animationTimer->stop();
79
void DragCountdown::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
83
painter->setRenderHint(QPainter::Antialiasing);
84
QColor color(Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor));
86
painter->setPen(QPen(color, 4));
88
if (m_animationTimer->isActive()) {
89
painter->drawArc(boundingRect(), 0, m_progress * 360 * 16);
91
m_icons->paint(painter, boundingRect(), "move");
97
void DragCountdown::updateProgress()
99
m_progress += m_increment;
100
if (m_progress >= 1) {
101
m_animationTimer->stop();
103
emit dragRequested();
108
#include "dragcountdown.moc"