Mercurial > hg > octave-jordi
changeset 20704:632683d6396f
provide actions for moving the editor tabs by shortscuts
* file-editor.cc (construct): use the new subclassed tab-widget, add the
actions for moving the tab left or right;
(set_shortcuts): set the shortcuts for the new actions;
(move_tab_left, move_tab_right): new slots for the actions;
(switch_tab): common slot, added boolean parameter for moving/switching;
* file-editor.h: new class tab_widget inheriting QTabWidget with usable
QTabBar, new actions and related slots, switch_tab with boolean parameter
* shortcut-manager.cc (do_init_data): init shortcuts for new move tab actions
author | Torsten <ttl@justmail.de> |
---|---|
date | Sun, 15 Nov 2015 14:24:38 +0100 |
parents | 571508c1ed06 |
children | fec7cc73507b |
files | libgui/src/m-editor/file-editor.cc libgui/src/m-editor/file-editor.h libgui/src/shortcut-manager.cc |
diffstat | 3 files changed, 61 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor.cc +++ b/libgui/src/m-editor/file-editor.cc @@ -1266,7 +1266,7 @@ #endif _tool_bar = new QToolBar (editor_widget); _tool_bar->setMovable (true); - _tab_widget = new QTabWidget (editor_widget); + _tab_widget = new tab_widget (editor_widget); _tab_widget->setTabsClosable (true); #ifdef HAVE_QTABWIDGET_SETMOVABLE _tab_widget->setMovable (true); @@ -1532,6 +1532,10 @@ SLOT (switch_left_tab ())); _switch_right_tab_action = add_action (0, QIcon (), "", SLOT (switch_right_tab ())); + _move_tab_left_action = add_action (0, QIcon (), "", + SLOT (move_tab_left ())); + _move_tab_right_action = add_action (0, QIcon (), "", + SLOT (move_tab_right ())); // toolbar @@ -1893,6 +1897,8 @@ // Tab navigation without menu entries shortcut_manager::set_shortcut (_switch_left_tab_action, "editor_tabs:switch_left_tab"); shortcut_manager::set_shortcut (_switch_right_tab_action, "editor_tabs:switch_right_tab"); + shortcut_manager::set_shortcut (_move_tab_left_action, "editor_tabs:move_tab_left"); + shortcut_manager::set_shortcut (_move_tab_right_action, "editor_tabs:move_tab_right"); } @@ -2033,19 +2039,44 @@ switch_tab (1); } void -file_editor::switch_tab (int direction) +file_editor::move_tab_left () +{ +#ifdef HAVE_QTABWIDGET_SETMOVABLE + switch_tab (-1, true); +#endif +} +void +file_editor::move_tab_right () +{ +#ifdef HAVE_QTABWIDGET_SETMOVABLE + switch_tab (1, true); +#endif +} +void +file_editor::switch_tab (int direction, bool move) { int tabs = _tab_widget->count (); if (tabs < 2) return; - int new_index = _tab_widget->currentIndex () + direction; + int old_pos = _tab_widget->currentIndex (); + int new_pos = _tab_widget->currentIndex () + direction; + + if (new_pos < 0 || new_pos >= tabs) + new_pos = new_pos - direction*tabs; - if (new_index < 0 || new_index >= tabs) - new_index = new_index - direction*tabs; - - _tab_widget->setCurrentIndex (new_index); + if (move) + { +#ifdef HAVE_QTABWIDGET_SETMOVABLE + _tab_widget->tabBar ()->moveTab (old_pos,new_pos); + _tab_widget->setCurrentIndex (old_pos); + _tab_widget->setCurrentIndex (new_pos); + focus (); +#endif + } + else + _tab_widget->setCurrentIndex (new_pos); } #endif
--- a/libgui/src/m-editor/file-editor.h +++ b/libgui/src/m-editor/file-editor.h @@ -39,6 +39,17 @@ #include "file-editor-interface.h" #include "file-editor-tab.h" +// subclassed QTabWidget for usable tab-bar +class tab_widget : public QTabWidget +{ + Q_OBJECT + +public: + tab_widget (QWidget *p) : QTabWidget (p) { } + ~tab_widget () { } + QTabBar* tabBar() const { return (QTabWidget::tabBar()); } +}; + class file_editor : public file_editor_interface { Q_OBJECT @@ -236,6 +247,8 @@ void switch_left_tab (); void switch_right_tab (); + void move_tab_left (); + void move_tab_right (); void create_context_menu (QMenu *); void edit_status_update (bool, bool); @@ -256,7 +269,7 @@ void toggle_preference (const QString& preference, bool def); - void switch_tab (int direction); + void switch_tab (int direction, bool move = false); bool editor_tab_has_focus (); @@ -345,6 +358,8 @@ QAction *_switch_left_tab_action; QAction *_switch_right_tab_action; + QAction *_move_tab_left_action; + QAction *_move_tab_right_action; QAction *_toggle_breakpoint_action; QAction *_next_breakpoint_action; @@ -357,7 +372,7 @@ QMenu *_fileMenu; QMenu *_view_editor_menu; - QTabWidget *_tab_widget; + tab_widget *_tab_widget; int _marker_breakpoint;
--- a/libgui/src/shortcut-manager.cc +++ b/libgui/src/shortcut-manager.cc @@ -318,10 +318,14 @@ QKeySequence (Qt::SHIFT + Qt::Key_F1)); // tab navigation - init (tr ("Switch to left tab"), "editor_tabs:switch_left_tab", + init (tr ("Switch to Left Tab"), "editor_tabs:switch_left_tab", QKeySequence (ctrl + Qt::Key_PageDown)); - init (tr ("Switch to right tab"), "editor_tabs:switch_right_tab", + init (tr ("Switch to Right Tab"), "editor_tabs:switch_right_tab", QKeySequence (ctrl + Qt::Key_PageUp)); + init (tr ("Move Tab Left"), "editor_tabs:move_tab_left", + QKeySequence (Qt::AltModifier + Qt::Key_PageDown)); + init (tr ("Move Tab Right"), "editor_tabs:move_tab_right", + QKeySequence (Qt::AltModifier + Qt::Key_PageUp)); }