All Classes Namespaces Functions Variables Enumerations Properties Pages
colorpalettewidget.h
1 /*
2 
3 Pencil2D - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2020 Matthew Chiawen Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 */
17 
18 #ifndef COLOR_PALETTE_WIDGET_H
19 #define COLOR_PALETTE_WIDGET_H
20 
21 #include "basedockwidget.h"
22 
23 class QToolButton;
24 class QListWidget;
25 class QListWidgetItem;
26 class Object;
27 class Editor;
28 class ColorBox;
29 class QActionGroup;
30 class QMenu;
31 class QString;
32 
33 namespace Ui
34 {
35  class ColorPalette;
36 }
37 
39 {
40  Q_OBJECT
41 
42 public:
43 
45  ~ColorPaletteWidget() override;
46 
47  void initUI() override;
48  void updateUI() override;
49  void setCore(Editor* editor);
50 
51  int currentColorNumber();
52 
53  void selectColorNumber(int);
54  void setColor(QColor, int);
55  void refreshColorList();
56 
57  void adjustSwatches();
58 
59  void showContextMenu(const QPoint&);
60 
61 signals:
62  void colorChanged(QColor);
63  void colorNumberChanged(int);
64 
65 protected:
66  void resizeEvent(QResizeEvent* event) override;
67 
68 private slots:
69  void clickColorListItem(QListWidgetItem*);
70  void changeColorName(QListWidgetItem*);
71  void onItemChanged(QListWidgetItem* item);
72  void onRowsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row);
73  void clickAddColorButton();
74  void clickColorDialogButton();
75  void clickRemoveColorButton();
76  void palettePreferences();
77  void setListMode();
78  void setGridMode();
79  void setSwatchSizeSmall();
80  void setSwatchSizeMedium();
81  void setSwatchSizeLarge();
82  void fitSwatchSize();
83  void addItem();
84  void replaceItem();
85  void removeItem();
86  void showPaletteReminder();
87 
88  bool showPaletteWarning();
89 
90 private:
91  void updateItemColor(int, QColor);
92  void updateGridUI();
93 
94  Ui::ColorPalette* ui = nullptr;
95  QActionGroup* mLayoutModeActionGroup = nullptr;
96  QAction* mListModeAction = nullptr;
97  QAction* mGridModeAction = nullptr;
98  QActionGroup* mIconSizesActionGroup = nullptr;
99  QAction* mSmallSwatchAction = nullptr;
100  QAction* mMediumSwatchAction = nullptr;
101  QAction* mLargeSwatchAction = nullptr;
102  QAction* mSeparator = nullptr;
103 
104  QSize mIconSize{ 34, 34 };
105  QMenu* mToolMenu = nullptr;
106  int stepper = 0;
107 
108  QString buttonStylesheet;
109 
110  bool mIsColorDialog = false;
111  bool mMultipleSelected = false;
112  bool mFitSwatches = false;
113 
114  const int MIN_ICON_SIZE = 19;
115  const int MEDIUM_ICON_SIZE = 26;
116  const int MAX_ICON_SIZE = 36;
117 
118  Editor* mEditor = nullptr;
119  Object* mObject = nullptr;
120 };
121 
122 #endif
123 
Q_OBJECTQ_OBJECT
virtual bool event(QEvent *event) override
Definition: object.h:54
Definition: editor.h:51
QObject * parent() const const