develop
kkk 3 months ago
parent c5d4a9b9d9
commit c34f275c6b

@ -3,6 +3,7 @@
#include <QBoxLayout>
#include <QDebug>
// LabelEditType 类的构造函数
LabelEditType::LabelEditType(QWidget *parent) : QLabel(parent)
{
setContentsMargins(0, 0, 0, 0);
@ -15,6 +16,7 @@ LabelEditType::LabelEditType(QWidget *parent) : QLabel(parent)
connect(m_editor, &QLineEdit::editingFinished, this, &LabelEditType::onFinishedEdit);
}
// 打开编辑器
void LabelEditType::openEditor()
{
m_editor->setText(text());
@ -25,6 +27,7 @@ void LabelEditType::openEditor()
emit editingStarted();
}
// 编辑完成后的处理
void LabelEditType::onFinishedEdit()
{
m_editor->hide();
@ -32,4 +35,4 @@ void LabelEditType::onFinishedEdit()
setText(m_editor->text());
}
emit editingFinished(text());
}
}

@ -3,25 +3,32 @@
#include <QLabel>
// 自定义LabelEditType类继承自QLabel
class QLineEdit;
class LabelEditType : public QLabel
{
Q_OBJECT
public:
// 构造函数,接受一个父部件指针
explicit LabelEditType(QWidget *parent = nullptr);
public slots:
// 打开编辑器的槽函数
void openEditor();
private slots:
// 编辑完成后的槽函数
void onFinishedEdit();
signals:
// 编辑开始信号
void editingStarted();
// 编辑完成信号,携带编辑的文本
void editingFinished(const QString &text);
private:
// 编辑器指针
QLineEdit *m_editor;
};
#endif // LABELEDITTYPE_H
#endif // LABELEDITTYPE_H

