File indexing completed on 2024-12-22 04:13:01
0001 /* This file is part of the KDE project 0002 * SPDX-FileCopyrightText: 2009 Boudewijn Rempt <boud@valdyas.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KIS_TOOL_RECTANGLE_BASE_H 0008 #define KIS_TOOL_RECTANGLE_BASE_H 0009 0010 #include <kis_tool_shape.h> 0011 #include <kis_cursor.h> 0012 0013 class KRITAUI_EXPORT KisToolRectangleBase : public KisToolShape 0014 { 0015 Q_OBJECT 0016 0017 Q_SIGNALS: 0018 void rectangleChanged(const QRectF &newRect); 0019 void sigRequestReloadConfig(); 0020 0021 public Q_SLOTS: 0022 void constraintsChanged(bool forceRatio, bool forceWidth, bool forceHeight, float ratio, float width, float height); 0023 void roundCornersChanged(int rx, int ry); 0024 0025 void requestStrokeEnd() override; 0026 void requestStrokeCancellation() override; 0027 0028 public: 0029 enum ToolType { 0030 PAINT, 0031 SELECT 0032 }; 0033 0034 explicit KisToolRectangleBase(KoCanvasBase * canvas, KisToolRectangleBase::ToolType type, const QCursor & cursor=KisCursor::load("tool_rectangle_cursor.png", 6, 6)); 0035 0036 void keyPressEvent(QKeyEvent *event) override; 0037 void keyReleaseEvent(QKeyEvent *event) override; 0038 void beginPrimaryAction(KoPointerEvent *event) override; 0039 void continuePrimaryAction(KoPointerEvent *event) override; 0040 void endPrimaryAction(KoPointerEvent *event) override; 0041 0042 void paint(QPainter& gc, const KoViewConverter &converter) override; 0043 void activate(const QSet<KoShape*> &shapes) override; 0044 void deactivate() override; 0045 0046 QList<QPointer<QWidget> > createOptionWidgets() override; 0047 void showSize(); 0048 0049 protected: 0050 virtual void finishRect(const QRectF &rect, qreal roundCornersX, qreal roundCornersY) = 0; 0051 0052 QPointF m_dragCenter; 0053 QPointF m_dragStart; 0054 QPointF m_dragEnd; 0055 ToolType m_type; 0056 0057 bool m_isRatioForced; 0058 bool m_isWidthForced; 0059 bool m_isHeightForced; 0060 bool m_rotateActive; 0061 float m_forcedRatio; 0062 float m_forcedWidth; 0063 float m_forcedHeight; 0064 int m_roundCornersX; 0065 int m_roundCornersY; 0066 qreal m_referenceAngle; 0067 qreal m_angle; 0068 qreal m_angleBuffer; 0069 Qt::KeyboardModifiers m_currentModifiers; 0070 0071 bool isFixedSize(); 0072 qreal getRotationAngle(); 0073 QPainterPath drawX(const QPointF &pt); 0074 void applyConstraints(QSizeF& area, bool overrideRatio); 0075 void getRotatedPath(QPainterPath &path, const QPointF ¢er, const qreal &angle); 0076 0077 void updateArea(); 0078 virtual void paintRectangle(QPainter &gc, const QRectF &imageRect); 0079 virtual QRectF createRect(const QPointF &start, const QPointF &end); 0080 virtual bool showRoundCornersGUI() const; 0081 0082 void endStroke(); 0083 void cancelStroke(); 0084 }; 0085 0086 #endif // KIS_TOOL_RECTANGLE_BASE_H