1
// vim: set tabstop=4 shiftwidth=4 expandtab:
3
Gwenview: an image viewer
4
Copyright 2014 Aurélien Gâteau <agateau@kde.org>
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.
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.
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/>.
20
#include <hudcountdown.moc>
23
#include <lib/hud/hudtheme.h>
34
struct HudCountDownPrivate
39
HudCountDown::HudCountDown(QGraphicsWidget* parent)
40
: QGraphicsWidget(parent)
41
, d(new HudCountDownPrivate)
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()));
48
// Use an odd value so that the vertical line is aligned to pixel
50
setMinimumSize(17, 17);
53
HudCountDown::~HudCountDown()
58
void HudCountDown::start(qreal ms)
60
d->mTimeLine->setDuration(ms);
61
d->mTimeLine->start();
65
void HudCountDown::paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*)
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);
75
QRectF square = boundingRect().adjusted(.5, .5, -.5, -.5);
76
qreal width = square.width();
77
qreal height = square.height();
79
square.setHeight(width);
80
square.moveTop((height - width) / 2);
82
square.setWidth(height);
83
square.moveLeft((width - height) / 2);
85
painter->drawPie(square, start, end);
88
void HudCountDown::doUpdate()