123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- #include "qtmaterialappbar.h"
- #include "qtmaterialappbar_p.h"
- #include <QtWidgets/QGraphicsDropShadowEffect>
- #include <QPainter>
- #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_ptr(new QtMaterialAppBarPrivate(this))
- {
- 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;
- }
- }
|