mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-08 08:04:08 +02:00
Improve SendFilesBox previews layout.
This commit is contained in:
parent
d7fe2948ac
commit
0d37949e74
6 changed files with 69 additions and 63 deletions
|
@ -515,8 +515,8 @@ sendBoxAlbumGroupRadius: 13px;
|
||||||
sendBoxAlbumGroupHeight: 26px;
|
sendBoxAlbumGroupHeight: 26px;
|
||||||
|
|
||||||
sendBoxFileGroupSkipTop: 2px;
|
sendBoxFileGroupSkipTop: 2px;
|
||||||
sendBoxFileGroupSkipRight: 0px;
|
sendBoxFileGroupSkipRight: 8px;
|
||||||
sendBoxFileGroupEditInternalSkip: 4px;
|
sendBoxFileGroupEditInternalSkip: -1px;
|
||||||
|
|
||||||
sendBoxAlbumGroupButtonFile: IconButton(editMediaButton) {
|
sendBoxAlbumGroupButtonFile: IconButton(editMediaButton) {
|
||||||
ripple: RippleAnimation(defaultRippleAnimation) {
|
ripple: RippleAnimation(defaultRippleAnimation) {
|
||||||
|
|
|
@ -233,6 +233,7 @@ SendFilesBox::SendFilesBox(
|
||||||
SendMenu::Type sendMenuType)
|
SendMenu::Type sendMenuType)
|
||||||
: _controller(controller)
|
: _controller(controller)
|
||||||
, _sendType(sendType)
|
, _sendType(sendType)
|
||||||
|
, _titleHeight(st::boxTitleHeight)
|
||||||
, _list(std::move(list))
|
, _list(std::move(list))
|
||||||
, _sendLimit(limit)
|
, _sendLimit(limit)
|
||||||
, _sendMenuType(sendMenuType)
|
, _sendMenuType(sendMenuType)
|
||||||
|
@ -262,7 +263,8 @@ void SendFilesBox::initPreview() {
|
||||||
rpl::combine(
|
rpl::combine(
|
||||||
_inner->heightValue(),
|
_inner->heightValue(),
|
||||||
_footerHeight.value(),
|
_footerHeight.value(),
|
||||||
_titleHeight + _1 + _2
|
_titleHeight.value(),
|
||||||
|
_1 + _2 + _3
|
||||||
) | rpl::start_with_next([=](int height) {
|
) | rpl::start_with_next([=](int height) {
|
||||||
setDimensions(
|
setDimensions(
|
||||||
st::boxWideWidth,
|
st::boxWideWidth,
|
||||||
|
@ -523,7 +525,9 @@ void SendFilesBox::pushBlock(int from, int till) {
|
||||||
gifPaused,
|
gifPaused,
|
||||||
_sendWay.current());
|
_sendWay.current());
|
||||||
auto &block = _blocks.back();
|
auto &block = _blocks.back();
|
||||||
const auto widget = _inner->add(block.takeWidget());
|
const auto widget = _inner->add(
|
||||||
|
block.takeWidget(),
|
||||||
|
QMargins(0, _inner->count() ? st::sendMediaFileThumbSkip : 0, 0, 0));
|
||||||
|
|
||||||
block.itemDeleteRequest(
|
block.itemDeleteRequest(
|
||||||
) | rpl::filter([=] {
|
) | rpl::filter([=] {
|
||||||
|
@ -817,7 +821,7 @@ void SendFilesBox::refreshTitleText() {
|
||||||
_titleHeight = st::boxTitleHeight;
|
_titleHeight = st::boxTitleHeight;
|
||||||
} else {
|
} else {
|
||||||
_titleText = QString();
|
_titleText = QString();
|
||||||
_titleHeight = 0;
|
_titleHeight = st::boxPhotoPadding.top();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -859,11 +863,11 @@ void SendFilesBox::paintEvent(QPaintEvent *e) {
|
||||||
if (!_titleText.isEmpty()) {
|
if (!_titleText.isEmpty()) {
|
||||||
Painter p(this);
|
Painter p(this);
|
||||||
|
|
||||||
p.setFont(st::boxPhotoTitleFont);
|
p.setFont(st::boxTitleFont);
|
||||||
p.setPen(st::boxTitleFg);
|
p.setPen(st::boxTitleFg);
|
||||||
p.drawTextLeft(
|
p.drawTextLeft(
|
||||||
st::boxPhotoTitlePosition.x(),
|
st::boxPhotoTitlePosition.x(),
|
||||||
st::boxPhotoTitlePosition.y(),
|
st::boxTitlePosition.y(),
|
||||||
width(),
|
width(),
|
||||||
_titleText);
|
_titleText);
|
||||||
}
|
}
|
||||||
|
@ -889,6 +893,7 @@ void SendFilesBox::updateControlsGeometry() {
|
||||||
+ st::sendMediaPreviewSize
|
+ st::sendMediaPreviewSize
|
||||||
- _emojiToggle->width()),
|
- _emojiToggle->width()),
|
||||||
_caption->y() + st::boxAttachEmojiTop);
|
_caption->y() + st::boxAttachEmojiTop);
|
||||||
|
_emojiToggle->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const auto pointers = {
|
const auto pointers = {
|
||||||
|
@ -903,8 +908,8 @@ void SendFilesBox::updateControlsGeometry() {
|
||||||
bottom -= st::boxPhotoCompressedSkip + pointer->heightNoMargins();
|
bottom -= st::boxPhotoCompressedSkip + pointer->heightNoMargins();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_scroll->resize(width(), bottom - _titleHeight);
|
_scroll->resize(width(), bottom - _titleHeight.current());
|
||||||
_scroll->move(0, _titleHeight);
|
_scroll->move(0, _titleHeight.current());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendFilesBox::setInnerFocus() {
|
void SendFilesBox::setInnerFocus() {
|
||||||
|
|
|
@ -158,7 +158,7 @@ private:
|
||||||
const Api::SendType _sendType = Api::SendType();
|
const Api::SendType _sendType = Api::SendType();
|
||||||
|
|
||||||
QString _titleText;
|
QString _titleText;
|
||||||
int _titleHeight = 0;
|
rpl::variable<int> _titleHeight = 0;
|
||||||
|
|
||||||
Ui::PreparedList _list;
|
Ui::PreparedList _list;
|
||||||
std::optional<int> _removingIndex;
|
std::optional<int> _removingIndex;
|
||||||
|
|
|
@ -32,9 +32,9 @@ SingleFilePreview::SingleFilePreview(
|
||||||
_editMedia->setIconOverride(&st::sendBoxAlbumGroupEditButtonIconFile);
|
_editMedia->setIconOverride(&st::sendBoxAlbumGroupEditButtonIconFile);
|
||||||
_deleteMedia->setIconOverride(&st::sendBoxAlbumGroupDeleteButtonIconFile);
|
_deleteMedia->setIconOverride(&st::sendBoxAlbumGroupDeleteButtonIconFile);
|
||||||
|
|
||||||
auto h = _fileThumb.isNull()
|
const auto h = _fileThumb.isNull()
|
||||||
? (st::msgFilePadding.top() + st::msgFileSize + st::msgFilePadding.bottom())
|
? st::msgFileSize
|
||||||
: (st::msgFileThumbPadding.top() + st::msgFileThumbSize + st::msgFileThumbPadding.bottom());
|
: st::sendMediaFileThumbSize;
|
||||||
resize(width(), h);
|
resize(width(), h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,9 +57,9 @@ void SingleFilePreview::prepareThumb(const QImage &preview) {
|
||||||
|
|
||||||
auto originalWidth = preview.width();
|
auto originalWidth = preview.width();
|
||||||
auto originalHeight = preview.height();
|
auto originalHeight = preview.height();
|
||||||
auto thumbWidth = st::msgFileThumbSize;
|
auto thumbWidth = st::sendMediaFileThumbSize;
|
||||||
if (originalWidth > originalHeight) {
|
if (originalWidth > originalHeight) {
|
||||||
thumbWidth = (originalWidth * st::msgFileThumbSize)
|
thumbWidth = (originalWidth * st::sendMediaFileThumbSize)
|
||||||
/ originalHeight;
|
/ originalHeight;
|
||||||
}
|
}
|
||||||
auto options = Images::Option::Smooth
|
auto options = Images::Option::Smooth
|
||||||
|
@ -73,8 +73,8 @@ void SingleFilePreview::prepareThumb(const QImage &preview) {
|
||||||
thumbWidth * style::DevicePixelRatio(),
|
thumbWidth * style::DevicePixelRatio(),
|
||||||
0,
|
0,
|
||||||
options,
|
options,
|
||||||
st::msgFileThumbSize,
|
st::sendMediaFileThumbSize,
|
||||||
st::msgFileThumbSize));
|
st::sendMediaFileThumbSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SingleFilePreview::preparePreview(const PreparedFile &file) {
|
void SingleFilePreview::preparePreview(const PreparedFile &file) {
|
||||||
|
@ -95,12 +95,8 @@ void SingleFilePreview::preparePreview(const PreparedFile &file) {
|
||||||
// QString(),
|
// QString(),
|
||||||
// true); // #TODO files
|
// true); // #TODO files
|
||||||
auto filename = "image.png";
|
auto filename = "image.png";
|
||||||
_nameText.setText(
|
_name = filename;
|
||||||
st::semiboldTextStyle,
|
|
||||||
filename,
|
|
||||||
NameTextOptions());
|
|
||||||
_statusText = u"%1x%2"_q.arg(preview.width()).arg(preview.height());
|
_statusText = u"%1x%2"_q.arg(preview.width()).arg(preview.height());
|
||||||
_statusWidth = qMax(_nameText.maxWidth(), st::normalFont->width(_statusText));
|
|
||||||
_fileIsImage = true;
|
_fileIsImage = true;
|
||||||
} else {
|
} else {
|
||||||
auto fileinfo = QFileInfo(filepath);
|
auto fileinfo = QFileInfo(filepath);
|
||||||
|
@ -118,46 +114,48 @@ void SingleFilePreview::preparePreview(const PreparedFile &file) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto nameString = ComposeNameString(
|
_name = ComposeNameString(filename, songTitle, songPerformer);
|
||||||
filename,
|
|
||||||
songTitle,
|
|
||||||
songPerformer);
|
|
||||||
_nameText.setText(
|
|
||||||
st::semiboldTextStyle,
|
|
||||||
nameString,
|
|
||||||
NameTextOptions());
|
|
||||||
_statusText = FormatSizeText(fileinfo.size());
|
_statusText = FormatSizeText(fileinfo.size());
|
||||||
_statusWidth = qMax(
|
|
||||||
_nameText.maxWidth(),
|
|
||||||
st::normalFont->width(_statusText));
|
|
||||||
}
|
}
|
||||||
|
const auto availableFileWidth = st::sendMediaPreviewSize
|
||||||
|
- st::sendMediaFileThumbSkip
|
||||||
|
- st::sendMediaFileThumbSize
|
||||||
|
// Right buttons.
|
||||||
|
- st::sendBoxAlbumGroupButtonFile.width * 2
|
||||||
|
- st::sendBoxAlbumGroupEditInternalSkip * 2
|
||||||
|
- st::sendBoxAlbumGroupSkipRight;
|
||||||
|
_nameWidth = st::semiboldFont->width(_name);
|
||||||
|
if (_nameWidth > availableFileWidth) {
|
||||||
|
_name = st::semiboldFont->elided(
|
||||||
|
_name,
|
||||||
|
availableFileWidth,
|
||||||
|
Qt::ElideMiddle);
|
||||||
|
_nameWidth = st::semiboldFont->width(_name);
|
||||||
|
}
|
||||||
|
_statusWidth = st::normalFont->width(_statusText);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SingleFilePreview::paintEvent(QPaintEvent *e) {
|
void SingleFilePreview::paintEvent(QPaintEvent *e) {
|
||||||
Painter p(this);
|
Painter p(this);
|
||||||
|
|
||||||
auto w = width() - st::boxPhotoPadding.left() - st::boxPhotoPadding.right();
|
auto w = width() - st::boxPhotoPadding.left() - st::boxPhotoPadding.right();
|
||||||
auto h = _fileThumb.isNull() ? (st::msgFilePadding.top() + st::msgFileSize + st::msgFilePadding.bottom()) : (st::msgFileThumbPadding.top() + st::msgFileThumbSize + st::msgFileThumbPadding.bottom());
|
auto h = _fileThumb.isNull() ? st::msgFileSize : st::sendMediaFileThumbSize;
|
||||||
auto nameleft = 0, nametop = 0, nameright = 0, statustop = 0, linktop = 0;
|
auto nameleft = 0, nametop = 0, statustop = 0;
|
||||||
if (_fileThumb.isNull()) {
|
if (_fileThumb.isNull()) {
|
||||||
nameleft = st::msgFilePadding.left() + st::msgFileSize + st::msgFilePadding.right();
|
nameleft = st::msgFileSize + st::msgFilePadding.right();
|
||||||
nametop = st::msgFileNameTop;
|
nametop = st::msgFileNameTop - st::msgFilePadding.top();
|
||||||
nameright = st::msgFilePadding.left();
|
statustop = st::msgFileStatusTop - st::msgFilePadding.top();
|
||||||
statustop = st::msgFileStatusTop;
|
|
||||||
} else {
|
} else {
|
||||||
nameleft = st::msgFileThumbPadding.left() + st::msgFileThumbSize + st::msgFileThumbPadding.right();
|
nameleft = st::sendMediaFileThumbSize + st::sendMediaFileThumbSkip;
|
||||||
nametop = st::msgFileThumbNameTop;
|
nametop = st::sendMediaFileNameTop;
|
||||||
nameright = st::msgFileThumbPadding.left();
|
statustop = st::sendMediaFileStatusTop;
|
||||||
statustop = st::msgFileThumbStatusTop;
|
|
||||||
linktop = st::msgFileThumbLinkTop;
|
|
||||||
}
|
}
|
||||||
auto namewidth = w - nameleft - (_fileThumb.isNull() ? st::msgFilePadding.left() : st::msgFileThumbPadding.left());
|
const auto x = (width() - w) / 2, y = 0;
|
||||||
int32 x = (width() - w) / 2, y = 0;
|
|
||||||
|
|
||||||
if (_fileThumb.isNull()) {
|
if (_fileThumb.isNull()) {
|
||||||
QRect inner(style::rtlrect(x + st::msgFilePadding.left(), y + st::msgFilePadding.top(), st::msgFileSize, st::msgFileSize, width()));
|
QRect inner(style::rtlrect(x, y, st::msgFileSize, st::msgFileSize, width()));
|
||||||
p.setPen(Qt::NoPen);
|
p.setPen(Qt::NoPen);
|
||||||
p.setBrush(st::msgFileOutBg);
|
p.setBrush(st::msgFileInBg);
|
||||||
|
|
||||||
{
|
{
|
||||||
PainterHighQualityEnabler hq(p);
|
PainterHighQualityEnabler hq(p);
|
||||||
|
@ -165,23 +163,22 @@ void SingleFilePreview::paintEvent(QPaintEvent *e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto &icon = _fileIsAudio
|
auto &icon = _fileIsAudio
|
||||||
? st::historyFileOutPlay
|
? st::historyFileInPlay
|
||||||
: _fileIsImage
|
: _fileIsImage
|
||||||
? st::historyFileOutImage
|
? st::historyFileInImage
|
||||||
: st::historyFileOutDocument;
|
: st::historyFileInDocument;
|
||||||
icon.paintInCenter(p, inner);
|
icon.paintInCenter(p, inner);
|
||||||
} else {
|
} else {
|
||||||
QRect rthumb(style::rtlrect(x + st::msgFileThumbPadding.left(), y + st::msgFileThumbPadding.top(), st::msgFileThumbSize, st::msgFileThumbSize, width()));
|
QRect rthumb(style::rtlrect(x, y, st::sendMediaFileThumbSize, st::sendMediaFileThumbSize, width()));
|
||||||
p.drawPixmap(rthumb.topLeft(), _fileThumb);
|
p.drawPixmap(rthumb.topLeft(), _fileThumb);
|
||||||
}
|
}
|
||||||
p.setFont(st::semiboldFont);
|
p.setFont(st::semiboldFont);
|
||||||
p.setPen(st::historyFileNameOutFg);
|
p.setPen(st::historyFileNameInFg);
|
||||||
_nameText.drawLeftElided(p, x + nameleft, y + nametop, namewidth, width());
|
p.drawTextLeft(x + nameleft, y + nametop, width(), _name, _nameWidth);
|
||||||
|
|
||||||
auto &status = st::mediaOutFg;
|
|
||||||
p.setFont(st::normalFont);
|
p.setFont(st::normalFont);
|
||||||
p.setPen(status);
|
p.setPen(st::mediaInFg);
|
||||||
p.drawTextLeft(x + nameleft, y + statustop, width(), _statusText);
|
p.drawTextLeft(x + nameleft, y + statustop, width(), _statusText, _statusWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SingleFilePreview::resizeEvent(QResizeEvent *e) {
|
void SingleFilePreview::resizeEvent(QResizeEvent *e) {
|
||||||
|
|
|
@ -33,11 +33,12 @@ private:
|
||||||
void prepareThumb(const QImage &preview);
|
void prepareThumb(const QImage &preview);
|
||||||
|
|
||||||
QPixmap _fileThumb;
|
QPixmap _fileThumb;
|
||||||
Text::String _nameText;
|
QString _name;
|
||||||
|
QString _statusText;
|
||||||
|
int _nameWidth = 0;
|
||||||
|
int _statusWidth = 0;
|
||||||
bool _fileIsAudio = false;
|
bool _fileIsAudio = false;
|
||||||
bool _fileIsImage = false;
|
bool _fileIsImage = false;
|
||||||
QString _statusText;
|
|
||||||
int _statusWidth = 0;
|
|
||||||
|
|
||||||
object_ptr<IconButton> _editMedia = { nullptr };
|
object_ptr<IconButton> _editMedia = { nullptr };
|
||||||
object_ptr<IconButton> _deleteMedia = { nullptr };
|
object_ptr<IconButton> _deleteMedia = { nullptr };
|
||||||
|
|
|
@ -155,7 +155,9 @@ void SingleMediaPreview::resizeEvent(QResizeEvent *e) {
|
||||||
const auto skipTop = st::sendBoxAlbumGroupSkipTop;
|
const auto skipTop = st::sendBoxAlbumGroupSkipTop;
|
||||||
const auto groupWidth = size * 2 + skipInternal;
|
const auto groupWidth = size * 2 + skipInternal;
|
||||||
|
|
||||||
const auto left = _previewLeft + _previewWidth - groupWidth - skipRight;
|
const auto right = (st::boxWideWidth - st::sendMediaPreviewSize) / 2
|
||||||
|
+ st::sendMediaPreviewSize;
|
||||||
|
const auto left = right - groupWidth - skipRight;
|
||||||
const auto top = skipTop;
|
const auto top = skipTop;
|
||||||
_editMedia->move(left, top);
|
_editMedia->move(left, top);
|
||||||
_deleteMedia->move(left + size + skipInternal, top);
|
_deleteMedia->move(left + size + skipInternal, top);
|
||||||
|
@ -259,8 +261,9 @@ void SingleMediaPreview::paintButtonsBackground(QPainter &p) {
|
||||||
const auto skipRight = st::sendBoxAlbumGroupSkipRight;
|
const auto skipRight = st::sendBoxAlbumGroupSkipRight;
|
||||||
const auto skipTop = st::sendBoxAlbumGroupSkipTop;
|
const auto skipTop = st::sendBoxAlbumGroupSkipTop;
|
||||||
const auto groupWidth = size * 2 + skipInternal;
|
const auto groupWidth = size * 2 + skipInternal;
|
||||||
|
const auto right = (st::boxWideWidth - st::sendMediaPreviewSize) / 2
|
||||||
const auto left = _previewLeft + _previewWidth - groupWidth - skipRight;
|
+ st::sendMediaPreviewSize;
|
||||||
|
const auto left = right - groupWidth - skipRight;
|
||||||
const auto top = skipTop;
|
const auto top = skipTop;
|
||||||
|
|
||||||
QRect groupRect(left, top, groupWidth, size);
|
QRect groupRect(left, top, groupWidth, size);
|
||||||
|
|
Loading…
Add table
Reference in a new issue