time_input.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // This file is part of Desktop App Toolkit,
  2. // a set of libraries for developing nice desktop applications.
  3. //
  4. // For license and copyright information please follow this link:
  5. // https://github.com/desktop-app/legal/blob/master/LEGAL
  6. //
  7. #pragma once
  8. #include "ui/rp_widget.h"
  9. #include "ui/effects/animations.h"
  10. #include "ui/widgets/labels.h"
  11. namespace Ui {
  12. class TimePart;
  13. class TimeInput final : public RpWidget {
  14. public:
  15. TimeInput(
  16. QWidget *parent,
  17. const QString &value,
  18. const style::InputField &stField,
  19. const style::InputField &stDateField,
  20. const style::FlatLabel &stSeparator,
  21. const style::margins &stSeparatorPadding);
  22. bool setFocusFast();
  23. [[nodiscard]] rpl::producer<QString> value() const;
  24. [[nodiscard]] rpl::producer<> submitRequests() const;
  25. [[nodiscard]] rpl::producer<> focuses() const;
  26. [[nodiscard]] QString valueCurrent() const;
  27. void showError();
  28. int resizeGetHeight(int width) override;
  29. protected:
  30. void paintEvent(QPaintEvent *e) override;
  31. void mousePressEvent(QMouseEvent *e) override;
  32. void mouseMoveEvent(QMouseEvent *e) override;
  33. private:
  34. void setInnerFocus();
  35. void putNext(const object_ptr<TimePart> &field, QChar ch);
  36. void erasePrevious(const object_ptr<TimePart> &field);
  37. void setFocusQueued(const object_ptr<TimePart> &field);
  38. void setErrorShown(bool error);
  39. void setFocused(bool focused);
  40. void startBorderAnimation();
  41. template <typename Widget>
  42. bool insideSeparator(QPoint position, const Widget &widget) const;
  43. [[nodiscard]] std::optional<int> hour() const;
  44. [[nodiscard]] std::optional<int> minute() const;
  45. const style::InputField &_stField;
  46. const style::InputField &_stDateField;
  47. const style::FlatLabel &_stSeparator;
  48. const style::margins &_stSeparatorPadding;
  49. object_ptr<TimePart> _hour;
  50. object_ptr<PaddingWrap<FlatLabel>> _separator1;
  51. object_ptr<TimePart> _minute;
  52. rpl::variable<QString> _value;
  53. rpl::event_stream<> _submitRequests;
  54. rpl::event_stream<> _focuses;
  55. style::cursor _cursor = style::cur_default;
  56. Animations::Simple _a_borderShown;
  57. int _borderAnimationStart = 0;
  58. Animations::Simple _a_borderOpacity;
  59. bool _borderVisible = false;
  60. Animations::Simple _a_error;
  61. bool _error = false;
  62. Animations::Simple _a_focused;
  63. bool _focused = false;
  64. };
  65. } // namespace Ui