You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
191 lines
6.7 KiB
191 lines
6.7 KiB
#ifndef NOTEEDITORLOGIC_H
|
|
#define NOTEEDITORLOGIC_H
|
|
|
|
#include <QObject>
|
|
#include <QTimer>
|
|
#include <QColor>
|
|
#include <QVector>
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)
|
|
# include <QWidget>
|
|
# include <QVariant>
|
|
# include <QJsonArray>
|
|
# include <QJsonObject>
|
|
# include <QRegularExpression>
|
|
#endif
|
|
|
|
#include "nodedata.h"
|
|
#include "editorsettingsoptions.h"
|
|
|
|
class CustomDocument;
|
|
class CustomMarkdownHighlighter;
|
|
class QLabel;
|
|
class QLineEdit;
|
|
class DBManager;
|
|
class TagListView;
|
|
class TagListModel;
|
|
class TagPool;
|
|
class TagListDelegate;
|
|
class QListWidget;
|
|
class NoteEditorLogic : public QObject// NoteEditorLogic 类,负责笔记编辑逻辑
|
|
{
|
|
Q_OBJECT
|
|
public:// NoteEditorLogic 类,负责笔记编辑逻辑
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)
|
|
explicit NoteEditorLogic(CustomDocument *textEdit, QLabel *editorDateLabel,
|
|
QLineEdit *searchEdit, QWidget *kanbanWidget, TagListView *tagListView,
|
|
TagPool *tagPool, DBManager *dbManager, QObject *parent = nullptr);
|
|
|
|
#else
|
|
explicit NoteEditorLogic(CustomDocument *textEdit, QLabel *editorDateLabel,
|
|
QLineEdit *searchEdit, TagListView *tagListView, TagPool *tagPool,
|
|
DBManager *dbManager, QObject *parent = nullptr);
|
|
#endif
|
|
|
|
// 获取是否启用 Markdown
|
|
bool markdownEnabled() const;
|
|
// 设置是否启用 Markdown
|
|
void setMarkdownEnabled(bool enabled);
|
|
// 获取笔记编辑日期
|
|
static QString getNoteDateEditor(const QString &dateEdited);
|
|
// 高亮搜索结果
|
|
void highlightSearch() const;
|
|
// 获取是否是临时笔记
|
|
bool isTempNote() const;
|
|
// 将笔记保存到数据库
|
|
void saveNoteToDB();
|
|
// 获取当前编辑的笔记 ID
|
|
int currentEditingNoteId() const;
|
|
// 删除当前笔记
|
|
void deleteCurrentNote();
|
|
|
|
// 获取文本的首行
|
|
static QString getFirstLine(const QString &str);
|
|
// 获取文本的第二行
|
|
static QString getSecondLine(const QString &str);
|
|
// 设置主题
|
|
void setTheme(Theme::Value theme, QColor textColor, qreal fontSize);
|
|
|
|
// 获取当前可适应的编辑器填充
|
|
int currentAdaptableEditorPadding() const;
|
|
// 设置当前可适应的编辑器填充
|
|
void setCurrentAdaptableEditorPadding(int newCurrentAdaptableEditorPadding);
|
|
|
|
// 获取当前最小编辑器填充
|
|
int currentMinimumEditorPadding() const;
|
|
// 设置当前最小编辑器填充
|
|
void setCurrentMinimumEditorPadding(int newCurrentMinimumEditorPadding);
|
|
|
|
public slots:
|
|
// 在编辑器中显示笔记
|
|
void showNotesInEditor(const QVector<NodeData> ¬es);
|
|
// 文本编辑器内容变化时的处理
|
|
void onTextEditTextChanged();
|
|
// 关闭编辑器
|
|
void closeEditor();
|
|
// 笔记标签列表发生变化时的处理
|
|
void onNoteTagListChanged(int noteId, const QSet<int> &tagIds);
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)
|
|
// 检查编辑器中的任务
|
|
bool checkForTasksInEditor();
|
|
// 重新排列文本编辑器中的任务
|
|
void rearrangeTasksInTextEditor(int startLinePosition, int endLinePosition,
|
|
int newLinePosition);
|
|
// 重新排列文本编辑器中的列
|
|
void rearrangeColumnsInTextEditor(int startLinePosition, int endLinePosition,
|
|
int newLinePosition);
|
|
// 检查某行的任务
|
|
void checkTaskInLine(int lineNumber);
|
|
// 取消检查某行的任务
|
|
void uncheckTaskInLine(int lineNumber);
|
|
// 更新任务文本
|
|
void updateTaskText(int startLinePosition, int endLinePosition, const QString &newText);
|
|
// 添加新任务
|
|
void addNewTask(int startLinePosition, const QString newTaskText);
|
|
// 移除任务
|
|
void removeTask(int startLinePosition, int endLinePosition);
|
|
// 添加新列
|
|
void addNewColumn(int startLinePosition, const QString &columnTitle);
|
|
// 移除列
|
|
void removeColumn(int startLinePosition, int endLinePosition);
|
|
// 更新列标题
|
|
void updateColumnTitle(int lineNumber, const QString &newText);
|
|
#endif
|
|
signals:
|
|
// 请求创建或更新笔记
|
|
void requestCreateUpdateNote(const NodeData ¬e);
|
|
// 笔记编辑关闭
|
|
void noteEditClosed(const NodeData ¬e, bool selectNext);
|
|
// 设置右侧框架部件的可见性
|
|
void setVisibilityOfFrameRightWidgets(bool);
|
|
// 设置右侧非编辑器部件的可见性
|
|
void setVisibilityOfFrameRightNonEditor(bool);
|
|
// 将笔记移动到列表视图顶部
|
|
void moveNoteToListViewTop(const NodeData ¬e);
|
|
// 更新列表中的笔记数据
|
|
void updateNoteDataInList(const NodeData ¬e);
|
|
// 请求删除笔记
|
|
void deleteNoteRequested(const NodeData ¬e);
|
|
// 显示看板视图
|
|
void showKanbanView();
|
|
// 隐藏看板视图
|
|
void hideKanbanView();
|
|
// 文本显示完成
|
|
void textShown();
|
|
// 看板显示完成
|
|
void kanbanShown();
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)
|
|
// 编辑器中找到任务
|
|
void tasksFoundInEditor(QVariant data);
|
|
// 清空看板模型
|
|
void clearKanbanModel();
|
|
// 重置看板设置
|
|
void resetKanbanSettings();
|
|
// 检查是否选择了多个笔记
|
|
void checkMultipleNotesSelected(QVariant isMultipleNotesSelected);
|
|
#endif
|
|
|
|
private:
|
|
// 将字符串转换为 QDateTime
|
|
static QDateTime getQDateTime(const QString &date);
|
|
// 显示当前笔记的标签列表
|
|
void showTagListForCurrentNote();
|
|
// 获取是否处于编辑模式
|
|
bool isInEditMode() const;
|
|
// 移动文本到新的行位置
|
|
QString moveTextToNewLinePosition(const QString &inputText, int startLinePosition,
|
|
int endLinePosition, int newLinePosition,
|
|
bool isColumns = false);
|
|
// 获取某行的任务数据
|
|
QMap<QString, int> getTaskDataInLine(const QString &line);
|
|
// 替换某行之间的文本
|
|
void replaceTextBetweenLines(int startLinePosition, int endLinePosition, QString &newText);
|
|
// 移除某行之间的文本
|
|
void removeTextBetweenLines(int startLinePosition, int endLinePosition);
|
|
// 添加新列到 JSON 数据
|
|
void appendNewColumn(QJsonArray &data, QJsonObject ¤tColumn, QString ¤tTitle,
|
|
QJsonArray &tasks);
|
|
// 向文本编辑器添加无标题列
|
|
void addUntitledColumnToTextEditor(int startLinePosition);
|
|
|
|
private:
|
|
CustomDocument *m_textEdit; // 文本编辑器
|
|
CustomMarkdownHighlighter *m_highlighter; // Markdown 高亮器
|
|
QLabel *m_editorDateLabel; // 编辑器日期标签
|
|
QLineEdit *m_searchEdit; // 搜索框
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)
|
|
QWidget *m_kanbanWidget; // 看板部件
|
|
#endif
|
|
TagListView *m_tagListView; // 标签列表视图
|
|
DBManager *m_dbManager; // 数据库管理器
|
|
QVector<NodeData> m_currentNotes; // 当前笔记数据
|
|
bool m_isContentModified; // 内容是否被修改
|
|
QTimer m_autoSaveTimer; // 自动保存定时器
|
|
TagListDelegate *m_tagListDelegate; // 标签列表委托
|
|
TagListModel *m_tagListModel; // 标签列表模型
|
|
QColor m_spacerColor; // 分隔符颜色
|
|
int m_currentAdaptableEditorPadding; // 当前可适应的编辑器填充
|
|
int m_currentMinimumEditorPadding; // 当前最小编辑器填充
|
|
};
|
|
|
|
#endif // NOTEEDITORLOGIC_H
|