File indexing completed on 2024-06-16 04:17:54
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef __KIS_CONSTRAINED_RECT_H 0008 #define __KIS_CONSTRAINED_RECT_H 0009 0010 #include <QObject> 0011 #include <QRect> 0012 0013 0014 0015 class KisConstrainedRect : public QObject 0016 { 0017 Q_OBJECT 0018 0019 public: 0020 enum HandleType { 0021 None = 0, 0022 UpperLeft, 0023 UpperRight, 0024 LowerLeft, 0025 LowerRight, 0026 Upper, 0027 Lower, 0028 Left, 0029 Right, 0030 Inside, 0031 Creation 0032 }; 0033 0034 public: 0035 KisConstrainedRect(); 0036 ~KisConstrainedRect() override; 0037 0038 void setRectInitial(const QRect &rect); 0039 void setCropRect(const QRect &cropRect); 0040 0041 bool centered() const; 0042 void setCentered(bool value); 0043 0044 bool canGrow() const; 0045 void setCanGrow(bool value); 0046 0047 QRect rect() const; 0048 0049 qreal ratio() const; 0050 0051 void moveHandle(HandleType handle, const QPoint &offset, const QRect &oldRect); 0052 QPointF handleSnapPoint(HandleType handle, const QPointF &cursorPos); 0053 0054 void setRatio(qreal value); 0055 void setOffset(const QPoint &offset); 0056 void setWidth(int value); 0057 void setHeight(int value); 0058 0059 bool widthLocked() const; 0060 void setWidthLocked(bool value); 0061 0062 bool heightLocked() const; 0063 void setHeightLocked(bool value); 0064 0065 bool ratioLocked() const; 0066 void setRatioLocked(bool value); 0067 0068 void normalize(); 0069 0070 Q_SIGNALS: 0071 void sigValuesChanged(); 0072 void sigLockValuesChanged(); 0073 0074 private: 0075 0076 int widthFromHeightUnsignedRatio(int height, qreal ratio, int oldWidth) const; 0077 int heightFromWidthUnsignedRatio(int width, qreal ratio, int oldHeight) const; 0078 0079 void assignNewSize(const QSize &newSize); 0080 void storeRatioSafe(const QSize &newSize); 0081 private: 0082 bool m_centered {false}; 0083 bool m_canGrow {true}; 0084 QRect m_rect; 0085 qreal m_ratio {1.0}; 0086 0087 bool m_widthLocked {false}; 0088 bool m_heightLocked {false}; 0089 bool m_ratioLocked {false}; 0090 0091 QRect m_cropRect; 0092 }; 0093 0094 #endif /* __KIS_CONSTRAINED_RECT_H */