1 // SPDX-License-Identifier: GPL-3.0-or-later 2 // SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors 3 4 #pragma once 5 6 #include <QWidget> 7 8 class QPropertyAnimation; 9 10 class SelectionWidget : public QWidget 11 { 12 Q_OBJECT 13 public: 14 enum SideType 15 { 16 TOPLEFT_SIDE, 17 BOTTOMLEFT_SIDE, 18 TOPRIGHT_SIDE, 19 BOTTOMRIGHT_SIDE, 20 TOP_SIDE, 21 BOTTOM_SIDE, 22 RIGHT_SIDE, 23 LEFT_SIDE, 24 NO_SIDE, 25 }; 26 27 explicit SelectionWidget(const QColor& c, QWidget* parent = nullptr); 28 29 SideType getMouseSide(const QPoint& point) const; 30 QVector<QRect> handlerAreas(); 31 32 void setGeometryAnimated(const QRect& r); 33 void saveGeometry(); 34 QRect savedGeometry(); 35 36 protected: 37 void paintEvent(QPaintEvent*); 38 void resizeEvent(QResizeEvent*); 39 void moveEvent(QMoveEvent*); 40 41 signals: 42 void animationEnded(); 43 44 public slots: 45 void updateColor(const QColor& c); 46 47 private: 48 void updateAreas(); 49 50 QPropertyAnimation* m_animation; 51 52 QColor m_color; 53 QPoint m_areaOffset; 54 QPoint m_handleOffset; 55 QRect m_geometryBackup; 56 57 // naming convention for handles 58 // T top, B bottom, R Right, L left 59 // 2 letters: a corner 60 // 1 letter: the handle on the middle of the corresponding side 61 QRect m_TLHandle, m_TRHandle, m_BLHandle, m_BRHandle; 62 QRect m_LHandle, m_THandle, m_RHandle, m_BHandle; 63 64 QRect m_TLArea, m_TRArea, m_BLArea, m_BRArea; 65 QRect m_LArea, m_TArea, m_RArea, m_BArea; 66 }; 67