KiCad PCB EDA Suite
wxunittext.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2014 CERN
5  * Author: Maciej Suminski <maciej.suminski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef WXUNITTEXT_H_
26 #define WXUNITTEXT_H_
27 
28 #include <common.h>
29 #include <wx/spinbutt.h>
30 
31 namespace boost
32 {
33  template <class T>
34  class optional;
35 }
36 class wxTextCtrl;
37 class wxSpinButton;
38 class wxStaticText;
39 
40 class WX_UNIT_TEXT : public wxPanel
41 {
42 public:
50  WX_UNIT_TEXT( wxWindow* aParent, const wxString& aLabel = _( "Size:" ),
51  double aValue = 0.0, double aStep = 0.1 );
52 
53  virtual ~WX_UNIT_TEXT();
54 
62  void SetUnits( EDA_UNITS_T aUnits, bool aConvert = false );
63 
69  virtual void SetValue( double aValue );
70 
71  /*
72  * Function GetValue
73  * Returns the current value using specified units (if currently used units are different, then
74  * they are converted first).
75  * @param aUnits is the wanted unit.
76  */
77  //virtual double GetValue( EDA_UNITS_T aUnits ) const;
78 
83  virtual boost::optional<double> GetValue() const;
84 
90  {
91  return m_units;
92  }
93 
99  void SetStep( double aStep )
100  {
101  assert( aStep > 0.0 );
102 
103  m_step = aStep;
104  }
105 
110  double GetStep() const
111  {
112  return m_step;
113  }
114 
115 protected:
117  void onSpinUpEvent( wxSpinEvent& aEvent );
118 
120  void onSpinDownEvent( wxSpinEvent& aEvent );
121 
123  wxStaticText* m_inputLabel;
124 
126  wxTextCtrl* m_inputValue;
127 
129  wxSpinButton* m_spinButton;
130 
132  wxStaticText* m_unitLabel;
133 
136 
138  double m_step;
139 
141  static const wxString DEFAULT_VALUE;
142 };
143 
144 #endif /* WXUNITTEXT_H_ */
EDA_UNITS_T GetUnits() const
Function GetUnits Returns currently used units.
Definition: wxunittext.h:89
void SetStep(double aStep)
Function SetStep Sets the difference introduced by a single spin button click.
Definition: wxunittext.h:99
static const wxString DEFAULT_VALUE
Default value (or non-specified)
Definition: wxunittext.h:141
virtual void SetValue(double aValue)
Function SetValue Sets new value for the control.
Definition: wxunittext.cpp:98
void onSpinUpEvent(wxSpinEvent &aEvent)
Spin up button click event handler.
Definition: wxunittext.cpp:127
wxTextCtrl * m_inputValue
Text input control.
Definition: wxunittext.h:126
wxStaticText * m_unitLabel
Label showing currently used units.
Definition: wxunittext.h:132
double GetStep() const
Function GetStep Returns the difference introduced by a single spin button click. ...
Definition: wxunittext.h:110
void onSpinDownEvent(wxSpinEvent &aEvent)
Spin down button click event handler.
Definition: wxunittext.cpp:133
WX_UNIT_TEXT(wxWindow *aParent, const wxString &aLabel=_("Size:"), double aValue=0.0, double aStep=0.1)
Constructor.
Definition: wxunittext.cpp:34
wxSpinButton * m_spinButton
Spin buttons for changing the value using mouse.
Definition: wxunittext.h:129
void SetUnits(EDA_UNITS_T aUnits, bool aConvert=false)
Function SetUnits Changes the units used by the control.
Definition: wxunittext.cpp:90
virtual ~WX_UNIT_TEXT()
Definition: wxunittext.cpp:85
double m_step
Step size (added/subtracted difference if spin buttons are used).
Definition: wxunittext.h:138
The common library.
wxStaticText * m_inputLabel
Label for the input (e.g. "Size:")
Definition: wxunittext.h:123
virtual boost::optional< double > GetValue() const
Function GetValue Returns the current value in currently used units.
Definition: wxunittext.cpp:112
EDA_UNITS_T m_units
Currently used units.
Definition: wxunittext.h:135
EDA_UNITS_T
Definition: common.h:144