[vlc-commits] [Git][videolan/vlc][master] 7 commits: qt/player_controller: Add the 'hasPrograms' property

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Mon Aug 22 20:21:50 UTC 2022



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
34e47193 by Benjamin Arnaud at 2022-08-22T20:07:29+00:00
qt/player_controller: Add the 'hasPrograms' property

- - - - -
b1da8f43 by Benjamin Arnaud at 2022-08-22T20:07:29+00:00
qt: Create QmlProgramMenu

- - - - -
667000aa by Benjamin Arnaud at 2022-08-22T20:07:29+00:00
qt/control_list_model: Add PROGRAM_BUTTON to ControlType enum

- - - - -
2a92cc00 by Benjamin Arnaud at 2022-08-22T20:07:29+00:00
qt/control_list_filter: Add PROGRAM_BUTTON filter

- - - - -
e7e071d9 by Benjamin Arnaud at 2022-08-22T20:07:29+00:00
qml: Create ProgramButton

- - - - -
46bd9404 by Benjamin Arnaud at 2022-08-22T20:07:29+00:00
qml/ControlbarControls: Add PROGRAM_BUTTON component

- - - - -
78d3fb38 by Benjamin Arnaud at 2022-08-22T20:07:29+00:00
qml/NavigationWidget: Add ProgramButton

- - - - -


14 changed files:

- modules/gui/qt/Makefile.am
- modules/gui/qt/maininterface/mainui.cpp
- modules/gui/qt/menus/qml_menu_wrapper.cpp
- modules/gui/qt/menus/qml_menu_wrapper.hpp
- modules/gui/qt/player/control_list_filter.cpp
- modules/gui/qt/player/control_list_model.hpp
- modules/gui/qt/player/player_controller.cpp
- modules/gui/qt/player/player_controller.hpp
- modules/gui/qt/player/player_controller_p.hpp
- modules/gui/qt/player/qml/ControlbarControls.qml
- modules/gui/qt/player/qml/controlbarcontrols/NavigationWidget.qml
- + modules/gui/qt/player/qml/controlbarcontrols/ProgramButton.qml
- modules/gui/qt/vlc.qrc
- po/POTFILES.in


Changes:

=====================================
modules/gui/qt/Makefile.am
=====================================
@@ -901,6 +901,7 @@ libqt_plugin_la_QML = \
 	gui/qt/player/qml/controlbarcontrols/PlayerSwitchButton.qml \
 	gui/qt/player/qml/controlbarcontrols/PlaylistButton.qml \
 	gui/qt/player/qml/controlbarcontrols/PreviousButton.qml \
+	gui/qt/player/qml/controlbarcontrols/ProgramButton.qml \
 	gui/qt/player/qml/controlbarcontrols/QuitButton.qml \
 	gui/qt/player/qml/controlbarcontrols/RandomButton.qml \
 	gui/qt/player/qml/controlbarcontrols/RendererButton.qml \


=====================================
modules/gui/qt/maininterface/mainui.cpp
=====================================
@@ -282,6 +282,7 @@ void MainUI::registerQMLTypes()
         qmlRegisterType<QmlGlobalMenu>( uri, versionMajor, versionMinor, "QmlGlobalMenu" );
         qmlRegisterType<QmlMenuBar>( uri, versionMajor, versionMinor, "QmlMenuBar" );
         qmlRegisterType<QmlBookmarkMenu>( uri, versionMajor, versionMinor, "QmlBookmarkMenu" );
+        qmlRegisterType<QmlProgramMenu>( uri, versionMajor, versionMinor, "QmlProgramMenu" );
         qmlRegisterType<QmlRendererMenu>( uri, versionMajor, versionMinor, "QmlRendererMenu" );
         qmlRegisterType<QmlSubtitleMenu>( uri, versionMajor, versionMinor, "QmlSubtitleMenu" );
         qmlRegisterType<QmlAudioMenu>( uri, versionMajor, versionMinor, "QmlAudioMenu" );


=====================================
modules/gui/qt/menus/qml_menu_wrapper.cpp
=====================================
@@ -493,6 +493,38 @@ bool QmlMenuPositioner::eventFilter(QObject * object, QEvent * event)
     m_positioner.popup(m_menu.get(), position, above);
 }
 
