+ */
+ //p->setClipRect(QRectF(pos, QSizeF(tsWidth, 15)));
+ //p->drawRect(QRectF(pos, QSizeF(tsWidth, minHeight)));
+ p->setBackgroundMode(Qt::OpaqueMode);
+ QPointF tp = pos;
+ QRectF rect(pos, QSizeF(tsWidth, minHeight));
+ QRectF brect;
+ foreach(FormatRange fr, tsFormat) {
+ p->setFont(fr.format.font());
+ p->setPen(QPen(fr.format.foreground(), 0)); p->setBackground(fr.format.background());
+ p->drawText(rect, Qt::AlignLeft|Qt::TextSingleLine, tsFormatted.text.mid(fr.start, fr.length), &brect);
+ rect.setLeft(brect.right());
+ }
+ rect = QRectF(pos + QPointF(tsWidth + Style::sepTsSender(), 0), QSizeF(senderWidth, minHeight));
+ for(int i = senderFormat.count() - 1; i >= 0; i--) {
+ FormatRange fr = senderFormat[i];
+ p->setFont(fr.format.font()); p->setPen(QPen(fr.format.foreground(), 0)); p->setBackground(fr.format.background());
+ p->drawText(rect, Qt::AlignRight|Qt::TextSingleLine, senderFormatted.text.mid(fr.start, fr.length), &brect);
+ rect.setRight(brect.left());
+ }
+ QPointF tpos = pos + QPointF(tsWidth + Style::sepTsSender() + senderWidth + Style::sepSenderText(), 0);
+ qreal h = 0; int l = 0;
+ rect = QRectF(tpos + QPointF(0, h), QSizeF(textWidth, lineLayouts[l].height));
+ int offset = 0;
+ foreach(FormatRange fr, textFormat) {
+ if(l >= lineLayouts.count()) break;
+ p->setFont(fr.format.font()); p->setPen(QPen(fr.format.foreground(), 0)); p->setBackground(fr.format.background());
+ int start, end, frend, llend;
+ do {
+ frend = fr.start + fr.length;
+ if(frend <= lineLayouts[l].start) break;
+ llend = lineLayouts[l].start + lineLayouts[l].length;
+ start = qMax(fr.start, lineLayouts[l].start); end = qMin(frend, llend);
+ rect.setLeft(tpos.x() + charPos[start] - offset);
+ p->drawText(rect, Qt::AlignLeft|Qt::TextSingleLine, textFormatted.text.mid(start, end - start), &brect);
+ if(llend <= end) {
+ h += lineLayouts[l].height;
+ l++;
+ if(l < lineLayouts.count()) {
+ rect = QRectF(tpos + QPointF(0, h), QSizeF(textWidth, lineLayouts[l].height));
+ offset = charPos[lineLayouts[l].start];
+ }
+ }
+ } while(end < frend && l < lineLayouts.count());
+ }
+}
+
+/******************************************************************************************************************/
+
+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);
+ }