summary refs log tree commit diff
path: root/src/ui/TextLabel.h
blob: 313ad97cc1efe82ccd12bf455e02a2d86db7ff56 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later

#pragma once

#include <QSize>
#include <QString>
#include <QTextBrowser>
#include <QUrl>

class QMouseEvent;
class QFocusEvent;
class QWheelEvent;

class ContextMenuFilter : public QObject
{
    Q_OBJECT

public:
    explicit ContextMenuFilter(QWidget *parent)
      : QObject(parent)
    {}

signals:
    void contextMenuIsOpening();

protected:
    bool eventFilter(QObject *obj, QEvent *event) override;
};

class TextLabel : public QTextBrowser
{
    Q_OBJECT

public:
    TextLabel(const QString &text, QWidget *parent = nullptr);
    TextLabel(QWidget *parent = nullptr);

    void wheelEvent(QWheelEvent *event) override;
    void clearLinks() { link_.clear(); }

protected:
    void mousePressEvent(QMouseEvent *e) override;
    void mouseReleaseEvent(QMouseEvent *e) override;
    void focusOutEvent(QFocusEvent *e) override;

private slots:
    void adjustHeight(const QSizeF &size) { setFixedHeight(size.height()); }
    void handleLinkActivation(const QUrl &link);

signals:
    void userProfileTriggered(const QString &user_id);
    void linkActivated(const QUrl &link);

private:
    QString link_;
    bool contextMenuRequested_ = false;
};