22 #include <QApplication>
25 #include <QStyleOptionSlider>
26 #include <QGraphicsSceneWheelEvent>
27 #include <kmimetype.h>
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();
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();
113 sliderOpt.state |= QStyle::State_Horizontal;
116 QRect backgroundRect =
117 style->subControlRect(QStyle::CC_Slider, &sliderOpt, QStyle::SC_SliderGroove, slider);
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());
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());
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);
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);
187 QWheelEvent e(event->pos().toPoint(),
event->delta(),
event->buttons(),
event->modifiers(),
event->orientation());
188 QApplication::sendEvent(widget(), &e);
194 static_cast<QSlider*
>(widget())->
setMaximum(max);
199 return static_cast<QSlider*
>(widget())->
maximum();
204 static_cast<QSlider*
>(widget())->
setMinimum(min);
209 return static_cast<QSlider*
>(widget())->
minimum();
214 static_cast<QSlider*
>(widget())->
setRange(min, max);
219 static_cast<QSlider*
>(widget())->
setValue(value);
224 return static_cast<QSlider*
>(widget())->
value();
234 return static_cast<QSlider*
>(widget())->
orientation();
239 widget()->setStyleSheet(stylesheet);
244 return widget()->styleSheet();
249 return static_cast<QSlider*
>(widget());
254 #include <slider.moc>