PCL
SpinBox.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.7.0
6 // ----------------------------------------------------------------------------
7 // pcl/SpinBox.h - Released 2024-06-18T15:48:54Z
8 // ----------------------------------------------------------------------------
9 // This file is part of the PixInsight Class Library (PCL).
10 // PCL is a multiplatform C++ framework for development of PixInsight modules.
11 //
12 // Copyright (c) 2003-2024 Pleiades Astrophoto S.L. All Rights Reserved.
13 //
14 // Redistribution and use in both source and binary forms, with or without
15 // modification, is permitted provided that the following conditions are met:
16 //
17 // 1. All redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 //
20 // 2. All redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the distribution.
23 //
24 // 3. Neither the names "PixInsight" and "Pleiades Astrophoto", nor the names
25 // of their contributors, may be used to endorse or promote products derived
26 // from this software without specific prior written permission. For written
27 // permission, please contact info@pixinsight.com.
28 //
29 // 4. All products derived from this software, in any form whatsoever, must
30 // reproduce the following acknowledgment in the end-user documentation
31 // and/or other materials provided with the product:
32 //
33 // "This product is based on software from the PixInsight project, developed
34 // by Pleiades Astrophoto and its contributors (https://pixinsight.com/)."
35 //
36 // Alternatively, if that is where third-party acknowledgments normally
37 // appear, this acknowledgment must be reproduced in the product itself.
38 //
39 // THIS SOFTWARE IS PROVIDED BY PLEIADES ASTROPHOTO AND ITS CONTRIBUTORS
40 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PLEIADES ASTROPHOTO OR ITS
43 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 // EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, BUSINESS
45 // INTERRUPTION; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; AND LOSS OF USE,
46 // DATA OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 // POSSIBILITY OF SUCH DAMAGE.
50 // ----------------------------------------------------------------------------
51 
52 #ifndef __PCL_SpinBox_h
53 #define __PCL_SpinBox_h
54 
56 
57 #ifndef __PCL_BUILDING_PIXINSIGHT_APPLICATION
58 
59 #include <pcl/Defs.h>
60 
61 #include <pcl/AutoPointer.h>
62 #include <pcl/Control.h>
63 
64 namespace pcl
65 {
66 
67 // ----------------------------------------------------------------------------
68 
75 class PCL_CLASS SpinBox : public Control
76 {
77 public:
78 
82  SpinBox( Control& parent = Control::Null() );
83 
87  ~SpinBox() override
88  {
89  }
90 
96  int Value() const;
97 
103  void SetValue( int v );
104 
111  double NormalizedValue() const;
112 
119  void SetNormalizedValue( double f );
120 
130  void GetRange( int& minValue, int& maxValue ) const;
131 
137  int MinValue() const
138  {
139  int m, dum; GetRange( m, dum ); return m;
140  }
141 
147  int MaxValue() const
148  {
149  int dum, m; GetRange( dum, m ); return m;
150  }
151 
160  void SetRange( int minValue, int maxValue );
161 
170  void SetMinValue( int m )
171  {
172  SetRange( m, MaxValue() );
173  }
174 
183  void SetMaxValue( int m )
184  {
185  SetRange( MinValue(), m );
186  }
187 
196  int StepSize() const;
197 
206  void SetStepSize( int );
207 
219  bool IsWrappingEnabled() const;
220 
228  void EnableWrapping( bool = true );
229 
240  void DisableWrapping( bool disable = true )
241  {
242  EnableWrapping( !disable );
243  }
244 
255  bool IsEditable() const;
256 
262  void SetEditable( bool = true );
263 
273  String Prefix() const;
274 
280  void SetPrefix( const String& prefix );
281 
288  void ClearPrefix()
289  {
290  SetPrefix( String() );
291  }
292 
302  String Suffix() const;
303 
309  void SetSuffix( const String& );
310 
317  void ClearSuffix()
318  {
319  SetSuffix( String() );
320  }
321 
332 
338  void SetMinimumValueText( const String& );
339 
347  {
348  SetMinimumValueText( String() );
349  }
350 
356  bool IsRightAligned() const;
357 
366  bool IsLeftAligned() const
367  {
368  return !IsRightAligned();
369  }
370 
377  void SetRightAlignment( bool = true );
378 
388  void SetLeftAlignment( bool left = true )
389  {
390  SetRightAlignment( !left );
391  }
392 
393  // -------------------------------------------------------------------------
394  // Event handlers
395  //
396  // void OnValueUpdated( SpinBox& sender, int value );
397  // void OnRangeUpdated( SpinBox& sender, int minValue, int maxValue );
398 
415  using value_event_handler = void (Control::*)( SpinBox& sender, int value );
416 
430  using range_event_handler = void (Control::*)( SpinBox& sender, int minValue, int maxValue );
431 
443  void OnValueUpdated( value_event_handler handler, Control& receiver );
444 
456  void OnRangeUpdated( range_event_handler handler, Control& receiver );
457 
458 private:
459 
460  struct EventHandlers
461  {
462  value_event_handler onValueUpdated = nullptr;
463  range_event_handler onRangeUpdated = nullptr;
464 
465  EventHandlers() = default;
466  EventHandlers( const EventHandlers& ) = default;
467  EventHandlers& operator =( const EventHandlers& ) = default;
468  };
469 
470  AutoPointer<EventHandlers> m_handlers;
471 
472  friend class SpinBoxEventDispatcher;
473 };
474 
475 // ----------------------------------------------------------------------------
476 
477 } // pcl
478 
479 #endif // __PCL_BUILDING_PIXINSIGHT_APPLICATION
480 
481 #endif // __PCL_SpinBox_h
482 
483 // ----------------------------------------------------------------------------
484 // EOF pcl/SpinBox.h - Released 2024-06-18T15:48:54Z
Client-side interface to a PixInsight Control object.
Definition: Control.h:126
static Control & Null()
Client-side interface to a PixInsight SpinBox control.
Definition: SpinBox.h:76
bool IsEditable() const
void SetMaxValue(int m)
Definition: SpinBox.h:183
void SetMinValue(int m)
Definition: SpinBox.h:170
void DisableWrapping(bool disable=true)
Definition: SpinBox.h:240
bool IsRightAligned() const
int Value() const
String Prefix() const
void SetRange(int minValue, int maxValue)
SpinBox(Control &parent=Control::Null())
void EnableWrapping(bool=true)
void SetStepSize(int)
void SetNormalizedValue(double f)
void SetRightAlignment(bool=true)
bool IsLeftAligned() const
Definition: SpinBox.h:366
void SetPrefix(const String &prefix)
String MinimumValueText() const
String Suffix() const
void SetEditable(bool=true)
void ClearPrefix()
Definition: SpinBox.h:288
void ClearMinimumValueText()
Definition: SpinBox.h:346
double NormalizedValue() const
void SetLeftAlignment(bool left=true)
Definition: SpinBox.h:388
int MinValue() const
Definition: SpinBox.h:137
void SetMinimumValueText(const String &)
void ClearSuffix()
Definition: SpinBox.h:317
int StepSize() const
void SetValue(int v)
bool IsWrappingEnabled() const
int MaxValue() const
Definition: SpinBox.h:147
void SetSuffix(const String &)
~SpinBox() override
Definition: SpinBox.h:87
void GetRange(int &minValue, int &maxValue) const
Unicode (UTF-16) string.
Definition: String.h:8113
void(Control::*)(SpinBox &sender, int minValue, int maxValue) range_event_handler
Definition: SpinBox.h:430
void OnRangeUpdated(range_event_handler handler, Control &receiver)
void OnValueUpdated(value_event_handler handler, Control &receiver)
void(Control::*)(SpinBox &sender, int value) value_event_handler
Definition: SpinBox.h:415
PCL root namespace.
Definition: AbstractImage.h:77