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

Plasma

  • 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
37namespace Plasma
38{
39
40class SpinBoxPrivate : public ThemedWidgetInterface<SpinBox>
41{
42public:
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
59SpinBox::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
93SpinBox::~SpinBox()
94{
95 delete d;
96 Plasma::Style::doneWithSharedStyle();
97}
98
99void SpinBox::setMaximum(int max)
100{
101 static_cast<KIntSpinBox*>(widget())->setMaximum(max);
102}
103
104int SpinBox::maximum() const
105{
106 return static_cast<KIntSpinBox*>(widget())->maximum();
107}
108
109void SpinBox::setMinimum(int min)
110{
111 static_cast<KIntSpinBox*>(widget())->setMinimum(min);
112}
113
114int SpinBox::minimum() const
115{
116 return static_cast<KIntSpinBox*>(widget())->minimum();
117}
118
119void SpinBox::setRange(int min, int max)
120{
121 static_cast<KIntSpinBox*>(widget())->setRange(min, max);
122}
123
124void SpinBox::setValue(int value)
125{
126 static_cast<KIntSpinBox*>(widget())->setValue(value);
127}
128
129int SpinBox::value() const
130{
131 return static_cast<KIntSpinBox*>(widget())->value();
132}
133
134void SpinBox::setStyleSheet(const QString &stylesheet)
135{
136 widget()->setStyleSheet(stylesheet);
137}
138
139QString SpinBox::styleSheet()
140{
141 return widget()->styleSheet();
142}
143
144KIntSpinBox *SpinBox::nativeWidget() const
145{
146 return static_cast<KIntSpinBox*>(widget());
147}
148
149void SpinBox::changeEvent(QEvent *event)
150{
151 d->changeEvent(event);
152 QGraphicsProxyWidget::changeEvent(event);
153}
154
155void SpinBox::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
156{
157 Q_UNUSED(event)
158 update();
159}
160
161void SpinBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
162{
163 Q_UNUSED(event)
164 update();
165}
166
167void 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
179void 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
187void 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
203void 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
applet.h
Plasma::Applet
The base Applet class.
Definition: applet.h:78
Plasma::Applet::setStatus
void setStatus(const ItemStatus stat)
sets the status for this applet
Definition: applet.cpp:1198
Plasma::FrameSvg
Provides an SVG with borders.
Definition: framesvg.h:77
Plasma::SpinBox::setMinimum
void setMinimum(int minimum)
Sets the minimum value the slider can take.
Definition: spinbox.cpp:109
Plasma::SpinBox::value
int value
Definition: spinbox.h:47
Plasma::SpinBox::minimum
int minimum
Definition: spinbox.h:46
Plasma::SpinBox::nativeWidget
KIntSpinBox * nativeWidget
Definition: spinbox.h:49
Plasma::SpinBox::setMaximum
void setMaximum(int maximum)
Sets the maximum value the slider can take.
Definition: spinbox.cpp:99
Plasma::SpinBox::setValue
void setValue(int value)
Sets the value of the slider.
Definition: spinbox.cpp:124
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::maximum
int maximum
Definition: spinbox.h:45
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::parentWidget
QGraphicsWidget * parentWidget
Definition: spinbox.h:44
Plasma::SpinBox::editingFinished
void editingFinished()
This signal is emitted when editing is finished.
QGraphicsProxyWidget
QGraphicsView
QGraphicsWidget
QStyleOptionGraphicsItem
QWidget
framesvg.h
Plasma
Namespace for everything in libplasma.
Definition: abstractdialogmanager.cpp:25
Plasma::AcceptingInputStatus
@ AcceptingInputStatus
The Item is accepting input.
Definition: plasma.h:261
Plasma::UnknownStatus
@ UnknownStatus
The status is unknown.
Definition: plasma.h:257
spinbox.h
theme.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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.14.38 API Reference

Skip menu "kdelibs-4.14.38 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