FINAL CUT
flabel.h
1 /***********************************************************************
2 * flabel.cpp - Widget FLabel *
3 * *
4 * This file is part of the FINAL CUT widget toolkit *
5 * *
6 * Copyright 2014-2024 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  * ▕ FLabel ▏
40  * ▕▁▁▁▁▁▁▁▁▏
41  */
42 
43 #ifndef FLABEL_H
44 #define FLABEL_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 <vector>
51 
52 #include "final/fwidget.h"
53 #include "final/fwidgetcolors.h"
54 
55 namespace finalcut
56 {
57 
58 //----------------------------------------------------------------------
59 // class FLabel
60 //----------------------------------------------------------------------
61 
62 class FLabel : public FWidget
63 {
64  public:
65  // Using-declaration
66  using FWidget::setEnable;
67  using FWidget::delAccelerator;
68 
69  // Constructor
70  explicit FLabel (FWidget* = nullptr);
71  explicit FLabel (const FString&, FWidget* = nullptr);
72 
73  // Disable copy constructor
74  FLabel (const FLabel&) = delete;
75 
76  // Disable move constructor
77  FLabel (FLabel&&) noexcept = delete;
78 
79  // Destructor
80  ~FLabel() noexcept override;
81 
82  // Disable copy assignment operator (=)
83  auto operator = (const FLabel&) -> FLabel& = delete;
84 
85  // Disable move assignment operator (=)
86  auto operator = (FLabel&&) noexcept -> FLabel& = delete;
87 
88  // Overloaded operators
89  auto operator = (const FString&) -> FLabel&;
90  template <typename typeT>
91  auto operator << (const typeT&) -> FLabel&;
92  auto operator << (UniChar) -> FLabel&;
93  auto operator << (const wchar_t) -> FLabel&;
94 
95  friend inline auto operator >> (const FLabel& lhs, FString& rhs) -> const FLabel&
96  {
97  rhs += lhs.text;
98  return lhs;
99  }
100 
101  // Accessors
102  auto getClassName() const -> FString override;
103  auto getAccelWidget() -> FWidget*;
104  auto getAlignment() const noexcept -> Align;
105  auto getText() & -> FString&;
106 
107  // Mutators
108  void setAccelWidget (FWidget* = nullptr);
109  void setAlignment (Align) noexcept;
110  void setEmphasis (bool = true) noexcept;
111  void unsetEmphasis() noexcept;
112  void resetColors() override;
113  void setReverseMode (bool = true) noexcept;
114  void unsetReverseMode() noexcept;
115  void setEnable (bool = true) override;
116  void setNumber (uLong);
117  void setNumber (long);
118  void setNumber (float, int = FLT_DIG);
119  void setNumber (double, int = DBL_DIG);
120  void setNumber (lDouble, int = LDBL_DIG);
121  void setText (const FString&);
122 
123  // Inquiries
124  auto hasEmphasis() const noexcept -> bool;
125  auto hasReverseMode() const noexcept -> bool;
126 
127  // Methods
128  void hide() override;
129  void clear();
130 
131  // Event handlers
132  void onMouseDown (FMouseEvent*) override;
133  void onAccel (FAccelEvent*) override;
134 
135  // Callback method
136  void cb_accelWidgetDestroyed();
137 
138  private:
139  // Constants
140  static constexpr auto NOT_SET = static_cast<std::size_t>(-1);
141 
142  // Methods
143  void init();
144  void setHotkeyAccelerator();
145  auto getAlignOffset (const std::size_t) const -> std::size_t;
146  void draw() override;
147  void drawMultiLine();
148  void drawSingleLine();
149  void printHotkeyChar (wchar_t);
150  void printLineContent (FString&, std::size_t);
151  void printLine (FString&);
152 
153  // Data members
154  FStringList multiline_text{};
155  FString text{};
156  FWidget* accel_widget{nullptr};
157  Align alignment{Align::Left};
158  std::size_t align_offset{0};
159  std::size_t hotkeypos{NOT_SET};
160  std::size_t column_width{0};
161  FColor emphasis_color{FColor::Default};
162  FColor ellipsis_color{FColor::Default};
163  bool multiline{false};
164  bool emphasis{false};
165  bool reverse_mode{false};
166 };
167 
168 // FLabel inline functions
169 //----------------------------------------------------------------------
170 template <typename typeT>
171 inline auto FLabel::operator << (const typeT& s) -> FLabel&
172 {
173  FString str{};
174  str << s;
175  setText(text + str);
176  return *this;
177 }
178 
179 //----------------------------------------------------------------------
180 inline auto FLabel::getClassName() const -> FString
181 { return "FLabel"; }
182 
183 //----------------------------------------------------------------------
184 inline auto FLabel::getAccelWidget () -> FWidget*
185 { return accel_widget; }
186 
187 //----------------------------------------------------------------------
188 inline auto FLabel::getAlignment() const noexcept -> Align
189 { return alignment; }
190 
191 //----------------------------------------------------------------------
192 inline auto FLabel::getText() & -> FString&
193 { return text; }
194 
195 //----------------------------------------------------------------------
196 inline void FLabel::setEmphasis (bool enable) noexcept
197 { emphasis = enable; }
198 
199 //----------------------------------------------------------------------
200 inline void FLabel::unsetEmphasis() noexcept
201 { setEmphasis(false); }
202 
203 //----------------------------------------------------------------------
204 inline void FLabel::setReverseMode (bool enable) noexcept
205 { reverse_mode = enable; }
206 
207 //----------------------------------------------------------------------
208 inline void FLabel::unsetReverseMode() noexcept
209 { setReverseMode(false); }
210 
211 //----------------------------------------------------------------------
212 inline void FLabel::setNumber (uLong num)
213 { setText(FString().setNumber(num)); }
214 
215 //----------------------------------------------------------------------
216 inline void FLabel::setNumber (long num)
217 { setText(FString().setNumber(num)); }
218 
219 //----------------------------------------------------------------------
220 inline void FLabel::setNumber (float num, int precision)
221 { setText(FString().setNumber(num, precision)); }
222 
223 //----------------------------------------------------------------------
224 inline void FLabel::setNumber (double num, int precision)
225 { setText(FString().setNumber(num, precision)); }
226 
227 //----------------------------------------------------------------------
228 inline void FLabel::setNumber (lDouble num, int precision)
229 { setText(FString().setNumber(num, precision)); }
230 
231 //----------------------------------------------------------------------
232 inline auto FLabel::hasEmphasis() const noexcept -> bool
233 { return emphasis; }
234 
235 //----------------------------------------------------------------------
236 inline auto FLabel::hasReverseMode() const noexcept -> bool
237 { return reverse_mode; }
238 
239 //----------------------------------------------------------------------
240 inline void FLabel::clear()
241 { text.clear(); }
242 
243 } // namespace finalcut
244 
245 #endif // FLABEL_H
Definition: fevent.h:144
Definition: class_template.cpp:25
Definition: fstring.h:79
Definition: fwidget.h:129
Definition: fevent.h:220
Definition: flabel.h:62