diff --git a/src/kexiutils/KexiLinkWidget.cpp b/src/kexiutils/KexiLinkWidget.cpp index 123d43399..f23f056f8 100644 --- a/src/kexiutils/KexiLinkWidget.cpp +++ b/src/kexiutils/KexiLinkWidget.cpp @@ -1,121 +1,142 @@ /* This file is part of the KDE project - Copyright (C) 2011 Jarosław Staniek + Copyright (C) 2011-2018 Jarosław Staniek This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "KexiLinkWidget.h" #include +#include #include class Q_DECL_HIDDEN KexiLinkWidget::Private { public: explicit Private(KexiLinkWidget* qq) : q(qq) { q->setFocusPolicy(Qt::StrongFocus); q->setTextFormat(Qt::RichText); updateColors(); } void updateColors() { KColorScheme scheme(q->palette().currentColorGroup()); linkColor = scheme.foreground(KColorScheme::LinkText).color(); } void updateText() { QString text; text = QString("%3") .arg(link).arg(linkColor.name()).arg(linkText); if (!format.isEmpty()) { text = QString(format).replace("%L", text); } q->setText(text); } KexiLinkWidget * const q; QString link; QString linkText; QString format; QColor linkColor; + QShortcut *shortcut = nullptr; }; KexiLinkWidget::KexiLinkWidget(QWidget* parent) : QLabel(parent), d(new Private(this)) { } KexiLinkWidget::KexiLinkWidget( const QString& link, const QString& linkText, QWidget* parent) : QLabel(parent), d(new Private(this)) { d->link = link; d->linkText = linkText; d->updateText(); } KexiLinkWidget::~KexiLinkWidget() { delete d; } QString KexiLinkWidget::link() const { return d->link; } void KexiLinkWidget::setLink(const QString& link) { d->link = link; d->updateText(); } QString KexiLinkWidget::linkText() const { return d->linkText; } void KexiLinkWidget::setLinkText(const QString& linkText) { d->linkText = linkText; d->updateText(); } QString KexiLinkWidget::format() const { return d->format; } void KexiLinkWidget::setFormat(const QString& format) { d->format = format; d->updateText(); } +void KexiLinkWidget::click() +{ + emit linkActivated(d->link); +} + +QKeySequence KexiLinkWidget::shortcut() const +{ + return d->shortcut ? d->shortcut->key() : QKeySequence(); +} + +void KexiLinkWidget::setShortcut(const QKeySequence &key) +{ + if (!d->shortcut) { + d->shortcut = new QShortcut(this); + connect(d->shortcut, &QShortcut::activatedAmbiguously, this, &KexiLinkWidget::click); + } + d->shortcut->setKey(key); +} + void KexiLinkWidget::changeEvent(QEvent* event) { switch (event->type()) { case QEvent::EnabledChange: case QEvent::PaletteChange: d->updateColors(); d->updateText(); break; default:; } QLabel::changeEvent(event); } diff --git a/src/kexiutils/KexiLinkWidget.h b/src/kexiutils/KexiLinkWidget.h index 83d280bd9..8d0f9f4c4 100644 --- a/src/kexiutils/KexiLinkWidget.h +++ b/src/kexiutils/KexiLinkWidget.h @@ -1,71 +1,79 @@ /* This file is part of the KDE project - Copyright (C) 2011 Jarosław Staniek + Copyright (C) 2011-2018 Jarosław Staniek This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KEXILINKWIDGET_H #define KEXILINKWIDGET_H #include "kexiutils_export.h" #include +class QKeySequence; + //! Link widget class KEXIUTILS_EXPORT KexiLinkWidget : public QLabel { Q_OBJECT Q_PROPERTY(QString link READ link WRITE setLink) Q_PROPERTY(QString linkText READ linkText WRITE setLinkText) Q_PROPERTY(QString format READ format WRITE setFormat) public: explicit KexiLinkWidget(QWidget* parent = 0); KexiLinkWidget(const QString& link, const QString& linkText, QWidget* parent = 0); virtual ~KexiLinkWidget(); QString link() const; QString linkText() const; QString format() const; + QKeySequence shortcut() const; + public Q_SLOTS: void setLink(const QString& link); void setLinkText(const QString& linkText); //! Sets format for the button. /*! Format defines user-visible text written around the link. Use "%L" as a placeholder for the link, e.g. when format is "‹ %L" and link text is "Back", the widget will show "‹ Back" where "Back" is a link. By default format is empty, what means only the link is displayed. */ void setFormat(const QString& format); + void click(); + + void setShortcut(const QKeySequence &key); + protected: virtual void changeEvent(QEvent* event); private: QString text() const { return QLabel::text(); } void setText(const QString& text) { QLabel::setText(text); } class Private; Private * const d; }; #endif