1 /***************************************************************************
2 * Copyright (C) 2005/06 by The Quassel Team *
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) any later version. *
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_
25 //#include "message.h"
33 //!\brief Scroll area showing part of the chat messages for a given buffer.
34 /** The contents of the scroll area, i.e. a widget of type ChatWidgetContents,
35 * needs to be provided by calling init(). We don't create this widget ourselves, because
36 * while a ChatWidget will be destroyed and recreated quite often (for example when switching
37 * buffers), there ususally is no need to re-render its content every time (which can be time-consuming).
38 * Before a ChatWidget is destroyed, it gives up its ownership of its contents, referring responsibility
39 * back to where it came from.
41 * Because we use this as a custom widget in Qt Designer, we cannot use a constructor that takes custom
42 * parameters. Instead, it is mandatory to call init() before using this widget.
44 class ChatWidget : public QAbstractScrollArea {
48 ChatWidget(QWidget *parent = 0);
50 void init(QString net, QString buf);
52 virtual QSize sizeHint() const;
57 void prependMsg(AbstractUiMsg *);
58 void appendMsg(AbstractUiMsg *);
60 void prependChatLine(ChatLine *);
61 void appendChatLine(ChatLine *);
62 void prependChatLines(QList<ChatLine *>);
63 void appendChatLines(QList<ChatLine *>);
64 void setContents(QList<ChatLine *>);
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();
82 QString networkName, bufferName;
83 enum SelectionMode { NoSelection, TextSelected, LinesSelected };
84 enum MouseMode { Normal, Pressed, DragTsSep, DragTextSep, MarkText, MarkLines };
85 enum MousePos { None, OverTsSep, OverTextSep, OverUrl };
89 MouseMode dragStartMode;
94 SelectionMode selectionMode;
95 int selectionStart, selectionEnd, selectionLine;
97 int bottomLine, bottomLineOffset;
99 QList<ChatLine *> lines;
100 QList<qreal> ycoords;
102 QPoint pointerPosition;
109 int tsGrabPos; ///< X-Position for changing the timestamp width
111 void computePositions();
117 void adjustScrollBar();
119 int yToLineIdx(qreal y);
120 void clearSelection();
121 QString selectionToString();
122 void handleMouseMoveEvent(const QPoint &pos);