mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
VEditArea: refine Navigation Mode
This commit is contained in:
parent
d421a8577c
commit
b09320e666
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user