remove old commented code
This commit is contained in:
parent
00662865f5
commit
e51251408b
|
@ -1,9 +1,8 @@
|
|||
#include "toggle.h"
|
||||
#include <QPainter>
|
||||
#include <QState>
|
||||
#include <QEventTransition>
|
||||
#include <QSignalTransition>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QDebug>
|
||||
#include "lib/rippleoverlay.h"
|
||||
#include "toggle_p.h"
|
||||
|
||||
|
@ -19,6 +18,7 @@ void TogglePrivate::init()
|
|||
{
|
||||
Q_Q(Toggle);
|
||||
|
||||
q->setCheckable(true);
|
||||
q->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
||||
|
||||
QState *offState = new QState;
|
||||
|
@ -29,55 +29,31 @@ void TogglePrivate::init()
|
|||
|
||||
machine.setInitialState(offState);
|
||||
|
||||
QEventTransition *transition;
|
||||
QSignalTransition *transition;
|
||||
QPropertyAnimation *animation;
|
||||
|
||||
//
|
||||
|
||||
transition = new QEventTransition(q, QEvent::MouseButtonPress);
|
||||
transition = new QSignalTransition(thumb, SIGNAL(clicked()));
|
||||
transition->setTargetState(onState);
|
||||
offState->addTransition(transition);
|
||||
|
||||
animation = new QPropertyAnimation;
|
||||
animation->setPropertyName("shift");
|
||||
animation->setTargetObject(thumb);
|
||||
animation->setDuration(200);
|
||||
animation->setDuration(150);
|
||||
transition->addAnimation(animation);
|
||||
|
||||
//
|
||||
|
||||
transition = new QEventTransition(q, QEvent::MouseButtonDblClick);
|
||||
transition->setTargetState(onState);
|
||||
offState->addTransition(transition);
|
||||
|
||||
animation = new QPropertyAnimation;
|
||||
animation->setPropertyName("shift");
|
||||
animation->setTargetObject(thumb);
|
||||
animation->setDuration(200);
|
||||
transition->addAnimation(animation);
|
||||
|
||||
//
|
||||
|
||||
transition = new QEventTransition(q, QEvent::MouseButtonPress);
|
||||
transition = new QSignalTransition(thumb, SIGNAL(clicked()));
|
||||
transition->setTargetState(offState);
|
||||
onState->addTransition(transition);
|
||||
|
||||
animation = new QPropertyAnimation;
|
||||
animation->setPropertyName("shift");
|
||||
animation->setTargetObject(thumb);
|
||||
animation->setDuration(200);
|
||||
transition->addAnimation(animation);
|
||||
|
||||
//
|
||||
|
||||
transition = new QEventTransition(q, QEvent::MouseButtonDblClick);
|
||||
transition->setTargetState(offState);
|
||||
onState->addTransition(transition);
|
||||
|
||||
animation = new QPropertyAnimation;
|
||||
animation->setPropertyName("shift");
|
||||
animation->setTargetObject(thumb);
|
||||
animation->setDuration(200);
|
||||
animation->setDuration(150);
|
||||
transition->addAnimation(animation);
|
||||
|
||||
//
|
||||
|
@ -199,201 +175,3 @@ void Toggle::paintEvent(QPaintEvent *event)
|
|||
painter.drawRoundedRect(r.adjusted(4, 14, -4, -14), w/2-4, w/2-4);
|
||||
}
|
||||
}
|
||||
|
||||
//#include <QAbstractButton>
|
||||
//#include <QPropertyAnimation>
|
||||
//#include <QMouseEvent>
|
||||
//#include <QEvent>
|
||||
//#include <QMouseEvent>
|
||||
//#include <QPainter>
|
||||
//#include "toggle.h"
|
||||
//#include "../lib/rippleoverlay.h"
|
||||
//#include "../lib/customshadoweffect.h"
|
||||
//
|
||||
//Thumb::Thumb(Toggle *parent)
|
||||
// : QWidget(parent),
|
||||
// _toggle(parent),
|
||||
// _animation(new QPropertyAnimation(this)),
|
||||
// _progress(1),
|
||||
// _offset(0)
|
||||
//{
|
||||
// parent->installEventFilter(this);
|
||||
//
|
||||
// _animation->setPropertyName("progress");
|
||||
// _animation->setTargetObject(this);
|
||||
// _animation->setDuration(350);
|
||||
// _animation->setStartValue(1);
|
||||
// _animation->setEndValue(0);
|
||||
//}
|
||||
//
|
||||
//Thumb::~Thumb()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//void Thumb::setProgress(qreal progress)
|
||||
//{
|
||||
// if (_progress == progress)
|
||||
// return;
|
||||
//
|
||||
// _progress = progress;
|
||||
//
|
||||
// const QSize s(Qt::Horizontal == _toggle->orientation()
|
||||
// ? size() : size().transposed());
|
||||
// setOffset(progress*static_cast<qreal>(s.width()-s.height()));
|
||||
//
|
||||
// _toggle->updateOverlayGeometry();
|
||||
// update();
|
||||
//}
|
||||
//
|
||||
//bool Thumb::eventFilter(QObject *obj, QEvent *event)
|
||||
//{
|
||||
// const QEvent::Type type = event->type();
|
||||
// if (QEvent::Resize == type || QEvent::Move == type) {
|
||||
// setGeometry(parentWidget()->rect().adjusted(8, 8, -8, -8));
|
||||
// } else if (QEvent::MouseButtonRelease == type) {
|
||||
// return true;
|
||||
// }
|
||||
// return QWidget::eventFilter(obj, event);
|
||||
//}
|
||||
//
|
||||
//void Thumb::mouseReleaseEvent(QMouseEvent *event)
|
||||
//{
|
||||
// const bool checked = _toggle->isChecked();
|
||||
//
|
||||
// _toggle->setChecked(!checked);
|
||||
//
|
||||
// if (QAbstractAnimation::Running != _animation->state()) {
|
||||
// _animation->setEasingCurve(checked
|
||||
// ? QEasingCurve::OutCubic
|
||||
// : QEasingCurve::InCubic);
|
||||
// }
|
||||
//
|
||||
// _animation->setDirection(checked
|
||||
// ? QAbstractAnimation::Forward
|
||||
// : QAbstractAnimation::Backward);
|
||||
// _animation->start();
|
||||
//
|
||||
// emit clicked();
|
||||
//
|
||||
// QWidget::mouseReleaseEvent(event);
|
||||
//}
|
||||
//
|
||||
//void Thumb::paintEvent(QPaintEvent *event)
|
||||
//{
|
||||
// Q_UNUSED(event)
|
||||
//
|
||||
// QPainter painter(this);
|
||||
// painter.setRenderHint(QPainter::Antialiasing);
|
||||
//
|
||||
// QBrush brush;
|
||||
// brush.setStyle(Qt::SolidPattern);
|
||||
// brush.setColor(Qt::white);
|
||||
// painter.setBrush(brush);
|
||||
// painter.setPen(Qt::NoPen);
|
||||
//
|
||||
// if (Qt::Horizontal == _toggle->orientation()) {
|
||||
// const int s = height()-10;
|
||||
// painter.drawEllipse(5+_offset, 5, s, s);
|
||||
// } else {
|
||||
// const int s = width()-10;
|
||||
// painter.drawEllipse(5, 5+_offset, s, s);
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//void Toggle::updateOverlayGeometry()
|
||||
//{
|
||||
// const int offset = _thumb->offset();
|
||||
// if (Qt::Horizontal == _orientation) {
|
||||
// _overlay->setGeometry(geometry().adjusted(-10+offset, -20, 10+offset, 20));
|
||||
// } else {
|
||||
// _overlay->setGeometry(geometry().adjusted(-10, -20+offset, 10, 20+offset));
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//Toggle::Toggle(QWidget *parent)
|
||||
// : QAbstractButton(parent),
|
||||
// _thumb(new Thumb(this)),
|
||||
// _overlay(new RippleOverlay(parent)),
|
||||
// _orientation(Qt::Horizontal)
|
||||
//{
|
||||
// setCheckable(true);
|
||||
// setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
||||
//
|
||||
// CustomShadowEffect *effect = new CustomShadowEffect;
|
||||
// effect->setDistance(0);
|
||||
// effect->setBlurRadius(6);
|
||||
// effect->setColor(QColor(0, 0, 0, 100));
|
||||
//
|
||||
// _thumb->setGraphicsEffect(effect);
|
||||
// _thumb->installEventFilter(this);
|
||||
//
|
||||
// connect(_thumb, SIGNAL(clicked()), this, SLOT(addRipple()));
|
||||
//}
|
||||
//
|
||||
//Toggle::~Toggle()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//QSize Toggle::sizeHint() const
|
||||
//{
|
||||
// return Qt::Horizontal == _orientation
|
||||
// ? QSize(64, 48)
|
||||
// : QSize(48, 64);
|
||||
//}
|
||||
//
|
||||
//void Toggle::setOrientation(Qt::Orientation orientation)
|
||||
//{
|
||||
// if (_orientation == orientation)
|
||||
// return;
|
||||
// _orientation = orientation;
|
||||
//}
|
||||
//
|
||||
//void Toggle::addRipple()
|
||||
//{
|
||||
// if (Qt::Horizontal == _orientation) {
|
||||
// const int d = height()/2;
|
||||
// const int w = _thumb->height()/2+10;
|
||||
// _overlay->addRipple(QPoint(10+d, 20+d), w);
|
||||
// } else {
|
||||
// const int d = width()/2;
|
||||
// const int w = _thumb->width()/2+10;
|
||||
// _overlay->addRipple(QPoint(10+d, 20+d), w);
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//bool Toggle::event(QEvent *event)
|
||||
//{
|
||||
// const QEvent::Type type = event->type();
|
||||
// if (QEvent::ParentChange == type && parentWidget()) {
|
||||
// _overlay->setParent(parentWidget());
|
||||
// } else if (QEvent::Resize == type || QEvent::Move == type) {
|
||||
// _overlay->setGeometry(geometry().adjusted(-10, -20, 10, 20));
|
||||
// }
|
||||
// return QAbstractButton::event(event);
|
||||
//}
|
||||
//
|
||||
//void Toggle::paintEvent(QPaintEvent *event)
|
||||
//{
|
||||
// Q_UNUSED(event)
|
||||
//
|
||||
// QPainter painter(this);
|
||||
// painter.setRenderHint(QPainter::Antialiasing);
|
||||
//
|
||||
// QBrush brush;
|
||||
// brush.setColor(QColor(180, 180, 180));
|
||||
// brush.setStyle(Qt::SolidPattern);
|
||||
// painter.setBrush(brush);
|
||||
//
|
||||
// painter.setPen(Qt::NoPen);
|
||||
//
|
||||
// if (Qt::Horizontal == _orientation) {
|
||||
// const int h = height()/2;
|
||||
// const QRect r(0, h/2, width(), h);
|
||||
// painter.drawRoundedRect(r.adjusted(14, 4, -14, -4), h/2-4, h/2-4);
|
||||
// } else {
|
||||
// const int w = width()/2;
|
||||
// const QRect r(w/2, 0, w, height());
|
||||
// painter.drawRoundedRect(r.adjusted(4, 14, -4, -14), w/2-4, w/2-4);
|
||||
// }
|
||||
//}
|
||||
//
|
||||
|
|
|
@ -35,76 +35,3 @@ private:
|
|||
};
|
||||
|
||||
#endif // TOGGLE_H
|
||||
|
||||
//#ifndef TOGGLE_H
|
||||
//#define TOGGLE_H
|
||||
//
|
||||
//#include <QAbstractButton>
|
||||
//
|
||||
//class QPropertyAnimation;
|
||||
//class RippleOverlay;
|
||||
//class Toggle;
|
||||
//
|
||||
//class Thumb : public QWidget
|
||||
//{
|
||||
// Q_OBJECT
|
||||
//
|
||||
// Q_PROPERTY(qreal progress WRITE setProgress READ progress)
|
||||
//
|
||||
//public:
|
||||
// explicit Thumb(Toggle *parent);
|
||||
// ~Thumb();
|
||||
//
|
||||
// void setProgress(qreal progress);
|
||||
// inline qreal progress() const { return _progress; }
|
||||
//
|
||||
// inline void setOffset(int offset) { _offset = offset; }
|
||||
// inline int offset() const { return _offset; }
|
||||
//
|
||||
//signals:
|
||||
// void clicked();
|
||||
//
|
||||
//protected:
|
||||
// bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE;
|
||||
// void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
||||
// void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
||||
//
|
||||
//private:
|
||||
// Toggle *const _toggle;
|
||||
// QPropertyAnimation *const _animation;
|
||||
// qreal _progress;
|
||||
// int _offset;
|
||||
//};
|
||||
//
|
||||
//class Toggle : public QAbstractButton
|
||||
//{
|
||||
// Q_OBJECT
|
||||
//
|
||||
// friend class Thumb;
|
||||
//
|
||||
// void updateOverlayGeometry();
|
||||
//
|
||||
//public:
|
||||
// explicit Toggle(QWidget *parent = 0);
|
||||
// ~Toggle();
|
||||
//
|
||||
// QSize sizeHint() const;
|
||||
//
|
||||
// inline Qt::Orientation orientation() const { return _orientation; }
|
||||
// void setOrientation(Qt::Orientation orientation);
|
||||
//
|
||||
//protected slots:
|
||||
// void addRipple();
|
||||
//
|
||||
//protected:
|
||||
// bool event(QEvent *event) Q_DECL_OVERRIDE;
|
||||
// void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
||||
//
|
||||
//private:
|
||||
// Thumb *const _thumb;
|
||||
// RippleOverlay *const _overlay;
|
||||
// Qt::Orientation _orientation;
|
||||
//};
|
||||
//
|
||||
//#endif // TOGGLE_H
|
||||
//
|
||||
|
|
|
@ -45,9 +45,7 @@ bool Thumb::eventFilter(QObject *obj, QEvent *event)
|
|||
const QEvent::Type type = event->type();
|
||||
if (QEvent::Resize == type || QEvent::Move == type) {
|
||||
setGeometry(parentWidget()->rect().adjusted(8, 8, -8, -8));
|
||||
} //else if (QEvent::MouseButtonRelease == type) {
|
||||
//return true;
|
||||
//}
|
||||
}
|
||||
return QWidget::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue