tweak the slider even more
This commit is contained in:
parent
0ef2d96318
commit
c17500ff37
|
@ -56,6 +56,21 @@ bool Slider::pageStepMode() const
|
||||||
return d->pageStepMode;
|
return d->pageStepMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Slider::setTrackColor(const QColor &color)
|
||||||
|
{
|
||||||
|
Q_D(Slider);
|
||||||
|
|
||||||
|
d->trackColor = color;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
QColor Slider::trackColor() const
|
||||||
|
{
|
||||||
|
Q_D(const Slider);
|
||||||
|
|
||||||
|
return d->trackColor;
|
||||||
|
}
|
||||||
|
|
||||||
void Slider::sliderChange(SliderChange change)
|
void Slider::sliderChange(SliderChange change)
|
||||||
{
|
{
|
||||||
Q_D(Slider);
|
Q_D(Slider);
|
||||||
|
@ -79,6 +94,18 @@ void Slider::sliderChange(SliderChange change)
|
||||||
QAbstractSlider::sliderChange(change);
|
QAbstractSlider::sliderChange(change);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Slider::changeEvent(QEvent *event)
|
||||||
|
{
|
||||||
|
if (QEvent::EnabledChange == event->type()) {
|
||||||
|
if (isEnabled()) {
|
||||||
|
emit sliderEnabled();
|
||||||
|
} else {
|
||||||
|
emit sliderDisabled();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QAbstractSlider::changeEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
void Slider::paintEvent(QPaintEvent *event)
|
void Slider::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event)
|
Q_UNUSED(event)
|
||||||
|
|
|
@ -10,6 +10,8 @@ class Slider : public QAbstractSlider
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY(QColor trackColor WRITE setTrackColor READ trackColor)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Slider(QWidget *parent = 0);
|
explicit Slider(QWidget *parent = 0);
|
||||||
~Slider();
|
~Slider();
|
||||||
|
@ -21,13 +23,19 @@ public:
|
||||||
void setPageStepMode(bool pageStep);
|
void setPageStepMode(bool pageStep);
|
||||||
bool pageStepMode() const;
|
bool pageStepMode() const;
|
||||||
|
|
||||||
|
void setTrackColor(const QColor &color);
|
||||||
|
QColor trackColor() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void changedToMinimum();
|
void changedToMinimum();
|
||||||
void changedFromMinimum();
|
void changedFromMinimum();
|
||||||
|
void sliderEnabled();
|
||||||
|
void sliderDisabled();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void sliderChange(SliderChange change) Q_DECL_OVERRIDE;
|
void sliderChange(SliderChange change) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
void changeEvent(QEvent *event) Q_DECL_OVERRIDE;
|
||||||
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
||||||
void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
||||||
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
// todo: disabled mode
|
|
||||||
|
|
||||||
#ifndef SLIDER_P_H
|
#ifndef SLIDER_P_H
|
||||||
#define SLIDER_P_H
|
#define SLIDER_P_H
|
||||||
|
|
||||||
|
@ -43,6 +41,7 @@ public:
|
||||||
bool pageStepMode;
|
bool pageStepMode;
|
||||||
int stepTo;
|
int stepTo;
|
||||||
int oldValue;
|
int oldValue;
|
||||||
|
QColor trackColor;
|
||||||
};
|
};
|
||||||
|
|
||||||
SliderPrivate::SliderPrivate(Slider *parent)
|
SliderPrivate::SliderPrivate(Slider *parent)
|
||||||
|
@ -53,7 +52,8 @@ SliderPrivate::SliderPrivate(Slider *parent)
|
||||||
step(false),
|
step(false),
|
||||||
pageStepMode(false),
|
pageStepMode(false),
|
||||||
stepTo(0),
|
stepTo(0),
|
||||||
oldValue(parent->value())
|
oldValue(parent->value()),
|
||||||
|
trackColor(QColor(200, 200, 200))
|
||||||
{
|
{
|
||||||
parent->setMouseTracking(true);
|
parent->setMouseTracking(true);
|
||||||
}
|
}
|
||||||
|
@ -66,21 +66,31 @@ void SliderPrivate::init(Slider *slider)
|
||||||
|
|
||||||
QState *inactiveState = new QState(fstState);
|
QState *inactiveState = new QState(fstState);
|
||||||
QState *focusState = new QState(fstState);
|
QState *focusState = new QState(fstState);
|
||||||
|
QState *slidingState = new QState(fstState);
|
||||||
|
QState *disabledState = new QState(fstState);
|
||||||
|
|
||||||
QState *pulseOutState = new QState(focusState);
|
QState *pulseOutState = new QState(focusState);
|
||||||
QState *pulseInState = new QState(focusState);
|
QState *pulseInState = new QState(focusState);
|
||||||
QState *slidingState = new QState(fstState);
|
|
||||||
|
|
||||||
focusState->setInitialState(pulseOutState);
|
focusState->setInitialState(pulseOutState);
|
||||||
|
|
||||||
inactiveState->assignProperty(thumb, "haloSize", 0);
|
inactiveState->assignProperty(thumb, "haloSize", 0);
|
||||||
|
slidingState->assignProperty(thumb, "haloSize", 0);
|
||||||
|
|
||||||
pulseOutState->assignProperty(thumb, "haloSize", 35);
|
pulseOutState->assignProperty(thumb, "haloSize", 35);
|
||||||
pulseInState->assignProperty(thumb, "haloSize", 28);
|
pulseInState->assignProperty(thumb, "haloSize", 28);
|
||||||
slidingState->assignProperty(thumb, "haloSize", 0);
|
|
||||||
|
disabledState->assignProperty(thumb, "diameter", 7);
|
||||||
|
//disabledState->assignProperty(thumb, "fillColor", QColor(200, 200, 200));
|
||||||
|
|
||||||
inactiveState->assignProperty(thumb, "diameter", 11);
|
inactiveState->assignProperty(thumb, "diameter", 11);
|
||||||
focusState->assignProperty(thumb, "diameter", 11);
|
focusState->assignProperty(thumb, "diameter", 11);
|
||||||
slidingState->assignProperty(thumb, "diameter", 17);
|
slidingState->assignProperty(thumb, "diameter", 17);
|
||||||
|
|
||||||
|
//inactiveState->assignProperty(thumb, "fillColor", QColor(0, 0, 0));
|
||||||
|
//focusState->assignProperty(thumb, "fillColor", QColor(0, 0, 0));
|
||||||
|
//slidingState->assignProperty(thumb, "fillColor", QColor(0, 0, 0));
|
||||||
|
|
||||||
machine.addState(topState);
|
machine.addState(topState);
|
||||||
|
|
||||||
fstState->setInitialState(inactiveState);
|
fstState->setInitialState(inactiveState);
|
||||||
|
@ -90,6 +100,24 @@ void SliderPrivate::init(Slider *slider)
|
||||||
QAbstractTransition *transition;
|
QAbstractTransition *transition;
|
||||||
QPropertyAnimation *animation;
|
QPropertyAnimation *animation;
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
transition = new QSignalTransition(slider, SIGNAL(sliderDisabled()));
|
||||||
|
transition->setTargetState(disabledState);
|
||||||
|
inactiveState->addTransition(transition);
|
||||||
|
|
||||||
|
transition = new QSignalTransition(slider, SIGNAL(sliderDisabled()));
|
||||||
|
transition->setTargetState(disabledState);
|
||||||
|
focusState->addTransition(transition);
|
||||||
|
|
||||||
|
transition = new QSignalTransition(slider, SIGNAL(sliderDisabled()));
|
||||||
|
transition->setTargetState(disabledState);
|
||||||
|
slidingState->addTransition(transition);
|
||||||
|
|
||||||
|
transition = new QSignalTransition(slider, SIGNAL(sliderEnabled()));
|
||||||
|
transition->setTargetState(inactiveState);
|
||||||
|
disabledState->addTransition(transition);
|
||||||
|
|
||||||
// Show halo on focus in
|
// Show halo on focus in
|
||||||
|
|
||||||
transition = new QEventTransition(slider, QEvent::FocusIn);
|
transition = new QEventTransition(slider, QEvent::FocusIn);
|
||||||
|
@ -213,22 +241,25 @@ void SliderPrivate::paintTrack(QPainter *painter)
|
||||||
|
|
||||||
QBrush fg;
|
QBrush fg;
|
||||||
fg.setStyle(Qt::SolidPattern);
|
fg.setStyle(Qt::SolidPattern);
|
||||||
fg.setColor(QColor(255, 0, 0));
|
fg.setColor(thumb->fillColor());
|
||||||
|
|
||||||
QBrush bg;
|
QBrush bg;
|
||||||
bg.setStyle(Qt::SolidPattern);
|
bg.setStyle(Qt::SolidPattern);
|
||||||
bg.setColor(QColor(0, 0, 0));
|
bg.setColor(trackColor);
|
||||||
|
|
||||||
qreal offset = q->thumbOffset() + THUMB_OUTER_SIZE/2;
|
qreal offset = q->thumbOffset() + THUMB_OUTER_SIZE/2;
|
||||||
|
|
||||||
QSizeF box(offset, qMax(q->width(), q->height()));
|
QSizeF box(q->isEnabled() ? offset : offset - 7,
|
||||||
|
qMax(q->width(), q->height()));
|
||||||
|
|
||||||
if (Qt::Vertical == q->orientation())
|
if (Qt::Vertical == q->orientation())
|
||||||
box.transpose();
|
box.transpose();
|
||||||
|
|
||||||
QRectF rect = Qt::Vertical == q->orientation()
|
QRectF rect = Qt::Vertical == q->orientation()
|
||||||
? QRectF(0, offset, box.width(), box.width())
|
? QRectF(0, q->isEnabled() ? offset : offset + 7,
|
||||||
: QRectF(offset, 0, box.height(), box.height());
|
box.width(), box.width())
|
||||||
|
: QRectF(q->isEnabled() ? offset : offset + 7, 0,
|
||||||
|
box.height(), box.height());
|
||||||
|
|
||||||
bool inverted = q->invertedAppearance();
|
bool inverted = q->invertedAppearance();
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ SliderThumb::SliderThumb(Slider *slider)
|
||||||
_diameter(11),
|
_diameter(11),
|
||||||
_borderWidth(0),
|
_borderWidth(0),
|
||||||
_fillColor(Qt::white),
|
_fillColor(Qt::white),
|
||||||
|
_minFillColor(Qt::white),
|
||||||
_haloSize(0)
|
_haloSize(0)
|
||||||
{
|
{
|
||||||
slider->installEventFilter(this);
|
slider->installEventFilter(this);
|
||||||
|
@ -61,7 +62,8 @@ void SliderThumb::paintEvent(QPaintEvent *event)
|
||||||
// Knob
|
// Knob
|
||||||
|
|
||||||
brush.setStyle(Qt::SolidPattern);
|
brush.setStyle(Qt::SolidPattern);
|
||||||
brush.setColor(_fillColor);
|
brush.setColor(slider->sliderPosition() > slider->minimum()
|
||||||
|
? _fillColor : _minFillColor);
|
||||||
painter.setBrush(brush);
|
painter.setBrush(brush);
|
||||||
|
|
||||||
if (_borderWidth > 0) {
|
if (_borderWidth > 0) {
|
||||||
|
|
|
@ -13,6 +13,7 @@ class SliderThumb : public QWidget
|
||||||
Q_PROPERTY(qreal diameter WRITE setDiameter READ diameter)
|
Q_PROPERTY(qreal diameter WRITE setDiameter READ diameter)
|
||||||
Q_PROPERTY(qreal borderWidth WRITE setBorderWidth READ borderWidth)
|
Q_PROPERTY(qreal borderWidth WRITE setBorderWidth READ borderWidth)
|
||||||
Q_PROPERTY(QColor fillColor WRITE setFillColor READ fillColor)
|
Q_PROPERTY(QColor fillColor WRITE setFillColor READ fillColor)
|
||||||
|
Q_PROPERTY(QColor minFillColor WRITE setMinFillColor READ minFillColor)
|
||||||
Q_PROPERTY(qreal haloSize WRITE setHaloSize READ haloSize)
|
Q_PROPERTY(qreal haloSize WRITE setHaloSize READ haloSize)
|
||||||
|
|
||||||
friend class SliderPrivate;
|
friend class SliderPrivate;
|
||||||
|
@ -54,6 +55,17 @@ public:
|
||||||
return _fillColor;
|
return _fillColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void setMinFillColor(const QColor &color)
|
||||||
|
{
|
||||||
|
_minFillColor = color;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline QColor minFillColor() const
|
||||||
|
{
|
||||||
|
return _minFillColor;
|
||||||
|
}
|
||||||
|
|
||||||
inline void setHaloSize(qreal size)
|
inline void setHaloSize(qreal size)
|
||||||
{
|
{
|
||||||
_haloSize = size;
|
_haloSize = size;
|
||||||
|
@ -73,6 +85,7 @@ private:
|
||||||
qreal _diameter;
|
qreal _diameter;
|
||||||
qreal _borderWidth;
|
qreal _borderWidth;
|
||||||
QColor _fillColor;
|
QColor _fillColor;
|
||||||
|
QColor _minFillColor;
|
||||||
qreal _haloSize;
|
qreal _haloSize;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,10 +30,12 @@ SliderExamples::SliderExamples(QWidget *parent)
|
||||||
|
|
||||||
QCheckBox *checkbox = new QCheckBox;
|
QCheckBox *checkbox = new QCheckBox;
|
||||||
QCheckBox *checkbox2 = new QCheckBox;
|
QCheckBox *checkbox2 = new QCheckBox;
|
||||||
|
QCheckBox *checkbox3 = new QCheckBox;
|
||||||
|
|
||||||
layout->addWidget(_slider3);
|
layout->addWidget(_slider3);
|
||||||
layout->addWidget(checkbox);
|
layout->addWidget(checkbox);
|
||||||
layout->addWidget(checkbox2);
|
layout->addWidget(checkbox2);
|
||||||
|
layout->addWidget(checkbox3);
|
||||||
|
|
||||||
ExampleView *view = new ExampleView;
|
ExampleView *view = new ExampleView;
|
||||||
view->setWidget(widget);
|
view->setWidget(widget);
|
||||||
|
@ -48,6 +50,7 @@ SliderExamples::SliderExamples(QWidget *parent)
|
||||||
|
|
||||||
connect(checkbox, SIGNAL(toggled(bool)), this, SLOT(inv()));
|
connect(checkbox, SIGNAL(toggled(bool)), this, SLOT(inv()));
|
||||||
connect(checkbox2, SIGNAL(toggled(bool)), this, SLOT(togglePageStepMode()));
|
connect(checkbox2, SIGNAL(toggled(bool)), this, SLOT(togglePageStepMode()));
|
||||||
|
connect(checkbox3, SIGNAL(toggled(bool)), this, SLOT(toggleEnabled()));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
Slider *slider = new Slider;
|
Slider *slider = new Slider;
|
||||||
|
@ -226,3 +229,9 @@ void SliderExamples::togglePageStepMode()
|
||||||
{
|
{
|
||||||
_slider3->setPageStepMode(!_slider3->pageStepMode());
|
_slider3->setPageStepMode(!_slider3->pageStepMode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SliderExamples::toggleEnabled()
|
||||||
|
{
|
||||||
|
bool enabled = !_slider3->isEnabled();
|
||||||
|
_slider3->setEnabled(enabled);
|
||||||
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ protected slots:
|
||||||
void updateSliderValue();
|
void updateSliderValue();
|
||||||
void inv();
|
void inv();
|
||||||
void togglePageStepMode();
|
void togglePageStepMode();
|
||||||
|
void toggleEnabled();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QLineEdit *const _edit;
|
QLineEdit *const _edit;
|
||||||
|
|
|
@ -51,7 +51,8 @@ SOURCES += main.cpp\
|
||||||
examples/iconmenuexamples.cpp \
|
examples/iconmenuexamples.cpp \
|
||||||
lib/scaleeffect.cpp \
|
lib/scaleeffect.cpp \
|
||||||
lib/style.cpp \
|
lib/style.cpp \
|
||||||
components/sliderthumb.cpp
|
components/sliderthumb.cpp \
|
||||||
|
components/searchfield.cpp
|
||||||
|
|
||||||
HEADERS += mainwindow.h \
|
HEADERS += mainwindow.h \
|
||||||
components/appbar.h \
|
components/appbar.h \
|
||||||
|
@ -97,7 +98,8 @@ HEADERS += mainwindow.h \
|
||||||
examples/iconmenuexamples.h \
|
examples/iconmenuexamples.h \
|
||||||
lib/scaleeffect.h \
|
lib/scaleeffect.h \
|
||||||
lib/style.h \
|
lib/style.h \
|
||||||
components/sliderthumb.h
|
components/sliderthumb.h \
|
||||||
|
components/searchfield.h
|
||||||
|
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
resources.qrc
|
resources.qrc
|
||||||
|
|
Loading…
Reference in New Issue