2020-10-13 15:11:53 +00:00
|
|
|
/*
|
|
|
|
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/rp_widget.h"
|
2020-10-15 14:27:16 +00:00
|
|
|
#include "ui/chat/attach/attach_send_files_way.h"
|
2020-10-13 15:11:53 +00:00
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
|
2020-10-16 07:52:55 +00:00
|
|
|
struct PreparedFile;
|
2020-10-13 15:11:53 +00:00
|
|
|
struct GroupMediaLayout;
|
|
|
|
class AlbumThumbnail;
|
|
|
|
|
|
|
|
class AlbumPreview final : public RpWidget {
|
|
|
|
public:
|
|
|
|
AlbumPreview(
|
|
|
|
QWidget *parent,
|
2020-10-16 10:38:12 +00:00
|
|
|
gsl::span<Ui::PreparedFile> items,
|
2020-10-13 15:11:53 +00:00
|
|
|
SendFilesWay way);
|
|
|
|
~AlbumPreview();
|
|
|
|
|
|
|
|
void setSendWay(SendFilesWay way);
|
|
|
|
std::vector<int> takeOrder();
|
|
|
|
|
2020-10-16 07:52:55 +00:00
|
|
|
[[nodiscard]] rpl::producer<int> thumbDeleted() const {
|
2020-10-13 15:11:53 +00:00
|
|
|
return _thumbDeleted.events();
|
|
|
|
}
|
|
|
|
|
2020-10-16 07:52:55 +00:00
|
|
|
[[nodiscard]] rpl::producer<int> thumbChanged() const {
|
2020-10-13 15:11:53 +00:00
|
|
|
return _thumbChanged.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
int countLayoutHeight(
|
|
|
|
const std::vector<GroupMediaLayout> &layout) const;
|
|
|
|
std::vector<GroupMediaLayout> generateOrderedLayout() const;
|
2020-10-16 10:38:12 +00:00
|
|
|
std::vector<int> defaultOrder(int count = -1) const;
|
|
|
|
void prepareThumbs(gsl::span<Ui::PreparedFile> items);
|
2020-10-13 15:11:53 +00:00
|
|
|
void updateSizeAnimated(const std::vector<GroupMediaLayout> &layout);
|
|
|
|
void updateSize();
|
|
|
|
void updateFileRows();
|
|
|
|
|
|
|
|
int thumbIndex(AlbumThumbnail *thumb);
|
|
|
|
AlbumThumbnail *thumbUnderCursor();
|
|
|
|
void deleteThumbByIndex(int index);
|
|
|
|
void changeThumbByIndex(int index);
|
|
|
|
void thumbButtonsCallback(
|
|
|
|
not_null<AlbumThumbnail*> thumb,
|
|
|
|
AttachButtonType type);
|
|
|
|
|
|
|
|
void paintAlbum(Painter &p) const;
|
|
|
|
void paintPhotos(Painter &p, QRect clip) const;
|
|
|
|
void paintFiles(Painter &p, QRect clip) const;
|
|
|
|
|
|
|
|
void applyCursor(style::cursor cursor);
|
|
|
|
int contentLeft() const;
|
|
|
|
int contentTop() const;
|
|
|
|
AlbumThumbnail *findThumb(QPoint position) const;
|
|
|
|
not_null<AlbumThumbnail*> findClosestThumb(QPoint position) const;
|
|
|
|
void updateSuggestedDrag(QPoint position);
|
|
|
|
int orderIndex(not_null<AlbumThumbnail*> thumb) const;
|
|
|
|
void cancelDrag();
|
|
|
|
void finishDrag();
|
|
|
|
|
2020-10-15 14:27:16 +00:00
|
|
|
SendFilesWay _sendWay;
|
2020-10-13 15:11:53 +00:00
|
|
|
style::cursor _cursor = style::cur_default;
|
|
|
|
std::vector<int> _order;
|
2020-10-16 10:38:12 +00:00
|
|
|
std::vector<QSize> _itemsShownDimensions;
|
2020-10-13 15:11:53 +00:00
|
|
|
std::vector<std::unique_ptr<AlbumThumbnail>> _thumbs;
|
|
|
|
int _thumbsHeight = 0;
|
|
|
|
int _photosHeight = 0;
|
|
|
|
int _filesHeight = 0;
|
|
|
|
|
|
|
|
AlbumThumbnail *_draggedThumb = nullptr;
|
|
|
|
AlbumThumbnail *_suggestedThumb = nullptr;
|
|
|
|
AlbumThumbnail *_paintedAbove = nullptr;
|
|
|
|
QPoint _draggedStartPosition;
|
|
|
|
|
|
|
|
rpl::event_stream<int> _thumbDeleted;
|
|
|
|
rpl::event_stream<int> _thumbChanged;
|
|
|
|
|
|
|
|
mutable Animations::Simple _thumbsHeightAnimation;
|
|
|
|
mutable Animations::Simple _shrinkAnimation;
|
|
|
|
mutable Animations::Simple _finishDragAnimation;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Ui
|