Changeset View
Changeset View
Standalone View
Standalone View
src/icon.cpp
Show First 20 Lines • Show All 345 Lines • ▼ Show 20 Line(s) | 340 | { | |||
---|---|---|---|---|---|
346 | 346 | | |||
347 | m_loadedImage = QImage(); | 347 | m_loadedImage = QImage(); | ||
348 | 348 | | |||
349 | const QString filename = reply->url().fileName(); | 349 | const QString filename = reply->url().fileName(); | ||
350 | if (!m_loadedImage.load(reply, filename.mid(filename.indexOf(QLatin1Char('.'))).toLatin1().constData())) { | 350 | if (!m_loadedImage.load(reply, filename.mid(filename.indexOf(QLatin1Char('.'))).toLatin1().constData())) { | ||
351 | qWarning() << "received broken image" << reply->url(); | 351 | qWarning() << "received broken image" << reply->url(); | ||
352 | 352 | | |||
353 | // broken image from data, inform the user of this with some useful broken-image thing... | 353 | // broken image from data, inform the user of this with some useful broken-image thing... | ||
354 | const QSize size = QSize(width(), height()) * (window() ? window()->devicePixelRatio() : qApp->devicePixelRatio()); | 354 | m_loadedImage = QIcon::fromTheme(m_fallback).pixmap(window(), QSize(width(), height()), iconMode(), QIcon::On).toImage(); | ||
355 | m_loadedImage = QIcon::fromTheme(m_fallback).pixmap(size, iconMode(), QIcon::On).toImage(); | | |||
356 | } | 355 | } | ||
357 | polish(); | 356 | polish(); | ||
358 | } | 357 | } | ||
359 | 358 | | |||
360 | void Icon::updatePolish() | 359 | void Icon::updatePolish() | ||
361 | { | 360 | { | ||
362 | QQuickItem::updatePolish(); | 361 | QQuickItem::updatePolish(); | ||
363 | 362 | | |||
Show All 12 Lines | 373 | case QVariant::Pixmap: | |||
376 | break; | 375 | break; | ||
377 | case QVariant::Image: | 376 | case QVariant::Image: | ||
378 | m_icon = m_source.value<QImage>(); | 377 | m_icon = m_source.value<QImage>(); | ||
379 | break; | 378 | break; | ||
380 | case QVariant::Bitmap: | 379 | case QVariant::Bitmap: | ||
381 | m_icon = m_source.value<QBitmap>().toImage(); | 380 | m_icon = m_source.value<QBitmap>().toImage(); | ||
382 | break; | 381 | break; | ||
383 | case QVariant::Icon: | 382 | case QVariant::Icon: | ||
384 | m_icon = m_source.value<QIcon>().pixmap(size, iconMode(), QIcon::On).toImage(); | 383 | m_icon = m_source.value<QIcon>().pixmap(window(), itemSize, iconMode(), QIcon::On).toImage(); | ||
385 | break; | 384 | break; | ||
386 | case QVariant::Url: | 385 | case QVariant::Url: | ||
387 | case QVariant::String: | 386 | case QVariant::String: | ||
388 | m_icon = findIcon(size); | 387 | m_icon = findIcon(size); | ||
389 | break; | 388 | break; | ||
390 | case QVariant::Brush: | 389 | case QVariant::Brush: | ||
391 | //todo: fill here too? | 390 | //todo: fill here too? | ||
392 | case QVariant::Color: | 391 | case QVariant::Color: | ||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Line(s) | 452 | } else if(iconSource.startsWith(QLatin1String("http://")) || iconSource.startsWith(QLatin1String("https://"))) { | |||
459 | QNetworkAccessManager* qnam; | 458 | QNetworkAccessManager* qnam; | ||
460 | if (engine && (qnam = engine->networkAccessManager()) && (!m_networkReply || m_networkReply->url() != url)) { | 459 | if (engine && (qnam = engine->networkAccessManager()) && (!m_networkReply || m_networkReply->url() != url)) { | ||
461 | QNetworkRequest request(url); | 460 | QNetworkRequest request(url); | ||
462 | request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); | 461 | request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); | ||
463 | m_networkReply = qnam->get(request); | 462 | m_networkReply = qnam->get(request); | ||
464 | connect(m_networkReply.data(), &QNetworkReply::finished, this, [this](){ handleFinished(m_networkReply); }); | 463 | connect(m_networkReply.data(), &QNetworkReply::finished, this, [this](){ handleFinished(m_networkReply); }); | ||
465 | } | 464 | } | ||
466 | // Temporary icon while we wait for the real image to load... | 465 | // Temporary icon while we wait for the real image to load... | ||
467 | img = QIcon::fromTheme(QStringLiteral("image-x-icon")).pixmap(size, iconMode(), QIcon::On).toImage(); | 466 | img = QIcon::fromTheme(QStringLiteral("image-x-icon")).pixmap(window(), size, iconMode(), QIcon::On).toImage(); | ||
468 | } else { | 467 | } else { | ||
469 | if (iconSource.startsWith(QLatin1String("qrc:/"))) { | 468 | if (iconSource.startsWith(QLatin1String("qrc:/"))) { | ||
470 | iconSource = iconSource.mid(3); | 469 | iconSource = iconSource.mid(3); | ||
471 | } else if (iconSource.startsWith(QLatin1String("file:/"))) { | 470 | } else if (iconSource.startsWith(QLatin1String("file:/"))) { | ||
472 | iconSource = QUrl(iconSource).path(); | 471 | iconSource = QUrl(iconSource).path(); | ||
473 | } | 472 | } | ||
474 | 473 | | |||
475 | QIcon icon; | 474 | QIcon icon; | ||
476 | const bool isPath = iconSource.contains(QLatin1String("/")); | 475 | const bool isPath = iconSource.contains(QLatin1String("/")); | ||
477 | if (isPath) { | 476 | if (isPath) { | ||
478 | icon = QIcon(iconSource); | 477 | icon = QIcon(iconSource); | ||
479 | } else { | 478 | } else { | ||
480 | if (icon.isNull()) { | 479 | if (icon.isNull()) { | ||
481 | icon = m_theme->iconFromTheme(iconSource, m_color); | 480 | icon = m_theme->iconFromTheme(iconSource, m_color); | ||
482 | } | 481 | } | ||
483 | } | 482 | } | ||
484 | if (!icon.isNull()) { | 483 | if (!icon.isNull()) { | ||
485 | img = icon.pixmap(size, iconMode(), QIcon::On).toImage(); | 484 | img = icon.pixmap(window(), size, iconMode(), QIcon::On).toImage(); | ||
486 | 485 | | |||
487 | /*const QColor tintColor = !m_color.isValid() || m_color == Qt::transparent ? (m_selected ? m_theme->highlightedTextColor() : m_theme->textColor()) : m_color; | 486 | /*const QColor tintColor = !m_color.isValid() || m_color == Qt::transparent ? (m_selected ? m_theme->highlightedTextColor() : m_theme->textColor()) : m_color; | ||
488 | 487 | | |||
489 | if (m_isMask || icon.isMask() || iconSource.endsWith(QLatin1String("-symbolic")) || iconSource.endsWith(QLatin1String("-symbolic-rtl")) || iconSource.endsWith(QLatin1String("-symbolic-ltr")) || guessMonochrome(img)) { | 488 | if (m_isMask || icon.isMask() || iconSource.endsWith(QLatin1String("-symbolic")) || iconSource.endsWith(QLatin1String("-symbolic-rtl")) || iconSource.endsWith(QLatin1String("-symbolic-ltr")) || guessMonochrome(img)) { | ||
490 | QPainter p(&img); | 489 | QPainter p(&img); | ||
491 | p.setCompositionMode(QPainter::CompositionMode_SourceIn); | 490 | p.setCompositionMode(QPainter::CompositionMode_SourceIn); | ||
492 | p.fillRect(img.rect(), tintColor); | 491 | p.fillRect(img.rect(), tintColor); | ||
493 | p.end(); | 492 | p.end(); | ||
494 | }*/ | 493 | }*/ | ||
495 | } | 494 | } | ||
496 | } | 495 | } | ||
497 | 496 | | |||
498 | if (!iconSource.isEmpty() && img.isNull()) { | 497 | if (!iconSource.isEmpty() && img.isNull()) { | ||
499 | img = QIcon::fromTheme(m_fallback).pixmap(size, iconMode(), QIcon::On).toImage(); | 498 | img = QIcon::fromTheme(m_fallback).pixmap(window(), size, iconMode(), QIcon::On).toImage(); | ||
500 | } | 499 | } | ||
501 | return img; | 500 | return img; | ||
502 | } | 501 | } | ||
503 | 502 | | |||
504 | QIcon::Mode Icon::iconMode() const | 503 | QIcon::Mode Icon::iconMode() const | ||
505 | { | 504 | { | ||
506 | if (!isEnabled()) { | 505 | if (!isEnabled()) { | ||
507 | return QIcon::Disabled; | 506 | return QIcon::Disabled; | ||
▲ Show 20 Lines • Show All 82 Lines • Show Last 20 Lines |