@ -10,6 +10,7 @@
#include "tagpool.h"
#include <QTimer>
// 检查当前笔记 ID 是否无效
static bool isInvalidCurrentNotesId(const QSet<int> &currentNotesId)
{
if (currentNotesId.isEmpty()) {
@ -24,6 +25,7 @@ static bool isInvalidCurrentNotesId(const QSet<int> &currentNotesId)
return isInvalid;
}
// ListViewLogic 类的构造函数,负责初始化相关组件并设置信号与槽
ListViewLogic::ListViewLogic(NoteListView *noteView, NoteListModel *noteModel,
QLineEdit *searchEdit, QToolButton *clearButton, TagPool *tagPool,
DBManager *dbManager, QObject *parent)
@ -125,6 +127,7 @@ ListViewLogic::ListViewLogic(NoteListView *noteView, NoteListModel *noteModel,
&ListViewLogic::onListViewClicked);
}
// 选择指定的笔记
void ListViewLogic::selectNote(const QModelIndex &noteIndex)
{
if (noteIndex.isValid()) {
@ -138,6 +141,7 @@ void ListViewLogic::selectNote(const QModelIndex &noteIndex)
}
}
// 将笔记移动到列表顶部
void ListViewLogic::moveNoteToTop(const NodeData &note)
{
QModelIndex noteIndex = m_listModel->getNoteIndex(note.id());
@ -164,6 +168,7 @@ void ListViewLogic::moveNoteToTop(const NodeData &note)
}
}
// 设置笔记的数据
void ListViewLogic::setNoteData(const NodeData &note)
{
QModelIndex noteIndex = m_listModel->getNoteIndex(note.id());
@ -188,6 +193,7 @@ void ListViewLogic::setNoteData(const NodeData &note)
}
}
// 处理笔记编辑关闭事件
void ListViewLogic::onNoteEditClosed(const NodeData &note, bool selectNext)
{
if (note.isTempNote()) {
@ -209,12 +215,14 @@ void ListViewLogic::onNoteEditClosed(const NodeData &note, bool selectNext)
}
}
// 请求删除笔记
void ListViewLogic::deleteNoteRequested(const NodeData &note)
{
auto index = m_listModel->getNoteIndex(note.id());
deleteNoteRequestedI({ index });
}
// 选择当前笔记的上一笔记
void ListViewLogic::selectNoteUp()
{
auto currentIndex = m_listView->currentIndex();
@ -235,6 +243,7 @@ void ListViewLogic::selectNoteUp()
}
}
// 选择当前笔记的下一笔记
void ListViewLogic::selectNoteDown()
{
auto currentIndex = m_listView->currentIndex();
@ -259,15 +268,14 @@ void ListViewLogic::selectNoteDown()
/*!
* \brief ListViewLogic::onSearchEditTextChanged
* When text on searchEdit change:
* If there is a temp note "New Note" while searching, we delete it
* Saving the last selected note for recovery after searching
* Clear all the notes from scrollArea and
* If text is empty, reload all the notes from database
* Else, load all the notes contain the string in searchEdit from database
*
* "新笔记"
* 便
*
*
*
* \param keyword
*/
void ListViewLogic::onSearchEditTextChanged(const QString &keyword)
{
if (keyword.isEmpty()) {
@ -287,6 +295,7 @@ void ListViewLogic::onSearchEditTextChanged(const QString &keyword)
}
}
// 清除搜索
void ListViewLogic::clearSearch(bool createNewNote, int scrollToId)
{
m_listViewInfo.needCreateNewNote = createNewNote;
@ -295,6 +304,7 @@ void ListViewLogic::clearSearch(bool createNewNote, int scrollToId)
emit requestClearSearchUI();
}
// 加载笔记列表模型
void ListViewLogic::loadNoteListModel(const QVector<NodeData> &noteList, const ListViewInfo &inf)
{
auto currentNotesId = m_listViewInfo.currentNotesId;
@ -363,6 +373,7 @@ void ListViewLogic::loadNoteListModel(const QVector<NodeData> &noteList, const L
selectFirstNote();
}
// 添加标签请求处理
void ListViewLogic::onAddTagRequest(const QModelIndex &index, int tagId)
{
if (index.isValid()) {
@ -382,12 +393,14 @@ void ListViewLogic::onAddTagRequest(const QModelIndex &index, int tagId)
}
}
// 直接请求添加标签
void ListViewLogic::onAddTagRequestD(int noteId, int tagId)
{
auto index = m_listModel->getNoteIndex(noteId);
onAddTagRequest(index, tagId);
}
// 笔记移动到其他区域的处理
void ListViewLogic::onNoteMovedOut(int nodeId, int targetId)
{
auto index = m_listModel->getNoteIndex(nodeId);
@ -415,6 +428,7 @@ void ListViewLogic::onNoteMovedOut(int nodeId, int targetId)
}
}
// 设置最后选择的笔记
void ListViewLogic::setLastSelectedNote()
{
auto indexes = m_listView->selectedIndex();
@ -427,11 +441,13 @@ void ListViewLogic::setLastSelectedNote()
setLastSavedState(ids, 0);
}
// 请求加载最后选择的笔记
void ListViewLogic::loadLastSelectedNoteRequested()
{
requestLoadSavedState(2);
}
// 处理文件夹中的笔记列表请求
void ListViewLogic::onNotesListInFolderRequested(int parentID, bool isRecursive, bool newNote,
int scrollToId)
{
@ -449,6 +465,7 @@ void ListViewLogic::onNotesListInFolderRequested(int parentID, bool isRecursive,
}
}
// 处理标签中的笔记列表请求
void ListViewLogic::onNotesListInTagsRequested(const QSet<int> &tagIds, bool newNote,
int scrollToId)
{
@ -465,6 +482,7 @@ void ListViewLogic::onNotesListInTagsRequested(const QSet<int> &tagIds, bool new
}
}
// 选择多个笔记
void ListViewLogic::selectNotes(const QModelIndexList &indexes)
{
m_listView->clearSelection();
@ -482,6 +500,7 @@ void ListViewLogic::selectNotes(const QModelIndexList &indexes)
onNotePressed(indexes);
}
// 处理移除标签请求
void ListViewLogic::onRemoveTagRequest(const QModelIndex &index, int tagId)
{
if (index.isValid()) {
@ -503,14 +522,13 @@ void ListViewLogic::onRemoveTagRequest(const QModelIndex &index, int tagId)
/*!
* \brief MainWindow::onNotePressed
* When clicking on a note in the scrollArea:
* Unhighlight the previous selected note
* If selecting a note when temporery note exist, delete the temp note
* Highlight the selected note
* Load the selected note content into textedit
*
*
*
*
*
* \param index
*/
void ListViewLogic::onNotePressed(const QModelIndexList &indexes)
{
QVector<NodeData> notes;
@ -527,6 +545,7 @@ void ListViewLogic::onNotePressed(const QModelIndexList &indexes)
m_listView->setCurrentRowActive(false);
}
// 删除笔记请求的内部处理
void ListViewLogic::deleteNoteRequestedI(const QModelIndexList &indexes)
{
if (!indexes.empty()) {
@ -582,6 +601,7 @@ void ListViewLogic::deleteNoteRequestedI(const QModelIndexList &indexes)
}
}
// 请求恢复笔记的内部处理
void ListViewLogic::restoreNotesRequestedI(const QModelIndexList &indexes)
{
QModelIndexList needRestoredI;
@ -617,6 +637,7 @@ void ListViewLogic::restoreNotesRequestedI(const QModelIndexList &indexes)
}
}
// 更新列表视图的标签
void ListViewLogic::updateListViewLabel()
{
QString l1, l2;
@ -650,6 +671,7 @@ void ListViewLogic::updateListViewLabel()
emit listViewLabelChanged(l1, l2);
}
// 行数变化的处理
void ListViewLogic::onRowCountChanged()
{
m_listView->closeAllEditor();
@ -667,6 +689,7 @@ void ListViewLogic::onRowCountChanged()
}
}
// 双击笔记的处理
void ListViewLogic::onNoteDoubleClicked(const QModelIndex &index)
{
if (!index.isValid() || !m_listViewInfo.isInSearch) {
@ -676,11 +699,13 @@ void ListViewLogic::onNoteDoubleClicked(const QModelIndex &index)
clearSearch(false, id);
}
// 请求设置笔记为置顶的处理
void ListViewLogic::onSetPinnedNoteRequested(const QModelIndexList &indexes, bool isPinned)
{
m_listModel->setNotesIsPinned(indexes, isPinned);
}
// 列表视图点击的处理
void ListViewLogic::onListViewClicked()
{
if (m_listModel->rowCount() > 1) {
@ -700,6 +725,7 @@ void ListViewLogic::onListViewClicked()
}
}
// 选择第一笔记
void ListViewLogic::selectFirstNote()
{
if (m_listModel->rowCount() > 0) {
@ -714,6 +740,7 @@ void ListViewLogic::selectFirstNote()
}
}
// 设置主题
void ListViewLogic::setTheme(Theme::Value theme)
{
m_listView->setTheme(theme);
@ -721,22 +748,26 @@ void ListViewLogic::setTheme(Theme::Value theme)
m_listView->update();
}
// 检查动画是否正在运行
bool ListViewLogic::isAnimationRunning()
{
return m_listDelegate->animationState() == QTimeLine::Running;
}
// 设置最后保存的状态
void ListViewLogic::setLastSavedState(const QSet<int> &lastSelectedNotes, int needLoadSavedState)
{
m_needLoadSavedState = needLoadSavedState;
m_lastSelectedNotes = lastSelectedNotes;
}
// 请求加载保存的状态
void ListViewLogic::requestLoadSavedState(int needLoadSavedState)
{
m_needLoadSavedState = needLoadSavedState;
}
// 选择所有笔记
void ListViewLogic::selectAllNotes()
{
if (m_listModel->rowCount() > 50) {
@ -771,7 +802,8 @@ void ListViewLogic::selectAllNotes()
onNotePressed(m_listView->selectedIndex());
}
// 获取当前视图信息
const ListViewInfo &ListViewLogic::listViewInfo() const
{
return m_listViewInfo;
}
}

@ -16,83 +16,136 @@ class QLineEdit;
class QToolButton;
class TagPool;
// 负责笔记列表视图逻辑的类
class ListViewLogic : public QObject
{
Q_OBJECT
public:
// 构造函数,初始化笔记视图、笔记模型、搜索框等
explicit ListViewLogic(NoteListView *noteView, NoteListModel *noteModel, QLineEdit *searchEdit,
QToolButton *clearButton, TagPool *tagPool, DBManager *dbManager,
QObject *parent = nullptr);
// 选择指定索引的笔记
void selectNote(const QModelIndex &noteIndex);
// 获取当前列表视图的信息
const ListViewInfo &listViewInfo() const;
// 选择第一个笔记
void selectFirstNote();
// 设置主题
void setTheme(Theme::Value theme);
// 检查动画是否正在运行
bool isAnimationRunning();
// 设置最后保存的状态
void setLastSavedState(const QSet<int> &lastSelectedNotes, int needLoadSavedState = 2);
// 请求加载保存的状态
void requestLoadSavedState(int needLoadSavedState);
// 选择所有笔记
void selectAllNotes();
public slots:
// 将笔记移动到顶部
void moveNoteToTop(const NodeData &note);
// 设置笔记数据
void setNoteData(const NodeData &note);
// 笔记编辑关闭后的处理
void onNoteEditClosed(const NodeData &note, bool selectNext);
// 请求删除笔记
void deleteNoteRequested(const NodeData &note);
// 选择上一个笔记
void selectNoteUp();
// 选择下一个笔记
void selectNoteDown();
// 搜索框文本改变的处理
void onSearchEditTextChanged(const QString &keyword);
// 清除搜索
void clearSearch(bool createNewNote = false, int scrollToId = SpecialNodeID::InvalidNodeId);
// 添加标签请求的处理
void onAddTagRequestD(int noteId, int tagId);
// 笔记移动事件处理
void onNoteMovedOut(int nodeId, int targetId);
// 设置最后选择的笔记
void setLastSelectedNote();
// 请求加载最后选择的笔记
void loadLastSelectedNoteRequested();
// 请求在文件夹中获取笔记列表
void onNotesListInFolderRequested(int parentID, bool isRecursive, bool newNote, int scrollToId);
// 请求通过标签获取笔记列表
void onNotesListInTagsRequested(const QSet<int> &tagIds, bool newNote, int scrollToId);
// 选择笔记
void selectNotes(const QModelIndexList &indexes);
signals:
// 显示笔记在编辑器中的信号
void showNotesInEditor(const QVector<NodeData> &notesData);
// 请求添加标签到数据库的信号
void requestAddTagDb(int noteId, int tagId);
// 请求从数据库中移除标签的信号
void requestRemoveTagDb(int noteId, int tagId);
// 请求从数据库中移除笔记的信号
void requestRemoveNoteDb(const NodeData &noteData);
// 请求将笔记移动到数据库的信号
void requestMoveNoteDb(int noteId, const NodeData &targetFolder);
// 请求高亮搜索的信号
void requestHighlightSearch();
// 关闭笔记编辑器的信号
void closeNoteEditor();
// 笔记标签列表更改的信号
void noteTagListChanged(int noteId, const QSet<int> &tagIds);
// 请求在数据库中搜索的信号
void requestSearchInDb(const QString &keyword, const ListViewInfo &inf);
// 请求清除数据库中的搜索的信号
void requestClearSearchDb(const ListViewInfo &inf);
// 请求清除UI中的搜索的信号
void requestClearSearchUI();
// 请求新笔记的信号
void requestNewNote();
// 请求移动笔记的信号
void moveNoteRequested(int id, int target);
// 列表视图标签改变的信号
void listViewLabelChanged(const QString &label1, const QString &label2);
// 设置新笔记按钮可见性的信号
void setNewNoteButtonVisible(bool visible);
// 请求在文件夹中获取笔记列表的信号
void requestNotesListInFolder(int parentID, bool isRecursive, bool newNote, int scrollToId);
// 请求通过标签获取笔记列表的信号
void requestNotesListInTags(const QSet<int> &tagIds, bool newNote, int scrollToId);
private slots:
// 加载笔记列表模型
void loadNoteListModel(const QVector<NodeData> &noteList, const ListViewInfo &inf);
// 处理添加标签请求
void onAddTagRequest(const QModelIndex &index, int tagId);
// 处理移除标签请求
void onRemoveTagRequest(const QModelIndex &index, int tagId);
// 处理笔记按下事件
void onNotePressed(const QModelIndexList &indexes);
// 请求删除笔记的处理
void deleteNoteRequestedI(const QModelIndexList &indexes);
// 请求恢复笔记的处理
void restoreNotesRequestedI(const QModelIndexList &indexes);
// 更新列表视图标签
void updateListViewLabel();
// 行数改变的处理
void onRowCountChanged();
// 处理双击笔记事件
void onNoteDoubleClicked(const QModelIndex &index);
// 请求设置固定笔记的处理
void onSetPinnedNoteRequested(const QModelIndexList &indexes, bool isPinned);
// 处理列表视图点击事件
void onListViewClicked();
private:
NoteListView *m_listView;
NoteListModel *m_listModel;
QLineEdit *m_searchEdit;
QToolButton *m_clearButton;
DBManager *m_dbManager;
NoteListDelegate *m_listDelegate;
TagPool *m_tagPool;
ListViewInfo m_listViewInfo;
QVector<QModelIndex> m_editorIndexes;
NoteListView *m_listView; // 笔记列表视图
NoteListModel *m_listModel; // 笔记列表模型
QLineEdit *m_searchEdit; // 搜索框
QToolButton *m_clearButton; // 清除按钮
DBManager *m_dbManager; // 数据库管理器
NoteListDelegate *m_listDelegate; // 笔记列表委托
TagPool *m_tagPool; // 标签池
ListViewInfo m_listViewInfo; // 列表视图信息
QVector<QModelIndex> m_editorIndexes; // 编辑器索引
int m_needLoadSavedState;
QSet<int> m_lastSelectedNotes;
int m_needLoadSavedState; // 需要加载的保存状态
QSet<int> m_lastSelectedNotes; // 最后选择的笔记集合
};
#endif // LISTVIEWLOGIC_H
#endif // LISTVIEWLOGIC_H

@ -23,32 +23,33 @@
**/
// Credit: https://github.com/carlonluca/lqtutils
#ifndef LQTUTILS_ENUM_H
#define LQTUTILS_ENUM_H
#include <QObject>
#include <QQmlEngine>
#define L_DECLARE_ENUM(enumName, ...) \
namespace enumName { \
Q_NAMESPACE \
enum Value { __VA_ARGS__ }; \
Q_ENUM_NS(Value) \
inline int qmlRegister##enumName(const char *uri, int major, int minor) \
{ \
return qmlRegisterUncreatableMetaObject(enumName::staticMetaObject, uri, major, minor, \
#enumName, "Access to enums & flags only"); \
} \
inline int qRegisterMetaType() \
{ \
return ::qRegisterMetaType<enumName::Value>(#enumName); \
} \
inline void registerEnum(const char *uri, int major, int minor) \
{ \
enumName::qmlRegister##enumName(uri, major, minor); \
enumName::qRegisterMetaType(); \
} \
}
// 宏定义 L_DECLARE_ENUM 用于声明枚举类型及其相关函数
#define L_DECLARE_ENUM(enumName, ...) \
namespace enumName { \
Q_NAMESPACE \
enum Value { __VA_ARGS__ }; \
Q_ENUM_NS(Value) \
// 注册 QML 中的枚举类型
inline int qmlRegister##enumName(const char *uri, int major, int minor)
{
return qmlRegisterUncreatableMetaObject(enumName::staticMetaObject, uri, major, minor,
#enumName, "Access to enums & flags only");
} // 注册元类型
inline int qRegisterMetaType()
{
return ::qRegisterMetaType<enumName::Value>(#enumName);
} // 注册枚举类型
inline void registerEnum(const char *uri, int major, int minor)
{
enumName::qmlRegister##enumName(uri, major, minor);
enumName::qRegisterMetaType();
}
}
#endif // LQTUTILS_ENUM_H
#endif // LQTUTILS_ENUM_H

@ -3,16 +3,11 @@
* Just a meantime project to see the ability of qt, the framework that my OS might be based on
* And for those linux users that believe in the power of notes
*********************************************************************************************/
#include "mainwindow.h"
#include "singleinstance.h"
#include <QApplication>
#include <QFontDatabase>
// 主函数,程序入口
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
// Set application information
// 设置应用程序信息
app.setApplicationName("Notes");
app.setApplicationVersion(APP_VERSION);
@ -24,6 +19,7 @@ int main(int argc, char *argv[])
app.setAttribute(Qt::AA_DisableWindowContextHelpButton);
#endif
// 尝试加载字体并报告错误
if (QFontDatabase::addApplicationFont(":/fonts/fontawesome/fa-solid-900.ttf") < 0)
qWarning() << "FontAwesome Solid cannot be loaded !";
@ -36,7 +32,7 @@ int main(int argc, char *argv[])
if (QFontDatabase::addApplicationFont(":/fonts/material/material-symbols-outlined.ttf") < 0)
qWarning() << "Material Symbols cannot be loaded !";
// Load fonts from resources
// 从资源加载字体
// Roboto
QFontDatabase::addApplicationFont(":/fonts/roboto-hinted/Roboto-Bold.ttf");
QFontDatabase::addApplicationFont(":/fonts/roboto-hinted/Roboto-Medium.ttf");
@ -56,38 +52,38 @@ int main(int argc, char *argv[])
QFontDatabase::addApplicationFont(":/fonts/sourcesanspro/SourceSansPro-SemiBold.ttf");
QFontDatabase::addApplicationFont(":/fonts/sourcesanspro/SourceSansPro-SemiBoldItalic.ttf");
// Trykker
// Trykker 字体
QFontDatabase::addApplicationFont(":/fonts/trykker/Trykker-Regular.ttf");
// Mate
// Mate 字体
QFontDatabase::addApplicationFont(":/fonts/mate/Mate-Regular.ttf");
QFontDatabase::addApplicationFont(":/fonts/mate/Mate-Italic.ttf");
// PT Serif
// PT Serif 字体
QFontDatabase::addApplicationFont(":/fonts/ptserif/PTSerif-Regular.ttf");
QFontDatabase::addApplicationFont(":/fonts/ptserif/PTSerif-Italic.ttf");
QFontDatabase::addApplicationFont(":/fonts/ptserif/PTSerif-Bold.ttf");
QFontDatabase::addApplicationFont(":/fonts/ptserif/PTSerif-BoldItalic.ttf");
// iA Mono
// iA Mono 字体
QFontDatabase::addApplicationFont(":/fonts/iamono/iAWriterMonoS-Regular.ttf");
QFontDatabase::addApplicationFont(":/fonts/iamono/iAWriterMonoS-Italic.ttf");
QFontDatabase::addApplicationFont(":/fonts/iamono/iAWriterMonoS-Bold.ttf");
QFontDatabase::addApplicationFont(":/fonts/iamono/iAWriterMonoS-BoldItalic.ttf");
// iA Duo
// iA Duo 字体
QFontDatabase::addApplicationFont(":/fonts/iaduo/iAWriterDuoS-Regular.ttf");
QFontDatabase::addApplicationFont(":/fonts/iaduo/iAWriterDuoS-Italic.ttf");
QFontDatabase::addApplicationFont(":/fonts/iaduo/iAWriterDuoS-Bold.ttf");
QFontDatabase::addApplicationFont(":/fonts/iaduo/iAWriterDuoS-BoldItalic.ttf");
// iA Quattro
// iA Quattro 字体
QFontDatabase::addApplicationFont(":/fonts/iaquattro/iAWriterQuattroS-Regular.ttf");
QFontDatabase::addApplicationFont(":/fonts/iaquattro/iAWriterQuattroS-Italic.ttf");
QFontDatabase::addApplicationFont(":/fonts/iaquattro/iAWriterQuattroS-Bold.ttf");
QFontDatabase::addApplicationFont(":/fonts/iaquattro/iAWriterQuattroS-BoldItalic.ttf");
// Prevent many instances of the app to be launched
// 防止多个应用实例启动
QString name = "com.awsomeness.notes";
SingleInstance instance;
if (instance.hasPrevious(name)) {
@ -96,13 +92,13 @@ int main(int argc, char *argv[])
instance.listen(name);
// Create and Show the app
// 创建并显示应用程序窗口
MainWindow w;
w.show();
// Bring the Notes window to the front
// 将Notes窗口置于最前
QObject::connect(&instance, &SingleInstance::newInstance, &w,
[&]() { (&w)->setMainWindowVisibility(true); });
return app.exec();
}
}

File diff suppressed because it is too large Load Diff

@ -6,7 +6,6 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtGui>
#include <QtCore>
@ -52,12 +51,15 @@
#include "nodetreeview.h"
#include "editorsettingsoptions.h"
// 定义订阅状态枚举
L_DECLARE_ENUM(SubscriptionStatus, NoSubscription, Active, ActivationLimitReached, Expired, Invalid,
EnteredGracePeriod, GracePeriodOver, NoInternetConnection, UnknownError)
namespace Ui {
class MainWindow;
}
// 前向声明类
class TreeViewLogic;
class ListViewLogic;
class NoteEditorLogic;
@ -75,6 +77,8 @@ using MainWindowBase = CFramelessWindow;
#else
using MainWindowBase = QMainWindow;
#endif
// 主窗口类
class MainWindow : public MainWindowBase
{
Q_OBJECT
@ -109,129 +113,232 @@ public:
Q_ENUM(ShadowSide)
Q_ENUM(StretchSide)
// 构造函数
explicit MainWindow(QWidget *parent = nullptr);
// 析构函数
~MainWindow() override;
// 设置主窗口可见性
void setMainWindowVisibility(bool state);
public slots:
// 保存最近选择的文件夹标签
void saveLastSelectedFolderTags(bool isFolder, const QString &folderPath,
const QSet<int> &tagId);
// 保存展开的文件夹
void saveExpandedFolder(const QStringList &folderPaths);
// 保存最近选择的笔记
void saveLastSelectedNote(const QSet<int> &notesId);
// 从样式按钮改变编辑器字体类型
void changeEditorFontTypeFromStyleButtons(FontTypeface::Value fontType, int chosenFontIndex);
// 从样式按钮改变编辑器字体大小
void changeEditorFontSizeFromStyleButtons(FontSizeAction::Value fontSizeAction);
// 从样式按钮改变编辑器文本宽度
void changeEditorTextWidthFromStyleButtons(EditorTextWidth::Value editorTextWidth);
// 重置编辑器设置
void resetEditorSettings();
// 设置主题
void setTheme(Theme::Value theme);
// 设置看板可见性
void setKanbanVisibility(bool isVisible);
// 折叠笔记列表
void collapseNoteList();
// 展开笔记列表
void expandNoteList();
// 折叠文件夹树
void collapseFolderTree();
// 展开文件夹树
void expandFolderTree();
// 设置Markdown启用状态
void setMarkdownEnabled(bool isMarkdownEnabled);
// 设置窗口置顶
void stayOnTop(bool checked);
// 将当前笔记移至回收站
void moveCurrentNoteToTrash();
// 切换编辑器设置
void toggleEditorSettings();
// 从快速视图设置编辑器设置可见性
void setEditorSettingsFromQuickViewVisibility(bool isVisible);
// 设置编辑器设置滚动条位置
void setEditorSettingsScrollBarPosition(double position);
// 设置激活成功的状态
void setActivationSuccessful(QString licenseKey, bool removeGracePeriodStartedDate = true);
// 检查专业版
void checkProVersion();
// 获取用户许可密钥
QVariant getUserLicenseKey();
protected:
// 重新绘制事件
void paintEvent(QPaintEvent *event) override;
// 重新调整事件
void resizeEvent(QResizeEvent *event) override;
// 关闭事件
void closeEvent(QCloseEvent *event) override;
// 鼠标按下事件
void mousePressEvent(QMouseEvent *event) override;
// 鼠标移动事件
void mouseMoveEvent(QMouseEvent *event) override;
// 移动事件
void moveEvent(QMoveEvent *event) override;
// 鼠标释放事件
void mouseReleaseEvent(QMouseEvent *event) override;
// 鼠标双击事件
void mouseDoubleClickEvent(QMouseEvent *event) override;
// 离开事件
void leaveEvent(QEvent *) override;
// 变更事件
void changeEvent(QEvent *event) override;
// 事件过滤器
bool eventFilter(QObject *object, QEvent *event) override;
private:
// UI界面指针
Ui::MainWindow *ui;
// 设置数据库指针
QSettings *m_settingsDatabase;
// 清除按钮
QToolButton *m_clearButton;
// 搜索按钮
QToolButton *m_searchButton;
// 绿色最大化按钮
QPushButton *m_greenMaximizeButton;
// 红色关闭按钮
QPushButton *m_redCloseButton;
// 黄色最小化按钮
QPushButton *m_yellowMinimizeButton;
// 交通灯布局
QHBoxLayout m_trafficLightLayout;
// 新笔记按钮
QPushButton *m_newNoteButton;
// 点点按钮
QPushButton *m_dotsButton;
// 全局设置按钮
QPushButton *m_globalSettingsButton;
// 切换树视图按钮
QPushButton *m_toggleTreeViewButton;
// 切换文本视图按钮
QPushButton *m_switchToTextViewButton;
// 切换看板视图按钮
QPushButton *m_switchToKanbanViewButton;
// 文本编辑器
CustomDocument *m_textEdit;
// 笔记编辑器逻辑
NoteEditorLogic *m_noteEditorLogic;
// 搜索框
QLineEdit *m_searchEdit;
// 编辑器日期标签
QLabel *m_editorDateLabel;
// 分割器
QSplitter *m_splitter;
// 笔记列表小部件
QWidget *m_noteListWidget;
// 文件夹小部件
QWidget *m_foldersWidget;
// 系统托盘图标
QSystemTrayIcon *m_trayIcon;
#if !defined(Q_OS_MAC)
// 恢复动作
QAction *m_restoreAction;
// 退出动作
QAction *m_quitAction;
#endif
// 笔记列表视图
NoteListView *m_listView;
// 笔记列表模型
NoteListModel *m_listModel;
// 列表视图逻辑
ListViewLogic *m_listViewLogic;
// 节点树视图
NodeTreeView *m_treeView;
// 节点树模型
NodeTreeModel *m_treeModel;
// 树视图逻辑
TreeViewLogic *m_treeViewLogic;
#if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)
// 看板快速视图
QQuickView m_kanbanQuickView;
// 看板小部件
QWidget *m_kanbanWidget;
#endif
// 编辑器设置快速视图
QQuickView m_editorSettingsQuickView;
// 编辑器设置小部件
QWidget *m_editorSettingsWidget;
// 标签池
TagPool *m_tagPool;
// 数据库管理器
DBManager *m_dbManager;
// 数据库线程
QThread *m_dbThread;
// 分割器样式
SplitterStyle *m_splitterStyle;
#if defined(UPDATE_CHECKER)
// 更新窗口
UpdaterWindow m_updater;
#endif
// 关于窗口
AboutWindow m_aboutWindow;
// 拉伸边
StretchSide m_stretchSide;
// 自启动
Autostart m_autostart;
// 鼠标按下坐标
int m_mousePressX;
int m_mousePressY;
// 回收站计数器
int m_trashCounter;
// 布局边距
int m_layoutMargin;
// 阴影宽度
int m_shadowWidth;
// 节点树宽度
int m_nodeTreeWidth;
// 小编辑器宽度
int m_smallEditorWidth;
// 大编辑器宽度
int m_largeEditorWidth;
// 能否移动窗口
bool m_canMoveWindow;
// 能否调整窗口大小
bool m_canStretchWindow;
// 临时标志
bool m_isTemp;
// 列表视图滚动条隐藏标志
bool m_isListViewScrollBarHidden;
// 操作运行标志
bool m_isOperationRunning;
#if defined(UPDATE_CHECKER)
// 不显示更新窗口标志
bool m_dontShowUpdateWindow;
#endif
// 始终置顶标志
bool m_alwaysStayOnTop;
// 使用本机窗口框架标志
bool m_useNativeWindowFrame;
// 隐藏到托盘标志
bool m_hideToTray;
// 样式表
QString m_styleSheet;
// Serif字体列表
QStringList m_listOfSerifFonts;
// Sans Serif字体列表
QStringList m_listOfSansSerifFonts;
// Mono字体列表
QStringList m_listOfMonoFonts;
// 选择的Serif字体索引
int m_chosenSerifFontIndex;
// 选择的Sans Serif字体索引
int m_chosenSansSerifFontIndex;
// 选择的Mono字体索引
int m_chosenMonoFontIndex;
// 编辑器中等字体大小
int m_editorMediumFontSize;
// 当前字体大小
int m_currentFontPointSize;
struct m_charsLimitPerFont
{
@ -239,166 +346,309 @@ private:
int serif;
int sansSerif;
} m_currentCharsLimitPerFont;
// 当前字体类型
FontTypeface::Value m_currentFontTypeface;
// 当前字体家族
QString m_currentFontFamily;
// 当前选定字体
QFont m_currentSelectedFont;
// 显示字体
QString m_displayFont;
// 当前主题
Theme::Value m_currentTheme;
// 当前编辑器文本颜色
QColor m_currentEditorTextColor;
// 非编辑器小部件可见性标志
bool m_areNonEditorWidgetsVisible;
#if !defined(Q_OS_MAC)
// 文本编辑滚动条定时器
QTimer *m_textEditScrollBarTimer;
// 文本编辑滚动条定时器持续时间
int m_textEditScrollBarTimerDuration;
#endif
// 帧右上小部件可见性标志
bool m_isFrameRightTopWidgetsVisible;
// 从快速视图可见的编辑器设置标志
bool m_isEditorSettingsFromQuickViewVisible;
// 专业版激活标志
bool m_isProVersionActivated;
// 本地许可数据
QSettings *m_localLicenseData;
// 支付详情
QJsonObject m_paymentDetails;
// 订阅状态
SubscriptionStatus::Value m_subscriptionStatus;
// 订阅窗口快速视图
QQuickView m_subscriptionWindowQuickView;
// 订阅窗口小部件
QWidget *m_subscriptionWindowWidget;
// 订阅窗口引擎
QQmlApplicationEngine m_subscriptionWindowEngine;
// 订阅窗口
QWindow *m_subscriptionWindow;
// 购买数据备用1
QString m_purchaseDataAlt1;
// 购买数据备用2
QString m_purchaseDataAlt2;
// 数据缓冲区
QByteArray *m_dataBuffer;
// 网络访问管理器
QNetworkAccessManager *m_netManager;
// 备用请求1
QNetworkRequest m_reqAlt1;
// 备用请求2
QNetworkRequest m_reqAlt2;
// 第一次尝试的网络购买数据回复
QNetworkReply *m_netPurchaseDataReplyFirstAttempt;
// 第二次尝试的网络购买数据回复
QNetworkReply *m_netPurchaseDataReplySecondAttempt;
// 用户许可密钥
QString m_userLicenseKey;
// 主菜单
QMenu m_mainMenu;
// 购买或管理订阅动作
QAction *m_buyOrManageSubscriptionAction;
// 检查格式是否已应用
bool alreadyAppliedFormat(const QString &formatChars);
// 应用格式
void applyFormat(const QString &formatChars);
// 设置主窗口
void setupMainWindow();
// 设置字体
void setupFonts();
// 设置托盘图标
void setupTrayIcon();
// 设置快捷键
void setupKeyboardShortcuts();
// 设置分割器
void setupSplitter();
// 设置按钮
void setupButtons();
// 设置信号与槽
void setupSignalsSlots();
#if defined(UPDATE_CHECKER)
// 自动检查更新
void autoCheckForUpdates();
#endif
// 设置搜索框
void setupSearchEdit();
// 设置订阅窗口
void setupSubscrirptionWindow();
void setupEditorSettings();
// 设置编辑器样式表
void setupTextEditStyleSheet(int paddingLeft, int paddingRight);
// 对齐文本编辑器文本
void alignTextEditText();
// 设置文本编辑器
void setupTextEdit();
#if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)
// 设置看板视图
void setupKanbanView();
#endif
// 设置数据库
void setupDatabases();
// 设置模型视图
void setupModelView();
// 设置全局设置菜单
void setupGlobalSettingsMenu();
// 初始化设置数据库
void initializeSettingsDatabase();
// 为滚动区域设置布局
void setLayoutForScrollArea();
// 设置按钮和字段的启用状态
void setButtonsAndFieldsEnabled(bool doEnable);
// 重置格式
void resetFormat(const QString &formatChars);
// 恢复状态
void restoreStates();
// 从版本0.9.0迁移
void migrateFromV0_9_0();
// 执行导入
void executeImport(const bool replace);
// 从版本0.9.0迁移笔记
void migrateNoteFromV0_9_0(const QString &notePath);
// 从版本0.9.0迁移回收站
void migrateTrashFromV0_9_0(const QString &trashPath);
// 根据字体类型设置当前字体
void setCurrentFontBasedOnTypeface(FontTypeface::Value selectedFontTypeFace);
// 设置右侧小部件可见性
void setVisibilityOfFrameRightWidgets(bool isVisible);
// 设置非编辑器小部件可见性
void setVisibilityOfFrameRightNonEditor(bool isVisible);
// 设置窗口按钮可见性
void setWindowButtonsVisible(bool isVisible);
// 显示编辑器设置
void showEditorSettings();
// 更新选定的编辑器设置选项
void updateSelectedOptionsEditorSettings();
// 添加阴影
void dropShadow(QPainter &painter, ShadowType type, ShadowSide side);
// 使用渐变填充矩形
void fillRectWithGradient(QPainter &painter, QRect rect, QGradient &gradient);
// 高斯分布
double gaussianDist(double x, const double center, double sigma) const;
// 调整并定位编辑器设置窗口
void resizeAndPositionEditorSettingsWindow();
// 获取支付详情信号与槽
void getPaymentDetailsSignalsSlots();
// 验证许可证信号与槽
void verifyLicenseSignalsSlots();
// 获取订阅状态
void getSubscriptionStatus();
// 设置边距
void setMargins(QMargins margins);
private slots:
// 初始化数据
void InitData();
// 系统托盘图标激活
void onSystemTrayIconActivated(QSystemTrayIcon::ActivationReason reason);
// 新笔记按钮点击
void onNewNoteButtonClicked();
// 点点按钮点击
void onDotsButtonClicked();
// 切换到看板视图按钮点击
void onSwitchToKanbanViewButtonClicked();
// 全局设置按钮点击
void onGlobalSettingsButtonClicked();
// 清除按钮点击
void onClearButtonClicked();
// 绿色最大化按钮按下
void onGreenMaximizeButtonPressed();
// 黄色最小化按钮按下
void onYellowMinimizeButtonPressed();
// 红色关闭按钮按下
void onRedCloseButtonPressed();
// 绿色最大化按钮点击
void onGreenMaximizeButtonClicked();
// 黄色最小化按钮点击
void onYellowMinimizeButtonClicked();
// 红色关闭按钮点击
void onRedCloseButtonClicked();
// 重置块格式
void resetBlockFormat();
// 创建新笔记
void createNewNote();
// 向下选择笔记
void selectNoteDown();
// 向上选择笔记
void selectNoteUp();
// 设置文本焦点
void setFocusOnText();
// 全屏窗口
void fullscreenWindow();
// 制作代码
void makeCode();
// 制作粗体
void makeBold();
// 制作斜体
void makeItalic();
// 制作删除线
void makeStrikethrough();
// 最大化窗口
void maximizeWindow();
// 最小化窗口
void minimizeWindow();
// 退出应用程序
void QuitApplication();
#if defined(UPDATE_CHECKER)
// 检查更新
void checkForUpdates();
#endif
// 切换笔记列表
void toggleNoteList();
// 切换文件夹树
void toggleFolderTree();
// 导入笔记文件
void importNotesFile();
// 导出笔记文件
void exportNotesFile();
// 恢复笔记文件
void restoreNotesFile();
// 增加标题
void increaseHeading();
// 减小标题
void decreaseHeading();
// 设置标题
void setHeading(int level);
// 设置使用本机窗口框架
void setUseNativeWindowFrame(bool useNativeWindowFrame);
// 设置隐藏到托盘
void setHideToTray(bool enabled);
// 切换始终置顶
void toggleStayOnTop();
// 搜索框回车按下
void onSearchEditReturnPressed();
// 删除选中笔记
void deleteSelectedNote();
// 清除搜索框
void clearSearch();
// 显示错误信息
void showErrorMessage(const QString &title, const QString &content);
// 设置笔记列表加载状态
void setNoteListLoading();
// 选择所有笔记
void selectAllNotesInList();
// 更新框架
void updateFrame();
// 检查是否是标题栏
bool isTitleBar(int x, int y) const;
// 打开订阅窗口
void openSubscriptionWindow();
signals:
// 请求节点树
void requestNodesTree();
// 请求打开数据库管理器
void requestOpenDBManager(const QString &path, bool doCreate);
// 请求恢复笔记
void requestRestoreNotes(const QString &filePath);
// 请求导入笔记
void requestImportNotes(const QString &filePath);
// 请求导出笔记
void requestExportNotes(QString fileName);
// 请求从版本0.9.0迁移笔记
void requestMigrateNotesFromV0_9_0(QVector<NodeData> &noteList);
// 请求从版本0.9.0迁移回收站
void requestMigrateTrashFromV0_9_0(QVector<NodeData> &noteList);
// 请求从版本1.5.0迁移笔记
void requestMigrateNotesFromV1_5_0(const QString &path);
// 请求更改数据库路径
void requestChangeDatabasePath(const QString &newPath);
// 主题变化信号
void themeChanged(QVariant theme);
// 平台设置信号
void platformSet(QVariant platform);
// Qt版本设置信号
void qtVersionSet(QVariant qtVersion);
// 编辑器设置显示信号
void editorSettingsShowed(QVariant data);
// 主窗口大小改变信号
void mainWindowResized(QVariant data);
// 主窗口移动信号
void mainWindowMoved(QVariant data);
// 设置显示字体信号
void displayFontSet(QVariant data);
// 设置改变信号
void settingsChanged(QVariant data);
// 字体改变信号
void fontsChanged(QVariant data);
// 切换编辑器设置快捷键触发信号
void toggleEditorSettingsKeyboardShorcutFired();
// 编辑器设置滚动条位置改变信号
void editorSettingsScrollBarPositionChanged(QVariant data);
// 专业版检查信号
void proVersionCheck(QVariant data);
// 尝试获取第二种购买数据
void tryPurchaseDataSecondAlternative();
// 远程获取支付详情完成信号
void fetchingPaymentDetailsRemotelyFinished();
// 获取支付详情完成信号
void gettingPaymentDetailsFinished();
// 订阅状态改变信号
void subscriptionStatusChanged(QVariant subscriptionStatus);
};
#endif // MAINWINDOW_H
#endif // MAINWINDOW_H
Loading…
Cancel
Save