22#include <QApplication>
25#include <QStyleOptionSlider>
26#include <QGraphicsSceneWheelEvent>
32#include "private/style_p.h"
33#include "private/focusindicator_p.h"
50 Plasma::Style::Ptr style;
51 FocusIndicator *focusIndicator;
58 QSlider *native =
new QSlider;
65 native->setWindowIcon(QIcon());
66 native->setAttribute(Qt::WA_NoSystemBackground);
69 d->background->setImagePath(
"widgets/slider");
70 d->focusIndicator =
new FocusIndicator(
this, d->background);
72 d->style = Plasma::Style::sharedStyle();
73 native->setStyle(d->style.data());
79 Plasma::Style::doneWithSharedStyle();
82void Slider::paint(QPainter *painter,
87 QGraphicsProxyWidget::paint(painter, option, widget);
92 QStyle *style = slider->style();
93 QStyleOptionSlider sliderOpt;
94 sliderOpt.initFrom(slider);
97 sliderOpt.subControls = QStyle::SC_None;
98 sliderOpt.activeSubControls = QStyle::SC_None;
99 sliderOpt.orientation = slider->orientation();
100 sliderOpt.maximum = slider->maximum();
101 sliderOpt.minimum = slider->minimum();
102 sliderOpt.tickPosition = (QSlider::TickPosition)slider->tickPosition();
103 sliderOpt.tickInterval = slider->tickInterval();
104 sliderOpt.upsideDown = (slider->orientation() == Qt::Horizontal) ?
105 (slider->invertedAppearance() != (sliderOpt.direction == Qt::RightToLeft))
106 : (!slider->invertedAppearance());
107 sliderOpt.direction = Qt::LeftToRight;
108 sliderOpt.sliderPosition = slider->sliderPosition();
109 sliderOpt.sliderValue = slider->value();
110 sliderOpt.singleStep = slider->singleStep();
111 sliderOpt.pageStep = slider->pageStep();
112 if (slider->orientation() == Qt::Horizontal) {
113 sliderOpt.state |= QStyle::State_Horizontal;
116 QRect backgroundRect =
117 style->subControlRect(QStyle::CC_Slider, &sliderOpt, QStyle::SC_SliderGroove, slider);
119 if (sliderOpt.orientation == Qt::Horizontal &&
120 d->background->hasElement(
"horizontal-background-center")) {
121 d->background->setElementPrefix(
"horizontal-background");
122 d->background->resizeFrame(backgroundRect.size());
123 d->background->paintFrame(painter, backgroundRect.topLeft());
124 }
else if (sliderOpt.orientation == Qt::Vertical &&
125 d->background->hasElement(
"vertical-background-center")) {
126 d->background->setElementPrefix(
"vertical-background");
127 d->background->resizeFrame(backgroundRect.size());
128 d->background->paintFrame(painter, backgroundRect.topLeft());
129 }
else if (sliderOpt.orientation == Qt::Horizontal) {
130 QRect elementRect = d->background->elementRect(
"horizontal-slider-line").toRect();
131 elementRect.setWidth(sliderOpt.rect.width());
132 elementRect.moveCenter(sliderOpt.rect.center());
133 d->background->paint(painter, elementRect,
"horizontal-slider-line");
135 QRect elementRect = d->background->elementRect(
"vertical-slider-line").toRect();
136 elementRect.setHeight(sliderOpt.rect.height());
137 elementRect.moveCenter(sliderOpt.rect.center());
138 d->background->paint(painter, elementRect,
"vertical-slider-line");
142 if (sliderOpt.tickPosition != QSlider::NoTicks) {
143 sliderOpt.subControls = QStyle::SC_SliderTickmarks;
144 sliderOpt.palette.setColor(
146 style->drawComplexControl(QStyle::CC_Slider, &sliderOpt, painter, slider);
149 QRect handleRect = style->subControlRect(QStyle::CC_Slider, &sliderOpt, QStyle::SC_SliderHandle, slider);
152 if (sliderOpt.orientation == Qt::Horizontal) {
153 handle =
"horizontal-slider-handle";
155 handle =
"vertical-slider-handle";
158 QRect elementRect = d->background->elementRect(handle).toRect();
159 elementRect.moveCenter(handleRect.center());
160 if (elementRect.right() > rect().right()) {
161 elementRect.moveRight(rect().right());
164 if (elementRect.left() < rect().left()) {
165 elementRect.moveLeft(rect().left());
168 if (elementRect.top() < rect().top()) {
169 elementRect.moveTop(rect().top());
172 if (elementRect.bottom() > rect().bottom()) {
173 elementRect.moveBottom(rect().bottom());
177 d->focusIndicator->setCustomPrefix(
"vertical-slider-");
179 d->focusIndicator->setCustomPrefix(
"horizontal-slider-");
181 d->focusIndicator->setCustomGeometry(elementRect);
182 d->background->paint(painter, elementRect, handle);
185void Slider::wheelEvent(QGraphicsSceneWheelEvent *event)
187 QWheelEvent e(event->pos().toPoint(), event->delta(),event->buttons(),event->modifiers(),event->orientation());
188 QApplication::sendEvent(widget(), &e);
192void Slider::setMaximum(
int max)
194 static_cast<QSlider*
>(widget())->
setMaximum(max);
197int Slider::maximum()
const
199 return static_cast<QSlider*
>(widget())->
maximum();
202void Slider::setMinimum(
int min)
204 static_cast<QSlider*
>(widget())->
setMinimum(min);
207int Slider::minimum()
const
209 return static_cast<QSlider*
>(widget())->
minimum();
212void Slider::setRange(
int min,
int max)
214 static_cast<QSlider*
>(widget())->
setRange(min, max);
217void Slider::setValue(
int value)
222int Slider::value()
const
224 return static_cast<QSlider*
>(widget())->
value();
227void Slider::setOrientation(Qt::Orientation orientation)
232Qt::Orientation Slider::orientation()
const
234 return static_cast<QSlider*
>(widget())->
orientation();
237void Slider::setStyleSheet(
const QString &stylesheet)
239 widget()->setStyleSheet(stylesheet);
242QString Slider::styleSheet()
244 return widget()->styleSheet();
247QSlider *Slider::nativeWidget()
const
249 return static_cast<QSlider*
>(widget());
Provides an SVG with borders.
void setMaximum(int maximum)
Sets the maximum value the slider can take.
Qt::Orientation orientation
void sliderMoved(int value)
This signal is emitted when the user drags the slider.
void setMinimum(int minimum)
Sets the minimum value the slider can take.
void setOrientation(Qt::Orientation orientation)
Sets the orientation of the slider.
void setRange(int minimum, int maximum)
Sets the minimum and maximum values the slider can take.
void valueChanged(int value)
This signal is emitted when the slider value has changed, with the new slider value as argument.
void setValue(int value)
Sets the value of the slider.
Q_INVOKABLE QColor color(ColorRole role) const
Returns the text color to be used by items resting on the background.
static Theme * defaultTheme()
Singleton pattern accessor.
@ TextColor
the text color to be used by items resting on the background
Namespace for everything in libplasma.