mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
Num keys in Captain mode to switch to given edit tab
1. Num keys 1 - 9 will activate the specified sequence edit tab; 2. Num key 0 will alternate between the current and last tab;
This commit is contained in:
parent
e1c09a83ec
commit
0a91037f71
@ -108,6 +108,39 @@ bool VCaptain::handleKeyPress(int p_key, Qt::KeyboardModifiers p_modifiers)
|
|||||||
|
|
||||||
// In Captain mode, Ctrl key won't make a difference.
|
// In Captain mode, Ctrl key won't make a difference.
|
||||||
switch (p_key) {
|
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 <i>.
|
||||||
|
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:
|
case Qt::Key_D:
|
||||||
// Locate current tab.
|
// Locate current tab.
|
||||||
m_mainWindow->locateCurrentFile();
|
m_mainWindow->locateCurrentFile();
|
||||||
|
@ -12,7 +12,8 @@
|
|||||||
extern VConfigManager vconfig;
|
extern VConfigManager vconfig;
|
||||||
|
|
||||||
VEditWindow::VEditWindow(VNote *vnote, VEditArea *editArea, QWidget *parent)
|
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();
|
initTabActions();
|
||||||
setupCornerWidget();
|
setupCornerWidget();
|
||||||
@ -399,9 +400,16 @@ void VEditWindow::handleTabbarClicked(int p_index)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VEditWindow::handleCurrentIndexChanged(int /* p_index */)
|
void VEditWindow::handleCurrentIndexChanged(int p_index)
|
||||||
{
|
{
|
||||||
focusWindow();
|
focusWindow();
|
||||||
|
|
||||||
|
QWidget *wid = widget(p_index);
|
||||||
|
if (wid && (wid == m_curTabWidget)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_lastTabWidget = m_curTabWidget;
|
||||||
|
m_curTabWidget = wid;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VEditWindow::mousePressEvent(QMouseEvent *event)
|
void VEditWindow::mousePressEvent(QMouseEvent *event)
|
||||||
@ -746,3 +754,26 @@ bool VEditWindow::showOpenedFileList()
|
|||||||
leftBtn->showMenu();
|
leftBtn->showMenu();
|
||||||
return true;
|
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;
|
||||||
|
}
|
||||||
|
@ -50,6 +50,9 @@ public:
|
|||||||
void focusNextTab(bool p_right);
|
void focusNextTab(bool p_right);
|
||||||
// Return true if the file list is shown.
|
// Return true if the file list is shown.
|
||||||
bool showOpenedFileList();
|
bool showOpenedFileList();
|
||||||
|
bool activateTab(int p_sequence);
|
||||||
|
// Switch to previous activated tab.
|
||||||
|
bool alternateTab();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
||||||
@ -102,6 +105,11 @@ private:
|
|||||||
|
|
||||||
VNote *vnote;
|
VNote *vnote;
|
||||||
VEditArea *m_editArea;
|
VEditArea *m_editArea;
|
||||||
|
|
||||||
|
// These two members are only used for alternateTab().
|
||||||
|
QWidget *m_curTabWidget;
|
||||||
|
QWidget *m_lastTabWidget;
|
||||||
|
|
||||||
// Button in the right corner
|
// Button in the right corner
|
||||||
QPushButton *rightBtn;
|
QPushButton *rightBtn;
|
||||||
// Button in the left corner
|
// Button in the left corner
|
||||||
|
Loading…
x
Reference in New Issue
Block a user