]> git.sesse.net Git - kdenlive/blob - src/widgets/abstractmonitor.cpp
Remove support for non-OpenGL main monitor.
[kdenlive] / src / widgets / abstractmonitor.cpp
1 /***************************************************************************
2  *   Copyright (C) 2011 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20
21 #include "widgets/abstractmonitor.h"
22 #include "kdenlivesettings.h"
23 #include "monitormanager.h"
24
25 #include <KDebug>
26
27 #include <QPaintEvent>
28 #include <QDesktopWidget>
29 #include <QVBoxLayout>
30
31
32 AbstractMonitor::AbstractMonitor(Kdenlive::MonitorId id, MonitorManager *manager, QWidget *parent): 
33     QWidget(parent),
34     videoSurface(NULL),
35     m_id(id),
36     m_monitorManager(manager)
37 {
38     videoBox = new VideoContainer(this);
39 }
40
41
42 AbstractMonitor::~AbstractMonitor()
43 {
44     delete videoSurface;
45 }
46
47 void AbstractMonitor::createVideoSurface()
48 {
49     QVBoxLayout *lay = new QVBoxLayout;
50     lay->setContentsMargins(0, 0, 0, 0);
51     videoSurface = new VideoSurface;
52     lay->addWidget(videoSurface);
53     videoBox->setLayout(lay);
54 }
55
56 bool AbstractMonitor::isActive() const
57 {
58     return m_monitorManager->isActive(m_id);
59 }
60
61 bool AbstractMonitor::slotActivateMonitor(bool forceRefresh)
62 {
63     return m_monitorManager->activateMonitor(m_id, forceRefresh);
64 }
65
66 VideoContainer::VideoContainer(AbstractMonitor* monitor, QWidget *parent) :
67     QFrame(parent)
68     , m_monitor(monitor)
69 {
70     setFrameShape(QFrame::NoFrame);
71     setFocusPolicy(Qt::ClickFocus);
72     //setEnabled(false);
73     setContentsMargins(0, 0, 0, 0);
74     setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
75 }
76
77 // virtual
78 void VideoContainer::mouseReleaseEvent(QMouseEvent * event)
79 {
80     if (event->button() != Qt::RightButton) {
81         if (m_monitor->isActive()) {
82             m_monitor->slotPlay();
83         }
84     }
85 }
86
87 // virtual
88 void VideoContainer::keyPressEvent(QKeyEvent *event)
89 {
90     // Exit fullscreen with Esc key
91     if (event->key() == Qt::Key_Escape && isFullScreen()) {
92         switchFullScreen();
93         event->setAccepted(true);
94     } else event->setAccepted(false);
95 }
96
97 // virtual
98 void VideoContainer::wheelEvent(QWheelEvent * event)
99 {
100     m_monitor->slotMouseSeek(event->delta(), event->modifiers() == Qt::ControlModifier);
101     event->accept();
102 }
103
104 void VideoContainer::mouseDoubleClickEvent(QMouseEvent * event)
105 {
106     event->accept();
107 }
108
109 void VideoContainer::switchFullScreen()
110 {
111     // TODO: disable screensaver?
112     Qt::WindowFlags flags = windowFlags();
113     if (!isFullScreen()) {
114         // Check if we ahave a multiple monitor setup
115         setUpdatesEnabled(false);
116 #if QT_VERSION >= 0x040600
117         int monitors = QApplication::desktop()->screenCount();
118 #else
119         int monitors = QApplication::desktop()->numScreens();
120 #endif
121         if (monitors > 1) {
122             QRect screenres;
123             // Move monitor widget to the second screen (one screen for Kdenlive, the other one for the Monitor widget
124             int currentScreen = QApplication::desktop()->screenNumber(this);
125             if (currentScreen < monitors - 1)
126                 screenres = QApplication::desktop()->screenGeometry(currentScreen + 1);
127             else
128                 screenres = QApplication::desktop()->screenGeometry(currentScreen - 1);
129             move(QPoint(screenres.x(), screenres.y()));
130             resize(screenres.width(), screenres.height());
131         }
132
133         m_baseFlags = flags & (Qt::Window | Qt::SubWindow);
134         flags |= Qt::Window;
135         flags ^= Qt::SubWindow;
136         setWindowFlags(flags);
137 #ifdef Q_WS_X11
138         // This works around a bug with Compiz
139         // as the window must be visible before we can set the state
140         show();
141         raise();
142         setWindowState(windowState() | Qt::WindowFullScreen);   // set
143 #else
144         setWindowState(windowState() | Qt::WindowFullScreen);   // set
145         setUpdatesEnabled(true);
146         show();
147 #endif
148         setEnabled(true);
149     } else {
150         setUpdatesEnabled(false);
151         flags ^= (Qt::Window | Qt::SubWindow); //clear the flags...
152         flags |= m_baseFlags; //then we reset the flags (window and subwindow)
153         setWindowFlags(flags);
154         setWindowState(windowState()  ^ Qt::WindowFullScreen);   // reset
155         setUpdatesEnabled(true);
156         setEnabled(false);
157         show();
158     }
159 }
160
161 #include "abstractmonitor.moc"