diff --git a/components/qtmaterialappbar.cpp b/components/qtmaterialappbar.cpp index 4e67b5a..5e5e230 100644 --- a/components/qtmaterialappbar.cpp +++ b/components/qtmaterialappbar.cpp @@ -1,2 +1,139 @@ #include "qtmaterialappbar.h" #include "qtmaterialappbar_p.h" +#include +#include +#include +#include "lib/qtmaterialstyle.h" + +/*! + * \class QtMaterialAppBarPrivate + * \internal + */ + +/*! + * \internal + */ +QtMaterialAppBarPrivate::QtMaterialAppBarPrivate(QtMaterialAppBar *q) + : q_ptr(q) +{ +} + +/*! + * \internal + */ +QtMaterialAppBarPrivate::~QtMaterialAppBarPrivate() +{ +} + +/*! + * \internal + */ +void QtMaterialAppBarPrivate::init() +{ + Q_Q(QtMaterialAppBar); + + useThemeColors = true; + + QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect; + effect->setBlurRadius(11); + effect->setColor(QColor(0, 0, 0, 50)); + effect->setOffset(0, 3); + + q->setGraphicsEffect(effect); + + QHBoxLayout *layout = new QHBoxLayout; + q->setLayout(layout); +} + +/*! + * \class QtMaterialAppBar + */ + +QtMaterialAppBar::QtMaterialAppBar(QWidget *parent) + : QWidget(parent) +{ + d_func()->init(); +} + +QtMaterialAppBar::~QtMaterialAppBar() +{ +} + +QSize QtMaterialAppBar::sizeHint() const +{ + return QSize(-1, 64); +} + +void QtMaterialAppBar::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event) + + QPainter painter(this); + + painter.fillRect(rect(), backgroundColor()); +} + +void QtMaterialAppBar::setUseThemeColors(bool value) +{ + Q_D(QtMaterialAppBar); + + if (d->useThemeColors == value) { + return; + } + + d->useThemeColors = value; + update(); +} + +bool QtMaterialAppBar::useThemeColors() const +{ + Q_D(const QtMaterialAppBar); + + return d->useThemeColors; +} + +void QtMaterialAppBar::setForegroundColor(const QColor &color) +{ + Q_D(QtMaterialAppBar); + + d->foregroundColor = color; + + if (d->useThemeColors == true) { + d->useThemeColors = false; + } + update(); +} + +QColor QtMaterialAppBar::foregroundColor() const +{ + Q_D(const QtMaterialAppBar); + + if (d->useThemeColors || !d->foregroundColor.isValid()) { + return QtMaterialStyle::instance().themeColor("primary1"); + } else { + return d->foregroundColor; + } +} + +void QtMaterialAppBar::setBackgroundColor(const QColor &color) +{ + Q_D(QtMaterialAppBar); + + d->backgroundColor = color; + + if (d->useThemeColors == true) { + d->useThemeColors = false; + } + update(); +} + +QColor QtMaterialAppBar::backgroundColor() const +{ + Q_D(const QtMaterialAppBar); + + if (d->useThemeColors || !d->backgroundColor.isValid()) { + return QtMaterialStyle::instance().themeColor("primary1"); + } else { + return d->backgroundColor; + } +} diff --git a/components/qtmaterialappbar.h b/components/qtmaterialappbar.h index b2c8a20..6558ccf 100644 --- a/components/qtmaterialappbar.h +++ b/components/qtmaterialappbar.h @@ -1,4 +1,40 @@ #ifndef QTMATERIALAPPBAR_H #define QTMATERIALAPPBAR_H +#include + +class QtMaterialAppBarPrivate; + +class QtMaterialAppBar : public QWidget +{ + Q_OBJECT + + Q_PROPERTY(QColor foregroundColor WRITE setForegroundColor READ foregroundColor) + Q_PROPERTY(QColor backgroundColor WRITE setBackgroundColor READ backgroundColor) + +public: + explicit QtMaterialAppBar(QWidget *parent = 0); + ~QtMaterialAppBar(); + + QSize sizeHint() const Q_DECL_OVERRIDE; + + void setUseThemeColors(bool value); + bool useThemeColors() const; + + void setForegroundColor(const QColor &color); + QColor foregroundColor() const; + + void setBackgroundColor(const QColor &color); + QColor backgroundColor() const; + +protected: + void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; + + const QScopedPointer d_ptr; + +private: + Q_DISABLE_COPY(QtMaterialAppBar) + Q_DECLARE_PRIVATE(QtMaterialAppBar) +}; + #endif // QTMATERIALAPPBAR_H diff --git a/components/qtmaterialappbar_p.h b/components/qtmaterialappbar_p.h index 58f1d3c..0586556 100644 --- a/components/qtmaterialappbar_p.h +++ b/components/qtmaterialappbar_p.h @@ -1,4 +1,26 @@ #ifndef QTMATERIALAPPBAR_P_H #define QTMATERIALAPPBAR_P_H +#include +#include + +class QtMaterialAppBar; + +class QtMaterialAppBarPrivate +{ + Q_DISABLE_COPY(QtMaterialAppBarPrivate) + Q_DECLARE_PUBLIC(QtMaterialAppBar) + +public: + QtMaterialAppBarPrivate(QtMaterialAppBar *q); + ~QtMaterialAppBarPrivate(); + + void init(); + + QtMaterialAppBar *const q_ptr; + bool useThemeColors; + QColor foregroundColor; + QColor backgroundColor; +}; + #endif // QTMATERIALAPPBAR_P_H