diff --git a/mainwindow.cpp b/mainwindow.cpp index 63a447b..7f8f0c5 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -62,6 +62,8 @@ MainWindow::MainWindow(QWidget *parent) //FlatButtonSettingsEditor *fb = new FlatButtonSettingsEditor; //setCentralWidget(fb); + //return; + //RaisedButtonSettingsEditor *fb = new RaisedButtonSettingsEditor; //setCentralWidget(fb); diff --git a/qt-material-widgets.pro b/qt-material-widgets.pro index adccafb..3bad498 100644 --- a/qt-material-widgets.pro +++ b/qt-material-widgets.pro @@ -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 diff --git a/xx/qtmaterialcheckbox.cpp b/xx/qtmaterialcheckbox.cpp new file mode 100644 index 0000000..3978305 --- /dev/null +++ b/xx/qtmaterialcheckbox.cpp @@ -0,0 +1,85 @@ +#include "xx/qtmaterialcheckbox.h" +#include "xx/qtmaterialcheckbox_p.h" +#include +#include +#include +#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() +{ +} diff --git a/xx/qtmaterialcheckbox.h b/xx/qtmaterialcheckbox.h new file mode 100644 index 0000000..8436744 --- /dev/null +++ b/xx/qtmaterialcheckbox.h @@ -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 diff --git a/xx/qtmaterialcheckbox_p.h b/xx/qtmaterialcheckbox_p.h new file mode 100644 index 0000000..ea8d308 --- /dev/null +++ b/xx/qtmaterialcheckbox_p.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 diff --git a/xx/qtmaterialraisedbutton.cpp b/xx/qtmaterialraisedbutton.cpp index ea0ff98..ebfd9e6 100644 --- a/xx/qtmaterialraisedbutton.cpp +++ b/xx/qtmaterialraisedbutton.cpp @@ -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); } } diff --git a/xx/qtmaterialraisedbutton_p.h b/xx/qtmaterialraisedbutton_p.h index 61db21e..bd5177c 100644 --- a/xx/qtmaterialraisedbutton_p.h +++ b/xx/qtmaterialraisedbutton_p.h @@ -19,11 +19,7 @@ public: void init(); - QRect fabGeometry() const; - - void assignAnimationProperties(); - - QStateMachine *shadowMachine; + QStateMachine *shadowStateMachine; QState *normalState; QState *pressedState; QGraphicsDropShadowEffect *effect; diff --git a/xxlib/qtmaterialcheckable.cpp b/xxlib/qtmaterialcheckable.cpp index 028631f..eb4c0d2 100644 --- a/xxlib/qtmaterialcheckable.cpp +++ b/xxlib/qtmaterialcheckable.cpp @@ -3,6 +3,11 @@ #include #include #include +#include +#include +#include +#include +#include #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(); } diff --git a/xxlib/qtmaterialcheckable.h b/xxlib/qtmaterialcheckable.h index 4e2c32e..2f11428 100644 --- a/xxlib/qtmaterialcheckable.h +++ b/xxlib/qtmaterialcheckable.h @@ -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 d_ptr; private: diff --git a/xxlib/qtmaterialcheckable_internal.cpp b/xxlib/qtmaterialcheckable_internal.cpp index 8c2f50c..039d4be 100644 --- a/xxlib/qtmaterialcheckable_internal.cpp +++ b/xxlib/qtmaterialcheckable_internal.cpp @@ -1,13 +1,24 @@ #include "xxlib/qtmaterialcheckable_internal.h" #include +#include +#include +#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((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); + } } diff --git a/xxlib/qtmaterialcheckable_internal.h b/xxlib/qtmaterialcheckable_internal.h index 01abeb6..03f4d7e 100644 --- a/xxlib/qtmaterialcheckable_internal.h +++ b/xxlib/qtmaterialcheckable_internal.h @@ -5,6 +5,8 @@ #include #include +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) diff --git a/xxlib/qtmaterialcheckable_p.h b/xxlib/qtmaterialcheckable_p.h index 6f951fa..3a54848 100644 --- a/xxlib/qtmaterialcheckable_p.h +++ b/xxlib/qtmaterialcheckable_p.h @@ -2,8 +2,11 @@ #define QTMATERIALCHECKABLE_P_H #include +#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 diff --git a/yy/checkboxsettingseditor.cpp b/yy/checkboxsettingseditor.cpp index df0749c..386ab1d 100644 --- a/yy/checkboxsettingseditor.cpp +++ b/yy/checkboxsettingseditor.cpp @@ -2,12 +2,13 @@ #include #include //#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(); } diff --git a/yy/checkboxsettingsform.ui b/yy/checkboxsettingsform.ui index 9640184..842f9d0 100644 --- a/yy/checkboxsettingsform.ui +++ b/yy/checkboxsettingsform.ui @@ -13,6 +13,163 @@ Form + + + + 0 + 0 + 301 + 281 + + + + + + + Disabled + + + + + + + + + + Label position + + + + + + + + Left + + + + + Right + + + + + + + + Label text + + + + + + + + + + Checked + + + + + + + + + + Use theme colors + + + + + + + + + + Checked color + + + + + + + + + + + + ... + + + + + + + + + Unchecked color + + + + + + + + + + + + ... + + + + + + + + + Text color + + + + + + + Disabled color + + + + + + + + + + + + ... + + + + + + + + + + + + + + ... + + + + + + + diff --git a/yy/flatbuttonsettingseditor.cpp b/yy/flatbuttonsettingseditor.cpp index 7071e5c..e1077ac 100644 --- a/yy/flatbuttonsettingseditor.cpp +++ b/yy/flatbuttonsettingseditor.cpp @@ -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())); } +