X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fstyledlabel.h;h=1a746085ff150834fb0e453aaa42b399c2a1867e;hp=de412a871c24ea86f9a06bd7eac6203e128196b2;hb=e8a39b4c3c92e193ab861a3fea84a261bb6fbd24;hpb=6ce1966d5d3070ad461a976a2bee7cc28e8b9149 diff --git a/src/uisupport/styledlabel.h b/src/uisupport/styledlabel.h index de412a87..1a746085 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-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -15,66 +15,78 @@ * 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; + Qt::Alignment _alignment; + QTextLayout _layout; + ClickableList _clickables; + bool _toolTipEnabled; + ResizeMode _resizeMode; + + QList _layoutList; + QVector _extraLayoutList; + + void layout(); + void updateSizeHint(); + void updateToolTip(); + + void setHoverMode(int start, int length); + void endHoverMode(); }; - -#endif