LayoutBuilder: Add a few Label related functions

... and use them in the CoPilot settings

Change-Id: Id861cf34274d2afe798d4735072d02c2c8f724e3
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
hjk
2024-05-31 12:50:40 +02:00
parent 04abc375f5
commit 58ac9aea68
3 changed files with 82 additions and 35 deletions

View File

@@ -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<void (const QString &)> &func, QObject *guard)
{
QObject::connect(access(this), &QLabel::linkHovered, guard, func);
}
// Group
Group::Group(std::initializer_list<I> ps)

View File

@@ -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<void(const QString &)> &, 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); }

View File

@@ -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,