323
QSize AbstractItemView::doTextLayout(QTextLayout &layout, const QSize &constraints, Qt::Alignment alignment,
324
QTextOption::WrapMode wrapMode) const
327
to.setAlignment(alignment);
328
to.setTextDirection(layoutDirection());
329
to.setWrapMode(wrapMode);
330
layout.setTextOption(to);
332
QFontMetricsF fm = QFontMetricsF(layout.font());
335
qreal leading = fm.leading();
339
layout.beginLayout();
340
while ((line = layout.createLine()).isValid()) {
341
// Make the last line that will fit infinitely long.
342
// drawTextLayout() will handle this by fading the line out
343
// if it won't fit inside the constraints.
344
if (height + 2 * fm.lineSpacing() > constraints.height()) {
345
line.setLineWidth(INT_MAX);
346
if (line.naturalTextWidth() < constraints.width()) {
347
line.setLineWidth(constraints.width());
348
widthUsed = qMax(widthUsed, line.naturalTextWidth());
350
widthUsed = constraints.width();
353
line.setLineWidth(constraints.width());
354
widthUsed = qMax(widthUsed, line.naturalTextWidth());
356
line.setPosition(QPointF(0, height));
357
height += line.height() + leading;
361
return QSize(widthUsed, height);
364
void AbstractItemView::drawTextLayout(QPainter *painter, const QTextLayout &layout, const QRect &rect) const
366
// Create the alpha gradient for the fade out effect
367
QLinearGradient alphaGradient(0, 0, 1, 0);
368
alphaGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
369
if (layout.textOption().textDirection() == Qt::LeftToRight) {
370
alphaGradient.setColorAt(0, QColor(0, 0, 0, 255));
371
alphaGradient.setColorAt(1, QColor(0, 0, 0, 0));
373
alphaGradient.setColorAt(0, QColor(0, 0, 0, 0));
374
alphaGradient.setColorAt(1, QColor(0, 0, 0, 255));
377
QFontMetrics fm(layout.font());
379
QList<QRect> fadeRects;
380
QList<QRect> haloRects;
383
// Compute halo and fade rects
384
for (int i = 0; i < layout.lineCount(); i++) {
385
const QTextLine line = layout.lineAt(i);
386
const QRectF lr = line.naturalTextRect();
388
// Add a fade out rect to the list if the line is too long
389
if (lr.width() > rect.width()) {
390
int x = rect.width() - fadeWidth;
392
QRect r = QStyle::visualRect(layout.textOption().textDirection(), QRect(QPoint(), rect.size()),
393
QRect(x, y, fadeWidth, int(lr.height())));
397
haloRects.append((lr & rect.translated(-rect.topLeft())).toAlignedRect());
400
// Create a pixmap for the text
401
QPixmap pixmap(rect.size());
402
pixmap.fill(Qt::transparent);
405
p.setPen(painter->pen());
407
// Draw each line in the layout
408
for (int i = 0; i < layout.lineCount(); i++)
410
const QTextLine line = layout.lineAt(i);
411
const QRectF tr = line.naturalTextRect();
413
if (tr.width() > rect.width()) {
414
if (layoutDirection() == Qt::LeftToRight) {
415
line.draw(&p, QPointF(-tr.x(), 0));
417
line.draw(&p, QPointF(rect.width() - tr.right(), 0));
420
line.draw(&p, QPointF());
424
// Reduce the alpha in each fade out rect using the alpha gradient
425
if (!fadeRects.isEmpty()) {
426
p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
427
foreach (const QRect &rect, fadeRects) {
428
p.fillRect(rect, alphaGradient);
434
const QColor color = painter->pen().color();
435
if (qGray(color.rgb()) < 192) {
437
foreach (const QRect &haloRect, haloRects) {
438
Plasma::PaintUtils::drawHalo(painter, haloRect.translated(rect.topLeft()));
442
QImage shadow = pixmap.toImage();
443
Plasma::PaintUtils::shadowBlur(shadow, 2, Qt::black);
444
painter->drawImage(rect.topLeft() + QPoint(1, 1), shadow);
448
// Draw the text pixmap
449
painter->drawPixmap(rect.topLeft(), pixmap);
304
452
void AbstractItemView::rowsInserted(const QModelIndex &parent, int first, int last)