[vlc-commits] [Git][videolan/vlc][master] 2 commits: qt: add property to MainCtx to access main window

Hugo Beauzée-Luyssen (@chouquette) gitlab at videolan.org
Thu Jan 13 09:03:55 UTC 2022



Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC


Commits:
7dd1707a by Fatih Uzunoglu at 2022-01-13T08:18:20+00:00
qt: add property to MainCtx to access main window

- - - - -
4bba2cee by Fatih Uzunoglu at 2022-01-13T08:18:20+00:00
qt, qml: fix incorrect downcasting

- - - - -


10 changed files:

- modules/gui/qt/maininterface/mainctx.cpp
- modules/gui/qt/maininterface/mainctx.hpp
- modules/gui/qt/maininterface/mainui.cpp
- modules/gui/qt/maininterface/qml/MainInterface.qml
- modules/gui/qt/player/qml/Player.qml
- modules/gui/qt/playlist/qml/PlaylistDetachedWindow.qml
- modules/gui/qt/style/AcrylicController.qml
- modules/gui/qt/widgets/qml/CSDMouseStealer.qml
- modules/gui/qt/widgets/qml/CSDTitlebarTapNDrapHandler.qml
- modules/gui/qt/widgets/qml/CSDWindowButtonSet.qml


Changes:

=====================================
modules/gui/qt/maininterface/mainctx.cpp
=====================================
@@ -848,3 +848,11 @@ void MainCtx::setPreferHotkeys(bool enable)
 
     emit preferHotkeysChanged();
 }
+
+QWindow *MainCtx::intfMainWindow() const
+{
+    if (p_intf->p_compositor)
+        return p_intf->p_compositor->interfaceMainWindow();
+    else
+        return nullptr;
+}


=====================================
modules/gui/qt/maininterface/mainctx.hpp
=====================================
@@ -174,6 +174,7 @@ class MainCtx : public QObject
     Q_PROPERTY(PlaylistPtr mainPlaylist READ getMainPlaylist CONSTANT FINAL)
     Q_PROPERTY(vlc::playlist::PlaylistControllerModel* mainPlaylistController READ getMainPlaylistController CONSTANT FINAL)
     Q_PROPERTY(bool smoothScroll READ smoothScroll NOTIFY smoothScrollChanged FINAL)
+    Q_PROPERTY(QWindow* intfMainWindow READ intfMainWindow CONSTANT FINAL)
 
     // This Property only works if hasAcrylicSurface is set
     Q_PROPERTY(bool acrylicActive READ acrylicActive WRITE setAcrylicActive NOTIFY acrylicActiveChanged FINAL)
@@ -272,6 +273,8 @@ public:
 
     bool preferHotkeys() const;
     void setPreferHotkeys(bool enable);
+    
+    QWindow *intfMainWindow() const;
 
 protected:
     /* Systray */


=====================================
modules/gui/qt/maininterface/mainui.cpp
=====================================
@@ -66,16 +66,9 @@ namespace {
 template<class T>
 class SingletonRegisterHelper
 {
-    static QObject* m_instance;
+    static QPointer<QObject> m_instance;
     static QQmlEngine::ObjectOwnership m_ownership;
 
-    static void connect()
-    {
-        QObject::connect(m_instance, &QObject::destroyed, []() {
-            m_instance = nullptr;
-        });
-    }
-
 public:
     static QObject* callback(QQmlEngine *engine, QJSEngine *)
     {
@@ -84,15 +77,14 @@ public:
         return m_instance;
     }
 
-    template<typename... Args>
+    template<class T2 = T, typename... Args>
     static auto getCallback(Args&&... args)
     {
         if (!m_instance)
         {
             m_ownership = QQmlEngine::ObjectOwnership::JavaScriptOwnership;
-            m_instance = new T(args...);
+            m_instance = new T2(std::forward<Args>(args)...);
             assert(!m_instance->parent());
-            connect();
         }
         else
             assert(sizeof...(args) == 0);
@@ -100,23 +92,23 @@ public:
         return callback;
     }
 
-    static void setInstance(T& instance)
+    template<class T2 = T>
+    static void setInstance(T2& instance)
     {
         assert(!m_instance);
         m_ownership = QQmlEngine::ObjectOwnership::CppOwnership;
         m_instance = &instance;
-        connect();
     }
 
     static auto getInstance()
     {
-        return m_instance;
+        return static_cast<T*>(m_instance);
     }
 };
 template<class T>
 QQmlEngine::ObjectOwnership SingletonRegisterHelper<T>::m_ownership = QQmlEngine::ObjectOwnership::JavaScriptOwnership;
 template<class T>
-QObject* SingletonRegisterHelper<T>::m_instance = nullptr;
+QPointer<QObject> SingletonRegisterHelper<T>::m_instance = nullptr;
 
 template<class T>
 void registerAnonymousType( const char *uri, int versionMajor )
@@ -130,8 +122,6 @@ void registerAnonymousType( const char *uri, int versionMajor )
 #endif
 }
 
