added extra ways to close fullscreen mode

This commit is contained in:
itsmattkc
2019-01-18 11:24:30 +11:00
parent 5776387eb0
commit a042520634
2 changed files with 78 additions and 2 deletions
+66 -2
View File
@@ -1,12 +1,18 @@
#include "viewerwindow.h"
#include <QMutex>
#include <QKeyEvent>
#include <QPainter>
ViewerWindow::ViewerWindow(QOpenGLContext *share) :
QOpenGLWindow(share),
texture(0),
mutex(nullptr)
{}
mutex(nullptr),
show_fullscreen_msg(false)
{
fullscreen_msg_timer.setInterval(2000);
connect(&fullscreen_msg_timer, SIGNAL(timeout()), this, SLOT(fullscreen_msg_timeout()));
}
void ViewerWindow::set_texture(GLuint t, double iar, QMutex* imutex) {
texture = t;
@@ -15,6 +21,26 @@ void ViewerWindow::set_texture(GLuint t, double iar, QMutex* imutex) {
update();
}
void ViewerWindow::keyPressEvent(QKeyEvent *e) {
if (e->key() == Qt::Key_Escape) {
hide();
}
}
void ViewerWindow::mousePressEvent(QMouseEvent *e) {
if (show_fullscreen_msg && fullscreen_msg_rect.contains(e->pos())) {
hide();
}
}
void ViewerWindow::mouseMoveEvent(QMouseEvent *) {
fullscreen_msg_timer.start();
if (!show_fullscreen_msg) {
show_fullscreen_msg = true;
update();
}
}
void ViewerWindow::paintGL() {
if (texture > 0) {
if (mutex != nullptr) mutex->lock();
@@ -65,4 +91,42 @@ void ViewerWindow::paintGL() {
if (mutex != nullptr) mutex->unlock();
}
if (show_fullscreen_msg) {
QPainter p(this);
QFont f = p.font();
f.setPointSize(24);
p.setFont(f);
QFontMetrics fm(f);
QString fs_str = tr("Exit Fullscreen");
p.setPen(Qt::white);
p.setBrush(QColor(0, 0, 0, 128));
int text_width = fm.width(fs_str);
int text_x = (width()/2)-(text_width/2);
int text_y = fm.height()+fm.ascent();
int rect_padding = 8;
fullscreen_msg_rect = QRect(text_x-rect_padding,
fm.height()-rect_padding,
text_width+rect_padding+rect_padding,
fm.height()+rect_padding+rect_padding);
p.drawRect(fullscreen_msg_rect);
p.drawText(text_x, text_y, fs_str);
}
}
void ViewerWindow::fullscreen_msg_timeout() {
fullscreen_msg_timer.stop();
if (show_fullscreen_msg) {
show_fullscreen_msg = false;
update();
}
}
+12
View File
@@ -2,6 +2,7 @@
#define VIEWERWINDOW_H
#include <QOpenGLWindow>
#include <QTimer>
class QMutex;
@@ -10,11 +11,22 @@ class ViewerWindow : public QOpenGLWindow {
public:
ViewerWindow(QOpenGLContext* share);
void set_texture(GLuint t, double iar, QMutex *imutex);
protected:
void keyPressEvent(QKeyEvent*);
void mousePressEvent(QMouseEvent*);
void mouseMoveEvent(QMouseEvent*);
private:
void paintGL();
GLuint texture;
double ar;
QMutex* mutex;
// exit full screen message
QTimer fullscreen_msg_timer;
bool show_fullscreen_msg;
QRect fullscreen_msg_rect;
private slots:
void fullscreen_msg_timeout();
};
#endif // VIEWERWINDOW_H