2016-10-20 19:48:35 +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.
|
2016-10-20 19:48:35 +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
|
2016-10-20 19:48:35 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2019-09-13 12:22:54 +00:00
|
|
|
#include "base/object_ptr.h"
|
2022-04-22 12:14:16 +00:00
|
|
|
#include "ui/rp_widget.h"
|
2016-10-20 19:48:35 +00:00
|
|
|
|
2022-04-22 12:14:16 +00:00
|
|
|
namespace style {
|
|
|
|
struct MultiSelect;
|
|
|
|
} // namespace style
|
2021-03-23 16:06:59 +00:00
|
|
|
|
2016-10-20 19:48:35 +00:00
|
|
|
namespace Ui {
|
|
|
|
|
2016-11-16 10:44:06 +00:00
|
|
|
class ScrollArea;
|
2016-10-20 19:48:35 +00:00
|
|
|
|
2017-09-13 16:57:44 +00:00
|
|
|
class MultiSelect : public RpWidget {
|
2016-10-20 19:48:35 +00:00
|
|
|
public:
|
2019-06-18 14:07:45 +00:00
|
|
|
MultiSelect(
|
|
|
|
QWidget *parent,
|
|
|
|
const style::MultiSelect &st,
|
|
|
|
rpl::producer<QString> placeholder = nullptr);
|
2016-10-20 19:48:35 +00:00
|
|
|
|
|
|
|
QString getQuery() const;
|
|
|
|
void setInnerFocus();
|
2016-10-21 12:28:26 +00:00
|
|
|
void clearQuery();
|
2016-10-20 19:48:35 +00:00
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
void setQueryChangedCallback(Fn<void(const QString &query)> callback);
|
|
|
|
void setSubmittedCallback(Fn<void(Qt::KeyboardModifiers)> callback);
|
2018-10-30 11:23:54 +00:00
|
|
|
void setCancelledCallback(Fn<void()> callback);
|
2018-06-04 15:35:11 +00:00
|
|
|
void setResizedCallback(Fn<void()> callback);
|
2016-10-20 19:48:35 +00:00
|
|
|
|
2016-10-22 13:03:20 +00:00
|
|
|
enum class AddItemWay {
|
|
|
|
Default,
|
|
|
|
SkipAnimation,
|
|
|
|
};
|
2018-06-04 15:35:11 +00:00
|
|
|
using PaintRoundImage = Fn<void(Painter &p, int x, int y, int outerWidth, int size)>;
|
2017-02-26 11:32:13 +00:00
|
|
|
void addItem(uint64 itemId, const QString &text, style::color color, PaintRoundImage paintRoundImage, AddItemWay way = AddItemWay::Default);
|
2017-03-17 12:05:50 +00:00
|
|
|
void addItemInBunch(uint64 itemId, const QString &text, style::color color, PaintRoundImage paintRoundImage);
|
|
|
|
void finishItemsBunch();
|
2016-10-20 19:48:35 +00:00
|
|
|
void setItemText(uint64 itemId, const QString &text);
|
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
void setItemRemovedCallback(Fn<void(uint64 itemId)> callback);
|
2016-10-21 12:28:26 +00:00
|
|
|
void removeItem(uint64 itemId);
|
2016-10-20 19:48:35 +00:00
|
|
|
|
2017-03-17 12:05:50 +00:00
|
|
|
int getItemsCount() const;
|
|
|
|
QVector<uint64> getItems() const;
|
|
|
|
bool hasItem(uint64 itemId) const;
|
|
|
|
|
2016-10-20 19:48:35 +00:00
|
|
|
protected:
|
|
|
|
int resizeGetHeight(int newWidth) override;
|
2016-10-21 12:28:26 +00:00
|
|
|
bool eventFilter(QObject *o, QEvent *e) override;
|
2016-10-20 19:48:35 +00:00
|
|
|
|
|
|
|
private:
|
2016-10-21 12:28:26 +00:00
|
|
|
void scrollTo(int activeTop, int activeBottom);
|
2016-10-20 19:48:35 +00:00
|
|
|
|
|
|
|
const style::MultiSelect &_st;
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<Ui::ScrollArea> _scroll;
|
2016-10-20 19:48:35 +00:00
|
|
|
|
2016-10-21 12:28:26 +00:00
|
|
|
class Inner;
|
2016-12-13 17:07:56 +00:00
|
|
|
QPointer<Inner> _inner;
|
2016-10-20 19:48:35 +00:00
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void()> _resizedCallback;
|
|
|
|
Fn<void(const QString &query)> _queryChangedCallback;
|
2016-10-20 19:48:35 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Ui
|