-class InterfaceWindow : public QWindow { };
-
 } // anonymous namespace
 
 
@@ -150,8 +140,6 @@ MainUI::MainUI(qt_intf_t *p_intf, MainCtx *mainCtx, QWindow* interfaceWindow,  Q
     assert(m_intf->p_mainPlayerController);
     SingletonRegisterHelper<PlayerController>::setInstance(*m_intf->p_mainPlayerController);
 
-    SingletonRegisterHelper<InterfaceWindow>::setInstance(*static_cast<InterfaceWindow*>(m_interfaceWindow));
-
     assert(DialogsProvider::getInstance());
     SingletonRegisterHelper<DialogsProvider>::setInstance(*DialogsProvider::getInstance());
 
@@ -232,7 +220,6 @@ void MainUI::registerQMLTypes()
         qmlRegisterSingletonType<NavigationHistory>(uri, versionMajor, versionMinor, "History", SingletonRegisterHelper<NavigationHistory>::getCallback());
         qmlRegisterSingletonType<PlayerController>(uri, versionMajor, versionMinor, "Player", SingletonRegisterHelper<PlayerController>::callback);
         qmlRegisterSingletonType<I18n>(uri, versionMajor, versionMinor, "I18n", SingletonRegisterHelper<I18n>::getCallback());
-        qmlRegisterSingletonType<InterfaceWindow>(uri, versionMajor, versionMinor, "IntfWindow", SingletonRegisterHelper<InterfaceWindow>::callback);
         qmlRegisterSingletonType<DialogsProvider>(uri, versionMajor, versionMinor, "DialogsProvider", SingletonRegisterHelper<DialogsProvider>::callback);
         qmlRegisterSingletonType<SystemPalette>(uri, versionMajor, versionMinor, "SystemPalette", SingletonRegisterHelper<SystemPalette>::getCallback());
         qmlRegisterSingletonType<DialogModel>(uri, versionMajor, versionMinor, "DialogModel", SingletonRegisterHelper<DialogModel>::getCallback(m_intf));


=====================================
modules/gui/qt/maininterface/qml/MainInterface.qml
=====================================
@@ -181,7 +181,7 @@ Rectangle {
         active: (MainCtx.clientSideDecoration
                  &&
                  // NOTE: We don't want to steal the mouse when we are maximized or in fullscreen
-                 !((IntfWindow.visibility & Window.Maximized) || MainCtx.interfaceFullScreen))
+                 !((MainCtx.intfMainWindow.visibility & Window.Maximized) || MainCtx.interfaceFullScreen))
 
         source: "qrc:///widgets/CSDMouseStealer.qml"
     }


