[vlc-commits] [Git][videolan/vlc][master] 6 commits: qt: set parent of the menu in `ExpertPrefsTable::contextMenuEvent()`
Steve Lhomme (@robUx4)
gitlab at videolan.org
Fri Jul 26 09:08:32 UTC 2024
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
208acf92 by Fatih Uzunoglu at 2024-07-26T08:47:49+00:00
qt: set parent of the menu in `ExpertPrefsTable::contextMenuEvent()`
- - - - -
b36c98bf by Fatih Uzunoglu at 2024-07-26T08:47:49+00:00
qt: set parent of the menu in `KeySelectorControl::tableContextMenuEvent()`
- - - - -
0aa19345 by Fatih Uzunoglu at 2024-07-26T08:47:49+00:00
qt: introduce `VLCMenu`
... which sets the transient parent if the menu is a window
automatically.
- - - - -
e32a67e4 by Fatih Uzunoglu at 2024-07-26T08:47:49+00:00
qt: use `VLCMenu` instead of parentless `QMenu` in `MainCtx::createSystray()`
- - - - -
8a870e79 by Fatih Uzunoglu at 2024-07-26T08:47:49+00:00
qt: use `VLCMenu` instead of parentless `QMenu` in menus.cpp
- - - - -
05ba33bc by Fatih Uzunoglu at 2024-07-26T08:47:49+00:00
qt: use `VLCMenu` instead of parentless `QMenu` in `qml_menu_wrapper`
- - - - -
17 changed files:
- modules/gui/qt/dialogs/preferences/expert_view.cpp
- modules/gui/qt/dialogs/preferences/preferences_widgets.cpp
- modules/gui/qt/dialogs/preferences/preferences_widgets.hpp
- modules/gui/qt/maininterface/mainctx.cpp
- modules/gui/qt/medialibrary/qml/PlaylistMediaDisplay.qml
- modules/gui/qt/menus/menus.cpp
- modules/gui/qt/menus/menus.hpp
- modules/gui/qt/menus/qml_menu_wrapper.cpp
- modules/gui/qt/menus/qml_menu_wrapper.hpp
- modules/gui/qt/network/qml/BrowseDisplay.qml
- modules/gui/qt/network/qml/NetworkAddressbar.qml
- modules/gui/qt/network/qml/ServicesHomeDisplay.qml
- modules/gui/qt/player/qml/TracksListPage.qml
- modules/gui/qt/player/qml/controlbarcontrols/ProgramButton.qml
- modules/gui/qt/playlist/qml/PlaylistListView.qml
- modules/gui/qt/util/qml/NativeMenu.qml
- modules/gui/qt/widgets/qml/SortControl.qml
Changes:
=====================================
modules/gui/qt/dialogs/preferences/expert_view.cpp
=====================================
@@ -107,7 +107,7 @@ void ExpertPrefsTable::contextMenuEvent( QContextMenuEvent *event )
ExpertPrefsTableItem *item = myModel()->itemAt( index );
- QMenu *menu = new QMenu();
+ QMenu *menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose);
if( CONFIG_CLASS( item->getType() ) == CONFIG_ITEM_BOOL )
=====================================
modules/gui/qt/dialogs/preferences/preferences_widgets.cpp
=====================================
@@ -1508,7 +1508,7 @@ bool KeySelectorControl::eventFilter( QObject *obj, QEvent *e )
#ifndef QT_NO_CONTEXTMENU
if( obj == table && e->type() == QEvent::ContextMenu )
{
- tableContextMenuEvent( static_cast<QContextMenuEvent*>(e) );
+ tableContextMenuEvent( table, static_cast<QContextMenuEvent*>(e) );
return true;
}
#endif
@@ -1538,7 +1538,7 @@ bool KeySelectorControl::eventFilter( QObject *obj, QEvent *e )
}
#ifndef QT_NO_CONTEXTMENU
-void KeySelectorControl::tableContextMenuEvent( QContextMenuEvent *event )
+void KeySelectorControl::tableContextMenuEvent( QWidget *widget, QContextMenuEvent *event )
{
KeyTableItem *item = static_cast<KeyTableItem *>( this->table->currentItem() );
if( !item || item->isHidden() )
@@ -1570,7 +1570,8 @@ void KeySelectorControl::tableContextMenuEvent( QContextMenuEvent *event )
unreachable();
}
- QMenu *menu = new QMenu();
+ assert(widget);
+ QMenu *menu = new QMenu(widget);
menu->setAttribute(Qt::WA_DeleteOnClose);
QAction *modify = new QAction( qtr( "&Modify" ), this->table );
=====================================
modules/gui/qt/dialogs/preferences/preferences_widgets.hpp
=====================================
@@ -435,7 +435,7 @@ public:
protected:
bool eventFilter( QObject *, QEvent * ) override;
#ifndef QT_NO_CONTEXTMENU
- void tableContextMenuEvent( QContextMenuEvent * );
+ void tableContextMenuEvent( QWidget *, QContextMenuEvent * );
#endif
void changeVisibility( bool ) override;
void unset( KeyTableItem *, enum ColumnIndex );
=====================================
modules/gui/qt/maininterface/mainctx.cpp
=====================================
@@ -660,7 +660,7 @@ void MainCtx::createSystray()
sysTray = new QSystemTrayIcon( iconVLC, this );
sysTray->setToolTip( qtr( "VLC media player" ));
- systrayMenu = std::make_unique<QMenu>( qtr( "VLC media player") );
+ systrayMenu = std::make_unique<VLCMenu>( qtr( "VLC media player"), p_intf );
systrayMenu->setIcon( iconVLC );
VLCMenuBar::updateSystrayMenu( this, p_intf, true );
=====================================
modules/gui/qt/medialibrary/qml/PlaylistMediaDisplay.qml
=====================================
@@ -181,6 +181,7 @@ FocusScope {
id: contextMenu
model: root.model
+ ctx: MainCtx
}
PlaylistMedia
=====================================
modules/gui/qt/menus/menus.cpp
=====================================
@@ -700,7 +700,7 @@ void VLCMenuBar::PopupMenuStaticEntries( QMenu *menu )
/* Video Tracks and Subtitles tracks */
QMenu* VLCMenuBar::VideoPopupMenu( qt_intf_t *p_intf, bool show )
{
- QMenu* menu = new QMenu();
+ QMenu* menu = new VLCMenu(p_intf);
VideoMenu(p_intf, menu);
if( show )
menu->popup( QCursor::pos() );
@@ -710,7 +710,7 @@ QMenu* VLCMenuBar::VideoPopupMenu( qt_intf_t *p_intf, bool show )
/* Audio Tracks */
QMenu* VLCMenuBar::AudioPopupMenu( qt_intf_t *p_intf, bool show )
{
- QMenu* menu = new QMenu();
+ QMenu* menu = new VLCMenu(p_intf);
AudioMenu(p_intf, menu);
if( show )
menu->popup( QCursor::pos() );
@@ -720,7 +720,7 @@ QMenu* VLCMenuBar::AudioPopupMenu( qt_intf_t *p_intf, bool show )
/* Navigation stuff, and general menus ( open ), used only for skins */
QMenu* VLCMenuBar::MiscPopupMenu( qt_intf_t *p_intf, bool show )
{
- QMenu* menu = new QMenu();
+ QMenu* menu = new VLCMenu(p_intf);
menu->addSeparator();
PopupMenuPlaylistEntries( menu, p_intf );
@@ -740,7 +740,7 @@ QMenu* VLCMenuBar::MiscPopupMenu( qt_intf_t *p_intf, bool show )
QMenu* VLCMenuBar::PopupMenu( qt_intf_t *p_intf, bool show )
{
/* */
- QMenu* menu = new QMenu();
+ QMenu* menu = new VLCMenu(p_intf);
input_item_t* p_input = THEMIM->getInput();
QAction *action;
bool b_isFullscreen = false;
=====================================
modules/gui/qt/menus/menus.hpp
=====================================
@@ -27,9 +27,33 @@
#include "qt.hpp"
#include "custom_menus.hpp"
+#include "widgets/native/qvlcframe.hpp"
#include <QObject>
+class VLCMenu : public QMenu
+{
+ Q_OBJECT
+
+public:
+ explicit VLCMenu(qt_intf_t* p_intf) : QMenu()
+ {
+ assert(p_intf);
+ if (isWindow())
+ QVLCDialog::setWindowTransientParent(this, nullptr, p_intf);
+ }
+
+ explicit VLCMenu(const QString& title, qt_intf_t* p_intf) : VLCMenu(p_intf)
+ {
+ setTitle(title);
+ }
+
+ explicit VLCMenu(const QString &title, QWidget *parent) : QMenu(title, parent)
+ {
+ assert(parent); // use VLCMenu(qt_intf_t* p_intf) if parent is null pointer
+ }
+};
+
class VLCMenuBar : public QObject
{
Q_OBJECT
=====================================
modules/gui/qt/menus/qml_menu_wrapper.cpp
=====================================
@@ -68,7 +68,8 @@ namespace
void StringListMenu::popup(const QPoint &point, const QVariantList &stringList)
{
- QMenu *m = new QMenu;
+ assert(m_ctx);
+ QMenu *m = new VLCMenu(m_ctx->getIntf());
m->setAttribute(Qt::WA_DeleteOnClose);
for (int i = 0; i != stringList.size(); ++i)
@@ -87,7 +88,8 @@ void StringListMenu::popup(const QPoint &point, const QVariantList &stringList)
void SortMenu::popup(const QPoint &point, const bool popupAbovePoint, const QVariantList &model)
{
- m_menu = std::make_unique<QMenu>();
+ assert(m_ctx);
+ m_menu = std::make_unique<VLCMenu>(m_ctx->getIntf());
connect( m_menu.get(), &QMenu::aboutToShow, this, [this]() {
m_shown = true;
@@ -198,7 +200,7 @@ void QmlGlobalMenu::popup(QPoint pos)
if (!p_intf)
return;
- m_menu = std::make_unique<QMenu>();
+ m_menu = std::make_unique<VLCMenu>(m_ctx->getIntf());
QMenu* submenu;
connect( m_menu.get(), &QMenu::aboutToShow, this, [this]() {
@@ -438,7 +440,7 @@ bool QmlMenuPositioner::eventFilter(QObject * object, QEvent * event)
if (m_ctx == nullptr || m_player == nullptr)
return;
- m_menu = std::make_unique<QMenu>();
+ m_menu = std::make_unique<VLCMenu>(m_ctx->getIntf());
connect(m_menu.get(), &QMenu::aboutToHide, this, &QmlBookmarkMenu::aboutToHide);
connect(m_menu.get(), &QMenu::aboutToShow, this, &QmlBookmarkMenu::aboutToShow);
@@ -521,10 +523,11 @@ bool QmlMenuPositioner::eventFilter(QObject * object, QEvent * event)
/* Q_INVOKABLE */ void QmlProgramMenu::popup(const QPoint & position, bool above)
{
+ assert(m_ctx);
if (m_player == nullptr)
return;
- m_menu = std::make_unique<QMenu>();
+ m_menu = std::make_unique<VLCMenu>(m_ctx->getIntf());
connect(m_menu.get(), &QMenu::aboutToHide, this, &QmlProgramMenu::aboutToHide);
connect(m_menu.get(), &QMenu::aboutToShow, this, &QmlProgramMenu::aboutToShow);
@@ -574,7 +577,8 @@ bool QmlMenuPositioner::eventFilter(QObject * object, QEvent * event)
/* Q_INVOKABLE */ void QmlTrackMenu::popup(const QPoint & position)
{
- m_menu = std::make_unique<QMenu>();
+ assert(m_ctx);
+ m_menu = std::make_unique<VLCMenu>(m_ctx->getIntf());
beforePopup(m_menu.get());
@@ -648,6 +652,8 @@ PlaylistListContextMenu::PlaylistListContextMenu(QObject * parent)
void PlaylistListContextMenu::popup(const QModelIndexList & selected, QPoint pos, QVariantMap)
{
+ assert(m_ctx);
+
if (!m_model)
return;
@@ -656,7 +662,7 @@ void PlaylistListContextMenu::popup(const QModelIndexList & selected, QPoint pos
for (const QModelIndex & modelIndex : selected)
ids.push_back(m_model->data(modelIndex, MLPlaylistListModel::PLAYLIST_ID));
- m_menu = std::make_unique<QMenu>();
+ m_menu = std::make_unique<VLCMenu>(m_ctx->getIntf());
MediaLib * ml = m_model->ml();
@@ -701,6 +707,8 @@ PlaylistMediaContextMenu::PlaylistMediaContextMenu(QObject * parent) : QObject(p
void PlaylistMediaContextMenu::popup(const QModelIndexList & selected, QPoint pos,
QVariantMap options)
{
+ assert(m_ctx);
+
if (!m_model)
return;
@@ -709,7 +717,7 @@ void PlaylistMediaContextMenu::popup(const QModelIndexList & selected, QPoint po
for (const QModelIndex& modelIndex : selected)
ids.push_back(m_model->data(modelIndex, MLPlaylistModel::MEDIA_ID));
- m_menu = std::make_unique<QMenu>();
+ m_menu = std::make_unique<VLCMenu>(m_ctx->getIntf());
MediaLib * ml = m_model->ml();
@@ -770,10 +778,12 @@ NetworkMediaContextMenu::NetworkMediaContextMenu(QObject* parent)
void NetworkMediaContextMenu::popup(const QModelIndexList& selected, QPoint pos)
{
+ assert(m_ctx);
+
if (!m_model)
return;
- m_menu = std::make_unique<QMenu>();
+ m_menu = std::make_unique<VLCMenu>(m_ctx->getIntf());
QAction* action;
action = m_menu->addAction( qtr("Add and play") );
@@ -825,10 +835,12 @@ NetworkDeviceContextMenu::NetworkDeviceContextMenu(QObject* parent)
void NetworkDeviceContextMenu::popup(const QModelIndexList& selected, QPoint pos)
{
+ assert(m_ctx);
+
if (!m_model)
return;
- m_menu = std::make_unique<QMenu>();
+ m_menu = std::make_unique<VLCMenu>(m_ctx->getIntf());
QAction* action;
action = m_menu->addAction( qtr("Add and play") );
@@ -850,10 +862,12 @@ PlaylistContextMenu::PlaylistContextMenu(QObject* parent)
void PlaylistContextMenu::popup(int selectedIndex, QPoint pos )
{
+ assert(m_ctx);
+
if (!m_controler || !m_model || !m_selectionModel)
return;
- m_menu = std::make_unique<QMenu>();
+ m_menu = std::make_unique<VLCMenu>(m_ctx->getIntf());
QAction* action;
QList<QUrl> selectedUrlList;
=====================================
modules/gui/qt/menus/qml_menu_wrapper.hpp
=====================================
@@ -52,7 +52,7 @@ class PlaylistListModel;
public: \
inline void set##name( type data) { m_##name = data; } \
inline type get##name() const { return m_##name; } \
- private: \
+ protected: \
type m_##name = defaultValue;
@@ -60,6 +60,8 @@ class StringListMenu : public QObject
{
Q_OBJECT
+ SIMPLE_MENU_PROPERTY(MainCtx *, ctx, nullptr)
+
public:
using QObject::QObject;
@@ -74,6 +76,8 @@ class SortMenu : public QObject
{
Q_OBJECT
+ SIMPLE_MENU_PROPERTY(MainCtx *, ctx, nullptr)
+
Q_PROPERTY(bool shown READ isShown NOTIFY shownChanged FINAL)
public:
@@ -101,8 +105,6 @@ class SortMenuVideo : public SortMenu
{
Q_OBJECT
- SIMPLE_MENU_PROPERTY(MainCtx *, ctx, nullptr)
-
protected: // SortMenu reimplementation
void onPopup(QMenu * menu) override;
@@ -232,6 +234,7 @@ class QmlProgramMenu : public QObject
{
Q_OBJECT
+ SIMPLE_MENU_PROPERTY(MainCtx *, ctx, nullptr)
SIMPLE_MENU_PROPERTY(PlayerController *, player, nullptr)
public:
@@ -278,6 +281,8 @@ class QmlTrackMenu : public QObject
{
Q_OBJECT
+ SIMPLE_MENU_PROPERTY(MainCtx *, ctx, nullptr)
+
public: // Enums
enum Action
{
@@ -330,6 +335,8 @@ protected: // QmlTrackMenu implementation
class PlaylistListContextMenu : public QObject {
Q_OBJECT
+
+ SIMPLE_MENU_PROPERTY(MainCtx *, ctx, nullptr)
SIMPLE_MENU_PROPERTY(MLPlaylistListModel *, model, nullptr)
public:
PlaylistListContextMenu(QObject * parent = nullptr);
@@ -343,6 +350,7 @@ private:
class PlaylistMediaContextMenu : public QObject {
Q_OBJECT
SIMPLE_MENU_PROPERTY(MLPlaylistModel *, model, nullptr)
+ SIMPLE_MENU_PROPERTY(MainCtx *, ctx, nullptr)
public:
PlaylistMediaContextMenu(QObject * parent = nullptr);
@@ -357,6 +365,7 @@ private:
class NetworkMediaContextMenu : public QObject {
Q_OBJECT
SIMPLE_MENU_PROPERTY(NetworkMediaModel*, model, nullptr)
+ SIMPLE_MENU_PROPERTY(MainCtx *, ctx, nullptr)
public:
NetworkMediaContextMenu(QObject* parent = nullptr);
@@ -369,6 +378,7 @@ private:
class NetworkDeviceContextMenu : public QObject {
Q_OBJECT
SIMPLE_MENU_PROPERTY(NetworkDeviceModel*, model, nullptr)
+ SIMPLE_MENU_PROPERTY(MainCtx *, ctx, nullptr)
public:
NetworkDeviceContextMenu(QObject* parent = nullptr);
public slots:
@@ -382,6 +392,7 @@ class PlaylistContextMenu : public QObject {
SIMPLE_MENU_PROPERTY(vlc::playlist::PlaylistListModel*, model, nullptr)
SIMPLE_MENU_PROPERTY(vlc::playlist::PlaylistController*, controler, nullptr)
SIMPLE_MENU_PROPERTY(ListSelectionModel*, selectionModel, nullptr)
+ SIMPLE_MENU_PROPERTY(MainCtx *, ctx, nullptr)
public:
PlaylistContextMenu(QObject* parent = nullptr);
=====================================
modules/gui/qt/network/qml/BrowseDisplay.qml
=====================================
@@ -169,6 +169,7 @@ Widgets.PageLoader {
contextMenu: NetworkMediaContextMenu {
model: mediaModel
+ ctx: MainCtx
}
Navigation.cancelAction: function() {
=====================================
modules/gui/qt/network/qml/NetworkAddressbar.qml
=====================================
@@ -207,6 +207,8 @@ T.Control {
StringListMenu {
id: popup
+ ctx: MainCtx
+
function show() {
const model = control._menuModel.map(function (modelData) {
return modelData.display
=====================================
modules/gui/qt/network/qml/ServicesHomeDisplay.qml
=====================================
@@ -111,6 +111,7 @@ Widgets.PageLoader {
id: contextMenu
model: deviceModel
+ ctx: MainCtx
}
}
}
@@ -150,6 +151,7 @@ Widgets.PageLoader {
contextMenu: NetworkMediaContextMenu {
model: mediaModel
+ ctx: MainCtx
}
}
}
=====================================
modules/gui/qt/player/qml/TracksListPage.qml
=====================================
@@ -254,6 +254,7 @@ RowLayout {
id: menuSubtitle
player: Player
+ ctx: MainCtx
onTriggered: {
if (action === QmlSubtitleMenu.Open) {
@@ -271,6 +272,8 @@ RowLayout {
QmlAudioMenu {
id: menuAudio
+ ctx: MainCtx
+
onTriggered: {
if (action === QmlSubtitleMenu.Open) {
DialogsProvider.loadAudioFile()
=====================================
modules/gui/qt/player/qml/controlbarcontrols/ProgramButton.qml
=====================================
@@ -43,6 +43,7 @@ Widgets.IconToolButton {
id: menu
player: Player
+ ctx: MainCtx
onAboutToShow: root.requestLockUnlockAutoHide(true)
onAboutToHide: root.requestLockUnlockAutoHide(false)
=====================================
modules/gui/qt/playlist/qml/PlaylistListView.qml
=====================================
@@ -134,6 +134,7 @@ T.Pane {
model: root.model
selectionModel: root.selectionModel
controler: MainPlaylistController
+ ctx: MainCtx
onJumpToCurrentPlaying: listView.positionViewAtIndex( MainPlaylistController.currentIndex, ItemView.Center)
}
=====================================
modules/gui/qt/util/qml/NativeMenu.qml
=====================================
@@ -100,6 +100,8 @@ QtObject {
readonly property StringListMenu _menu: StringListMenu {
id: menu
+ ctx: MainCtx
+
onSelected: (index, _) => {
root._executeAction(index)
}
=====================================
modules/gui/qt/widgets/qml/SortControl.qml
=====================================
@@ -120,7 +120,10 @@ Widgets.IconToolButton {
// Children
- SortMenu { id: sortMenu }
+ SortMenu {
+ id: sortMenu
+ ctx: MainCtx
+ }
}
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/4d920c8ff72cd9964a945f5b186cf098a7c1f28e...05ba33bcc7f18407f3f9263400123b84228eb67f
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/4d920c8ff72cd9964a945f5b186cf098a7c1f28e...05ba33bcc7f18407f3f9263400123b84228eb67f
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