Thu, 07 Feb 2019 13:45:07 +0200
stuff
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 | #include <QListView> |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
20 | #include "colortoolbareditor.h" |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
21 | #include "ui_colortoolbareditor.h" |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
22 | #include "guiutilities.h" |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
23 | #include "colorselector.h" |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
24 | |
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 | * Constructs a new color toolbar editor widget. |
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 | ColorToolbarEditor::ColorToolbarEditor(QWidget *parent) : |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
29 | QWidget {parent}, |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
30 | colorToolbar {config::quickColorToolbar()}, |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
31 | model {colorToolbar}, |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
32 | ui {*new Ui_ColorToolbarEditor} |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
33 | { |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
34 | ui.setupUi(this); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
35 | ui.colorToolbarView->setModel(&model); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
36 | connect(ui.quickColor_add, &QAbstractButton::clicked, this, &ColorToolbarEditor::addColor); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
37 | connect(ui.quickColor_remove, &QAbstractButton::clicked, this, &ColorToolbarEditor::removeColor); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
38 | connect(ui.quickColor_edit, &QAbstractButton::clicked, this, &ColorToolbarEditor::editColor); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
39 | connect(ui.quickColor_addSep, &QAbstractButton::clicked, this, &ColorToolbarEditor::addSeparator); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
40 | connect(ui.quickColor_moveUp, &QAbstractButton::clicked, this, &ColorToolbarEditor::moveColor); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
41 | connect(ui.quickColor_moveDown, &QAbstractButton::clicked, this, &ColorToolbarEditor::moveColor); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
42 | connect(ui.quickColor_clear, &QAbstractButton::clicked, this, &ColorToolbarEditor::clearColors); |
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 | |
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 | * Destroys the color toolbar editor widget. |
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 | ColorToolbarEditor::~ColorToolbarEditor() |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
49 | { |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
50 | delete &ui; |
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 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
53 | /* |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
54 | * Returns where a new color toolbar entry should be inserted to. |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
55 | * If the user has selected an entry, the new entry is placed below it. |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
56 | * Otherwise it goes to the end of the toolbar. |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
57 | */ |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
58 | int ColorToolbarEditor::newItemPosition() |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
59 | { |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
60 | QModelIndexList const indexes = ui.colorToolbarView->selectionModel()->selectedIndexes(); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
61 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
62 | if (indexes.size() > 0) |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
63 | return indexes.last().row() + 1; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
64 | else |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
65 | return model.rowCount(); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
66 | } |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
67 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
68 | /* |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
69 | * Adds a new color toolbar entry |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
70 | */ |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
71 | void ColorToolbarEditor::addColor() |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
72 | { |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
73 | LDColor value; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
74 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
75 | if (not ColorSelector::selectColor (this, value, LDColor::nullColor)) |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
76 | return; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
77 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
78 | int const position = newItemPosition(); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
79 | model.insertRow(position); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
80 | model.setColorAt(model.index(position), value); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
81 | } |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
82 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
83 | /* |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
84 | * Changes an existing color toolbar entry |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
85 | */ |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
86 | void ColorToolbarEditor::editColor() |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
87 | { |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
88 | QModelIndexList const indexes = ui.colorToolbarView->selectionModel()->selectedIndexes(); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
89 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
90 | if (indexes.size() > 0) |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
91 | { |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
92 | QModelIndex const& position = indexes[0]; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
93 | LDColor const color = model.colorAt(position); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
94 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
95 | if (color == LDColor::nullColor) |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
96 | return; // don't color separators |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
97 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
98 | LDColor newColor; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
99 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
100 | if (ColorSelector::selectColor(this, newColor, color)) |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
101 | model.setColorAt(position, newColor); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
102 | } |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
103 | } |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
104 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
105 | // |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
106 | // Remove a quick color |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
107 | // |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
108 | void ColorToolbarEditor::removeColor() |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
109 | { |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
110 | QModelIndexList const selection = ui.colorToolbarView->selectionModel()->selectedIndexes(); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
111 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
112 | if (not selection.empty()) |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
113 | model.removeRow(selection[0].row()); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
114 | } |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
115 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
116 | // |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
117 | // Move a quick color up/down |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
118 | // |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
119 | void ColorToolbarEditor::moveColor() |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
120 | { |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
121 | bool const up = (static_cast<QPushButton*>(sender()) == ui.quickColor_moveUp); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
122 | QModelIndexList const selection = ui.colorToolbarView->selectionModel()->selectedIndexes(); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
123 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
124 | if (not selection.empty()) |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
125 | model.moveColor(selection[0], up); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
126 | } |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
127 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
128 | /* |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
129 | * Adds a new separator into the color toolbar. |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
130 | */ |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
131 | void ColorToolbarEditor::addSeparator() |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
132 | { |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
133 | int const position = newItemPosition(); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
134 | model.insertRow(position); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
135 | model.setColorAt(model.index(position), LDColor::nullColor); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
136 | } |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
137 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
138 | /* |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
139 | * Clears the color toolbar. |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
140 | */ |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
141 | void ColorToolbarEditor::clearColors() |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
142 | { |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
143 | model.removeRows(0, model.rowCount()); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
144 | } |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
145 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
146 | /* |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
147 | * Saves the changes done in the color toolbar editor |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
148 | */ |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
149 | void ColorToolbarEditor::saveChanges() |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
150 | { |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
151 | config::setQuickColorToolbar(colorToolbar); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
152 | } |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
153 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
154 | /* |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
155 | * Constructs a new model for editing the color toolbar. |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
156 | */ |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
157 | ColorToolbarModel::ColorToolbarModel(QVector<LDColor> &colorToolbar) : |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
158 | colorToolbar {colorToolbar} {} |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
159 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
160 | /* |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
161 | * Returns the amount of entries in the color toolbar. |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
162 | */ |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
163 | int ColorToolbarModel::rowCount(QModelIndex const&) const |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
164 | { |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
165 | return colorToolbar.size(); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
166 | } |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
167 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
168 | /* |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
169 | * Returns data of the color toolbar. |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
170 | */ |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
171 | QVariant ColorToolbarModel::data(const QModelIndex& index, int role) const |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
172 | { |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
173 | int const row = index.row(); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
174 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
175 | if (row < 0 or row >= rowCount()) |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
176 | return {}; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
177 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
178 | LDColor const color = colorToolbar[row]; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
179 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
180 | switch(role) |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
181 | { |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
182 | case Qt::DecorationRole: |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
183 | if (color == LDColor::nullColor) |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
184 | return {}; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
185 | else |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
186 | return makeColorIcon(color, 16); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
187 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
188 | case Qt::DisplayRole: |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
189 | if (color == LDColor::nullColor) |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
190 | return ""; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
191 | else |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
192 | return color.name(); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
193 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
194 | default: |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
195 | return {}; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
196 | } |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
197 | } |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
198 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
199 | /* |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
200 | * Returns a color in the color toolbar. |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
201 | */ |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
202 | LDColor ColorToolbarModel::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
|
203 | { |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
204 | if (isValidIndex(index)) |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
205 | return colorToolbar[index.row()]; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
206 | else |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
207 | return {}; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
208 | } |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
209 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
210 | /* |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
211 | * Changes a color in the color toolbar. |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
212 | */ |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
213 | void ColorToolbarModel::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
|
214 | { |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
215 | if (isValidIndex(index)) |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
216 | { |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
217 | colorToolbar[index.row()] = newColor; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
218 | emit dataChanged(index, index); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
219 | } |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
220 | } |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
221 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
222 | /* |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
223 | * Moves a color up or down in the color toolbar. |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
224 | */ |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
225 | void ColorToolbarModel::moveColor(const QModelIndex &index, bool const up) |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
226 | { |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
227 | int const position = index.row(); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
228 | int const destination = position + (up ? -1 : 1); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
229 | int const end = destination + (up ? 0 : 1); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
230 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
231 | if (isValidRow(position) and isValidRow(destination)) |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
232 | { |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
233 | emit beginMoveRows({}, position, position, {}, end); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
234 | qSwap(colorToolbar[destination], colorToolbar[position]); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
235 | emit endMoveRows(); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
236 | } |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
237 | } |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
238 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
239 | /* |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
240 | * Inserts entries in the color toolbar. |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
241 | */ |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
242 | bool ColorToolbarModel::insertRows(int row, int count, QModelIndex const&) |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
243 | { |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
244 | if (row >= 0 and row <= colorToolbar.size()) |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
245 | { |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
246 | emit beginInsertRows({}, row, count); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
247 | while (count > 0) |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
248 | { |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
249 | colorToolbar.insert(row, {}); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
250 | count -= 1; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
251 | row += 1; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
252 | } |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
253 | emit endInsertRows(); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
254 | return true; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
255 | } |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
256 | else |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
257 | { |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
258 | return false; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
259 | } |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
260 | } |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
261 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
262 | /* |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
263 | * Removes entries in the color toolbar. |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
264 | */ |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
265 | bool ColorToolbarModel::removeRows(int row, int count, QModelIndex const&) |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
266 | { |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
267 | if (row >= 0 and row + count <= colorToolbar.size()) |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
268 | { |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
269 | emit beginRemoveRows({}, row, row); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
270 | while (count > 0) |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
271 | { |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
272 | colorToolbar.removeAt(row); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
273 | count -= 1; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
274 | } |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
275 | emit endRemoveRows(); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
276 | return true; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
277 | } |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
278 | else |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
279 | { |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
280 | return false; |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
281 | } |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
282 | } |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
283 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
284 | /* |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
285 | * Returns whether or not the specified index is valid in the color toolbar. |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
286 | */ |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
287 | bool ColorToolbarModel::isValidIndex(const QModelIndex &index) const |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
288 | { |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
289 | return isValidRow(index.row()); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
290 | } |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
291 | |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
292 | /* |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
293 | * Returns whether or not the specified row is valid in the color toolbar. |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
294 | */ |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
295 | bool ColorToolbarModel::isValidRow(int row) const |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
296 | { |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
297 | return row >= 0 and row < colorToolbar.size(); |
4cc687851fbb
Refactored the color toolbar editing into a new model/view system
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
298 | } |