/
editor.cpp
243 lines (205 loc) · 7.91 KB
/
editor.cpp
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
#include "editor.h"
#include "ui_editor.h"
Editor::Editor(const Logger* lg, ProjectManager* pm, QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Editor),
GridVisible(true),
LogViewerDialog(lg,this),
LayerViewerDialog(this),
ChooseExportTypeDialog(0),
UndoViewerDialog(0),
ProjectManagerPtr(pm)
{
ui->setupUi(this);
connect(this->ui->tabWidget,SIGNAL(requestNewArray(int)),pm,SLOT(createNewArray(int)));
connect(this->ui->tabWidget,SIGNAL(currentArrayChanged(Array*)),pm,SLOT(setCurrentArray(Array*)));
connect(pm,SIGNAL(newArrayCreated(int,Array*)),this->ui->tabWidget,SLOT(setNewArray(int,Array*)));
connect(lg,SIGNAL(totalLogCountChanged(int)),&(this->LogViewerDialog),SLOT(setTotalLogCount(int)));
connect(this->ui->tabWidget,SIGNAL(layerTreeModelChanged(LayerTreeModel*)),&LayerViewerDialog,SLOT(setLayerTreeModel(LayerTreeModel*)));
connect(&LayerViewerDialog,SIGNAL(selectionModelChanged(QItemSelectionModel*)),this->ui->tabWidget,SLOT(setLayerSelectionModel(QItemSelectionModel*)));
//LayerViewerDialog buttons/key stroke signals
connect(&LayerViewerDialog,SIGNAL(deleteSelectedLayers()),SLOT(on_LayerViewer_deleteLayers()));
connect(&LayerViewerDialog,SIGNAL(groupSelectedLayers()),SLOT(on_LayerViewer_groupLayers()));
connect(&LayerViewerDialog,SIGNAL(ungroupSelectedLayers()),SLOT(on_LayerViewer_ungroupLayers()));
connect(&LayerViewerDialog,SIGNAL(moveSelectedLayersUp()),SLOT(on_LayerViewer_moveLayersUp()));
connect(&LayerViewerDialog,SIGNAL(moveSelectedLayersDown()),SLOT(on_LayerViewer_moveLayersDown()));
connect(&LayerViewerDialog,SIGNAL(moveSelectedLayersToFront()),SLOT(on_LayerViewer_moveLayersToFront()));
connect(&LayerViewerDialog,SIGNAL(moveSelectedLayersToBack()),SLOT(on_LayerViewer_moveLayersToBack()));
//unchecks the tool bar buttons when the corresponding window is closed/rejected (QDialog)
connect(&LogViewerDialog,SIGNAL(rejected()),SLOT(on_LogViewer_closed()));
connect(&LayerViewerDialog,SIGNAL(rejected()),SLOT(on_LayerViewer_closed()));
//hack to remove the first Tab created by the qt designer
this->ui->tabWidget->newTab();
this->ui->tabWidget->removeTab(0);
//Add Undo/Redo To Toolbar
QAction* undo = pm->getUndoAction(this);
undo->setIcon(QIcon(":/Toolbar/Undo.ico"));
undo->setShortcut(QKeySequence::Undo);
this->ui->mainToolBar->insertAction(this->ui->actionUndoList,undo);
QAction* redo = pm->getRedoAction(this);
redo->setIcon(QIcon(":/Toolbar/Redo.ico"));
redo->setShortcut(QKeySequence::Redo);
this->ui->mainToolBar->insertAction(this->ui->actionCropArray,redo);
//Create UndoViewerDialog and link it to the UndoGroup
this->UndoViewerDialog = new UndoViewer(this);
pm->setUndoViewer(this->UndoViewerDialog->getView());
//TODO proper check if the grid is enabled after loading a project or change of array
this->ui->actionShowGrid->setChecked(true);
showMaximized();
}
Editor::~Editor()
{
delete ui;
if(this->ChooseExportTypeDialog)
delete this->ChooseExportTypeDialog;
if(this->UndoViewerDialog)
delete this->UndoViewerDialog;
}
void Editor::setLogTableModel(LogTableModel *model)
{
this->LogViewerDialog.setLogTableModel(model);
}
void Editor::keyPressEvent(QKeyEvent *event)
{
//////////////////////////////////////////////////////////////////////////////////////////////
//Please handle all short-cuts here and not in QtDesigner
//if a short cut triggers a window and therefore the new window gathers the focus please
//add the shortcut to the windows keyPressedEvent to hide/reject it for a better workflow
//////////////////////////////////////////////////////////////////////////////////////////////
switch(event->key())
{
case Qt::Key_Delete:
this->ui->tabWidget->getCurrentView()->scene()->removeSelectedLayers();
break;
case Qt::Key_U:
if(event->modifiers() == Qt::ControlModifier)
this->ui->tabWidget->getCurrentView()->scene()->ungroupSelectedLayers();
else
this->ui->actionUndoList->trigger();
break;
case Qt::Key_Control:
this->ui->tabWidget->enablePanning(true);
this->ui->actionEnablePanning->setChecked(true);
break;
case Qt::Key_G:
if(event->modifiers() == Qt::ControlModifier)
{
this->ui->tabWidget->getCurrentView()->scene()->groupSelectedLayers();
}
else
{
this->GridVisible = !(this->ui->tabWidget->isCurrentGridVisible());
this->ui->tabWidget->showGrid(this->GridVisible);
this->ui->actionShowGrid->setChecked(this->GridVisible);
}
break;
case Qt::Key_L:
if(event->modifiers() == Qt::ControlModifier)
this->ui->actionLog->trigger();
else
this->ui->actionLayerViewer->trigger();
break;
}
}
void Editor::keyReleaseEvent(QKeyEvent *event)
{
switch(event->key())
{
case Qt::Key_Control:
this->ui->tabWidget->enablePanning(false);
this->ui->actionEnablePanning->setChecked(false);
break;
}
}
bool Editor::event(QEvent *e)
{
if(e->type() == QEvent::WindowDeactivate)
{
this->ui->actionEnablePanning->setChecked(false);
this->ui->tabWidget->enablePanning(false);
}
return QMainWindow::event(e);
}
void Editor::on_actionLog_triggered()
{
if(this->LogViewerDialog.isVisible())
this->LogViewerDialog.hide();
else
this->LogViewerDialog.show();
this->ui->actionLog->setChecked(this->LogViewerDialog.isVisible());
}
void Editor::on_actionLayerViewer_triggered()
{
if(this->LayerViewerDialog.isVisible())
this->LayerViewerDialog.hide();
else
this->LayerViewerDialog.show();
this->ui->actionLayerViewer->setChecked(this->LayerViewerDialog.isVisible());
}
void Editor::on_actionEnablePanning_triggered()
{
this->ui->tabWidget->enablePanning(this->ui->actionEnablePanning->isChecked());
}
void Editor::on_actionShowGrid_triggered()
{
this->ui->tabWidget->showGrid(this->ui->actionShowGrid->isChecked());
}
void Editor::on_LogViewer_closed()
{
this->ui->actionLog->setChecked(false);
}
void Editor::on_LayerViewer_closed()
{
this->ui->actionLayerViewer->setChecked(false);
}
void Editor::on_LayerViewer_deleteLayers()
{
this->ui->tabWidget->getCurrentView()->scene()->removeSelectedLayers();
}
void Editor::on_LayerViewer_groupLayers()
{
this->ui->tabWidget->getCurrentView()->scene()->groupSelectedLayers();
}
void Editor::on_LayerViewer_ungroupLayers()
{
this->ui->tabWidget->getCurrentView()->scene()->ungroupSelectedLayers();
}
void Editor::on_LayerViewer_moveLayersUp()
{
this->ui->tabWidget->getCurrentView()->scene()->moveSelectedLayersUp();
}
void Editor::on_LayerViewer_moveLayersDown()
{
this->ui->tabWidget->getCurrentView()->scene()->moveSelectedLayersDown();
}
void Editor::on_LayerViewer_moveLayersToFront()
{
this->ui->tabWidget->getCurrentView()->scene()->moveSelectedLayersUp(true);
}
void Editor::on_LayerViewer_moveLayersToBack()
{
this->ui->tabWidget->getCurrentView()->scene()->moveSelectedLayersDown(true);
}
void Editor::on_actionSaveArray_triggered()
{
if(!(this->ChooseExportTypeDialog))
{
this->ChooseExportTypeDialog = new ExportTypeDialog(this->ProjectManagerPtr->getExportFilters(),this);
}
if(this->ChooseExportTypeDialog->exec() == QDialog::Accepted)
{
if(!(this->ChooseExportTypeDialog->getSelectedType().isEmpty()))
this->ui->tabWidget->getCurrentView()->scene()->exportImage(this->ChooseExportTypeDialog->getSelectedType());
}
}
void Editor::on_actionUndoList_triggered()
{
if(this->UndoViewerDialog)
{
if(this->UndoViewerDialog->isVisible())
this->UndoViewerDialog->hide();
else
this->UndoViewerDialog->show();
this->ui->actionUndoList->setChecked(this->UndoViewerDialog->isVisible());
}
}