1 /***************************************************************************
2 * Copyright (C) 2011 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
21 #include "abstractmonitor.h"
22 #include "kdenlivesettings.h"
23 #include "monitormanager.h"
27 #include <QPaintEvent>
28 #include <QDesktopWidget>
29 #include <QVBoxLayout>
32 AbstractMonitor::AbstractMonitor(Kdenlive::MONITORID id, MonitorManager *manager, QWidget *parent):
36 m_monitorManager(manager)
38 videoBox = new VideoContainer(this);
42 AbstractMonitor::~AbstractMonitor()
48 void AbstractMonitor::createVideoSurface()
50 QVBoxLayout *lay = new QVBoxLayout;
51 lay->setContentsMargins(0, 0, 0, 0);
52 videoSurface = new VideoSurface;
53 lay->addWidget(videoSurface);
54 videoBox->setLayout(lay);
57 bool AbstractMonitor::isActive() const
59 return m_monitorManager->isActive(m_id);
62 bool AbstractMonitor::slotActivateMonitor()
64 return m_monitorManager->activateMonitor(m_id);
67 VideoContainer::VideoContainer(AbstractMonitor* monitor, QWidget *parent) :
71 setFrameShape(QFrame::NoFrame);
72 setFocusPolicy(Qt::ClickFocus);
74 setContentsMargins(0, 0, 0, 0);
75 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
79 void VideoContainer::mouseReleaseEvent(QMouseEvent * event)
81 if (event->button() != Qt::RightButton) {
82 if (m_monitor->isActive()) {
83 m_monitor->slotPlay();
89 void VideoContainer::keyPressEvent(QKeyEvent *event)
91 // Exit fullscreen with Esc key
92 if (event->key() == Qt::Key_Escape && isFullScreen()) {
94 event->setAccepted(true);
95 } else event->setAccepted(false);
99 void VideoContainer::wheelEvent(QWheelEvent * event)
101 m_monitor->slotMouseSeek(event->delta(), event->modifiers() == Qt::ControlModifier);
105 void VideoContainer::mouseDoubleClickEvent(QMouseEvent * event)
107 if (!KdenliveSettings::openglmonitors())
112 void VideoContainer::switchFullScreen()
114 // TODO: disable screensaver?
115 Qt::WindowFlags flags = windowFlags();
116 if (!isFullScreen()) {
117 // Check if we ahave a multiple monitor setup
118 setUpdatesEnabled(false);
119 #if QT_VERSION >= 0x040600
120 int monitors = QApplication::desktop()->screenCount();
122 int monitors = QApplication::desktop()->numScreens();
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
148 setUpdatesEnabled(true);
153 setUpdatesEnabled(false);
154 flags ^= (Qt::Window | Qt::SubWindow); //clear the flags...
155 flags |= m_baseFlags; //then we reset the flags (window and subwindow)
156 setWindowFlags(flags);
157 setWindowState(windowState() ^ Qt::WindowFullScreen); // reset
158 setUpdatesEnabled(true);
164 VideoSurface::VideoSurface(QWidget* parent) :
167 // MonitorRefresh is used as container for the SDL display (it's window id is passed to SDL)
168 setAttribute(Qt::WA_PaintOnScreen);
169 setAttribute(Qt::WA_OpaquePaintEvent);
170 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
171 setAttribute(Qt::WA_NoSystemBackground);
172 setUpdatesEnabled(false);
175 void VideoSurface::paintEvent(QPaintEvent *event)
178 //WARNING: This might trigger unnecessary refreshes from MLT's producer, but without this,
179 // as soon as monitor is covered by a popup menu or another window, image is corrupted.
180 emit refreshMonitor();