Debian Codegraph @

libs/ui/kis_popup_palette.h

raw symbols SCIP
1 /* This file is part of the KDE project
2 SPDX-FileCopyrightText: 2009 Vera Lukman <[email protected]>
3 SPDX-FileCopyrightText: 2016 Scott Petrovic <[email protected]>
4
5 SPDX-License-Identifier: LGPL-2.0-only
6 */
7
8 #ifndef KIS_POPUP_PALETTE_H
9 #define KIS_POPUP_PALETTE_H
10
11 #include <QPushButton>
12 #include <QSlider>
13 #include <QGraphicsOpacityEffect>
14 #include "KisViewManager.h"
15 #include "kactioncollection.h"
16 #include "kis_tool_button.h"
17 #include "KisHighlightedToolButton.h"
18 #include "KisColorSelectorInterface.h"
19 #include "KisPopupWidgetInterface.h"
20
21 class KisFavoriteResourceManager;
22 class QWidget;
23 class KoColor;
24 class KoTriangleColorSelector;
25 class KisSignalCompressor;
26 class KisRoundHudButton;
27 class KisDockerHud;
28 class KisCanvasResourceProvider;
29 class KisVisualColorSelector;
30 class KisAcyclicSignalConnector;
31 class KisMouseClickEater;
32 class KisCoordinatesConverter;
33
34
35 struct CachedPresetLayout {
36 int ringCount{1};
37 qreal firstRowRadius{0};
38 qreal secondRowRadius{0};
39 qreal thirdRowRadius{0};
40 qreal firstRowPos{0};
41 qreal secondRowPos{0};
42 qreal thirdRowPos{0};
43 };
44
45 class KisPopupPalette : public QWidget, public KisPopupWidgetInterface
46 {
47 Q_OBJECT
48 Q_INTERFACES(KisPopupWidgetInterface)
49
50 Q_PROPERTY(int hoveredPreset READ hoveredPreset WRITE setHoveredPreset)
51 Q_PROPERTY(int hoveredColor READ hoveredColor WRITE setHoveredColor)
52 Q_PROPERTY(int selectedColor READ selectedColor WRITE setSelectedColor)
53
54 public:
55 KisPopupPalette(KisViewManager*, KisCoordinatesConverter* ,KisFavoriteResourceManager*, const KoColorDisplayRendererInterface *displayRenderer,
56 QWidget *parent = 0);
57 ~KisPopupPalette() override;
58 QSize sizeHint() const override;
59
60 //functions to set up selectedColor
61 void setSelectedColor(int x);
62 int selectedColor() const;
63 void setParent(QWidget *parent);
64
65
66 void popup(const QPoint& position) override;
67 void dismiss() override;
68 bool onScreen() override;
69
70 void ensureWithinParent(const QPoint& globalPos, bool useUpperLeft);
71
72 protected:
73 void showEvent(QShowEvent *event) override;
74 void paintEvent(QPaintEvent*) override;
75 void resizeEvent(QResizeEvent*) override;
76 void tabletEvent(QTabletEvent *event) override;
77 void mouseReleaseEvent(QMouseEvent*) override;
78 void mouseMoveEvent(QMouseEvent*) override;
79 void mousePressEvent(QMouseEvent*) override;
80 bool eventFilter(QObject *, QEvent *) override;
81
82 /**
83 * @brief Calculate index of recent color in array
84 * @param numColors the total number of recent colors
85 * @return -1 if numColors < 1
86 */
87 int calculateColorIndex(QPointF position, int numColors) const;
88 /**
89 * @brief/ find the index of the brush preset slot containing @position.
90 * @return -1 if none is found
91 */
92 int findPresetSlot(QPointF position) const;
93
94 //functions to set up hoveredBrush
95 void setHoveredPreset(int x);
96 int hoveredPreset() const;
97 //functions to set up hoveredColor
98 void setHoveredColor(int x);
99 int hoveredColor() const;
100
101 private:
102 void reconfigure();
103
104 QPainterPath drawDonutPathFull(int, int, int, int);
105 QPainterPath drawDonutPathAngle(int, int, int);
106 QPainterPath drawFgBgColorIndicator(int type) const;
107 QRectF rotationIndicatorRect(qreal rotationAngle) const;
108 bool isPointInPixmap(QPointF&, int pos);
109
110 QPointF drawPointOnAngle(qreal angle, qreal radius) const;
111 /**
112 * @brief Determine the number of rings to distribute the presets
113 * and calculate the radius of the brush preset slots
114 * and saves the "layout" to m_cachedPresetLayout.
115 */
116 void calculatePresetLayout();
117 QPainterPath createPathFromPresetIndex(int index) const;
118
119 void calculateRotationSnapAreas();
120
121 QPoint m_mirrorPos {};
122 int m_maxPresetSlotCount {10};
123 int m_presetSlotCount {10};
124 int m_hoveredPreset {0};
125 bool m_useDynamicSlotCount {true};
126 int m_hoveredColor {0};
127 int m_selectedColor {0};
128 bool m_touchBeginReceived {false};
129 bool m_isOverFgBgColors {false};
130 bool m_snapRotation {false};
131 qreal m_rotationSnapAngle {0};
132 qreal m_snapRadius {15};
133 std::array<QRect, 24> m_snapRects{};
134 std::array<QLineF, 24> m_snapLines {};
135
136 KisCoordinatesConverter *m_coordinatesConverter;
137
138 KisViewManager *m_viewManager;
139 KisActionManager *m_actionManager;
140 KisFavoriteResourceManager *m_resourceManager;
141 KisColorSelectorInterface *m_colorSelector {0};
142 const KoColorDisplayRendererInterface *m_displayRenderer;
143 QScopedPointer<KisSignalCompressor> m_colorChangeCompressor;
144 KisKActionCollection *m_actionCollection;
145
146 QSpacerItem *m_mainArea {0};
147 KisDockerHud *m_dockerHud {0};
148 QWidget* m_bottomBarWidget {0};
149 qreal m_popupPaletteSize {385.0};
150 qreal m_colorHistoryInnerRadius {72.0};
151 qreal m_colorHistoryOuterRadius {92.0};
152 bool m_showColorHistory {true};
153 qreal m_rotationTrackSize {18.0};
154 bool m_showRotationTrack {true};
155 qreal m_presetRingMargin {3.0};
156
157 KisRoundHudButton *m_clearColorHistoryButton {0};
158 KisRoundHudButton *m_tagsButton {0};
159 KisRoundHudButton *m_bottomBarButton {0};
160 KisRoundHudButton *m_dockerHudButton {0};
161 QRectF m_canvasRotationIndicatorRect;
162 QRectF m_resetCanvasRotationIndicatorRect;
163 bool m_isOverCanvasRotationIndicator {false};
164 bool m_isOverResetCanvasRotationIndicator{false};
165 bool m_isRotatingCanvasIndicator{false};
166 bool m_isZoomingCanvas {false};
167
168 KisHighlightedToolButton *mirrorMode {0};
169 KisHighlightedToolButton *canvasOnlyButton {0};
170 QPushButton *zoomToOneHundredPercentButton {0};
171 QPushButton *fitToViewButton {0};
172 QSlider *zoomCanvasSlider {0};
173 int zoomSliderMinValue {10};
174 int zoomSliderMaxValue {200};
175 KisAcyclicSignalConnector *m_acyclicConnector = 0;
176
177 CachedPresetLayout m_cachedPresetLayout;
178
179 // updates the transparency and effects of the whole widget
180 QGraphicsOpacityEffect *opacityChange {0};
181 KisMouseClickEater *m_clicksEater;
182
183 Q_SIGNALS:
184 void sigChangeActivePaintop(int);
185 void sigUpdateRecentColor(int);
186 void sigChangefGColor(const KoColor&);
187 void sigUpdateCanvas();
188 void zoomLevelChanged(int);
189 void finished() override; // KisPopupWidgetInterface.
190
191 public Q_SLOTS:
192 void slotUpdateIcons();
193
194 private Q_SLOTS:
195 void slotSetMirrorPos();
196 void slotRemoveMirrorPos();
197 void slotDisplayConfigurationChanged();
198 void slotConfigurationChanged();
199 void slotExternalFgColorChanged(const KoColor &color);
200 void slotEmitColorChanged();
201 void slotSetSelectedColor(int x) { setSelectedColor(x); update(); }
202 void slotUpdate();
203 void slotShowTagsPopup();
204 void showHudWidget(bool visible);
205 void showBottomBarWidget(bool visible);
206 void slotZoomToOneHundredPercentClicked();
207 void slotFitToViewClicked();
208 void slotZoomSliderChanged(int zoom);
209
210 void slotZoomSliderPressed();
211 void slotZoomSliderReleased();
212 };
213
214 #endif // KIS_POPUP_PALETTE_H