[vlc-commits] [Git][videolan/vlc][master] 4 commits: qt: remove garbage code in SortMenu::popup()
Steve Lhomme (@robUx4)
gitlab at videolan.org
Sun Oct 22 07:52:02 UTC 2023
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
60fd81da by Fatih Uzunoglu at 2023-10-22T07:32:45+00:00
qt: remove garbage code in SortMenu::popup()
- - - - -
e94d7856 by Fatih Uzunoglu at 2023-10-22T07:32:45+00:00
qt: add `shown` property to SortMenu and QmlGlobalMenu
- - - - -
93c4b1e4 by Fatih Uzunoglu at 2023-10-22T07:32:45+00:00
qml: set global menu button checked when menu is shown
- - - - -
1035ce7d by Fatih Uzunoglu at 2023-10-22T07:32:45+00:00
qml: set SortControl checked when menu is shown
- - - - -
6 changed files:
- modules/gui/qt/maininterface/qml/BannerSources.qml
- modules/gui/qt/menus/qml_menu_wrapper.cpp
- modules/gui/qt/menus/qml_menu_wrapper.hpp
- modules/gui/qt/player/qml/TopBar.qml
- modules/gui/qt/player/qml/controlbarcontrols/MenuButton.qml
- modules/gui/qt/widgets/qml/SortControl.qml
Changes:
=====================================
modules/gui/qt/maininterface/qml/BannerSources.qml
=====================================
@@ -452,6 +452,7 @@ T.ToolBar {
text: I18n.qtr("Menu")
width: VLCStyle.bannerButton_width
height: VLCStyle.bannerButton_height
+ checked: contextMenu.shown
onClicked: contextMenu.popup(this.mapToGlobal(0, height))
=====================================
modules/gui/qt/menus/qml_menu_wrapper.cpp
=====================================
@@ -89,6 +89,15 @@ void SortMenu::popup(const QPoint &point, const bool popupAbovePoint, const QVar
{
m_menu = std::make_unique<QMenu>();
+ connect( m_menu.get(), &QMenu::aboutToShow, this, [this]() {
+ m_shown = true;
+ shownChanged();
+ } );
+ connect( m_menu.get(), &QMenu::aboutToHide, this, [this]() {
+ m_shown = false;
+ shownChanged();
+ } );
+
// model => [{text: "", checked: <bool>, order: <sort order> if checked else <invalid>}...]
for (int i = 0; i != model.size(); ++i)
{
@@ -111,14 +120,10 @@ void SortMenu::popup(const QPoint &point, const bool popupAbovePoint, const QVar
onPopup(m_menu.get());
- // m_menu->height() returns invalid height until initial popup call
- // so in case of 'popupAbovePoint', first show the menu and then reposition it
- m_menu->popup(point);
if (popupAbovePoint)
- {
- // use 'popup' instead of 'move' so that menu can reposition itself if it's parts are hidden
- m_menu->popup(QPoint(point.x(), point.y() - m_menu->height()));
- }
+ m_menu->popup(QPoint(point.x(), point.y() - m_menu->sizeHint().height()));
+ else
+ m_menu->popup(point);
}
void SortMenu::close()
@@ -196,8 +201,16 @@ void QmlGlobalMenu::popup(QPoint pos)
m_menu = std::make_unique<QMenu>();
QMenu* submenu;
- connect( m_menu.get(), &QMenu::aboutToShow, this, &QmlGlobalMenu::aboutToShow );
- connect( m_menu.get(), &QMenu::aboutToHide, this, &QmlGlobalMenu::aboutToHide );
+ connect( m_menu.get(), &QMenu::aboutToShow, this, [this]() {
+ m_shown = true;
+ shownChanged();
+ aboutToShow();
+ });
+ connect( m_menu.get(), &QMenu::aboutToHide, this, [this]() {
+ m_shown = false;
+ shownChanged();
+ aboutToHide();
+ });
submenu = m_menu->addMenu(qtr( "&Media" ));
FileMenu( p_intf, submenu );
=====================================
modules/gui/qt/menus/qml_menu_wrapper.hpp
=====================================
@@ -67,6 +67,8 @@ class SortMenu : public QObject
{
Q_OBJECT
+ Q_PROPERTY(bool shown READ isShown NOTIFY shownChanged FINAL)
+
public:
using QObject::QObject;
@@ -74,14 +76,18 @@ public:
Q_INVOKABLE void close();
+ bool isShown() const { return m_shown; };
+
protected:
virtual void onPopup(QMenu * menu);
signals:
void selected(int index);
+ void shownChanged();
private:
std::unique_ptr<QMenu> m_menu;
+ bool m_shown = false;
};
class SortMenuVideo : public SortMenu
@@ -102,17 +108,24 @@ class QmlGlobalMenu : public VLCMenuBar
{
Q_OBJECT
SIMPLE_MENU_PROPERTY(MainCtx*, ctx, nullptr)
+
+ Q_PROPERTY(bool shown READ isShown NOTIFY shownChanged FINAL)
+
public:
explicit QmlGlobalMenu(QObject *parent = nullptr);
+ bool isShown() const { return m_shown; };
+
signals:
void aboutToShow();
void aboutToHide();
+ void shownChanged();
public slots:
void popup( QPoint pos );
private:
std::unique_ptr<QMenu> m_menu;
+ bool m_shown = false;
};
//inherit VLCMenuBar so we can access menu creation functions
=====================================
modules/gui/qt/player/qml/TopBar.qml
=====================================
@@ -425,6 +425,7 @@ FocusScope{
iconText: VLCIcons.more
text: I18n.qtr("Menu")
+ checked: contextMenu.shown
Navigation.parentItem: root
Navigation.leftItem: backBtn
=====================================
modules/gui/qt/player/qml/controlbarcontrols/MenuButton.qml
=====================================
@@ -30,6 +30,7 @@ Widgets.IconControlButton {
iconText: VLCIcons.ellipsis
text: I18n.qtr("Menu")
+ checked: contextMenu.shown
onClicked: contextMenu.popup(this.mapToGlobal(0, 0))
=====================================
modules/gui/qt/widgets/qml/SortControl.qml
=====================================
@@ -64,6 +64,8 @@ Widgets.IconToolButton {
iconText: VLCIcons.topbar_sort
+ checked: _menu && _menu.shown
+
Keys.priority: Keys.AfterItem
Keys.onPressed: Navigation.defaultKeyAction(event)
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/1606e027532c0141c93d9f7e7637f42e5f54ead4...1035ce7dd43e0b18b7a03d0ba52146687a684710
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/1606e027532c0141c93d9f7e7637f42e5f54ead4...1035ce7dd43e0b18b7a03d0ba52146687a684710
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