modernize: Use override instead of virtual
[quassel.git] / src / uisupport / styledlabel.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #pragma once
22
23 #include "uisupport-export.h"
24
25 #include <QFrame>
26
27 #include "clickable.h"
28 #include "uistyle.h"
29
30 class UISUPPORT_EXPORT StyledLabel : public QFrame
31 {
32     Q_OBJECT
33
34 public:
35     enum ResizeMode {
36         NoResize,
37         DynamicResize,
38         ResizeOnHover
39     };
40
41     StyledLabel(QWidget *parent = nullptr);
42
43     void setText(const QString &text);
44     void setCustomFont(const QFont &font);
45
46     QSize sizeHint() const override;
47     //virtual QSize minimumSizeHint() const;
48
49     inline QTextOption::WrapMode wrapMode() const { return _wrapMode; }
50     void setWrapMode(QTextOption::WrapMode mode);
51
52     inline Qt::Alignment alignment() const { return _alignment; }
53     void setAlignment(Qt::Alignment alignment);
54
55     inline bool toolTipEnabled() const { return _toolTipEnabled; }
56     void setToolTipEnabled(bool);
57
58     inline ResizeMode resizeMode() const { return _resizeMode; }
59     void setResizeMode(ResizeMode);
60
61 signals:
62     void clickableActivated(const Clickable &click);
63
64 protected:
65     void paintEvent(QPaintEvent *event) override;
66     void resizeEvent(QResizeEvent *event) override;
67     void enterEvent(QEvent *) override;
68     void leaveEvent(QEvent *) override;
69     void mouseMoveEvent(QMouseEvent *event) override;
70     void mousePressEvent(QMouseEvent *event) override;
71
72     int posToCursor(const QPointF &pos);
73
74 private:
75     QSize _sizeHint;
76     QTextOption::WrapMode _wrapMode;
77     Qt::Alignment _alignment;
78     QTextLayout _layout;
79     ClickableList _clickables;
80     bool _toolTipEnabled;
81     ResizeMode _resizeMode;
82
83     QList<QTextLayout::FormatRange> _layoutList;
84     QVector<QTextLayout::FormatRange> _extraLayoutList;
85
86     void layout();
87     void updateSizeHint();
88     void updateToolTip();
89
90     void setHoverMode(int start, int length);
91     void endHoverMode();
92 };