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