X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=gui%2Fchatwidget.cpp;h=51ab625c02935ba1b0e9ae13051e45697a47d2ca;hp=a3ab3add5e1110a4ffaa0686f87acdb7e57b42fd;hb=a72defa2957b67d05fb4fb3d18b1fb6755a5908c;hpb=9cbaab34158d0f2e77c18d6ac055582102812553 diff --git a/gui/chatwidget.cpp b/gui/chatwidget.cpp index a3ab3add..51ab625c 100644 --- a/gui/chatwidget.cpp +++ b/gui/chatwidget.cpp @@ -65,9 +65,9 @@ void ChatWidget::init(QString netname, QString bufname) { ChatWidget::~ChatWidget() { //qDebug() << "destroying chatwidget" << bufferName; - foreach(ChatLine *l, lines) { - delete l; - } + //foreach(ChatLine *l, lines) { + // delete l; + //} } QSize ChatWidget::sizeHint() const { @@ -140,6 +140,21 @@ void ChatWidget::clear() { //contents->clear(); } +void ChatWidget::prependChatLine(ChatLine *line) { + qreal h = line->layout(tsWidth, senderWidth, textWidth); + for(int i = 1; i < ycoords.count(); i++) ycoords[i] += h; + ycoords.insert(1, h); + lines.prepend(line); + height += h; + // Fix all variables containing line numbers + dragStartLine ++; + curLine ++; + selectionStart ++; selectionEnd ++; + adjustScrollBar(); + verticalScrollBar()->setValue(verticalScrollBar()->value() + (int)h); + viewport()->update(); +} + void ChatWidget::prependChatLines(QList clist) { QList tmpy; tmpy.append(0); qreal h = 0; @@ -152,11 +167,11 @@ void ChatWidget::prependChatLines(QList clist) { ycoords = tmpy + ycoords; lines = clist + lines; height += h; - /* Fix all variables containing line numbers */ + // Fix all variables containing line numbers int i = clist.count(); dragStartLine += i; curLine += i; - selectionStart += i; selectionEnd += i; selectionEnd += i; + selectionStart += i; selectionEnd += i; //? selectionEnd += i; //if(bottomLine >= 0) bottomLine += i; adjustScrollBar(); //verticalScrollBar()->setPageStep(viewport()->height()); @@ -166,8 +181,8 @@ void ChatWidget::prependChatLines(QList clist) { viewport()->update(); } -void ChatWidget::appendMsg(Message msg) { - ChatLine *line = new ChatLine(msg, networkName, bufferName); + +void ChatWidget::appendChatLine(ChatLine *line) { qreal h = line->layout(tsWidth, senderWidth, textWidth); ycoords.append(h + ycoords[ycoords.count() - 1]); height += h; @@ -178,9 +193,8 @@ void ChatWidget::appendMsg(Message msg) { viewport()->update(); } -void ChatWidget::appendMsgList(QList *list) { - foreach(Message msg, *list) { - ChatLine *line = new ChatLine(msg, networkName, bufferName); +void ChatWidget::appendChatLines(QList list) { + foreach(ChatLine *line, list) { qreal h = line->layout(tsWidth, senderWidth, textWidth); ycoords.append(h + ycoords[ycoords.count() - 1]); height += h; @@ -192,6 +206,14 @@ void ChatWidget::appendMsgList(QList *list) { viewport()->update(); } +void ChatWidget::setContents(QList list) { + ycoords.clear(); + ycoords.append(0); + height = 0; + lines.clear(); + appendChatLines(list); +} + //!\brief Computes the different x position vars for given tsWidth and senderWidth. void ChatWidget::computePositions() { senderX = tsWidth + Style::sepTsSender(); @@ -492,13 +514,13 @@ QString ChatWidget::selectionToString() { if(selectionMode == LinesSelected) { QString result; for(int l = selectionStart; l <= selectionEnd; l++) { - result += QString("[%1] %2 %3\n").arg(lines[l]->getTimeStamp().toLocalTime().toString("hh:mm:ss")) - .arg(lines[l]->getSender()).arg(lines[l]->getText()); + result += QString("[%1] %2 %3\n").arg(lines[l]->timeStamp().toLocalTime().toString("hh:mm:ss")) + .arg(lines[l]->sender()).arg(lines[l]->text()); } return result; } // selectionMode == TextSelected - return lines[selectionLine]->getText().mid(selectionStart, selectionEnd - selectionStart); + return lines[selectionLine]->text().mid(selectionStart, selectionEnd - selectionStart); } /************************************************************************************/ @@ -509,14 +531,13 @@ QString ChatWidget::selectionToString() { * \param net The network name * \param buf The buffer name */ -ChatLine::ChatLine(Message m, QString net, QString buf) : QObject() { +ChatLine::ChatLine(Message m) : QObject() { hght = 0; - networkName = net; - bufferName = buf; + //networkName = m.buffer.network(); + //bufferName = m.buffer.buffer(); msg = m; selectionMode = None; formatMsg(msg); - } ChatLine::~ChatLine() { @@ -528,6 +549,8 @@ void ChatLine::formatMsg(Message msg) { QString host = hostFromMask(msg.sender); QString nick = nickFromMask(msg.sender); QString text = Style::mircToInternal(msg.text); + QString networkName = msg.buffer.network(); + QString bufferName = msg.buffer.buffer(); QString c = tr("%DT[%1]").arg(msg.timeStamp.toLocalTime().toString("hh:mm:ss")); QString s, t; @@ -567,6 +590,10 @@ void ChatLine::formatMsg(Message msg) { if(nick.isEmpty()) t = tr("%DmUser mode: %DM%1%DM").arg(msg.text); else t = tr("%DmMode %DM%1%DM by %DN%DU%2%DU%DN").arg(msg.text, nick); break; + case Message::Action: + s = tr("%Da-*-"); + t = tr("%Da%DN%DU%1%DU%DN %2").arg(nick).arg(msg.text); + break; default: s = tr("%De%1").arg(msg.sender); t = tr("%De[%1]").arg(msg.text); @@ -649,15 +676,23 @@ void ChatLine::setSelection(SelectionMode mode, int start, int end) { } } -QDateTime ChatLine::getTimeStamp() { +uint ChatLine::msgId() { + return msg.buffer.uid(); +} + +BufferId ChatLine::bufferId() { + return msg.buffer; +} + +QDateTime ChatLine::timeStamp() { return msg.timeStamp; } -QString ChatLine::getSender() { +QString ChatLine::sender() { return senderFormatted.text; } -QString ChatLine::getText() { +QString ChatLine::text() { return textFormatted.text; } @@ -879,50 +914,3 @@ void ChatLine::draw(QPainter *p, const QPointF &pos) { /******************************************************************************************************************/ -LayoutThread::LayoutThread() : QThread() { - mutex.lock(); - abort = false; - mutex.unlock(); - -} - -LayoutThread::~LayoutThread() { - mutex.lock(); - abort = true; - mutex.unlock(); - condition.wakeOne(); - wait(); -} - -void LayoutThread::processTask(LayoutTask task) { - if(!isRunning()) start(); - Q_ASSERT(isRunning()); - mutex.lock(); - queue.append(task); - condition.wakeOne(); - mutex.unlock(); -} - -void LayoutThread::run() { - forever { - mutex.lock(); - if(!queue.count()) { - condition.wait(&mutex); - } - if(abort) { - mutex.unlock(); return; - } - Q_ASSERT(queue.count()); //qDebug() << "process"; - LayoutTask task = queue.takeFirst(); - mutex.unlock(); - /* - foreach(Message msg, task.messages) { - //qDebug() << msg.text; - ChatLine *line = new ChatLine(msg, task.net, task.buf); - task.lines.append(line); - } - emit taskProcessed(task); - */ - //msleep(500); - } -}