FINAL CUT
fspinbox.h
1 /***********************************************************************
2 * fspinbox.h - Widget FSpinBox *
3 * *
4 * This file is part of the FINAL CUT widget toolkit *
5 * *
6 * Copyright 2019-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  * ▕ FSpinBox ▏
40  * ▕▁▁▁▁▁▁▁▁▁▁▏
41  */
42 
43 #ifndef FSPINBOX_H
44 #define FSPINBOX_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 <limits>
51 
52 #include "final/fwidget.h"
53 #include "final/widget/flineedit.h"
54 
55 namespace finalcut
56 {
57 
58 // class forward declaration
59 class FLineEdit;
60 
61 //----------------------------------------------------------------------
62 // class FSpinBox
63 //----------------------------------------------------------------------
64 
65 class FSpinBox : public FWidget
66 {
67  public:
68  // Using-declaration
69  using FWidget::setGeometry;
70  using LabelOrientation = FLineEdit::LabelOrientation;
71 
72  // Constructors
73  explicit FSpinBox (FWidget* = nullptr);
74 
75  // Destructor
76  ~FSpinBox() noexcept override;
77 
78  // Accessors
79  auto getClassName() const -> FString override;
80  auto getValue() const noexcept -> sInt64;
81  auto getPrefix() const -> FString;
82  auto getSuffix() const -> FString;
83  auto getLabelOrientation() const -> LabelOrientation;
84 
85  // Mutators
86  void setSize (const FSize&, bool = true) override;
87  void setGeometry (const FPoint&, const FSize&, bool = true) override;
88  void setEnable (bool = true) override;
89  void unsetEnable() override;
90  void setDisable() override;
91  void setShadow (bool = true);
92  void unsetShadow();
93  void setValue (sInt64);
94  void setMinValue (sInt64);
95  void setMaxValue (sInt64);
96  void setRange (sInt64, sInt64);
97  void setPrefix (const FString&);
98  void setSuffix (const FString&);
99  void setLabelText (const FString&);
100  void setLabelOrientation (const LabelOrientation);
101 
102  // Inquiries
103  auto hasShadow() const -> bool;
104 
105  // Methods
106  void hide() override;
107 
108  // Event handlers
109  void onKeyPress (FKeyEvent*) override;
110  void onMouseDown (FMouseEvent*) override;
111  void onMouseUp (FMouseEvent*) override;
112  void onWheel (FWheelEvent*) override;
113  void onTimer (FTimerEvent*) override;
114  void onFocusIn (FFocusEvent*) override;
115  void onFailAtChildFocus (FFocusEvent*) override;
116 
117  private:
118  // Enumeration
119  enum class SpiningState
120  {
121  None = 0,
122  Up = 1,
123  Down = 2
124  };
125 
126  // Methods
127  void init();
128  void draw() override;
129  void updateInputField();
130  void increaseValue (sInt64 = 1);
131  void decreaseValue (sInt64 = 1);
132  void processActivate() const;
133  void processChanged() const;
134  void forceFocus();
135 
136  // Callback methods
137  void cb_inputFieldActivate() const;
138  void cb_inputFieldChange (const FLineEdit&);
139 
140  // Data members
141  FLineEdit input_field{this};
142  sInt64 value{0};
143  sInt64 min{std::numeric_limits<sInt64>::min()};
144  sInt64 max{std::numeric_limits<sInt64>::max()};
145  FString pfix{};
146  FString sfix{};
147  SpiningState spining_state{SpiningState::None};
148  bool threshold_reached{false};
149  int threshold_time{500};
150  int repeat_time{80};
151 };
152 
153 
154 // FSpinBox inline functions
155 //----------------------------------------------------------------------
156 inline auto FSpinBox::getClassName() const -> FString
157 { return "FSpinBox"; }
158 
159 //----------------------------------------------------------------------
160 inline auto FSpinBox::getValue() const noexcept -> sInt64
161 { return value; }
162 
163 //----------------------------------------------------------------------
164 inline auto FSpinBox::getPrefix() const -> FString
165 { return pfix; }
166 
167 //----------------------------------------------------------------------
168 inline auto FSpinBox::getSuffix() const -> FString
169 { return sfix; }
170 
171 //----------------------------------------------------------------------
172 inline auto FSpinBox::getLabelOrientation() const -> FLineEdit::LabelOrientation
173 { return input_field.getLabelOrientation(); }
174 
175 //----------------------------------------------------------------------
176 inline void FSpinBox::unsetEnable()
177 { setEnable(false); }
178 
179 //----------------------------------------------------------------------
180 inline void FSpinBox::setDisable()
181 { setEnable(false); }
182 
183 //----------------------------------------------------------------------
184 inline void FSpinBox::unsetShadow()
185 { setShadow(false); }
186 
187 //----------------------------------------------------------------------
188 inline auto FSpinBox::hasShadow() const -> bool
189 { return getFlags().shadow.shadow; }
190 
191 //----------------------------------------------------------------------
192 inline void FSpinBox::setLabelText (const FString& s)
193 { input_field.setLabelText(s); }
194 
195 //----------------------------------------------------------------------
196 inline void FSpinBox::setLabelOrientation (const LabelOrientation o)
197 { input_field.setLabelOrientation(o); }
198 
199 } // namespace finalcut
200 
201 #endif // FSPINBOX_H
Definition: fevent.h:196
Definition: fevent.h:144
Definition: fevent.h:300
Definition: fevent.h:171
Definition: class_template.cpp:25
Definition: fpoint.h:50
Definition: fsize.h:55
Definition: fspinbox.h:65
Definition: fstring.h:79
Definition: fwidget.h:129
Definition: flineedit.h:67
Definition: fevent.h:124