File indexing completed on 2024-12-01 04:36:50
0001 /* 0002 SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "libruqolawidgets_private_export.h" 0010 #include "pixmapcache.h" 0011 #include "utils.h" 0012 #include <QFont> 0013 #include <QObject> 0014 0015 class RocketChatAccount; 0016 class LIBRUQOLAWIDGETS_TESTS_EXPORT AvatarCacheManager : public QObject 0017 { 0018 Q_OBJECT 0019 public: 0020 explicit AvatarCacheManager(const Utils::AvatarType avatarType, QObject *parent = nullptr); 0021 ~AvatarCacheManager() override; 0022 0023 void setCurrentRocketChatAccount(RocketChatAccount *currentRocketChatAccount); 0024 0025 [[nodiscard]] QPixmap makeAvatarPixmap(const QWidget *widget, const Utils::AvatarInfo &info, int maxHeight) const; 0026 [[nodiscard]] QPixmap makeAvatarEmojiPixmap(const QString &emojiStr, const QWidget *widget, const Utils::AvatarInfo &info, int maxHeight) const; 0027 [[nodiscard]] QPixmap makeAvatarUrlPixmap(const QWidget *widget, const QString &url, int maxHeight) const; 0028 0029 void clearCache(); 0030 void setMaxEntries(int maxEntries); 0031 0032 private: 0033 LIBRUQOLAWIDGETS_NO_EXPORT void slotAvatarChanged(const Utils::AvatarInfo &info); 0034 [[nodiscard]] LIBRUQOLAWIDGETS_NO_EXPORT qreal checkIfNeededToClearCache(const QWidget *widget) const; 0035 0036 // DPR-dependent cache of avatars 0037 struct AvatarCache { 0038 qreal dpr = 0.; 0039 // For Avatar not necessary to limit cache. (cache) 0040 PixmapCache cache; 0041 }; 0042 mutable AvatarCache mAvatarCache; 0043 const Utils::AvatarType mAvatarType; 0044 const QFont mEmojiFont; 0045 RocketChatAccount *mRocketChatAccount = nullptr; 0046 };