-//!\brief Draw ChatLine on the given QPainter at the given position.
-void ChatLine::draw(QPainter *p, const QPointF &pos) {
- QPalette pal = QApplication::palette();
-
- if(selectionMode == Full) {
- p->setPen(Qt::NoPen);
- p->setBrush(pal.brush(QPalette::Highlight));
- p->drawRect(QRectF(pos, QSizeF(tsWidth + QtUi::style()->sepTsSender() + senderWidth + QtUi::style()->sepSenderText() + textWidth, height())));
- } else if(selectionMode == Partial) {
-
- } /*
- p->setClipRect(QRectF(pos, QSizeF(tsWidth, height())));
- tsLayout.draw(p, pos, tsFormat);
- p->setClipRect(QRectF(pos + QPointF(tsWidth + Style::sepTsSender(), 0), QSizeF(senderWidth, height())));
- senderLayout.draw(p, pos + QPointF(tsWidth + Style::sepTsSender(), 0), senderFormat);
- p->setClipping(false);
- textLayout.draw(p, pos + QPointF(tsWidth + Style::sepTsSender() + senderWidth + Style::sepSenderText(), 0), textFormat);
- */
- //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, styledTimeStamp.text.mid(fr.start, fr.length), &brect);
- rect.setLeft(brect.right());
- }
- rect = QRectF(pos + QPointF(tsWidth + QtUi::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, styledSender.text.mid(fr.start, fr.length), &brect);
- rect.setRight(brect.left());
- }
- QPointF tpos = pos + QPointF(tsWidth + QtUi::style()->sepTsSender() + senderWidth + QtUi::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, styledText.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());
- }