switched to opengl widget and made shortcuts application context, fixes #400
This commit is contained in:
@@ -37,6 +37,7 @@ KeySequenceEditor::KeySequenceEditor(QWidget* parent, QAction* a)
|
||||
|
||||
void KeySequenceEditor::set_action_shortcut() {
|
||||
action->setShortcut(keySequence());
|
||||
action->setShortcutContext(Qt::ApplicationShortcut);
|
||||
}
|
||||
|
||||
void KeySequenceEditor::reset_to_default() {
|
||||
|
||||
@@ -86,6 +86,8 @@ int main(int argc, char *argv[]) {
|
||||
av_register_all();
|
||||
avfilter_register_all();
|
||||
|
||||
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
|
||||
|
||||
QApplication a(argc, argv);
|
||||
a.setWindowIcon(QIcon(":/icons/olive64.png"));
|
||||
|
||||
|
||||
+3
-2
@@ -321,10 +321,11 @@ void kbd_shortcut_processor(QByteArray& file, QMenu* menu, bool save, bool first
|
||||
}
|
||||
QKeySequence ks(shortcut);
|
||||
if (!ks.isEmpty()) {
|
||||
a->setShortcut(ks);
|
||||
a->setShortcut(ks);
|
||||
}
|
||||
}
|
||||
}
|
||||
a->setShortcutContext(Qt::ApplicationShortcut);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -972,7 +973,7 @@ void MainWindow::setup_menus() {
|
||||
|
||||
tools_menu->addSeparator();
|
||||
|
||||
tools_menu->addAction(tr("Preferences"), this, SLOT(preferences()), QKeySequence("Ctrl+."))->setProperty("id", "prefs");
|
||||
tools_menu->addAction(tr("Preferences"), this, SLOT(preferences()), QKeySequence("Ctrl+,"))->setProperty("id", "prefs");
|
||||
|
||||
#ifdef QT_DEBUG
|
||||
tools_menu->addAction(tr("Clear Undo"), this, SLOT(clear_undo_stack()))->setProperty("id", "clearundo");
|
||||
|
||||
+8
-7
@@ -363,17 +363,18 @@ void Viewer::play(bool in_to_out) {
|
||||
uncue_recording();
|
||||
}
|
||||
|
||||
if (playback_speed == 0) {
|
||||
playback_speed = 1;
|
||||
}
|
||||
|
||||
bool seek_to_in = (seq->using_workarea && (config.loop || playing_in_to_out));
|
||||
if (!is_recording_cued()
|
||||
&& playback_speed > 0
|
||||
&& (playing_in_to_out
|
||||
|| seq->playhead >= seq->getEndFrame()
|
||||
|| seq->playhead >= seq->getEndFrame()
|
||||
|| (seek_to_in && seq->playhead >= seq->workarea_out))) {
|
||||
seek(seek_to_in ? seq->workarea_in : 0);
|
||||
}
|
||||
|
||||
if (playback_speed == 0) {
|
||||
playback_speed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
reset_all_audio();
|
||||
if (is_recording_cued() && !start_recording()) {
|
||||
@@ -781,7 +782,7 @@ void Viewer::timer_update() {
|
||||
if (recording_start != recording_end && seq->playhead >= recording_end) {
|
||||
pause();
|
||||
}
|
||||
} else {
|
||||
} else if (playback_speed > 0) {
|
||||
if (seq->playhead >= seq->getEndFrame()) {
|
||||
pause();
|
||||
}
|
||||
|
||||
+14
-40
@@ -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
@@ -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
@@ -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();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user