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