forked from qt-creator/qt-creator
TextEditor: remove mark width factor
Needed to optimize painting of different text mark icons in one line. Change-Id: Ia7f9dd12020e2a21875b3de54b65257f8ea337d9 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -996,10 +996,8 @@ bool TextDocument::addMark(TextMark *mark)
|
||||
if (!mark->isVisible())
|
||||
return true;
|
||||
// Update document layout
|
||||
double newMaxWidthFactor = qMax(mark->widthFactor(), documentLayout->maxMarkWidthFactor);
|
||||
bool fullUpdate = newMaxWidthFactor > documentLayout->maxMarkWidthFactor || !documentLayout->hasMarks;
|
||||
bool fullUpdate = !documentLayout->hasMarks;
|
||||
documentLayout->hasMarks = true;
|
||||
documentLayout->maxMarkWidthFactor = newMaxWidthFactor;
|
||||
if (fullUpdate)
|
||||
documentLayout->requestUpdate();
|
||||
else
|
||||
@@ -1037,7 +1035,6 @@ void TextDocument::removeMarkFromMarksCache(TextMark *mark)
|
||||
|
||||
if (d->m_marksCache.isEmpty()) {
|
||||
documentLayout->hasMarks = false;
|
||||
documentLayout->maxMarkWidthFactor = 1.0;
|
||||
scheduleLayoutUpdate();
|
||||
return;
|
||||
}
|
||||
@@ -1045,28 +1042,7 @@ void TextDocument::removeMarkFromMarksCache(TextMark *mark)
|
||||
if (!mark->isVisible())
|
||||
return;
|
||||
|
||||
if (documentLayout->maxMarkWidthFactor == 1.0
|
||||
|| mark->widthFactor() == 1.0
|
||||
|| mark->widthFactor() < documentLayout->maxMarkWidthFactor) {
|
||||
// No change in width possible
|
||||
documentLayout->requestExtraAreaUpdate();
|
||||
} else {
|
||||
double maxWidthFactor = 1.0;
|
||||
for (const TextMark *mark : qAsConst(d->m_marksCache)) {
|
||||
if (!mark->isVisible())
|
||||
continue;
|
||||
maxWidthFactor = qMax(mark->widthFactor(), maxWidthFactor);
|
||||
if (maxWidthFactor == documentLayout->maxMarkWidthFactor)
|
||||
break; // Still a mark with the maxMarkWidthFactor
|
||||
}
|
||||
|
||||
if (maxWidthFactor != documentLayout->maxMarkWidthFactor) {
|
||||
documentLayout->maxMarkWidthFactor = maxWidthFactor;
|
||||
scheduleLayoutUpdate();
|
||||
} else {
|
||||
documentLayout->requestExtraAreaUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TextDocument::removeMark(TextMark *mark)
|
||||
|
||||
@@ -225,7 +225,6 @@ public:
|
||||
|
||||
int lastSaveRevision = 0;
|
||||
bool hasMarks = false;
|
||||
double maxMarkWidthFactor = 1.0;
|
||||
int m_requiredWidth = 0;
|
||||
|
||||
void setRequiredWidth(int width);
|
||||
|
||||
@@ -4793,7 +4793,7 @@ int TextEditorWidget::extraAreaWidth(int *markWidthPtr) const
|
||||
int markWidth = 0;
|
||||
|
||||
if (d->m_marksVisible) {
|
||||
markWidth += documentLayout->maxMarkWidthFactor * fm.lineSpacing() + 2;
|
||||
markWidth += fm.lineSpacing() + 2;
|
||||
|
||||
// if (documentLayout->doubleMarkCount)
|
||||
// markWidth += fm.lineSpacing() / 3;
|
||||
@@ -4919,8 +4919,7 @@ void TextEditorWidgetPrivate::paintTextMarks(QPainter &painter, const ExtraAreaP
|
||||
if (!mark->isVisible() && !mark->icon().isNull())
|
||||
continue;
|
||||
const int height = data.lineSpacing - 1;
|
||||
const int width = int(.5 + height * mark->widthFactor());
|
||||
const QRect r(xoffset, int(blockBoundingRect.top()), width, height);
|
||||
const QRect r(xoffset, int(blockBoundingRect.top()), height, height);
|
||||
mark->paintIcon(&painter, r);
|
||||
xoffset += 2;
|
||||
}
|
||||
@@ -5698,8 +5697,7 @@ void TextEditorWidget::extraAreaMouseEvent(QMouseEvent *e)
|
||||
if (dist > QApplication::startDragDistance()) {
|
||||
d->m_markDragging = true;
|
||||
const int height = fontMetrics().lineSpacing() - 1;
|
||||
const int width = int(.5 + height * d->m_dragMark->widthFactor());
|
||||
d->m_markDragCursor = QCursor(d->m_dragMark->icon().pixmap({height, width}));
|
||||
d->m_markDragCursor = QCursor(d->m_dragMark->icon().pixmap({height, height}));
|
||||
d->m_dragMark->setVisible(false);
|
||||
QGuiApplication::setOverrideCursor(d->m_markDragCursor);
|
||||
}
|
||||
|
||||
@@ -84,12 +84,11 @@ private:
|
||||
|
||||
TextMarkRegistry *m_instance = nullptr;
|
||||
|
||||
TextMark::TextMark(const FilePath &fileName, int lineNumber, Id category, double widthFactor)
|
||||
TextMark::TextMark(const FilePath &fileName, int lineNumber, Id category)
|
||||
: m_fileName(fileName)
|
||||
, m_lineNumber(lineNumber)
|
||||
, m_visible(true)
|
||||
, m_category(category)
|
||||
, m_widthFactor(widthFactor)
|
||||
{
|
||||
if (!m_fileName.isEmpty())
|
||||
TextMarkRegistry::add(this);
|
||||
@@ -200,7 +199,7 @@ TextMark::AnnotationRects TextMark::annotationRects(const QRectF &boundingRect,
|
||||
rects.iconRect = QRectF(rects.annotationRect.left(), boundingRect.top(),
|
||||
0, boundingRect.height());
|
||||
if (drawIcon)
|
||||
rects.iconRect.setWidth(rects.iconRect.height() * m_widthFactor);
|
||||
rects.iconRect.setWidth(rects.iconRect.height());
|
||||
rects.textRect = QRectF(rects.iconRect.right() + margin, boundingRect.top(),
|
||||
qreal(fm.horizontalAdvance(rects.text)), boundingRect.height());
|
||||
rects.annotationRect.setRight(rects.textRect.right() + margin);
|
||||
@@ -263,16 +262,6 @@ void TextMark::setVisible(bool visible)
|
||||
updateMarker();
|
||||
}
|
||||
|
||||
double TextMark::widthFactor() const
|
||||
{
|
||||
return m_widthFactor;
|
||||
}
|
||||
|
||||
void TextMark::setWidthFactor(double factor)
|
||||
{
|
||||
m_widthFactor = factor;
|
||||
}
|
||||
|
||||
bool TextMark::isClickable() const
|
||||
{
|
||||
return false;
|
||||
|
||||
@@ -55,8 +55,7 @@ class TEXTEDITOR_EXPORT TextMark
|
||||
public:
|
||||
TextMark(const Utils::FilePath &fileName,
|
||||
int lineNumber,
|
||||
Utils::Id category,
|
||||
double widthFactor = 1.0);
|
||||
Utils::Id category);
|
||||
TextMark() = delete;
|
||||
virtual ~TextMark();
|
||||
|
||||
@@ -112,8 +111,6 @@ public:
|
||||
bool isVisible() const;
|
||||
void setVisible(bool isVisible);
|
||||
Utils::Id category() const { return m_category; }
|
||||
double widthFactor() const;
|
||||
void setWidthFactor(double factor);
|
||||
|
||||
Utils::optional<Utils::Theme::Color> color() const;
|
||||
void setColor(const Utils::Theme::Color &color);
|
||||
@@ -149,7 +146,6 @@ private:
|
||||
Utils::optional<Utils::Theme::Color> m_color;
|
||||
bool m_visible = false;
|
||||
Utils::Id m_category;
|
||||
double m_widthFactor = 1.0;
|
||||
QString m_lineAnnotation;
|
||||
QString m_toolTip;
|
||||
std::function<QString()> m_toolTipProvider;
|
||||
|
||||
Reference in New Issue
Block a user