From f3ba8fea571f9edc81d55d365865bb81eaa3a821 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 8 Aug 2023 19:32:13 +0200 Subject: [PATCH] Support vertical attach modify buttons layout. --- .../chat_helpers/chat_helpers.style | 1 + .../ui/chat/attach/attach_album_thumbnail.cpp | 33 +++++++++++-------- .../ui/chat/attach/attach_album_thumbnail.h | 3 +- .../ui/chat/attach/attach_controls.cpp | 29 ++++++++++++---- .../ui/chat/attach/attach_controls.h | 3 ++ 5 files changed, 48 insertions(+), 21 deletions(-) diff --git a/Telegram/SourceFiles/chat_helpers/chat_helpers.style b/Telegram/SourceFiles/chat_helpers/chat_helpers.style index e791a7a35..aa5e8bdac 100644 --- a/Telegram/SourceFiles/chat_helpers/chat_helpers.style +++ b/Telegram/SourceFiles/chat_helpers/chat_helpers.style @@ -508,6 +508,7 @@ sendBoxAlbumGroupSkipRight: 5px; sendBoxAlbumGroupSkipTop: 5px; sendBoxAlbumGroupRadius: 4px; sendBoxAlbumGroupSize: size(62px, 25px); +sendBoxAlbumGroupSizeVertical: size(30px, 50px); sendBoxAlbumSmallGroupSize: size(30px, 25px); sendBoxFileGroupSkipTop: 2px; diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_album_thumbnail.cpp b/Telegram/SourceFiles/ui/chat/attach/attach_album_thumbnail.cpp index 2f847c7c0..3c8f155d6 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_album_thumbnail.cpp +++ b/Telegram/SourceFiles/ui/chat/attach/attach_album_thumbnail.cpp @@ -259,8 +259,7 @@ void AlbumThumbnail::paintInAlbum( _lastRectOfButtons = paintButtons( p, - geometry.topLeft(), - geometry.width(), + geometry, shrinkProgress); _lastRectOfModify = geometry; } @@ -460,8 +459,7 @@ void AlbumThumbnail::paintPhoto(Painter &p, int left, int top, int outerWidth) { _lastRectOfButtons = paintButtons( p, - topLeft, - st::sendMediaPreviewSize, + QRect(left, top, st::sendMediaPreviewSize, size.height()), 0); _lastRectOfModify = QRect(topLeft, size); @@ -521,7 +519,9 @@ AttachButtonType AlbumThumbnail::buttonTypeFromPoint(QPoint position) const { } return (!_lastRectOfButtons.contains(position) && !_isCompressedSticker) ? AttachButtonType::Modify - : (position.x() < _lastRectOfButtons.center().x()) + : (_buttons.vertical() + ? (position.y() < _lastRectOfButtons.center().y()) + : (position.x() < _lastRectOfButtons.center().x())) ? AttachButtonType::Edit : AttachButtonType::Delete; } @@ -585,24 +585,31 @@ void AlbumThumbnail::finishAnimations() { QRect AlbumThumbnail::paintButtons( QPainter &p, - QPoint point, - int outerWidth, + QRect geometry, float64 shrinkProgress) { const auto &skipRight = st::sendBoxAlbumGroupSkipRight; const auto &skipTop = st::sendBoxAlbumGroupSkipTop; - const auto groupWidth = _buttons.width(); - - // If the width is tiny, it would be better to not display the buttons. - if (groupWidth > outerWidth) { + const auto outerWidth = geometry.width(); + const auto outerHeight = geometry.height(); + if (st::sendBoxAlbumGroupSize.width() <= outerWidth) { + _buttons.setVertical(false); + } else if (st::sendBoxAlbumGroupSize.height() <= outerHeight) { + _buttons.setVertical(true); + } else { + // If the size is tiny, skip the buttons. return QRect(); } + const auto groupWidth = _buttons.width(); + const auto groupHeight = _buttons.height(); // If the width is too small, // it would be better to display the buttons in the center. - const auto groupX = point.x() + ((groupWidth + skipRight * 2 > outerWidth) + const auto groupX = geometry.x() + ((groupWidth + skipRight * 2 > outerWidth) ? (outerWidth - groupWidth) / 2 : outerWidth - skipRight - groupWidth); - const auto groupY = point.y() + skipTop; + const auto groupY = geometry.y() + ((groupHeight + skipTop * 2 > outerHeight) + ? (outerHeight - groupHeight) / 2 + : skipTop); const auto opacity = p.opacity(); p.setOpacity(1.0 - shrinkProgress); diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_album_thumbnail.h b/Telegram/SourceFiles/ui/chat/attach/attach_album_thumbnail.h index c3ffac584..1bfd8fc62 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_album_thumbnail.h +++ b/Telegram/SourceFiles/ui/chat/attach/attach_album_thumbnail.h @@ -78,8 +78,7 @@ private: void drawSimpleFrame(QPainter &p, QRect to, QSize size) const; QRect paintButtons( QPainter &p, - QPoint point, - int outerWidth, + QRect geometry, float64 shrinkProgress); void paintPlayVideo(QPainter &p, QRect geometry); diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_controls.cpp b/Telegram/SourceFiles/ui/chat/attach/attach_controls.cpp index 7ad686350..775218a87 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_controls.cpp +++ b/Telegram/SourceFiles/ui/chat/attach/attach_controls.cpp @@ -25,10 +25,15 @@ void AttachControls::paint(QPainter &p, int x, int y) { if (full) { const auto groupHalfWidth = groupWidth / 2; - QRect leftRect(x, y, groupHalfWidth, groupHeight); - st::sendBoxAlbumGroupButtonMediaEdit.paintInCenter(p, leftRect); - QRect rightRect(x + groupHalfWidth, y, groupHalfWidth, groupHeight); - st::sendBoxAlbumGroupButtonMediaDelete.paintInCenter(p, rightRect); + const auto groupHalfHeight = groupHeight / 2; + const auto editRect = _vertical + ? QRect(x, y, groupWidth, groupHalfHeight) + : QRect(x, y, groupHalfWidth, groupHeight); + st::sendBoxAlbumGroupButtonMediaEdit.paintInCenter(p, editRect); + const auto deleteRect = _vertical + ? QRect(x, y + groupHalfHeight, groupWidth, groupHalfHeight) + : QRect(x + groupHalfWidth, y, groupHalfWidth, groupHeight); + st::sendBoxAlbumGroupButtonMediaDelete.paintInCenter(p, deleteRect); } else if (_type == Type::EditOnly) { st::sendBoxAlbumButtonMediaEdit.paintInCenter(p, groupRect); } @@ -36,7 +41,9 @@ void AttachControls::paint(QPainter &p, int x, int y) { int AttachControls::width() const { return (_type == Type::Full) - ? st::sendBoxAlbumGroupSize.width() + ? (_vertical + ? st::sendBoxAlbumGroupSizeVertical.width() + : st::sendBoxAlbumGroupSize.width()) : (_type == Type::EditOnly) ? st::sendBoxAlbumSmallGroupSize.width() : 0; @@ -44,7 +51,9 @@ int AttachControls::width() const { int AttachControls::height() const { return (_type == Type::Full) - ? st::sendBoxAlbumGroupSize.height() + ? (_vertical + ? st::sendBoxAlbumGroupSizeVertical.height() + : st::sendBoxAlbumGroupSize.height()) : (_type == Type::EditOnly) ? st::sendBoxAlbumSmallGroupSize.height() : 0; @@ -54,12 +63,20 @@ AttachControls::Type AttachControls::type() const { return _type; } +bool AttachControls::vertical() const { + return _vertical; +} + void AttachControls::setType(Type type) { if (_type != type) { _type = type; } } +void AttachControls::setVertical(bool vertical) { + _vertical = vertical; +} + AttachControlsWidget::AttachControlsWidget( not_null parent, AttachControls::Type type) diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_controls.h b/Telegram/SourceFiles/ui/chat/attach/attach_controls.h index 9b7ad55c5..bf6992774 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_controls.h +++ b/Telegram/SourceFiles/ui/chat/attach/attach_controls.h @@ -25,14 +25,17 @@ public: void paint(QPainter &p, int x, int y); void setType(Type type); + void setVertical(bool vertical); [[nodiscard]] int width() const; [[nodiscard]] int height() const; [[nodiscard]] Type type() const; + [[nodiscard]] bool vertical() const; private: RoundRect _rect; Type _type = Type::Full; + bool _vertical = false; };