1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        src/qt/gauge.cpp
3 // Author:      Peter Most, Mariano Reingart
4 // Copyright:   (c) 2010 wxWidgets dev team
5 // Licence:     wxWindows licence
6 /////////////////////////////////////////////////////////////////////////////
7 
8 // For compilers that support precompilation, includes "wx.h".
9 #include "wx/wxprec.h"
10 
11 #include "wx/gauge.h"
12 #include "wx/qt/private/converter.h"
13 #include "wx/qt/private/winevent.h"
14 
15 #include <QtWidgets/QProgressBar>
16 
17 class wxQtProgressBar : public wxQtEventSignalHandler< QProgressBar, wxGauge >
18 {
19 public:
20     wxQtProgressBar( wxWindow *parent, wxGauge *handler );
21 
22 private:
23     void valueChanged(int value);
24 };
25 
wxQtProgressBar(wxWindow * parent,wxGauge * handler)26 wxQtProgressBar::wxQtProgressBar( wxWindow *parent, wxGauge *handler )
27     : wxQtEventSignalHandler< QProgressBar, wxGauge >( parent, handler )
28 {
29 }
30 
31 
wxGauge()32 wxGauge::wxGauge() :
33     m_qtProgressBar(NULL)
34 {
35 }
36 
wxGauge(wxWindow * parent,wxWindowID id,int range,const wxPoint & pos,const wxSize & size,long style,const wxValidator & validator,const wxString & name)37 wxGauge::wxGauge(wxWindow *parent,
38         wxWindowID id,
39         int range,
40         const wxPoint& pos,
41         const wxSize& size,
42         long style,
43         const wxValidator& validator,
44         const wxString& name)
45 {
46     Create( parent, id, range, pos, size, style, validator, name );
47 }
48 
Create(wxWindow * parent,wxWindowID id,int range,const wxPoint & pos,const wxSize & size,long style,const wxValidator & validator,const wxString & name)49 bool wxGauge::Create(wxWindow *parent,
50             wxWindowID id,
51             int range,
52             const wxPoint& pos,
53             const wxSize& size,
54             long style,
55             const wxValidator& validator,
56             const wxString& name)
57 {
58     m_qtProgressBar = new wxQtProgressBar( parent, this);
59     m_qtProgressBar->setOrientation( wxQtConvertOrientation( style, wxGA_HORIZONTAL ));
60     m_qtProgressBar->setRange( 0, range );
61     m_qtProgressBar->setTextVisible( style & wxGA_TEXT );
62     m_qtProgressBar->setValue(0);
63 
64     return QtCreateControl( parent, id, pos, size, style, validator, name );
65 }
66 
67 
GetHandle() const68 QWidget *wxGauge::GetHandle() const
69 {
70     return m_qtProgressBar;
71 }
72 
73 // set/get the control range and value
74 
SetRange(int range)75 void wxGauge::SetRange(int range)
76 {
77     // note that in wx minimun range is fixed at 0
78     m_qtProgressBar->setMaximum(range);
79 }
80 
GetRange() const81 int wxGauge::GetRange() const
82 {
83     return m_qtProgressBar->maximum();
84 }
85 
SetValue(int pos)86 void wxGauge::SetValue(int pos)
87 {
88     m_qtProgressBar->setValue(pos);
89 }
90 
GetValue() const91 int wxGauge::GetValue() const
92 {
93     return m_qtProgressBar->value();
94 }
95