2 * Copyright (C) 2007 Petri Damsten <damu@iki.fi>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2, 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 Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "monitorbutton.h"
28 #include <KPushButton>
30 #include <Plasma/PaintUtils>
34 class MonitorButton::Private
37 Private() : imageSize(32, 32)
44 QTimeLine highlighter
;
47 MonitorButton::MonitorButton(QGraphicsWidget
*parent
) :
48 Plasma::PushButton(parent
),
51 setSizePolicy(QSizePolicy::Expanding
, QSizePolicy::Fixed
);
52 setPreferredSize(d
->imageSize
.width() + 2 * MARGIN
, d
->imageSize
.height() + 2 * MARGIN
);
54 d
->highlighter
.setDuration(100);
55 d
->highlighter
.setFrameRange(0, 10);
56 d
->highlighter
.setCurveShape(QTimeLine::EaseInCurve
);
57 connect(&d
->highlighter
, SIGNAL(valueChanged(qreal
)), this, SLOT(highlight()));
60 MonitorButton::~MonitorButton()
65 QString
MonitorButton::image() const
70 void MonitorButton::setImage(const QString
&image
)
73 d
->icon
= KIcon(image
);
77 void MonitorButton::highlight()
82 void MonitorButton::hoverEnterEvent(QGraphicsSceneHoverEvent
* event
)
84 if (nativeWidget()->isChecked()) {
88 d
->highlighter
.setDirection(QTimeLine::Forward
);
89 d
->highlighter
.start();
92 void MonitorButton::hoverLeaveEvent(QGraphicsSceneHoverEvent
* event
)
94 if (nativeWidget()->isChecked()) {
98 d
->highlighter
.setDirection(QTimeLine::Backward
);
99 d
->highlighter
.start();
102 void MonitorButton::paint(QPainter
*p
,
103 const QStyleOptionGraphicsItem
*option
,
109 QIcon::Mode mode
= QIcon::Disabled
;
110 if (nativeWidget()->isChecked()) {
111 mode
= QIcon::Normal
;
114 QPixmap icon
= Plasma::PaintUtils::transition(d
->icon
.pixmap(d
->imageSize
, QIcon::Disabled
),
115 d
->icon
.pixmap(d
->imageSize
, QIcon::Normal
),
116 nativeWidget()->isChecked() ? 1 : d
->highlighter
.currentValue());
117 p
->drawPixmap(QPointF((size().width() - d
->imageSize
.width()) / 2,
118 (size().height() - d
->imageSize
.height()) / 2),
122 #include "monitorbutton.moc"