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)
63 double this_aspect = (double) width / height;
65 // Special case optimisation to negate odd effect of sample aspect ratio
66 // not corresponding exactly with image resolution.
67 if ((int)(this_aspect * 1000) == (int)(m_display_ratio * 1000)) {
71 // Use OpenGL to normalise sample aspect ratio
72 else if (height * m_display_ratio > width) {
74 h = width / m_display_ratio;
76 w = height * m_display_ratio;
82 glViewport(0, 0, width, height);
83 glMatrixMode(GL_PROJECTION);
85 gluOrtho2D(0, width, height, 0);
86 glMatrixMode(GL_MODELVIEW);
87 glClear(GL_COLOR_BUFFER_BIT);
90 void VideoGLWidget::paintGL()
94 glClear(GL_COLOR_BUFFER_BIT);
96 glEnable(GL_TEXTURE_RECTANGLE_EXT);
100 glTexCoord2i(m_image_width, 0);
101 glVertex2i(x + w, y);
102 glTexCoord2i(m_image_width, m_image_height);
103 glVertex2i(x + w, y + h);
104 glTexCoord2i(0, m_image_height);
105 glVertex2i(x, y + h);
107 glDisable(GL_TEXTURE_RECTANGLE_EXT);
111 void VideoGLWidget::showImage(QImage image)
113 m_image_width = image.width();
114 m_image_height = image.height();
118 glDeleteTextures(1, &m_texture);
120 glPixelStorei(GL_UNPACK_ROW_LENGTH, m_image_width);
121 glGenTextures(1, &m_texture);
122 glBindTexture(GL_TEXTURE_RECTANGLE_EXT, m_texture);
123 glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
124 glTexParameterf(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
125 glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA8, m_image_width, m_image_height, 0, GL_RGBA,
126 GL_UNSIGNED_BYTE, image.bits());
130 void VideoGLWidget::mouseDoubleClickEvent(QMouseEvent * event)
132 // TODO: disable screensaver?
133 Qt::WindowFlags flags = windowFlags();
134 if (!isFullScreen()) {
135 // Check if we ahave a multiple monitor setup
136 #if QT_VERSION >= 0x040600
137 int monitors = QApplication::desktop()->screenCount();
139 int monitors = QApplication::desktop()->numScreens();
143 // Move monitor widget to the second screen (one screen for Kdenlive, the other one for the Monitor widget
144 int currentScreen = QApplication::desktop()->screenNumber(this);
145 if (currentScreen < monitors - 1)
146 screenres = QApplication::desktop()->screenGeometry(currentScreen + 1);
148 screenres = QApplication::desktop()->screenGeometry(currentScreen - 1);
149 move(QPoint(screenres.x(), screenres.y()));
150 resize(screenres.width(), screenres.height());
153 m_baseFlags = flags & (Qt::Window | Qt::SubWindow);
155 flags ^= Qt::SubWindow;
156 setWindowFlags(flags);
158 // This works around a bug with Compiz
159 // as the window must be visible before we can set the state
162 setWindowState(windowState() | Qt::WindowFullScreen); // set
164 setWindowState(windowState() | Qt::WindowFullScreen); // set
168 flags ^= (Qt::Window | Qt::SubWindow); //clear the flags...
169 flags |= m_baseFlags; //then we reset the flags (window and subwindow)
170 setWindowFlags(flags);
171 setWindowState(windowState() ^ Qt::WindowFullScreen); // reset