diff --git a/lcl/interfaces/qt/qtwidgets.pas b/lcl/interfaces/qt/qtwidgets.pas index 05a9b0f630..54c3b74e13 100644 --- a/lcl/interfaces/qt/qtwidgets.pas +++ b/lcl/interfaces/qt/qtwidgets.pas @@ -545,8 +545,10 @@ type protected function CreateWidget(const AParams: TCreateParams):QWidgetH; override; public - function IsReadOnly: Boolean; - procedure SetReadOnly(r: Boolean); + function getValue: single; virtual; abstract; + function getReadOnly: Boolean; + procedure setReadOnly(const r: Boolean); + procedure setValue(const v: single); virtual; abstract; public procedure AttachEvents; override; procedure DetachEvents; override; @@ -561,6 +563,9 @@ type FValueChangedHook: QDoubleSpinBox_hookH; protected function CreateWidget(const AParams: TCreateParams):QWidgetH; override; + public + function getValue: single; override; + procedure setValue(const v: single); override; public procedure AttachEvents; override; procedure DetachEvents; override; @@ -575,6 +580,9 @@ type FValueChangedHook: QSpinBox_hookH; protected function CreateWidget(const AParams: TCreateParams):QWidgetH; override; + public + function getValue: single; override; + procedure setValue(const v: single); override; public procedure AttachEvents; override; procedure DetachEvents; override; @@ -4466,7 +4474,7 @@ begin Result := QAbstractSpinBox_create(Parent); end; -function TQtAbstractSpinBox.IsReadOnly: Boolean; +function TQtAbstractSpinBox.getReadOnly: Boolean; begin {$ifdef VerboseQt} WriteLn('TQtAbstractSpinBox.IsReadOnly'); @@ -4474,7 +4482,7 @@ begin Result := QAbstractSpinBox_isReadOnly(QAbstractSpinBoxH(Widget)); end; -procedure TQtAbstractSpinBox.SetReadOnly(r: Boolean); +procedure TQtAbstractSpinBox.setReadOnly(const r: Boolean); begin {$ifdef VerboseQt} WriteLn('TQtAbstractSpinBox.SetReadOnly'); @@ -4533,6 +4541,16 @@ begin Result := QDoubleSpinBox_create(Parent); end; +function TQtFloatSpinBox.getValue: single; +begin + Result := QDoubleSpinBox_value(QDoubleSpinBoxH(Widget)); +end; + +procedure TQtFloatSpinBox.setValue(const v: single); +begin + QDoubleSpinBox_setValue(QDoubleSpinBoxH(Widget), v); +end; + procedure TQtFloatSpinBox.AttachEvents; var Method: TMethod; @@ -4572,6 +4590,16 @@ begin Result := QSpinBox_create(Parent); end; +function TQtSpinBox.getValue: single; +begin + Result := QSpinBox_value(QSpinBoxH(Widget)); +end; + +procedure TQtSpinBox.setValue(const v: single); +begin + QSpinBox_setValue(QSpinBoxH(Widget), round(v)); +end; + procedure TQtSpinBox.AttachEvents; var Method: TMethod; diff --git a/lcl/interfaces/qt/qtwsspin.pp b/lcl/interfaces/qt/qtwsspin.pp index ae2d9036ad..c1fffe10f4 100644 --- a/lcl/interfaces/qt/qtwsspin.pp +++ b/lcl/interfaces/qt/qtwsspin.pp @@ -92,35 +92,22 @@ implementation class function TQtWSCustomFloatSpinEdit.CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): HWND; var - QtSpinBox: TQtSpinBox; - QtFloatSpinBox: TQtFloatSpinBox; - FIsFloat: Boolean; + QtSpinBox: TQtAbstractSpinBox; begin + // qt4 has two different QSpinBoxes, one is QSpinBox (integer), another is QDoubleSpinBox (double) - { qt4 has two different QSpinBoxes, one is QSpinBox (integer), another is QDoubleSpinBox (double) } - - FIsFloat := TCustomFloatSpinEdit(AWinControl).DecimalPlaces > 0; - - if FIsFloat then - begin - QtFloatSpinBox := TQtFloatSpinBox.Create(AWinControl, AParams); - QtFloatSpinBox.AttachEvents; - Result := THandle(QtFloatSpinBox); - end + if TCustomFloatSpinEdit(AWinControl).DecimalPlaces > 0 then + QtSpinBox := TQtFloatSpinBox.Create(AWinControl, AParams) else - begin QtSpinBox := TQtSpinBox.Create(AWinControl, AParams); - QtSpinBox.AttachEvents; - Result := THandle(QtSpinBox); - end; + + QtSpinBox.AttachEvents; + Result := THandle(QtSpinBox); end; class function TQtWSCustomFloatSpinEdit.GetValue(const ACustomFloatSpinEdit: TCustomFloatSpinEdit): single; begin - if ACustomFloatSpinEdit.DecimalPlaces > 0 then - Result := QDoubleSpinBox_value(QDoubleSpinBoxH(TQtFloatSpinBox(ACustomFloatSpinEdit.Handle).Widget)) - else - Result := QSpinBox_value(QSpinBoxH(TQtFloatSpinBox(ACustomFloatSpinEdit.Handle).Widget)); + Result := TQtAbstractSpinBox(ACustomFloatSpinEdit.Handle).getValue; end; class procedure TQtWSCustomFloatSpinEdit.SetCharCase( @@ -138,7 +125,7 @@ begin begin QtFloatSpinEdit := TQtFloatSpinBox(ACustomFloatSpinEdit.Handle); QDoubleSpinBox_setDecimals(QDoubleSpinBoxH(QtFloatSpinEdit.Widget), ACustomFloatSpinEdit.DecimalPlaces); - QDoubleSpinBox_setValue(QDoubleSpinBoxH(QtFloatSpinEdit.Widget), ACustomFloatSpinEdit.Value); + QtFloatSpinEdit.setValue(ACustomFloatSpinEdit.Value); QDoubleSpinBox_setMinimum(QDoubleSpinBoxH(QtFloatSpinEdit.Widget), ACustomFloatSpinEdit.MinValue); QDoubleSpinBox_setMaximum(QDoubleSpinBoxH(QtFloatSpinEdit.Widget), ACustomFloatSpinEdit.MaxValue); QDoubleSpinBox_setSingleStep(QDoubleSpinBoxH(QtFloatSpinEdit.Widget), ACustomFloatSpinEdit.Increment); @@ -146,7 +133,7 @@ begin else begin QtSpinEdit := TQtSpinBox(ACustomFloatSpinEdit.Handle); - QSpinBox_setValue(QSpinBoxH(QtSpinEdit.Widget), Round(ACustomFloatSpinEdit.Value)); + QtSpinEdit.setValue(Round(ACustomFloatSpinEdit.Value)); QSpinBox_setMinimum(QSpinBoxH(QtSpinEdit.Widget), Round(ACustomFloatSpinEdit.MinValue)); QSpinBox_setMaximum(QSpinBoxH(QtSpinEdit.Widget), Round(ACustomFloatSpinEdit.MaxValue)); QSpinBox_setSingleStep(QSpinBoxH(QtSpinEdit.Widget), Round(ACustomFloatSpinEdit.Increment)); @@ -181,7 +168,7 @@ end; class procedure TQtWSCustomFloatSpinEdit.SetReadOnly(const ACustomEdit: TCustomEdit; NewReadOnly: boolean); begin - QAbstractSpinBox_setReadOnly(QAbstractSpinBoxH(TQtAbstractSpinBox(ACustomEdit.Handle).Widget), NewReadOnly); + TQtAbstractSpinBox(ACustomEdit.Handle).setReadOnly(NewReadOnly); end; class procedure TQtWSCustomFloatSpinEdit.SetSelLength(