snapshot
This commit is contained in:
parent
40f311bdb7
commit
2b50f65438
|
@ -30,8 +30,8 @@ int Slider::thumbOffset() const
|
||||||
maximum(),
|
maximum(),
|
||||||
sliderPosition(),
|
sliderPosition(),
|
||||||
Qt::Horizontal == orientation()
|
Qt::Horizontal == orientation()
|
||||||
? rect().width() - SLIDER_MARGIN*2
|
? width() - SLIDER_MARGIN*2
|
||||||
: rect().height() - SLIDER_MARGIN*2,
|
: height() - SLIDER_MARGIN*2,
|
||||||
invertedAppearance());
|
invertedAppearance());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,6 +100,8 @@ void Slider::paintEvent(QPaintEvent *event)
|
||||||
Q_UNUSED(event)
|
Q_UNUSED(event)
|
||||||
|
|
||||||
#ifdef DEBUG_LAYOUT
|
#ifdef DEBUG_LAYOUT
|
||||||
|
QPainter painter(this);
|
||||||
|
|
||||||
if (hasFocus())
|
if (hasFocus())
|
||||||
painter.drawRect(rect().adjusted(0, 0, -1, -1));
|
painter.drawRect(rect().adjusted(0, 0, -1, -1));
|
||||||
|
|
||||||
|
|
|
@ -21,14 +21,13 @@ public:
|
||||||
QRectF trackBoundingRect() const;
|
QRectF trackBoundingRect() const;
|
||||||
QRectF thumbBoundingRect() const;
|
QRectF thumbBoundingRect() const;
|
||||||
|
|
||||||
//void paintTrack(QPainter *painter);
|
|
||||||
int valueFromPosition(const QPoint &pos) const;
|
int valueFromPosition(const QPoint &pos) const;
|
||||||
|
|
||||||
void setHovered(bool status);
|
void setHovered(bool status);
|
||||||
|
|
||||||
Slider *const q_ptr;
|
Slider *const q_ptr;
|
||||||
SliderTrack *const track;
|
|
||||||
SliderThumb *const thumb;
|
SliderThumb *const thumb;
|
||||||
|
SliderTrack *const track;
|
||||||
SliderStateMachine *const machine;
|
SliderStateMachine *const machine;
|
||||||
bool hoverTrack;
|
bool hoverTrack;
|
||||||
bool hoverThumb;
|
bool hoverThumb;
|
||||||
|
@ -42,9 +41,9 @@ public:
|
||||||
|
|
||||||
SliderPrivate::SliderPrivate(Slider *parent)
|
SliderPrivate::SliderPrivate(Slider *parent)
|
||||||
: q_ptr(parent),
|
: q_ptr(parent),
|
||||||
track(new SliderTrack(parent)),
|
|
||||||
thumb(new SliderThumb(parent)),
|
thumb(new SliderThumb(parent)),
|
||||||
machine(new SliderStateMachine(parent, thumb)),
|
track(new SliderTrack(parent)),
|
||||||
|
machine(new SliderStateMachine(parent, thumb, track)),
|
||||||
hoverTrack(false),
|
hoverTrack(false),
|
||||||
hoverThumb(false),
|
hoverThumb(false),
|
||||||
hover(false),
|
hover(false),
|
||||||
|
@ -94,57 +93,6 @@ QRectF SliderPrivate::thumbBoundingRect() const
|
||||||
SLIDER_MARGIN*2, SLIDER_MARGIN*2);
|
SLIDER_MARGIN*2, SLIDER_MARGIN*2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
void SliderPrivate::paintTrack(QPainter *painter)
|
|
||||||
{
|
|
||||||
Q_Q(const Slider);
|
|
||||||
|
|
||||||
Style &style = Style::instance();
|
|
||||||
|
|
||||||
painter->save();
|
|
||||||
|
|
||||||
QBrush fg;
|
|
||||||
fg.setStyle(Qt::SolidPattern);
|
|
||||||
fg.setColor(q->isEnabled() ? style.themeColor("primary1")
|
|
||||||
: style.themeColor("disabled"));
|
|
||||||
QBrush bg;
|
|
||||||
bg.setStyle(Qt::SolidPattern);
|
|
||||||
bg.setColor(hover ? QColor(0, 0, 0, 150) // @TODO: set theme color
|
|
||||||
: style.themeColor("accent3"));
|
|
||||||
|
|
||||||
qreal offset = q->thumbOffset() + SLIDER_MARGIN;
|
|
||||||
|
|
||||||
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, q->isEnabled() ? offset : offset + 7,
|
|
||||||
box.width(), box.width())
|
|
||||||
: QRectF(q->isEnabled() ? offset : offset + 7, 0,
|
|
||||||
box.height(), box.height());
|
|
||||||
|
|
||||||
bool inverted = q->invertedAppearance();
|
|
||||||
|
|
||||||
painter->fillRect(QRectF(QPointF(0, 0), box).intersected(trackBoundingRect()),
|
|
||||||
inverted ? bg : fg);
|
|
||||||
painter->fillRect(rect.intersected(trackBoundingRect()), inverted ? fg : bg);
|
|
||||||
|
|
||||||
painter->restore();
|
|
||||||
|
|
||||||
#ifdef DEBUG_LAYOUT
|
|
||||||
if (hoverTrack) {
|
|
||||||
painter->save();
|
|
||||||
painter->setPen(Qt::red);
|
|
||||||
painter->drawRect(trackBoundingRect());
|
|
||||||
painter->restore();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
int SliderPrivate::valueFromPosition(const QPoint &pos) const
|
int SliderPrivate::valueFromPosition(const QPoint &pos) const
|
||||||
{
|
{
|
||||||
Q_Q(const Slider);
|
Q_Q(const Slider);
|
||||||
|
@ -152,8 +100,8 @@ int SliderPrivate::valueFromPosition(const QPoint &pos) const
|
||||||
int position = Qt::Horizontal == q->orientation() ? pos.x() : pos.y();
|
int position = Qt::Horizontal == q->orientation() ? pos.x() : pos.y();
|
||||||
|
|
||||||
int span = Qt::Horizontal == q->orientation()
|
int span = Qt::Horizontal == q->orientation()
|
||||||
? q->rect().width() - SLIDER_MARGIN*2
|
? q->width() - SLIDER_MARGIN*2
|
||||||
: q->rect().height() - SLIDER_MARGIN*2;
|
: q->height() - SLIDER_MARGIN*2;
|
||||||
|
|
||||||
return Style::sliderValueFromPosition(
|
return Style::sliderValueFromPosition(
|
||||||
q->minimum(),
|
q->minimum(),
|
||||||
|
|
|
@ -5,8 +5,11 @@
|
||||||
#include "lib/style.h"
|
#include "lib/style.h"
|
||||||
#include "slider.h"
|
#include "slider.h"
|
||||||
#include "sliderthumb.h"
|
#include "sliderthumb.h"
|
||||||
|
#include "slidertrack.h"
|
||||||
|
|
||||||
SliderStateMachine::SliderStateMachine(Slider *parent, SliderThumb *thumb)
|
SliderStateMachine::SliderStateMachine(Slider *parent,
|
||||||
|
SliderThumb *thumb,
|
||||||
|
SliderTrack *track)
|
||||||
: QStateMachine(parent)
|
: QStateMachine(parent)
|
||||||
{
|
{
|
||||||
Style &style = Style::instance();
|
Style &style = Style::instance();
|
||||||
|
@ -44,6 +47,11 @@ SliderStateMachine::SliderStateMachine(Slider *parent, SliderThumb *thumb)
|
||||||
focusState->assignProperty(thumb, "fillColor", fillColor);
|
focusState->assignProperty(thumb, "fillColor", fillColor);
|
||||||
slidingState->assignProperty(thumb, "fillColor", fillColor);
|
slidingState->assignProperty(thumb, "fillColor", fillColor);
|
||||||
|
|
||||||
|
inactiveState->assignProperty(track, "fillColor", style.themeColor("accent2"));
|
||||||
|
slidingState->assignProperty(track, "fillColor", style.themeColor("accent3"));
|
||||||
|
focusState->assignProperty(track, "fillColor", style.themeColor("accent3"));
|
||||||
|
disabledState->assignProperty(track, "fillColor", style.themeColor("disabled"));
|
||||||
|
|
||||||
addState(topState);
|
addState(topState);
|
||||||
|
|
||||||
fstState->setInitialState(inactiveState);
|
fstState->setInitialState(inactiveState);
|
||||||
|
@ -79,6 +87,7 @@ SliderStateMachine::SliderStateMachine(Slider *parent, SliderThumb *thumb)
|
||||||
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"));
|
||||||
inactiveState->addTransition(transition);
|
inactiveState->addTransition(transition);
|
||||||
|
|
||||||
// Show halo on focus in
|
// Show halo on focus in
|
||||||
|
@ -89,6 +98,7 @@ SliderStateMachine::SliderStateMachine(Slider *parent, SliderThumb *thumb)
|
||||||
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"));
|
||||||
inactiveState->addTransition(transition);
|
inactiveState->addTransition(transition);
|
||||||
|
|
||||||
// Hide halo on focus out
|
// Hide halo on focus out
|
||||||
|
@ -99,6 +109,7 @@ SliderStateMachine::SliderStateMachine(Slider *parent, SliderThumb *thumb)
|
||||||
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"));
|
||||||
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
|
||||||
|
@ -109,6 +120,7 @@ SliderStateMachine::SliderStateMachine(Slider *parent, SliderThumb *thumb)
|
||||||
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"));
|
||||||
focusState->addTransition(transition);
|
focusState->addTransition(transition);
|
||||||
|
|
||||||
// Pulse in
|
// Pulse in
|
||||||
|
|
|
@ -5,13 +5,14 @@
|
||||||
|
|
||||||
class Slider;
|
class Slider;
|
||||||
class SliderThumb;
|
class SliderThumb;
|
||||||
|
class SliderTrack;
|
||||||
|
|
||||||
class SliderStateMachine : public QStateMachine
|
class SliderStateMachine : public QStateMachine
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SliderStateMachine(Slider *parent, SliderThumb *thumb);
|
SliderStateMachine(Slider *parent, SliderThumb *thumb, SliderTrack *track);
|
||||||
~SliderStateMachine();
|
~SliderStateMachine();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
|
@ -36,10 +36,9 @@ void SliderTrack::paintEvent(QPaintEvent *event)
|
||||||
: style.themeColor("disabled"));
|
: style.themeColor("disabled"));
|
||||||
QBrush bg;
|
QBrush bg;
|
||||||
bg.setStyle(Qt::SolidPattern);
|
bg.setStyle(Qt::SolidPattern);
|
||||||
bg.setColor(slider->hovered() ? QColor(0, 0, 0, 150) // @TODO: set theme color
|
bg.setColor(slider->isEnabled() ? _fillColor : style.themeColor("disabled"));
|
||||||
: style.themeColor("accent3"));
|
|
||||||
|
|
||||||
qreal offset = slider->thumbOffset() + SLIDER_MARGIN;
|
qreal offset = slider->thumbOffset();
|
||||||
|
|
||||||
QSizeF box(slider->isEnabled() ? offset : offset - 7,
|
QSizeF box(slider->isEnabled() ? offset : offset - 7,
|
||||||
qMax(slider->width(), slider->height()));
|
qMax(slider->width(), slider->height()));
|
||||||
|
@ -50,25 +49,34 @@ void SliderTrack::paintEvent(QPaintEvent *event)
|
||||||
QRectF rect = Qt::Vertical == slider->orientation()
|
QRectF rect = Qt::Vertical == slider->orientation()
|
||||||
? QRectF(0, slider->isEnabled() ? offset : offset + 7,
|
? QRectF(0, slider->isEnabled() ? offset : offset + 7,
|
||||||
box.width(), box.width())
|
box.width(), box.width())
|
||||||
: QRectF(slider->isEnabled() ? offset : offset + 7, 0,
|
: QRectF(slider->isEnabled() ? slider->x() + offset : offset + 7, 0,
|
||||||
box.height(), box.height());
|
box.height(), box.height());
|
||||||
|
|
||||||
qreal hw = static_cast<qreal>(_width)/2;
|
qreal hw = static_cast<qreal>(_width)/2;
|
||||||
|
|
||||||
QRectF geometry = Qt::Horizontal == slider->orientation()
|
QRectF geometry = Qt::Horizontal == slider->orientation()
|
||||||
? QRectF(SLIDER_MARGIN, slider->rect().height()/2 - hw,
|
? QRectF(slider->x() + SLIDER_MARGIN,
|
||||||
slider->width() - SLIDER_MARGIN*2, hw*2)
|
slider->y() + slider->height()/2 - hw,
|
||||||
: QRectF(slider->width()/2 - hw, SLIDER_MARGIN, hw*2,
|
slider->width() - SLIDER_MARGIN*2,
|
||||||
|
hw*2)
|
||||||
|
: QRectF(slider->x() + slider->width()/2 - hw,
|
||||||
|
slider->y() + SLIDER_MARGIN,
|
||||||
|
hw*2,
|
||||||
slider->height() - SLIDER_MARGIN*2);
|
slider->height() - SLIDER_MARGIN*2);
|
||||||
|
|
||||||
bool inverted = slider->invertedAppearance();
|
bool inverted = slider->invertedAppearance();
|
||||||
|
|
||||||
painter.fillRect(QRectF(QPointF(0, 0), box).intersected(geometry),
|
QPointF pos = Qt::Horizontal == slider->orientation()
|
||||||
inverted ? bg : fg);
|
? QPointF(slider->x() + SLIDER_MARGIN, 0)
|
||||||
painter.fillRect(rect.intersected(geometry), inverted ? fg : bg);
|
: QPointF(0, slider->y() + SLIDER_MARGIN);
|
||||||
|
|
||||||
|
//painter.fillRect(QRectF(QPointF(0, 0), box).intersected(geometry),
|
||||||
|
|
||||||
|
// painter.fillRect(QRectF(pos, box), inverted ? bg : fg);
|
||||||
|
painter.fillRect(rect, inverted ? fg : bg);
|
||||||
|
|
||||||
#ifdef DEBUG_LAYOUT
|
#ifdef DEBUG_LAYOUT
|
||||||
if (hoverTrack) {
|
if (slider->hovered()) {
|
||||||
painter.save();
|
painter.save();
|
||||||
painter.setPen(Qt::red);
|
painter.setPen(Qt::red);
|
||||||
painter.drawRect(geometry);
|
painter.drawRect(geometry);
|
||||||
|
|
|
@ -5,7 +5,7 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||||
TARGET = qt-material-widgets
|
TARGET = qt-material-widgets
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
|
|
||||||
#DEFINES += DEBUG_LAYOUT=1
|
DEFINES += DEBUG_LAYOUT=1
|
||||||
|
|
||||||
SOURCES += main.cpp\
|
SOURCES += main.cpp\
|
||||||
mainwindow.cpp \
|
mainwindow.cpp \
|
||||||
|
|
Loading…
Reference in New Issue