diff options
author | Nikolai Kosjar <nikolai.kosjar@qt.io> | 2019-01-28 09:32:11 +0100 |
---|---|---|
committer | Nikolai Kosjar <nikolai.kosjar@qt.io> | 2019-02-01 08:15:36 +0000 |
commit | 0df7468e517192b5fbc6c8a5059d3ef6c412545c (patch) | |
tree | 8f203735d93e1fd467e58c9e8f6cfec0b32dcb45 /src/plugins/texteditor/textmark.cpp | |
parent | 966f4ea6a9d1e46833fc30df878ba6fa8f919988 (diff) |
Clang: Add tooltip action to copy to clipboard
...as selecting text in the tooltip was difficult and eventually got
disabled due to other problems - see
d58c0a9ac8123fd81c335b322defbbb567de840d.
This adds support for actions in TextMarks. They are displayed as
QToolButtons in a dedicated column in the tooltip.
Change-Id: I84ee3c3e4af573a80953786881d1333b00e4200c
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/texteditor/textmark.cpp')
-rw-r--r-- | src/plugins/texteditor/textmark.cpp | 49 |
1 files changed, 42 insertions, 7 deletions
diff --git a/src/plugins/texteditor/textmark.cpp b/src/plugins/texteditor/textmark.cpp index 17c6268f85f..89951675646 100644 --- a/src/plugins/texteditor/textmark.cpp +++ b/src/plugins/texteditor/textmark.cpp @@ -31,9 +31,12 @@ #include <coreplugin/editormanager/editormanager.h> #include <coreplugin/documentmanager.h> #include <utils/qtcassert.h> +#include <utils/tooltip/tooltip.h> +#include <QAction> #include <QGridLayout> #include <QPainter> +#include <QToolButton> using namespace Core; using namespace Utils; @@ -88,6 +91,8 @@ TextMark::TextMark(const FileName &fileName, int lineNumber, Id category, double TextMark::~TextMark() { + qDeleteAll(m_actions); + m_actions.clear(); if (!m_fileName.isEmpty()) TextMarkRegistry::remove(this); if (m_baseTextDocument) @@ -269,14 +274,34 @@ void TextMark::addToToolTipLayout(QGridLayout *target) const { 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); + if (contentLayout->count() <= 0) + return; + + // Left column: text mark icon + 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); + } + + // Middle column: tooltip content + target->addLayout(contentLayout, row, 1); + + // Right column: action icons/button + if (!m_actions.isEmpty()) { + auto actionsLayout = new QHBoxLayout; + for (QAction *action : m_actions) { + QTC_ASSERT(!action->icon().isNull(), continue); + auto button = new QToolButton; + button->setIcon(action->icon()); + QObject::connect(button, &QToolButton::clicked, action, &QAction::triggered); + QObject::connect(button, &QToolButton::clicked, []() { + Utils::ToolTip::hideImmediately(); + }); + actionsLayout->addWidget(button, 0, Qt::AlignTop | Qt::AlignRight); } - target->addLayout(contentLayout, row, 1); + target->addLayout(actionsLayout, row, 2); } } @@ -311,6 +336,16 @@ void TextMark::setColor(const Theme::Color &color) m_color = color; } +QVector<QAction *> TextMark::actions() const +{ + return m_actions; +} + +void TextMark::setActions(const QVector<QAction *> &actions) +{ + m_actions = actions; +} + TextMarkRegistry::TextMarkRegistry(QObject *parent) : QObject(parent) { |