5 #include <OpenGL/glu.h>
9 #include "videoglwidget.h"
11 #ifndef GL_TEXTURE_RECTANGLE_EXT
12 #define GL_TEXTURE_RECTANGLE_EXT GL_TEXTURE_RECTANGLE_NV
15 VideoGLWidget::VideoGLWidget(QWidget *parent)
20 , m_display_ratio(4.0 / 3.0)
21 , m_backgroundColor(Qt::gray)
23 setAttribute(Qt::WA_PaintOnScreen);
24 setAttribute(Qt::WA_OpaquePaintEvent);
27 VideoGLWidget::~VideoGLWidget()
31 glDeleteTextures(1, &m_texture);
34 QSize VideoGLWidget::minimumSizeHint() const
39 QSize VideoGLWidget::sizeHint() const
41 return QSize(400, 300);
44 void VideoGLWidget::initializeGL()
46 qglClearColor(m_backgroundColor);
47 glShadeModel(GL_FLAT);
48 glDisable(GL_DEPTH_TEST);
49 glDisable(GL_CULL_FACE);
50 glDisable(GL_LIGHTING);
53 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
56 void VideoGLWidget::resizeEvent(QResizeEvent* event)
58 resizeGL(event->size().width(),event->size().height());
60 void VideoGLWidget::resizeGL(int width, int height)
62 double this_aspect = (double) width / height;
64 // Special case optimisation to negate odd effect of sample aspect ratio
65 // not corresponding exactly with image resolution.
66 if ((int)(this_aspect * 1000) == (int)(m_display_ratio * 1000)) {
70 // Use OpenGL to normalise sample aspect ratio
71 else if (height * m_display_ratio > width) {
73 h = width / m_display_ratio;
75 w = height * m_display_ratio;
81 glViewport(0, 0, width, height);
82 glMatrixMode(GL_PROJECTION);
84 gluOrtho2D(0, width, height, 0);
85 glMatrixMode(GL_MODELVIEW);
86 glClear(GL_COLOR_BUFFER_BIT);
89 void VideoGLWidget::activateMonitor()
92 glViewport(0, 0, width(), height());
93 glMatrixMode(GL_PROJECTION);
95 gluOrtho2D(0, width(), height(), 0);
96 glMatrixMode(GL_MODELVIEW);
97 glClear(GL_COLOR_BUFFER_BIT);
100 void VideoGLWidget::paintGL()
104 glClear(GL_COLOR_BUFFER_BIT);
106 glEnable(GL_TEXTURE_RECTANGLE_EXT);
110 glTexCoord2i(m_image_width, 0);
111 glVertex2i(x + w, y);
112 glTexCoord2i(m_image_width, m_image_height);
113 glVertex2i(x + w, y + h);
114 glTexCoord2i(0, m_image_height);
115 glVertex2i(x, y + h);
117 glDisable(GL_TEXTURE_RECTANGLE_EXT);
121 void VideoGLWidget::showImage(QImage image)
123 m_image_width = image.width();
124 m_image_height = image.height();
127 glDeleteTextures(1, &m_texture);
129 glPixelStorei(GL_UNPACK_ROW_LENGTH, m_image_width);
130 glGenTextures(1, &m_texture);
131 glBindTexture(GL_TEXTURE_RECTANGLE_EXT, m_texture);
132 glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
133 glTexParameterf(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
134 glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA8, m_image_width, m_image_height, 0, GL_RGBA,
135 GL_UNSIGNED_BYTE, image.bits());
139 void VideoGLWidget::mouseDoubleClickEvent(QMouseEvent * event)
141 // TODO: disable screensaver?
142 Qt::WindowFlags flags = windowFlags();
143 if (!isFullScreen()) {
144 // Check if we ahave a multiple monitor setup
145 #if QT_VERSION >= 0x040600
146 int monitors = QApplication::desktop()->screenCount();
148 int monitors = QApplication::desktop()->numScreens();
152 // Move monitor widget to the second screen (one screen for Kdenlive, the other one for the Monitor widget
153 int currentScreen = QApplication::desktop()->screenNumber(this);
154 if (currentScreen < monitors - 1)
155 screenres = QApplication::desktop()->screenGeometry(currentScreen + 1);
157 screenres = QApplication::desktop()->screenGeometry(currentScreen - 1);
158 move(QPoint(screenres.x(), screenres.y()));
159 resize(screenres.width(), screenres.height());
162 m_baseFlags = flags & (Qt::Window | Qt::SubWindow);
164 flags ^= Qt::SubWindow;
165 setWindowFlags(flags);
167 // This works around a bug with Compiz
168 // as the window must be visible before we can set the state
171 setWindowState(windowState() | Qt::WindowFullScreen); // set
173 setWindowState(windowState() | Qt::WindowFullScreen); // set
177 flags ^= (Qt::Window | Qt::SubWindow); //clear the flags...
178 flags |= m_baseFlags; //then we reset the flags (window and subwindow)
179 setWindowFlags(flags);
180 setWindowState(windowState() ^ Qt::WindowFullScreen); // reset