qtmaterialradiobutton.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include "qtmaterialradiobutton.h"
  2. #include "qtmaterialradiobutton_p.h"
  3. #include <QStateMachine>
  4. #include <QState>
  5. #include <QPropertyAnimation>
  6. #include <QColor>
  7. #include "lib/qtmaterialcheckable_internal.h"
  8. /*!
  9. * \class QtMaterialRadioButtonPrivate
  10. * \internal
  11. */
  12. QtMaterialRadioButtonPrivate::QtMaterialRadioButtonPrivate(QtMaterialRadioButton *q)
  13. : QtMaterialCheckablePrivate(q)
  14. {
  15. }
  16. QtMaterialRadioButtonPrivate::~QtMaterialRadioButtonPrivate()
  17. {
  18. }
  19. void QtMaterialRadioButtonPrivate::init()
  20. {
  21. Q_Q(QtMaterialRadioButton);
  22. q->setAutoExclusive(true);
  23. q->setCheckedIcon(QIcon(":/icons/icons/toggle/svg/production/ic_radio_button_checked_24px.svg"));
  24. q->setUncheckedIcon(QIcon(":/icons/icons/toggle/svg/production/ic_radio_button_unchecked_24px.svg"));
  25. uncheckedState->assignProperty(checkedIcon, "iconSize", 0);
  26. uncheckedState->assignProperty(uncheckedIcon, "iconSize", 24);
  27. disabledUncheckedState->assignProperty(checkedIcon, "iconSize", 0);
  28. disabledUncheckedState->assignProperty(uncheckedIcon, "iconSize", 24);
  29. checkedState->assignProperty(uncheckedIcon, "iconSize", 0);
  30. checkedState->assignProperty(checkedIcon, "iconSize", 24);
  31. disabledCheckedState->assignProperty(uncheckedIcon, "iconSize", 0);
  32. disabledCheckedState->assignProperty(checkedIcon, "iconSize", 24);
  33. uncheckedState->assignProperty(checkedIcon, "opacity", 0);
  34. uncheckedState->assignProperty(uncheckedIcon, "opacity", 1);
  35. checkedState->assignProperty(uncheckedIcon, "opacity", 0);
  36. checkedState->assignProperty(checkedIcon, "opacity", 1);
  37. checkedIcon->setIconSize(0);
  38. //
  39. checkedState->assignProperty(checkedIcon, "color", q->checkedColor());
  40. checkedState->assignProperty(uncheckedIcon, "color", q->uncheckedColor());
  41. uncheckedState->assignProperty(uncheckedIcon, "color", q->uncheckedColor());
  42. QPropertyAnimation *animation;
  43. animation = new QPropertyAnimation(checkedIcon, "iconSize", q);
  44. animation->setDuration(250);
  45. stateMachine->addDefaultAnimation(animation);
  46. animation = new QPropertyAnimation(uncheckedIcon, "iconSize", q);
  47. animation->setDuration(250);
  48. stateMachine->addDefaultAnimation(animation);
  49. animation = new QPropertyAnimation(uncheckedIcon, "opacity", q);
  50. animation->setDuration(250);
  51. stateMachine->addDefaultAnimation(animation);
  52. animation = new QPropertyAnimation(checkedIcon, "opacity", q);
  53. animation->setDuration(250);
  54. stateMachine->addDefaultAnimation(animation);
  55. }
  56. /*!
  57. * \class QtMaterialRadioButton
  58. */
  59. QtMaterialRadioButton::QtMaterialRadioButton(QWidget *parent)
  60. : QtMaterialCheckable(*new QtMaterialRadioButtonPrivate(this), parent)
  61. {
  62. d_func()->init();
  63. }
  64. QtMaterialRadioButton::~QtMaterialRadioButton()
  65. {
  66. }
  67. void QtMaterialRadioButton::setupProperties()
  68. {
  69. QtMaterialCheckable::setupProperties();
  70. Q_D(QtMaterialRadioButton);
  71. d->checkedState->assignProperty(d->checkedIcon, "color", checkedColor());
  72. d->checkedState->assignProperty(d->uncheckedIcon, "color", uncheckedColor());
  73. d->uncheckedState->assignProperty(d->uncheckedIcon, "color", uncheckedColor());
  74. }