Add Fullscreen Mode on F11 (Fix #9)

This commit is contained in:
Florian Märkl 2019-08-22 20:37:14 +02:00
commit 8f539cc3fa
No known key found for this signature in database
GPG key ID: 125BC8A5A6A1E857
2 changed files with 41 additions and 13 deletions

View file

@ -38,6 +38,8 @@ class StreamWindow: public QMainWindow
AVOpenGLWidget *av_widget;
void Init(const StreamSessionConnectInfo &connect_info);
protected:
void keyPressEvent(QKeyEvent *event) override;
void keyReleaseEvent(QKeyEvent *event) override;
@ -45,6 +47,7 @@ class StreamWindow: public QMainWindow
private slots:
void SessionQuit(ChiakiQuitReason reason, const QString &reason_str);
void ToggleFullscreen();
};
#endif // CHIAKI_GUI_STREAMWINDOW_H

View file

@ -22,6 +22,7 @@
#include <QLabel>
#include <QMessageBox>
#include <QCoreApplication>
#include <QAction>
StreamWindow::StreamWindow(const StreamSessionConnectInfo &connect_info, QWidget *parent)
: QMainWindow(parent)
@ -30,19 +31,7 @@ StreamWindow::StreamWindow(const StreamSessionConnectInfo &connect_info, QWidget
setWindowTitle(qApp->applicationName());
try
{
session = new StreamSession(connect_info, this);
connect(session, &StreamSession::SessionQuit, this, &StreamWindow::SessionQuit);
av_widget = new AVOpenGLWidget(session->GetVideoDecoder(), this);
setCentralWidget(av_widget);
grabKeyboard();
session->Start();
resize(connect_info.video_profile.width, connect_info.video_profile.height);
show();
Init(connect_info);
}
catch(const Exception &e)
{
@ -59,6 +48,28 @@ StreamWindow::~StreamWindow()
delete av_widget;
}
void StreamWindow::Init(const StreamSessionConnectInfo &connect_info)
{
session = new StreamSession(connect_info, this);
connect(session, &StreamSession::SessionQuit, this, &StreamWindow::SessionQuit);
av_widget = new AVOpenGLWidget(session->GetVideoDecoder(), this);
setCentralWidget(av_widget);
grabKeyboard();
session->Start();
auto fullscreen_action = new QAction(tr("Fullscreen"), this);
fullscreen_action->setShortcut(Qt::Key_F11);
addAction(fullscreen_action);
connect(fullscreen_action, &QAction::triggered, this, &StreamWindow::ToggleFullscreen);
resize(connect_info.video_profile.width, connect_info.video_profile.height);
show();
}
void StreamWindow::keyPressEvent(QKeyEvent *event)
{
if(session)
@ -87,3 +98,17 @@ void StreamWindow::SessionQuit(ChiakiQuitReason reason, const QString &reason_st
QMessageBox::critical(this, tr("Session has quit"), m);
close();
}
void StreamWindow::ToggleFullscreen()
{
if(isFullScreen())
{
setCursor(Qt::ArrowCursor);
showNormal();
}
else
{
setCursor(Qt::BlankCursor);
showFullScreen();
}
}