2016-04-29 13:46:16 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2016-04-29 13:46:16 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ui/twidget.h"
|
|
|
|
|
2016-11-16 10:44:06 +00:00
|
|
|
namespace Ui {
|
|
|
|
class ScrollArea;
|
|
|
|
} // namespace Ui
|
|
|
|
|
2016-04-29 13:46:16 +00:00
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
using MentionRows = QList<UserData*>;
|
|
|
|
using HashtagRows = QList<QString>;
|
|
|
|
using BotCommandRows = QList<QPair<UserData*, const BotCommand*>>;
|
|
|
|
|
|
|
|
class FieldAutocompleteInner;
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
|
|
|
|
class FieldAutocomplete final : public TWidget {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
FieldAutocomplete(QWidget *parent);
|
|
|
|
|
|
|
|
bool clearFilteredBotCommands();
|
2016-05-08 16:11:47 +00:00
|
|
|
void showFiltered(PeerData *peer, QString query, bool addInlineBots);
|
2016-04-29 13:46:16 +00:00
|
|
|
void showStickers(EmojiPtr emoji);
|
|
|
|
void setBoundings(QRect boundings);
|
|
|
|
|
|
|
|
const QString &filter() const;
|
|
|
|
ChatData *chat() const;
|
|
|
|
ChannelData *channel() const;
|
|
|
|
UserData *user() const;
|
|
|
|
|
|
|
|
int32 innerTop();
|
|
|
|
int32 innerBottom();
|
|
|
|
|
2016-05-10 13:39:42 +00:00
|
|
|
bool eventFilter(QObject *obj, QEvent *e) override;
|
2016-04-29 13:46:16 +00:00
|
|
|
|
|
|
|
enum class ChooseMethod {
|
|
|
|
ByEnter,
|
|
|
|
ByTab,
|
|
|
|
ByClick,
|
|
|
|
};
|
|
|
|
bool chooseSelected(ChooseMethod method) const;
|
|
|
|
|
|
|
|
bool stickersShown() const {
|
|
|
|
return !_srows.isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool overlaps(const QRect &globalRect) {
|
|
|
|
if (isHidden() || !testAttribute(Qt::WA_OpaquePaintEvent)) return false;
|
|
|
|
|
|
|
|
return rect().contains(QRect(mapFromGlobal(globalRect.topLeft()), globalRect.size()));
|
|
|
|
}
|
|
|
|
|
2016-10-26 16:43:13 +00:00
|
|
|
void hideFast();
|
|
|
|
|
2016-04-29 13:46:16 +00:00
|
|
|
~FieldAutocomplete();
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void mentionChosen(UserData *user, FieldAutocomplete::ChooseMethod method) const;
|
|
|
|
void hashtagChosen(QString hashtag, FieldAutocomplete::ChooseMethod method) const;
|
|
|
|
void botCommandChosen(QString command, FieldAutocomplete::ChooseMethod method) const;
|
|
|
|
void stickerChosen(DocumentData *sticker, FieldAutocomplete::ChooseMethod method) const;
|
|
|
|
|
2016-06-24 16:58:41 +00:00
|
|
|
void moderateKeyActivate(int key, bool *outHandled) const;
|
2016-06-22 18:41:13 +00:00
|
|
|
|
2016-04-29 13:46:16 +00:00
|
|
|
public slots:
|
2016-10-26 16:43:13 +00:00
|
|
|
void showAnimated();
|
|
|
|
void hideAnimated();
|
2016-04-29 13:46:16 +00:00
|
|
|
|
2016-10-01 12:34:23 +00:00
|
|
|
protected:
|
2016-04-29 13:46:16 +00:00
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
2016-10-01 12:34:23 +00:00
|
|
|
private:
|
2016-12-07 13:32:25 +00:00
|
|
|
void animationCallback();
|
2016-10-26 16:43:13 +00:00
|
|
|
void hideFinish();
|
|
|
|
|
2016-04-29 13:46:16 +00:00
|
|
|
void updateFiltered(bool resetScroll = false);
|
|
|
|
void recount(bool resetScroll = false);
|
|
|
|
|
|
|
|
QPixmap _cache;
|
|
|
|
internal::MentionRows _mrows;
|
|
|
|
internal::HashtagRows _hrows;
|
|
|
|
internal::BotCommandRows _brows;
|
|
|
|
StickerPack _srows;
|
|
|
|
|
|
|
|
void rowsUpdated(const internal::MentionRows &mrows, const internal::HashtagRows &hrows, const internal::BotCommandRows &brows, const StickerPack &srows, bool resetScroll);
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<Ui::ScrollArea> _scroll;
|
|
|
|
QPointer<internal::FieldAutocompleteInner> _inner;
|
2016-04-29 13:46:16 +00:00
|
|
|
|
2016-10-01 12:34:23 +00:00
|
|
|
ChatData *_chat = nullptr;
|
|
|
|
UserData *_user = nullptr;
|
|
|
|
ChannelData *_channel = nullptr;
|
2016-04-29 13:46:16 +00:00
|
|
|
EmojiPtr _emoji;
|
2016-05-08 16:11:47 +00:00
|
|
|
enum class Type {
|
|
|
|
Mentions,
|
|
|
|
Hashtags,
|
|
|
|
BotCommands,
|
|
|
|
Stickers,
|
|
|
|
};
|
|
|
|
Type _type = Type::Mentions;
|
2016-04-29 13:46:16 +00:00
|
|
|
QString _filter;
|
|
|
|
QRect _boundings;
|
|
|
|
bool _addInlineBots;
|
|
|
|
|
|
|
|
int32 _width, _height;
|
2016-10-01 12:34:23 +00:00
|
|
|
bool _hiding = false;
|
2016-04-29 13:46:16 +00:00
|
|
|
|
2016-12-07 13:32:25 +00:00
|
|
|
Animation _a_opacity;
|
2016-04-29 13:46:16 +00:00
|
|
|
|
|
|
|
friend class internal::FieldAutocompleteInner;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace internal {
|
|
|
|
|
2016-09-26 13:57:08 +00:00
|
|
|
class FieldAutocompleteInner final : public TWidget, private base::Subscriber {
|
2016-04-29 13:46:16 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
FieldAutocompleteInner(FieldAutocomplete *parent, MentionRows *mrows, HashtagRows *hrows, BotCommandRows *brows, StickerPack *srows);
|
|
|
|
|
|
|
|
void clearSel(bool hidden = false);
|
|
|
|
bool moveSel(int key);
|
|
|
|
bool chooseSelected(FieldAutocomplete::ChooseMethod method) const;
|
|
|
|
|
|
|
|
void setRecentInlineBotsInRows(int32 bots);
|
|
|
|
|
2016-07-13 17:34:57 +00:00
|
|
|
signals:
|
2016-04-29 13:46:16 +00:00
|
|
|
void mentionChosen(UserData *user, FieldAutocomplete::ChooseMethod method) const;
|
|
|
|
void hashtagChosen(QString hashtag, FieldAutocomplete::ChooseMethod method) const;
|
|
|
|
void botCommandChosen(QString command, FieldAutocomplete::ChooseMethod method) const;
|
|
|
|
void stickerChosen(DocumentData *sticker, FieldAutocomplete::ChooseMethod method) const;
|
|
|
|
void mustScrollTo(int scrollToTop, int scrollToBottom);
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void onParentGeometryChanged();
|
|
|
|
void onUpdateSelected(bool force = false);
|
|
|
|
void onPreview();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
|
|
|
|
2017-02-11 11:24:37 +00:00
|
|
|
void enterEventHook(QEvent *e) override;
|
|
|
|
void leaveEventHook(QEvent *e) override;
|
2016-04-29 13:46:16 +00:00
|
|
|
|
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
|
|
|
|
|
|
|
void updateSelectedRow();
|
|
|
|
void setSel(int sel, bool scroll = false);
|
|
|
|
|
|
|
|
FieldAutocomplete *_parent;
|
|
|
|
MentionRows *_mrows;
|
|
|
|
HashtagRows *_hrows;
|
|
|
|
BotCommandRows *_brows;
|
|
|
|
StickerPack *_srows;
|
|
|
|
int32 _stickersPerRow, _recentInlineBotsInRows;
|
|
|
|
int32 _sel, _down;
|
|
|
|
bool _mouseSel;
|
|
|
|
QPoint _mousePos;
|
|
|
|
|
|
|
|
bool _overDelete;
|
|
|
|
|
|
|
|
bool _previewShown;
|
|
|
|
|
|
|
|
QTimer _previewTimer;
|
2016-07-13 17:34:57 +00:00
|
|
|
|
2016-04-29 13:46:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace internal
|