source: projectionDesigner/trunk/projdesigner/src/gui/QDesignViewWindow.cpp @ 414

Last change on this file since 414 was 4, checked in by Torben Dannhauer, 15 years ago
File size: 12.4 KB
RevLine 
[4]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
17using namespace projection;
18
19QDesignViewWindow::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
73QDesignViewWindow::~QDesignViewWindow()
74{
75}
76
77void 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
90QGLWidget* QDesignViewWindow::getGLWidget() const
91{
92        return ui.designViewWidget;
93}
94
95QDesignViewWidget* QDesignViewWindow::getDesignView() const
96{
97    return ui.designViewWidget;
98}
99
100QPanelWidget* QDesignViewWindow::getPanel() const
101{
102    return ui.panelWidget;
103}
104
105void 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
133void 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
152void QDesignViewWindow::openRecentFile()
153{
154    QAction* pAction = qobject_cast<QAction *>(sender());
155    if (pAction)
156        loadFile(pAction->data().toString());
157}
158
159bool 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
177bool 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
190void QDesignViewWindow::on_actionFileNew_triggered()
191{
192    m_pModel->newFile();
193    setCurrentFile("");
194}
195
196void 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
206void QDesignViewWindow::on_actionFileSave_triggered()
207{
208    if (m_fileName.isEmpty())
209        on_actionFileSaveAs_triggered();
210    else
211        saveFile(m_fileName);
212}
213
214void 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
228void 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
241void QDesignViewWindow::on_actionFileSyncClients_triggered()
242{
243    m_pModel->getRSync()->sendReloadSettings();
244}
245
246void QDesignViewWindow::on_actionFileExit_triggered()
247{
248    m_pModel->getRSync()->sendChanges(RSYNC_COMMAND_DISCONNECT, "Disconnect");
249        close();
250}
251
252void QDesignViewWindow::on_actionFileExitAll_triggered()
253{
254    m_pModel->getRSync()->sendChanges(RSYNC_COMMAND_END, "End");
255        close();
256}
257
258void QDesignViewWindow::on_actionEditDesignDistortionMap_triggered()
259{
260    m_pModel->setDesignMode(DESIGN_MODE_DISTORTIONMAP);
261}
262
263void QDesignViewWindow::on_actionEditDesignBlendMap_triggered()
264{
265    m_pModel->setDesignMode(DESIGN_MODE_BLENDMAP);
266}
267
268void QDesignViewWindow::on_actionEditPreference_triggered()
269{
270    m_pModel->getGUI()->showPreferenceDialog();
271}
272
273void QDesignViewWindow::on_actionViewPerspective_triggered()
274{
275    ui.designViewWidget->setViewMode(DESIGN_VIEWMODE_PERSPECTIVE);
276}
277
278void QDesignViewWindow::on_actionViewCenter_triggered()
279{
280    ui.designViewWidget->setViewMode(DESIGN_VIEWMODE_CENTER);
281}
282
283void QDesignViewWindow::on_actionViewTop_triggered()
284{
285    ui.designViewWidget->setViewMode(DESIGN_VIEWMODE_TOP);
286}
287
288void QDesignViewWindow::on_actionViewSide_triggered()
289{
290    ui.designViewWidget->setViewMode(DESIGN_VIEWMODE_SIDE);
291}
292
293void QDesignViewWindow::on_actionViewFront_triggered()
294{
295    ui.designViewWidget->setViewMode(DESIGN_VIEWMODE_FRONT);
296}
297
298void 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
304void 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
313void QDesignViewWindow::on_actionViewAxis_triggered(bool checked)
314{
315        ui.designViewWidget->setAxisVisible(checked);
316    ui.designViewWidget->updateGL();
317        ui.actionViewAxis->setChecked(checked);
318}
319
320void QDesignViewWindow::on_designViewWidget_axisVisibilityChanged(bool bVisible)
321{
322        ui.actionViewAxis->setChecked(bVisible);
323}
324
325void QDesignViewWindow::on_actionViewGrid_triggered(bool checked)
326{
327        ui.designViewWidget->setGridVisible(checked);
328    ui.designViewWidget->updateGL();
329        ui.actionViewGrid->setChecked(checked);
330}
331
332void QDesignViewWindow::on_designViewWidget_gridVisibilityChanged(bool bVisible)
333{
334        ui.actionViewGrid->setChecked(bVisible);
335}
336
337void QDesignViewWindow::on_actionViewInfo_triggered(bool checked)
338{
339        ui.designViewWidget->setInfoVisible(checked);
340        ui.actionViewInfo->setChecked(checked);
341}
342
343void QDesignViewWindow::on_designViewWidget_infoVisibilityChanged(bool displayed)
344{
345        ui.actionViewInfo->setChecked(displayed);
346}
347
348void QDesignViewWindow::on_actionViewViewAll_triggered()
349{
350        ui.designViewWidget->viewAll();
351}
352
353void QDesignViewWindow::on_actionWindowSceneViewer_triggered()
354{
355        m_pModel->getGUI()->showSceneViewerWindow();
356}
357
358void QDesignViewWindow::on_actionWindowSceneDialog_triggered()
359{
360    ui.panelWidget->activateScene();
361}
362
363void QDesignViewWindow::on_actionWindowScreenDialog_triggered()
364{
365    ui.panelWidget->activateScreen();
366}
367
368void QDesignViewWindow::on_actionWindowChannelManager_triggered()
369{
370    ui.panelWidget->activateChannels();
371}
372
373void QDesignViewWindow::on_actionHelpHelp_triggered()
374{
375}
376
377void QDesignViewWindow::on_actionHelpPlugins_triggered()
378{
379                PluginDialog dialog(ProjectionModel::pluginsDir.path(), ProjectionModel::pluginFileNames, this);
380    dialog.exec();
381}
382
383void 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
391void QDesignViewWindow::on_actionHelpAbout_Qt_triggered()
392{
393        QMessageBox::aboutQt(this);
394}
395
396void QDesignViewWindow::activateDesignView()
397{
398    ui.designViewWidget->setFocus();
399}
400
401void QDesignViewWindow::closeEvent(QCloseEvent* pEvent)
402{
403    QMainWindow::closeEvent(pEvent);
404
405    m_pModel->getGUI()->closeAllWindows();
406}
407
408void 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
421QDomElement 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}
Note: See TracBrowser for help on using the repository browser.