+// QmlProgramMenu
+
+/* explicit */ QmlProgramMenu::QmlProgramMenu(QObject * parent)
+    : QObject(parent)
+{}
+
+// Interface
+
+/* Q_INVOKABLE */ void QmlProgramMenu::popup(const QPoint & position, bool above)
+{
+    if (m_player == nullptr)
+        return;
+
+    m_menu = std::make_unique<QMenu>();
+
+    connect(m_menu.get(), &QMenu::aboutToHide, this, &QmlProgramMenu::aboutToHide);
+    connect(m_menu.get(), &QMenu::aboutToShow, this, &QmlProgramMenu::aboutToShow);
+
+    m_menu->addSection(qtr("Programs"));
+
+    ProgramListModel * programs = m_player->getPrograms();
+
+    ListMenuHelper * helper = new ListMenuHelper(m_menu.get(), programs, nullptr, m_menu.get());
+
+    connect(helper, &ListMenuHelper::select, [programs](int index)
+    {
+        programs->setData(programs->index(index), true, Qt::CheckStateRole);
+    });
+
+    m_positioner.popup(m_menu.get(), position, above);
+}
+
 // QmlRendererMenu
 
 /* explicit */ QmlRendererMenu::QmlRendererMenu(QObject * parent)


=====================================
modules/gui/qt/menus/qml_menu_wrapper.hpp
=====================================
@@ -207,6 +207,28 @@ private:
     std::unique_ptr<QMenu> m_menu;
 };
 
+class QmlProgramMenu : public QObject
+{
+    Q_OBJECT
+
+    SIMPLE_MENU_PROPERTY(PlayerController *, player, nullptr)
+
+public:
+    explicit QmlProgramMenu(QObject * parent = nullptr);
+
+public: // Interface
+    Q_INVOKABLE void popup(const QPoint & position, bool above = false);
+
+signals:
+    void aboutToHide();
+    void aboutToShow();
+
+private:
+    QmlMenuPositioner m_positioner;
+
+    std::unique_ptr<QMenu> m_menu;
+};
+
 class QmlRendererMenu : public QObject
 {
     Q_OBJECT


=====================================
modules/gui/qt/player/control_list_filter.cpp
=====================================
@@ -59,12 +59,16 @@ bool ControlListFilter::filterAcceptsRow(int source_row, const QModelIndex &) co
     // NOTE: These controls are completely hidden when the current media does not support them.
     if (type == ControlListModel::NAVIGATION_BUTTONS)
     {
-        return (m_player->hasMenu() || m_player->isTeletextAvailable());
+        return (m_player->hasMenu() || m_player->hasPrograms() || m_player->isTeletextAvailable());
     }
     else if (type == ControlListModel::BOOKMARK_BUTTON)
     {
         return (m_ctx->hasMediaLibrary() || m_player->hasChapters() || m_player->hasTitles());
     }
+    else if (type == ControlListModel::PROGRAM_BUTTON)
+    {
+        return m_player->hasPrograms();
+    }
 
     return true;
 }


=====================================
modules/gui/qt/player/control_list_model.hpp
=====================================
@@ -76,6 +76,7 @@ public:
         BOOKMARK_BUTTON,
         RENDERER_BUTTON,
         NAVIGATION_BUTTONS,
+        PROGRAM_BUTTON,
         SPECIAL_MAX,
 
         WIDGET_SPACER = 0x40,


