File indexing completed on 2024-05-12 16:01:41
0001 /* This file is part of the KDE project 0002 SPDX-FileCopyrightText: 2009 Vera Lukman <shicmap@gmail.com> 0003 SPDX-FileCopyrightText: 2016 Scott Petrovic <scottpetrovic@gmail.com> 0004 0005 SPDX-License-Identifier: LGPL-2.0-only 0006 */ 0007 0008 #ifndef KIS_POPUP_PALETTE_H 0009 #define KIS_POPUP_PALETTE_H 0010 0011 #include <QPushButton> 0012 #include <QSlider> 0013 #include <QGraphicsOpacityEffect> 0014 #include "KisViewManager.h" 0015 #include "kactioncollection.h" 0016 #include "kis_tool_button.h" 0017 #include "KisHighlightedToolButton.h" 0018 #include "KisColorSelectorInterface.h" 0019 #include "KisPopupWidgetInterface.h" 0020 0021 class KisFavoriteResourceManager; 0022 class QWidget; 0023 class KoColor; 0024 class KoTriangleColorSelector; 0025 class KisSignalCompressor; 0026 class KisBrushHud; 0027 class KisRoundHudButton; 0028 class KisCanvasResourceProvider; 0029 class KisVisualColorSelector; 0030 class KisAcyclicSignalConnector; 0031 class KisMouseClickEater; 0032 class KisCoordinatesConverter; 0033 0034 0035 struct CachedPresetLayout { 0036 int ringCount{1}; 0037 qreal firstRowRadius{0}; 0038 qreal secondRowRadius{0}; 0039 qreal thirdRowRadius{0}; 0040 qreal firstRowPos{0}; 0041 qreal secondRowPos{0}; 0042 qreal thirdRowPos{0}; 0043 }; 0044 0045 class KisPopupPalette : public QWidget, public KisPopupWidgetInterface 0046 { 0047 Q_OBJECT 0048 Q_INTERFACES(KisPopupWidgetInterface) 0049 0050 Q_PROPERTY(int hoveredPreset READ hoveredPreset WRITE setHoveredPreset) 0051 Q_PROPERTY(int hoveredColor READ hoveredColor WRITE setHoveredColor) 0052 Q_PROPERTY(int selectedColor READ selectedColor WRITE setSelectedColor) 0053 0054 public: 0055 KisPopupPalette(KisViewManager*, KisCoordinatesConverter* ,KisFavoriteResourceManager*, const KoColorDisplayRendererInterface *displayRenderer, 0056 KisCanvasResourceProvider *provider, QWidget *parent = 0); 0057 ~KisPopupPalette() override; 0058 QSize sizeHint() const override; 0059 0060 //functions to set up selectedColor 0061 void setSelectedColor(int x); 0062 int selectedColor() const; 0063 void setParent(QWidget *parent); 0064 0065 0066 void popup(const QPoint& position) override; 0067 void dismiss() override; 0068 bool onScreen() override; 0069 0070 void ensureWithinParent(const QPoint& position, bool useUpperLeft); 0071 0072 protected: 0073 void showEvent(QShowEvent *event) override; 0074 void paintEvent(QPaintEvent*) override; 0075 void resizeEvent(QResizeEvent*) override; 0076 void tabletEvent(QTabletEvent *event) override; 0077 void mouseReleaseEvent(QMouseEvent*) override; 0078 void mouseMoveEvent(QMouseEvent*) override; 0079 void mousePressEvent(QMouseEvent*) override; 0080 bool eventFilter(QObject *, QEvent *) override; 0081 0082 /** 0083 * @brief Calculate index of recent color in array 0084 * @param numColors the total number of recent colors 0085 * @return -1 if numColors < 1 0086 */ 0087 int calculateColorIndex(QPointF position, int numColors) const; 0088 /** 0089 * @brief/ find the index of the brush preset slot containing @position. 0090 * @return -1 if none is found 0091 */ 0092 int findPresetSlot(QPointF position) const; 0093 0094 //functions to set up hoveredBrush 0095 void setHoveredPreset(int x); 0096 int hoveredPreset() const; 0097 //functions to set up hoveredColor 0098 void setHoveredColor(int x); 0099 int hoveredColor() const; 0100 0101 private: 0102 void reconfigure(); 0103 0104 QPainterPath drawDonutPathFull(int, int, int, int); 0105 QPainterPath drawDonutPathAngle(int, int, int); 0106 QPainterPath drawFgBgColorIndicator(int type) const; 0107 QRectF rotationIndicatorRect(qreal rotationAngle) const; 0108 bool isPointInPixmap(QPointF&, int pos); 0109 0110 QPointF drawPointOnAngle(qreal angle, qreal radius) const; 0111 /** 0112 * @brief Determine the number of rings to distribute the presets 0113 * and calculate the radius of the brush preset slots 0114 * and saves the "layout" to m_cachedPresetLayout. 0115 */ 0116 void calculatePresetLayout(); 0117 QPainterPath createPathFromPresetIndex(int index) const; 0118 0119 void calculateRotationSnapAreas(); 0120 0121 QPoint m_mirrorPos {}; 0122 int m_maxPresetSlotCount {10}; 0123 int m_presetSlotCount {10}; 0124 int m_hoveredPreset {0}; 0125 bool m_useDynamicSlotCount {true}; 0126 int m_hoveredColor {0}; 0127 int m_selectedColor {0}; 0128 bool m_tabletRightClickPressed {false}; 0129 bool m_touchBeginReceived {false}; 0130 bool m_isOverFgBgColors {false}; 0131 bool m_snapRotation {false}; 0132 qreal m_rotationSnapAngle {0}; 0133 qreal m_snapRadius {15}; 0134 std::array<QRect, 24> m_snapRects{}; 0135 std::array<QLineF, 24> m_snapLines {}; 0136 0137 KisCoordinatesConverter *m_coordinatesConverter; 0138 0139 KisViewManager *m_viewManager; 0140 KisActionManager *m_actionManager; 0141 KisFavoriteResourceManager *m_resourceManager; 0142 KisColorSelectorInterface *m_colorSelector {0}; 0143 const KoColorDisplayRendererInterface *m_displayRenderer; 0144 QScopedPointer<KisSignalCompressor> m_colorChangeCompressor; 0145 KisKActionCollection *m_actionCollection; 0146 0147 QSpacerItem *m_mainArea {0}; 0148 KisBrushHud *m_brushHud {0}; 0149 QWidget* m_bottomBarWidget {0}; 0150 qreal m_popupPaletteSize {385.0}; 0151 qreal m_colorHistoryInnerRadius {72.0}; 0152 qreal m_colorHistoryOuterRadius {92.0}; 0153 bool m_showColorHistory {true}; 0154 qreal m_rotationTrackSize {18.0}; 0155 bool m_showRotationTrack {true}; 0156 qreal m_presetRingMargin {3.0}; 0157 0158 KisRoundHudButton *m_clearColorHistoryButton {0}; 0159 KisRoundHudButton *m_tagsButton {0}; 0160 KisRoundHudButton *m_bottomBarButton {0}; 0161 KisRoundHudButton *m_brushHudButton {0}; 0162 QRectF m_canvasRotationIndicatorRect; 0163 QRectF m_resetCanvasRotationIndicatorRect; 0164 bool m_isOverCanvasRotationIndicator {false}; 0165 bool m_isOverResetCanvasRotationIndicator{false}; 0166 bool m_isRotatingCanvasIndicator{false}; 0167 bool m_isZoomingCanvas {false}; 0168 0169 KisHighlightedToolButton *mirrorMode {0}; 0170 KisHighlightedToolButton *canvasOnlyButton {0}; 0171 QPushButton *zoomToOneHundredPercentButton {0}; 0172 QSlider *zoomCanvasSlider {0}; 0173 int zoomSliderMinValue {10}; 0174 int zoomSliderMaxValue {200}; 0175 KisAcyclicSignalConnector *m_acyclicConnector = 0; 0176 0177 CachedPresetLayout m_cachedPresetLayout; 0178 0179 // updates the transparency and effects of the whole widget 0180 QGraphicsOpacityEffect *opacityChange {0}; 0181 KisMouseClickEater *m_clicksEater; 0182 0183 Q_SIGNALS: 0184 void sigChangeActivePaintop(int); 0185 void sigUpdateRecentColor(int); 0186 void sigChangefGColor(const KoColor&); 0187 void sigUpdateCanvas(); 0188 void zoomLevelChanged(int); 0189 void finished() override; // KisPopupWidgetInterface. 0190 0191 public Q_SLOTS: 0192 void slotUpdateIcons(); 0193 0194 private Q_SLOTS: 0195 void slotSetMirrorPos(); 0196 void slotRemoveMirrorPos(); 0197 void slotDisplayConfigurationChanged(); 0198 void slotConfigurationChanged(); 0199 void slotExternalFgColorChanged(const KoColor &color); 0200 void slotEmitColorChanged(); 0201 void slotSetSelectedColor(int x) { setSelectedColor(x); update(); } 0202 void slotUpdate(); 0203 void slotShowTagsPopup(); 0204 void showHudWidget(bool visible); 0205 void showBottomBarWidget(bool visible); 0206 void slotZoomToOneHundredPercentClicked(); 0207 void slotZoomSliderChanged(int zoom); 0208 0209 void slotZoomSliderPressed(); 0210 void slotZoomSliderReleased(); 0211 }; 0212 0213 #endif // KIS_POPUP_PALETTE_H