Serenity Operating System
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
8#pragma once
9
10#include <LibGUI/Frame.h>
11
12namespace GUI {
13
14class Progressbar : public Frame {
15 C_OBJECT(Progressbar)
16public:
17 virtual ~Progressbar() override = default;
18
19 void set_range(int min, int max);
20 void set_min(int min) { set_range(min, max()); }
21 void set_max(int max) { set_range(min(), max); }
22 void set_value(int);
23
24 int value() const { return m_value; }
25 int min() const { return m_min; }
26 int max() const { return m_max; }
27
28 void set_orientation(Orientation value);
29 Orientation orientation() const { return m_orientation; }
30
31 DeprecatedString text() const { return m_text; }
32 void set_text(DeprecatedString text) { m_text = move(text); }
33
34 enum Format {
35 NoText,
36 Percentage,
37 ValueSlashMax
38 };
39 Format format() const { return m_format; }
40 void set_format(Format format) { m_format = format; }
41
42protected:
43 Progressbar(Orientation = Orientation::Horizontal);
44
45 virtual void paint_event(PaintEvent&) override;
46
47private:
48 virtual Optional<UISize> calculated_preferred_size() const override;
49
50 Format m_format { Percentage };
51 int m_min { 0 };
52 int m_max { 100 };
53 int m_value { 0 };
54 DeprecatedString m_text;
55 Orientation m_orientation { Orientation::Horizontal };
56};
57
58class VerticalProgressbar final : public Progressbar {
59 C_OBJECT(VerticalProgressbar);
60
61public:
62 virtual ~VerticalProgressbar() override = default;
63
64private:
65 VerticalProgressbar()
66 : Progressbar(Orientation::Vertical)
67 {
68 }
69};
70
71class HorizontalProgressbar final : public Progressbar {
72 C_OBJECT(HorizontalProgressbar);
73
74public:
75 virtual ~HorizontalProgressbar() override = default;
76
77private:
78 HorizontalProgressbar()
79 : Progressbar(Orientation::Horizontal)
80 {
81 }
82};
83
84}