time_part_input.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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/widgets/fields/masked_input_field.h"
  9. namespace Ui {
  10. class TimePart : public MaskedInputField {
  11. public:
  12. using MaskedInputField::MaskedInputField;
  13. void setMaxValue(int value);
  14. void setWheelStep(int value);
  15. [[nodiscard]] rpl::producer<> erasePrevious() const;
  16. [[nodiscard]] rpl::producer<> jumpToPrevious() const;
  17. [[nodiscard]] rpl::producer<QChar> putNext() const;
  18. [[nodiscard]] std::optional<int> number();
  19. protected:
  20. void keyPressEvent(QKeyEvent *e) override;
  21. void wheelEvent(QWheelEvent *e) override;
  22. void correctValue(
  23. const QString &was,
  24. int wasCursor,
  25. QString &now,
  26. int &nowCursor) override;
  27. private:
  28. int _maxValue = 0;
  29. int _maxDigits = 0;
  30. int _wheelStep = 0;
  31. rpl::event_stream<> _erasePrevious;
  32. rpl::event_stream<> _jumpToPrevious;
  33. rpl::event_stream<QChar> _putNext;
  34. };
  35. } // namespace Ui