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