qt-material-widgets/components/qtmaterialappbar.cpp

143 lines
2.2 KiB
C++
Raw Normal View History

2017-10-05 11:31:52 +00:00
#include "qtmaterialappbar.h"
#include "qtmaterialappbar_p.h"
2017-10-05 14:11:41 +00:00
#include <QtWidgets/QGraphicsDropShadowEffect>
#include <QPainter>
#include "lib/qtmaterialstyle.h"
namespace md {
2017-10-05 14:11:41 +00:00
/*!
* \class QtMaterialAppBarPrivate
* \internal
*/
/*!
* \internal
*/
AppBarPrivate::AppBarPrivate(AppBar *q)
2017-10-05 14:11:41 +00:00
: q_ptr(q)
{
}
/*!
* \internal
*/
AppBarPrivate::~AppBarPrivate()
2017-10-05 14:11:41 +00:00
{
}
/*!
* \internal
*/
void AppBarPrivate::init()
2017-10-05 14:11:41 +00:00
{
Q_Q(AppBar);
2017-10-05 14:11:41 +00:00
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
*/
AppBar::AppBar(QWidget *parent)
2017-10-11 19:25:22 +00:00
: QWidget(parent),
d_ptr(new AppBarPrivate(this))
2017-10-05 14:11:41 +00:00
{
d_func()->init();
}
AppBar::~AppBar()
2017-10-05 14:11:41 +00:00
{
}
QSize AppBar::sizeHint() const
2017-10-05 14:11:41 +00:00
{
return QSize(-1, 64);
}
void AppBar::paintEvent(QPaintEvent *event)
2017-10-05 14:11:41 +00:00
{
Q_UNUSED(event)
QPainter painter(this);
painter.fillRect(rect(), backgroundColor());
}
void AppBar::setUseThemeColors(bool value)
2017-10-05 14:11:41 +00:00
{
Q_D(AppBar);
2017-10-05 14:11:41 +00:00
if (d->useThemeColors == value) {
return;
}
d->useThemeColors = value;
update();
}
bool AppBar::useThemeColors() const
2017-10-05 14:11:41 +00:00
{
Q_D(const AppBar);
2017-10-05 14:11:41 +00:00
return d->useThemeColors;
}
void AppBar::setForegroundColor(const QColor &color)
2017-10-05 14:11:41 +00:00
{
Q_D(AppBar);
2017-10-05 14:11:41 +00:00
d->foregroundColor = color;
if (d->useThemeColors == true) {
d->useThemeColors = false;
}
update();
}
QColor AppBar::foregroundColor() const
2017-10-05 14:11:41 +00:00
{
Q_D(const AppBar);
2017-10-05 14:11:41 +00:00
if (d->useThemeColors || !d->foregroundColor.isValid()) {
return Style::instance().themeColor("primary1");
2017-10-05 14:11:41 +00:00
} else {
return d->foregroundColor;
}
}
void AppBar::setBackgroundColor(const QColor &color)
2017-10-05 14:11:41 +00:00
{
Q_D(AppBar);
2017-10-05 14:11:41 +00:00
d->backgroundColor = color;
if (d->useThemeColors == true) {
d->useThemeColors = false;
}
update();
}
QColor AppBar::backgroundColor() const
2017-10-05 14:11:41 +00:00
{
Q_D(const AppBar);
2017-10-05 14:11:41 +00:00
if (d->useThemeColors || !d->backgroundColor.isValid()) {
return Style::instance().themeColor("primary1");
2017-10-05 14:11:41 +00:00
} else {
return d->backgroundColor;
}
}
}