1 /***************************************************************************
2 * Copyright (C) 2005-08 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 ***************************************************************************/
23 #include "chatwidget.h"
25 ChatWidget::ChatWidget(QWidget *parent) : QTextEdit(parent), AbstractChatView() {
26 setStyleSheet("background-color: rgba(255, 255, 255, 60%)");
27 setTextInteractionFlags(Qt::TextBrowserInteraction);
30 void ChatWidget::setContents(const QList<AbstractUiMsg *> &lines) {
32 QList<ChatLine *> list;
33 foreach(AbstractUiMsg *msg, lines) list << static_cast<ChatLine*>(msg);
34 appendChatLines(list);
38 void ChatWidget::prependMsg(AbstractUiMsg *msg) {
39 ChatLine *line = static_cast<ChatLine*>(msg);
41 prependChatLine(line);
44 void ChatWidget::appendMsg(AbstractUiMsg *msg) {
45 ChatLine *line = static_cast<ChatLine*>(msg);
50 void ChatWidget::appendChatLine(ChatLine *line) {
51 QTextCursor cursor = textCursor();
52 moveCursor(QTextCursor::End);
53 if(!document()->isEmpty()) insertPlainText("\n");
54 insertStyledText(line->styledSender());
56 insertStyledText(line->styledText());
57 setTextCursor(cursor);
60 void ChatWidget::appendChatLines(QList<ChatLine *> list) {
61 foreach(ChatLine *line, list) {
66 void ChatWidget::prependChatLine(ChatLine *line) {
67 QTextCursor cursor = textCursor();
68 moveCursor(QTextCursor::Start);
69 bool flg = document()->isEmpty();
70 insertStyledText(line->styledSender());
72 insertStyledText(line->styledText());
73 if(!flg) insertPlainText("\n");
74 setTextCursor(cursor);
77 void ChatWidget::prependChatLines(QList<ChatLine *> list) {
78 foreach(ChatLine *line, list) {
79 prependChatLine(line);
83 void ChatWidget::insertChatLine(ChatLine *line) {
84 if(!document()->isEmpty()) insertPlainText("\n");
85 insertStyledText(line->styledSender());
87 insertStyledText(line->styledText());
90 void ChatWidget::insertStyledText(const QtopiaUiStyle::StyledText &stext) {
91 QTextCursor cursor = textCursor();
92 foreach(QTextLayout::FormatRange format, stext.formats) {
93 cursor.setCharFormat(format.format);
94 setTextCursor(cursor);
95 insertPlainText(stext.text.mid(format.start, format.length));