ui: Added markers to active lines in code view
This commit is contained in:
@@ -100,7 +100,9 @@
|
|||||||
|
|
||||||
<line_number>
|
<line_number>
|
||||||
<text>#C4C4C4</text>
|
<text>#C4C4C4</text>
|
||||||
|
<inactive_text>#A0A0A0</inactive_text>
|
||||||
<background>#494949</background>
|
<background>#494949</background>
|
||||||
|
<marker>#C4C4C4</marker>
|
||||||
</line_number>
|
</line_number>
|
||||||
|
|
||||||
<syntax>
|
<syntax>
|
||||||
|
|||||||
@@ -100,7 +100,9 @@
|
|||||||
|
|
||||||
<line_number>
|
<line_number>
|
||||||
<text>black</text>
|
<text>black</text>
|
||||||
|
<inactive_text>#A0A0A0</inactive_text>
|
||||||
<background>white</background>
|
<background>white</background>
|
||||||
|
<marker>#A0A0A0</marker>
|
||||||
</line_number>
|
</line_number>
|
||||||
|
|
||||||
<syntax>
|
<syntax>
|
||||||
|
|||||||
@@ -119,7 +119,9 @@
|
|||||||
|
|
||||||
<line_number>
|
<line_number>
|
||||||
<text>#F7F7F7</text>
|
<text>#F7F7F7</text>
|
||||||
|
<inactive_text>#A0A0A0</inactive_text>
|
||||||
<background>#272728</background>
|
<background>#272728</background>
|
||||||
|
<marker>#969696</marker>
|
||||||
</line_number>
|
</line_number>
|
||||||
|
|
||||||
<syntax>
|
<syntax>
|
||||||
|
|||||||
@@ -73,7 +73,7 @@
|
|||||||
|
|
||||||
#code_file #code_snippet #dots {
|
#code_file #code_snippet #dots {
|
||||||
background-color: <color:code/snippet/line_number/background>;
|
background-color: <color:code/snippet/line_number/background>;
|
||||||
padding-right: 13px;
|
padding-right: 16px;
|
||||||
text-align: right;
|
text-align: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -195,20 +195,32 @@ void QtCodeArea::lineNumberAreaPaintEvent(QPaintEvent *event)
|
|||||||
std::set<int> activeLineNumbers = getActiveLineNumbers();
|
std::set<int> activeLineNumbers = getActiveLineNumbers();
|
||||||
|
|
||||||
ColorScheme* scheme = ColorScheme::getInstance().get();
|
ColorScheme* scheme = ColorScheme::getInstance().get();
|
||||||
QColor backgroundColor(scheme->getColor("code/snippet/line_number/background").c_str());
|
|
||||||
backgroundColor.setAlpha(150);
|
QColor textColor(scheme->getColor("code/snippet/line_number/text").c_str());
|
||||||
|
QColor inactiveTextColor(scheme->getColor("code/snippet/line_number/inactive_text").c_str());
|
||||||
|
QColor markerColor(scheme->getColor("code/snippet/line_number/marker").c_str());
|
||||||
|
|
||||||
|
QPen p = painter.pen();
|
||||||
|
|
||||||
while (block.isValid() && top <= event->rect().bottom())
|
while (block.isValid() && top <= event->rect().bottom())
|
||||||
{
|
{
|
||||||
if (block.isVisible() && bottom >= event->rect().top())
|
if (block.isVisible() && bottom >= event->rect().top())
|
||||||
{
|
{
|
||||||
int number = blockNumber + m_startLineNumber;
|
int number = blockNumber + m_startLineNumber;
|
||||||
painter.drawText(0, top, m_lineNumberArea->width() - 13, fontMetrics().height(), Qt::AlignRight, QString::number(number));
|
|
||||||
|
|
||||||
if (!m_isActiveFile && activeLineNumbers.find(number) == activeLineNumbers.end())
|
p.setColor(textColor);
|
||||||
|
|
||||||
|
if (activeLineNumbers.find(number) != activeLineNumbers.end())
|
||||||
{
|
{
|
||||||
painter.fillRect(0, top, m_lineNumberArea->width(), fontMetrics().height(), backgroundColor);
|
painter.fillRect(m_lineNumberArea->width() - 8, top, 3, fontMetrics().height() + 1, markerColor);
|
||||||
}
|
}
|
||||||
|
else if (!m_isActiveFile)
|
||||||
|
{
|
||||||
|
p.setColor(inactiveTextColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
painter.setPen(p);
|
||||||
|
painter.drawText(0, top, m_lineNumberArea->width() - 16, fontMetrics().height(), Qt::AlignRight, QString::number(number));
|
||||||
}
|
}
|
||||||
|
|
||||||
block = block.next();
|
block = block.next();
|
||||||
@@ -373,23 +385,6 @@ void QtCodeArea::paintEvent(QPaintEvent* event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QPlainTextEdit::paintEvent(event);
|
QPlainTextEdit::paintEvent(event);
|
||||||
|
|
||||||
QPainter painter2(viewport());
|
|
||||||
std::set<int> activeLineNumbers = getActiveLineNumbers();
|
|
||||||
|
|
||||||
ColorScheme* scheme = ColorScheme::getInstance().get();
|
|
||||||
QColor backgroundColor(scheme->getColor("code/snippet/background").c_str());
|
|
||||||
backgroundColor.setAlpha(75);
|
|
||||||
|
|
||||||
for (int i = 0; i < document()->blockCount(); i++)
|
|
||||||
{
|
|
||||||
int lineNumber = i + m_startLineNumber;
|
|
||||||
if (!m_isActiveFile && activeLineNumbers.find(lineNumber) == activeLineNumbers.end() &&
|
|
||||||
lineNumber >= firstVisibleLine && lineNumber <= lastVisibleLine)
|
|
||||||
{
|
|
||||||
painter.fillRect(0, top + i * blockHeight, width(), blockHeight, backgroundColor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtCodeArea::enterEvent(QEvent* event)
|
void QtCodeArea::enterEvent(QEvent* event)
|
||||||
@@ -811,14 +806,9 @@ std::set<int> QtCodeArea::getActiveLineNumbers() const
|
|||||||
{
|
{
|
||||||
std::set<int> activeLineNumbers;
|
std::set<int> activeLineNumbers;
|
||||||
|
|
||||||
if (m_isActiveFile)
|
|
||||||
{
|
|
||||||
return activeLineNumbers;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const Annotation& annotation : m_annotations)
|
for (const Annotation& annotation : m_annotations)
|
||||||
{
|
{
|
||||||
if (annotation.isActive)
|
if (annotation.isActive || annotation.isFocused)
|
||||||
{
|
{
|
||||||
for (int i = annotation.startLine; i <= annotation.endLine; i++)
|
for (int i = annotation.startLine; i <= annotation.endLine; i++)
|
||||||
{
|
{
|
||||||
@@ -827,20 +817,6 @@ std::set<int> QtCodeArea::getActiveLineNumbers() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activeLineNumbers.size())
|
|
||||||
{
|
|
||||||
for (const Annotation& annotation : m_annotations)
|
|
||||||
{
|
|
||||||
if (annotation.isFocused)
|
|
||||||
{
|
|
||||||
for (int i = annotation.startLine; i <= annotation.endLine; i++)
|
|
||||||
{
|
|
||||||
activeLineNumbers.insert(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return activeLineNumbers;
|
return activeLineNumbers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user