1 /***************************************************************************
2 * Copyright (C) 2005-2020 by the Quassel Project *
3 * devel@quassel-irc.org *
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. *
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. *
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 ***************************************************************************/
23 #include "uisupport-export.h"
27 #include "clickable.h"
30 class UISUPPORT_EXPORT StyledLabel : public QFrame
42 StyledLabel(QWidget* parent = nullptr);
44 void setText(const QString& text);
45 void setCustomFont(const QFont& font);
47 QSize sizeHint() const override;
48 // virtual QSize minimumSizeHint() const;
50 inline QTextOption::WrapMode wrapMode() const { return _wrapMode; }
51 void setWrapMode(QTextOption::WrapMode mode);
53 inline Qt::Alignment alignment() const { return _alignment; }
54 void setAlignment(Qt::Alignment alignment);
56 inline bool toolTipEnabled() const { return _toolTipEnabled; }
57 void setToolTipEnabled(bool);
59 inline ResizeMode resizeMode() const { return _resizeMode; }
60 void setResizeMode(ResizeMode);
63 void clickableActivated(const Clickable& click);
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;
73 int posToCursor(const QPointF& pos);
77 QTextOption::WrapMode _wrapMode{QTextOption::NoWrap};
78 Qt::Alignment _alignment;
80 ClickableList _clickables;
81 bool _toolTipEnabled{true};
82 ResizeMode _resizeMode{NoResize};
84 QList<QTextLayout::FormatRange> _layoutList;
85 QVector<QTextLayout::FormatRange> _extraLayoutList;
88 void updateSizeHint();
91 void setHoverMode(int start, int length);