#include "ProjectionModel.h" #include "Scene.h" #include "Screen.h" #include "Channel.h" #include "RSync.h" #include "Exporter.h" #include "GUIControler.h" #include "gui/QDesignViewWindow.h" #include "plugindialog.h" #include #include #include using namespace projection; QDesignViewWindow::QDesignViewWindow(QWidget* pParent, Qt::WFlags flags) : QMainWindow(pParent, flags) { ui.setupUi(this); // initialize recent files list for (unsigned int i=0; isetVisible(false); connect(m_pRecentFileActs[i], SIGNAL(triggered()), this, SLOT(openRecentFile())); } m_pSeparatorAct = ui.menuFile->addSeparator(); m_pSeparatorAct->setVisible(false); for (unsigned int i=0; iaddAction(m_pRecentFileActs[i]); ui.menuFile->addSeparator(); ui.menuFile->addAction(ui.actionFileExit); ui.menuFile->addAction(ui.actionFileExitAll); updateRecentFileActions(); // initialize toggle actions ui.actionEditDesignDistortionMap->setCheckable(true); ui.actionEditDesignBlendMap->setCheckable(true); ui.actionEditDesignDistortionMap->setChecked(true); ui.actionViewPerspective->setCheckable(true); ui.actionViewCenter->setCheckable(true); ui.actionViewTop->setCheckable(true); ui.actionViewSide->setCheckable(true); ui.actionViewFront->setCheckable(true); ui.actionViewAxis->setCheckable(true); ui.actionViewGrid->setCheckable(true); ui.actionViewInfo->setCheckable(true); ui.actionViewAxis->setChecked(ui.designViewWidget->isAxisVisible()); ui.actionViewGrid->setChecked(ui.designViewWidget->isGridVisible()); ui.actionViewInfo->setChecked(ui.designViewWidget->isInfoVisible()); QShortcut* pShortcut = new QShortcut(this); pShortcut->setKey(Qt::Key_Escape); pShortcut->setContext(Qt::WindowShortcut); pShortcut->setEnabled(true); connect(pShortcut, SIGNAL(activated()), this, SLOT(activateDesignView())); statusBar(); ui.panelWidget->setMinimumWidth(240); QList sizes; sizes << width()-240 << 240; ui.splitter->setSizes(sizes); } QDesignViewWindow::~QDesignViewWindow() { } void QDesignViewWindow::setModel(ProjectionModel* pModel) { m_pModel = pModel; ui.designViewWidget->setModel(pModel); ui.panelWidget->setModel(pModel); if (m_pModel->getRSync()->isServer()) ui.actionFileSyncClients->setEnabled(true); else ui.actionFileSyncClients->setEnabled(false); setCurrentFile(""); } QGLWidget* QDesignViewWindow::getGLWidget() const { return ui.designViewWidget; } QDesignViewWidget* QDesignViewWindow::getDesignView() const { return ui.designViewWidget; } QPanelWidget* QDesignViewWindow::getPanel() const { return ui.panelWidget; } void QDesignViewWindow::setCurrentFile(const QString& fileName) { m_fileName = fileName; QString title; if (m_pModel->getRSync()->isServer()) title = QString(" : Server (%1:%2)").arg(m_pModel->getRSync()->getHostName()).arg(m_pModel->getRSync()->getPortNo()); else title = QString(" : Client (%1:%2)").arg(m_pModel->getRSync()->getServerAddress()).arg(m_pModel->getRSync()->getPortNo()); if (m_fileName.isEmpty()) setWindowTitle(tr(APPLICATION_NAME) + title); else setWindowTitle(tr("%1 - %2").arg(QFileInfo(m_fileName).fileName()).arg(APPLICATION_NAME) + title); if (!fileName.isEmpty()) { QSettings settings("Orihalcon", APPLICATION_NAME); QStringList files = settings.value("recentFileList").toStringList(); files.removeAll(m_fileName); files.prepend(m_fileName); while (files.size() > MAX_RECENT_FILES) files.removeLast(); settings.setValue("recentFileList", files); updateRecentFileActions(); } } void QDesignViewWindow::updateRecentFileActions() { QSettings settings("Orihalcon", APPLICATION_NAME); QStringList files = settings.value("recentFileList").toStringList(); int numRecentFiles = qMin(files.size(), (int)MAX_RECENT_FILES); for (int i=0; isetText(text); m_pRecentFileActs[i]->setData(files[i]); m_pRecentFileActs[i]->setVisible(true); } for (int j=numRecentFiles; jsetVisible(false); m_pSeparatorAct->setVisible(numRecentFiles > 0); } void QDesignViewWindow::openRecentFile() { QAction* pAction = qobject_cast(sender()); if (pAction) loadFile(pAction->data().toString()); } bool QDesignViewWindow::loadFile(const QString& fileName) { QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); bool result = m_pModel->loadFile(fileName); if (result) { setCurrentFile(fileName); statusBar()->showMessage(tr("File loaded"), 2000); } else { QMessageBox::critical( this, "Could not load File", "An Error occured while parsing the project file.
It's impossible to continue, so starting an new empty project."); on_actionFileNew_triggered(); } QApplication::restoreOverrideCursor(); return result; } bool QDesignViewWindow::saveFile(const QString& fileName) { QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); bool result = m_pModel->saveFile(fileName); if (result) { setCurrentFile(fileName); statusBar()->showMessage(tr("File saved"), 2000); } QApplication::restoreOverrideCursor(); return result; } void QDesignViewWindow::on_actionFileNew_triggered() { m_pModel->newFile(); setCurrentFile(""); } void QDesignViewWindow::on_actionFileOpen_triggered() { QString fileName = QFileDialog::getOpenFileName( this, "Choose a file to open", QString(), "Projection setting files (*.xml)"); if (!fileName.isEmpty()) { loadFile(fileName); } } void QDesignViewWindow::on_actionFileSave_triggered() { if (m_fileName.isEmpty()) on_actionFileSaveAs_triggered(); else saveFile(m_fileName); } void QDesignViewWindow::on_actionFileSaveAs_triggered() { QString fileName = QFileDialog::getSaveFileName( this, "Choose a filename to save under", m_fileName, "Projection setting files (*.xml)"); if (!fileName.isEmpty()) { QFileInfo fileInfo(fileName); if (fileInfo.suffix().toLower() != "xml") { fileName = fileInfo.absolutePath() + "/" + fileInfo.baseName() + ".xml"; } saveFile(fileName); } } void QDesignViewWindow::on_actionFileExportDataset_triggered() { if (m_fileName.isEmpty()) { QMessageBox::warning(this, APPLICATION_NAME, tr("Save the current project before export data set.")); return; } QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); m_pModel->getExporter()->exportDataset(m_fileName); QApplication::restoreOverrideCursor(); } void QDesignViewWindow::on_actionFileSyncClients_triggered() { m_pModel->getRSync()->sendReloadSettings(); } void QDesignViewWindow::on_actionFileExit_triggered() { m_pModel->getRSync()->sendChanges(RSYNC_COMMAND_DISCONNECT, "Disconnect"); close(); } void QDesignViewWindow::on_actionFileExitAll_triggered() { m_pModel->getRSync()->sendChanges(RSYNC_COMMAND_END, "End"); close(); } void QDesignViewWindow::on_actionEditDesignDistortionMap_triggered() { m_pModel->setDesignMode(DESIGN_MODE_DISTORTIONMAP); } void QDesignViewWindow::on_actionEditDesignBlendMap_triggered() { m_pModel->setDesignMode(DESIGN_MODE_BLENDMAP); } void QDesignViewWindow::on_actionEditPreference_triggered() { m_pModel->getGUI()->showPreferenceDialog(); } void QDesignViewWindow::on_actionViewPerspective_triggered() { ui.designViewWidget->setViewMode(DESIGN_VIEWMODE_PERSPECTIVE); } void QDesignViewWindow::on_actionViewCenter_triggered() { ui.designViewWidget->setViewMode(DESIGN_VIEWMODE_CENTER); } void QDesignViewWindow::on_actionViewTop_triggered() { ui.designViewWidget->setViewMode(DESIGN_VIEWMODE_TOP); } void QDesignViewWindow::on_actionViewSide_triggered() { ui.designViewWidget->setViewMode(DESIGN_VIEWMODE_SIDE); } void QDesignViewWindow::on_actionViewFront_triggered() { ui.designViewWidget->setViewMode(DESIGN_VIEWMODE_FRONT); } void QDesignViewWindow::on_menuEdit_aboutToShow() { ui.actionEditDesignDistortionMap->setChecked(m_pModel->getDesignMode() == DESIGN_MODE_DISTORTIONMAP); ui.actionEditDesignBlendMap->setChecked(m_pModel->getDesignMode() == DESIGN_MODE_BLENDMAP); } void QDesignViewWindow::on_menuView_aboutToShow() { ui.actionViewPerspective->setChecked(ui.designViewWidget->getViewMode()==DESIGN_VIEWMODE_PERSPECTIVE); ui.actionViewCenter->setChecked(ui.designViewWidget->getViewMode()==DESIGN_VIEWMODE_CENTER); ui.actionViewTop->setChecked(ui.designViewWidget->getViewMode()==DESIGN_VIEWMODE_TOP); ui.actionViewSide->setChecked(ui.designViewWidget->getViewMode()==DESIGN_VIEWMODE_SIDE); ui.actionViewFront->setChecked(ui.designViewWidget->getViewMode()==DESIGN_VIEWMODE_FRONT); } void QDesignViewWindow::on_actionViewAxis_triggered(bool checked) { ui.designViewWidget->setAxisVisible(checked); ui.designViewWidget->updateGL(); ui.actionViewAxis->setChecked(checked); } void QDesignViewWindow::on_designViewWidget_axisVisibilityChanged(bool bVisible) { ui.actionViewAxis->setChecked(bVisible); } void QDesignViewWindow::on_actionViewGrid_triggered(bool checked) { ui.designViewWidget->setGridVisible(checked); ui.designViewWidget->updateGL(); ui.actionViewGrid->setChecked(checked); } void QDesignViewWindow::on_designViewWidget_gridVisibilityChanged(bool bVisible) { ui.actionViewGrid->setChecked(bVisible); } void QDesignViewWindow::on_actionViewInfo_triggered(bool checked) { ui.designViewWidget->setInfoVisible(checked); ui.actionViewInfo->setChecked(checked); } void QDesignViewWindow::on_designViewWidget_infoVisibilityChanged(bool displayed) { ui.actionViewInfo->setChecked(displayed); } void QDesignViewWindow::on_actionViewViewAll_triggered() { ui.designViewWidget->viewAll(); } void QDesignViewWindow::on_actionWindowSceneViewer_triggered() { m_pModel->getGUI()->showSceneViewerWindow(); } void QDesignViewWindow::on_actionWindowSceneDialog_triggered() { ui.panelWidget->activateScene(); } void QDesignViewWindow::on_actionWindowScreenDialog_triggered() { ui.panelWidget->activateScreen(); } void QDesignViewWindow::on_actionWindowChannelManager_triggered() { ui.panelWidget->activateChannels(); } void QDesignViewWindow::on_actionHelpHelp_triggered() { } void QDesignViewWindow::on_actionHelpPlugins_triggered() { PluginDialog dialog(ProjectionModel::pluginsDir.path(), ProjectionModel::pluginFileNames, this); dialog.exec(); } void QDesignViewWindow::on_actionHelpAbout_triggered() { QMessageBox::about(this, "Information", "

