Changeset View
Changeset View
Standalone View
Standalone View
src/plasma/svg.cpp
Show First 20 Lines • Show All 305 Lines • ▼ Show 20 Line(s) | 305 | { | |||
---|---|---|---|---|---|
306 | QSize size; | 306 | QSize size; | ||
307 | QString actualElementId; | 307 | QString actualElementId; | ||
308 | 308 | | |||
309 | if (elementsWithSizeHints.isEmpty()) { | 309 | if (elementsWithSizeHints.isEmpty()) { | ||
310 | // Fetch all size hinted element ids from the theme's rect cache | 310 | // Fetch all size hinted element ids from the theme's rect cache | ||
311 | // and store them locally. | 311 | // and store them locally. | ||
312 | QRegExp sizeHintedKeyExpr(CACHE_ID_NATURAL_SIZE(QStringLiteral("(\\d+)-(\\d+)-(.+)"), status, ratio)); | 312 | QRegExp sizeHintedKeyExpr(CACHE_ID_NATURAL_SIZE(QStringLiteral("(\\d+)-(\\d+)-(.+)"), status, ratio)); | ||
313 | 313 | | |||
314 | foreach (const QString &key, cacheAndColorsTheme()->listCachedRectKeys(path)) { | 314 | const auto lst = cacheAndColorsTheme()->listCachedRectKeys(path); | ||
315 | for (const QString &key : lst) { | ||||
315 | if (sizeHintedKeyExpr.exactMatch(key)) { | 316 | if (sizeHintedKeyExpr.exactMatch(key)) { | ||
316 | QString baseElementId = sizeHintedKeyExpr.cap(3); | 317 | QString baseElementId = sizeHintedKeyExpr.cap(3); | ||
317 | QSize sizeHint(sizeHintedKeyExpr.cap(1).toInt(), | 318 | QSize sizeHint(sizeHintedKeyExpr.cap(1).toInt(), | ||
318 | sizeHintedKeyExpr.cap(2).toInt()); | 319 | sizeHintedKeyExpr.cap(2).toInt()); | ||
319 | 320 | | |||
320 | if (sizeHint.isValid()) { | 321 | if (sizeHint.isValid()) { | ||
321 | elementsWithSizeHints.insertMulti(baseElementId, sizeHint); | 322 | elementsWithSizeHints.insertMulti(baseElementId, sizeHint); | ||
322 | } | 323 | } | ||
323 | } | 324 | } | ||
324 | } | 325 | } | ||
325 | 326 | | |||
326 | if (elementsWithSizeHints.isEmpty()) { | 327 | if (elementsWithSizeHints.isEmpty()) { | ||
327 | // Make sure we won't query the theme unnecessarily. | 328 | // Make sure we won't query the theme unnecessarily. | ||
328 | elementsWithSizeHints.insert(QString(), QSize()); | 329 | elementsWithSizeHints.insert(QString(), QSize()); | ||
329 | } | 330 | } | ||
330 | } | 331 | } | ||
331 | 332 | | |||
332 | // Look at the size hinted elements and try to find the smallest one with an | 333 | // Look at the size hinted elements and try to find the smallest one with an | ||
333 | // identical aspect ratio. | 334 | // identical aspect ratio. | ||
334 | if (s.isValid() && !elementId.isEmpty()) { | 335 | if (s.isValid() && !elementId.isEmpty()) { | ||
335 | QList<QSize> elementSizeHints = elementsWithSizeHints.values(elementId); | 336 | const QList<QSize> elementSizeHints = elementsWithSizeHints.values(elementId); | ||
336 | 337 | | |||
337 | if (!elementSizeHints.isEmpty()) { | 338 | if (!elementSizeHints.isEmpty()) { | ||
338 | QSize bestFit(-1, -1); | 339 | QSize bestFit(-1, -1); | ||
339 | 340 | | |||
340 | Q_FOREACH (QSize hint, elementSizeHints) { | 341 | for (QSize hint : elementSizeHints) { | ||
341 | 342 | | |||
342 | if (hint.width() >= s.width() * ratio && hint.height() >= s.height() * ratio && | 343 | if (hint.width() >= s.width() * ratio && hint.height() >= s.height() * ratio && | ||
343 | (!bestFit.isValid() || | 344 | (!bestFit.isValid() || | ||
344 | (bestFit.width() * bestFit.height()) > (hint.width() * hint.height()))) { | 345 | (bestFit.width() * bestFit.height()) > (hint.width() * hint.height()))) { | ||
345 | bestFit = hint; | 346 | bestFit = hint; | ||
346 | } | 347 | } | ||
347 | } | 348 | } | ||
348 | 349 | | |||
▲ Show 20 Lines • Show All 656 Lines • Show Last 20 Lines |