~ubuntu-branches/ubuntu/maverick/plasma-mobile/maverick

« back to all changes in this revision

Viewing changes to containments/mobiledesktop/dragcountdown.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Belem
  • Date: 2010-08-30 23:41:22 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20100830234122-3q94e0vf1qfl4e2c
Tags: 0.0~svn20100830-0ubuntu1
* New svn snapshot, revision 1170070. (LP: #627205)
* Updated Standards-Version to 3.9.1.
* Updated the build-dep kdebase-workspace-dev to >= 4.5.
* Removed the patches kubuntu_02_enable_mobilesystray_build.diff and
  kubuntu_03_add_mobilesystray_to_all_desktops.diff since upstream
  already enables the systray build and it is by default on all
  desktops.
* Switch to dpkg-source 3.0 (quilt) format.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright 2010 Marco Martin <mart@kde.org>
 
3
 *
 
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.
 
8
 *
 
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
 
13
 *
 
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.
 
18
 */
 
19
 
 
20
#include "dragcountdown.h"
 
21
 
 
22
#include <QColor>
 
23
#include <QPainter>
 
24
#include <QStyleOptionGraphicsItem>
 
25
#include <QTimer>
 
26
 
 
27
#include <KDebug>
 
28
#include <KIconLoader>
 
29
 
 
30
#include <Plasma/Svg>
 
31
#include <Plasma/Theme>
 
32
 
 
33
DragCountdown::DragCountdown(QGraphicsItem *parent)
 
34
    : QGraphicsWidget(parent),
 
35
      m_progress(0),
 
36
      m_increment(0)
 
37
{
 
38
    hide();
 
39
    setFlag(QGraphicsItem::ItemHasNoContents, false);
 
40
    m_animationTimer = new QTimer(this);
 
41
 
 
42
    m_countdownTimer = new QTimer(this);
 
43
    m_countdownTimer->setSingleShot(true);
 
44
    connect(m_countdownTimer, SIGNAL(timeout()), this, SIGNAL(dragRequested()));
 
45
 
 
46
    m_animationTimer = new QTimer(this);
 
47
    m_animationTimer->setSingleShot(false);
 
48
    connect(m_animationTimer, SIGNAL(timeout()), this, SLOT(updateProgress()));
 
49
 
 
50
    resize(KIconLoader::SizeLarge, KIconLoader::SizeLarge);
 
51
 
 
52
    m_icons = new Plasma::Svg(this);
 
53
    m_icons->setImagePath("widgets/configuration-icons");
 
54
    m_icons->setContainsMultipleImages(true);
 
55
}
 
56
 
 
57
DragCountdown::~DragCountdown()
 
58
{
 
59
}
 
60
 
 
61
void DragCountdown::start(const int timeout)
 
62
{
 
63
    m_progress = 0;
 
64
    if (timeout > 0) {
 
65
        m_increment = (qreal)40/timeout;
 
66
        m_animationTimer->start(40);
 
67
    } else {
 
68
        emit dragRequested();
 
69
    }
 
70
    show();
 
71
}
 
72
 
 
73
void DragCountdown::stop()
 
74
{
 
75
    m_animationTimer->stop();
 
76
    hide();
 
77
}
 
78
 
 
79
void DragCountdown::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
 
80
{
 
81
    painter->save();
 
82
 
 
83
    painter->setRenderHint(QPainter::Antialiasing);
 
84
    QColor color(Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor));
 
85
    color.setAlphaF(0.6);
 
86
    painter->setPen(QPen(color, 4));
 
87
 
 
88
    if (m_animationTimer->isActive()) {
 
89
        painter->drawArc(boundingRect(), 0, m_progress * 360 * 16);
 
90
    } else {
 
91
        m_icons->paint(painter, boundingRect(), "move");
 
92
    }
 
93
 
 
94
    painter->restore();
 
95
}
 
96
 
 
97
void DragCountdown::updateProgress()
 
98
{
 
99
    m_progress += m_increment;
 
100
    if (m_progress >= 1) {
 
101
        m_animationTimer->stop();
 
102
        m_progress = 0;
 
103
        emit dragRequested();
 
104
    }
 
105
    update();
 
106
}
 
107
 
 
108
#include "dragcountdown.moc"