switched to opengl widget and made shortcuts application context, fixes #400

This commit is contained in:
itsmattkc
2019-02-10 03:07:52 -08:00
parent 12487a0cb3
commit 85325cd7d3
7 changed files with 57 additions and 72 deletions
+14 -40
View File
@@ -55,8 +55,7 @@ ViewerWidget::ViewerWidget(QWidget *parent) :
waveform_scroll(0),
dragging(false),
gizmos(nullptr),
selected_gizmo(nullptr),
window(nullptr),
selected_gizmo(nullptr),
x_scroll(0),
y_scroll(0)
{
@@ -74,13 +73,11 @@ ViewerWidget::ViewerWidget(QWidget *parent) :
renderer->start(QThread::HighPriority);
connect(renderer, SIGNAL(ready()), this, SLOT(queue_repaint()));
connect(renderer, SIGNAL(finished()), renderer, SLOT(deleteLater()));
window = new ViewerWindow(this);
}
ViewerWidget::~ViewerWidget() {
if (window != nullptr) {
window->close();
delete window;
}
renderer->cancel();
delete renderer;
}
@@ -100,10 +97,7 @@ void ViewerWidget::set_fullscreen(int screen) {
if (screen >= 0 && screen < QGuiApplication::screens().size()) {
QScreen* selected_screen = QGuiApplication::screens().at(screen);
window->showFullScreen();
window->setGeometry(selected_screen->geometry());
// HACK: window seems to show with distorted texture on first showing, so we queue an update after it's shown
QTimer::singleShot(100, window, SLOT(update()));
window->setGeometry(selected_screen->geometry());
} else {
qCritical() << "Failed to find requested screen" << screen << "to set fullscreen to";
}
@@ -119,7 +113,7 @@ void ViewerWidget::show_context_menu() {
connect(show_fullscreen_action, SIGNAL(triggered()), this, SLOT(show_fullscreen()));*/
QMenu* fullscreen_menu = menu.addMenu(tr("Show Fullscreen"));
QList<QScreen*> screens = QGuiApplication::screens();
if (window != nullptr && window->isVisible()) {
if (window->isVisible()) {
fullscreen_menu->addAction(tr("Disable"));
}
for (int i=0;i<screens.size();i++) {
@@ -177,15 +171,11 @@ void ViewerWidget::queue_repaint() {
}
void ViewerWidget::fullscreen_menu_action(QAction *action) {
if (window == nullptr) {
QMessageBox::critical(this, "Error", "Failed to create viewer window");
} else {
if (action->data().isNull()) {
window->hide();
} else {
set_fullscreen(action->data().toInt());
}
}
if (action->data().isNull()) {
window->hide();
} else {
set_fullscreen(action->data().toInt());
}
}
void ViewerWidget::set_fit_zoom() {
@@ -222,9 +212,7 @@ void ViewerWidget::retry() {
void ViewerWidget::initializeGL() {
initializeOpenGLFunctions();
connect(context(), SIGNAL(aboutToBeDestroyed()), this, SLOT(context_destroy()), Qt::DirectConnection);
window = new ViewerWindow(context());
connect(context(), SIGNAL(aboutToBeDestroyed()), this, SLOT(context_destroy()), Qt::DirectConnection);
}
void ViewerWidget::frame_update() {
@@ -254,16 +242,6 @@ void ViewerWidget::set_scroll(double x, double y) {
update();
}
//void ViewerWidget::resizeGL(int w, int h)
//{
//}
/*void ViewerWidget::paintEvent(QPaintEvent *e) {
if (!rendering) {
QOpenGLWidget::paintEvent(e);
}
}*/
void ViewerWidget::seek_from_click(int x) {
viewer->seek(getFrameFromScreenPoint(waveform_zoom, x+waveform_scroll));
}
@@ -272,11 +250,7 @@ void ViewerWidget::context_destroy() {
makeCurrent();
if (viewer->seq != nullptr) {
closeActiveClips(viewer->seq);
}
if (window != nullptr) {
delete window;
}
//QMetaObject::invokeMethod(renderer, "delete_ctx", Qt::QueuedConnection);
}
renderer->delete_ctx();
doneCurrent();
}
@@ -405,7 +379,7 @@ void ViewerWidget::wheelEvent(QWheelEvent *event) {
}
void ViewerWidget::close_window() {
if (window != nullptr) window->hide();
window->hide();
}
void ViewerWidget::draw_waveform_func() {
@@ -629,7 +603,7 @@ void ViewerWidget::paintGL() {
glDisable(GL_TEXTURE_2D);
if (window != nullptr && window->isVisible()) {
if (window->isVisible()) {
window->set_texture(renderer->front_texture, double(viewer->seq->width)/double(viewer->seq->height), &renderer->mutex);
}
+18 -15
View File
@@ -5,28 +5,31 @@
#include <QPainter>
#include <QApplication>
#include <QMenuBar>
#include <QShortcut>
#include <QOpenGLFunctions>
#include <QOpenGLContext>
#include <QDebug>
#include "mainwindow.h"
ViewerWindow::ViewerWindow(QOpenGLContext *share) :
QOpenGLWindow(share),
ViewerWindow::ViewerWindow(QWidget *parent) :
QOpenGLWidget(parent, Qt::Window),
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()));
setMouseTracking(true);
installEventFilter(mainWindow);
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;
ar = iar;
mutex = imutex;
update();
update();
}
void ViewerWindow::keyPressEvent(QKeyEvent *e) {
@@ -46,14 +49,14 @@ void ViewerWindow::mouseMoveEvent(QMouseEvent *) {
if (!show_fullscreen_msg) {
show_fullscreen_msg = true;
update();
}
}
}
void ViewerWindow::paintGL() {
if (texture > 0) {
if (mutex != nullptr) mutex->lock();
glClearColor(0.0, 0.0, 0.0, 1.0);
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
@@ -63,7 +66,7 @@ void ViewerWindow::paintGL() {
glLoadIdentity();
glOrtho(0, 1, 0, 1, -1, 1);
glBegin(GL_QUADS);
glBegin(GL_QUADS);
double top = 0;
double left = 0;
@@ -85,17 +88,17 @@ void ViewerWindow::paintGL() {
glVertex2d(left, top);
glTexCoord2d(0, 0);
glVertex2d(left, bottom);
glTexCoord2d(1, 0);
glTexCoord2d(1, 0);
glVertex2d(right, bottom);
glTexCoord2d(1, 1);
glTexCoord2d(1, 1);
glVertex2d(right, top);
glTexCoord2d(0, 1);
glTexCoord2d(0, 1);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);
glDisable(GL_TEXTURE_2D);
if (mutex != nullptr) mutex->unlock();
}
@@ -128,7 +131,7 @@ void ViewerWindow::paintGL() {
p.drawRect(fullscreen_msg_rect);
p.drawText(text_x, text_y, fs_str);
}
}
}
void ViewerWindow::fullscreen_msg_timeout() {
+11 -8
View File
@@ -1,30 +1,33 @@
#ifndef VIEWERWINDOW_H
#define VIEWERWINDOW_H
#include <QOpenGLWindow>
#include <QOpenGLWidget>
#include <QTimer>
class QMutex;
class QMenu;
class QShortcut;
class ViewerWindow : public QOpenGLWindow {
class ViewerWindow : public QOpenGLWidget {
Q_OBJECT
public:
ViewerWindow(QOpenGLContext* share);
void set_texture(GLuint t, double iar, QMutex *imutex);
ViewerWindow(QWidget *parent);
void set_texture(GLuint t, double iar, QMutex *imutex);
protected:
virtual void keyPressEvent(QKeyEvent*) override;
virtual void mousePressEvent(QMouseEvent*) override;
virtual void mouseMoveEvent(QMouseEvent*) override;
virtual void mouseMoveEvent(QMouseEvent*) override;
virtual void paintGL() override;
private:
virtual void paintGL() override;
GLuint texture;
double ar;
QMutex* mutex;
QMutex* mutex;
// exit full screen message
QTimer fullscreen_msg_timer;
bool show_fullscreen_msg;
QRect fullscreen_msg_rect;
QRect fullscreen_msg_rect;
private slots:
void fullscreen_msg_timeout();
};