SVN_SILENT made messages (.desktop file)
[kdegraphics.git] / ksnapshot / snapshottimer.cpp
blobeb7035550fe82260e3083b8b83c99e3b3f680d6b
1 /*
2 * Copyright (C) 2007777777 Aaron J. Seigo <aseigo@kde.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, 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 Lesser General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #include <QTimerEvent>
21 #include <QPainter>
22 #include <QPaintEvent>
23 #include <QToolTip>
25 #include <KDebug>
26 #include <klocale.h>
29 #include "snapshottimer.h"
31 SnapshotTimer::SnapshotTimer() : QWidget(0)
33 setWindowFlags( Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint);
34 resize(180,20);
35 connect(&timer, SIGNAL(timeout()), this, SLOT(bell()));
38 SnapshotTimer::~SnapshotTimer()
42 void SnapshotTimer::start(int seconds)
44 show();
45 time = 0;
46 length = seconds;
47 timer.start(1000);
50 void SnapshotTimer::stop()
52 setVisible(false);
53 hide();
54 timer.stop();
57 void SnapshotTimer::bell()
59 if (time == length - 1) {
60 hide();
61 } else {
62 if (time == length) {
63 emit timeout();
64 timer.stop();
67 ++time;
68 update();
71 void SnapshotTimer::paintEvent( QPaintEvent* e )
73 Q_UNUSED( e );
75 QPainter painter( this );
77 if (time < length) {
78 QPalette pal(QToolTip::palette());
79 QColor handleColor = pal.color( QPalette::Active, QPalette::Highlight );
80 handleColor.setAlpha( 160 );
81 QColor overlayColor( 0, 0, 0, 160 );
82 QColor textColor = pal.color( QPalette::Active, QPalette::Text );
83 QColor textBackgroundColor = pal.color( QPalette::Active, QPalette::Base );
85 painter.setPen( textColor );
86 painter.setBrush( textBackgroundColor );
87 QString helpText = i18np( "Snapshot will be taken in 1 second",
88 "Snapshot will be taken in %1 seconds", ( length-time ) );
89 QRect textRect = painter.boundingRect( rect().adjusted( 2, 2, -2, -2 ), Qt::TextWordWrap, helpText );
90 textRect.adjust( -2, -2, 4, 2 );
91 painter.drawRect( rect().adjusted(0,0,-1,-1) );
92 textRect.moveTopLeft( QPoint( 3, 3 ) );
93 painter.drawText(textRect, helpText);