/* 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" #include "ui/chat/attach/attach_send_files_way.h" namespace Ui { struct PreparedFile; struct GroupMediaLayout; class AlbumThumbnail; class AlbumPreview final : public RpWidget { public: AlbumPreview( QWidget *parent, gsl::span items, SendFilesWay way); ~AlbumPreview(); void setSendWay(SendFilesWay way); std::vector takeOrder(); [[nodiscard]] rpl::producer thumbDeleted() const { return _thumbDeleted.events(); } [[nodiscard]] rpl::producer thumbChanged() const { return _thumbChanged.events(); } rpl::producer thumbModified() const; 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 &layout) const; std::vector generateOrderedLayout() const; std::vector defaultOrder(int count = -1) const; void prepareThumbs(gsl::span items); void updateSizeAnimated(const std::vector &layout); void updateSize(); void updateFileRows(); int thumbIndex(AlbumThumbnail *thumb); AlbumThumbnail *thumbUnderCursor(); void deleteThumbByIndex(int index); void changeThumbByIndex(int index); void thumbButtonsCallback( not_null 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 findClosestThumb(QPoint position) const; void updateSuggestedDrag(QPoint position); int orderIndex(not_null thumb) const; void cancelDrag(); void finishDrag(); SendFilesWay _sendWay; style::cursor _cursor = style::cur_default; std::vector _order; std::vector _itemsShownDimensions; std::vector> _thumbs; int _thumbsHeight = 0; int _photosHeight = 0; int _filesHeight = 0; AlbumThumbnail *_draggedThumb = nullptr; AlbumThumbnail *_suggestedThumb = nullptr; AlbumThumbnail *_paintedAbove = nullptr; QPoint _draggedStartPosition; AttachButtonType _pressedButtonType = AttachButtonType::None; rpl::event_stream _thumbDeleted; rpl::event_stream _thumbChanged; rpl::event_stream _thumbModified; mutable Animations::Simple _thumbsHeightAnimation; mutable Animations::Simple _shrinkAnimation; mutable Animations::Simple _finishDragAnimation; }; } // namespace Ui