From 26072c83735001269b936c8202081f94479da805 Mon Sep 17 00:00:00 2001 From: laserpants Date: Sun, 29 May 2016 13:08:55 +0300 Subject: [PATCH] make toggle pimpl class --- components/toggle.cpp | 14 +++++++++++++- components/toggle.h | 8 ++++++++ components/toggle_internal.cpp | 11 +++++++++++ components/toggle_internal.h | 20 ++++++++++++++++++++ components/toggle_p.h | 15 +++++++++++++++ qt-material-widgets.pro | 6 ++++-- 6 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 components/toggle_internal.cpp create mode 100644 components/toggle_internal.h diff --git a/components/toggle.cpp b/components/toggle.cpp index 6576928..8e9f474 100644 --- a/components/toggle.cpp +++ b/components/toggle.cpp @@ -1,8 +1,20 @@ #include "toggle.h" +#include "toggle_p.h" + +TogglePrivate::TogglePrivate(Toggle *q) + : q_ptr(q) +{ +} + +void TogglePrivate::init() +{ +} Toggle::Toggle(QWidget *parent) - : QAbstractButton(parent) + : QAbstractButton(parent), + d_ptr(new TogglePrivate(this)) { + d_func()->init(); } Toggle::~Toggle() diff --git a/components/toggle.h b/components/toggle.h index 03b5542..294b458 100644 --- a/components/toggle.h +++ b/components/toggle.h @@ -3,6 +3,8 @@ #include +class TogglePrivate; + class Toggle : public QAbstractButton { Q_OBJECT @@ -15,6 +17,12 @@ public: protected: void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; + + const QScopedPointer d_ptr; + +private: + Q_DISABLE_COPY(Toggle) + Q_DECLARE_PRIVATE(Toggle) }; #endif // TOGGLE_H diff --git a/components/toggle_internal.cpp b/components/toggle_internal.cpp new file mode 100644 index 0000000..dbbd906 --- /dev/null +++ b/components/toggle_internal.cpp @@ -0,0 +1,11 @@ +#include "toggle_internal.h" +#include "toggle.h" + +Thumb::Thumb(Toggle *parent) + : QWidget(parent) +{ +} + +Thumb::~Thumb() +{ +} diff --git a/components/toggle_internal.h b/components/toggle_internal.h new file mode 100644 index 0000000..b4648fa --- /dev/null +++ b/components/toggle_internal.h @@ -0,0 +1,20 @@ +#ifndef TOGGLE_INTERNAL_H +#define TOGGLE_INTERNAL_H + +#include + +class Toggle; + +class Thumb : public QWidget +{ + Q_OBJECT + +public: + Thumb(Toggle *parent); + ~Thumb(); + +private: + Q_DISABLE_COPY(Thumb) +}; + +#endif // TOGGLE_INTERNAL_H diff --git a/components/toggle_p.h b/components/toggle_p.h index 133d43b..e46bb0d 100644 --- a/components/toggle_p.h +++ b/components/toggle_p.h @@ -1,4 +1,19 @@ #ifndef TOGGLE_P_H #define TOGGLE_P_H +#include "toggle_internal.h" + +class TogglePrivate +{ + Q_DISABLE_COPY(TogglePrivate) + Q_DECLARE_PUBLIC(Toggle) + +public: + TogglePrivate(Toggle *q); + + void init(); + + Toggle *const q_ptr; +}; + #endif // TOGGLE_P_H diff --git a/qt-material-widgets.pro b/qt-material-widgets.pro index cab1120..6cd6c3b 100644 --- a/qt-material-widgets.pro +++ b/qt-material-widgets.pro @@ -54,7 +54,8 @@ SOURCES += main.cpp\ components/searchfield.cpp \ lib/theme.cpp \ components/slider_internal.cpp \ - components/flatbutton_internal.cpp + components/flatbutton_internal.cpp \ + components/toggle_internal.cpp HEADERS += mainwindow.h \ components/appbar.h \ @@ -107,7 +108,8 @@ HEADERS += mainwindow.h \ components/slider_internal.h \ components/flatbutton_internal.h \ components/raisedbutton_p.h \ - components/toggle_p.h + components/toggle_p.h \ + components/toggle_internal.h RESOURCES += \ resources.qrc