Progressbar.h 1.7 KB

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