tweak various slider settings
This commit is contained in:
parent
e19f8b4fa4
commit
d388183f84
|
@ -39,52 +39,21 @@ int Slider::thumbOffset() const
|
||||||
sliderPosition(),
|
sliderPosition(),
|
||||||
Qt::Horizontal == orientation()
|
Qt::Horizontal == orientation()
|
||||||
? rect().width() - 20 : rect().height() - 20,
|
? rect().width() - 20 : rect().height() - 20,
|
||||||
false);
|
invertedAppearance());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Slider::setThumbSize(qreal size)
|
void Slider::setPageStepMode(bool pageStep)
|
||||||
{
|
{
|
||||||
Q_D(Slider);
|
Q_D(Slider);
|
||||||
|
|
||||||
d->thumbSize = size;
|
d->pageStepMode = pageStep;
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal Slider::thumbSize() const
|
bool Slider::pageStepMode() const
|
||||||
{
|
{
|
||||||
Q_D(const Slider);
|
Q_D(const Slider);
|
||||||
|
|
||||||
return d->thumbSize;
|
return d->pageStepMode;
|
||||||
}
|
|
||||||
|
|
||||||
void Slider::setThumbPenWidth(qreal width)
|
|
||||||
{
|
|
||||||
Q_D(Slider);
|
|
||||||
|
|
||||||
d->thumbPenWidth = width;
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
qreal Slider::thumbPenWidth() const
|
|
||||||
{
|
|
||||||
Q_D(const Slider);
|
|
||||||
|
|
||||||
return d->thumbPenWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Slider::setThumbColor(const QColor &color)
|
|
||||||
{
|
|
||||||
Q_D(Slider);
|
|
||||||
|
|
||||||
d->thumbColor = color;
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
QColor Slider::thumbColor() const
|
|
||||||
{
|
|
||||||
Q_D(const Slider);
|
|
||||||
|
|
||||||
return d->thumbColor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Slider::sliderChange(SliderChange change)
|
void Slider::sliderChange(SliderChange change)
|
||||||
|
@ -119,7 +88,6 @@ void Slider::paintEvent(QPaintEvent *event)
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
|
|
||||||
d->paintTrack(&painter);
|
d->paintTrack(&painter);
|
||||||
d->paintThumb(&painter);
|
|
||||||
|
|
||||||
#ifdef DEBUG_LAYOUT
|
#ifdef DEBUG_LAYOUT
|
||||||
if (hasFocus())
|
if (hasFocus())
|
||||||
|
@ -178,6 +146,12 @@ void Slider::mousePressEvent(QMouseEvent *event)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!d->pageStepMode) {
|
||||||
|
setSliderPosition(d->valueFromPosition(event->pos()));
|
||||||
|
//setSliderDown(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
d->step = true;
|
d->step = true;
|
||||||
d->stepTo = d->valueFromPosition(pos);
|
d->stepTo = d->valueFromPosition(pos);
|
||||||
|
|
||||||
|
|
|
@ -10,26 +10,16 @@ class Slider : public QAbstractSlider
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
Q_PROPERTY(qreal thumbSize WRITE setThumbSize READ thumbSize)
|
|
||||||
Q_PROPERTY(qreal thumbPenWidth WRITE setThumbPenWidth READ thumbPenWidth)
|
|
||||||
Q_PROPERTY(QColor thumbColor WRITE setThumbColor READ thumbColor)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Slider(QWidget *parent = 0);
|
explicit Slider(QWidget *parent = 0);
|
||||||
~Slider();
|
~Slider();
|
||||||
|
|
||||||
QSize minimumSizeHint() const;
|
QSize minimumSizeHint() const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
int thumbOffset() const;
|
int thumbOffset() const;
|
||||||
|
|
||||||
void setThumbSize(qreal size);
|
void setPageStepMode(bool pageStep);
|
||||||
qreal thumbSize() const;
|
bool pageStepMode() const;
|
||||||
|
|
||||||
void setThumbPenWidth(qreal width);
|
|
||||||
qreal thumbPenWidth() const;
|
|
||||||
|
|
||||||
void setThumbColor(const QColor &color);
|
|
||||||
QColor thumbColor() const;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void changedToMinimum();
|
void changedToMinimum();
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
// @todo -- separate decl. and impl.
|
// todo: disabled mode
|
||||||
// inverse mode
|
|
||||||
// paint track differently left of thumb
|
|
||||||
// direct click mode (mode thumb to click pos)
|
|
||||||
#ifndef SLIDER_P_H
|
#ifndef SLIDER_P_H
|
||||||
#define SLIDER_P_H
|
#define SLIDER_P_H
|
||||||
|
|
||||||
|
@ -15,6 +13,7 @@
|
||||||
#include "lib/style.h"
|
#include "lib/style.h"
|
||||||
#include "sliderthumb.h"
|
#include "sliderthumb.h"
|
||||||
|
|
||||||
|
// change
|
||||||
#define THUMB_OUTER_SIZE 20
|
#define THUMB_OUTER_SIZE 20
|
||||||
|
|
||||||
class SliderPrivate
|
class SliderPrivate
|
||||||
|
@ -25,55 +24,68 @@ class SliderPrivate
|
||||||
friend class SliderThumb;
|
friend class SliderThumb;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SliderPrivate(Slider *parent)
|
SliderPrivate(Slider *parent);
|
||||||
|
|
||||||
|
void init(Slider *slider);
|
||||||
|
|
||||||
|
QRectF trackGeometry() const;
|
||||||
|
QRectF thumbGeometry() const;
|
||||||
|
|
||||||
|
void paintTrack(QPainter *painter);
|
||||||
|
int valueFromPosition(const QPoint &pos) const;
|
||||||
|
|
||||||
|
Slider *const q_ptr;
|
||||||
|
SliderThumb *const thumb;
|
||||||
|
QStateMachine machine;
|
||||||
|
bool hoverTrack;
|
||||||
|
bool hoverThumb;
|
||||||
|
bool step;
|
||||||
|
bool pageStepMode;
|
||||||
|
int stepTo;
|
||||||
|
int oldValue;
|
||||||
|
};
|
||||||
|
|
||||||
|
SliderPrivate::SliderPrivate(Slider *parent)
|
||||||
: q_ptr(parent),
|
: q_ptr(parent),
|
||||||
thumb(new SliderThumb(this)),
|
thumb(new SliderThumb(parent)),
|
||||||
hoverTrack(false),
|
hoverTrack(false),
|
||||||
hoverThumb(false),
|
hoverThumb(false),
|
||||||
step(false),
|
step(false),
|
||||||
|
pageStepMode(true),
|
||||||
stepTo(0),
|
stepTo(0),
|
||||||
oldValue(parent->value()),
|
oldValue(parent->value())
|
||||||
thumbSize(11),
|
{
|
||||||
thumbPenWidth(0),
|
|
||||||
thumbColor(Qt::white)
|
|
||||||
{
|
|
||||||
parent->setMouseTracking(true);
|
parent->setMouseTracking(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void init(Slider *slider)
|
void SliderPrivate::init(Slider *slider)
|
||||||
{
|
{
|
||||||
QState *s1 = new QState(QState::ParallelStates);
|
QState *topState = new QState(QState::ParallelStates);
|
||||||
|
|
||||||
QState *s11 = new QState(s1);
|
QState *fstState = new QState(topState);
|
||||||
|
|
||||||
QState *inactiveState = new QState(s11);
|
QState *inactiveState = new QState(fstState);
|
||||||
QState *focusState = new QState(s11);
|
QState *focusState = new QState(fstState);
|
||||||
QState *pulseState = new QState(focusState);
|
QState *pulseOutState = new QState(focusState);
|
||||||
QState *pulse2State = new QState(focusState);
|
QState *pulseInState = new QState(focusState);
|
||||||
QState *downState = new QState(s11);
|
QState *slidingState = new QState(fstState);
|
||||||
|
|
||||||
focusState->setInitialState(pulseState);
|
focusState->setInitialState(pulseOutState);
|
||||||
|
|
||||||
inactiveState->assignProperty(thumb, "haloSize", 0);
|
inactiveState->assignProperty(thumb, "haloSize", 0);
|
||||||
pulseState->assignProperty(thumb, "haloSize", 35);
|
pulseOutState->assignProperty(thumb, "haloSize", 35);
|
||||||
pulse2State->assignProperty(thumb, "haloSize", 28);
|
pulseInState->assignProperty(thumb, "haloSize", 28);
|
||||||
downState->assignProperty(thumb, "haloSize", 0);
|
slidingState->assignProperty(thumb, "haloSize", 0);
|
||||||
|
|
||||||
inactiveState->assignProperty(slider, "thumbSize", 11);
|
inactiveState->assignProperty(thumb, "diameter", 11);
|
||||||
focusState->assignProperty(slider, "thumbSize", 11);
|
focusState->assignProperty(thumb, "diameter", 11);
|
||||||
downState->assignProperty(slider, "thumbSize", 17);
|
slidingState->assignProperty(thumb, "diameter", 17);
|
||||||
|
|
||||||
machine.addState(s1);
|
machine.addState(topState);
|
||||||
|
|
||||||
s11->setInitialState(inactiveState);
|
fstState->setInitialState(inactiveState);
|
||||||
|
|
||||||
//machine.addState(inactiveState);
|
machine.setInitialState(topState);
|
||||||
//machine.addState(focusState);
|
|
||||||
//machine.addState(downState);
|
|
||||||
|
|
||||||
//machine.setInitialState(inactiveState);
|
|
||||||
|
|
||||||
machine.setInitialState(s1);
|
|
||||||
|
|
||||||
QAbstractTransition *transition;
|
QAbstractTransition *transition;
|
||||||
QPropertyAnimation *animation;
|
QPropertyAnimation *animation;
|
||||||
|
@ -98,31 +110,31 @@ public:
|
||||||
|
|
||||||
// Pulse in
|
// Pulse in
|
||||||
|
|
||||||
transition = new QSignalTransition(pulseState, SIGNAL(propertiesAssigned()));
|
transition = new QSignalTransition(pulseOutState, SIGNAL(propertiesAssigned()));
|
||||||
transition->setTargetState(pulse2State);
|
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);
|
||||||
pulseState->addTransition(transition);
|
pulseOutState->addTransition(transition);
|
||||||
|
|
||||||
// Pulse out
|
// Pulse out
|
||||||
|
|
||||||
transition = new QSignalTransition(pulse2State, SIGNAL(propertiesAssigned()));
|
transition = new QSignalTransition(pulseInState, SIGNAL(propertiesAssigned()));
|
||||||
transition->setTargetState(pulseState);
|
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);
|
||||||
pulse2State->addTransition(transition);
|
pulseInState->addTransition(transition);
|
||||||
|
|
||||||
// Slider pressed
|
// Slider pressed
|
||||||
|
|
||||||
transition = new QSignalTransition(slider, SIGNAL(sliderPressed()));
|
transition = new QSignalTransition(slider, SIGNAL(sliderPressed()));
|
||||||
transition->setTargetState(downState);
|
transition->setTargetState(slidingState);
|
||||||
transition->addAnimation(new QPropertyAnimation(slider, "thumbSize"));
|
transition->addAnimation(new QPropertyAnimation(thumb, "diameter"));
|
||||||
transition->addAnimation(new QPropertyAnimation(thumb, "haloSize"));
|
transition->addAnimation(new QPropertyAnimation(thumb, "haloSize"));
|
||||||
focusState->addTransition(transition);
|
focusState->addTransition(transition);
|
||||||
|
|
||||||
|
@ -130,54 +142,49 @@ public:
|
||||||
|
|
||||||
transition = new QSignalTransition(slider, SIGNAL(sliderReleased()));
|
transition = new QSignalTransition(slider, SIGNAL(sliderReleased()));
|
||||||
transition->setTargetState(focusState);
|
transition->setTargetState(focusState);
|
||||||
transition->addAnimation(new QPropertyAnimation(slider, "thumbSize"));
|
transition->addAnimation(new QPropertyAnimation(thumb, "diameter"));
|
||||||
transition->addAnimation(new QPropertyAnimation(thumb, "haloSize"));
|
transition->addAnimation(new QPropertyAnimation(thumb, "haloSize"));
|
||||||
downState->addTransition(transition);
|
slidingState->addTransition(transition);
|
||||||
|
|
||||||
//
|
// Min. value animation
|
||||||
|
|
||||||
QState *s12 = new QState(s1);
|
QState *sndState = new QState(topState);
|
||||||
|
|
||||||
QState *t1 = new QState(s12);
|
QState *minState = new QState(sndState);
|
||||||
QState *t2 = new QState(s12);
|
QState *normalState = new QState(sndState);
|
||||||
|
|
||||||
t1->assignProperty(slider, "thumbColor", QColor(0, 0, 0));
|
minState->assignProperty(thumb, "fillColor", QColor(0, 0, 0));
|
||||||
t1->assignProperty(slider, "thumbPenWidth", 0);
|
minState->assignProperty(thumb, "borderWidth", 0);
|
||||||
t2->assignProperty(slider, "thumbColor", QColor(255, 255, 255));
|
normalState->assignProperty(thumb, "fillColor", QColor(255, 255, 255));
|
||||||
t2->assignProperty(slider, "thumbPenWidth", 1.5);
|
normalState->assignProperty(thumb, "borderWidth", 1.5);
|
||||||
|
|
||||||
//machine.addState(t1);
|
sndState->setInitialState(minState);
|
||||||
//machine.addState(t2);
|
|
||||||
|
|
||||||
//machine.addState(s12);
|
|
||||||
|
|
||||||
s12->setInitialState(t1);
|
|
||||||
|
|
||||||
transition = new QSignalTransition(slider, SIGNAL(changedToMinimum()));
|
transition = new QSignalTransition(slider, SIGNAL(changedToMinimum()));
|
||||||
transition->setTargetState(t2);
|
transition->setTargetState(normalState);
|
||||||
animation = new QPropertyAnimation(slider, "thumbColor");
|
animation = new QPropertyAnimation(thumb, "fillColor");
|
||||||
animation->setDuration(700);
|
animation->setDuration(400);
|
||||||
transition->addAnimation(animation);
|
transition->addAnimation(animation);
|
||||||
animation = new QPropertyAnimation(slider, "thumbPenWidth");
|
animation = new QPropertyAnimation(thumb, "borderWidth");
|
||||||
animation->setDuration(700);
|
animation->setDuration(400);
|
||||||
transition->addAnimation(animation);
|
transition->addAnimation(animation);
|
||||||
t1->addTransition(transition);
|
minState->addTransition(transition);
|
||||||
|
|
||||||
transition = new QSignalTransition(slider, SIGNAL(changedFromMinimum()));
|
transition = new QSignalTransition(slider, SIGNAL(changedFromMinimum()));
|
||||||
transition->setTargetState(t1);
|
transition->setTargetState(minState);
|
||||||
animation = new QPropertyAnimation(slider, "thumbColor");
|
animation = new QPropertyAnimation(thumb, "fillColor");
|
||||||
animation->setDuration(700);
|
animation->setDuration(400);
|
||||||
transition->addAnimation(animation);
|
transition->addAnimation(animation);
|
||||||
animation = new QPropertyAnimation(slider, "thumbPenWidth");
|
animation = new QPropertyAnimation(thumb, "borderWidth");
|
||||||
animation->setDuration(700);
|
animation->setDuration(400);
|
||||||
transition->addAnimation(animation);
|
transition->addAnimation(animation);
|
||||||
t2->addTransition(transition);
|
normalState->addTransition(transition);
|
||||||
|
|
||||||
machine.start();
|
machine.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF trackGeometry() const
|
QRectF SliderPrivate::trackGeometry() const
|
||||||
{
|
{
|
||||||
Q_Q(const Slider);
|
Q_Q(const Slider);
|
||||||
|
|
||||||
return Qt::Horizontal == q->orientation()
|
return Qt::Horizontal == q->orientation()
|
||||||
|
@ -185,17 +192,49 @@ public:
|
||||||
q->rect().width() - THUMB_OUTER_SIZE, 2)
|
q->rect().width() - THUMB_OUTER_SIZE, 2)
|
||||||
: QRectF(q->rect().width()/2 - 1, THUMB_OUTER_SIZE/2, 2,
|
: QRectF(q->rect().width()/2 - 1, THUMB_OUTER_SIZE/2, 2,
|
||||||
q->rect().height() - THUMB_OUTER_SIZE);
|
q->rect().height() - THUMB_OUTER_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QRectF SliderPrivate::thumbGeometry() const
|
||||||
|
{
|
||||||
|
Q_Q(const Slider);
|
||||||
|
|
||||||
|
return Qt::Horizontal == q->orientation()
|
||||||
|
? QRectF(q->thumbOffset(), q->rect().height()/2 - THUMB_OUTER_SIZE/2,
|
||||||
|
THUMB_OUTER_SIZE, THUMB_OUTER_SIZE)
|
||||||
|
: QRectF(q->rect().width()/2 - THUMB_OUTER_SIZE/2, q->thumbOffset(),
|
||||||
|
THUMB_OUTER_SIZE, THUMB_OUTER_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SliderPrivate::paintTrack(QPainter *painter)
|
||||||
|
{
|
||||||
|
Q_Q(const Slider);
|
||||||
|
|
||||||
void paintTrack(QPainter *painter)
|
|
||||||
{
|
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
QBrush brush;
|
QBrush fg;
|
||||||
brush.setStyle(Qt::SolidPattern);
|
fg.setStyle(Qt::SolidPattern);
|
||||||
brush.setColor(QColor(0, 0, 0, 255));
|
fg.setColor(QColor(255, 0, 0));
|
||||||
|
|
||||||
painter->fillRect(trackGeometry(), brush);
|
QBrush bg;
|
||||||
|
bg.setStyle(Qt::SolidPattern);
|
||||||
|
bg.setColor(QColor(0, 0, 0));
|
||||||
|
|
||||||
|
qreal offset = q->thumbOffset() + THUMB_OUTER_SIZE/2;
|
||||||
|
|
||||||
|
QSizeF box(offset, 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());
|
||||||
|
|
||||||
|
bool inverted = q->invertedAppearance();
|
||||||
|
|
||||||
|
painter->fillRect(QRectF(QPointF(0, 0), box).intersected(trackGeometry()),
|
||||||
|
inverted ? bg : fg);
|
||||||
|
painter->fillRect(rect.intersected(trackGeometry()), inverted ? fg : bg);
|
||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
|
|
||||||
|
@ -207,68 +246,10 @@ public:
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove
|
int SliderPrivate::valueFromPosition(const QPoint &pos) const
|
||||||
// remove
|
{
|
||||||
// remove
|
|
||||||
QRectF thumbGeometry() const
|
|
||||||
{
|
|
||||||
Q_Q(const Slider);
|
|
||||||
|
|
||||||
return Qt::Horizontal == q->orientation()
|
|
||||||
? QRectF(q->thumbOffset(), q->rect().height()/2 - THUMB_OUTER_SIZE/2,
|
|
||||||
THUMB_OUTER_SIZE, THUMB_OUTER_SIZE)
|
|
||||||
: QRectF(q->rect().width()/2 - THUMB_OUTER_SIZE/2, q->thumbOffset(),
|
|
||||||
THUMB_OUTER_SIZE, THUMB_OUTER_SIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove
|
|
||||||
// remove
|
|
||||||
void paintThumb(QPainter *painter)
|
|
||||||
{
|
|
||||||
painter->drawRect(thumbGeometry().adjusted(0, 0, -1, -1));
|
|
||||||
|
|
||||||
/*
|
|
||||||
painter->save();
|
|
||||||
|
|
||||||
QBrush brush;
|
|
||||||
brush.setStyle(Qt::SolidPattern);
|
|
||||||
brush.setColor(thumbColor);
|
|
||||||
painter->setBrush(brush);
|
|
||||||
|
|
||||||
if (thumbPenWidth) {
|
|
||||||
QPen pen;
|
|
||||||
pen.setWidthF(thumbPenWidth);
|
|
||||||
painter->setPen(pen);
|
|
||||||
} else {
|
|
||||||
painter->setPen(Qt::NoPen);
|
|
||||||
}
|
|
||||||
|
|
||||||
painter->setRenderHint(QPainter::Antialiasing);
|
|
||||||
|
|
||||||
QRectF thumb(0, 0, thumbSize, thumbSize);
|
|
||||||
thumb.moveCenter(thumbGeometry().center());
|
|
||||||
|
|
||||||
painter->drawEllipse(thumb);
|
|
||||||
|
|
||||||
painter->restore();
|
|
||||||
|
|
||||||
#ifdef DEBUG_LAYOUT
|
|
||||||
painter->drawRect(thumbGeometry());
|
|
||||||
|
|
||||||
if (hoverThumb) {
|
|
||||||
painter->save();
|
|
||||||
painter->setPen(Qt::red);
|
|
||||||
painter->drawRect(thumbGeometry());
|
|
||||||
painter->restore();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
int valueFromPosition(const QPoint &pos) const
|
|
||||||
{
|
|
||||||
Q_Q(const Slider);
|
Q_Q(const Slider);
|
||||||
|
|
||||||
int position = Qt::Horizontal == q->orientation() ? pos.x() : pos.y();
|
int position = Qt::Horizontal == q->orientation() ? pos.x() : pos.y();
|
||||||
|
@ -282,20 +263,7 @@ public:
|
||||||
q->maximum(),
|
q->maximum(),
|
||||||
position - THUMB_OUTER_SIZE/2,
|
position - THUMB_OUTER_SIZE/2,
|
||||||
span,
|
span,
|
||||||
false);
|
q->invertedAppearance());
|
||||||
}
|
}
|
||||||
|
|
||||||
Slider *const q_ptr;
|
|
||||||
SliderThumb *const thumb;
|
|
||||||
QStateMachine machine;
|
|
||||||
bool hoverTrack;
|
|
||||||
bool hoverThumb;
|
|
||||||
bool step;
|
|
||||||
int stepTo;
|
|
||||||
int oldValue;
|
|
||||||
qreal thumbSize; // move VVV
|
|
||||||
qreal thumbPenWidth;
|
|
||||||
QColor thumbColor;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // SLIDER_P_H
|
#endif // SLIDER_P_H
|
||||||
|
|
|
@ -1,18 +1,24 @@
|
||||||
#include "sliderthumb.h"
|
#include "sliderthumb.h"
|
||||||
#include "slider_p.h"
|
#include <QEvent>
|
||||||
|
#include <QPainter>
|
||||||
|
#include "slider.h"
|
||||||
|
|
||||||
SliderThumb::SliderThumb(SliderPrivate *slider)
|
// change
|
||||||
: QWidget(slider->q_func()),
|
#define THUMB_OUTER_SIZE 20
|
||||||
|
|
||||||
|
SliderThumb::SliderThumb(Slider *slider)
|
||||||
|
: QWidget(slider->parentWidget()),
|
||||||
slider(slider),
|
slider(slider),
|
||||||
|
_diameter(11),
|
||||||
|
_borderWidth(0),
|
||||||
|
_fillColor(Qt::white),
|
||||||
_haloSize(0)
|
_haloSize(0)
|
||||||
{
|
{
|
||||||
Slider *parent = slider->q_func();
|
slider->installEventFilter(this);
|
||||||
|
|
||||||
parent->installEventFilter(this);
|
|
||||||
setAttribute(Qt::WA_TransparentForMouseEvents, true);
|
setAttribute(Qt::WA_TransparentForMouseEvents, true);
|
||||||
|
|
||||||
connect(parent, SIGNAL(sliderMoved(int)), this, SLOT(update()));
|
connect(slider, SIGNAL(sliderMoved(int)), this, SLOT(update()));
|
||||||
connect(parent, SIGNAL(valueChanged(int)), this, SLOT(update()));
|
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(update()));
|
||||||
}
|
}
|
||||||
|
|
||||||
SliderThumb::~SliderThumb()
|
SliderThumb::~SliderThumb()
|
||||||
|
@ -22,15 +28,13 @@ SliderThumb::~SliderThumb()
|
||||||
bool SliderThumb::eventFilter(QObject *obj, QEvent *event)
|
bool SliderThumb::eventFilter(QObject *obj, QEvent *event)
|
||||||
{
|
{
|
||||||
if (QEvent::ParentChange == event->type()) {
|
if (QEvent::ParentChange == event->type()) {
|
||||||
setParent(slider->q_func()->parentWidget());
|
setParent(slider->parentWidget());
|
||||||
}
|
}
|
||||||
return QWidget::eventFilter(obj, event);
|
return QWidget::eventFilter(obj, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SliderThumb::paintEvent(QPaintEvent *event)
|
void SliderThumb::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
Slider *const q = slider->q_func();
|
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
|
|
||||||
// Halo
|
// Halo
|
||||||
|
@ -43,33 +47,40 @@ void SliderThumb::paintEvent(QPaintEvent *event)
|
||||||
|
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
|
|
||||||
QPointF disp = Qt::Horizontal == q->orientation()
|
QPointF disp = Qt::Horizontal == slider->orientation()
|
||||||
? QPointF(THUMB_OUTER_SIZE/2 + q->thumbOffset(),
|
? QPointF(THUMB_OUTER_SIZE/2 + slider->thumbOffset(),
|
||||||
q->height()/2)
|
slider->height()/2)
|
||||||
: QPointF(q->width()/2,
|
: QPointF(slider->width()/2,
|
||||||
THUMB_OUTER_SIZE/2 + q->thumbOffset());
|
THUMB_OUTER_SIZE/2 + slider->thumbOffset());
|
||||||
|
|
||||||
QRectF halo((q->pos() - QPointF(_haloSize, _haloSize)/2) + disp,
|
QRectF halo((slider->pos() - QPointF(_haloSize, _haloSize)/2) + disp,
|
||||||
QSize(_haloSize, _haloSize));
|
QSizeF(_haloSize, _haloSize));
|
||||||
|
|
||||||
painter.drawEllipse(halo);
|
painter.drawEllipse(halo);
|
||||||
|
|
||||||
// Knob
|
// Knob
|
||||||
|
|
||||||
brush.setStyle(Qt::SolidPattern);
|
brush.setStyle(Qt::SolidPattern);
|
||||||
brush.setColor(slider->thumbColor);
|
brush.setColor(_fillColor);
|
||||||
painter.setBrush(brush);
|
painter.setBrush(brush);
|
||||||
|
|
||||||
if (slider->thumbPenWidth > 0) {
|
if (_borderWidth > 0) {
|
||||||
QPen pen;
|
QPen pen;
|
||||||
pen.setWidthF(slider->thumbPenWidth);
|
pen.setWidthF(_borderWidth);
|
||||||
painter.setPen(pen);
|
painter.setPen(pen);
|
||||||
} else {
|
} else {
|
||||||
painter.setPen(Qt::NoPen);
|
painter.setPen(Qt::NoPen);
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF thumb(0, 0, slider->thumbSize, slider->thumbSize);
|
QRectF geometry = Qt::Horizontal == slider->orientation()
|
||||||
thumb.moveCenter(thumbGeometry().center());
|
? QRectF(slider->thumbOffset(), slider->height()/2 - THUMB_OUTER_SIZE/2,
|
||||||
|
THUMB_OUTER_SIZE, THUMB_OUTER_SIZE).translated(slider->pos())
|
||||||
|
: QRectF(slider->width()/2 - THUMB_OUTER_SIZE/2, slider->thumbOffset(),
|
||||||
|
THUMB_OUTER_SIZE, THUMB_OUTER_SIZE).translated(slider->pos());
|
||||||
|
|
||||||
|
QRectF thumb(0, 0, _diameter, _diameter);
|
||||||
|
|
||||||
|
thumb.moveCenter(geometry.center());
|
||||||
|
|
||||||
painter.drawEllipse(thumb);
|
painter.drawEllipse(thumb);
|
||||||
|
|
||||||
|
@ -85,14 +96,3 @@ void SliderThumb::paintEvent(QPaintEvent *event)
|
||||||
|
|
||||||
QWidget::paintEvent(event);
|
QWidget::paintEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF SliderThumb::thumbGeometry() const
|
|
||||||
{
|
|
||||||
const Slider *const q = slider->q_func();
|
|
||||||
|
|
||||||
return Qt::Horizontal == q->orientation()
|
|
||||||
? QRectF(q->thumbOffset(), q->rect().height()/2 - THUMB_OUTER_SIZE/2,
|
|
||||||
THUMB_OUTER_SIZE, THUMB_OUTER_SIZE)
|
|
||||||
: QRectF(q->rect().width()/2 - THUMB_OUTER_SIZE/2, q->thumbOffset(),
|
|
||||||
THUMB_OUTER_SIZE, THUMB_OUTER_SIZE);
|
|
||||||
}
|
|
||||||
|
|
|
@ -3,20 +3,57 @@
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
class Slider;
|
||||||
class SliderPrivate;
|
class SliderPrivate;
|
||||||
|
|
||||||
class SliderThumb : public QWidget
|
class SliderThumb : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
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(qreal haloSize WRITE setHaloSize READ haloSize)
|
Q_PROPERTY(qreal haloSize WRITE setHaloSize READ haloSize)
|
||||||
|
|
||||||
friend class SliderPrivate;
|
friend class SliderPrivate;
|
||||||
explicit SliderThumb(SliderPrivate *slider);
|
explicit SliderThumb(Slider *slider);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~SliderThumb();
|
~SliderThumb();
|
||||||
|
|
||||||
|
inline void setDiameter(qreal diameter)
|
||||||
|
{
|
||||||
|
_diameter = diameter;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline qreal diameter() const
|
||||||
|
{
|
||||||
|
return _diameter;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void setBorderWidth(qreal width)
|
||||||
|
{
|
||||||
|
_borderWidth = width;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline qreal borderWidth() const
|
||||||
|
{
|
||||||
|
return _borderWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void setFillColor(const QColor &color)
|
||||||
|
{
|
||||||
|
_fillColor = color;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline QColor fillColor() const
|
||||||
|
{
|
||||||
|
return _fillColor;
|
||||||
|
}
|
||||||
|
|
||||||
inline void setHaloSize(qreal size)
|
inline void setHaloSize(qreal size)
|
||||||
{
|
{
|
||||||
_haloSize = size;
|
_haloSize = size;
|
||||||
|
@ -32,10 +69,12 @@ protected:
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(SliderThumb)
|
Q_DISABLE_COPY(SliderThumb)
|
||||||
|
|
||||||
QRectF thumbGeometry() const;
|
const Slider *const slider;
|
||||||
|
qreal _diameter;
|
||||||
SliderPrivate *const slider;
|
qreal _borderWidth;
|
||||||
|
QColor _fillColor;
|
||||||
qreal _haloSize;
|
qreal _haloSize;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SLIDERTHUMB_H
|
#endif // SLIDERTHUMB_H
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QSlider>
|
#include <QSlider>
|
||||||
|
#include <QCheckBox>
|
||||||
#include "sliderexamples.h"
|
#include "sliderexamples.h"
|
||||||
#include "components/slider.h"
|
#include "components/slider.h"
|
||||||
#include "exampleview.h"
|
#include "exampleview.h"
|
||||||
|
@ -14,16 +15,28 @@ SliderExamples::SliderExamples(QWidget *parent)
|
||||||
_edit2(new QLineEdit),
|
_edit2(new QLineEdit),
|
||||||
_slider(new Slider),
|
_slider(new Slider),
|
||||||
_slider2(new Slider),
|
_slider2(new Slider),
|
||||||
|
_slider3(new Slider),
|
||||||
__slider(new QSlider)
|
__slider(new QSlider)
|
||||||
{
|
{
|
||||||
QLayout *mainLayout = widget()->layout();
|
QLayout *mainLayout = widget()->layout();
|
||||||
|
|
||||||
{
|
{
|
||||||
Slider *slider = new Slider;
|
QHBoxLayout *layout = new QHBoxLayout;
|
||||||
slider->setMinimumWidth(250);
|
QWidget *widget = new QWidget;
|
||||||
|
|
||||||
|
widget->setLayout(layout);
|
||||||
|
|
||||||
|
_slider3->setMinimumWidth(250);
|
||||||
|
|
||||||
|
QCheckBox *checkbox = new QCheckBox;
|
||||||
|
QCheckBox *checkbox2 = new QCheckBox;
|
||||||
|
|
||||||
|
layout->addWidget(_slider3);
|
||||||
|
layout->addWidget(checkbox);
|
||||||
|
layout->addWidget(checkbox2);
|
||||||
|
|
||||||
ExampleView *view = new ExampleView;
|
ExampleView *view = new ExampleView;
|
||||||
view->setWidget(slider);
|
view->setWidget(widget);
|
||||||
|
|
||||||
Frame *frame = new Frame;
|
Frame *frame = new Frame;
|
||||||
frame->setCodeSnippet(
|
frame->setCodeSnippet(
|
||||||
|
@ -32,6 +45,9 @@ SliderExamples::SliderExamples(QWidget *parent)
|
||||||
frame->setWidget(view);
|
frame->setWidget(view);
|
||||||
|
|
||||||
mainLayout->addWidget(frame);
|
mainLayout->addWidget(frame);
|
||||||
|
|
||||||
|
connect(checkbox, SIGNAL(toggled(bool)), this, SLOT(inv()));
|
||||||
|
connect(checkbox2, SIGNAL(toggled(bool)), this, SLOT(togglePageStepMode()));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
Slider *slider = new Slider;
|
Slider *slider = new Slider;
|
||||||
|
@ -200,3 +216,13 @@ void SliderExamples::updateSliderValue()
|
||||||
{
|
{
|
||||||
_slider2->setValue(_edit2->text().toInt());
|
_slider2->setValue(_edit2->text().toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SliderExamples::inv()
|
||||||
|
{
|
||||||
|
_slider3->setInvertedAppearance(!_slider3->invertedAppearance());
|
||||||
|
}
|
||||||
|
|
||||||
|
void SliderExamples::togglePageStepMode()
|
||||||
|
{
|
||||||
|
_slider3->setPageStepMode(!_slider3->pageStepMode());
|
||||||
|
}
|
||||||
|
|
|
@ -20,12 +20,15 @@ protected slots:
|
||||||
void flip();
|
void flip();
|
||||||
void flip2();
|
void flip2();
|
||||||
void updateSliderValue();
|
void updateSliderValue();
|
||||||
|
void inv();
|
||||||
|
void togglePageStepMode();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QLineEdit *const _edit;
|
QLineEdit *const _edit;
|
||||||
QLineEdit *const _edit2;
|
QLineEdit *const _edit2;
|
||||||
Slider *const _slider;
|
Slider *const _slider;
|
||||||
Slider *const _slider2;
|
Slider *const _slider2;
|
||||||
|
Slider *const _slider3;
|
||||||
QSlider *const __slider;
|
QSlider *const __slider;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue