qt: move qml utility classes to the util folder
[vlc.git] / modules / gui / qt / main_interface.hpp
blob2362603e5b24ed25240fcc327805b7d67f1e78b1
1 /*****************************************************************************
2 * main_interface.hpp : Main Interface
3 ****************************************************************************
4 * Copyright (C) 2006-2010 VideoLAN and AUTHORS
6 * Authors: Clément Stenac <zorglub@videolan.org>
7 * Jean-Baptiste Kempf <jb@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #ifndef QVLC_MAIN_INTERFACE_H_
25 #define QVLC_MAIN_INTERFACE_H_
27 #include "qt.hpp"
29 #include "widgets/native/qvlcframe.hpp"
30 #include "player/player_controller.hpp"
31 #include "components/voutwindow/qvoutwindow.hpp"
33 #include <QSystemTrayIcon>
34 #include <QStackedWidget>
35 #include <QtQuick/QQuickView>
36 #include <QtQuickWidgets/QQuickWidget>
37 #include <QtQuick/QQuickWindow>
39 #ifdef _WIN32
40 # include <shobjidl.h>
41 #endif
43 #include <atomic>
45 class QSettings;
46 class QCloseEvent;
47 class QKeyEvent;
48 class QLabel;
49 class QEvent;
50 class VideoWidget;
51 class VisualSelector;
52 class QVBoxLayout;
53 class QStackedLayout;
54 class QMenu;
55 class QSize;
56 class QScreen;
57 class QTimer;
58 class StandardPLPanel;
59 struct vout_window_t;
60 struct vout_window_cfg_t;
62 class MainInterface : public QVLCMW
64 Q_OBJECT
66 Q_PROPERTY(bool playlistDocked READ isPlaylistDocked WRITE setPlaylistDocked NOTIFY playlistDockedChanged)
67 Q_PROPERTY(bool playlistVisible READ isPlaylistVisible WRITE setPlaylistVisible NOTIFY playlistVisibleChanged)
68 Q_PROPERTY(bool interfaceAlwaysOnTop READ isInterfaceAlwaysOnTop WRITE setInterfaceAlwaysOnTop NOTIFY interfaceAlwaysOnTopChanged)
69 Q_PROPERTY(bool interfaceFullScreen READ isInterfaceFullScreen WRITE setInterfaceFullScreen NOTIFY interfaceFullScreenChanged)
70 Q_PROPERTY(bool hasEmbededVideo READ hasEmbededVideo NOTIFY hasEmbededVideoChanged)
71 Q_PROPERTY(bool showRemainingTime READ isShowRemainingTime WRITE setShowRemainingTime NOTIFY showRemainingTimeChanged)
72 Q_PROPERTY(VLCVarChoiceModel* extraInterfaces READ getExtraInterfaces CONSTANT)
74 public:
75 /* tors */
76 MainInterface( intf_thread_t *);
77 virtual ~MainInterface();
79 static const QEvent::Type ToolbarsNeedRebuild;
81 /* Video requests from core */
82 bool getVideo( struct vout_window_t * );
83 private:
84 bool m_hasEmbededVideo = false;
85 bool m_showRemainingTime = false;
86 VLCVarChoiceModel* m_extraInterfaces;
87 std::atomic_flag videoActive;
88 static int enableVideo( struct vout_window_t *,
89 const struct vout_window_cfg_t * );
90 static void disableVideo( struct vout_window_t * );
91 static void releaseVideo( struct vout_window_t * );
92 static void resizeVideo( struct vout_window_t *, unsigned, unsigned );
93 static void requestVideoState( struct vout_window_t *, unsigned );
94 static void requestVideoWindowed( struct vout_window_t * );
95 static void requestVideoFullScreen( struct vout_window_t *, const char * );
97 public:
98 QQmlContext* getRootCtx() { return mediacenterView->rootContext(); }
99 QQuickWindow* getRootQuickWindow();
100 QQmlEngine* getEngine(){ return mediacenterView->engine(); }
101 VideoSurfaceProvider* getVideoSurfaceProvider() const;
103 /* Getters */
104 QSystemTrayIcon *getSysTray() { return sysTray; }
105 QMenu *getSysTrayMenu() { return systrayMenu; }
106 enum
108 CONTROLS_VISIBLE = 0x1,
109 CONTROLS_HIDDEN = 0x2,
110 CONTROLS_ADVANCED = 0x4,
112 enum
114 RAISE_NEVER,
115 RAISE_VIDEO,
116 RAISE_AUDIO,
117 RAISE_AUDIOVIDEO,
119 bool isInterfaceFullScreen() { return b_interfaceFullScreen; }
120 bool isPlaylistDocked() { return b_playlistDocked; }
121 bool isPlaylistVisible() { return playlistVisible; }
122 bool isInterfaceAlwaysOnTop() { return b_interfaceOnTop; }
123 bool hasEmbededVideo() { return m_hasEmbededVideo; }
124 inline bool isShowRemainingTime() const { return m_showRemainingTime; }
125 QList<QQmlError> qmlErrors() const;
127 protected:
128 void dropEventPlay( QDropEvent* event, bool b_play );
129 void changeEvent( QEvent * ) Q_DECL_OVERRIDE;
130 void dropEvent( QDropEvent *) Q_DECL_OVERRIDE;
131 void dragEnterEvent( QDragEnterEvent * ) Q_DECL_OVERRIDE;
132 void dragMoveEvent( QDragMoveEvent * ) Q_DECL_OVERRIDE;
133 void dragLeaveEvent( QDragLeaveEvent * ) Q_DECL_OVERRIDE;
134 void closeEvent( QCloseEvent *) Q_DECL_OVERRIDE;
135 virtual void toggleUpdateSystrayMenuWhenVisible();
136 void resizeWindow(int width, int height);
138 protected:
139 /* Main Widgets Creation */
140 void createMainWidget( QSettings* );
142 /* Systray */
143 void createSystray();
144 void initSystray();
145 void handleSystray();
147 /* */
148 void setInterfaceFullScreen( bool );
149 void computeMinimumSize();
151 /* */
152 QSettings *settings;
153 QSystemTrayIcon *sysTray;
154 QMenu *systrayMenu;
156 QString input_name;
157 QVBoxLayout *mainLayout;
159 std::unique_ptr<QVoutWindow> m_videoRenderer;
161 QQuickWidget *mediacenterView;
162 QWidget *mediacenterWrapper;
164 /* Status Bar */
165 QLabel *nameLabel;
166 QLabel *cryptedLabel;
168 /* Status and flags */
169 QPoint lastWinPosition;
170 QSize lastWinSize; /// To restore the same window size when leaving fullscreen
171 QScreen *lastWinScreen;
173 QSize pendingResize; // to be applied when fullscreen is disabled
175 QMap<QWidget *, QSize> stackWidgetsSizes;
177 /* Flags */
178 unsigned i_notificationSetting; /// Systray Notifications
179 bool b_autoresize; ///< persistent resizable window
180 bool b_videoFullScreen; ///< --fullscreen
181 bool b_hideAfterCreation;
182 bool b_minimalView; ///< Minimal video
183 bool b_playlistDocked;
184 bool b_interfaceFullScreen;
185 bool b_interfaceOnTop; ///keep UI on top
186 bool b_pauseOnMinimize;
187 bool b_maximizedView;
188 bool b_isWindowTiled;
189 #ifdef QT5_HAS_WAYLAND
190 bool b_hasWayland;
191 #endif
192 bool b_hasMedialibrary = false;
193 /* States */
194 bool playlistVisible; ///< Is the playlist visible ?
195 // bool videoIsActive; ///< Having a video now / THEMIM->hasV
196 // bool b_visualSelectorEnabled;
198 bool b_hasPausedWhenMinimized;
200 static const Qt::Key kc[10]; /* easter eggs */
201 int i_kc_offset;
203 public slots:
204 void toggleUpdateSystrayMenu();
205 void showUpdateSystrayMenu();
206 void hideUpdateSystrayMenu();
207 void toggleInterfaceFullScreen();
208 void setPlaylistDocked( bool );
209 void setPlaylistVisible( bool );
210 void setInterfaceAlwaysOnTop( bool );
211 void setShowRemainingTime( bool );
213 void emitBoss();
214 void emitRaise();
215 void emitShow();
216 void popupMenu( bool show );
218 virtual void reloadPrefs();
219 VLCVarChoiceModel* getExtraInterfaces();
221 protected slots:
222 void setVLCWindowsTitle( const QString& title = "" );
223 void handleSystrayClick( QSystemTrayIcon::ActivationReason );
224 void updateSystrayTooltipName( const QString& );
225 void updateSystrayTooltipStatus( PlayerController::PlayingState );
227 void showBuffering( float );
229 /* Manage the Video Functions from the vout threads */
230 void getVideoSlot( bool );
231 void releaseVideoSlot( void );
233 void setVideoSize(unsigned int w, unsigned int h);
234 virtual void setVideoFullScreen( bool );
235 void setVideoOnTop( bool );
236 void setBoss();
237 void setRaise();
238 void setFullScreen( bool );
239 void onInputChanged( bool );
241 void sendHotkey(Qt::Key key, Qt::KeyboardModifiers modifiers );
243 signals:
244 void askGetVideo( bool );
245 void askReleaseVideo( );
246 void askVideoToResize( unsigned int, unsigned int );
247 void askVideoSetFullScreen( bool );
248 void askVideoOnTop( bool );
249 void minimalViewToggled( bool );
250 void fullscreenInterfaceToggled( bool );
251 void askToQuit();
252 void askShow();
253 void askBoss();
254 void askRaise();
255 void askPopupMenu( bool show );
256 void kc_pressed(); /* easter eggs */
258 void playlistDockedChanged(bool);
259 void playlistVisibleChanged(bool);
260 void interfaceAlwaysOnTopChanged(bool);
261 void interfaceFullScreenChanged(bool);
262 void hasEmbededVideoChanged(bool);
263 void toolBarConfUpdated();
264 void showRemainingTimeChanged(bool);
267 #endif