2
* Copyright 2010 Inalogic Inc.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License version 3, as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the applicable version of the GNU Lesser General Public
12
* License for more details.
14
* You should have received a copy of both the GNU Lesser General Public
15
* License version 3 along with this program. If not, see
16
* <http://www.gnu.org/licenses/>
18
* Authored by: Jay Taoko <jay.taoko_AT_gmail_DOT_com>
25
#include "EditTextBox.h"
26
#include "DoubleValidator.h"
27
#include "NumericValuator.h"
32
const int BTN_WIDTH = 14;
33
const int BTN_HEIGHT = 14;
35
NumericValuator::NumericValuator()
36
: m_DoubleValidator (0.0, 100.0)
43
NumericValuator::~NumericValuator()
48
void NumericValuator::InitializeWidgets()
50
m_EditLine->SetValidator (&m_DoubleValidator);
51
m_EditLine->SetText (inlPrintf (TEXT ("%d"), m_DoubleValidator.GetMinimum() ) );
53
m_EditLine->SetMinimumSize (2 * DEFAULT_WIDGET_WIDTH, PRACTICAL_WIDGET_HEIGHT);
54
m_EditLine->SetGeometry (Geometry (0, 0, 2 * DEFAULT_WIDGET_WIDTH, PRACTICAL_WIDGET_HEIGHT) );
56
m_SpinnerDownBtn->SetMinimumSize (BTN_WIDTH, BTN_HEIGHT);
57
m_SpinnerDownBtn->SetGeometry (Geometry (0, 0, BTN_WIDTH, BTN_HEIGHT) );
58
m_SpinnerUpBtn->SetMinimumSize (BTN_WIDTH, BTN_HEIGHT);
59
m_SpinnerUpBtn->SetGeometry (Geometry (0, 0, BTN_WIDTH, BTN_HEIGHT) );
61
hlayout->AddView (m_SpinnerDownBtn, 0);
62
hlayout->AddView (m_EditLine, 1);
63
hlayout->AddView (m_SpinnerUpBtn, 0);
64
hlayout->SetContentDistribution (eStackLeft);
66
SetCompositionLayout (hlayout);
69
void NumericValuator::InitializeLayout()
71
hlayout = new HLayout (TEXT (""), NUX_TRACKER_LOCATION);
74
void NumericValuator::DestroyLayout()
78
long NumericValuator::ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo)
80
long ret = TraverseInfo;
81
ret = m_SpinnerDownBtn->OnEvent (ievent, ret, ProcessEventInfo);
82
ret = m_SpinnerUpBtn->OnEvent (ievent, ret, ProcessEventInfo);
83
ret = m_EditLine->ProcessEvent (ievent, ret, ProcessEventInfo);
84
ret = PostProcessEvent2 (ievent, ret, ProcessEventInfo);
88
void NumericValuator::Draw (GraphicsEngine &GfxContext, bool force_draw)
90
Geometry base = GetGeometry();
92
GeometryPositioning gp (eHALeft, eVACenter);
93
Geometry GeoPo = ComputeGeometryPositioning (m_SpinnerUpBtn->GetGeometry(), GetTheme().GetImageGeometry (eTRIANGLE_RIGHT), gp);
94
GetPainter().PaintShape (GfxContext, GeoPo, Color (0xFFFFFFFF), eTRIANGLE_RIGHT);
96
GeoPo = ComputeGeometryPositioning (m_SpinnerDownBtn->GetGeometry(), GetTheme().GetImageGeometry (eTRIANGLE_LEFT), gp);
97
GetPainter().PaintShape (GfxContext, GeoPo, Color (0xFFFFFFFF), eTRIANGLE_LEFT);
99
m_EditLine->NeedRedraw();
102
void NumericValuator::DrawContent (GraphicsEngine &GfxContext, bool force_draw)
104
m_EditLine->ProcessDraw (GfxContext, force_draw);
107
void NumericValuator::PostDraw (GraphicsEngine &GfxContext, bool force_draw)
112
void NumericValuator::SetValue (float value)
116
if (m_fValue < m_DoubleValidator.GetMinimum() )
117
m_fValue = m_DoubleValidator.GetMinimum();
119
if (m_fValue > m_DoubleValidator.GetMaximum() )
120
m_fValue = m_DoubleValidator.GetMaximum();
122
m_EditLine->SetText (inlPrintf ("%f", m_fValue) );
125
float NumericValuator::GetValue() const
130
void NumericValuator::SetStep (float f)
135
float NumericValuator::GetStep()
141
void NumericValuator::ImplementIncrementBtn()
143
SetValue (m_fValue + m_Step);
145
sigValueChanged.emit (m_fValue);
147
if (m_fValue < m_DoubleValidator.GetMaximum() )
149
m_UpTimerHandler = GetTimer().AddTimerHandler (100, m_UpTimerCallback, 0);
154
void NumericValuator::ImplementDecrementBtn()
156
SetValue (m_fValue - m_Step);
158
sigValueChanged.emit (m_fValue);
160
if (m_fValue > m_DoubleValidator.GetMinimum() )
162
m_DownTimerHandler = GetTimer().AddTimerHandler (100, m_DownTimerCallback, 0);
167
void NumericValuator::ImplementValidateEntry()
170
ret = CharToDouble (m_EditLine->GetCleanText().GetTCharPtr() );
174
if (m_fValue < m_DoubleValidator.GetMinimum() )
176
m_fValue = m_DoubleValidator.GetMinimum();
177
m_EditLine->SetText (inlPrintf ("%f", m_fValue) );
180
if (m_fValue > m_DoubleValidator.GetMaximum() )
182
m_fValue = m_DoubleValidator.GetMaximum();
183
m_EditLine->SetText (inlPrintf ("%f", m_fValue) );
188
// m_EditLine->SetText(inlPrintf("%f", m_fValue));
2
* Copyright 2010 Inalogic Inc.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License version 3, as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the applicable version of the GNU Lesser General Public
12
* License for more details.
14
* You should have received a copy of both the GNU Lesser General Public
15
* License version 3 along with this program. If not, see
16
* <http://www.gnu.org/licenses/>
18
* Authored by: Jay Taoko <jay.taoko_AT_gmail_DOT_com>
25
#include "EditTextBox.h"
26
#include "DoubleValidator.h"
27
#include "NumericValuator.h"
32
const int BTN_WIDTH = 14;
33
const int BTN_HEIGHT = 14;
35
NumericValuator::NumericValuator()
36
: m_DoubleValidator (0.0, 100.0)
43
NumericValuator::~NumericValuator()
48
void NumericValuator::InitializeWidgets()
50
m_EditLine->SetValidator (&m_DoubleValidator);
51
m_EditLine->SetText (inlPrintf (TEXT ("%d"), m_DoubleValidator.GetMinimum() ) );
53
m_EditLine->SetMinimumSize (2 * DEFAULT_WIDGET_WIDTH, PRACTICAL_WIDGET_HEIGHT);
54
m_EditLine->SetGeometry (Geometry (0, 0, 2 * DEFAULT_WIDGET_WIDTH, PRACTICAL_WIDGET_HEIGHT) );
56
m_SpinnerDownBtn->SetMinimumSize (BTN_WIDTH, BTN_HEIGHT);
57
m_SpinnerDownBtn->SetGeometry (Geometry (0, 0, BTN_WIDTH, BTN_HEIGHT) );
58
m_SpinnerUpBtn->SetMinimumSize (BTN_WIDTH, BTN_HEIGHT);
59
m_SpinnerUpBtn->SetGeometry (Geometry (0, 0, BTN_WIDTH, BTN_HEIGHT) );
61
hlayout->AddView (m_SpinnerDownBtn, 0);
62
hlayout->AddView (m_EditLine, 1);
63
hlayout->AddView (m_SpinnerUpBtn, 0);
64
hlayout->SetContentDistribution (eStackLeft);
66
SetCompositionLayout (hlayout);
69
void NumericValuator::InitializeLayout()
71
hlayout = new HLayout (TEXT (""), NUX_TRACKER_LOCATION);
74
void NumericValuator::DestroyLayout()
78
long NumericValuator::ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo)
80
long ret = TraverseInfo;
81
ret = m_SpinnerDownBtn->OnEvent (ievent, ret, ProcessEventInfo);
82
ret = m_SpinnerUpBtn->OnEvent (ievent, ret, ProcessEventInfo);
83
ret = m_EditLine->ProcessEvent (ievent, ret, ProcessEventInfo);
84
ret = PostProcessEvent2 (ievent, ret, ProcessEventInfo);
88
void NumericValuator::Draw (GraphicsEngine &GfxContext, bool force_draw)
90
Geometry base = GetGeometry();
92
GeometryPositioning gp (eHALeft, eVACenter);
93
Geometry GeoPo = ComputeGeometryPositioning (m_SpinnerUpBtn->GetGeometry(), GetTheme().GetImageGeometry (eTRIANGLE_RIGHT), gp);
94
GetPainter().PaintShape (GfxContext, GeoPo, Color (0xFFFFFFFF), eTRIANGLE_RIGHT);
96
GeoPo = ComputeGeometryPositioning (m_SpinnerDownBtn->GetGeometry(), GetTheme().GetImageGeometry (eTRIANGLE_LEFT), gp);
97
GetPainter().PaintShape (GfxContext, GeoPo, Color (0xFFFFFFFF), eTRIANGLE_LEFT);
99
m_EditLine->NeedRedraw();
102
void NumericValuator::DrawContent (GraphicsEngine &GfxContext, bool force_draw)
104
m_EditLine->ProcessDraw (GfxContext, force_draw);
107
void NumericValuator::PostDraw (GraphicsEngine &GfxContext, bool force_draw)
112
void NumericValuator::SetValue (float value)
116
if (m_fValue < m_DoubleValidator.GetMinimum() )
117
m_fValue = m_DoubleValidator.GetMinimum();
119
if (m_fValue > m_DoubleValidator.GetMaximum() )
120
m_fValue = m_DoubleValidator.GetMaximum();
122
m_EditLine->SetText (inlPrintf ("%f", m_fValue) );
125
float NumericValuator::GetValue() const
130
void NumericValuator::SetStep (float f)
135
float NumericValuator::GetStep()
141
void NumericValuator::ImplementIncrementBtn()
143
SetValue (m_fValue + m_Step);
145
sigValueChanged.emit (m_fValue);
147
if (m_fValue < m_DoubleValidator.GetMaximum() )
149
m_UpTimerHandler = GetTimer().AddTimerHandler (100, m_UpTimerCallback, 0);
154
void NumericValuator::ImplementDecrementBtn()
156
SetValue (m_fValue - m_Step);
158
sigValueChanged.emit (m_fValue);
160
if (m_fValue > m_DoubleValidator.GetMinimum() )
162
m_DownTimerHandler = GetTimer().AddTimerHandler (100, m_DownTimerCallback, 0);
167
void NumericValuator::ImplementValidateEntry()
170
ret = CharToDouble (m_EditLine->GetCleanText().GetTCharPtr() );
174
if (m_fValue < m_DoubleValidator.GetMinimum() )
176
m_fValue = m_DoubleValidator.GetMinimum();
177
m_EditLine->SetText (inlPrintf ("%f", m_fValue) );
180
if (m_fValue > m_DoubleValidator.GetMaximum() )
182
m_fValue = m_DoubleValidator.GetMaximum();
183
m_EditLine->SetText (inlPrintf ("%f", m_fValue) );
188
// m_EditLine->SetText(inlPrintf("%f", m_fValue));