Page MenuHome GnuPG

No OneTemporary

diff --git a/src/view/urllabel.cpp b/src/view/urllabel.cpp
index 5ba8569ea..80851ba81 100644
--- a/src/view/urllabel.cpp
+++ b/src/view/urllabel.cpp
@@ -1,99 +1,49 @@
/*
view/urllabel.cpp
This file is part of Kleopatra, the KDE keymanager
- SPDX-FileCopyrightText: 2021 g10 Code GmbH
+ SPDX-FileCopyrightText: 2021, 2022 g10 Code GmbH
SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <config-kleopatra.h>
#include "urllabel.h"
-#include <QAccessible>
-#include <QPalette>
+#include <QUrl>
using namespace Kleo;
-class UrlLabel::Private
-{
- UrlLabel *q;
-public:
- Private(UrlLabel *q) : q{q} {}
-
- void ensureLinkColorIsValid();
- void updateLabel();
-
- QUrl url;
- QString text;
- QColor linkColor;
-};
-
-void UrlLabel::Private::ensureLinkColorIsValid()
+UrlLabel::UrlLabel(QWidget *parent)
+ : HtmlLabel{parent}
{
- if (!linkColor.isValid()) {
- linkColor = q->palette().link().color();
- }
}
-void UrlLabel::Private::updateLabel()
+UrlLabel::~UrlLabel() = default;
+
+void UrlLabel::setUrl(const QUrl &url, const QString &text)
{
// we prepend a zero-width-space character to work around a bug in QLabel::focusNextPrevChild(false)
// which makes it impossible to leave the label with Shift+Tab if the text starts with a link
- static const QString templateString{QLatin1String{"&#8203;<a style=\"color: %1;\" href=\"%2\">%3</a>"}};
+ static const QString templateString{QLatin1String{"&#8203;<a href=\"%1\">%2</a>"}};
if (url.isEmpty()) {
- q->clear();
+ HtmlLabel::setHtml({});
return;
}
- ensureLinkColorIsValid();
- q->setText(templateString.arg(
- linkColor.name(),
+ setHtml(templateString.arg(
url.url(QUrl::FullyEncoded),
text.isEmpty() ? url.toDisplayString().toHtmlEscaped() : text.toHtmlEscaped()));
}
-UrlLabel::UrlLabel(QWidget *parent)
- : QLabel{parent}
- , d{new Private{this}}
-{
- setTextFormat(Qt::RichText);
- setTextInteractionFlags(Qt::TextBrowserInteraction);
-}
-
-UrlLabel::~UrlLabel() = default;
-
-void UrlLabel::setUrl(const QUrl &url, const QString &text)
-{
- d->url = url;
- d->text = text;
- d->updateLabel();
-}
-
-void UrlLabel::setLinkColor(const QColor &color)
-{
- d->linkColor = color;
- d->updateLabel();
-}
-
void UrlLabel::focusInEvent(QFocusEvent *event)
{
// immediately focus the URL when the label get focus
QLabel::focusInEvent(event);
if (!hasSelectedText()) {
focusNextPrevChild(true);
}
}
-
-bool UrlLabel::focusNextPrevChild(bool next)
-{
- const bool result = QLabel::focusNextPrevChild(next);
- if (hasFocus() && hasSelectedText()) {
- QAccessibleTextSelectionEvent ev(this, selectionStart(), selectionStart() + selectedText().size());
- QAccessible::updateAccessibility(&ev);
- }
- return result;
-}
diff --git a/src/view/urllabel.h b/src/view/urllabel.h
index 2b0f188d8..54ce11281 100644
--- a/src/view/urllabel.h
+++ b/src/view/urllabel.h
@@ -1,43 +1,36 @@
/*
view/urllabel.h
This file is part of Kleopatra, the KDE keymanager
- SPDX-FileCopyrightText: 2021 g10 Code GmbH
+ SPDX-FileCopyrightText: 2021, 2022 g10 Code GmbH
SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
-#include <QLabel>
+#include "htmllabel.h"
#include <memory>
namespace Kleo
{
-class UrlLabel : public QLabel
+class UrlLabel : public HtmlLabel
{
Q_OBJECT
public:
explicit UrlLabel(QWidget *parent = nullptr);
~UrlLabel() override;
void setUrl(const QUrl &url, const QString &text = {});
- void setLinkColor(const QColor &color);
-
protected:
void focusInEvent(QFocusEvent *event) override;
- bool focusNextPrevChild(bool next) override;
-
-private:
- using QLabel::setText;
private:
- class Private;
- std::unique_ptr<Private> d;
+ using HtmlLabel::setHtml;
};
}

File Metadata

Mime Type
text/x-diff
Expires
Mon, Dec 23, 3:34 PM (1 d, 1 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
bb/8d/fe944ddce5ba6efc2f838d62587f

Event Timeline