mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 15:43:55 +02:00
Slightly refactored InlineBots::Layout::Widget.
This commit is contained in:
parent
1eea07d88a
commit
af9440db38
2 changed files with 29 additions and 32 deletions
|
@ -159,6 +159,10 @@ bool Inner::tooltipWindowActive() const {
|
||||||
return Ui::AppInFocus() && Ui::InFocusChain(window());
|
return Ui::AppInFocus() && Ui::InFocusChain(window());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rpl::producer<> Inner::inlineRowsCleared() const {
|
||||||
|
return _inlineRowsCleared.events();
|
||||||
|
}
|
||||||
|
|
||||||
Inner::~Inner() = default;
|
Inner::~Inner() = default;
|
||||||
|
|
||||||
void Inner::paintEvent(QPaintEvent *e) {
|
void Inner::paintEvent(QPaintEvent *e) {
|
||||||
|
@ -517,7 +521,7 @@ int Inner::refreshInlineRows(PeerData *queryPeer, UserData *bot, const CacheEntr
|
||||||
clearInlineRows(true);
|
clearInlineRows(true);
|
||||||
deleteUnusedInlineLayouts();
|
deleteUnusedInlineLayouts();
|
||||||
}
|
}
|
||||||
emit emptyInlineRows();
|
_inlineRowsCleared.fire({});
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -788,7 +792,8 @@ Widget::Widget(
|
||||||
, _api(&_controller->session().mtp())
|
, _api(&_controller->session().mtp())
|
||||||
, _contentMaxHeight(st::emojiPanMaxHeight)
|
, _contentMaxHeight(st::emojiPanMaxHeight)
|
||||||
, _contentHeight(_contentMaxHeight)
|
, _contentHeight(_contentMaxHeight)
|
||||||
, _scroll(this, st::inlineBotsScroll) {
|
, _scroll(this, st::inlineBotsScroll)
|
||||||
|
, _inlineRequestTimer([=] { onInlineRequest(); }) {
|
||||||
resize(QRect(0, 0, st::emojiPanWidth, _contentHeight).marginsAdded(innerPadding()).size());
|
resize(QRect(0, 0, st::emojiPanWidth, _contentHeight).marginsAdded(innerPadding()).size());
|
||||||
_width = width();
|
_width = width();
|
||||||
_height = height();
|
_height = height();
|
||||||
|
@ -800,13 +805,17 @@ Widget::Widget(
|
||||||
|
|
||||||
_inner->moveToLeft(0, 0, _scroll->width());
|
_inner->moveToLeft(0, 0, _scroll->width());
|
||||||
|
|
||||||
connect(_scroll, SIGNAL(scrolled()), this, SLOT(onScroll()));
|
connect(
|
||||||
|
_scroll,
|
||||||
|
&Ui::ScrollArea::scrolled,
|
||||||
|
this,
|
||||||
|
&InlineBots::Layout::Widget::onScroll);
|
||||||
|
|
||||||
connect(_inner, SIGNAL(emptyInlineRows()), this, SLOT(onEmptyInlineRows()));
|
_inner->inlineRowsCleared(
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
// inline bots
|
hideAnimated();
|
||||||
_inlineRequestTimer.setSingleShot(true);
|
_inner->clearInlineRowsPanel();
|
||||||
connect(&_inlineRequestTimer, SIGNAL(timeout()), this, SLOT(onInlineRequest()));
|
}, lifetime());
|
||||||
|
|
||||||
macWindowDeactivateEvents(
|
macWindowDeactivateEvents(
|
||||||
) | rpl::filter([=] {
|
) | rpl::filter([=] {
|
||||||
|
@ -1149,12 +1158,12 @@ void Widget::queryInlineBot(UserData *bot, PeerData *peer, QString query) {
|
||||||
_requesting.fire(false);
|
_requesting.fire(false);
|
||||||
}
|
}
|
||||||
if (_inlineCache.find(query) != _inlineCache.cend()) {
|
if (_inlineCache.find(query) != _inlineCache.cend()) {
|
||||||
_inlineRequestTimer.stop();
|
_inlineRequestTimer.cancel();
|
||||||
_inlineQuery = _inlineNextQuery = query;
|
_inlineQuery = _inlineNextQuery = query;
|
||||||
showInlineRows(true);
|
showInlineRows(true);
|
||||||
} else {
|
} else {
|
||||||
_inlineNextQuery = query;
|
_inlineNextQuery = query;
|
||||||
_inlineRequestTimer.start(internal::kInlineBotRequestDelay);
|
_inlineRequestTimer.callOnce(internal::kInlineBotRequestDelay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1188,11 +1197,6 @@ void Widget::onInlineRequest() {
|
||||||
}).handleAllErrors().send();
|
}).handleAllErrors().send();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::onEmptyInlineRows() {
|
|
||||||
hideAnimated();
|
|
||||||
_inner->clearInlineRowsPanel();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Widget::refreshInlineRows(int *added) {
|
bool Widget::refreshInlineRows(int *added) {
|
||||||
auto it = _inlineCache.find(_inlineQuery);
|
auto it = _inlineCache.find(_inlineQuery);
|
||||||
const internal::CacheEntry *entry = nullptr;
|
const internal::CacheEntry *entry = nullptr;
|
||||||
|
|
|
@ -16,8 +16,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "mtproto/sender.h"
|
#include "mtproto/sender.h"
|
||||||
#include "inline_bots/inline_bot_layout_item.h"
|
#include "inline_bots/inline_bot_layout_item.h"
|
||||||
|
|
||||||
#include <QtCore/QTimer>
|
|
||||||
|
|
||||||
namespace Api {
|
namespace Api {
|
||||||
struct SendOptions;
|
struct SendOptions;
|
||||||
} // namespace Api
|
} // namespace Api
|
||||||
|
@ -62,7 +60,6 @@ class Inner
|
||||||
, public Ui::AbstractTooltipShower
|
, public Ui::AbstractTooltipShower
|
||||||
, public Context
|
, public Context
|
||||||
, private base::Subscriber {
|
, private base::Subscriber {
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Inner(QWidget *parent, not_null<Window::SessionController*> controller);
|
Inner(QWidget *parent, not_null<Window::SessionController*> controller);
|
||||||
|
@ -94,6 +91,8 @@ public:
|
||||||
QPoint tooltipPos() const override;
|
QPoint tooltipPos() const override;
|
||||||
bool tooltipWindowActive() const override;
|
bool tooltipWindowActive() const override;
|
||||||
|
|
||||||
|
rpl::producer<> inlineRowsCleared() const;
|
||||||
|
|
||||||
~Inner();
|
~Inner();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -110,12 +109,6 @@ protected:
|
||||||
void enterFromChildEvent(QEvent *e, QWidget *child) override;
|
void enterFromChildEvent(QEvent *e, QWidget *child) override;
|
||||||
void contextMenuEvent(QContextMenuEvent *e) override;
|
void contextMenuEvent(QContextMenuEvent *e) override;
|
||||||
|
|
||||||
private slots:
|
|
||||||
void onSwitchPm();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void emptyInlineRows();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static constexpr bool kRefreshIconsScrollAnimation = true;
|
static constexpr bool kRefreshIconsScrollAnimation = true;
|
||||||
static constexpr bool kRefreshIconsNoAnimation = false;
|
static constexpr bool kRefreshIconsNoAnimation = false;
|
||||||
|
@ -125,6 +118,8 @@ private:
|
||||||
QVector<ItemBase*> items;
|
QVector<ItemBase*> items;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void onSwitchPm();
|
||||||
|
|
||||||
void updateSelected();
|
void updateSelected();
|
||||||
void checkRestrictedPeer();
|
void checkRestrictedPeer();
|
||||||
bool isRestrictedView();
|
bool isRestrictedView();
|
||||||
|
@ -171,6 +166,8 @@ private:
|
||||||
|
|
||||||
std::map<Result*, std::unique_ptr<ItemBase>> _inlineLayouts;
|
std::map<Result*, std::unique_ptr<ItemBase>> _inlineLayouts;
|
||||||
|
|
||||||
|
rpl::event_stream<> _inlineRowsCleared;
|
||||||
|
|
||||||
int _selected = -1;
|
int _selected = -1;
|
||||||
int _pressed = -1;
|
int _pressed = -1;
|
||||||
QPoint _lastMousePos;
|
QPoint _lastMousePos;
|
||||||
|
@ -185,7 +182,6 @@ private:
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
||||||
class Widget : public Ui::RpWidget {
|
class Widget : public Ui::RpWidget {
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Widget(QWidget *parent, not_null<Window::SessionController*> controller);
|
Widget(QWidget *parent, not_null<Window::SessionController*> controller);
|
||||||
|
@ -218,18 +214,15 @@ public:
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *e) override;
|
void paintEvent(QPaintEvent *e) override;
|
||||||
|
|
||||||
private slots:
|
|
||||||
void onScroll();
|
|
||||||
|
|
||||||
void onInlineRequest();
|
|
||||||
void onEmptyInlineRows();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void moveByBottom();
|
void moveByBottom();
|
||||||
void paintContent(Painter &p);
|
void paintContent(Painter &p);
|
||||||
|
|
||||||
style::margins innerPadding() const;
|
style::margins innerPadding() const;
|
||||||
|
|
||||||
|
void onScroll();
|
||||||
|
void onInlineRequest();
|
||||||
|
|
||||||
// Rounded rect which has shadow around it.
|
// Rounded rect which has shadow around it.
|
||||||
QRect innerRect() const;
|
QRect innerRect() const;
|
||||||
|
|
||||||
|
@ -283,7 +276,7 @@ private:
|
||||||
QPointer<internal::Inner> _inner;
|
QPointer<internal::Inner> _inner;
|
||||||
|
|
||||||
std::map<QString, std::unique_ptr<internal::CacheEntry>> _inlineCache;
|
std::map<QString, std::unique_ptr<internal::CacheEntry>> _inlineCache;
|
||||||
QTimer _inlineRequestTimer;
|
base::Timer _inlineRequestTimer;
|
||||||
|
|
||||||
UserData *_inlineBot = nullptr;
|
UserData *_inlineBot = nullptr;
|
||||||
PeerData *_inlineQueryPeer = nullptr;
|
PeerData *_inlineQueryPeer = nullptr;
|
||||||
|
|
Loading…
Add table
Reference in a new issue