4 #include "videoglwidget.h"
6 #ifndef GL_TEXTURE_RECTANGLE_EXT
7 #define GL_TEXTURE_RECTANGLE_EXT GL_TEXTURE_RECTANGLE_NV
10 VideoGLWidget::VideoGLWidget(QWidget *parent)
15 , m_display_ratio(4.0 / 3.0)
16 , m_backgroundColor(Qt::gray)
18 setAttribute(Qt::WA_PaintOnScreen);
19 setAttribute(Qt::WA_OpaquePaintEvent);
22 VideoGLWidget::~VideoGLWidget()
26 glDeleteTextures(1, &m_texture);
29 QSize VideoGLWidget::minimumSizeHint() const
34 QSize VideoGLWidget::sizeHint() const
36 return QSize(400, 300);
39 void VideoGLWidget::initializeGL()
41 qglClearColor(m_backgroundColor);
42 glShadeModel(GL_FLAT);
43 glDisable(GL_DEPTH_TEST);
44 glDisable(GL_CULL_FACE);
45 glDisable(GL_LIGHTING);
48 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
51 void VideoGLWidget::resizeGL(int width, int height)
53 double this_aspect = (double) width / height;
55 // Special case optimisation to negate odd effect of sample aspect ratio
56 // not corresponding exactly with image resolution.
57 if ((int)(this_aspect * 1000) == (int)(m_display_ratio * 1000)) {
61 // Use OpenGL to normalise sample aspect ratio
62 else if (height * m_display_ratio > width) {
64 h = width / m_display_ratio;
66 w = height * m_display_ratio;
72 glViewport(0, 0, width, height);
73 glMatrixMode(GL_PROJECTION);
75 gluOrtho2D(0, width, height, 0);
76 glMatrixMode(GL_MODELVIEW);
77 glClear(GL_COLOR_BUFFER_BIT); // | GL_DEPTH_BUFFER_BIT // Depth is disabled, so shouldn'b be necessary to clear DEPTH_BUFFER
80 void VideoGLWidget::paintGL()
83 glEnable(GL_TEXTURE_RECTANGLE_EXT);
87 glTexCoord2i(m_image_width, 0);
89 glTexCoord2i(m_image_width, m_image_height);
90 glVertex2i(x + w, y + h);
91 glTexCoord2i(0, m_image_height);
94 glDisable(GL_TEXTURE_RECTANGLE_EXT);
98 void VideoGLWidget::showImage(QImage image)
100 m_image_width = image.width();
101 m_image_height = image.height();
105 glDeleteTextures(1, &m_texture);
107 glPixelStorei(GL_UNPACK_ROW_LENGTH, m_image_width);
108 glGenTextures(1, &m_texture);
109 glBindTexture(GL_TEXTURE_RECTANGLE_EXT, m_texture);
110 glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
111 glTexParameterf(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
112 glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA8, m_image_width, m_image_height, 0, GL_RGBA,
113 GL_UNSIGNED_BYTE, image.bits());
117 void VideoGLWidget::mouseDoubleClickEvent(QMouseEvent * event)
119 // TODO: disable screensaver?
120 Qt::WindowFlags flags = windowFlags();
121 if (!isFullScreen()) {
122 // Check if we ahave a multiple monitor setup
123 int monitors = QApplication::desktop()->screenCount();
126 // Move monitor widget to the second screen (one screen for Kdenlive, the other one for the Monitor widget
127 int currentScreen = QApplication::desktop()->screenNumber(this);
128 if (currentScreen < monitors - 1)
129 screenres = QApplication::desktop()->screenGeometry(currentScreen + 1);
131 screenres = QApplication::desktop()->screenGeometry(currentScreen - 1);
132 move(QPoint(screenres.x(), screenres.y()));
133 resize(screenres.width(), screenres.height());
136 m_baseFlags = flags & (Qt::Window | Qt::SubWindow);
138 flags ^= Qt::SubWindow;
139 setWindowFlags(flags);
141 // This works around a bug with Compiz
142 // as the window must be visible before we can set the state
145 setWindowState(windowState() | Qt::WindowFullScreen); // set
147 setWindowState(windowState() | Qt::WindowFullScreen); // set
151 flags ^= (Qt::Window | Qt::SubWindow); //clear the flags...
152 flags |= m_baseFlags; //then we reset the flags (window and subwindow)
153 setWindowFlags(flags);
154 setWindowState(windowState() ^ Qt::WindowFullScreen); // reset