diff --git a/src/vcaptain.cpp b/src/vcaptain.cpp index 901c49e2..217c70d3 100644 --- a/src/vcaptain.cpp +++ b/src/vcaptain.cpp @@ -108,6 +108,39 @@ bool VCaptain::handleKeyPress(int p_key, Qt::KeyboardModifiers p_modifiers) // In Captain mode, Ctrl key won't make a difference. switch (p_key) { + case Qt::Key_1: + case Qt::Key_2: + case Qt::Key_3: + case Qt::Key_4: + case Qt::Key_5: + case Qt::Key_6: + case Qt::Key_7: + case Qt::Key_8: + case Qt::Key_9: + { + // Switch to tab . + VEditWindow *win = m_mainWindow->editArea->getCurrentWindow(); + if (win) { + int sequence = p_key - Qt::Key_0; + if (win->activateTab(sequence)) { + m_widgetBeforeCaptain = NULL; + } + } + break; + } + + case Qt::Key_0: + { + // Alternate the tab. + VEditWindow *win = m_mainWindow->editArea->getCurrentWindow(); + if (win) { + if (win->alternateTab()) { + m_widgetBeforeCaptain = NULL; + } + } + break; + } + case Qt::Key_D: // Locate current tab. m_mainWindow->locateCurrentFile(); diff --git a/src/veditwindow.cpp b/src/veditwindow.cpp index 4560d0d7..8d22eaff 100644 --- a/src/veditwindow.cpp +++ b/src/veditwindow.cpp @@ -12,7 +12,8 @@ extern VConfigManager vconfig; VEditWindow::VEditWindow(VNote *vnote, VEditArea *editArea, QWidget *parent) - : QTabWidget(parent), vnote(vnote), m_editArea(editArea) + : QTabWidget(parent), vnote(vnote), m_editArea(editArea), + m_curTabWidget(NULL), m_lastTabWidget(NULL) { initTabActions(); setupCornerWidget(); @@ -399,9 +400,16 @@ void VEditWindow::handleTabbarClicked(int p_index) } } -void VEditWindow::handleCurrentIndexChanged(int /* p_index */) +void VEditWindow::handleCurrentIndexChanged(int p_index) { focusWindow(); + + QWidget *wid = widget(p_index); + if (wid && (wid == m_curTabWidget)) { + return; + } + m_lastTabWidget = m_curTabWidget; + m_curTabWidget = wid; } void VEditWindow::mousePressEvent(QMouseEvent *event) @@ -746,3 +754,26 @@ bool VEditWindow::showOpenedFileList() leftBtn->showMenu(); return true; } + +bool VEditWindow::activateTab(int p_sequence) +{ + const int base = 1; + if (p_sequence < base || p_sequence >= (base + count())) { + return false; + } + setCurrentIndex(p_sequence - base); + return true; +} + +bool VEditWindow::alternateTab() +{ + if (m_lastTabWidget) { + if (-1 != indexOf(m_lastTabWidget)) { + setCurrentWidget(m_lastTabWidget); + return true; + } else { + m_lastTabWidget = NULL; + } + } + return false; +} diff --git a/src/veditwindow.h b/src/veditwindow.h index 193ba8f9..6265f301 100644 --- a/src/veditwindow.h +++ b/src/veditwindow.h @@ -50,6 +50,9 @@ public: void focusNextTab(bool p_right); // Return true if the file list is shown. bool showOpenedFileList(); + bool activateTab(int p_sequence); + // Switch to previous activated tab. + bool alternateTab(); protected: void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; @@ -102,6 +105,11 @@ private: VNote *vnote; VEditArea *m_editArea; + + // These two members are only used for alternateTab(). + QWidget *m_curTabWidget; + QWidget *m_lastTabWidget; + // Button in the right corner QPushButton *rightBtn; // Button in the left corner