2021-03-05 02:35:15 +03:00
|
|
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2018-09-26 15:17:14 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QSize>
|
|
|
|
#include <QString>
|
|
|
|
#include <QTextBrowser>
|
|
|
|
#include <QUrl>
|
|
|
|
|
|
|
|
class QMouseEvent;
|
|
|
|
class QFocusEvent;
|
|
|
|
class QWheelEvent;
|
|
|
|
|
2018-09-26 19:21:10 +03:00
|
|
|
class ContextMenuFilter : public QObject
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
Q_OBJECT
|
2018-09-26 19:21:10 +03:00
|
|
|
|
|
|
|
public:
|
2021-09-18 01:22:33 +03:00
|
|
|
explicit ContextMenuFilter(QWidget *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
{}
|
2018-09-26 19:21:10 +03:00
|
|
|
|
|
|
|
signals:
|
2021-09-18 01:22:33 +03:00
|
|
|
void contextMenuIsOpening();
|
2018-09-26 19:21:10 +03:00
|
|
|
|
|
|
|
protected:
|
2021-09-18 01:22:33 +03:00
|
|
|
bool eventFilter(QObject *obj, QEvent *event) override;
|
2018-09-26 19:21:10 +03:00
|
|
|
};
|
|
|
|
|
2018-09-26 15:17:14 +03:00
|
|
|
class TextLabel : public QTextBrowser
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
Q_OBJECT
|
2018-09-26 15:17:14 +03:00
|
|
|
|
|
|
|
public:
|
2021-09-18 01:22:33 +03:00
|
|
|
TextLabel(const QString &text, QWidget *parent = nullptr);
|
|
|
|
TextLabel(QWidget *parent = nullptr);
|
2018-09-26 15:17:14 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
void wheelEvent(QWheelEvent *event) override;
|
|
|
|
void clearLinks() { link_.clear(); }
|
2018-09-26 15:17:14 +03:00
|
|
|
|
|
|
|
protected:
|
2021-09-18 01:22:33 +03:00
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
|
|
|
void focusOutEvent(QFocusEvent *e) override;
|
2018-09-26 15:17:14 +03:00
|
|
|
|
|
|
|
private slots:
|
2021-09-18 01:22:33 +03:00
|
|
|
void adjustHeight(const QSizeF &size) { setFixedHeight(size.height()); }
|
|
|
|
void handleLinkActivation(const QUrl &link);
|
2018-09-26 15:17:14 +03:00
|
|
|
|
|
|
|
signals:
|
2021-09-18 01:22:33 +03:00
|
|
|
void userProfileTriggered(const QString &user_id);
|
|
|
|
void linkActivated(const QUrl &link);
|
2018-09-26 15:17:14 +03:00
|
|
|
|
|
|
|
private:
|
2021-09-18 01:22:33 +03:00
|
|
|
QString link_;
|
|
|
|
bool contextMenuRequested_ = false;
|
2018-09-26 15:17:14 +03:00
|
|
|
};
|