• Skip to content
  • Skip to link menu
KDE 4.7 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 #include <QGraphicsView>
00026 
00027 #include <kmimetype.h>
00028 #include <knuminput.h>
00029 
00030 #include "applet.h"
00031 #include "framesvg.h"
00032 #include "private/focusindicator_p.h"
00033 #include "private/style_p.h"
00034 #include "private/themedwidgetinterface_p.h"
00035 #include "theme.h"
00036 
00037 namespace Plasma
00038 {
00039 
00040 class SpinBoxPrivate : public ThemedWidgetInterface<SpinBox>
00041 {
00042 public:
00043     SpinBoxPrivate(SpinBox *spinBox)
00044         : ThemedWidgetInterface<SpinBox>(spinBox),
00045           focusIndicator(0)
00046     {
00047         buttonColorForText = true;
00048     }
00049 
00050     ~SpinBoxPrivate()
00051     {
00052     }
00053 
00054     Plasma::Style::Ptr style;
00055     Plasma::FrameSvg *background;
00056     FocusIndicator *focusIndicator;
00057 };
00058 
00059 SpinBox::SpinBox(QGraphicsWidget *parent)
00060     : QGraphicsProxyWidget(parent),
00061       d(new SpinBoxPrivate(this))
00062 {
00063     KIntSpinBox *native = new KIntSpinBox;
00064 
00065     connect(native, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int)));
00066     connect(native, SIGNAL(editingFinished()), this, SIGNAL(editingFinished()));
00067 
00068     d->focusIndicator = new FocusIndicator(this, "widgets/lineedit");
00069 
00070     setWidget(native);
00071     native->setWindowIcon(QIcon());
00072     native->setAttribute(Qt::WA_NoSystemBackground);
00073     native->setAutoFillBackground(false);
00074 
00075     d->background = new Plasma::FrameSvg(this);
00076     d->background->setImagePath("widgets/lineedit");
00077     d->background->setCacheAllRenderedFrames(true);
00078 
00079 
00080     d->style = Plasma::Style::sharedStyle();
00081     native->setStyle(d->style.data());
00082     d->initTheming();
00083 
00084     QStyleOptionSpinBox spinOpt;
00085     spinOpt.initFrom(nativeWidget());
00086     QRect controlrect = nativeWidget()->style()->subControlRect(QStyle::CC_SpinBox, &spinOpt, QStyle::SC_SpinBoxFrame, nativeWidget());
00087     d->focusIndicator->setCustomGeometry(controlrect);
00088 }
00089 
00090 SpinBox::~SpinBox()
00091 {
00092     delete d;
00093     Plasma::Style::doneWithSharedStyle();
00094 }
00095 
00096 void SpinBox::setMaximum(int max)
00097 {
00098     static_cast<KIntSpinBox*>(widget())->setMaximum(max);
00099 }
00100 
00101 int SpinBox::maximum() const
00102 {
00103     return static_cast<KIntSpinBox*>(widget())->maximum();
00104 }
00105 
00106 void SpinBox::setMinimum(int min)
00107 {
00108     static_cast<KIntSpinBox*>(widget())->setMinimum(min);
00109 }
00110 
00111 int SpinBox::minimum() const
00112 {
00113     return static_cast<KIntSpinBox*>(widget())->minimum();
00114 }
00115 
00116 void SpinBox::setRange(int min, int max)
00117 {
00118     static_cast<KIntSpinBox*>(widget())->setRange(min, max);
00119 }
00120 
00121 void SpinBox::setValue(int value)
00122 {
00123     static_cast<KIntSpinBox*>(widget())->setValue(value);
00124 }
00125 
00126 int SpinBox::value() const
00127 {
00128     return static_cast<KIntSpinBox*>(widget())->value();
00129 }
00130 
00131 void SpinBox::setStyleSheet(const QString &stylesheet)
00132 {
00133     widget()->setStyleSheet(stylesheet);
00134 }
00135 
00136 QString SpinBox::styleSheet()
00137 {
00138     return widget()->styleSheet();
00139 }
00140 
00141 KIntSpinBox *SpinBox::nativeWidget() const
00142 {
00143     return static_cast<KIntSpinBox*>(widget());
00144 }
00145 
00146 void SpinBox::changeEvent(QEvent *event)
00147 {
00148     d->changeEvent(event);
00149     QGraphicsProxyWidget::changeEvent(event);
00150 }
00151 
00152 void SpinBox::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
00153 {
00154     Q_UNUSED(event)
00155     update();
00156 }
00157 
00158 void SpinBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
00159 {
00160     Q_UNUSED(event)
00161     update();
00162 }
00163 
00164 void SpinBox::resizeEvent(QGraphicsSceneResizeEvent *event)
00165 {
00166     QGraphicsProxyWidget::resizeEvent(event);
00167     QStyleOptionSpinBox spinOpt;
00168     spinOpt.initFrom(nativeWidget());
00169     QRect controlrect = nativeWidget()->style()->subControlRect(QStyle::CC_SpinBox, &spinOpt, QStyle::SC_SpinBoxFrame, nativeWidget());
00170 
00171     if (d->focusIndicator) {
00172         d->focusIndicator->setCustomGeometry(controlrect);
00173     }
00174 }
00175 
00176 void SpinBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
00177 {
00178     Q_UNUSED(option)
00179     Q_UNUSED(widget)
00180 
00181     QGraphicsProxyWidget::paint(painter, option, widget);
00182 }
00183 
00184 void SpinBox::mousePressEvent(QGraphicsSceneMouseEvent *event)
00185 {
00186     QGraphicsWidget *widget = parentWidget();
00187     Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);
00188 
00189     while (!applet && widget) {
00190         widget = widget->parentWidget();
00191         applet = qobject_cast<Plasma::Applet *>(widget);
00192     }
00193 
00194     if (applet) {
00195         applet->setStatus(Plasma::AcceptingInputStatus);
00196     }
00197     QGraphicsProxyWidget::mousePressEvent(event);
00198 }
00199 
00200 void SpinBox::focusOutEvent(QFocusEvent *event)
00201 {
00202     QGraphicsWidget *widget = parentWidget();
00203     Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);
00204 
00205     while (!applet && widget) {
00206         widget = widget->parentWidget();
00207         applet = qobject_cast<Plasma::Applet *>(widget);
00208     }
00209 
00210     if (applet) {
00211         applet->setStatus(Plasma::UnknownStatus);
00212     }
00213 
00214     QEvent closeEvent(QEvent::CloseSoftwareInputPanel);
00215     if (qApp) {
00216         if (QGraphicsView *view = qobject_cast<QGraphicsView*>(qApp->focusWidget())) {
00217             if (view->scene() && view->scene() == scene()) {
00218                 QApplication::sendEvent(view, &closeEvent);
00219             }
00220         }
00221     }
00222 
00223     QGraphicsProxyWidget::focusOutEvent(event);
00224 }
00225 
00226 } // namespace Plasma
00227 
00228 #include <spinbox.moc>
00229 

Plasma

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • 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.5
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