2016-10-28 12:44:28 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-10-28 12:44:28 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-10-28 12:44:28 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2019-01-25 14:37:28 +00:00
|
|
|
class Image;
|
|
|
|
|
2019-01-16 17:26:26 +00:00
|
|
|
namespace Data {
|
|
|
|
|
2019-01-28 13:59:49 +00:00
|
|
|
struct FileOrigin;
|
|
|
|
|
|
|
|
class WallPaper {
|
|
|
|
public:
|
|
|
|
explicit WallPaper(WallPaperId id);
|
|
|
|
|
|
|
|
void setLocalImageAsThumbnail(not_null<Image*> image);
|
|
|
|
|
|
|
|
[[nodiscard]] WallPaperId id() const;
|
|
|
|
[[nodiscard]] std::optional<QColor> backgroundColor() const;
|
|
|
|
[[nodiscard]] DocumentData *document() const;
|
|
|
|
[[nodiscard]] Image *thumbnail() const;
|
2019-01-29 07:29:38 +00:00
|
|
|
[[nodiscard]] bool isPattern() const;
|
|
|
|
[[nodiscard]] bool isDefault() const;
|
|
|
|
[[nodiscard]] bool isCreator() const;
|
2019-02-04 18:37:40 +00:00
|
|
|
[[nodiscard]] bool isDark() const;
|
|
|
|
[[nodiscard]] bool isLocal() const;
|
2019-02-06 14:38:37 +00:00
|
|
|
[[nodiscard]] bool isBlurred() const;
|
2019-01-29 07:29:38 +00:00
|
|
|
[[nodiscard]] int patternIntensity() const;
|
2019-01-28 13:59:49 +00:00
|
|
|
[[nodiscard]] bool hasShareUrl() const;
|
|
|
|
[[nodiscard]] QString shareUrl() const;
|
|
|
|
|
|
|
|
void loadDocument() const;
|
|
|
|
void loadThumbnail() const;
|
|
|
|
[[nodiscard]] FileOrigin fileOrigin() const;
|
|
|
|
|
2019-01-29 07:29:38 +00:00
|
|
|
[[nodiscard]] WallPaper withUrlParams(
|
|
|
|
const QMap<QString, QString> ¶ms) const;
|
|
|
|
|
2019-01-28 13:59:49 +00:00
|
|
|
[[nodiscard]] static std::optional<WallPaper> Create(
|
|
|
|
const MTPWallPaper &data);
|
|
|
|
[[nodiscard]] static std::optional<WallPaper> Create(
|
|
|
|
const MTPDwallPaper &data);
|
|
|
|
|
|
|
|
[[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);
|
|
|
|
[[nodiscard]] static std::optional<WallPaper> FromColorSlug(
|
|
|
|
const QString &slug);
|
|
|
|
|
|
|
|
private:
|
2019-01-29 07:29:38 +00:00
|
|
|
static constexpr auto kDefaultIntensity = 40;
|
|
|
|
|
2019-01-28 13:59:49 +00:00
|
|
|
WallPaperId _id = WallPaperId();
|
|
|
|
uint64 _accessHash = 0;
|
|
|
|
MTPDwallPaper::Flags _flags;
|
|
|
|
QString _slug;
|
|
|
|
|
|
|
|
MTPDwallPaperSettings::Flags _settings;
|
|
|
|
std::optional<QColor> _backgroundColor;
|
2019-01-29 07:29:38 +00:00
|
|
|
int _intensity = kDefaultIntensity;
|
2019-01-28 13:59:49 +00:00
|
|
|
|
|
|
|
DocumentData *_document = nullptr;
|
|
|
|
Image *_thumbnail = nullptr;
|
|
|
|
|
2019-01-16 17:26:26 +00:00
|
|
|
};
|
|
|
|
|
2019-01-28 13:59:49 +00:00
|
|
|
[[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);
|
|
|
|
[[nodiscard]] WallPaper DefaultWallPaper();
|
|
|
|
[[nodiscard]] bool IsDefaultWallPaper(const WallPaper &paper);
|
2019-01-16 17:26:26 +00:00
|
|
|
|
2019-01-29 16:26:19 +00:00
|
|
|
QColor PatternColor(QColor background);
|
|
|
|
QImage PreparePatternImage(
|
|
|
|
QImage image,
|
|
|
|
QColor bg,
|
|
|
|
QColor fg,
|
|
|
|
int intensity);
|
2019-02-06 14:38:37 +00:00
|
|
|
QImage PrepareBlurredBackground(QImage image);
|
2019-01-29 16:26:19 +00:00
|
|
|
|
2019-01-16 17:26:26 +00:00
|
|
|
namespace details {
|
2016-10-28 12:44:28 +00:00
|
|
|
|
2019-01-28 13:59:49 +00:00
|
|
|
[[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);
|
2016-10-28 12:44:28 +00:00
|
|
|
|
2019-01-16 17:26:26 +00:00
|
|
|
} // namespace details
|
2019-01-28 13:59:49 +00:00
|
|
|
} // namespace Data
|
2016-10-28 12:44:28 +00:00
|
|
|
|
2019-01-28 13:59:49 +00:00
|
|
|
namespace Window {
|
|
|
|
namespace Theme {
|
2016-10-28 12:44:28 +00:00
|
|
|
|
2019-01-17 08:18:23 +00:00
|
|
|
constexpr auto kMinimumTiledSize = 512;
|
|
|
|
|
2016-10-28 12:44:28 +00:00
|
|
|
struct Cached {
|
|
|
|
QByteArray colors;
|
|
|
|
QByteArray background;
|
|
|
|
bool tiled = false;
|
|
|
|
int32 paletteChecksum = 0;
|
|
|
|
int32 contentChecksum = 0;
|
|
|
|
};
|
2018-07-19 14:58:40 +00:00
|
|
|
struct Saved {
|
|
|
|
QString pathRelative;
|
|
|
|
QString pathAbsolute;
|
|
|
|
QByteArray content;
|
|
|
|
Cached cache;
|
|
|
|
};
|
|
|
|
bool Load(Saved &&saved);
|
2016-10-28 12:44:28 +00:00
|
|
|
void Unload();
|
|
|
|
|
|
|
|
struct Instance {
|
|
|
|
style::palette palette;
|
|
|
|
QImage background;
|
|
|
|
Cached cached;
|
|
|
|
bool tiled = false;
|
|
|
|
};
|
2016-12-23 13:21:01 +00:00
|
|
|
|
|
|
|
struct Preview {
|
2018-07-19 14:58:40 +00:00
|
|
|
QString pathRelative;
|
|
|
|
QString pathAbsolute;
|
2016-12-23 13:21:01 +00:00
|
|
|
Instance instance;
|
|
|
|
QByteArray content;
|
2018-01-02 19:10:49 +00:00
|
|
|
QImage preview;
|
2016-12-23 13:21:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
bool Apply(const QString &filepath);
|
2017-02-21 13:45:56 +00:00
|
|
|
bool Apply(std::unique_ptr<Preview> preview);
|
2018-09-26 11:28:16 +00:00
|
|
|
void ApplyDefaultWithPath(const QString &themePath);
|
2017-02-03 20:07:26 +00:00
|
|
|
bool ApplyEditedPalette(const QString &path, const QByteArray &content);
|
2016-12-23 13:21:01 +00:00
|
|
|
void KeepApplied();
|
2018-07-19 14:58:40 +00:00
|
|
|
QString NightThemePath();
|
2019-01-17 08:18:23 +00:00
|
|
|
[[nodiscard]] bool IsNightMode();
|
2018-07-19 14:58:40 +00:00
|
|
|
void SetNightModeValue(bool nightMode);
|
|
|
|
void ToggleNightMode();
|
2018-09-26 11:28:16 +00:00
|
|
|
void ToggleNightMode(const QString &themePath);
|
2019-01-17 08:18:23 +00:00
|
|
|
[[nodiscard]] bool IsNonDefaultBackground();
|
2016-12-23 13:21:01 +00:00
|
|
|
void Revert();
|
|
|
|
|
2016-10-28 12:44:28 +00:00
|
|
|
bool LoadFromFile(const QString &file, Instance *out, QByteArray *outContent);
|
2017-02-03 20:07:26 +00:00
|
|
|
bool IsPaletteTestingPath(const QString &path);
|
2019-01-29 17:03:51 +00:00
|
|
|
QColor CountAverageColor(const QImage &image);
|
|
|
|
QColor AdjustedColor(QColor original, QColor background);
|
2019-02-04 15:53:00 +00:00
|
|
|
QImage ProcessBackgroundImage(QImage image);
|
2016-10-28 12:44:28 +00:00
|
|
|
|
|
|
|
struct BackgroundUpdate {
|
|
|
|
enum class Type {
|
|
|
|
New,
|
|
|
|
Changed,
|
|
|
|
Start,
|
2016-11-02 14:44:33 +00:00
|
|
|
TestingTheme,
|
|
|
|
RevertingTheme,
|
|
|
|
ApplyingTheme,
|
2016-10-28 12:44:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
BackgroundUpdate(Type type, bool tiled) : type(type), tiled(tiled) {
|
|
|
|
}
|
2016-12-23 13:21:01 +00:00
|
|
|
bool paletteChanged() const {
|
|
|
|
return (type == Type::TestingTheme || type == Type::RevertingTheme);
|
|
|
|
}
|
2016-10-28 12:44:28 +00:00
|
|
|
Type type;
|
|
|
|
bool tiled;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ChatBackground : public base::Observable<BackgroundUpdate> {
|
|
|
|
public:
|
2018-07-21 13:54:00 +00:00
|
|
|
ChatBackground();
|
|
|
|
|
2016-10-28 12:44:28 +00:00
|
|
|
// This method is allowed to (and should) be called before start().
|
|
|
|
void setThemeData(QImage &&themeImage, bool themeTile);
|
|
|
|
|
|
|
|
// This method is setting the default (themed) image if none was set yet.
|
|
|
|
void start();
|
2019-01-29 10:57:29 +00:00
|
|
|
void set(const Data::WallPaper &paper, QImage image = QImage());
|
2016-10-28 12:44:28 +00:00
|
|
|
void setTile(bool tile);
|
2018-07-19 14:58:40 +00:00
|
|
|
void setTileDayValue(bool tile);
|
|
|
|
void setTileNightValue(bool tile);
|
|
|
|
void setThemeAbsolutePath(const QString &path);
|
2019-01-17 08:18:23 +00:00
|
|
|
[[nodiscard]] QString themeAbsolutePath() const;
|
2016-11-02 14:44:33 +00:00
|
|
|
void reset();
|
|
|
|
|
2018-07-21 13:54:00 +00:00
|
|
|
void setTestingTheme(Instance &&theme);
|
|
|
|
void saveAdjustableColors();
|
2016-12-20 13:03:51 +00:00
|
|
|
void setTestingDefaultTheme();
|
2016-11-02 14:44:33 +00:00
|
|
|
void revert();
|
2016-10-28 12:44:28 +00:00
|
|
|
|
2019-01-28 13:59:49 +00:00
|
|
|
[[nodiscard]] WallPaperId id() const {
|
|
|
|
return _paper.id();
|
|
|
|
}
|
2019-01-17 08:18:23 +00:00
|
|
|
[[nodiscard]] const QPixmap &pixmap() const {
|
2017-01-01 16:45:20 +00:00
|
|
|
return _pixmap;
|
|
|
|
}
|
2019-01-17 08:18:23 +00:00
|
|
|
[[nodiscard]] const QPixmap &pixmapForTiled() const {
|
2017-01-01 16:45:20 +00:00
|
|
|
return _pixmapForTiled;
|
|
|
|
}
|
2019-01-29 07:29:38 +00:00
|
|
|
[[nodiscard]] std::optional<QColor> colorForFill() const;
|
2019-01-17 08:18:23 +00:00
|
|
|
[[nodiscard]] QImage createCurrentImage() const;
|
|
|
|
[[nodiscard]] bool tile() const;
|
|
|
|
[[nodiscard]] bool tileDay() const;
|
|
|
|
[[nodiscard]] bool tileNight() const;
|
2016-10-28 12:44:28 +00:00
|
|
|
|
|
|
|
private:
|
2018-07-21 13:54:00 +00:00
|
|
|
struct AdjustableColor {
|
|
|
|
AdjustableColor(style::color data);
|
|
|
|
|
|
|
|
style::color item;
|
|
|
|
QColor original;
|
|
|
|
};
|
|
|
|
|
2016-11-02 14:44:33 +00:00
|
|
|
void ensureStarted();
|
|
|
|
void saveForRevert();
|
2019-01-29 10:57:29 +00:00
|
|
|
void setPreparedImage(QImage original, QImage prepared);
|
|
|
|
void preparePixmaps(QImage image);
|
2016-11-02 14:44:33 +00:00
|
|
|
void writeNewBackgroundSettings();
|
2019-01-17 08:18:23 +00:00
|
|
|
void setPaper(const Data::WallPaper &paper);
|
2016-10-28 12:44:28 +00:00
|
|
|
|
2019-01-17 08:18:23 +00:00
|
|
|
[[nodiscard]] bool adjustPaletteRequired();
|
2019-01-29 10:57:29 +00:00
|
|
|
void adjustPaletteUsingBackground(const QImage &image);
|
2019-01-17 08:18:23 +00:00
|
|
|
void adjustPaletteUsingColor(QColor color);
|
2018-07-21 13:54:00 +00:00
|
|
|
void restoreAdjustableColors();
|
|
|
|
|
2018-07-19 14:58:40 +00:00
|
|
|
void setNightModeValue(bool nightMode);
|
2019-01-17 08:18:23 +00:00
|
|
|
[[nodiscard]] bool nightMode() const;
|
2018-09-26 11:28:16 +00:00
|
|
|
void toggleNightMode(std::optional<QString> themePath);
|
2018-07-19 14:58:40 +00:00
|
|
|
void keepApplied(const QString &path, bool write);
|
2019-01-17 08:18:23 +00:00
|
|
|
[[nodiscard]] bool isNonDefaultThemeOrBackground();
|
|
|
|
[[nodiscard]] bool isNonDefaultBackground();
|
2018-07-19 14:58:40 +00:00
|
|
|
|
|
|
|
friend bool IsNightMode();
|
|
|
|
friend void SetNightModeValue(bool nightMode);
|
|
|
|
friend void ToggleNightMode();
|
2018-09-26 11:28:16 +00:00
|
|
|
friend void ToggleNightMode(const QString &themePath);
|
2018-07-19 14:58:40 +00:00
|
|
|
friend void KeepApplied();
|
2018-09-26 11:28:16 +00:00
|
|
|
friend bool IsNonDefaultBackground();
|
2018-07-19 14:58:40 +00:00
|
|
|
|
2019-01-28 13:59:49 +00:00
|
|
|
Data::WallPaper _paper = Data::details::UninitializedWallPaper();
|
2019-01-17 08:18:23 +00:00
|
|
|
std::optional<QColor> _paperColor;
|
2019-01-29 10:57:29 +00:00
|
|
|
QImage _original;
|
2017-01-01 16:45:20 +00:00
|
|
|
QPixmap _pixmap;
|
|
|
|
QPixmap _pixmapForTiled;
|
2018-07-19 14:58:40 +00:00
|
|
|
bool _nightMode = false;
|
|
|
|
bool _tileDayValue = false;
|
|
|
|
bool _tileNightValue = true;
|
2016-10-28 12:44:28 +00:00
|
|
|
|
2018-07-19 14:58:40 +00:00
|
|
|
QString _themeAbsolutePath;
|
2016-10-28 12:44:28 +00:00
|
|
|
QImage _themeImage;
|
|
|
|
bool _themeTile = false;
|
|
|
|
|
2019-01-28 13:59:49 +00:00
|
|
|
Data::WallPaper _paperForRevert
|
|
|
|
= Data::details::UninitializedWallPaper();
|
2019-01-29 10:57:29 +00:00
|
|
|
QImage _originalForRevert;
|
2016-11-02 14:44:33 +00:00
|
|
|
bool _tileForRevert = false;
|
|
|
|
|
2018-07-21 13:54:00 +00:00
|
|
|
std::vector<AdjustableColor> _adjustableColors;
|
|
|
|
|
2016-10-28 12:44:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ChatBackground *Background();
|
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
void ComputeBackgroundRects(QRect wholeFill, QSize imageSize, QRect &to, QRect &from);
|
|
|
|
|
2017-02-03 20:07:26 +00:00
|
|
|
bool CopyColorsToPalette(const QString &path, const QByteArray &themeContent);
|
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
bool ReadPaletteValues(const QByteArray &content, Fn<bool(QLatin1String name, QLatin1String value)> callback);
|
2017-02-03 20:07:26 +00:00
|
|
|
|
2016-10-28 12:44:28 +00:00
|
|
|
} // namespace Theme
|
|
|
|
} // namespace Window
|