-
Notifications
You must be signed in to change notification settings - Fork 103
/
IconToolBar.qml
266 lines (210 loc) · 7.58 KB
/
IconToolBar.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
import QtQuick 2.6
import QtQuick.Controls 2.1
import App 1.0
import "." as Ui
Item {
id: root
objectName: "iconToolBar"
implicitWidth: toolbarRow.implicitWidth
implicitHeight: toolbarRow.implicitHeight
property Project project
property int projectType: project ? project.type : 0
property ImageCanvas canvas
property FontMetrics fontMetrics
property alias toolButtonGroup: toolButtonGroup
function switchTool(tool) {
root.ignoreToolChanges = true;
canvas.tool = tool;
root.ignoreToolChanges = false;
}
// TODO: figure out a nicer solution than this.
property bool ignoreToolChanges: false
Connections {
target: canvas
onToolChanged: {
if (root.ignoreToolChanges)
return;
switch (canvas.tool) {
case TileCanvas.PenTool:
toolButtonGroup.checkedButton = penToolButton;
break;
case TileCanvas.EyeDropperTool:
toolButtonGroup.checkedButton = eyeDropperToolButton;
break;
case TileCanvas.EraserTool:
toolButtonGroup.checkedButton = eraserToolButton;
break;
case TileCanvas.FillTool:
toolButtonGroup.checkedButton = fillToolButton;
break;
case TileCanvas.SelectionTool:
toolButtonGroup.checkedButton = selectionToolButton;
break;
}
}
}
Row {
id: toolbarRow
enabled: canvas
anchors.fill: parent
// Make sure that we don't end up on a sub-pixel position.
anchors.leftMargin: Math.round(toolSeparator.implicitWidth / 2)
ToolButton {
id: canvasSizeButton
objectName: "canvasSizeButton"
enabled: project ? project.loaded : false
hoverEnabled: true
focusPolicy: Qt.TabFocus
icon.source: "qrc:/images/change-size.png"
ToolTip.text: qsTr("Change the size of the canvas")
ToolTip.visible: hovered && !canvasSizePopup.visible
onClicked: canvasSizePopup.visible = !canvasSizePopup.visible
CanvasSizePopup {
id: canvasSizePopup
x: parent.x
y: parent.height + 10
project: root.project
}
}
ToolSeparator {}
Row {
spacing: 5
Ui.IconToolButton {
objectName: "undoButton"
iconText: "\uf0e2"
enabled: project ? project.undoStack.canUndo : false
hoverEnabled: true
ToolTip.text: qsTr("Undo the last canvas operation")
ToolTip.visible: hovered
onClicked: project.undoStack.undo()
}
Ui.IconToolButton {
objectName: "redoButton"
iconText: "\uf01e"
enabled: project ? project.undoStack.canRedo : false
hoverEnabled: true
ToolTip.text: qsTr("Redo the last undone canvas operation")
ToolTip.visible: hovered
onClicked: project.undoStack.redo()
}
ToolSeparator {}
}
Ui.IconToolButton {
id: modeToolButton
objectName: "modeToolButton"
iconText: "\uf044"
checked: canvas && canvas.mode === TileCanvas.TileMode
checkable: true
hoverEnabled: true
enabled: canvas && projectType === Project.TilesetType
ToolTip.text: qsTr("Operate on either pixels or whole tiles")
ToolTip.visible: hovered
onClicked: {
root.ignoreToolChanges = true;
canvas.mode = checked ? TileCanvas.TileMode : TileCanvas.PixelMode;
root.ignoreToolChanges = false;
}
}
ToolSeparator {}
ButtonGroup {
id: toolButtonGroup
buttons: toolLayout.children
}
Row {
id: toolLayout
spacing: 5
Ui.IconToolButton {
id: penToolButton
objectName: "penToolButton"
iconText: "\uf040"
checked: true
hoverEnabled: true
ToolTip.text: qsTr("Draw pixels or tiles on the canvas")
ToolTip.visible: hovered
onClicked: switchTool(ImageCanvas.PenTool)
}
Ui.IconToolButton {
id: eyeDropperToolButton
objectName: "eyeDropperToolButton"
iconText: "\uf1fb"
checkable: true
hoverEnabled: true
ToolTip.text: qsTr("Select colours or tiles from the canvas")
ToolTip.visible: hovered
onClicked: switchTool(ImageCanvas.EyeDropperTool)
}
Ui.IconToolButton {
id: eraserToolButton
objectName: "eraserToolButton"
iconText: "\uf12d"
checkable: true
hoverEnabled: true
ToolTip.text: qsTr("Erase pixels or tiles from the canvas")
ToolTip.visible: hovered
onClicked: switchTool(ImageCanvas.EraserTool)
}
Ui.IconToolButton {
id: fillToolButton
objectName: "fillToolButton"
iconText: "\uf0c3"
checkable: true
hoverEnabled: true
ToolTip.text: qsTr("Fill a contiguous area with pixels or tiles")
ToolTip.visible: hovered
onClicked: switchTool(ImageCanvas.FillTool)
}
ToolButton {
id: selectionToolButton
objectName: "selectionToolButton"
checkable: true
hoverEnabled: true
focusPolicy: Qt.TabFocus
enabled: projectType === Project.ImageType
icon.source: "qrc:/images/selection.png"
// TODO: checked colour
// icon.color: enabled ? undefined : Material.hintTextColor
ToolTip.text: qsTr("Select pixels within an area and move them")
ToolTip.visible: hovered
onClicked: switchTool(ImageCanvas.SelectionTool)
}
ToolSeparator {}
}
Ui.IconToolButton {
id: toolSizeButton
objectName: "toolSizeButton"
hoverEnabled: true
ToolTip.text: qsTr("Change the size of drawing tools")
ToolTip.visible: hovered && !toolSizeSliderPopup.visible
onClicked: toolSizeSliderPopup.visible = !toolSizeSliderPopup.visible
Item {
objectName: "toolSizeButtonIcon"
width: 12
height: 12
anchors.centerIn: parent
Ui.IconRectangle {
width: parent.width
height: 1
}
Ui.IconRectangle {
y: 4
width: parent.width
height: 2
}
Ui.IconRectangle {
y: 9
width: parent.width
height: 3
}
}
ToolSizePopup {
id: toolSizeSliderPopup
x: parent.width / 2 - width / 2
y: parent.height
canvas: root.canvas
}
}
ToolSeparator {
id: toolSeparator
}
}
}