File indexing completed on 2024-06-16 04:16:24
0001 /* 0002 * SPDX-FileCopyrightText: 2020 Mathias Wein <lynx.mw+kde@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #ifndef WGCOLORPATCHES_H 0008 #define WGCOLORPATCHES_H 0009 0010 #include "WGSelectorWidgetBase.h" 0011 0012 #include <kis_types.h> 0013 0014 class KisUniqueColorSet; 0015 class KoColorDisplayRendererInterface; 0016 class QToolButton; 0017 0018 namespace WGConfig { 0019 struct ColorPatches; 0020 } 0021 0022 class WGColorPatches : public WGSelectorWidgetBase 0023 { 0024 Q_OBJECT 0025 public: 0026 enum Preset { 0027 None, 0028 History, 0029 CommonColors 0030 }; 0031 0032 WGColorPatches(WGSelectorDisplayConfigSP displayConfig, KisUniqueColorSet *history, QWidget *parent = nullptr); 0033 0034 KisUniqueColorSet* colorHistory() const; 0035 void updateSettings() override; 0036 void setPreset(Preset preset); 0037 QPoint popupOffset() const override; 0038 /*! set buttons, that should be drawn additionally to the patches 0039 * this class takes ownership of them and will delete them 0040 * they will be resized to the patchsize */ 0041 void setAdditionalButtons(QList<QToolButton*> buttonList); 0042 void setColorHistory(KisUniqueColorSet *history); 0043 public Q_SLOTS: 0044 void updateIcons(); 0045 protected: 0046 bool event(QEvent *event) override; 0047 bool eventFilter(QObject *watched, QEvent *e) override; 0048 void mouseMoveEvent(QMouseEvent *event) override; 0049 void mousePressEvent(QMouseEvent *event) override; 0050 void mouseReleaseEvent(QMouseEvent *event) override; 0051 void wheelEvent(QWheelEvent *event) override; 0052 void contentPaintEvent(QPaintEvent *event); 0053 void resizeEvent(QResizeEvent *event) override; 0054 QSize sizeHint() const override; 0055 0056 int indexAt(const QPoint &widgetPos) const; 0057 QRect patchRect(int gridIndex) const; 0058 QPoint scrollOffset() const; 0059 void updateMetrics(); 0060 QToolButton* fetchButton(QList<QToolButton*> &recycleList); 0061 void reconnectButtons(KisUniqueColorSet *oldSet, KisUniqueColorSet *newSet); 0062 0063 private: 0064 QPointer<KisUniqueColorSet> m_colors; 0065 QList<QToolButton*> m_buttonList; 0066 Qt::Orientation m_orientation {Qt::Horizontal}; 0067 const WGConfig::ColorPatches *m_configSource {0}; 0068 QWidget *m_viewport {0}; 0069 QWidget *m_contentWidget {0}; 0070 int m_numLines {1}; 0071 int m_patchesPerLine {30}; 0072 int m_totalLines {1}; 0073 int m_patchWidth {16}; 0074 int m_patchHeight {16}; 0075 int m_patchCount {30}; 0076 int m_scrollValue {0}; 0077 int m_maxScroll {0}; 0078 int m_mouseIndex {-1}; 0079 bool m_allowScrolling {true}; 0080 bool m_scrollInline {true}; 0081 Preset m_preset {None}; 0082 0083 Q_SIGNALS: 0084 void sigColorChanged(const KoColor &color); 0085 0086 }; 0087 0088 #endif // WGCOLORPATCHES_H