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 // class forward declaration
56 class FProgressBar;
57 
58 // Legacy code compatibility
59 using FProgressbar = FProgressBar;
60 
61 //----------------------------------------------------------------------
62 // class FProgressBar
63 //----------------------------------------------------------------------
64 
65 class FProgressBar : public FWidget
66 {
67  public:
68  // Using-declarations
69  using FWidget::setGeometry;
70 
71  // Constructor
72  explicit FProgressBar(FWidget* = nullptr);
73 
74  // Destructor
75  ~FProgressBar() noexcept override;
76 
77  // Accessors
78  auto getClassName() const -> FString override;
79  auto getPercentage() const noexcept -> std::size_t;
80 
81  // Mutators
82  void setPercentage (std::size_t);
83  void setSize (const FSize&, bool = true) override;
84  void setGeometry (const FPoint&, const FSize&, bool = true) override;
85  void setShadow (bool = true) ;
86  void unsetShadow();
87 
88  // Predicate
89  auto hasShadow() const -> bool;
90 
91  // Methods
92  void hide() override;
93  void reset();
94 
95  private:
96  // Constants
97  static constexpr auto NOT_SET = static_cast<std::size_t>(-1);
98 
99  // Methods
100  void init();
101  void draw() override;
102  void drawProgressLabel();
103  void drawProgressBar();
104  auto drawProgressIndicator() -> std::size_t;
105  void drawProgressBackground (std::size_t);
106 
107  // Data members
108  std::size_t percentage{NOT_SET};
109  std::size_t bar_length{getWidth()};
110 };
111 
112 
113 // FProgressBar inline functions
114 //----------------------------------------------------------------------
115 inline auto FProgressBar::getClassName() const -> FString
116 { return "FProgressBar"; }
117 
118 //----------------------------------------------------------------------
119 inline auto FProgressBar::getPercentage() const noexcept -> std::size_t
120 { return percentage; }
121 
122 //----------------------------------------------------------------------
123 inline void FProgressBar::unsetShadow()
124 { setShadow(false); }
125 
126 //----------------------------------------------------------------------
127 inline auto FProgressBar::hasShadow() const -> bool
128 { return getFlags().shadow.shadow; }
129 
130 } // namespace finalcut
131 
132 #endif // FPROGRESSBAR_H
Definition: fprogressbar.h:65
Definition: class_template.cpp:25
Definition: fpoint.h:50
Definition: fsize.h:55
Definition: fstring.h:82
Definition: fwidget.h:129