+ p->save();
+
+ QRectF rect = chatLine()->columnBoundingRect(columnType());
+
+ qreal layoutWidth = layout()->minimumWidth();
+ qreal offset = 0;
+
+ if(layout()->textOption().alignment() == Qt::AlignRight) {
+ /*
+ if(chatScene()->senderCutoffMode() == ChatScene::CutoffLeft)
+ offset = qMin(width() - layoutWidth, (qreal)0);
+ else
+ offset = qMax(layoutWidth - width(), (qreal)0);
+ */
+ offset = qMax(layoutWidth - rect.width(), (qreal)0);
+ }
+
+ if(layoutWidth > rect.width()) {
+ // Draw a nice gradient for longer items
+
+ QLinearGradient gradient;
+ if(offset < 0) {
+ gradient.setStart(0, 0);
+ gradient.setFinalStop(12, 0);
+ gradient.setColorAt(0, Qt::transparent);
+ gradient.setColorAt(1, Qt::white);
+ } else {
+ gradient.setStart(rect.width()-12, 0);
+ gradient.setFinalStop(rect.width(), 0);
+ gradient.setColorAt(0, Qt::white);
+ gradient.setColorAt(1, Qt::transparent);
+ }
+
+ QImage img(layout()->boundingRect().toRect().size(), QImage::Format_ARGB32_Premultiplied);
+ //img.fill(Qt::transparent);
+ QPainter imgPainter(&img);
+ imgPainter.fillRect(img.rect(), gradient);
+ imgPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
+ layout()->draw(&imgPainter, QPointF(qMax(offset, (qreal)0), 0), selectionFormats());
+ imgPainter.end();
+ p->drawImage(rect.topLeft(), img);
+ } else {
+ layout()->draw(p, rect.topLeft(), selectionFormats(), rect);
+ }
+
+ p->restore();
+}
+
+QVector<QTextLayout::FormatRange> QmlChatLine::ColumnLayout::selectionFormats() const {
+ return QVector<QTextLayout::FormatRange>();
+}
+
+/**************/
+
+QmlChatLine::TimestampLayout::TimestampLayout(QmlChatLine *chatLine)
+ : ColumnLayout(TimestampColumn, chatLine)
+{
+ initLayout(QTextOption::NoWrap, Qt::AlignLeft);
+}
+
+
+/**************/
+
+QmlChatLine::SenderLayout::SenderLayout(QmlChatLine *chatLine)
+ : ColumnLayout(SenderColumn, chatLine)
+{
+ initLayout(QTextOption::NoWrap, Qt::AlignRight);
+}
+
+
+/**************/
+
+QmlChatLine::ContentsLayout::ContentsLayout(QmlChatLine *chatLine)
+ : ColumnLayout(ContentsColumn, chatLine)
+{
+ initLayout(QTextOption::WrapAtWordBoundaryOrAnywhere, Qt::AlignLeft);
+}