X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fvideoglwidget.cpp;h=9595ef254da658d7c1ab6126f071619fd915f230;hb=ab65ab29ddec974e04b93679bf10e4046129d97d;hp=8fa6b344230261f68a3fbef14cd84e40123b812a;hpb=623c7ac1fac4f52a39f102649d062cc900e470d6;p=kdenlive diff --git a/src/videoglwidget.cpp b/src/videoglwidget.cpp index 8fa6b344..9595ef25 100644 --- a/src/videoglwidget.cpp +++ b/src/videoglwidget.cpp @@ -1,6 +1,11 @@ #include #include +#ifdef Q_WS_MAC +#include +#else +#include +#endif #include "videoglwidget.h" #ifndef GL_TEXTURE_RECTANGLE_EXT @@ -8,13 +13,15 @@ #endif VideoGLWidget::VideoGLWidget(QWidget *parent) - : QGLWidget(parent) - , m_image_width(0) - , m_image_height(0) - , m_texture(0) - , m_display_ratio(4.0/3.0) - , m_backgroundColor(Qt::gray) + : QGLWidget(parent) + , m_image_width(0) + , m_image_height(0) + , m_texture(0) + , m_display_ratio(4.0 / 3.0) + , m_backgroundColor(Qt::gray) { + setAttribute(Qt::WA_PaintOnScreen); + setAttribute(Qt::WA_OpaquePaintEvent); } VideoGLWidget::~VideoGLWidget() @@ -46,25 +53,26 @@ void VideoGLWidget::initializeGL() glPixelStorei(GL_UNPACK_ALIGNMENT, 1); } +void VideoGLWidget::resizeEvent(QResizeEvent* event) +{ + resizeGL(event->size().width(),event->size().height()); +} void VideoGLWidget::resizeGL(int width, int height) { + double this_aspect = (double) width / height; // Special case optimisation to negate odd effect of sample aspect ratio // not corresponding exactly with image resolution. - if ((int)(this_aspect * 1000) == (int)(m_display_ratio * 1000)) - { + if ((int)(this_aspect * 1000) == (int)(m_display_ratio * 1000)) { w = width; h = height; } // Use OpenGL to normalise sample aspect ratio - else if (height * m_display_ratio > width) - { + else if (height * m_display_ratio > width) { w = width; h = width / m_display_ratio; - } - else - { + } else { w = height * m_display_ratio; h = height; } @@ -76,23 +84,25 @@ void VideoGLWidget::resizeGL(int width, int height) glLoadIdentity(); gluOrtho2D(0, width, height, 0); glMatrixMode(GL_MODELVIEW); + glClear(GL_COLOR_BUFFER_BIT); } void VideoGLWidget::paintGL() { - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - if (m_texture) - { + if (m_texture) { +#ifdef Q_WS_MAC + glClear(GL_COLOR_BUFFER_BIT); +#endif glEnable(GL_TEXTURE_RECTANGLE_EXT); glBegin(GL_QUADS); - glTexCoord2i(0, 0); - glVertex2i(x, y); - glTexCoord2i(m_image_width, 0); - glVertex2i(x + w, y); - glTexCoord2i(m_image_width, m_image_height); - glVertex2i(x + w, y + h); - glTexCoord2i(0, m_image_height); - glVertex2i(x, y + h); + glTexCoord2i(0, 0); + glVertex2i(x, y); + glTexCoord2i(m_image_width, 0); + glVertex2i(x + w, y); + glTexCoord2i(m_image_width, m_image_height); + glVertex2i(x + w, y + h); + glTexCoord2i(0, m_image_height); + glVertex2i(x, y + h); glEnd(); glDisable(GL_TEXTURE_RECTANGLE_EXT); } @@ -106,12 +116,61 @@ void VideoGLWidget::showImage(QImage image) makeCurrent(); if (m_texture) glDeleteTextures(1, &m_texture); + glPixelStorei(GL_UNPACK_ROW_LENGTH, m_image_width); glGenTextures(1, &m_texture); glBindTexture(GL_TEXTURE_RECTANGLE_EXT, m_texture); glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA8, m_image_width, m_image_height, 0, GL_RGBA, - GL_UNSIGNED_BYTE, image.bits()); + GL_UNSIGNED_BYTE, image.bits()); updateGL(); } + +void VideoGLWidget::mouseDoubleClickEvent(QMouseEvent * event) +{ + // TODO: disable screensaver? + Qt::WindowFlags flags = windowFlags(); + if (!isFullScreen()) { + // Check if we ahave a multiple monitor setup +#if QT_VERSION >= 0x040600 + int monitors = QApplication::desktop()->screenCount(); +#else + int monitors = QApplication::desktop()->numScreens(); +#endif + if (monitors > 1) { + QRect screenres; + // Move monitor widget to the second screen (one screen for Kdenlive, the other one for the Monitor widget + int currentScreen = QApplication::desktop()->screenNumber(this); + if (currentScreen < monitors - 1) + screenres = QApplication::desktop()->screenGeometry(currentScreen + 1); + else + screenres = QApplication::desktop()->screenGeometry(currentScreen - 1); + move(QPoint(screenres.x(), screenres.y())); + resize(screenres.width(), screenres.height()); + } + + m_baseFlags = flags & (Qt::Window | Qt::SubWindow); + flags |= Qt::Window; + flags ^= Qt::SubWindow; + setWindowFlags(flags); +#ifdef Q_WS_X11 + // This works around a bug with Compiz + // as the window must be visible before we can set the state + show(); + raise(); + setWindowState(windowState() | Qt::WindowFullScreen); // set +#else + setWindowState(windowState() | Qt::WindowFullScreen); // set + show(); +#endif + } else { + flags ^= (Qt::Window | Qt::SubWindow); //clear the flags... + flags |= m_baseFlags; //then we reset the flags (window and subwindow) + setWindowFlags(flags); + setWindowState(windowState() ^ Qt::WindowFullScreen); // reset + show(); + } + event->accept(); +} +