File indexing completed on 2024-07-21 04:18:48

0001 /*
0002  * SPDX-FileCopyrightText: (C) 2019 Marco Martin <mart@kde.org>
0003  * SPDX-FileCopyrightText: (C) 2020 Carl Schwan <carl@carlschwan.eu>
0004  *
0005  * SPDX-License-Identifier: LGPL-2.1-or-later
0006  */
0007 
0008 #pragma once
0009 
0010 #include <QQuickItem>
0011 
0012 class ResizeRectangle;
0013 
0014 class ResizeHandle : public QQuickItem
0015 {
0016     Q_OBJECT
0017     Q_PROPERTY(bool resizeBlocked READ resizeBlocked NOTIFY resizeBlockedChanged)
0018     Q_PROPERTY(QQuickItem *rectangle READ rectangle WRITE setRectangle NOTIFY rectangleChanged)
0019 
0020 public:
0021     enum Corner {
0022         Left = 0,
0023         TopLeft,
0024         Top,
0025         TopRight,
0026         Right,
0027         BottomRight,
0028         Bottom,
0029         BottomLeft,
0030     };
0031     Q_ENUM(Corner)
0032 
0033     ResizeHandle(QQuickItem *parent = nullptr);
0034     ~ResizeHandle() = default;
0035 
0036     QQuickItem *rectangle() const;
0037     void setRectangle(QQuickItem *rectangle);
0038 
0039     bool resizeBlocked() const;
0040 
0041     void setResizeCorner(Corner corner);
0042 
0043 protected:
0044     void mousePressEvent(QMouseEvent *event) override;
0045     void mouseReleaseEvent(QMouseEvent *event) override;
0046     void mouseMoveEvent(QMouseEvent *event) override;
0047 
0048 Q_SIGNALS:
0049     void resizeCornerChanged();
0050     void resizeBlockedChanged();
0051     void rectangleChanged();
0052 
0053 private:
0054     inline bool resizeLeft() const;
0055     inline bool resizeTop() const;
0056     inline bool resizeRight() const;
0057     inline bool resizeBottom() const;
0058     void setResizeBlocked(bool width, bool height);
0059 
0060     QPointF m_mouseDownPosition;
0061     QRectF m_mouseDownGeometry;
0062 
0063     Corner m_resizeCorner = Left;
0064     bool m_resizeWidthBlocked = false;
0065     bool m_resizeHeightBlocked = false;
0066     ResizeRectangle *m_rectangle = nullptr;
0067 };