" APPLICATION_NAME "


" "version 1.0.99.Plugin by Toshiyuki Takahei, 2006
" "version " APPLICATION_VERSION "
by Torben Dannhauer, 2009
"); } void QDesignViewWindow::on_actionHelpAbout_Qt_triggered() { QMessageBox::aboutQt(this); } void QDesignViewWindow::activateDesignView() { ui.designViewWidget->setFocus(); } void QDesignViewWindow::closeEvent(QCloseEvent* pEvent) { QMainWindow::closeEvent(pEvent); m_pModel->getGUI()->closeAllWindows(); } void QDesignViewWindow::initFromDOMElement(const QDomElement& element) { if (!element.isNull()) { if (!element.firstChildElement("DesignView").isNull()) ui.designViewWidget->initFromDOMElement(element.firstChildElement("DesignView")); } ui.actionViewAxis->setChecked(ui.designViewWidget->isAxisVisible()); ui.actionViewGrid->setChecked(ui.designViewWidget->isGridVisible()); ui.actionViewInfo->setChecked(ui.designViewWidget->isInfoVisible()); } QDomElement QDesignViewWindow::domElement(const QString& name, QDomDocument& doc) const { QDomElement de = doc.createElement(name); de.appendChild(ui.designViewWidget->domElement(doc)); return de; }