• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

Plasma

spinbox.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright 2008 Aaron Seigo <aseigo@kde.org>
00003  *   Copyright 2009 Davide Bettio <davide.bettio@kdemail.net>
00004  *
00005  *   This program is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU Library General Public License as
00007  *   published by the Free Software Foundation; either version 2, or
00008  *   (at your option) any later version.
00009  *
00010  *   This program is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details
00014  *
00015  *   You should have received a copy of the GNU Library General Public
00016  *   License along with this program; if not, write to the
00017  *   Free Software Foundation, Inc.,
00018  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00019  */
00020 
00021 #include "spinbox.h"
00022 
00023 #include <QPainter>
00024 #include <QStyleOptionSpinBox>
00025 
00026 #include <kmimetype.h>
00027 #include <knuminput.h>
00028 
00029 #include "applet.h"
00030 #include "framesvg.h"
00031 #include "private/focusindicator_p.h"
00032 #include "private/style_p.h"
00033 #include "private/themedwidgetinterface_p.h"
00034 #include "theme.h"
00035 
00036 namespace Plasma
00037 {
00038 
00039 class SpinBoxPrivate : public ThemedWidgetInterface<SpinBox>
00040 {
00041 public:
00042     SpinBoxPrivate(SpinBox *spinBox)
00043         : ThemedWidgetInterface<SpinBox>(spinBox),
00044           focusIndicator(0)
00045     {
00046         buttonColorForText = true;
00047     }
00048 
00049     ~SpinBoxPrivate()
00050     {
00051     }
00052 
00053     Plasma::Style::Ptr style;
00054     Plasma::FrameSvg *background;
00055     FocusIndicator *focusIndicator;
00056 };
00057 
00058 SpinBox::SpinBox(QGraphicsWidget *parent)
00059     : QGraphicsProxyWidget(parent),
00060       d(new SpinBoxPrivate(this))
00061 {
00062     KIntSpinBox *native = new KIntSpinBox;
00063 
00064     connect(native, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int)));
00065     connect(native, SIGNAL(editingFinished()), this, SIGNAL(editingFinished()));
00066 
00067     d->focusIndicator = new FocusIndicator(this, "widgets/lineedit");
00068 
00069     setWidget(native);
00070     native->setWindowIcon(QIcon());
00071     native->setAttribute(Qt::WA_NoSystemBackground);
00072     native->setAutoFillBackground(false);
00073 
00074     d->background = new Plasma::FrameSvg(this);
00075     d->background->setImagePath("widgets/lineedit");
00076     d->background->setCacheAllRenderedFrames(true);
00077 
00078 
00079     d->style = Plasma::Style::sharedStyle();
00080     native->setStyle(d->style.data());
00081     d->initTheming();
00082 
00083     QStyleOptionSpinBox spinOpt;
00084     spinOpt.initFrom(nativeWidget());
00085     QRect controlrect = nativeWidget()->style()->subControlRect(QStyle::CC_SpinBox, &spinOpt, QStyle::SC_SpinBoxFrame, nativeWidget());
00086     d->focusIndicator->setCustomGeometry(controlrect);
00087 }
00088 
00089 SpinBox::~SpinBox()
00090 {
00091     delete d;
00092     Plasma::Style::doneWithSharedStyle();
00093 }
00094 
00095 void SpinBox::setMaximum(int max)
00096 {
00097     static_cast<KIntSpinBox*>(widget())->setMaximum(max);
00098 }
00099 
00100 int SpinBox::maximum() const
00101 {
00102     return static_cast<KIntSpinBox*>(widget())->maximum();
00103 }
00104 
00105 void SpinBox::setMinimum(int min)
00106 {
00107     static_cast<KIntSpinBox*>(widget())->setMinimum(min);
00108 }
00109 
00110 int SpinBox::minimum() const
00111 {
00112     return static_cast<KIntSpinBox*>(widget())->minimum();
00113 }
00114 
00115 void SpinBox::setRange(int min, int max)
00116 {
00117     static_cast<KIntSpinBox*>(widget())->setRange(min, max);
00118 }
00119 
00120 void SpinBox::setValue(int value)
00121 {
00122     static_cast<KIntSpinBox*>(widget())->setValue(value);
00123 }
00124 
00125 int SpinBox::value() const
00126 {
00127     return static_cast<KIntSpinBox*>(widget())->value();
00128 }
00129 
00130 void SpinBox::setStyleSheet(const QString &stylesheet)
00131 {
00132     widget()->setStyleSheet(stylesheet);
00133 }
00134 
00135 QString SpinBox::styleSheet()
00136 {
00137     return widget()->styleSheet();
00138 }
00139 
00140 KIntSpinBox *SpinBox::nativeWidget() const
00141 {
00142     return static_cast<KIntSpinBox*>(widget());
00143 }
00144 
00145 void SpinBox::changeEvent(QEvent *event)
00146 {
00147     d->changeEvent(event);
00148     QGraphicsProxyWidget::changeEvent(event);
00149 }
00150 
00151 void SpinBox::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
00152 {
00153     Q_UNUSED(event)
00154     update();
00155 }
00156 
00157 void SpinBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
00158 {
00159     Q_UNUSED(event)
00160     update();
00161 }
00162 
00163 void SpinBox::resizeEvent(QGraphicsSceneResizeEvent *event)
00164 {
00165     QGraphicsProxyWidget::resizeEvent(event);
00166     QStyleOptionSpinBox spinOpt;
00167     spinOpt.initFrom(nativeWidget());
00168     QRect controlrect = nativeWidget()->style()->subControlRect(QStyle::CC_SpinBox, &spinOpt, QStyle::SC_SpinBoxFrame, nativeWidget());
00169 
00170     if (d->focusIndicator) {
00171         d->focusIndicator->setCustomGeometry(controlrect);
00172     }
00173 }
00174 
00175 void SpinBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
00176 {
00177     Q_UNUSED(option)
00178     Q_UNUSED(widget)
00179 
00180     QGraphicsProxyWidget::paint(painter, option, widget);
00181 }
00182 
00183 void SpinBox::mousePressEvent(QGraphicsSceneMouseEvent *event)
00184 {
00185     QGraphicsWidget *widget = parentWidget();
00186     Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);
00187 
00188     while (!applet && widget) {
00189         widget = widget->parentWidget();
00190         applet = qobject_cast<Plasma::Applet *>(widget);
00191     }
00192 
00193     if (applet) {
00194         applet->setStatus(Plasma::AcceptingInputStatus);
00195     }
00196     QGraphicsProxyWidget::mousePressEvent(event);
00197 }
00198 
00199 void SpinBox::focusOutEvent(QFocusEvent *event)
00200 {
00201     QGraphicsWidget *widget = parentWidget();
00202     Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);
00203 
00204     while (!applet && widget) {
00205         widget = widget->parentWidget();
00206         applet = qobject_cast<Plasma::Applet *>(widget);
00207     }
00208 
00209     if (applet) {
00210         applet->setStatus(Plasma::UnknownStatus);
00211     }
00212     QGraphicsProxyWidget::focusOutEvent(event);
00213 }
00214 
00215 } // namespace Plasma
00216 
00217 #include <spinbox.moc>
00218 

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
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