diff --git a/src/libs/utils/layoutbuilder.cpp b/src/libs/utils/layoutbuilder.cpp index cd4fde81109..09e3a83520e 100644 --- a/src/libs/utils/layoutbuilder.cpp +++ b/src/libs/utils/layoutbuilder.cpp @@ -763,6 +763,31 @@ void Label::setText(const QString &text) access(this)->setText(text); } +void Label::setTextFormat(Qt::TextFormat format) +{ + access(this)->setTextFormat(format); +} + +void Label::setWordWrap(bool on) +{ + access(this)->setWordWrap(on); +} + +void Label::setTextInteractionFlags(Qt::TextInteractionFlags flags) +{ + access(this)->setTextInteractionFlags(flags); +} + +void Label::setOpenExternalLinks(bool on) +{ + access(this)->setOpenExternalLinks(on); +} + +void Label::onLinkHovered(const std::function &func, QObject *guard) +{ + QObject::connect(access(this), &QLabel::linkHovered, guard, func); +} + // Group Group::Group(std::initializer_list ps) diff --git a/src/libs/utils/layoutbuilder.h b/src/libs/utils/layoutbuilder.h index 3a7eca26a57..07a6b9478ef 100644 --- a/src/libs/utils/layoutbuilder.h +++ b/src/libs/utils/layoutbuilder.h @@ -279,6 +279,11 @@ public: Label(const QString &text); void setText(const QString &); + void setTextFormat(Qt::TextFormat); + void setWordWrap(bool); + void setTextInteractionFlags(Qt::TextInteractionFlags); + void setOpenExternalLinks(bool); + void onLinkHovered(const std::function &, QObject *guard); }; class QTCREATOR_UTILS_EXPORT Group : public Widget @@ -446,6 +451,26 @@ class TitleId {}; auto title(auto p) { return IdAndArg{TitleId{}, p}; } void doit(auto x, TitleId, auto p) { x->setTitle(p); } +class TextFormatId {}; +auto textFormat(auto p) { return IdAndArg{TextFormatId{}, p}; } +void doit(auto x, TextFormatId, auto p) { x->setTextFormat(p); } + +class WordWrapId {}; +auto wordWrap(auto p) { return IdAndArg{WordWrapId{}, p}; } +void doit(auto x, WordWrapId, auto p) { x->setWordWrap(p); } + +class TextInteractionFlagId {}; +auto textInteractionFlags(auto p) { return IdAndArg{TextInteractionFlagId{}, p}; } +void doit(auto x, TextInteractionFlagId, auto p) { x->setTextInteractionFlags(p); } + +class OpenExternalLinksId {}; +auto openExternalLinks(auto p) { return IdAndArg{OpenExternalLinksId{}, p}; } +void doit(auto x, OpenExternalLinksId, auto p) { x->setOpenExternalLinks(p); } + +class OnLinkHoveredId {}; +auto onLinkHovered(auto p, QObject *guard) { return IdAndArg{OnLinkHoveredId{}, std::pair{p, guard}}; } +void doit(auto x, OnLinkHoveredId, auto p) { x->onLinkHovered(p.first, p.second); } + class GroupCheckerId {}; auto groupChecker(auto p) { return IdAndArg{GroupCheckerId{}, p}; } void doit(auto x, GroupCheckerId, auto p) { x->setGroupChecker(p); } diff --git a/src/plugins/copilot/copilotsettings.cpp b/src/plugins/copilot/copilotsettings.cpp index 9ddfa4edfbb..aeac499c631 100644 --- a/src/plugins/copilot/copilotsettings.cpp +++ b/src/plugins/copilot/copilotsettings.cpp @@ -168,41 +168,38 @@ CopilotSettings::CopilotSettings() setLayouter([this] { using namespace Layouting; - auto warningLabel = new QLabel; - warningLabel->setWordWrap(true); - warningLabel->setTextInteractionFlags( - Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard | Qt::TextSelectableByMouse); - warningLabel->setText( - Tr::tr("Enabling %1 is subject to your agreement and abidance with your applicable " - "%1 terms. It is your responsibility to know and accept the requirements and " - "parameters of using tools like %1. This may include, but is not limited to, " - "ensuring you have the rights to allow %1 access to your code, as well as " - "understanding any implications of your use of %1 and suggestions produced " - "(like copyright, accuracy, etc.).") - .arg("Copilot")); - - auto authWidget = new AuthWidget(); - - auto helpLabel = new QLabel(); - helpLabel->setTextFormat(Qt::MarkdownText); - helpLabel->setWordWrap(true); - helpLabel->setTextInteractionFlags( - Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard | Qt::TextSelectableByMouse); - helpLabel->setOpenExternalLinks(true); - connect(helpLabel, &QLabel::linkHovered, [](const QString &link) { - QToolTip::showText(QCursor::pos(), link); - }); - // clang-format off - helpLabel->setText(Tr::tr( - "The Copilot plugin requires node.js and the Copilot neovim plugin. " - "If you install the neovim plugin as described in %1, " - "the plugin will find the agent.js file automatically.\n\n" - "Otherwise you need to specify the path to the %2 " - "file from the Copilot neovim plugin.", - "Markdown text for the copilot instruction label") - .arg("[README.md](https://github.com/github/copilot.vim)") - .arg("[agent.js](https://github.com/github/copilot.vim/tree/release/dist)")); + + Label warningLabel { + wordWrap(true), + textInteractionFlags( + Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard | Qt::TextSelectableByMouse), + text(Tr::tr("Enabling %1 is subject to your agreement and abidance with your applicable " + "%1 terms. It is your responsibility to know and accept the requirements and " + "parameters of using tools like %1. This may include, but is not limited to, " + "ensuring you have the rights to allow %1 access to your code, as well as " + "understanding any implications of your use of %1 and suggestions produced " + "(like copyright, accuracy, etc.).") + .arg("Copilot")), + }; + + Label helpLabel { + textFormat(Qt::MarkdownText), + wordWrap(true), + textInteractionFlags( + Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard | Qt::TextSelectableByMouse), + openExternalLinks(true), + onLinkHovered([](const QString &link) { QToolTip::showText(QCursor::pos(), link); }, this), + text(Tr::tr( + "The Copilot plugin requires node.js and the Copilot neovim plugin. " + "If you install the neovim plugin as described in %1, " + "the plugin will find the agent.js file automatically.\n\n" + "Otherwise you need to specify the path to the %2 " + "file from the Copilot neovim plugin.", + "Markdown text for the copilot instruction label") + .arg("[README.md](https://github.com/github/copilot.vim)") + .arg("[agent.js](https://github.com/github/copilot.vim/tree/release/dist)")) + }; return Column { Group { @@ -213,7 +210,7 @@ CopilotSettings::CopilotSettings() } }, Form { - authWidget, br, + new AuthWidget, br, enableCopilot, br, nodeJsPath, br, distPath, br,