5 #include "videoglwidget.h"
7 #ifndef GL_TEXTURE_RECTANGLE_EXT
8 #define GL_TEXTURE_RECTANGLE_EXT GL_TEXTURE_RECTANGLE_NV
11 VideoGLWidget::VideoGLWidget(QWidget *parent)
16 , m_display_ratio(4.0 / 3.0)
17 , m_backgroundColor(Qt::gray)
19 setAttribute(Qt::WA_PaintOnScreen);
20 setAttribute(Qt::WA_OpaquePaintEvent);
23 VideoGLWidget::~VideoGLWidget()
27 glDeleteTextures(1, &m_texture);
30 QSize VideoGLWidget::minimumSizeHint() const
35 QSize VideoGLWidget::sizeHint() const
37 return QSize(400, 300);
40 void VideoGLWidget::initializeGL()
42 qglClearColor(m_backgroundColor);
43 glShadeModel(GL_FLAT);
44 glDisable(GL_DEPTH_TEST);
45 glDisable(GL_CULL_FACE);
46 glDisable(GL_LIGHTING);
49 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
52 void VideoGLWidget::resizeEvent(QResizeEvent* event)
54 resizeGL(event->size().width(),event->size().height());
56 void VideoGLWidget::resizeGL(int width, int height)
59 double this_aspect = (double) width / height;
61 // Special case optimisation to negate odd effect of sample aspect ratio
62 // not corresponding exactly with image resolution.
63 if ((int)(this_aspect * 1000) == (int)(m_display_ratio * 1000)) {
67 // Use OpenGL to normalise sample aspect ratio
68 else if (height * m_display_ratio > width) {
70 h = width / m_display_ratio;
72 w = height * m_display_ratio;
78 glViewport(0, 0, width, height);
79 glMatrixMode(GL_PROJECTION);
81 gluOrtho2D(0, width, height, 0);
82 glMatrixMode(GL_MODELVIEW);
83 glClear(GL_COLOR_BUFFER_BIT);
86 void VideoGLWidget::paintGL()
90 glClear(GL_COLOR_BUFFER_BIT);
92 glEnable(GL_TEXTURE_RECTANGLE_EXT);
96 glTexCoord2i(m_image_width, 0);
98 glTexCoord2i(m_image_width, m_image_height);
99 glVertex2i(x + w, y + h);
100 glTexCoord2i(0, m_image_height);
101 glVertex2i(x, y + h);
103 glDisable(GL_TEXTURE_RECTANGLE_EXT);
107 void VideoGLWidget::showImage(QImage image)
109 m_image_width = image.width();
110 m_image_height = image.height();
114 glDeleteTextures(1, &m_texture);
116 glPixelStorei(GL_UNPACK_ROW_LENGTH, m_image_width);
117 glGenTextures(1, &m_texture);
118 glBindTexture(GL_TEXTURE_RECTANGLE_EXT, m_texture);
119 glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
120 glTexParameterf(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
121 glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA8, m_image_width, m_image_height, 0, GL_RGBA,
122 GL_UNSIGNED_BYTE, image.bits());
126 void VideoGLWidget::mouseDoubleClickEvent(QMouseEvent * event)
128 // TODO: disable screensaver?
129 Qt::WindowFlags flags = windowFlags();
130 if (!isFullScreen()) {
131 // Check if we ahave a multiple monitor setup
132 #if QT_VERSION >= 0x040600
133 int monitors = QApplication::desktop()->screenCount();
135 int monitors = QApplication::desktop()->numScreens();
139 // Move monitor widget to the second screen (one screen for Kdenlive, the other one for the Monitor widget
140 int currentScreen = QApplication::desktop()->screenNumber(this);
141 if (currentScreen < monitors - 1)
142 screenres = QApplication::desktop()->screenGeometry(currentScreen + 1);
144 screenres = QApplication::desktop()->screenGeometry(currentScreen - 1);
145 move(QPoint(screenres.x(), screenres.y()));
146 resize(screenres.width(), screenres.height());
149 m_baseFlags = flags & (Qt::Window | Qt::SubWindow);
151 flags ^= Qt::SubWindow;
152 setWindowFlags(flags);
154 // This works around a bug with Compiz
155 // as the window must be visible before we can set the state
158 setWindowState(windowState() | Qt::WindowFullScreen); // set
160 setWindowState(windowState() | Qt::WindowFullScreen); // set
164 flags ^= (Qt::Window | Qt::SubWindow); //clear the flags...
165 flags |= m_baseFlags; //then we reset the flags (window and subwindow)
166 setWindowFlags(flags);
167 setWindowState(windowState() ^ Qt::WindowFullScreen); // reset