Add AppBar files
This commit is contained in:
parent
83b5b10bbe
commit
b3b0f18be9
|
@ -1,2 +1,139 @@
|
||||||
#include "qtmaterialappbar.h"
|
#include "qtmaterialappbar.h"
|
||||||
#include "qtmaterialappbar_p.h"
|
#include "qtmaterialappbar_p.h"
|
||||||
|
#include <QtWidgets/QGraphicsDropShadowEffect>
|
||||||
|
#include <QtWidgets/QHBoxLayout>
|
||||||
|
#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_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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,40 @@
|
||||||
#ifndef QTMATERIALAPPBAR_H
|
#ifndef QTMATERIALAPPBAR_H
|
||||||
#define QTMATERIALAPPBAR_H
|
#define QTMATERIALAPPBAR_H
|
||||||
|
|
||||||
|
#include <QtWidgets/QWidget>
|
||||||
|
|
||||||
|
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<QtMaterialAppBarPrivate> d_ptr;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Q_DISABLE_COPY(QtMaterialAppBar)
|
||||||
|
Q_DECLARE_PRIVATE(QtMaterialAppBar)
|
||||||
|
};
|
||||||
|
|
||||||
#endif // QTMATERIALAPPBAR_H
|
#endif // QTMATERIALAPPBAR_H
|
||||||
|
|
|
@ -1,4 +1,26 @@
|
||||||
#ifndef QTMATERIALAPPBAR_P_H
|
#ifndef QTMATERIALAPPBAR_P_H
|
||||||
#define QTMATERIALAPPBAR_P_H
|
#define QTMATERIALAPPBAR_P_H
|
||||||
|
|
||||||
|
#include <QtGlobal>
|
||||||
|
#include <QColor>
|
||||||
|
|
||||||
|
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
|
#endif // QTMATERIALAPPBAR_P_H
|
||||||
|
|
Loading…
Reference in New Issue