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.
This commit is contained in:
Mark Liversedge
2011-11-03 23:35:00 +00:00
parent 0a67ed1e01
commit 04f2abd00e
5 changed files with 137 additions and 1 deletions

View File

@@ -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 <assert.h>
#include <QApplication>
@@ -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()
{

View File

@@ -57,6 +57,7 @@ class RideNavigator;
class GcToolBar;
class GcBubble;
class LionFullScreen;
class QTFullScreen;
extern QList<MainWindow *> 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);

60
src/QTFullScreen.cpp Normal file
View File

@@ -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<QKeyEvent *>(event)->key() == Qt::Key_F11) {
toggle();
}
// ESC cancels fullscreen
if (event->type() == QEvent::KeyPress && static_cast<QKeyEvent *>(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;
}

48
src/QTFullScreen.h Normal file
View File

@@ -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 <QtGui>
#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

View File

@@ -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 {