forked from qt-creator/qt-creator
Editor: improve painting multiple mark icons per line
Instead of painting them visually on top of each other paint them in a grid with a number indicating how much marks are in total in that line. Fixes: QTCREATORBUG-27415 Change-Id: Ifbf35c956670976b54e5084569d77a6f9e7f59a7 Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -4922,31 +4922,62 @@ void TextEditorWidgetPrivate::paintTextMarks(QPainter &painter, const ExtraAreaP
|
|||||||
auto userData = static_cast<TextBlockUserData*>(data.block.userData());
|
auto userData = static_cast<TextBlockUserData*>(data.block.userData());
|
||||||
if (!userData || !m_marksVisible)
|
if (!userData || !m_marksVisible)
|
||||||
return;
|
return;
|
||||||
int xoffset = 0;
|
|
||||||
TextMarks marks = userData->marks();
|
TextMarks marks = userData->marks();
|
||||||
TextMarks::const_iterator it = marks.constBegin();
|
QList<QIcon> icons;
|
||||||
if (marks.size() > 3) {
|
auto end = marks.crend();
|
||||||
// We want the 3 with the highest priority that have an icon so iterate from the back
|
int marksWithIconCount = 0;
|
||||||
int count = 0;
|
for (auto it = marks.crbegin(); it != end; ++it) {
|
||||||
it = marks.constEnd() - 1;
|
if ((*it)->isVisible()) {
|
||||||
while (it != marks.constBegin()) {
|
const QIcon icon = (*it)->icon();
|
||||||
if ((*it)->isVisible() && !(*it)->icon().isNull())
|
if (!icon.isNull()) {
|
||||||
++count;
|
if (icons.size() < 3
|
||||||
if (count == 3)
|
&& !Utils::contains(icons, Utils::equal(&QIcon::cacheKey, icon.cacheKey()))) {
|
||||||
break;
|
icons << icon;
|
||||||
--it;
|
}
|
||||||
|
++marksWithIconCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TextMarks::const_iterator end = marks.constEnd();
|
|
||||||
for ( ; it != end; ++it) {
|
|
||||||
TextMark *mark = *it;
|
|
||||||
if (!mark->isVisible() && !mark->icon().isNull())
|
|
||||||
continue;
|
|
||||||
const int height = data.lineSpacing - 1;
|
|
||||||
const QRect r(xoffset, int(blockBoundingRect.top()), height, height);
|
|
||||||
mark->paintIcon(&painter, r);
|
|
||||||
xoffset += 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (icons.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
painter.save();
|
||||||
|
Utils::ExecuteOnDestruction painterRestore([&]() { painter.restore(); });
|
||||||
|
|
||||||
|
int size = data.lineSpacing - 1;
|
||||||
|
int xoffset = 0;
|
||||||
|
int yoffset = blockBoundingRect.top();
|
||||||
|
|
||||||
|
if (icons.size() == 1) {
|
||||||
|
const QRect r(xoffset, yoffset, size, size);
|
||||||
|
icons.first().paint(&painter, r, Qt::AlignCenter);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
size = size / 2;
|
||||||
|
for (const QIcon &icon : qAsConst(icons)) {
|
||||||
|
const QRect r(xoffset, yoffset, size, size);
|
||||||
|
icon.paint(&painter, r, Qt::AlignCenter);
|
||||||
|
if (xoffset != 0) {
|
||||||
|
yoffset += size;
|
||||||
|
xoffset = 0;
|
||||||
|
} else {
|
||||||
|
xoffset = size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QFont font = painter.font();
|
||||||
|
font.setPixelSize(size);
|
||||||
|
painter.setFont(font);
|
||||||
|
|
||||||
|
const QColor color = data.currentLineNumberFormat.foreground().color();
|
||||||
|
if (color.isValid())
|
||||||
|
painter.setPen(color);
|
||||||
|
|
||||||
|
const QRect r(size, blockBoundingRect.top() + size, size, size);
|
||||||
|
const QString detail = marksWithIconCount > 9 ? QString("+")
|
||||||
|
: QString::number(marksWithIconCount);
|
||||||
|
painter.drawText(r, Qt::AlignRight, detail);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void drawRectBox(QPainter *painter, const QRect &rect, const QPalette &pal)
|
static void drawRectBox(QPainter *painter, const QRect &rect, const QPalette &pal)
|
||||||
|
Reference in New Issue
Block a user