X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fstyledlabel.h;h=4fcbbc4d463590a391fb8ea238e749a131116bfb;hp=de412a871c24ea86f9a06bd7eac6203e128196b2;hb=cc6e7c08709c4e761e2fd9c2e322751015497003;hpb=6ce1966d5d3070ad461a976a2bee7cc28e8b9149 diff --git a/src/uisupport/styledlabel.h b/src/uisupport/styledlabel.h index de412a87..4fcbbc4d 100644 --- a/src/uisupport/styledlabel.h +++ b/src/uisupport/styledlabel.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-09 by the Quassel Project * + * Copyright (C) 2005-2019 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -15,66 +15,79 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef STYLEDLABEL_H -#define STYLEDLABEL_H +#pragma once + +#include "uisupport-export.h" #include #include "clickable.h" #include "uistyle.h" -class StyledLabel : public QFrame { - Q_OBJECT +class UISUPPORT_EXPORT StyledLabel : public QFrame +{ + Q_OBJECT public: - StyledLabel(QWidget *parent = 0); + enum ResizeMode + { + NoResize, + DynamicResize, + ResizeOnHover + }; + + StyledLabel(QWidget* parent = nullptr); - void setText(const QString &text); + void setText(const QString& text); + void setCustomFont(const QFont& font); - virtual QSize sizeHint() const; - //virtual QSize minimumSizeHint() const; + QSize sizeHint() const override; + // virtual QSize minimumSizeHint() const; - inline QTextOption::WrapMode wrapMode() const { return _wrapMode; } - void setWrapMode(QTextOption::WrapMode mode); + inline QTextOption::WrapMode wrapMode() const { return _wrapMode; } + void setWrapMode(QTextOption::WrapMode mode); - inline Qt::Alignment alignment() const { return _alignment; } - void setAlignment(Qt::Alignment alignment); + inline Qt::Alignment alignment() const { return _alignment; } + void setAlignment(Qt::Alignment alignment); - inline bool toolTipEnabled() const { return _toolTipEnabled; } - void setToolTipEnabled(bool); + inline bool toolTipEnabled() const { return _toolTipEnabled; } + void setToolTipEnabled(bool); + + inline ResizeMode resizeMode() const { return _resizeMode; } + void setResizeMode(ResizeMode); signals: - void clickableActivated(const Clickable &click); + void clickableActivated(const Clickable& click); protected: - virtual void paintEvent(QPaintEvent *event); - virtual void resizeEvent(QResizeEvent *event); - virtual void leaveEvent(QEvent *); - virtual void mouseMoveEvent(QMouseEvent *event); - virtual void mousePressEvent(QMouseEvent *event); + void paintEvent(QPaintEvent* event) override; + void resizeEvent(QResizeEvent* event) override; + void enterEvent(QEvent*) override; + void leaveEvent(QEvent*) override; + void mouseMoveEvent(QMouseEvent* event) override; + void mousePressEvent(QMouseEvent* event) override; - int posToCursor(const QPointF &pos); + int posToCursor(const QPointF& pos); private: - QSize _sizeHint; - QTextOption::WrapMode _wrapMode; - Qt::Alignment _alignment; - QTextLayout _layout; - ClickableList _clickables; - bool _toolTipEnabled; - - QList _layoutList; - QVector _extraLayoutList; - - void layout(); - void updateSizeHint(); - void updateToolTip(); - - void setHoverMode(int start, int length); - void endHoverMode(); + QSize _sizeHint; + QTextOption::WrapMode _wrapMode{QTextOption::NoWrap}; + Qt::Alignment _alignment; + QTextLayout _layout; + ClickableList _clickables; + bool _toolTipEnabled{true}; + ResizeMode _resizeMode{NoResize}; + + QList _layoutList; + QVector _extraLayoutList; + + void layout(); + void updateSizeHint(); + void updateToolTip(); + + void setHoverMode(int start, int length); + void endHoverMode(); }; - -#endif