Changeset View
Changeset View
Standalone View
Standalone View
src/kitemviews/kstandarditemlistwidget.cpp
Show First 20 Lines • Show All 1107 Lines • ▼ Show 20 Line(s) | 1090 | if (ratingTextInfo) { | |||
---|---|---|---|---|---|
1108 | const QRect rect(QPoint(0, 0), ratingSize.toSize()); | 1108 | const QRect rect(QPoint(0, 0), ratingSize.toSize()); | ||
1109 | const int rating = data().value("rating").toInt(); | 1109 | const int rating = data().value("rating").toInt(); | ||
1110 | KRatingPainter::paintRating(&painter, rect, Qt::AlignJustify | Qt::AlignVCenter, rating); | 1110 | KRatingPainter::paintRating(&painter, rect, Qt::AlignJustify | Qt::AlignVCenter, rating); | ||
1111 | } else if (!m_rating.isNull()) { | 1111 | } else if (!m_rating.isNull()) { | ||
1112 | m_rating = QPixmap(); | 1112 | m_rating = QPixmap(); | ||
1113 | } | 1113 | } | ||
1114 | } | 1114 | } | ||
1115 | 1115 | | |||
1116 | QString KStandardItemListWidget::elideRightKeepExtension(const QString &text, int elidingWidth) const | ||||
1117 | { | ||||
1118 | auto extensionIndex = text.lastIndexOf('.'); | ||||
cfeck: Did you test if using https://bugs.kde.org/show_bug.cgi?id=404955#c11 made things too slow? | |||||
I didn't, probably a good idea to use QMimeDatabase::mimeTypesForFileName here instead of this naive file extension detection. meven: I didn't, probably a good idea to use `QMimeDatabase::mimeTypesForFileName` here instead of… | |||||
1119 | if (extensionIndex != -1) { | ||||
1120 | // has file extension | ||||
1121 | auto extensionLength = text.length() - extensionIndex; | ||||
1122 | auto extensionWidth = m_customizedFontMetrics.width(text.right(extensionLength)); | ||||
1123 | if (elidingWidth > extensionWidth && extensionLength < 6 && (float(extensionWidth) / float(elidingWidth)) < 0.3) { | ||||
1124 | // if we have room to display the file extension and the extension is not too long | ||||
1125 | QString ret = m_customizedFontMetrics.elidedText(text.chopped(extensionLength), | ||||
1126 | Qt::ElideRight, | ||||
1127 | elidingWidth - extensionWidth); | ||||
1128 | ret.append(text.right(extensionLength)); | ||||
1129 | return ret; | ||||
1130 | } | ||||
1131 | } | ||||
1132 | return m_customizedFontMetrics.elidedText(text,Qt::ElideRight, | ||||
1133 | elidingWidth); | ||||
1134 | } | ||||
1135 | | ||||
1116 | void KStandardItemListWidget::updateIconsLayoutTextCache() | 1136 | void KStandardItemListWidget::updateIconsLayoutTextCache() | ||
1117 | { | 1137 | { | ||
1118 | // +------+ | 1138 | // +------+ | ||
1119 | // | Icon | | 1139 | // | Icon | | ||
1120 | // +------+ | 1140 | // +------+ | ||
1121 | // | 1141 | // | ||
1122 | // Name role that | 1142 | // Name role that | ||
1123 | // might get wrapped above | 1143 | // might get wrapped above | ||
Show All 35 Lines | 1177 | if (nameLineIndex == option.maxTextLines) { | |||
1159 | // the case provide an elided text if necessary. | 1179 | // the case provide an elided text if necessary. | ||
1160 | const int textLength = line.textStart() + line.textLength(); | 1180 | const int textLength = line.textStart() + line.textLength(); | ||
1161 | if (textLength < nameText.length()) { | 1181 | if (textLength < nameText.length()) { | ||
1162 | // Elide the last line of the text | 1182 | // Elide the last line of the text | ||
1163 | qreal elidingWidth = maxWidth; | 1183 | qreal elidingWidth = maxWidth; | ||
1164 | qreal lastLineWidth; | 1184 | qreal lastLineWidth; | ||
1165 | do { | 1185 | do { | ||
1166 | QString lastTextLine = nameText.mid(line.textStart()); | 1186 | QString lastTextLine = nameText.mid(line.textStart()); | ||
1167 | lastTextLine = m_customizedFontMetrics.elidedText(lastTextLine, | 1187 | lastTextLine = elideRightKeepExtension(lastTextLine, elidingWidth); | ||
1168 | Qt::ElideMiddle, | | |||
1169 | elidingWidth); | | |||
1170 | const QString elidedText = nameText.left(line.textStart()) + lastTextLine; | 1188 | const QString elidedText = nameText.left(line.textStart()) + lastTextLine; | ||
1171 | nameTextInfo->staticText.setText(elidedText); | 1189 | nameTextInfo->staticText.setText(elidedText); | ||
1172 | 1190 | | |||
1173 | lastLineWidth = m_customizedFontMetrics.boundingRect(lastTextLine).width(); | 1191 | lastLineWidth = m_customizedFontMetrics.boundingRect(lastTextLine).width(); | ||
1174 | 1192 | | |||
1175 | // We do the text eliding in a loop with decreasing width (1 px / iteration) | 1193 | // We do the text eliding in a loop with decreasing width (1 px / iteration) | ||
1176 | // to avoid problems related to different width calculation code paths | 1194 | // to avoid problems related to different width calculation code paths | ||
1177 | // within Qt. (see bug 337104) | 1195 | // within Qt. (see bug 337104) | ||
Show All 38 Lines | 1220 | foreach (const QByteArray& role, m_sortedVisibleRoles) { | |||
1216 | layout.setTextOption(textOption); | 1234 | layout.setTextOption(textOption); | ||
1217 | 1235 | | |||
1218 | layout.beginLayout(); | 1236 | layout.beginLayout(); | ||
1219 | QTextLine textLine = layout.createLine(); | 1237 | QTextLine textLine = layout.createLine(); | ||
1220 | if (textLine.isValid()) { | 1238 | if (textLine.isValid()) { | ||
1221 | textLine.setLineWidth(maxWidth); | 1239 | textLine.setLineWidth(maxWidth); | ||
1222 | requiredWidth = textLine.naturalTextWidth(); | 1240 | requiredWidth = textLine.naturalTextWidth(); | ||
1223 | if (requiredWidth > maxWidth) { | 1241 | if (requiredWidth > maxWidth) { | ||
1224 | const QString elidedText = m_customizedFontMetrics.elidedText(text, Qt::ElideMiddle, maxWidth); | 1242 | const QString elidedText = elideRightKeepExtension(text, maxWidth); | ||
1225 | textInfo->staticText.setText(elidedText); | 1243 | textInfo->staticText.setText(elidedText); | ||
1226 | requiredWidth = m_customizedFontMetrics.width(elidedText); | 1244 | requiredWidth = m_customizedFontMetrics.width(elidedText); | ||
1227 | } else if (role == "rating") { | 1245 | } else if (role == "rating") { | ||
1228 | // Use the width of the rating pixmap, because the rating text is empty. | 1246 | // Use the width of the rating pixmap, because the rating text is empty. | ||
1229 | requiredWidth = m_rating.width(); | 1247 | requiredWidth = m_rating.width(); | ||
1230 | } | 1248 | } | ||
1231 | } | 1249 | } | ||
1232 | layout.endLayout(); | 1250 | layout.endLayout(); | ||
Show All 32 Lines | 1266 | { | |||
1265 | foreach (const QByteArray& role, m_sortedVisibleRoles) { | 1283 | foreach (const QByteArray& role, m_sortedVisibleRoles) { | ||
1266 | const QString text = roleText(role, values); | 1284 | const QString text = roleText(role, values); | ||
1267 | TextInfo* textInfo = m_textInfo.value(role); | 1285 | TextInfo* textInfo = m_textInfo.value(role); | ||
1268 | textInfo->staticText.setText(text); | 1286 | textInfo->staticText.setText(text); | ||
1269 | 1287 | | |||
1270 | qreal requiredWidth = m_customizedFontMetrics.width(text); | 1288 | qreal requiredWidth = m_customizedFontMetrics.width(text); | ||
1271 | if (requiredWidth > maxWidth) { | 1289 | if (requiredWidth > maxWidth) { | ||
1272 | requiredWidth = maxWidth; | 1290 | requiredWidth = maxWidth; | ||
1273 | const QString elidedText = m_customizedFontMetrics.elidedText(text, Qt::ElideMiddle, maxWidth); | 1291 | const QString elidedText = elideRightKeepExtension(text, maxWidth); | ||
1274 | textInfo->staticText.setText(elidedText); | 1292 | textInfo->staticText.setText(elidedText); | ||
1275 | } | 1293 | } | ||
1276 | 1294 | | |||
1277 | textInfo->pos = QPointF(x, y); | 1295 | textInfo->pos = QPointF(x, y); | ||
1278 | textInfo->staticText.setTextWidth(maxWidth); | 1296 | textInfo->staticText.setTextWidth(maxWidth); | ||
1279 | 1297 | | |||
1280 | maximumRequiredTextWidth = qMax(maximumRequiredTextWidth, requiredWidth); | 1298 | maximumRequiredTextWidth = qMax(maximumRequiredTextWidth, requiredWidth); | ||
1281 | 1299 | | |||
Show All 40 Lines | 1334 | foreach (const QByteArray& role, m_sortedVisibleRoles) { | |||
1322 | qreal availableTextWidth = roleWidth - columnWidthInc; | 1340 | qreal availableTextWidth = roleWidth - columnWidthInc; | ||
1323 | 1341 | | |||
1324 | const bool isTextRole = (role == "text"); | 1342 | const bool isTextRole = (role == "text"); | ||
1325 | if (isTextRole) { | 1343 | if (isTextRole) { | ||
1326 | availableTextWidth -= firstColumnInc; | 1344 | availableTextWidth -= firstColumnInc; | ||
1327 | } | 1345 | } | ||
1328 | 1346 | | |||
1329 | if (requiredWidth > availableTextWidth) { | 1347 | if (requiredWidth > availableTextWidth) { | ||
1330 | text = m_customizedFontMetrics.elidedText(text, Qt::ElideMiddle, availableTextWidth); | 1348 | text = elideRightKeepExtension(text, availableTextWidth); | ||
1331 | requiredWidth = m_customizedFontMetrics.width(text); | 1349 | requiredWidth = m_customizedFontMetrics.width(text); | ||
1332 | } | 1350 | } | ||
1333 | 1351 | | |||
1334 | TextInfo* textInfo = m_textInfo.value(role); | 1352 | TextInfo* textInfo = m_textInfo.value(role); | ||
1335 | textInfo->staticText.setText(text); | 1353 | textInfo->staticText.setText(text); | ||
1336 | textInfo->pos = QPointF(x + columnWidthInc / 2, y); | 1354 | textInfo->pos = QPointF(x + columnWidthInc / 2, y); | ||
1337 | x += roleWidth; | 1355 | x += roleWidth; | ||
1338 | 1356 | | |||
▲ Show 20 Lines • Show All 188 Lines • Show Last 20 Lines |
Did you test if using https://bugs.kde.org/show_bug.cgi?id=404955#c11 made things too slow?