Wed, 26 Dec 2018 16:38:38 +0200
Refactored the color toolbar editing into a new model/view system
1432
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
1 | /* |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
3 | * Copyright (C) 2013 - 2018 Teemu Piippo |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
4 | * |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
9 | * |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
14 | * |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
17 | */ |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
18 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
19 | #pragma once |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
20 | #include <QWidget> |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
21 | #include <QAbstractListModel> |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
22 | #include "colors.h" |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
23 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
24 | class ColorToolbarModel : public QAbstractListModel |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
25 | { |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
26 | Q_OBJECT |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
27 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
28 | public: |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
29 | ColorToolbarModel(QVector<LDColor>& colorToolbar); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
30 | int rowCount(QModelIndex const& = {}) const override; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
31 | QVariant data(QModelIndex const& index, int role) const override; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
32 | LDColor colorAt(QModelIndex const& index) const; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
33 | void setColorAt(QModelIndex const& index, LDColor newColor); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
34 | bool isValidIndex(QModelIndex const& index) const; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
35 | void moveColor(const QModelIndex &index, const bool up); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
36 | bool insertRows(int row, int count, QModelIndex const& = {}) override; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
37 | bool removeRows(int row, int count, QModelIndex const& = {}) override; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
38 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
39 | bool isValidRow(int row) const; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
40 | private: |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
41 | QVector<LDColor>& colorToolbar; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
42 | }; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
43 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
44 | class ColorToolbarEditor : public QWidget |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
45 | { |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
46 | Q_OBJECT |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
47 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
48 | public: |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
49 | explicit ColorToolbarEditor(QWidget *parent = nullptr); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
50 | ~ColorToolbarEditor(); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
51 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
52 | public slots: |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
53 | void addColor(); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
54 | void editColor(); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
55 | void removeColor(); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
56 | void moveColor(); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
57 | void addSeparator(); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
58 | void clearColors(); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
59 | void saveChanges(); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
60 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
61 | private: |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
62 | QVector<LDColor> colorToolbar; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
63 | ColorToolbarModel model; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
64 | class Ui_ColorToolbarEditor &ui; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
65 | int newItemPosition(); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
66 | }; |