• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Applets

monitorbutton.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright (C) 2007 Petri Damsten <damu@iki.fi>
00003  *
00004  *   This program is free software; you can redistribute it and/or modify
00005  *   it under the terms of the GNU Library General Public License as
00006  *   published by the Free Software Foundation; either version 2, or
00007  *   (at your option) any later version.
00008  *
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details
00013  *
00014  *   You should have received a copy of the GNU Library General Public
00015  *   License along with this program; if not, write to the
00016  *   Free Software Foundation, Inc.,
00017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018  */
00019 
00020 #include "monitorbutton.h"
00021 
00022 #include <QIcon>
00023 #include <QPainter>
00024 #include <QTimeLine>
00025 
00026 #include <KDebug>
00027 #include <KIcon>
00028 #include <KPushButton>
00029 
00030 #include <Plasma/PaintUtils>
00031 
00032 #define MARGIN 2
00033 
00034 class MonitorButton::Private
00035 {
00036 public:
00037     Private() : imageSize(32, 32)
00038     {
00039     }
00040 
00041     QSize imageSize;
00042     QString image;
00043     KIcon icon;
00044     QTimeLine highlighter;
00045 };
00046 
00047 MonitorButton::MonitorButton(QGraphicsWidget *parent) :
00048         Plasma::PushButton(parent),
00049         d(new Private)
00050 {
00051    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
00052    setPreferredSize(d->imageSize.width() + 2 * MARGIN, d->imageSize.height() + 2 * MARGIN);
00053 
00054    d->highlighter.setDuration(100);
00055    d->highlighter.setFrameRange(0, 10);
00056    d->highlighter.setCurveShape(QTimeLine::EaseInCurve);
00057    connect(&d->highlighter, SIGNAL(valueChanged(qreal)), this, SLOT(highlight()));
00058 }
00059 
00060 MonitorButton::~MonitorButton()
00061 {
00062     delete d;
00063 }
00064 
00065 QString MonitorButton::image() const
00066 {
00067     return d->image;
00068 }
00069 
00070 void MonitorButton::setImage(const QString &image)
00071 {
00072     d->image = image;
00073     d->icon = KIcon(image);
00074     update();
00075 }
00076 
00077 void MonitorButton::highlight()
00078 {
00079     update();
00080 }
00081 
00082 void MonitorButton::hoverEnterEvent(QGraphicsSceneHoverEvent * event)
00083 {
00084     if (nativeWidget()->isChecked()) {
00085         return;
00086     }
00087 
00088     d->highlighter.setDirection(QTimeLine::Forward);
00089     d->highlighter.start();
00090 }
00091 
00092 void MonitorButton::hoverLeaveEvent(QGraphicsSceneHoverEvent * event)
00093 {
00094     if (nativeWidget()->isChecked()) {
00095         return;
00096     }
00097 
00098     d->highlighter.setDirection(QTimeLine::Backward);
00099     d->highlighter.start();
00100 }
00101 
00102 void MonitorButton::paint(QPainter *p,
00103                           const QStyleOptionGraphicsItem *option,
00104                           QWidget *widget)
00105 {
00106     Q_UNUSED(option)
00107     Q_UNUSED(widget)
00108 
00109     QIcon::Mode mode = QIcon::Disabled;
00110     if (nativeWidget()->isChecked()) {
00111         mode = QIcon::Normal;
00112     }
00113 
00114     QPixmap icon = Plasma::PaintUtils::transition(d->icon.pixmap(d->imageSize, QIcon::Disabled),
00115                                                   d->icon.pixmap(d->imageSize, QIcon::Normal),
00116                                                   nativeWidget()->isChecked() ? 1 : d->highlighter.currentValue());
00117     p->drawPixmap(QPointF((size().width() - d->imageSize.width()) / 2,
00118                         (size().height() - d->imageSize.height()) / 2),
00119                   icon);
00120 }
00121 
00122 #include "monitorbutton.moc"

Applets

Skip menu "Applets"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal