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) const;
54  void refreshColorList();
55 
56  void adjustSwatches();
57 
58  void showContextMenu(const QPoint&);
59 
60 signals:
61  void colorNumberChanged(int);
62 
63 protected:
64  void resizeEvent(QResizeEvent* event) override;
65 
66 private slots:
67  void clickColorListItem(QListWidgetItem*);
68  void changeColorName(QListWidgetItem*);
69  void onItemChanged(QListWidgetItem* item);
70  void onRowsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row);
71  void clickAddColorButton();
72  void clickColorDialogButton();
73  void clickRemoveColorButton();
74  void palettePreferences();
75  void setListMode();
76  void setGridMode();
77  void setSwatchSizeSmall();
78  void setSwatchSizeMedium();
79  void setSwatchSizeLarge();
80  void fitSwatchSize();
81  void addItem();
82  void replaceItem();
83  void removeItem();
84  void showPaletteReminder();
85 
86  bool showPaletteWarning();
87 
88 private:
89  void updateItemColor(int, QColor);
90  void updateGridUI();
91  void addSwatch(int colorIndex) const;
92 
93  Ui::ColorPalette* ui = nullptr;
94  QActionGroup* mLayoutModeActionGroup = nullptr;
95  QAction* mListModeAction = nullptr;
96  QAction* mGridModeAction = nullptr;
97  QActionGroup* mIconSizesActionGroup = nullptr;
98  QAction* mSmallSwatchAction = nullptr;
99  QAction* mMediumSwatchAction = nullptr;
100  QAction* mLargeSwatchAction = nullptr;
101  QAction* mSeparator = nullptr;
102 
103  QSize mIconSize{ 34, 34 };
104  QMenu* mToolMenu = nullptr;
105  int stepper = 0;
106 
107  QString buttonStylesheet;
108 
109  bool mIsColorDialog = false;
110  bool mMultipleSelected = false;
111  bool mFitSwatches = false;
112 
113  const int MIN_ICON_SIZE = 19;
114  const int MEDIUM_ICON_SIZE = 26;
115  const int MAX_ICON_SIZE = 36;
116 
117  Editor* mEditor = nullptr;
118  Object* mObject = nullptr;
119 };
120 
121 #endif
122 
Q_OBJECTQ_OBJECT
virtual bool event(QEvent *event) override
Definition: object.h:41
Definition: editor.h:55
QObject * parent() const const