File indexing completed on 2024-06-23 04:28:11
0001 /* This file is part of the KDE project 0002 0003 SPDX-FileCopyrightText: 2006 Thorsten Zachmann <zachmann@kde.org> 0004 SPDX-FileCopyrightText: 2006-2007 Thomas Zander <zander@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #ifndef SELECTIONDECORATOR_H 0010 #define SELECTIONDECORATOR_H 0011 0012 #include <KoViewConverter.h> 0013 #include <KoFlake.h> 0014 0015 #include "KoShapeMeshGradientHandles.h" 0016 0017 #include <QPainter> 0018 #include <QPointer> 0019 0020 class KoSelection; 0021 class KoCanvasResourceProvider; 0022 0023 static const struct DecoratorIconPositions { 0024 QPoint uiOffset = QPoint(0, 40); 0025 } decoratorIconPositions; 0026 0027 /** 0028 * The SelectionDecorator is used to paint extra user-interface items on top of a selection. 0029 */ 0030 class SelectionDecorator 0031 { 0032 public: 0033 /** 0034 * Constructor. 0035 * @param arrows the direction that needs highlighting. (currently unused) 0036 * @param rotationHandles if true; the rotation handles will be drawn 0037 * @param shearHandles if true; the shearhandles will be drawn 0038 */ 0039 SelectionDecorator(KoCanvasResourceProvider *resourceManager); 0040 ~SelectionDecorator() {} 0041 0042 /** 0043 * paint the decorations. 0044 * @param painter the painter to paint to. 0045 * @param converter to convert between internal and view coordinates. 0046 */ 0047 void paint(QPainter &painter, const KoViewConverter &converter); 0048 0049 /** 0050 * set the selection that is to be painted. 0051 * @param selection the current selection. 0052 */ 0053 void setSelection(KoSelection *selection); 0054 0055 /** 0056 * set the radius of the selection handles 0057 * @param radius the new handle radius 0058 */ 0059 void setHandleRadius(int radius); 0060 0061 /** 0062 * set the thickness of decoration lines, used for HiDPI support. 0063 * @param thickness -- the new thickness 0064 */ 0065 void setDecorationThickness(int thickness); 0066 0067 /** 0068 * Set true if you want to render gradient handles on the canvas. 0069 * Default value: false 0070 */ 0071 void setShowFillGradientHandles(bool value); 0072 0073 /** 0074 * Set true if you want to render gradient handles on the canvas. 0075 * Default value: false 0076 */ 0077 void setShowStrokeFillGradientHandles(bool value); 0078 0079 void setShowFillMeshGradientHandles(bool value); 0080 void setCurrentMeshGradientHandles(const KoShapeMeshGradientHandles::Handle &selectedHandle, 0081 const KoShapeMeshGradientHandles::Handle &hoveredHandle); 0082 0083 void setForceShapeOutlines(bool value); 0084 0085 private: 0086 void paintGradientHandles(KoShape *shape, KoFlake::FillVariant fillVariant, QPainter &painter, const KoViewConverter &converter); 0087 0088 void paintMeshGradientHandles(KoShape *shape, KoFlake::FillVariant fillVariant, QPainter &painter, const KoViewConverter &converter); 0089 0090 private: 0091 KoFlake::AnchorPosition m_hotPosition; 0092 KoSelection *m_selection {nullptr}; 0093 KoShapeMeshGradientHandles::Handle m_currentHoveredMeshHandle; 0094 KoShapeMeshGradientHandles::Handle m_selectedMeshHandle; 0095 int m_handleRadius {7}; 0096 int m_decorationThickness {1}; 0097 bool m_showFillGradientHandles {false}; 0098 bool m_showStrokeFillGradientHandles {false}; 0099 bool m_showFillMeshGradientHandles {false}; 0100 bool m_forceShapeOutlines {false}; 0101 }; 0102 0103 #endif