2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

ITextLink moved to ClickHandler, TextLinkPtr > ClickHandlerPtr.

Global methods textlnkOver/Down/DrawOver were replaced by
static members of ClickHandler, now global state consists
of the handler pointer + host pointer, who declares callbacks
for the active and pressed handler changed events.

This will allow to use ClickHandler from different hosts
simultaneously (like HistoryItem / BotDescription / BotKeyboard).

Not yet tested.
This commit is contained in:
John Preston
2016-03-29 20:17:00 +03:00
parent 2c6f74f923
commit 7f6cf32cdd
40 changed files with 1976 additions and 1446 deletions

View File

@@ -24,16 +24,22 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#include "mainwidget.h"
#include "application.h"
#include "boxes/confirmbox.h"
#include "layerwidget.h"
#include "lang.h"
Q_DECLARE_METATYPE(TextLinkPtr);
Q_DECLARE_METATYPE(ClickHandlerPtr);
Q_DECLARE_METATYPE(Qt::MouseButton);
namespace App {
void sendBotCommand(const QString &cmd, MsgId replyTo) {
if (MainWidget *m = main()) m->sendBotCommand(cmd, replyTo);
void sendBotCommand(PeerData *peer, const QString &cmd, MsgId replyTo) {
if (MainWidget *m = main()) m->sendBotCommand(peer, cmd, replyTo);
}
void sendBotCallback(PeerData *peer, const QString &cmd, MsgId replyTo) {
if (MainWidget *m = main()) m->sendBotCallback(peer, cmd, replyTo);
}
bool insertBotCommand(const QString &cmd, bool specialGif) {
@@ -41,13 +47,36 @@ namespace App {
return false;
}
void activateBotCommand(const HistoryMessageReplyMarkup::Button &button, MsgId replyTo) {
QString cmd(button.text);
App::sendBotCommand(cmd, replyTo);
void activateBotCommand(PeerData *peer, const HistoryMessageReplyMarkup::Button &button, MsgId replyTo) {
switch (button.type) {
case HistoryMessageReplyMarkup::Button::Default: {
// copy string before passing it to the sending method
// the original button can be destroyed inside
sendBotCommand(peer, QString(button.text), replyTo);
} break;
case HistoryMessageReplyMarkup::Button::Callback: {
sendBotCallback(peer, QString(button.text), replyTo);
} break;
case HistoryMessageReplyMarkup::Button::Url: {
HiddenUrlClickHandler(button.url).onClick(Qt::LeftButton);
} break;
case HistoryMessageReplyMarkup::Button::RequestLocation: {
Ui::showLayer(new InformBox(lang(lng_bot_share_location_unavailable)));
} break;
case HistoryMessageReplyMarkup::Button::RequestPhone: {
ConfirmBox *box = new ConfirmBox(lang(lng_bot_share_phone), lang(lng_bot_share_phone_confirm));
box->connect(box, SIGNAL(confirmed()), App::main(), SLOT(onShareBotLocation()));
Ui::showLayer(box);
} break;
}
}
void searchByHashtag(const QString &tag, PeerData *inPeer) {
if (MainWidget *m = main()) m->searchMessages(tag + ' ', (inPeer && inPeer->isChannel()) ? inPeer : 0);
if (MainWidget *m = main()) m->searchMessages(tag + ' ', (inPeer && inPeer->isChannel() && !inPeer->isMegagroup()) ? inPeer : 0);
}
void openPeerByName(const QString &username, MsgId msgId, const QString &startToken) {
@@ -83,11 +112,11 @@ namespace App {
}
}
void activateTextLink(TextLinkPtr link, Qt::MouseButton button) {
void activateClickHandler(ClickHandlerPtr handler, Qt::MouseButton button) {
if (Window *w = wnd()) {
qRegisterMetaType<TextLinkPtr>();
qRegisterMetaType<ClickHandlerPtr>();
qRegisterMetaType<Qt::MouseButton>();
QMetaObject::invokeMethod(w, "app_activateTextLink", Qt::QueuedConnection, Q_ARG(TextLinkPtr, link), Q_ARG(Qt::MouseButton, button));
QMetaObject::invokeMethod(w, "app_activateClickHandler", Qt::QueuedConnection, Q_ARG(ClickHandlerPtr, handler), Q_ARG(Qt::MouseButton, button));
}
}
@@ -165,6 +194,13 @@ namespace Ui {
}
}
PeerData *getPeerForMouseAction() {
if (Window *w = App::wnd()) {
return w->ui_getPeerForMouseAction();
}
return nullptr;
}
bool hideWindowNoQuit() {
if (!App::quitting()) {
if (Window *w = App::wnd()) {