draw a thin line to link preview image and its block

Add config preview-image-line-foreground in MDHL for the line color.
This commit is contained in:
Le Tan 2017-11-03 19:49:58 +08:00
parent 9de40e4d78
commit c59974744e
8 changed files with 47 additions and 1 deletions

View File

@ -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

View File

@ -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;
}
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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()

View File

@ -51,6 +51,8 @@ public:
// Relayout @p_blocks.
void relayout(const QSet<int> &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

View File

@ -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);
}

View File

@ -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;