Skip to content

Commit 924451b

Browse files
authored
feature-add-node-visual (#2637)
* feature-add-node-visual * adj * adj * adj * fix dir index bug
1 parent f094b24 commit 924451b

File tree

14 files changed

+799
-36
lines changed

14 files changed

+799
-36
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ build
1717
build.*
1818
build*
1919
.DS_Store
20-
.vscode
20+
.vscode
21+
dev.sh

src/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ target_sources(vnote PRIVATE
4444
notebook/inotebookfactory.h
4545
notebook/node.cpp notebook/node.h
4646
notebook/nodeparameters.cpp notebook/nodeparameters.h
47+
notebook/nodevisual.cpp notebook/nodevisual.h
4748
notebook/notebook.cpp notebook/notebook.h
4849
notebook/notebookdatabaseaccess.cpp notebook/notebookdatabaseaccess.h
4950
notebook/notebookparameters.cpp notebook/notebookparameters.h

src/core/notebook/node.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Node::Node(Flags p_flags,
2727
m_modifiedTimeUtc(p_paras.m_modifiedTimeUtc),
2828
m_tags(p_paras.m_tags),
2929
m_attachmentFolder(p_paras.m_attachmentFolder),
30+
m_visual(p_paras.m_visual),
3031
m_parent(p_parent)
3132
{
3233
Q_ASSERT(m_notebook);
@@ -66,6 +67,8 @@ void Node::loadCompleteInfo(const NodeParameters &p_paras,
6667
m_modifiedTimeUtc = p_paras.m_modifiedTimeUtc;
6768
Q_ASSERT(p_paras.m_tags.isEmpty());
6869
Q_ASSERT(p_paras.m_attachmentFolder.isEmpty());
70+
71+
m_visual = p_paras.m_visual;
6972

7073
m_children = p_children;
7174
m_loaded = true;
@@ -493,3 +496,72 @@ void Node::checkSignature()
493496
m_signature = generateSignature();
494497
}
495498
}
499+
500+
// 视觉效果相关方法
501+
const NodeVisual &Node::getVisual() const
502+
{
503+
return m_visual;
504+
}
505+
506+
void Node::setVisual(const NodeVisual &p_visual)
507+
{
508+
m_visual = p_visual;
509+
}
510+
511+
// 视觉效果便捷访问方法
512+
const QString &Node::getBackgroundColor() const
513+
{
514+
return m_visual.getBackgroundColor();
515+
}
516+
517+
void Node::setBackgroundColor(const QString &p_backgroundColor)
518+
{
519+
m_visual.setBackgroundColor(p_backgroundColor);
520+
}
521+
522+
const QString &Node::getBorderColor() const
523+
{
524+
return m_visual.getBorderColor();
525+
}
526+
527+
void Node::setBorderColor(const QString &p_borderColor)
528+
{
529+
m_visual.setBorderColor(p_borderColor);
530+
}
531+
532+
const QString &Node::getNameColor() const
533+
{
534+
return m_visual.getNameColor();
535+
}
536+
537+
void Node::setNameColor(const QString &p_nameColor)
538+
{
539+
m_visual.setNameColor(p_nameColor);
540+
}
541+
542+
QString Node::getEffectiveBackgroundColor() const
543+
{
544+
return getBackgroundColor();
545+
}
546+
547+
QString Node::getEffectiveBorderColor() const
548+
{
549+
return getBorderColor();
550+
}
551+
552+
void Node::updateNodeVisual(const NodeVisual &p_visual)
553+
{
554+
if (m_visual.getBackgroundColor() == p_visual.getBackgroundColor() &&
555+
m_visual.getBorderColor() == p_visual.getBorderColor() &&
556+
m_visual.getNameColor() == p_visual.getNameColor()) {
557+
return;
558+
}
559+
560+
m_visual = p_visual;
561+
562+
// 持久化更新
563+
getConfigMgr()->updateNodeVisual(this, p_visual);
564+
565+
// 界面更新
566+
emit m_notebook->nodeUpdated(this);
567+
}

src/core/notebook/node.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <QEnableSharedFromThis>
99

1010
#include <global.h>
11+
#include "nodevisual.h"
1112

1213
namespace vnotex
1314
{
@@ -140,6 +141,26 @@ namespace vnotex
140141

141142
QString fetchAttachmentFolderPath();
142143

144+
// 视觉效果相关方法
145+
const NodeVisual &getVisual() const;
146+
void setVisual(const NodeVisual &p_visual);
147+
148+
// 视觉效果便捷访问方法
149+
const QString &getBackgroundColor() const;
150+
void setBackgroundColor(const QString &p_backgroundColor);
151+
152+
const QString &getBorderColor() const;
153+
void setBorderColor(const QString &p_borderColor);
154+
155+
const QString &getNameColor() const;
156+
void setNameColor(const QString &p_nameColor);
157+
158+
// 获取有效颜色(直接返回设置的颜色)
159+
QString getEffectiveBackgroundColor() const;
160+
QString getEffectiveBorderColor() const;
161+
162+
void updateNodeVisual(const NodeVisual &p_visual);
163+
143164
virtual QStringList addAttachment(const QString &p_destFolderPath, const QStringList &p_files) = 0;
144165

145166
virtual QString newAttachmentFile(const QString &p_destFolderPath, const QString &p_name) = 0;
@@ -204,6 +225,8 @@ namespace vnotex
204225

205226
QString m_attachmentFolder;
206227

228+
NodeVisual m_visual;
229+
207230
Node *m_parent = nullptr;
208231

209232
QVector<QSharedPointer<Node>> m_children;

src/core/notebook/nodeparameters.h

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,37 @@
1-
#ifndef NODEPARAMETERS_H
2-
#define NODEPARAMETERS_H
3-
4-
#include <QDateTime>
5-
#include <QStringList>
6-
7-
#include <core/global.h>
8-
9-
#include "node.h"
10-
11-
namespace vnotex
12-
{
13-
class NodeParameters
14-
{
15-
public:
16-
NodeParameters() = default;
17-
18-
NodeParameters(ID p_id);
19-
20-
ID m_id = Node::InvalidId;
21-
22-
ID m_signature = Node::InvalidId;
23-
24-
QDateTime m_createdTimeUtc = QDateTime::currentDateTimeUtc();
25-
26-
QDateTime m_modifiedTimeUtc = QDateTime::currentDateTimeUtc();
27-
28-
QStringList m_tags;
29-
30-
QString m_attachmentFolder;
31-
};
32-
}
33-
34-
#endif // NODEPARAMETERS_H
1+
#ifndef NODEPARAMETERS_H
2+
#define NODEPARAMETERS_H
3+
4+
#include <QDateTime>
5+
#include <QStringList>
6+
7+
#include <core/global.h>
8+
9+
#include "node.h"
10+
#include "nodevisual.h"
11+
12+
namespace vnotex
13+
{
14+
class NodeParameters
15+
{
16+
public:
17+
NodeParameters() = default;
18+
19+
NodeParameters(ID p_id);
20+
21+
ID m_id = Node::InvalidId;
22+
23+
ID m_signature = Node::InvalidId;
24+
25+
QDateTime m_createdTimeUtc = QDateTime::currentDateTimeUtc();
26+
27+
QDateTime m_modifiedTimeUtc = QDateTime::currentDateTimeUtc();
28+
29+
QStringList m_tags;
30+
31+
QString m_attachmentFolder;
32+
33+
NodeVisual m_visual;
34+
};
35+
}
36+
37+
#endif // NODEPARAMETERS_H

src/core/notebook/nodevisual.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "nodevisual.h"
2+
3+
#include <QColor>
4+
#include <QtMath>
5+
6+
using namespace vnotex;
7+
8+
NodeVisual::NodeVisual(const QString &p_backgroundColor,
9+
const QString &p_borderColor,
10+
const QString &p_nameColor)
11+
: m_backgroundColor(p_backgroundColor)
12+
, m_borderColor(p_borderColor)
13+
, m_nameColor(p_nameColor)
14+
{
15+
}
16+
17+
bool NodeVisual::hasAnyVisualEffect() const
18+
{
19+
return !m_backgroundColor.isEmpty() ||
20+
!m_borderColor.isEmpty() ||
21+
!m_nameColor.isEmpty();
22+
}
23+
24+
void NodeVisual::clearAllColors()
25+
{
26+
m_backgroundColor.clear();
27+
m_borderColor.clear();
28+
m_nameColor.clear();
29+
}

src/core/notebook/nodevisual.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#ifndef NODEVISUAL_H
2+
#define NODEVISUAL_H
3+
4+
#include <QString>
5+
6+
/*
7+
* 节点视觉效果类
8+
* 自定义节点名称,背景颜色,边框颜色,节点名称颜色
9+
* 支持清除所有颜色,包括背景颜色,边框颜色,节点名称颜色
10+
* 支持级联修改,包括背景颜色,边框颜色,节点名称颜色
11+
*/
12+
namespace vnotex
13+
{
14+
class NodeVisual
15+
{
16+
public:
17+
NodeVisual() = default;
18+
19+
NodeVisual(const QString &p_backgroundColor,
20+
const QString &p_borderColor,
21+
const QString &p_nameColor);
22+
23+
// 背景颜色
24+
const QString &getBackgroundColor() const { return m_backgroundColor; }
25+
void setBackgroundColor(const QString &p_color) { m_backgroundColor = p_color; }
26+
27+
// 边框颜色
28+
const QString &getBorderColor() const { return m_borderColor; }
29+
void setBorderColor(const QString &p_color) { m_borderColor = p_color; }
30+
31+
// 节点名称颜色
32+
const QString &getNameColor() const { return m_nameColor; }
33+
void setNameColor(const QString &p_color) { m_nameColor = p_color; }
34+
35+
// 判断是否有任何视觉效果
36+
bool hasAnyVisualEffect() const;
37+
38+
// 清除所有颜色
39+
void clearAllColors();
40+
41+
private:
42+
QString m_backgroundColor; // 背景颜色
43+
QString m_borderColor; // 边框颜色
44+
QString m_nameColor; // 节点名称颜色
45+
};
46+
}
47+
48+
#endif // NODEVISUAL_H

src/core/notebookconfigmgr/inotebookconfigmgr.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <QSharedPointer>
66

77
#include "notebook/node.h"
8+
#include "notebook/nodevisual.h"
89

910
namespace vnotex
1011
{
@@ -84,6 +85,8 @@ namespace vnotex
8485

8586
virtual QStringList scanAndImportExternalFiles(Node *p_node) = 0;
8687

88+
virtual void updateNodeVisual(Node *p_node, const NodeVisual &p_visual) = 0;
89+
8790
// Version of the config processing code.
8891
virtual int getCodeVersion() const = 0;
8992

0 commit comments

Comments
 (0)