diff --git a/MainWindow.cpp b/MainWindow.cpp index 7adfa97..89394f0 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -777,7 +777,7 @@ void MainWindow::createLayout() destinationCanvas->setMinimumSize(CANVAS_MINIMUM_WIDTH, CANVAS_MINIMUM_HEIGHT); outputWindow = new OutputGLWindow(this, this, sourceCanvas); - outputWindow->mySetVisible(true); + outputWindow->setVisible(true); // Source changed -> change destination connect(sourceCanvas, SIGNAL(shapeChanged(Shape*)), @@ -944,10 +944,22 @@ void MainWindow::createActions() displayOutputWindow->setCheckable(true); displayOutputWindow->setChecked(true); // Manage show/hide of GL output window. - connect(displayOutputWindow, SIGNAL(toggled(bool)), outputWindow, SLOT(mySetVisible(bool))); + connect(displayOutputWindow, SIGNAL(toggled(bool)), outputWindow, SLOT(setVisible(bool))); // When closing the GL output window, uncheck the action in menu. connect(outputWindow, SIGNAL(closed()), displayOutputWindow, SLOT(toggle())); + // Toggle display of output window. + outputWindowFullScreen = new QAction(tr("&Full screen"), this); + outputWindowFullScreen->setShortcut(tr("Ctrl+F")); + outputWindowFullScreen->setStatusTip(tr("Full screen")); + outputWindowFullScreen->setCheckable(true); + outputWindowFullScreen->setChecked(false); + // Manage fullscreen mode for output window. +// connect(outputWindowFullScreen, SIGNAL(toggled(bool)), outputWindow, SLOT(showFullScreen())); +// connect(outputWindowFullScreen, SIGNAL(toggled(bool)), this, SLOT(outputFullScreen(bool))); + connect(outputWindowFullScreen, SIGNAL(toggled(bool)), outputWindow, SLOT(setFullScreen(bool))); + // When closing the GL output window, uncheck the action in menu. + connect(outputWindow, SIGNAL(fullScreenToggled(bool)), outputWindowFullScreen, SLOT(setChecked(bool))); // Toggle display of canvas controls. displayCanvasControls = new QAction(tr("&Display canvas controls"), this); // displayCanvasControls->setShortcut(tr("Ctrl+E")); @@ -984,6 +996,7 @@ void MainWindow::createMenus() // View. viewMenu = menuBar()->addMenu(tr("&View")); viewMenu->addAction(displayOutputWindow); + viewMenu->addAction(outputWindowFullScreen); viewMenu->addAction(displayCanvasControls); // selectSubMenu = editMenu->addMenu(tr("&Select")); diff --git a/MainWindow.h b/MainWindow.h index 3044a24..d3ec21a 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -228,6 +228,7 @@ private: QAction *addEllipseAction; QAction *displayOutputWindow; + QAction *outputWindowFullScreen; QAction *displayCanvasControls; // Widgets and layout. diff --git a/OutputGLWindow.cpp b/OutputGLWindow.cpp index a2347c6..279e819 100644 --- a/OutputGLWindow.cpp +++ b/OutputGLWindow.cpp @@ -33,6 +33,9 @@ OutputGLWindow::OutputGLWindow(MainWindow* mainWindow, QWidget* parent, const QG layout->setContentsMargins(0,0,0,0); // remove margin layout->addWidget(canvas); setLayout(layout); + + // Save window geometry. + _geometry = saveGeometry(); } void OutputGLWindow::closeEvent(QCloseEvent *event) @@ -41,28 +44,65 @@ void OutputGLWindow::closeEvent(QCloseEvent *event) event->accept(); } -void OutputGLWindow::fullscreen(bool is_fullscreen) +void OutputGLWindow::keyPressEvent(QKeyEvent *event) { - if (is_fullscreen) - { - this->showFullScreen(); - } - else - { - this->showNormal(); - } + // Escape from full screen mode. + if (isFullScreen() && event->key() == Qt::Key_Escape) + { + setFullScreen(false); + emit fullScreenToggled(false); + } + else + QDialog::keyPressEvent(event); } -void OutputGLWindow::mySetVisible(bool value) -{ - this->setVisible(value); - if (value) - { - this->fullscreen(value); - } -} -//void OutputGLWindow::updateCanvas() { -// qDebug() << "Update output canvas" << endl; -// canvas->updateCanvas(); -//} +void OutputGLWindow::setFullScreen(bool fullscreen) +{ + // NOTE: The showFullScreen() method does not work well under Ubuntu Linux. The code below fixes the issue. + // Notice that there might be problems with the fullscreen in other OS / window managers. If so, please add + // the code to fix those issues here. + // See: http://qt-project.org/doc/qt-4.8/qwidget.html#showFullScreen + // Source: http://stackoverflow.com/questions/12645880/fullscreen-for-qdialog-from-within-mainwindow-only-working-sometimes +#ifdef Q_OS_UNIX + const QString session = QString(getenv("DESKTOP_SESSION")).toLower(); +#endif + if (fullscreen) + { + // Save window geometry. + _geometry = saveGeometry(); + + // Move window to second screen before fullscreening it. + if (QApplication::desktop()->screenCount() > 1) + setGeometry(QApplication::desktop()->screenGeometry(1)); + +#ifdef Q_OS_UNIX + // Special case for Unity. + if (session == "ubuntu") { + setWindowState( windowState() | Qt::WindowFullScreen | Qt::WindowMaximized); + setWindowFlags(Qt::Dialog); + show(); + } else { + showFullScreen(); + } +#else + showFullScreen(); +#endif + } + else + { + // Restore geometry of window to what it was before full screen call. + restoreGeometry(_geometry); + +#ifdef Q_OS_UNIX + // Special case for Unity. + if (session == "ubuntu") { + setWindowState( windowState() & ~Qt::WindowFullScreen); + } else { + showNormal(); + } +#else + showNormal(); +#endif + } +} diff --git a/OutputGLWindow.h b/OutputGLWindow.h index 0c60884..8c85572 100644 --- a/OutputGLWindow.h +++ b/OutputGLWindow.h @@ -21,6 +21,7 @@ #define OUTPUTGLWINDOW_H_ #include +#include #include "DestinationGLCanvas.h" // TODO: add SLOT for mySetVisible @@ -34,20 +35,22 @@ public: OutputGLWindow(MainWindow* mainWindow, QWidget* parent = 0, const QGLWidget * shareWidget = 0); public slots: - void fullscreen(bool is_fullscreen); - void mySetVisible(bool value); + void setFullScreen(bool fullScreen); protected: void closeEvent(QCloseEvent* event); + void keyPressEvent(QKeyEvent *event); signals: void closed(); + void fullScreenToggled(bool fullScreen); public: DestinationGLCanvas* getCanvas() const { return canvas; } private: DestinationGLCanvas* canvas; + QByteArray _geometry; }; #endif /* OutputGLWINDOW_H_ */