diff --git a/src/resources/styles/default.mdhl b/src/resources/styles/default.mdhl index ef8f5c72..561fed3d 100644 --- a/src/resources/styles/default.mdhl +++ b/src/resources/styles/default.mdhl @@ -30,6 +30,8 @@ incremental-searched-word-background: ce93d8 # [VNote] Style for color column in fenced code block color-column-background: dd0000 color-column-foreground: ffff00 +# [VNote} Style for preview image line +preview-image-line-foreground: 9575cd editor-selection foreground: eeeeee diff --git a/src/vconfigmanager.cpp b/src/vconfigmanager.cpp index 23c257ad..9cb03520 100644 --- a/src/vconfigmanager.cpp +++ b/src/vconfigmanager.cpp @@ -538,6 +538,7 @@ void VConfigManager::updateMarkdownEditStyle() static const QString defaultLineNumberFg = "#424242"; static const QString defaultColorColumnBg = "#DD0000"; static const QString defaultColorColumnFg = "#FFFF00"; + static const QString defaultPreviewImageLineFg = "#9575CD"; // Read style file .mdhl QString file(getEditorStyleUrl()); @@ -602,6 +603,7 @@ void VConfigManager::updateMarkdownEditStyle() m_editorLineNumberFg = defaultLineNumberFg; m_editorColorColumnBg = defaultColorColumnBg; m_editorColorColumnFg = defaultColorColumnFg; + m_editorPreviewImageLineFg = defaultPreviewImageLineFg; auto editorIt = styles.find("editor"); if (editorIt != styles.end()) { auto it = editorIt->find("trailing-space"); @@ -648,6 +650,11 @@ void VConfigManager::updateMarkdownEditStyle() if (it != editorIt->end()) { m_editorColorColumnFg = "#" + *it; } + + it = editorIt->find("preview-image-line-foreground"); + if (it != editorIt->end()) { + m_editorPreviewImageLineFg = "#" + *it; + } } } diff --git a/src/vconfigmanager.h b/src/vconfigmanager.h index 702f9271..c2a01c0c 100644 --- a/src/vconfigmanager.h +++ b/src/vconfigmanager.h @@ -287,6 +287,8 @@ public: const QString &getEditorColorColumnBg() const; const QString &getEditorColorColumnFg() const; + const QString &getEditorPreviewImageLineFg() const; + bool getEnableCodeBlockLineNumber() const; void setEnableCodeBlockLineNumber(bool p_enabled); @@ -648,6 +650,9 @@ private: // The foreground color of the color column. QString m_editorColorColumnFg; + // The foreground color of the preview image line. + QString m_editorPreviewImageLineFg; + // Icon size of tool bar in pixels. int m_toolBarIconSize; @@ -1562,6 +1567,11 @@ inline const QString &VConfigManager::getEditorColorColumnFg() const return m_editorColorColumnFg; } +inline const QString &VConfigManager::getEditorPreviewImageLineFg() const +{ + return m_editorPreviewImageLineFg; +} + inline bool VConfigManager::getEnableCodeBlockLineNumber() const { return m_enableCodeBlockLineNumber; diff --git a/src/vmdeditor.cpp b/src/vmdeditor.cpp index b9de8045..3e295e06 100644 --- a/src/vmdeditor.cpp +++ b/src/vmdeditor.cpp @@ -853,6 +853,8 @@ void VMdEditor::updateTextEditConfig() setLineLeading(m_config.m_lineDistanceHeight); + setImageLineColor(g_config->getEditorPreviewImageLineFg()); + int lineNumber = g_config->getEditorLineNumber(); if (lineNumber < (int)LineNumberType::None || lineNumber >= (int)LineNumberType::Invalid) { lineNumber = (int)LineNumberType::None; diff --git a/src/vtextdocumentlayout.cpp b/src/vtextdocumentlayout.cpp index b67c27f0..0df49c99 100644 --- a/src/vtextdocumentlayout.cpp +++ b/src/vtextdocumentlayout.cpp @@ -27,7 +27,8 @@ VTextDocumentLayout::VTextDocumentLayout(QTextDocument *p_doc, m_cursorMargin(4), m_imageMgr(p_imageMgr), m_blockImageEnabled(false), - m_imageWidthConstrainted(false) + m_imageWidthConstrainted(false), + m_imageLineColor("#9575CD") { } @@ -757,6 +758,13 @@ void VTextDocumentLayout::drawBlockImage(QPainter *p_painter, size.height()); p_painter->drawPixmap(targetRect, *image); + + // Draw a thin line to link them. + QPen oldPen = p_painter->pen(); + QPen newPen(m_imageLineColor, 2, Qt::DashLine); + p_painter->setPen(newPen); + p_painter->drawLine(QPointF(2, p_offset.y()), QPointF(2, targetRect.bottom())); + p_painter->setPen(oldPen); } void VTextDocumentLayout::relayout() diff --git a/src/vtextdocumentlayout.h b/src/vtextdocumentlayout.h index 98d13437..8b38ca23 100644 --- a/src/vtextdocumentlayout.h +++ b/src/vtextdocumentlayout.h @@ -51,6 +51,8 @@ public: // Relayout @p_blocks. void relayout(const QSet &p_blocks); + void setImageLineColor(const QColor &p_color); + protected: void documentChanged(int p_from, int p_charsRemoved, int p_charsAdded) Q_DECL_OVERRIDE; @@ -184,6 +186,9 @@ private: // Whether constraint the width of image to the width of the page. bool m_imageWidthConstrainted; + + // Color of the image line. + QColor m_imageLineColor; }; inline qreal VTextDocumentLayout::getLineLeading() const @@ -191,4 +196,9 @@ inline qreal VTextDocumentLayout::getLineLeading() const return m_lineLeading; } +inline void VTextDocumentLayout::setImageLineColor(const QColor &p_color) +{ + m_imageLineColor = p_color; +} + #endif // VTEXTDOCUMENTLAYOUT_H diff --git a/src/vtextedit.cpp b/src/vtextedit.cpp index 7dbbd9bd..2842a308 100644 --- a/src/vtextedit.cpp +++ b/src/vtextedit.cpp @@ -313,3 +313,8 @@ void VTextEdit::setImageWidthConstrainted(bool p_enabled) { getLayout()->setImageWidthConstrainted(p_enabled); } + +void VTextEdit::setImageLineColor(const QColor &p_color) +{ + getLayout()->setImageLineColor(p_color); +} diff --git a/src/vtextedit.h b/src/vtextedit.h index 74d48c75..dfe739d1 100644 --- a/src/vtextedit.h +++ b/src/vtextedit.h @@ -129,6 +129,8 @@ public: void setImageWidthConstrainted(bool p_enabled); + void setImageLineColor(const QColor &p_color); + protected: void resizeEvent(QResizeEvent *p_event) Q_DECL_OVERRIDE;