tdesktop/Telegram/SourceFiles/boxes/send_files_box.h

204 lines
5.0 KiB
C
Raw Normal View History

/*
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
2017-12-22 17:42:33 +00:00
#include <rpl/variable.h>
2017-04-06 14:38:10 +00:00
#include "boxes/abstract_box.h"
#include "ui/chat/attach/attach_prepare.h"
2020-10-15 14:27:16 +00:00
#include "ui/chat/attach/attach_send_files_way.h"
2017-03-04 10:23:56 +00:00
#include "storage/localimageloader.h"
2017-12-19 16:57:42 +00:00
#include "storage/storage_media_prepare.h"
namespace Window {
class SessionController;
} // namespace Window
namespace Api {
struct SendOptions;
2019-08-20 13:21:10 +00:00
enum class SendType;
} // namespace Api
namespace ChatHelpers {
class TabbedPanel;
} // namespace ChatHelpers
namespace Ui {
2020-10-15 14:27:16 +00:00
class Checkbox;
class RoundButton;
class InputField;
2017-12-19 16:57:42 +00:00
struct GroupMediaLayout;
class EmojiButton;
class AlbumPreview;
2020-10-16 07:52:55 +00:00
class VerticalLayout;
class FlatLabel;
} // namespace Ui
2018-04-06 16:23:09 +00:00
namespace Window {
class SessionController;
2018-04-06 16:23:09 +00:00
} // namespace Window
namespace SendMenu {
enum class Type;
} // namespace SendMenu
2019-08-28 16:46:47 +00:00
2019-09-18 11:19:05 +00:00
class SendFilesBox : public Ui::BoxContent {
public:
2019-07-17 10:37:42 +00:00
enum class SendLimit {
One,
Many
};
SendFilesBox(
QWidget*,
not_null<Window::SessionController*> controller,
Ui::PreparedList &&list,
const TextWithTags &caption,
2019-08-20 13:21:10 +00:00
SendLimit limit,
2019-08-28 16:46:47 +00:00
Api::SendType sendType,
SendMenu::Type sendMenuType);
void setConfirmedCallback(
Fn<void(
Ui::PreparedList &&list,
Ui::SendFilesWay way,
TextWithTags &&caption,
Api::SendOptions options,
bool ctrlShiftEnter)> callback) {
_confirmedCallback = std::move(callback);
}
void setCancelledCallback(Fn<void()> callback) {
_cancelledCallback = std::move(callback);
}
2015-10-11 08:37:24 +00:00
~SendFilesBox();
protected:
void prepare() override;
void setInnerFocus() override;
void keyPressEvent(QKeyEvent *e) override;
void paintEvent(QPaintEvent *e) override;
void resizeEvent(QResizeEvent *e) override;
private:
class Block final {
public:
Block(
not_null<QWidget*> parent,
not_null<std::vector<Ui::PreparedFile>*> items,
int from,
int till,
Fn<bool()> gifPaused,
Ui::SendFilesWay way);
Block(Block &&other) = default;
Block &operator=(Block &&other) = default;
[[nodiscard]] int fromIndex() const;
[[nodiscard]] int tillIndex() const;
[[nodiscard]] object_ptr<Ui::RpWidget> takeWidget();
[[nodiscard]] rpl::producer<int> itemDeleteRequest() const;
[[nodiscard]] rpl::producer<int> itemReplaceRequest() const;
[[nodiscard]] rpl::producer<int> itemModifyRequest() const;
void setSendWay(Ui::SendFilesWay way);
void applyAlbumOrder();
private:
base::unique_qptr<Ui::RpWidget> _preview;
not_null<std::vector<Ui::PreparedFile>*> _items;
int _from = 0;
int _till = 0;
bool _isAlbum = false;
bool _isSingleMedia = false;
2020-10-16 07:52:55 +00:00
};
2017-12-22 17:42:33 +00:00
void initSendWay();
2020-10-16 07:52:55 +00:00
void initPreview();
2017-12-22 17:42:33 +00:00
void refreshControls();
2017-12-22 17:42:33 +00:00
void setupSendWayControls();
void setupCaption();
void setupShadows();
2017-12-22 17:42:33 +00:00
void setupEmojiPanel();
2020-10-15 14:27:16 +00:00
void updateSendWayControlsVisibility();
void updateEmojiPanelGeometry();
void emojiFilterForGeometry(not_null<QEvent*> event);
void preparePreview();
void generatePreviewFrom(int fromBlock);
void send(Api::SendOptions options, bool ctrlShiftEnter = false);
void sendSilent();
void sendScheduled();
2017-12-19 16:57:42 +00:00
void captionResized();
void saveSendWaySettings();
2017-12-19 16:57:42 +00:00
void setupDragArea();
void refreshTitleText();
2015-10-11 08:37:24 +00:00
void updateBoxSize();
void updateControlsGeometry();
void updateCaptionPlaceholder();
2015-10-11 08:37:24 +00:00
bool canAddFiles(not_null<const QMimeData*> data) const;
bool addFiles(not_null<const QMimeData*> data);
bool addFiles(Ui::PreparedList list);
void addFile(Ui::PreparedFile &&file);
void pushBlock(int from, int till);
void openDialogToAddFileToAlbum();
void refreshAllAfterChanges(int fromItem);
void enqueueNextPrepare();
void addPreparedAsyncFile(Ui::PreparedFile &&file);
2019-08-20 13:21:10 +00:00
const not_null<Window::SessionController*> _controller;
const Api::SendType _sendType = Api::SendType();
QString _titleText;
2020-10-19 10:02:39 +00:00
rpl::variable<int> _titleHeight = 0;
2017-12-22 17:42:33 +00:00
Ui::PreparedList _list;
std::optional<int> _removingIndex;
2019-07-17 10:37:42 +00:00
SendLimit _sendLimit = SendLimit::Many;
SendMenu::Type _sendMenuType = SendMenu::Type();
Fn<void(
Ui::PreparedList &&list,
Ui::SendFilesWay way,
TextWithTags &&caption,
Api::SendOptions options,
bool ctrlShiftEnter)> _confirmedCallback;
Fn<void()> _cancelledCallback;
bool _confirmed = false;
object_ptr<Ui::InputField> _caption = { nullptr };
object_ptr<Ui::EmojiButton> _emojiToggle = { nullptr };
base::unique_qptr<ChatHelpers::TabbedPanel> _emojiPanel;
base::unique_qptr<QObject> _emojiFilter;
2020-10-15 14:27:16 +00:00
object_ptr<Ui::Checkbox> _groupFiles = { nullptr };
2020-10-17 09:51:55 +00:00
object_ptr<Ui::Checkbox> _sendImagesAsPhotos = { nullptr };
object_ptr<Ui::FlatLabel> _hintLabel = { nullptr };
2020-10-15 14:27:16 +00:00
rpl::variable<Ui::SendFilesWay> _sendWay = Ui::SendFilesWay();
2017-12-22 17:42:33 +00:00
rpl::variable<int> _footerHeight = 0;
2020-10-15 14:27:16 +00:00
rpl::lifetime _dimensionsLifetime;
2017-12-19 16:57:42 +00:00
2020-10-16 07:52:55 +00:00
object_ptr<Ui::ScrollArea> _scroll;
QPointer<Ui::VerticalLayout> _inner;
std::vector<Block> _blocks;
Fn<void()> _whenReadySend;
bool _preparing = false;
2017-12-19 16:57:42 +00:00
2017-12-22 17:42:33 +00:00
QPointer<Ui::RoundButton> _send;
2020-10-15 14:27:16 +00:00
QPointer<Ui::RoundButton> _addFile;
2017-12-19 16:57:42 +00:00
};