编辑模式 / 源代码模式语义修正 - 默认「编辑模式」不再显示 #、**、反引号等标记:标题按级别放大加粗、 粗体真加粗、行内代码带底色、链接只保留文字 - 光标所在行会露出原始标记,方便直接修改;切换行时只重排这两行 - 源代码模式仍是原样显示 + 着色,左下角 <src> 切换 高亮器 - QSyntaxHighlighter::setFormat 是整段替换而非合并,改为每段先与 当前行基础格式(标题 / 引用 / 代码块)compose 后再设置 - 强调正则收紧,避免 **粗体** 被 *斜体* 抢先匹配 侧栏 - 去掉刷新按钮,改为每 5 秒自动扫描;文件集合没变就不重建列表 - 状态栏左下角新增「侧栏」开关按钮,与 Ctrl+B 同步 其它 - 使用 logo.png 作为窗口图标(resources.qrc) - 版本号 0.3.0,README 同步更新
69 lines
2.3 KiB
C++
69 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#include <QPlainTextEdit>
|
|
|
|
class MarkdownHighlighter;
|
|
class QTextBlock;
|
|
|
|
/// 编辑器本体:等宽字体、行号栏、当前行高亮、Tab 缩进、
|
|
/// Ctrl+滚轮缩放,以及把拖入的文件转交给主窗口打开。
|
|
class MarkdownEditor : public QPlainTextEdit
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit MarkdownEditor(QWidget *parent = nullptr);
|
|
|
|
int lineNumberAreaWidth() const;
|
|
void lineNumberAreaPaintEvent(QPaintEvent *event);
|
|
|
|
void setEditorFontPointSize(int points);
|
|
int editorFontPointSize() const { return m_fontPointSize; }
|
|
|
|
MarkdownHighlighter *highlighter() const { return m_highlighter; }
|
|
|
|
bool isSourceMode() const { return m_sourceMode; }
|
|
/// 源代码模式:关掉语法高亮、行号与当前行高亮,只看文件原始内容。
|
|
void setSourceMode(bool enabled);
|
|
|
|
/// 把选中的行设为 N 级标题(1–6);整段已经是这一级时改回正文。
|
|
void setHeadingLevel(int level);
|
|
/// 把选中内容包成围栏代码块;如果已经围起来了则拆掉。
|
|
void toggleCodeBlock();
|
|
|
|
signals:
|
|
void zoomStepRequested(int direction);
|
|
void fileDropped(const QString &path);
|
|
void sourceModeChanged(bool enabled);
|
|
|
|
protected:
|
|
void resizeEvent(QResizeEvent *event) override;
|
|
void keyPressEvent(QKeyEvent *event) override;
|
|
void wheelEvent(QWheelEvent *event) override;
|
|
void dragEnterEvent(QDragEnterEvent *event) override;
|
|
void dragMoveEvent(QDragMoveEvent *event) override;
|
|
void dropEvent(QDropEvent *event) override;
|
|
|
|
private slots:
|
|
void updateLineNumberAreaWidth(int newBlockCount);
|
|
void updateLineNumberArea(const QRect &rect, int dy);
|
|
void updateCurrentLineHighlight();
|
|
void updateActiveBlock();
|
|
void applyTheme();
|
|
|
|
private:
|
|
void applyEditorFont();
|
|
void indentSelection(bool outdent);
|
|
bool acceptsLocalFiles(const QMimeData *mime) const;
|
|
void selectedBlockRange(int *firstBlock, int *lastBlock) const;
|
|
void selectBlocks(int firstBlock, int lastBlock);
|
|
bool enclosingFence(int firstBlock, int lastBlock,
|
|
QTextBlock *opener, QTextBlock *closer) const;
|
|
|
|
QWidget *m_lineNumberArea = nullptr;
|
|
MarkdownHighlighter *m_highlighter = nullptr;
|
|
int m_fontPointSize = 12;
|
|
bool m_sourceMode = false;
|
|
int m_activeBlock = -1;
|
|
};
|