1 /*
2 This file is part of Telegram Desktop,
3 the official desktop application for the Telegram messaging service.
4 
5 For license and copyright information please follow this link:
6 https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
7 */
8 #pragma once
9 
10 #include "ui/chat/attach/attach_abstract_single_preview.h"
11 #include "ui/chat/attach/attach_controls.h"
12 #include "base/object_ptr.h"
13 
14 namespace Ui {
15 
16 class IconButton;
17 
18 class AbstractSingleFilePreview : public AbstractSinglePreview {
19 public:
20 	AbstractSingleFilePreview(QWidget *parent, AttachControls::Type type);
21 	~AbstractSingleFilePreview();
22 
23 	[[nodiscard]] rpl::producer<> deleteRequests() const override;
24 	[[nodiscard]] rpl::producer<> editRequests() const override;
25 	[[nodiscard]] rpl::producer<> modifyRequests() const override;
26 
27 protected:
28 	struct Data {
29 		QPixmap fileThumb;
30 		QString name;
31 		QString statusText;
32 		int nameWidth = 0;
33 		int statusWidth = 0;
34 		bool fileIsAudio = false;
35 		bool fileIsImage = false;
36 	};
37 
38 	void prepareThumbFor(Data &data, const QImage &preview);
39 	bool isThumbedLayout(Data &data) const;
40 
41 	void setData(const Data &data);
42 
43 private:
44 	void paintEvent(QPaintEvent *e) override;
45 	void resizeEvent(QResizeEvent *e) override;
46 
47 	void updateTextWidthFor(Data &data);
48 
49 	const AttachControls::Type _type;
50 
51 	Data _data;
52 
53 	object_ptr<IconButton> _editMedia = { nullptr };
54 	object_ptr<IconButton> _deleteMedia = { nullptr };
55 
56 };
57 
58 } // namespace Ui
59