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

Plasma

  • sources
  • kde-4.12
  • kdelibs
  • plasma
  • widgets
spinbox.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Aaron Seigo <aseigo@kde.org>
3  * Copyright 2009 Davide Bettio <davide.bettio@kdemail.net>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU Library General Public License as
7  * published by the Free Software Foundation; either version 2, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this program; if not, write to the
17  * Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #include "spinbox.h"
22 
23 #include <QPainter>
24 #include <QStyleOptionSpinBox>
25 #include <QGraphicsView>
26 
27 #include <kmimetype.h>
28 #include <knuminput.h>
29 
30 #include "applet.h"
31 #include "framesvg.h"
32 #include "private/focusindicator_p.h"
33 #include "private/style_p.h"
34 #include "private/themedwidgetinterface_p.h"
35 #include "theme.h"
36 
37 namespace Plasma
38 {
39 
40 class SpinBoxPrivate : public ThemedWidgetInterface<SpinBox>
41 {
42 public:
43  SpinBoxPrivate(SpinBox *spinBox)
44  : ThemedWidgetInterface<SpinBox>(spinBox),
45  focusIndicator(0)
46  {
47  buttonColorForText = true;
48  }
49 
50  ~SpinBoxPrivate()
51  {
52  }
53 
54  Plasma::Style::Ptr style;
55  Plasma::FrameSvg *background;
56  FocusIndicator *focusIndicator;
57 };
58 
59 SpinBox::SpinBox(QGraphicsWidget *parent)
60  : QGraphicsProxyWidget(parent),
61  d(new SpinBoxPrivate(this))
62 {
63  KIntSpinBox *native = new KIntSpinBox;
64 
65  connect(native, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int)));
66  connect(native, SIGNAL(editingFinished()), this, SIGNAL(editingFinished()));
67 
68  d->focusIndicator = new FocusIndicator(this, "widgets/lineedit");
69 
70  d->setWidget(native);
71  native->setWindowIcon(QIcon());
72  native->setAttribute(Qt::WA_NoSystemBackground);
73  native->setAutoFillBackground(false);
74 
75  d->background = new Plasma::FrameSvg(this);
76  d->background->setImagePath("widgets/lineedit");
77  d->background->setCacheAllRenderedFrames(true);
78 
79  if (d->background->hasElement("hint-focus-over-base")) {
80  d->focusIndicator->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
81  }
82 
83  d->style = Plasma::Style::sharedStyle();
84  native->setStyle(d->style.data());
85  d->initTheming();
86 
87  QStyleOptionSpinBox spinOpt;
88  spinOpt.initFrom(nativeWidget());
89  QRect controlrect = nativeWidget()->style()->subControlRect(QStyle::CC_SpinBox, &spinOpt, QStyle::SC_SpinBoxFrame, nativeWidget());
90  d->focusIndicator->setCustomGeometry(controlrect);
91 }
92 
93 SpinBox::~SpinBox()
94 {
95  delete d;
96  Plasma::Style::doneWithSharedStyle();
97 }
98 
99 void SpinBox::setMaximum(int max)
100 {
101  static_cast<KIntSpinBox*>(widget())->setMaximum(max);
102 }
103 
104 int SpinBox::maximum() const
105 {
106  return static_cast<KIntSpinBox*>(widget())->maximum();
107 }
108 
109 void SpinBox::setMinimum(int min)
110 {
111  static_cast<KIntSpinBox*>(widget())->setMinimum(min);
112 }
113 
114 int SpinBox::minimum() const
115 {
116  return static_cast<KIntSpinBox*>(widget())->minimum();
117 }
118 
119 void SpinBox::setRange(int min, int max)
120 {
121  static_cast<KIntSpinBox*>(widget())->setRange(min, max);
122 }
123 
124 void SpinBox::setValue(int value)
125 {
126  static_cast<KIntSpinBox*>(widget())->setValue(value);
127 }
128 
129 int SpinBox::value() const
130 {
131  return static_cast<KIntSpinBox*>(widget())->value();
132 }
133 
134 void SpinBox::setStyleSheet(const QString &stylesheet)
135 {
136  widget()->setStyleSheet(stylesheet);
137 }
138 
139 QString SpinBox::styleSheet()
140 {
141  return widget()->styleSheet();
142 }
143 
144 KIntSpinBox *SpinBox::nativeWidget() const
145 {
146  return static_cast<KIntSpinBox*>(widget());
147 }
148 
149 void SpinBox::changeEvent(QEvent *event)
150 {
151  d->changeEvent(event);
152  QGraphicsProxyWidget::changeEvent(event);
153 }
154 
155 void SpinBox::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
156 {
157  Q_UNUSED(event)
158  update();
159 }
160 
161 void SpinBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
162 {
163  Q_UNUSED(event)
164  update();
165 }
166 
167 void SpinBox::resizeEvent(QGraphicsSceneResizeEvent *event)
168 {
169  QGraphicsProxyWidget::resizeEvent(event);
170  QStyleOptionSpinBox spinOpt;
171  spinOpt.initFrom(nativeWidget());
172  QRect controlrect = nativeWidget()->style()->subControlRect(QStyle::CC_SpinBox, &spinOpt, QStyle::SC_SpinBoxFrame, nativeWidget());
173 
174  if (d->focusIndicator) {
175  d->focusIndicator->setCustomGeometry(controlrect);
176  }
177 }
178 
179 void SpinBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
180 {
181  Q_UNUSED(option)
182  Q_UNUSED(widget)
183 
184  QGraphicsProxyWidget::paint(painter, option, widget);
185 }
186 
187 void SpinBox::mousePressEvent(QGraphicsSceneMouseEvent *event)
188 {
189  QGraphicsWidget *widget = parentWidget();
190  Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);
191 
192  while (!applet && widget) {
193  widget = widget->parentWidget();
194  applet = qobject_cast<Plasma::Applet *>(widget);
195  }
196 
197  if (applet) {
198  applet->setStatus(Plasma::AcceptingInputStatus);
199  }
200  QGraphicsProxyWidget::mousePressEvent(event);
201 }
202 
203 void SpinBox::focusOutEvent(QFocusEvent *event)
204 {
205  QGraphicsWidget *widget = parentWidget();
206  Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);
207 
208  while (!applet && widget) {
209  widget = widget->parentWidget();
210  applet = qobject_cast<Plasma::Applet *>(widget);
211  }
212 
213  if (applet) {
214  applet->setStatus(Plasma::UnknownStatus);
215  }
216 
217  QEvent closeEvent(QEvent::CloseSoftwareInputPanel);
218  if (qApp) {
219  if (QGraphicsView *view = qobject_cast<QGraphicsView*>(qApp->focusWidget())) {
220  if (view->scene() && view->scene() == scene()) {
221  QApplication::sendEvent(view, &closeEvent);
222  }
223  }
224  }
225 
226  QGraphicsProxyWidget::focusOutEvent(event);
227 }
228 
229 } // namespace Plasma
230 
231 #include <spinbox.moc>
232 
Plasma::SpinBox::resizeEvent
void resizeEvent(QGraphicsSceneResizeEvent *event)
Definition: spinbox.cpp:167
Plasma::SpinBox::setStyleSheet
void setStyleSheet(const QString &stylesheet)
Sets the stylesheet used to control the visual display of this SpinBox.
Definition: spinbox.cpp:134
Plasma::UnknownStatus
The status is unknown.
Definition: plasma.h:257
Plasma::SpinBox::minimum
int minimum() const
Plasma::SpinBox::styleSheet
QString styleSheet()
Plasma::SpinBox::maximum
int maximum() const
QWidget
Plasma::SpinBox::changeEvent
void changeEvent(QEvent *event)
Definition: spinbox.cpp:149
theme.h
Plasma::SpinBox::focusOutEvent
void focusOutEvent(QFocusEvent *event)
Definition: spinbox.cpp:203
Plasma::FrameSvg
Provides an SVG with borders.
Definition: framesvg.h:76
Plasma::SpinBox::setMaximum
void setMaximum(int maximum)
Sets the maximum value the slider can take.
Definition: spinbox.cpp:99
Plasma::SpinBox::parentWidget
QGraphicsWidget parentWidget
Definition: spinbox.h:44
Plasma::Applet
The base Applet class.
Definition: applet.h:77
Plasma::SpinBox::setRange
void setRange(int minimum, int maximum)
Sets the minimum and maximum values the slider can take.
Definition: spinbox.cpp:119
Plasma::SpinBox::editingFinished
void editingFinished()
This signal is emitted when editing is finished.
Plasma::Applet::setStatus
void setStatus(const ItemStatus stat)
sets the status for this applet
Definition: applet.cpp:1198
Plasma::SpinBox::setValue
void setValue(int value)
Sets the value of the slider.
Definition: spinbox.cpp:124
Plasma::SpinBox::mousePressEvent
void mousePressEvent(QGraphicsSceneMouseEvent *event)
Definition: spinbox.cpp:187
applet.h
Plasma::SpinBox::paint
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
Definition: spinbox.cpp:179
Plasma::SpinBox::nativeWidget
KIntSpinBox * nativeWidget() const
QGraphicsProxyWidget
Plasma::SpinBox::~SpinBox
~SpinBox()
Definition: spinbox.cpp:93
Plasma::SpinBox::setMinimum
void setMinimum(int minimum)
Sets the minimum value the slider can take.
Definition: spinbox.cpp:109
Plasma::SpinBox::SpinBox
SpinBox(QGraphicsWidget *parent=0)
Definition: spinbox.cpp:59
framesvg.h
QGraphicsView
Plasma::SpinBox::valueChanged
void valueChanged(int value)
This signal is emitted when the slider value has changed, with the new slider value as argument...
Plasma::SpinBox::hoverLeaveEvent
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
Definition: spinbox.cpp:161
Plasma::SpinBox::value
int value() const
QStyleOptionGraphicsItem
spinbox.h
Plasma::SpinBox::hoverEnterEvent
void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
Definition: spinbox.cpp:155
Plasma::AcceptingInputStatus
The Item is accepting input.
Definition: plasma.h:261
QGraphicsWidget
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:34 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



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