mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Added ability to generate single file preview from history item.
This commit is contained in:
parent
9509a00664
commit
19139a9a5f
3 changed files with 142 additions and 0 deletions
|
@ -1069,6 +1069,8 @@ PRIVATE
|
|||
support/support_helper.h
|
||||
support/support_templates.cpp
|
||||
support/support_templates.h
|
||||
ui/chat/attach/attach_item_single_file_preview.cpp
|
||||
ui/chat/attach/attach_item_single_file_preview.h
|
||||
ui/effects/fireworks_animation.cpp
|
||||
ui/effects/fireworks_animation.h
|
||||
ui/effects/round_checkbox.cpp
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "ui/chat/attach/attach_item_single_file_preview.h"
|
||||
|
||||
#include "data/data_document.h"
|
||||
#include "data/data_document_media.h"
|
||||
#include "data/data_file_origin.h"
|
||||
#include "history/history_item.h"
|
||||
#include "history/view/media/history_view_document.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "main/main_session.h"
|
||||
#include "ui/chat/attach/attach_prepare.h"
|
||||
#include "ui/text/format_song_name.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "styles/style_chat.h"
|
||||
|
||||
namespace Ui {
|
||||
|
||||
ItemSingleFilePreview::ItemSingleFilePreview(
|
||||
QWidget *parent,
|
||||
not_null<HistoryItem*> item)
|
||||
: AbstractSingleFilePreview(parent) {
|
||||
const auto media = item->media();
|
||||
Assert(media != nullptr);
|
||||
const auto document = media->document();
|
||||
Assert(document != nullptr);
|
||||
|
||||
_documentMedia = document->createMediaView();
|
||||
_documentMedia->thumbnailWanted(item->fullId());
|
||||
|
||||
rpl::single(
|
||||
rpl::empty_value()
|
||||
) | rpl::then(
|
||||
document->session().downloaderTaskFinished()
|
||||
) | rpl::start_with_next([=] {
|
||||
if (_documentMedia->thumbnail()) {
|
||||
_lifetimeDownload.destroy();
|
||||
}
|
||||
preparePreview(document);
|
||||
}, _lifetimeDownload);
|
||||
}
|
||||
|
||||
void ItemSingleFilePreview::preparePreview(not_null<DocumentData*> document) {
|
||||
AbstractSingleFilePreview::Data data;
|
||||
|
||||
const auto preview = _documentMedia->thumbnail()
|
||||
? _documentMedia->thumbnail()->original()
|
||||
: QImage();
|
||||
|
||||
prepareThumbFor(data, preview);
|
||||
data.fileIsImage = document->isImage();
|
||||
data.fileIsAudio = document->isAudioFile() || document->isVoiceMessage();
|
||||
|
||||
if (data.fileIsImage) {
|
||||
data.name = document->filename();
|
||||
// data.statusText = FormatImageSizeText(preview.size()
|
||||
// / preview.devicePixelRatio());
|
||||
} else if (data.fileIsAudio) {
|
||||
auto filename = document->filename();
|
||||
|
||||
auto songTitle = QString();
|
||||
auto songPerformer = QString();
|
||||
if (const auto song = document->song()) {
|
||||
songTitle = song->title;
|
||||
songPerformer = song->performer;
|
||||
|
||||
if (document->isSongWithCover()) {
|
||||
const auto size = QSize(
|
||||
st::attachPreviewLayout.thumbSize,
|
||||
st::attachPreviewLayout.thumbSize);
|
||||
auto thumb = QPixmap(size);
|
||||
thumb.fill(Qt::transparent);
|
||||
Painter p(&thumb);
|
||||
|
||||
HistoryView::DrawThumbnailAsSongCover(
|
||||
p,
|
||||
_documentMedia,
|
||||
QRect(QPoint(), size));
|
||||
data.fileThumb = std::move(thumb);
|
||||
}
|
||||
} else if (document->isVoiceMessage()) {
|
||||
songTitle = tr::lng_media_audio(tr::now);
|
||||
}
|
||||
|
||||
data.name = Text::FormatSongName(filename, songTitle, songPerformer)
|
||||
.string();
|
||||
data.statusText = FormatSizeText(document->size);
|
||||
} else {
|
||||
data.name = document->filename();
|
||||
}
|
||||
data.statusText = FormatSizeText(document->size);
|
||||
|
||||
setData(data);
|
||||
}
|
||||
|
||||
} // namespace Ui
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "ui/chat/attach/attach_abstract_single_file_preview.h"
|
||||
|
||||
class HistoryItem;
|
||||
class DocumentData;
|
||||
|
||||
namespace Data {
|
||||
class DocumentMedia;
|
||||
} // namespace Data
|
||||
|
||||
namespace Ui {
|
||||
|
||||
struct PreparedFile;
|
||||
class IconButton;
|
||||
|
||||
class ItemSingleFilePreview final : public AbstractSingleFilePreview {
|
||||
public:
|
||||
ItemSingleFilePreview(
|
||||
QWidget *parent,
|
||||
not_null<HistoryItem*> item);
|
||||
|
||||
private:
|
||||
void preparePreview(not_null<DocumentData*> document);
|
||||
|
||||
std::shared_ptr<::Data::DocumentMedia> _documentMedia;
|
||||
|
||||
rpl::lifetime _lifetimeDownload;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Ui
|
Loading…
Add table
Reference in a new issue