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