Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ build
build.*
build*
.DS_Store
.vscode
.vscode
dev.sh
1 change: 1 addition & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ target_sources(vnote PRIVATE
notebook/inotebookfactory.h
notebook/node.cpp notebook/node.h
notebook/nodeparameters.cpp notebook/nodeparameters.h
notebook/nodevisual.cpp notebook/nodevisual.h
notebook/notebook.cpp notebook/notebook.h
notebook/notebookdatabaseaccess.cpp notebook/notebookdatabaseaccess.h
notebook/notebookparameters.cpp notebook/notebookparameters.h
Expand Down
72 changes: 72 additions & 0 deletions src/core/notebook/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Node::Node(Flags p_flags,
m_modifiedTimeUtc(p_paras.m_modifiedTimeUtc),
m_tags(p_paras.m_tags),
m_attachmentFolder(p_paras.m_attachmentFolder),
m_visual(p_paras.m_visual),
m_parent(p_parent)
{
Q_ASSERT(m_notebook);
Expand Down Expand Up @@ -66,6 +67,8 @@ void Node::loadCompleteInfo(const NodeParameters &p_paras,
m_modifiedTimeUtc = p_paras.m_modifiedTimeUtc;
Q_ASSERT(p_paras.m_tags.isEmpty());
Q_ASSERT(p_paras.m_attachmentFolder.isEmpty());

m_visual = p_paras.m_visual;

m_children = p_children;
m_loaded = true;
Expand Down Expand Up @@ -493,3 +496,72 @@ void Node::checkSignature()
m_signature = generateSignature();
}
}

// 视觉效果相关方法
const NodeVisual &Node::getVisual() const
{
return m_visual;
}

void Node::setVisual(const NodeVisual &p_visual)
{
m_visual = p_visual;
}

// 视觉效果便捷访问方法
const QString &Node::getBackgroundColor() const
{
return m_visual.getBackgroundColor();
}

void Node::setBackgroundColor(const QString &p_backgroundColor)
{
m_visual.setBackgroundColor(p_backgroundColor);
}

const QString &Node::getBorderColor() const
{
return m_visual.getBorderColor();
}

void Node::setBorderColor(const QString &p_borderColor)
{
m_visual.setBorderColor(p_borderColor);
}

const QString &Node::getNameColor() const
{
return m_visual.getNameColor();
}

void Node::setNameColor(const QString &p_nameColor)
{
m_visual.setNameColor(p_nameColor);
}

QString Node::getEffectiveBackgroundColor() const
{
return getBackgroundColor();
}

QString Node::getEffectiveBorderColor() const
{
return getBorderColor();
}

void Node::updateNodeVisual(const NodeVisual &p_visual)
{
if (m_visual.getBackgroundColor() == p_visual.getBackgroundColor() &&
m_visual.getBorderColor() == p_visual.getBorderColor() &&
m_visual.getNameColor() == p_visual.getNameColor()) {
return;
}

m_visual = p_visual;

// 持久化更新
getConfigMgr()->updateNodeVisual(this, p_visual);

// 界面更新
emit m_notebook->nodeUpdated(this);
}
23 changes: 23 additions & 0 deletions src/core/notebook/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <QEnableSharedFromThis>

#include <global.h>
#include "nodevisual.h"

namespace vnotex
{
Expand Down Expand Up @@ -140,6 +141,26 @@ namespace vnotex

QString fetchAttachmentFolderPath();

// 视觉效果相关方法
const NodeVisual &getVisual() const;
void setVisual(const NodeVisual &p_visual);

// 视觉效果便捷访问方法
const QString &getBackgroundColor() const;
void setBackgroundColor(const QString &p_backgroundColor);

const QString &getBorderColor() const;
void setBorderColor(const QString &p_borderColor);

const QString &getNameColor() const;
void setNameColor(const QString &p_nameColor);

// 获取有效颜色(直接返回设置的颜色)
QString getEffectiveBackgroundColor() const;
QString getEffectiveBorderColor() const;

void updateNodeVisual(const NodeVisual &p_visual);

virtual QStringList addAttachment(const QString &p_destFolderPath, const QStringList &p_files) = 0;

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

QString m_attachmentFolder;

NodeVisual m_visual;

Node *m_parent = nullptr;

QVector<QSharedPointer<Node>> m_children;
Expand Down
71 changes: 37 additions & 34 deletions src/core/notebook/nodeparameters.h
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
#ifndef NODEPARAMETERS_H
#define NODEPARAMETERS_H

#include <QDateTime>
#include <QStringList>

#include <core/global.h>

#include "node.h"

namespace vnotex
{
class NodeParameters
{
public:
NodeParameters() = default;

NodeParameters(ID p_id);

ID m_id = Node::InvalidId;

ID m_signature = Node::InvalidId;

QDateTime m_createdTimeUtc = QDateTime::currentDateTimeUtc();

QDateTime m_modifiedTimeUtc = QDateTime::currentDateTimeUtc();

QStringList m_tags;

QString m_attachmentFolder;
};
}

#endif // NODEPARAMETERS_H
#ifndef NODEPARAMETERS_H
#define NODEPARAMETERS_H

#include <QDateTime>
#include <QStringList>

#include <core/global.h>

#include "node.h"
#include "nodevisual.h"

namespace vnotex
{
class NodeParameters
{
public:
NodeParameters() = default;

NodeParameters(ID p_id);

ID m_id = Node::InvalidId;

ID m_signature = Node::InvalidId;

QDateTime m_createdTimeUtc = QDateTime::currentDateTimeUtc();

QDateTime m_modifiedTimeUtc = QDateTime::currentDateTimeUtc();

QStringList m_tags;

QString m_attachmentFolder;

NodeVisual m_visual;
};
}

#endif // NODEPARAMETERS_H
29 changes: 29 additions & 0 deletions src/core/notebook/nodevisual.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "nodevisual.h"

#include <QColor>
#include <QtMath>

using namespace vnotex;

NodeVisual::NodeVisual(const QString &p_backgroundColor,
const QString &p_borderColor,
const QString &p_nameColor)
: m_backgroundColor(p_backgroundColor)
, m_borderColor(p_borderColor)
, m_nameColor(p_nameColor)
{
}

bool NodeVisual::hasAnyVisualEffect() const
{
return !m_backgroundColor.isEmpty() ||
!m_borderColor.isEmpty() ||
!m_nameColor.isEmpty();
}

void NodeVisual::clearAllColors()
{
m_backgroundColor.clear();
m_borderColor.clear();
m_nameColor.clear();
}
48 changes: 48 additions & 0 deletions src/core/notebook/nodevisual.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#ifndef NODEVISUAL_H
#define NODEVISUAL_H

#include <QString>

/*
* 节点视觉效果类
* 自定义节点名称,背景颜色,边框颜色,节点名称颜色
* 支持清除所有颜色,包括背景颜色,边框颜色,节点名称颜色
* 支持级联修改,包括背景颜色,边框颜色,节点名称颜色
*/
namespace vnotex
{
class NodeVisual
{
public:
NodeVisual() = default;

NodeVisual(const QString &p_backgroundColor,
const QString &p_borderColor,
const QString &p_nameColor);

// 背景颜色
const QString &getBackgroundColor() const { return m_backgroundColor; }
void setBackgroundColor(const QString &p_color) { m_backgroundColor = p_color; }

// 边框颜色
const QString &getBorderColor() const { return m_borderColor; }
void setBorderColor(const QString &p_color) { m_borderColor = p_color; }

// 节点名称颜色
const QString &getNameColor() const { return m_nameColor; }
void setNameColor(const QString &p_color) { m_nameColor = p_color; }

// 判断是否有任何视觉效果
bool hasAnyVisualEffect() const;

// 清除所有颜色
void clearAllColors();

private:
QString m_backgroundColor; // 背景颜色
QString m_borderColor; // 边框颜色
QString m_nameColor; // 节点名称颜色
};
}

#endif // NODEVISUAL_H
3 changes: 3 additions & 0 deletions src/core/notebookconfigmgr/inotebookconfigmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <QSharedPointer>

#include "notebook/node.h"
#include "notebook/nodevisual.h"

namespace vnotex
{
Expand Down Expand Up @@ -84,6 +85,8 @@ namespace vnotex

virtual QStringList scanAndImportExternalFiles(Node *p_node) = 0;

virtual void updateNodeVisual(Node *p_node, const NodeVisual &p_visual) = 0;

// Version of the config processing code.
virtual int getCodeVersion() const = 0;

Expand Down
Loading
Loading