X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fstyledlabel.h;h=4fcbbc4d463590a391fb8ea238e749a131116bfb;hp=4eefb6a0c146eb0b48a3fe89674b768f844d6ebe;hb=cc6e7c08709c4e761e2fd9c2e322751015497003;hpb=148964099b6e799121402d297c854393f9988be8 diff --git a/src/uisupport/styledlabel.h b/src/uisupport/styledlabel.h index 4eefb6a0..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,57 +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 + }; - void setText(const QString &text); + StyledLabel(QWidget* parent = nullptr); - virtual QSize sizeHint() const; - //virtual QSize minimumSizeHint() const; + void setText(const QString& text); + void setCustomFont(const QFont& font); - inline QTextOption::WrapMode wrapMode() const { return _wrapMode; } - void setWrapMode(QTextOption::WrapMode mode); + QSize sizeHint() const override; + // virtual QSize minimumSizeHint() const; - inline Qt::Alignment alignment() const { return _alignment; } - void setAlignment(Qt::Alignment alignment); + inline QTextOption::WrapMode wrapMode() const { return _wrapMode; } + void setWrapMode(QTextOption::WrapMode mode); - inline bool toolTipEnabled() const { return _toolTipEnabled; } - void setToolTipEnabled(bool); + inline Qt::Alignment alignment() const { return _alignment; } + void setAlignment(Qt::Alignment alignment); -protected: - virtual void paintEvent(QPaintEvent *event); - virtual void resizeEvent(QResizeEvent *event); + inline bool toolTipEnabled() const { return _toolTipEnabled; } + void setToolTipEnabled(bool); - //void mouseMoveEvent(QMouseEvent *event); - //void mousePressEvent(QMouseEvent *event); - //void mouseReleaseEvent(QMouseEvent *event); - //void mouseDoubleClickEvent(QMouseEvent *event); + inline ResizeMode resizeMode() const { return _resizeMode; } + void setResizeMode(ResizeMode); -private: - QSize _sizeHint; - QTextOption::WrapMode _wrapMode; - Qt::Alignment _alignment; - QTextLayout _layout; - bool _toolTipEnabled; +signals: + void clickableActivated(const Clickable& click); - QList _layoutList; +protected: + 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; - void layout(); - void updateSizeHint(); - void updateToolTip(); -}; + int posToCursor(const QPointF& pos); -#endif +private: + 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(); +};