├── README.md ├── bounceindicator.cpp ├── bounceindicator.h ├── changeshapecanvas.cpp ├── changeshapecanvas.h ├── changeshapecanvas.ui ├── circle.cpp ├── circle.h ├── colorball.cpp ├── colorball.h ├── eventfilter.cpp ├── eventfilter.h ├── explodeanimation.cpp ├── explodeanimation.h ├── explodeanimation.ui ├── fadingtoolbutton.cpp ├── fadingtoolbutton.h ├── flowlayout.cpp ├── flowlayout.h ├── flyawayanimation.cpp ├── flyawayanimation.h ├── flyawayanimation.ui ├── frame.cpp ├── frame.h ├── graphicsellipseobject.cpp ├── graphicsellipseobject.h ├── graphicslineobject.cpp ├── graphicslineobject.h ├── graphicspathobject.cpp ├── graphicspathobject.h ├── highlighwindow.cpp ├── highlighwindow.h ├── imagecarousel.cpp ├── imagecarousel.h ├── images.qrc ├── images ├── bug.png └── navigate.png ├── inputdialog.cpp ├── inputdialog.h ├── inputdialog.ui ├── layoutwindowsanimation.cpp ├── layoutwindowsanimation.h ├── layoutwindowsanimation.ui ├── lednumber.cpp ├── lednumber.h ├── lednumberanimation.cpp ├── lednumberanimation.h ├── lednumberanimation.ui ├── ledunit.cpp ├── ledunit.h ├── main.cpp ├── resizeAnimation.pro ├── scrollanimationwindow.cpp ├── scrollanimationwindow.h ├── scrollanimationwindow.ui ├── shadowwindow.cpp ├── shadowwindow.h ├── slidemenuanimation.cpp ├── slidemenuanimation.h ├── slidetextanimation.cpp ├── slidetextanimation.h ├── slidetextanimation.ui ├── slidewidgetcontainer.cpp ├── slidewidgetcontainer.h ├── tableselectionanimation.cpp ├── tableselectionanimation.h ├── tableselectionanimation.ui ├── tagwidget.cpp ├── tagwidget.h ├── tstflowlayout.cpp ├── tstflowlayout.h ├── tstflowlayout.ui ├── tsttagwidget.cpp ├── tsttagwidget.h ├── tsttagwidget.ui ├── widget.cpp ├── widget.h └── widget.ui /README.md: -------------------------------------------------------------------------------- 1 | #resizeAnimation 2 | ##Shaking 3 | Shaking animation 4 | ##Table animation 5 | Table animation 6 | ##Flash animation 7 | Flash animation 8 | ##Flowlayout animation 9 | Flowlayout animation 10 | ##Slide text animation 11 | Slide text animation 12 | ##Slide widget animation 13 | Slide widget animation 14 | -------------------------------------------------------------------------------- /bounceindicator.cpp: -------------------------------------------------------------------------------- 1 | #include "bounceindicator.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | inline QColor randomColor() 9 | { 10 | srand(QTime::currentTime().msecsSinceStartOfDay()); 11 | return QColor(qrand() % 255, qrand() % 255, qrand() % 255); 12 | } 13 | 14 | static const QSize ItemSize = QSize(30, 30); 15 | static const int TopMargin = 10; 16 | static const int BounceDuration = 200; 17 | static const QEasingCurve::Type EasingCurve = QEasingCurve::Linear; 18 | 19 | class BounceItem : public QWidget 20 | { 21 | Q_OBJECT 22 | public: 23 | explicit BounceItem(QWidget* parent = nullptr); 24 | void setColor(const QColor& clr) { m_color = clr; update(); } 25 | QColor color() const { return m_color; } 26 | 27 | protected: 28 | void paintEvent(QPaintEvent* event); 29 | 30 | private: 31 | QColor m_color = Qt::blue; 32 | }; 33 | 34 | BounceItem::BounceItem(QWidget *parent) : QWidget(parent) 35 | { 36 | setFixedSize(ItemSize); 37 | } 38 | 39 | void BounceItem::paintEvent(QPaintEvent *event) 40 | { 41 | Q_UNUSED(event) 42 | QPainter painter(this); 43 | painter.setRenderHints(QPainter::Antialiasing); 44 | painter.setPen(Qt::NoPen); 45 | painter.setBrush(QBrush(m_color)); 46 | painter.drawEllipse(rect()); 47 | } 48 | 49 | class BounceIndicatorPrivate 50 | { 51 | public: 52 | void layoutItems(); 53 | void makeBounce(int index); 54 | 55 | BounceIndicator* q_ptr; 56 | bool started = false; 57 | QList items; 58 | QPropertyAnimation* headAnimation = nullptr; 59 | QParallelAnimationGroup* parallelAnimGroup = nullptr; 60 | }; 61 | 62 | void BounceIndicatorPrivate::layoutItems() 63 | { 64 | int itemCount = items.size(); 65 | static const int ItemSpace = 30; 66 | int horSpace = ItemSpace; 67 | for (int i = 0; i < items.size(); ++i) { 68 | items.at(i)->move(horSpace, (q_ptr->height() / 2) - (ItemSize.height() / 2)); 69 | horSpace += ItemSize.width() + ItemSpace; 70 | } 71 | } 72 | 73 | void BounceIndicatorPrivate::makeBounce(int index) 74 | { 75 | if (index >= items.size()) 76 | return; 77 | 78 | BounceItem* item = items.at(index); 79 | int x = item->x(); 80 | int end = 20; 81 | int start = 50; 82 | 83 | QPropertyAnimation* anim = new QPropertyAnimation(item, "pos"); 84 | anim->setEasingCurve(EasingCurve); 85 | anim->setDuration(BounceDuration); 86 | anim->setStartValue(QPoint(x, start)); 87 | anim->setEndValue(QPoint(x, end)); 88 | anim->start(); 89 | 90 | if (index == 0 && !headAnimation) 91 | headAnimation = anim; 92 | 93 | q_ptr->connect(anim, &QAbstractAnimation::finished, [this, item, x, index, anim, start, end] () { 94 | QPropertyAnimation* reverseAnim = new QPropertyAnimation(item, "pos"); 95 | reverseAnim->setEasingCurve(EasingCurve); 96 | reverseAnim->setDuration(BounceDuration); 97 | reverseAnim->setStartValue(QPoint(x, end)); 98 | reverseAnim->setEndValue(QPoint(x, start)); 99 | reverseAnim->start(); 100 | 101 | makeBounce(index + 1); 102 | 103 | if (index == (items.size() - 1)) 104 | q_ptr->connect(reverseAnim, SIGNAL(finished()), headAnimation, SLOT(start())); 105 | 106 | q_ptr->connect(reverseAnim, &QAbstractAnimation::finished, [anim] () { 107 | // anim->start(); 108 | }); 109 | }); 110 | } 111 | 112 | BounceIndicator::BounceIndicator(QWidget *parent) : QWidget(parent) 113 | { 114 | d_ptr = new BounceIndicatorPrivate; 115 | d_ptr->q_ptr = this; 116 | setNumberOfItems(7); 117 | setWindowFlags(Qt::FramelessWindowHint); 118 | setAttribute(Qt::WA_TranslucentBackground); 119 | } 120 | 121 | BounceIndicator::~BounceIndicator() 122 | { 123 | delete d_ptr; 124 | } 125 | 126 | void BounceIndicator::setAnimationStarted(bool start) 127 | { 128 | if (start) { 129 | 130 | if (d_ptr->items.isEmpty()) 131 | return; 132 | 133 | int startIndex = 0; 134 | d_ptr->makeBounce(startIndex); 135 | 136 | } else { 137 | 138 | } 139 | } 140 | 141 | bool BounceIndicator::animationStarted() const 142 | { 143 | return false; 144 | } 145 | 146 | void BounceIndicator::setNumberOfItems(int number) 147 | { 148 | if (d_ptr->items.size() != number) { 149 | int delta = number - d_ptr->items.size(); 150 | if (delta > 0) { 151 | for (int i = 0; i < delta; ++i) { 152 | BounceItem* item = new BounceItem(this); 153 | item->setColor(randomColor()); 154 | d_ptr->items.append(item); 155 | } 156 | } else { 157 | for (int i = 0 ; i < qAbs(delta); ++i) { 158 | BounceItem* bi = d_ptr->items.takeLast(); 159 | delete bi; 160 | d_ptr->items.pop_back(); 161 | } 162 | } 163 | 164 | d_ptr->layoutItems(); 165 | } 166 | } 167 | 168 | int BounceIndicator::numberOfItems() const 169 | { 170 | return d_ptr->items.size(); 171 | } 172 | 173 | QSize BounceIndicator::sizeHint() const 174 | { 175 | return QSize(300, 80); 176 | } 177 | 178 | void BounceIndicator::resizeEvent(QResizeEvent* event) 179 | { 180 | QWidget::resizeEvent(event); 181 | d_ptr->layoutItems(); 182 | } 183 | 184 | #include "bounceindicator.moc" 185 | -------------------------------------------------------------------------------- /bounceindicator.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNCEINDICATOR_H 2 | #define BOUNCEINDICATOR_H 3 | 4 | #include 5 | 6 | class BounceIndicatorPrivate; 7 | class BounceIndicator : public QWidget 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit BounceIndicator(QWidget *parent = 0); 12 | ~BounceIndicator(); 13 | 14 | public slots: 15 | void setAnimationStarted(bool start); 16 | bool animationStarted() const; 17 | 18 | void setNumberOfItems(int number); 19 | int numberOfItems() const; 20 | 21 | protected: 22 | QSize sizeHint() const; 23 | void resizeEvent(QResizeEvent* event); 24 | 25 | private: 26 | BounceIndicatorPrivate* d_ptr; 27 | Q_DISABLE_COPY(BounceIndicator) 28 | }; 29 | 30 | #endif // BOUNCEINDICATOR_H 31 | -------------------------------------------------------------------------------- /changeshapecanvas.cpp: -------------------------------------------------------------------------------- 1 | #include "changeshapecanvas.h" 2 | #include "ui_changeshapecanvas.h" 3 | #include "graphicspathobject.h" 4 | #include "graphicslineobject.h" 5 | #include "graphicsellipseobject.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | inline QColor randomColor() 14 | { 15 | return QColor(qrand() % 255, qrand() % 255, qrand() % 255); 16 | } 17 | 18 | ChangeShapeCanvas::ChangeShapeCanvas(QWidget *parent) : 19 | QWidget(parent), 20 | m_ui(new Ui::ChangeShapeCanvas) 21 | { 22 | m_ui->setupUi(this); 23 | init(); 24 | } 25 | 26 | ChangeShapeCanvas::~ChangeShapeCanvas() 27 | { 28 | delete m_ui; 29 | } 30 | 31 | void ChangeShapeCanvas::resizeEvent(QResizeEvent *event) 32 | { 33 | QWidget::resizeEvent(event); 34 | m_scene->setSceneRect(rect()); 35 | } 36 | 37 | void ChangeShapeCanvas::init() 38 | { 39 | m_view = new QGraphicsView(this); 40 | m_ui->canvasLayout->addWidget(m_view); 41 | 42 | m_scene = new QGraphicsScene(this); 43 | m_view->setScene(m_scene); 44 | 45 | QPainterPath circle; 46 | circle.addEllipse(QRect(QPoint(0, 0), QSize(100, 100))); 47 | 48 | QPainterPath rect; 49 | circle.addRect(QRect(QPoint(100, 100), QSize(300, 400))); 50 | 51 | m_pathObj = new GraphicsPathObject(this); 52 | m_scene->addItem(m_pathObj); 53 | 54 | QPropertyAnimation* anim = new QPropertyAnimation(m_pathObj, "path"); 55 | anim->setEasingCurve(QEasingCurve::OutCubic); 56 | anim->setDuration(1000); 57 | anim->setStartValue(QVariant::fromValue(circle)); 58 | anim->setEndValue(QVariant::fromValue(rect)); 59 | anim->start(QAbstractAnimation::DeleteWhenStopped); 60 | } 61 | 62 | void ChangeShapeCanvas::on_addLineButton_clicked() 63 | { 64 | QPoint initPoint(m_ui->point1XSpinBox->value(), m_ui->point1YSpinBox->value()); 65 | QPoint endPoint(m_ui->point2XSpinBox->value(), m_ui->point2YSpinBox->value()); 66 | 67 | GraphicsLineObject* line = new GraphicsLineObject; 68 | line->setFlag(QGraphicsItem::ItemIsMovable); 69 | line->setFlag(QGraphicsItem::ItemIsSelectable); 70 | line->setPoint1(initPoint); 71 | line->setPoint2(initPoint); 72 | line->setPen(QPen(randomColor(), 2)); 73 | m_scene->addItem(line); 74 | 75 | QPropertyAnimation* anim = new QPropertyAnimation(line, "point2"); 76 | anim->setEasingCurve(QEasingCurve::OutCubic); 77 | anim->setDuration(500); 78 | anim->setStartValue(QVariant::fromValue(initPoint)); 79 | anim->setEndValue(QVariant::fromValue(endPoint)); 80 | anim->start(QAbstractAnimation::DeleteWhenStopped); 81 | } 82 | 83 | void ChangeShapeCanvas::on_addPieButton_clicked() 84 | { 85 | QRect pieRect(QPoint(10, 10), QPoint(300, 300)); 86 | 87 | GraphicsEllipseObject* ellipse = new GraphicsEllipseObject(); 88 | ellipse->setFlag(QGraphicsItem::ItemIsMovable); 89 | ellipse->setFlag(QGraphicsItem::ItemIsSelectable); 90 | ellipse->setRect(pieRect); 91 | ellipse->setStartAngle(m_ui->startAngleSpinBox->value() * 16); 92 | ellipse->setBrush(QBrush(randomColor())); 93 | m_scene->addItem(ellipse); 94 | 95 | QPropertyAnimation* anim = new QPropertyAnimation(ellipse, "spanAngle"); 96 | anim->setEasingCurve(QEasingCurve::OutCubic); 97 | anim->setDuration(500); 98 | anim->setStartValue(0); 99 | anim->setEndValue(m_ui->spanAngleSpinBox->value() * 16); 100 | anim->start(QAbstractAnimation::DeleteWhenStopped); 101 | } 102 | -------------------------------------------------------------------------------- /changeshapecanvas.h: -------------------------------------------------------------------------------- 1 | #ifndef CHANGESHAPECANVAS_H 2 | #define CHANGESHAPECANVAS_H 3 | 4 | #include 5 | 6 | namespace Ui 7 | { 8 | class ChangeShapeCanvas; 9 | } 10 | 11 | class QGraphicsView; 12 | class QGraphicsScene; 13 | class GraphicsPathObject; 14 | class ChangeShapeCanvas : public QWidget 15 | { 16 | Q_OBJECT 17 | public: 18 | explicit ChangeShapeCanvas(QWidget *parent = 0); 19 | ~ChangeShapeCanvas(); 20 | 21 | protected: 22 | void resizeEvent(QResizeEvent *event); 23 | 24 | private slots: 25 | void on_addLineButton_clicked(); 26 | void on_addPieButton_clicked(); 27 | 28 | private: 29 | void init(); 30 | 31 | private: 32 | Ui::ChangeShapeCanvas *m_ui; 33 | QGraphicsView* m_view; 34 | QGraphicsScene* m_scene; 35 | GraphicsPathObject* m_pathObj = nullptr; 36 | }; 37 | 38 | Q_DECLARE_METATYPE(QPainterPath) 39 | #endif // CHANGESHAPECANVAS_H 40 | -------------------------------------------------------------------------------- /changeshapecanvas.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | ChangeShapeCanvas 4 | 5 | 6 | 7 | 0 8 | 0 9 | 913 10 | 591 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 20 | Qt::Horizontal 21 | 22 | 23 | 24 | 25 | 300 26 | 16777215 27 | 28 | 29 | 30 | Config 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | Add Pie 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | Start Angle 47 | 48 | 49 | 50 | 51 | 52 | 53 | Span Angle 54 | 55 | 56 | 57 | 58 | 59 | 60 | 360 61 | 62 | 63 | 64 | 65 | 66 | 67 | 360 68 | 69 | 70 | 71 | 72 | 73 | 74 | Add 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | Add Line 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | Point2 95 | 96 | 97 | 98 | 99 | 100 | 101 | 100000 102 | 103 | 104 | 105 | 106 | 107 | 108 | 10000 109 | 110 | 111 | 112 | 113 | 114 | 115 | 10000 116 | 117 | 118 | 119 | 120 | 121 | 122 | 10000 123 | 124 | 125 | 126 | 127 | 128 | 129 | Point1 130 | 131 | 132 | 133 | 134 | 135 | 136 | Add 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | Start Animation 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | Qt::Vertical 158 | 159 | 160 | 161 | 20 162 | 40 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | Canvas 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | -------------------------------------------------------------------------------- /circle.cpp: -------------------------------------------------------------------------------- 1 | #include "circle.h" 2 | 3 | #include 4 | 5 | Circle::Circle(QWidget *parent) : QWidget(parent) 6 | { 7 | setAttribute(Qt::WA_TranslucentBackground); 8 | setWindowFlags(Qt::FramelessWindowHint| Qt::ToolTip); 9 | } 10 | 11 | void Circle::setRadius(qreal radius) 12 | { 13 | if (m_radius != radius) { 14 | m_radius = radius; 15 | emit radiusChanged(radius); 16 | update(); 17 | } 18 | } 19 | 20 | qreal Circle::radius() const 21 | { 22 | return m_radius; 23 | } 24 | 25 | 26 | void Circle::setOpacity(qreal opacity) 27 | { 28 | if (m_opacity != opacity) { 29 | m_opacity = opacity; 30 | update(); 31 | emit opacityChanged(opacity); 32 | } 33 | } 34 | 35 | qreal Circle::opacity() const 36 | { 37 | return m_opacity; 38 | } 39 | 40 | void Circle::setColor(const QColor& clr) 41 | { 42 | if (m_color != clr) { 43 | m_color = clr; 44 | update(); 45 | emit colorChanged(clr); 46 | } 47 | } 48 | 49 | QColor Circle::color() const 50 | { 51 | return m_color; 52 | } 53 | 54 | void Circle::paintEvent(QPaintEvent*) 55 | { 56 | QPainter painter(this); 57 | painter.setRenderHints(QPainter::Antialiasing); 58 | painter.setOpacity(m_opacity); 59 | painter.setPen(QPen(m_color, 1)); 60 | 61 | if (m_radius <= 3) 62 | painter.setBrush(QBrush(m_color)); 63 | 64 | QPoint center = rect().center(); 65 | painter.drawEllipse(QPointF(center.x(), center.y()), m_radius, m_radius); 66 | } 67 | -------------------------------------------------------------------------------- /circle.h: -------------------------------------------------------------------------------- 1 | #ifndef CIRCLE_H 2 | #define CIRCLE_H 3 | 4 | #include 5 | 6 | class Circle : public QWidget 7 | { 8 | Q_OBJECT 9 | Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged) 10 | Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged) 11 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) 12 | public: 13 | explicit Circle(QWidget *parent = 0); 14 | 15 | void setRadius(qreal radius); 16 | qreal radius() const; 17 | 18 | void setOpacity(qreal opacity); 19 | qreal opacity() const; 20 | 21 | void setColor(const QColor& clr); 22 | QColor color() const; 23 | 24 | signals: 25 | void radiusChanged(qreal radius); 26 | void opacityChanged(qreal opacity); 27 | void colorChanged(const QColor& clr); 28 | 29 | protected: 30 | void paintEvent(QPaintEvent* e); 31 | 32 | private: 33 | qreal m_radius = 1.0; 34 | qreal m_opacity = 1.0; 35 | QColor m_color = Qt::black; 36 | }; 37 | 38 | #endif // CIRCLE_H 39 | -------------------------------------------------------------------------------- /colorball.cpp: -------------------------------------------------------------------------------- 1 | #include "colorball.h" 2 | 3 | #include 4 | #include 5 | 6 | ColorBall::ColorBall(QWidget *parent) : QWidget(parent) 7 | { 8 | setFixedSize(QSize(50, 50)); 9 | setWindowFlags(Qt::FramelessWindowHint); 10 | setAttribute(Qt::WA_TranslucentBackground); 11 | } 12 | 13 | void ColorBall::setColor(const QColor& clr) 14 | { 15 | if (m_color != clr) { 16 | m_color = clr; 17 | update(); 18 | } 19 | } 20 | 21 | QColor ColorBall::color() const 22 | { 23 | return m_color; 24 | } 25 | 26 | void ColorBall::paintEvent(QPaintEvent *event) 27 | { 28 | Q_UNUSED(event) 29 | QPainter painter(this); 30 | painter.setRenderHints(QPainter::Antialiasing); 31 | painter.setPen(QPen(Qt::black, 1)); 32 | painter.setBrush(QBrush(m_color)); 33 | painter.drawEllipse(rect()); 34 | } 35 | -------------------------------------------------------------------------------- /colorball.h: -------------------------------------------------------------------------------- 1 | #ifndef COLORBALL_H 2 | #define COLORBALL_H 3 | 4 | #include 5 | 6 | class ColorBall : public QWidget 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit ColorBall(QWidget *parent = 0); 11 | 12 | void setColor(const QColor& clr); 13 | QColor color() const; 14 | 15 | protected: 16 | void paintEvent(QPaintEvent *event); 17 | 18 | private: 19 | QColor m_color = Qt::red; 20 | }; 21 | 22 | #endif // COLORBALL_H 23 | -------------------------------------------------------------------------------- /eventfilter.cpp: -------------------------------------------------------------------------------- 1 | #include "eventfilter.h" 2 | 3 | EventFilter::EventFilter(QObject *parent) : QObject(parent) 4 | { 5 | 6 | } 7 | 8 | void EventFilter::addFilteredObject(QObject *obj) 9 | { 10 | m_targets.append(obj); 11 | } 12 | 13 | bool EventFilter::eventFilter(QObject *obj, QEvent *e) 14 | { 15 | bool ret = QObject::eventFilter(obj, e); 16 | 17 | if (m_targets.contains(obj)) 18 | emit filterEvent(obj, e); 19 | 20 | return ret; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /eventfilter.h: -------------------------------------------------------------------------------- 1 | #ifndef EVENTFILTER 2 | #define EVENTFILTER 3 | 4 | #include 5 | 6 | class QEvent; 7 | class EventFilter : public QObject 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit EventFilter(QObject* parent = nullptr); 12 | 13 | void addFilteredObject(QObject* obj); 14 | 15 | signals: 16 | void filterEvent(QObject* obj, QEvent *e); 17 | 18 | protected: 19 | bool eventFilter(QObject *obj, QEvent *e); 20 | 21 | private: 22 | QObjectList m_targets; 23 | }; 24 | 25 | #endif // EVENTFILTER 26 | 27 | -------------------------------------------------------------------------------- /explodeanimation.cpp: -------------------------------------------------------------------------------- 1 | #include "explodeanimation.h" 2 | #include "ui_explodeanimation.h" 3 | 4 | #include 5 | #include 6 | 7 | ExplodeAnimation::ExplodeAnimation(QWidget *parent) : 8 | QWidget(parent), 9 | m_ui(new Ui::ExplodeAnimation) 10 | { 11 | m_ui->setupUi(this); 12 | } 13 | 14 | ExplodeAnimation::~ExplodeAnimation() 15 | { 16 | delete m_ui; 17 | } 18 | 19 | void ExplodeAnimation::on_pushButton_clicked() 20 | { 21 | QParallelAnimationGroup* animGroup = new QParallelAnimationGroup(this); 22 | 23 | const int DeltaSize = 150; 24 | QRect newGeo(QPoint(this->pos() - QPoint(DeltaSize / 2, DeltaSize / 2)), this->size() + QSize(DeltaSize, DeltaSize)); 25 | 26 | QPropertyAnimation* sizeAnim = new QPropertyAnimation(this, "geometry"); 27 | sizeAnim->setEasingCurve(QEasingCurve::OutCubic); 28 | sizeAnim->setDuration(500); 29 | sizeAnim->setStartValue(this->geometry()); 30 | sizeAnim->setEndValue(newGeo); 31 | 32 | QPropertyAnimation* opacityAnim = new QPropertyAnimation(this, "windowOpacity"); 33 | opacityAnim->setEasingCurve(QEasingCurve::OutCubic); 34 | opacityAnim->setDuration(500); 35 | opacityAnim->setStartValue(1); 36 | opacityAnim->setEndValue(0); 37 | 38 | animGroup->addAnimation(sizeAnim); 39 | animGroup->addAnimation(opacityAnim); 40 | animGroup->start(QAbstractAnimation::DeleteWhenStopped); 41 | 42 | connect(animGroup, SIGNAL(finished()), this, SLOT(close())); 43 | } 44 | -------------------------------------------------------------------------------- /explodeanimation.h: -------------------------------------------------------------------------------- 1 | #ifndef EXPLODEANIMATION_H 2 | #define EXPLODEANIMATION_H 3 | 4 | #include 5 | 6 | namespace Ui 7 | { 8 | class ExplodeAnimation; 9 | } 10 | 11 | class ExplodeAnimation : public QWidget 12 | { 13 | Q_OBJECT 14 | public: 15 | explicit ExplodeAnimation(QWidget *parent = 0); 16 | ~ExplodeAnimation(); 17 | 18 | private slots: 19 | void on_pushButton_clicked(); 20 | 21 | private: 22 | Ui::ExplodeAnimation *m_ui; 23 | }; 24 | 25 | #endif // EXPLODEANIMATION_H 26 | -------------------------------------------------------------------------------- /explodeanimation.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | ExplodeAnimation 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 300 11 | 12 | 13 | 14 | Explode Animation 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Fire 23 | 24 | 25 | 26 | 27 | 28 | 29 | Qt::Horizontal 30 | 31 | 32 | 33 | 40 34 | 20 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | Qt::Horizontal 43 | 44 | 45 | 46 | 40 47 | 20 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /fadingtoolbutton.cpp: -------------------------------------------------------------------------------- 1 | #include "fadingtoolbutton.h" 2 | 3 | #include 4 | #include 5 | 6 | static const int MinBlurRadius = 5; 7 | static const int MaxBlurRadius = 40; 8 | static const int Duration = 1000; 9 | 10 | class FadingToolButtonPrivate 11 | { 12 | public: 13 | void init(); 14 | void startFading(); 15 | void stopFading(); 16 | 17 | FadingToolButton* q_ptr; 18 | QPropertyAnimation* fadeInAnim = nullptr; 19 | QPropertyAnimation* fadeOutAnim = nullptr; 20 | }; 21 | 22 | void FadingToolButtonPrivate::init() 23 | { 24 | fadeInAnim = new QPropertyAnimation(q_ptr); 25 | fadeInAnim->setEasingCurve(QEasingCurve::Linear); 26 | fadeInAnim->setDuration(Duration); 27 | fadeInAnim->setStartValue(MinBlurRadius); 28 | fadeInAnim->setEndValue(MaxBlurRadius); 29 | 30 | fadeOutAnim = new QPropertyAnimation(q_ptr); 31 | fadeOutAnim->setEasingCurve(QEasingCurve::Linear); 32 | fadeOutAnim->setDuration(Duration); 33 | fadeOutAnim->setStartValue(MaxBlurRadius); 34 | fadeOutAnim->setEndValue(MinBlurRadius); 35 | 36 | QObject::connect(fadeInAnim, SIGNAL(finished()), fadeOutAnim, SLOT(start())); 37 | QObject::connect(fadeOutAnim, SIGNAL(finished()), fadeInAnim, SLOT(start())); 38 | } 39 | 40 | void FadingToolButtonPrivate::startFading() 41 | { 42 | QGraphicsDropShadowEffect* dropShadow = new QGraphicsDropShadowEffect(); 43 | dropShadow->setOffset(0); 44 | 45 | q_ptr->setGraphicsEffect(dropShadow); 46 | fadeInAnim->setTargetObject(dropShadow); 47 | fadeInAnim->setPropertyName("blurRadius"); 48 | 49 | fadeOutAnim->setTargetObject(dropShadow); 50 | fadeOutAnim->setPropertyName("blurRadius"); 51 | fadeInAnim->start(); 52 | } 53 | 54 | void FadingToolButtonPrivate::stopFading() 55 | { 56 | q_ptr->setGraphicsEffect(nullptr); 57 | fadeInAnim->stop(); 58 | fadeOutAnim->stop(); 59 | } 60 | 61 | FadingToolButton::FadingToolButton(QWidget* parent) : QToolButton(parent) 62 | { 63 | d_ptr = new FadingToolButtonPrivate; 64 | d_ptr->q_ptr = this; 65 | d_ptr->init(); 66 | } 67 | 68 | FadingToolButton::~FadingToolButton() 69 | { 70 | delete d_ptr; 71 | } 72 | 73 | void FadingToolButton::enterEvent(QEvent* event) 74 | { 75 | d_ptr->startFading(); 76 | QToolButton::enterEvent(event); 77 | } 78 | 79 | void FadingToolButton::leaveEvent(QEvent* event) 80 | { 81 | d_ptr->stopFading(); 82 | QToolButton::leaveEvent(event); 83 | } 84 | 85 | -------------------------------------------------------------------------------- /fadingtoolbutton.h: -------------------------------------------------------------------------------- 1 | #ifndef FADINGTOOLBUTTON_H 2 | #define FADINGTOOLBUTTON_H 3 | 4 | #include 5 | 6 | class FadingToolButtonPrivate; 7 | class FadingToolButton : public QToolButton 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit FadingToolButton(QWidget* parent = nullptr); 12 | ~FadingToolButton(); 13 | 14 | protected: 15 | void enterEvent(QEvent* event); 16 | void leaveEvent(QEvent* event); 17 | 18 | private: 19 | FadingToolButtonPrivate* d_ptr; 20 | Q_DISABLE_COPY(FadingToolButton) 21 | }; 22 | 23 | #endif // FADINGTOOLBUTTON_H 24 | -------------------------------------------------------------------------------- /flowlayout.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the examples of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see https://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at https://www.qt.io/contact-us. 16 | ** 17 | ** BSD License Usage 18 | ** Alternatively, you may use this file under the terms of the BSD license 19 | ** as follows: 20 | ** 21 | ** "Redistribution and use in source and binary forms, with or without 22 | ** modification, are permitted provided that the following conditions are 23 | ** met: 24 | ** * Redistributions of source code must retain the above copyright 25 | ** notice, this list of conditions and the following disclaimer. 26 | ** * Redistributions in binary form must reproduce the above copyright 27 | ** notice, this list of conditions and the following disclaimer in 28 | ** the documentation and/or other materials provided with the 29 | ** distribution. 30 | ** * Neither the name of The Qt Company Ltd nor the names of its 31 | ** contributors may be used to endorse or promote products derived 32 | ** from this software without specific prior written permission. 33 | ** 34 | ** 35 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 46 | ** 47 | ** $QT_END_LICENSE$ 48 | ** 49 | ****************************************************************************/ 50 | 51 | #include 52 | #include 53 | 54 | #include "flowlayout.h" 55 | FlowLayout::FlowLayout(QWidget *parent, int margin, int hSpacing, int vSpacing) 56 | : QLayout(parent), m_hSpace(hSpacing), m_vSpace(vSpacing) 57 | { 58 | setContentsMargins(margin, margin, margin, margin); 59 | } 60 | 61 | FlowLayout::FlowLayout(int margin, int hSpacing, int vSpacing) 62 | : m_hSpace(hSpacing), m_vSpace(vSpacing) 63 | { 64 | setContentsMargins(margin, margin, margin, margin); 65 | } 66 | 67 | FlowLayout::~FlowLayout() 68 | { 69 | clear(); 70 | } 71 | 72 | void FlowLayout::clear() 73 | { 74 | QLayoutItem *item; 75 | while ((item = takeAt(0))) 76 | delete item; 77 | } 78 | 79 | void FlowLayout::addItem(QLayoutItem *item) 80 | { 81 | itemList.append(item); 82 | } 83 | 84 | int FlowLayout::horizontalSpacing() const 85 | { 86 | if (m_hSpace >= 0) { 87 | return m_hSpace; 88 | } else { 89 | return smartSpacing(QStyle::PM_LayoutHorizontalSpacing); 90 | } 91 | } 92 | 93 | int FlowLayout::verticalSpacing() const 94 | { 95 | if (m_vSpace >= 0) { 96 | return m_vSpace; 97 | } else { 98 | return smartSpacing(QStyle::PM_LayoutVerticalSpacing); 99 | } 100 | } 101 | 102 | int FlowLayout::count() const 103 | { 104 | return itemList.size(); 105 | } 106 | 107 | QLayoutItem *FlowLayout::itemAt(int index) const 108 | { 109 | return itemList.value(index); 110 | } 111 | 112 | QLayoutItem *FlowLayout::takeAt(int index) 113 | { 114 | if (index >= 0 && index < itemList.size()) 115 | return itemList.takeAt(index); 116 | else 117 | return 0; 118 | } 119 | 120 | void FlowLayout::setAnimated(bool animated) 121 | { 122 | if (m_animated != animated) 123 | m_animated = animated; 124 | } 125 | 126 | bool FlowLayout::animated() const 127 | { 128 | return m_animated; 129 | } 130 | 131 | Qt::Orientations FlowLayout::expandingDirections() const 132 | { 133 | return 0; 134 | } 135 | 136 | bool FlowLayout::hasHeightForWidth() const 137 | { 138 | return true; 139 | } 140 | 141 | int FlowLayout::heightForWidth(int width) const 142 | { 143 | int height = doLayout(QRect(0, 0, width, 0), true); 144 | return height; 145 | } 146 | 147 | void FlowLayout::setGeometry(const QRect &rect) 148 | { 149 | QLayout::setGeometry(rect); 150 | doLayout(rect, false); 151 | } 152 | 153 | QSize FlowLayout::sizeHint() const 154 | { 155 | return minimumSize(); 156 | } 157 | 158 | QSize FlowLayout::minimumSize() const 159 | { 160 | QSize size; 161 | QLayoutItem *item; 162 | foreach (item, itemList) 163 | size = size.expandedTo(item->minimumSize()); 164 | 165 | size += QSize(2*margin(), 2*margin()); 166 | return size; 167 | } 168 | 169 | int FlowLayout::doLayout(const QRect &rect, bool testOnly) const 170 | { 171 | int left, top, right, bottom; 172 | getContentsMargins(&left, &top, &right, &bottom); 173 | QRect effectiveRect = rect.adjusted(+left, +top, -right, -bottom); 174 | int x = effectiveRect.x(); 175 | int y = effectiveRect.y(); 176 | int lineHeight = 0; 177 | 178 | QLayoutItem *item; 179 | foreach (item, itemList) { 180 | QWidget *wid = item->widget(); 181 | int spaceX = horizontalSpacing(); 182 | if (spaceX == -1) 183 | spaceX = wid->style()->layoutSpacing( 184 | QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Horizontal); 185 | int spaceY = verticalSpacing(); 186 | if (spaceY == -1) 187 | spaceY = wid->style()->layoutSpacing( 188 | QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Vertical); 189 | int nextX = x + item->sizeHint().width() + spaceX; 190 | if (nextX - spaceX > effectiveRect.right() && lineHeight > 0) { 191 | x = effectiveRect.x(); 192 | y = y + lineHeight + spaceY; 193 | nextX = x + item->sizeHint().width() + spaceX; 194 | lineHeight = 0; 195 | } 196 | 197 | if (!testOnly) { 198 | if (m_animated) { 199 | QPropertyAnimation* anim = new QPropertyAnimation(wid, "geometry"); 200 | anim->setEasingCurve(QEasingCurve::OutCubic); 201 | anim->setDuration(500); 202 | anim->setStartValue(wid->geometry()); 203 | anim->setEndValue(QRect(QPoint(x, y), item->sizeHint())); 204 | anim->start(QAbstractAnimation::DeleteWhenStopped); 205 | } else { 206 | item->setGeometry(QRect(QPoint(x, y), item->sizeHint())); 207 | } 208 | } 209 | x = nextX; 210 | lineHeight = qMax(lineHeight, item->sizeHint().height()); 211 | } 212 | return y + lineHeight - rect.y() + bottom; 213 | } 214 | 215 | int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const 216 | { 217 | QObject *parent = this->parent(); 218 | if (!parent) { 219 | return -1; 220 | } else if (parent->isWidgetType()) { 221 | QWidget *pw = static_cast(parent); 222 | return pw->style()->pixelMetric(pm, 0, pw); 223 | } else { 224 | return static_cast(parent)->spacing(); 225 | } 226 | } 227 | -------------------------------------------------------------------------------- /flowlayout.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the examples of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see https://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at https://www.qt.io/contact-us. 16 | ** 17 | ** BSD License Usage 18 | ** Alternatively, you may use this file under the terms of the BSD license 19 | ** as follows: 20 | ** 21 | ** "Redistribution and use in source and binary forms, with or without 22 | ** modification, are permitted provided that the following conditions are 23 | ** met: 24 | ** * Redistributions of source code must retain the above copyright 25 | ** notice, this list of conditions and the following disclaimer. 26 | ** * Redistributions in binary form must reproduce the above copyright 27 | ** notice, this list of conditions and the following disclaimer in 28 | ** the documentation and/or other materials provided with the 29 | ** distribution. 30 | ** * Neither the name of The Qt Company Ltd nor the names of its 31 | ** contributors may be used to endorse or promote products derived 32 | ** from this software without specific prior written permission. 33 | ** 34 | ** 35 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 46 | ** 47 | ** $QT_END_LICENSE$ 48 | ** 49 | ****************************************************************************/ 50 | 51 | #ifndef FLOWLAYOUT_H 52 | #define FLOWLAYOUT_H 53 | 54 | #include 55 | #include 56 | #include 57 | 58 | class FlowLayout : public QLayout 59 | { 60 | public: 61 | explicit FlowLayout(QWidget *parent, int margin = -1, int hSpacing = -1, int vSpacing = -1); 62 | explicit FlowLayout(int margin = -1, int hSpacing = -1, int vSpacing = -1); 63 | ~FlowLayout(); 64 | 65 | void clear(); 66 | void addItem(QLayoutItem *item) Q_DECL_OVERRIDE; 67 | int horizontalSpacing() const; 68 | int verticalSpacing() const; 69 | Qt::Orientations expandingDirections() const Q_DECL_OVERRIDE; 70 | bool hasHeightForWidth() const Q_DECL_OVERRIDE; 71 | int heightForWidth(int) const Q_DECL_OVERRIDE; 72 | int count() const Q_DECL_OVERRIDE; 73 | QLayoutItem *itemAt(int index) const Q_DECL_OVERRIDE; 74 | QSize minimumSize() const Q_DECL_OVERRIDE; 75 | void setGeometry(const QRect &rect) Q_DECL_OVERRIDE; 76 | QSize sizeHint() const Q_DECL_OVERRIDE; 77 | QLayoutItem *takeAt(int index) Q_DECL_OVERRIDE; 78 | 79 | void setAnimated(bool animated); 80 | bool animated() const; 81 | 82 | private: 83 | int doLayout(const QRect &rect, bool testOnly) const; 84 | int smartSpacing(QStyle::PixelMetric pm) const; 85 | 86 | QList itemList; 87 | int m_hSpace; 88 | int m_vSpace; 89 | bool m_animated = false; 90 | }; 91 | 92 | #endif // FLOWLAYOUT_H 93 | -------------------------------------------------------------------------------- /flyawayanimation.cpp: -------------------------------------------------------------------------------- 1 | #include "flyawayanimation.h" 2 | #include "ui_flyawayanimation.h" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #ifdef Q_OS_WIN 10 | #include 11 | 12 | // Borrowed from https://causeyourestuck.io/2016/01/12/screenshot-c-win32-api/ 13 | void takeScreenshot(POINT a, POINT b) 14 | { 15 | // copy screen to bitmap 16 | HDC hScreen = GetDC(NULL); 17 | HDC hDC = CreateCompatibleDC(hScreen); 18 | HBITMAP hBitmap = CreateCompatibleBitmap(hScreen, abs(b.x-a.x), abs(b.y-a.y)); 19 | HGDIOBJ old_obj = SelectObject(hDC, hBitmap); 20 | BOOL bRet = BitBlt(hDC, 0, 0, abs(b.x-a.x), abs(b.y-a.y), hScreen, a.x, a.y, SRCCOPY); 21 | 22 | // save bitmap to clipboard 23 | OpenClipboard(NULL); 24 | EmptyClipboard(); 25 | SetClipboardData(CF_BITMAP, hBitmap); 26 | CloseClipboard(); 27 | 28 | // clean up 29 | SelectObject(hDC, old_obj); 30 | DeleteDC(hDC); 31 | ReleaseDC(NULL, hScreen); 32 | DeleteObject(hBitmap); 33 | } 34 | 35 | int titleBarHeight() 36 | { 37 | return (GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYCAPTION) + 38 | GetSystemMetrics(SM_CXPADDEDBORDER)); 39 | } 40 | 41 | QSize widgetSize(QWidget* widget) 42 | { 43 | if (!widget) 44 | return QSize(); 45 | 46 | RECT rect; 47 | int width, height; 48 | if(GetWindowRect((HWND)widget->winId(), &rect)) { 49 | width = rect.right - rect.left; 50 | height= rect.bottom - rect.top; 51 | } 52 | 53 | return QSize(width, height); 54 | } 55 | #endif // Q_OS_WIN 56 | 57 | FlyAwayAnimation::FlyAwayAnimation(QWidget *parent) : QWidget(parent) 58 | { 59 | m_ui = new Ui::FlyAwayAnimation; 60 | m_ui->setupUi(this); 61 | } 62 | 63 | FlyAwayAnimation::~FlyAwayAnimation() 64 | { 65 | delete m_ui; 66 | } 67 | 68 | void FlyAwayAnimation::closeEvent(QCloseEvent *e) 69 | { 70 | QLabel* label = new QLabel(); 71 | QPixmap oriScreenshot = screenshot(); 72 | 73 | label->setWindowFlags(Qt::ToolTip); 74 | label->setAttribute(Qt::WA_TranslucentBackground); 75 | label->setPixmap(oriScreenshot); 76 | label->move(mapToGlobal(this->pos())); 77 | label->resize(this->size()); 78 | label->show(); 79 | 80 | QDesktopWidget desktop; 81 | QWidget* screen = desktop.screen(); 82 | QPoint endPos(screen->width(), 0); 83 | QRect startGeo(geometry()); 84 | 85 | #ifdef Q_OS_WIN 86 | startGeo = QRect(QPoint(startGeo.topLeft().x() - GetSystemMetrics(SM_CXSIZEFRAME), 87 | startGeo.topLeft().y() - titleBarHeight()), widgetSize(this)); 88 | #endif 89 | 90 | QPropertyAnimation* anim = new QPropertyAnimation(label, "geometry"); 91 | anim->setDuration(1000); 92 | anim->setEasingCurve(QEasingCurve::OutCubic); 93 | anim->setStartValue(startGeo); 94 | anim->setEndValue(QRect(endPos, QSize(0, 0))); 95 | anim->start(QAbstractAnimation::DeleteWhenStopped); 96 | connect(anim, &QAbstractAnimation::finished, label, &QWidget::deleteLater); 97 | connect(anim, &QAbstractAnimation::stateChanged, [=] (QAbstractAnimation::State newState, QAbstractAnimation::State oldState) { 98 | if (newState == QAbstractAnimation::Stopped) 99 | label->deleteLater(); 100 | }); 101 | 102 | connect(anim, &QPropertyAnimation::valueChanged, [=] { 103 | QPixmap scaledScreenshot = oriScreenshot.scaled(label->size()); 104 | 105 | // if the scaled pixmap is null the stop the animation immediately, and delete the label 106 | if (scaledScreenshot.isNull()) { 107 | anim->stop(); 108 | return; 109 | } 110 | label->setPixmap(scaledScreenshot); 111 | }); 112 | 113 | e->accept(); 114 | } 115 | 116 | QPixmap FlyAwayAnimation::screenshot() 117 | { 118 | #ifdef Q_OS_WIN 119 | QPoint globalTopLeft = this->pos(); 120 | QSize wSize = widgetSize(this); 121 | 122 | POINT topLeft {globalTopLeft.x(), globalTopLeft.y() }; 123 | POINT bottomRight{globalTopLeft.x() + wSize.width(), 124 | globalTopLeft.y() + wSize.height()}; 125 | takeScreenshot(topLeft, bottomRight); 126 | #endif 127 | 128 | return QApplication::clipboard()->pixmap(); 129 | } 130 | -------------------------------------------------------------------------------- /flyawayanimation.h: -------------------------------------------------------------------------------- 1 | #ifndef FLYAWAYANIMATION_H 2 | #define FLYAWAYANIMATION_H 3 | 4 | #include 5 | 6 | namespace Ui 7 | { 8 | class FlyAwayAnimation; 9 | } 10 | 11 | class FlyAwayAnimation : public QWidget 12 | { 13 | Q_OBJECT 14 | public: 15 | explicit FlyAwayAnimation(QWidget *parent = 0); 16 | ~FlyAwayAnimation(); 17 | 18 | protected: 19 | void closeEvent(QCloseEvent* e); 20 | 21 | QPixmap screenshot(); 22 | 23 | private: 24 | Ui::FlyAwayAnimation* m_ui = nullptr; 25 | }; 26 | 27 | #endif // FLYAWAYANIMATION_H 28 | -------------------------------------------------------------------------------- /flyawayanimation.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | FlyAwayAnimation 4 | 5 | 6 | 7 | 0 8 | 0 9 | 281 10 | 430 11 | 12 | 13 | 14 | Fly Away Animation 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | TextLabel 26 | 27 | 28 | 29 | 30 | 31 | 32 | PushButton 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | Qt::LeftToRight 43 | 44 | 45 | QDialogButtonBox::Cancel|QDialogButtonBox::Ok 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /frame.cpp: -------------------------------------------------------------------------------- 1 | #include "frame.h" 2 | 3 | #include 4 | 5 | Frame::Frame(QWidget *parent) : QWidget(parent) 6 | { 7 | setAttribute(Qt::WA_TranslucentBackground); 8 | setWindowFlags(Qt::FramelessWindowHint); 9 | setAttribute(Qt::WA_TransparentForMouseEvents); 10 | } 11 | 12 | void Frame::setColor(const QColor& clr) 13 | { 14 | if (m_color != clr) { 15 | m_color = clr; 16 | update(); 17 | } 18 | } 19 | 20 | QColor Frame::color() const 21 | { 22 | return m_color; 23 | } 24 | 25 | void Frame::paintEvent(QPaintEvent* event) 26 | { 27 | Q_UNUSED(event) 28 | QPainter painter(this); 29 | painter.setRenderHints(QPainter::Antialiasing); 30 | painter.setPen(QPen(m_color, 2)); 31 | painter.drawRoundedRect(rect(), 5, 5); 32 | } 33 | -------------------------------------------------------------------------------- /frame.h: -------------------------------------------------------------------------------- 1 | #ifndef FRAME_H 2 | #define FRAME_H 3 | 4 | #include 5 | 6 | class Frame : public QWidget 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit Frame(QWidget *parent = 0); 11 | 12 | void setColor(const QColor& clr); 13 | QColor color() const; 14 | 15 | protected: 16 | void paintEvent(QPaintEvent* event); 17 | 18 | private: 19 | QColor m_color = Qt::blue; 20 | }; 21 | 22 | #endif // FRAME_H 23 | -------------------------------------------------------------------------------- /graphicsellipseobject.cpp: -------------------------------------------------------------------------------- 1 | #include "graphicsellipseobject.h" 2 | 3 | GraphicsEllipseObject::GraphicsEllipseObject(QObject *parent) : QObject(parent) 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /graphicsellipseobject.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHICSELLIPSEOBJECT_H 2 | #define GRAPHICSELLIPSEOBJECT_H 3 | 4 | #include 5 | 6 | class GraphicsEllipseObject : public QObject, public QGraphicsEllipseItem 7 | { 8 | Q_OBJECT 9 | Q_PROPERTY(int spanAngle READ spanAngle WRITE setSpanAngle) 10 | Q_PROPERTY(int startAngle READ startAngle WRITE setStartAngle) 11 | public: 12 | explicit GraphicsEllipseObject(QObject *parent = 0); 13 | }; 14 | 15 | #endif // GRAPHICSELLIPSEOBJECT_H 16 | -------------------------------------------------------------------------------- /graphicslineobject.cpp: -------------------------------------------------------------------------------- 1 | #include "graphicslineobject.h" 2 | 3 | GraphicsLineObject::GraphicsLineObject(QGraphicsItem* parent) : QGraphicsLineItem(parent) 4 | { 5 | 6 | } 7 | 8 | void GraphicsLineObject::setPoint1(const QPoint& point) 9 | { 10 | if (m_point1 != point) { 11 | m_point1 = point; 12 | setLine(QLineF(m_point1, m_point2)); 13 | } 14 | } 15 | 16 | QPoint GraphicsLineObject::point1() const 17 | { 18 | return m_point1; 19 | } 20 | 21 | void GraphicsLineObject::setPoint2(const QPoint& point) 22 | { 23 | if (m_point2 != point) { 24 | m_point2 = point; 25 | setLine(QLineF(m_point1, m_point2)); 26 | } 27 | } 28 | 29 | QPoint GraphicsLineObject::point2() const 30 | { 31 | return m_point2; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /graphicslineobject.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHICSLINEOBJECT_H 2 | #define GRAPHICSLINEOBJECT_H 3 | 4 | #include 5 | 6 | class GraphicsLineObject : public QObject, public QGraphicsLineItem 7 | { 8 | Q_OBJECT 9 | Q_PROPERTY(QPoint point1 READ point1 WRITE setPoint1) 10 | Q_PROPERTY(QPoint point2 READ point2 WRITE setPoint2) 11 | public: 12 | explicit GraphicsLineObject(QGraphicsItem* parent = nullptr); 13 | 14 | void setPoint1(const QPoint& point); 15 | QPoint point1() const; 16 | 17 | void setPoint2(const QPoint& point); 18 | QPoint point2() const; 19 | 20 | protected: 21 | QPoint m_point1; 22 | QPoint m_point2; 23 | }; 24 | 25 | #endif // GRAPHICSLINEOBJECT_H 26 | -------------------------------------------------------------------------------- /graphicspathobject.cpp: -------------------------------------------------------------------------------- 1 | #include "graphicspathobject.h" 2 | 3 | GraphicsPathObject::GraphicsPathObject(QObject* parent) : QObject(parent) 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /graphicspathobject.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHICSPATHOBJECT_H 2 | #define GRAPHICSPATHOBJECT_H 3 | 4 | #include 5 | #include 6 | 7 | class GraphicsPathObject : public QObject, public QGraphicsPathItem 8 | { 9 | Q_OBJECT 10 | Q_PROPERTY(QPainterPath path READ path WRITE setPath) 11 | public: 12 | explicit GraphicsPathObject(QObject* parent = nullptr); 13 | }; 14 | 15 | #endif // GRAPHICSPATHOBJECT_H 16 | -------------------------------------------------------------------------------- /highlighwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "highlighwindow.h" 2 | #include "frame.h" 3 | 4 | #include 5 | #include 6 | 7 | static Frame* sFrame = nullptr; 8 | 9 | // Mouse-move hooking code grabbed from SO 10 | // http://stackoverflow.com/questions/20401896/qt-global-mouse-listener 11 | #ifdef Q_OS_WIN 12 | #include 13 | #pragma comment(lib, "user32.lib") 14 | HHOOK hHook = NULL; 15 | using namespace std; 16 | 17 | LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam) 18 | { 19 | switch( wParam ) 20 | { 21 | case WM_MOUSEMOVE: 22 | { 23 | POINT pos; 24 | ::GetCursorPos(&pos); 25 | qDebug() << "Global mouse pos: " << pos.x << "," << pos.y; 26 | static HWND oldWindow = NULL; 27 | HWND hwnd = ::WindowFromPoint(pos); 28 | if (hwnd == oldWindow) { 29 | qDebug() << "same window, quit."; 30 | return CallNextHookEx(hHook, nCode, wParam, lParam); 31 | } 32 | 33 | oldWindow = hwnd; 34 | 35 | if (hwnd != NULL) { 36 | RECT rect; 37 | ::GetWindowRect(hwnd, &rect); 38 | 39 | if (!sFrame) { 40 | sFrame = new Frame(); 41 | sFrame->setColor(Qt::red); 42 | } 43 | 44 | sFrame->show(); 45 | sFrame->raise(); 46 | 47 | QPropertyAnimation* anim = new QPropertyAnimation(sFrame, "geometry"); 48 | anim->setDuration(500); 49 | anim->setEasingCurve(QEasingCurve::OutCubic); 50 | anim->setStartValue(sFrame->geometry()); 51 | anim->setEndValue(QRect(QPoint(rect.left, rect.top), QSize(rect.right - rect.left, rect.bottom - rect.top))); 52 | anim->start(QAbstractAnimation::DeleteWhenStopped); 53 | } 54 | } 55 | } 56 | return CallNextHookEx(hHook, nCode, wParam, lParam); 57 | } 58 | #endif 59 | 60 | HighlighWindow::HighlighWindow(QWidget *parent) : QWidget(parent) 61 | { 62 | #ifdef Q_OS_WIN 63 | hHook = SetWindowsHookEx(WH_MOUSE_LL, MouseProc, NULL, 0); 64 | if (hHook == NULL) { 65 | qDebug() << "Hook failed"; 66 | } 67 | #endif 68 | } 69 | 70 | HighlighWindow::~HighlighWindow() 71 | { 72 | if (sFrame) 73 | delete sFrame; 74 | } 75 | -------------------------------------------------------------------------------- /highlighwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef HIGHLIGHWINDOW_H 2 | #define HIGHLIGHWINDOW_H 3 | 4 | #include 5 | 6 | class HighlighWindow : public QWidget 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit HighlighWindow(QWidget *parent = 0); 11 | ~HighlighWindow(); 12 | }; 13 | 14 | #endif // HIGHLIGHWINDOW_H 15 | -------------------------------------------------------------------------------- /imagecarousel.cpp: -------------------------------------------------------------------------------- 1 | #include "imagecarousel.h" 2 | 3 | class ImageCarouselPrivate 4 | { 5 | public: 6 | 7 | }; 8 | 9 | ImageCarousel::ImageCarousel(QWidget *parent) : QWidget(parent) 10 | { 11 | d_ptr = new ImageCarouselPrivate; 12 | } 13 | 14 | ImageCarousel::~ImageCarousel() 15 | { 16 | delete d_ptr; 17 | } 18 | 19 | void ImageCarousel::addImage(const QString& image) 20 | { 21 | // TODO 22 | } 23 | 24 | void ImageCarousel::removeImage(const QString& image) 25 | { 26 | // TODO 27 | } 28 | 29 | void ImageCarousel::clear() 30 | { 31 | // TODO 32 | } 33 | -------------------------------------------------------------------------------- /imagecarousel.h: -------------------------------------------------------------------------------- 1 | #ifndef IMAGECAROUSEL_H 2 | #define IMAGECAROUSEL_H 3 | 4 | #include 5 | 6 | class ImageCarouselPrivate; 7 | class ImageCarousel : public QWidget 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit ImageCarousel(QWidget *parent = 0); 12 | ~ImageCarousel(); 13 | 14 | void addImage(const QString& image); 15 | void removeImage(const QString& image); 16 | void clear(); 17 | 18 | private: 19 | ImageCarouselPrivate* d_ptr; 20 | Q_DISABLE_COPY(ImageCarousel) 21 | }; 22 | 23 | #endif // IMAGECAROUSEL_H 24 | -------------------------------------------------------------------------------- /images.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/navigate.png 4 | images/bug.png 5 | 6 | 7 | -------------------------------------------------------------------------------- /images/bug.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kimtaikee/resizeAnimation/8ec05cd23e2bf689b0475ce4fa73684b413f8dfb/images/bug.png -------------------------------------------------------------------------------- /images/navigate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kimtaikee/resizeAnimation/8ec05cd23e2bf689b0475ce4fa73684b413f8dfb/images/navigate.png -------------------------------------------------------------------------------- /inputdialog.cpp: -------------------------------------------------------------------------------- 1 | #include "inputdialog.h" 2 | #include "ui_inputdialog.h" 3 | #include "eventfilter.h" 4 | 5 | #include 6 | #include 7 | 8 | InputDialog::InputDialog(QWidget *parent) : 9 | QDialog(parent), 10 | m_ui(new Ui::InputDialog) 11 | { 12 | m_ui->setupUi(this); 13 | 14 | // remove the question mark 15 | setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint)); 16 | 17 | EventFilter* evtFilter = new EventFilter(this); 18 | evtFilter->addFilteredObject(m_ui->lineEdit); 19 | evtFilter->addFilteredObject(m_ui->textEdit); 20 | 21 | m_ui->lineEdit->installEventFilter(evtFilter); 22 | m_ui->textEdit->installEventFilter(evtFilter); 23 | 24 | auto addDropShadow = [] (QWidget* widget) { 25 | QGraphicsDropShadowEffect* effect = new QGraphicsDropShadowEffect(); 26 | effect->setOffset(0); 27 | effect->setColor(QColor(112, 181, 245)); 28 | widget->setGraphicsEffect(effect); 29 | 30 | QPropertyAnimation* anim = new QPropertyAnimation(effect, "blurRadius"); 31 | anim->setDuration(500); 32 | anim->setEasingCurve(QEasingCurve::OutCubic); 33 | anim->setStartValue(0); 34 | anim->setEndValue(20); 35 | anim->start(QAbstractAnimation::DeleteWhenStopped); 36 | }; 37 | 38 | auto removeDropShadow = [] (QWidget* widget) { 39 | widget->setGraphicsEffect(nullptr); 40 | }; 41 | 42 | connect(evtFilter, &EventFilter::filterEvent, [=, this] (QObject* obj, QEvent* evt) { 43 | if (evt->type() == QEvent::Enter) { 44 | if (obj == m_ui->lineEdit) 45 | addDropShadow(m_ui->lineEdit); 46 | else if (obj == m_ui->textEdit) 47 | addDropShadow(m_ui->textEdit); 48 | } else if (evt->type() == QEvent::Leave) { 49 | if (obj == m_ui->lineEdit) 50 | removeDropShadow(m_ui->lineEdit); 51 | else if (obj == m_ui->textEdit) 52 | removeDropShadow(m_ui->textEdit); 53 | } 54 | }); 55 | } 56 | 57 | InputDialog::~InputDialog() 58 | { 59 | delete m_ui; 60 | } 61 | -------------------------------------------------------------------------------- /inputdialog.h: -------------------------------------------------------------------------------- 1 | #ifndef INPUTDIALOG_H 2 | #define INPUTDIALOG_H 3 | 4 | #include 5 | 6 | namespace Ui 7 | { 8 | class InputDialog; 9 | } 10 | 11 | class InputDialog : public QDialog 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | explicit InputDialog(QWidget *parent = 0); 17 | ~InputDialog(); 18 | 19 | private: 20 | Ui::InputDialog *m_ui; 21 | }; 22 | 23 | #endif // INPUTDIALOG_H 24 | -------------------------------------------------------------------------------- /inputdialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | InputDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 265 10 | 319 11 | 12 | 13 | 14 | Input Control DropShadowEffect 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | Qt::Horizontal 31 | 32 | 33 | QDialogButtonBox::Cancel|QDialogButtonBox::Ok 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | buttonBox 43 | accepted() 44 | InputDialog 45 | accept() 46 | 47 | 48 | 248 49 | 254 50 | 51 | 52 | 157 53 | 274 54 | 55 | 56 | 57 | 58 | buttonBox 59 | rejected() 60 | InputDialog 61 | reject() 62 | 63 | 64 | 316 65 | 260 66 | 67 | 68 | 286 69 | 274 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /layoutwindowsanimation.cpp: -------------------------------------------------------------------------------- 1 | #include "layoutwindowsanimation.h" 2 | #include "ui_layoutwindowsanimation.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class CustomWidget : public QWidget 9 | { 10 | public: 11 | explicit CustomWidget(QWidget* parent = nullptr) : QWidget(parent) {} 12 | 13 | protected: 14 | QSize sizeHint() const { return QSize(200, 200); } 15 | }; 16 | 17 | void addWindowAnimation(QParallelAnimationGroup* paraAnimGroup, QMdiSubWindow* subWin, const QPoint& newPos, const QSize& newSize) 18 | { 19 | if (!paraAnimGroup) 20 | return; 21 | 22 | QPropertyAnimation* posAnim = new QPropertyAnimation(subWin, "pos"); 23 | posAnim->setEasingCurve(QEasingCurve::OutCubic); 24 | posAnim->setDuration(1000); 25 | posAnim->setStartValue(subWin->pos()); 26 | posAnim->setEndValue(newPos); 27 | paraAnimGroup->addAnimation(posAnim); 28 | 29 | QPropertyAnimation* sizeAnim = new QPropertyAnimation(subWin, "size"); 30 | sizeAnim->setEasingCurve(QEasingCurve::OutCubic); 31 | sizeAnim->setDuration(1000); 32 | sizeAnim->setStartValue(subWin->size()); 33 | sizeAnim->setEndValue(newSize); 34 | paraAnimGroup->addAnimation(sizeAnim); 35 | } 36 | 37 | void cascadeWindows(QMdiArea* mdi) 38 | { 39 | QParallelAnimationGroup* animGroup = new QParallelAnimationGroup(); 40 | 41 | QList subWins = mdi->subWindowList(); 42 | for (int i = 0; i < subWins.size(); ++i) 43 | addWindowAnimation(animGroup, subWins.at(i), QPoint(i * 30, i * 30), subWins.at(i)->widget()->sizeHint()); 44 | animGroup->start(QAbstractAnimation::DeleteWhenStopped); 45 | } 46 | 47 | LayoutWindowsAnimation::LayoutWindowsAnimation(QWidget *parent) : 48 | QWidget(parent), 49 | ui(new Ui::LayoutWindowsAnimation) 50 | { 51 | ui->setupUi(this); 52 | ui->mdiArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); 53 | ui->mdiArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); 54 | } 55 | 56 | LayoutWindowsAnimation::~LayoutWindowsAnimation() 57 | { 58 | delete ui; 59 | } 60 | 61 | void LayoutWindowsAnimation::on_addWindowButton_clicked() 62 | { 63 | CustomWidget* widget = new CustomWidget; 64 | auto win = ui->mdiArea->addSubWindow(widget); 65 | win->show(); 66 | } 67 | 68 | void LayoutWindowsAnimation::on_cascadeButton_clicked() 69 | { 70 | cascadeWindows(ui->mdiArea); 71 | } 72 | -------------------------------------------------------------------------------- /layoutwindowsanimation.h: -------------------------------------------------------------------------------- 1 | #ifndef LAYOUTWINDOWSANIMATION_H 2 | #define LAYOUTWINDOWSANIMATION_H 3 | 4 | #include 5 | 6 | namespace Ui 7 | { 8 | class LayoutWindowsAnimation; 9 | } 10 | 11 | class LayoutWindowsAnimation : public QWidget 12 | { 13 | Q_OBJECT 14 | public: 15 | explicit LayoutWindowsAnimation(QWidget *parent = 0); 16 | ~LayoutWindowsAnimation(); 17 | 18 | private slots: 19 | void on_addWindowButton_clicked(); 20 | void on_cascadeButton_clicked(); 21 | 22 | private: 23 | Ui::LayoutWindowsAnimation *ui; 24 | }; 25 | 26 | #endif // LAYOUTWINDOWSANIMATION_H 27 | -------------------------------------------------------------------------------- /layoutwindowsanimation.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | LayoutWindowsAnimation 4 | 5 | 6 | 7 | 0 8 | 0 9 | 612 10 | 394 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 20 | Qt::Horizontal 21 | 22 | 23 | 24 | 25 | 200 26 | 16777215 27 | 28 | 29 | 30 | GroupBox 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | Add Window 39 | 40 | 41 | 42 | 43 | 44 | 45 | Qt::Vertical 46 | 47 | 48 | 49 | 20 50 | 40 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | Cascade 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | GroupBox 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /lednumber.cpp: -------------------------------------------------------------------------------- 1 | #include "lednumber.h" 2 | #include "ledunit.h" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | static QMap > sNumber2PatternMap; 10 | LedNumber::LedNumber(QWidget *parent) : QWidget(parent) 11 | { 12 | init(); 13 | } 14 | 15 | void LedNumber::setNumber(int number) 16 | { 17 | if (m_number != number) { 18 | m_number = number; 19 | 20 | foreach (LedUnit* unit, m_units) { 21 | unit->setColor(unit->offColor()); 22 | unit->setOn(false); 23 | } 24 | 25 | QList ledIndexes = sNumber2PatternMap.value(number); 26 | 27 | #define PARALLEL_ANIMATION 28 | #ifdef PARALLEL_ANIMATION 29 | foreach (int index, ledIndexes) 30 | m_units.at(index)->setOn(true); 31 | #elif defined(SEQUENCIAL_ANIMATION) 32 | // QSequentialAnimationGroup* animGroup = new QSequentialAnimationGroup(this); 33 | // foreach (int index, ledIndexes) { 34 | // LedUnit* unit = m_units.at(index); 35 | // QPropertyAnimation* anim = new QPropertyAnimation(unit, "color"); 36 | // anim->setDuration(50); 37 | // anim->setEasingCurve(QEasingCurve::OutCubic); 38 | // anim->setStartValue(unit->offColor()); 39 | // anim->setEndValue(unit->onColor()); 40 | // animGroup->addAnimation(anim); 41 | // } 42 | // animGroup->start(QAbstractAnimation::DeleteWhenStopped); 43 | #else 44 | 45 | #endif 46 | } 47 | } 48 | 49 | int LedNumber::number() const 50 | { 51 | return m_number; 52 | } 53 | 54 | void LedNumber::resizeEvent(QResizeEvent* event) 55 | { 56 | layoutUnits(); 57 | QWidget::resizeEvent(event); 58 | } 59 | 60 | void LedNumber::init() 61 | { 62 | sNumber2PatternMap.insert(0, QList() << 0 << 1 << 2 << 3 << 4 << 5 << 9 << 10 << 14 << 15 << 19 << 20 << 21 << 22 << 23 << 24); 63 | sNumber2PatternMap.insert(1, QList() << 2 << 7 << 12 << 17 << 22); 64 | sNumber2PatternMap.insert(2, QList() << 0 << 1 << 2 << 3 << 4 << 9 << 10 << 11 << 12 << 13 << 14 << 15 << 20 << 21 << 22 << 23 << 24); 65 | sNumber2PatternMap.insert(3, QList() << 0 << 1 << 2 << 3 << 4 << 9 << 10 << 11 << 12 << 13 << 14 << 19 << 20 << 21 << 22 << 23 << 24); 66 | sNumber2PatternMap.insert(4, QList() << 0 << 2 << 5 << 7 << 10 << 11 << 12 << 13 << 14 << 17 << 22); 67 | sNumber2PatternMap.insert(5, QList() << 0 << 1 << 2 << 3 << 4 << 5 << 10 << 11 << 12 << 13 << 14 << 19 << 20 << 21 << 22 << 23 << 24); 68 | sNumber2PatternMap.insert(6, QList() << 0 << 1 << 2 << 3 << 4 << 5 << 10 << 11 << 12 << 13 << 14 << 15 << 19 << 20 << 21 << 22 << 23 << 24); 69 | sNumber2PatternMap.insert(7, QList() << 0 << 1 << 2 << 3 << 4 << 9 << 14 << 19 << 24); 70 | sNumber2PatternMap.insert(8, QList() << 0 << 1 << 2 << 3 << 4 << 5 << 9 << 10 << 11 << 12 << 13 << 14 << 15 << 19 << 20 << 21 << 22 << 23 << 24); 71 | sNumber2PatternMap.insert(9, QList() << 0 << 1 << 2 << 3 << 4 << 5 << 9 << 10 << 11 << 12 << 13 << 14 << 19 << 20 << 21 << 22 << 23 << 24); 72 | 73 | const int UnitCount = 25; 74 | for (int i = 0; i < UnitCount; ++i) 75 | m_units.append(new LedUnit(this)); 76 | setNumber(m_number); 77 | } 78 | 79 | void LedNumber::layoutUnits() 80 | { 81 | int cols = 5; 82 | int rows = 5; 83 | int unitWidth = this->width() / 5; 84 | int unitHeight = this->height() / 5; 85 | int x = 0; 86 | int y = 0; 87 | int index = 0; 88 | for (int row = 0; row < rows; ++row) { 89 | x = 0; 90 | for (int col = 0; col < cols; ++col) { 91 | LedUnit* unit = m_units.at(index++); 92 | unit->move(x, y); 93 | unit->setFixedSize(unitWidth, unitHeight); 94 | x += unitWidth; 95 | } 96 | 97 | y += unitHeight; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /lednumber.h: -------------------------------------------------------------------------------- 1 | #ifndef LEDNUMBER_H 2 | #define LEDNUMBER_H 3 | 4 | #include 5 | 6 | class LedUnit; 7 | class LedNumber : public QWidget 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit LedNumber(QWidget *parent = 0); 12 | 13 | void setNumber(int number); 14 | int number() const; 15 | 16 | protected: 17 | void resizeEvent(QResizeEvent* event); 18 | 19 | private: 20 | void init(); 21 | void layoutUnits(); 22 | 23 | private: 24 | int m_number = 0; 25 | QList m_units; 26 | }; 27 | 28 | #endif // LEDNUMBER_H 29 | -------------------------------------------------------------------------------- /lednumberanimation.cpp: -------------------------------------------------------------------------------- 1 | #include "lednumberanimation.h" 2 | #include "ui_lednumberanimation.h" 3 | #include "lednumber.h" 4 | 5 | LedNumberAnimation::LedNumberAnimation(QWidget *parent) : 6 | QWidget(parent), m_ui(new Ui::LedNumberAnimation) 7 | { 8 | m_ui->setupUi(this); 9 | 10 | m_led = new LedNumber(m_ui->groupBox_2); 11 | m_ui->previewLayout->addWidget(m_led); 12 | } 13 | 14 | LedNumberAnimation::~LedNumberAnimation() 15 | { 16 | delete m_ui; 17 | } 18 | 19 | void LedNumberAnimation::on_numberSpinBox_valueChanged(int arg1) 20 | { 21 | m_led->setNumber(arg1); 22 | } 23 | -------------------------------------------------------------------------------- /lednumberanimation.h: -------------------------------------------------------------------------------- 1 | #ifndef LEDNUMBERANIMATION_H 2 | #define LEDNUMBERANIMATION_H 3 | 4 | #include 5 | 6 | namespace Ui 7 | { 8 | class LedNumberAnimation; 9 | } 10 | 11 | class LedNumber; 12 | class LedNumberAnimation : public QWidget 13 | { 14 | Q_OBJECT 15 | public: 16 | explicit LedNumberAnimation(QWidget *parent = 0); 17 | ~LedNumberAnimation(); 18 | 19 | private slots: 20 | void on_numberSpinBox_valueChanged(int arg1); 21 | 22 | private: 23 | Ui::LedNumberAnimation *m_ui; 24 | LedNumber* m_led = nullptr; 25 | }; 26 | 27 | #endif // LEDNUMBERANIMATION_H 28 | -------------------------------------------------------------------------------- /lednumberanimation.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | LedNumberAnimation 4 | 5 | 6 | 7 | 0 8 | 0 9 | 438 10 | 347 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 20 | Qt::Horizontal 21 | 22 | 23 | 24 | 25 | 120 26 | 16777215 27 | 28 | 29 | 30 | GroupBox 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | Number 39 | 40 | 41 | 42 | 43 | 44 | 45 | 9 46 | 47 | 48 | 49 | 50 | 51 | 52 | Qt::Vertical 53 | 54 | 55 | 56 | 20 57 | 40 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | Preview 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /ledunit.cpp: -------------------------------------------------------------------------------- 1 | #include "ledunit.h" 2 | 3 | #include 4 | #include 5 | 6 | LedUnit::LedUnit(QWidget *parent) : QWidget(parent) 7 | { 8 | 9 | } 10 | 11 | void LedUnit::setOn(bool on) 12 | { 13 | if (m_on != on) { 14 | m_on = on; 15 | 16 | if (m_animated) { 17 | QPropertyAnimation* anim = new QPropertyAnimation(this, "color"); 18 | anim->setDuration(1000); 19 | anim->setEasingCurve(QEasingCurve::OutCubic); 20 | anim->setStartValue(on ? m_offColor : m_onColor); 21 | anim->setEndValue(on ? m_onColor : m_offColor); 22 | anim->start(QAbstractAnimation::DeleteWhenStopped); 23 | } else { 24 | m_color = on ? m_onColor : m_offColor; 25 | update(); 26 | } 27 | } 28 | } 29 | 30 | bool LedUnit::on() const 31 | { 32 | return m_on; 33 | } 34 | 35 | void LedUnit::setAnimated(bool animate) 36 | { 37 | if (m_animated != animate) 38 | m_animated = animate; 39 | } 40 | 41 | bool LedUnit::animated() const 42 | { 43 | return m_animated; 44 | } 45 | 46 | void LedUnit::setColor(const QColor& clr) 47 | { 48 | if (m_color != clr) { 49 | m_color = clr; 50 | update(); 51 | } 52 | } 53 | 54 | QColor LedUnit::color() const 55 | { 56 | return m_color; 57 | } 58 | 59 | void LedUnit::setOffColor(const QColor& clr) 60 | { 61 | m_offColor = clr; 62 | } 63 | 64 | QColor LedUnit::offColor() const 65 | { 66 | return m_offColor; 67 | } 68 | 69 | void LedUnit::setOnColor(const QColor& clr) 70 | { 71 | m_onColor = clr; 72 | } 73 | 74 | QColor LedUnit::onColor() const 75 | { 76 | return m_onColor; 77 | } 78 | 79 | void LedUnit::paintEvent(QPaintEvent *event) 80 | { 81 | Q_UNUSED(event) 82 | QPainter painter(this); 83 | painter.setPen(QPen(QColor(89, 89, 89), 1)); 84 | QLinearGradient lg(this->rect().topLeft(), this->rect().bottomLeft()); 85 | lg.setColorAt(0.0, m_color.lighter()); 86 | lg.setColorAt(1.0, m_color); 87 | painter.setBrush(QBrush(lg)); 88 | painter.drawRect(rect()); 89 | } 90 | -------------------------------------------------------------------------------- /ledunit.h: -------------------------------------------------------------------------------- 1 | #ifndef LEDUNIT_H 2 | #define LEDUNIT_H 3 | 4 | #include 5 | 6 | class LedUnit : public QWidget 7 | { 8 | Q_OBJECT 9 | Q_PROPERTY(QColor color READ color WRITE setColor) 10 | Q_PROPERTY(bool on READ on WRITE setOn) 11 | public: 12 | explicit LedUnit(QWidget *parent = 0); 13 | 14 | void setOn(bool on); 15 | bool on() const; 16 | 17 | void setAnimated(bool animate); 18 | bool animated() const; 19 | 20 | void setColor(const QColor& clr); 21 | QColor color() const; 22 | 23 | void setOffColor(const QColor& clr); 24 | QColor offColor() const; 25 | 26 | void setOnColor(const QColor& clr); 27 | QColor onColor() const; 28 | 29 | protected: 30 | void paintEvent(QPaintEvent* event); 31 | 32 | private: 33 | bool m_on = false; 34 | bool m_animated = true; 35 | QColor m_color = QColor(45, 45, 45); 36 | QColor m_onColor = Qt::green; 37 | QColor m_offColor = QColor(45, 45, 45); 38 | }; 39 | 40 | #endif // LEDUNIT_H 41 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | Widget w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /resizeAnimation.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = resizeAnimation 3 | INCLUDEPATH += . 4 | 5 | QT += widgets core gui 6 | 7 | # Input 8 | HEADERS += widget.h \ 9 | scrollanimationwindow.h \ 10 | changeshapecanvas.h \ 11 | graphicspathobject.h \ 12 | slidetextanimation.h \ 13 | graphicslineobject.h \ 14 | graphicsellipseobject.h \ 15 | layoutwindowsanimation.h \ 16 | colorball.h \ 17 | tagwidget.h \ 18 | flowlayout.h \ 19 | tsttagwidget.h \ 20 | imagecarousel.h \ 21 | bounceindicator.h \ 22 | slidewidgetcontainer.h \ 23 | fadingtoolbutton.h \ 24 | tstflowlayout.h \ 25 | explodeanimation.h \ 26 | tableselectionanimation.h \ 27 | frame.h \ 28 | ledunit.h \ 29 | lednumber.h \ 30 | lednumberanimation.h \ 31 | slidemenuanimation.h \ 32 | shadowwindow.h \ 33 | inputdialog.h \ 34 | eventfilter.h \ 35 | circle.h \ 36 | flyawayanimation.h \ 37 | highlighwindow.h 38 | 39 | FORMS += widget.ui \ 40 | scrollanimationwindow.ui \ 41 | changeshapecanvas.ui \ 42 | slidetextanimation.ui \ 43 | layoutwindowsanimation.ui \ 44 | tsttagwidget.ui \ 45 | tstflowlayout.ui \ 46 | explodeanimation.ui \ 47 | tableselectionanimation.ui \ 48 | lednumberanimation.ui \ 49 | inputdialog.ui \ 50 | flyawayanimation.ui 51 | 52 | SOURCES += main.cpp widget.cpp \ 53 | scrollanimationwindow.cpp \ 54 | changeshapecanvas.cpp \ 55 | graphicspathobject.cpp \ 56 | slidetextanimation.cpp \ 57 | graphicslineobject.cpp \ 58 | graphicsellipseobject.cpp \ 59 | layoutwindowsanimation.cpp \ 60 | colorball.cpp \ 61 | tagwidget.cpp \ 62 | flowlayout.cpp \ 63 | tsttagwidget.cpp \ 64 | imagecarousel.cpp \ 65 | bounceindicator.cpp \ 66 | slidewidgetcontainer.cpp \ 67 | fadingtoolbutton.cpp \ 68 | tstflowlayout.cpp \ 69 | explodeanimation.cpp \ 70 | tableselectionanimation.cpp \ 71 | frame.cpp \ 72 | ledunit.cpp \ 73 | lednumber.cpp \ 74 | lednumberanimation.cpp \ 75 | slidemenuanimation.cpp \ 76 | shadowwindow.cpp \ 77 | inputdialog.cpp \ 78 | eventfilter.cpp \ 79 | circle.cpp \ 80 | flyawayanimation.cpp \ 81 | highlighwindow.cpp 82 | 83 | LIBS += user32.lib gdi32.lib 84 | 85 | RESOURCES += \ 86 | images.qrc 87 | -------------------------------------------------------------------------------- /scrollanimationwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "scrollanimationwindow.h" 2 | #include "ui_scrollanimationwindow.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | ScrollAnimationWindow::ScrollAnimationWindow(QWidget *parent) : 9 | QDialog(parent), m_ui(new Ui::ScrollAnimationWindow) 10 | { 11 | m_ui->setupUi(this); 12 | m_ui->scrollArea->setWidgetResizable(true); 13 | setWindowTitle(tr("Scroll Animation")); 14 | } 15 | 16 | ScrollAnimationWindow::~ScrollAnimationWindow() 17 | { 18 | delete m_ui; 19 | } 20 | 21 | void ScrollAnimationWindow::on_loadImageButton_clicked() 22 | { 23 | QString imageFile = QFileDialog::getOpenFileName(this, tr("Load Image"), ".", "PNG Files(*.png);;JPG Files(*.jpg)"); 24 | if (imageFile.isEmpty()) 25 | return; 26 | 27 | QPixmap pixmap(imageFile); 28 | m_ui->imageLabel->setPixmap(pixmap); 29 | } 30 | 31 | void ScrollAnimationWindow::on_leftButton_clicked() 32 | { 33 | auto horBar = m_ui->scrollArea->horizontalScrollBar(); 34 | startAnimation(horBar, "value", horBar->value(), 0); 35 | } 36 | 37 | void ScrollAnimationWindow::on_rightButton_clicked() 38 | { 39 | auto horBar = m_ui->scrollArea->horizontalScrollBar(); 40 | startAnimation(horBar, "value", horBar->value(), horBar->maximum()); 41 | } 42 | 43 | void ScrollAnimationWindow::on_topButton_clicked() 44 | { 45 | auto verBar = m_ui->scrollArea->verticalScrollBar(); 46 | startAnimation(verBar, "value", verBar->value(), 0); 47 | } 48 | 49 | void ScrollAnimationWindow::on_bottomButton_clicked() 50 | { 51 | auto verBar = m_ui->scrollArea->verticalScrollBar(); 52 | startAnimation(verBar, "value", verBar->value(), verBar->maximum()); 53 | } 54 | 55 | void ScrollAnimationWindow::startAnimation(QObject *target, const QByteArray &propertyName, const QVariant& startValue, const QVariant& endValue) 56 | { 57 | QPropertyAnimation* anim = new QPropertyAnimation(target, propertyName); 58 | anim->setDuration(1000); 59 | anim->setStartValue(startValue); 60 | anim->setEndValue(endValue); 61 | anim->setEasingCurve(QEasingCurve::OutCubic); 62 | anim->start(QAbstractAnimation::DeleteWhenStopped); 63 | } 64 | 65 | -------------------------------------------------------------------------------- /scrollanimationwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef SCROLLANIMATIONWINDOW_H 2 | #define SCROLLANIMATIONWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui 7 | { 8 | class ScrollAnimationWindow; 9 | } 10 | 11 | class QPropertyAnimation; 12 | class ScrollAnimationWindow : public QDialog 13 | { 14 | Q_OBJECT 15 | public: 16 | explicit ScrollAnimationWindow(QWidget *parent = 0); 17 | ~ScrollAnimationWindow(); 18 | 19 | private slots: 20 | void on_loadImageButton_clicked(); 21 | void on_leftButton_clicked(); 22 | void on_rightButton_clicked(); 23 | void on_topButton_clicked(); 24 | void on_bottomButton_clicked(); 25 | 26 | private: 27 | void startAnimation(QObject *target, const QByteArray &propertyName, const QVariant& startValue, const QVariant& endValue); 28 | 29 | private: 30 | Ui::ScrollAnimationWindow *m_ui; 31 | }; 32 | 33 | #endif // SCROLLANIMATIONWINDOW_H 34 | -------------------------------------------------------------------------------- /scrollanimationwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | ScrollAnimationWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 424 10 | 305 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Bottom 23 | 24 | 25 | 26 | 27 | 28 | 29 | Left 30 | 31 | 32 | 33 | 34 | 35 | 36 | Top 37 | 38 | 39 | 40 | 41 | 42 | 43 | Right 44 | 45 | 46 | 47 | 48 | 49 | 50 | Load Image 51 | 52 | 53 | 54 | 55 | 56 | 57 | true 58 | 59 | 60 | 61 | 62 | 0 63 | 0 64 | 402 65 | 257 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /shadowwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "shadowwindow.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | class ShadowWindowPrivate 8 | { 9 | public: 10 | void init(); 11 | 12 | ShadowWindow* q_ptr; 13 | bool enabled = true; 14 | }; 15 | 16 | void ShadowWindowPrivate::init() 17 | { 18 | q_ptr->setWindowTitle(QObject::tr("Shadow Window")); 19 | 20 | q_ptr->setWindowFlags(Qt::FramelessWindowHint); 21 | q_ptr->setAttribute(Qt::WA_TranslucentBackground); 22 | 23 | QGraphicsDropShadowEffect *wndShadow = new QGraphicsDropShadowEffect; 24 | wndShadow->setBlurRadius(9.0); 25 | wndShadow->setColor(QColor(0, 0, 0, 160)); 26 | wndShadow->setOffset(4.0); 27 | q_ptr->setGraphicsEffect(wndShadow); 28 | } 29 | 30 | ShadowWindow::ShadowWindow(QWidget *parent) : QWidget(parent) 31 | { 32 | d_ptr = new ShadowWindowPrivate; 33 | d_ptr->q_ptr = this; 34 | d_ptr->init(); 35 | } 36 | 37 | ShadowWindow::~ShadowWindow() 38 | { 39 | delete d_ptr; 40 | } 41 | 42 | void ShadowWindow::setShadowEnabled(bool enable) 43 | { 44 | if (d_ptr->enabled != enable) { 45 | d_ptr->enabled = enable; 46 | if (enable) { 47 | QGraphicsDropShadowEffect* shadowEffect = new QGraphicsDropShadowEffect(this); 48 | shadowEffect->setBlurRadius(15); 49 | shadowEffect->setOffset(0); 50 | setGraphicsEffect(shadowEffect); 51 | } else { 52 | setGraphicsEffect(nullptr); 53 | } 54 | } 55 | } 56 | 57 | bool ShadowWindow::shadowEnabled() const 58 | { 59 | return d_ptr->enabled; 60 | } 61 | 62 | QSize ShadowWindow::sizeHint() const 63 | { 64 | return QSize(400, 400); 65 | } 66 | 67 | 68 | -------------------------------------------------------------------------------- /shadowwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef SHADOWWINDOW_H 2 | #define SHADOWWINDOW_H 3 | 4 | #include 5 | 6 | class ShadowWindowPrivate; 7 | class ShadowWindow : public QWidget 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit ShadowWindow(QWidget *parent = 0); 12 | ~ShadowWindow(); 13 | 14 | void setShadowEnabled(bool enable); 15 | bool shadowEnabled() const; 16 | 17 | QSize sizeHint() const; 18 | 19 | private: 20 | ShadowWindowPrivate* d_ptr; 21 | Q_DISABLE_COPY(ShadowWindow) 22 | }; 23 | 24 | #endif // SHADOWWINDOW_H 25 | -------------------------------------------------------------------------------- /slidemenuanimation.cpp: -------------------------------------------------------------------------------- 1 | #include "slidemenuanimation.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | SlideMenuAnimation::SlideMenuAnimation(QWidget *parent) : QWidget(parent) 10 | { 11 | populateMenu(); 12 | } 13 | 14 | void SlideMenuAnimation::contextMenuEvent(QContextMenuEvent *event) 15 | { 16 | #if 0 17 | QPoint pos = event->pos(); 18 | if (pos.x() > (width() / 2)) 19 | slideIn(Right); 20 | else 21 | slideIn(Left); 22 | #endif 23 | expand(event->globalPos()); 24 | } 25 | 26 | void SlideMenuAnimation::keyPressEvent(QKeyEvent* event) 27 | { 28 | QWidget::keyPressEvent(event); 29 | 30 | if (event->key() == Qt::Key_F1) 31 | m_direction = (m_direction == Left) ? Right: Left; 32 | } 33 | 34 | void SlideMenuAnimation::slideIn(Direction d) 35 | { 36 | m_direction = d; 37 | m_menu->show(); 38 | 39 | QPropertyAnimation* anim = new QPropertyAnimation(m_menu, "pos"); 40 | anim->setDuration(500); 41 | anim->setEasingCurve(QEasingCurve::OutCubic); 42 | 43 | QPoint globalTopLeft = pos(); 44 | 45 | if (d == Left) { 46 | anim->setStartValue(QPoint(-m_menu->width() + globalTopLeft.x(), globalTopLeft.y())); 47 | anim->setEndValue(globalTopLeft); 48 | } else { 49 | anim->setStartValue(QPoint(globalTopLeft.x() + width(), globalTopLeft.x())); 50 | anim->setEndValue(QPoint(globalTopLeft.x() + width() - m_menu->width(), globalTopLeft.x())); 51 | } 52 | 53 | anim->start(QAbstractAnimation::DeleteWhenStopped); 54 | } 55 | 56 | void SlideMenuAnimation::slideOut(Direction d) 57 | { 58 | m_direction = d; 59 | m_menu->show(); 60 | 61 | QPropertyAnimation* anim = new QPropertyAnimation(m_menu, "pos"); 62 | anim->setDuration(500); 63 | anim->setEasingCurve(QEasingCurve::OutCubic); 64 | 65 | QPoint globalTopLeft = pos(); 66 | 67 | if (d == Left) { 68 | anim->setStartValue(m_menu->pos()); 69 | anim->setEndValue(QPoint(-m_menu->width(), 0)); 70 | } else { 71 | anim->setStartValue(m_menu->pos()); 72 | anim->setEndValue(QPoint(width(), 0)); 73 | } 74 | 75 | anim->start(QAbstractAnimation::DeleteWhenStopped); 76 | } 77 | 78 | void SlideMenuAnimation::expand(const QPoint& globalPos) 79 | { 80 | m_globalPos = globalPos; 81 | m_menu->exec(globalPos); 82 | 83 | QPropertyAnimation* anim = new QPropertyAnimation(m_menu, "size"); 84 | anim->setDuration(500); 85 | anim->setEasingCurve(QEasingCurve::OutCubic); 86 | anim->setStartValue(QSize(0, m_menu->height())); 87 | anim->setEndValue(QSize(m_menu->width(), m_menu->height())); 88 | 89 | QPropertyAnimation* opacityAnim = new QPropertyAnimation(m_menu, "windowOpacity"); 90 | opacityAnim->setDuration(500); 91 | opacityAnim->setEasingCurve(QEasingCurve::OutCubic); 92 | opacityAnim->setStartValue(0); 93 | opacityAnim->setEndValue(1); 94 | 95 | QParallelAnimationGroup* animGroup = new QParallelAnimationGroup(); 96 | animGroup->addAnimation(anim); 97 | animGroup->addAnimation(opacityAnim); 98 | animGroup->start(QAbstractAnimation::DeleteWhenStopped); 99 | } 100 | 101 | void SlideMenuAnimation::populateMenu() 102 | { 103 | m_menu = new QMenu(this); 104 | 105 | auto onActionTriggered = [this] { 106 | // slideOut(m_direction); 107 | }; 108 | 109 | m_menu->addAction("Action 1", onActionTriggered); 110 | m_menu->addAction("Action 2", onActionTriggered); 111 | m_menu->addAction("Action 3", onActionTriggered); 112 | m_menu->addAction("Action 4", onActionTriggered); 113 | m_menu->addAction("Action 5", onActionTriggered); 114 | m_menu->addAction("Action 6", onActionTriggered); 115 | m_menu->addAction("Action 7", onActionTriggered); 116 | m_menu->addAction("Action 8", onActionTriggered); 117 | m_menu->addAction("Action 9", onActionTriggered); 118 | } 119 | 120 | -------------------------------------------------------------------------------- /slidemenuanimation.h: -------------------------------------------------------------------------------- 1 | #ifndef SLIDEMENUANIMATION_H 2 | #define SLIDEMENUANIMATION_H 3 | 4 | #include 5 | 6 | class QMenu; 7 | class SlideMenuAnimation : public QWidget 8 | { 9 | Q_OBJECT 10 | enum Direction { Left, Right }; 11 | public: 12 | explicit SlideMenuAnimation(QWidget *parent = 0); 13 | 14 | protected: 15 | void contextMenuEvent(QContextMenuEvent *event); 16 | void keyPressEvent(QKeyEvent* event); 17 | 18 | private: 19 | void slideIn(Direction d); 20 | void slideOut(Direction d); 21 | void expand(const QPoint& globalPos); 22 | void populateMenu(); 23 | 24 | private: 25 | QMenu* m_menu; 26 | QPoint m_globalPos; 27 | Direction m_direction = Left; 28 | }; 29 | 30 | #endif // SLIDEMENUANIMATION_H 31 | -------------------------------------------------------------------------------- /slidetextanimation.cpp: -------------------------------------------------------------------------------- 1 | #include "slidetextanimation.h" 2 | #include "ui_slidetextanimation.h" 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | const int Margin = 10; 10 | 11 | SlideTextAnimation::SlideTextAnimation(QWidget *parent) : 12 | QWidget(parent), 13 | m_ui(new Ui::SlideTextAnimation) 14 | { 15 | m_ui->setupUi(this); 16 | m_label = new QLabel(m_ui->frame); 17 | m_label->setScaledContents(true); 18 | m_label->setWordWrap(true); 19 | } 20 | 21 | SlideTextAnimation::~SlideTextAnimation() 22 | { 23 | delete m_ui; 24 | } 25 | 26 | void SlideTextAnimation::resizeEvent(QResizeEvent* event) 27 | { 28 | QWidget::resizeEvent(event); 29 | m_label->setFixedWidth(m_ui->frame->width()); 30 | } 31 | 32 | void SlideTextAnimation::on_goButton_clicked() 33 | { 34 | m_label->setText(m_ui->textEdit->toPlainText()); 35 | m_label->setFixedWidth(m_ui->frame->width() - 2 * Margin); 36 | m_label->adjustSize(); 37 | startAnimation(); 38 | } 39 | 40 | void SlideTextAnimation::on_textEdit_textChanged() 41 | { 42 | on_goButton_clicked(); 43 | } 44 | 45 | void SlideTextAnimation::startAnimation() 46 | { 47 | if (!m_posAnim) { 48 | m_posAnim = new QPropertyAnimation(m_label, "pos"); 49 | connect(m_posAnim, SIGNAL(finished()), m_posAnim, SLOT(start())); 50 | } 51 | 52 | m_posAnim->setDuration(m_ui->durationSpinBox->value()); 53 | m_posAnim->setEasingCurve(static_cast(m_ui->easingCurveCombo->currentIndex())); 54 | m_posAnim->setStartValue(QPoint(Margin, m_ui->frame->height())); 55 | m_posAnim->setEndValue(QPoint(Margin, -m_label->height())); 56 | m_posAnim->start(); 57 | } 58 | -------------------------------------------------------------------------------- /slidetextanimation.h: -------------------------------------------------------------------------------- 1 | #ifndef SLIDETEXTANIMATION_H 2 | #define SLIDETEXTANIMATION_H 3 | 4 | #include 5 | 6 | namespace Ui 7 | { 8 | class SlideTextAnimation; 9 | } 10 | 11 | class QLabel; 12 | class QPropertyAnimation; 13 | class SlideTextAnimation : public QWidget 14 | { 15 | Q_OBJECT 16 | public: 17 | explicit SlideTextAnimation(QWidget *parent = 0); 18 | ~SlideTextAnimation(); 19 | 20 | protected: 21 | void resizeEvent(QResizeEvent* event); 22 | 23 | private slots: 24 | void on_goButton_clicked(); 25 | void on_textEdit_textChanged(); 26 | void startAnimation(); 27 | 28 | private: 29 | Ui::SlideTextAnimation *m_ui; 30 | QLabel* m_label = nullptr; 31 | QPropertyAnimation* m_posAnim = nullptr; 32 | }; 33 | 34 | #endif // SLIDETEXTANIMATION_H 35 | -------------------------------------------------------------------------------- /slidetextanimation.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | SlideTextAnimation 4 | 5 | 6 | 7 | 0 8 | 0 9 | 757 10 | 330 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 20 | Qt::Horizontal 21 | 22 | 23 | 24 | 25 | 300 26 | 16777215 27 | 28 | 29 | 30 | Config 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | Enter Text: 39 | 40 | 41 | 42 | 43 | 44 | 45 | Go 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | Qt::Horizontal 56 | 57 | 58 | 59 | 40 60 | 20 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | Duration 69 | 70 | 71 | 72 | 73 | 74 | 75 | 100 76 | 77 | 78 | 100000000 79 | 80 | 81 | 5000 82 | 83 | 84 | 85 | 86 | 87 | 88 | Easing Curve 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | Linear 97 | 98 | 99 | 100 | 101 | InQuad 102 | 103 | 104 | 105 | 106 | OutQuad 107 | 108 | 109 | 110 | 111 | InOutQuad 112 | 113 | 114 | 115 | 116 | OutInQuad 117 | 118 | 119 | 120 | 121 | InCubic 122 | 123 | 124 | 125 | 126 | OutCubic 127 | 128 | 129 | 130 | 131 | InOutCubic 132 | 133 | 134 | 135 | 136 | OutInCubic 137 | 138 | 139 | 140 | 141 | InQuart 142 | 143 | 144 | 145 | 146 | OutQuart 147 | 148 | 149 | 150 | 151 | InOutQuart 152 | 153 | 154 | 155 | 156 | OutInQuart 157 | 158 | 159 | 160 | 161 | InQuint 162 | 163 | 164 | 165 | 166 | OutQuint 167 | 168 | 169 | 170 | 171 | InOutQuint 172 | 173 | 174 | 175 | 176 | OutInQuint 177 | 178 | 179 | 180 | 181 | InSine 182 | 183 | 184 | 185 | 186 | OutSine 187 | 188 | 189 | 190 | 191 | InOutSine 192 | 193 | 194 | 195 | 196 | OutInSine 197 | 198 | 199 | 200 | 201 | InExpo 202 | 203 | 204 | 205 | 206 | OutExpo 207 | 208 | 209 | 210 | 211 | InOutExpo 212 | 213 | 214 | 215 | 216 | OutInExpo 217 | 218 | 219 | 220 | 221 | InCirc 222 | 223 | 224 | 225 | 226 | OutCirc 227 | 228 | 229 | 230 | 231 | InOutCirc 232 | 233 | 234 | 235 | 236 | OutInCirc 237 | 238 | 239 | 240 | 241 | InElastic 242 | 243 | 244 | 245 | 246 | OutElastic 247 | 248 | 249 | 250 | 251 | InOutElastic 252 | 253 | 254 | 255 | 256 | OutInElastic 257 | 258 | 259 | 260 | 261 | InBack 262 | 263 | 264 | 265 | 266 | OutBack 267 | 268 | 269 | 270 | 271 | InOutBack 272 | 273 | 274 | 275 | 276 | OutInBack 277 | 278 | 279 | 280 | 281 | InBounce 282 | 283 | 284 | 285 | 286 | OutBounce 287 | 288 | 289 | 290 | 291 | InOutBounce 292 | 293 | 294 | 295 | 296 | OutInBounce 297 | 298 | 299 | 300 | 301 | InCurve 302 | 303 | 304 | 305 | 306 | OutCurve 307 | 308 | 309 | 310 | 311 | SineCurve 312 | 313 | 314 | 315 | 316 | CosineCurve 317 | 318 | 319 | 320 | 321 | BezierSpline 322 | 323 | 324 | 325 | 326 | TCBSpline 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | Preview 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | QFrame::Panel 346 | 347 | 348 | QFrame::Raised 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | -------------------------------------------------------------------------------- /slidewidgetcontainer.cpp: -------------------------------------------------------------------------------- 1 | #include "slidewidgetcontainer.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | const int SwitchThresholdFactor = 4; 10 | const int DragThreshold = 120; 11 | const int SlideDuration = 500; 12 | static const QEasingCurve::Type EasingCurve = QEasingCurve::OutCubic; 13 | 14 | class SlideWidgetContainerPrivate 15 | { 16 | public: 17 | void layoutWidgetsHorizontally(); 18 | void slideWidgetHorizontally(const QPoint& pos); 19 | void switchWidgetHorizontally(const QPoint& pos); 20 | 21 | void layoutWidgetsVertically(); 22 | void slideWidgetVertically(const QPoint& pos); 23 | void switchWidgetVertically(const QPoint& pos); 24 | 25 | void stopAnimations() { /*return;*/ foreach (auto anim, animations) anim->stop(); } 26 | void startAnimation(QWidget* target, const QPoint& oldPos, const QPoint& newPos, bool add = true); 27 | 28 | SlideWidgetContainer* q_ptr; 29 | QWidgetList widgets; 30 | bool pressed = false; 31 | QPoint pressedPoint; 32 | int currentIndex = -1; 33 | QList animations; 34 | Qt::Orientation orientation = Qt::Horizontal; 35 | }; 36 | 37 | void SlideWidgetContainerPrivate::layoutWidgetsHorizontally() 38 | { 39 | if (currentIndex < 0 || currentIndex >= widgets.size()) 40 | return; 41 | 42 | int x = -currentIndex * q_ptr->width(); 43 | for (int i = 0; i < widgets.size(); ++i) { 44 | widgets.at(i)->move(QPoint(x, 0)); 45 | widgets.at(i)->resize(q_ptr->size()); 46 | x += q_ptr->width(); 47 | } 48 | } 49 | 50 | void SlideWidgetContainerPrivate::slideWidgetHorizontally(const QPoint &pos) 51 | { 52 | if (currentIndex < 0 || currentIndex >= widgets.size()) 53 | return; 54 | 55 | stopAnimations(); 56 | 57 | int deltaX = pos.x() - pressedPoint.x(); 58 | QWidget* widget = widgets.at(currentIndex); 59 | bool reachThreshold = qAbs(deltaX) > DragThreshold; 60 | bool slideBackward = deltaX > 0; 61 | 62 | // boundary check, cannot drag too far 63 | if (currentIndex == 0 && reachThreshold && slideBackward) 64 | deltaX = DragThreshold; 65 | else if (currentIndex == (widgets.size() - 1) && reachThreshold &&!slideBackward) 66 | deltaX = - DragThreshold; 67 | widget->move(QPoint(deltaX, 0)); 68 | 69 | if (deltaX < 0) { 70 | // slide in next widget 71 | if (widgets.size() > (currentIndex + 1)) { 72 | qDebug() << "slide in next widget"; 73 | QWidget* nextWidget = widgets.at(currentIndex + 1); 74 | QPoint nextPos(q_ptr->width() - qAbs(deltaX), 0); 75 | qDebug() << "next pos: " << nextPos; 76 | qDebug() << "next widget pos:" << nextWidget->pos(); 77 | nextWidget->move(nextPos); 78 | } 79 | } else { 80 | // slide in previous widget 81 | if ((currentIndex - 1) >= 0) { 82 | qDebug() << "slide in previous widget"; 83 | QWidget* prevWidget = widgets.at(currentIndex - 1); 84 | prevWidget->move(-q_ptr->width() + deltaX, 0); 85 | } 86 | } 87 | } 88 | 89 | void SlideWidgetContainerPrivate::switchWidgetHorizontally(const QPoint &pos) 90 | { 91 | if (currentIndex < 0 || currentIndex >= widgets.size()) 92 | return; 93 | 94 | int deltaX = pos.x() - pressedPoint.x(); 95 | bool shouldSwitch = qAbs(deltaX) > (q_ptr->width() / SwitchThresholdFactor); 96 | bool slideForward = deltaX < 0; 97 | 98 | if (shouldSwitch) { 99 | if (slideForward) { 100 | if (widgets.size() > (currentIndex + 1)) { 101 | QWidget* currentWidget = widgets.at(currentIndex); 102 | startAnimation(currentWidget, currentWidget->pos(), QPoint(-q_ptr->width(), 0)); 103 | 104 | QWidget* nextWidget = widgets.at(currentIndex + 1); 105 | startAnimation(nextWidget, nextWidget->pos(), QPoint(0, 0)); 106 | 107 | ++currentIndex; 108 | } else { 109 | // move to original position 110 | QWidget* currentWidget = widgets.at(currentIndex); 111 | startAnimation(currentWidget, currentWidget->pos(), QPoint(0, 0)); 112 | } 113 | } else { 114 | if ((currentIndex - 1) >= 0) { 115 | QWidget* prevWidget = widgets.at(currentIndex - 1); 116 | startAnimation(prevWidget, prevWidget->pos(), QPoint(0, 0)); 117 | 118 | QWidget* currentWidget = widgets.at(currentIndex); 119 | startAnimation(currentWidget, currentWidget->pos(), QPoint(q_ptr->width(), 0), false); 120 | 121 | --currentIndex; 122 | } else { 123 | // move to original position 124 | QWidget* currentWidget = widgets.at(currentIndex); 125 | startAnimation(currentWidget, currentWidget->pos(), QPoint(0, 0)); 126 | } 127 | } 128 | } else { 129 | QWidget* widget = widgets.at(currentIndex); 130 | startAnimation(widget, QPoint(deltaX, 0), QPoint(0, 0)); 131 | 132 | if (deltaX < 0) { 133 | // handle next widget's animation 134 | if (widgets.size() > (currentIndex + 1)) { 135 | QWidget* nextWidget = widgets.at(currentIndex + 1); 136 | startAnimation(nextWidget, nextWidget->pos(), QPoint(q_ptr->width(), 0), false); 137 | } 138 | 139 | } else { 140 | // handle previous widget's animation 141 | if ((currentIndex - 1) >= 0) { 142 | QWidget* prevWidget = widgets.at(currentIndex - 1); 143 | startAnimation(prevWidget, prevWidget->pos(), QPoint(-q_ptr->width(), 0), false); 144 | } 145 | } 146 | } 147 | } 148 | 149 | void SlideWidgetContainerPrivate::layoutWidgetsVertically() 150 | { 151 | if (currentIndex < 0 || currentIndex >= widgets.size()) 152 | return; 153 | 154 | int y = -currentIndex * q_ptr->height(); 155 | for (int i = 0; i < widgets.size(); ++i) { 156 | widgets.at(i)->move(QPoint(0, y)); 157 | widgets.at(i)->resize(q_ptr->size()); 158 | y += q_ptr->height(); 159 | } 160 | } 161 | 162 | void SlideWidgetContainerPrivate::slideWidgetVertically(const QPoint& pos) 163 | { 164 | if (currentIndex < 0 || currentIndex >= widgets.size()) 165 | return; 166 | 167 | stopAnimations(); 168 | 169 | int deltaY = pos.y() - pressedPoint.y(); 170 | QWidget* widget = widgets.at(currentIndex); 171 | bool reachThreshold = qAbs(deltaY) > DragThreshold; 172 | bool slideBackward = deltaY > 0; 173 | 174 | // boundary check, cannot drag too far 175 | if (currentIndex == 0 && reachThreshold && slideBackward) 176 | deltaY = DragThreshold; 177 | else if (currentIndex == (widgets.size() - 1) && reachThreshold &&!slideBackward) 178 | deltaY = - DragThreshold; 179 | widget->move(QPoint(0, deltaY)); 180 | 181 | if (deltaY < 0) { 182 | // slide in next widget 183 | if (widgets.size() > (currentIndex + 1)) { 184 | qDebug() << "slide in next widget"; 185 | QWidget* nextWidget = widgets.at(currentIndex + 1); 186 | QPoint nextPos(0, q_ptr->height() - qAbs(deltaY)); 187 | qDebug() << "next pos: " << nextPos; 188 | qDebug() << "next widget pos:" << nextWidget->pos(); 189 | nextWidget->move(nextPos); 190 | } 191 | } else { 192 | // slide in previous widget 193 | if ((currentIndex - 1) >= 0) { 194 | qDebug() << "slide in previous widget"; 195 | QWidget* prevWidget = widgets.at(currentIndex - 1); 196 | prevWidget->move(0, -q_ptr->height() + deltaY); 197 | } 198 | } 199 | } 200 | 201 | void SlideWidgetContainerPrivate::switchWidgetVertically(const QPoint& pos) 202 | { 203 | if (currentIndex < 0 || currentIndex >= widgets.size()) 204 | return; 205 | 206 | int deltaY = pos.y() - pressedPoint.y(); 207 | bool shouldSwitch = qAbs(deltaY) > (q_ptr->height() / SwitchThresholdFactor); 208 | bool slideForward = deltaY < 0; 209 | 210 | if (shouldSwitch) { 211 | if (slideForward) { 212 | if (widgets.size() > (currentIndex + 1)) { 213 | QWidget* currentWidget = widgets.at(currentIndex); 214 | startAnimation(currentWidget, currentWidget->pos(), QPoint(0, -q_ptr->height())); 215 | 216 | QWidget* nextWidget = widgets.at(currentIndex + 1); 217 | startAnimation(nextWidget, nextWidget->pos(), QPoint(0, 0)); 218 | 219 | ++currentIndex; 220 | } else { 221 | // move to original position 222 | QWidget* currentWidget = widgets.at(currentIndex); 223 | startAnimation(currentWidget, currentWidget->pos(), QPoint(0, 0)); 224 | } 225 | } else { 226 | if ((currentIndex - 1) >= 0) { 227 | QWidget* prevWidget = widgets.at(currentIndex - 1); 228 | startAnimation(prevWidget, prevWidget->pos(), QPoint(0, 0)); 229 | 230 | QWidget* currentWidget = widgets.at(currentIndex); 231 | startAnimation(currentWidget, currentWidget->pos(), QPoint(0, q_ptr->height()), false); 232 | 233 | --currentIndex; 234 | } else { 235 | // move to original position 236 | QWidget* currentWidget = widgets.at(currentIndex); 237 | startAnimation(currentWidget, currentWidget->pos(), QPoint(0, 0)); 238 | } 239 | } 240 | } else { 241 | QWidget* widget = widgets.at(currentIndex); 242 | startAnimation(widget, QPoint(0, deltaY), QPoint(0, 0)); 243 | 244 | if (deltaY < 0) { 245 | // handle next widget's animation 246 | if (widgets.size() > (currentIndex + 1)) { 247 | QWidget* nextWidget = widgets.at(currentIndex + 1); 248 | startAnimation(nextWidget, nextWidget->pos(), QPoint(0, q_ptr->height()), false); 249 | } 250 | 251 | } else { 252 | // handle previous widget's animation 253 | if ((currentIndex - 1) >= 0) { 254 | QWidget* prevWidget = widgets.at(currentIndex - 1); 255 | startAnimation(prevWidget, prevWidget->pos(), QPoint(0, -q_ptr->height()), false); 256 | } 257 | } 258 | } 259 | } 260 | 261 | void SlideWidgetContainerPrivate::startAnimation(QWidget *target, const QPoint &oldPos, const QPoint &newPos, bool add) 262 | { 263 | QPropertyAnimation* anim = new QPropertyAnimation(target, "pos"); 264 | anim->setEasingCurve(EasingCurve); 265 | anim->setDuration(SlideDuration); 266 | anim->setStartValue(oldPos); 267 | anim->setEndValue(newPos); 268 | 269 | if (add) 270 | animations.append(anim); 271 | 272 | q_ptr->connect(anim, &QAbstractAnimation::finished, [this, anim] { 273 | animations.removeAll(anim); 274 | }); 275 | q_ptr->connect(anim, &QAbstractAnimation::stateChanged, [this, anim] (QAbstractAnimation::State newState, QAbstractAnimation::State oldState) { 276 | if (newState == QAbstractAnimation::Stopped) 277 | animations.removeAll(anim); 278 | }); 279 | anim->start(QAbstractAnimation::DeleteWhenStopped); 280 | } 281 | 282 | SlideWidgetContainer::SlideWidgetContainer(QWidget *parent) : QWidget(parent) 283 | { 284 | d_ptr = new SlideWidgetContainerPrivate; 285 | d_ptr->q_ptr = this; 286 | } 287 | 288 | SlideWidgetContainer::~SlideWidgetContainer() 289 | { 290 | delete d_ptr; 291 | } 292 | 293 | void SlideWidgetContainer::addWidget(QWidget* widget) 294 | { 295 | if (d_ptr->widgets.contains(widget)) { 296 | qDebug() << "Already contains this widget."; 297 | return; 298 | } 299 | 300 | d_ptr->widgets.append(widget); 301 | if (d_ptr->currentIndex < 0) 302 | d_ptr->currentIndex = 0; 303 | 304 | if (d_ptr->orientation == Qt::Horizontal) 305 | d_ptr->layoutWidgetsHorizontally(); 306 | else 307 | d_ptr->layoutWidgetsVertically(); 308 | } 309 | 310 | void SlideWidgetContainer::removeWidget(QWidget* widget) 311 | { 312 | if (!d_ptr->widgets.contains(widget)) { 313 | qDebug() << "Doesn't contain this widget."; 314 | return; 315 | } 316 | 317 | d_ptr->widgets.removeAll(widget); 318 | } 319 | 320 | int SlideWidgetContainer::count() const 321 | { 322 | return d_ptr->widgets.size(); 323 | } 324 | 325 | int SlideWidgetContainer::currentIndex() const 326 | { 327 | return d_ptr->currentIndex; 328 | } 329 | 330 | void SlideWidgetContainer::setOrientation(Qt::Orientation ori) 331 | { 332 | if (d_ptr->orientation != ori) 333 | d_ptr->orientation = ori; 334 | } 335 | 336 | Qt::Orientation SlideWidgetContainer::orientation() const 337 | { 338 | return d_ptr->orientation; 339 | } 340 | 341 | QSize SlideWidgetContainer::sizeHint() const 342 | { 343 | return QSize(400, 400); 344 | } 345 | 346 | void SlideWidgetContainer::resizeEvent(QResizeEvent* event) 347 | { 348 | QWidget::resizeEvent(event); 349 | 350 | if (d_ptr->orientation == Qt::Horizontal) 351 | d_ptr->layoutWidgetsHorizontally(); 352 | else 353 | d_ptr->layoutWidgetsVertically(); 354 | } 355 | 356 | void SlideWidgetContainer::mousePressEvent(QMouseEvent* event) 357 | { 358 | if (event->button() == Qt::LeftButton) { 359 | d_ptr->pressed = true; 360 | d_ptr->pressedPoint = event->pos(); 361 | d_ptr->stopAnimations(); 362 | setCursor(QCursor(Qt::ClosedHandCursor)); 363 | } 364 | } 365 | 366 | void SlideWidgetContainer::mouseMoveEvent(QMouseEvent* event) 367 | { 368 | if (!d_ptr->pressed) { 369 | QWidget::mouseMoveEvent(event); 370 | return; 371 | } 372 | 373 | if (d_ptr->orientation == Qt::Horizontal) 374 | d_ptr->slideWidgetHorizontally(event->pos()); 375 | else 376 | d_ptr->slideWidgetVertically(event->pos()); 377 | } 378 | 379 | void SlideWidgetContainer::mouseReleaseEvent(QMouseEvent* event) 380 | { 381 | if (event->button() == Qt::LeftButton) { 382 | 383 | if (d_ptr->orientation == Qt::Horizontal) 384 | d_ptr->switchWidgetHorizontally(event->pos()); 385 | else 386 | d_ptr->switchWidgetVertically(event->pos()); 387 | 388 | d_ptr->pressed = false; 389 | d_ptr->pressedPoint = QPoint(); 390 | setCursor(QCursor(Qt::ArrowCursor)); 391 | } 392 | } 393 | 394 | void SlideWidgetContainer::keyPressEvent(QKeyEvent* event) 395 | { 396 | switch (event->key()) { 397 | case Qt::Key_F1: 398 | if (d_ptr->orientation == Qt::Horizontal) 399 | d_ptr->switchWidgetHorizontally(QPoint(-DragThreshold + 10, 10)); 400 | else 401 | d_ptr->switchWidgetVertically(QPoint(10, -DragThreshold + 10)); 402 | break; 403 | 404 | case Qt::Key_F2: 405 | if (d_ptr->orientation == Qt::Horizontal) 406 | d_ptr->switchWidgetHorizontally(QPoint(DragThreshold + 10, 10)); 407 | else 408 | d_ptr->switchWidgetHorizontally(QPoint(10, DragThreshold + 10)); 409 | break; 410 | 411 | case Qt::Key_F3: 412 | d_ptr->orientation = (d_ptr->orientation == Qt::Horizontal) ? Qt::Vertical : Qt::Horizontal; 413 | break; 414 | } 415 | } 416 | 417 | 418 | -------------------------------------------------------------------------------- /slidewidgetcontainer.h: -------------------------------------------------------------------------------- 1 | #ifndef SLIDEWIDGETCONTAINER_H 2 | #define SLIDEWIDGETCONTAINER_H 3 | 4 | #include 5 | 6 | class SlideWidgetContainerPrivate; 7 | class SlideWidgetContainer : public QWidget 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit SlideWidgetContainer(QWidget *parent = 0); 12 | ~SlideWidgetContainer(); 13 | 14 | void addWidget(QWidget* widget); 15 | void removeWidget(QWidget* widget); 16 | int count() const; 17 | int currentIndex() const; 18 | 19 | void setOrientation(Qt::Orientation ori); 20 | Qt::Orientation orientation() const; 21 | 22 | protected: 23 | QSize sizeHint() const; 24 | void resizeEvent(QResizeEvent* event); 25 | void mousePressEvent(QMouseEvent* event); 26 | void mouseMoveEvent(QMouseEvent* event); 27 | void mouseReleaseEvent(QMouseEvent* event); 28 | void keyPressEvent(QKeyEvent* event); 29 | 30 | private: 31 | SlideWidgetContainerPrivate* d_ptr; 32 | Q_DISABLE_COPY(SlideWidgetContainer) 33 | }; 34 | 35 | #endif // SLIDEWIDGETCONTAINER_H 36 | -------------------------------------------------------------------------------- /tableselectionanimation.cpp: -------------------------------------------------------------------------------- 1 | #include "tableselectionanimation.h" 2 | #include "ui_tableselectionanimation.h" 3 | #include "frame.h" 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | static const int Duration = 300; 11 | static const QEasingCurve::Type EasingCurve = QEasingCurve::OutCubic; 12 | 13 | TableSelectionAnimation::TableSelectionAnimation(QWidget *parent) : 14 | QWidget(parent), 15 | m_ui(new Ui::TableSelectionAnimation) 16 | { 17 | m_ui->setupUi(this); 18 | m_ui->gridLayout->setContentsMargins(0, 0, 0, 0); 19 | 20 | QPalette p = m_ui->tableWidget->palette(); 21 | p.setColor(QPalette::Highlight, Qt::white); 22 | p.setColor(QPalette::HighlightedText, Qt::blue); 23 | m_ui->tableWidget->setPalette(p); 24 | 25 | populateTable(); 26 | m_frame = new Frame(this); 27 | m_frame->setColor(Qt::blue); 28 | m_frame->hide(); 29 | 30 | auto updateSingleItem = [this] (QTableWidgetItem* item) { 31 | QRect itemRect = m_ui->tableWidget->visualItemRect(item); 32 | int horHeaderHeight = m_ui->tableWidget->horizontalHeader()->height(); 33 | int verHeaderWidth = m_ui->tableWidget->verticalHeader()->width(); 34 | m_frame->show(); 35 | 36 | QRect newGeo(QPoint(itemRect.left() + verHeaderWidth, itemRect.top() + horHeaderHeight), itemRect.size()); 37 | 38 | QPropertyAnimation* anim = new QPropertyAnimation(m_frame, "geometry"); 39 | anim->setEasingCurve(EasingCurve); 40 | anim->setDuration(Duration); 41 | anim->setStartValue(m_frame->geometry()); 42 | anim->setEndValue(newGeo); 43 | anim->start(QAbstractAnimation::DeleteWhenStopped); 44 | }; 45 | 46 | connect(m_ui->tableWidget, &QTableWidget::itemClicked, [=, this] (QTableWidgetItem* item) { 47 | updateSingleItem(item); 48 | }); 49 | 50 | auto updateMultiItems = [this] (const QList& items) { 51 | if (items.isEmpty()) 52 | return; 53 | 54 | QRect firstRect = m_ui->tableWidget->visualItemRect(items.first()); 55 | QRect lastRect = m_ui->tableWidget->visualItemRect(items.last()); 56 | 57 | int xMin = firstRect.topLeft().x(); 58 | int yMin = firstRect.topLeft().y(); 59 | int xMax = lastRect.bottomRight().x(); 60 | int yMax = lastRect.bottomRight().y(); 61 | 62 | int horHeaderHeight = m_ui->tableWidget->horizontalHeader()->height(); 63 | int verHeaderWidth = m_ui->tableWidget->verticalHeader()->width(); 64 | m_frame->show(); 65 | 66 | QRect newGeo(QPoint(xMin + verHeaderWidth, yMin + horHeaderHeight), QSize(xMax - xMin, yMax - yMin)); 67 | 68 | QPropertyAnimation* anim = new QPropertyAnimation(m_frame, "geometry"); 69 | anim->setEasingCurve(EasingCurve); 70 | anim->setDuration(Duration); 71 | anim->setStartValue(m_frame->geometry()); 72 | anim->setEndValue(newGeo); 73 | anim->start(QAbstractAnimation::DeleteWhenStopped); 74 | }; 75 | 76 | connect(m_ui->tableWidget, &QTableWidget::itemSelectionChanged, [=, this] { 77 | updateMultiItems(m_ui->tableWidget->selectedItems()); 78 | }); 79 | 80 | auto onScrollBarValueChanged = [this] (int) { 81 | QList selectedItems = m_ui->tableWidget->selectedItems(); 82 | 83 | if (selectedItems.isEmpty()) 84 | return; 85 | 86 | if (selectedItems.size() == 1) { 87 | QRect itemRect = m_ui->tableWidget->visualItemRect(selectedItems.first()); 88 | int horHeaderHeight = m_ui->tableWidget->horizontalHeader()->height(); 89 | int verHeaderWidth = m_ui->tableWidget->verticalHeader()->width(); 90 | m_frame->show(); 91 | 92 | QRect newGeo(QPoint(itemRect.left() + verHeaderWidth, itemRect.top() + horHeaderHeight), itemRect.size()); 93 | 94 | QPropertyAnimation* anim = new QPropertyAnimation(m_frame, "geometry"); 95 | anim->setEasingCurve(EasingCurve); 96 | anim->setDuration(Duration); 97 | anim->setStartValue(m_frame->geometry()); 98 | anim->setEndValue(newGeo); 99 | anim->start(QAbstractAnimation::DeleteWhenStopped); 100 | 101 | } else if (selectedItems.size() >= 2) { 102 | QRect firstRect = m_ui->tableWidget->visualItemRect(selectedItems.first()); 103 | QRect lastRect = m_ui->tableWidget->visualItemRect(selectedItems.last()); 104 | 105 | int xMin = firstRect.topLeft().x(); 106 | int yMin = firstRect.topLeft().y(); 107 | int xMax = lastRect.bottomRight().x(); 108 | int yMax = lastRect.bottomRight().y(); 109 | 110 | int horHeaderHeight = m_ui->tableWidget->horizontalHeader()->height(); 111 | int verHeaderWidth = m_ui->tableWidget->verticalHeader()->width(); 112 | m_frame->show(); 113 | 114 | QRect newGeo(QPoint(xMin + verHeaderWidth, yMin + horHeaderHeight), QSize(xMax - xMin, yMax - yMin)); 115 | 116 | QPropertyAnimation* anim = new QPropertyAnimation(m_frame, "geometry"); 117 | anim->setEasingCurve(EasingCurve); 118 | anim->setDuration(Duration); 119 | anim->setStartValue(m_frame->geometry()); 120 | anim->setEndValue(newGeo); 121 | anim->start(QAbstractAnimation::DeleteWhenStopped); 122 | } 123 | }; 124 | 125 | connect(m_ui->tableWidget->horizontalScrollBar(), &QScrollBar::valueChanged, onScrollBarValueChanged); 126 | connect(m_ui->tableWidget->verticalScrollBar(), &QScrollBar::valueChanged, onScrollBarValueChanged); 127 | } 128 | 129 | TableSelectionAnimation::~TableSelectionAnimation() 130 | { 131 | delete m_ui; 132 | } 133 | 134 | void TableSelectionAnimation::populateTable() 135 | { 136 | const int Cols = 10; 137 | const int Rows = 100; 138 | 139 | m_ui->tableWidget->setColumnCount(Cols); 140 | m_ui->tableWidget->setRowCount(Rows); 141 | 142 | int index = 0; 143 | for (int col = 0; col < Cols; ++col) { 144 | for (int row = 0; row < Rows; ++row) { 145 | QTableWidgetItem* item = new QTableWidgetItem; 146 | item->setText(QString("Item %1").arg(++index)); 147 | m_ui->tableWidget->setItem(row, col, item); 148 | } 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /tableselectionanimation.h: -------------------------------------------------------------------------------- 1 | #ifndef TABLESELECTIONANIMATION_H 2 | #define TABLESELECTIONANIMATION_H 3 | 4 | #include 5 | 6 | namespace Ui 7 | { 8 | class TableSelectionAnimation; 9 | } 10 | 11 | class Frame; 12 | class TableSelectionAnimation : public QWidget 13 | { 14 | Q_OBJECT 15 | public: 16 | explicit TableSelectionAnimation(QWidget *parent = 0); 17 | ~TableSelectionAnimation(); 18 | 19 | private: 20 | void populateTable(); 21 | 22 | private: 23 | Ui::TableSelectionAnimation *m_ui; 24 | Frame* m_frame = nullptr; 25 | }; 26 | 27 | #endif // TABLESELECTIONANIMATION_H 28 | -------------------------------------------------------------------------------- /tableselectionanimation.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | TableSelectionAnimation 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 300 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /tagwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "tagwidget.h" 2 | #include "flowlayout.h" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | static const int TagMargin = 5; 11 | static const int RoundRadius = 6; 12 | 13 | #define COLOR_SCHEME1 14 | #ifdef COLOR_SCHEME1 15 | static const QColor NormalBackgroundColor = QColor(240, 240, 240); 16 | static const QColor HoverBackgroundColor = QColor(49, 101, 148); 17 | static const QColor NormalTextColor = QColor(69, 149, 212); 18 | static const QColor HoverTextColor = QColor(250, 250, 250); 19 | static const QColor BorderColor = QColor(211, 211, 211); 20 | #else 21 | static const QColor NormalBackgroundColor = QColor(254, 197, 86); 22 | static const QColor HoverBackgroundColor = QColor(255, 238, 100); 23 | static const QColor NormalTextColor = QColor(156, 124, 117); 24 | static const QColor HoverTextColor = QColor(156, 124, 117); 25 | static const QColor BorderColor = QColor(239, 187, 98); 26 | #endif 27 | 28 | class Tag : public QWidget 29 | { 30 | Q_OBJECT 31 | Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor) 32 | Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor) 33 | public: 34 | explicit Tag(QWidget* parent = nullptr); 35 | 36 | void setText(const QString& text); 37 | QString text() const; 38 | 39 | void setTextColor(const QColor& clr); 40 | QColor textColor() const; 41 | 42 | void setBackgroundColor(const QColor& clr); 43 | QColor backgroundColor() const; 44 | 45 | void setHoverBackgroundColor(const QColor& clr); 46 | QColor hoverBackgroundColor() const; 47 | 48 | protected: 49 | void enterEvent(QEvent* event); 50 | void leaveEvent(QEvent *event); 51 | void paintEvent(QPaintEvent* event); 52 | 53 | protected: 54 | QString m_text; 55 | QColor m_backgroundColor = NormalBackgroundColor; 56 | QColor m_textColor = NormalTextColor; 57 | }; 58 | 59 | Tag::Tag(QWidget *parent) : QWidget(parent) 60 | { 61 | setWindowFlags(Qt::FramelessWindowHint); 62 | } 63 | 64 | void Tag::setText(const QString& text) 65 | { 66 | if (m_text != text) { 67 | m_text = text; 68 | int textLen = fontMetrics().width(text); 69 | setFixedSize(QSize(textLen + 2 * TagMargin, fontMetrics().height() + 2 * TagMargin)); 70 | update(); 71 | } 72 | } 73 | 74 | QString Tag::text() const 75 | { 76 | return m_text; 77 | } 78 | 79 | void Tag::setTextColor(const QColor& clr) 80 | { 81 | if (m_textColor != clr) { 82 | m_textColor = clr; 83 | update(); 84 | } 85 | } 86 | 87 | QColor Tag::textColor() const 88 | { 89 | return m_textColor; 90 | } 91 | 92 | void Tag::setBackgroundColor(const QColor& clr) 93 | { 94 | if (m_backgroundColor != clr) { 95 | m_backgroundColor = clr; 96 | update(); 97 | } 98 | } 99 | 100 | QColor Tag::backgroundColor() const 101 | { 102 | return m_backgroundColor; 103 | } 104 | 105 | void Tag::enterEvent(QEvent* event) 106 | { 107 | QWidget::enterEvent(event); 108 | 109 | QPropertyAnimation* bgColorAnim = new QPropertyAnimation(this, "backgroundColor"); 110 | bgColorAnim->setEasingCurve(QEasingCurve::OutCubic); 111 | bgColorAnim->setDuration(1000); 112 | bgColorAnim->setStartValue(NormalBackgroundColor); 113 | bgColorAnim->setEndValue(HoverBackgroundColor); 114 | 115 | QPropertyAnimation* textColorAnim = new QPropertyAnimation(this, "textColor"); 116 | textColorAnim->setEasingCurve(QEasingCurve::OutCubic); 117 | textColorAnim->setDuration(1000); 118 | textColorAnim->setStartValue(NormalTextColor); 119 | textColorAnim->setEndValue(HoverTextColor); 120 | 121 | QParallelAnimationGroup* animGroup = new QParallelAnimationGroup(); 122 | animGroup->addAnimation(bgColorAnim); 123 | animGroup->addAnimation(textColorAnim); 124 | animGroup->start(QAbstractAnimation::DeleteWhenStopped); 125 | } 126 | 127 | void Tag::leaveEvent(QEvent *event) 128 | { 129 | QWidget::leaveEvent(event); 130 | 131 | QPropertyAnimation* bgColorAnim = new QPropertyAnimation(this, "backgroundColor"); 132 | bgColorAnim->setEasingCurve(QEasingCurve::OutCubic); 133 | bgColorAnim->setDuration(1000); 134 | bgColorAnim->setStartValue(HoverBackgroundColor); 135 | bgColorAnim->setEndValue(NormalBackgroundColor); 136 | 137 | QPropertyAnimation* textColorAnim = new QPropertyAnimation(this, "textColor"); 138 | textColorAnim->setEasingCurve(QEasingCurve::OutCubic); 139 | textColorAnim->setDuration(1000); 140 | textColorAnim->setStartValue(HoverTextColor); 141 | textColorAnim->setEndValue(NormalTextColor); 142 | 143 | QParallelAnimationGroup* animGroup = new QParallelAnimationGroup(); 144 | animGroup->addAnimation(bgColorAnim); 145 | animGroup->addAnimation(textColorAnim); 146 | animGroup->start(QAbstractAnimation::DeleteWhenStopped); 147 | } 148 | 149 | void Tag::paintEvent(QPaintEvent* event) 150 | { 151 | Q_UNUSED(event) 152 | QPainter painter(this); 153 | painter.setRenderHints(QPainter::Antialiasing); 154 | 155 | // draw background 156 | painter.save(); 157 | painter.setBrush(QBrush(m_backgroundColor)); 158 | painter.setPen(QPen(BorderColor, 1)); 159 | painter.drawRoundedRect(rect(), RoundRadius, RoundRadius); 160 | painter.restore(); 161 | 162 | // draw text 163 | painter.save(); 164 | painter.setPen(QPen(m_textColor, 1)); 165 | painter.drawText(rect(), m_text, Qt::AlignHCenter | Qt::AlignVCenter); 166 | painter.restore(); 167 | } 168 | 169 | class TagWidgetPrivate 170 | { 171 | public: 172 | void init(); 173 | 174 | TagWidget* q_ptr; 175 | QWidget* container; 176 | FlowLayout* layout; 177 | 178 | QMap tags; 179 | }; 180 | 181 | void TagWidgetPrivate::init() 182 | { 183 | container = new QWidget(q_ptr); 184 | container->setStyleSheet("background-color:white;"); 185 | q_ptr->setWidget(container); 186 | q_ptr->setWidgetResizable(true); 187 | 188 | layout = new FlowLayout; 189 | container->setLayout(layout); 190 | } 191 | 192 | TagWidget::TagWidget(QWidget* parent) : QScrollArea(parent) 193 | { 194 | d_ptr = new TagWidgetPrivate; 195 | d_ptr->q_ptr = this; 196 | d_ptr->init(); 197 | } 198 | 199 | TagWidget::~TagWidget() 200 | { 201 | delete d_ptr; 202 | } 203 | 204 | void TagWidget::addTag(const QString& name) 205 | { 206 | if (d_ptr->tags.contains(name)) 207 | return; 208 | 209 | Tag* tag = new Tag(this); 210 | tag->setText(name); 211 | d_ptr->layout->addWidget(tag); 212 | d_ptr->tags.insert(name, tag); 213 | } 214 | 215 | void TagWidget::removeTag(const QString& name) 216 | { 217 | if (!d_ptr->tags.contains(name)) 218 | return; 219 | 220 | Tag* tag = d_ptr->tags.value(name); 221 | delete tag; 222 | d_ptr->tags.remove(name); 223 | } 224 | 225 | void TagWidget::clear() 226 | { 227 | qDeleteAll(d_ptr->tags.values()); 228 | d_ptr->tags.clear(); 229 | } 230 | 231 | QStringList TagWidget::tags() const 232 | { 233 | return d_ptr->tags.keys(); 234 | } 235 | 236 | #include "tagwidget.moc" 237 | -------------------------------------------------------------------------------- /tagwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef TAGWIDGET_H 2 | #define TAGWIDGET_H 3 | 4 | #include 5 | 6 | class TagWidgetPrivate; 7 | class TagWidget : public QScrollArea 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit TagWidget(QWidget* parent = nullptr); 12 | ~TagWidget(); 13 | 14 | void addTag(const QString& name); 15 | void removeTag(const QString& name); 16 | void clear(); 17 | 18 | QStringList tags() const; 19 | 20 | private: 21 | TagWidgetPrivate* d_ptr; 22 | Q_DISABLE_COPY(TagWidget) 23 | }; 24 | 25 | #endif // TAGWIDGET_H 26 | -------------------------------------------------------------------------------- /tstflowlayout.cpp: -------------------------------------------------------------------------------- 1 | #include "tstflowlayout.h" 2 | #include "ui_tstflowlayout.h" 3 | #include "flowlayout.h" 4 | 5 | #include 6 | 7 | TstFlowLayout::TstFlowLayout(QWidget *parent) : 8 | QWidget(parent), 9 | m_ui(new Ui::TstFlowLayout) 10 | { 11 | m_ui->setupUi(this); 12 | 13 | m_flowLayout = new FlowLayout(); 14 | m_flowLayout->setAnimated(true); 15 | m_ui->previewGroupBox->setLayout(m_flowLayout); 16 | 17 | populateButtons(); 18 | } 19 | 20 | TstFlowLayout::~TstFlowLayout() 21 | { 22 | delete m_ui; 23 | } 24 | 25 | void TstFlowLayout::on_addButton_clicked() 26 | { 27 | m_flowLayout->addWidget(createButton()); 28 | } 29 | 30 | void TstFlowLayout::populateButtons() 31 | { 32 | for (int i = 0; i < 50; ++i) 33 | m_flowLayout->addWidget(createButton()); 34 | } 35 | 36 | QToolButton* TstFlowLayout::createButton() 37 | { 38 | QToolButton* button = new QToolButton(this); 39 | button->setIconSize(QSize(32, 32)); 40 | button->setAutoRaise(true); 41 | button->setIcon(QIcon(":/images/bug.png")); 42 | connect(button, &QAbstractButton::clicked, [this, button] { 43 | m_flowLayout->removeWidget(button); 44 | m_flowLayout->update(); 45 | button->deleteLater(); 46 | }); 47 | 48 | return button; 49 | } 50 | -------------------------------------------------------------------------------- /tstflowlayout.h: -------------------------------------------------------------------------------- 1 | #ifndef TSTFLOWLAYOUT_H 2 | #define TSTFLOWLAYOUT_H 3 | 4 | #include 5 | 6 | namespace Ui 7 | { 8 | class TstFlowLayout; 9 | } 10 | 11 | class FlowLayout; 12 | class QToolButton; 13 | class TstFlowLayout : public QWidget 14 | { 15 | Q_OBJECT 16 | public: 17 | explicit TstFlowLayout(QWidget *parent = 0); 18 | ~TstFlowLayout(); 19 | 20 | private slots: 21 | void on_addButton_clicked(); 22 | 23 | private: 24 | void populateButtons(); 25 | QToolButton* createButton(); 26 | 27 | private: 28 | Ui::TstFlowLayout *m_ui; 29 | FlowLayout* m_flowLayout; 30 | }; 31 | 32 | #endif // TSTFLOWLAYOUT_H 33 | -------------------------------------------------------------------------------- /tstflowlayout.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | TstFlowLayout 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 300 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 20 | Qt::Horizontal 21 | 22 | 23 | 24 | 25 | 80 26 | 16777215 27 | 28 | 29 | 30 | Config 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | Add 39 | 40 | 41 | 42 | 43 | 44 | 45 | Qt::Vertical 46 | 47 | 48 | 49 | 20 50 | 40 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | Preview 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /tsttagwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "tsttagwidget.h" 2 | #include "ui_tsttagwidget.h" 3 | #include "tagwidget.h" 4 | 5 | TstTagWidget::TstTagWidget(QWidget *parent) : 6 | QWidget(parent), 7 | m_ui(new Ui::TstTagWidget) 8 | { 9 | m_ui->setupUi(this); 10 | m_tagWidget = new TagWidget(this); 11 | m_ui->previewLayout->addWidget(m_tagWidget); 12 | 13 | // populate tags 14 | for (int i = 0; i < 100; ++i) 15 | m_tagWidget->addTag(QString("Tag %1").arg(i + 1)); 16 | } 17 | 18 | TstTagWidget::~TstTagWidget() 19 | { 20 | delete m_ui; 21 | } 22 | 23 | void TstTagWidget::on_pushButton_clicked() 24 | { 25 | m_tagWidget->addTag(m_ui->tagEdit->text()); 26 | } 27 | 28 | void TstTagWidget::on_tagEdit_returnPressed() 29 | { 30 | m_tagWidget->addTag(m_ui->tagEdit->text()); 31 | } 32 | -------------------------------------------------------------------------------- /tsttagwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef TSTTAGWIDGET_H 2 | #define TSTTAGWIDGET_H 3 | 4 | #include 5 | 6 | namespace Ui 7 | { 8 | class TstTagWidget; 9 | } 10 | 11 | class TagWidget; 12 | class TstTagWidget : public QWidget 13 | { 14 | Q_OBJECT 15 | public: 16 | explicit TstTagWidget(QWidget *parent = 0); 17 | ~TstTagWidget(); 18 | 19 | private slots: 20 | void on_pushButton_clicked(); 21 | void on_tagEdit_returnPressed(); 22 | 23 | private: 24 | Ui::TstTagWidget *m_ui; 25 | TagWidget* m_tagWidget = nullptr; 26 | }; 27 | 28 | #endif // TSTTAGWIDGET_H 29 | -------------------------------------------------------------------------------- /tsttagwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | TstTagWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 515 10 | 260 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 20 | Qt::Horizontal 21 | 22 | 23 | 24 | 25 | 250 26 | 16777215 27 | 28 | 29 | 30 | Config 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | Add Tag 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | Tag: 49 | 50 | 51 | 52 | 53 | 54 | 55 | Qt::Vertical 56 | 57 | 58 | 59 | 20 60 | 40 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | Preview 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "ui_widget.h" 3 | #include "changeshapecanvas.h" 4 | #include "slidetextanimation.h" 5 | #include "layoutwindowsanimation.h" 6 | #include "colorball.h" 7 | #include "tagwidget.h" 8 | #include "tsttagwidget.h" 9 | #include "bounceindicator.h" 10 | #include "slidewidgetcontainer.h" 11 | #include "tstflowlayout.h" 12 | #include "explodeanimation.h" 13 | #include "tableselectionanimation.h" 14 | #include "lednumberanimation.h" 15 | #include "slidemenuanimation.h" 16 | #include "shadowwindow.h" 17 | #include "inputdialog.h" 18 | #include "circle.h" 19 | #include "flyawayanimation.h" 20 | #include "highlighwindow.h" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #ifdef Q_OS_WIN 32 | #include 33 | #endif 34 | 35 | static const int Duration = 500; 36 | 37 | Widget::Widget(QWidget *parent) : 38 | QWidget(parent), 39 | m_ui(new Ui::Widget) 40 | { 41 | m_ui->setupUi(this); 42 | m_ui->toolButton->setIcon(QIcon(":/images/navigate.png")); 43 | m_ui->toolButton->setIconSize(QSize(64, 64)); 44 | } 45 | 46 | Widget::~Widget() 47 | { 48 | delete m_ui; 49 | } 50 | 51 | float Widget::rotation() const 52 | { 53 | return m_rotation; 54 | } 55 | 56 | void Widget::setRotation(float rotation) 57 | { 58 | m_rotation = rotation; 59 | 60 | if (!m_flipLabel) { 61 | m_flipLabel = new QLabel(); 62 | } 63 | 64 | m_flipLabel->setWindowTitle(windowTitle()); 65 | m_flipLabel->move(pos()); 66 | m_flipLabel->resize(size()); 67 | m_flipLabel->show(); 68 | 69 | QPixmap pixmap = grab(rect()); 70 | QPainter painter(&pixmap); 71 | 72 | QTransform transform; 73 | transform.translate(width() / 2, 0); 74 | 75 | if(m_rotation > 90) 76 | transform.rotate(m_rotation + 180, Qt::YAxis); 77 | else 78 | transform.rotate(m_rotation, Qt::YAxis); 79 | 80 | painter.setTransform(transform); 81 | painter.drawPixmap(-1 * width() / 2, 0, pixmap); 82 | m_flipLabel->setPixmap(pixmap); 83 | } 84 | 85 | void Widget::flyIn() 86 | { 87 | // TODO 88 | } 89 | 90 | void Widget::flyOut() 91 | { 92 | // TODO 93 | } 94 | 95 | QSize Widget::sizeHint() const 96 | { 97 | return QSize(300, 500); 98 | } 99 | 100 | void Widget::closeEvent(QCloseEvent* e) 101 | { 102 | m_keepRaining = false; 103 | QWidget::close(); 104 | } 105 | 106 | void Widget::on_resizeButton_clicked() 107 | { 108 | doAnimation(); 109 | } 110 | 111 | void Widget::on_easingCurveCombo_currentIndexChanged(int index) 112 | { 113 | m_easingCurve = index; 114 | } 115 | 116 | void Widget::doAnimation() 117 | { 118 | #if 1 119 | QPropertyAnimation* animation = new QPropertyAnimation(this, "size"); 120 | animation->setDuration(Duration); 121 | animation->setStartValue(this->size()); 122 | animation->setEasingCurve(QEasingCurve(static_cast(m_easingCurve))); 123 | animation->setEndValue(QSize(width() + 30, height() + 100)); 124 | // animation->start(QAbstractAnimation::DeleteWhenStopped); 125 | #elif 1 126 | QPropertyAnimation *animation = new QPropertyAnimation(this, "pos"); 127 | animation->setDuration(Duration); 128 | animation->setEasingCurve(QEasingCurve(static_cast(m_easingCurve))); 129 | animation->setStartValue(this->pos()); 130 | animation->setEndValue(QPoint(0,0)); 131 | animation->start(QAbstractAnimation::DeleteWhenStopped); 132 | #elif 0 133 | QRect startRect(60, 0, 5, 5); 134 | QRect endRect(60, 0, 300, 300); 135 | QPropertyAnimation *animation = new QPropertyAnimation(this, "geometry"); 136 | animation->setDuration(Duration); 137 | animation->setEasingCurve(QEasingCurve(static_cast(m_easingCurve))); 138 | animation->setStartValue(startRect); 139 | animation->setEndValue(endRect); 140 | animation->start(QAbstractAnimation::DeleteWhenStopped); 141 | #endif 142 | 143 | QPropertyAnimation* animation2 = new QPropertyAnimation(this, "windowOpacity"); 144 | animation2->setDuration(Duration); 145 | animation2->setEasingCurve(QEasingCurve::Linear); 146 | animation2->setStartValue(0.0); 147 | animation2->setEndValue(1.0); 148 | // animation2->start(QAbstractAnimation::DeleteWhenStopped); 149 | 150 | QParallelAnimationGroup *group = new QParallelAnimationGroup; 151 | group->addAnimation(animation); 152 | group->addAnimation(animation2); 153 | group->start(QAbstractAnimation::DeleteWhenStopped); 154 | } 155 | 156 | void Widget::on_dropShadowCheckBox_toggled(bool checked) 157 | { 158 | 159 | QList buttons = findChildren(); 160 | foreach (QPushButton* button, buttons) { 161 | QGraphicsDropShadowEffect* effect = new QGraphicsDropShadowEffect(this); 162 | effect->setBlurRadius(15); 163 | effect->setOffset(0); 164 | button->setGraphicsEffect(checked ? effect : nullptr); 165 | } 166 | } 167 | 168 | void Widget::on_shakeButton_clicked() 169 | { 170 | const int DeltaPos = 10; 171 | 172 | QPropertyAnimation *animation = new QPropertyAnimation(this, "pos"); 173 | animation->setDuration(500); 174 | 175 | if (m_ui->shakeDirectionCombo->currentIndex() == 0) { 176 | int oldX = pos().x(); 177 | animation->setEasingCurve(QEasingCurve(static_cast(m_easingCurve))); 178 | animation->setKeyValueAt(0.0, QPoint(oldX - DeltaPos, pos().y())); 179 | animation->setKeyValueAt(0.1, QPoint(oldX + DeltaPos, pos().y())); 180 | animation->setKeyValueAt(0.2, QPoint(oldX - DeltaPos, pos().y())); 181 | animation->setKeyValueAt(0.3, QPoint(oldX + DeltaPos, pos().y())); 182 | animation->setKeyValueAt(0.4, QPoint(oldX - DeltaPos, pos().y())); 183 | animation->setKeyValueAt(0.5, QPoint(oldX + DeltaPos, pos().y())); 184 | animation->setKeyValueAt(0.6, QPoint(oldX - DeltaPos, pos().y())); 185 | animation->setKeyValueAt(0.7, QPoint(oldX + DeltaPos, pos().y())); 186 | animation->setKeyValueAt(0.8, QPoint(oldX - DeltaPos, pos().y())); 187 | animation->setKeyValueAt(0.9, QPoint(oldX + DeltaPos, pos().y())); 188 | animation->setKeyValueAt(1.0, QPoint(oldX, pos().y())); 189 | } else { 190 | int oldY = pos().y(); 191 | animation->setEasingCurve(QEasingCurve(static_cast(m_easingCurve))); 192 | animation->setKeyValueAt(0.0, QPoint(pos().x(), oldY + DeltaPos)); 193 | animation->setKeyValueAt(0.1, QPoint(pos().x(), oldY - DeltaPos)); 194 | animation->setKeyValueAt(0.2, QPoint(pos().x(), oldY + DeltaPos)); 195 | animation->setKeyValueAt(0.3, QPoint(pos().x(), oldY - DeltaPos)); 196 | animation->setKeyValueAt(0.4, QPoint(pos().x(), oldY + DeltaPos)); 197 | animation->setKeyValueAt(0.5, QPoint(pos().x(), oldY - DeltaPos)); 198 | animation->setKeyValueAt(0.6, QPoint(pos().x(), oldY + DeltaPos)); 199 | animation->setKeyValueAt(0.7, QPoint(pos().x(), oldY - DeltaPos)); 200 | animation->setKeyValueAt(0.8, QPoint(pos().x(), oldY + DeltaPos)); 201 | animation->setKeyValueAt(0.9, QPoint(pos().x(), oldY - DeltaPos)); 202 | animation->setKeyValueAt(1.0, QPoint(pos().x(), oldY)); 203 | } 204 | animation->start(QAbstractAnimation::DeleteWhenStopped); 205 | } 206 | 207 | void Widget::on_shrinkButton_clicked() 208 | { 209 | m_shrinkOldSize = size(); 210 | QPropertyAnimation* sizeAnim = new QPropertyAnimation(this, "size"); 211 | sizeAnim->setStartValue(size()); 212 | sizeAnim->setEasingCurve(QEasingCurve(static_cast(m_easingCurve))); 213 | sizeAnim->setEndValue(QSize(width(), this->minimumHeight())); 214 | 215 | QPoint topLeft = pos(); 216 | m_shrinkOldPos = topLeft; 217 | QPropertyAnimation* posAnim = new QPropertyAnimation(this, "pos"); 218 | posAnim->setStartValue(topLeft); 219 | posAnim->setEndValue(QPoint(topLeft.x(), topLeft.y() + (height() - minimumHeight())/ 2)); 220 | posAnim->setEasingCurve(QEasingCurve(static_cast(m_easingCurve))); 221 | 222 | QParallelAnimationGroup* animGroup = new QParallelAnimationGroup(this); 223 | animGroup->addAnimation(sizeAnim); 224 | animGroup->addAnimation(posAnim); 225 | animGroup->start(QAbstractAnimation::DeleteWhenStopped); 226 | } 227 | 228 | void Widget::on_expandButton_clicked() 229 | { 230 | QPropertyAnimation* sizeAnim = new QPropertyAnimation(this, "size"); 231 | sizeAnim->setStartValue(size()); 232 | sizeAnim->setEasingCurve(QEasingCurve(static_cast(m_easingCurve))); 233 | sizeAnim->setEndValue(m_shrinkOldSize); 234 | 235 | QPoint topLeft = pos(); 236 | QPropertyAnimation* posAnim = new QPropertyAnimation(this, "pos"); 237 | posAnim->setStartValue(topLeft); 238 | posAnim->setEndValue(m_shrinkOldPos); 239 | posAnim->setEasingCurve(QEasingCurve(static_cast(m_easingCurve))); 240 | 241 | QParallelAnimationGroup* animGroup = new QParallelAnimationGroup(this); 242 | animGroup->addAnimation(sizeAnim); 243 | animGroup->addAnimation(posAnim); 244 | animGroup->start(QAbstractAnimation::DeleteWhenStopped); 245 | } 246 | 247 | void Widget::on_shakeDirectionCombo_currentIndexChanged(int index) 248 | { 249 | Q_UNUSED(index) 250 | on_shakeButton_clicked(); 251 | } 252 | 253 | void Widget::on_fadeInButton_clicked() 254 | { 255 | QPropertyAnimation* opacityAnim = new QPropertyAnimation(this, "windowOpacity"); 256 | opacityAnim->setStartValue(0); 257 | opacityAnim->setEndValue(1); 258 | opacityAnim->setDuration(1000); 259 | opacityAnim->setEasingCurve(QEasingCurve(static_cast(m_easingCurve))); 260 | 261 | QPropertyAnimation* sizeAnim = new QPropertyAnimation(this, "size"); 262 | sizeAnim->setStartValue(QSize(sizeHint().width(), 0)); 263 | sizeAnim->setEndValue(this->sizeHint()); 264 | sizeAnim->setDuration(1000); 265 | sizeAnim->setEasingCurve(QEasingCurve(static_cast(m_easingCurve))); 266 | 267 | QParallelAnimationGroup* animGroup = new QParallelAnimationGroup(this); 268 | animGroup->addAnimation(opacityAnim); 269 | animGroup->addAnimation(sizeAnim); 270 | animGroup->start(QAbstractAnimation::DeleteWhenStopped); 271 | } 272 | 273 | void Widget::on_fadeOutButton_clicked() 274 | { 275 | 276 | } 277 | 278 | void Widget::on_flipButton_clicked() 279 | { 280 | QPropertyAnimation *flipAnim = new QPropertyAnimation(this, "rotation"); 281 | flipAnim->setDuration(5000); 282 | flipAnim->setEasingCurve(QEasingCurve::InQuad); 283 | flipAnim->setStartValue(0); 284 | flipAnim->setEndValue(180); 285 | connect(flipAnim, &QAbstractAnimation::finished, [this] () { 286 | m_fliping = false; 287 | m_flipLabel->hide(); 288 | show(); 289 | }); 290 | 291 | flipAnim->start(QAbstractAnimation::DeleteWhenStopped); 292 | hide(); 293 | m_fliping = true; 294 | } 295 | 296 | void Widget::on_newWindowButton_clicked() 297 | { 298 | QPushButton* nwButton = m_ui->newWindowButton; 299 | QPoint nwButtonGlobalTopLeft = mapToGlobal(nwButton->geometry().topLeft()); 300 | 301 | QWidget* fooWidget = new QWidget(); 302 | 303 | QPropertyAnimation* resizeAnim = new QPropertyAnimation(fooWidget, "size"); 304 | resizeAnim->setDuration(500); 305 | resizeAnim->setEasingCurve(static_cast(m_easingCurve)); 306 | resizeAnim->setStartValue(nwButton->size()); 307 | resizeAnim->setEndValue(QSize(500, 400)); 308 | 309 | QPropertyAnimation* posAnim = new QPropertyAnimation(fooWidget, "pos"); 310 | posAnim->setDuration(500); 311 | posAnim->setEasingCurve(static_cast(m_easingCurve)); 312 | posAnim->setStartValue(nwButtonGlobalTopLeft); 313 | posAnim->setEndValue(QPoint(300, 200)); 314 | 315 | QParallelAnimationGroup* animGroup = new QParallelAnimationGroup(); 316 | animGroup->addAnimation(resizeAnim); 317 | animGroup->addAnimation(posAnim); 318 | animGroup->start(QAbstractAnimation::DeleteWhenStopped); 319 | 320 | connect(animGroup, &QAbstractAnimation::finished, [=] () { 321 | QTimer::singleShot(3000, fooWidget, SLOT(deleteLater())); 322 | }); 323 | 324 | fooWidget->show(); 325 | } 326 | 327 | void Widget::on_changeShapeButton_clicked() 328 | { 329 | ChangeShapeCanvas* canvas = new ChangeShapeCanvas; 330 | canvas->show(); 331 | } 332 | 333 | void Widget::on_slideTextButton_clicked() 334 | { 335 | SlideTextAnimation* sta = new SlideTextAnimation; 336 | sta->show(); 337 | } 338 | 339 | void Widget::on_layoutWindowsButton_clicked() 340 | { 341 | LayoutWindowsAnimation* lwa = new LayoutWindowsAnimation; 342 | lwa->show(); 343 | } 344 | 345 | void Widget::on_toolButton_clicked() 346 | { 347 | QPropertyAnimation* shrinkAnim = new QPropertyAnimation(m_ui->toolButton, "iconSize"); 348 | shrinkAnim->setEasingCurve(QEasingCurve::OutCubic); 349 | shrinkAnim->setDuration(300); 350 | shrinkAnim->setStartValue(QSize(64, 64)); 351 | shrinkAnim->setEndValue(QSize(32, 32)); 352 | 353 | QPropertyAnimation* enlargeAnim = new QPropertyAnimation(m_ui->toolButton, "iconSize"); 354 | enlargeAnim->setEasingCurve(QEasingCurve::OutCubic); 355 | enlargeAnim->setDuration(300); 356 | enlargeAnim->setStartValue(QSize(32, 32)); 357 | enlargeAnim->setEndValue(QSize(64, 64)); 358 | 359 | QSequentialAnimationGroup* animGroup = new QSequentialAnimationGroup(); 360 | animGroup->addAnimation(shrinkAnim); 361 | animGroup->addAnimation(enlargeAnim); 362 | animGroup->start(QAbstractAnimation::DeleteWhenStopped); 363 | } 364 | 365 | int getTaskBarHeight() 366 | { 367 | #ifdef Q_OS_WIN 368 | // return 35; 369 | RECT rect; 370 | HWND taskBar = FindWindow(L"Shell_traywnd", NULL); 371 | if(taskBar && GetWindowRect(taskBar, &rect)) 372 | return rect.bottom - rect.top; 373 | #else 374 | return 0; 375 | #endif 376 | } 377 | 378 | void Widget::on_popupWindowButton_clicked() 379 | { 380 | QWidget* widget = new QWidget; 381 | widget->resize(QSize(150, 100)); 382 | widget->show(); 383 | 384 | QDesktopWidget desktop; 385 | QRect desktopRect = desktop.availableGeometry(); 386 | const int HorMargin = 10; 387 | 388 | QPropertyAnimation* posAnim = new QPropertyAnimation(widget, "pos"); 389 | posAnim->setEasingCurve(QEasingCurve::OutCubic); 390 | posAnim->setDuration(500); 391 | posAnim->setStartValue(QPoint(desktopRect.bottomRight().x() - widget->width() - HorMargin, desktopRect.bottomRight().y() - getTaskBarHeight())); 392 | posAnim->setEndValue(QPoint(desktopRect.bottomRight().x() - widget->width() - HorMargin, desktopRect.bottomRight().y() - widget->height() - getTaskBarHeight())); 393 | 394 | QPropertyAnimation* opacityAnim = new QPropertyAnimation(widget, "windowOpacity"); 395 | opacityAnim->setEasingCurve(QEasingCurve::OutCubic); 396 | opacityAnim->setDuration(500); 397 | opacityAnim->setStartValue(0); 398 | opacityAnim->setEndValue(1); 399 | 400 | QParallelAnimationGroup* animGroup = new QParallelAnimationGroup(this); 401 | animGroup->addAnimation(posAnim); 402 | animGroup->addAnimation(opacityAnim); 403 | animGroup->start(QAbstractAnimation::DeleteWhenStopped); 404 | 405 | connect(animGroup, &QAbstractAnimation::finished, [widget] () { 406 | QTimer::singleShot(1000, widget, SLOT(deleteLater())); 407 | }); 408 | } 409 | 410 | void Widget::on_slideInButton_clicked() 411 | { 412 | QDesktopWidget desktop; 413 | QRect desktopRect = desktop.availableGeometry(); 414 | 415 | if (!m_colorBall) { 416 | m_colorBall = new ColorBall(); 417 | m_colorBall->setColor(QColor(qrand() % 255, qrand() % 255, qrand() % 255)); 418 | } 419 | 420 | m_colorBall->show(); 421 | 422 | QPropertyAnimation* anim = new QPropertyAnimation(m_colorBall, "pos"); 423 | anim->setEasingCurve(static_cast(m_easingCurve)); 424 | anim->setDuration(500); 425 | anim->setStartValue(QPoint(desktopRect.width() + m_colorBall->width(), 20)); 426 | anim->setEndValue(QPoint(m_colorBall->width()/*desktopRect.width() - m_colorBall->width() * 2*/, 20)); 427 | anim->start(QAbstractAnimation::DeleteWhenStopped); 428 | } 429 | 430 | void Widget::on_slideOutButton_clicked() 431 | { 432 | QDesktopWidget desktop; 433 | QRect desktopRect = desktop.availableGeometry(); 434 | 435 | if (!m_colorBall) { 436 | m_colorBall = new ColorBall(); 437 | m_colorBall->setColor(QColor(qrand() % 255, qrand() % 255, qrand() % 255)); 438 | } 439 | 440 | m_colorBall->show(); 441 | 442 | QPropertyAnimation* anim = new QPropertyAnimation(m_colorBall, "pos"); 443 | anim->setEasingCurve(static_cast(m_easingCurve)); 444 | anim->setDuration(500); 445 | anim->setStartValue(m_colorBall->pos()); 446 | anim->setEndValue(QPoint(desktopRect.width() + m_colorBall->width(), 20)); 447 | anim->start(QAbstractAnimation::DeleteWhenStopped); 448 | } 449 | 450 | void Widget::on_tagButton_clicked() 451 | { 452 | TstTagWidget* tagWidget = new TstTagWidget; 453 | tagWidget->show(); 454 | } 455 | 456 | void Widget::on_imageCarouselButton_clicked() 457 | { 458 | 459 | } 460 | 461 | void Widget::on_bounceButton_clicked() 462 | { 463 | BounceIndicator* bi = new BounceIndicator; 464 | bi->setAnimationStarted(true); 465 | bi->show(); 466 | } 467 | 468 | void Widget::on_slideWidgetButton_clicked() 469 | { 470 | SlideWidgetContainer* container = new SlideWidgetContainer(); 471 | 472 | // populate tags 473 | for (int tagIndex = 0; tagIndex < 5; ++tagIndex) { 474 | TagWidget* tagWidget = new TagWidget(container); 475 | tagWidget->setStyleSheet(QString("background-color:rgb(%1, %2, %3);").arg(qrand() % 255).arg(qrand() % 255).arg(qrand() % 255)); 476 | 477 | for (int i = 0; i < 100; ++i) 478 | tagWidget->addTag(QString("Tag %1").arg(i + 1)); 479 | container->addWidget(tagWidget); 480 | } 481 | 482 | container->show(); 483 | } 484 | 485 | void Widget::on_fadingCheckBox_toggled(bool checked) 486 | { 487 | QList buttons = findChildren(); 488 | const int MaxBlurRadius = 30; 489 | const int MinBlurRadius = 3; 490 | const int Duration = 1000; 491 | foreach (QAbstractButton* button, buttons) { 492 | QGraphicsDropShadowEffect* effect = new QGraphicsDropShadowEffect(this); 493 | effect->setBlurRadius(15); 494 | effect->setOffset(0); 495 | button->setGraphicsEffect(checked ? effect : nullptr); 496 | 497 | if (checked) { 498 | QPropertyAnimation* anim = new QPropertyAnimation(effect, "blurRadius"); 499 | anim->setDuration(Duration); 500 | anim->setEasingCurve(QEasingCurve::Linear); 501 | anim->setStartValue(MinBlurRadius); 502 | anim->setEndValue(MaxBlurRadius); 503 | connect(anim, &QAbstractAnimation::finished, [=] { 504 | QPropertyAnimation* reverseAnim = new QPropertyAnimation(effect, "blurRadius"); 505 | reverseAnim->setDuration(Duration); 506 | reverseAnim->setEasingCurve(QEasingCurve::Linear); 507 | reverseAnim->setStartValue(MaxBlurRadius); 508 | reverseAnim->setEndValue(MinBlurRadius); 509 | reverseAnim->start(); 510 | connect(reverseAnim, &QAbstractAnimation::finished, [=] { 511 | anim->start(); 512 | }); 513 | }); 514 | anim->start(); 515 | } 516 | } 517 | } 518 | 519 | void Widget::on_tstFlowLayout_clicked() 520 | { 521 | static TstFlowLayout* tstFlowLayout = nullptr; 522 | if (!tstFlowLayout) 523 | tstFlowLayout = new TstFlowLayout; 524 | tstFlowLayout->show(); 525 | } 526 | 527 | void Widget::on_explodeButton_clicked() 528 | { 529 | ExplodeAnimation* explodeAnim = new ExplodeAnimation; 530 | explodeAnim->show(); 531 | } 532 | 533 | void Widget::on_tableSelectionButton_clicked() 534 | { 535 | TableSelectionAnimation* tableSelectionAnimation = new TableSelectionAnimation(); 536 | tableSelectionAnimation->show(); 537 | } 538 | 539 | void Widget::on_ledDisplayButton_clicked() 540 | { 541 | LedNumberAnimation* lna = new LedNumberAnimation; 542 | lna->show(); 543 | } 544 | 545 | void Widget::on_slideMenuButton_clicked() 546 | { 547 | SlideMenuAnimation* sma = new SlideMenuAnimation; 548 | sma->show(); 549 | } 550 | 551 | void Widget::on_shadowWindowButton_clicked() 552 | { 553 | ShadowWindow* sw = new ShadowWindow; 554 | sw->show(); 555 | } 556 | 557 | void Widget::on_inputButton_clicked() 558 | { 559 | InputDialog* inputDlg = new InputDialog; 560 | inputDlg->show(); 561 | } 562 | 563 | void Widget::on_rainButton_toggled(bool checked) 564 | { 565 | m_keepRaining = checked; 566 | makeItRain(); 567 | } 568 | 569 | void delay(int millisecondsToWait) 570 | { 571 | QTime dieTime = QTime::currentTime().addMSecs( millisecondsToWait ); 572 | while( QTime::currentTime() < dieTime ) 573 | QCoreApplication::processEvents( QEventLoop::AllEvents, 100 ); 574 | } 575 | 576 | void Widget::makeItRain() 577 | { 578 | QDesktopWidget desktop; 579 | int desktopWidth = desktop.screen()->width(); 580 | int desktopHeight = desktop.screen()->height(); 581 | 582 | QPoint randomPos; 583 | while (m_keepRaining) { 584 | randomPos = QPoint(qrand() % desktopWidth, qrand() % desktopHeight); 585 | 586 | Circle* circle = new Circle(); 587 | circle->move(randomPos); 588 | circle->show(); 589 | 590 | //#define RAINBOW_RAIN 591 | #ifdef RAINBOW_RAIN 592 | circle->setColor(QColor(qrand() % 255, qrand() % 255, qrand() % 255)); 593 | #endif 594 | 595 | QPropertyAnimation* radiusAnim = new QPropertyAnimation(circle, "radius"); 596 | radiusAnim->setEasingCurve(QEasingCurve::Linear); 597 | radiusAnim->setDuration(1000); 598 | radiusAnim->setStartValue(1); 599 | radiusAnim->setEndValue(80); 600 | 601 | QPropertyAnimation* opacityAnim = new QPropertyAnimation(circle, "windowOpacity"); 602 | opacityAnim->setEasingCurve(QEasingCurve::Linear); 603 | opacityAnim->setDuration(1000); 604 | opacityAnim->setStartValue(1); 605 | opacityAnim->setEndValue(0); 606 | 607 | QParallelAnimationGroup* animGroup = new QParallelAnimationGroup(); 608 | animGroup->addAnimation(radiusAnim); 609 | animGroup->addAnimation(opacityAnim); 610 | animGroup->start(QAbstractAnimation::DeleteWhenStopped); 611 | connect(animGroup, &QAbstractAnimation::finished, circle, &QWidget::deleteLater); 612 | 613 | delay(10); 614 | } 615 | } 616 | 617 | void Widget::on_flyAwayButton_clicked() 618 | { 619 | FlyAwayAnimation* faa = new FlyAwayAnimation; 620 | faa->show(); 621 | } 622 | 623 | void Widget::on_highlightWindowButton_clicked() 624 | { 625 | static HighlighWindow* sHw = nullptr; 626 | if (!sHw) { 627 | sHw = new HighlighWindow(this); 628 | } 629 | sHw->show(); 630 | } 631 | -------------------------------------------------------------------------------- /widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | namespace Ui 7 | { 8 | class Widget; 9 | } 10 | 11 | class QLabel; 12 | class ColorBall; 13 | class Widget : public QWidget 14 | { 15 | Q_OBJECT 16 | Q_PROPERTY(float rotation READ rotation WRITE setRotation) 17 | public: 18 | explicit Widget(QWidget *parent = 0); 19 | ~Widget(); 20 | 21 | float rotation() const; 22 | void setRotation(float rotation); 23 | 24 | public slots: 25 | void flyIn(); 26 | void flyOut(); 27 | 28 | protected: 29 | QSize sizeHint() const; 30 | void closeEvent(QCloseEvent* e); 31 | 32 | private slots: 33 | void on_resizeButton_clicked(); 34 | void on_easingCurveCombo_currentIndexChanged(int index); 35 | void doAnimation(); 36 | void on_dropShadowCheckBox_toggled(bool checked); 37 | void on_shakeButton_clicked(); 38 | void on_shrinkButton_clicked(); 39 | void on_expandButton_clicked(); 40 | void on_shakeDirectionCombo_currentIndexChanged(int index); 41 | void on_fadeInButton_clicked(); 42 | void on_fadeOutButton_clicked(); 43 | void on_flipButton_clicked(); 44 | void on_newWindowButton_clicked(); 45 | void on_changeShapeButton_clicked(); 46 | void on_slideTextButton_clicked(); 47 | void on_layoutWindowsButton_clicked(); 48 | void on_toolButton_clicked(); 49 | void on_popupWindowButton_clicked(); 50 | void on_slideInButton_clicked(); 51 | void on_slideOutButton_clicked(); 52 | void on_tagButton_clicked(); 53 | void on_imageCarouselButton_clicked(); 54 | void on_bounceButton_clicked(); 55 | void on_slideWidgetButton_clicked(); 56 | void on_fadingCheckBox_toggled(bool checked); 57 | void on_tstFlowLayout_clicked(); 58 | void on_explodeButton_clicked(); 59 | void on_tableSelectionButton_clicked(); 60 | void on_ledDisplayButton_clicked(); 61 | void on_slideMenuButton_clicked(); 62 | void on_shadowWindowButton_clicked(); 63 | void on_inputButton_clicked(); 64 | void on_rainButton_toggled(bool checked); 65 | 66 | void on_flyAwayButton_clicked(); 67 | 68 | void on_highlightWindowButton_clicked(); 69 | 70 | private: 71 | void makeItRain(); 72 | 73 | private: 74 | Ui::Widget *m_ui; 75 | int m_easingCurve = 0; // default to linear 76 | QPoint m_shrinkOldPos; 77 | QSize m_shrinkOldSize; 78 | float m_rotation = 0; 79 | bool m_fliping = false; 80 | QLabel* m_flipLabel = nullptr; 81 | ColorBall* m_colorBall = nullptr; 82 | bool m_keepRaining = false; 83 | }; 84 | 85 | #endif // WIDGET_H 86 | -------------------------------------------------------------------------------- /widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 355 10 | 445 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Qt::Vertical 23 | 24 | 25 | 26 | 20 27 | 40 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | Linear 37 | 38 | 39 | 40 | 41 | InQuad 42 | 43 | 44 | 45 | 46 | OutQuad 47 | 48 | 49 | 50 | 51 | InOutQuad 52 | 53 | 54 | 55 | 56 | OutInQuad 57 | 58 | 59 | 60 | 61 | InCubic 62 | 63 | 64 | 65 | 66 | OutCubic 67 | 68 | 69 | 70 | 71 | InOutCubic 72 | 73 | 74 | 75 | 76 | OutInCubic 77 | 78 | 79 | 80 | 81 | InQuart 82 | 83 | 84 | 85 | 86 | OutQuart 87 | 88 | 89 | 90 | 91 | InOutQuart 92 | 93 | 94 | 95 | 96 | OutInQuart 97 | 98 | 99 | 100 | 101 | InQuint 102 | 103 | 104 | 105 | 106 | OutQuint 107 | 108 | 109 | 110 | 111 | InOutQuint 112 | 113 | 114 | 115 | 116 | OutInQuint 117 | 118 | 119 | 120 | 121 | InSine 122 | 123 | 124 | 125 | 126 | OutSine 127 | 128 | 129 | 130 | 131 | InOutSine 132 | 133 | 134 | 135 | 136 | OutInSine 137 | 138 | 139 | 140 | 141 | InExpo 142 | 143 | 144 | 145 | 146 | OutExpo 147 | 148 | 149 | 150 | 151 | InOutExpo 152 | 153 | 154 | 155 | 156 | OutInExpo 157 | 158 | 159 | 160 | 161 | InCirc 162 | 163 | 164 | 165 | 166 | OutCirc 167 | 168 | 169 | 170 | 171 | InOutCirc 172 | 173 | 174 | 175 | 176 | OutInCirc 177 | 178 | 179 | 180 | 181 | InElastic 182 | 183 | 184 | 185 | 186 | OutElastic 187 | 188 | 189 | 190 | 191 | InOutElastic 192 | 193 | 194 | 195 | 196 | OutInElastic 197 | 198 | 199 | 200 | 201 | InBack 202 | 203 | 204 | 205 | 206 | OutBack 207 | 208 | 209 | 210 | 211 | InOutBack 212 | 213 | 214 | 215 | 216 | OutInBack 217 | 218 | 219 | 220 | 221 | InBounce 222 | 223 | 224 | 225 | 226 | OutBounce 227 | 228 | 229 | 230 | 231 | InOutBounce 232 | 233 | 234 | 235 | 236 | OutInBounce 237 | 238 | 239 | 240 | 241 | InCurve 242 | 243 | 244 | 245 | 246 | OutCurve 247 | 248 | 249 | 250 | 251 | SineCurve 252 | 253 | 254 | 255 | 256 | CosineCurve 257 | 258 | 259 | 260 | 261 | BezierSpline 262 | 263 | 264 | 265 | 266 | TCBSpline 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | Slide Text 275 | 276 | 277 | 278 | 279 | 280 | 281 | Flip 282 | 283 | 284 | 285 | 286 | 287 | 288 | Slide In 289 | 290 | 291 | 292 | 293 | 294 | 295 | Slide Out 296 | 297 | 298 | 299 | 300 | 301 | 302 | ... 303 | 304 | 305 | 306 | 307 | 308 | 309 | Test FlowLayout 310 | 311 | 312 | 313 | 314 | 315 | 316 | Explode 317 | 318 | 319 | 320 | 321 | 322 | 323 | Fade Out 324 | 325 | 326 | 327 | 328 | 329 | 330 | Layout Windows 331 | 332 | 333 | 334 | 335 | 336 | 337 | Fading 338 | 339 | 340 | 341 | 342 | 343 | 344 | Resize 345 | 346 | 347 | 348 | 349 | 350 | 351 | New Window 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | Left -> Right 360 | 361 | 362 | 363 | 364 | Top -> Bottom 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | Slide Widget 373 | 374 | 375 | 376 | 377 | 378 | 379 | Fade In 380 | 381 | 382 | 383 | 384 | 385 | 386 | Bounce 387 | 388 | 389 | 390 | 391 | 392 | 393 | Tag 394 | 395 | 396 | 397 | 398 | 399 | 400 | Drop Shadow 401 | 402 | 403 | 404 | 405 | 406 | 407 | Popup Window 408 | 409 | 410 | 411 | 412 | 413 | 414 | Change Shape 415 | 416 | 417 | 418 | 419 | 420 | 421 | Shrink 422 | 423 | 424 | 425 | 426 | 427 | 428 | Image Carousel 429 | 430 | 431 | 432 | 433 | 434 | 435 | Shake 436 | 437 | 438 | 439 | 440 | 441 | 442 | Easing Curve 443 | 444 | 445 | 446 | 447 | 448 | 449 | Expand 450 | 451 | 452 | 453 | 454 | 455 | 456 | Table Selection 457 | 458 | 459 | 460 | 461 | 462 | 463 | Led Display 464 | 465 | 466 | 467 | 468 | 469 | 470 | Slide Menu 471 | 472 | 473 | 474 | 475 | 476 | 477 | Shadow Window 478 | 479 | 480 | 481 | 482 | 483 | 484 | Input 485 | 486 | 487 | 488 | 489 | 490 | 491 | Rain 492 | 493 | 494 | true 495 | 496 | 497 | 498 | 499 | 500 | 501 | Fly Away 502 | 503 | 504 | 505 | 506 | 507 | 508 | Highlight Window 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | FadingToolButton 520 | QToolButton 521 |
fadingtoolbutton.h
522 |
523 |
524 | 525 | 526 |
527 | --------------------------------------------------------------------------------