diff --git a/MainWindow.cpp b/MainWindow.cpp index 6eb8860..4fbb4f3 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -776,6 +776,33 @@ void MainWindow::paintListEditEnd(QWidget *editor) renamePaint(getItemId(*paintList->currentItem()), name); } +void MainWindow::setupOutputScreen() +{ + QAction *actionSender = qobject_cast(sender()); + + if (actionSender) + outputWindow->setPreferredScreen(actionSender->data().toInt()); + // If want that the changes take effect immediatelly + // when the output is in fullscreen mode + if (outputFullScreenAction->isChecked()) { + // XXX: Close and reopen // It's not the best way to do + outputFullScreenAction->toggle(); + outputFullScreenAction->trigger(); + } +} + +void MainWindow::updateScreenCount() +{ + // Clear action list before + if (!screenActions.isEmpty()) + screenActions.clear(); + // Refresh screen action + updateScreenActions(); + // Update Output menu + outputMenu->clear(); + addOutputMenuActions(); +} + void MainWindow::openRecentFile() { QAction *action = qobject_cast(sender()); @@ -1643,9 +1670,7 @@ void MainWindow::createActions() addAction(outputFullScreenAction); // Manage fullscreen/modal show of GL output window. connect(outputFullScreenAction, SIGNAL(toggled(bool)), outputWindow, SLOT(setFullScreen(bool))); - // When closing the GL output window or hit ESC key, uncheck the action in menu. -// connect(outputWindow, SIGNAL(closed()), outputFullScreenAction, SLOT(toggle())); - connect(QApplication::desktop(), SIGNAL(screenCountChanged(int)), outputWindow, SLOT(updateScreenCount(int))); + connect(QApplication::desktop(), SIGNAL(screenCountChanged(int)), this, SLOT(updateScreenCount())); // Create hiden action for closing output window QAction *closeOutput = new QAction(this); closeOutput->setShortcut(Qt::Key_Escape); @@ -1770,6 +1795,8 @@ void MainWindow::createActions() docAction = new QAction(tr("Documentation"), this); connect(docAction, SIGNAL(triggered()), this, SLOT(documentation())); + // All available screen as action + updateScreenActions(); } void MainWindow::startFullScreen() @@ -1842,10 +1869,7 @@ void MainWindow::createMenus() // Preferences editMenu->addAction(preferencesAction); - // View. - //viewMenu = menuBar->addMenu(tr("&View")); - - // Run. + // Playback. playbackMenu = menuBar->addMenu(tr("&Playback")); playbackMenu->addAction(playAction); playbackMenu->addAction(pauseAction); @@ -1854,10 +1878,8 @@ void MainWindow::createMenus() // Output outputMenu = menuBar->addMenu(tr("&Output")); - outputMenu->addAction(outputFullScreenAction); - outputMenu->addSeparator(); - outputMenu->addAction(displayTestSignalAction); - outputMenu->addAction(displayControlsAction); + // Add actions + addOutputMenuActions(); // Tools toolsMenu = menuBar->addMenu(tr("&Tools")); @@ -1874,7 +1896,6 @@ void MainWindow::createMenus() #ifdef Q_OS_WIN toolBarsMenu->addAction(showMenuBarAction); #endif - windowMenu->addSeparator(); windowMenu->addAction(displayUndoStackAction); windowMenu->addAction(displayZoomToolAction); windowMenu->addSeparator(); @@ -2253,6 +2274,43 @@ void MainWindow::updateRecentVideoActions() } } +void MainWindow:: updateScreenActions() +{ + // Add new action for each screen + foreach (QScreen *screen, QApplication::screens()) { + QString actionLabel = tr("%1 - %2x%3") + .arg(screen->name()) + .arg(QString::number(screen->size().width())) + .arg(QString::number(screen->size().height())); + if (screen == QApplication::primaryScreen()) + actionLabel.append(" - Primary"); + QAction *action = new QAction(actionLabel, this); + screenActions.append(action); + action->setData(screenActions.count() - 1); + } + + // Configure actions + screenActionGroup = new QActionGroup(this); + int preferredScreen = outputWindow->getPreferredScreen(); + foreach (QAction *action, screenActions) { + action->setCheckable(true); + if (action == screenActions.at(preferredScreen)) + action->setChecked(true); + + connect(action, SIGNAL(triggered()), this, SLOT(setupOutputScreen())); + screenActionGroup->addAction(action); + } +} + +void MainWindow::addOutputMenuActions() +{ + outputMenu->addAction(outputFullScreenAction); + outputMenu->addActions(screenActions); + outputMenu->addSeparator(); + outputMenu->addAction(displayTestSignalAction); + outputMenu->addAction(displayControlsAction); +} + void MainWindow::clearRecentFileList() { recentFiles = settings.value("recentFiles").toStringList(); diff --git a/MainWindow.h b/MainWindow.h index 4ab72a2..0a71492 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -109,6 +109,9 @@ private slots: void deletePaintItem(); void renamePaintItem(); void paintListEditEnd(QWidget* editor); + // Output menu + void setupOutputScreen(); + void updateScreenCount(); // Widget callbacks. void handlePaintItemSelectionChanged(); @@ -250,6 +253,8 @@ private: void createStatusBar(); void updateRecentFileActions(); void updateRecentVideoActions(); + void updateScreenActions(); + void addOutputMenuActions(); // Settings. void readSettings(); @@ -386,6 +391,10 @@ private: QAction *supportAction; QAction *docAction; + // Screen output action + QList screenActions; + QActionGroup *screenActionGroup; + // Widgets and layout. QTabWidget* contentTab; diff --git a/OutputGLWindow.cpp b/OutputGLWindow.cpp index 89389e0..3f6347f 100644 --- a/OutputGLWindow.cpp +++ b/OutputGLWindow.cpp @@ -40,6 +40,7 @@ OutputGLWindow:: OutputGLWindow(QWidget* parent, const MapperGLCanvas* canvas_) setDisplayCrosshair(false); // default this->_is_fullscreen = false; + _preferredScreen = QApplication::screens().size() - 1; } //OutputGLWindow::OutputGLWindow(MainWindow* mainWindow, QWidget* parent, const QGLWidget * shareWidget) : QDialog(parent) @@ -83,17 +84,10 @@ void OutputGLWindow::setFullScreen(bool fullscreen) this->_is_fullscreen = fullscreen; } -void OutputGLWindow::updateScreenCount(int nScreens) -{ - Q_UNUSED(nScreens); - // Untested. - _updateToPreferredScreen(); -} - void OutputGLWindow::_updateToPreferredScreen() { // Check if user is on multiple screen (always pre - int screen = _getPreferredScreen(); + int screen = _preferredScreen; //Move window to second screen before fullscreening it. setGeometry(QApplication::desktop()->screenGeometry(screen)); } @@ -111,5 +105,13 @@ void OutputGLWindow::setDisplayTestSignal(bool displayTestSignal) canvas->update(); } +void OutputGLWindow::setPreferredScreen(int screen) +{ + if (screen < QApplication::screens().size()) + _preferredScreen = screen; + else + _preferredScreen = QApplication::screens().size() - 1; +} + MM_END_NAMESPACE diff --git a/OutputGLWindow.h b/OutputGLWindow.h index 7cc37da..19c594f 100644 --- a/OutputGLWindow.h +++ b/OutputGLWindow.h @@ -46,7 +46,6 @@ public: public slots: void setFullScreen(bool fullScreen); - void updateScreenCount(int nScreens); void setDisplayCrosshair(bool crosshair); void setDisplayTestSignal(bool displayTestSignal); @@ -57,14 +56,15 @@ public: MapperGLCanvas* getCanvas() const { return canvas; } void setPointerHasMoved(); + int getPreferredScreen() const { return _preferredScreen; } + void setPreferredScreen(int screen); + private: OutputGLCanvas* canvas; - int _getPreferredScreen() const { - return QApplication::desktop()->screenCount()-1; - } void _updateToPreferredScreen(); bool _is_fullscreen; + int _preferredScreen; }; MM_END_NAMESPACE