snapshot
This commit is contained in:
parent
733f7310d3
commit
254a619c2a
|
@ -62,6 +62,8 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
//FlatButtonSettingsEditor *fb = new FlatButtonSettingsEditor;
|
||||
//setCentralWidget(fb);
|
||||
|
||||
//return;
|
||||
|
||||
//RaisedButtonSettingsEditor *fb = new RaisedButtonSettingsEditor;
|
||||
//setCentralWidget(fb);
|
||||
|
||||
|
|
|
@ -113,7 +113,8 @@ SOURCES += main.cpp\
|
|||
yy/selectfieldsettingseditor.cpp \
|
||||
yy/checkboxsettingseditor.cpp \
|
||||
xxlib/qtmaterialcheckable.cpp \
|
||||
xxlib/qtmaterialcheckable_internal.cpp
|
||||
xxlib/qtmaterialcheckable_internal.cpp \
|
||||
xx/qtmaterialcheckbox.cpp
|
||||
|
||||
HEADERS += mainwindow.h \
|
||||
components/appbar.h \
|
||||
|
@ -255,7 +256,9 @@ HEADERS += mainwindow.h \
|
|||
yy/checkboxsettingseditor.h \
|
||||
xxlib/qtmaterialcheckable.h \
|
||||
xxlib/qtmaterialcheckable_p.h \
|
||||
xxlib/qtmaterialcheckable_internal.h
|
||||
xxlib/qtmaterialcheckable_internal.h \
|
||||
xx/qtmaterialcheckbox.h \
|
||||
xx/qtmaterialcheckbox_p.h
|
||||
|
||||
RESOURCES += \
|
||||
resources.qrc
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
#include "xx/qtmaterialcheckbox.h"
|
||||
#include "xx/qtmaterialcheckbox_p.h"
|
||||
#include <QPropertyAnimation>
|
||||
#include <QSignalTransition>
|
||||
#include <QState>
|
||||
#include "xxlib/qtmaterialcheckable_internal.h"
|
||||
|
||||
/*!
|
||||
* \class QtMaterialCheckBoxPrivate
|
||||
* \internal
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \internal
|
||||
*/
|
||||
QtMaterialCheckBoxPrivate::QtMaterialCheckBoxPrivate(QtMaterialCheckBox *q)
|
||||
: QtMaterialCheckablePrivate(q)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \internal
|
||||
*/
|
||||
QtMaterialCheckBoxPrivate::~QtMaterialCheckBoxPrivate()
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \internal
|
||||
*/
|
||||
void QtMaterialCheckBoxPrivate::init()
|
||||
{
|
||||
Q_Q(QtMaterialCheckBox);
|
||||
|
||||
checkedState->assignProperty(checkedIcon, "iconSize", 24);
|
||||
uncheckedState->assignProperty(checkedIcon, "iconSize", 0);
|
||||
|
||||
QPropertyAnimation *animation;
|
||||
|
||||
animation = new QPropertyAnimation(checkedIcon, "iconSize", q);
|
||||
animation->setDuration(300);
|
||||
uncheckedTransition->addAnimation(animation);
|
||||
|
||||
animation = new QPropertyAnimation(checkedIcon, "iconSize", q);
|
||||
animation->setDuration(1300);
|
||||
checkedTransition->addAnimation(animation);
|
||||
|
||||
animation = new QPropertyAnimation(checkedIcon, "opacity", q);
|
||||
animation->setDuration(440);
|
||||
checkedTransition->addAnimation(animation);
|
||||
|
||||
animation = new QPropertyAnimation(checkedIcon, "opacity", q);
|
||||
animation->setDuration(440);
|
||||
uncheckedTransition->addAnimation(animation);
|
||||
|
||||
animation = new QPropertyAnimation(uncheckedIcon, "opacity", q);
|
||||
animation->setDuration(440);
|
||||
checkedTransition->addAnimation(animation);
|
||||
|
||||
animation = new QPropertyAnimation(uncheckedIcon, "opacity", q);
|
||||
animation->setDuration(440);
|
||||
uncheckedTransition->addAnimation(animation);
|
||||
|
||||
animation = new QPropertyAnimation(uncheckedIcon, "color", q);
|
||||
animation->setDuration(440);
|
||||
checkedTransition->addAnimation(animation);
|
||||
|
||||
animation = new QPropertyAnimation(uncheckedIcon, "color", q);
|
||||
animation->setDuration(440);
|
||||
uncheckedTransition->addAnimation(animation);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \class QtMaterialCheckBox
|
||||
*/
|
||||
|
||||
QtMaterialCheckBox::QtMaterialCheckBox(QWidget *parent)
|
||||
: QtMaterialCheckable(*new QtMaterialCheckBoxPrivate(this), parent)
|
||||
{
|
||||
d_func()->init();
|
||||
}
|
||||
|
||||
QtMaterialCheckBox::~QtMaterialCheckBox()
|
||||
{
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef QTMATERIALCHECKBOX_H
|
||||
#define QTMATERIALCHECKBOX_H
|
||||
|
||||
#include "xxlib/qtmaterialcheckable.h"
|
||||
|
||||
class QtMaterialCheckBoxPrivate;
|
||||
|
||||
class QtMaterialCheckBox : public QtMaterialCheckable
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit QtMaterialCheckBox(QWidget *parent = 0);
|
||||
~QtMaterialCheckBox();
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(QtMaterialCheckBox)
|
||||
Q_DECLARE_PRIVATE(QtMaterialCheckBox)
|
||||
};
|
||||
|
||||
#endif // QTMATERIALCHECKBOX_H
|
|
@ -0,0 +1,20 @@
|
|||
#ifndef QTMATERIALCHECKBOX_P_H
|
||||
#define QTMATERIALCHECKBOX_P_H
|
||||
|
||||
#include "xxlib/qtmaterialcheckable_p.h"
|
||||
|
||||
class QtMaterialCheckBox;
|
||||
|
||||
class QtMaterialCheckBoxPrivate : public QtMaterialCheckablePrivate
|
||||
{
|
||||
Q_DISABLE_COPY(QtMaterialCheckBoxPrivate)
|
||||
Q_DECLARE_PUBLIC(QtMaterialCheckBox)
|
||||
|
||||
public:
|
||||
QtMaterialCheckBoxPrivate(QtMaterialCheckBox *q);
|
||||
~QtMaterialCheckBoxPrivate();
|
||||
|
||||
void init();
|
||||
};
|
||||
|
||||
#endif // QTMATERIALCHECKBOX_P_H
|
|
@ -32,10 +32,10 @@ void QtMaterialRaisedButtonPrivate::init()
|
|||
{
|
||||
Q_Q(QtMaterialRaisedButton);
|
||||
|
||||
shadowMachine = new QStateMachine(q);
|
||||
normalState = new QState;
|
||||
pressedState = new QState;
|
||||
effect = new QGraphicsDropShadowEffect;
|
||||
shadowStateMachine = new QStateMachine(q);
|
||||
normalState = new QState;
|
||||
pressedState = new QState;
|
||||
effect = new QGraphicsDropShadowEffect;
|
||||
|
||||
effect->setBlurRadius(7);
|
||||
effect->setOffset(QPointF(0, 2));
|
||||
|
@ -46,8 +46,8 @@ void QtMaterialRaisedButtonPrivate::init()
|
|||
q->setGraphicsEffect(effect);
|
||||
q->setBaseOpacity(0.3);
|
||||
|
||||
shadowMachine->addState(normalState);
|
||||
shadowMachine->addState(pressedState);
|
||||
shadowStateMachine->addState(normalState);
|
||||
shadowStateMachine->addState(pressedState);
|
||||
|
||||
normalState->assignProperty(effect, "offset", QPointF(0, 2));
|
||||
normalState->assignProperty(effect, "blurRadius", 7);
|
||||
|
@ -73,14 +73,14 @@ void QtMaterialRaisedButtonPrivate::init()
|
|||
|
||||
animation = new QPropertyAnimation(effect, "offset", q);
|
||||
animation->setDuration(100);
|
||||
shadowMachine->addDefaultAnimation(animation);
|
||||
shadowStateMachine->addDefaultAnimation(animation);
|
||||
|
||||
animation = new QPropertyAnimation(effect, "blurRadius", q);
|
||||
animation->setDuration(100);
|
||||
shadowMachine->addDefaultAnimation(animation);
|
||||
shadowStateMachine->addDefaultAnimation(animation);
|
||||
|
||||
shadowMachine->setInitialState(normalState);
|
||||
shadowMachine->start();
|
||||
shadowStateMachine->setInitialState(normalState);
|
||||
shadowStateMachine->start();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -117,10 +117,10 @@ bool QtMaterialRaisedButton::event(QEvent *event)
|
|||
|
||||
if (QEvent::EnabledChange == event->type()) {
|
||||
if (isEnabled()) {
|
||||
d->shadowMachine->start();
|
||||
d->shadowStateMachine->start();
|
||||
d->effect->setEnabled(true);
|
||||
} else {
|
||||
d->shadowMachine->stop();
|
||||
d->shadowStateMachine->stop();
|
||||
d->effect->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,11 +19,7 @@ public:
|
|||
|
||||
void init();
|
||||
|
||||
QRect fabGeometry() const;
|
||||
|
||||
void assignAnimationProperties();
|
||||
|
||||
QStateMachine *shadowMachine;
|
||||
QStateMachine *shadowStateMachine;
|
||||
QState *normalState;
|
||||
QState *pressedState;
|
||||
QGraphicsDropShadowEffect *effect;
|
||||
|
|
|
@ -3,6 +3,11 @@
|
|||
#include <QPainter>
|
||||
#include <QFontDatabase>
|
||||
#include <QEvent>
|
||||
#include <QStateMachine>
|
||||
#include <QSignalTransition>
|
||||
#include <QEventTransition>
|
||||
#include <QColor>
|
||||
#include <QCoreApplication>
|
||||
#include "xxlib/qtmaterialrippleoverlay.h"
|
||||
#include "xxlib/qtmaterialripple.h"
|
||||
#include "xxlib/qtmaterialstyle.h"
|
||||
|
@ -26,9 +31,18 @@ void QtMaterialCheckablePrivate::init()
|
|||
{
|
||||
Q_Q(QtMaterialCheckable);
|
||||
|
||||
rippleOverlay = new QtMaterialRippleOverlay;
|
||||
checkedIcon = new QtMaterialCheckableIcon(QIcon("../qt-material-widgets/ic_check_box_black_24px.svg"));
|
||||
uncheckedIcon = new QtMaterialCheckableIcon(QIcon("../qt-material-widgets/ic_check_box_outline_blank_black_24px.svg"));
|
||||
rippleOverlay = new QtMaterialRippleOverlay;
|
||||
checkedIcon = new QtMaterialCheckableIcon(QIcon("../qt-material-widgets/ic_check_box_black_24px.svg"), q);
|
||||
uncheckedIcon = new QtMaterialCheckableIcon(QIcon("../qt-material-widgets/ic_check_box_outline_blank_black_24px.svg"), q);
|
||||
stateMachine = new QStateMachine(q);
|
||||
uncheckedState = new QState;
|
||||
checkedState = new QState;
|
||||
disabledUncheckedState = new QState;
|
||||
disabledCheckedState = new QState;
|
||||
uncheckedTransition = new QSignalTransition(q, SIGNAL(toggled(bool)));
|
||||
checkedTransition = new QSignalTransition(q, SIGNAL(toggled(bool)));
|
||||
labelPosition = QtMaterialCheckable::LabelPositionRight;
|
||||
useThemeColors = true;
|
||||
|
||||
rippleOverlay->setParent(q->parentWidget());
|
||||
rippleOverlay->installEventFilter(q);
|
||||
|
@ -39,6 +53,73 @@ void QtMaterialCheckablePrivate::init()
|
|||
QFontDatabase db;
|
||||
QFont font(db.font("Roboto", "Medium", 11));
|
||||
q->setFont(font);
|
||||
|
||||
stateMachine->addState(uncheckedState);
|
||||
stateMachine->addState(checkedState);
|
||||
stateMachine->addState(disabledUncheckedState);
|
||||
stateMachine->addState(disabledCheckedState);
|
||||
stateMachine->setInitialState(uncheckedState);
|
||||
|
||||
// Transition to checked
|
||||
|
||||
uncheckedTransition->setTargetState(checkedState);
|
||||
uncheckedState->addTransition(uncheckedTransition);
|
||||
|
||||
// Transition to unchecked
|
||||
|
||||
checkedTransition->setTargetState(uncheckedState);
|
||||
checkedState->addTransition(checkedTransition);
|
||||
|
||||
QAbstractTransition *transition;
|
||||
|
||||
// Transitions enabled <==> disabled
|
||||
|
||||
transition = new QEventTransition(q, QEvent::EnabledChange);
|
||||
transition->setTargetState(disabledUncheckedState);
|
||||
uncheckedState->addTransition(transition);
|
||||
|
||||
transition = new QEventTransition(q, QEvent::EnabledChange);
|
||||
transition->setTargetState(uncheckedState);
|
||||
disabledUncheckedState->addTransition(transition);
|
||||
|
||||
transition = new QEventTransition(q, QEvent::EnabledChange);
|
||||
transition->setTargetState(disabledCheckedState);
|
||||
checkedState->addTransition(transition);
|
||||
|
||||
transition = new QEventTransition(q, QEvent::EnabledChange);
|
||||
transition->setTargetState(checkedState);
|
||||
disabledCheckedState->addTransition(transition);
|
||||
|
||||
transition = new QSignalTransition(q, SIGNAL(toggled(bool)));
|
||||
transition->setTargetState(disabledCheckedState);
|
||||
disabledUncheckedState->addTransition(transition);
|
||||
|
||||
transition = new QSignalTransition(q, SIGNAL(toggled(bool)));
|
||||
transition->setTargetState(disabledUncheckedState);
|
||||
disabledCheckedState->addTransition(transition);
|
||||
|
||||
//
|
||||
|
||||
checkedState->assignProperty(checkedIcon, "opacity", 1);
|
||||
checkedState->assignProperty(uncheckedIcon, "opacity", 0);
|
||||
|
||||
uncheckedState->assignProperty(checkedIcon, "opacity", 0);
|
||||
uncheckedState->assignProperty(uncheckedIcon, "opacity", 1);
|
||||
|
||||
disabledCheckedState->assignProperty(checkedIcon, "opacity", 1);
|
||||
disabledUncheckedState->assignProperty(uncheckedIcon, "opacity", 1);
|
||||
|
||||
checkedState->assignProperty(checkedIcon, "color", q->checkedColor());
|
||||
checkedState->assignProperty(uncheckedIcon, "color", q->checkedColor());
|
||||
|
||||
uncheckedState->assignProperty(uncheckedIcon, "color", q->uncheckedColor());
|
||||
uncheckedState->assignProperty(uncheckedIcon, "color", q->uncheckedColor());
|
||||
|
||||
disabledUncheckedState->assignProperty(uncheckedIcon, "color", q->disabledColor());
|
||||
disabledCheckedState->assignProperty(checkedIcon, "color", q->disabledColor());
|
||||
|
||||
stateMachine->start();
|
||||
QCoreApplication::processEvents();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -56,6 +137,145 @@ QtMaterialCheckable::~QtMaterialCheckable()
|
|||
{
|
||||
}
|
||||
|
||||
void QtMaterialCheckable::setLabelPosition(LabelPosition placement)
|
||||
{
|
||||
Q_D(QtMaterialCheckable);
|
||||
|
||||
d->labelPosition = placement;
|
||||
update();
|
||||
}
|
||||
|
||||
QtMaterialCheckable::LabelPosition QtMaterialCheckable::labelPosition() const
|
||||
{
|
||||
Q_D(const QtMaterialCheckable);
|
||||
|
||||
return d->labelPosition;
|
||||
}
|
||||
|
||||
void QtMaterialCheckable::setUseThemeColors(bool value)
|
||||
{
|
||||
Q_D(QtMaterialCheckable);
|
||||
|
||||
d->useThemeColors = value;
|
||||
setupProperties();
|
||||
}
|
||||
|
||||
bool QtMaterialCheckable::useThemeColors() const
|
||||
{
|
||||
Q_D(const QtMaterialCheckable);
|
||||
|
||||
return d->useThemeColors;
|
||||
}
|
||||
|
||||
void QtMaterialCheckable::setCheckedColor(const QColor &color)
|
||||
{
|
||||
Q_D(QtMaterialCheckable);
|
||||
|
||||
d->checkedColor = color;
|
||||
setUseThemeColors(false);
|
||||
}
|
||||
|
||||
QColor QtMaterialCheckable::checkedColor() const
|
||||
{
|
||||
Q_D(const QtMaterialCheckable);
|
||||
|
||||
if (d->useThemeColors || !d->checkedColor.isValid()) {
|
||||
return QtMaterialStyle::instance().themeColor("primary1");
|
||||
} else {
|
||||
return d->checkedColor;
|
||||
}
|
||||
}
|
||||
|
||||
void QtMaterialCheckable::setUncheckedColor(const QColor &color)
|
||||
{
|
||||
Q_D(QtMaterialCheckable);
|
||||
|
||||
d->uncheckedColor = color;
|
||||
setUseThemeColors(false);
|
||||
}
|
||||
|
||||
QColor QtMaterialCheckable::uncheckedColor() const
|
||||
{
|
||||
Q_D(const QtMaterialCheckable);
|
||||
|
||||
if (d->useThemeColors || !d->uncheckedColor.isValid()) {
|
||||
return QtMaterialStyle::instance().themeColor("text");
|
||||
} else {
|
||||
return d->uncheckedColor;
|
||||
}
|
||||
}
|
||||
|
||||
void QtMaterialCheckable::setTextColor(const QColor &color)
|
||||
{
|
||||
Q_D(QtMaterialCheckable);
|
||||
|
||||
d->textColor = color;
|
||||
setUseThemeColors(false);
|
||||
}
|
||||
|
||||
QColor QtMaterialCheckable::textColor() const
|
||||
{
|
||||
Q_D(const QtMaterialCheckable);
|
||||
|
||||
if (d->useThemeColors || !d->textColor.isValid()) {
|
||||
return QtMaterialStyle::instance().themeColor("text");
|
||||
} else {
|
||||
return d->textColor;
|
||||
}
|
||||
}
|
||||
|
||||
void QtMaterialCheckable::setDisabledColor(const QColor &color)
|
||||
{
|
||||
Q_D(QtMaterialCheckable);
|
||||
|
||||
d->disabledColor = color;
|
||||
setUseThemeColors(false);
|
||||
}
|
||||
|
||||
QColor QtMaterialCheckable::disabledColor() const
|
||||
{
|
||||
Q_D(const QtMaterialCheckable);
|
||||
|
||||
if (d->useThemeColors || !d->disabledColor.isValid()) {
|
||||
return QtMaterialStyle::instance().themeColor("accent3");
|
||||
} else {
|
||||
return d->disabledColor;
|
||||
}
|
||||
}
|
||||
|
||||
void QtMaterialCheckable::setCheckedIcon(const QIcon &icon)
|
||||
{
|
||||
Q_D(QtMaterialCheckable);
|
||||
|
||||
d->checkedIcon->setIcon(icon);
|
||||
update();
|
||||
}
|
||||
|
||||
QIcon QtMaterialCheckable::checkedIcon() const
|
||||
{
|
||||
Q_D(const QtMaterialCheckable);
|
||||
|
||||
return d->checkedIcon->icon();
|
||||
}
|
||||
|
||||
void QtMaterialCheckable::setUncheckedIcon(const QIcon &icon)
|
||||
{
|
||||
Q_D(QtMaterialCheckable);
|
||||
|
||||
d->uncheckedIcon->setIcon(icon);
|
||||
update();
|
||||
}
|
||||
|
||||
QIcon QtMaterialCheckable::uncheckedIcon() const
|
||||
{
|
||||
Q_D(const QtMaterialCheckable);
|
||||
|
||||
return d->uncheckedIcon->icon();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \reimp
|
||||
*/
|
||||
QSize QtMaterialCheckable::sizeHint() const
|
||||
{
|
||||
if (text().isEmpty()) {
|
||||
|
@ -71,12 +291,21 @@ QtMaterialCheckable::QtMaterialCheckable(QtMaterialCheckablePrivate &d, QWidget
|
|||
d_func()->init();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \reimp
|
||||
*/
|
||||
bool QtMaterialCheckable::event(QEvent *event)
|
||||
{
|
||||
Q_D(QtMaterialCheckable);
|
||||
|
||||
switch (event->type())
|
||||
{
|
||||
case QEvent::Resize:
|
||||
case QEvent::Move:
|
||||
d->checkedIcon->setGeometry(rect());
|
||||
d->uncheckedIcon->setGeometry(rect());
|
||||
d->rippleOverlay->setGeometry(geometry().adjusted(-8, -8, 8, 8));
|
||||
break;
|
||||
case QEvent::ParentChange:
|
||||
QWidget *widget;
|
||||
if ((widget = parentWidget())) {
|
||||
|
@ -89,6 +318,9 @@ bool QtMaterialCheckable::event(QEvent *event)
|
|||
return QAbstractButton::event(event);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \reimp
|
||||
*/
|
||||
bool QtMaterialCheckable::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
if (QEvent::Resize == event->type())
|
||||
|
@ -100,6 +332,9 @@ bool QtMaterialCheckable::eventFilter(QObject *obj, QEvent *event)
|
|||
return QAbstractButton::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \reimp
|
||||
*/
|
||||
void QtMaterialCheckable::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
|
@ -110,9 +345,14 @@ void QtMaterialCheckable::mousePressEvent(QMouseEvent *event)
|
|||
return;
|
||||
}
|
||||
|
||||
QtMaterialRipple *ripple = new QtMaterialRipple(QPoint(28, 28));
|
||||
QtMaterialRipple *ripple;
|
||||
if (QtMaterialCheckable::LabelPositionLeft == d->labelPosition) {
|
||||
ripple = new QtMaterialRipple(QPoint(width()-14, 28));
|
||||
} else {
|
||||
ripple = new QtMaterialRipple(QPoint(28, 28));
|
||||
}
|
||||
ripple->setRadiusEndValue(22);
|
||||
//ripple->setColor(isChecked() ? checkedColor() : uncheckedColor());
|
||||
ripple->setColor(isChecked() ? checkedColor() : uncheckedColor());
|
||||
if (isChecked()) {
|
||||
ripple->setOpacityStartValue(1);
|
||||
}
|
||||
|
@ -121,11 +361,44 @@ void QtMaterialCheckable::mousePressEvent(QMouseEvent *event)
|
|||
QAbstractButton::mousePressEvent(event);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \reimp
|
||||
*/
|
||||
void QtMaterialCheckable::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
|
||||
Q_D(QtMaterialCheckable);
|
||||
|
||||
QPainter painter(this);
|
||||
|
||||
painter.drawRect(rect().adjusted(0, 0, -1, -1));
|
||||
if (QtMaterialCheckable::LabelPositionLeft == d->labelPosition) {
|
||||
painter.drawText(4, 25, text());
|
||||
} else {
|
||||
painter.drawText(48, 25, text());
|
||||
}
|
||||
}
|
||||
|
||||
void QtMaterialCheckable::setupProperties()
|
||||
{
|
||||
Q_D(QtMaterialCheckable);
|
||||
|
||||
d->checkedState->assignProperty(d->checkedIcon, "color", checkedColor());
|
||||
d->checkedState->assignProperty(d->uncheckedIcon, "color", checkedColor());
|
||||
d->uncheckedState->assignProperty(d->uncheckedIcon, "color", uncheckedColor());
|
||||
d->disabledUncheckedState->assignProperty(d->uncheckedIcon, "color", disabledColor());
|
||||
d->disabledCheckedState->assignProperty(d->checkedIcon, "color", disabledColor());
|
||||
|
||||
if (isEnabled()) {
|
||||
if (isChecked()) {
|
||||
d->checkedIcon->setColor(checkedColor());
|
||||
} else {
|
||||
d->uncheckedIcon->setColor(uncheckedColor());
|
||||
}
|
||||
} else {
|
||||
d->checkedIcon->setColor(disabledColor());
|
||||
d->uncheckedIcon->setColor(disabledColor());
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
|
|
@ -10,9 +10,38 @@ class QtMaterialCheckable : public QAbstractButton
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum LabelPosition {
|
||||
LabelPositionLeft,
|
||||
LabelPositionRight,
|
||||
};
|
||||
|
||||
explicit QtMaterialCheckable(QWidget *parent = 0);
|
||||
~QtMaterialCheckable();
|
||||
|
||||
void setLabelPosition(LabelPosition placement);
|
||||
LabelPosition labelPosition() const;
|
||||
|
||||
void setUseThemeColors(bool value);
|
||||
bool useThemeColors() const;
|
||||
|
||||
void setCheckedColor(const QColor &color);
|
||||
QColor checkedColor() const;
|
||||
|
||||
void setUncheckedColor(const QColor &color);
|
||||
QColor uncheckedColor() const;
|
||||
|
||||
void setTextColor(const QColor &color);
|
||||
QColor textColor() const;
|
||||
|
||||
void setDisabledColor(const QColor &color);
|
||||
QColor disabledColor() const;
|
||||
|
||||
void setCheckedIcon(const QIcon &icon);
|
||||
QIcon checkedIcon() const;
|
||||
|
||||
void setUncheckedIcon(const QIcon &icon);
|
||||
QIcon uncheckedIcon() const;
|
||||
|
||||
QSize sizeHint() const Q_DECL_OVERRIDE;
|
||||
|
||||
protected:
|
||||
|
@ -23,6 +52,8 @@ protected:
|
|||
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
||||
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
||||
|
||||
virtual void setupProperties();
|
||||
|
||||
const QScopedPointer<QtMaterialCheckablePrivate> d_ptr;
|
||||
|
||||
private:
|
||||
|
|
|
@ -1,13 +1,24 @@
|
|||
#include "xxlib/qtmaterialcheckable_internal.h"
|
||||
#include <QPainter>
|
||||
#include <QIcon>
|
||||
#include <QTransform>
|
||||
#include "xxlib/qtmaterialcheckable.h"
|
||||
|
||||
QtMaterialCheckableIcon::QtMaterialCheckableIcon(const QIcon &icon, QWidget *parent)
|
||||
/*!
|
||||
* \class QtMaterialCheckableIcon
|
||||
* \internal
|
||||
*/
|
||||
|
||||
QtMaterialCheckableIcon::QtMaterialCheckableIcon(const QIcon &icon, QtMaterialCheckable *parent)
|
||||
: QWidget(parent),
|
||||
m_checkable(parent),
|
||||
m_color(Qt::black),
|
||||
m_icon(icon),
|
||||
m_iconSize(24),
|
||||
m_opacity(1.0)
|
||||
{
|
||||
Q_ASSERT(parent);
|
||||
|
||||
setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
}
|
||||
|
||||
|
@ -26,8 +37,27 @@ void QtMaterialCheckableIcon::paintEvent(QPaintEvent *event)
|
|||
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
painter.drawRect(rect());
|
||||
|
||||
painter.setOpacity(m_opacity);
|
||||
|
||||
QPixmap pixmap = icon().pixmap(24, 24);
|
||||
|
||||
if (!pixmap.isNull())
|
||||
{
|
||||
const qreal p = static_cast<qreal>((height())-m_iconSize)/2;
|
||||
const qreal z = m_iconSize/24;
|
||||
|
||||
QTransform t;
|
||||
if (QtMaterialCheckable::LabelPositionLeft == m_checkable->labelPosition()) {
|
||||
t.translate(p+width()-42, p);
|
||||
} else {
|
||||
t.translate(p, p);
|
||||
}
|
||||
t.scale(z, z);
|
||||
painter.setTransform(t);
|
||||
|
||||
QPainter icon(&pixmap);
|
||||
icon.setCompositionMode(QPainter::CompositionMode_SourceIn);
|
||||
icon.fillRect(pixmap.rect(), color());
|
||||
painter.drawPixmap(0, 0, pixmap);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#include <QColor>
|
||||
#include <QIcon>
|
||||
|
||||
class QtMaterialCheckable;
|
||||
|
||||
class QtMaterialCheckableIcon : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -14,7 +16,7 @@ class QtMaterialCheckableIcon : public QWidget
|
|||
Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity)
|
||||
|
||||
public:
|
||||
explicit QtMaterialCheckableIcon(const QIcon &icon, QWidget *parent = 0);
|
||||
QtMaterialCheckableIcon(const QIcon &icon, QtMaterialCheckable *parent);
|
||||
~QtMaterialCheckableIcon();
|
||||
|
||||
QSize sizeHint() const Q_DECL_OVERRIDE;
|
||||
|
@ -37,10 +39,11 @@ protected:
|
|||
private:
|
||||
Q_DISABLE_COPY(QtMaterialCheckableIcon)
|
||||
|
||||
QColor m_color;
|
||||
QIcon m_icon;
|
||||
qreal m_iconSize;
|
||||
qreal m_opacity;
|
||||
QtMaterialCheckable *const m_checkable;
|
||||
QColor m_color;
|
||||
QIcon m_icon;
|
||||
qreal m_iconSize;
|
||||
qreal m_opacity;
|
||||
};
|
||||
|
||||
inline void QtMaterialCheckableIcon::setIcon(const QIcon &icon)
|
||||
|
|
|
@ -2,8 +2,11 @@
|
|||
#define QTMATERIALCHECKABLE_P_H
|
||||
|
||||
#include <QtGlobal>
|
||||
#include "xxlib/qtmaterialcheckable.h"
|
||||
|
||||
class QtMaterialCheckable;
|
||||
class QStateMachine;
|
||||
class QState;
|
||||
class QSignalTransition;
|
||||
class QtMaterialRippleOverlay;
|
||||
class QtMaterialCheckableIcon;
|
||||
|
||||
|
@ -18,10 +21,23 @@ public:
|
|||
|
||||
void init();
|
||||
|
||||
QtMaterialCheckable *const q_ptr;
|
||||
QtMaterialRippleOverlay *rippleOverlay;
|
||||
QtMaterialCheckableIcon *checkedIcon;
|
||||
QtMaterialCheckableIcon *uncheckedIcon;
|
||||
QtMaterialCheckable *const q_ptr;
|
||||
QtMaterialRippleOverlay *rippleOverlay;
|
||||
QtMaterialCheckableIcon *checkedIcon;
|
||||
QtMaterialCheckableIcon *uncheckedIcon;
|
||||
QStateMachine *stateMachine;
|
||||
QState *uncheckedState;
|
||||
QState *checkedState;
|
||||
QState *disabledUncheckedState;
|
||||
QState *disabledCheckedState;
|
||||
QSignalTransition *uncheckedTransition;
|
||||
QSignalTransition *checkedTransition;
|
||||
QtMaterialCheckable::LabelPosition labelPosition;
|
||||
QColor checkedColor;
|
||||
QColor uncheckedColor;
|
||||
QColor textColor;
|
||||
QColor disabledColor;
|
||||
bool useThemeColors;
|
||||
};
|
||||
|
||||
#endif // QTMATERIALCHECKABLE_P_H
|
||||
|
|
|
@ -2,12 +2,13 @@
|
|||
#include <QVBoxLayout>
|
||||
#include <QColorDialog>
|
||||
//#include "components/checkbox.h"
|
||||
#include "xxlib/qtmaterialcheckable.h"
|
||||
//#include "xxlib/qtmaterialcheckable.h"
|
||||
#include "xx/qtmaterialcheckbox.h"
|
||||
|
||||
CheckBoxSettingsEditor::CheckBoxSettingsEditor(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
ui(new Ui::CheckBoxSettingsForm),
|
||||
m_checkBox(new QtMaterialCheckable)
|
||||
m_checkBox(new QtMaterialCheckBox)
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout;
|
||||
setLayout(layout);
|
||||
|
@ -23,6 +24,7 @@ CheckBoxSettingsEditor::CheckBoxSettingsEditor(QWidget *parent)
|
|||
layout->setContentsMargins(20, 20, 20, 20);
|
||||
|
||||
m_checkBox->setText("Palak paneer");
|
||||
m_checkBox->setChecked(true);
|
||||
|
||||
layout = new QVBoxLayout;
|
||||
canvas->setLayout(layout);
|
||||
|
@ -30,6 +32,17 @@ CheckBoxSettingsEditor::CheckBoxSettingsEditor(QWidget *parent)
|
|||
layout->setAlignment(m_checkBox, Qt::AlignCenter);
|
||||
|
||||
setupForm();
|
||||
|
||||
connect(ui->disabledCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateWidget()));
|
||||
connect(ui->labelPositionComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateWidget()));
|
||||
connect(ui->labelTextLineEdit, SIGNAL(textChanged(QString)), this, SLOT(updateWidget()));
|
||||
connect(ui->useThemeColorsCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateWidget()));
|
||||
connect(ui->checkedCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateWidget()));
|
||||
connect(ui->textColorToolButton, SIGNAL(pressed()), this, SLOT(selectColor()));
|
||||
connect(ui->disabledColorToolButton, SIGNAL(pressed()), this, SLOT(selectColor()));
|
||||
connect(ui->checkedColorToolButton, SIGNAL(pressed()), this, SLOT(selectColor()));
|
||||
connect(ui->uncheckedColorToolButton, SIGNAL(pressed()), this, SLOT(selectColor()));
|
||||
connect(m_checkBox, SIGNAL(toggled(bool)), this, SLOT(setupForm()));
|
||||
}
|
||||
|
||||
CheckBoxSettingsEditor::~CheckBoxSettingsEditor()
|
||||
|
@ -39,12 +52,63 @@ CheckBoxSettingsEditor::~CheckBoxSettingsEditor()
|
|||
|
||||
void CheckBoxSettingsEditor::setupForm()
|
||||
{
|
||||
switch (m_checkBox->labelPosition())
|
||||
{
|
||||
case QtMaterialCheckable::LabelPositionLeft:
|
||||
ui->labelPositionComboBox->setCurrentIndex(0);
|
||||
break;
|
||||
case QtMaterialCheckable::LabelPositionRight:
|
||||
ui->labelPositionComboBox->setCurrentIndex(1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
ui->disabledCheckBox->setChecked(!m_checkBox->isEnabled());
|
||||
ui->labelTextLineEdit->setText(m_checkBox->text());
|
||||
ui->useThemeColorsCheckBox->setChecked(m_checkBox->useThemeColors());
|
||||
ui->checkedCheckBox->setChecked(m_checkBox->isChecked());
|
||||
}
|
||||
|
||||
void CheckBoxSettingsEditor::updateWidget()
|
||||
{
|
||||
switch (ui->labelPositionComboBox->currentIndex())
|
||||
{
|
||||
case 0:
|
||||
m_checkBox->setLabelPosition(QtMaterialCheckable::LabelPositionLeft);
|
||||
break;
|
||||
case 1:
|
||||
m_checkBox->setLabelPosition(QtMaterialCheckable::LabelPositionRight);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
m_checkBox->setDisabled(ui->disabledCheckBox->isChecked());
|
||||
m_checkBox->setText(ui->labelTextLineEdit->text());
|
||||
m_checkBox->setUseThemeColors(ui->useThemeColorsCheckBox->isChecked());
|
||||
m_checkBox->setChecked(ui->checkedCheckBox->isChecked());
|
||||
}
|
||||
|
||||
void CheckBoxSettingsEditor::selectColor()
|
||||
{
|
||||
QColorDialog dialog;
|
||||
if (dialog.exec()) {
|
||||
QColor color = dialog.selectedColor();
|
||||
QString senderName = sender()->objectName();
|
||||
if ("textColorToolButton" == senderName) {
|
||||
m_checkBox->setTextColor(color);
|
||||
ui->textColorLineEdit->setText(color.name(QColor::HexRgb));
|
||||
} else if ("disabledColorToolButton" == senderName) {
|
||||
m_checkBox->setDisabledColor(color);
|
||||
ui->disabledColorLineEdit->setText(color.name(QColor::HexRgb));
|
||||
} else if ("checkedColorToolButton" == senderName) {
|
||||
m_checkBox->setCheckedColor(color);
|
||||
ui->checkedColorLineEdit->setText(color.name(QColor::HexRgb));
|
||||
} else if ("uncheckedColorToolButton" == senderName) {
|
||||
m_checkBox->setUncheckedColor(color);
|
||||
ui->uncheckedColorLineEdit->setText(color.name(QColor::HexRgb));
|
||||
}
|
||||
}
|
||||
setupForm();
|
||||
}
|
||||
|
|
|
@ -13,6 +13,163 @@
|
|||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="formLayoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>301</width>
|
||||
<height>281</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="disabledLabel">
|
||||
<property name="text">
|
||||
<string>Disabled</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QCheckBox" name="disabledCheckBox"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="labelPositionLabel">
|
||||
<property name="text">
|
||||
<string>Label position</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="labelPositionComboBox">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Left</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Right</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="labelTextLabel">
|
||||
<property name="text">
|
||||
<string>Label text</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="labelTextLineEdit"/>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="checkedLabel">
|
||||
<property name="text">
|
||||
<string>Checked</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QCheckBox" name="checkedCheckBox"/>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="useThemeColorsLabel">
|
||||
<property name="text">
|
||||
<string>Use theme colors</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QCheckBox" name="useThemeColorsCheckBox"/>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="checkedColorLabel">
|
||||
<property name="text">
|
||||
<string>Checked color</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="checkedColorLineEdit"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="checkedColorToolButton">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="uncheckedColorLabel">
|
||||
<property name="text">
|
||||
<string>Unchecked color</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="uncheckedColorLineEdit"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="uncheckedColorToolButton">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="textColorLabel">
|
||||
<property name="text">
|
||||
<string>Text color</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<widget class="QLabel" name="disabledColorLabel">
|
||||
<property name="text">
|
||||
<string>Disabled color</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="textColorLineEdit"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="textColorToolButton">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="8" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="disabledColorLineEdit"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="disabledColorToolButton">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
|
|
@ -287,4 +287,6 @@ void FlatButtonSettingsEditor::init()
|
|||
connect(ui->buttonTextLineEdit, SIGNAL(textChanged(QString)), this, SLOT(updateWidget()));
|
||||
connect(ui->defaultPresetPushButton, SIGNAL(pressed()), this, SLOT(applyDefaultPreset()));
|
||||
connect(ui->checkablePresetPushButton, SIGNAL(pressed()), this, SLOT(applyCheckablePreset()));
|
||||
connect(m_button, SIGNAL(toggled(bool)), this, SLOT(setupForm()));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue