Commit 5294c68c authored by David Schulz's avatar David Schulz
Browse files

TextEditor: Add display settings page link to annotation tool tips



Change-Id: I453127693dd1e0b30918333ac6866ac2fca4baa6
Reviewed-by: Christian Stenger's avatarChristian Stenger <christian.stenger@qt.io>
parent 3ec59b46
......@@ -47,6 +47,7 @@
#include <cpptools/editordocumenthandle.h>
#include <texteditor/convenience.h>
#include <texteditor/displaysettings.h>
#include <texteditor/fontsettings.h>
#include <texteditor/texteditor.h>
#include <texteditor/texteditorconstants.h>
......@@ -274,6 +275,9 @@ void ClangEditorDocumentProcessor::addDiagnosticToolTipToLayout(uint line,
= m_diagnosticManager.diagnosticsAt(line, column);
target->addWidget(ClangDiagnosticWidget::create(diagnostics, ClangDiagnosticWidget::ToolTip));
auto link = TextEditor::DisplaySettings::createAnnotationSettingsLink();
target->addWidget(link);
target->setAlignment(link, Qt::AlignRight);
}
void ClangEditorDocumentProcessor::editorDocumentTimerRestarted()
......
......@@ -25,6 +25,12 @@
#include "displaysettings.h"
#include "texteditorconstants.h"
#include <coreplugin/icore.h>
#include <utils/tooltip/tooltip.h>
#include <QLabel>
#include <QSettings>
#include <QString>
......@@ -131,7 +137,17 @@ bool DisplaySettings::equals(const DisplaySettings &ds) const
&& m_displayAnnotations == ds.m_displayAnnotations
&& m_annotationAlignment == ds.m_annotationAlignment
&& m_minimalAnnotationContent == ds.m_minimalAnnotationContent
;
;
}
QLabel *DisplaySettings::createAnnotationSettingsLink()
{
auto *label = new QLabel("<i><a href>Annotation Settings</a></i>", Core::ICore::mainWindow());
QObject::connect(label, &QLabel::linkActivated, []() {
Utils::ToolTip::hideImmediately();
Core::ICore::showOptionsDialog(Constants::TEXT_EDITOR_DISPLAY_SETTINGS);
});
return label;
}
} // namespace TextEditor
......@@ -31,6 +31,7 @@
QT_BEGIN_NAMESPACE
class QSettings;
class QLabel;
QT_END_NAMESPACE
namespace TextEditor {
......@@ -72,6 +73,8 @@ public:
int m_minimalAnnotationContent = 15;
bool equals(const DisplaySettings &ds) const;
static QLabel *createAnnotationSettingsLink();
};
inline bool operator==(const DisplaySettings &t1, const DisplaySettings &t2) { return t1.equals(t2); }
......
......@@ -46,6 +46,7 @@
#include "tabsettings.h"
#include "textdocument.h"
#include "textdocumentlayout.h"
#include "texteditorconstants.h"
#include "texteditoroverlay.h"
#include "refactoroverlay.h"
#include "texteditorsettings.h"
......@@ -3291,30 +3292,32 @@ bool TextEditorWidgetPrivate::processAnnotaionTooltipRequest(const QTextBlock &b
return false;
for (const AnnotationRect &annotationRect : m_annotationRects[block.blockNumber()]) {
if (annotationRect.rect.contains(pos)) {
auto layout = new QGridLayout;
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(2);
annotationRect.mark->addToToolTipLayout(layout);
TextMarks marks = blockUserData->marks();
if (marks.size() > 1) {
QFrame* separator = new QFrame();
separator->setFrameShape(QFrame::HLine);
layout->addWidget(separator, 2, 0, 1, layout->columnCount());
layout->addWidget(new QLabel(tr("Other annotations:")), 3, 0, 1,
layout->columnCount());
Utils::sort(marks, [](const TextMark* mark1, const TextMark* mark2){
return mark1->priority() > mark2->priority();
});
for (const TextMark *mark : Utils::asConst(marks)) {
if (mark != annotationRect.mark)
mark->addToToolTipLayout(layout);
}
if (!annotationRect.rect.contains(pos))
continue;
auto layout = new QGridLayout;
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(2);
annotationRect.mark->addToToolTipLayout(layout);
TextMarks marks = blockUserData->marks();
if (marks.size() > 1) {
QFrame* separator = new QFrame();
separator->setFrameShape(QFrame::HLine);
layout->addWidget(separator, layout->rowCount(), 0, 1, -1);
layout->addWidget(new QLabel(tr("Other annotations:")), layout->rowCount(), 0, 1, -1);
Utils::sort(marks, [](const TextMark* mark1, const TextMark* mark2){
return mark1->priority() > mark2->priority();
});
for (const TextMark *mark : Utils::asConst(marks)) {
if (mark != annotationRect.mark)
mark->addToToolTipLayout(layout);
}
ToolTip::show(q->mapToGlobal(pos), layout, q);
return true;
}
layout->addWidget(DisplaySettings::createAnnotationSettingsLink(),
layout->rowCount(), 0, 1, -1, Qt::AlignRight);
ToolTip::show(q->mapToGlobal(pos), layout, q);
return true;
}
return false;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment