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 in Cart;
|
||||||
- Support sorting notes and folders via name or modification date;
|
- Support sorting notes and folders via name or modification date;
|
||||||
- Support both `flow` and `flowchart` as the language of *flowchart.js* diagram;
|
- 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;
|
- Add options for Markdown-it to support subscript and superscript;
|
||||||
- Better support for 4K display;
|
- Better support for 4K display;
|
||||||
|
|
||||||
|
@ -743,25 +743,30 @@ void VEditArea::showNavigation()
|
|||||||
for (auto label : m_naviLabels) {
|
for (auto label : m_naviLabels) {
|
||||||
delete label;
|
delete label;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_naviLabels.clear();
|
m_naviLabels.clear();
|
||||||
|
|
||||||
if (!isVisible()) {
|
if (!isVisible()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate labels for VEditWindow.
|
// Generate labels for VEDitTab.
|
||||||
for (int i = 0; i < 26 && i < splitter->count(); ++i) {
|
int charIdx = 0;
|
||||||
QChar key('a' + i);
|
for (int i = 0; charIdx < 26 && i < splitter->count(); ++i) {
|
||||||
m_keyMap[key] = getWindow(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;
|
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->setStyleSheet(g_vnote->getNavigationLabelStyle(str));
|
||||||
label->move(getWindow(i)->geometry().topLeft());
|
|
||||||
label->show();
|
label->show();
|
||||||
|
label->move(tabInfos[j].m_topLeft);
|
||||||
m_naviLabels.append(label);
|
m_naviLabels.append(label);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void VEditArea::hideNavigation()
|
void VEditArea::hideNavigation()
|
||||||
{
|
{
|
||||||
@ -769,6 +774,7 @@ void VEditArea::hideNavigation()
|
|||||||
for (auto label : m_naviLabels) {
|
for (auto label : m_naviLabels) {
|
||||||
delete label;
|
delete label;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_naviLabels.clear();
|
m_naviLabels.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -781,11 +787,10 @@ bool VEditArea::handleKeyNavigation(int p_key, bool &p_succeed)
|
|||||||
if (secondKey && !keyChar.isNull()) {
|
if (secondKey && !keyChar.isNull()) {
|
||||||
secondKey = false;
|
secondKey = false;
|
||||||
p_succeed = true;
|
p_succeed = true;
|
||||||
ret = true;
|
|
||||||
auto it = m_keyMap.find(keyChar);
|
auto it = m_keyMap.find(keyChar);
|
||||||
if (it != m_keyMap.end()) {
|
if (it != m_keyMap.end()) {
|
||||||
setCurrentWindow(splitter->indexOf(static_cast<VEditWindow *>(it.value())),
|
ret = true;
|
||||||
true);
|
static_cast<VEditTab *>(it.value())->focusTab();
|
||||||
}
|
}
|
||||||
} else if (keyChar == m_majorKey) {
|
} else if (keyChar == m_majorKey) {
|
||||||
// Major key pressed.
|
// Major key pressed.
|
||||||
@ -797,6 +802,7 @@ bool VEditArea::handleKeyNavigation(int p_key, bool &p_succeed)
|
|||||||
}
|
}
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1010,7 +1010,10 @@ bool VEditWindow::addEditTab(QWidget *p_widget)
|
|||||||
void VEditWindow::connectEditTab(const VEditTab *p_tab)
|
void VEditWindow::connectEditTab(const VEditTab *p_tab)
|
||||||
{
|
{
|
||||||
connect(p_tab, &VEditTab::getFocused,
|
connect(p_tab, &VEditTab::getFocused,
|
||||||
this, &VEditWindow::getFocused);
|
this, [this]() {
|
||||||
|
setCurrentWidget(static_cast<VEditTab *>(sender()));
|
||||||
|
emit getFocused();
|
||||||
|
});
|
||||||
connect(p_tab, &VEditTab::outlineChanged,
|
connect(p_tab, &VEditTab::outlineChanged,
|
||||||
this, &VEditWindow::handleTabOutlineChanged);
|
this, &VEditWindow::handleTabOutlineChanged);
|
||||||
connect(p_tab, &VEditTab::currentHeaderChanged,
|
connect(p_tab, &VEditTab::currentHeaderChanged,
|
||||||
@ -1196,3 +1199,22 @@ int VEditWindow::tabBarHeight() const
|
|||||||
{
|
{
|
||||||
return tabBar()->height();
|
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 QActionGroup;
|
||||||
class VEditArea;
|
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
|
class VEditWindow : public QTabWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -85,6 +95,8 @@ public:
|
|||||||
|
|
||||||
int tabBarHeight() const;
|
int tabBarHeight() const;
|
||||||
|
|
||||||
|
QVector<TabNavigationInfo> getTabsNavigationInfo() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
@ -79,11 +79,14 @@ void VListWidget::resizeEvent(QResizeEvent *p_event)
|
|||||||
m_searchInput->height()));
|
m_searchInput->height()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void VListWidget::handleSearchModeTriggered(bool p_inSearchMode)
|
void VListWidget::handleSearchModeTriggered(bool p_inSearchMode, bool p_focus)
|
||||||
{
|
{
|
||||||
setSearchInputVisible(p_inSearchMode);
|
setSearchInputVisible(p_inSearchMode);
|
||||||
if (!p_inSearchMode) {
|
if (!p_inSearchMode) {
|
||||||
clearItemsHighlight();
|
clearItemsHighlight();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p_focus) {
|
||||||
setFocus();
|
setFocus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ public:
|
|||||||
static void sortListWidget(QListWidget *p_list, const QVector<int> &p_sortedIdx);
|
static void sortListWidget(QListWidget *p_list, const QVector<int> &p_sortedIdx);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void handleSearchModeTriggered(bool p_inSearchMode);
|
void handleSearchModeTriggered(bool p_inSearchMode, bool p_focus);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void keyPressEvent(QKeyEvent *p_event) Q_DECL_OVERRIDE;
|
void keyPressEvent(QKeyEvent *p_event) Q_DECL_OVERRIDE;
|
||||||
|
@ -123,9 +123,9 @@ bool VNavigationMode::handleKeyNavigation(QListWidget *p_widget,
|
|||||||
if (p_secondKey && !keyChar.isNull()) {
|
if (p_secondKey && !keyChar.isNull()) {
|
||||||
p_secondKey = false;
|
p_secondKey = false;
|
||||||
p_succeed = true;
|
p_succeed = true;
|
||||||
ret = true;
|
|
||||||
auto it = m_keyMap.find(keyChar);
|
auto it = m_keyMap.find(keyChar);
|
||||||
if (it != m_keyMap.end()) {
|
if (it != m_keyMap.end()) {
|
||||||
|
ret = true;
|
||||||
p_widget->setCurrentItem(static_cast<QListWidgetItem *>(it.value()),
|
p_widget->setCurrentItem(static_cast<QListWidgetItem *>(it.value()),
|
||||||
QItemSelectionModel::ClearAndSelect);
|
QItemSelectionModel::ClearAndSelect);
|
||||||
p_widget->setFocus();
|
p_widget->setFocus();
|
||||||
@ -189,9 +189,9 @@ bool VNavigationMode::handleKeyNavigation(QTreeWidget *p_widget,
|
|||||||
if (p_secondKey && !keyChar.isNull()) {
|
if (p_secondKey && !keyChar.isNull()) {
|
||||||
p_secondKey = false;
|
p_secondKey = false;
|
||||||
p_succeed = true;
|
p_succeed = true;
|
||||||
ret = true;
|
|
||||||
auto it = m_keyMap.find(keyChar);
|
auto it = m_keyMap.find(keyChar);
|
||||||
if (it != m_keyMap.end()) {
|
if (it != m_keyMap.end()) {
|
||||||
|
ret = true;
|
||||||
p_widget->setCurrentItem(static_cast<QTreeWidgetItem *>(it.value()));
|
p_widget->setCurrentItem(static_cast<QTreeWidgetItem *>(it.value()));
|
||||||
p_widget->setFocus();
|
p_widget->setFocus();
|
||||||
}
|
}
|
||||||
|
@ -254,7 +254,7 @@ void VSearcher::initUIFields()
|
|||||||
m_searchTargetCB->addItem(tr("Note"), VSearchConfig::Note);
|
m_searchTargetCB->addItem(tr("Note"), VSearchConfig::Note);
|
||||||
m_searchTargetCB->addItem(tr("Folder"), VSearchConfig::Folder);
|
m_searchTargetCB->addItem(tr("Folder"), VSearchConfig::Folder);
|
||||||
m_searchTargetCB->addItem(tr("Notebook"), VSearchConfig::Notebook);
|
m_searchTargetCB->addItem(tr("Notebook"), VSearchConfig::Notebook);
|
||||||
m_searchTargetCB->addItem(tr("All"),
|
m_searchTargetCB->addItem(tr("Note/Folder/Notebook"),
|
||||||
VSearchConfig::Note
|
VSearchConfig::Note
|
||||||
| VSearchConfig:: Folder
|
| VSearchConfig:: Folder
|
||||||
| VSearchConfig::Notebook);
|
| VSearchConfig::Notebook);
|
||||||
|
@ -103,7 +103,7 @@ bool VSimpleSearchInput::tryHandleKeyPressEvent(QKeyEvent *p_event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (m_inSearchMode) {
|
if (m_inSearchMode) {
|
||||||
emit triggered(m_inSearchMode);
|
emit triggered(m_inSearchMode, false);
|
||||||
|
|
||||||
clearSearch();
|
clearSearch();
|
||||||
m_searchEdit->setFocus();
|
m_searchEdit->setFocus();
|
||||||
@ -120,7 +120,7 @@ bool VSimpleSearchInput::tryHandleKeyPressEvent(QKeyEvent *p_event)
|
|||||||
|| (key == Qt::Key_BracketLeft
|
|| (key == Qt::Key_BracketLeft
|
||||||
&& VUtils::isControlModifierForVim(modifiers))) {
|
&& VUtils::isControlModifierForVim(modifiers))) {
|
||||||
m_inSearchMode = false;
|
m_inSearchMode = false;
|
||||||
emit triggered(m_inSearchMode);
|
emit triggered(m_inSearchMode, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -132,7 +132,7 @@ bool VSimpleSearchInput::tryHandleKeyPressEvent(QKeyEvent *p_event)
|
|||||||
|
|
||||||
if (!m_inSearchMode) {
|
if (!m_inSearchMode) {
|
||||||
m_inSearchMode = true;
|
m_inSearchMode = true;
|
||||||
emit triggered(m_inSearchMode);
|
emit triggered(m_inSearchMode, false);
|
||||||
m_searchEdit->setFocus();
|
m_searchEdit->setFocus();
|
||||||
|
|
||||||
m_obj->highlightHitItems(m_hitItems);
|
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);
|
QFocusEvent *eve = static_cast<QFocusEvent *>(p_event);
|
||||||
if (eve->reason() != Qt::ActiveWindowFocusReason) {
|
if (eve->reason() != Qt::ActiveWindowFocusReason) {
|
||||||
m_inSearchMode = false;
|
m_inSearchMode = false;
|
||||||
emit triggered(m_inSearchMode);
|
emit triggered(m_inSearchMode, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,8 @@ public:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
// Search mode is triggered.
|
// 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);
|
void inputTextChanged(const QString &p_text);
|
||||||
|
|
||||||
|
@ -164,9 +164,9 @@ bool VToolBox::handleKeyNavigation(int p_key, bool &p_succeed)
|
|||||||
if (secondKey && !keyChar.isNull()) {
|
if (secondKey && !keyChar.isNull()) {
|
||||||
secondKey = false;
|
secondKey = false;
|
||||||
p_succeed = true;
|
p_succeed = true;
|
||||||
ret = true;
|
|
||||||
auto it = m_keyMap.find(keyChar);
|
auto it = m_keyMap.find(keyChar);
|
||||||
if (it != m_keyMap.end()) {
|
if (it != m_keyMap.end()) {
|
||||||
|
ret = true;
|
||||||
QWidget *widget = static_cast<QWidget *>(it.value());
|
QWidget *widget = static_cast<QWidget *>(it.value());
|
||||||
setCurrentWidget(widget);
|
setCurrentWidget(widget);
|
||||||
}
|
}
|
||||||
|
@ -101,12 +101,14 @@ void VTreeWidget::resizeEvent(QResizeEvent *p_event)
|
|||||||
m_searchInput->height()));
|
m_searchInput->height()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void VTreeWidget::handleSearchModeTriggered(bool p_inSearchMode)
|
void VTreeWidget::handleSearchModeTriggered(bool p_inSearchMode, bool p_focus)
|
||||||
{
|
{
|
||||||
setSearchInputVisible(p_inSearchMode);
|
setSearchInputVisible(p_inSearchMode);
|
||||||
if (!p_inSearchMode) {
|
if (!p_inSearchMode) {
|
||||||
clearItemsHighlight();
|
clearItemsHighlight();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p_focus) {
|
||||||
setFocus();
|
setFocus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ signals:
|
|||||||
void rowsMoved(int p_first, int p_last, int p_row);
|
void rowsMoved(int p_first, int p_last, int p_row);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void handleSearchModeTriggered(bool p_inSearchMode);
|
void handleSearchModeTriggered(bool p_inSearchMode, bool p_focus);
|
||||||
|
|
||||||
void handleSearchInputTextChanged(const QString &p_text);
|
void handleSearchInputTextChanged(const QString &p_text);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user