=====================================
modules/gui/qt/player/qml/Player.qml
=====================================
@@ -644,7 +644,7 @@ FocusScope {
     //visible when user navigates within the control bar
     KeyEventFilter {
         id: filter
-        target: IntfWindow
+        target: MainCtx.intfMainWindow
         enabled: controlBarView.state === "visible"
                  && (controlBarView.focus || topcontrolView.focus)
         Keys.onPressed: toolbarAutoHide.setVisible(5000)


=====================================
modules/gui/qt/playlist/qml/PlaylistDetachedWindow.qml
=====================================
@@ -27,7 +27,8 @@ import "qrc:///style/"
 Window {
     visible: true
 
-    property QtWindow window: IntfWindow
+    // TODO: Qt >5.13 use transientParent
+    property QtWindow parentWindow: MainCtx.intfMainWindow
 
     width: 350
     minimumWidth: playlistView.minimumWidth
@@ -36,12 +37,12 @@ Window {
     color: VLCStyle.colors.bg
 
     Component.onCompleted: {
-        if (!!window) {
-            height = window.height
-            minimumHeight = window.minimumHeight
+        if (!!parentWindow) {
+            height = parentWindow.height
+            minimumHeight = parentWindow.minimumHeight
 
-            x = window.x + window.width + 10
-            y = window.y
+            x = parentWindow.x + parentWindow.width + 10
+            y = parentWindow.y
         } else {
             height = 400
             minimumHeight = 200


=====================================
modules/gui/qt/style/AcrylicController.qml
=====================================
@@ -25,7 +25,7 @@ import org.videolan.vlc 0.1
 Item {
     id: root
 
-    property real uiTransluency: (enabled && IntfWindow.active) ? 1 : 0
+    property real uiTransluency: (enabled && MainCtx.intfMainWindow.active) ? 1 : 0
 
     enabled: MainCtx.hasAcrylicSurface
 


=====================================
modules/gui/qt/widgets/qml/CSDMouseStealer.qml
=====================================
@@ -111,7 +111,7 @@ Item {
             cursorShape: modelData.cursor
             acceptedButtons: Qt.LeftButton
 
-            onPressed: IntfWindow.startSystemResize(modelData.edge)
+            onPressed: MainCtx.intfMainWindow.startSystemResize(modelData.edge)
         }
     }
 }


=====================================
modules/gui/qt/widgets/qml/CSDTitlebarTapNDrapHandler.qml
=====================================
@@ -26,7 +26,7 @@ Item {
     TapHandler {
         onDoubleTapped: {
             
-                if ((IntfWindow.visibility & Window.Maximized) !== 0) {
+                if ((MainCtx.intfMainWindow.visibility & Window.Maximized) !== 0) {
                     MainCtx.requestInterfaceNormal()
                 } else {
                     MainCtx.requestInterfaceMaximized()
@@ -40,7 +40,7 @@ Item {
         grabPermissions: TapHandler.CanTakeOverFromAnything
         onActiveChanged: {
             if (active) {
-                IntfWindow.startSystemMove();
+                MainCtx.intfMainWindow.startSystemMove();
             }
         }
     }


=====================================
modules/gui/qt/widgets/qml/CSDWindowButtonSet.qml
=====================================
@@ -40,9 +40,9 @@ Row {
     }
 
     CSDWindowButton {
-        iconTxt: (IntfWindow.visibility & Window.Maximized)  ? VLCIcons.window_restore :VLCIcons.window_maximize
+        iconTxt: (MainCtx.intfMainWindow.visibility & Window.Maximized)  ? VLCIcons.window_restore :VLCIcons.window_maximize
         onClicked: {
-            if (IntfWindow.visibility & Window.Maximized) {
+            if (MainCtx.intfMainWindow & Window.Maximized) {
                 MainCtx.requestInterfaceNormal()
             } else {
                 MainCtx.requestInterfaceMaximized()
@@ -56,7 +56,7 @@ Row {
     CSDWindowButton {
         id: closeButton
         iconTxt: VLCIcons.window_close
-        onClicked: IntfWindow.close()
+        onClicked: MainCtx.intfMainWindow.close()
         height: windowButtonGroup.height
         color: closeButton.hovered ? "white" : windowButtonGroup.color
         hoverColor: "red"



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/4b31f3c9f50cc86505986254d568c5e7a5de8c7d...4bba2cee5de7af6710b3693b4c503c0c2e10a884

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/4b31f3c9f50cc86505986254d568c5e7a5de8c7d...4bba2cee5de7af6710b3693b4c503c0c2e10a884
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list