tdesktop/Telegram/SourceFiles/ui/countryinput.h

147 lines
3.1 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
2017-04-06 14:38:10 +00:00
#include "boxes/abstract_box.h"
2016-11-24 19:28:23 +00:00
#include "styles/style_widgets.h"
namespace Data {
struct CountryInfo;
} // namespace Data
namespace Ui {
class MultiSelect;
class RippleAnimation;
} // namespace Ui
2016-11-24 19:28:23 +00:00
class CountryInput : public TWidget {
Q_OBJECT
public:
2016-11-24 19:28:23 +00:00
CountryInput(QWidget *parent, const style::InputField &st);
2018-05-30 15:08:12 +00:00
QString iso() const {
return _chosenIso;
}
public slots:
void onChooseCode(const QString &code);
bool onChooseCountry(const QString &country);
signals:
void codeChanged(const QString &code);
protected:
void paintEvent(QPaintEvent *e) override;
void mouseMoveEvent(QMouseEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
void enterEventHook(QEvent *e) override;
void leaveEventHook(QEvent *e) override;
private:
void setText(const QString &newText);
2016-11-24 19:28:23 +00:00
const style::InputField &_st;
bool _active = false;
QString _text;
2018-05-30 15:08:12 +00:00
QString _chosenIso;
QPainterPath _placeholderPath;
};
2019-09-18 11:19:05 +00:00
class CountrySelectBox : public Ui::BoxContent {
Q_OBJECT
public:
2018-04-10 11:26:21 +00:00
enum class Type {
Phones,
Countries,
};
CountrySelectBox(QWidget*);
2018-04-10 11:26:21 +00:00
CountrySelectBox(QWidget*, const QString &iso, Type type);
signals:
void countryChosen(const QString &iso);
protected:
void prepare() override;
void setInnerFocus() override;
void keyPressEvent(QKeyEvent *e) override;
void resizeEvent(QResizeEvent *e) override;
private:
void submit();
void applyFilterUpdate(const QString &query);
2018-04-10 11:26:21 +00:00
Type _type = Type::Phones;
object_ptr<Ui::MultiSelect> _select;
class Inner;
QPointer<Inner> _inner;
};
// This class is hold in header because it requires Qt preprocessing.
class CountrySelectBox::Inner : public TWidget {
2015-10-11 08:37:24 +00:00
Q_OBJECT
public:
2018-04-10 11:26:21 +00:00
Inner(QWidget *parent, Type type);
2015-10-11 08:37:24 +00:00
void updateFilter(QString filter = QString());
void selectSkip(int32 dir);
void selectSkipPage(int32 h, int32 dir);
void chooseCountry();
2015-10-11 08:37:24 +00:00
void refresh();
~Inner();
2015-10-11 08:37:24 +00:00
signals:
void countryChosen(const QString &iso);
void mustScrollTo(int ymin, int ymax);
protected:
void paintEvent(QPaintEvent *e) override;
void enterEventHook(QEvent *e) override;
void leaveEventHook(QEvent *e) override;
void mouseMoveEvent(QMouseEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
2015-10-11 08:37:24 +00:00
private:
void updateSelected() {
updateSelected(mapFromGlobal(QCursor::pos()));
}
void updateSelected(QPoint localPos);
2015-10-11 08:37:24 +00:00
void updateSelectedRow();
void updateRow(int index);
void setPressed(int pressed);
const std::vector<not_null<const Data::CountryInfo*>> &current() const;
2015-10-11 08:37:24 +00:00
2018-04-10 11:26:21 +00:00
Type _type = Type::Phones;
int _rowHeight = 0;
2015-10-11 08:37:24 +00:00
int _selected = -1;
int _pressed = -1;
2015-10-11 08:37:24 +00:00
QString _filter;
bool _mouseSelection = false;
2015-10-11 08:37:24 +00:00
std::vector<std::unique_ptr<Ui::RippleAnimation>> _ripples;
std::vector<not_null<const Data::CountryInfo*>> _list;
std::vector<not_null<const Data::CountryInfo*>> _filtered;
base::flat_map<QChar, std::vector<int>> _byLetter;
std::vector<std::vector<QString>> _namesList;
2015-10-11 08:37:24 +00:00
};