1 | #include "ProjectionModel.h" |
---|
2 | #include "Scene.h" |
---|
3 | #include "Screen.h" |
---|
4 | #include "Channel.h" |
---|
5 | #include "RSync.h" |
---|
6 | #include "Exporter.h" |
---|
7 | #include "GUIControler.h" |
---|
8 | |
---|
9 | #include "gui/QDesignViewWindow.h" |
---|
10 | |
---|
11 | #include "plugindialog.h" |
---|
12 | |
---|
13 | #include <QAction> |
---|
14 | #include <QApplication> |
---|
15 | #include <QFileDialog> |
---|
16 | |
---|
17 | using namespace projection; |
---|
18 | |
---|
19 | QDesignViewWindow::QDesignViewWindow(QWidget* pParent, Qt::WFlags flags) |
---|
20 | : QMainWindow(pParent, flags) |
---|
21 | { |
---|
22 | ui.setupUi(this); |
---|
23 | |
---|
24 | // initialize recent files list |
---|
25 | for (unsigned int i=0; i<MAX_RECENT_FILES; ++i) { |
---|
26 | m_pRecentFileActs[i] = new QAction(this); |
---|
27 | m_pRecentFileActs[i]->setVisible(false); |
---|
28 | connect(m_pRecentFileActs[i], SIGNAL(triggered()), this, SLOT(openRecentFile())); |
---|
29 | } |
---|
30 | |
---|
31 | m_pSeparatorAct = ui.menuFile->addSeparator(); |
---|
32 | m_pSeparatorAct->setVisible(false); |
---|
33 | for (unsigned int i=0; i<MAX_RECENT_FILES; ++i) |
---|
34 | ui.menuFile->addAction(m_pRecentFileActs[i]); |
---|
35 | ui.menuFile->addSeparator(); |
---|
36 | ui.menuFile->addAction(ui.actionFileExit); |
---|
37 | ui.menuFile->addAction(ui.actionFileExitAll); |
---|
38 | |
---|
39 | updateRecentFileActions(); |
---|
40 | |
---|
41 | // initialize toggle actions |
---|
42 | ui.actionEditDesignDistortionMap->setCheckable(true); |
---|
43 | ui.actionEditDesignBlendMap->setCheckable(true); |
---|
44 | ui.actionEditDesignDistortionMap->setChecked(true); |
---|
45 | |
---|
46 | ui.actionViewPerspective->setCheckable(true); |
---|
47 | ui.actionViewCenter->setCheckable(true); |
---|
48 | ui.actionViewTop->setCheckable(true); |
---|
49 | ui.actionViewSide->setCheckable(true); |
---|
50 | ui.actionViewFront->setCheckable(true); |
---|
51 | ui.actionViewAxis->setCheckable(true); |
---|
52 | ui.actionViewGrid->setCheckable(true); |
---|
53 | ui.actionViewInfo->setCheckable(true); |
---|
54 | |
---|
55 | ui.actionViewAxis->setChecked(ui.designViewWidget->isAxisVisible()); |
---|
56 | ui.actionViewGrid->setChecked(ui.designViewWidget->isGridVisible()); |
---|
57 | ui.actionViewInfo->setChecked(ui.designViewWidget->isInfoVisible()); |
---|
58 | |
---|
59 | QShortcut* pShortcut = new QShortcut(this); |
---|
60 | pShortcut->setKey(Qt::Key_Escape); |
---|
61 | pShortcut->setContext(Qt::WindowShortcut); |
---|
62 | pShortcut->setEnabled(true); |
---|
63 | connect(pShortcut, SIGNAL(activated()), this, SLOT(activateDesignView())); |
---|
64 | |
---|
65 | statusBar(); |
---|
66 | |
---|
67 | ui.panelWidget->setMinimumWidth(240); |
---|
68 | QList<int> sizes; |
---|
69 | sizes << width()-240 << 240; |
---|
70 | ui.splitter->setSizes(sizes); |
---|
71 | } |
---|
72 | |
---|
73 | QDesignViewWindow::~QDesignViewWindow() |
---|
74 | { |
---|
75 | } |
---|
76 | |
---|
77 | void QDesignViewWindow::setModel(ProjectionModel* pModel) |
---|
78 | { |
---|
79 | m_pModel = pModel; |
---|
80 | ui.designViewWidget->setModel(pModel); |
---|
81 | ui.panelWidget->setModel(pModel); |
---|
82 | |
---|
83 | if (m_pModel->getRSync()->isServer()) |
---|
84 | ui.actionFileSyncClients->setEnabled(true); |
---|
85 | else |
---|
86 | ui.actionFileSyncClients->setEnabled(false); |
---|
87 | setCurrentFile(""); |
---|
88 | } |
---|
89 | |
---|
90 | QGLWidget* QDesignViewWindow::getGLWidget() const |
---|
91 | { |
---|
92 | return ui.designViewWidget; |
---|
93 | } |
---|
94 | |
---|
95 | QDesignViewWidget* QDesignViewWindow::getDesignView() const |
---|
96 | { |
---|
97 | return ui.designViewWidget; |
---|
98 | } |
---|
99 | |
---|
100 | QPanelWidget* QDesignViewWindow::getPanel() const |
---|
101 | { |
---|
102 | return ui.panelWidget; |
---|
103 | } |
---|
104 | |
---|
105 | void QDesignViewWindow::setCurrentFile(const QString& fileName) |
---|
106 | { |
---|
107 | m_fileName = fileName; |
---|
108 | |
---|
109 | QString title; |
---|
110 | if (m_pModel->getRSync()->isServer()) |
---|
111 | title = QString(" : Server (%1:%2)").arg(m_pModel->getRSync()->getHostName()).arg(m_pModel->getRSync()->getPortNo()); |
---|
112 | else |
---|
113 | title = QString(" : Client (%1:%2)").arg(m_pModel->getRSync()->getServerAddress()).arg(m_pModel->getRSync()->getPortNo()); |
---|
114 | |
---|
115 | if (m_fileName.isEmpty()) |
---|
116 | setWindowTitle(tr(APPLICATION_NAME) + title); |
---|
117 | else |
---|
118 | setWindowTitle(tr("%1 - %2").arg(QFileInfo(m_fileName).fileName()).arg(APPLICATION_NAME) + title); |
---|
119 | |
---|
120 | if (!fileName.isEmpty()) |
---|
121 | { |
---|
122 | QSettings settings("Orihalcon", APPLICATION_NAME); |
---|
123 | QStringList files = settings.value("recentFileList").toStringList(); |
---|
124 | files.removeAll(m_fileName); |
---|
125 | files.prepend(m_fileName); |
---|
126 | while (files.size() > MAX_RECENT_FILES) |
---|
127 | files.removeLast(); |
---|
128 | settings.setValue("recentFileList", files); |
---|
129 | updateRecentFileActions(); |
---|
130 | } |
---|
131 | } |
---|
132 | |
---|
133 | void QDesignViewWindow::updateRecentFileActions() |
---|
134 | { |
---|
135 | QSettings settings("Orihalcon", APPLICATION_NAME); |
---|
136 | QStringList files = settings.value("recentFileList").toStringList(); |
---|
137 | |
---|
138 | int numRecentFiles = qMin(files.size(), (int)MAX_RECENT_FILES); |
---|
139 | |
---|
140 | for (int i=0; i<numRecentFiles; ++i) { |
---|
141 | QString text = tr("&%1 %2").arg(i + 1).arg(QFileInfo(files[i]).fileName()); |
---|
142 | m_pRecentFileActs[i]->setText(text); |
---|
143 | m_pRecentFileActs[i]->setData(files[i]); |
---|
144 | m_pRecentFileActs[i]->setVisible(true); |
---|
145 | } |
---|
146 | for (int j=numRecentFiles; j<MAX_RECENT_FILES; ++j) |
---|
147 | m_pRecentFileActs[j]->setVisible(false); |
---|
148 | |
---|
149 | m_pSeparatorAct->setVisible(numRecentFiles > 0); |
---|
150 | } |
---|
151 | |
---|
152 | void QDesignViewWindow::openRecentFile() |
---|
153 | { |
---|
154 | QAction* pAction = qobject_cast<QAction *>(sender()); |
---|
155 | if (pAction) |
---|
156 | loadFile(pAction->data().toString()); |
---|
157 | } |
---|
158 | |
---|
159 | bool QDesignViewWindow::loadFile(const QString& fileName) |
---|
160 | { |
---|
161 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
162 | bool result = m_pModel->loadFile(fileName); |
---|
163 | if (result) |
---|
164 | { |
---|
165 | setCurrentFile(fileName); |
---|
166 | statusBar()->showMessage(tr("File loaded"), 2000); |
---|
167 | } |
---|
168 | else |
---|
169 | { |
---|
170 | QMessageBox::critical( this, "Could not load File", "An Error occured while parsing the project file.<br>It's impossible to continue, so starting an new empty project."); |
---|
171 | on_actionFileNew_triggered(); |
---|
172 | } |
---|
173 | QApplication::restoreOverrideCursor(); |
---|
174 | return result; |
---|
175 | } |
---|
176 | |
---|
177 | bool QDesignViewWindow::saveFile(const QString& fileName) |
---|
178 | { |
---|
179 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
180 | bool result = m_pModel->saveFile(fileName); |
---|
181 | if (result) |
---|
182 | { |
---|
183 | setCurrentFile(fileName); |
---|
184 | statusBar()->showMessage(tr("File saved"), 2000); |
---|
185 | } |
---|
186 | QApplication::restoreOverrideCursor(); |
---|
187 | return result; |
---|
188 | } |
---|
189 | |
---|
190 | void QDesignViewWindow::on_actionFileNew_triggered() |
---|
191 | { |
---|
192 | m_pModel->newFile(); |
---|
193 | setCurrentFile(""); |
---|
194 | } |
---|
195 | |
---|
196 | void QDesignViewWindow::on_actionFileOpen_triggered() |
---|
197 | { |
---|
198 | QString fileName = QFileDialog::getOpenFileName( |
---|
199 | this, "Choose a file to open", QString(), "Projection setting files (*.xml)"); |
---|
200 | if (!fileName.isEmpty()) |
---|
201 | { |
---|
202 | loadFile(fileName); |
---|
203 | } |
---|
204 | } |
---|
205 | |
---|
206 | void QDesignViewWindow::on_actionFileSave_triggered() |
---|
207 | { |
---|
208 | if (m_fileName.isEmpty()) |
---|
209 | on_actionFileSaveAs_triggered(); |
---|
210 | else |
---|
211 | saveFile(m_fileName); |
---|
212 | } |
---|
213 | |
---|
214 | void QDesignViewWindow::on_actionFileSaveAs_triggered() |
---|
215 | { |
---|
216 | QString fileName = QFileDialog::getSaveFileName( |
---|
217 | this, "Choose a filename to save under", m_fileName, "Projection setting files (*.xml)"); |
---|
218 | if (!fileName.isEmpty()) |
---|
219 | { |
---|
220 | QFileInfo fileInfo(fileName); |
---|
221 | if (fileInfo.suffix().toLower() != "xml") { |
---|
222 | fileName = fileInfo.absolutePath() + "/" + fileInfo.baseName() + ".xml"; |
---|
223 | } |
---|
224 | saveFile(fileName); |
---|
225 | } |
---|
226 | } |
---|
227 | |
---|
228 | void QDesignViewWindow::on_actionFileExportDataset_triggered() |
---|
229 | { |
---|
230 | if (m_fileName.isEmpty()) { |
---|
231 | QMessageBox::warning(this, APPLICATION_NAME, |
---|
232 | tr("Save the current project before export data set.")); |
---|
233 | return; |
---|
234 | } |
---|
235 | |
---|
236 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
237 | m_pModel->getExporter()->exportDataset(m_fileName); |
---|
238 | QApplication::restoreOverrideCursor(); |
---|
239 | } |
---|
240 | |
---|
241 | void QDesignViewWindow::on_actionFileSyncClients_triggered() |
---|
242 | { |
---|
243 | m_pModel->getRSync()->sendReloadSettings(); |
---|
244 | } |
---|
245 | |
---|
246 | void QDesignViewWindow::on_actionFileExit_triggered() |
---|
247 | { |
---|
248 | m_pModel->getRSync()->sendChanges(RSYNC_COMMAND_DISCONNECT, "Disconnect"); |
---|
249 | close(); |
---|
250 | } |
---|
251 | |
---|
252 | void QDesignViewWindow::on_actionFileExitAll_triggered() |
---|
253 | { |
---|
254 | m_pModel->getRSync()->sendChanges(RSYNC_COMMAND_END, "End"); |
---|
255 | close(); |
---|
256 | } |
---|
257 | |
---|
258 | void QDesignViewWindow::on_actionEditDesignDistortionMap_triggered() |
---|
259 | { |
---|
260 | m_pModel->setDesignMode(DESIGN_MODE_DISTORTIONMAP); |
---|
261 | } |
---|
262 | |
---|
263 | void QDesignViewWindow::on_actionEditDesignBlendMap_triggered() |
---|
264 | { |
---|
265 | m_pModel->setDesignMode(DESIGN_MODE_BLENDMAP); |
---|
266 | } |
---|
267 | |
---|
268 | void QDesignViewWindow::on_actionEditPreference_triggered() |
---|
269 | { |
---|
270 | m_pModel->getGUI()->showPreferenceDialog(); |
---|
271 | } |
---|
272 | |
---|
273 | void QDesignViewWindow::on_actionViewPerspective_triggered() |
---|
274 | { |
---|
275 | ui.designViewWidget->setViewMode(DESIGN_VIEWMODE_PERSPECTIVE); |
---|
276 | } |
---|
277 | |
---|
278 | void QDesignViewWindow::on_actionViewCenter_triggered() |
---|
279 | { |
---|
280 | ui.designViewWidget->setViewMode(DESIGN_VIEWMODE_CENTER); |
---|
281 | } |
---|
282 | |
---|
283 | void QDesignViewWindow::on_actionViewTop_triggered() |
---|
284 | { |
---|
285 | ui.designViewWidget->setViewMode(DESIGN_VIEWMODE_TOP); |
---|
286 | } |
---|
287 | |
---|
288 | void QDesignViewWindow::on_actionViewSide_triggered() |
---|
289 | { |
---|
290 | ui.designViewWidget->setViewMode(DESIGN_VIEWMODE_SIDE); |
---|
291 | } |
---|
292 | |
---|
293 | void QDesignViewWindow::on_actionViewFront_triggered() |
---|
294 | { |
---|
295 | ui.designViewWidget->setViewMode(DESIGN_VIEWMODE_FRONT); |
---|
296 | } |
---|
297 | |
---|
298 | void QDesignViewWindow::on_menuEdit_aboutToShow() |
---|
299 | { |
---|
300 | ui.actionEditDesignDistortionMap->setChecked(m_pModel->getDesignMode() == DESIGN_MODE_DISTORTIONMAP); |
---|
301 | ui.actionEditDesignBlendMap->setChecked(m_pModel->getDesignMode() == DESIGN_MODE_BLENDMAP); |
---|
302 | } |
---|
303 | |
---|
304 | void QDesignViewWindow::on_menuView_aboutToShow() |
---|
305 | { |
---|
306 | ui.actionViewPerspective->setChecked(ui.designViewWidget->getViewMode()==DESIGN_VIEWMODE_PERSPECTIVE); |
---|
307 | ui.actionViewCenter->setChecked(ui.designViewWidget->getViewMode()==DESIGN_VIEWMODE_CENTER); |
---|
308 | ui.actionViewTop->setChecked(ui.designViewWidget->getViewMode()==DESIGN_VIEWMODE_TOP); |
---|
309 | ui.actionViewSide->setChecked(ui.designViewWidget->getViewMode()==DESIGN_VIEWMODE_SIDE); |
---|
310 | ui.actionViewFront->setChecked(ui.designViewWidget->getViewMode()==DESIGN_VIEWMODE_FRONT); |
---|
311 | } |
---|
312 | |
---|
313 | void QDesignViewWindow::on_actionViewAxis_triggered(bool checked) |
---|
314 | { |
---|
315 | ui.designViewWidget->setAxisVisible(checked); |
---|
316 | ui.designViewWidget->updateGL(); |
---|
317 | ui.actionViewAxis->setChecked(checked); |
---|
318 | } |
---|
319 | |
---|
320 | void QDesignViewWindow::on_designViewWidget_axisVisibilityChanged(bool bVisible) |
---|
321 | { |
---|
322 | ui.actionViewAxis->setChecked(bVisible); |
---|
323 | } |
---|
324 | |
---|
325 | void QDesignViewWindow::on_actionViewGrid_triggered(bool checked) |
---|
326 | { |
---|
327 | ui.designViewWidget->setGridVisible(checked); |
---|
328 | ui.designViewWidget->updateGL(); |
---|
329 | ui.actionViewGrid->setChecked(checked); |
---|
330 | } |
---|
331 | |
---|
332 | void QDesignViewWindow::on_designViewWidget_gridVisibilityChanged(bool bVisible) |
---|
333 | { |
---|
334 | ui.actionViewGrid->setChecked(bVisible); |
---|
335 | } |
---|
336 | |
---|
337 | void QDesignViewWindow::on_actionViewInfo_triggered(bool checked) |
---|
338 | { |
---|
339 | ui.designViewWidget->setInfoVisible(checked); |
---|
340 | ui.actionViewInfo->setChecked(checked); |
---|
341 | } |
---|
342 | |
---|
343 | void QDesignViewWindow::on_designViewWidget_infoVisibilityChanged(bool displayed) |
---|
344 | { |
---|
345 | ui.actionViewInfo->setChecked(displayed); |
---|
346 | } |
---|
347 | |
---|
348 | void QDesignViewWindow::on_actionViewViewAll_triggered() |
---|
349 | { |
---|
350 | ui.designViewWidget->viewAll(); |
---|
351 | } |
---|
352 | |
---|
353 | void QDesignViewWindow::on_actionWindowSceneViewer_triggered() |
---|
354 | { |
---|
355 | m_pModel->getGUI()->showSceneViewerWindow(); |
---|
356 | } |
---|
357 | |
---|
358 | void QDesignViewWindow::on_actionWindowSceneDialog_triggered() |
---|
359 | { |
---|
360 | ui.panelWidget->activateScene(); |
---|
361 | } |
---|
362 | |
---|
363 | void QDesignViewWindow::on_actionWindowScreenDialog_triggered() |
---|
364 | { |
---|
365 | ui.panelWidget->activateScreen(); |
---|
366 | } |
---|
367 | |
---|
368 | void QDesignViewWindow::on_actionWindowChannelManager_triggered() |
---|
369 | { |
---|
370 | ui.panelWidget->activateChannels(); |
---|
371 | } |
---|
372 | |
---|
373 | void QDesignViewWindow::on_actionHelpHelp_triggered() |
---|
374 | { |
---|
375 | } |
---|
376 | |
---|
377 | void QDesignViewWindow::on_actionHelpPlugins_triggered() |
---|
378 | { |
---|
379 | PluginDialog dialog(ProjectionModel::pluginsDir.path(), ProjectionModel::pluginFileNames, this); |
---|
380 | dialog.exec(); |
---|
381 | } |
---|
382 | |
---|
383 | void QDesignViewWindow::on_actionHelpAbout_triggered() |
---|
384 | { |
---|
385 | QMessageBox::about(this, "Information", |
---|
386 | "<h2>" APPLICATION_NAME "</h2><br>" |
---|
387 | "<nobr>version 1.0.99.Plugin by Toshiyuki Takahei, 2006</nobr><br>" |
---|
388 | "<nobr>version " APPLICATION_VERSION "<br>by Torben Dannhauer, 2009</nobr>"); |
---|
389 | } |
---|
390 | |
---|
391 | void QDesignViewWindow::on_actionHelpAbout_Qt_triggered() |
---|
392 | { |
---|
393 | QMessageBox::aboutQt(this); |
---|
394 | } |
---|
395 | |
---|
396 | void QDesignViewWindow::activateDesignView() |
---|
397 | { |
---|
398 | ui.designViewWidget->setFocus(); |
---|
399 | } |
---|
400 | |
---|
401 | void QDesignViewWindow::closeEvent(QCloseEvent* pEvent) |
---|
402 | { |
---|
403 | QMainWindow::closeEvent(pEvent); |
---|
404 | |
---|
405 | m_pModel->getGUI()->closeAllWindows(); |
---|
406 | } |
---|
407 | |
---|
408 | void QDesignViewWindow::initFromDOMElement(const QDomElement& element) |
---|
409 | { |
---|
410 | if (!element.isNull()) |
---|
411 | { |
---|
412 | if (!element.firstChildElement("DesignView").isNull()) |
---|
413 | ui.designViewWidget->initFromDOMElement(element.firstChildElement("DesignView")); |
---|
414 | } |
---|
415 | |
---|
416 | ui.actionViewAxis->setChecked(ui.designViewWidget->isAxisVisible()); |
---|
417 | ui.actionViewGrid->setChecked(ui.designViewWidget->isGridVisible()); |
---|
418 | ui.actionViewInfo->setChecked(ui.designViewWidget->isInfoVisible()); |
---|
419 | } |
---|
420 | |
---|
421 | QDomElement QDesignViewWindow::domElement(const QString& name, QDomDocument& doc) const |
---|
422 | { |
---|
423 | QDomElement de = doc.createElement(name); |
---|
424 | |
---|
425 | de.appendChild(ui.designViewWidget->domElement(doc)); |
---|
426 | |
---|
427 | return de; |
---|
428 | } |
---|