1 /***************************************************************************
2 * Copyright (C) 2005-2018 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
41 StyledLabel(QWidget *parent = nullptr);
43 void setText(const QString &text);
44 void setCustomFont(const QFont &font);
46 QSize sizeHint() const override;
47 //virtual QSize minimumSizeHint() const;
49 inline QTextOption::WrapMode wrapMode() const { return _wrapMode; }
50 void setWrapMode(QTextOption::WrapMode mode);
52 inline Qt::Alignment alignment() const { return _alignment; }
53 void setAlignment(Qt::Alignment alignment);
55 inline bool toolTipEnabled() const { return _toolTipEnabled; }
56 void setToolTipEnabled(bool);
58 inline ResizeMode resizeMode() const { return _resizeMode; }
59 void setResizeMode(ResizeMode);
62 void clickableActivated(const Clickable &click);
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;
72 int posToCursor(const QPointF &pos);
76 QTextOption::WrapMode _wrapMode{QTextOption::NoWrap};
77 Qt::Alignment _alignment;
79 ClickableList _clickables;
80 bool _toolTipEnabled{true};
81 ResizeMode _resizeMode{NoResize};
83 QList<QTextLayout::FormatRange> _layoutList;
84 QVector<QTextLayout::FormatRange> _extraLayoutList;
87 void updateSizeHint();
90 void setHoverMode(int start, int length);