[SCM] ktp-common-internals packaging branch, master, updated. debian/15.12.1-2-1839-gf0635e9
Maximiliano Curia
maxy at moszumanska.debian.org
Mon May 9 09:04:40 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=e2b86ae
The following commit has been merged in the master branch:
commit e2b86ae292fbf5ebe2604640cc0301d60a8caae5
Author: Martin Klapetek <martin.klapetek at gmail.com>
Date: Thu Nov 10 11:35:44 2011 +0100
Circular countdown widget
Displays the countdown in a subtracting circle, like clock countdown
Reviewed-by: Daniele E. Domenichelli
REVIEW: 103094
---
circular-countdown.cpp | 112 +++++++++++++++++++++++++++++
error-dictionary.h => circular-countdown.h | 45 +++++++-----
2 files changed, 138 insertions(+), 19 deletions(-)
diff --git a/circular-countdown.cpp b/circular-countdown.cpp
new file mode 100644
index 0000000..0821e4c
--- /dev/null
+++ b/circular-countdown.cpp
@@ -0,0 +1,112 @@
+/*
+ Circular countdown widget
+ Copyright (C) 2011 Martin Klapetek <martin.klapetek at gmail.com>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "circular-countdown.h"
+
+#include <QPainter>
+#include <QPaintEvent>
+#include <QTimeLine>
+
+class CircularCountdown::Private
+{
+public:
+ Private(CircularCountdown *parent)
+ : q(parent)
+ {
+
+ }
+
+ CircularCountdown *q;
+ QTimeLine *timeLine;
+};
+
+CircularCountdown::CircularCountdown(int msec, QWidget *parent)
+ : QWidget(parent),
+ d(new Private(this))
+{
+ setAutoFillBackground(false);
+
+ d->timeLine = new QTimeLine(msec, this);
+ //circle has 360 degrees, for better smoothness we use 2x as much
+ d->timeLine->setFrameRange(0, 720);
+ //to paint the subtraction animation, we start from full circle to 0
+ d->timeLine->setDirection(QTimeLine::Backward);
+
+ //repaint on every frame change for smooth animation
+ connect(d->timeLine, SIGNAL(frameChanged(int)), this, SLOT(repaint()));
+
+ //repaint after animation is finished
+ connect(d->timeLine, SIGNAL(finished()), this, SLOT(repaint()));
+
+ //emit timeoutReached() when the timeout is reached
+ connect(d->timeLine, SIGNAL(finished()), this, SIGNAL(timeout()));
+}
+
+CircularCountdown::~CircularCountdown()
+{
+}
+
+void CircularCountdown::paintEvent(QPaintEvent *event) {
+ if (d->timeLine->state() == QTimeLine::Running || d->timeLine->state() == QTimeLine::Paused) {
+ QPainter painter(this);
+ //always take parent widget's palette and use it's Base color
+ painter.setBrush(QBrush(parentWidget()->palette().color(QPalette::Base), Qt::SolidPattern));
+ painter.setRenderHint(QPainter::Antialiasing);
+ /* drawPie always paints 1/16th of a degree, the total circle is 5760 (16 * 360)
+ * the first argument is this widget size with 2px padding
+ * second argument is start position, which is 3 o'clock by default,
+ * to move it to 12 o'clock we need to start at 90 degrees, hence 90 * 16
+ * third argument tells how much of the current circle is painted
+ * the range is [0..720], hence the *8 (to get 5760 in total)
+ * and it's minus because we want it to rotate in the other direction
+ */
+ painter.drawPie(this->rect().adjusted(2, 2, -2, -2), 90*16, -d->timeLine->currentFrame()*8);
+ }
+}
+
+QSize CircularCountdown::sizeHint() const
+{
+ return QSize(16, 16);
+}
+
+void CircularCountdown::setDuration(int msec) {
+ d->timeLine->setDuration(msec);
+}
+
+int CircularCountdown::duration() const
+{
+ return d->timeLine->duration();
+}
+
+void CircularCountdown::start() {
+ d->timeLine->start();
+}
+
+void CircularCountdown::stop() {
+ d->timeLine->stop();
+}
+
+void CircularCountdown::pause() {
+ //no, there really is no ->pause() if you're thinking about that ;)
+ d->timeLine->setPaused(true);
+}
+
+void CircularCountdown::resume() {
+ d->timeLine->resume();
+}
diff --git a/error-dictionary.h b/circular-countdown.h
similarity index 53%
copy from error-dictionary.h
copy to circular-countdown.h
index ee92d12..039ce75 100644
--- a/error-dictionary.h
+++ b/circular-countdown.h
@@ -1,5 +1,5 @@
/*
- Telepathy error dictionary - usable strings for dbus messages
+ Circular countdown widget
Copyright (C) 2011 Martin Klapetek <martin.klapetek at gmail.com>
This library is free software; you can redistribute it and/or
@@ -17,32 +17,39 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#ifndef CIRCULARCOUNTDOWN_H
+#define CIRCULARCOUNTDOWN_H
-#ifndef ERROR_DICTIONARY_H
-#define ERROR_DICTIONARY_H
+#include <QWidget>
-#include <QObject>
-#include <QHash>
-
-class ErrorDictionary : public QObject
+class CircularCountdown : public QWidget
{
+ Q_OBJECT
public:
- static ErrorDictionary *instance();
- virtual ~ErrorDictionary();
+ explicit CircularCountdown(int msec = 5000, QWidget *parent = 0);
+ ~CircularCountdown();
- ///Returns a verbose error message usable for displaying to the user
- QString displayVerboseErrorMessage(const QString& dbusErrorName) const;
+ void setDuration(int msec);
+ int duration() const;
- ///Returns a short error message usable for little space
- QString displayShortErrorMessage(const QString& dbusErrorName) const;
+public Q_SLOTS:
+ void start();
+ void stop();
+ void pause();
+ void resume();
+
+Q_SIGNALS:
+ void timeout();
-private:
- ErrorDictionary(QObject *parent);
- QHash<QString, QString> m_verboseDict;
- QHash<QString, QString> m_shortDict;
- static ErrorDictionary *s_instance;
+protected:
+ void paintEvent(QPaintEvent *event);
+ QSize sizeHint() const;
+
+private:
+ class Private;
+ Private * const d;
};
-#endif // ERROR_DICTIONARY_H
+#endif // CIRCULARCOUNTDOWN_H
--
ktp-common-internals packaging
More information about the pkg-kde-commits
mailing list