mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 22:09:52 +08:00

- Caculate font height every time on painting line number area; - Support specifying multiple fonts in font-family in qss; - Add margin for "li ol" in CSS;
90 lines
1.8 KiB
C++
90 lines
1.8 KiB
C++
#ifndef VLINENUMBERAREA_H
|
|
#define VLINENUMBERAREA_H
|
|
|
|
#include <QWidget>
|
|
#include <QColor>
|
|
|
|
class QPaintEvent;
|
|
class QTextDocument;
|
|
|
|
|
|
enum class LineNumberType
|
|
{
|
|
None = 0,
|
|
Absolute,
|
|
Relative,
|
|
CodeBlock,
|
|
Invalid
|
|
};
|
|
|
|
|
|
class VTextEditWithLineNumber
|
|
{
|
|
public:
|
|
virtual ~VTextEditWithLineNumber() {}
|
|
|
|
virtual void paintLineNumberArea(QPaintEvent *p_event) = 0;
|
|
};
|
|
|
|
|
|
// To use VLineNumberArea, the editor should implement VTextEditWithLineNumber.
|
|
class VLineNumberArea : public QWidget
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
VLineNumberArea(VTextEditWithLineNumber *p_editor,
|
|
const QTextDocument *p_document,
|
|
int p_digitWidth,
|
|
QWidget *p_parent = nullptr);
|
|
|
|
QSize sizeHint() const Q_DECL_OVERRIDE
|
|
{
|
|
return QSize(calculateWidth(), 0);
|
|
}
|
|
|
|
int calculateWidth() const;
|
|
|
|
const QColor &getBackgroundColor() const;
|
|
void setBackgroundColor(const QColor &p_color);
|
|
|
|
const QColor &getForegroundColor() const;
|
|
void setForegroundColor(const QColor &p_color);
|
|
|
|
protected:
|
|
void paintEvent(QPaintEvent *p_event) Q_DECL_OVERRIDE
|
|
{
|
|
m_editor->paintLineNumberArea(p_event);
|
|
}
|
|
|
|
private:
|
|
VTextEditWithLineNumber *m_editor;
|
|
const QTextDocument *m_document;
|
|
int m_width;
|
|
int m_blockCount;
|
|
int m_digitWidth;
|
|
QColor m_foregroundColor;
|
|
QColor m_backgroundColor;
|
|
};
|
|
|
|
inline const QColor &VLineNumberArea::getBackgroundColor() const
|
|
{
|
|
return m_backgroundColor;
|
|
}
|
|
|
|
inline void VLineNumberArea::setBackgroundColor(const QColor &p_color)
|
|
{
|
|
m_backgroundColor = p_color;
|
|
}
|
|
|
|
inline const QColor &VLineNumberArea::getForegroundColor() const
|
|
{
|
|
return m_foregroundColor;
|
|
}
|
|
|
|
inline void VLineNumberArea::setForegroundColor(const QColor &p_color)
|
|
{
|
|
m_foregroundColor = p_color;
|
|
}
|
|
|
|
#endif // VLINENUMBERAREA_H
|