From 0690c4f98c28db609a58178dec5fd8539356cf3b Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 29 Mar 2017 18:09:16 +0300 Subject: [PATCH] Move EmojiPanel bottom controls to Controller. Open sticker set by click on the name. Add a delete sticker set button. --- .../SourceFiles/codegen/emoji/generator.cpp | 53 +- .../SourceFiles/codegen/emoji/generator.h | 2 +- Telegram/SourceFiles/core/utils.h | 12 - Telegram/SourceFiles/core/variant.h | 13 + .../stickers/emoji_list_widget.cpp | 123 ++- .../SourceFiles/stickers/emoji_list_widget.h | 24 +- Telegram/SourceFiles/stickers/emoji_panel.cpp | 560 +----------- Telegram/SourceFiles/stickers/emoji_panel.h | 110 +-- .../SourceFiles/stickers/gifs_list_widget.cpp | 68 +- .../SourceFiles/stickers/gifs_list_widget.h | 15 +- Telegram/SourceFiles/stickers/stickers.style | 37 +- .../stickers/stickers_list_widget.cpp | 835 ++++++++++++++---- .../stickers/stickers_list_widget.h | 92 +- Telegram/SourceFiles/ui/emoji_config.cpp | 56 +- Telegram/SourceFiles/ui/emoji_config.h | 24 +- 15 files changed, 1085 insertions(+), 939 deletions(-) diff --git a/Telegram/SourceFiles/codegen/emoji/generator.cpp b/Telegram/SourceFiles/codegen/emoji/generator.cpp index 3917af3da0..34fb95f8c9 100644 --- a/Telegram/SourceFiles/codegen/emoji/generator.cpp +++ b/Telegram/SourceFiles/codegen/emoji/generator.cpp @@ -296,7 +296,7 @@ inline QString ComputeId(Args... args) {\n\ if (!writeInitCode()) { return false; } - if (!writePacks()) { + if (!writeSections()) { return false; } source_->stream() << "\ @@ -391,22 +391,23 @@ void Init() {\n\ return true; } -bool Generator::writePacks() { - constexpr const char *packNames[] = { - "dbiesPeople", - "dbiesNature", - "dbiesFood", - "dbiesActivity", - "dbiesTravel", - "dbiesObjects", - "dbiesSymbols", +bool Generator::writeSections() { + constexpr const char *sectionNames[] = { + "Section::People", + "Section::Nature", + "Section::Food", + "Section::Activity", + "Section::Travel", + "Section::Objects", + "Section::Symbols", }; source_->stream() << "\ \n\ -int GetPackCount(DBIEmojiSection section) {\n\ - switch (section) {\n"; +int GetSectionCount(Section section) {\n\ + switch (section) {\n\ + case Section::Recent: return GetRecent().size();\n"; auto countIndex = 0; - for (auto name : packNames) { + for (auto name : sectionNames) { if (countIndex >= int(data_.categories.size())) { logDataError() << "category " << countIndex << " not found."; return false; @@ -415,21 +416,29 @@ int GetPackCount(DBIEmojiSection section) {\n\ case " << name << ": return " << data_.categories[countIndex++].size() << ";\n"; } source_->stream() << "\ - case dbiesRecent: return GetRecent().size();\n\ }\n\ return 0;\n\ }\n\ \n\ -EmojiPack GetPack(DBIEmojiSection section) {\n\ - switch (section) {\n"; +EmojiPack GetSection(Section section) {\n\ + switch (section) {\n\ + case Section::Recent: {\n\ + auto result = EmojiPack();\n\ + result.reserve(GetRecent().size());\n\ + for (auto &item : GetRecent()) {\n\ + result.push_back(item.first);\n\ + }\n\ + return result;\n\ + } break;\n"; auto index = 0; - for (auto name : packNames) { + for (auto name : sectionNames) { if (index >= int(data_.categories.size())) { logDataError() << "category " << index << " not found."; return false; } auto &category = data_.categories[index++]; source_->stream() << "\ +\n\ case " << name << ": {\n\ static auto result = EmojiPack();\n\ if (result.isEmpty()) {\n\ @@ -441,17 +450,9 @@ EmojiPack GetPack(DBIEmojiSection section) {\n\ source_->stream() << "\ }\n\ return result;\n\ - } break;\n\n"; + } break;\n"; } source_->stream() << "\ - case dbiesRecent: {\n\ - auto result = EmojiPack();\n\ - result.reserve(GetRecent().size());\n\ - for (auto &item : GetRecent()) {\n\ - result.push_back(item.first);\n\ - }\n\ - return result;\n\ - } break;\n\ }\n\ return EmojiPack();\n\ }\n"; diff --git a/Telegram/SourceFiles/codegen/emoji/generator.h b/Telegram/SourceFiles/codegen/emoji/generator.h index 3ea4172965..8205778652 100644 --- a/Telegram/SourceFiles/codegen/emoji/generator.h +++ b/Telegram/SourceFiles/codegen/emoji/generator.h @@ -44,7 +44,7 @@ private: bool writeSource(); bool writeInitCode(); - bool writePacks(); + bool writeSections(); bool writeFindReplace(); bool writeFind(); bool writeFindFromDictionary(const std::map> &dictionary, bool skipPostfixes = false); diff --git a/Telegram/SourceFiles/core/utils.h b/Telegram/SourceFiles/core/utils.h index 72b0e3d4d3..2bc1e051c6 100644 --- a/Telegram/SourceFiles/core/utils.h +++ b/Telegram/SourceFiles/core/utils.h @@ -527,18 +527,6 @@ enum DBIScale { static const int MatrixRowShift = 40000; -enum DBIEmojiSection { - dbiesRecent = -1, - dbiesPeople = 0, - dbiesNature = 1, - dbiesFood = 2, - dbiesActivity = 3, - dbiesTravel = 4, - dbiesObjects = 5, - dbiesSymbols = 6, - dbiesStickers = 666, -}; - enum DBIPlatform { dbipWindows = 0, dbipMac = 1, diff --git a/Telegram/SourceFiles/core/variant.h b/Telegram/SourceFiles/core/variant.h index 4ff51e07bc..963f101178 100644 --- a/Telegram/SourceFiles/core/variant.h +++ b/Telegram/SourceFiles/core/variant.h @@ -28,9 +28,22 @@ namespace base { template using variant = mapbox::util::variant; +template +using optional_variant = variant; + template inline T *get_if(variant *v) { return (v && v->template is()) ? &v->template get_unchecked() : nullptr; } +template +inline const T *get_if(const variant *v) { + return (v && v->template is()) ? &v->template get_unchecked() : nullptr; +} + +template +inline bool is_null_variant(const optional_variant &variant) { + return get_if(&variant) != nullptr; +} + } // namespace base diff --git a/Telegram/SourceFiles/stickers/emoji_list_widget.cpp b/Telegram/SourceFiles/stickers/emoji_list_widget.cpp index 51d59ad220..8c0aba93ee 100644 --- a/Telegram/SourceFiles/stickers/emoji_list_widget.cpp +++ b/Telegram/SourceFiles/stickers/emoji_list_widget.cpp @@ -20,6 +20,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org */ #include "stickers/emoji_list_widget.h" +#include "ui/widgets/buttons.h" #include "styles/style_stickers.h" #include "ui/widgets/shadow.h" #include "lang.h" @@ -33,6 +34,70 @@ constexpr auto kSaveRecentEmojiTimeout = 3000; } // namespace +class EmojiListWidget::Footer : public EmojiPanel::InnerFooter { +public: + Footer(gsl::not_null parent); + + void setCurrentSectionIcon(Section section); + +protected: + void processPanelHideFinished() override; + +private: + void prepareSection(int &left, int top, int _width, Ui::IconButton *sectionIcon, Section section); + void setActiveSection(Section section); + + gsl::not_null _pan; + std::array, kEmojiSectionCount> _sections; + +}; + +EmojiListWidget::Footer::Footer(gsl::not_null parent) : InnerFooter(parent) +, _pan(parent) +, _sections { + object_ptr(this, st::emojiCategoryRecent), + object_ptr(this, st::emojiCategoryPeople), + object_ptr(this, st::emojiCategoryNature), + object_ptr(this, st::emojiCategoryFood), + object_ptr(this, st::emojiCategoryActivity), + object_ptr(this, st::emojiCategoryTravel), + object_ptr(this, st::emojiCategoryObjects), + object_ptr(this, st::emojiCategorySymbols), +} { + auto left = (st::emojiPanWidth - _sections.size() * st::emojiCategory.width) / 2; + for (auto i = 0; i != _sections.size(); ++i) { + auto &button = _sections[i]; + button->moveToLeft(left, 0); + left += button->width(); + button->setClickedCallback([this, value = static_cast
(i)] { setActiveSection(value); }); + } + setCurrentSectionIcon(Section::Recent); +} + +void EmojiListWidget::Footer::processPanelHideFinished() { + setCurrentSectionIcon(Section::Recent); +} + +void EmojiListWidget::Footer::setCurrentSectionIcon(Section section) { + std::array overrides = { + &st::emojiRecentActive, + &st::emojiPeopleActive, + &st::emojiNatureActive, + &st::emojiFoodActive, + &st::emojiActivityActive, + &st::emojiTravelActive, + &st::emojiObjectsActive, + &st::emojiSymbolsActive, + }; + for (auto i = 0; i != _sections.size(); ++i) { + _sections[i]->setIconOverride((section == static_cast
(i)) ? overrides[i] : nullptr); + } +} + +void EmojiListWidget::Footer::setActiveSection(Ui::Emoji::Section section) { + _pan->showEmojiSection(section); +} + EmojiColorPicker::EmojiColorPicker(QWidget *parent) : TWidget(parent) { setMouseTracking(true); @@ -237,19 +302,6 @@ void EmojiColorPicker::drawVariant(Painter &p, int variant) { p.drawPixmapLeft(w.x() + (st::emojiPanSize.width() - (esize / cIntRetinaFactor())) / 2, w.y() + (st::emojiPanSize.height() - (esize / cIntRetinaFactor())) / 2, width(), App::emojiLarge(), QRect(_variants[variant]->x() * esize, _variants[variant]->y() * esize, esize, esize)); } -class EmojiListWidget::Controller : public TWidget { -public: - Controller(gsl::not_null parent); - -private: - gsl::not_null _pan; - -}; - -EmojiListWidget::Controller::Controller(gsl::not_null parent) : TWidget(parent) -, _pan(parent) { -} - EmojiListWidget::EmojiListWidget(QWidget *parent) : Inner(parent) , _picker(this) { resize(st::emojiPanWidth - st::emojiScroll.width - st::buttonRadius, countHeight()); @@ -262,7 +314,7 @@ EmojiListWidget::EmojiListWidget(QWidget *parent) : Inner(parent) _esize = Ui::Emoji::Size(Ui::Emoji::Index() + 1); for (auto i = 0; i != kEmojiSectionCount; ++i) { - _counts[i] = Ui::Emoji::GetPackCount(EmojiSectionAtIndex(i)); + _counts[i] = Ui::Emoji::GetSectionCount(static_cast
(i)); } _showPickerTimer.setSingleShot(true); @@ -271,8 +323,18 @@ EmojiListWidget::EmojiListWidget(QWidget *parent) : Inner(parent) connect(_picker, SIGNAL(hidden()), this, SLOT(onPickerHidden())); } -object_ptr EmojiListWidget::createController() { - return object_ptr(this); +void EmojiListWidget::setVisibleTopBottom(int visibleTop, int visibleBottom) { + Inner::setVisibleTopBottom(visibleTop, visibleBottom); + if (_footer) { + _footer->setCurrentSectionIcon(currentSection(visibleTop)); + } +} + +object_ptr EmojiListWidget::createFooter() { + Expects(_footer == nullptr); + auto result = object_ptr