2014-05-30 08:53:19 +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.
|
2014-05-30 08:53:19 +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
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#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"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2019-06-22 12:01:54 +00:00
|
|
|
namespace Data {
|
|
|
|
struct CountryInfo;
|
|
|
|
} // namespace Data
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
namespace Ui {
|
2016-10-22 13:03:20 +00:00
|
|
|
class MultiSelect;
|
2018-01-11 19:33:26 +00:00
|
|
|
class RippleAnimation;
|
2016-10-20 16:32:15 +00:00
|
|
|
} // namespace Ui
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
class CountryInput : public TWidget {
|
2014-05-30 08:53:19 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2016-11-24 19:28:23 +00:00
|
|
|
CountryInput(QWidget *parent, const style::InputField &st);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2018-05-30 15:08:12 +00:00
|
|
|
QString iso() const {
|
|
|
|
return _chosenIso;
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
public slots:
|
|
|
|
void onChooseCode(const QString &code);
|
|
|
|
bool onChooseCountry(const QString &country);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void codeChanged(const QString &code);
|
|
|
|
|
2016-08-16 16:53:10 +00:00
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
2017-02-11 11:24:37 +00:00
|
|
|
void enterEventHook(QEvent *e) override;
|
|
|
|
void leaveEventHook(QEvent *e) override;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-08-16 16:53:10 +00:00
|
|
|
private:
|
2014-05-30 08:53:19 +00:00
|
|
|
void setText(const QString &newText);
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
const style::InputField &_st;
|
|
|
|
bool _active = false;
|
2014-05-30 08:53:19 +00:00
|
|
|
QString _text;
|
2018-05-30 15:08:12 +00:00
|
|
|
QString _chosenIso;
|
2016-12-09 18:56:01 +00:00
|
|
|
QPainterPath _placeholderPath;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-09-18 11:19:05 +00:00
|
|
|
class CountrySelectBox : public Ui::BoxContent {
|
2016-10-20 16:32:15 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2018-04-10 11:26:21 +00:00
|
|
|
enum class Type {
|
|
|
|
Phones,
|
|
|
|
Countries,
|
|
|
|
};
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
CountrySelectBox(QWidget*);
|
2018-04-10 11:26:21 +00:00
|
|
|
CountrySelectBox(QWidget*, const QString &iso, Type type);
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
signals:
|
|
|
|
void countryChosen(const QString &iso);
|
|
|
|
|
|
|
|
protected:
|
2016-12-13 17:07:56 +00:00
|
|
|
void prepare() override;
|
|
|
|
void setInnerFocus() override;
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void keyPressEvent(QKeyEvent *e) override;
|
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
2018-12-29 08:11:54 +00:00
|
|
|
void submit();
|
|
|
|
void applyFilterUpdate(const QString &query);
|
2016-10-22 13:03:20 +00:00
|
|
|
|
2018-04-10 11:26:21 +00:00
|
|
|
Type _type = Type::Phones;
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<Ui::MultiSelect> _select;
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
class Inner;
|
|
|
|
QPointer<Inner> _inner;
|
2016-10-20 16:32:15 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// This class is hold in header because it requires Qt preprocessing.
|
2016-10-26 16:43:13 +00:00
|
|
|
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();
|
2016-08-16 16:53:10 +00:00
|
|
|
|
2015-10-11 08:37:24 +00:00
|
|
|
void refresh();
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
~Inner();
|
|
|
|
|
2015-10-11 08:37:24 +00:00
|
|
|
signals:
|
|
|
|
void countryChosen(const QString &iso);
|
|
|
|
void mustScrollTo(int ymin, int ymax);
|
|
|
|
|
2016-08-16 16:53:10 +00:00
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
2017-02-11 11:24:37 +00:00
|
|
|
void enterEventHook(QEvent *e) override;
|
|
|
|
void leaveEventHook(QEvent *e) override;
|
2016-08-16 16:53:10 +00:00
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
2016-12-05 11:01:08 +00:00
|
|
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
2015-10-11 08:37:24 +00:00
|
|
|
|
2016-08-16 16:53:10 +00:00
|
|
|
private:
|
2016-12-05 11:01:08 +00:00
|
|
|
void updateSelected() {
|
|
|
|
updateSelected(mapFromGlobal(QCursor::pos()));
|
|
|
|
}
|
|
|
|
void updateSelected(QPoint localPos);
|
2015-10-11 08:37:24 +00:00
|
|
|
void updateSelectedRow();
|
2016-12-05 11:01:08 +00:00
|
|
|
void updateRow(int index);
|
|
|
|
void setPressed(int pressed);
|
2019-06-22 12:01:54 +00:00
|
|
|
const std::vector<not_null<const Data::CountryInfo*>> ¤t() 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
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
int _selected = -1;
|
|
|
|
int _pressed = -1;
|
2015-10-11 08:37:24 +00:00
|
|
|
QString _filter;
|
2016-12-05 11:01:08 +00:00
|
|
|
bool _mouseSelection = false;
|
2015-10-11 08:37:24 +00:00
|
|
|
|
2017-02-21 13:45:56 +00:00
|
|
|
std::vector<std::unique_ptr<Ui::RippleAnimation>> _ripples;
|
2016-08-16 16:53:10 +00:00
|
|
|
|
2019-06-22 12:01:54 +00:00
|
|
|
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
|
|
|
};
|