add appearance properties to Slider
This commit is contained in:
parent
2394ed0be8
commit
46105dceae
|
@ -4,7 +4,6 @@
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDebug>
|
|
||||||
#include "slider_p.h"
|
#include "slider_p.h"
|
||||||
|
|
||||||
void SliderPrivate::init()
|
void SliderPrivate::init()
|
||||||
|
@ -102,9 +101,83 @@ Slider::~Slider()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Slider::setUseThemeColors(bool value)
|
||||||
|
{
|
||||||
|
Q_D(Slider);
|
||||||
|
|
||||||
|
d->useThemeColors = value;
|
||||||
|
d->machine->updatePalette();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Slider::useThemeColors() const
|
||||||
|
{
|
||||||
|
Q_D(const Slider);
|
||||||
|
|
||||||
|
return d->useThemeColors;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Slider::setThumbColor(const QColor &color)
|
||||||
|
{
|
||||||
|
Q_D(Slider);
|
||||||
|
|
||||||
|
d->thumbColor = color;
|
||||||
|
setUseThemeColors(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
QColor Slider::thumbColor() const
|
||||||
|
{
|
||||||
|
Q_D(const Slider);
|
||||||
|
|
||||||
|
if (d->useThemeColors || !d->thumbColor.isValid()) {
|
||||||
|
return Style::instance().themeColor("primary1");
|
||||||
|
} else {
|
||||||
|
return d->thumbColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Slider::setTrackColor(const QColor &color)
|
||||||
|
{
|
||||||
|
Q_D(Slider);
|
||||||
|
|
||||||
|
d->trackColor = color;
|
||||||
|
setUseThemeColors(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
QColor Slider::trackColor() const
|
||||||
|
{
|
||||||
|
Q_D(const Slider);
|
||||||
|
|
||||||
|
if (d->useThemeColors || !d->trackColor.isValid()) {
|
||||||
|
return Style::instance().themeColor("accent3");
|
||||||
|
} else {
|
||||||
|
return d->trackColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Slider::setDisabledColor(const QColor &color)
|
||||||
|
{
|
||||||
|
Q_D(Slider);
|
||||||
|
|
||||||
|
d->disabledColor = color;
|
||||||
|
setUseThemeColors(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
QColor Slider::disabledColor() const
|
||||||
|
{
|
||||||
|
Q_D(const Slider);
|
||||||
|
|
||||||
|
if (d->useThemeColors || !d->disabledColor.isValid()) {
|
||||||
|
return Style::instance().themeColor("disabled");
|
||||||
|
} else {
|
||||||
|
return d->disabledColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QSize Slider::minimumSizeHint() const
|
QSize Slider::minimumSizeHint() const
|
||||||
{
|
{
|
||||||
return QSize(20, 20);
|
return Qt::Horizontal == orientation()
|
||||||
|
? QSize(20, 34)
|
||||||
|
: QSize(34, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Slider::thumbOffset() const
|
int Slider::thumbOffset() const
|
||||||
|
|
|
@ -12,10 +12,26 @@ class Slider : public QAbstractSlider
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY(QColor thumbColor WRITE setThumbColor READ thumbColor)
|
||||||
|
Q_PROPERTY(QColor trackColor WRITE setTrackColor READ trackColor)
|
||||||
|
Q_PROPERTY(QColor disabledColor WRITE setDisabledColor READ disabledColor)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Slider(QWidget *parent = 0);
|
explicit Slider(QWidget *parent = 0);
|
||||||
~Slider();
|
~Slider();
|
||||||
|
|
||||||
|
void setUseThemeColors(bool value);
|
||||||
|
bool useThemeColors() const;
|
||||||
|
|
||||||
|
void setThumbColor(const QColor &color);
|
||||||
|
QColor thumbColor() const;
|
||||||
|
|
||||||
|
void setTrackColor(const QColor &color);
|
||||||
|
QColor trackColor() const;
|
||||||
|
|
||||||
|
void setDisabledColor(const QColor &color);
|
||||||
|
QColor disabledColor() const;
|
||||||
|
|
||||||
QSize minimumSizeHint() const Q_DECL_OVERRIDE;
|
QSize minimumSizeHint() const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
int thumbOffset() const;
|
int thumbOffset() const;
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QPalette>
|
||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
#include <QSignalTransition>
|
#include <QSignalTransition>
|
||||||
#include <QEventTransition>
|
#include <QEventTransition>
|
||||||
|
@ -11,47 +12,37 @@
|
||||||
SliderStateMachine::SliderStateMachine(Slider *parent,
|
SliderStateMachine::SliderStateMachine(Slider *parent,
|
||||||
SliderThumb *thumb,
|
SliderThumb *thumb,
|
||||||
SliderTrack *track)
|
SliderTrack *track)
|
||||||
: QStateMachine(parent)
|
: QStateMachine(parent),
|
||||||
|
slider(parent),
|
||||||
|
_track(track),
|
||||||
|
_thumb(thumb),
|
||||||
|
_topState(new QState(QState::ParallelStates)),
|
||||||
|
_fstState(new QState(_topState)),
|
||||||
|
_inactiveState(new QState(_fstState)),
|
||||||
|
_focusState(new QState(_fstState)),
|
||||||
|
_slidingState(new QState(_fstState)),
|
||||||
|
_pulseOutState(new QState(_focusState)),
|
||||||
|
_pulseInState(new QState(_focusState)),
|
||||||
|
_sndState(new QState(_topState)),
|
||||||
|
_minState(new QState(_sndState)),
|
||||||
|
_normalState(new QState(_sndState))
|
||||||
{
|
{
|
||||||
Style &style = Style::instance();
|
_focusState->setInitialState(_pulseOutState);
|
||||||
|
|
||||||
QState *topState = new QState(QState::ParallelStates);
|
_inactiveState->assignProperty(thumb, "haloSize", 0);
|
||||||
|
_slidingState->assignProperty(thumb, "haloSize", 0);
|
||||||
|
|
||||||
QState *fstState = new QState(topState);
|
_pulseOutState->assignProperty(thumb, "haloSize", 35);
|
||||||
|
_pulseInState->assignProperty(thumb, "haloSize", 28);
|
||||||
|
|
||||||
QState *inactiveState = new QState(fstState);
|
_inactiveState->assignProperty(thumb, "diameter", 11);
|
||||||
QState *focusState = new QState(fstState);
|
_focusState->assignProperty(thumb, "diameter", 11);
|
||||||
QState *slidingState = new QState(fstState);
|
_slidingState->assignProperty(thumb, "diameter", 17);
|
||||||
|
|
||||||
QState *pulseOutState = new QState(focusState);
|
addState(_topState);
|
||||||
QState *pulseInState = new QState(focusState);
|
setInitialState(_topState);
|
||||||
|
|
||||||
focusState->setInitialState(pulseOutState);
|
_fstState->setInitialState(_inactiveState);
|
||||||
|
|
||||||
inactiveState->assignProperty(thumb, "haloSize", 0);
|
|
||||||
slidingState->assignProperty(thumb, "haloSize", 0);
|
|
||||||
|
|
||||||
pulseOutState->assignProperty(thumb, "haloSize", 35);
|
|
||||||
pulseInState->assignProperty(thumb, "haloSize", 28);
|
|
||||||
|
|
||||||
inactiveState->assignProperty(thumb, "diameter", 11);
|
|
||||||
focusState->assignProperty(thumb, "diameter", 11);
|
|
||||||
slidingState->assignProperty(thumb, "diameter", 17);
|
|
||||||
|
|
||||||
QColor fillColor = style.themeColor("primary1");
|
|
||||||
|
|
||||||
inactiveState->assignProperty(track, "fillColor",
|
|
||||||
style.themeColor("accent3").lighter(130));
|
|
||||||
slidingState->assignProperty(track, "fillColor",
|
|
||||||
style.themeColor("accent3"));
|
|
||||||
focusState->assignProperty(track, "fillColor",
|
|
||||||
style.themeColor("accent3"));
|
|
||||||
|
|
||||||
addState(topState);
|
|
||||||
|
|
||||||
fstState->setInitialState(inactiveState);
|
|
||||||
|
|
||||||
setInitialState(topState);
|
|
||||||
|
|
||||||
QAbstractTransition *transition;
|
QAbstractTransition *transition;
|
||||||
QPropertyAnimation *animation;
|
QPropertyAnimation *animation;
|
||||||
|
@ -59,73 +50,73 @@ SliderStateMachine::SliderStateMachine(Slider *parent,
|
||||||
// Show halo on mouse enter
|
// Show halo on mouse enter
|
||||||
|
|
||||||
transition = new QSignalTransition(this, SIGNAL(noFocusMouseEnter()));
|
transition = new QSignalTransition(this, SIGNAL(noFocusMouseEnter()));
|
||||||
transition->setTargetState(focusState);
|
transition->setTargetState(_focusState);
|
||||||
|
|
||||||
animation = new QPropertyAnimation(thumb, "haloSize");
|
animation = new QPropertyAnimation(thumb, "haloSize");
|
||||||
animation->setEasingCurve(QEasingCurve::InOutSine);
|
animation->setEasingCurve(QEasingCurve::InOutSine);
|
||||||
transition->addAnimation(animation);
|
transition->addAnimation(animation);
|
||||||
transition->addAnimation(new QPropertyAnimation(track, "fillColor"));
|
transition->addAnimation(new QPropertyAnimation(track, "fillColor"));
|
||||||
inactiveState->addTransition(transition);
|
_inactiveState->addTransition(transition);
|
||||||
|
|
||||||
// Show halo on focus in
|
// Show halo on focus in
|
||||||
|
|
||||||
transition = new QEventTransition(parent, QEvent::FocusIn);
|
transition = new QEventTransition(parent, QEvent::FocusIn);
|
||||||
transition->setTargetState(focusState);
|
transition->setTargetState(_focusState);
|
||||||
|
|
||||||
animation = new QPropertyAnimation(thumb, "haloSize");
|
animation = new QPropertyAnimation(thumb, "haloSize");
|
||||||
animation->setEasingCurve(QEasingCurve::InOutSine);
|
animation->setEasingCurve(QEasingCurve::InOutSine);
|
||||||
transition->addAnimation(animation);
|
transition->addAnimation(animation);
|
||||||
transition->addAnimation(new QPropertyAnimation(track, "fillColor"));
|
transition->addAnimation(new QPropertyAnimation(track, "fillColor"));
|
||||||
inactiveState->addTransition(transition);
|
_inactiveState->addTransition(transition);
|
||||||
|
|
||||||
// Hide halo on focus out
|
// Hide halo on focus out
|
||||||
|
|
||||||
transition = new QEventTransition(parent, QEvent::FocusOut);
|
transition = new QEventTransition(parent, QEvent::FocusOut);
|
||||||
transition->setTargetState(inactiveState);
|
transition->setTargetState(_inactiveState);
|
||||||
|
|
||||||
animation = new QPropertyAnimation(thumb, "haloSize");
|
animation = new QPropertyAnimation(thumb, "haloSize");
|
||||||
animation->setEasingCurve(QEasingCurve::InOutSine);
|
animation->setEasingCurve(QEasingCurve::InOutSine);
|
||||||
transition->addAnimation(animation);
|
transition->addAnimation(animation);
|
||||||
transition->addAnimation(new QPropertyAnimation(track, "fillColor"));
|
transition->addAnimation(new QPropertyAnimation(track, "fillColor"));
|
||||||
focusState->addTransition(transition);
|
_focusState->addTransition(transition);
|
||||||
|
|
||||||
// Hide halo on mouse leave, except if widget has focus
|
// Hide halo on mouse leave, except if widget has focus
|
||||||
|
|
||||||
transition = new QSignalTransition(this, SIGNAL(noFocusMouseLeave()));
|
transition = new QSignalTransition(this, SIGNAL(noFocusMouseLeave()));
|
||||||
transition->setTargetState(inactiveState);
|
transition->setTargetState(_inactiveState);
|
||||||
|
|
||||||
animation = new QPropertyAnimation(thumb, "haloSize");
|
animation = new QPropertyAnimation(thumb, "haloSize");
|
||||||
animation->setEasingCurve(QEasingCurve::InOutSine);
|
animation->setEasingCurve(QEasingCurve::InOutSine);
|
||||||
transition->addAnimation(animation);
|
transition->addAnimation(animation);
|
||||||
transition->addAnimation(new QPropertyAnimation(track, "fillColor"));
|
transition->addAnimation(new QPropertyAnimation(track, "fillColor"));
|
||||||
focusState->addTransition(transition);
|
_focusState->addTransition(transition);
|
||||||
|
|
||||||
// Pulse in
|
// Pulse in
|
||||||
|
|
||||||
transition = new QSignalTransition(pulseOutState, SIGNAL(propertiesAssigned()));
|
transition = new QSignalTransition(_pulseOutState, SIGNAL(propertiesAssigned()));
|
||||||
transition->setTargetState(pulseInState);
|
transition->setTargetState(_pulseInState);
|
||||||
|
|
||||||
animation = new QPropertyAnimation(thumb, "haloSize");
|
animation = new QPropertyAnimation(thumb, "haloSize");
|
||||||
animation->setEasingCurve(QEasingCurve::InOutSine);
|
animation->setEasingCurve(QEasingCurve::InOutSine);
|
||||||
animation->setDuration(1000);
|
animation->setDuration(1000);
|
||||||
transition->addAnimation(animation);
|
transition->addAnimation(animation);
|
||||||
pulseOutState->addTransition(transition);
|
_pulseOutState->addTransition(transition);
|
||||||
|
|
||||||
// Pulse out
|
// Pulse out
|
||||||
|
|
||||||
transition = new QSignalTransition(pulseInState, SIGNAL(propertiesAssigned()));
|
transition = new QSignalTransition(_pulseInState, SIGNAL(propertiesAssigned()));
|
||||||
transition->setTargetState(pulseOutState);
|
transition->setTargetState(_pulseOutState);
|
||||||
|
|
||||||
animation = new QPropertyAnimation(thumb, "haloSize");
|
animation = new QPropertyAnimation(thumb, "haloSize");
|
||||||
animation->setEasingCurve(QEasingCurve::InOutSine);
|
animation->setEasingCurve(QEasingCurve::InOutSine);
|
||||||
animation->setDuration(1000);
|
animation->setDuration(1000);
|
||||||
transition->addAnimation(animation);
|
transition->addAnimation(animation);
|
||||||
pulseInState->addTransition(transition);
|
_pulseInState->addTransition(transition);
|
||||||
|
|
||||||
// Slider pressed
|
// Slider pressed
|
||||||
|
|
||||||
transition = new QSignalTransition(parent, SIGNAL(sliderPressed()));
|
transition = new QSignalTransition(parent, SIGNAL(sliderPressed()));
|
||||||
transition->setTargetState(slidingState);
|
transition->setTargetState(_slidingState);
|
||||||
animation = new QPropertyAnimation(thumb, "diameter");
|
animation = new QPropertyAnimation(thumb, "diameter");
|
||||||
animation->setDuration(70);
|
animation->setDuration(70);
|
||||||
transition->addAnimation(animation);
|
transition->addAnimation(animation);
|
||||||
|
@ -133,12 +124,12 @@ SliderStateMachine::SliderStateMachine(Slider *parent,
|
||||||
animation = new QPropertyAnimation(thumb, "haloSize");
|
animation = new QPropertyAnimation(thumb, "haloSize");
|
||||||
animation->setEasingCurve(QEasingCurve::InOutSine);
|
animation->setEasingCurve(QEasingCurve::InOutSine);
|
||||||
transition->addAnimation(animation);
|
transition->addAnimation(animation);
|
||||||
focusState->addTransition(transition);
|
_focusState->addTransition(transition);
|
||||||
|
|
||||||
// Slider released
|
// Slider released
|
||||||
|
|
||||||
transition = new QSignalTransition(parent, SIGNAL(sliderReleased()));
|
transition = new QSignalTransition(parent, SIGNAL(sliderReleased()));
|
||||||
transition->setTargetState(focusState);
|
transition->setTargetState(_focusState);
|
||||||
animation = new QPropertyAnimation(thumb, "diameter");
|
animation = new QPropertyAnimation(thumb, "diameter");
|
||||||
animation->setDuration(70);
|
animation->setDuration(70);
|
||||||
transition->addAnimation(animation);
|
transition->addAnimation(animation);
|
||||||
|
@ -146,43 +137,24 @@ SliderStateMachine::SliderStateMachine(Slider *parent,
|
||||||
animation = new QPropertyAnimation(thumb, "haloSize");
|
animation = new QPropertyAnimation(thumb, "haloSize");
|
||||||
animation->setEasingCurve(QEasingCurve::InOutSine);
|
animation->setEasingCurve(QEasingCurve::InOutSine);
|
||||||
transition->addAnimation(animation);
|
transition->addAnimation(animation);
|
||||||
slidingState->addTransition(transition);
|
_slidingState->addTransition(transition);
|
||||||
|
|
||||||
// Min. value transitions
|
// Min. value transitions
|
||||||
|
|
||||||
QState *sndState = new QState(topState);
|
_minState->assignProperty(thumb, "borderWidth", 2);
|
||||||
|
_normalState->assignProperty(thumb, "borderWidth", 0);
|
||||||
|
|
||||||
QState *minState = new QState(sndState);
|
_sndState->setInitialState(_minState);
|
||||||
QState *normalState = new QState(sndState);
|
|
||||||
|
|
||||||
QColor minHaloColor = style.themeColor("accent3");
|
|
||||||
minHaloColor.setAlphaF(0.15);
|
|
||||||
|
|
||||||
QColor haloColor = style.themeColor("primary1");
|
|
||||||
haloColor.setAlphaF(0.15);
|
|
||||||
|
|
||||||
QColor canvasColor = style.themeColor("canvas");
|
|
||||||
|
|
||||||
minState->assignProperty(thumb, "fillColor", canvasColor);
|
|
||||||
minState->assignProperty(thumb, "haloColor", minHaloColor);
|
|
||||||
minState->assignProperty(thumb, "borderColor", style.themeColor("accent3"));
|
|
||||||
minState->assignProperty(thumb, "borderWidth", 2);
|
|
||||||
normalState->assignProperty(thumb, "fillColor", fillColor);
|
|
||||||
normalState->assignProperty(thumb, "haloColor", haloColor);
|
|
||||||
normalState->assignProperty(thumb, "borderColor", fillColor);
|
|
||||||
normalState->assignProperty(thumb, "borderWidth", 0);
|
|
||||||
|
|
||||||
sndState->setInitialState(minState);
|
|
||||||
|
|
||||||
transition = new QSignalTransition(this, SIGNAL(changedFromMinimum()));
|
transition = new QSignalTransition(this, SIGNAL(changedFromMinimum()));
|
||||||
transition->setTargetState(normalState);
|
transition->setTargetState(_normalState);
|
||||||
|
|
||||||
animation = new QPropertyAnimation(thumb, "fillColor");
|
animation = new QPropertyAnimation(thumb, "fillColor");
|
||||||
animation->setDuration(200);
|
animation->setDuration(200);
|
||||||
transition->addAnimation(animation);
|
transition->addAnimation(animation);
|
||||||
|
|
||||||
animation = new QPropertyAnimation(thumb, "haloColor");
|
animation = new QPropertyAnimation(thumb, "haloColor");
|
||||||
animation->setDuration(200);
|
animation->setDuration(300);
|
||||||
transition->addAnimation(animation);
|
transition->addAnimation(animation);
|
||||||
|
|
||||||
animation = new QPropertyAnimation(thumb, "borderColor");
|
animation = new QPropertyAnimation(thumb, "borderColor");
|
||||||
|
@ -193,17 +165,17 @@ SliderStateMachine::SliderStateMachine(Slider *parent,
|
||||||
animation->setDuration(200);
|
animation->setDuration(200);
|
||||||
transition->addAnimation(animation);
|
transition->addAnimation(animation);
|
||||||
|
|
||||||
minState->addTransition(transition);
|
_minState->addTransition(transition);
|
||||||
|
|
||||||
transition = new QSignalTransition(this, SIGNAL(changedToMinimum()));
|
transition = new QSignalTransition(this, SIGNAL(changedToMinimum()));
|
||||||
transition->setTargetState(minState);
|
transition->setTargetState(_minState);
|
||||||
|
|
||||||
animation = new QPropertyAnimation(thumb, "fillColor");
|
animation = new QPropertyAnimation(thumb, "fillColor");
|
||||||
animation->setDuration(200);
|
animation->setDuration(200);
|
||||||
transition->addAnimation(animation);
|
transition->addAnimation(animation);
|
||||||
|
|
||||||
animation = new QPropertyAnimation(thumb, "haloColor");
|
animation = new QPropertyAnimation(thumb, "haloColor");
|
||||||
animation->setDuration(200);
|
animation->setDuration(300);
|
||||||
transition->addAnimation(animation);
|
transition->addAnimation(animation);
|
||||||
|
|
||||||
animation = new QPropertyAnimation(thumb, "borderColor");
|
animation = new QPropertyAnimation(thumb, "borderColor");
|
||||||
|
@ -214,13 +186,35 @@ SliderStateMachine::SliderStateMachine(Slider *parent,
|
||||||
animation->setDuration(200);
|
animation->setDuration(200);
|
||||||
transition->addAnimation(animation);
|
transition->addAnimation(animation);
|
||||||
|
|
||||||
normalState->addTransition(transition);
|
_normalState->addTransition(transition);
|
||||||
|
|
||||||
|
updatePalette();
|
||||||
}
|
}
|
||||||
|
|
||||||
SliderStateMachine::~SliderStateMachine()
|
SliderStateMachine::~SliderStateMachine()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SliderStateMachine::updatePalette()
|
||||||
|
{
|
||||||
|
QColor trackColor = slider->trackColor();
|
||||||
|
QColor thumbColor = slider->thumbColor();
|
||||||
|
|
||||||
|
_inactiveState->assignProperty(_track, "fillColor", trackColor.lighter(130));
|
||||||
|
_slidingState->assignProperty(_track, "fillColor", trackColor);
|
||||||
|
_focusState->assignProperty(_track, "fillColor", trackColor);
|
||||||
|
|
||||||
|
_minState->assignProperty(_thumb, "fillColor", slider->palette().color(QPalette::Base));
|
||||||
|
_minState->assignProperty(_thumb, "haloColor", trackColor);
|
||||||
|
_minState->assignProperty(_thumb, "borderColor", trackColor);
|
||||||
|
|
||||||
|
_normalState->assignProperty(_thumb, "fillColor", thumbColor);
|
||||||
|
_normalState->assignProperty(_thumb, "haloColor", thumbColor);
|
||||||
|
_normalState->assignProperty(_thumb, "borderColor", thumbColor);
|
||||||
|
|
||||||
|
slider->update();
|
||||||
|
}
|
||||||
|
|
||||||
SliderThumb::SliderThumb(Slider *slider)
|
SliderThumb::SliderThumb(Slider *slider)
|
||||||
: QWidget(slider->parentWidget()),
|
: QWidget(slider->parentWidget()),
|
||||||
slider(slider),
|
slider(slider),
|
||||||
|
@ -256,6 +250,8 @@ bool SliderThumb::eventFilter(QObject *obj, QEvent *event)
|
||||||
|
|
||||||
void SliderThumb::paintEvent(QPaintEvent *event)
|
void SliderThumb::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
|
Q_UNUSED(event)
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
|
|
||||||
// Halo
|
// Halo
|
||||||
|
@ -275,19 +271,24 @@ void SliderThumb::paintEvent(QPaintEvent *event)
|
||||||
QRectF halo((slider->pos() - QPointF(_haloSize, _haloSize)/2) + disp,
|
QRectF halo((slider->pos() - QPointF(_haloSize, _haloSize)/2) + disp,
|
||||||
QSizeF(_haloSize, _haloSize));
|
QSizeF(_haloSize, _haloSize));
|
||||||
|
|
||||||
|
painter.setOpacity(0.15);
|
||||||
painter.drawEllipse(halo);
|
painter.drawEllipse(halo);
|
||||||
|
|
||||||
// Knob
|
// Knob
|
||||||
|
|
||||||
|
const bool isMin = slider->value() == slider->minimum();
|
||||||
|
|
||||||
brush.setColor(slider->isEnabled()
|
brush.setColor(slider->isEnabled()
|
||||||
? _fillColor
|
? _fillColor
|
||||||
: Style::instance().themeColor("disabled"));
|
: slider->disabledColor());
|
||||||
painter.setBrush(brush);
|
painter.setBrush(!slider->isEnabled() && isMin
|
||||||
|
? Qt::NoBrush
|
||||||
|
: brush);
|
||||||
|
|
||||||
if (slider->isEnabled()) {
|
if (slider->isEnabled() || isMin) {
|
||||||
QPen pen;
|
QPen pen;
|
||||||
pen.setColor(_borderColor);
|
pen.setColor(_borderColor);
|
||||||
pen.setWidthF(_borderWidth);
|
pen.setWidthF((isMin && !slider->isEnabled()) ? 1.7 : _borderWidth);
|
||||||
painter.setPen(pen);
|
painter.setPen(pen);
|
||||||
} else {
|
} else {
|
||||||
painter.setPen(Qt::NoPen);
|
painter.setPen(Qt::NoPen);
|
||||||
|
@ -305,6 +306,7 @@ void SliderThumb::paintEvent(QPaintEvent *event)
|
||||||
|
|
||||||
thumb.moveCenter(geometry.center());
|
thumb.moveCenter(geometry.center());
|
||||||
|
|
||||||
|
painter.setOpacity(1);
|
||||||
painter.drawEllipse(thumb);
|
painter.drawEllipse(thumb);
|
||||||
|
|
||||||
#ifdef DEBUG_LAYOUT
|
#ifdef DEBUG_LAYOUT
|
||||||
|
@ -318,8 +320,6 @@ void SliderThumb::paintEvent(QPaintEvent *event)
|
||||||
|
|
||||||
painter.drawRect(rect().adjusted(0, 0, -2, -2));
|
painter.drawRect(rect().adjusted(0, 0, -2, -2));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QWidget::paintEvent(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SliderTrack::SliderTrack(Slider *slider)
|
SliderTrack::SliderTrack(Slider *slider)
|
||||||
|
@ -353,17 +353,18 @@ bool SliderTrack::eventFilter(QObject *obj, QEvent *event)
|
||||||
|
|
||||||
void SliderTrack::paintEvent(QPaintEvent *event)
|
void SliderTrack::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
|
Q_UNUSED(event)
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
Style &style = Style::instance();
|
|
||||||
|
|
||||||
QBrush fg;
|
QBrush fg;
|
||||||
fg.setStyle(Qt::SolidPattern);
|
fg.setStyle(Qt::SolidPattern);
|
||||||
fg.setColor(slider->isEnabled() ? style.themeColor("primary1")
|
fg.setColor(slider->isEnabled() ? slider->thumbColor()
|
||||||
: style.themeColor("disabled"));
|
: slider->disabledColor());
|
||||||
QBrush bg;
|
QBrush bg;
|
||||||
bg.setStyle(Qt::SolidPattern);
|
bg.setStyle(Qt::SolidPattern);
|
||||||
bg.setColor(slider->isEnabled() ? _fillColor
|
bg.setColor(slider->isEnabled() ? _fillColor
|
||||||
: style.themeColor("disabled"));
|
: slider->disabledColor());
|
||||||
|
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
|
|
||||||
|
@ -414,6 +415,4 @@ void SliderTrack::paintEvent(QPaintEvent *event)
|
||||||
painter.restore();
|
painter.restore();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QWidget::paintEvent(event);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,8 @@ public:
|
||||||
SliderStateMachine(Slider *parent, SliderThumb *thumb, SliderTrack *track);
|
SliderStateMachine(Slider *parent, SliderThumb *thumb, SliderTrack *track);
|
||||||
~SliderStateMachine();
|
~SliderStateMachine();
|
||||||
|
|
||||||
|
void updatePalette();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void changedToMinimum();
|
void changedToMinimum();
|
||||||
void changedFromMinimum();
|
void changedFromMinimum();
|
||||||
|
@ -24,6 +26,21 @@ signals:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(SliderStateMachine)
|
Q_DISABLE_COPY(SliderStateMachine)
|
||||||
|
|
||||||
|
Slider *const slider;
|
||||||
|
SliderTrack *const _track;
|
||||||
|
SliderThumb *const _thumb;
|
||||||
|
QState *const _topState;
|
||||||
|
QState *const _fstState;
|
||||||
|
QState *const _inactiveState;
|
||||||
|
QState *const _focusState;
|
||||||
|
QState *const _slidingState;
|
||||||
|
QState *const _pulseOutState;
|
||||||
|
QState *const _pulseInState;
|
||||||
|
QState *const _sndState;
|
||||||
|
QState *const _minState;
|
||||||
|
QState *const _normalState;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class SliderThumb : public QWidget
|
class SliderThumb : public QWidget
|
||||||
|
|
|
@ -22,7 +22,8 @@ public:
|
||||||
pageStepMode(true),
|
pageStepMode(true),
|
||||||
stepTo(0),
|
stepTo(0),
|
||||||
oldValue(0),
|
oldValue(0),
|
||||||
trackWidth(2)
|
trackWidth(2),
|
||||||
|
useThemeColors(true)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
@ -46,6 +47,10 @@ public:
|
||||||
int stepTo;
|
int stepTo;
|
||||||
int oldValue;
|
int oldValue;
|
||||||
int trackWidth;
|
int trackWidth;
|
||||||
|
QColor thumbColor;
|
||||||
|
QColor trackColor;
|
||||||
|
QColor disabledColor;
|
||||||
|
bool useThemeColors;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SLIDER_P_H
|
#endif // SLIDER_P_H
|
||||||
|
|
|
@ -115,6 +115,8 @@ void TogglePrivate::updatePalette()
|
||||||
|
|
||||||
offState->assignProperty(thumb, "thumbColor", q->inactiveColor());
|
offState->assignProperty(thumb, "thumbColor", q->inactiveColor());
|
||||||
onState->assignProperty(thumb, "thumbColor", q->activeColor());
|
onState->assignProperty(thumb, "thumbColor", q->activeColor());
|
||||||
|
|
||||||
|
q->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
Toggle::Toggle(QWidget *parent)
|
Toggle::Toggle(QWidget *parent)
|
||||||
|
|
Loading…
Reference in New Issue