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) {
26 setStyleSheet("background-color: rgba(255, 255, 255, 60%)");
27 setTextInteractionFlags(Qt::TextBrowserInteraction);
30 void ChatWidget::setContents(QList<ChatLine *> lines) {
32 appendChatLines(lines);
36 void ChatWidget::prependMsg(AbstractUiMsg *msg) {
37 ChatLine *line = static_cast<ChatLine*>(msg);
39 prependChatLine(line);
42 void ChatWidget::appendMsg(AbstractUiMsg *msg) {
43 ChatLine *line = static_cast<ChatLine*>(msg);
48 void ChatWidget::appendChatLine(ChatLine *line) {
49 QTextCursor cursor = textCursor();
50 moveCursor(QTextCursor::End);
51 if(!document()->isEmpty()) insertPlainText("\n");
52 insertStyledText(line->styledSender());
54 insertStyledText(line->styledText());
55 setTextCursor(cursor);
58 void ChatWidget::appendChatLines(QList<ChatLine *> list) {
59 foreach(ChatLine *line, list) {
64 void ChatWidget::prependChatLine(ChatLine *line) {
65 QTextCursor cursor = textCursor();
66 moveCursor(QTextCursor::Start);
67 bool flg = document()->isEmpty();
68 insertStyledText(line->styledSender());
70 insertStyledText(line->styledText());
71 if(!flg) insertPlainText("\n");
72 setTextCursor(cursor);
75 void ChatWidget::prependChatLines(QList<ChatLine *> list) {
76 foreach(ChatLine *line, list) {
77 prependChatLine(line);
81 void ChatWidget::insertChatLine(ChatLine *line) {
82 if(!document()->isEmpty()) insertPlainText("\n");
83 insertStyledText(line->styledSender());
85 insertStyledText(line->styledText());
88 void ChatWidget::insertStyledText(const QtopiaUiStyle::StyledText &stext) {
89 QTextCursor cursor = textCursor();
90 foreach(QTextLayout::FormatRange format, stext.formats) {
91 cursor.setCharFormat(format.format);
92 setTextCursor(cursor);
93 insertPlainText(stext.text.mid(format.start, format.length));