2017-03-27 18:11:51 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-03-27 18:11:51 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-03-27 18:11:51 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ui/twidget.h"
|
|
|
|
#include "ui/abstract_button.h"
|
|
|
|
#include "ui/effects/panel_animation.h"
|
|
|
|
#include "mtproto/sender.h"
|
|
|
|
#include "inline_bots/inline_bot_layout_item.h"
|
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
class ScrollArea;
|
|
|
|
class IconButton;
|
|
|
|
class LinkButton;
|
|
|
|
class RoundButton;
|
2017-06-11 18:33:20 +00:00
|
|
|
class FlatLabel;
|
2017-03-27 18:11:51 +00:00
|
|
|
class RippleAnimation;
|
|
|
|
} // namesapce Ui
|
|
|
|
|
2017-04-07 18:10:49 +00:00
|
|
|
namespace Window {
|
|
|
|
class Controller;
|
|
|
|
} // namespace Window
|
|
|
|
|
2017-03-27 18:11:51 +00:00
|
|
|
namespace InlineBots {
|
|
|
|
|
|
|
|
class Result;
|
|
|
|
|
|
|
|
namespace Layout {
|
|
|
|
|
|
|
|
class ItemBase;
|
|
|
|
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
constexpr int kInlineItemsMaxPerRow = 5;
|
|
|
|
|
|
|
|
using Results = std::vector<std::unique_ptr<Result>>;
|
|
|
|
|
|
|
|
struct CacheEntry {
|
|
|
|
QString nextOffset;
|
|
|
|
QString switchPmText, switchPmStartToken;
|
|
|
|
Results results;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Inner : public TWidget, public Context, private base::Subscriber {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2017-08-17 08:31:24 +00:00
|
|
|
Inner(QWidget *parent, not_null<Window::Controller*> controller);
|
2017-03-27 18:11:51 +00:00
|
|
|
|
|
|
|
void hideFinish(bool completely);
|
|
|
|
|
|
|
|
void clearSelection();
|
|
|
|
|
2017-06-11 18:33:20 +00:00
|
|
|
int refreshInlineRows(PeerData *queryPeer, UserData *bot, const CacheEntry *results, bool resultsDeleted);
|
2017-03-27 18:11:51 +00:00
|
|
|
void inlineBotChanged();
|
|
|
|
void hideInlineRowsPanel();
|
|
|
|
void clearInlineRowsPanel();
|
|
|
|
|
|
|
|
void preloadImages();
|
|
|
|
|
|
|
|
void inlineItemLayoutChanged(const ItemBase *layout) override;
|
|
|
|
void inlineItemRepaint(const ItemBase *layout) override;
|
|
|
|
bool inlineItemVisible(const ItemBase *layout) override;
|
2018-07-13 21:25:47 +00:00
|
|
|
Data::FileOrigin inlineItemFileOrigin() override;
|
2017-03-27 18:11:51 +00:00
|
|
|
|
2017-04-03 16:46:24 +00:00
|
|
|
int countHeight();
|
2017-03-27 18:11:51 +00:00
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
void setResultSelectedCallback(Fn<void(Result *result, UserData *bot)> callback) {
|
2017-03-27 18:11:51 +00:00
|
|
|
_resultSelectedCallback = std::move(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
~Inner();
|
|
|
|
|
|
|
|
protected:
|
2017-09-13 16:57:44 +00:00
|
|
|
void visibleTopBottomUpdated(
|
|
|
|
int visibleTop,
|
|
|
|
int visibleBottom) override;
|
|
|
|
|
2017-03-27 18:11:51 +00:00
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
void leaveEventHook(QEvent *e) override;
|
|
|
|
void leaveToChildEvent(QEvent *e, QWidget *child) override;
|
|
|
|
void enterFromChildEvent(QEvent *e, QWidget *child) override;
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void onPreview();
|
|
|
|
void onUpdateInlineItems();
|
|
|
|
void onSwitchPm();
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void emptyInlineRows();
|
|
|
|
|
|
|
|
private:
|
|
|
|
static constexpr bool kRefreshIconsScrollAnimation = true;
|
|
|
|
static constexpr bool kRefreshIconsNoAnimation = false;
|
|
|
|
|
|
|
|
void updateSelected();
|
2017-06-11 18:33:20 +00:00
|
|
|
void checkRestrictedPeer();
|
|
|
|
bool isRestrictedView();
|
2017-03-27 18:11:51 +00:00
|
|
|
|
|
|
|
void paintInlineItems(Painter &p, const QRect &r);
|
|
|
|
|
|
|
|
void refreshSwitchPmButton(const CacheEntry *entry);
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<Window::Controller*> _controller;
|
2017-04-07 18:10:49 +00:00
|
|
|
|
2017-03-27 18:11:51 +00:00
|
|
|
int _visibleTop = 0;
|
|
|
|
int _visibleBottom = 0;
|
|
|
|
|
2017-06-11 18:33:20 +00:00
|
|
|
UserData *_inlineBot = nullptr;
|
|
|
|
PeerData *_inlineQueryPeer = nullptr;
|
2017-03-27 18:11:51 +00:00
|
|
|
TimeMs _lastScrolled = 0;
|
|
|
|
QTimer _updateInlineItems;
|
|
|
|
bool _inlineWithThumb = false;
|
|
|
|
|
|
|
|
object_ptr<Ui::RoundButton> _switchPmButton = { nullptr };
|
|
|
|
QString _switchPmStartToken;
|
|
|
|
|
2017-06-11 18:33:20 +00:00
|
|
|
object_ptr<Ui::FlatLabel> _restrictedLabel = { nullptr };
|
|
|
|
|
2017-03-27 18:11:51 +00:00
|
|
|
struct Row {
|
|
|
|
int height = 0;
|
|
|
|
QVector<ItemBase*> items;
|
|
|
|
};
|
|
|
|
QVector<Row> _rows;
|
|
|
|
void clearInlineRows(bool resultsDeleted);
|
|
|
|
|
|
|
|
std::map<Result*, std::unique_ptr<ItemBase>> _inlineLayouts;
|
|
|
|
ItemBase *layoutPrepareInlineResult(Result *result, int32 position);
|
|
|
|
|
|
|
|
bool inlineRowsAddItem(Result *result, Row &row, int32 &sumWidth);
|
|
|
|
bool inlineRowFinalize(Row &row, int32 &sumWidth, bool force = false);
|
|
|
|
|
|
|
|
Row &layoutInlineRow(Row &row, int32 sumWidth = 0);
|
|
|
|
void deleteUnusedInlineLayouts();
|
|
|
|
|
|
|
|
int validateExistingInlineRows(const Results &results);
|
|
|
|
void selectInlineResult(int row, int column);
|
|
|
|
|
|
|
|
int _selected = -1;
|
|
|
|
int _pressed = -1;
|
|
|
|
QPoint _lastMousePos;
|
|
|
|
|
|
|
|
QTimer _previewTimer;
|
|
|
|
bool _previewShown = false;
|
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(Result *result, UserData *bot)> _resultSelectedCallback;
|
2017-03-27 18:11:51 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
|
|
|
|
class Widget : public TWidget, private MTP::Sender {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2017-08-17 08:31:24 +00:00
|
|
|
Widget(QWidget *parent, not_null<Window::Controller*> controller);
|
2017-03-27 18:11:51 +00:00
|
|
|
|
|
|
|
void moveBottom(int bottom);
|
|
|
|
|
|
|
|
void hideFast();
|
|
|
|
bool hiding() const {
|
|
|
|
return _hiding;
|
|
|
|
}
|
|
|
|
|
|
|
|
void queryInlineBot(UserData *bot, PeerData *peer, QString query);
|
|
|
|
void clearInlineBot();
|
|
|
|
|
|
|
|
bool overlaps(const QRect &globalRect) const;
|
|
|
|
|
|
|
|
void showAnimated();
|
|
|
|
void hideAnimated();
|
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
void setResultSelectedCallback(Fn<void(Result *result, UserData *bot)> callback) {
|
2017-03-27 18:11:51 +00:00
|
|
|
_inner->setResultSelectedCallback(std::move(callback));
|
|
|
|
}
|
|
|
|
|
|
|
|
~Widget();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void onWndActiveChanged();
|
|
|
|
|
|
|
|
void onScroll();
|
|
|
|
|
|
|
|
void onInlineRequest();
|
|
|
|
void onEmptyInlineRows();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void moveByBottom();
|
|
|
|
void paintContent(Painter &p);
|
|
|
|
|
|
|
|
style::margins innerPadding() const;
|
|
|
|
|
|
|
|
// Rounded rect which has shadow around it.
|
|
|
|
QRect innerRect() const;
|
|
|
|
|
|
|
|
// Inner rect with removed st::buttonRadius from top and bottom.
|
|
|
|
// This one is allowed to be not rounded.
|
|
|
|
QRect horizontalRect() const;
|
|
|
|
|
|
|
|
// Inner rect with removed st::buttonRadius from left and right.
|
|
|
|
// This one is allowed to be not rounded.
|
|
|
|
QRect verticalRect() const;
|
|
|
|
|
|
|
|
QImage grabForPanelAnimation();
|
|
|
|
void startShowAnimation();
|
|
|
|
void startOpacityAnimation(bool hiding);
|
|
|
|
void prepareCache();
|
|
|
|
|
|
|
|
class Container;
|
|
|
|
void opacityAnimationCallback();
|
|
|
|
|
|
|
|
void hideFinished();
|
|
|
|
void showStarted();
|
|
|
|
|
|
|
|
void updateContentHeight();
|
|
|
|
|
|
|
|
void inlineBotChanged();
|
|
|
|
int showInlineRows(bool newResults);
|
|
|
|
void recountContentMaxHeight();
|
|
|
|
bool refreshInlineRows(int *added = nullptr);
|
|
|
|
void inlineResultsDone(const MTPmessages_BotResults &result);
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<Window::Controller*> _controller;
|
2017-04-07 18:10:49 +00:00
|
|
|
|
2017-03-27 18:11:51 +00:00
|
|
|
int _contentMaxHeight = 0;
|
|
|
|
int _contentHeight = 0;
|
|
|
|
bool _horizontal = false;
|
|
|
|
|
|
|
|
int _width = 0;
|
|
|
|
int _height = 0;
|
|
|
|
int _bottom = 0;
|
|
|
|
|
|
|
|
std::unique_ptr<Ui::PanelAnimation> _showAnimation;
|
|
|
|
Animation _a_show;
|
|
|
|
|
|
|
|
bool _hiding = false;
|
|
|
|
QPixmap _cache;
|
|
|
|
Animation _a_opacity;
|
|
|
|
bool _inPanelGrab = false;
|
|
|
|
|
|
|
|
object_ptr<Ui::ScrollArea> _scroll;
|
|
|
|
QPointer<internal::Inner> _inner;
|
|
|
|
|
|
|
|
std::map<QString, std::unique_ptr<internal::CacheEntry>> _inlineCache;
|
|
|
|
QTimer _inlineRequestTimer;
|
|
|
|
|
|
|
|
UserData *_inlineBot = nullptr;
|
|
|
|
PeerData *_inlineQueryPeer = nullptr;
|
|
|
|
QString _inlineQuery, _inlineNextQuery, _inlineNextOffset;
|
|
|
|
mtpRequestId _inlineRequestId = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Layout
|
|
|
|
} // namespace InlineBots
|