/* Copyright 2003 Rikard Björklind, Mikael Gransell This file is part of dc-qt. dc-qt is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. dc-qt is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with dc-qt; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include "dc_settings.h" #include "chatwdgt.h" #include "chatedit.h" ChatWdgt::ChatWdgt(bool priv,QWidget *parent,const char *name) : QWidget(parent,name) { is_priv = priv; QGridLayout *layout = new QGridLayout(this,2,3); chatText = new QTextEdit(this, "chat text"); chatText->setTextFormat( is_priv ? PlainText : RichText ); chatText->setReadOnly( true ); chatText->viewport()->setFocus(); if (is_priv) chatEdit = new QLineEdit(this, "priv chat edit"); else { chatEdit = (QLineEdit*) new ChatEdit(this, "pub chat edit"); connect( chatEdit, SIGNAL( messageStr(const QString &) ), this, SLOT( addChatStr(const QString &) ) ); } QLabel *laban = new QLabel("Chat:",this,"chatlabel"); connect( chatEdit, SIGNAL( returnPressed() ), this, SLOT( handleReturn() ) ); // QPushButton *btn = new QPushButton("X",this,"CloseButton"); // connect( btn, SIGNAL(pressed()), this, SLOT( emitClose() ) ); // if( !priv ) btn->setDisabled(true); // btn->setFlat(true); layout->addMultiCellWidget( chatText,0,0,0,2 ); layout->addWidget( laban, 1,0); layout->addWidget( chatEdit, 1,1); //layout->addWidget( btn, 1,2); } void ChatWdgt::addChatStr(const QString& str) { bool show_timestamp = (settings.get_setting("chat_timestamp") == "true"); QString ts(""); //timestamp if (show_timestamp) { if (is_priv) ts = (QTime::currentTime()).toString(QString("[hh:mm] ")); else ts = (QTime::currentTime()).toString(QString("[hh:mm] ")); } if (is_priv) { chatText->append(ts + str); } else { bool nick_highlight = (settings.get_setting("nick_highlight") == "true"); QString hl_on(""), hl_off(""); //highlight QString usr(""); //user nick QString msg(""); //message int i = str.find('>', 0) + 1; int j = str.find(' ', 0) + 1; if (i==0 || i>j) { // this is a user "emote" or a list of possible nick completions i = j-1; //str.find(' ', 0); } usr = QString("%1 ").arg((QStyleSheet::escape(str.left(i))).leftJustify(12, ' ')); msg = QStyleSheet::escape(str.right(str.length() - (i+1))); if (settings.get_setting("nick").length()>3 && msg.contains(settings.get_setting("nick"))>0) { if (nick_highlight) { hl_on = QString(""); hl_off = QString(""); } // move the nick of the person who talked to this user last to the front of the list ((ChatEdit*)chatEdit)->moveCompletionToFront( usr ); } chatText->append(ts+hl_on+""+usr+""+hl_off+msg); } } void ChatWdgt::handleReturn() { emit newChatStr( chatEdit->text(), this ); chatEdit->clear(); } void ChatWdgt::emitClose() { emit close(this); } bool ChatWdgt::is_private() { return is_priv; }