From 9e54e1776e9cee28f8efb8983b96f310a5dee5cc Mon Sep 17 00:00:00 2001 From: hjk Date: Fri, 14 Aug 2020 08:55:22 +0200 Subject: [PATCH] ProjectExplorer: Introduce TextDisplay for simple display tasks That's effectively a beefed-up TextDisplay previously used only in Incredibuild. Change-Id: I0cedef24cede8b8513e80b64f589abe62a68814e Reviewed-by: Christian Kandeler --- .../incredibuild/commandbuilderaspect.cpp | 11 ---- .../incredibuild/commandbuilderaspect.h | 12 ----- .../projectconfigurationaspects.cpp | 54 +++++++++++++++++++ .../projectconfigurationaspects.h | 18 +++++++ 4 files changed, 72 insertions(+), 23 deletions(-) diff --git a/src/plugins/incredibuild/commandbuilderaspect.cpp b/src/plugins/incredibuild/commandbuilderaspect.cpp index fa80d83d08d..14477f1e79a 100644 --- a/src/plugins/incredibuild/commandbuilderaspect.cpp +++ b/src/plugins/incredibuild/commandbuilderaspect.cpp @@ -220,16 +220,5 @@ void CommandBuilderAspect::updateGui() d->makeArgumentsLineEdit->setText(d->m_activeCommandBuilder->arguments()); } -// TextDisplay - -void TextDisplay::addToLayout(LayoutBuilder &builder) -{ - if (!m_label) { - m_label = new QLabel(m_message); - m_label->setTextInteractionFlags(Qt::TextSelectableByMouse); - } - builder.addItem(m_label.data()); -} - } // namespace Internal } // namespace IncrediBuild diff --git a/src/plugins/incredibuild/commandbuilderaspect.h b/src/plugins/incredibuild/commandbuilderaspect.h index 1647b858da4..f2fccd340ca 100644 --- a/src/plugins/incredibuild/commandbuilderaspect.h +++ b/src/plugins/incredibuild/commandbuilderaspect.h @@ -52,17 +52,5 @@ private: class CommandBuilderAspectPrivate *d = nullptr; }; -class TextDisplay final : public ProjectExplorer::ProjectConfigurationAspect -{ -public: - TextDisplay(const QString &message) : m_message(message) {} - -private: - void addToLayout(ProjectExplorer::LayoutBuilder &builder) final; - - QString m_message; - QPointer m_label; -}; - } // namespace Internal } // namespace IncrediBuild diff --git a/src/plugins/projectexplorer/projectconfigurationaspects.cpp b/src/plugins/projectexplorer/projectconfigurationaspects.cpp index a9f4aaa5e20..76710542aea 100644 --- a/src/plugins/projectexplorer/projectconfigurationaspects.cpp +++ b/src/plugins/projectexplorer/projectconfigurationaspects.cpp @@ -156,6 +156,15 @@ public: QList m_items; }; +class TextDisplayPrivate +{ +public: + QString m_message; + QString m_tooltip; + QPixmap m_pixmap; + QPointer m_label; +}; + } // Internal /*! @@ -876,6 +885,51 @@ void StringListAspect::setValue(const QStringList &value) d->m_value = value; } +/*! + \class ProjectExplorer::TextDisplay +*/ + +TextDisplay::TextDisplay(const QString &message) + : d(new Internal::TextDisplayPrivate) +{ + d->m_message = message; +} + +TextDisplay::~TextDisplay() = default; + +void TextDisplay::addToLayout(LayoutBuilder &builder) +{ + if (!d->m_label) { + d->m_label = new QLabel(d->m_message); + d->m_label->setTextInteractionFlags(Qt::TextSelectableByMouse); + d->m_label->setVisible(isVisible()); + d->m_label->setToolTip(d->m_tooltip); + d->m_label->setPixmap(d->m_pixmap); + } + builder.addItem(d->m_label.data()); +} + +void TextDisplay::setVisible(bool visible) +{ + ProjectConfigurationAspect::setVisible(visible); + if (d->m_label) + d->m_label->setVisible(visible); +} + +void TextDisplay::setToolTip(const QString &tooltip) +{ + d->m_tooltip = tooltip; + if (d->m_label) + d->m_label->setToolTip(tooltip); +} + +void TextDisplay::setPixmap(const QPixmap &pixmap) +{ + d->m_pixmap = pixmap; + if (d->m_label) + d->m_label->setPixmap(pixmap); +} + /*! \class ProjectExplorer::AspectContainer */ diff --git a/src/plugins/projectexplorer/projectconfigurationaspects.h b/src/plugins/projectexplorer/projectconfigurationaspects.h index ff0a48193fe..01c3e87deef 100644 --- a/src/plugins/projectexplorer/projectconfigurationaspects.h +++ b/src/plugins/projectexplorer/projectconfigurationaspects.h @@ -257,6 +257,24 @@ private: std::unique_ptr d; }; +class PROJECTEXPLORER_EXPORT TextDisplay : public ProjectConfigurationAspect +{ + Q_OBJECT + +public: + TextDisplay(const QString &message = {}); + ~TextDisplay() override; + + void addToLayout(LayoutBuilder &builder) override; + + void setVisible(bool visible); + void setToolTip(const QString &tooltip); + void setPixmap(const QPixmap &pixmap); + +private: + std::unique_ptr d; +}; + class PROJECTEXPLORER_EXPORT AspectContainer : public ProjectConfigurationAspect { Q_OBJECT