diff --git a/components/flatbutton.cpp b/components/flatbutton.cpp index 0766754..bb1ea93 100644 --- a/components/flatbutton.cpp +++ b/components/flatbutton.cpp @@ -10,16 +10,57 @@ #include "flatbutton_p.h" +void FlatButtonPrivate::init() +{ + Q_Q(FlatButton); + + ripple = new RippleOverlay(q); + delegate = new FlatButtonDelegate(q); + + Style &style = Style::instance(); + + q->setStyle(&style); + q->setAttribute(Qt::WA_Hover); + q->setMouseTracking(true); + + QFont font(q->font()); + font.setCapitalization(QFont::AllUppercase); + font.setPointSizeF(10.5); + font.setStyleName("Medium"); + q->setFont(font); + + QPalette palette; + palette.setColor(QPalette::Disabled, QPalette::ButtonText, + style.themeColor("disabled")); + q->setPalette(palette); +} + +void FlatButtonPrivate::setTextColor(const QString &themeColor) +{ + Q_Q(FlatButton); + + QPalette palette(q->palette()); + Style &style = Style::instance(); + + palette.setColor(QPalette::Active, QPalette::ButtonText, + style.themeColor(themeColor)); + + q->setPalette(palette); +} + FlatButton::FlatButton(QWidget *parent) : QPushButton(parent), d_ptr(new FlatButtonPrivate(this)) { + d_func()->init(); } FlatButton::FlatButton(const QString &text, QWidget *parent) : QPushButton(parent), d_ptr(new FlatButtonPrivate(this)) { + d_func()->init(); + setText(text); } @@ -51,6 +92,13 @@ void FlatButton::setRole(Material::Role role) update(); } +FlatButton::FlatButton(FlatButtonPrivate &d, QWidget *parent) + : QPushButton(parent), + d_ptr(&d) +{ + d_func()->init(); +} + void FlatButton::resizeEvent(QResizeEvent *event) { Q_D(FlatButton); @@ -115,3 +163,4 @@ void FlatButton::mousePressEvent(QMouseEvent *event) QPushButton::mousePressEvent(event); } + diff --git a/components/flatbutton.h b/components/flatbutton.h index 804cce9..b9e753f 100644 --- a/components/flatbutton.h +++ b/components/flatbutton.h @@ -19,6 +19,8 @@ public: void setRole(Material::Role role); protected: + FlatButton(FlatButtonPrivate &d, QWidget *parent = 0); + void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE; void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; diff --git a/components/flatbutton_p.h b/components/flatbutton_p.h index e93a348..c733ae6 100644 --- a/components/flatbutton_p.h +++ b/components/flatbutton_p.h @@ -13,51 +13,19 @@ class FlatButtonPrivate Q_DECLARE_PUBLIC(FlatButton) public: - FlatButtonPrivate(FlatButton *parent); + FlatButtonPrivate(FlatButton *q) + : q_ptr(q), + role(Material::Default) + { + } + void init(); void setTextColor(const QString &themeColor); - FlatButton *const q_ptr; - RippleOverlay *const ripple; - FlatButtonDelegate *const delegate; + FlatButton *const q_ptr; + RippleOverlay *ripple; + FlatButtonDelegate *delegate; Material::Role role; }; -FlatButtonPrivate::FlatButtonPrivate(FlatButton *parent) - : q_ptr(parent), - ripple(new RippleOverlay(parent)), - delegate(new FlatButtonDelegate(parent)), - role(Material::Default) -{ - Style &style = Style::instance(); - - parent->setStyle(&style); - parent->setAttribute(Qt::WA_Hover); - parent->setMouseTracking(true); - - QFont font(parent->font()); - font.setCapitalization(QFont::AllUppercase); - font.setPointSizeF(10.5); - font.setStyleName("Medium"); - parent->setFont(font); - - QPalette palette; - palette.setColor(QPalette::Disabled, QPalette::ButtonText, - style.themeColor("disabled")); - parent->setPalette(palette); -} - -void FlatButtonPrivate::setTextColor(const QString &themeColor) -{ - Q_Q(FlatButton); - - QPalette palette(q->palette()); - Style &style = Style::instance(); - - palette.setColor(QPalette::Active, QPalette::ButtonText, - style.themeColor(themeColor)); - - q->setPalette(palette); -} - #endif // FLATBUTTON_P_H diff --git a/components/raisedbutton.cpp b/components/raisedbutton.cpp index 5acc66b..27996fe 100644 --- a/components/raisedbutton.cpp +++ b/components/raisedbutton.cpp @@ -1,67 +1,81 @@ -#include -#include -#include -#include -#include #include "raisedbutton.h" +#include "raisedbutton_p.h" + RaisedButton::RaisedButton(QWidget *parent) - : FlatButton(parent) + : FlatButton(*new RaisedButtonPrivate(this), parent) { - QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect; - effect->setBlurRadius(7); - effect->setOffset(QPoint(0, 0)); - effect->setColor(QColor(0, 0, 0, 100)); - setGraphicsEffect(effect); - - setAutoFillBackground(true); - - QPropertyAnimation *animation; - - animation = new QPropertyAnimation; - animation->setTargetObject(effect); - animation->setPropertyName("offset"); - animation->setStartValue(QPoint(0, 6)); - animation->setEndValue(QPoint(0, 0)); - animation->setDuration(100); - _group.addAnimation(animation); - - animation = new QPropertyAnimation; - animation->setTargetObject(effect); - animation->setPropertyName("blurRadius"); - animation->setStartValue(20); - animation->setEndValue(7); - animation->setDuration(100); - _group.addAnimation(animation); - - connect(animation, SIGNAL(valueChanged(QVariant)), this, SLOT(update())); } RaisedButton::~RaisedButton() { } -void RaisedButton::mousePressEvent(QMouseEvent *event) -{ - _group.setDirection(QAbstractAnimation::Backward); - _group.start(); - - FlatButton::mousePressEvent(event); -} - -void RaisedButton::mouseReleaseEvent(QMouseEvent *event) -{ - _group.setDirection(QAbstractAnimation::Forward); - _group.start(); - - FlatButton::mouseReleaseEvent(event); -} - -void RaisedButton::paintEvent(QPaintEvent *event) -{ - Q_UNUSED(event) - - QStylePainter painter(this); - -// painter.drawControl(QStyle::CE_PushButton, getStyleOption()); -} +//#include +//#include +//#include +//#include +//#include +//#include "raisedbutton.h" +// +//RaisedButton::RaisedButton(QWidget *parent) +// : FlatButton(parent) +//{ +// QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect; +// effect->setBlurRadius(7); +// effect->setOffset(QPoint(0, 0)); +// effect->setColor(QColor(0, 0, 0, 100)); +// setGraphicsEffect(effect); +// +// setAutoFillBackground(true); +// +// QPropertyAnimation *animation; +// +// animation = new QPropertyAnimation; +// animation->setTargetObject(effect); +// animation->setPropertyName("offset"); +// animation->setStartValue(QPoint(0, 6)); +// animation->setEndValue(QPoint(0, 0)); +// animation->setDuration(100); +// _group.addAnimation(animation); +// +// animation = new QPropertyAnimation; +// animation->setTargetObject(effect); +// animation->setPropertyName("blurRadius"); +// animation->setStartValue(20); +// animation->setEndValue(7); +// animation->setDuration(100); +// _group.addAnimation(animation); +// +// connect(animation, SIGNAL(valueChanged(QVariant)), this, SLOT(update())); +//} +// +//RaisedButton::~RaisedButton() +//{ +//} +// +//void RaisedButton::mousePressEvent(QMouseEvent *event) +//{ +// _group.setDirection(QAbstractAnimation::Backward); +// _group.start(); +// +// FlatButton::mousePressEvent(event); +//} +// +//void RaisedButton::mouseReleaseEvent(QMouseEvent *event) +//{ +// _group.setDirection(QAbstractAnimation::Forward); +// _group.start(); +// +// FlatButton::mouseReleaseEvent(event); +//} +// +//void RaisedButton::paintEvent(QPaintEvent *event) +//{ +// Q_UNUSED(event) +// +// QStylePainter painter(this); +// +//// painter.drawControl(QStyle::CE_PushButton, getStyleOption()); +//} +// diff --git a/components/raisedbutton.h b/components/raisedbutton.h index 9a40674..5ee0c41 100644 --- a/components/raisedbutton.h +++ b/components/raisedbutton.h @@ -1,11 +1,8 @@ #ifndef RAISEDBUTTON_H #define RAISEDBUTTON_H -#include #include "flatbutton.h" -class QPropertyAnimation; - class RaisedButton : public FlatButton { Q_OBJECT @@ -13,14 +10,34 @@ class RaisedButton : public FlatButton public: explicit RaisedButton(QWidget *parent = 0); ~RaisedButton(); - -protected: - void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; - -private: - QParallelAnimationGroup _group; }; #endif // RAISEDBUTTON_H + +//#ifndef RAISEDBUTTON_H +//#define RAISEDBUTTON_H +// +//#include +//#include "flatbutton.h" +// +//class QPropertyAnimation; +// +//class RaisedButton : public FlatButton +//{ +// Q_OBJECT +// +//public: +// explicit RaisedButton(QWidget *parent = 0); +// ~RaisedButton(); +// +//protected: +// void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; +// void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; +// void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; +// +//private: +// QParallelAnimationGroup _group; +//}; +// +//#endif // RAISEDBUTTON_H +// diff --git a/components/raisedbutton_p.h b/components/raisedbutton_p.h new file mode 100644 index 0000000..8f3661b --- /dev/null +++ b/components/raisedbutton_p.h @@ -0,0 +1,18 @@ +#ifndef RAISEDBUTTON_P_H +#define RAISEDBUTTON_P_H + +#include "flatbutton_p.h" + +class RaisedButtonPrivate : public FlatButtonPrivate +{ + Q_DISABLE_COPY(RaisedButtonPrivate) + Q_DECLARE_PUBLIC(RaisedButton) + +public: + RaisedButtonPrivate(RaisedButton *q) + : FlatButtonPrivate(q) + { + } +}; + +#endif // RAISEDBUTTON_P_H diff --git a/components/slider_p.h b/components/slider_p.h index 08ec62a..ad111e0 100644 --- a/components/slider_p.h +++ b/components/slider_p.h @@ -38,29 +38,29 @@ public: int trackWidth; }; -SliderPrivate::SliderPrivate(Slider *parent) - : q_ptr(parent), - thumb(new SliderThumb(parent)), - track(new SliderTrack(parent)), - machine(new SliderStateMachine(parent, thumb, track)), +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(parent->value()), + oldValue(q->value()), trackWidth(2) { - parent->setMouseTracking(true); - parent->setFocusPolicy(Qt::StrongFocus); - parent->setPageStep(1); + q->setMouseTracking(true); + q->setFocusPolicy(Qt::StrongFocus); + q->setPageStep(1); QSizePolicy sp(QSizePolicy::Expanding, QSizePolicy::Fixed); - if (parent->orientation() == Qt::Vertical) + if (q->orientation() == Qt::Vertical) sp.transpose(); - parent->setSizePolicy(sp); - parent->setAttribute(Qt::WA_WState_OwnSizePolicy, false); + q->setSizePolicy(sp); + q->setAttribute(Qt::WA_WState_OwnSizePolicy, false); machine->start(); diff --git a/lib/theme_p.h b/lib/theme_p.h index 063bd8b..31f4adb 100644 --- a/lib/theme_p.h +++ b/lib/theme_p.h @@ -9,7 +9,7 @@ class ThemePrivate Q_DECLARE_PUBLIC(Theme) public: - ThemePrivate(Theme *parent); + ThemePrivate(Theme *q); QColor rgba(int r, int g, int b, qreal a) const; @@ -18,8 +18,8 @@ public: QHash colors; }; -ThemePrivate::ThemePrivate(Theme *parent) - : q_ptr(parent) +ThemePrivate::ThemePrivate(Theme *q) + : q_ptr(q) { } diff --git a/qt-material-widgets.pro b/qt-material-widgets.pro index 61e4f07..97eb843 100644 --- a/qt-material-widgets.pro +++ b/qt-material-widgets.pro @@ -105,7 +105,8 @@ HEADERS += mainwindow.h \ lib/theme_p.h \ components/flatbutton_p.h \ components/slider_internal.h \ - components/flatbutton_internal.h + components/flatbutton_internal.h \ + components/raisedbutton_p.h RESOURCES += \ resources.qrc