VEditArea: refine Navigation Mode

This commit is contained in:
Le Tan 2018-03-28 19:36:18 +08:00
parent d421a8577c
commit b09320e666
13 changed files with 75 additions and 29 deletions

View File

@ -13,7 +13,7 @@
- Support sorting in Cart;
- Support sorting notes and folders via name or modification date;
- Support both `flow` and `flowchart` as the language of *flowchart.js* diagram;
- Add ParsteAsBlockQuote menu action to parste text as block quote from clipboard;
- Add PasteAsBlockQuote menu action to paste text as block quote from clipboard;
- Add options for Markdown-it to support subscript and superscript;
- Better support for 4K display;

View File

@ -743,25 +743,30 @@ void VEditArea::showNavigation()
for (auto label : m_naviLabels) {
delete label;
}
m_naviLabels.clear();
if (!isVisible()) {
return;
}
// Generate labels for VEditWindow.
for (int i = 0; i < 26 && i < splitter->count(); ++i) {
QChar key('a' + i);
m_keyMap[key] = getWindow(i);
// Generate labels for VEDitTab.
int charIdx = 0;
for (int i = 0; charIdx < 26 && i < splitter->count(); ++i) {
VEditWindow *win = getWindow(i);
QVector<TabNavigationInfo> tabInfos = win->getTabsNavigationInfo();
for (int j = 0; charIdx < 26 && j < tabInfos.size(); ++j, ++charIdx) {
QChar key('a' + charIdx);
m_keyMap[key] = tabInfos[j].m_tab;
QString str = QString(m_majorKey) + key;
QLabel *label = new QLabel(str, this);
QLabel *label = new QLabel(str, win);
label->setStyleSheet(g_vnote->getNavigationLabelStyle(str));
label->move(getWindow(i)->geometry().topLeft());
label->show();
label->move(tabInfos[j].m_topLeft);
m_naviLabels.append(label);
}
}
}
void VEditArea::hideNavigation()
{
@ -769,6 +774,7 @@ void VEditArea::hideNavigation()
for (auto label : m_naviLabels) {
delete label;
}
m_naviLabels.clear();
}
@ -781,11 +787,10 @@ bool VEditArea::handleKeyNavigation(int p_key, bool &p_succeed)
if (secondKey && !keyChar.isNull()) {
secondKey = false;
p_succeed = true;
ret = true;
auto it = m_keyMap.find(keyChar);
if (it != m_keyMap.end()) {
setCurrentWindow(splitter->indexOf(static_cast<VEditWindow *>(it.value())),
true);
ret = true;
static_cast<VEditTab *>(it.value())->focusTab();
}
} else if (keyChar == m_majorKey) {
// Major key pressed.
@ -797,6 +802,7 @@ bool VEditArea::handleKeyNavigation(int p_key, bool &p_succeed)
}
ret = true;
}
return ret;
}

View File

@ -1010,7 +1010,10 @@ bool VEditWindow::addEditTab(QWidget *p_widget)
void VEditWindow::connectEditTab(const VEditTab *p_tab)
{
connect(p_tab, &VEditTab::getFocused,
this, &VEditWindow::getFocused);
this, [this]() {
setCurrentWidget(static_cast<VEditTab *>(sender()));
emit getFocused();
});
connect(p_tab, &VEditTab::outlineChanged,
this, &VEditWindow::handleTabOutlineChanged);
connect(p_tab, &VEditTab::currentHeaderChanged,
@ -1196,3 +1199,22 @@ int VEditWindow::tabBarHeight() const
{
return tabBar()->height();
}
QVector<TabNavigationInfo> VEditWindow::getTabsNavigationInfo() const
{
QVector<TabNavigationInfo> infos;
QTabBar *bar = tabBar();
for (int i = 0; i < bar->count(); ++i) {
QPoint tl = bar->tabRect(i).topLeft();
if (tl.x() < 0 || tl.x() >= bar->width()) {
continue;
}
TabNavigationInfo info;
info.m_topLeft = bar->mapToParent(tl);
info.m_tab = getTab(i);
infos.append(info);
}
return infos;
}

View File

@ -15,6 +15,16 @@ class QPushButton;
class QActionGroup;
class VEditArea;
// Tab info for navigation mode.
struct TabNavigationInfo
{
// Top left of the tab relative to edit window.
QPoint m_topLeft;
VEditTab *m_tab;
};
class VEditWindow : public QTabWidget
{
Q_OBJECT
@ -85,6 +95,8 @@ public:
int tabBarHeight() const;
QVector<TabNavigationInfo> getTabsNavigationInfo() const;
protected:
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;

View File

@ -79,11 +79,14 @@ void VListWidget::resizeEvent(QResizeEvent *p_event)
m_searchInput->height()));
}
void VListWidget::handleSearchModeTriggered(bool p_inSearchMode)
void VListWidget::handleSearchModeTriggered(bool p_inSearchMode, bool p_focus)
{
setSearchInputVisible(p_inSearchMode);
if (!p_inSearchMode) {
clearItemsHighlight();
}
if (p_focus) {
setFocus();
}
}

