mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Added ability to show song cover in EditCaptionBox and SendFilesBox.
This commit is contained in:
parent
8fffe7d128
commit
cf0cde6e83
6 changed files with 100 additions and 27 deletions
|
@ -32,6 +32,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "history/history.h"
|
||||
#include "history/history_drag_area.h"
|
||||
#include "history/history_item.h"
|
||||
#include "history/view/media/history_view_document.h" // DrawThumbnailAsSongCover
|
||||
#include "platform/platform_specific.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "media/streaming/media_streaming_instance.h"
|
||||
|
@ -171,7 +172,9 @@ EditCaptionBox::EditCaptionBox(
|
|||
_thumbw = 0;
|
||||
_thumbnailImageLoaded = true;
|
||||
} else {
|
||||
const auto thumbSize = st::msgFileThumbLayout.thumbSize;
|
||||
const auto thumbSize = (!media->document()->isSongWithCover()
|
||||
? st::msgFileThumbLayout
|
||||
: st::msgFileLayout).thumbSize;
|
||||
const auto tw = dimensions.width(), th = dimensions.height();
|
||||
if (tw > th) {
|
||||
_thumbw = (tw * thumbSize) / th;
|
||||
|
@ -183,19 +186,31 @@ EditCaptionBox::EditCaptionBox(
|
|||
if (!image) {
|
||||
return;
|
||||
}
|
||||
const auto options = Images::Option::Smooth
|
||||
| Images::Option::RoundedSmall
|
||||
| Images::Option::RoundedTopLeft
|
||||
| Images::Option::RoundedTopRight
|
||||
| Images::Option::RoundedBottomLeft
|
||||
| Images::Option::RoundedBottomRight;
|
||||
_thumb = App::pixmapFromImageInPlace(Images::prepare(
|
||||
image->original(),
|
||||
_thumbw * cIntRetinaFactor(),
|
||||
0,
|
||||
options,
|
||||
thumbSize,
|
||||
thumbSize));
|
||||
if (media->document()->isSongWithCover()) {
|
||||
const auto size = QSize(thumbSize, thumbSize);
|
||||
_thumb = QPixmap(size);
|
||||
_thumb.fill(Qt::transparent);
|
||||
Painter p(&_thumb);
|
||||
|
||||
HistoryView::DrawThumbnailAsSongCover(
|
||||
p,
|
||||
_documentMedia,
|
||||
QRect(QPoint(), size));
|
||||
} else {
|
||||
const auto options = Images::Option::Smooth
|
||||
| Images::Option::RoundedSmall
|
||||
| Images::Option::RoundedTopLeft
|
||||
| Images::Option::RoundedTopRight
|
||||
| Images::Option::RoundedBottomLeft
|
||||
| Images::Option::RoundedBottomRight;
|
||||
_thumb = App::pixmapFromImageInPlace(Images::prepare(
|
||||
image->original(),
|
||||
_thumbw * cIntRetinaFactor(),
|
||||
0,
|
||||
options,
|
||||
thumbSize,
|
||||
thumbSize));
|
||||
}
|
||||
_thumbnailImageLoaded = true;
|
||||
};
|
||||
_refreshThumbnail();
|
||||
|
@ -539,6 +554,14 @@ void EditCaptionBox::updateEditPreview() {
|
|||
song->title,
|
||||
song->performer);
|
||||
_isAudio = true;
|
||||
|
||||
if (auto cover = song->cover; !cover.isNull()) {
|
||||
_thumb = Ui::PrepareSongCoverForThumbnail(
|
||||
cover,
|
||||
st::msgFileLayout.thumbSize);
|
||||
_thumbw = _thumb.width() / cIntRetinaFactor();
|
||||
_thumbh = _thumb.height() / cIntRetinaFactor();
|
||||
}
|
||||
}
|
||||
|
||||
const auto getExt = [&] {
|
||||
|
@ -810,15 +833,21 @@ void EditCaptionBox::setupDragArea() {
|
|||
areas.photo->setDroppedCallback(droppedCallback(true));
|
||||
}
|
||||
|
||||
bool EditCaptionBox::isThumbedLayout() const {
|
||||
return (_thumbw && !_isAudio);
|
||||
}
|
||||
|
||||
void EditCaptionBox::updateBoxSize() {
|
||||
auto newHeight = st::boxPhotoPadding.top() + st::boxPhotoCaptionSkip + _field->height() + errorTopSkip() + st::normalFont->height;
|
||||
if (_photo) {
|
||||
newHeight += _wayWrap->height() / 2;
|
||||
}
|
||||
const auto &st = _thumbw ? st::msgFileThumbLayout : st::msgFileLayout;
|
||||
const auto &st = isThumbedLayout()
|
||||
? st::msgFileThumbLayout
|
||||
: st::msgFileLayout;
|
||||
if (_photo || _animated) {
|
||||
newHeight += std::max(_thumbh, _gifh);
|
||||
} else if (_thumbw || _doc) {
|
||||
} else if (isThumbedLayout() || _doc) {
|
||||
newHeight += 0 + st.thumbSize + 0;
|
||||
} else {
|
||||
newHeight += st::boxTitleFont->height;
|
||||
|
@ -902,7 +931,9 @@ void EditCaptionBox::paintEvent(QPaintEvent *e) {
|
|||
icon->paintInCenter(p, inner);
|
||||
}
|
||||
} else if (_doc) {
|
||||
const auto &st = _thumbw ? st::msgFileThumbLayout : st::msgFileLayout;
|
||||
const auto &st = isThumbedLayout()
|
||||
? st::msgFileThumbLayout
|
||||
: st::msgFileLayout;
|
||||
const auto w = width() - st::boxPhotoPadding.left() - st::boxPhotoPadding.right();
|
||||
const auto h = 0 + st.thumbSize + 0;
|
||||
const auto nameleft = 0 + st.thumbSize + st.padding.right();
|
||||
|
@ -918,18 +949,24 @@ void EditCaptionBox::paintEvent(QPaintEvent *e) {
|
|||
// Ui::FillRoundCorner(p, x, y, w, h, st::msgInBg, Ui::MessageInCorners, &st::msgInShadow);
|
||||
|
||||
const auto rthumb = style::rtlrect(x + 0, y + 0, st.thumbSize, st.thumbSize, width());
|
||||
if (_thumbw) {
|
||||
if (isThumbedLayout()) {
|
||||
p.drawPixmap(rthumb.topLeft(), _thumb);
|
||||
} else {
|
||||
p.setPen(Qt::NoPen);
|
||||
p.setBrush(st::msgFileInBg);
|
||||
|
||||
{
|
||||
if (_isAudio && _thumbw) {
|
||||
p.drawPixmap(rthumb.topLeft(), _thumb);
|
||||
} else {
|
||||
p.setBrush(st::msgFileInBg);
|
||||
PainterHighQualityEnabler hq(p);
|
||||
p.drawEllipse(rthumb);
|
||||
}
|
||||
|
||||
const auto icon = &(_isAudio ? st::historyFileInPlay : _isImage ? st::historyFileInImage : st::historyFileInDocument);
|
||||
const auto icon = &(_isAudio
|
||||
? st::historyFileInPlay
|
||||
: _isImage
|
||||
? st::historyFileInImage
|
||||
: st::historyFileInDocument);
|
||||
icon->paintInCenter(p, rthumb);
|
||||
}
|
||||
p.setFont(st::semiboldFont);
|
||||
|
|
|
@ -96,6 +96,8 @@ private:
|
|||
void createEditMediaButton();
|
||||
bool setPreparedList(Ui::PreparedList &&list);
|
||||
|
||||
bool isThumbedLayout() const;
|
||||
|
||||
inline QString getNewMediaPath() {
|
||||
return _preparedList.files.empty()
|
||||
? QString()
|
||||
|
|
|
@ -8,6 +8,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/chat/attach/attach_prepare.h"
|
||||
|
||||
#include "ui/chat/attach/attach_send_files_way.h"
|
||||
#include "ui/image/image_prepare.h"
|
||||
#include "ui/ui_utility.h"
|
||||
#include "core/mime_type.h"
|
||||
|
||||
namespace Ui {
|
||||
|
@ -255,4 +257,20 @@ std::vector<PreparedGroup> DivideByGroups(
|
|||
return result;
|
||||
}
|
||||
|
||||
QPixmap PrepareSongCoverForThumbnail(QImage image, int size) {
|
||||
const auto scaledSize = image.size().scaled(
|
||||
size,
|
||||
size,
|
||||
Qt::KeepAspectRatioByExpanding);
|
||||
using Option = Images::Option;
|
||||
return PixmapFromImage(Images::prepare(
|
||||
std::move(image),
|
||||
scaledSize.width() * style::DevicePixelRatio(),
|
||||
scaledSize.height() * style::DevicePixelRatio(),
|
||||
Option::Circled | Option::Colored | Option::Smooth,
|
||||
size,
|
||||
size,
|
||||
&st::songCoverOverlayFg));
|
||||
}
|
||||
|
||||
} // namespace Ui
|
||||
|
|
|
@ -132,4 +132,6 @@ struct PreparedGroup {
|
|||
[[nodiscard]] int MaxAlbumItems();
|
||||
[[nodiscard]] bool ValidateThumbDimensions(int width, int height);
|
||||
|
||||
[[nodiscard]] QPixmap PrepareSongCoverForThumbnail(QImage image, int size);
|
||||
|
||||
} // namespace Ui
|
||||
|
|
|
@ -32,7 +32,7 @@ SingleFilePreview::SingleFilePreview(
|
|||
_editMedia->setIconOverride(&st::sendBoxAlbumGroupEditButtonIconFile);
|
||||
_deleteMedia->setIconOverride(&st::sendBoxAlbumGroupDeleteButtonIconFile);
|
||||
|
||||
const auto &st = _fileThumb.isNull()
|
||||
const auto &st = !isThumbedLayout()
|
||||
? st::attachPreviewLayout
|
||||
: st::attachPreviewThumbLayout;
|
||||
resize(width(), st.thumbSize);
|
||||
|
@ -106,13 +106,19 @@ void SingleFilePreview::preparePreview(const PreparedFile &file) {
|
|||
songTitle = song->title;
|
||||
songPerformer = song->performer;
|
||||
_fileIsAudio = true;
|
||||
|
||||
if (auto cover = song->cover; !cover.isNull()) {
|
||||
_fileThumb = Ui::PrepareSongCoverForThumbnail(
|
||||
cover,
|
||||
st::attachPreviewLayout.thumbSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_name = ComposeNameString(filename, songTitle, songPerformer);
|
||||
_statusText = FormatSizeText(fileinfo.size());
|
||||
}
|
||||
const auto &st = _fileThumb.isNull()
|
||||
const auto &st = !isThumbedLayout()
|
||||
? st::attachPreviewLayout
|
||||
: st::attachPreviewThumbLayout;
|
||||
const auto nameleft = st.thumbSize + st.padding.right();
|
||||
|
@ -141,7 +147,7 @@ void SingleFilePreview::paintEvent(QPaintEvent *e) {
|
|||
|
||||
auto w = width() - st::boxPhotoPadding.left() - st::boxPhotoPadding.right();
|
||||
auto h = height();
|
||||
const auto &st = _fileThumb.isNull()
|
||||
const auto &st = !isThumbedLayout()
|
||||
? st::attachPreviewLayout
|
||||
: st::attachPreviewThumbLayout;
|
||||
const auto nameleft = st.thumbSize + st.padding.right();
|
||||
|
@ -149,12 +155,14 @@ void SingleFilePreview::paintEvent(QPaintEvent *e) {
|
|||
const auto statustop = st.statusTop;
|
||||
const auto x = (width() - w) / 2, y = 0;
|
||||
|
||||
if (_fileThumb.isNull()) {
|
||||
if (!isThumbedLayout()) {
|
||||
QRect inner(style::rtlrect(x, y, st.thumbSize, st.thumbSize, width()));
|
||||
p.setPen(Qt::NoPen);
|
||||
p.setBrush(st::msgFileInBg);
|
||||
|
||||
{
|
||||
if (_fileIsAudio && !_fileThumb.isNull()) {
|
||||
p.drawPixmap(inner.topLeft(), _fileThumb);
|
||||
} else {
|
||||
p.setBrush(st::msgFileInBg);
|
||||
PainterHighQualityEnabler hq(p);
|
||||
p.drawEllipse(inner);
|
||||
}
|
||||
|
@ -188,4 +196,8 @@ void SingleFilePreview::resizeEvent(QResizeEvent *e) {
|
|||
_editMedia->moveToRight(right, top);
|
||||
}
|
||||
|
||||
bool SingleFilePreview::isThumbedLayout() const {
|
||||
return (!_fileThumb.isNull() && !_fileIsAudio);
|
||||
}
|
||||
|
||||
} // namespace Ui
|
||||
|
|
|
@ -32,6 +32,8 @@ private:
|
|||
void preparePreview(const PreparedFile &file);
|
||||
void prepareThumb(const QImage &preview);
|
||||
|
||||
bool isThumbedLayout() const;
|
||||
|
||||
QPixmap _fileThumb;
|
||||
QString _name;
|
||||
QString _statusText;
|
||||
|
|
Loading…
Add table
Reference in a new issue