mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
Outline: focus to edit area after item clicked or activated in Navigation mode
This commit is contained in:
parent
72fb0f18c6
commit
6ab85e1c1c
@ -98,7 +98,16 @@ void VOutline::setupUI()
|
|||||||
m_tree->setSelectionMode(QAbstractItemView::SingleSelection);
|
m_tree->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||||
// TODO: jump to the header when user click the same item twice.
|
// TODO: jump to the header when user click the same item twice.
|
||||||
connect(m_tree, &QTreeWidget::currentItemChanged,
|
connect(m_tree, &QTreeWidget::currentItemChanged,
|
||||||
this, &VOutline::handleCurrentItemChanged);
|
this, [this](QTreeWidgetItem *p_cur, QTreeWidgetItem *p_pre) {
|
||||||
|
Q_UNUSED(p_pre);
|
||||||
|
activateItem(p_cur);
|
||||||
|
});
|
||||||
|
connect(m_tree, &QTreeWidget::itemClicked,
|
||||||
|
this, [this](QTreeWidgetItem *p_item, int p_col) {
|
||||||
|
Q_UNUSED(p_col);
|
||||||
|
// Will duplicate the signal. That's fine.
|
||||||
|
activateItem(p_item, true);
|
||||||
|
});
|
||||||
|
|
||||||
QVBoxLayout *layout = new QVBoxLayout();
|
QVBoxLayout *layout = new QVBoxLayout();
|
||||||
layout->addLayout(btnLayout);
|
layout->addLayout(btnLayout);
|
||||||
@ -218,21 +227,21 @@ void VOutline::expandTreeOne(QTreeWidgetItem *p_item, int p_levelToBeExpanded)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VOutline::handleCurrentItemChanged(QTreeWidgetItem *p_curItem,
|
void VOutline::activateItem(QTreeWidgetItem *p_item, bool p_focusEditArea)
|
||||||
QTreeWidgetItem * p_preItem)
|
|
||||||
{
|
{
|
||||||
Q_UNUSED(p_preItem);
|
if (!p_item) {
|
||||||
|
|
||||||
if (!p_curItem) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const VTableOfContentItem *header = getHeaderFromItem(p_curItem, m_outline);
|
const VTableOfContentItem *header = getHeaderFromItem(p_item, m_outline);
|
||||||
Q_ASSERT(header);
|
Q_ASSERT(header);
|
||||||
m_currentHeader.update(m_outline.getFile(), header->m_index);
|
m_currentHeader.update(m_outline.getFile(), header->m_index);
|
||||||
|
|
||||||
if (!header->isEmpty() && !m_muted) {
|
if (!header->isEmpty() && !m_muted) {
|
||||||
emit outlineItemActivated(m_currentHeader);
|
emit outlineItemActivated(m_currentHeader);
|
||||||
|
if (p_focusEditArea) {
|
||||||
|
g_mainWin->focusEditArea();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -329,10 +338,16 @@ void VOutline::showNavigation()
|
|||||||
bool VOutline::handleKeyNavigation(int p_key, bool &p_succeed)
|
bool VOutline::handleKeyNavigation(int p_key, bool &p_succeed)
|
||||||
{
|
{
|
||||||
static bool secondKey = false;
|
static bool secondKey = false;
|
||||||
return VNavigationMode::handleKeyNavigation(m_tree,
|
bool ret = VNavigationMode::handleKeyNavigation(m_tree,
|
||||||
secondKey,
|
secondKey,
|
||||||
p_key,
|
p_key,
|
||||||
p_succeed);
|
p_succeed);
|
||||||
|
|
||||||
|
if (ret && p_succeed && !secondKey) {
|
||||||
|
g_mainWin->focusEditArea();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
const VTableOfContentItem *VOutline::getHeaderFromItem(QTreeWidgetItem *p_item,
|
const VTableOfContentItem *VOutline::getHeaderFromItem(QTreeWidgetItem *p_item,
|
||||||
|
@ -57,11 +57,6 @@ protected:
|
|||||||
|
|
||||||
void focusInEvent(QFocusEvent *p_event) Q_DECL_OVERRIDE;
|
void focusInEvent(QFocusEvent *p_event) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
private slots:
|
|
||||||
// Handle current item change even of the tree.
|
|
||||||
// Do not response if m_muted is true.
|
|
||||||
void handleCurrentItemChanged(QTreeWidgetItem *p_curItem, QTreeWidgetItem *p_preItem);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupUI();
|
void setupUI();
|
||||||
|
|
||||||
@ -71,6 +66,9 @@ private:
|
|||||||
|
|
||||||
void updateButtonsState();
|
void updateButtonsState();
|
||||||
|
|
||||||
|
// Do not response if m_muted is true.
|
||||||
|
void activateItem(QTreeWidgetItem *p_item, bool p_focusEditArea = false);
|
||||||
|
|
||||||
// @index: the index in @headers.
|
// @index: the index in @headers.
|
||||||
static void updateTreeByLevel(QTreeWidget *p_treeWidget,
|
static void updateTreeByLevel(QTreeWidget *p_treeWidget,
|
||||||
const QVector<VTableOfContentItem> &p_headers,
|
const QVector<VTableOfContentItem> &p_headers,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user