File indexing completed on 2025-02-02 04:26:12
0001 /* 0002 * SPDX-FileCopyrightText: 2018 Ambareesh "Amby" Balaji <ambareeshbalaji@gmail.com> 0003 * SPDX-FileCopyrightText: 2022 Noah Davis <noahadvs@gmail.com> 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef SELECTIONEDITOR_H 0008 #define SELECTIONEDITOR_H 0009 0010 #include "ExportManager.h" 0011 0012 #include <memory> 0013 0014 class QHoverEvent; 0015 class QKeyEvent; 0016 class QMouseEvent; 0017 class QQuickItem; 0018 class Selection; 0019 class SelectionEditorPrivate; 0020 0021 /** 0022 * This class is used to set the selected rectangle capture region, 0023 * get information related to it and handle input from a capture window. 0024 */ 0025 class SelectionEditor : public QObject 0026 { 0027 Q_OBJECT 0028 Q_PROPERTY(Selection *selection READ selection CONSTANT FINAL) 0029 Q_PROPERTY(qreal devicePixelRatio READ devicePixelRatio NOTIFY devicePixelRatioChanged FINAL) 0030 Q_PROPERTY(QRectF screensRect READ screensRect NOTIFY screensRectChanged FINAL) 0031 Q_PROPERTY(Location dragLocation READ dragLocation NOTIFY dragLocationChanged FINAL) 0032 Q_PROPERTY(QRectF handlesRect READ handlesRect NOTIFY handlesRectChanged FINAL) 0033 Q_PROPERTY(QPointF mousePosition READ mousePosition NOTIFY mousePositionChanged) 0034 /// Whether or not to show the magnifier. 0035 Q_PROPERTY(bool showMagnifier READ showMagnifier NOTIFY showMagnifierChanged FINAL) 0036 /// The location that the magnifier is looking at, 0037 /// not necessarily the location of the magnifier. 0038 Q_PROPERTY(Location magnifierLocation READ magnifierLocation NOTIFY magnifierLocationChanged FINAL) 0039 0040 public: 0041 /// Locations in relation to the current selection 0042 enum Location : short { 0043 None = 0, 0044 Outside, 0045 // clang-format off 0046 TopLeft, Top, TopRight, 0047 Left, Inside, Right, 0048 BottomLeft, Bottom, BottomRight, 0049 // clang-format on 0050 FollowMouse = Outside, // Semantic alias for the magnifier 0051 }; 0052 Q_ENUM(Location) 0053 0054 explicit SelectionEditor(QObject *parent = nullptr); 0055 0056 static SelectionEditor *instance(); 0057 0058 Selection *selection() const; 0059 0060 qreal devicePixelRatio() const; 0061 0062 QRectF screensRect() const; 0063 0064 qreal screensWidth() const; 0065 qreal screensHeight() const; 0066 0067 Location dragLocation() const; 0068 0069 QRectF handlesRect() const; 0070 0071 QPointF mousePosition() const; 0072 0073 bool showMagnifier() const; 0074 0075 Location magnifierLocation() const; 0076 0077 Q_SLOT bool acceptSelection(ExportManager::Actions actions = {}); 0078 0079 void reset(); 0080 0081 Q_SIGNALS: 0082 void devicePixelRatioChanged(); 0083 void screensRectChanged(); 0084 void dragLocationChanged(); 0085 void handlesRectChanged(); 0086 void mousePositionChanged(); 0087 void showMagnifierChanged(); 0088 void magnifierLocationChanged(); 0089 0090 void accepted(const QRectF &rect, const ExportManager::Actions &actions); 0091 0092 protected: 0093 bool eventFilter(QObject *watched, QEvent *event) override; 0094 void keyPressEvent(QQuickItem *item, QKeyEvent *event); 0095 void keyReleaseEvent(QQuickItem *item, QKeyEvent *event); 0096 void hoverMoveEvent(QQuickItem *item, QHoverEvent *event); 0097 void mousePressEvent(QQuickItem *item, QMouseEvent *event); 0098 void mouseMoveEvent(QQuickItem *item, QMouseEvent *event); 0099 void mouseReleaseEvent(QQuickItem *item, QMouseEvent *event); 0100 void mouseDoubleClickEvent(QQuickItem *item, QMouseEvent *event); 0101 0102 private: 0103 const std::unique_ptr<SelectionEditorPrivate> d; 0104 }; 0105 0106 #endif // SELECTIONEDITOR_H