1 /* This file is part of the KDE project 2 Copyright 2009 Vera Lukman <shicmap@gmail.com> 3 Copyright 2016 Scott Petrovic <scottpetrovic@gmail.com> 4 5 This library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Library General Public 7 License version 2 as published by the Free Software Foundation. 8 9 This library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Library General Public License for more details. 13 14 You should have received a copy of the GNU Library General Public License 15 along with this library; see the file COPYING.LIB. If not, write to 16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 Boston, MA 02110-1301, USA. 18 */ 19 20 #ifndef KIS_POPUP_PALETTE_H 21 #define KIS_POPUP_PALETTE_H 22 23 #include <QElapsedTimer> 24 #include <QPushButton> 25 #include <QSlider> 26 #include <QGraphicsOpacityEffect> 27 #include "KisViewManager.h" 28 #include "kactioncollection.h" 29 #include "kis_tool_button.h" 30 #include "KisHighlightedToolButton.h" 31 #include <KisColorSelectorInterface.h> 32 33 class KisFavoriteResourceManager; 34 class QWidget; 35 class KoColor; 36 class KoTriangleColorSelector; 37 class KisSignalCompressor; 38 class KisBrushHud; 39 class KisRoundHudButton; 40 class KisCanvasResourceProvider; 41 class KisVisualColorSelector; 42 class KisAcyclicSignalConnector; 43 class KisMouseClickEater; 44 45 class KisPopupPalette : public QWidget 46 { 47 Q_OBJECT 48 49 Q_PROPERTY(int hoveredPreset READ hoveredPreset WRITE setHoveredPreset) 50 Q_PROPERTY(int hoveredColor READ hoveredColor WRITE setHoveredColor) 51 Q_PROPERTY(int selectedColor READ selectedColor WRITE setSelectedColor) 52 53 public: 54 KisPopupPalette(KisViewManager*, KisCoordinatesConverter* ,KisFavoriteResourceManager*, const KoColorDisplayRendererInterface *displayRenderer, 55 KisCanvasResourceProvider *provider, QWidget *parent = 0); 56 ~KisPopupPalette() override; 57 QSize sizeHint() const override; 58 59 void showPopupPalette(const QPoint&); 60 void showPopupPalette(bool b); 61 62 //functions to set up selectedBrush 63 void setSelectedBrush(int x); 64 int selectedBrush() const; 65 //functions to set up selectedColor 66 void setSelectedColor(int x); 67 int selectedColor() const; 68 void setParent(QWidget *parent); 69 70 void tabletEvent(QTabletEvent *event) override; 71 72 protected: 73 74 void showEvent(QShowEvent *event) override; 75 void paintEvent(QPaintEvent*) override; 76 void resizeEvent(QResizeEvent*) override; 77 void mouseReleaseEvent(QMouseEvent*) override; 78 void mouseMoveEvent(QMouseEvent*) override; 79 void mousePressEvent(QMouseEvent*) override; 80 81 //functions to calculate index of favorite brush or recent color in array 82 //n is the total number of favorite brushes or recent colors 83 int calculateIndex(QPointF, int n); 84 85 int calculatePresetIndex(QPointF, int n); 86 87 //functions to set up hoveredBrush 88 void setHoveredPreset(int x); 89 int hoveredPreset() const; 90 //functions to set up hoveredColor 91 void setHoveredColor(int x); 92 int hoveredColor() const; 93 94 private: 95 void setVisible(bool b) override; 96 97 QPainterPath drawDonutPathFull(int, int, int, int); 98 QPainterPath drawDonutPathAngle(int, int, int); 99 QPainterPath drawRotationIndicator(qreal rotationAngle, bool canDrag); 100 bool isPointInPixmap(QPointF&, int pos); 101 102 QPainterPath createPathFromPresetIndex(int index); 103 104 int numSlots(); 105 void adjustLayout(const QPoint &p); 106 107 private: 108 int m_hoveredPreset {0}; 109 int m_hoveredColor {0}; 110 int m_selectedColor {0}; 111 112 KisCoordinatesConverter *m_coordinatesConverter; 113 114 KisViewManager *m_viewManager; 115 KisActionManager *m_actionManager; 116 KisFavoriteResourceManager *m_resourceManager; 117 KisColorSelectorInterface *m_triangleColorSelector {0}; 118 const KoColorDisplayRendererInterface *m_displayRenderer; 119 QScopedPointer<KisSignalCompressor> m_colorChangeCompressor; 120 KActionCollection *m_actionCollection; 121 122 KisBrushHud *m_brushHud {0}; 123 float m_popupPaletteSize {385.0}; 124 float m_colorHistoryInnerRadius {72.0}; 125 qreal m_colorHistoryOuterRadius {92.0}; 126 127 KisRoundHudButton *m_settingsButton {0}; 128 KisRoundHudButton *m_brushHudButton {0}; 129 QPoint m_lastCenterPoint; 130 QRect m_canvasRotationIndicatorRect; 131 QRect m_resetCanvasRotationIndicatorRect; 132 bool m_isOverCanvasRotationIndicator {false}; 133 bool m_isRotatingCanvasIndicator {false}; 134 bool m_isZoomingCanvas {false}; 135 136 137 KisHighlightedToolButton *mirrorMode {0}; 138 KisHighlightedToolButton *canvasOnlyButton {0}; 139 QPushButton *zoomToOneHundredPercentButton {0}; 140 QSlider *zoomCanvasSlider {0}; 141 int zoomSliderMinValue {10}; 142 int zoomSliderMaxValue {200}; 143 QPushButton *clearHistoryButton {0}; 144 KisAcyclicSignalConnector *m_acyclicConnector = 0; 145 146 int m_cachedNumSlots {0}; 147 qreal m_cachedRadius {0.0}; 148 149 // updates the transparency and effects of the whole widget 150 QGraphicsOpacityEffect *opacityChange {0}; 151 KisMouseClickEater *m_clicksEater; 152 153 Q_SIGNALS: 154 void sigChangeActivePaintop(int); 155 void sigUpdateRecentColor(int); 156 void sigChangefGColor(const KoColor&); 157 void sigUpdateCanvas(); 158 void zoomLevelChanged(int); 159 160 public Q_SLOTS: 161 void slotUpdateIcons(); 162 163 private Q_SLOTS: 164 void slotDisplayConfigurationChanged(); 165 void slotExternalFgColorChanged(const KoColor &color); 166 void slotEmitColorChanged(); slotSetSelectedColor(int x)167 void slotSetSelectedColor(int x) { setSelectedColor(x); update(); } slotUpdate()168 void slotUpdate() { update(); } slotHide()169 void slotHide() { showPopupPalette(false); } 170 void slotShowTagsPopup(); 171 void showHudWidget(bool visible); 172 void slotZoomToOneHundredPercentClicked(); 173 void slotZoomSliderChanged(int zoom); 174 175 void slotZoomSliderPressed(); 176 void slotZoomSliderReleased(); 177 178 }; 179 180 #endif // KIS_POPUP_PALETTE_H 181