forked from qt-creator/qt-creator
Editor: Use optional for text mark color
instead of an additional hasColor member Change-Id: I658401bb91374b10420e070625cf61049cb3cc64 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -6364,7 +6364,9 @@ void TextEditorWidgetPrivate::addSearchResultsToScrollBar(QVector<SearchResult>
|
||||
|
||||
Highlight markToHighlight(TextMark *mark, int lineNumber)
|
||||
{
|
||||
return Highlight(mark->category(), lineNumber, mark->color(),
|
||||
return Highlight(mark->category(),
|
||||
lineNumber,
|
||||
mark->color().value_or(Utils::Theme::TextColorNormal),
|
||||
textMarkPrioToScrollBarPrio(mark->priority()));
|
||||
}
|
||||
|
||||
@@ -6382,8 +6384,9 @@ void TextEditorWidgetPrivate::updateHighlightScrollBarNow()
|
||||
addSearchResultsToScrollBar(m_searchResults);
|
||||
|
||||
// update text marks
|
||||
foreach (TextMark *mark, m_document->marks()) {
|
||||
if (!mark->isVisible() || !mark->hasColor())
|
||||
const TextMarks marks = m_document->marks();
|
||||
for (TextMark *mark : marks) {
|
||||
if (!mark->isVisible() || !mark->color().has_value())
|
||||
continue;
|
||||
const QTextBlock &block = q->document()->findBlockByNumber(mark->lineNumber() - 1);
|
||||
if (block.isVisible())
|
||||
|
@@ -136,8 +136,9 @@ void TextMark::paintAnnotation(QPainter &painter, QRectF *annotationRect,
|
||||
|
||||
const AnnotationRects &rects = annotationRects(*annotationRect, painter.fontMetrics(),
|
||||
fadeInOffset, fadeOutOffset);
|
||||
const QColor &markColor = m_hasColor ? Utils::creatorTheme()->color(m_color).toHsl()
|
||||
: painter.pen().color();
|
||||
const QColor &markColor = m_color.has_value()
|
||||
? Utils::creatorTheme()->color(m_color.value()).toHsl()
|
||||
: painter.pen().color();
|
||||
const AnnotationColors &colors = AnnotationColors::getAnnotationColors(
|
||||
markColor, painter.background().color());
|
||||
|
||||
@@ -327,15 +328,13 @@ bool TextMark::addToolTipContent(QLayout *target) const
|
||||
return true;
|
||||
}
|
||||
|
||||
Theme::Color TextMark::color() const
|
||||
Utils::optional<Theme::Color> TextMark::color() const
|
||||
{
|
||||
QTC_CHECK(m_hasColor);
|
||||
return m_color;
|
||||
}
|
||||
|
||||
void TextMark::setColor(const Theme::Color &color)
|
||||
{
|
||||
m_hasColor = true;
|
||||
m_color = color;
|
||||
}
|
||||
|
||||
|
@@ -30,6 +30,7 @@
|
||||
#include <coreplugin/id.h>
|
||||
#include <utils/theme/theme.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/optional.h>
|
||||
|
||||
#include <QIcon>
|
||||
#include <QVector>
|
||||
@@ -108,9 +109,8 @@ public:
|
||||
double widthFactor() const;
|
||||
void setWidthFactor(double factor);
|
||||
|
||||
Utils::Theme::Color color() const;
|
||||
Utils::optional<Utils::Theme::Color> color() const;
|
||||
void setColor(const Utils::Theme::Color &color);
|
||||
bool hasColor() const { return m_hasColor; }
|
||||
|
||||
QString defaultToolTip() const { return m_defaultToolTip; }
|
||||
void setDefaultToolTip(const QString &toolTip) { m_defaultToolTip = toolTip; }
|
||||
@@ -135,9 +135,8 @@ private:
|
||||
int m_lineNumber = 0;
|
||||
Priority m_priority = LowPriority;
|
||||
QIcon m_icon;
|
||||
Utils::Theme::Color m_color = Utils::Theme::TextColorNormal;
|
||||
Utils::optional<Utils::Theme::Color> m_color;
|
||||
bool m_visible = false;
|
||||
bool m_hasColor = false;
|
||||
Core::Id m_category;
|
||||
double m_widthFactor = 1.0;
|
||||
QString m_lineAnnotation;
|
||||
|
Reference in New Issue
Block a user