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
|
|
|
|
|
|
|
|
namespace Window {
|
|
|
|
namespace Theme {
|
|
|
|
namespace internal {
|
|
|
|
|
2016-11-02 14:44:33 +00:00
|
|
|
constexpr int32 kUninitializedBackground = -999;
|
|
|
|
constexpr int32 kTestingThemeBackground = -666;
|
|
|
|
constexpr int32 kTestingDefaultBackground = -665;
|
2017-02-03 20:07:26 +00:00
|
|
|
constexpr int32 kTestingEditorBackground = -664;
|
2016-10-28 12:44:28 +00:00
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
|
|
|
|
constexpr int32 kThemeBackground = -2;
|
|
|
|
constexpr int32 kCustomBackground = -1;
|
2016-11-07 15:24:28 +00:00
|
|
|
constexpr int32 kInitialBackground = 0;
|
|
|
|
constexpr int32 kDefaultBackground = 105;
|
2016-10-28 12:44:28 +00:00
|
|
|
|
|
|
|
struct Cached {
|
|
|
|
QByteArray colors;
|
|
|
|
QByteArray background;
|
|
|
|
bool tiled = false;
|
|
|
|
int32 paletteChecksum = 0;
|
|
|
|
int32 contentChecksum = 0;
|
|
|
|
};
|
|
|
|
bool Load(const QString &pathRelative, const QString &pathAbsolute, const QByteArray &content, Cached &cache);
|
|
|
|
void Unload();
|
|
|
|
|
|
|
|
struct Instance {
|
|
|
|
style::palette palette;
|
|
|
|
QImage background;
|
|
|
|
Cached cached;
|
|
|
|
bool tiled = false;
|
|
|
|
};
|
2016-12-23 13:21:01 +00:00
|
|
|
|
|
|
|
struct Preview {
|
|
|
|
QString path;
|
|
|
|
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);
|
2016-12-23 13:21:01 +00:00
|
|
|
void ApplyDefault();
|
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();
|
2017-06-29 19:09:10 +00:00
|
|
|
bool IsNonDefaultUsed();
|
|
|
|
bool IsNightTheme();
|
|
|
|
void SwitchNightTheme(bool enabled);
|
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);
|
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:
|
|
|
|
// 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();
|
|
|
|
void setImage(int32 id, QImage &&image = QImage());
|
|
|
|
void setTile(bool tile);
|
2016-11-02 14:44:33 +00:00
|
|
|
void reset();
|
|
|
|
|
2017-06-30 12:03:51 +00:00
|
|
|
enum class ChangeMode {
|
|
|
|
SwitchToThemeBackground,
|
|
|
|
LeaveCurrentCustomBackground,
|
|
|
|
};
|
|
|
|
void setTestingTheme(Instance &&theme, ChangeMode mode = ChangeMode::SwitchToThemeBackground);
|
2016-12-20 13:03:51 +00:00
|
|
|
void setTestingDefaultTheme();
|
2016-11-02 14:44:33 +00:00
|
|
|
void keepApplied();
|
|
|
|
void revert();
|
2016-10-28 12:44:28 +00:00
|
|
|
|
|
|
|
int32 id() const;
|
2017-01-01 16:45:20 +00:00
|
|
|
const QPixmap &pixmap() const {
|
|
|
|
return _pixmap;
|
|
|
|
}
|
|
|
|
const QPixmap &pixmapForTiled() const {
|
|
|
|
return _pixmapForTiled;
|
|
|
|
}
|
2016-10-28 12:44:28 +00:00
|
|
|
bool tile() const;
|
2016-11-02 14:44:33 +00:00
|
|
|
bool tileForSave() const;
|
2016-10-28 12:44:28 +00:00
|
|
|
|
|
|
|
private:
|
2016-11-02 14:44:33 +00:00
|
|
|
void ensureStarted();
|
|
|
|
void saveForRevert();
|
2016-10-28 12:44:28 +00:00
|
|
|
void setPreparedImage(QImage &&image);
|
2016-11-02 14:44:33 +00:00
|
|
|
void writeNewBackgroundSettings();
|
2016-10-28 12:44:28 +00:00
|
|
|
|
|
|
|
int32 _id = internal::kUninitializedBackground;
|
2017-01-01 16:45:20 +00:00
|
|
|
QPixmap _pixmap;
|
|
|
|
QPixmap _pixmapForTiled;
|
2016-10-28 12:44:28 +00:00
|
|
|
bool _tile = false;
|
|
|
|
|
|
|
|
QImage _themeImage;
|
|
|
|
bool _themeTile = false;
|
|
|
|
|
2016-11-02 14:44:33 +00:00
|
|
|
int32 _idForRevert = internal::kUninitializedBackground;
|
|
|
|
QImage _imageForRevert;
|
|
|
|
bool _tileForRevert = false;
|
|
|
|
|
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
|