7 #include "videoglwidget.h"
9 #ifndef GL_TEXTURE_RECTANGLE_EXT
10 #define GL_TEXTURE_RECTANGLE_EXT GL_TEXTURE_RECTANGLE_NV
13 VideoGLWidget::VideoGLWidget(QWidget *parent)
18 , m_display_ratio(4.0 / 3.0)
19 , m_backgroundColor(Qt::gray)
21 setAttribute(Qt::WA_PaintOnScreen);
22 setAttribute(Qt::WA_OpaquePaintEvent);
25 VideoGLWidget::~VideoGLWidget()
29 glDeleteTextures(1, &m_texture);
32 QSize VideoGLWidget::minimumSizeHint() const
37 QSize VideoGLWidget::sizeHint() const
39 return QSize(400, 300);
42 void VideoGLWidget::initializeGL()
44 qglClearColor(m_backgroundColor);
45 glShadeModel(GL_FLAT);
46 glDisable(GL_DEPTH_TEST);
47 glDisable(GL_CULL_FACE);
48 glDisable(GL_LIGHTING);
51 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
54 void VideoGLWidget::resizeEvent(QResizeEvent* event)
56 resizeGL(event->size().width(),event->size().height());
58 void VideoGLWidget::resizeGL(int width, int height)
61 double this_aspect = (double) width / height;
63 // Special case optimisation to negate odd effect of sample aspect ratio
64 // not corresponding exactly with image resolution.
65 if ((int)(this_aspect * 1000) == (int)(m_display_ratio * 1000)) {
69 // Use OpenGL to normalise sample aspect ratio
70 else if (height * m_display_ratio > width) {
72 h = width / m_display_ratio;
74 w = height * m_display_ratio;
80 glViewport(0, 0, width, height);
81 glMatrixMode(GL_PROJECTION);
83 gluOrtho2D(0, width, height, 0);
84 glMatrixMode(GL_MODELVIEW);
85 glClear(GL_COLOR_BUFFER_BIT);
88 void VideoGLWidget::paintGL()
92 glClear(GL_COLOR_BUFFER_BIT);
94 glEnable(GL_TEXTURE_RECTANGLE_EXT);
98 glTexCoord2i(m_image_width, 0);
100 glTexCoord2i(m_image_width, m_image_height);
101 glVertex2i(x + w, y + h);
102 glTexCoord2i(0, m_image_height);
103 glVertex2i(x, y + h);
105 glDisable(GL_TEXTURE_RECTANGLE_EXT);
109 void VideoGLWidget::showImage(QImage image)
111 m_image_width = image.width();
112 m_image_height = image.height();
116 glDeleteTextures(1, &m_texture);
118 glPixelStorei(GL_UNPACK_ROW_LENGTH, m_image_width);
119 glGenTextures(1, &m_texture);
120 glBindTexture(GL_TEXTURE_RECTANGLE_EXT, m_texture);
121 glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
122 glTexParameterf(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
123 glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA8, m_image_width, m_image_height, 0, GL_RGBA,
124 GL_UNSIGNED_BYTE, image.bits());
128 void VideoGLWidget::mouseDoubleClickEvent(QMouseEvent * event)
130 // TODO: disable screensaver?
131 Qt::WindowFlags flags = windowFlags();
132 if (!isFullScreen()) {
133 // Check if we ahave a multiple monitor setup
134 #if QT_VERSION >= 0x040600
135 int monitors = QApplication::desktop()->screenCount();
137 int monitors = QApplication::desktop()->numScreens();
141 // Move monitor widget to the second screen (one screen for Kdenlive, the other one for the Monitor widget
142 int currentScreen = QApplication::desktop()->screenNumber(this);
143 if (currentScreen < monitors - 1)
144 screenres = QApplication::desktop()->screenGeometry(currentScreen + 1);
146 screenres = QApplication::desktop()->screenGeometry(currentScreen - 1);
147 move(QPoint(screenres.x(), screenres.y()));
148 resize(screenres.width(), screenres.height());
151 m_baseFlags = flags & (Qt::Window | Qt::SubWindow);
153 flags ^= Qt::SubWindow;
154 setWindowFlags(flags);
156 // This works around a bug with Compiz
157 // as the window must be visible before we can set the state
160 setWindowState(windowState() | Qt::WindowFullScreen); // set
162 setWindowState(windowState() | Qt::WindowFullScreen); // set
166 flags ^= (Qt::Window | Qt::SubWindow); //clear the flags...
167 flags |= m_baseFlags; //then we reset the flags (window and subwindow)
168 setWindowFlags(flags);
169 setWindowState(windowState() ^ Qt::WindowFullScreen); // reset