From 95686ea63036db98635fd7061f17f6dad23afee2 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Wed, 5 Oct 2022 22:27:13 +0200 Subject: [PATCH] Modified 'close all except/left/right' to be effective on the tab the mouse points at. --- src/lay/lay/layMacroEditorDialog.cc | 20 ++++++--- src/lay/lay/layMacroEditorDialog.h | 3 +- src/lay/lay/layMainWindow.cc | 66 ++++++++++++----------------- src/lay/lay/layMainWindow.h | 7 ++- 4 files changed, 45 insertions(+), 51 deletions(-) diff --git a/src/lay/lay/layMacroEditorDialog.cc b/src/lay/lay/layMacroEditorDialog.cc index 1d8694110..8b50c5cd9 100644 --- a/src/lay/lay/layMacroEditorDialog.cc +++ b/src/lay/lay/layMacroEditorDialog.cc @@ -397,8 +397,8 @@ MacroEditorDialog::MacroEditorDialog (lay::Dispatcher *pr, lym::MacroCollection QAction *action = new QAction (tr ("Close All"), this); connect (action, SIGNAL (triggered ()), this, SLOT (close_all ())); tabWidget->addAction (action); - action = new QAction (tr ("Close All Except Current"), this); - connect (action, SIGNAL (triggered ()), this, SLOT (close_all_but_current ())); + action = new QAction (tr ("Close All Except This"), this); + connect (action, SIGNAL (triggered ()), this, SLOT (close_all_but_this ())); tabWidget->addAction (action); action = new QAction (tr ("Close All Left"), this); connect (action, SIGNAL (triggered ()), this, SLOT (close_all_left ())); @@ -474,6 +474,8 @@ MacroEditorDialog::MacroEditorDialog (lay::Dispatcher *pr, lym::MacroCollection connect (replaceAllButton, SIGNAL (clicked ()), this, SLOT (replace_all_button_clicked ())); connect (allVariables, SIGNAL (clicked (bool)), variableList, SLOT (set_show_all (bool))); + tabWidget->installEventFilter (this); + splitter->setCollapsible (1, false); replaceFrame->hide (); @@ -1541,7 +1543,13 @@ MacroEditorDialog::eventFilter (QObject *obj, QEvent *event) } - } + } else if (obj == tabWidget->tabBar () && dynamic_cast (event) != 0) { + + // just spy on the events, don't eat them + QMouseEvent *mouse_event = dynamic_cast (event); + m_mouse_pos = mouse_event->pos (); + + } return false; } @@ -2269,7 +2277,7 @@ END_PROTECTED } void -MacroEditorDialog::close_all_but_current () +MacroEditorDialog::close_all_but_this () { close_many (0); } @@ -2295,10 +2303,8 @@ MacroEditorDialog::close_many (int r2c) BEGIN_PROTECTED - int ci = tabWidget->currentIndex (); - + int ci = tabWidget->tabBar ()->tabAt (m_mouse_pos); if (ci < 0) { - close_all (); return; } diff --git a/src/lay/lay/layMacroEditorDialog.h b/src/lay/lay/layMacroEditorDialog.h index eec5e0f24..bfb45f24d 100644 --- a/src/lay/lay/layMacroEditorDialog.h +++ b/src/lay/lay/layMacroEditorDialog.h @@ -213,7 +213,7 @@ private slots: void search_finished (); void tab_close_requested (int); void close_all (); - void close_all_but_current (); + void close_all_but_this (); void close_all_left (); void close_all_right (); void replace_mode_button_clicked (); @@ -306,6 +306,7 @@ private: lay::Dispatcher *mp_plugin_root; lym::MacroCollection *mp_root; bool m_first_show; + QPoint m_mouse_pos; bool m_debugging_on; lym::Macro *mp_run_macro; std::vector m_macro_templates; diff --git a/src/lay/lay/layMainWindow.cc b/src/lay/lay/layMainWindow.cc index 202882ffc..470809b20 100644 --- a/src/lay/lay/layMainWindow.cc +++ b/src/lay/lay/layMainWindow.cc @@ -234,6 +234,7 @@ MainWindow::MainWindow (QApplication *app, const char *name, bool undo_enabled) EnhancedTabBar *enh_tab_widget = new EnhancedTabBar (mp_main_frame); mp_tab_bar = enh_tab_widget; + mp_tab_bar->installEventFilter (this); vbh_tab->addWidget (enh_tab_widget); vbh_tab->addWidget (enh_tab_widget->menu_button ()); @@ -248,8 +249,8 @@ MainWindow::MainWindow (QApplication *app, const char *name, bool undo_enabled) QAction *action = new QAction (tr ("Close All"), this); connect (action, SIGNAL (triggered ()), this, SLOT (close_all_views ())); mp_tab_bar->addAction (action); - action = new QAction (tr ("Close All Except Current"), this); - connect (action, SIGNAL (triggered ()), this, SLOT (close_all_except_current_view ())); + action = new QAction (tr ("Close All Except This"), this); + connect (action, SIGNAL (triggered ()), this, SLOT (close_all_except_this ())); mp_tab_bar->addAction (action); action = new QAction (tr ("Close All Left"), this); connect (action, SIGNAL (triggered ()), this, SLOT (close_all_views_left ())); @@ -2608,33 +2609,6 @@ MainWindow::cm_close_all () interactive_close_view (0, views (), false, false); } -void -MainWindow::cm_close_all_except_current () -{ - int current_index = index_of (lay::LayoutView::current ()); - if (current_index >= 0) { - interactive_close_view (current_index, current_index + 1, true, false); - } -} - -void -MainWindow::cm_close_all_left () -{ - int current_index = index_of (lay::LayoutView::current ()); - if (current_index >= 0) { - interactive_close_view (0, current_index, false, false); - } -} - -void -MainWindow::cm_close_all_right () -{ - int current_index = index_of (lay::LayoutView::current ()); - if (current_index >= 0) { - interactive_close_view (current_index + 1, views (), false, false); - } -} - void MainWindow::cm_close () { @@ -2865,21 +2839,30 @@ MainWindow::close_all_views () } void -MainWindow::close_all_except_current_view () +MainWindow::close_all_except_this () { - cm_close_all_except_current (); + int index = mp_tab_bar->tabAt (m_mouse_pos); + if (index >= 0) { + interactive_close_view (index, index + 1, true, false); + } } void MainWindow::close_all_views_left () { - cm_close_all_left (); + int index = mp_tab_bar->tabAt (m_mouse_pos); + if (index >= 0) { + interactive_close_view (0, index, false, false); + } } void MainWindow::close_all_views_right () { - cm_close_all_right (); + int index = mp_tab_bar->tabAt (m_mouse_pos); + if (index >= 0) { + interactive_close_view (index + 1, views (), false, false); + } } void @@ -3986,12 +3969,6 @@ MainWindow::menu_activated (const std::string &symbol) cm_clone (); } else if (symbol == "cm_close_all") { cm_close_all (); - } else if (symbol == "cm_close_all_left") { - cm_close_all_left (); - } else if (symbol == "cm_close_all_right") { - cm_close_all_right (); - } else if (symbol == "cm_close_all_except_current") { - cm_close_all_except_current (); } else if (symbol == "cm_close") { cm_close (); } else if (symbol == "cm_packages") { @@ -4058,6 +4035,17 @@ MainWindow::dragEnterEvent(QDragEnterEvent *event) } } +bool +MainWindow::eventFilter (QObject *watched, QEvent *event) +{ + // spy on the mouse events of the tab bar so we can tell which tab the menu was issued on + if (watched == mp_tab_bar && dynamic_cast (event) != 0) { + m_mouse_pos = dynamic_cast (event)->pos (); + } + + return QMainWindow::eventFilter (watched, event); +} + void MainWindow::dropEvent(QDropEvent *event) { diff --git a/src/lay/lay/layMainWindow.h b/src/lay/lay/layMainWindow.h index 01c44ff89..48c787f24 100644 --- a/src/lay/lay/layMainWindow.h +++ b/src/lay/lay/layMainWindow.h @@ -633,7 +633,7 @@ public slots: void close_current_view (); void close_view (int index); void close_all_views (); - void close_all_except_current_view (); + void close_all_except_this (); void close_all_views_left (); void close_all_views_right (); void clone (); @@ -680,6 +680,7 @@ protected: void update_content (); void do_update_menu (); void do_update_mru_menus (); + bool eventFilter (QObject *watched, QEvent *event); private: lay::Dispatcher m_dispatcher; @@ -688,6 +689,7 @@ private: // Main menu QTabBar *mp_tab_bar; + QPoint m_mouse_pos; QToolBar *mp_tool_bar; QDockWidget *mp_navigator_dock_widget; lay::Navigator *mp_navigator; @@ -793,9 +795,6 @@ private: void cm_new_layout (); void cm_clone (); void cm_close_all (); - void cm_close_all_except_current (); - void cm_close_all_left (); - void cm_close_all_right (); void cm_close (); void cm_packages (); void cm_technologies ();