clean up pimpl code

This commit is contained in:
FarmRadio Hangar 2016-05-17 15:39:20 +03:00
parent 0f4020d193
commit 7c39d083bb
7 changed files with 115 additions and 112 deletions

View File

@ -7,7 +7,6 @@
#include <QDebug>
#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);
}

View File

@ -16,8 +16,7 @@ public:
FlatButtonPrivate(FlatButton *q)
: q_ptr(q),
role(Material::Default)
{
}
{}
void init();
void setTextColor(const QString &themeColor);

View File

@ -1,5 +1,4 @@
#include "raisedbutton.h"
#include "raisedbutton_p.h"
RaisedButton::RaisedButton(QWidget *parent)

View File

@ -5,13 +5,97 @@
#include <QMouseEvent>
#include <QApplication>
#include <QDebug>
#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<qreal>(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()

View File

@ -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<qreal>(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

View File

@ -1,8 +1,19 @@
#include "theme.h"
#include <QDebug>
#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))

View File

@ -18,16 +18,4 @@ public:
QHash<QString, QColor> 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