1
// vim: set tabstop=4 shiftwidth=4 noexpandtab:
3
Gwenview: an image viewer
4
Copyright 2009 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, write to the Free Software
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
22
#include "messagebubble.moc"
25
#include <QHBoxLayout>
29
#include <QToolButton>
39
static const int TIMEOUT = 10000;
41
class PieWidget : public QWidget {
43
PieWidget(QWidget* parent=0)
47
setMinimumSize(16, 16);
50
void setValue(qreal value) {
55
int heightForWidth(int width) const {
60
void paintEvent(QPaintEvent*) {
61
QPainter painter(this);
62
painter.setRenderHint(QPainter::Antialiasing);
63
const int circle = 5760;
64
const int start = circle / 4; // Start at 12h, not 3h
65
const int end = int(circle * mValue);
66
painter.setBrush(palette().dark());
67
painter.setPen(palette().light().color());
69
QRectF square = QRectF(rect()).adjusted(.5, .5, -.5, -.5);
70
qreal width = square.width();
71
qreal height= square.height();
73
square.setHeight(width);
74
square.moveTop((height - width) / 2);
76
square.setWidth(height);
77
square.moveLeft((width - height) / 2);
79
painter.drawPie(square, start, end);
87
struct MessageBubblePrivate {
88
PieWidget* mCountDownWidget;
94
MessageBubble::MessageBubble(QWidget* parent)
96
, d(new MessageBubblePrivate) {
97
d->mWidget = new QWidget;
98
d->mCountDownWidget = new PieWidget;
99
d->mCountDownWidget->setValue(1);
100
d->mLabel = new QLabel;
102
QTimeLine* timeLine = new QTimeLine(TIMEOUT, this);
103
connect(timeLine, SIGNAL(valueChanged(qreal)),
104
SLOT(slotTimeLineChanged(qreal)));
105
connect(timeLine, SIGNAL(finished()),
106
SLOT(deleteLater()));
109
QHBoxLayout* layout = new QHBoxLayout(d->mWidget);
110
layout->setMargin(0);
111
layout->addWidget(d->mCountDownWidget);
112
layout->addWidget(d->mLabel);
114
init(d->mWidget, HudWidget::OptionCloseButton);
118
MessageBubble::~MessageBubble() {
123
void MessageBubble::setText(const QString& text) {
124
d->mLabel->setText(text);
129
QToolButton* MessageBubble::addButton(const KGuiItem& guiItem) {
130
QToolButton* button = new QToolButton;
131
button->setText(guiItem.text());
132
button->setIcon(guiItem.icon());
133
button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
134
d->mWidget->layout()->addWidget(button);
140
void MessageBubble::slotTimeLineChanged(qreal value) {
141
d->mCountDownWidget->setValue(1 - value);