View File

@ -36,7 +36,7 @@ public:
static void sortListWidget(QListWidget *p_list, const QVector<int> &p_sortedIdx);
private slots:
void handleSearchModeTriggered(bool p_inSearchMode);
void handleSearchModeTriggered(bool p_inSearchMode, bool p_focus);
protected:
void keyPressEvent(QKeyEvent *p_event) Q_DECL_OVERRIDE;

View File

@ -123,9 +123,9 @@ bool VNavigationMode::handleKeyNavigation(QListWidget *p_widget,
if (p_secondKey && !keyChar.isNull()) {
p_secondKey = false;
p_succeed = true;
ret = true;
auto it = m_keyMap.find(keyChar);
if (it != m_keyMap.end()) {
ret = true;
p_widget->setCurrentItem(static_cast<QListWidgetItem *>(it.value()),
QItemSelectionModel::ClearAndSelect);
p_widget->setFocus();
@ -189,9 +189,9 @@ bool VNavigationMode::handleKeyNavigation(QTreeWidget *p_widget,
if (p_secondKey && !keyChar.isNull()) {
p_secondKey = false;
p_succeed = true;
ret = true;
auto it = m_keyMap.find(keyChar);
if (it != m_keyMap.end()) {
ret = true;
p_widget->setCurrentItem(static_cast<QTreeWidgetItem *>(it.value()));
p_widget->setFocus();
}

View File

@ -254,7 +254,7 @@ void VSearcher::initUIFields()
m_searchTargetCB->addItem(tr("Note"), VSearchConfig::Note);
m_searchTargetCB->addItem(tr("Folder"), VSearchConfig::Folder);
m_searchTargetCB->addItem(tr("Notebook"), VSearchConfig::Notebook);
m_searchTargetCB->addItem(tr("All"),
m_searchTargetCB->addItem(tr("Note/Folder/Notebook"),
VSearchConfig::Note
| VSearchConfig:: Folder
| VSearchConfig::Notebook);

View File

@ -103,7 +103,7 @@ bool VSimpleSearchInput::tryHandleKeyPressEvent(QKeyEvent *p_event)
}
if (m_inSearchMode) {
emit triggered(m_inSearchMode);
emit triggered(m_inSearchMode, false);
clearSearch();
m_searchEdit->setFocus();
@ -120,7 +120,7 @@ bool VSimpleSearchInput::tryHandleKeyPressEvent(QKeyEvent *p_event)
|| (key == Qt::Key_BracketLeft
&& VUtils::isControlModifierForVim(modifiers))) {
m_inSearchMode = false;
emit triggered(m_inSearchMode);
emit triggered(m_inSearchMode, true);
return true;
}
}
@ -132,7 +132,7 @@ bool VSimpleSearchInput::tryHandleKeyPressEvent(QKeyEvent *p_event)
if (!m_inSearchMode) {
m_inSearchMode = true;
emit triggered(m_inSearchMode);
emit triggered(m_inSearchMode, false);
m_searchEdit->setFocus();
m_obj->highlightHitItems(m_hitItems);
@ -189,7 +189,7 @@ bool VSimpleSearchInput::eventFilter(QObject *p_watched, QEvent *p_event)
QFocusEvent *eve = static_cast<QFocusEvent *>(p_event);
if (eve->reason() != Qt::ActiveWindowFocusReason) {
m_inSearchMode = false;
emit triggered(m_inSearchMode);
emit triggered(m_inSearchMode, false);
}
}

View File

@ -53,7 +53,8 @@ public:
signals:
// Search mode is triggered.
void triggered(bool p_inSearchMode);
// @p_focus: whether the widget containing this input should get focus.
void triggered(bool p_inSearchMode, bool p_focus);
void inputTextChanged(const QString &p_text);

View File

@ -164,9 +164,9 @@ bool VToolBox::handleKeyNavigation(int p_key, bool &p_succeed)
if (secondKey && !keyChar.isNull()) {
secondKey = false;
p_succeed = true;
ret = true;
auto it = m_keyMap.find(keyChar);
if (it != m_keyMap.end()) {
ret = true;
QWidget *widget = static_cast<QWidget *>(it.value());
setCurrentWidget(widget);
}

View File

@ -101,12 +101,14 @@ void VTreeWidget::resizeEvent(QResizeEvent *p_event)
m_searchInput->height()));
}
void VTreeWidget::handleSearchModeTriggered(bool p_inSearchMode)
void VTreeWidget::handleSearchModeTriggered(bool p_inSearchMode, bool p_focus)
{
setSearchInputVisible(p_inSearchMode);
if (!p_inSearchMode) {
clearItemsHighlight();
}
if (p_focus) {
setFocus();
}
}

View File

@ -51,7 +51,7 @@ signals:
void rowsMoved(int p_first, int p_last, int p_row);
private slots:
void handleSearchModeTriggered(bool p_inSearchMode);
void handleSearchModeTriggered(bool p_inSearchMode, bool p_focus);
void handleSearchInputTextChanged(const QString &p_text);