|
@@ -140,43 +140,9 @@ void SwitchButton::paintEvent(QPaintEvent*)
|
|
|
|
|
|
void SwitchButton::mousePressEvent(QMouseEvent*)
|
|
void SwitchButton::mousePressEvent(QMouseEvent*)
|
|
{
|
|
{
|
|
- if (!_enabled)
|
|
|
|
- return;
|
|
|
|
-
|
|
|
|
- __btn_move->stop();
|
|
|
|
- __back_move->stop();
|
|
|
|
-
|
|
|
|
- __btn_move->setDuration(_duration);
|
|
|
|
- __back_move->setDuration(_duration);
|
|
|
|
-
|
|
|
|
- int hback = 20;
|
|
|
|
- QSize initial_size(hback, hback);
|
|
|
|
- QSize final_size(width() - 4, hback);
|
|
|
|
-
|
|
|
|
- int xi = 2;
|
|
|
|
- int y = 2;
|
|
|
|
- int xf = width() - 22;
|
|
|
|
-
|
|
|
|
- if (_value)
|
|
|
|
- {
|
|
|
|
- final_size = QSize(hback, hback);
|
|
|
|
- initial_size = QSize(width() - 4, hback);
|
|
|
|
-
|
|
|
|
- xi = xf;
|
|
|
|
- xf = 2;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- __btn_move->setStartValue(QPoint(xi, y));
|
|
|
|
- __btn_move->setEndValue(QPoint(xf, y));
|
|
|
|
-
|
|
|
|
- __back_move->setStartValue(initial_size);
|
|
|
|
- __back_move->setEndValue(final_size);
|
|
|
|
-
|
|
|
|
- __btn_move->start();
|
|
|
|
- __back_move->start();
|
|
|
|
-
|
|
|
|
// Assigning new current value
|
|
// Assigning new current value
|
|
_value = !_value;
|
|
_value = !_value;
|
|
|
|
+ _update();
|
|
emit valueChanged(_value);
|
|
emit valueChanged(_value);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -204,14 +170,13 @@ void SwitchButton::setDuration(int time)
|
|
|
|
|
|
void SwitchButton::setValue(bool flag)
|
|
void SwitchButton::setValue(bool flag)
|
|
{
|
|
{
|
|
- if (flag == value())
|
|
|
|
- return;
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
|
|
+ if (flag == value()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
_value = flag;
|
|
_value = flag;
|
|
_update();
|
|
_update();
|
|
- setEnabled(_enabled);
|
|
|
|
- }
|
|
|
|
|
|
+ repaint();
|
|
}
|
|
}
|
|
|
|
|
|
bool SwitchButton::value() const
|
|
bool SwitchButton::value() const
|
|
@@ -221,20 +186,41 @@ bool SwitchButton::value() const
|
|
|
|
|
|
void SwitchButton::_update()
|
|
void SwitchButton::_update()
|
|
{
|
|
{
|
|
- int hback = 20;
|
|
|
|
- QSize final_size(width() - 4, hback);
|
|
|
|
|
|
+ if (!_enabled) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
|
|
- int y = 2;
|
|
|
|
- int xf = width() - 22;
|
|
|
|
|
|
+ __btn_move->stop();
|
|
|
|
+ __back_move->stop();
|
|
|
|
|
|
- if (_value)
|
|
|
|
- {
|
|
|
|
- final_size = QSize(hback, hback);
|
|
|
|
- xf = 2;
|
|
|
|
- }
|
|
|
|
|
|
+ __btn_move->setDuration(_duration);
|
|
|
|
+ __back_move->setDuration(_duration);
|
|
|
|
+
|
|
|
|
+ int hback = 20;
|
|
|
|
+ QSize initial_size(hback, hback);
|
|
|
|
+ QSize final_size(width() - 4, hback);
|
|
|
|
+
|
|
|
|
+ int xi = 2;
|
|
|
|
+ int y = 2;
|
|
|
|
+ int xf = width() - 22;
|
|
|
|
+
|
|
|
|
+ if (!_value)
|
|
|
|
+ {
|
|
|
|
+ final_size = QSize(hback, hback);
|
|
|
|
+ initial_size = QSize(width() - 4, hback);
|
|
|
|
+
|
|
|
|
+ xi = xf;
|
|
|
|
+ xf = 2;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ __btn_move->setStartValue(QPoint(xi, y));
|
|
|
|
+ __btn_move->setEndValue(QPoint(xf, y));
|
|
|
|
+
|
|
|
|
+ __back_move->setStartValue(initial_size);
|
|
|
|
+ __back_move->setEndValue(final_size);
|
|
|
|
|
|
- _circle->move(QPoint(xf, y));
|
|
|
|
- _background->resize(final_size);
|
|
|
|
|
|
+ __btn_move->start();
|
|
|
|
+ __back_move->start();
|
|
}
|
|
}
|
|
|
|
|
|
SwitchButton::SwitchBackground::SwitchBackground(QWidget* parent, QColor color, bool rect)
|
|
SwitchButton::SwitchBackground::SwitchBackground(QWidget* parent, QColor color, bool rect)
|