The base classes moved to md namespace.
This commit is contained in:
parent
c71884d83b
commit
49778ebc24
|
|
@ -12,27 +12,29 @@
|
||||||
#include "lib/qtmaterialstyle.h"
|
#include "lib/qtmaterialstyle.h"
|
||||||
#include "lib/qtmaterialcheckable_internal.h"
|
#include "lib/qtmaterialcheckable_internal.h"
|
||||||
|
|
||||||
|
namespace md
|
||||||
|
{
|
||||||
/*!
|
/*!
|
||||||
* \class QtMaterialCheckablePrivate
|
* \class QtMaterialCheckablePrivate
|
||||||
* \internal
|
* \internal
|
||||||
*/
|
*/
|
||||||
|
|
||||||
QtMaterialCheckablePrivate::QtMaterialCheckablePrivate(QtMaterialCheckable *q)
|
CheckablePrivate::CheckablePrivate(Checkable *q)
|
||||||
: q_ptr(q)
|
: q_ptr(q)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QtMaterialCheckablePrivate::~QtMaterialCheckablePrivate()
|
CheckablePrivate::~CheckablePrivate()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialCheckablePrivate::init()
|
void CheckablePrivate::init()
|
||||||
{
|
{
|
||||||
Q_Q(QtMaterialCheckable);
|
Q_Q(Checkable);
|
||||||
|
|
||||||
rippleOverlay = new QtMaterialRippleOverlay;
|
rippleOverlay = new RippleOverlay;
|
||||||
checkedIcon = new QtMaterialCheckableIcon(QIcon(":/icons/icons/toggle/svg/production/ic_check_box_24px.svg"), q);
|
checkedIcon = new CheckableIcon(QIcon(":/icons/icons/toggle/svg/production/ic_check_box_24px.svg"), q);
|
||||||
uncheckedIcon = new QtMaterialCheckableIcon(QIcon(":/icons/icons/toggle/svg/production/ic_check_box_outline_blank_24px.svg"), q);
|
uncheckedIcon = new CheckableIcon(QIcon(":/icons/icons/toggle/svg/production/ic_check_box_outline_blank_24px.svg"), q);
|
||||||
stateMachine = new QStateMachine(q);
|
stateMachine = new QStateMachine(q);
|
||||||
uncheckedState = new QState;
|
uncheckedState = new QState;
|
||||||
checkedState = new QState;
|
checkedState = new QState;
|
||||||
|
|
@ -40,14 +42,14 @@ void QtMaterialCheckablePrivate::init()
|
||||||
disabledCheckedState = new QState;
|
disabledCheckedState = new QState;
|
||||||
uncheckedTransition = new QSignalTransition(q, SIGNAL(toggled(bool)));
|
uncheckedTransition = new QSignalTransition(q, SIGNAL(toggled(bool)));
|
||||||
checkedTransition = new QSignalTransition(q, SIGNAL(toggled(bool)));
|
checkedTransition = new QSignalTransition(q, SIGNAL(toggled(bool)));
|
||||||
labelPosition = QtMaterialCheckable::LabelPositionRight;
|
labelPosition = Checkable::LabelPositionRight;
|
||||||
useThemeColors = true;
|
useThemeColors = true;
|
||||||
|
|
||||||
rippleOverlay->setParent(q->parentWidget());
|
rippleOverlay->setParent(q->parentWidget());
|
||||||
rippleOverlay->installEventFilter(q);
|
rippleOverlay->installEventFilter(q);
|
||||||
|
|
||||||
q->setCheckable(true);
|
q->setCheckable(true);
|
||||||
q->setStyle(&QtMaterialStyle::instance());
|
q->setStyle(&Style::instance());
|
||||||
q->setFont(QFont("Roboto", 11, QFont::Normal));
|
q->setFont(QFont("Roboto", 11, QFont::Normal));
|
||||||
|
|
||||||
stateMachine->addState(uncheckedState);
|
stateMachine->addState(uncheckedState);
|
||||||
|
|
@ -125,35 +127,35 @@ void QtMaterialCheckablePrivate::init()
|
||||||
* \class QtMaterialCheckable
|
* \class QtMaterialCheckable
|
||||||
*/
|
*/
|
||||||
|
|
||||||
QtMaterialCheckable::QtMaterialCheckable(QWidget *parent)
|
Checkable::Checkable(QWidget *parent)
|
||||||
: QAbstractButton(parent),
|
: QAbstractButton(parent),
|
||||||
d_ptr(new QtMaterialCheckablePrivate(this))
|
d_ptr(new CheckablePrivate(this))
|
||||||
{
|
{
|
||||||
d_func()->init();
|
d_func()->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
QtMaterialCheckable::~QtMaterialCheckable()
|
Checkable::~Checkable()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialCheckable::setLabelPosition(LabelPosition placement)
|
void Checkable::setLabelPosition(LabelPosition placement)
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialCheckable);
|
Q_D(Checkable);
|
||||||
|
|
||||||
d->labelPosition = placement;
|
d->labelPosition = placement;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
QtMaterialCheckable::LabelPosition QtMaterialCheckable::labelPosition() const
|
Checkable::LabelPosition Checkable::labelPosition() const
|
||||||
{
|
{
|
||||||
Q_D(const QtMaterialCheckable);
|
Q_D(const Checkable);
|
||||||
|
|
||||||
return d->labelPosition;
|
return d->labelPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialCheckable::setUseThemeColors(bool value)
|
void Checkable::setUseThemeColors(bool value)
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialCheckable);
|
Q_D(Checkable);
|
||||||
|
|
||||||
if (d->useThemeColors == value) {
|
if (d->useThemeColors == value) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -163,16 +165,16 @@ void QtMaterialCheckable::setUseThemeColors(bool value)
|
||||||
setupProperties();
|
setupProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QtMaterialCheckable::useThemeColors() const
|
bool Checkable::useThemeColors() const
|
||||||
{
|
{
|
||||||
Q_D(const QtMaterialCheckable);
|
Q_D(const Checkable);
|
||||||
|
|
||||||
return d->useThemeColors;
|
return d->useThemeColors;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialCheckable::setCheckedColor(const QColor &color)
|
void Checkable::setCheckedColor(const QColor &color)
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialCheckable);
|
Q_D(Checkable);
|
||||||
|
|
||||||
d->checkedColor = color;
|
d->checkedColor = color;
|
||||||
|
|
||||||
|
|
@ -180,20 +182,20 @@ void QtMaterialCheckable::setCheckedColor(const QColor &color)
|
||||||
setupProperties();
|
setupProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor QtMaterialCheckable::checkedColor() const
|
QColor Checkable::checkedColor() const
|
||||||
{
|
{
|
||||||
Q_D(const QtMaterialCheckable);
|
Q_D(const Checkable);
|
||||||
|
|
||||||
if (d->useThemeColors || !d->checkedColor.isValid()) {
|
if (d->useThemeColors || !d->checkedColor.isValid()) {
|
||||||
return QtMaterialStyle::instance().themeColor("primary1");
|
return Style::instance().themeColor("primary1");
|
||||||
} else {
|
} else {
|
||||||
return d->checkedColor;
|
return d->checkedColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialCheckable::setUncheckedColor(const QColor &color)
|
void Checkable::setUncheckedColor(const QColor &color)
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialCheckable);
|
Q_D(Checkable);
|
||||||
|
|
||||||
d->uncheckedColor = color;
|
d->uncheckedColor = color;
|
||||||
|
|
||||||
|
|
@ -201,20 +203,20 @@ void QtMaterialCheckable::setUncheckedColor(const QColor &color)
|
||||||
setupProperties();
|
setupProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor QtMaterialCheckable::uncheckedColor() const
|
QColor Checkable::uncheckedColor() const
|
||||||
{
|
{
|
||||||
Q_D(const QtMaterialCheckable);
|
Q_D(const Checkable);
|
||||||
|
|
||||||
if (d->useThemeColors || !d->uncheckedColor.isValid()) {
|
if (d->useThemeColors || !d->uncheckedColor.isValid()) {
|
||||||
return QtMaterialStyle::instance().themeColor("text");
|
return Style::instance().themeColor("text");
|
||||||
} else {
|
} else {
|
||||||
return d->uncheckedColor;
|
return d->uncheckedColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialCheckable::setTextColor(const QColor &color)
|
void Checkable::setTextColor(const QColor &color)
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialCheckable);
|
Q_D(Checkable);
|
||||||
|
|
||||||
d->textColor = color;
|
d->textColor = color;
|
||||||
|
|
||||||
|
|
@ -222,20 +224,20 @@ void QtMaterialCheckable::setTextColor(const QColor &color)
|
||||||
setupProperties();
|
setupProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor QtMaterialCheckable::textColor() const
|
QColor Checkable::textColor() const
|
||||||
{
|
{
|
||||||
Q_D(const QtMaterialCheckable);
|
Q_D(const Checkable);
|
||||||
|
|
||||||
if (d->useThemeColors || !d->textColor.isValid()) {
|
if (d->useThemeColors || !d->textColor.isValid()) {
|
||||||
return QtMaterialStyle::instance().themeColor("text");
|
return Style::instance().themeColor("text");
|
||||||
} else {
|
} else {
|
||||||
return d->textColor;
|
return d->textColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialCheckable::setDisabledColor(const QColor &color)
|
void Checkable::setDisabledColor(const QColor &color)
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialCheckable);
|
Q_D(Checkable);
|
||||||
|
|
||||||
d->disabledColor = color;
|
d->disabledColor = color;
|
||||||
|
|
||||||
|
|
@ -243,43 +245,43 @@ void QtMaterialCheckable::setDisabledColor(const QColor &color)
|
||||||
setupProperties();
|
setupProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor QtMaterialCheckable::disabledColor() const
|
QColor Checkable::disabledColor() const
|
||||||
{
|
{
|
||||||
Q_D(const QtMaterialCheckable);
|
Q_D(const Checkable);
|
||||||
|
|
||||||
if (d->useThemeColors || !d->disabledColor.isValid()) {
|
if (d->useThemeColors || !d->disabledColor.isValid()) {
|
||||||
return QtMaterialStyle::instance().themeColor("accent3");
|
return Style::instance().themeColor("accent3");
|
||||||
} else {
|
} else {
|
||||||
return d->disabledColor;
|
return d->disabledColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialCheckable::setCheckedIcon(const QIcon &icon)
|
void Checkable::setCheckedIcon(const QIcon &icon)
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialCheckable);
|
Q_D(Checkable);
|
||||||
|
|
||||||
d->checkedIcon->setIcon(icon);
|
d->checkedIcon->setIcon(icon);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon QtMaterialCheckable::checkedIcon() const
|
QIcon Checkable::checkedIcon() const
|
||||||
{
|
{
|
||||||
Q_D(const QtMaterialCheckable);
|
Q_D(const Checkable);
|
||||||
|
|
||||||
return d->checkedIcon->icon();
|
return d->checkedIcon->icon();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialCheckable::setUncheckedIcon(const QIcon &icon)
|
void Checkable::setUncheckedIcon(const QIcon &icon)
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialCheckable);
|
Q_D(Checkable);
|
||||||
|
|
||||||
d->uncheckedIcon->setIcon(icon);
|
d->uncheckedIcon->setIcon(icon);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon QtMaterialCheckable::uncheckedIcon() const
|
QIcon Checkable::uncheckedIcon() const
|
||||||
{
|
{
|
||||||
Q_D(const QtMaterialCheckable);
|
Q_D(const Checkable);
|
||||||
|
|
||||||
return d->uncheckedIcon->icon();
|
return d->uncheckedIcon->icon();
|
||||||
}
|
}
|
||||||
|
|
@ -287,7 +289,7 @@ QIcon QtMaterialCheckable::uncheckedIcon() const
|
||||||
/*!
|
/*!
|
||||||
* \reimp
|
* \reimp
|
||||||
*/
|
*/
|
||||||
QSize QtMaterialCheckable::sizeHint() const
|
QSize Checkable::sizeHint() const
|
||||||
{
|
{
|
||||||
if (text().isEmpty()) {
|
if (text().isEmpty()) {
|
||||||
return QSize(40, 40);
|
return QSize(40, 40);
|
||||||
|
|
@ -295,7 +297,7 @@ QSize QtMaterialCheckable::sizeHint() const
|
||||||
return QSize(fontMetrics().size(Qt::TextShowMnemonic, text()).width()+52, 40);
|
return QSize(fontMetrics().size(Qt::TextShowMnemonic, text()).width()+52, 40);
|
||||||
}
|
}
|
||||||
|
|
||||||
QtMaterialCheckable::QtMaterialCheckable(QtMaterialCheckablePrivate &d, QWidget *parent)
|
Checkable::Checkable(CheckablePrivate &d, QWidget *parent)
|
||||||
: QAbstractButton(parent),
|
: QAbstractButton(parent),
|
||||||
d_ptr(&d)
|
d_ptr(&d)
|
||||||
{
|
{
|
||||||
|
|
@ -305,9 +307,9 @@ QtMaterialCheckable::QtMaterialCheckable(QtMaterialCheckablePrivate &d, QWidget
|
||||||
/*!
|
/*!
|
||||||
* \reimp
|
* \reimp
|
||||||
*/
|
*/
|
||||||
bool QtMaterialCheckable::event(QEvent *event)
|
bool Checkable::event(QEvent *event)
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialCheckable);
|
Q_D(Checkable);
|
||||||
|
|
||||||
switch (event->type())
|
switch (event->type())
|
||||||
{
|
{
|
||||||
|
|
@ -332,11 +334,11 @@ bool QtMaterialCheckable::event(QEvent *event)
|
||||||
/*!
|
/*!
|
||||||
* \reimp
|
* \reimp
|
||||||
*/
|
*/
|
||||||
bool QtMaterialCheckable::eventFilter(QObject *obj, QEvent *event)
|
bool Checkable::eventFilter(QObject *obj, QEvent *event)
|
||||||
{
|
{
|
||||||
if (QEvent::Resize == event->type())
|
if (QEvent::Resize == event->type())
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialCheckable);
|
Q_D(Checkable);
|
||||||
|
|
||||||
d->rippleOverlay->setGeometry(geometry().adjusted(-8, -8, 8, 8));
|
d->rippleOverlay->setGeometry(geometry().adjusted(-8, -8, 8, 8));
|
||||||
}
|
}
|
||||||
|
|
@ -346,21 +348,21 @@ bool QtMaterialCheckable::eventFilter(QObject *obj, QEvent *event)
|
||||||
/*!
|
/*!
|
||||||
* \reimp
|
* \reimp
|
||||||
*/
|
*/
|
||||||
void QtMaterialCheckable::mousePressEvent(QMouseEvent *event)
|
void Checkable::mousePressEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event)
|
Q_UNUSED(event)
|
||||||
|
|
||||||
Q_D(QtMaterialCheckable);
|
Q_D(Checkable);
|
||||||
|
|
||||||
if (!isEnabled()) {
|
if (!isEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QtMaterialRipple *ripple;
|
Ripple *ripple;
|
||||||
if (QtMaterialCheckable::LabelPositionLeft == d->labelPosition) {
|
if (Checkable::LabelPositionLeft == d->labelPosition) {
|
||||||
ripple = new QtMaterialRipple(QPoint(width()-14, 28));
|
ripple = new Ripple(QPoint(width()-14, 28));
|
||||||
} else {
|
} else {
|
||||||
ripple = new QtMaterialRipple(QPoint(28, 28));
|
ripple = new Ripple(QPoint(28, 28));
|
||||||
}
|
}
|
||||||
ripple->setRadiusEndValue(22);
|
ripple->setRadiusEndValue(22);
|
||||||
ripple->setColor(isChecked() ? checkedColor() : uncheckedColor());
|
ripple->setColor(isChecked() ? checkedColor() : uncheckedColor());
|
||||||
|
|
@ -375,11 +377,11 @@ void QtMaterialCheckable::mousePressEvent(QMouseEvent *event)
|
||||||
/*!
|
/*!
|
||||||
* \reimp
|
* \reimp
|
||||||
*/
|
*/
|
||||||
void QtMaterialCheckable::paintEvent(QPaintEvent *event)
|
void Checkable::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event)
|
Q_UNUSED(event)
|
||||||
|
|
||||||
Q_D(QtMaterialCheckable);
|
Q_D(Checkable);
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
|
|
||||||
|
|
@ -387,16 +389,16 @@ void QtMaterialCheckable::paintEvent(QPaintEvent *event)
|
||||||
pen.setColor(isEnabled() ? textColor() : disabledColor());
|
pen.setColor(isEnabled() ? textColor() : disabledColor());
|
||||||
painter.setPen(pen);
|
painter.setPen(pen);
|
||||||
|
|
||||||
if (QtMaterialCheckable::LabelPositionLeft == d->labelPosition) {
|
if (Checkable::LabelPositionLeft == d->labelPosition) {
|
||||||
painter.drawText(4, 25, text());
|
painter.drawText(4, 25, text());
|
||||||
} else {
|
} else {
|
||||||
painter.drawText(48, 25, text());
|
painter.drawText(48, 25, text());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialCheckable::setupProperties()
|
void Checkable::setupProperties()
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialCheckable);
|
Q_D(Checkable);
|
||||||
|
|
||||||
d->checkedState->assignProperty(d->checkedIcon, "color", checkedColor());
|
d->checkedState->assignProperty(d->checkedIcon, "color", checkedColor());
|
||||||
d->checkedState->assignProperty(d->uncheckedIcon, "color", checkedColor());
|
d->checkedState->assignProperty(d->uncheckedIcon, "color", checkedColor());
|
||||||
|
|
@ -417,3 +419,5 @@ void QtMaterialCheckable::setupProperties()
|
||||||
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,11 @@
|
||||||
#define QTMATERIALCHECKABLE_H
|
#define QTMATERIALCHECKABLE_H
|
||||||
|
|
||||||
#include <QtWidgets/QAbstractButton>
|
#include <QtWidgets/QAbstractButton>
|
||||||
|
namespace md
|
||||||
|
{
|
||||||
|
class CheckablePrivate;
|
||||||
|
|
||||||
class QtMaterialCheckablePrivate;
|
class Checkable : public QAbstractButton
|
||||||
|
|
||||||
class QtMaterialCheckable : public QAbstractButton
|
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
|
@ -15,8 +16,8 @@ public:
|
||||||
LabelPositionRight,
|
LabelPositionRight,
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit QtMaterialCheckable(QWidget *parent = 0);
|
explicit Checkable(QWidget *parent = 0);
|
||||||
~QtMaterialCheckable();
|
~Checkable();
|
||||||
|
|
||||||
void setLabelPosition(LabelPosition placement);
|
void setLabelPosition(LabelPosition placement);
|
||||||
LabelPosition labelPosition() const;
|
LabelPosition labelPosition() const;
|
||||||
|
|
@ -45,7 +46,7 @@ public:
|
||||||
QSize sizeHint() const Q_DECL_OVERRIDE;
|
QSize sizeHint() const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QtMaterialCheckable(QtMaterialCheckablePrivate &d, QWidget *parent = 0);
|
Checkable(CheckablePrivate &d, QWidget *parent = 0);
|
||||||
|
|
||||||
bool event(QEvent *event) Q_DECL_OVERRIDE;
|
bool event(QEvent *event) Q_DECL_OVERRIDE;
|
||||||
bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE;
|
bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE;
|
||||||
|
|
@ -54,11 +55,12 @@ protected:
|
||||||
|
|
||||||
virtual void setupProperties();
|
virtual void setupProperties();
|
||||||
|
|
||||||
const QScopedPointer<QtMaterialCheckablePrivate> d_ptr;
|
const QScopedPointer<CheckablePrivate> d_ptr;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(QtMaterialCheckable)
|
Q_DISABLE_COPY(Checkable)
|
||||||
Q_DECLARE_PRIVATE(QtMaterialCheckable)
|
Q_DECLARE_PRIVATE(Checkable)
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#endif // QTMATERIALCHECKABLE_H
|
#endif // QTMATERIALCHECKABLE_H
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,14 @@
|
||||||
#include <QTransform>
|
#include <QTransform>
|
||||||
#include "lib/qtmaterialcheckable.h"
|
#include "lib/qtmaterialcheckable.h"
|
||||||
|
|
||||||
|
namespace md
|
||||||
|
{
|
||||||
/*!
|
/*!
|
||||||
* \class QtMaterialCheckableIcon
|
* \class QtMaterialCheckableIcon
|
||||||
* \internal
|
* \internal
|
||||||
*/
|
*/
|
||||||
|
|
||||||
QtMaterialCheckableIcon::QtMaterialCheckableIcon(const QIcon &icon, QtMaterialCheckable *parent)
|
CheckableIcon::CheckableIcon(const QIcon &icon, Checkable *parent)
|
||||||
: QWidget(parent),
|
: QWidget(parent),
|
||||||
m_checkable(parent),
|
m_checkable(parent),
|
||||||
m_color(Qt::black),
|
m_color(Qt::black),
|
||||||
|
|
@ -22,16 +24,16 @@ QtMaterialCheckableIcon::QtMaterialCheckableIcon(const QIcon &icon, QtMaterialCh
|
||||||
setAttribute(Qt::WA_TransparentForMouseEvents);
|
setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
QtMaterialCheckableIcon::~QtMaterialCheckableIcon()
|
CheckableIcon::~CheckableIcon()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize QtMaterialCheckableIcon::sizeHint() const
|
QSize CheckableIcon::sizeHint() const
|
||||||
{
|
{
|
||||||
return QSize(m_iconSize, m_iconSize);
|
return QSize(m_iconSize, m_iconSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialCheckableIcon::paintEvent(QPaintEvent *event)
|
void CheckableIcon::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event)
|
Q_UNUSED(event)
|
||||||
|
|
||||||
|
|
@ -47,7 +49,7 @@ void QtMaterialCheckableIcon::paintEvent(QPaintEvent *event)
|
||||||
const qreal z = m_iconSize/24;
|
const qreal z = m_iconSize/24;
|
||||||
|
|
||||||
QTransform t;
|
QTransform t;
|
||||||
if (QtMaterialCheckable::LabelPositionLeft == m_checkable->labelPosition()) {
|
if (Checkable::LabelPositionLeft == m_checkable->labelPosition()) {
|
||||||
t.translate(p+width()-42, p);
|
t.translate(p+width()-42, p);
|
||||||
} else {
|
} else {
|
||||||
t.translate(p, p);
|
t.translate(p, p);
|
||||||
|
|
@ -61,3 +63,5 @@ void QtMaterialCheckableIcon::paintEvent(QPaintEvent *event)
|
||||||
painter.drawPixmap(0, 0, pixmap);
|
painter.drawPixmap(0, 0, pixmap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,11 @@
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
|
||||||
class QtMaterialCheckable;
|
namespace md
|
||||||
|
{
|
||||||
|
class Checkable;
|
||||||
|
|
||||||
class QtMaterialCheckableIcon : public QWidget
|
class CheckableIcon : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
|
@ -16,8 +18,8 @@ class QtMaterialCheckableIcon : public QWidget
|
||||||
Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity)
|
Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QtMaterialCheckableIcon(const QIcon &icon, QtMaterialCheckable *parent);
|
CheckableIcon(const QIcon &icon, Checkable *parent);
|
||||||
~QtMaterialCheckableIcon();
|
~CheckableIcon();
|
||||||
|
|
||||||
QSize sizeHint() const Q_DECL_OVERRIDE;
|
QSize sizeHint() const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
|
@ -37,57 +39,58 @@ protected:
|
||||||
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(QtMaterialCheckableIcon)
|
Q_DISABLE_COPY(CheckableIcon)
|
||||||
|
|
||||||
QtMaterialCheckable *const m_checkable;
|
Checkable *const m_checkable;
|
||||||
QColor m_color;
|
QColor m_color;
|
||||||
QIcon m_icon;
|
QIcon m_icon;
|
||||||
qreal m_iconSize;
|
qreal m_iconSize;
|
||||||
qreal m_opacity;
|
qreal m_opacity;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void QtMaterialCheckableIcon::setIcon(const QIcon &icon)
|
inline void CheckableIcon::setIcon(const QIcon &icon)
|
||||||
{
|
{
|
||||||
m_icon = icon;
|
m_icon = icon;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QIcon QtMaterialCheckableIcon::icon() const
|
inline QIcon CheckableIcon::icon() const
|
||||||
{
|
{
|
||||||
return m_icon;
|
return m_icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void QtMaterialCheckableIcon::setColor(const QColor &color)
|
inline void CheckableIcon::setColor(const QColor &color)
|
||||||
{
|
{
|
||||||
m_color = color;
|
m_color = color;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QColor QtMaterialCheckableIcon::color() const
|
inline QColor CheckableIcon::color() const
|
||||||
{
|
{
|
||||||
return m_color;
|
return m_color;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void QtMaterialCheckableIcon::setIconSize(qreal size)
|
inline void CheckableIcon::setIconSize(qreal size)
|
||||||
{
|
{
|
||||||
m_iconSize = size;
|
m_iconSize = size;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline qreal QtMaterialCheckableIcon::iconSize() const
|
inline qreal CheckableIcon::iconSize() const
|
||||||
{
|
{
|
||||||
return m_iconSize;
|
return m_iconSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void QtMaterialCheckableIcon::setOpacity(qreal opacity)
|
inline void CheckableIcon::setOpacity(qreal opacity)
|
||||||
{
|
{
|
||||||
m_opacity = opacity;
|
m_opacity = opacity;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline qreal QtMaterialCheckableIcon::opacity() const
|
inline qreal CheckableIcon::opacity() const
|
||||||
{
|
{
|
||||||
return m_opacity;
|
return m_opacity;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif // QTMATERIALCHECKABLE_INTERNAL_H
|
#endif // QTMATERIALCHECKABLE_INTERNAL_H
|
||||||
|
|
|
||||||
|
|
@ -4,27 +4,29 @@
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
#include "lib/qtmaterialcheckable.h"
|
#include "lib/qtmaterialcheckable.h"
|
||||||
|
|
||||||
|
namespace md
|
||||||
|
{
|
||||||
class QStateMachine;
|
class QStateMachine;
|
||||||
class QState;
|
class QState;
|
||||||
class QSignalTransition;
|
class QSignalTransition;
|
||||||
class QtMaterialRippleOverlay;
|
class RippleOverlay;
|
||||||
class QtMaterialCheckableIcon;
|
class CheckableIcon;
|
||||||
|
|
||||||
class QtMaterialCheckablePrivate
|
class CheckablePrivate
|
||||||
{
|
{
|
||||||
Q_DISABLE_COPY(QtMaterialCheckablePrivate)
|
Q_DISABLE_COPY(CheckablePrivate)
|
||||||
Q_DECLARE_PUBLIC(QtMaterialCheckable)
|
Q_DECLARE_PUBLIC(Checkable)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QtMaterialCheckablePrivate(QtMaterialCheckable *q);
|
CheckablePrivate(Checkable *q);
|
||||||
virtual ~QtMaterialCheckablePrivate();
|
virtual ~CheckablePrivate();
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
QtMaterialCheckable *const q_ptr;
|
Checkable *const q_ptr;
|
||||||
QtMaterialRippleOverlay *rippleOverlay;
|
RippleOverlay *rippleOverlay;
|
||||||
QtMaterialCheckableIcon *checkedIcon;
|
CheckableIcon *checkedIcon;
|
||||||
QtMaterialCheckableIcon *uncheckedIcon;
|
CheckableIcon *uncheckedIcon;
|
||||||
QStateMachine *stateMachine;
|
QStateMachine *stateMachine;
|
||||||
QState *uncheckedState;
|
QState *uncheckedState;
|
||||||
QState *checkedState;
|
QState *checkedState;
|
||||||
|
|
@ -32,12 +34,13 @@ public:
|
||||||
QState *disabledCheckedState;
|
QState *disabledCheckedState;
|
||||||
QSignalTransition *uncheckedTransition;
|
QSignalTransition *uncheckedTransition;
|
||||||
QSignalTransition *checkedTransition;
|
QSignalTransition *checkedTransition;
|
||||||
QtMaterialCheckable::LabelPosition labelPosition;
|
Checkable::LabelPosition labelPosition;
|
||||||
QColor checkedColor;
|
QColor checkedColor;
|
||||||
QColor uncheckedColor;
|
QColor uncheckedColor;
|
||||||
QColor textColor;
|
QColor textColor;
|
||||||
QColor disabledColor;
|
QColor disabledColor;
|
||||||
bool useThemeColors;
|
bool useThemeColors;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#endif // QTMATERIALCHECKABLE_P_H
|
#endif // QTMATERIALCHECKABLE_P_H
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,14 @@
|
||||||
#include "lib/qtmaterialoverlaywidget.h"
|
#include "lib/qtmaterialoverlaywidget.h"
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
|
|
||||||
|
namespace md
|
||||||
|
{
|
||||||
/*!
|
/*!
|
||||||
* \class QtMaterialOverlayWidget
|
* \class QtMaterialOverlayWidget
|
||||||
* \internal
|
* \internal
|
||||||
*/
|
*/
|
||||||
|
|
||||||
QtMaterialOverlayWidget::QtMaterialOverlayWidget(QWidget *parent)
|
OverlayWidget::OverlayWidget(QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
{
|
{
|
||||||
if (parent) {
|
if (parent) {
|
||||||
|
|
@ -14,14 +16,14 @@ QtMaterialOverlayWidget::QtMaterialOverlayWidget(QWidget *parent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QtMaterialOverlayWidget::~QtMaterialOverlayWidget()
|
OverlayWidget::~OverlayWidget()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \reimp
|
* \reimp
|
||||||
*/
|
*/
|
||||||
bool QtMaterialOverlayWidget::event(QEvent *event)
|
bool OverlayWidget::event(QEvent *event)
|
||||||
{
|
{
|
||||||
if (!parent()) {
|
if (!parent()) {
|
||||||
return QWidget::event(event);
|
return QWidget::event(event);
|
||||||
|
|
@ -48,7 +50,7 @@ bool QtMaterialOverlayWidget::event(QEvent *event)
|
||||||
/*!
|
/*!
|
||||||
* \reimp
|
* \reimp
|
||||||
*/
|
*/
|
||||||
bool QtMaterialOverlayWidget::eventFilter(QObject *obj, QEvent *event)
|
bool OverlayWidget::eventFilter(QObject *obj, QEvent *event)
|
||||||
{
|
{
|
||||||
switch (event->type())
|
switch (event->type())
|
||||||
{
|
{
|
||||||
|
|
@ -62,7 +64,7 @@ bool QtMaterialOverlayWidget::eventFilter(QObject *obj, QEvent *event)
|
||||||
return QWidget::eventFilter(obj, event);
|
return QWidget::eventFilter(obj, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
QRect QtMaterialOverlayWidget::overlayGeometry() const
|
QRect OverlayWidget::overlayGeometry() const
|
||||||
{
|
{
|
||||||
QWidget *widget = parentWidget();
|
QWidget *widget = parentWidget();
|
||||||
if (!widget) {
|
if (!widget) {
|
||||||
|
|
@ -70,3 +72,5 @@ QRect QtMaterialOverlayWidget::overlayGeometry() const
|
||||||
}
|
}
|
||||||
return widget->rect();
|
return widget->rect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,15 @@
|
||||||
|
|
||||||
#include <QtWidgets/QWidget>
|
#include <QtWidgets/QWidget>
|
||||||
|
|
||||||
class QtMaterialOverlayWidget : public QWidget
|
namespace md
|
||||||
|
{
|
||||||
|
class OverlayWidget : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit QtMaterialOverlayWidget(QWidget *parent = 0);
|
explicit OverlayWidget(QWidget *parent = 0);
|
||||||
~QtMaterialOverlayWidget();
|
~OverlayWidget();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool event(QEvent *event) Q_DECL_OVERRIDE;
|
bool event(QEvent *event) Q_DECL_OVERRIDE;
|
||||||
|
|
@ -18,7 +20,8 @@ protected:
|
||||||
virtual QRect overlayGeometry() const;
|
virtual QRect overlayGeometry() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(QtMaterialOverlayWidget)
|
Q_DISABLE_COPY(OverlayWidget)
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#endif // QTMATERIALOVERLAYWIDGET_H
|
#endif // QTMATERIALOVERLAYWIDGET_H
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,14 @@
|
||||||
#include "qtmaterialripple.h"
|
#include "qtmaterialripple.h"
|
||||||
#include "lib/qtmaterialrippleoverlay.h"
|
#include "lib/qtmaterialrippleoverlay.h"
|
||||||
|
|
||||||
|
namespace md
|
||||||
|
{
|
||||||
/*!
|
/*!
|
||||||
* \class QtMaterialRipple
|
* \class QtMaterialRipple
|
||||||
* \internal
|
* \internal
|
||||||
*/
|
*/
|
||||||
|
|
||||||
QtMaterialRipple::QtMaterialRipple(const QPoint ¢er, QObject *parent)
|
Ripple::Ripple(const QPoint ¢er, QObject *parent)
|
||||||
: QParallelAnimationGroup(parent),
|
: QParallelAnimationGroup(parent),
|
||||||
m_overlay(0),
|
m_overlay(0),
|
||||||
m_radiusAnimation(animate("radius")),
|
m_radiusAnimation(animate("radius")),
|
||||||
|
|
@ -18,8 +20,8 @@ QtMaterialRipple::QtMaterialRipple(const QPoint ¢er, QObject *parent)
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
QtMaterialRipple::QtMaterialRipple(const QPoint ¢er,
|
Ripple::Ripple(const QPoint ¢er,
|
||||||
QtMaterialRippleOverlay *overlay,
|
RippleOverlay *overlay,
|
||||||
QObject *parent)
|
QObject *parent)
|
||||||
: QParallelAnimationGroup(parent),
|
: QParallelAnimationGroup(parent),
|
||||||
m_overlay(overlay),
|
m_overlay(overlay),
|
||||||
|
|
@ -32,11 +34,11 @@ QtMaterialRipple::QtMaterialRipple(const QPoint ¢er,
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
QtMaterialRipple::~QtMaterialRipple()
|
Ripple::~Ripple()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialRipple::setRadius(qreal radius)
|
void Ripple::setRadius(qreal radius)
|
||||||
{
|
{
|
||||||
Q_ASSERT(m_overlay);
|
Q_ASSERT(m_overlay);
|
||||||
|
|
||||||
|
|
@ -47,7 +49,7 @@ void QtMaterialRipple::setRadius(qreal radius)
|
||||||
m_overlay->update();
|
m_overlay->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialRipple::setOpacity(qreal opacity)
|
void Ripple::setOpacity(qreal opacity)
|
||||||
{
|
{
|
||||||
Q_ASSERT(m_overlay);
|
Q_ASSERT(m_overlay);
|
||||||
|
|
||||||
|
|
@ -58,7 +60,7 @@ void QtMaterialRipple::setOpacity(qreal opacity)
|
||||||
m_overlay->update();
|
m_overlay->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialRipple::setColor(const QColor &color)
|
void Ripple::setColor(const QColor &color)
|
||||||
{
|
{
|
||||||
if (m_brush.color() == color) {
|
if (m_brush.color() == color) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -70,7 +72,7 @@ void QtMaterialRipple::setColor(const QColor &color)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialRipple::setBrush(const QBrush &brush)
|
void Ripple::setBrush(const QBrush &brush)
|
||||||
{
|
{
|
||||||
m_brush = brush;
|
m_brush = brush;
|
||||||
|
|
||||||
|
|
@ -79,7 +81,7 @@ void QtMaterialRipple::setBrush(const QBrush &brush)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialRipple::destroy()
|
void Ripple::destroy()
|
||||||
{
|
{
|
||||||
Q_ASSERT(m_overlay);
|
Q_ASSERT(m_overlay);
|
||||||
|
|
||||||
|
|
@ -89,7 +91,7 @@ void QtMaterialRipple::destroy()
|
||||||
/*!
|
/*!
|
||||||
* \internal
|
* \internal
|
||||||
*/
|
*/
|
||||||
QPropertyAnimation *QtMaterialRipple::animate(const QByteArray &property,
|
QPropertyAnimation *Ripple::animate(const QByteArray &property,
|
||||||
const QEasingCurve &easing,
|
const QEasingCurve &easing,
|
||||||
int duration)
|
int duration)
|
||||||
{
|
{
|
||||||
|
|
@ -105,7 +107,7 @@ QPropertyAnimation *QtMaterialRipple::animate(const QByteArray &property,
|
||||||
/*!
|
/*!
|
||||||
* \internal
|
* \internal
|
||||||
*/
|
*/
|
||||||
void QtMaterialRipple::init()
|
void Ripple::init()
|
||||||
{
|
{
|
||||||
setOpacityStartValue(0.5);
|
setOpacityStartValue(0.5);
|
||||||
setOpacityEndValue(0);
|
setOpacityEndValue(0);
|
||||||
|
|
@ -117,3 +119,5 @@ void QtMaterialRipple::init()
|
||||||
|
|
||||||
connect(this, SIGNAL(finished()), this, SLOT(destroy()));
|
connect(this, SIGNAL(finished()), this, SLOT(destroy()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,11 @@
|
||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
#include <QBrush>
|
#include <QBrush>
|
||||||
|
|
||||||
class QtMaterialRippleOverlay;
|
namespace md
|
||||||
|
{
|
||||||
|
class RippleOverlay;
|
||||||
|
|
||||||
class QtMaterialRipple : public QParallelAnimationGroup
|
class Ripple : public QParallelAnimationGroup
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
|
@ -17,11 +19,11 @@ class QtMaterialRipple : public QParallelAnimationGroup
|
||||||
Q_PROPERTY(qreal opacity WRITE setOpacity READ opacity)
|
Q_PROPERTY(qreal opacity WRITE setOpacity READ opacity)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit QtMaterialRipple(const QPoint ¢er, QObject *parent = 0);
|
explicit Ripple(const QPoint ¢er, QObject *parent = 0);
|
||||||
QtMaterialRipple(const QPoint ¢er, QtMaterialRippleOverlay *overlay, QObject *parent = 0);
|
Ripple(const QPoint ¢er, RippleOverlay *overlay, QObject *parent = 0);
|
||||||
~QtMaterialRipple();
|
~Ripple();
|
||||||
|
|
||||||
inline void setOverlay(QtMaterialRippleOverlay *overlay);
|
inline void setOverlay(RippleOverlay *overlay);
|
||||||
|
|
||||||
void setRadius(qreal radius);
|
void setRadius(qreal radius);
|
||||||
inline qreal radius() const;
|
inline qreal radius() const;
|
||||||
|
|
@ -50,7 +52,7 @@ protected slots:
|
||||||
void destroy();
|
void destroy();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(QtMaterialRipple)
|
Q_DISABLE_COPY(Ripple)
|
||||||
|
|
||||||
QPropertyAnimation *animate(const QByteArray &property,
|
QPropertyAnimation *animate(const QByteArray &property,
|
||||||
const QEasingCurve &easing = QEasingCurve::OutQuad,
|
const QEasingCurve &easing = QEasingCurve::OutQuad,
|
||||||
|
|
@ -58,7 +60,7 @@ private:
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
QtMaterialRippleOverlay *m_overlay;
|
RippleOverlay *m_overlay;
|
||||||
QPropertyAnimation *const m_radiusAnimation;
|
QPropertyAnimation *const m_radiusAnimation;
|
||||||
QPropertyAnimation *const m_opacityAnimation;
|
QPropertyAnimation *const m_opacityAnimation;
|
||||||
qreal m_radius;
|
qreal m_radius;
|
||||||
|
|
@ -67,70 +69,71 @@ private:
|
||||||
QBrush m_brush;
|
QBrush m_brush;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void QtMaterialRipple::setOverlay(QtMaterialRippleOverlay *overlay)
|
inline void Ripple::setOverlay(RippleOverlay *overlay)
|
||||||
{
|
{
|
||||||
m_overlay = overlay;
|
m_overlay = overlay;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline qreal QtMaterialRipple::radius() const
|
inline qreal Ripple::radius() const
|
||||||
{
|
{
|
||||||
return m_radius;
|
return m_radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline qreal QtMaterialRipple::opacity() const
|
inline qreal Ripple::opacity() const
|
||||||
{
|
{
|
||||||
return m_opacity;
|
return m_opacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QColor QtMaterialRipple::color() const
|
inline QColor Ripple::color() const
|
||||||
{
|
{
|
||||||
return m_brush.color();
|
return m_brush.color();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QBrush QtMaterialRipple::brush() const
|
inline QBrush Ripple::brush() const
|
||||||
{
|
{
|
||||||
return m_brush;
|
return m_brush;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QPoint QtMaterialRipple::center() const
|
inline QPoint Ripple::center() const
|
||||||
{
|
{
|
||||||
return m_center;
|
return m_center;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QPropertyAnimation *QtMaterialRipple::radiusAnimation() const
|
inline QPropertyAnimation *Ripple::radiusAnimation() const
|
||||||
{
|
{
|
||||||
return m_radiusAnimation;
|
return m_radiusAnimation;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QPropertyAnimation *QtMaterialRipple::opacityAnimation() const
|
inline QPropertyAnimation *Ripple::opacityAnimation() const
|
||||||
{
|
{
|
||||||
return m_opacityAnimation;
|
return m_opacityAnimation;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void QtMaterialRipple::setOpacityStartValue(qreal value)
|
inline void Ripple::setOpacityStartValue(qreal value)
|
||||||
{
|
{
|
||||||
m_opacityAnimation->setStartValue(value);
|
m_opacityAnimation->setStartValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void QtMaterialRipple::setOpacityEndValue(qreal value)
|
inline void Ripple::setOpacityEndValue(qreal value)
|
||||||
{
|
{
|
||||||
m_opacityAnimation->setEndValue(value);
|
m_opacityAnimation->setEndValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void QtMaterialRipple::setRadiusStartValue(qreal value)
|
inline void Ripple::setRadiusStartValue(qreal value)
|
||||||
{
|
{
|
||||||
m_radiusAnimation->setStartValue(value);
|
m_radiusAnimation->setStartValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void QtMaterialRipple::setRadiusEndValue(qreal value)
|
inline void Ripple::setRadiusEndValue(qreal value)
|
||||||
{
|
{
|
||||||
m_radiusAnimation->setEndValue(value);
|
m_radiusAnimation->setEndValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void QtMaterialRipple::setDuration(int msecs)
|
inline void Ripple::setDuration(int msecs)
|
||||||
{
|
{
|
||||||
m_radiusAnimation->setDuration(msecs);
|
m_radiusAnimation->setDuration(msecs);
|
||||||
m_opacityAnimation->setDuration(msecs);
|
m_opacityAnimation->setDuration(msecs);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif // QTMATERIALRIPPLE_H
|
#endif // QTMATERIALRIPPLE_H
|
||||||
|
|
|
||||||
|
|
@ -2,24 +2,26 @@
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include "lib/qtmaterialripple.h"
|
#include "lib/qtmaterialripple.h"
|
||||||
|
|
||||||
|
namespace md
|
||||||
|
{
|
||||||
/*!
|
/*!
|
||||||
* \class QtMaterialRippleOverlay
|
* \class QtMaterialRippleOverlay
|
||||||
* \internal
|
* \internal
|
||||||
*/
|
*/
|
||||||
|
|
||||||
QtMaterialRippleOverlay::QtMaterialRippleOverlay(QWidget *parent)
|
RippleOverlay::RippleOverlay(QWidget *parent)
|
||||||
: QtMaterialOverlayWidget(parent),
|
: OverlayWidget(parent),
|
||||||
m_useClip(false)
|
m_useClip(false)
|
||||||
{
|
{
|
||||||
setAttribute(Qt::WA_TransparentForMouseEvents);
|
setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||||
setAttribute(Qt::WA_NoSystemBackground);
|
setAttribute(Qt::WA_NoSystemBackground);
|
||||||
}
|
}
|
||||||
|
|
||||||
QtMaterialRippleOverlay::~QtMaterialRippleOverlay()
|
RippleOverlay::~RippleOverlay()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialRippleOverlay::addRipple(QtMaterialRipple *ripple)
|
void RippleOverlay::addRipple(Ripple *ripple)
|
||||||
{
|
{
|
||||||
ripple->setOverlay(this);
|
ripple->setOverlay(this);
|
||||||
m_ripples.push_back(ripple);
|
m_ripples.push_back(ripple);
|
||||||
|
|
@ -29,14 +31,14 @@ void QtMaterialRippleOverlay::addRipple(QtMaterialRipple *ripple)
|
||||||
connect(this, SIGNAL(destroyed(QObject*)), ripple, SLOT(deleteLater()));
|
connect(this, SIGNAL(destroyed(QObject*)), ripple, SLOT(deleteLater()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialRippleOverlay::addRipple(const QPoint &position, qreal radius)
|
void RippleOverlay::addRipple(const QPoint &position, qreal radius)
|
||||||
{
|
{
|
||||||
QtMaterialRipple *ripple = new QtMaterialRipple(position);
|
Ripple *ripple = new Ripple(position);
|
||||||
ripple->setRadiusEndValue(radius);
|
ripple->setRadiusEndValue(radius);
|
||||||
addRipple(ripple);
|
addRipple(ripple);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialRippleOverlay::removeRipple(QtMaterialRipple *ripple)
|
void RippleOverlay::removeRipple(Ripple *ripple)
|
||||||
{
|
{
|
||||||
if (m_ripples.removeOne(ripple)) {
|
if (m_ripples.removeOne(ripple)) {
|
||||||
delete ripple;
|
delete ripple;
|
||||||
|
|
@ -47,7 +49,7 @@ void QtMaterialRippleOverlay::removeRipple(QtMaterialRipple *ripple)
|
||||||
/*!
|
/*!
|
||||||
* \reimp
|
* \reimp
|
||||||
*/
|
*/
|
||||||
void QtMaterialRippleOverlay::paintEvent(QPaintEvent *event)
|
void RippleOverlay::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event)
|
Q_UNUSED(event)
|
||||||
|
|
||||||
|
|
@ -59,13 +61,13 @@ void QtMaterialRippleOverlay::paintEvent(QPaintEvent *event)
|
||||||
painter.setClipPath(m_clipPath);
|
painter.setClipPath(m_clipPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QtMaterialRipple *>::const_iterator i;
|
QList<Ripple *>::const_iterator i;
|
||||||
for (i = m_ripples.begin(); i != m_ripples.end(); ++i) {
|
for (i = m_ripples.begin(); i != m_ripples.end(); ++i) {
|
||||||
paintRipple(&painter, *i);
|
paintRipple(&painter, *i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialRippleOverlay::paintRipple(QPainter *painter, QtMaterialRipple *ripple)
|
void RippleOverlay::paintRipple(QPainter *painter, Ripple *ripple)
|
||||||
{
|
{
|
||||||
const qreal radius = ripple->radius();
|
const qreal radius = ripple->radius();
|
||||||
const QPointF center = ripple->center();
|
const QPointF center = ripple->center();
|
||||||
|
|
@ -73,3 +75,5 @@ void QtMaterialRippleOverlay::paintRipple(QPainter *painter, QtMaterialRipple *r
|
||||||
painter->setBrush(ripple->brush());
|
painter->setBrush(ripple->brush());
|
||||||
painter->drawEllipse(center, radius, radius);
|
painter->drawEllipse(center, radius, radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,20 +4,22 @@
|
||||||
#include <QPainterPath>
|
#include <QPainterPath>
|
||||||
#include "lib/qtmaterialoverlaywidget.h"
|
#include "lib/qtmaterialoverlaywidget.h"
|
||||||
|
|
||||||
class QtMaterialRipple;
|
namespace md
|
||||||
|
{
|
||||||
|
class Ripple;
|
||||||
|
|
||||||
class QtMaterialRippleOverlay : public QtMaterialOverlayWidget
|
class RippleOverlay : public OverlayWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit QtMaterialRippleOverlay(QWidget *parent = 0);
|
explicit RippleOverlay(QWidget *parent = 0);
|
||||||
~QtMaterialRippleOverlay();
|
~RippleOverlay();
|
||||||
|
|
||||||
void addRipple(QtMaterialRipple *ripple);
|
void addRipple(Ripple *ripple);
|
||||||
void addRipple(const QPoint &position, qreal radius = 300);
|
void addRipple(const QPoint &position, qreal radius = 300);
|
||||||
|
|
||||||
void removeRipple(QtMaterialRipple *ripple);
|
void removeRipple(Ripple *ripple);
|
||||||
|
|
||||||
inline void setClipping(bool enable);
|
inline void setClipping(bool enable);
|
||||||
inline bool hasClipping() const;
|
inline bool hasClipping() const;
|
||||||
|
|
@ -27,38 +29,39 @@ public:
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
inline QList<QtMaterialRipple *> ripples() const;
|
inline QList<Ripple *> ripples() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(QtMaterialRippleOverlay)
|
Q_DISABLE_COPY(RippleOverlay)
|
||||||
|
|
||||||
void paintRipple(QPainter *painter, QtMaterialRipple *ripple);
|
void paintRipple(QPainter *painter, Ripple *ripple);
|
||||||
|
|
||||||
QList<QtMaterialRipple *> m_ripples;
|
QList<Ripple *> m_ripples;
|
||||||
QPainterPath m_clipPath;
|
QPainterPath m_clipPath;
|
||||||
bool m_useClip;
|
bool m_useClip;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void QtMaterialRippleOverlay::setClipping(bool enable)
|
inline void RippleOverlay::setClipping(bool enable)
|
||||||
{
|
{
|
||||||
m_useClip = enable;
|
m_useClip = enable;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool QtMaterialRippleOverlay::hasClipping() const
|
inline bool RippleOverlay::hasClipping() const
|
||||||
{
|
{
|
||||||
return m_useClip;
|
return m_useClip;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void QtMaterialRippleOverlay::setClipPath(const QPainterPath &path)
|
inline void RippleOverlay::setClipPath(const QPainterPath &path)
|
||||||
{
|
{
|
||||||
m_clipPath = path;
|
m_clipPath = path;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QList<QtMaterialRipple *> QtMaterialRippleOverlay::ripples() const
|
inline QList<Ripple *> RippleOverlay::ripples() const
|
||||||
{
|
{
|
||||||
return m_ripples;
|
return m_ripples;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif // QTMATERIALRIPPLEOVERLAY_H
|
#endif // QTMATERIALRIPPLEOVERLAY_H
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,22 @@
|
||||||
#include "lib/qtmaterialstatetransition.h"
|
#include "lib/qtmaterialstatetransition.h"
|
||||||
|
|
||||||
QtMaterialStateTransition::QtMaterialStateTransition(QtMaterialStateTransitionType type)
|
namespace md
|
||||||
|
{
|
||||||
|
StateTransition::StateTransition(StateTransitionType type)
|
||||||
: m_type(type)
|
: m_type(type)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QtMaterialStateTransition::eventTest(QEvent *event)
|
bool StateTransition::eventTest(QEvent *event)
|
||||||
{
|
{
|
||||||
if (event->type() != QEvent::Type(QEvent::User + 1)) {
|
if (event->type() != QEvent::Type(QEvent::User + 1)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
QtMaterialStateTransitionEvent *transition = static_cast<QtMaterialStateTransitionEvent *>(event);
|
StateTransitionEvent *transition = static_cast<StateTransitionEvent *>(event);
|
||||||
return (m_type == transition->type);
|
return (m_type == transition->type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialStateTransition::onTransition(QEvent *)
|
void StateTransition::onTransition(QEvent *)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,19 +4,22 @@
|
||||||
#include <QAbstractTransition>
|
#include <QAbstractTransition>
|
||||||
#include "lib/qtmaterialstatetransitionevent.h"
|
#include "lib/qtmaterialstatetransitionevent.h"
|
||||||
|
|
||||||
class QtMaterialStateTransition : public QAbstractTransition
|
namespace md
|
||||||
|
{
|
||||||
|
class StateTransition : public QAbstractTransition
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QtMaterialStateTransition(QtMaterialStateTransitionType type);
|
StateTransition(StateTransitionType type);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool eventTest(QEvent *event);
|
virtual bool eventTest(QEvent *event);
|
||||||
virtual void onTransition(QEvent *);
|
virtual void onTransition(QEvent *);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QtMaterialStateTransitionType m_type;
|
StateTransitionType m_type;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#endif // QTMATERIALSTATETRANSITION_H
|
#endif // QTMATERIALSTATETRANSITION_H
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,9 @@
|
||||||
|
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
|
|
||||||
enum QtMaterialStateTransitionType {
|
namespace md
|
||||||
|
{
|
||||||
|
enum StateTransitionType {
|
||||||
// Snackbar
|
// Snackbar
|
||||||
SnackbarShowTransition = 1,
|
SnackbarShowTransition = 1,
|
||||||
SnackbarHideTransition,
|
SnackbarHideTransition,
|
||||||
|
|
@ -28,15 +30,16 @@ enum QtMaterialStateTransitionType {
|
||||||
MaxTransitionType = 65535
|
MaxTransitionType = 65535
|
||||||
};
|
};
|
||||||
|
|
||||||
struct QtMaterialStateTransitionEvent : public QEvent
|
struct StateTransitionEvent : public QEvent
|
||||||
{
|
{
|
||||||
QtMaterialStateTransitionEvent(QtMaterialStateTransitionType type)
|
StateTransitionEvent(StateTransitionType type)
|
||||||
: QEvent(QEvent::Type(QEvent::User + 1)),
|
: QEvent(QEvent::Type(QEvent::User + 1)),
|
||||||
type(type)
|
type(type)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QtMaterialStateTransitionType type;
|
StateTransitionType type;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#endif // QTMATERIALSTATETRANSITIONEVENT_H
|
#endif // QTMATERIALSTATETRANSITIONEVENT_H
|
||||||
|
|
|
||||||
|
|
@ -2,29 +2,31 @@
|
||||||
#include <QFontDatabase>
|
#include <QFontDatabase>
|
||||||
#include "lib/qtmaterialtheme.h"
|
#include "lib/qtmaterialtheme.h"
|
||||||
|
|
||||||
|
namespace md
|
||||||
|
{
|
||||||
/*!
|
/*!
|
||||||
* \class QtMaterialStylePrivate
|
* \class QtMaterialStylePrivate
|
||||||
* \internal
|
* \internal
|
||||||
*/
|
*/
|
||||||
|
|
||||||
QtMaterialStylePrivate::QtMaterialStylePrivate(QtMaterialStyle *q)
|
StylePrivate::StylePrivate(Style *q)
|
||||||
: q_ptr(q)
|
: q_ptr(q)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QtMaterialStylePrivate::~QtMaterialStylePrivate()
|
StylePrivate::~StylePrivate()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialStylePrivate::init()
|
void StylePrivate::init()
|
||||||
{
|
{
|
||||||
Q_Q(QtMaterialStyle);
|
Q_Q(Style);
|
||||||
|
|
||||||
QFontDatabase::addApplicationFont(":/fonts/roboto_regular");
|
QFontDatabase::addApplicationFont(":/fonts/roboto_regular");
|
||||||
QFontDatabase::addApplicationFont(":/fonts/roboto_medium");
|
QFontDatabase::addApplicationFont(":/fonts/roboto_medium");
|
||||||
QFontDatabase::addApplicationFont(":/fonts/roboto_bold");
|
QFontDatabase::addApplicationFont(":/fonts/roboto_bold");
|
||||||
|
|
||||||
q->setTheme(new QtMaterialTheme);
|
q->setTheme(new Theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
@ -32,26 +34,28 @@ void QtMaterialStylePrivate::init()
|
||||||
* \internal
|
* \internal
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void QtMaterialStyle::setTheme(QtMaterialTheme *theme)
|
void Style::setTheme(Theme *theme)
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialStyle);
|
Q_D(Style);
|
||||||
|
|
||||||
d->theme = theme;
|
d->theme = theme;
|
||||||
theme->setParent(this);
|
theme->setParent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor QtMaterialStyle::themeColor(const QString &key) const
|
QColor Style::themeColor(const QString &key) const
|
||||||
{
|
{
|
||||||
Q_D(const QtMaterialStyle);
|
Q_D(const Style);
|
||||||
|
|
||||||
Q_ASSERT(d->theme);
|
Q_ASSERT(d->theme);
|
||||||
|
|
||||||
return d->theme->getColor(key);
|
return d->theme->getColor(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
QtMaterialStyle::QtMaterialStyle()
|
Style::Style()
|
||||||
: QCommonStyle(),
|
: QCommonStyle(),
|
||||||
d_ptr(new QtMaterialStylePrivate(this))
|
d_ptr(new StylePrivate(this))
|
||||||
{
|
{
|
||||||
d_func()->init();
|
d_func()->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,34 +7,37 @@
|
||||||
#define MATERIAL_DISABLE_THEME_COLORS \
|
#define MATERIAL_DISABLE_THEME_COLORS \
|
||||||
if (d->useThemeColors == true) { d->useThemeColors = false; }
|
if (d->useThemeColors == true) { d->useThemeColors = false; }
|
||||||
|
|
||||||
class QtMaterialTheme;
|
namespace md
|
||||||
|
{
|
||||||
|
class Theme;
|
||||||
|
|
||||||
class QtMaterialStyle : public QCommonStyle
|
class Style : public QCommonStyle
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline static QtMaterialStyle &instance();
|
inline static Style &instance();
|
||||||
|
|
||||||
void setTheme(QtMaterialTheme *theme);
|
void setTheme(Theme *theme);
|
||||||
QColor themeColor(const QString &key) const;
|
QColor themeColor(const QString &key) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const QScopedPointer<QtMaterialStylePrivate> d_ptr;
|
const QScopedPointer<StylePrivate> d_ptr;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DECLARE_PRIVATE(QtMaterialStyle)
|
Q_DECLARE_PRIVATE(Style)
|
||||||
|
|
||||||
QtMaterialStyle();
|
Style();
|
||||||
|
|
||||||
QtMaterialStyle(QtMaterialStyle const &);
|
Style(Style const &);
|
||||||
void operator=(QtMaterialStyle const &);
|
void operator=(Style const &);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline QtMaterialStyle &QtMaterialStyle::instance()
|
inline Style &Style::instance()
|
||||||
{
|
{
|
||||||
static QtMaterialStyle instance;
|
static Style instance;
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif // QTMATERIALSTYLE_H
|
#endif // QTMATERIALSTYLE_H
|
||||||
|
|
|
||||||
|
|
@ -3,22 +3,25 @@
|
||||||
|
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
|
||||||
class QtMaterialStyle;
|
namespace md
|
||||||
class QtMaterialTheme;
|
|
||||||
|
|
||||||
class QtMaterialStylePrivate
|
|
||||||
{
|
{
|
||||||
Q_DISABLE_COPY(QtMaterialStylePrivate)
|
class Style;
|
||||||
Q_DECLARE_PUBLIC(QtMaterialStyle)
|
class Theme;
|
||||||
|
|
||||||
|
class StylePrivate
|
||||||
|
{
|
||||||
|
Q_DISABLE_COPY(StylePrivate)
|
||||||
|
Q_DECLARE_PUBLIC(Style)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QtMaterialStylePrivate(QtMaterialStyle *q);
|
StylePrivate(Style *q);
|
||||||
~QtMaterialStylePrivate();
|
~StylePrivate();
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
QtMaterialStyle *const q_ptr;
|
Style *const q_ptr;
|
||||||
QtMaterialTheme *theme;
|
Theme *theme;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#endif // QTMATERIALSTYLE_P_H
|
#endif // QTMATERIALSTYLE_P_H
|
||||||
|
|
|
||||||
|
|
@ -3,22 +3,23 @@
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
namespace md
|
||||||
|
{
|
||||||
/*!material
|
/*!material
|
||||||
* \class QtMaterialThemePrivate
|
* \class QtMaterialThemePrivate
|
||||||
* \internal
|
* \internal
|
||||||
*/
|
*/
|
||||||
|
|
||||||
QtMaterialThemePrivate::QtMaterialThemePrivate(QtMaterialTheme *q)
|
ThemePrivate::ThemePrivate(Theme *q)
|
||||||
: q_ptr(q)
|
: q_ptr(q)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QtMaterialThemePrivate::~QtMaterialThemePrivate()
|
ThemePrivate::~ThemePrivate()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor QtMaterialThemePrivate::rgba(int r, int g, int b, qreal a) const
|
QColor ThemePrivate::rgba(int r, int g, int b, qreal a) const
|
||||||
{
|
{
|
||||||
QColor color(r, g, b);
|
QColor color(r, g, b);
|
||||||
color.setAlphaF(a);
|
color.setAlphaF(a);
|
||||||
|
|
@ -29,9 +30,9 @@ QColor QtMaterialThemePrivate::rgba(int r, int g, int b, qreal a) const
|
||||||
* \class QtMaterialTheme
|
* \class QtMaterialTheme
|
||||||
*/
|
*/
|
||||||
|
|
||||||
QtMaterialTheme::QtMaterialTheme(QObject *parent)
|
Theme::Theme(QObject *parent)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
d_ptr(new QtMaterialThemePrivate(this))
|
d_ptr(new ThemePrivate(this))
|
||||||
{
|
{
|
||||||
setColor("primary1", Material::cyan500);
|
setColor("primary1", Material::cyan500);
|
||||||
setColor("primary2", Material::cyan700);
|
setColor("primary2", Material::cyan700);
|
||||||
|
|
@ -48,13 +49,13 @@ QtMaterialTheme::QtMaterialTheme(QObject *parent)
|
||||||
setColor("disabled3", Material::grey300);
|
setColor("disabled3", Material::grey300);
|
||||||
}
|
}
|
||||||
|
|
||||||
QtMaterialTheme::~QtMaterialTheme()
|
Theme::~Theme()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor QtMaterialTheme::getColor(const QString &key) const
|
QColor Theme::getColor(const QString &key) const
|
||||||
{
|
{
|
||||||
Q_D(const QtMaterialTheme);
|
Q_D(const Theme);
|
||||||
|
|
||||||
if (!d->colors.contains(key)) {
|
if (!d->colors.contains(key)) {
|
||||||
qWarning() << "A theme color matching the key '" << key << "' could not be found.";
|
qWarning() << "A theme color matching the key '" << key << "' could not be found.";
|
||||||
|
|
@ -63,16 +64,16 @@ QColor QtMaterialTheme::getColor(const QString &key) const
|
||||||
return d->colors.value(key);
|
return d->colors.value(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialTheme::setColor(const QString &key, const QColor &color)
|
void Theme::setColor(const QString &key, const QColor &color)
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialTheme);
|
Q_D(Theme);
|
||||||
|
|
||||||
d->colors.insert(key, color);
|
d->colors.insert(key, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialTheme::setColor(const QString &key, Material::Color color)
|
void Theme::setColor(const QString &key, Material::Color color)
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialTheme);
|
Q_D(Theme);
|
||||||
|
|
||||||
static const QColor palette[] = {
|
static const QColor palette[] = {
|
||||||
QColor("#ffebee"), QColor("#ffcdd2"), QColor("#ef9a9a"), QColor("#e57373"),
|
QColor("#ffebee"), QColor("#ffcdd2"), QColor("#ef9a9a"), QColor("#e57373"),
|
||||||
|
|
@ -153,7 +154,9 @@ void QtMaterialTheme::setColor(const QString &key, Material::Color color)
|
||||||
d->colors.insert(key, palette[color]);
|
d->colors.insert(key, palette[color]);
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon QtMaterialTheme::icon(QString category, QString icon)
|
QIcon Theme::icon(QString category, QString icon)
|
||||||
{
|
{
|
||||||
return QIcon(":/icons/icons/" % category % "/svg/production/ic_" % icon % "_24px.svg");
|
return QIcon(":/icons/icons/" % category % "/svg/production/ic_" % icon % "_24px.svg");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
|
||||||
|
namespace md
|
||||||
|
{
|
||||||
namespace Material
|
namespace Material
|
||||||
{
|
{
|
||||||
enum ButtonPreset {
|
enum ButtonPreset {
|
||||||
|
|
@ -316,15 +318,15 @@ namespace Material
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
class QtMaterialThemePrivate;
|
class ThemePrivate;
|
||||||
|
|
||||||
class QtMaterialTheme : public QObject
|
class Theme : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit QtMaterialTheme(QObject *parent = 0);
|
explicit Theme(QObject *parent = 0);
|
||||||
~QtMaterialTheme();
|
~Theme();
|
||||||
|
|
||||||
QColor getColor(const QString &key) const;
|
QColor getColor(const QString &key) const;
|
||||||
|
|
||||||
|
|
@ -334,11 +336,12 @@ public:
|
||||||
static QIcon icon(QString category, QString icon);
|
static QIcon icon(QString category, QString icon);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const QScopedPointer<QtMaterialThemePrivate> d_ptr;
|
const QScopedPointer<ThemePrivate> d_ptr;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(QtMaterialTheme)
|
Q_DISABLE_COPY(Theme)
|
||||||
Q_DECLARE_PRIVATE(QtMaterialTheme)
|
Q_DECLARE_PRIVATE(Theme)
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#endif // QTMATERIALTHEME_H
|
#endif // QTMATERIALTHEME_H
|
||||||
|
|
|
||||||
|
|
@ -4,21 +4,24 @@
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
|
||||||
class QtMaterialTheme;
|
namespace md
|
||||||
|
|
||||||
class QtMaterialThemePrivate
|
|
||||||
{
|
{
|
||||||
Q_DISABLE_COPY(QtMaterialThemePrivate)
|
class Theme;
|
||||||
Q_DECLARE_PUBLIC(QtMaterialTheme)
|
|
||||||
|
class ThemePrivate
|
||||||
|
{
|
||||||
|
Q_DISABLE_COPY(ThemePrivate)
|
||||||
|
Q_DECLARE_PUBLIC(Theme)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QtMaterialThemePrivate(QtMaterialTheme *q);
|
ThemePrivate(Theme *q);
|
||||||
~QtMaterialThemePrivate();
|
~ThemePrivate();
|
||||||
|
|
||||||
QColor rgba(int r, int g, int b, qreal a) const;
|
QColor rgba(int r, int g, int b, qreal a) const;
|
||||||
|
|
||||||
QtMaterialTheme *const q_ptr;
|
Theme *const q_ptr;
|
||||||
QHash<QString, QColor> colors;
|
QHash<QString, QColor> colors;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#endif // QTMATERIALTHEME_P_H
|
#endif // QTMATERIALTHEME_P_H
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue