FINAL CUT
fprogressbar.h
1 /***********************************************************************
2 * fprogressbar.h - Widget FProgressbar *
3 * *
4 * This file is part of the FINAL CUT widget toolkit *
5 * *
6 * Copyright 2014-2023 Markus Gans *
7 * *
8 * FINAL CUT is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as *
10 * published by the Free Software Foundation; either version 3 of *
11 * the License, or (at your option) any later version. *
12 * *
13 * FINAL CUT is distributed in the hope that it will be useful, but *
14 * WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this program. If not, see *
20 * <http://www.gnu.org/licenses/>. *
21 ***********************************************************************/
22 
23 /* Inheritance diagram
24  * ═══════════════════
25  *
26  * ▕▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▏
27  * ▕ FVTerm ▏ ▕ FObject ▏
28  * ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▏
29  * ▲ ▲
30  * │ │
31  * └─────┬─────┘
32  * │
33  * ▕▔▔▔▔▔▔▔▔▔▏
34  * ▕ FWidget ▏
35  * ▕▁▁▁▁▁▁▁▁▁▏
36  * ▲
37  * │
38  * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏
39  * ▕ FProgressbar ▏
40  * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏
41  */
42 
43 #ifndef FPROGRESSBAR_H
44 #define FPROGRESSBAR_H
45 
46 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
47  #error "Only <final/final.h> can be included directly."
48 #endif
49 
50 #include "final/fwidget.h"
51 
52 namespace finalcut
53 {
54 
55 //----------------------------------------------------------------------
56 // class FProgressbar
57 //----------------------------------------------------------------------
58 
59 class FProgressbar : public FWidget
60 {
61  public:
62  // Using-declarations
63  using FWidget::setGeometry;
64 
65  // Constructor
66  explicit FProgressbar(FWidget* = nullptr);
67 
68  // Destructor
69  ~FProgressbar() noexcept override;
70 
71  // Accessors
72  auto getClassName() const -> FString override;
73  auto getPercentage() const noexcept -> std::size_t;
74 
75  // Mutators
76  void setPercentage (std::size_t);
77  void setSize (const FSize&, bool = true) override;
78  void setGeometry (const FPoint&, const FSize&, bool = true) override;
79  void setShadow (bool = true) ;
80  void unsetShadow();
81 
82  // Inquiries
83  auto hasShadow() const -> bool;
84 
85  // Methods
86  void hide() override;
87  void reset();
88 
89  private:
90  // Constants
91  static constexpr auto NOT_SET = static_cast<std::size_t>(-1);
92 
93  // Methods
94  void init();
95  void draw() override;
96  void drawProgressLabel();
97  void drawProgressBar();
98  auto drawProgressIndicator() -> std::size_t;
99  void drawProgressBackground (std::size_t);
100 
101  // Data members
102  std::size_t percentage{NOT_SET};
103  std::size_t bar_length{getWidth()};
104 };
105 
106 
107 // FProgressbar inline functions
108 //----------------------------------------------------------------------
109 inline auto FProgressbar::getClassName() const -> FString
110 { return "FProgressbar"; }
111 
112 //----------------------------------------------------------------------
113 inline auto FProgressbar::getPercentage() const noexcept -> std::size_t
114 { return percentage; }
115 
116 //----------------------------------------------------------------------
117 inline void FProgressbar::unsetShadow()
118 { setShadow(false); }
119 
120 //----------------------------------------------------------------------
121 inline auto FProgressbar::hasShadow() const -> bool
122 { return getFlags().shadow.shadow; }
123 
124 } // namespace finalcut
125 
126 #endif // FPROGRESSBAR_H
Definition: fprogressbar.h:59
Definition: class_template.cpp:25
Definition: fpoint.h:50
Definition: fsize.h:55
Definition: fstring.h:79
Definition: fwidget.h:129