/* 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 "data/data_cloud_themes.h" #include "ui/layers/generic_box.h" #include "ui/widgets/checkbox.h" #include "base/unique_qptr.h" #include "base/binary_guard.h" namespace style { struct colorizer; } // namespace style namespace Ui { class PopupMenu; } // namespace Ui namespace Window { class SessionController; namespace Theme { struct EmbeddedScheme; 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 style::colorizer &colorizer); class CloudListCheck final : public Ui::AbstractCheckView { public: using Colors = CloudListColors; explicit CloudListCheck(bool checked); CloudListCheck(const Colors &colors, bool checked); QSize getSize() const override; void paint( QPainter &p, int left, int top, int outerWidth) override; QImage prepareRippleMask() const override; bool checkRippleStartPosition(QPoint position) const override; void setColors(const Colors &colors); private: void paintNotSupported(QPainter &p, int left, int top, int outerWidth); void paintWithColors(QPainter &p, int left, int top, int outerWidth); void checkedChangedHook(anim::type animated) override; void validateBackgroundCache(int width); void ensureContrast(); std::optional _colors; Ui::RadioView _radio; QImage _backgroundFull; QImage _backgroundCache; int _backgroundCacheWidth = -1; }; class CloudList final { public: CloudList( not_null parent, not_null window); void showAll(); [[nodiscard]] rpl::producer empty() const; [[nodiscard]] rpl::producer allShown() const; [[nodiscard]] object_ptr takeWidget(); private: struct Element { Data::CloudTheme theme; not_null check; std::unique_ptr button; std::shared_ptr media; base::binary_guard generating; bool waiting = false; uint64 id() const { return theme.id; } }; void setup(); [[nodiscard]] std::vector collectAll() const; void rebuildUsing(std::vector &&list); bool applyChangesFrom(std::vector &&list); bool removeStaleUsing(const std::vector &list); bool insertTillLimit( const std::vector &list, int limit); void refreshElementUsing(Element &element, const Data::CloudTheme &data); void insert(int index, const Data::CloudTheme &theme); void refreshColors(Element &element); void showMenu(Element &element); void refreshColorsFromDocument(Element &element); void setWaiting(Element &element, bool waiting); void subscribeToDownloadFinished(); int resizeGetHeight(int newWidth); void updateGeometry(); [[nodiscard]] bool amCreator(const Data::CloudTheme &theme) const; [[nodiscard]] int groupValueForId(uint64 id); const not_null _window; object_ptr _owned; const not_null _outer; const std::shared_ptr _group; rpl::variable _showAll = false; rpl::variable _count = 0; std::vector _elements; std::vector _idByGroupValue; base::flat_map _groupValueById; rpl::lifetime _downloadFinishedLifetime; base::unique_qptr _contextMenu; }; } // namespace Theme } // namespace Window