=====================================
modules/gui/qt/player/player_controller.cpp
=====================================
@@ -154,6 +154,16 @@ void PlayerControllerPrivate::UpdateProgram(enum vlc_player_list_action action,
 {
     Q_Q(PlayerController);
     m_programList.updatePrograms( action, prgm );
+
+    bool hasPrograms = (m_programList.getCount() > 1);
+
+    if (m_hasPrograms != hasPrograms)
+    {
+        m_hasPrograms = hasPrograms;
+
+        emit q->hasProgramsChanged(hasPrograms);
+    }
+
     emit q->isEncryptedChanged( prgm->scrambled );
 }
 
@@ -356,6 +366,9 @@ static void on_player_state_changed(vlc_player_t *, enum vlc_player_state state,
             emit q->infoChanged( NULL );
             emit q->currentMetaChanged( (input_item_t *)NULL );
 
+            that->m_hasPrograms =false;
+            emit q->hasProgramsChanged( false );
+
             that->m_encrypted =false;
             emit q->isEncryptedChanged( false );
             that->m_recording =false;
@@ -1947,6 +1960,7 @@ PRIMITIVETYPE_GETTER(bool, hasChapters, m_hasChapters)
 PRIMITIVETYPE_GETTER(bool, hasMenu, m_hasMenu)
 PRIMITIVETYPE_GETTER(bool, isMenu, m_isMenu)
 PRIMITIVETYPE_GETTER(bool, isInteractive, m_isInteractive)
+PRIMITIVETYPE_GETTER(bool, hasPrograms, m_hasPrograms)
 PRIMITIVETYPE_GETTER(bool, isEncrypted, m_encrypted)
 PRIMITIVETYPE_GETTER(bool, isRecording, m_recording)
 PRIMITIVETYPE_GETTER(PlayerController::ABLoopState, getABloopState, m_ABLoopState)


=====================================
modules/gui/qt/player/player_controller.hpp
=====================================
@@ -151,6 +151,8 @@ public:
 
     //programs
     Q_PROPERTY(ProgramListModel* programs READ getPrograms CONSTANT FINAL)
+
+    Q_PROPERTY(bool hasPrograms READ hasPrograms NOTIFY hasProgramsChanged FINAL)
     Q_PROPERTY(bool isEncrypted READ isEncrypted NOTIFY isEncryptedChanged FINAL)
 
     //teletext
@@ -324,6 +326,7 @@ public slots:
 
     //programs
     ProgramListModel* getPrograms();
+    bool hasPrograms() const;
     bool isEncrypted() const;
 
     //teletext
@@ -409,6 +412,7 @@ signals:
     void isInteractiveChanged( bool );
 
     //program
+    void hasProgramsChanged( bool );
     void isEncryptedChanged( bool );
 
     //teletext


=====================================
modules/gui/qt/player/player_controller_p.hpp
=====================================
@@ -128,6 +128,7 @@ public:
 
     //programs
     ProgramListModel m_programList;
+    bool m_hasPrograms = false;
     bool m_encrypted = false;
 
     //teletext


=====================================
modules/gui/qt/player/qml/ControlbarControls.qml
=====================================
@@ -59,6 +59,7 @@ QtObject {
         { id: ControlListModel.NAVIGATION_BUTTONS, file: "NavigationWidget.qml", label: VLCIcons.dvd_menu, text: I18n.qtr("Navigation") },
         { id: ControlListModel.DVD_MENUS_BUTTON, file: "DvdMenuButton.qml", label: VLCIcons.dvd_menu, text: I18n.qtr("DVD menus") },
         { id: ControlListModel.TELETEXT_BUTTONS, file: "TeletextWidget.qml", label: VLCIcons.tvtelx, text: I18n.qtr("Teletext") },
+        { id: ControlListModel.PROGRAM_BUTTON, file: "ProgramButton.qml", label: VLCIcons.bookmark, text: I18n.qtr("Program Button") },
         { id: ControlListModel.RENDERER_BUTTON, file: "RendererButton.qml", label: VLCIcons.renderer, text: I18n.qtr("Renderer Button") },
         { id: ControlListModel.ASPECT_RATIO_COMBOBOX, file: "AspectRatioWidget.qml", label: VLCIcons.aspect_ratio, text: I18n.qtr("Aspect Ratio") },
         { id: ControlListModel.WIDGET_SPACER, file: "SpacerWidget.qml", label: VLCIcons.space, text: I18n.qtr("Spacer") },


=====================================
modules/gui/qt/player/qml/controlbarcontrols/NavigationWidget.qml
=====================================
@@ -83,7 +83,9 @@ Templates.Pane {
             source: (Player.hasMenu || root.paintOnly) ? _controlPath + "DvdMenuButton.qml" : ""
 
             Navigation.parentItem: root
-            Navigation.rightItem: loaderB.item
+
+            Navigation.rightItem: (loaderB.item) ? loaderB.item
+                                                 : loaderC.item
 
             onLoaded: {
                 if (item === null) return
@@ -101,14 +103,35 @@ Templates.Pane {
 
             focus: (item && item.enabled && loaderA.focus === false)
 
-            source: (Player.isTeletextAvailable
+            source: (Player.hasPrograms
                      &&
-                     root.paintOnly == false) ? _controlPath + "TeletextWidget.qml" : ""
+                     root.paintOnly == false) ? _controlPath + "ProgramButton.qml" : ""
 
             Navigation.parentItem: root
+
             Navigation.leftItem: loaderA.item
+            Navigation.rightItem: loaderC.item
 
             onLoaded: if (item) _applyItem(loaderB, item)
         }
+
+        Loader {
+            id: loaderC
+
+            anchors.verticalCenter: parent.verticalCenter
+
+            focus: (item && item.enabled && (loaderA.focus === false && loaderB.focus === false))
+
+            source: (Player.isTeletextAvailable
+                     &&
+                     root.paintOnly == false) ? _controlPath + "TeletextWidget.qml" : ""
+
+            Navigation.parentItem: root
+
+            Navigation.leftItem: (loaderB.item) ? loaderB.item
+                                                : loaderA.item
+
+            onLoaded: if (item) _applyItem(loaderC, item)
+        }
     }
 }


=====================================
modules/gui/qt/player/qml/controlbarcontrols/ProgramButton.qml
=====================================
@@ -0,0 +1,51 @@
+/*****************************************************************************
+ * Copyright (C) 2021 VLC authors and VideoLAN
+ *
+ * Authors: Benjamin Arnaud <bunjee at omega.gg>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * ( at your option ) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+import QtQuick 2.11
+
+import org.videolan.vlc 0.1
+
+import "qrc:///widgets/" as Widgets
+import "qrc:///style/"
+
+Widgets.IconControlButton {
+    id: root
+
+    signal requestLockUnlockAutoHide(bool lock)
+
+    // FIXME: Placeholder icon.
+    iconText: VLCIcons.bookmark
+
+    text: I18n.qtr("Programs")
+
+    // NOTE: We want to pop the menu above the button.
+    onClicked: menu.popup(this.mapToGlobal(0, 0), true)
+
+    enabled: (paintOnly === false && Player.hasPrograms)
+
+    QmlProgramMenu {
+        id: menu
+
+        player: Player
+
+        onAboutToShow: root.requestLockUnlockAutoHide(true)
+        onAboutToHide: root.requestLockUnlockAutoHide(false)
+    }
+}


=====================================
modules/gui/qt/vlc.qrc
=====================================
@@ -334,6 +334,7 @@
         <file alias="PlayerSwitchButton.qml">player/qml/controlbarcontrols/PlayerSwitchButton.qml</file>
         <file alias="PlaylistButton.qml">player/qml/controlbarcontrols/PlaylistButton.qml</file>
         <file alias="PreviousButton.qml">player/qml/controlbarcontrols/PreviousButton.qml</file>
+        <file alias="ProgramButton.qml">player/qml/controlbarcontrols/ProgramButton.qml</file>
         <file alias="QuitButton.qml">player/qml/controlbarcontrols/QuitButton.qml</file>
         <file alias="RandomButton.qml">player/qml/controlbarcontrols/RandomButton.qml</file>
         <file alias="RendererButton.qml">player/qml/controlbarcontrols/RendererButton.qml</file>


=====================================
po/POTFILES.in
=====================================
@@ -875,6 +875,7 @@ modules/gui/qt/player/qml/controlbarcontrols/PlaybackSpeedButton.qml
 modules/gui/qt/player/qml/controlbarcontrols/PlayerSwitchButton.qml
 modules/gui/qt/player/qml/controlbarcontrols/PlaylistButton.qml
 modules/gui/qt/player/qml/controlbarcontrols/PreviousButton.qml
+modules/gui/qt/player/qml/controlbarcontrols/ProgramButton.qml
 modules/gui/qt/player/qml/controlbarcontrols/QuitButton.qml
 modules/gui/qt/player/qml/controlbarcontrols/RandomButton.qml
 modules/gui/qt/player/qml/controlbarcontrols/RecordButton.qml



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/72512a8494a7d5a7da60f0303f42122bf9360db2...78d3fb3833eda250a70b9114555a6e64857b116c

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/72512a8494a7d5a7da60f0303f42122bf9360db2...78d3fb3833eda250a70b9114555a6e64857b116c
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list