X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=gui%2Fbuffer.cpp;h=751da803b8cf19799fb53b1a3c2b4d1e3ea44c19;hp=3892ee95b08af767d8403e315d5bd23169a2145b;hb=12369966345e76e3bba92f64c84c940ef4d8d916;hpb=3e7ed151306ef44a9be5ca7e3f37c89408d4a6d1 diff --git a/gui/buffer.cpp b/gui/buffer.cpp index 3892ee95..751da803 100644 --- a/gui/buffer.cpp +++ b/gui/buffer.cpp @@ -20,17 +20,21 @@ #include "buffer.h" #include "util.h" +#include "chatwidget.h" Buffer::Buffer(QString netname, QString bufname) { networkName = netname; bufferName = bufname; widget = 0; + chatWidget = 0; + contentsWidget = 0; active = false; } Buffer::~Buffer() { delete widget; + delete chatWidget; } void Buffer::setActive(bool a) { @@ -49,21 +53,30 @@ void Buffer::userInput(QString msg) { emit userInput(networkName, bufferName, msg); } +/* FIXME do we need this? */ void Buffer::scrollToEnd() { if(!widget) return; - widget->scrollToEnd(); + //widget->scrollToEnd(); } QWidget * Buffer::showWidget(QWidget *parent) { + if(widget) { - widget->scrollToEnd(); return qobject_cast(widget); } - widget = new BufferWidget(networkName, bufferName, isActive(), ownNick, contents, parent); + + if(!contentsWidget) { + contentsWidget = new ChatWidgetContents(networkName, bufferName, 0); + contentsWidget->hide(); + /* FIXME do we need this? */ + for(int i = 0; i < contents.count(); i++) { + contentsWidget->appendMsg(contents[i]); + } + } + contentsWidget->hide(); + widget = new BufferWidget(networkName, bufferName, isActive(), ownNick, contentsWidget, this, parent); widget->setTopic(topic); widget->updateNickList(nicks); - //widget->renderContents(); - //widget->scrollToEnd(); connect(widget, SIGNAL(userInput(QString)), this, SLOT(userInput(QString))); return qobject_cast(widget); } @@ -73,6 +86,10 @@ void Buffer::hideWidget() { widget = 0; } +void Buffer::deleteWidget() { + widget = 0; +} + QWidget * Buffer::getWidget() { return qobject_cast(widget); } @@ -112,12 +129,19 @@ void Buffer::setOwnNick(QString nick) { /****************************************************************************************/ -BufferWidget::BufferWidget(QString netname, QString bufname, bool act, QString own, QList cont, QWidget *parent) : QWidget(parent) { + + +/****************************************************************************************/ + +BufferWidget::BufferWidget(QString netname, QString bufname, bool act, QString own, ChatWidgetContents *contents, Buffer *pBuf, QWidget *parent) : QWidget(parent) { ui.setupUi(this); networkName = netname; bufferName = bufname; active = act; - contents = cont; + parentBuffer = pBuf; + + ui.chatWidget->init(netname, bufname, contents); + ui.ownNick->clear(); ui.ownNick->addItem(own); if(bufname.isEmpty()) { @@ -130,30 +154,15 @@ BufferWidget::BufferWidget(QString netname, QString bufname, bool act, QString o connect(ui.nickTree, SIGNAL(itemCollapsed(QTreeWidgetItem *)), this, SLOT(itemExpansionChanged(QTreeWidgetItem*))); connect(ui.inputEdit, SIGNAL(returnPressed()), this, SLOT(enterPressed())); - ui.chatWidget->setFocusProxy(ui.inputEdit); - ui.chatWidget->setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); - opsExpanded = voicedExpanded = usersExpanded = true; - // Define standard colors - stdCol = "black"; - inactiveCol = "grey"; - noticeCol = "darkblue"; - serverCol = "darkblue"; - errorCol = "red"; - joinCol = "green"; - quitCol = "firebrick"; - partCol = "firebrick"; - kickCol = "firebrick"; - nickCol = "magenta"; - - int i = contents.count() - 100; - if(i < 0) i = 0; - for(int j = 0; j < i; j++) contents.removeAt(0); - show(); - renderContents(); + ui.chatWidget->setFocusProxy(ui.inputEdit); updateTitle(); - //show(); +} + +BufferWidget::~BufferWidget() { + ui.chatWidget->takeWidget(); /* remove ownership so the chatwidget contents does not get destroyed */ + parentBuffer->deleteWidget(); /* make sure the parent buffer knows we are gone */ } void BufferWidget::updateTitle() { @@ -173,100 +182,13 @@ void BufferWidget::enterPressed() { void BufferWidget::setActive(bool act) { if(act != active) { active = act; - renderContents(); + //renderContents(); //scrollToEnd(); } } -void BufferWidget::renderContents() { - QString html; - //html = ""; - for(int i = 0; i < contents.count(); i++) { - html += htmlFromMsg(contents[i]); - } - //ui.chatWidget->clear(); - hide(); - ui.chatWidget->setHtml(html); show(); - //ui.chatWidget->insertHtml("
"); // <-- bug that would not reset the scrollbar sizes... - scrollToEnd(); -} - -void BufferWidget::scrollToEnd() { - QScrollBar *sb = ui.chatWidget->verticalScrollBar(); - sb->setValue(sb->maximum()); - //qDebug() << bufferName << "scrolled" << sb->value() << sb->maximum(); -} - -QString BufferWidget::htmlFromMsg(Message msg) { - QString s, n; - QString c = stdCol; - QString user = userFromMask(msg.sender); - QString host = hostFromMask(msg.sender); - QString nick = nickFromMask(msg.sender); - switch(msg.type) { - case Message::Plain: - c = stdCol; n = QString("<%1>").arg(nick); s = msg.text; - break; - case Message::Server: - c = serverCol; s = msg.text; - break; - case Message::Error: - c = errorCol; s = msg.text; - break; - case Message::Join: - c = joinCol; - s = QString(tr("--> %1 (%2@%3) has joined %4")).arg(nick).arg(user).arg(host).arg(bufferName); - break; - case Message::Part: - c = partCol; - s = QString(tr("<-- %1 (%2@%3) has left %4")).arg(nick).arg(user).arg(host).arg(bufferName); - if(!msg.text.isEmpty()) s = QString("%1 (%2)").arg(s).arg(msg.text); - break; - case Message::Kick: - { c = kickCol; - QString victim = msg.text.section(" ", 0, 0); - if(victim == ui.ownNick->currentText()) victim = tr("you"); - QString kickmsg = msg.text.section(" ", 1); - s = QString(tr("--> %1 has kicked %2 from %3")).arg(nick).arg(victim).arg(bufferName); - if(!kickmsg.isEmpty()) s = QString("%1 (%2)").arg(s).arg(kickmsg); - } - break; - case Message::Quit: - c = quitCol; - s = QString(tr("<-- %1 (%2@%3) has quit")).arg(nick).arg(user).arg(host); - if(!msg.text.isEmpty()) s = QString("%1 (%2)").arg(s).arg(msg.text); - break; - case Message::Nick: - c = nickCol; - if(nick == msg.text) s = QString(tr("<-> You are now known as %1")).arg(msg.text); - else s = QString(tr("<-> %1 is now known as %2")).arg(nick).arg(msg.text); - break; - case Message::Mode: - c = serverCol; - if(nick.isEmpty()) s = tr("*** User mode: %1").arg(msg.text); - else s = tr("*** Mode %1 by %2").arg(msg.text).arg(nick); - break; - default: - c = stdCol; n = QString("[%1]").arg(msg.sender); s = msg.text; - break; - } - if(!active) c = inactiveCol; - s.replace('&', "&"); s.replace('<', "<"); s.replace('>', ">"); - QString html = QString("" - "") - .arg(msg.timeStamp.toLocalTime().toString("hh:mm:ss")).arg("darkblue"); - if(!n.isEmpty()) - html += QString("") - .arg(n).arg("royalblue"); - html += QString("""
[%1]
%1
%1
").arg(s).arg(c); - return html; -} - void BufferWidget::displayMsg(Message msg) { - contents.append(msg); - ui.chatWidget->append(htmlFromMsg(msg)); + ui.chatWidget->appendMsg(msg); } void BufferWidget::setOwnNick(QString nick) {