mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Add send context menu to StickerSetBox.
This commit is contained in:
parent
e73928f6a3
commit
4efeaacf5c
4 changed files with 92 additions and 17 deletions
|
@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_file_origin.h"
|
||||
#include "data/data_document_media.h"
|
||||
#include "data/stickers/data_stickers.h"
|
||||
#include "chat_helpers/send_context_menu.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "ui/boxes/confirm_box.h"
|
||||
#include "core/application.h"
|
||||
|
@ -35,6 +36,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "base/unixtime.h"
|
||||
#include "main/main_session.h"
|
||||
#include "apiwrap.h"
|
||||
#include "api/api_toggling_media.h"
|
||||
#include "api/api_common.h"
|
||||
#include "mainwidget.h"
|
||||
#include "mainwindow.h"
|
||||
#include "styles/style_layers.h"
|
||||
|
@ -87,6 +90,7 @@ protected:
|
|||
void mousePressEvent(QMouseEvent *e) override;
|
||||
void mouseMoveEvent(QMouseEvent *e) override;
|
||||
void mouseReleaseEvent(QMouseEvent *e) override;
|
||||
void contextMenuEvent(QContextMenuEvent *e) override;
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
void leaveEventHook(QEvent *e) override;
|
||||
|
||||
|
@ -113,6 +117,8 @@ private:
|
|||
void gotSet(const MTPmessages_StickerSet &set);
|
||||
void installDone(const MTPmessages_StickerSetInstallResult &result);
|
||||
|
||||
void send(not_null<DocumentData*> sticker, Api::SendOptions options);
|
||||
|
||||
not_null<Lottie::MultiPlayer*> getLottiePlayer();
|
||||
|
||||
void showPreview();
|
||||
|
@ -144,6 +150,8 @@ private:
|
|||
base::Timer _previewTimer;
|
||||
int _previewShown = -1;
|
||||
|
||||
base::unique_qptr<Ui::PopupMenu> _menu;
|
||||
|
||||
rpl::event_stream<uint64> _setInstalled;
|
||||
rpl::event_stream<uint64> _setArchived;
|
||||
rpl::event_stream<> _updateControls;
|
||||
|
@ -577,10 +585,14 @@ void StickerSetBox::Inner::installDone(
|
|||
}
|
||||
|
||||
void StickerSetBox::Inner::mousePressEvent(QMouseEvent *e) {
|
||||
int index = stickerFromGlobalPos(e->globalPos());
|
||||
if (index >= 0 && index < _pack.size()) {
|
||||
_previewTimer.callOnce(QApplication::startDragTime());
|
||||
if (e->button() != Qt::LeftButton) {
|
||||
return;
|
||||
}
|
||||
const auto index = stickerFromGlobalPos(e->globalPos());
|
||||
if (index < 0 || index >= _pack.size()) {
|
||||
return;
|
||||
}
|
||||
_previewTimer.callOnce(QApplication::startDragTime());
|
||||
}
|
||||
|
||||
void StickerSetBox::Inner::mouseMoveEvent(QMouseEvent *e) {
|
||||
|
@ -605,18 +617,62 @@ void StickerSetBox::Inner::mouseReleaseEvent(QMouseEvent *e) {
|
|||
_previewShown = -1;
|
||||
return;
|
||||
}
|
||||
if (_previewTimer.isActive()) {
|
||||
_previewTimer.cancel();
|
||||
const auto index = stickerFromGlobalPos(e->globalPos());
|
||||
if (index >= 0 && index < _pack.size() && !isMasksSet()) {
|
||||
const auto sticker = _pack[index];
|
||||
Ui::PostponeCall(crl::guard(_controller, [=] {
|
||||
if (_controller->content()->sendExistingDocument(sticker)) {
|
||||
Ui::hideSettingsAndLayer();
|
||||
}
|
||||
}));
|
||||
}
|
||||
if (!_previewTimer.isActive()) {
|
||||
return;
|
||||
}
|
||||
_previewTimer.cancel();
|
||||
const auto index = stickerFromGlobalPos(e->globalPos());
|
||||
if (index < 0 || index >= _pack.size() || isMasksSet()) {
|
||||
return;
|
||||
}
|
||||
send(_pack[index], Api::SendOptions());
|
||||
}
|
||||
|
||||
void StickerSetBox::Inner::send(
|
||||
not_null<DocumentData*> sticker,
|
||||
Api::SendOptions options) {
|
||||
const auto controller = _controller;
|
||||
Ui::PostponeCall(controller, [=] {
|
||||
if (controller->content()->sendExistingDocument(sticker, options)) {
|
||||
Ui::hideSettingsAndLayer();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void StickerSetBox::Inner::contextMenuEvent(QContextMenuEvent *e) {
|
||||
const auto index = stickerFromGlobalPos(e->globalPos());
|
||||
if (index < 0 || index >= _pack.size()) {
|
||||
return;
|
||||
}
|
||||
const auto type = _controller->content()->sendMenuType();
|
||||
if (type == SendMenu::Type::Disabled) {
|
||||
return;
|
||||
}
|
||||
_previewTimer.cancel();
|
||||
_menu = base::make_unique_q<Ui::PopupMenu>(this);
|
||||
|
||||
const auto document = _pack[index];
|
||||
const auto sendSelected = [=](Api::SendOptions options) {
|
||||
send(document, options);
|
||||
};
|
||||
SendMenu::FillSendMenu(
|
||||
_menu.get(),
|
||||
type,
|
||||
SendMenu::DefaultSilentCallback(sendSelected),
|
||||
SendMenu::DefaultScheduleCallback(this, type, sendSelected));
|
||||
|
||||
const auto toggleFavedSticker = [=] {
|
||||
Api::ToggleFavedSticker(
|
||||
document,
|
||||
Data::FileOriginStickerSet(Data::Stickers::FavedSetId, 0));
|
||||
};
|
||||
_menu->addAction(
|
||||
(document->owner().stickers().isFaved(document)
|
||||
? tr::lng_faved_stickers_remove
|
||||
: tr::lng_faved_stickers_add)(tr::now),
|
||||
toggleFavedSticker);
|
||||
|
||||
_menu->popup(QCursor::pos());
|
||||
}
|
||||
|
||||
void StickerSetBox::Inner::updateSelected() {
|
||||
|
|
|
@ -265,6 +265,7 @@ public:
|
|||
void confirmDeleteSelected();
|
||||
void clearSelected();
|
||||
|
||||
[[nodiscard]] SendMenu::Type sendMenuType() const;
|
||||
bool sendExistingDocument(
|
||||
not_null<DocumentData*> document,
|
||||
Api::SendOptions options);
|
||||
|
@ -374,7 +375,6 @@ private:
|
|||
void sendWithModifiers(Qt::KeyboardModifiers modifiers);
|
||||
void sendSilent();
|
||||
void sendScheduled();
|
||||
[[nodiscard]] SendMenu::Type sendMenuType() const;
|
||||
[[nodiscard]] SendMenu::Type sendButtonMenuType() const;
|
||||
void handlePendingHistoryUpdate();
|
||||
void fullInfoUpdated();
|
||||
|
|
|
@ -1067,8 +1067,18 @@ void MainWidget::inlineResultLoadFailed(FileLoader *loader, bool started) {
|
|||
//Ui::repaintInlineItem();
|
||||
}
|
||||
|
||||
SendMenu::Type MainWidget::sendMenuType() const {
|
||||
return _history->sendMenuType();
|
||||
}
|
||||
|
||||
bool MainWidget::sendExistingDocument(not_null<DocumentData*> document) {
|
||||
return _history->sendExistingDocument(document, Api::SendOptions());
|
||||
return sendExistingDocument(document, Api::SendOptions());
|
||||
}
|
||||
|
||||
bool MainWidget::sendExistingDocument(
|
||||
not_null<DocumentData*> document,
|
||||
Api::SendOptions options) {
|
||||
return _history->sendExistingDocument(document, options);
|
||||
}
|
||||
|
||||
void MainWidget::dialogsCancelled() {
|
||||
|
|
|
@ -29,8 +29,13 @@ class Error;
|
|||
|
||||
namespace Api {
|
||||
struct SendAction;
|
||||
struct SendOptions;
|
||||
} // namespace Api
|
||||
|
||||
namespace SendMenu {
|
||||
enum class Type;
|
||||
} // namespace SendMenu
|
||||
|
||||
namespace Main {
|
||||
class Session;
|
||||
} // namespace Main
|
||||
|
@ -150,7 +155,11 @@ public:
|
|||
QPixmap grabForShowAnimation(const Window::SectionSlideParams ¶ms);
|
||||
void checkMainSectionToLayer();
|
||||
|
||||
bool sendExistingDocument(not_null<DocumentData*> sticker);
|
||||
[[nodiscard]] SendMenu::Type sendMenuType() const;
|
||||
bool sendExistingDocument(not_null<DocumentData*> document);
|
||||
bool sendExistingDocument(
|
||||
not_null<DocumentData*> document,
|
||||
Api::SendOptions options);
|
||||
|
||||
bool isActive() const;
|
||||
[[nodiscard]] bool doWeMarkAsRead() const;
|
||||
|
|
Loading…
Add table
Reference in a new issue