diff --git a/components/flatbutton.cpp b/components/flatbutton.cpp index bb1ea93..64b14fb 100644 --- a/components/flatbutton.cpp +++ b/components/flatbutton.cpp @@ -7,7 +7,6 @@ #include #include "lib/rippleoverlay.h" #include "lib/ripple.h" - #include "flatbutton_p.h" void FlatButtonPrivate::init() @@ -163,4 +162,3 @@ void FlatButton::mousePressEvent(QMouseEvent *event) QPushButton::mousePressEvent(event); } - diff --git a/components/flatbutton_p.h b/components/flatbutton_p.h index c733ae6..e1df510 100644 --- a/components/flatbutton_p.h +++ b/components/flatbutton_p.h @@ -16,8 +16,7 @@ public: FlatButtonPrivate(FlatButton *q) : q_ptr(q), role(Material::Default) - { - } + {} void init(); void setTextColor(const QString &themeColor); diff --git a/components/raisedbutton.cpp b/components/raisedbutton.cpp index 27996fe..d23c4fd 100644 --- a/components/raisedbutton.cpp +++ b/components/raisedbutton.cpp @@ -1,5 +1,4 @@ #include "raisedbutton.h" - #include "raisedbutton_p.h" RaisedButton::RaisedButton(QWidget *parent) diff --git a/components/slider.cpp b/components/slider.cpp index bbf3c36..c954398 100644 --- a/components/slider.cpp +++ b/components/slider.cpp @@ -5,13 +5,97 @@ #include #include #include - #include "slider_p.h" +void SliderPrivate::init() +{ + Q_Q(Slider); + + thumb = new SliderThumb(q); + track = new SliderTrack(q); + machine = new SliderStateMachine(q, thumb, track); + + oldValue = q->value(); + + q->setMouseTracking(true); + q->setFocusPolicy(Qt::StrongFocus); + q->setPageStep(1); + + QSizePolicy sp(QSizePolicy::Expanding, QSizePolicy::Fixed); + if (q->orientation() == Qt::Vertical) + sp.transpose(); + q->setSizePolicy(sp); + q->setAttribute(Qt::WA_WState_OwnSizePolicy, false); + + machine->start(); + + QCoreApplication::processEvents(); +} + +QRectF SliderPrivate::trackBoundingRect() const +{ + Q_Q(const Slider); + + qreal hw = static_cast(trackWidth)/2; + + return Qt::Horizontal == q->orientation() + ? QRectF(SLIDER_MARGIN, q->height()/2 - hw, + q->width() - SLIDER_MARGIN*2, hw*2) + : QRectF(q->width()/2 - hw, SLIDER_MARGIN, hw*2, + q->height() - SLIDER_MARGIN*2); +} + +QRectF SliderPrivate::thumbBoundingRect() const +{ + Q_Q(const Slider); + + return Qt::Horizontal == q->orientation() + ? QRectF(q->thumbOffset(), q->height()/2 - SLIDER_MARGIN, + SLIDER_MARGIN*2, SLIDER_MARGIN*2) + : QRectF(q->width()/2 - SLIDER_MARGIN, q->thumbOffset(), + SLIDER_MARGIN*2, SLIDER_MARGIN*2); +} + +int SliderPrivate::valueFromPosition(const QPoint &pos) const +{ + Q_Q(const Slider); + + int position = Qt::Horizontal == q->orientation() ? pos.x() : pos.y(); + + int span = Qt::Horizontal == q->orientation() + ? q->width() - SLIDER_MARGIN*2 + : q->height() - SLIDER_MARGIN*2; + + return Style::sliderValueFromPosition( + q->minimum(), + q->maximum(), + position - SLIDER_MARGIN, + span, + q->invertedAppearance()); +} + +void SliderPrivate::setHovered(bool status) +{ + Q_Q(Slider); + + if (hover != status) { + hover = status; + if (!q->hasFocus()) { + if (status) { + emit machine->noFocusMouseEnter(); + } else { + emit machine->noFocusMouseLeave(); + } + } + q->update(); + } +} + Slider::Slider(QWidget *parent) : QAbstractSlider(parent), d_ptr(new SliderPrivate(this)) { + d_func()->init(); } Slider::~Slider() diff --git a/components/slider_p.h b/components/slider_p.h index ad111e0..ab744c0 100644 --- a/components/slider_p.h +++ b/components/slider_p.h @@ -15,7 +15,19 @@ class SliderPrivate Q_DECLARE_PUBLIC(Slider) public: - SliderPrivate(Slider *parent); + SliderPrivate(Slider *q) + : q_ptr(q), + hoverTrack(false), + hoverThumb(false), + hover(false), + step(false), + pageStepMode(true), + stepTo(0), + oldValue(0), + trackWidth(2) + {} + + void init(); QRectF trackBoundingRect() const; QRectF thumbBoundingRect() const; @@ -24,10 +36,10 @@ public: void setHovered(bool status); - Slider *const q_ptr; - SliderThumb *const thumb; - SliderTrack *const track; - SliderStateMachine *const machine; + Slider *const q_ptr; + SliderThumb *thumb; + SliderTrack *track; + SliderStateMachine *machine; bool hoverTrack; bool hoverThumb; bool hover; @@ -38,92 +50,4 @@ public: int trackWidth; }; -SliderPrivate::SliderPrivate(Slider *q) - : q_ptr(q), - thumb(new SliderThumb(q)), - track(new SliderTrack(q)), - machine(new SliderStateMachine(q, thumb, track)), - hoverTrack(false), - hoverThumb(false), - hover(false), - step(false), - pageStepMode(true), - stepTo(0), - oldValue(q->value()), - trackWidth(2) -{ - q->setMouseTracking(true); - q->setFocusPolicy(Qt::StrongFocus); - q->setPageStep(1); - - QSizePolicy sp(QSizePolicy::Expanding, QSizePolicy::Fixed); - if (q->orientation() == Qt::Vertical) - sp.transpose(); - q->setSizePolicy(sp); - q->setAttribute(Qt::WA_WState_OwnSizePolicy, false); - - machine->start(); - - QCoreApplication::processEvents(); -} - -QRectF SliderPrivate::trackBoundingRect() const -{ - Q_Q(const Slider); - - qreal hw = static_cast(trackWidth)/2; - - return Qt::Horizontal == q->orientation() - ? QRectF(SLIDER_MARGIN, q->height()/2 - hw, - q->width() - SLIDER_MARGIN*2, hw*2) - : QRectF(q->width()/2 - hw, SLIDER_MARGIN, hw*2, - q->height() - SLIDER_MARGIN*2); -} - -QRectF SliderPrivate::thumbBoundingRect() const -{ - Q_Q(const Slider); - - return Qt::Horizontal == q->orientation() - ? QRectF(q->thumbOffset(), q->height()/2 - SLIDER_MARGIN, - SLIDER_MARGIN*2, SLIDER_MARGIN*2) - : QRectF(q->width()/2 - SLIDER_MARGIN, q->thumbOffset(), - SLIDER_MARGIN*2, SLIDER_MARGIN*2); -} - -int SliderPrivate::valueFromPosition(const QPoint &pos) const -{ - Q_Q(const Slider); - - int position = Qt::Horizontal == q->orientation() ? pos.x() : pos.y(); - - int span = Qt::Horizontal == q->orientation() - ? q->width() - SLIDER_MARGIN*2 - : q->height() - SLIDER_MARGIN*2; - - return Style::sliderValueFromPosition( - q->minimum(), - q->maximum(), - position - SLIDER_MARGIN, - span, - q->invertedAppearance()); -} - -void SliderPrivate::setHovered(bool status) -{ - Q_Q(Slider); - - if (hover != status) { - hover = status; - if (!q->hasFocus()) { - if (status) { - emit machine->noFocusMouseEnter(); - } else { - emit machine->noFocusMouseLeave(); - } - } - q->update(); - } -} - #endif // SLIDER_P_H diff --git a/lib/theme.cpp b/lib/theme.cpp index 7107a2d..8beb9f9 100644 --- a/lib/theme.cpp +++ b/lib/theme.cpp @@ -1,8 +1,19 @@ #include "theme.h" #include - #include "theme_p.h" +ThemePrivate::ThemePrivate(Theme *q) + : q_ptr(q) +{ +} + +QColor ThemePrivate::rgba(int r, int g, int b, qreal a) const +{ + QColor color(r, g, b); + color.setAlphaF(a); + return color; +} + Theme::Theme(QObject *parent) : QObject(parent), d_ptr(new ThemePrivate(this)) diff --git a/lib/theme_p.h b/lib/theme_p.h index 31f4adb..bcbc345 100644 --- a/lib/theme_p.h +++ b/lib/theme_p.h @@ -18,16 +18,4 @@ public: QHash colors; }; -ThemePrivate::ThemePrivate(Theme *q) - : q_ptr(q) -{ -} - -QColor ThemePrivate::rgba(int r, int g, int b, qreal a) const -{ - QColor color(r, g, b); - color.setAlphaF(a); - return color; -} - #endif // THEME_P_H