From e33072e93de71006c2530c2b3ffd7cbe8d7a5da1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Wed, 30 Sep 2020 08:46:41 +0100 Subject: [PATCH 1/3] Allow to show or hide menu items --- src/YQMenuBar.cc | 24 ++++++++++++++++++++++++ src/YQMenuBar.h | 9 ++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/YQMenuBar.cc b/src/YQMenuBar.cc index 6ffccfbe..a3cc5acd 100644 --- a/src/YQMenuBar.cc +++ b/src/YQMenuBar.cc @@ -197,6 +197,30 @@ YQMenuBar::setItemEnabled( YMenuItem * item, bool enabled ) } +void +YQMenuBar::setItemVisible( YMenuItem * item, bool visible ) +{ + QObject * qObj = static_cast( item->uiItem() ); + + if ( qObj ) + { + QMenu * menu = qobject_cast( qObj ); + + if ( menu ) + menu->menuAction()->setVisible( visible ); + else + { + QAction * action = qobject_cast( qObj ); + + if ( action ) + action->setVisible( visible ); + } + } + + YMenuWidget::setItemVisible( item, visible ); +} + + void YQMenuBar::setEnabled( bool enabled ) { diff --git a/src/YQMenuBar.h b/src/YQMenuBar.h index d8f88a3e..271c1355 100644 --- a/src/YQMenuBar.h +++ b/src/YQMenuBar.h @@ -52,7 +52,7 @@ class YQMenuBar : public QMenuBar, public YMenuBar /** * Rebuild the displayed menu tree from the internally stored YMenuItems. * - * Implemented from YMenuBar. + * Implemented from YMenuWidget. **/ virtual void rebuildMenuTree(); @@ -96,6 +96,13 @@ class YQMenuBar : public QMenuBar, public YMenuBar **/ virtual void setItemEnabled( YMenuItem * item, bool enabled ); + /** + * Show or hide an item. + * + * Reimplemented from YMenuWidget. + **/ + virtual void setItemVisible( YMenuItem * item, bool visible ); + /** * Activate the item selected in the tree. Can be used in tests to simulate * user input. From 00c5d6527ff96a43510e168ca6436d597b7766bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Wed, 30 Sep 2020 17:02:00 +0100 Subject: [PATCH 2/3] Add editorconfig --- .editorconfig | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..f3b50ac6 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +# https://EditorConfig.org -*- ini -*- +# This is a unified way to tell all your editors +# about the proper indentation style in this repo. +# +# Emacs: https://github.com/editorconfig/editorconfig-emacs#readme +# Vim: https://github.com/editorconfig/editorconfig-vim#readme +# VS Code: https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig + +# don't continue looking in upper directories, this is the top level +root = true + +[*.{h,cc}] +indent_style = tab +indent_size = 4 +tab_width = 8 From 87187129de5881d35a02ae35ebf2cfc2fc88dc90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Wed, 30 Sep 2020 17:02:18 +0100 Subject: [PATCH 3/3] Fix indentation --- src/YQMenuBar.cc | 78 ++++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/src/YQMenuBar.cc b/src/YQMenuBar.cc index a3cc5acd..c80c5c2c 100644 --- a/src/YQMenuBar.cc +++ b/src/YQMenuBar.cc @@ -73,19 +73,19 @@ YQMenuBar::rebuildMenuTree() for ( YItemIterator it = itemsBegin(); it != itemsEnd(); ++it ) { YMenuItem * item = dynamic_cast( *it ); - YUI_CHECK_PTR( item ); + YUI_CHECK_PTR( item ); - if ( ! item->isMenu() ) - YUI_THROW( YUIException( "YQMenuBar: Only menus allowed on toplevel." ) ); + if ( ! item->isMenu() ) + YUI_THROW( YUIException( "YQMenuBar: Only menus allowed on toplevel." ) ); - QMenu * menu = QMenuBar::addMenu( fromUTF8( item->label() )); - item->setUiItem( menu ); + QMenu * menu = QMenuBar::addMenu( fromUTF8( item->label() )); + item->setUiItem( menu ); - connect( menu, &pclass(menu)::triggered, - this, &pclass(this)::menuEntryActivated ); + connect( menu, &pclass(menu)::triggered, + this, &pclass(this)::menuEntryActivated ); - // Recursively add menu content - rebuildMenuTree( menu, item->childrenBegin(), item->childrenEnd() ); + // Recursively add menu content + rebuildMenuTree( menu, item->childrenBegin(), item->childrenEnd() ); } } @@ -96,20 +96,20 @@ YQMenuBar::rebuildMenuTree( QMenu * parentMenu, YItemIterator begin, YItemIterat for ( YItemIterator it = begin; it != end; ++it ) { YMenuItem * item = dynamic_cast( *it ); - YUI_CHECK_PTR( item ); + YUI_CHECK_PTR( item ); QIcon icon; if ( item->hasIconName() ) icon = YQUI::ui()->loadIcon( item->iconName() ); - if ( item->isSeparator() ) - { - parentMenu->addSeparator(); - } + if ( item->isSeparator() ) + { + parentMenu->addSeparator(); + } else if ( item->isMenu() ) { QMenu * subMenu = parentMenu->addMenu( fromUTF8( item->label() )); - item->setUiItem( subMenu ); + item->setUiItem( subMenu ); if ( ! icon.isNull() ) subMenu->setIcon( icon ); @@ -121,12 +121,12 @@ YQMenuBar::rebuildMenuTree( QMenu * parentMenu, YItemIterator begin, YItemIterat } else // Plain menu item (leaf item) { - QAction * action = parentMenu->addAction( fromUTF8( item->label() ) ); - item->setUiItem( action ); - _actionMap[ action ] = item; + QAction * action = parentMenu->addAction( fromUTF8( item->label() ) ); + item->setUiItem( action ); + _actionMap[ action ] = item; - if ( ! icon.isNull() ) - action->setIcon( icon ); + if ( ! icon.isNull() ) + action->setIcon( icon ); } } } @@ -136,11 +136,11 @@ void YQMenuBar::menuEntryActivated( QAction * action ) { if ( _actionMap.contains( action ) ) - _selectedItem = _actionMap[ action ]; + _selectedItem = _actionMap[ action ]; if ( _selectedItem ) { - // yuiDebug() << "Selected menu entry \"" << fromUTF8( _selectedItem->label() ) << "\"" << endl; + // yuiDebug() << "Selected menu entry \"" << fromUTF8( _selectedItem->label() ) << "\"" << endl; /* * Defer the real returnNow() until all popup related events have been @@ -180,17 +180,17 @@ YQMenuBar::setItemEnabled( YMenuItem * item, bool enabled ) if ( qObj ) { - QMenu * menu = qobject_cast( qObj ); + QMenu * menu = qobject_cast( qObj ); - if ( menu ) - menu->setEnabled( enabled ); - else - { - QAction * action = qobject_cast( qObj ); + if ( menu ) + menu->setEnabled( enabled ); + else + { + QAction * action = qobject_cast( qObj ); - if ( action ) - action->setEnabled( enabled ); - } + if ( action ) + action->setEnabled( enabled ); + } } YMenuWidget::setItemEnabled( item, enabled ); @@ -204,17 +204,17 @@ YQMenuBar::setItemVisible( YMenuItem * item, bool visible ) if ( qObj ) { - QMenu * menu = qobject_cast( qObj ); + QMenu * menu = qobject_cast( qObj ); - if ( menu ) + if ( menu ) menu->menuAction()->setVisible( visible ); - else - { - QAction * action = qobject_cast( qObj ); + else + { + QAction * action = qobject_cast( qObj ); - if ( action ) + if ( action ) action->setVisible( visible ); - } + } } YMenuWidget::setItemVisible( item, visible ); @@ -260,7 +260,7 @@ void YQMenuBar::activateItem( YMenuItem * item ) { if ( item ) - YQUI::ui()->sendEvent( new YMenuEvent( item ) ); + YQUI::ui()->sendEvent( new YMenuEvent( item ) ); }