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