From 04f2abd00e9fea2300cc48edac2a28ea74373cb7 Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Thu, 3 Nov 2011 23:35:00 +0000 Subject: [PATCH] Add Support for FullScreen on Linux/Windows Add support to toggle full screen mode on Linux and Windows, in similar fashion to the recent update for Mac OSX Lion. A new view menu option to toggle full screen has been added in lieu of the Mac titlebar icon on either Win/Linux. Additionally, hitting Function key F11 toggles fullscreen and hitting ESC whilst in full screen also returns to normal. --- src/MainWindow.cpp | 17 ++++++++++++- src/MainWindow.h | 8 ++++++ src/QTFullScreen.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++ src/QTFullScreen.h | 48 +++++++++++++++++++++++++++++++++++ src/src.pro | 5 ++++ 5 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 src/QTFullScreen.cpp create mode 100644 src/QTFullScreen.h diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 37dfbd923..ee242d82c 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -76,6 +76,9 @@ #if (defined Q_OS_MAC) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7) #include "LionFullScreen.h" #endif +#ifndef Q_OS_MAC +#include "QTFullScreen.h" +#endif #include #include @@ -130,6 +133,9 @@ MainWindow::MainWindow(const QDir &home) : #if (defined Q_OS_MAC) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7) fullScreen = new LionFullScreen(this); #endif +#ifndef Q_OS_MAC + fullScreen = new QTFullScreen(this); +#endif /*---------------------------------------------------------------------- * The help bubble used everywhere @@ -526,6 +532,9 @@ MainWindow::MainWindow(const QDir &home) : } QMenu *viewMenu = menuBar()->addMenu(tr("&View")); +#ifndef Q_OS_MAC + viewMenu->addAction(tr("Toggle Full Screen"), this, SLOT(toggleFullScreen())); +#endif QAction *showhideSidebar = viewMenu->addAction(tr("Show Sidebar"), this, SLOT(showSidebar(bool))); showhideSidebar->setCheckable(true); showhideSidebar->setChecked(true); @@ -535,7 +544,6 @@ MainWindow::MainWindow(const QDir &home) : showhideToolbar->setCheckable(true); showhideToolbar->setChecked(true); //connect(showhideSidebar, SIGNAL(triggered(bool)), this, SLOT(showSidebar(bool))); - viewMenu->addSeparator(); viewMenu->addAction(tr("Analysis"), this, SLOT(selectAnalysis())); viewMenu->addAction(tr("Home"), this, SLOT(selectHome())); @@ -621,6 +629,13 @@ MainWindow::selectWindow(QAction *act) } } +#ifndef Q_OS_MAC +void +MainWindow::toggleFullScreen() +{ + fullScreen->toggle(); +} +#endif void MainWindow::rideTreeWidgetSelectionChanged() { diff --git a/src/MainWindow.h b/src/MainWindow.h index 9254d4c6e..f05cd2007 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -57,6 +57,7 @@ class RideNavigator; class GcToolBar; class GcBubble; class LionFullScreen; +class QTFullScreen; extern QList mainwindows; // keep track of all the MainWindows we have open @@ -135,6 +136,9 @@ class MainWindow : public QMainWindow #if (defined Q_OS_MAC) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7) LionFullScreen *fullScreen; #endif +#ifndef Q_OS_MAC + QTFullScreen *fullScreen; +#endif // ********************************************* // APPLICATION EVENTS @@ -273,6 +277,10 @@ class MainWindow : public QMainWindow void selectWindow(QAction*); void showDock(); +#ifndef Q_OS_MAC + void toggleFullScreen(); +#endif + protected: static QString notesFileName(QString rideFileName); diff --git a/src/QTFullScreen.cpp b/src/QTFullScreen.cpp new file mode 100644 index 000000000..41201399f --- /dev/null +++ b/src/QTFullScreen.cpp @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2011 Mark Liversedge (liversedge@gmail.com) +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the Free +* Software Foundation; either version 2 of the License, or (at your option) +* any later version. +* +* This program is distributed in the hope that it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., 51 +* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "QTFullScreen.h" + +QTFullScreen::QTFullScreen(MainWindow *main) : QObject(main), main(main), isFull(false) +{ + // watch for ESC key being hit when in full screen + main->installEventFilter(this); +} + +bool +QTFullScreen::eventFilter(QObject *obj, QEvent *event) +{ + if (obj != main) return false; + + // F11 toggle full screen + if (event->type() == QEvent::KeyPress && static_cast(event)->key() == Qt::Key_F11) { + toggle(); + } + + // ESC cancels fullscreen + if (event->type() == QEvent::KeyPress && static_cast(event)->key() == Qt::Key_Escape) { + + // if in full screen then toggle, otherwise do nothing + if (isFull) { + main->showNormal(); + isFull = false; + } + return false; + } + return false; // always pass thru, just in case +} + + +void +QTFullScreen::toggle() +{ + if (isFull) { + main->showNormal(); + } else { + main->showFullScreen(); + } + isFull = !isFull; +} diff --git a/src/QTFullScreen.h b/src/QTFullScreen.h new file mode 100644 index 000000000..0951fe9af --- /dev/null +++ b/src/QTFullScreen.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2011 Mark Liversedge (liversedge@gmail.com) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +#ifndef _GC_QTFullScreen_h +#define _GC_QTFullScreen_h 1 + +#include "GoldenCheetah.h" + +// QT stuff etc +#include +#include "MainWindow.h" + +class QTFullScreen : public QObject +{ + Q_OBJECT; + + public: + + QTFullScreen(MainWindow *main); + + // found in the supplied directory + void toggle(); + + public slots: + bool eventFilter(QObject *obj, QEvent *event); + + private: + MainWindow *main; + bool isFull; +}; + +#endif // _GC_QTFullScreen_h diff --git a/src/src.pro b/src/src.pro index 8c2a91534..829359dea 100644 --- a/src/src.pro +++ b/src/src.pro @@ -127,6 +127,11 @@ macx { LIBS += -lobjc -framework Carbon -framework IOKit -framework AppKit -framework QTKit HEADERS += QtMacSegmentedButton.h QtMacVideoWindow.h LionFullScreen.h SOURCES += QtMacSegmentedButton.mm QtMacVideoWindow.mm LionFullScreen.mm +} else { + # not a mac? then F12 to toggle full screen using + # standard QT showFullScreen / showNormal + HEADERS += QTFullScreen.h + SOURCES += QTFullScreen.cpp } !win32 {