mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-01-20 22:41:11 +00:00
Support vertical attach modify buttons layout.
This commit is contained in:
parent
38941eb3c8
commit
f3ba8fea57
@ -508,6 +508,7 @@ sendBoxAlbumGroupSkipRight: 5px;
|
||||
sendBoxAlbumGroupSkipTop: 5px;
|
||||
sendBoxAlbumGroupRadius: 4px;
|
||||
sendBoxAlbumGroupSize: size(62px, 25px);
|
||||
sendBoxAlbumGroupSizeVertical: size(30px, 50px);
|
||||
sendBoxAlbumSmallGroupSize: size(30px, 25px);
|
||||
|
||||
sendBoxFileGroupSkipTop: 2px;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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<RpWidget*> parent,
|
||||
AttachControls::Type type)
|
||||
|
@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user