]> git.sesse.net Git - kdenlive/blobdiff - src/videoglwidget.cpp
Fix indent
[kdenlive] / src / videoglwidget.cpp
index e3b0c7506ad071a9b72cd25cb5561dd394cad292..3da19948159ba2cb78ab9f571bfdb7e814c67f95 100644 (file)
@@ -1,6 +1,11 @@
 
 #include <QtGui>
 #include <QtOpenGL>
+#ifdef Q_WS_MAC
+#include <OpenGL/glu.h>
+#else
+#include <GL/glu.h>
+#endif
 #include "videoglwidget.h"
 
 #ifndef GL_TEXTURE_RECTANGLE_EXT
 
 VideoGLWidget::VideoGLWidget(QWidget *parent)
     : QGLWidget(parent)
+    , x(0)
+    , y(0)
+    , w(width())
+    , h(height())
     , 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);
 }
@@ -36,6 +45,12 @@ QSize VideoGLWidget::sizeHint() const
     return QSize(400, 300);
 }
 
+void VideoGLWidget::setImageAspectRatio(double ratio)
+{
+    m_display_ratio = ratio;
+    resizeGL(width(), height());
+}
+
 void VideoGLWidget::initializeGL()
 {
     qglClearColor(m_backgroundColor);
@@ -48,6 +63,11 @@ 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;
@@ -74,12 +94,26 @@ void VideoGLWidget::resizeGL(int width, int height)
     glLoadIdentity();
     gluOrtho2D(0, width, height, 0);
     glMatrixMode(GL_MODELVIEW);
-    glClear(GL_COLOR_BUFFER_BIT); // | GL_DEPTH_BUFFER_BIT // Depth is disabled, so shouldn'b be necessary to clear DEPTH_BUFFER
+    glClear(GL_COLOR_BUFFER_BIT);
+}
+
+void VideoGLWidget::activateMonitor()
+{
+    makeCurrent();
+    glViewport(0, 0, width(), height());
+    glMatrixMode(GL_PROJECTION);
+    glLoadIdentity();
+    gluOrtho2D(0, width(), height(), 0);
+    glMatrixMode(GL_MODELVIEW);
+    glClear(GL_COLOR_BUFFER_BIT);
 }
 
 void VideoGLWidget::paintGL()
 {
     if (m_texture) {
+#ifdef Q_WS_MAC
+               glClear(GL_COLOR_BUFFER_BIT);
+#endif
         glEnable(GL_TEXTURE_RECTANGLE_EXT);
         glBegin(GL_QUADS);
         glTexCoord2i(0, 0);
@@ -95,11 +129,10 @@ void VideoGLWidget::paintGL()
     }
 }
 
-void VideoGLWidget::showImage(QImage image)
+void VideoGLWidget::showImage(const QImage &image)
 {
     m_image_width = image.width();
     m_image_height = image.height();
-
     makeCurrent();
     if (m_texture)
         glDeleteTextures(1, &m_texture);
@@ -109,7 +142,7 @@ void VideoGLWidget::showImage(QImage image)
     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,
+    glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA8, m_image_width, m_image_height, 0, GL_RGB,
                  GL_UNSIGNED_BYTE, image.bits());
     updateGL();
 }
@@ -120,7 +153,11 @@ void VideoGLWidget::mouseDoubleClickEvent(QMouseEvent * event)
     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
@@ -157,3 +194,5 @@ void VideoGLWidget::mouseDoubleClickEvent(QMouseEvent * event)
     event->accept();
 }
 
+
+#include "videoglwidget.moc"