1
/***************************************************************************
2
* Copyright (C) 2005/06 by the Quassel Project *
3
* devel@quassel-irc.org *
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. *
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. *
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
***************************************************************************/
21
#ifndef _CHATWIDGET_H_
22
#define _CHATWIDGET_H_
26
#include "abstractbuffercontainer.h"
32
//!\brief Scroll area showing part of the chat messages for a given buffer.
33
/** The contents of the scroll area, i.e. a widget of type ChatWidgetContents,
34
* needs to be provided by calling init(). We don't create this widget ourselves, because
35
* while a ChatWidget will be destroyed and recreated quite often (for example when switching
36
* buffers), there ususally is no need to re-render its content every time (which can be time-consuming).
37
* Before a ChatWidget is destroyed, it gives up its ownership of its contents, referring responsibility
38
* back to where it came from.
40
* Because we use this as a custom widget in Qt Designer, we cannot use a constructor that takes custom
41
* parameters. Instead, it is mandatory to call init() before using this widget.
43
class ChatWidget : public QAbstractScrollArea, public AbstractChatView {
47
ChatWidget(BufferId, QWidget *parent = 0);
49
void init(BufferId id);
51
virtual QSize minimumSizeHint() const;
52
virtual QSize sizeHint() const;
57
void prependMsg(AbstractUiMsg *);
58
void appendMsg(AbstractUiMsg *);
60
void prependChatLine(ChatLineOld *);
61
void appendChatLine(ChatLineOld *);
62
void prependChatLines(QList<ChatLineOld *>);
63
void appendChatLines(QList<ChatLineOld *>);
64
void setContents(const QList<AbstractUiMsg *> &);
67
virtual void resizeEvent(QResizeEvent *event);
68
virtual void paintEvent(QPaintEvent * event);
69
virtual void mousePressEvent(QMouseEvent *event);
70
virtual void mouseReleaseEvent(QMouseEvent *event);
71
virtual void mouseMoveEvent(QMouseEvent *event);
72
virtual void mouseDoubleClickEvent(QMouseEvent *event);
76
void scrollBarAction(int);
77
void scrollBarValChanged(int);
78
void ensureVisible(int line);
79
void handleScrollTimer();
80
void viewportChanged(int newPos);
84
enum SelectionMode { NoSelection, TextSelected, LinesSelected };
85
enum MouseMode { Normal, Pressed, DragTsSep, DragTextSep, MarkText, MarkLines };
86
enum MousePos { None, OverTsSep, OverTextSep, OverUrl };
90
MouseMode dragStartMode;
95
SelectionMode selectionMode;
96
int selectionStart, selectionEnd, selectionLine;
98
int bottomLine, bottomLineOffset;
100
QList<ChatLineOld *> lines;
101
QList<qreal> ycoords;
103
QPoint pointerPosition;
110
int tsGrabPos; ///< X-Position for changing the timestamp width
112
void computePositions();
118
void adjustScrollBar();
120
int yToLineIdx(qreal y);
121
void clearSelection();
122
QString selectionToString();
123
void handleMouseMoveEvent(const QPoint &pos);
125
MsgId lastBacklogOffset;