Skip to content

Commit

Permalink
Fix null pixmaps
Browse files Browse the repository at this point in the history
Fixes: #11804
  • Loading branch information
TheOneRing committed Aug 20, 2024
1 parent 382861e commit 4c539c4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
9 changes: 1 addition & 8 deletions src/gui/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,7 @@ class AvatarImageProvider : public QQuickImageProvider
{
const auto qmlIcon = OCC::Resources::QMLResources::parseIcon(id);
const auto accountState = OCC::AccountManager::instance()->account(QUuid::fromString(qmlIcon.iconName));
QIcon icon = accountState->account()->avatar();
// the sourceSize of the Image must be provided
Q_ASSERT(requestedSize.isValid());
const QSize actualSize = requestedSize.isValid() ? requestedSize : icon.availableSizes().constFirst();
if (size) {
*size = actualSize;
}
return icon.pixmap(actualSize, qmlIcon.enabled ? QIcon::Normal : QIcon::Disabled);
return OCC::Resources::pixmap(requestedSize, accountState->account()->avatar(), qmlIcon.enabled ? QIcon::Normal : QIcon::Disabled, size);
}
};
}
Expand Down
9 changes: 2 additions & 7 deletions src/gui/spaces/spaceimageprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
#include "spaceimageprovider.h"
#include "libsync/graphapi/spacesmanager.h"
#include "resources/qmlresources.h"
#include "resources/resources.h"

using namespace OCC;
Expand All @@ -36,11 +37,5 @@ QPixmap SpaceImageProvider::requestPixmap(const QString &id, QSize *size, const
icon = space->image()->image();
}
}
// the sourceSize of the Image must be provided
Q_ASSERT(requestedSize.isValid());
const QSize actualSize = requestedSize.isValid() ? requestedSize : icon.availableSizes().constFirst();
if (size) {
*size = actualSize;
}
return icon.pixmap(actualSize);
return Resources::pixmap(requestedSize, icon, QIcon::Normal, size);
}
14 changes: 14 additions & 0 deletions src/resources/qmlresources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

#include "resources/resources.h"

namespace {
constexpr QSize minIconSize{16, 16};
}

using namespace OCC;
QUrl Resources::QMLResources::resourcePath2(const QString &provider, const QString &icon, bool enabled, const QVariantMap &properies)
{
Expand All @@ -36,3 +40,13 @@ Resources::QMLResources::Icon Resources::QMLResources::parseIcon(const QString &
const auto data = QJsonDocument::fromJson(QByteArray::fromBase64(id.toUtf8())).object();
return Icon{data.value(QLatin1String("theme")).toString(), data.value(QLatin1String("icon")).toString(), data.value(QLatin1String("enabled")).toBool()};
}

QPixmap Resources::pixmap(const QSize &requestedSize, const QIcon &icon, QIcon::Mode mode, QSize *outSize)
{
Q_ASSERT(requestedSize.isValid());
QSize actualSize = requestedSize.isValid() ? requestedSize : icon.availableSizes().constFirst();
if (outSize) {
*outSize = actualSize;
}
return icon.pixmap(actualSize.expandedTo(minIconSize), mode);
}
3 changes: 3 additions & 0 deletions src/resources/qmlresources.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once
#include "resources/owncloudresources.h"

#include <QIcon>
#include <QtQml/QtQml>

namespace OCC {
Expand All @@ -38,5 +39,7 @@ namespace Resources {

static Icon parseIcon(const QString &id);
};

QPixmap OWNCLOUDRESOURCES_EXPORT pixmap(const QSize &requestedSize, const QIcon &icon, QIcon::Mode mode, QSize *outSize);
} // Resources
} // OCC
9 changes: 1 addition & 8 deletions src/resources/resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,5 @@ QPixmap CoreImageProvider::requestPixmap(const QString &id, QSize *size, const Q
} else {
icon = themeIcon(qmlIcon.iconName);
}

// the sourceSize of the Image must be provided
Q_ASSERT(requestedSize.isValid());
const QSize actualSize = requestedSize.isValid() ? requestedSize : icon.availableSizes().constFirst();
if (size) {
*size = actualSize;
}
return icon.pixmap(actualSize, qmlIcon.enabled ? QIcon::Normal : QIcon::Disabled);
return Resources::pixmap(requestedSize, icon, qmlIcon.enabled ? QIcon::Normal : QIcon::Disabled, size);
}

0 comments on commit 4c539c4

Please sign in to comment.