Changeset View
Changeset View
Standalone View
Standalone View
lib/thumbnailview/previewitemdelegate.cpp
Show First 20 Lines • Show All 344 Lines • ▼ Show 20 Line(s) | 336 | { | |||
---|---|---|---|---|---|
345 | } else { | 345 | } else { | ||
346 | text = it.value(); | 346 | text = it.value(); | ||
347 | } | 347 | } | ||
348 | 348 | | |||
349 | // Compute x pos | 349 | // Compute x pos | ||
350 | int posX; | 350 | int posX; | ||
351 | if (text.length() == fullText.length()) { | 351 | if (text.length() == fullText.length()) { | ||
352 | // Not elided, center text | 352 | // Not elided, center text | ||
353 | posX = (rect.width() - fm.width(text)) / 2; | 353 | posX = (rect.width() - fm.boundingRect(text).width()) / 2; | ||
354 | } else { | 354 | } else { | ||
355 | // Elided, left align | 355 | // Elided, left align | ||
356 | posX = 0; | 356 | posX = 0; | ||
357 | } | 357 | } | ||
358 | 358 | | |||
359 | // Draw text | 359 | // Draw text | ||
360 | painter->setPen(fgColor); | 360 | painter->setPen(fgColor); | ||
361 | painter->drawText(rect.left() + posX, rect.top() + fm.ascent(), text); | 361 | painter->drawText(rect.left() + posX, rect.top() + fm.ascent(), text); | ||
▲ Show 20 Lines • Show All 594 Lines • ▼ Show 20 Line(s) | |||||
956 | 956 | | |||
957 | void PreviewItemDelegate::updateEditorGeometry(QWidget* widget, const QStyleOptionViewItem& option, const QModelIndex& index) const | 957 | void PreviewItemDelegate::updateEditorGeometry(QWidget* widget, const QStyleOptionViewItem& option, const QModelIndex& index) const | ||
958 | { | 958 | { | ||
959 | ItemEditor* edit = qobject_cast<ItemEditor*>(widget); | 959 | ItemEditor* edit = qobject_cast<ItemEditor*>(widget); | ||
960 | if (!edit) { | 960 | if (!edit) { | ||
961 | return; | 961 | return; | ||
962 | } | 962 | } | ||
963 | QString text = index.data().toString(); | 963 | QString text = index.data().toString(); | ||
964 | int textWidth = edit->fontMetrics().width(QStringLiteral(" ") + text + QStringLiteral(" ")); | 964 | int textWidth = edit->fontMetrics().boundingRect(QStringLiteral(" ") + text + QStringLiteral(" ")).width(); | ||
965 | QRect textRect( | 965 | QRect textRect( | ||
966 | option.rect.left() + (option.rect.width() - textWidth) / 2, | 966 | option.rect.left() + (option.rect.width() - textWidth) / 2, | ||
967 | option.rect.top() + 2 * ITEM_MARGIN + d->mThumbnailSize.height(), | 967 | option.rect.top() + 2 * ITEM_MARGIN + d->mThumbnailSize.height(), | ||
968 | textWidth, | 968 | textWidth, | ||
969 | edit->sizeHint().height()); | 969 | edit->sizeHint().height()); | ||
970 | 970 | | |||
971 | edit->setGeometry(textRect); | 971 | edit->setGeometry(textRect); | ||
972 | } | 972 | } | ||
Show All 13 Lines |