cmake: Add missing Boost dependency
[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     {
37         NoResize,
38         DynamicResize,
39         ResizeOnHover
40     };
41
42     StyledLabel(QWidget* parent = nullptr);
43
44     void setText(const QString& text);
45     void setCustomFont(const QFont& font);
46
47     QSize sizeHint() const override;
48     // virtual QSize minimumSizeHint() const;
49
50     inline QTextOption::WrapMode wrapMode() const { return _wrapMode; }
51     void setWrapMode(QTextOption::WrapMode mode);
52
53     inline Qt::Alignment alignment() const { return _alignment; }
54     void setAlignment(Qt::Alignment alignment);
55
56     inline bool toolTipEnabled() const { return _toolTipEnabled; }
57     void setToolTipEnabled(bool);
58
59     inline ResizeMode resizeMode() const { return _resizeMode; }
60     void setResizeMode(ResizeMode);
61
62 signals:
63     void clickableActivated(const Clickable& click);
64
65 protected:
66     void paintEvent(QPaintEvent* event) override;
67     void resizeEvent(QResizeEvent* event) override;
68     void enterEvent(QEvent*) override;
69     void leaveEvent(QEvent*) override;
70     void mouseMoveEvent(QMouseEvent* event) override;
71     void mousePressEvent(QMouseEvent* event) override;
72
73     int posToCursor(const QPointF& pos);
74
75 private:
76     QSize _sizeHint;
77     QTextOption::WrapMode _wrapMode{QTextOption::NoWrap};
78     Qt::Alignment _alignment;
79     QTextLayout _layout;
80     ClickableList _clickables;
81     bool _toolTipEnabled{true};
82     ResizeMode _resizeMode{NoResize};
83
84     QList<QTextLayout::FormatRange> _layoutList;
85     QVector<QTextLayout::FormatRange> _extraLayoutList;
86
87     void layout();
88     void updateSizeHint();
89     void updateToolTip();
90
91     void setHoverMode(int start, int length);
92     void endHoverMode();
93 };