tdesktop/Telegram/SourceFiles/data/data_wall_paper.h

159 lines
5.1 KiB
C
Raw Normal View History

2019-02-08 16:20:08 +00:00
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
2021-08-12 09:32:30 +00:00
#include "base/flags.h"
2019-02-08 16:20:08 +00:00
class Image;
2020-06-08 09:06:50 +00:00
namespace Main {
class Session;
} // namespace Main
namespace Ui {
[[nodiscard]] QColor ColorFromSerialized(MTPint serialized);
[[nodiscard]] std::optional<QColor> MaybeColorFromSerialized(
const tl::conditional<MTPint> &mtp);
} // namespace Ui
2019-02-08 16:20:08 +00:00
namespace Data {
struct FileOrigin;
2021-08-12 09:32:30 +00:00
enum class WallPaperFlag {
Pattern = (1 << 0),
Default = (1 << 1),
Creator = (1 << 2),
Dark = (1 << 3),
};
inline constexpr bool is_flag_type(WallPaperFlag) { return true; };
using WallPaperFlags = base::flags<WallPaperFlag>;
2019-02-08 16:20:08 +00:00
class WallPaper {
public:
explicit WallPaper(WallPaperId id);
void setLocalImageAsThumbnail(std::shared_ptr<Image> image);
2023-04-17 09:43:08 +00:00
[[nodiscard]] bool equals(const WallPaper &paper) const;
2019-02-08 16:20:08 +00:00
[[nodiscard]] WallPaperId id() const;
[[nodiscard]] QString emojiId() const;
2023-04-17 09:43:08 +00:00
[[nodiscard]] bool isNull() const;
[[nodiscard]] QString key() const;
2021-08-12 09:32:30 +00:00
[[nodiscard]] const std::vector<QColor> backgroundColors() const;
2019-02-08 16:20:08 +00:00
[[nodiscard]] DocumentData *document() const;
2020-05-29 15:10:25 +00:00
[[nodiscard]] Image *localThumbnail() const;
2019-02-08 16:20:08 +00:00
[[nodiscard]] bool isPattern() const;
[[nodiscard]] bool isDefault() const;
[[nodiscard]] bool isCreator() const;
[[nodiscard]] bool isDark() const;
[[nodiscard]] bool isLocal() const;
[[nodiscard]] bool isBlurred() const;
[[nodiscard]] int patternIntensity() const;
[[nodiscard]] float64 patternOpacity() const;
[[nodiscard]] int gradientRotation() const;
2019-02-08 16:20:08 +00:00
[[nodiscard]] bool hasShareUrl() const;
[[nodiscard]] QString shareUrl(not_null<Main::Session*> session) const;
2019-02-08 16:20:08 +00:00
void loadDocument() const;
void loadDocumentThumbnail() const;
2019-02-08 16:20:08 +00:00
[[nodiscard]] FileOrigin fileOrigin() const;
2019-02-08 16:47:02 +00:00
2020-06-19 15:14:55 +00:00
[[nodiscard]] UserId ownerId() const;
[[nodiscard]] MTPInputWallPaper mtpInput(
not_null<Main::Session*> session) const;
2019-02-08 16:20:08 +00:00
[[nodiscard]] MTPWallPaperSettings mtpSettings() const;
[[nodiscard]] WallPaper withUrlParams(
const QMap<QString, QString> &params) const;
[[nodiscard]] WallPaper withBlurred(bool blurred) const;
[[nodiscard]] WallPaper withPatternIntensity(int intensity) const;
2021-08-12 09:32:30 +00:00
[[nodiscard]] WallPaper withGradientRotation(int rotation) const;
[[nodiscard]] WallPaper withBackgroundColors(
std::vector<QColor> colors) const;
2019-02-08 16:20:08 +00:00
[[nodiscard]] WallPaper withParamsFrom(const WallPaper &other) const;
[[nodiscard]] WallPaper withoutImageData() const;
[[nodiscard]] static std::optional<WallPaper> Create(
2020-06-08 09:06:50 +00:00
not_null<Main::Session*> session,
2019-02-08 16:20:08 +00:00
const MTPWallPaper &data);
[[nodiscard]] static std::optional<WallPaper> Create(
2020-06-08 09:06:50 +00:00
not_null<Main::Session*> session,
2019-02-08 16:20:08 +00:00
const MTPDwallPaper &data);
2021-08-12 09:32:30 +00:00
[[nodiscard]] static std::optional<WallPaper> Create(
const MTPDwallPaperNoFile &data);
2019-02-08 16:20:08 +00:00
[[nodiscard]] QByteArray serialize() const;
[[nodiscard]] static std::optional<WallPaper> FromSerialized(
const QByteArray &serialized);
[[nodiscard]] static std::optional<WallPaper> FromLegacySerialized(
quint64 id,
quint64 accessHash,
quint32 flags,
QString slug);
[[nodiscard]] static std::optional<WallPaper> FromLegacyId(
qint32 legacyId);
2021-08-12 09:32:30 +00:00
[[nodiscard]] static std::optional<WallPaper> FromColorsSlug(
2019-02-08 16:20:08 +00:00
const QString &slug);
2023-12-22 04:17:44 +00:00
[[nodiscard]] static WallPaper FromEmojiId(const QString &emojiId);
2021-08-31 19:10:39 +00:00
[[nodiscard]] static WallPaper ConstructDefault();
2019-02-08 16:20:08 +00:00
private:
2021-08-12 09:32:30 +00:00
static constexpr auto kDefaultIntensity = 50;
2019-02-08 16:20:08 +00:00
2023-04-17 09:43:08 +00:00
[[nodiscard]] QStringList collectShareParams() const;
2019-02-08 16:20:08 +00:00
WallPaperId _id = WallPaperId();
uint64 _accessHash = 0;
2020-06-19 15:14:55 +00:00
UserId _ownerId = 0;
2021-08-12 09:32:30 +00:00
WallPaperFlags _flags;
2019-02-08 16:20:08 +00:00
QString _slug;
QString _emojiId;
2019-02-08 16:20:08 +00:00
2021-08-12 09:32:30 +00:00
std::vector<QColor> _backgroundColors;
int _rotation = 0;
2019-02-08 16:20:08 +00:00
int _intensity = kDefaultIntensity;
2021-08-12 09:32:30 +00:00
bool _blurred = false;
2019-02-08 16:20:08 +00:00
DocumentData *_document = nullptr;
std::shared_ptr<Image> _thumbnail;
};
[[nodiscard]] WallPaper ThemeWallPaper();
[[nodiscard]] bool IsThemeWallPaper(const WallPaper &paper);
[[nodiscard]] WallPaper CustomWallPaper();
[[nodiscard]] bool IsCustomWallPaper(const WallPaper &paper);
[[nodiscard]] WallPaper Legacy1DefaultWallPaper();
[[nodiscard]] bool IsLegacy1DefaultWallPaper(const WallPaper &paper);
2021-07-23 09:16:33 +00:00
[[nodiscard]] bool IsLegacy2DefaultWallPaper(const WallPaper &paper);
2021-08-31 19:10:39 +00:00
[[nodiscard]] bool IsLegacy3DefaultWallPaper(const WallPaper &paper);
[[nodiscard]] bool IsLegacy4DefaultWallPaper(const WallPaper &paper);
2019-02-08 16:20:08 +00:00
[[nodiscard]] WallPaper DefaultWallPaper();
[[nodiscard]] bool IsDefaultWallPaper(const WallPaper &paper);
2019-02-08 16:47:02 +00:00
[[nodiscard]] bool IsCloudWallPaper(const WallPaper &paper);
2019-02-08 16:20:08 +00:00
[[nodiscard]] QImage GenerateDitheredGradient(const WallPaper &paper);
2019-02-08 16:20:08 +00:00
namespace details {
[[nodiscard]] WallPaper UninitializedWallPaper();
[[nodiscard]] bool IsUninitializedWallPaper(const WallPaper &paper);
[[nodiscard]] WallPaper TestingThemeWallPaper();
[[nodiscard]] bool IsTestingThemeWallPaper(const WallPaper &paper);
[[nodiscard]] WallPaper TestingDefaultWallPaper();
[[nodiscard]] bool IsTestingDefaultWallPaper(const WallPaper &paper);
[[nodiscard]] WallPaper TestingEditorWallPaper();
[[nodiscard]] bool IsTestingEditorWallPaper(const WallPaper &paper);
} // namespace details
} // namespace Data