tdesktop/Telegram/SourceFiles/ui/widgets/multi_select.h

76 lines
2.0 KiB
C
Raw Normal View History

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "styles/style_widgets.h"
2017-09-13 16:57:44 +00:00
#include "ui/rp_widget.h"
2019-04-02 09:13:30 +00:00
#include "ui/effects/animations.h"
2019-09-13 12:22:54 +00:00
#include "base/object_ptr.h"
#include <set>
namespace Ui {
class InputField;
2016-11-21 17:46:29 +00:00
class CrossButton;
class ScrollArea;
2017-09-13 16:57:44 +00:00
class MultiSelect : public RpWidget {
public:
MultiSelect(
QWidget *parent,
const style::MultiSelect &st,
rpl::producer<QString> placeholder = nullptr);
QString getQuery() const;
void setInnerFocus();
2016-10-21 12:28:26 +00:00
void clearQuery();
void setQueryChangedCallback(Fn<void(const QString &query)> callback);
void setSubmittedCallback(Fn<void(Qt::KeyboardModifiers)> callback);
void setCancelledCallback(Fn<void()> callback);
void setResizedCallback(Fn<void()> callback);
enum class AddItemWay {
Default,
SkipAnimation,
};
using PaintRoundImage = Fn<void(Painter &p, int x, int y, int outerWidth, int size)>;
void addItem(uint64 itemId, const QString &text, style::color color, PaintRoundImage paintRoundImage, AddItemWay way = AddItemWay::Default);
void addItemInBunch(uint64 itemId, const QString &text, style::color color, PaintRoundImage paintRoundImage);
void finishItemsBunch();
void setItemText(uint64 itemId, const QString &text);
void setItemRemovedCallback(Fn<void(uint64 itemId)> callback);
2016-10-21 12:28:26 +00:00
void removeItem(uint64 itemId);
int getItemsCount() const;
QVector<uint64> getItems() const;
bool hasItem(uint64 itemId) const;
protected:
int resizeGetHeight(int newWidth) override;
2016-10-21 12:28:26 +00:00
bool eventFilter(QObject *o, QEvent *e) override;
private:
2016-10-21 12:28:26 +00:00
void scrollTo(int activeTop, int activeBottom);
const style::MultiSelect &_st;
object_ptr<Ui::ScrollArea> _scroll;
2016-10-21 12:28:26 +00:00
class Inner;
QPointer<Inner> _inner;
Fn<void()> _resizedCallback;
Fn<void(const QString &query)> _queryChangedCallback;
};
} // namespace Ui