forked from qt-creator/qt-creator
Use icons and default tool tips in text mark popup
Change-Id: I4487d642e066479e8e344ed77e539de92fbca651 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -31,7 +31,6 @@
|
||||
#include <utils/icon.h>
|
||||
#include <utils/theme/theme.h>
|
||||
|
||||
#include <QLayout>
|
||||
#include <QString>
|
||||
|
||||
namespace ClangCodeModel {
|
||||
@@ -83,9 +82,10 @@ void ClangTextMark::setIcon(ClangBackEnd::DiagnosticSeverity severity)
|
||||
TextMark::setIcon(errorIcon);
|
||||
}
|
||||
|
||||
void ClangTextMark::addToToolTipLayout(QLayout *target)
|
||||
bool ClangTextMark::addToolTipContent(QLayout *target)
|
||||
{
|
||||
Internal::addToolTipToLayout(m_diagnostic, target);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace ClangCodeModel
|
||||
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
ClangTextMark(const QString &fileName, const ClangBackEnd::DiagnosticContainer &diagnostic);
|
||||
|
||||
private:
|
||||
void addToToolTipLayout(QLayout *target);
|
||||
bool addToolTipContent(QLayout *target);
|
||||
void setIcon(ClangBackEnd::DiagnosticSeverity severity);
|
||||
|
||||
ClangBackEnd::DiagnosticContainer m_diagnostic;
|
||||
|
||||
@@ -147,6 +147,7 @@ void TaskHub::addTask(Task task)
|
||||
auto mark = new TaskMark(task.taskId, task.file.toString(), task.line, task.type, !task.icon.isNull());
|
||||
mark->setIcon(task.icon);
|
||||
mark->setPriority(TextEditor::TextMark::LowPriority);
|
||||
mark->setToolTip(task.description);
|
||||
task.setMark(mark);
|
||||
}
|
||||
emit m_instance->taskAdded(task);
|
||||
|
||||
@@ -91,6 +91,7 @@
|
||||
#include <QClipboard>
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
#include <QGridLayout>
|
||||
#include <QKeyEvent>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
@@ -111,7 +112,6 @@
|
||||
#include <QTimeLine>
|
||||
#include <QTimer>
|
||||
#include <QToolBar>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
//#define DO_FOO
|
||||
|
||||
@@ -5122,7 +5122,7 @@ void TextEditorWidget::extraAreaMouseEvent(QMouseEvent *e)
|
||||
if (data->marks().isEmpty()) {
|
||||
ToolTip::hide();
|
||||
} else {
|
||||
auto layout = new QVBoxLayout;
|
||||
auto layout = new QGridLayout;
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->setSpacing(2);
|
||||
foreach (TextMark *mark, data->marks())
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
#include <coreplugin/documentmanager.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QLayout>
|
||||
#include <QGridLayout>
|
||||
|
||||
using namespace Core;
|
||||
using namespace Utils;
|
||||
@@ -114,6 +114,11 @@ void TextMark::setIcon(const QIcon &icon)
|
||||
m_icon = icon;
|
||||
}
|
||||
|
||||
const QIcon &TextMark::icon() const
|
||||
{
|
||||
return m_icon;
|
||||
}
|
||||
|
||||
Theme::Color TextMark::categoryColor(Id category)
|
||||
{
|
||||
return TextEditorPlugin::baseTextMarkRegistry()->categoryColor(category);
|
||||
@@ -195,10 +200,37 @@ void TextMark::dragToLine(int lineNumber)
|
||||
Q_UNUSED(lineNumber);
|
||||
}
|
||||
|
||||
void TextMark::addToToolTipLayout(QLayout *target)
|
||||
void TextMark::addToToolTipLayout(QGridLayout *target)
|
||||
{
|
||||
if (!m_toolTip.isEmpty())
|
||||
target->addWidget(new QLabel(m_toolTip));
|
||||
auto *contentLayout = new QVBoxLayout;
|
||||
addToolTipContent(contentLayout);
|
||||
if (contentLayout->count() > 0) {
|
||||
const int row = target->rowCount();
|
||||
if (!m_icon.isNull()) {
|
||||
auto iconLabel = new QLabel;
|
||||
iconLabel->setPixmap(m_icon.pixmap(16, 16));
|
||||
target->addWidget(iconLabel, row, 0, Qt::AlignTop | Qt::AlignHCenter);
|
||||
}
|
||||
target->addLayout(contentLayout, row, 1);
|
||||
}
|
||||
}
|
||||
|
||||
bool TextMark::addToolTipContent(QLayout *target)
|
||||
{
|
||||
QString text = m_toolTip;
|
||||
if (text.isEmpty()) {
|
||||
text = TextEditorPlugin::baseTextMarkRegistry()->defaultToolTip(m_category);
|
||||
if (text.isEmpty())
|
||||
return false;
|
||||
}
|
||||
|
||||
auto textLabel = new QLabel;
|
||||
textLabel->setText(text);
|
||||
// Differentiate between tool tips that where explicitly set and default tool tips.
|
||||
textLabel->setEnabled(!m_toolTip.isEmpty());
|
||||
target->addWidget(textLabel);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
TextDocument *TextMark::baseTextDocument() const
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <QIcon>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QGridLayout;
|
||||
class QLayout;
|
||||
class QPainter;
|
||||
class QRect;
|
||||
@@ -74,13 +75,15 @@ public:
|
||||
virtual void clicked();
|
||||
virtual bool isDraggable() const;
|
||||
virtual void dragToLine(int lineNumber);
|
||||
virtual void addToToolTipLayout(QLayout *target);
|
||||
void addToToolTipLayout(QGridLayout *target);
|
||||
virtual bool addToolTipContent(QLayout *target);
|
||||
|
||||
static Utils::Theme::Color categoryColor(Core::Id category);
|
||||
static bool categoryHasColor(Core::Id category);
|
||||
static void setCategoryColor(Core::Id category, Utils::Theme::Color color);
|
||||
static void setDefaultToolTip(Core::Id category, const QString &toolTip);
|
||||
void setIcon(const QIcon &icon);
|
||||
const QIcon &icon() const;
|
||||
// call this if the icon has changed.
|
||||
void updateMarker();
|
||||
Priority priority() const;
|
||||
|
||||
Reference in New Issue
Block a user