Progressbar.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2022, the SerenityOS developers.
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <LibGUI/Frame.h>
  9. namespace GUI {
  10. class Progressbar : public Frame {
  11. C_OBJECT(Progressbar)
  12. public:
  13. virtual ~Progressbar() override = default;
  14. void set_range(int min, int max);
  15. void set_min(int min) { set_range(min, max()); }
  16. void set_max(int max) { set_range(min(), max); }
  17. void set_value(int);
  18. int value() const { return m_value; }
  19. int min() const { return m_min; }
  20. int max() const { return m_max; }
  21. void set_orientation(Orientation value);
  22. Orientation orientation() const { return m_orientation; }
  23. DeprecatedString text() const { return m_text; }
  24. void set_text(DeprecatedString text) { m_text = move(text); }
  25. enum Format {
  26. NoText,
  27. Percentage,
  28. ValueSlashMax
  29. };
  30. Format format() const { return m_format; }
  31. void set_format(Format format) { m_format = format; }
  32. protected:
  33. Progressbar(Orientation = Orientation::Horizontal);
  34. virtual void paint_event(PaintEvent&) override;
  35. private:
  36. virtual Optional<UISize> calculated_preferred_size() const override;
  37. Format m_format { Percentage };
  38. int m_min { 0 };
  39. int m_max { 100 };
  40. int m_value { 0 };
  41. DeprecatedString m_text;
  42. Orientation m_orientation { Orientation::Horizontal };
  43. };
  44. class VerticalProgressbar final : public Progressbar {
  45. C_OBJECT(VerticalProgressbar);
  46. public:
  47. virtual ~VerticalProgressbar() override = default;
  48. private:
  49. VerticalProgressbar()
  50. : Progressbar(Orientation::Vertical)
  51. {
  52. }
  53. };
  54. class HorizontalProgressbar final : public Progressbar {
  55. C_OBJECT(HorizontalProgressbar);
  56. public:
  57. virtual ~HorizontalProgressbar() override = default;
  58. private:
  59. HorizontalProgressbar()
  60. : Progressbar(Orientation::Horizontal)
  61. {
  62. }
  63. };
  64. }