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()
47 void AbstractMonitor::createVideoSurface()
49 QVBoxLayout *lay = new QVBoxLayout;
50 lay->setContentsMargins(0, 0, 0, 0);
51 videoSurface = new VideoSurface;
52 lay->addWidget(videoSurface);
53 videoBox->setLayout(lay);
56 bool AbstractMonitor::isActive() const
58 return m_monitorManager->isActive(m_id);
61 bool AbstractMonitor::slotActivateMonitor(bool forceRefresh)
63 return m_monitorManager->activateMonitor(m_id, forceRefresh);
66 VideoContainer::VideoContainer(AbstractMonitor* monitor, QWidget *parent) :
70 setFrameShape(QFrame::NoFrame);
71 setFocusPolicy(Qt::ClickFocus);
73 setContentsMargins(0, 0, 0, 0);
74 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
78 void VideoContainer::mouseReleaseEvent(QMouseEvent * event)
80 if (event->button() != Qt::RightButton) {
81 if (m_monitor->isActive()) {
82 m_monitor->slotPlay();
88 void VideoContainer::keyPressEvent(QKeyEvent *event)
90 // Exit fullscreen with Esc key
91 if (event->key() == Qt::Key_Escape && isFullScreen()) {
93 event->setAccepted(true);
94 } else event->setAccepted(false);
98 void VideoContainer::wheelEvent(QWheelEvent * event)
100 m_monitor->slotMouseSeek(event->delta(), event->modifiers() == Qt::ControlModifier);
104 void VideoContainer::mouseDoubleClickEvent(QMouseEvent * event)
106 if (!KdenliveSettings::openglmonitors())
111 void VideoContainer::switchFullScreen()
113 // TODO: disable screensaver?
114 Qt::WindowFlags flags = windowFlags();
115 if (!isFullScreen()) {
116 // Check if we ahave a multiple monitor setup
117 setUpdatesEnabled(false);
118 #if QT_VERSION >= 0x040600
119 int monitors = QApplication::desktop()->screenCount();
121 int monitors = QApplication::desktop()->numScreens();
125 // Move monitor widget to the second screen (one screen for Kdenlive, the other one for the Monitor widget
126 int currentScreen = QApplication::desktop()->screenNumber(this);
127 if (currentScreen < monitors - 1)
128 screenres = QApplication::desktop()->screenGeometry(currentScreen + 1);
130 screenres = QApplication::desktop()->screenGeometry(currentScreen - 1);
131 move(QPoint(screenres.x(), screenres.y()));
132 resize(screenres.width(), screenres.height());
135 m_baseFlags = flags & (Qt::Window | Qt::SubWindow);
137 flags ^= Qt::SubWindow;
138 setWindowFlags(flags);
140 // This works around a bug with Compiz
141 // as the window must be visible before we can set the state
144 setWindowState(windowState() | Qt::WindowFullScreen); // set
146 setWindowState(windowState() | Qt::WindowFullScreen); // set
147 setUpdatesEnabled(true);
152 setUpdatesEnabled(false);
153 flags ^= (Qt::Window | Qt::SubWindow); //clear the flags...
154 flags |= m_baseFlags; //then we reset the flags (window and subwindow)
155 setWindowFlags(flags);
156 setWindowState(windowState() ^ Qt::WindowFullScreen); // reset
157 setUpdatesEnabled(true);
163 VideoSurface::VideoSurface(QWidget* parent) :
166 // MonitorRefresh is used as container for the SDL display (it's window id is passed to SDL)
167 setAttribute(Qt::WA_PaintOnScreen);
168 setAttribute(Qt::WA_OpaquePaintEvent);
169 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
170 setAttribute(Qt::WA_NoSystemBackground);
171 //setUpdatesEnabled(false);
174 void VideoSurface::paintEvent(QPaintEvent *event)
177 //WARNING: This might trigger unnecessary refreshes from MLT's producer, but without this,
178 // as soon as monitor is covered by a popup menu or another window, image is corrupted.
179 emit refreshMonitor();
183 #include "abstractmonitor.moc"