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>
31 AbstractMonitor::AbstractMonitor(Kdenlive::MONITORID id, MonitorManager *manager, QWidget *parent):
34 m_monitorManager(manager)
37 bool AbstractMonitor::isActive() const
39 return m_monitorManager->isActive(m_id);
42 bool AbstractMonitor::slotActivateMonitor()
44 return m_monitorManager->activateMonitor(m_id);
47 VideoContainer::VideoContainer(AbstractMonitor* monitor, QWidget *parent) :
51 setFrameShape(QFrame::NoFrame);
52 setFocusPolicy(Qt::ClickFocus);
53 setAttribute(Qt::WA_PaintOnScreen);
54 setAttribute(Qt::WA_OpaquePaintEvent);
56 setContentsMargins(0, 0, 0, 0);
57 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
61 void VideoContainer::mouseReleaseEvent(QMouseEvent * event)
63 if (event->button() != Qt::RightButton) {
64 if (m_monitor->isActive()) {
65 m_monitor->slotPlay();
71 void VideoContainer::keyPressEvent(QKeyEvent *event)
73 // Exit fullscreen with Esc key
74 if (event->key() == Qt::Key_Escape && isFullScreen()) {
76 event->setAccepted(true);
77 } else event->setAccepted(false);
81 void VideoContainer::wheelEvent(QWheelEvent * event)
83 m_monitor->slotMouseSeek(event->delta(), event->modifiers() == Qt::ControlModifier);
87 void VideoContainer::mouseDoubleClickEvent(QMouseEvent * event)
89 if (!KdenliveSettings::openglmonitors())
94 void VideoContainer::switchFullScreen()
96 // TODO: disable screensaver?
98 Qt::WindowFlags flags = windowFlags();
99 if (!isFullScreen()) {
100 // Check if we ahave a multiple monitor setup
101 setUpdatesEnabled(false);
102 #if QT_VERSION >= 0x040600
103 int monitors = QApplication::desktop()->screenCount();
105 int monitors = QApplication::desktop()->numScreens();
109 // Move monitor widget to the second screen (one screen for Kdenlive, the other one for the Monitor widget
110 int currentScreen = QApplication::desktop()->screenNumber(this);
111 if (currentScreen < monitors - 1)
112 screenres = QApplication::desktop()->screenGeometry(currentScreen + 1);
114 screenres = QApplication::desktop()->screenGeometry(currentScreen - 1);
115 move(QPoint(screenres.x(), screenres.y()));
116 resize(screenres.width(), screenres.height());
119 m_baseFlags = flags & (Qt::Window | Qt::SubWindow);
121 flags ^= Qt::SubWindow;
122 setWindowFlags(flags);
124 // This works around a bug with Compiz
125 // as the window must be visible before we can set the state
128 setWindowState(windowState() | Qt::WindowFullScreen); // set
130 setWindowState(windowState() | Qt::WindowFullScreen); // set
131 setUpdatesEnabled(true);
136 setUpdatesEnabled(false);
137 flags ^= (Qt::Window | Qt::SubWindow); //clear the flags...
138 flags |= m_baseFlags; //then we reset the flags (window and subwindow)
139 setWindowFlags(flags);
140 setWindowState(windowState() ^ Qt::WindowFullScreen); // reset
141 setUpdatesEnabled(true);
145 m_monitor->unpause();