2019-09-03 15:24:51 +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
|
|
|
|
|
|
|
|
#include "boxes/generic_box.h"
|
2019-09-04 15:59:43 +00:00
|
|
|
#include "data/data_cloud_themes.h"
|
2019-09-03 15:24:51 +00:00
|
|
|
#include "ui/widgets/checkbox.h"
|
2019-09-08 17:05:26 +00:00
|
|
|
#include "base/unique_qptr.h"
|
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
class PopupMenu;
|
|
|
|
} // namespace Ui
|
2019-09-03 15:24:51 +00:00
|
|
|
|
|
|
|
namespace Window {
|
|
|
|
|
|
|
|
class SessionController;
|
|
|
|
|
|
|
|
namespace Theme {
|
|
|
|
|
|
|
|
struct EmbeddedScheme;
|
|
|
|
struct Colorizer;
|
|
|
|
|
|
|
|
struct CloudListColors {
|
|
|
|
QImage background;
|
|
|
|
QColor sent;
|
|
|
|
QColor received;
|
|
|
|
QColor radiobuttonInactive;
|
|
|
|
QColor radiobuttonActive;
|
|
|
|
};
|
|
|
|
|
|
|
|
[[nodiscard]] CloudListColors ColorsFromScheme(const EmbeddedScheme &scheme);
|
|
|
|
[[nodiscard]] CloudListColors ColorsFromScheme(
|
|
|
|
const EmbeddedScheme &scheme,
|
|
|
|
const Colorizer &colorizer);
|
|
|
|
|
|
|
|
class CloudListCheck final : public Ui::AbstractCheckView {
|
|
|
|
public:
|
|
|
|
using Colors = CloudListColors;
|
2019-09-04 15:59:43 +00:00
|
|
|
|
|
|
|
explicit CloudListCheck(bool checked);
|
2019-09-03 15:24:51 +00:00
|
|
|
CloudListCheck(const Colors &colors, bool checked);
|
|
|
|
|
|
|
|
QSize getSize() const override;
|
|
|
|
void paint(
|
|
|
|
Painter &p,
|
|
|
|
int left,
|
|
|
|
int top,
|
|
|
|
int outerWidth) override;
|
|
|
|
QImage prepareRippleMask() const override;
|
|
|
|
bool checkRippleStartPosition(QPoint position) const override;
|
|
|
|
|
|
|
|
void setColors(const Colors &colors);
|
|
|
|
|
|
|
|
private:
|
2019-09-04 15:59:43 +00:00
|
|
|
void paintNotSupported(Painter &p, int left, int top, int outerWidth);
|
|
|
|
void paintWithColors(Painter &p, int left, int top, int outerWidth);
|
2019-09-03 15:24:51 +00:00
|
|
|
void checkedChangedHook(anim::type animated) override;
|
2019-09-04 11:20:07 +00:00
|
|
|
void validateBackgroundCache(int width);
|
2019-09-03 15:24:51 +00:00
|
|
|
|
2019-09-04 15:59:43 +00:00
|
|
|
std::optional<Colors> _colors;
|
2019-09-03 15:24:51 +00:00
|
|
|
Ui::RadioView _radio;
|
2019-09-04 11:20:07 +00:00
|
|
|
QImage _backgroundFull;
|
|
|
|
QImage _backgroundCache;
|
|
|
|
int _backgroundCacheWidth = -1;
|
2019-09-03 15:24:51 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-09-04 15:59:43 +00:00
|
|
|
class CloudList final {
|
|
|
|
public:
|
|
|
|
CloudList(
|
|
|
|
not_null<QWidget*> parent,
|
|
|
|
not_null<Window::SessionController*> window);
|
|
|
|
|
|
|
|
void showAll();
|
|
|
|
[[nodiscard]] rpl::producer<bool> empty() const;
|
|
|
|
[[nodiscard]] rpl::producer<bool> allShown() const;
|
|
|
|
[[nodiscard]] object_ptr<Ui::RpWidget> takeWidget();
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct Element {
|
|
|
|
Data::CloudTheme theme;
|
|
|
|
not_null<CloudListCheck*> check;
|
|
|
|
std::unique_ptr<Ui::Radiobutton> button;
|
2019-09-09 06:59:57 +00:00
|
|
|
base::binary_guard generating;
|
2019-09-04 15:59:43 +00:00
|
|
|
bool waiting = false;
|
|
|
|
|
|
|
|
uint64 id() const {
|
|
|
|
return theme.id;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
void setup();
|
|
|
|
[[nodiscard]] std::vector<Data::CloudTheme> collectAll() const;
|
|
|
|
void rebuildUsing(std::vector<Data::CloudTheme> &&list);
|
|
|
|
bool applyChangesFrom(std::vector<Data::CloudTheme> &&list);
|
|
|
|
bool removeStaleUsing(const std::vector<Data::CloudTheme> &list);
|
|
|
|
bool insertTillLimit(
|
|
|
|
const std::vector<Data::CloudTheme> &list,
|
|
|
|
int limit);
|
|
|
|
void refreshElementUsing(Element &element, const Data::CloudTheme &data);
|
|
|
|
void insert(int index, const Data::CloudTheme &theme);
|
|
|
|
void refreshColors(Element &element);
|
2019-09-08 17:05:26 +00:00
|
|
|
void showMenu(Element &element);
|
2019-09-04 15:59:43 +00:00
|
|
|
void refreshColorsFromDocument(
|
|
|
|
Element &element,
|
|
|
|
not_null<DocumentData*> document);
|
|
|
|
void setWaiting(Element &element, bool waiting);
|
|
|
|
void subscribeToDownloadFinished();
|
|
|
|
int resizeGetHeight(int newWidth);
|
|
|
|
void updateGeometry();
|
|
|
|
|
2019-09-05 10:51:36 +00:00
|
|
|
[[nodiscard]] bool amCreator(const Data::CloudTheme &theme) const;
|
2019-09-04 15:59:43 +00:00
|
|
|
[[nodiscard]] int groupValueForId(uint64 id);
|
|
|
|
|
|
|
|
const not_null<Window::SessionController*> _window;
|
|
|
|
object_ptr<Ui::RpWidget> _owned;
|
|
|
|
const not_null<Ui::RpWidget*> _outer;
|
|
|
|
const std::shared_ptr<Ui::RadiobuttonGroup> _group;
|
|
|
|
rpl::variable<bool> _showAll = false;
|
|
|
|
rpl::variable<int> _count = 0;
|
|
|
|
std::vector<Element> _elements;
|
|
|
|
std::vector<uint64> _idByGroupValue;
|
|
|
|
base::flat_map<uint64, int> _groupValueById;
|
|
|
|
rpl::lifetime _downloadFinishedLifetime;
|
2019-09-08 17:05:26 +00:00
|
|
|
base::unique_qptr<Ui::PopupMenu> _contextMenu;
|
2019-09-04 15:59:43 +00:00
|
|
|
|
|
|
|
};
|
2019-09-03 15:24:51 +00:00
|
|
|
|
|
|
|
} // namespace Theme
|
|
|
|
} // namespace Window
|