Commit a4b6783f authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Make "select label text on focus" workaround customizable

Disable the workaround be default. Enable the workaround for all
current users of HtmlLabel.

GnuPG-bug-id: 6034
parent 9ffe17d3
......@@ -251,6 +251,7 @@ ResultItemWidget::ResultItemWidget(const std::shared_ptr<const Task::Result> &re
overview->setHtml(d->m_result->overview());
overview->setStyleSheet(styleSheet);
overview->setLinkColor(linkColor);
overview->setSelectTextOnFocus(true);
setFocusPolicy(overview->focusPolicy());
setFocusProxy(overview);
connect(overview, &QLabel::linkActivated,
......@@ -280,6 +281,7 @@ ResultItemWidget::ResultItemWidget(const std::shared_ptr<const Task::Result> &re
detailsLabel->setHtml(d->m_result->details());
detailsLabel->setStyleSheet(styleSheet);
detailsLabel->setLinkColor(linkColor);
detailsLabel->setSelectTextOnFocus(true);
connect(detailsLabel, &QLabel::linkActivated,
this, [this](const auto &link) { d->slotLinkActivated(link); });
vlay->addWidget(detailsLabel);
......
......@@ -98,6 +98,7 @@ public:
ui.resultLabel = new HtmlLabel{q};
ui.resultLabel->setWordWrap(true);
ui.resultLabel->setFocusPolicy(Qt::ClickFocus);
ui.resultLabel->setSelectTextOnFocus(true);
labelHelper.addLabel(ui.resultLabel);
scrollAreaLayout->addWidget(ui.resultLabel);
}
......
......@@ -43,6 +43,7 @@ public:
int anchorIndex(int start);
void invalidateAnchorCache();
bool mSelectTextOnFocus = false;
bool mAnchorsValid = false;
std::vector<AnchorData> mAnchors;
QColor linkColor;
......@@ -152,6 +153,11 @@ HtmlLabel::HtmlLabel(const QString &html, QWidget *parent)
HtmlLabel::~HtmlLabel() = default;
void HtmlLabel::setSelectTextOnFocus(bool select)
{
d->mSelectTextOnFocus = select;
}
void HtmlLabel::setHtml(const QString &html)
{
if (html.isEmpty()) {
......@@ -224,14 +230,16 @@ void HtmlLabel::focusInEvent(QFocusEvent *ev)
{
QLabel::focusInEvent(ev);
// if the text label gets focus, then select its text; this is a workaround
// for missing focus indicators for labels in many Qt styles
const Qt::FocusReason reason = ev->reason();
const auto isKeyboardFocusEvent = reason == Qt::TabFocusReason
|| reason == Qt::BacktabFocusReason
|| reason == Qt::ShortcutFocusReason;
if (!text().isEmpty() && isKeyboardFocusEvent) {
Kleo::selectLabelText(this);
if (d->mSelectTextOnFocus) {
// if the text label gets focus, then select its text; this is a workaround
// for missing focus indicators for labels in many Qt styles
const Qt::FocusReason reason = ev->reason();
const auto isKeyboardFocusEvent = reason == Qt::TabFocusReason
|| reason == Qt::BacktabFocusReason
|| reason == Qt::ShortcutFocusReason;
if (!text().isEmpty() && isKeyboardFocusEvent) {
Kleo::selectLabelText(this);
}
}
}
......
......@@ -27,6 +27,8 @@ public:
explicit HtmlLabel(const QString &html, QWidget *parent = nullptr);
~HtmlLabel() override;
void setSelectTextOnFocus(bool select);
void setHtml(const QString &html);
void setLinkColor(const QColor &color);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment