From a5317cdaa51386eba406b65ab2d440d5b87a967d Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Fri, 1 Feb 2019 09:05:41 +0100 Subject: [PATCH] TextEditor: Polish separator in text mark tooltip Use one row instead of two for showing "Other annotations" and the separator line. Change-Id: I25234fc2fb49ccb71125a1cf762c89b668032b77 Reviewed-by: David Schulz --- src/plugins/texteditor/texteditor.cpp | 41 ++++++++++++++++++++------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index 0fdb332b384..acf9072bc25 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -839,6 +839,35 @@ TextEditorWidgetPrivate::~TextEditorWidgetPrivate() delete m_highlightScrollBarController; } +static QFrame *createSeparator(const QString &styleSheet) +{ + QFrame* separator = new QFrame(); + separator->setStyleSheet(styleSheet); + separator->setFrameShape(QFrame::HLine); + QSizePolicy sizePolicy = separator->sizePolicy(); + sizePolicy.setHorizontalPolicy(QSizePolicy::MinimumExpanding); + separator->setSizePolicy(sizePolicy); + + return separator; +} + +static QLayout *createSeparatorLayout() +{ + QString styleSheet = "color: gray"; + + QFrame* separator1 = createSeparator(styleSheet); + QFrame* separator2 = createSeparator(styleSheet); + auto label = new QLabel(TextEditorWidget::tr("Other annotations")); + label->setStyleSheet(styleSheet); + + auto layout = new QHBoxLayout; + layout->addWidget(separator1); + layout->addWidget(label); + layout->addWidget(separator2); + + return layout; +} + void TextEditorWidgetPrivate::showTextMarksToolTip(const QPoint &pos, const TextMarks &marks, const TextMark *mainTextMark) const @@ -854,16 +883,8 @@ void TextEditorWidgetPrivate::showTextMarksToolTip(const QPoint &pos, if (mainTextMark) { mainTextMark->addToToolTipLayout(layout); - if (allMarks.size() > 1) { - QFrame* separator = new QFrame(); - separator->setFrameShape(QFrame::HLine); - layout->addWidget(separator, layout->rowCount(), 0, 1, -1); - layout->addWidget(new QLabel(TextEditorWidget::tr("Other annotations:")), - layout->rowCount(), - 0, - 1, - -1); - } + if (allMarks.size() > 1) + layout->addLayout(createSeparatorLayout(), layout->rowCount(), 0, 1, -1); } Utils::sort(allMarks, [](const TextMark *mark1, const TextMark *mark2) {