Make URLs (and channel names!) in the topic widget clickable again
[quassel.git] / src / uisupport / styledlabel.h
1 /***************************************************************************
2  *   Copyright (C) 2005-09 by the Quassel Project                          *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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.                                           *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #ifndef STYLEDLABEL_H
22 #define STYLEDLABEL_H
23
24 #include <QFrame>
25
26 #include "clickable.h"
27 #include "uistyle.h"
28
29 class StyledLabel : public QFrame {
30   Q_OBJECT
31
32 public:
33   StyledLabel(QWidget *parent = 0);
34
35   void setText(const QString &text);
36
37   virtual QSize sizeHint() const;
38   //virtual QSize minimumSizeHint() const;
39
40   inline QTextOption::WrapMode wrapMode() const { return _wrapMode; }
41   void setWrapMode(QTextOption::WrapMode mode);
42
43   inline Qt::Alignment alignment() const { return _alignment; }
44   void setAlignment(Qt::Alignment alignment);
45
46   inline bool toolTipEnabled() const { return _toolTipEnabled; }
47   void setToolTipEnabled(bool);
48
49 signals:
50   void clickableActivated(const Clickable &click);
51
52 protected:
53   virtual void paintEvent(QPaintEvent *event);
54   virtual void resizeEvent(QResizeEvent *event);
55   virtual void leaveEvent(QEvent *);
56   virtual void mouseMoveEvent(QMouseEvent *event);
57   virtual void mousePressEvent(QMouseEvent *event);
58
59   int posToCursor(const QPointF &pos);
60
61 private:
62   QSize _sizeHint;
63   QTextOption::WrapMode _wrapMode;
64   Qt::Alignment _alignment;
65   QTextLayout _layout;
66   ClickableList _clickables;
67   bool _toolTipEnabled;
68
69   QList<QTextLayout::FormatRange> _layoutList;
70   QVector<QTextLayout::FormatRange> _extraLayoutList;
71
72   void layout();
73   void updateSizeHint();
74   void updateToolTip();
75
76   void setHoverMode(int start, int length);
77   void endHoverMode();
78 };
79
80 #endif