• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.8.3 API Reference
  • 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     d->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     if (d->background->hasElement("hint-focus-over-base")) {
00080         d->focusIndicator->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
00081     }
00082 
00083     d->style = Plasma::Style::sharedStyle();
00084     native->setStyle(d->style.data());
00085     d->initTheming();
00086 
00087     QStyleOptionSpinBox spinOpt;
00088     spinOpt.initFrom(nativeWidget());
00089     QRect controlrect = nativeWidget()->style()->subControlRect(QStyle::CC_SpinBox, &spinOpt, QStyle::SC_SpinBoxFrame, nativeWidget());
00090     d->focusIndicator->setCustomGeometry(controlrect);
00091 }
00092 
00093 SpinBox::~SpinBox()
00094 {
00095     delete d;
00096     Plasma::Style::doneWithSharedStyle();
00097 }
00098 
00099 void SpinBox::setMaximum(int max)
00100 {
00101     static_cast<KIntSpinBox*>(widget())->setMaximum(max);
00102 }
00103 
00104 int SpinBox::maximum() const
00105 {
00106     return static_cast<KIntSpinBox*>(widget())->maximum();
00107 }
00108 
00109 void SpinBox::setMinimum(int min)
00110 {
00111     static_cast<KIntSpinBox*>(widget())->setMinimum(min);
00112 }
00113 
00114 int SpinBox::minimum() const
00115 {
00116     return static_cast<KIntSpinBox*>(widget())->minimum();
00117 }
00118 
00119 void SpinBox::setRange(int min, int max)
00120 {
00121     static_cast<KIntSpinBox*>(widget())->setRange(min, max);
00122 }
00123 
00124 void SpinBox::setValue(int value)
00125 {
00126     static_cast<KIntSpinBox*>(widget())->setValue(value);
00127 }
00128 
00129 int SpinBox::value() const
00130 {
00131     return static_cast<KIntSpinBox*>(widget())->value();
00132 }
00133 
00134 void SpinBox::setStyleSheet(const QString &stylesheet)
00135 {
00136     widget()->setStyleSheet(stylesheet);
00137 }
00138 
00139 QString SpinBox::styleSheet()
00140 {
00141     return widget()->styleSheet();
00142 }
00143 
00144 KIntSpinBox *SpinBox::nativeWidget() const
00145 {
00146     return static_cast<KIntSpinBox*>(widget());
00147 }
00148 
00149 void SpinBox::changeEvent(QEvent *event)
00150 {
00151     d->changeEvent(event);
00152     QGraphicsProxyWidget::changeEvent(event);
00153 }
00154 
00155 void SpinBox::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
00156 {
00157     Q_UNUSED(event)
00158     update();
00159 }
00160 
00161 void SpinBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
00162 {
00163     Q_UNUSED(event)
00164     update();
00165 }
00166 
00167 void SpinBox::resizeEvent(QGraphicsSceneResizeEvent *event)
00168 {
00169     QGraphicsProxyWidget::resizeEvent(event);
00170     QStyleOptionSpinBox spinOpt;
00171     spinOpt.initFrom(nativeWidget());
00172     QRect controlrect = nativeWidget()->style()->subControlRect(QStyle::CC_SpinBox, &spinOpt, QStyle::SC_SpinBoxFrame, nativeWidget());
00173 
00174     if (d->focusIndicator) {
00175         d->focusIndicator->setCustomGeometry(controlrect);
00176     }
00177 }
00178 
00179 void SpinBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
00180 {
00181     Q_UNUSED(option)
00182     Q_UNUSED(widget)
00183 
00184     QGraphicsProxyWidget::paint(painter, option, widget);
00185 }
00186 
00187 void SpinBox::mousePressEvent(QGraphicsSceneMouseEvent *event)
00188 {
00189     QGraphicsWidget *widget = parentWidget();
00190     Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);
00191 
00192     while (!applet && widget) {
00193         widget = widget->parentWidget();
00194         applet = qobject_cast<Plasma::Applet *>(widget);
00195     }
00196 
00197     if (applet) {
00198         applet->setStatus(Plasma::AcceptingInputStatus);
00199     }
00200     QGraphicsProxyWidget::mousePressEvent(event);
00201 }
00202 
00203 void SpinBox::focusOutEvent(QFocusEvent *event)
00204 {
00205     QGraphicsWidget *widget = parentWidget();
00206     Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);
00207 
00208     while (!applet && widget) {
00209         widget = widget->parentWidget();
00210         applet = qobject_cast<Plasma::Applet *>(widget);
00211     }
00212 
00213     if (applet) {
00214         applet->setStatus(Plasma::UnknownStatus);
00215     }
00216 
00217     QEvent closeEvent(QEvent::CloseSoftwareInputPanel);
00218     if (qApp) {
00219         if (QGraphicsView *view = qobject_cast<QGraphicsView*>(qApp->focusWidget())) {
00220             if (view->scene() && view->scene() == scene()) {
00221                 QApplication::sendEvent(view, &closeEvent);
00222             }
00223         }
00224     }
00225 
00226     QGraphicsProxyWidget::focusOutEvent(event);
00227 }
00228 
00229 } // namespace Plasma
00230 
00231 #include <spinbox.moc>
00232 
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 20:51:37 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

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-4.8.3 API Reference

Skip menu "kdelibs-4.8.3 API Reference"
  • 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
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal