Fixed restore-to-defaults in settings dialog.
[quassel.git] / src / qtui / chatwidget.h
1 /***************************************************************************
2  *   Copyright (C) 2005/06 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 _CHATWIDGET_H_
22 #define _CHATWIDGET_H_
23
24 #include <QtGui>
25
26 #include "types.h"
27
28 class ChatLine;
29 class AbstractUiMsg;
30
31 //!\brief Scroll area showing part of the chat messages for a given buffer.
32 /** The contents of the scroll area, i.e. a widget of type ChatWidgetContents,
33  * needs to be provided by calling init(). We don't create this widget ourselves, because
34  * while a ChatWidget will be destroyed and recreated quite often (for example when switching
35  * buffers), there ususally is no need to re-render its content every time (which can be time-consuming).
36  * Before a ChatWidget is destroyed, it gives up its ownership of its contents, referring responsibility
37  * back to where it came from.
38  *
39  * Because we use this as a custom widget in Qt Designer, we cannot use a constructor that takes custom
40  * parameters. Instead, it is mandatory to call init() before using this widget.
41  */
42 class ChatWidget : public QAbstractScrollArea {
43   Q_OBJECT
44
45   public:
46     ChatWidget(QWidget *parent = 0);
47     ~ChatWidget();
48     void init(BufferId id);
49
50     virtual QSize minimumSizeHint() const;
51   //    virtual QSize sizeHint() const;
52
53   public slots:
54     void clear();
55
56     void prependMsg(AbstractUiMsg *);
57     void appendMsg(AbstractUiMsg *);
58
59     void prependChatLine(ChatLine *);
60     void appendChatLine(ChatLine *);
61     void prependChatLines(QList<ChatLine *>);
62     void appendChatLines(QList<ChatLine *>);
63     void setContents(QList<ChatLine *>);
64
65   protected:
66     virtual void resizeEvent(QResizeEvent *event);
67     virtual void paintEvent(QPaintEvent * event);
68     virtual void mousePressEvent(QMouseEvent *event);
69     virtual void mouseReleaseEvent(QMouseEvent *event);
70     virtual void mouseMoveEvent(QMouseEvent *event);
71     virtual void mouseDoubleClickEvent(QMouseEvent *event);
72
73   private slots:
74     void layout();
75     void scrollBarAction(int);
76     void scrollBarValChanged(int);
77     void ensureVisible(int line);
78     void handleScrollTimer();
79
80   private:
81     BufferId bufferId;
82     enum SelectionMode { NoSelection, TextSelected, LinesSelected };
83     enum MouseMode { Normal, Pressed, DragTsSep, DragTextSep, MarkText, MarkLines };
84     enum MousePos { None, OverTsSep, OverTextSep, OverUrl };
85     MouseMode mouseMode;
86     MousePos mousePos;
87     QPoint dragStartPos;
88     MouseMode dragStartMode;
89     int dragStartLine;
90     int dragStartCursor;
91     int curCursor;
92     int curLine;
93     SelectionMode selectionMode;
94     int selectionStart, selectionEnd, selectionLine;
95
96     int bottomLine, bottomLineOffset;
97
98     QList<ChatLine *> lines;
99     QList<qreal> ycoords;
100     QTimer *scrollTimer;
101     QPoint pointerPosition;
102
103     int senderX;
104     int textX;
105     int tsWidth;
106     int senderWidth;
107     int textWidth;
108     int tsGrabPos;     ///< X-Position for changing the timestamp width
109     int senderGrabPos;
110     void computePositions();
111
112     int width;
113     qreal height;
114     qreal y;
115
116     void adjustScrollBar();
117
118     int yToLineIdx(qreal y);
119     void clearSelection();
120     QString selectionToString();
121     void handleMouseMoveEvent(const QPoint &pos);
122
123 };
124
125 #endif