diff --git a/doc/汇报文稿.docx b/doc/汇报文稿.docx index e69de29..e7408ad 100644 Binary files a/doc/汇报文稿.docx and b/doc/汇报文稿.docx differ diff --git a/source/src/nodedata.cpp b/source/src/nodedata.cpp index 8d08430..3bc1eb6 100644 --- a/source/src/nodedata.cpp +++ b/source/src/nodedata.cpp @@ -1,6 +1,7 @@ #include "nodedata.h" #include +// NodeData 类的构造函数,初始化成员变量 NodeData::NodeData() : m_id{ SpecialNodeID::InvalidNodeId }, m_isModified(false), @@ -14,206 +15,247 @@ NodeData::NodeData() { } +// 获取节点ID int NodeData::id() const { return m_id; } +// 设置节点ID void NodeData::setId(int id) { m_id = id; } +// 获取节点的完整标题 QString NodeData::fullTitle() const { return m_fullTitle; } +// 设置节点的完整标题 void NodeData::setFullTitle(const QString &fullTitle) { m_fullTitle = fullTitle; } +// 获取最后修改时间 QDateTime NodeData::lastModificationdateTime() const { return m_lastModificationDateTime; } +// 设置最后修改时间 void NodeData::setLastModificationDateTime(const QDateTime &lastModificationdateTime) { m_lastModificationDateTime = lastModificationdateTime; } +// 获取节点内容 QString NodeData::content() const { return m_content; } +// 设置节点内容 void NodeData::setContent(const QString &content) { m_content = content; } +// 检查节点是否被修改过 bool NodeData::isModified() const { return m_isModified; } +// 设置节点的修改状态 void NodeData::setModified(bool isModified) { m_isModified = isModified; } +// 检查节点是否被选中 bool NodeData::isSelected() const { return m_isSelected; } +// 设置节点的选中状态 void NodeData::setSelected(bool isSelected) { m_isSelected = isSelected; } +// 获取滚动条位置 int NodeData::scrollBarPosition() const { return m_scrollBarPosition; } +// 设置滚动条位置 void NodeData::setScrollBarPosition(int scrollBarPosition) { m_scrollBarPosition = scrollBarPosition; } +// 获取删除时间 QDateTime NodeData::deletionDateTime() const { return m_deletionDateTime; } +// 设置删除时间 void NodeData::setDeletionDateTime(const QDateTime &deletionDateTime) { m_deletionDateTime = deletionDateTime; } +// 获取节点类型 NodeData::Type NodeData::nodeType() const { return m_nodeType; } +// 设置节点类型 void NodeData::setNodeType(NodeData::Type newNodeType) { m_nodeType = newNodeType; } +// 获取父节点ID int NodeData::parentId() const { return m_parentId; } +// 设置父节点ID void NodeData::setParentId(int newParentId) { m_parentId = newParentId; } +// 获取相对位置 int NodeData::relativePosition() const { return m_relativePosition; } +// 设置相对位置 void NodeData::setRelativePosition(int newRelativePosition) { m_relativePosition = newRelativePosition; } +// 获取绝对路径 const QString &NodeData::absolutePath() const { return m_absolutePath; } +// 设置绝对路径 void NodeData::setAbsolutePath(const QString &newAbsolutePath) { m_absolutePath = newAbsolutePath; } +// 获取标签ID集 const QSet &NodeData::tagIds() const { return m_tagIds; } +// 设置标签ID集 void NodeData::setTagIds(const QSet &newTagIds) { m_tagIds = newTagIds; } +// 检查是否为临时节点 bool NodeData::isTempNote() const { return m_isTempNote; } +// 设置临时节点状态 void NodeData::setIsTempNote(bool newIsTempNote) { m_isTempNote = newIsTempNote; } +// 获取父节点名称 const QString &NodeData::parentName() const { return m_parentName; } +// 设置父节点名称 void NodeData::setParentName(const QString &newParentName) { m_parentName = newParentName; } +// 检查是否为固定节点 bool NodeData::isPinnedNote() const { return m_isPinnedNote; } +// 设置固定节点状态 void NodeData::setIsPinnedNote(bool newIsPinnedNote) { m_isPinnedNote = newIsPinnedNote; } +// 获取标签列表滚动条位置 int NodeData::tagListScrollBarPos() const { return m_tagListScrollBarPos; } +// 设置标签列表滚动条位置 void NodeData::setTagListScrollBarPos(int newTagListScrollBarPos) { m_tagListScrollBarPos = newTagListScrollBarPos; } +// 获取相对位置AN int NodeData::relativePosAN() const { return m_relativePosAN; } +// 设置相对位置AN void NodeData::setRelativePosAN(int newRelativePosAN) { m_relativePosAN = newRelativePosAN; } +// 获取子节点计数 int NodeData::childNotesCount() const { return m_childNotesCount; } +// 设置子节点计数 void NodeData::setChildNotesCount(int newChildCount) { m_childNotesCount = newChildCount; } +// 获取创建时间 QDateTime NodeData::creationDateTime() const { return m_creationDateTime; } +// 设置创建时间 void NodeData::setCreationDateTime(const QDateTime &creationDateTime) { m_creationDateTime = creationDateTime; } +// 重载流提取运算符,读取 NodeData 对象 QDataStream &operator>>(QDataStream &stream, NodeData &nodeData) { int id; @@ -230,6 +272,7 @@ QDataStream &operator>>(QDataStream &stream, NodeData &nodeData) return stream; } +// 重载流提取运算符,读取 NodeData 指针对象 QDataStream &operator>>(QDataStream &stream, NodeData *&nodeData) { nodeData = new NodeData(); @@ -245,4 +288,4 @@ QDataStream &operator>>(QDataStream &stream, NodeData *&nodeData) nodeData->setCreationDateTime(creationDateTime); nodeData->setContent(content); return stream; -} +} \ No newline at end of file diff --git a/source/src/nodedata.h b/source/src/nodedata.h index 2f75fa4..3723aca 100644 --- a/source/src/nodedata.h +++ b/source/src/nodedata.h @@ -14,6 +14,7 @@ enum Value { }; } +// NodeData类用于表示节点数据 class NodeData { public: @@ -21,64 +22,104 @@ public: enum Type { Note = 0, Folder }; + // 获取节点ID int id() const; + // 设置节点ID void setId(int id); + // 获取完整标题 QString fullTitle() const; + // 设置完整标题 void setFullTitle(const QString &fullTitle); + // 获取最后修改时间 QDateTime lastModificationdateTime() const; + // 设置最后修改时间 void setLastModificationDateTime(const QDateTime &lastModificationdateTime); + // 获取创建时间 QDateTime creationDateTime() const; + // 设置创建时间 void setCreationDateTime(const QDateTime &creationDateTime); + // 获取内容 QString content() const; + // 设置内容 void setContent(const QString &content); + // 判断是否被修改 bool isModified() const; + // 设置修改状态 void setModified(bool isModified); + // 判断是否被选中 bool isSelected() const; + // 设置选中状态 void setSelected(bool isSelected); + // 获取滚动条位置 int scrollBarPosition() const; + // 设置滚动条位置 void setScrollBarPosition(int scrollBarPosition); + // 获取删除时间 QDateTime deletionDateTime() const; + // 设置删除时间 void setDeletionDateTime(const QDateTime &deletionDateTime); + // 获取节点类型 NodeData::Type nodeType() const; + // 设置节点类型 void setNodeType(NodeData::Type newNodeType); + // 获取父节点ID int parentId() const; + // 设置父节点ID void setParentId(int newParentId); + // 获取相对位置 int relativePosition() const; + // 设置相对位置 void setRelativePosition(int newRelativePosition); + // 获取绝对路径 const QString &absolutePath() const; + // 设置绝对路径 void setAbsolutePath(const QString &newAbsolutePath); + // 获取标签ID集合 const QSet &tagIds() const; + // 设置标签ID集合 void setTagIds(const QSet &newTagIds); + // 判断是否为临时笔记 bool isTempNote() const; + // 设置临时笔记状态 void setIsTempNote(bool newIsTempNote); + // 获取父节点名称 const QString &parentName() const; + // 设置父节点名称 void setParentName(const QString &newParentName); + // 判断是否为固定笔记 bool isPinnedNote() const; + // 设置固定笔记状态 void setIsPinnedNote(bool newIsPinnedNote); + // 获取标签列表滚动条位置 int tagListScrollBarPos() const; + // 设置标签列表滚动条位置 void setTagListScrollBarPos(int newTagListScrollBarPos); + // 获取相对位置AN int relativePosAN() const; + // 设置相对位置AN void setRelativePosAN(int newRelativePosAN); + // 获取子笔记数量 int childNotesCount() const; + // 设置子笔记数量 void setChildNotesCount(int newChildCount); private: @@ -104,9 +145,12 @@ private: int m_childNotesCount; }; +// 用于QMetaType的声明 Q_DECLARE_METATYPE(NodeData) +// 重载输入流运算符以读取NodeData对象 QDataStream &operator>>(QDataStream &stream, NodeData &nodeData); +// 重载输入流运算符以读取NodeData指针对象 QDataStream &operator>>(QDataStream &stream, NodeData *&nodeData); -#endif // NODEDATA_H +#endif // NODEDATA_H \ No newline at end of file diff --git a/source/src/nodepath.cpp b/source/src/nodepath.cpp index 91e0a88..ca9b8c6 100644 --- a/source/src/nodepath.cpp +++ b/source/src/nodepath.cpp @@ -1,8 +1,10 @@ #include "nodepath.h" #include "nodedata.h" +// NodePath类的构造函数,初始化路径 NodePath::NodePath(const QString &path) : m_path(path) { } +// 分离路径为QStringList QStringList NodePath::separate() const { #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) @@ -12,11 +14,13 @@ QStringList NodePath::separate() const #endif } +// 获取当前路径 QString NodePath::path() const { return m_path; } +// 获取父路径 NodePath NodePath::parentPath() const { auto s = separate(); @@ -24,13 +28,15 @@ NodePath NodePath::parentPath() const return s.join(PATH_SEPARATOR); } +// 获取所有笔记文件夹的路径 QString NodePath::getAllNoteFolderPath() { return PATH_SEPARATOR + QString::number(SpecialNodeID::RootFolder); } +// 获取回收站文件夹的路径 QString NodePath::getTrashFolderPath() { return PATH_SEPARATOR + QString::number(SpecialNodeID::RootFolder) + PATH_SEPARATOR + QString::number(SpecialNodeID::TrashFolder); -} +} \ No newline at end of file diff --git a/source/src/nodepath.h b/source/src/nodepath.h index 7a8c799..2f3ecbe 100644 --- a/source/src/nodepath.h +++ b/source/src/nodepath.h @@ -9,19 +9,30 @@ #define TAG_MIME "application/x-tagnode" #define NOTE_MIME "application/x-notenode" +// NodePath 类用于处理节点路径 class NodePath { public: + // 构造函数,初始化节点路径 NodePath(const QString &path); + + // 将路径分割为字符串列表 QStringList separate() const; + // 获取当前路径 QString path() const; + + // 获取父路径 NodePath parentPath() const; + + // 获取所有笔记文件夹的路径 static QString getAllNoteFolderPath(); + + // 获取回收站文件夹的路径 static QString getTrashFolderPath(); private: - QString m_path; + QString m_path; // 存储节点路径 }; -#endif // NODEPATH_H +#endif // NODEPATH_H \ No newline at end of file diff --git a/source/src/singleinstance.cpp b/source/src/singleinstance.cpp index 16cdeae..b19b862 100644 --- a/source/src/singleinstance.cpp +++ b/source/src/singleinstance.cpp @@ -1,20 +1,22 @@ -#include "singleinstance.h" +#include "singleinstance.h"// SingleInstanceͷļ -SingleInstance::SingleInstance(QObject *parent) : QObject(parent) +SingleInstance::SingleInstance(QObject *parent) : QObject(parent)// SingleInstanceĹ캯 { + // QLocalServernewConnectionźŵһlambdaʽ + // ʱnewInstanceź connect(&m_server, &QLocalServer::newConnection, [this]() { emit newInstance(); }); } -void SingleInstance::listen(const QString &name) +void SingleInstance::listen(const QString &name)// ָƵıط { - m_server.removeServer(name); - m_server.listen(name); + m_server.removeServer(name);// ƳѴڵͬ + m_server.listen(name);// ʼָƵıط } -bool SingleInstance::hasPrevious(const QString &name) +bool SingleInstance::hasPrevious(const QString &name)// Ƿʵ { - QLocalSocket socket; - socket.connectToServer(name, QLocalSocket::ReadOnly); + QLocalSocket socket; // һ׽ֶ + socket.connectToServer(name, QLocalSocket::ReadOnly);// ӵָƵķ - return socket.waitForConnected(); + return socket.waitForConnected();// ȴӽ } diff --git a/source/src/singleinstance.h b/source/src/singleinstance.h index 8512c7c..30f267b 100644 --- a/source/src/singleinstance.h +++ b/source/src/singleinstance.h @@ -1,25 +1,25 @@ #ifndef SINGLEINSTANCE_H #define SINGLEINSTANCE_H -#include -#include -#include +#include // QObjectͷļQObjectQtĻ +#include // QLocalServerͷļڴط +#include // QLocalSocketͷļڴ׽ -class SingleInstance : public QObject +class SingleInstance : public QObject// SingleInstance̳࣬QObject { - Q_OBJECT + Q_OBJECT// ֧꣬źźͲۻ public: - explicit SingleInstance(QObject *parent = 0); + explicit SingleInstance(QObject *parent = 0);// 캯븸ָ룬ĬΪ - void listen(const QString &name); - bool hasPrevious(const QString &name); + void listen(const QString &name);// ָƵıط + bool hasPrevious(const QString &name);// Ƿʵ signals: - void newInstance(); + void newInstance(); // ʵʱź private: - QLocalSocket *m_socket; - QLocalServer m_server; + QLocalSocket *m_socket;// ˽гԱڴ洢׽ָ + QLocalServer m_server;// ˽гԱڴ洢ط }; #endif // SINGLEINSTANCE_H diff --git a/source/src/taglistmodel.cpp b/source/src/taglistmodel.cpp index caf9779..ceb2c14 100644 --- a/source/src/taglistmodel.cpp +++ b/source/src/taglistmodel.cpp @@ -1,79 +1,87 @@ #include "taglistmodel.h" -#include "tagpool.h" -#include +#include "tagpool.h"//ȡ͸±ǩ +#include //ڵ #include "nodepath.h" +// TagListModelĹ캯 TagListModel::TagListModel(QObject *parent) : QAbstractListModel(parent), m_tagPool{ nullptr } { } +// ʼQAbstractListModelm_tagPoolʼΪnullptr +// ñǩصĺ void TagListModel::setTagPool(TagPool *tagPool) { - beginResetModel(); - m_tagPool = tagPool; - connect(tagPool, &TagPool::dataReset, this, [this] { - beginResetModel(); - updateTagData(); - endResetModel(); - }); - endResetModel(); + beginResetModel(); // ʼģ֪ͣͨͼģͼı + m_tagPool = tagPool; // ñǩָ + connect(tagPool, &TagPool::dataReset, this, + [this] { // ӱǩصdataResetźŵһlambdaʽ + beginResetModel(); // ǩʱʼģ + updateTagData(); // ±ǩ + endResetModel(); // ģ֪ͣͨͼģѸı + }); + endResetModel(); // ģ } +// ģݵĺ void TagListModel::setModelData(const QSet &data) { - if (!m_tagPool) { - qDebug() << __FUNCTION__ << "Tag pool is not init yet"; + if (!m_tagPool) { // ǩδʼ + qDebug() << __FUNCTION__ << "Tag pool is not init yet"; // Ϣ return; } - beginResetModel(); - m_ids = data; - updateTagData(); - endResetModel(); + beginResetModel(); // ʼģ + m_ids = data; // ñǩID + updateTagData(); // ±ǩ + endResetModel(); // ģ } +// ӱǩĺ void TagListModel::addTag(int tagId) { - if (!m_tagPool) { - qDebug() << __FUNCTION__ << "Tag pool is not init yet"; + if (!m_tagPool) { // ǩδʼ + qDebug() << __FUNCTION__ << "Tag pool is not init yet"; // Ϣ return; } - if (m_tagPool->contains(tagId)) { - beginInsertRows(QModelIndex(), rowCount(), rowCount()); - m_data.append(m_tagPool->getTag(tagId)); - endInsertRows(); + if (m_tagPool->contains(tagId)) { // ǩذñǩID + beginInsertRows(QModelIndex(), rowCount(), rowCount()); // ʼУ֪ͨͼ + m_data.append(m_tagPool->getTag(tagId)); // ǩӵ + endInsertRows(); // У֪ͨͼѲ } else { - qDebug() << __FUNCTION__ << "Tag is not in pool:" << tagId; + qDebug() << __FUNCTION__ << "Tag is not in pool:" << tagId; // Ϣ } } +// rowCountģ͵ int TagListModel::rowCount(const QModelIndex &parent) const { - Q_UNUSED(parent); - return m_data.count(); + Q_UNUSED(parent); // parentδʹã + return m_data.count(); // رǩĴС } -QVariant TagListModel::data(const QModelIndex &index, int role) const +QVariant TagListModel::data(const QModelIndex &index, int role) const// ָͽɫ { - if (!index.isValid()) { - return QVariant(); + if (!index.isValid()) { // Ч + return QVariant(); // ؿյQVariant } - const TagData &tag = m_data[index.row()]; - if (role == IdRole) { - return tag.id(); - } else if (role == NameRole) { - return tag.name(); - } else if (role == ColorRole) { - return tag.color(); + const TagData &tag = m_data[index.row()]; // ȡӦеıǩ + if (role == IdRole) { // ɫIdRole + return tag.id(); // رǩID + } else if (role == NameRole) { // ɫNameRole + return tag.name(); // رǩ + } else if (role == ColorRole) { // ɫColorRole + return tag.color(); // رǩɫ } - return QVariant(); + return QVariant(); // ɫƥ䣬ؿյQVariant } -void TagListModel::updateTagData() + +void TagListModel::updateTagData()// ±ǩݵĺ { - m_data.clear(); - for (const auto &id : qAsConst(m_ids)) { - if (m_tagPool->contains(id)) { - m_data.append(m_tagPool->getTag(id)); + m_data.clear(); // ձǩ + for (const auto &id : qAsConst(m_ids)) { // ǩID + if (m_tagPool->contains(id)) { // ǩذñǩID + m_data.append(m_tagPool->getTag(id)); // ǩӵ } else { - qDebug() << __FUNCTION__ << "Tag is not in pool:" << id; + qDebug() << __FUNCTION__ << "Tag is not in pool:" << id; // Ϣ } } } diff --git a/source/src/taglistmodel.h b/source/src/taglistmodel.h index 103f3a3..8673438 100644 --- a/source/src/taglistmodel.h +++ b/source/src/taglistmodel.h @@ -1,28 +1,47 @@ #ifndef TAGLISTMODEL_H #define TAGLISTMODEL_H -#include -#include +#include // QAbstractListModelͷļQAbstractListModelQtʵԶбģ͵Ļ +#include // QSetͷļQSetһڴ洢ظԪ #include "tagdata.h" class TagPool; +// TagListModel̳࣬QAbstractListModel class TagListModel : public QAbstractListModel { - Q_OBJECT -public: - enum TagListRoles { IdRole = Qt::UserRole + 1, NameRole, ColorRole }; + Q_OBJECT // ֧꣬źźͲۻ + public : + // ɫö٣ָģеIJͬɫ + enum TagListRoles { + IdRole = Qt::UserRole + 1, + NameRole, + ColorRole + }; + + // 캯븸ָ룬ĬΪ TagListModel(QObject *parent = nullptr); + + // ñǩصĺһTagPoolָ void setTagPool(TagPool *tagPool); + + // ģݵĺһQSet͵ļ void setModelData(const QSet &data); + + // ӱǩĺһǩID void addTag(int tagId); + + // rowCountģ͵ int rowCount(const QModelIndex &parent = QModelIndex()) const; + + // dataָͽɫ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; private: - TagPool *m_tagPool; - QVector m_data; - QSet m_ids; + TagPool *m_tagPool; // ˽гԱڴ洢ǩָ + QVector m_data; // ˽гԱڴ洢ǩݵ + QSet m_ids; // ˽гԱڴ洢ǩIDļ + // ±ǩݵĺ void updateTagData(); }; diff --git a/source/src/taglistview.cpp b/source/src/taglistview.cpp index 8356cda..307e88f 100644 --- a/source/src/taglistview.cpp +++ b/source/src/taglistview.cpp @@ -1,86 +1,93 @@ #include "taglistview.h" -#include -#include -#include +#include // QFileͷļļ +#include // QDebugͷļڵ +#include // QMouseEventͷļڴ¼ +// TagListViewĹ캯 TagListView::TagListView(QWidget *parent) : QListView(parent) { - setFlow(QListView::LeftToRight); - setSpacing(3); - setWrapping(true); - setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setFlow(QListView::LeftToRight); // бзΪ + setSpacing(3); // б֮ļΪ3 + setWrapping(true); // бԶ + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); // ˮƽʼղʾ - QFile file(":/styles/taglistview.css"); - file.open(QFile::ReadOnly); - setStyleSheet(file.readAll()); - setTheme(Theme::Light); + QFile file(":/styles/taglistview.css"); // QFileڶȡCSSʽļ + file.open(QFile::ReadOnly); // ļΪֻģʽ + setStyleSheet(file.readAll()); // ȡļݣΪͼʽ + setTheme(Theme::Light); // ͼΪdzɫ } +// ĺ void TagListView::setTheme(Theme::Value theme) { - setCSSThemeAndUpdate(this, theme); + setCSSThemeAndUpdate(this, theme); // setCSSThemeAndUpdateͼCSSʽ } +// ñɫĺ void TagListView::setBackground(const QColor color) { - if (m_backgroundColor != color) { - m_backgroundColor = color; - QString ss = QStringLiteral( - R"(QListView { background: %1; } )" - R"(QScrollBar::handle:vertical:hover { background: rgb(170, 170, 171); } )" - R"(QScrollBar::handle:vertical:pressed { background: rgb(149, 149, 149); } )" - R"(QScrollBar::handle:vertical { border-radius: 4px; background: rgb(188, 188, 188); min-height: 20px; } )" - R"(QScrollBar::vertical {border-radius: 4px; width: 8px; color: rgba(255, 255, 255,0);} )" - R"(QScrollBar {margin: 0; background: transparent;} )" - R"(QScrollBar:hover { background-color: rgb(217, 217, 217);})" - R"(QScrollBar::add-line:vertical { width:0px; height: 0px; subcontrol-position: bottom; subcontrol-origin: margin; } )" - R"(QScrollBar::sub-line:vertical { width:0px; height: 0px; subcontrol-position: top; subcontrol-origin: margin; })"); - setStyleSheet(ss.arg(m_backgroundColor.name())); + if (m_backgroundColor != color) { // ɫ뵱ǰɫͬ + m_backgroundColor = color; // ±ɫ + QString ss = QStringLiteral( // һַڴ洢CSSʽ + R"(QListView { background: %1; } )" // QListViewıɫ + R"(QScrollBar::handle:vertical:hover { background: rgb(170, 170, 171); } )" // ôֱֱͣʱıɫ + R"(QScrollBar::handle:vertical:pressed { background: rgb(149, 149, 149); } )" // ôֱֱڰʱıɫ + R"(QScrollBar::handle:vertical { border-radius: 4px; background: rgb(188, 188, 188); min-height: 20px; } )" // ôֱֱʽ + R"(QScrollBar::vertical {border-radius: 4px; width: 8px; color: rgba(255, 255, 255,0);} )" // ôֱʽ + R"(QScrollBar {margin: 0; background: transparent;} )" // ùʽ + R"(QScrollBar:hover { background-color: rgb(217, 217, 217);})" // ùͣʱıɫ + R"(QScrollBar::add-line:vertical { width:0px; height: 0px; subcontrol-position: bottom; subcontrol-origin: margin; } )" // ôֱӰťʽ + R"(QScrollBar::sub-line:vertical { width:0px; height: 0px; subcontrol-position: top; subcontrol-origin: margin; })"); // ôֱٰťʽ + setStyleSheet( + ss.arg(m_backgroundColor + .name())); // ɫ뵽ʽַУΪͼʽ } } +// reset void TagListView::reset() { - QListView::reset(); - auto sz = sizeHint(); - if (!model() || model()->rowCount() == 0) { - sz.setHeight(0); + QListView::reset(); // ûreset + auto sz = sizeHint(); // ȡͼijߴʾ + if (!model() || model()->rowCount() == 0) { // ͼûģͻģ͵Ϊ0 + sz.setHeight(0); // ߴʾĸ߶Ϊ0 } else { - auto firstIndex = model()->index(0, 0); - auto lastIndex = model()->index(model()->rowCount() - 1, 0); - auto fr = visualRect(firstIndex); - fr.setBottom(visualRect(lastIndex).bottom()); - if (fr.height() < 80) { - sz.setHeight(fr.height() + 10); + auto firstIndex = model()->index(0, 0); // ȡģ͵ĵһ + auto lastIndex = model()->index(model()->rowCount() - 1, 0); // ȡģ͵һ + auto fr = visualRect(firstIndex); // ȡһĿӾ + fr.setBottom(visualRect(lastIndex) + .bottom()); // ӾεĵײΪһĿӾεĵײ + if (fr.height() < 80) { // Ӿεĸ߶С80 + sz.setHeight(fr.height() + 10); // ߴʾĸ߶ΪӾεĸ߶ȼ10 } else { - sz.setHeight(80); + sz.setHeight(80); // 򽫳ߴʾĸ߶Ϊ80 } } - setFixedHeight(sz.height()); + setFixedHeight(sz.height()); // ͼĸ߶Ϊߴʾĸ߶ } void TagListView::resizeEvent(QResizeEvent *event) { - QListView::resizeEvent(event); - setWrapping(true); + QListView::resizeEvent(event); // ûresizeEvent + setWrapping(true); // бԶ } void TagListView::mousePressEvent(QMouseEvent *event) { - event->ignore(); + event->ignore();// 갴¼ } void TagListView::mouseReleaseEvent(QMouseEvent *event) { - event->ignore(); + event->ignore();// ͷ¼ } void TagListView::mouseDoubleClickEvent(QMouseEvent *event) { - event->ignore(); + event->ignore();// ˫¼ } void TagListView::mouseMoveEvent(QMouseEvent *event) { - event->ignore(); + event->ignore();// ƶ¼ } diff --git a/source/src/taglistview.h b/source/src/taglistview.h index 28bc179..9800969 100644 --- a/source/src/taglistview.h +++ b/source/src/taglistview.h @@ -1,28 +1,29 @@ #pragma once -#include +#include // QListViewĶ壬QListViewQtеһбͼؼ #include "editorsettingsoptions.h" -class TagListView : public QListView +class TagListView : public QListView// TagListView̳࣬QListView { - Q_OBJECT + Q_OBJECT// ֧꣬źźͲۻ public: - explicit TagListView(QWidget *parent = nullptr); - void setTheme(Theme::Value theme); - void setBackground(const QColor color); + explicit TagListView(QWidget *parent = nullptr); // 캯븸ָ룬ĬΪ + void setTheme(Theme::Value theme); // ĺThemeöеһֵ + void setBackground(const QColor color);// ñɫķһQColor signals: - // QAbstractItemView interface + // QAbstractItemView interface QAbstractItemViewӿڵź public slots: - virtual void reset() override; + virtual void reset() override;// resetͼ״̬ - // QWidget interface + // QWidget interface ĺQWidgetӿ protected: - virtual void resizeEvent(QResizeEvent *event) override; - virtual void mousePressEvent(QMouseEvent *event) override; - virtual void mouseReleaseEvent(QMouseEvent *event) override; - virtual void mouseDoubleClickEvent(QMouseEvent *event) override; - virtual void mouseMoveEvent(QMouseEvent *event) override; + virtual void resizeEvent(QResizeEvent *event) override;// resizeEventڴС仯¼ + virtual void mousePressEvent(QMouseEvent *event) override;// mousePressEvent갴¼ + virtual void mouseReleaseEvent(QMouseEvent *event) override;// mouseReleaseEventͷ¼ + virtual void mouseDoubleClickEvent( + QMouseEvent *event) override; // mouseDoubleClickEvent˫¼ + virtual void mouseMoveEvent(QMouseEvent *event) override;// mouseMoveEventƶ¼ private: - QColor m_backgroundColor; + QColor m_backgroundColor;// ˽гԱڴ洢ɫ };