|
|
@ -10,59 +10,60 @@
|
|
|
|
#include <QScrollBar>
|
|
|
|
#include <QScrollBar>
|
|
|
|
#include "nodetreeview_p.h"
|
|
|
|
#include "nodetreeview_p.h"
|
|
|
|
|
|
|
|
|
|
|
|
NodeTreeView::NodeTreeView(QWidget *parent)
|
|
|
|
NodeTreeView::NodeTreeView(QWidget *parent)// 构造函数,初始化 NodeTreeView
|
|
|
|
: QTreeView(parent),
|
|
|
|
: QTreeView(parent),
|
|
|
|
m_isContextMenuOpened{ false },
|
|
|
|
m_isContextMenuOpened{ false },
|
|
|
|
m_isEditing{ false },
|
|
|
|
m_isEditing{ false },
|
|
|
|
m_ignoreThisCurrentLoad{ false },
|
|
|
|
m_ignoreThisCurrentLoad{ false },
|
|
|
|
m_isLastSelectedFolder{ false }
|
|
|
|
m_isLastSelectedFolder{ false }
|
|
|
|
{
|
|
|
|
{
|
|
|
|
setHeaderHidden(true);
|
|
|
|
setHeaderHidden(true);// 隐藏表头
|
|
|
|
|
|
|
|
|
|
|
|
QFile file(":/styles/nodetreeview.css");
|
|
|
|
QFile file(":/styles/nodetreeview.css");
|
|
|
|
file.open(QFile::ReadOnly);
|
|
|
|
file.open(QFile::ReadOnly);
|
|
|
|
setStyleSheet(file.readAll());
|
|
|
|
setStyleSheet(file.readAll());// 设置样式表
|
|
|
|
|
|
|
|
|
|
|
|
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) || defined(Q_OS_WIN) || defined(Q_OS_WINDOWS)
|
|
|
|
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) || defined(Q_OS_WIN) || defined(Q_OS_WINDOWS)
|
|
|
|
QFile scollBarStyleFile(QStringLiteral(":/styles/components/custom-scrollbar.css"));
|
|
|
|
QFile scollBarStyleFile(QStringLiteral(":/styles/components/custom-scrollbar.css"));
|
|
|
|
scollBarStyleFile.open(QFile::ReadOnly);
|
|
|
|
scollBarStyleFile.open(QFile::ReadOnly);
|
|
|
|
QString scrollbarStyleSheet = QString::fromLatin1(scollBarStyleFile.readAll());
|
|
|
|
QString scrollbarStyleSheet = QString::fromLatin1(scollBarStyleFile.readAll());
|
|
|
|
verticalScrollBar()->setStyleSheet(scrollbarStyleSheet);
|
|
|
|
verticalScrollBar()->setStyleSheet(scrollbarStyleSheet);// 设置滚动条样式
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
setRootIsDecorated(false);
|
|
|
|
setRootIsDecorated(false); // 不显示根节点的装饰
|
|
|
|
setMouseTracking(true);
|
|
|
|
setMouseTracking(true); // 启用鼠标跟踪
|
|
|
|
setSelectionMode(QAbstractItemView::MultiSelection);
|
|
|
|
setSelectionMode(QAbstractItemView::MultiSelection); // 设置选择模式为多选
|
|
|
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
setContextMenuPolicy(Qt::CustomContextMenu); // 设置上下文菜单策略为自定义
|
|
|
|
connect(this, &QWidget::customContextMenuRequested, this, &NodeTreeView::onCustomContextMenu);
|
|
|
|
connect(this, &QWidget::customContextMenuRequested, this,
|
|
|
|
contextMenu = new QMenu(this);
|
|
|
|
&NodeTreeView::onCustomContextMenu); // 连接自定义上下文菜单信号
|
|
|
|
renameFolderAction = new QAction(tr("Rename Folder"), this);
|
|
|
|
contextMenu = new QMenu(this); // 创建上下文菜单
|
|
|
|
|
|
|
|
renameFolderAction = new QAction(tr("Rename Folder"), this);// 创建和连接重命名文件夹动作
|
|
|
|
connect(renameFolderAction, &QAction::triggered, this, [this] {
|
|
|
|
connect(renameFolderAction, &QAction::triggered, this, [this] {
|
|
|
|
setIsEditing(true);
|
|
|
|
setIsEditing(true);
|
|
|
|
emit renameFolderRequested();
|
|
|
|
emit renameFolderRequested();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
deleteFolderAction = new QAction(tr("Delete Folder"), this);
|
|
|
|
deleteFolderAction = new QAction(tr("Delete Folder"), this);// 创建和连接删除文件夹动作
|
|
|
|
connect(deleteFolderAction, &QAction::triggered, this, &NodeTreeView::onDeleteNodeAction);
|
|
|
|
connect(deleteFolderAction, &QAction::triggered, this, &NodeTreeView::onDeleteNodeAction);
|
|
|
|
addSubfolderAction = new QAction(tr("Add Subfolder"), this);
|
|
|
|
addSubfolderAction = new QAction(tr("Add Subfolder"), this);// 创建和连接添加子文件夹动作
|
|
|
|
connect(addSubfolderAction, &QAction::triggered, this, &NodeTreeView::addFolderRequested);
|
|
|
|
connect(addSubfolderAction, &QAction::triggered, this, &NodeTreeView::addFolderRequested);
|
|
|
|
|
|
|
|
|
|
|
|
renameTagAction = new QAction(tr("Rename Tag"), this);
|
|
|
|
renameTagAction = new QAction(tr("Rename Tag"), this);// 创建和连接重命名标签动作
|
|
|
|
connect(renameTagAction, &QAction::triggered, this, [this] {
|
|
|
|
connect(renameTagAction, &QAction::triggered, this, [this] {
|
|
|
|
setIsEditing(true);
|
|
|
|
setIsEditing(true);
|
|
|
|
emit renameTagRequested();
|
|
|
|
emit renameTagRequested();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
changeTagColorAction = new QAction(tr("Change Tag Color"), this);
|
|
|
|
changeTagColorAction = new QAction(tr("Change Tag Color"), this); // 创建和连接更改标签颜色动作
|
|
|
|
connect(changeTagColorAction, &QAction::triggered, this, &NodeTreeView::onChangeTagColorAction);
|
|
|
|
connect(changeTagColorAction, &QAction::triggered, this, &NodeTreeView::onChangeTagColorAction);
|
|
|
|
deleteTagAction = new QAction(tr("Delete Tag"), this);
|
|
|
|
deleteTagAction = new QAction(tr("Delete Tag"), this);// 创建和连接删除标签动作
|
|
|
|
connect(deleteTagAction, &QAction::triggered, this, &NodeTreeView::onDeleteNodeAction);
|
|
|
|
connect(deleteTagAction, &QAction::triggered, this, &NodeTreeView::onDeleteNodeAction);
|
|
|
|
clearSelectionAction = new QAction(tr("Clear Selection"), this);
|
|
|
|
clearSelectionAction = new QAction(tr("Clear Selection"), this);// 创建和连接清除选择动作
|
|
|
|
connect(clearSelectionAction, &QAction::triggered, this, [this] {
|
|
|
|
connect(clearSelectionAction, &QAction::triggered, this, [this] {
|
|
|
|
closeCurrentEditor();
|
|
|
|
closeCurrentEditor();
|
|
|
|
clearSelection();
|
|
|
|
clearSelection();
|
|
|
|
setCurrentIndexC(dynamic_cast<NodeTreeModel *>(model())->getAllNotesButtonIndex());
|
|
|
|
setCurrentIndexC(dynamic_cast<NodeTreeModel *>(model())->getAllNotesButtonIndex());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
contextMenuTimer.setInterval(100);
|
|
|
|
contextMenuTimer.setInterval(100);// 设置上下文菜单定时器
|
|
|
|
contextMenuTimer.setSingleShot(true);
|
|
|
|
contextMenuTimer.setSingleShot(true);
|
|
|
|
connect(&contextMenuTimer, &QTimer::timeout, this, [this] {
|
|
|
|
connect(&contextMenuTimer, &QTimer::timeout, this, [this] {
|
|
|
|
if (!m_isEditing) {
|
|
|
|
if (!m_isEditing) {
|
|
|
@ -70,19 +71,19 @@ NodeTreeView::NodeTreeView(QWidget *parent)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
connect(contextMenu, &QMenu::aboutToHide, this, [this] {
|
|
|
|
connect(contextMenu, &QMenu::aboutToHide, this, [this] { // 连接上下文菜单隐藏信号
|
|
|
|
m_isContextMenuOpened = false;
|
|
|
|
m_isContextMenuOpened = false;
|
|
|
|
// this signal is emitted before QAction::triggered
|
|
|
|
// this signal is emitted before QAction::triggered
|
|
|
|
contextMenuTimer.start();
|
|
|
|
contextMenuTimer.start();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
connect(this, &NodeTreeView::expanded, this, &NodeTreeView::onExpanded);
|
|
|
|
connect(this, &NodeTreeView::expanded, this, &NodeTreeView::onExpanded);// 连接展开和收起信号
|
|
|
|
connect(this, &NodeTreeView::collapsed, this, &NodeTreeView::onCollapsed);
|
|
|
|
connect(this, &NodeTreeView::collapsed, this, &NodeTreeView::onCollapsed);
|
|
|
|
|
|
|
|
|
|
|
|
setDragEnabled(true);
|
|
|
|
setDragEnabled(true); // 启用拖动
|
|
|
|
setAcceptDrops(true);
|
|
|
|
setAcceptDrops(true); // 启用接受拖放
|
|
|
|
setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
setSelectionMode(QAbstractItemView::SingleSelection); // 设置选择模式为单选
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 删除节点动作
|
|
|
|
void NodeTreeView::onDeleteNodeAction()
|
|
|
|
void NodeTreeView::onDeleteNodeAction()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto itemType = static_cast<NodeItem::Type>(
|
|
|
|
auto itemType = static_cast<NodeItem::Type>(
|
|
|
@ -98,29 +99,29 @@ void NodeTreeView::onDeleteNodeAction()
|
|
|
|
emit deleteTagRequested(index);
|
|
|
|
emit deleteTagRequested(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 节点展开时的处理
|
|
|
|
void NodeTreeView::onExpanded(const QModelIndex &index)
|
|
|
|
void NodeTreeView::onExpanded(const QModelIndex &index)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m_expanded.push_back(index.data(NodeItem::Roles::AbsPath).toString());
|
|
|
|
m_expanded.push_back(index.data(NodeItem::Roles::AbsPath).toString());
|
|
|
|
emit saveExpand(QStringList::fromVector(m_expanded));
|
|
|
|
emit saveExpand(QStringList::fromVector(m_expanded));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 节点收起时的处理
|
|
|
|
void NodeTreeView::onCollapsed(const QModelIndex &index)
|
|
|
|
void NodeTreeView::onCollapsed(const QModelIndex &index)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m_expanded.removeAll(index.data(NodeItem::Roles::AbsPath).toString());
|
|
|
|
m_expanded.removeAll(index.data(NodeItem::Roles::AbsPath).toString());
|
|
|
|
emit saveExpand(QStringList::fromVector(m_expanded));
|
|
|
|
emit saveExpand(QStringList::fromVector(m_expanded));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 获取当前编辑的索引
|
|
|
|
const QModelIndex &NodeTreeView::currentEditingIndex() const
|
|
|
|
const QModelIndex &NodeTreeView::currentEditingIndex() const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return m_currentEditingIndex;
|
|
|
|
return m_currentEditingIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 设置忽略当前加载
|
|
|
|
void NodeTreeView::setIgnoreThisCurrentLoad(bool newIgnoreThisCurrentLoad)
|
|
|
|
void NodeTreeView::setIgnoreThisCurrentLoad(bool newIgnoreThisCurrentLoad)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m_ignoreThisCurrentLoad = newIgnoreThisCurrentLoad;
|
|
|
|
m_ignoreThisCurrentLoad = newIgnoreThisCurrentLoad;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 文件夹拖放成功时的处理
|
|
|
|
void NodeTreeView::onFolderDropSuccessful(const QString &path)
|
|
|
|
void NodeTreeView::onFolderDropSuccessful(const QString &path)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto m_model = dynamic_cast<NodeTreeModel *>(model());
|
|
|
|
auto m_model = dynamic_cast<NodeTreeModel *>(model());
|
|
|
@ -131,7 +132,7 @@ void NodeTreeView::onFolderDropSuccessful(const QString &path)
|
|
|
|
setCurrentIndexC(m_model->getAllNotesButtonIndex());
|
|
|
|
setCurrentIndexC(m_model->getAllNotesButtonIndex());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 标签拖放成功时的处理
|
|
|
|
void NodeTreeView::onTagsDropSuccessful(const QSet<int> &ids)
|
|
|
|
void NodeTreeView::onTagsDropSuccessful(const QSet<int> &ids)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto m_model = dynamic_cast<NodeTreeModel *>(model());
|
|
|
|
auto m_model = dynamic_cast<NodeTreeModel *>(model());
|
|
|
@ -151,18 +152,18 @@ void NodeTreeView::onTagsDropSuccessful(const QSet<int> &ids)
|
|
|
|
setCurrentIndexC(m_model->getAllNotesButtonIndex());
|
|
|
|
setCurrentIndexC(m_model->getAllNotesButtonIndex());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 获取主题
|
|
|
|
Theme::Value NodeTreeView::theme() const
|
|
|
|
Theme::Value NodeTreeView::theme() const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return m_theme;
|
|
|
|
return m_theme;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool NodeTreeView::isDragging() const
|
|
|
|
bool NodeTreeView::isDragging() const// 是否正在拖动
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return state() == DraggingState;
|
|
|
|
return state() == DraggingState;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NodeTreeView::reExpandC()
|
|
|
|
void NodeTreeView::reExpandC()// 重新展开节点
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto needExpand = std::move(m_expanded);
|
|
|
|
auto needExpand = std::move(m_expanded);
|
|
|
|
m_expanded.clear();
|
|
|
|
m_expanded.clear();
|
|
|
@ -176,14 +177,14 @@ void NodeTreeView::reExpandC()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NodeTreeView::reExpandC(const QStringList &expanded)
|
|
|
|
void NodeTreeView::reExpandC(const QStringList &expanded)// 重新展开节点(带参数)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m_expanded.clear();
|
|
|
|
m_expanded.clear();
|
|
|
|
m_expanded = expanded.toVector();
|
|
|
|
m_expanded = expanded.toVector();
|
|
|
|
reExpandC();
|
|
|
|
reExpandC();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NodeTreeView::onChangeTagColorAction()
|
|
|
|
void NodeTreeView::onChangeTagColorAction()// 更改标签颜色动作
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto itemType = static_cast<NodeItem::Type>(
|
|
|
|
auto itemType = static_cast<NodeItem::Type>(
|
|
|
|
m_currentEditingIndex.data(NodeItem::Roles::ItemType).toInt());
|
|
|
|
m_currentEditingIndex.data(NodeItem::Roles::ItemType).toInt());
|
|
|
@ -193,13 +194,13 @@ void NodeTreeView::onChangeTagColorAction()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NodeTreeView::onRequestExpand(const QString &folderPath)
|
|
|
|
void NodeTreeView::onRequestExpand(const QString &folderPath)// 请求展开节点
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto m_model = dynamic_cast<NodeTreeModel *>(model());
|
|
|
|
auto m_model = dynamic_cast<NodeTreeModel *>(model());
|
|
|
|
expand(m_model->folderIndexFromIdPath(folderPath));
|
|
|
|
expand(m_model->folderIndexFromIdPath(folderPath));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NodeTreeView::onUpdateAbsPath(const QString &oldPath, const QString &newPath)
|
|
|
|
void NodeTreeView::onUpdateAbsPath(const QString &oldPath, const QString &newPath)// 更新绝对路径
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::transform(m_expanded.begin(), m_expanded.end(), m_expanded.begin(), [&](QString s) {
|
|
|
|
std::transform(m_expanded.begin(), m_expanded.end(), m_expanded.begin(), [&](QString s) {
|
|
|
|
s.replace(s.indexOf(oldPath), oldPath.size(), newPath);
|
|
|
|
s.replace(s.indexOf(oldPath), oldPath.size(), newPath);
|
|
|
@ -207,7 +208,7 @@ void NodeTreeView::onUpdateAbsPath(const QString &oldPath, const QString &newPat
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NodeTreeView::updateEditingIndex(QPoint pos)
|
|
|
|
void NodeTreeView::updateEditingIndex(QPoint pos)// 更新编辑索引
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto index = indexAt(pos);
|
|
|
|
auto index = indexAt(pos);
|
|
|
|
if (indexAt(pos) != m_currentEditingIndex && !m_isContextMenuOpened && !m_isEditing) {
|
|
|
|
if (indexAt(pos) != m_currentEditingIndex && !m_isContextMenuOpened && !m_isEditing) {
|
|
|
@ -224,13 +225,13 @@ void NodeTreeView::updateEditingIndex(QPoint pos)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NodeTreeView::closeCurrentEditor()
|
|
|
|
void NodeTreeView::closeCurrentEditor()// 关闭当前编辑器
|
|
|
|
{
|
|
|
|
{
|
|
|
|
closePersistentEditor(m_currentEditingIndex);
|
|
|
|
closePersistentEditor(m_currentEditingIndex);
|
|
|
|
m_currentEditingIndex = QModelIndex();
|
|
|
|
m_currentEditingIndex = QModelIndex();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NodeTreeView::selectionChanged(const QItemSelection &selected,
|
|
|
|
void NodeTreeView::selectionChanged(const QItemSelection &selected,// 选择发生变化时的处理
|
|
|
|
const QItemSelection &deselected)
|
|
|
|
const QItemSelection &deselected)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QTreeView::selectionChanged(selected, deselected);
|
|
|
|
QTreeView::selectionChanged(selected, deselected);
|
|
|
@ -289,7 +290,7 @@ void NodeTreeView::selectionChanged(const QItemSelection &selected,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NodeTreeView::currentChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
|
|
|
void NodeTreeView::currentChanged(const QModelIndex ¤t, const QModelIndex &previous)// 当前索引发生变化时的处理
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QTreeView::currentChanged(current, previous);
|
|
|
|
QTreeView::currentChanged(current, previous);
|
|
|
|
auto itemType = static_cast<NodeItem::Type>(current.data(NodeItem::Roles::ItemType).toInt());
|
|
|
|
auto itemType = static_cast<NodeItem::Type>(current.data(NodeItem::Roles::ItemType).toInt());
|
|
|
@ -302,7 +303,7 @@ void NodeTreeView::currentChanged(const QModelIndex ¤t, const QModelIndex
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NodeTreeView::dragEnterEvent(QDragEnterEvent *event)
|
|
|
|
void NodeTreeView::dragEnterEvent(QDragEnterEvent *event)// 拖动进入事件
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (event->mimeData()->hasFormat(NOTE_MIME)) {
|
|
|
|
if (event->mimeData()->hasFormat(NOTE_MIME)) {
|
|
|
|
event->acceptProposedAction();
|
|
|
|
event->acceptProposedAction();
|
|
|
@ -311,7 +312,7 @@ void NodeTreeView::dragEnterEvent(QDragEnterEvent *event)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NodeTreeView::dragMoveEvent(QDragMoveEvent *event)
|
|
|
|
void NodeTreeView::dragMoveEvent(QDragMoveEvent *event)// 拖动移动事件
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (event->mimeData()->hasFormat(NOTE_MIME)) {
|
|
|
|
if (event->mimeData()->hasFormat(NOTE_MIME)) {
|
|
|
|
auto index = indexAt(event->pos());
|
|
|
|
auto index = indexAt(event->pos());
|
|
|
@ -349,13 +350,13 @@ void NodeTreeView::dragMoveEvent(QDragMoveEvent *event)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NodeTreeView::reset()
|
|
|
|
void NodeTreeView::reset()// 重置视图
|
|
|
|
{
|
|
|
|
{
|
|
|
|
closeCurrentEditor();
|
|
|
|
closeCurrentEditor();
|
|
|
|
reExpandC();
|
|
|
|
reExpandC();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NodeTreeView::dropEvent(QDropEvent *event)
|
|
|
|
void NodeTreeView::dropEvent(QDropEvent *event)// 拖放事件
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (event->mimeData()->hasFormat(NOTE_MIME)) {
|
|
|
|
if (event->mimeData()->hasFormat(NOTE_MIME)) {
|
|
|
|
auto dropIndex = indexAt(event->pos());
|
|
|
|
auto dropIndex = indexAt(event->pos());
|
|
|
@ -385,12 +386,12 @@ void NodeTreeView::dropEvent(QDropEvent *event)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NodeTreeView::setIsEditing(bool newIsEditing)
|
|
|
|
void NodeTreeView::setIsEditing(bool newIsEditing)// 设置是否正在编辑
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m_isEditing = newIsEditing;
|
|
|
|
m_isEditing = newIsEditing;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NodeTreeView::onRenameFolderFinished(const QString &newName)
|
|
|
|
void NodeTreeView::onRenameFolderFinished(const QString &newName)// 重命名文件夹完成
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (m_currentEditingIndex.isValid()) {
|
|
|
|
if (m_currentEditingIndex.isValid()) {
|
|
|
|
auto itemType = static_cast<NodeItem::Type>(
|
|
|
|
auto itemType = static_cast<NodeItem::Type>(
|
|
|
@ -407,7 +408,7 @@ void NodeTreeView::onRenameFolderFinished(const QString &newName)
|
|
|
|
}*/
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NodeTreeView::onRenameTagFinished(const QString &newName)
|
|
|
|
void NodeTreeView::onRenameTagFinished(const QString &newName)// 重命名标签完成
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (m_currentEditingIndex.isValid()) {
|
|
|
|
if (m_currentEditingIndex.isValid()) {
|
|
|
|
auto itemType = static_cast<NodeItem::Type>(
|
|
|
|
auto itemType = static_cast<NodeItem::Type>(
|
|
|
@ -424,7 +425,7 @@ void NodeTreeView::onRenameTagFinished(const QString &newName)
|
|
|
|
}*/
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NodeTreeView::setCurrentIndexC(const QModelIndex &index)
|
|
|
|
void NodeTreeView::setCurrentIndexC(const QModelIndex &index)// 设置当前索引
|
|
|
|
{
|
|
|
|
{
|
|
|
|
setCurrentIndex(index);
|
|
|
|
setCurrentIndex(index);
|
|
|
|
clearSelection();
|
|
|
|
clearSelection();
|
|
|
@ -432,18 +433,18 @@ void NodeTreeView::setCurrentIndexC(const QModelIndex &index)
|
|
|
|
selectionModel()->setCurrentIndex(index, QItemSelectionModel::SelectCurrent);
|
|
|
|
selectionModel()->setCurrentIndex(index, QItemSelectionModel::SelectCurrent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NodeTreeView::setCurrentIndexNC(const QModelIndex &index)
|
|
|
|
void NodeTreeView::setCurrentIndexNC(const QModelIndex &index)// 设置当前索引(不改变选择模式)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
setCurrentIndex(index);
|
|
|
|
setCurrentIndex(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NodeTreeView::setTheme(Theme::Value theme)
|
|
|
|
void NodeTreeView::setTheme(Theme::Value theme)// 设置主题
|
|
|
|
{
|
|
|
|
{
|
|
|
|
setCSSThemeAndUpdate(this, theme);
|
|
|
|
setCSSThemeAndUpdate(this, theme);
|
|
|
|
m_theme = theme;
|
|
|
|
m_theme = theme;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NodeTreeView::onCustomContextMenu(QPoint point)
|
|
|
|
void NodeTreeView::onCustomContextMenu(QPoint point)// 自定义上下文菜单请求
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QModelIndex index = indexAt(point);
|
|
|
|
QModelIndex index = indexAt(point);
|
|
|
|
if (index.isValid()) {
|
|
|
|
if (index.isValid()) {
|
|
|
@ -471,7 +472,7 @@ void NodeTreeView::onCustomContextMenu(QPoint point)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NodeTreeView::setTreeSeparator(const QVector<QModelIndex> &newTreeSeparator,
|
|
|
|
void NodeTreeView::setTreeSeparator(const QVector<QModelIndex> &newTreeSeparator,// 设置树分隔符
|
|
|
|
const QModelIndex &defaultNotesIndex)
|
|
|
|
const QModelIndex &defaultNotesIndex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for (const auto &sep : qAsConst(m_treeSeparator)) {
|
|
|
|
for (const auto &sep : qAsConst(m_treeSeparator)) {
|
|
|
@ -484,7 +485,7 @@ void NodeTreeView::setTreeSeparator(const QVector<QModelIndex> &newTreeSeparator
|
|
|
|
m_defaultNotesIndex = defaultNotesIndex;
|
|
|
|
m_defaultNotesIndex = defaultNotesIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NodeTreeView::mouseMoveEvent(QMouseEvent *event)
|
|
|
|
void NodeTreeView::mouseMoveEvent(QMouseEvent *event)// 鼠标移动事件
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Q_D(NodeTreeView);
|
|
|
|
Q_D(NodeTreeView);
|
|
|
|
QPoint topLeft;
|
|
|
|
QPoint topLeft;
|
|
|
@ -511,7 +512,7 @@ void NodeTreeView::mouseMoveEvent(QMouseEvent *event)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NodeTreeView::mousePressEvent(QMouseEvent *event)
|
|
|
|
void NodeTreeView::mousePressEvent(QMouseEvent *event)// 鼠标按下事件
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Q_D(NodeTreeView);
|
|
|
|
Q_D(NodeTreeView);
|
|
|
|
d->delayedAutoScroll.stop();
|
|
|
|
d->delayedAutoScroll.stop();
|
|
|
@ -577,7 +578,7 @@ void NodeTreeView::mousePressEvent(QMouseEvent *event)
|
|
|
|
updateEditingIndex(event->pos());
|
|
|
|
updateEditingIndex(event->pos());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NodeTreeView::leaveEvent(QEvent *event)
|
|
|
|
void NodeTreeView::leaveEvent(QEvent *event)// 离开事件
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!m_isContextMenuOpened && !m_isEditing) {
|
|
|
|
if (!m_isContextMenuOpened && !m_isEditing) {
|
|
|
|
closeCurrentEditor();
|
|
|
|
closeCurrentEditor();
|
|
|
@ -585,7 +586,7 @@ void NodeTreeView::leaveEvent(QEvent *event)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NodeTreeView::mouseReleaseEvent(QMouseEvent *event)
|
|
|
|
void NodeTreeView::mouseReleaseEvent(QMouseEvent *event)// 鼠标释放
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Q_UNUSED(event);
|
|
|
|
Q_UNUSED(event);
|
|
|
|
Q_D(NodeTreeView);
|
|
|
|
Q_D(NodeTreeView);
|
|
|
@ -612,7 +613,7 @@ void NodeTreeView::mouseReleaseEvent(QMouseEvent *event)
|
|
|
|
d->pressedIndex = QPersistentModelIndex();
|
|
|
|
d->pressedIndex = QPersistentModelIndex();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NodeTreeView::mouseDoubleClickEvent(QMouseEvent *event)
|
|
|
|
void NodeTreeView::mouseDoubleClickEvent(QMouseEvent *event)// 鼠标双击
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Q_UNUSED(event);
|
|
|
|
Q_UNUSED(event);
|
|
|
|
Q_D(NodeTreeView);
|
|
|
|
Q_D(NodeTreeView);
|
|
|
|