/***************************************************************************
- * Copyright (C) 2005-09 by the Quassel Project *
+ * Copyright (C) 2005-2022 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
* 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 <QFrame>
+#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<QTextLayout::FormatRange> _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<QTextLayout::FormatRange> _layoutList;
+ QVector<QTextLayout::FormatRange> _extraLayoutList;
+
+ void layout();
+ void updateSizeHint();
+ void updateToolTip();
+
+ void setHoverMode(int start, int length);
+ void endHoverMode();
+};