Support vertical attach modify buttons layout.

This commit is contained in:
John Preston 2023-08-08 19:32:13 +02:00
parent 38941eb3c8
commit f3ba8fea57
5 changed files with 48 additions and 21 deletions

View file

@ -508,6 +508,7 @@ sendBoxAlbumGroupSkipRight: 5px;
sendBoxAlbumGroupSkipTop: 5px; sendBoxAlbumGroupSkipTop: 5px;
sendBoxAlbumGroupRadius: 4px; sendBoxAlbumGroupRadius: 4px;
sendBoxAlbumGroupSize: size(62px, 25px); sendBoxAlbumGroupSize: size(62px, 25px);
sendBoxAlbumGroupSizeVertical: size(30px, 50px);
sendBoxAlbumSmallGroupSize: size(30px, 25px); sendBoxAlbumSmallGroupSize: size(30px, 25px);
sendBoxFileGroupSkipTop: 2px; sendBoxFileGroupSkipTop: 2px;

View file

@ -259,8 +259,7 @@ void AlbumThumbnail::paintInAlbum(
_lastRectOfButtons = paintButtons( _lastRectOfButtons = paintButtons(
p, p,
geometry.topLeft(), geometry,
geometry.width(),
shrinkProgress); shrinkProgress);
_lastRectOfModify = geometry; _lastRectOfModify = geometry;
} }
@ -460,8 +459,7 @@ void AlbumThumbnail::paintPhoto(Painter &p, int left, int top, int outerWidth) {
_lastRectOfButtons = paintButtons( _lastRectOfButtons = paintButtons(
p, p,
topLeft, QRect(left, top, st::sendMediaPreviewSize, size.height()),
st::sendMediaPreviewSize,
0); 0);
_lastRectOfModify = QRect(topLeft, size); _lastRectOfModify = QRect(topLeft, size);
@ -521,7 +519,9 @@ AttachButtonType AlbumThumbnail::buttonTypeFromPoint(QPoint position) const {
} }
return (!_lastRectOfButtons.contains(position) && !_isCompressedSticker) return (!_lastRectOfButtons.contains(position) && !_isCompressedSticker)
? AttachButtonType::Modify ? AttachButtonType::Modify
: (position.x() < _lastRectOfButtons.center().x()) : (_buttons.vertical()
? (position.y() < _lastRectOfButtons.center().y())
: (position.x() < _lastRectOfButtons.center().x()))
? AttachButtonType::Edit ? AttachButtonType::Edit
: AttachButtonType::Delete; : AttachButtonType::Delete;
} }
@ -585,24 +585,31 @@ void AlbumThumbnail::finishAnimations() {
QRect AlbumThumbnail::paintButtons( QRect AlbumThumbnail::paintButtons(
QPainter &p, QPainter &p,
QPoint point, QRect geometry,
int outerWidth,
float64 shrinkProgress) { float64 shrinkProgress) {
const auto &skipRight = st::sendBoxAlbumGroupSkipRight; const auto &skipRight = st::sendBoxAlbumGroupSkipRight;
const auto &skipTop = st::sendBoxAlbumGroupSkipTop; const auto &skipTop = st::sendBoxAlbumGroupSkipTop;
const auto groupWidth = _buttons.width(); const auto outerWidth = geometry.width();
const auto outerHeight = geometry.height();
// If the width is tiny, it would be better to not display the buttons. if (st::sendBoxAlbumGroupSize.width() <= outerWidth) {
if (groupWidth > outerWidth) { _buttons.setVertical(false);
} else if (st::sendBoxAlbumGroupSize.height() <= outerHeight) {
_buttons.setVertical(true);
} else {
// If the size is tiny, skip the buttons.
return QRect(); return QRect();
} }
const auto groupWidth = _buttons.width();
const auto groupHeight = _buttons.height();
// If the width is too small, // If the width is too small,
// it would be better to display the buttons in the center. // 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 - groupWidth) / 2
: outerWidth - skipRight - groupWidth); : 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(); const auto opacity = p.opacity();
p.setOpacity(1.0 - shrinkProgress); p.setOpacity(1.0 - shrinkProgress);

View file

@ -78,8 +78,7 @@ private:
void drawSimpleFrame(QPainter &p, QRect to, QSize size) const; void drawSimpleFrame(QPainter &p, QRect to, QSize size) const;
QRect paintButtons( QRect paintButtons(
QPainter &p, QPainter &p,
QPoint point, QRect geometry,
int outerWidth,
float64 shrinkProgress); float64 shrinkProgress);
void paintPlayVideo(QPainter &p, QRect geometry); void paintPlayVideo(QPainter &p, QRect geometry);

View file

@ -25,10 +25,15 @@ void AttachControls::paint(QPainter &p, int x, int y) {
if (full) { if (full) {
const auto groupHalfWidth = groupWidth / 2; const auto groupHalfWidth = groupWidth / 2;
QRect leftRect(x, y, groupHalfWidth, groupHeight); const auto groupHalfHeight = groupHeight / 2;
st::sendBoxAlbumGroupButtonMediaEdit.paintInCenter(p, leftRect); const auto editRect = _vertical
QRect rightRect(x + groupHalfWidth, y, groupHalfWidth, groupHeight); ? QRect(x, y, groupWidth, groupHalfHeight)
st::sendBoxAlbumGroupButtonMediaDelete.paintInCenter(p, rightRect); : 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) { } else if (_type == Type::EditOnly) {
st::sendBoxAlbumButtonMediaEdit.paintInCenter(p, groupRect); st::sendBoxAlbumButtonMediaEdit.paintInCenter(p, groupRect);
} }
@ -36,7 +41,9 @@ void AttachControls::paint(QPainter &p, int x, int y) {
int AttachControls::width() const { int AttachControls::width() const {
return (_type == Type::Full) return (_type == Type::Full)
? st::sendBoxAlbumGroupSize.width() ? (_vertical
? st::sendBoxAlbumGroupSizeVertical.width()
: st::sendBoxAlbumGroupSize.width())
: (_type == Type::EditOnly) : (_type == Type::EditOnly)
? st::sendBoxAlbumSmallGroupSize.width() ? st::sendBoxAlbumSmallGroupSize.width()
: 0; : 0;
@ -44,7 +51,9 @@ int AttachControls::width() const {
int AttachControls::height() const { int AttachControls::height() const {
return (_type == Type::Full) return (_type == Type::Full)
? st::sendBoxAlbumGroupSize.height() ? (_vertical
? st::sendBoxAlbumGroupSizeVertical.height()
: st::sendBoxAlbumGroupSize.height())
: (_type == Type::EditOnly) : (_type == Type::EditOnly)
? st::sendBoxAlbumSmallGroupSize.height() ? st::sendBoxAlbumSmallGroupSize.height()
: 0; : 0;
@ -54,12 +63,20 @@ AttachControls::Type AttachControls::type() const {
return _type; return _type;
} }
bool AttachControls::vertical() const {
return _vertical;
}
void AttachControls::setType(Type type) { void AttachControls::setType(Type type) {
if (_type != type) { if (_type != type) {
_type = type; _type = type;
} }
} }
void AttachControls::setVertical(bool vertical) {
_vertical = vertical;
}
AttachControlsWidget::AttachControlsWidget( AttachControlsWidget::AttachControlsWidget(
not_null<RpWidget*> parent, not_null<RpWidget*> parent,
AttachControls::Type type) AttachControls::Type type)

View file

@ -25,14 +25,17 @@ public:
void paint(QPainter &p, int x, int y); void paint(QPainter &p, int x, int y);
void setType(Type type); void setType(Type type);
void setVertical(bool vertical);
[[nodiscard]] int width() const; [[nodiscard]] int width() const;
[[nodiscard]] int height() const; [[nodiscard]] int height() const;
[[nodiscard]] Type type() const; [[nodiscard]] Type type() const;
[[nodiscard]] bool vertical() const;
private: private:
RoundRect _rect; RoundRect _rect;
Type _type = Type::Full; Type _type = Type::Full;
bool _vertical = false;
}; };