countryinput.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. #include "ui/rp_widget.h"
  9. namespace style {
  10. struct InputField;
  11. } // namespace style
  12. namespace Countries {
  13. struct Info;
  14. } // namespace Countries
  15. namespace Ui {
  16. class Show;
  17. } // namespace Ui
  18. class CountryInput : public Ui::RpWidget {
  19. public:
  20. CountryInput(
  21. QWidget *parent,
  22. std::shared_ptr<Ui::Show> show,
  23. const style::InputField &st);
  24. [[nodiscard]] QString iso() const {
  25. return _chosenIso;
  26. }
  27. bool chooseCountry(const QString &country);
  28. void onChooseCode(const QString &code);
  29. rpl::producer<QString> codeChanged() const;
  30. protected:
  31. void paintEvent(QPaintEvent *e) override;
  32. void mouseMoveEvent(QMouseEvent *e) override;
  33. void mousePressEvent(QMouseEvent *e) override;
  34. void enterEventHook(QEnterEvent *e) override;
  35. void leaveEventHook(QEvent *e) override;
  36. private:
  37. void chooseCountry(not_null<const Countries::Info*> info, int codeIndex);
  38. void setText(const QString &newText);
  39. const std::shared_ptr<Ui::Show> _show;
  40. const style::InputField &_st;
  41. bool _active = false;
  42. QString _text;
  43. QString _chosenIso;
  44. rpl::event_stream<QString> _codeChanged;
  45. };