Progressbar.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. String text() const { return m_text; }
  24. void set_text(String 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. Format m_format { Percentage };
  37. int m_min { 0 };
  38. int m_max { 100 };
  39. int m_value { 0 };
  40. String m_text;
  41. Orientation m_orientation { Orientation::Horizontal };
  42. };
  43. class VerticalProgressbar final : public Progressbar {
  44. C_OBJECT(VerticalProgressbar);
  45. public:
  46. virtual ~VerticalProgressbar() override = default;
  47. private:
  48. VerticalProgressbar()
  49. : Progressbar(Orientation::Vertical)
  50. {
  51. }
  52. };
  53. class HorizontalProgressbar final : public Progressbar {
  54. C_OBJECT(HorizontalProgressbar);
  55. public:
  56. virtual ~HorizontalProgressbar() override = default;
  57. private:
  58. HorizontalProgressbar()
  59. : Progressbar(Orientation::Horizontal)
  60. {
  61. }
  62. };
  63. }