~ubuntu-branches/ubuntu/trusty/gwenview/trusty-proposed

« back to all changes in this revision

Viewing changes to lib/hud/hudcountdown.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2014-03-19 10:34:35 UTC
  • mto: This revision was merged to the branch mainline in revision 51.
  • Revision ID: package-import@ubuntu.com-20140319103435-r20hzcnkejmkcxp4
Tags: upstream-4.12.90
Import upstream version 4.12.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// vim: set tabstop=4 shiftwidth=4 expandtab:
 
2
/*
 
3
Gwenview: an image viewer
 
4
Copyright 2014 Aurélien Gâteau <agateau@kde.org>
 
5
 
 
6
This program is free software; you can redistribute it and/or
 
7
modify it under the terms of the GNU General Public License
 
8
as published by the Free Software Foundation; either version 2
 
9
of the License, or (at your option) any later version.
 
10
 
 
11
This program is distributed in the hope that it will be useful,
 
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
GNU General Public License for more details.
 
15
 
 
16
You should have received a copy of the GNU General Public License
 
17
along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
*/
 
19
// Self
 
20
#include <hudcountdown.moc>
 
21
 
 
22
// Local
 
23
#include <lib/hud/hudtheme.h>
 
24
 
 
25
// KDE
 
26
 
 
27
// Qt
 
28
#include <QPainter>
 
29
#include <QTimeLine>
 
30
 
 
31
namespace Gwenview
 
32
{
 
33
 
 
34
struct HudCountDownPrivate
 
35
{
 
36
    QTimeLine* mTimeLine;
 
37
};
 
38
 
 
39
HudCountDown::HudCountDown(QGraphicsWidget* parent)
 
40
: QGraphicsWidget(parent)
 
41
, d(new HudCountDownPrivate)
 
42
{
 
43
    d->mTimeLine = new QTimeLine(0, this);
 
44
    d->mTimeLine->setDirection(QTimeLine::Backward);
 
45
    connect(d->mTimeLine, SIGNAL(valueChanged(qreal)), SLOT(doUpdate()));
 
46
    connect(d->mTimeLine, SIGNAL(finished()), SIGNAL(timeout()));
 
47
 
 
48
    // Use an odd value so that the vertical line is aligned to pixel
 
49
    // boundaries
 
50
    setMinimumSize(17, 17);
 
51
}
 
52
 
 
53
HudCountDown::~HudCountDown()
 
54
{
 
55
    delete d;
 
56
}
 
57
 
 
58
void HudCountDown::start(qreal ms)
 
59
{
 
60
    d->mTimeLine->setDuration(ms);
 
61
    d->mTimeLine->start();
 
62
    update();
 
63
}
 
64
 
 
65
void HudCountDown::paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*)
 
66
{
 
67
    HudTheme::RenderInfo info = HudTheme::renderInfo(HudTheme::CountDown);
 
68
    painter->setRenderHint(QPainter::Antialiasing);
 
69
    const int circle = 5760;
 
70
    const int start = circle / 4; // Start at 12h, not 3h
 
71
    const int end = int(circle * d->mTimeLine->currentValue());
 
72
    painter->setBrush(info.bgBrush);
 
73
    painter->setPen(info.borderPen);
 
74
 
 
75
    QRectF square = boundingRect().adjusted(.5, .5, -.5, -.5);
 
76
    qreal width = square.width();
 
77
    qreal height = square.height();
 
78
    if (width < height) {
 
79
        square.setHeight(width);
 
80
        square.moveTop((height - width) / 2);
 
81
    } else {
 
82
        square.setWidth(height);
 
83
        square.moveLeft((width - height) / 2);
 
84
    }
 
85
    painter->drawPie(square, start, end);
 
86
}
 
87
 
 
88
void HudCountDown::doUpdate()
 
89
{
 
90
    update();
 
91
}
 
92
 
 
93
} // namespace