From 354584e1b1e530288e72644b6c5c2a79809ccef4 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 20 Mar 2022 10:12:03 +0300 Subject: [PATCH] Moved out MultiSelect::Inner from header. --- .../SourceFiles/ui/widgets/multi_select.cpp | 99 +++++++++++++++++++ .../SourceFiles/ui/widgets/multi_select.h | 98 ------------------ 2 files changed, 99 insertions(+), 98 deletions(-) diff --git a/Telegram/SourceFiles/ui/widgets/multi_select.cpp b/Telegram/SourceFiles/ui/widgets/multi_select.cpp index fc4d0dd777..1ea3237252 100644 --- a/Telegram/SourceFiles/ui/widgets/multi_select.cpp +++ b/Telegram/SourceFiles/ui/widgets/multi_select.cpp @@ -23,6 +23,105 @@ constexpr int kWideScale = 3; } // namespace +class MultiSelect::Inner : public TWidget { +public: + using ScrollCallback = Fn; + Inner( + QWidget *parent, + const style::MultiSelect &st, + rpl::producer placeholder, + ScrollCallback callback); + + QString getQuery() const; + bool setInnerFocus(); + void clearQuery(); + + void setQueryChangedCallback(Fn callback); + void setSubmittedCallback(Fn callback); + void setCancelledCallback(Fn callback); + + void addItemInBunch(std::unique_ptr item); + void finishItemsBunch(AddItemWay way); + void setItemText(uint64 itemId, const QString &text); + + void setItemRemovedCallback(Fn callback); + void removeItem(uint64 itemId); + + int getItemsCount() const; + QVector getItems() const; + bool hasItem(uint64 itemId) const; + + void setResizedCallback(Fn callback); + + ~Inner(); + +protected: + int resizeGetHeight(int newWidth) override; + + void paintEvent(QPaintEvent *e) override; + void leaveEventHook(QEvent *e) override; + void mouseMoveEvent(QMouseEvent *e) override; + void mousePressEvent(QMouseEvent *e) override; + void keyPressEvent(QKeyEvent *e) override; + +private: + void submitted(Qt::KeyboardModifiers modifiers); + void cancelled(); + void queryChanged(); + void fieldFocused(); + void computeItemsGeometry(int newWidth); + void updateItemsGeometry(); + void updateFieldGeometry(); + void updateHasAnyItems(bool hasAnyItems); + void updateSelection(QPoint mousePosition); + void clearSelection() { + updateSelection(QPoint(-1, -1)); + } + void updateCursor(); + void updateHeightStep(); + void finishHeightAnimation(); + enum class ChangeActiveWay { + Default, + SkipSetFocus, + }; + void setActiveItem( + int active, + ChangeActiveWay skipSetFocus = ChangeActiveWay::Default); + void setActiveItemPrevious(); + void setActiveItemNext(); + + QMargins itemPaintMargins() const; + + const style::MultiSelect &_st; + Ui::Animations::Simple _iconOpacity; + + ScrollCallback _scrollCallback; + + std::set _idsMap; + std::vector> _items; + std::set> _removingItems; + + int _selected = -1; + int _active = -1; + bool _overDelete = false; + + int _fieldLeft = 0; + int _fieldTop = 0; + int _fieldWidth = 0; + object_ptr _field; + object_ptr _cancel; + + int _newHeight = 0; + Ui::Animations::Simple _height; + + Fn _queryChangedCallback; + Fn _submittedCallback; + Fn _cancelledCallback; + Fn _itemRemovedCallback; + Fn _resizedCallback; + +}; + MultiSelect::Item::Item(const style::MultiSelectItem &st, uint64 id, const QString &text, style::color color, PaintRoundImage &&paintRoundImage) : _st(st) , _id(id) diff --git a/Telegram/SourceFiles/ui/widgets/multi_select.h b/Telegram/SourceFiles/ui/widgets/multi_select.h index 0a0e486803..5a551757cf 100644 --- a/Telegram/SourceFiles/ui/widgets/multi_select.h +++ b/Telegram/SourceFiles/ui/widgets/multi_select.h @@ -74,104 +74,6 @@ private: }; -// This class is hold in header because it requires Qt preprocessing. -class MultiSelect::Inner : public TWidget { -public: - using ScrollCallback = Fn; - Inner( - QWidget *parent, - const style::MultiSelect &st, - rpl::producer placeholder, - ScrollCallback callback); - - QString getQuery() const; - bool setInnerFocus(); - void clearQuery(); - - void setQueryChangedCallback(Fn callback); - void setSubmittedCallback(Fn callback); - void setCancelledCallback(Fn callback); - - void addItemInBunch(std::unique_ptr item); - void finishItemsBunch(AddItemWay way); - void setItemText(uint64 itemId, const QString &text); - - void setItemRemovedCallback(Fn callback); - void removeItem(uint64 itemId); - - int getItemsCount() const; - QVector getItems() const; - bool hasItem(uint64 itemId) const; - - void setResizedCallback(Fn callback); - - ~Inner(); - -protected: - int resizeGetHeight(int newWidth) override; - - void paintEvent(QPaintEvent *e) override; - void leaveEventHook(QEvent *e) override; - void mouseMoveEvent(QMouseEvent *e) override; - void mousePressEvent(QMouseEvent *e) override; - void keyPressEvent(QKeyEvent *e) override; - -private: - void submitted(Qt::KeyboardModifiers modifiers); - void cancelled(); - void queryChanged(); - void fieldFocused(); - void computeItemsGeometry(int newWidth); - void updateItemsGeometry(); - void updateFieldGeometry(); - void updateHasAnyItems(bool hasAnyItems); - void updateSelection(QPoint mousePosition); - void clearSelection() { - updateSelection(QPoint(-1, -1)); - } - void updateCursor(); - void updateHeightStep(); - void finishHeightAnimation(); - enum class ChangeActiveWay { - Default, - SkipSetFocus, - }; - void setActiveItem(int active, ChangeActiveWay skipSetFocus = ChangeActiveWay::Default); - void setActiveItemPrevious(); - void setActiveItemNext(); - - QMargins itemPaintMargins() const; - - const style::MultiSelect &_st; - Ui::Animations::Simple _iconOpacity; - - ScrollCallback _scrollCallback; - - std::set _idsMap; - std::vector> _items; - std::set> _removingItems; - - int _selected = -1; - int _active = -1; - bool _overDelete = false; - - int _fieldLeft = 0; - int _fieldTop = 0; - int _fieldWidth = 0; - object_ptr _field; - object_ptr _cancel; - - int _newHeight = 0; - Ui::Animations::Simple _height; - - Fn _queryChangedCallback; - Fn _submittedCallback; - Fn _cancelledCallback; - Fn _itemRemovedCallback; - Fn _resizedCallback; - -}; - class MultiSelect::Item { public: Item(const style::MultiSelectItem &st, uint64 id, const QString &text, style::color color, PaintRoundImage &&paintRoundImage);