mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-07 01:57:57 +02:00
Qt: improve spin logic
git-svn-id: trunk@12009 -
This commit is contained in:
parent
390db77320
commit
a6de3a8e90
@ -266,7 +266,7 @@ var
|
||||
AccelIndex : Longint;
|
||||
OldShortCut: TShortCut;
|
||||
begin
|
||||
Inherited RealSetText(Value);
|
||||
inherited RealSetText(Value);
|
||||
If (not HandleAllocated) or (csDesigning in ComponentState) then exit;
|
||||
ParseStr := Value;
|
||||
AccelIndex := DeleteAmpersands(ParseStr);
|
||||
|
@ -542,13 +542,21 @@ type
|
||||
TQtAbstractSpinBox = class(TQtWidget)
|
||||
private
|
||||
FEditingFinishedHook: QAbstractSpinBox_hookH;
|
||||
// parts
|
||||
FLineEdit: QLineEditH;
|
||||
function GetLineEdit: QLineEditH;
|
||||
protected
|
||||
function CreateWidget(const AParams: TCreateParams):QWidgetH; override;
|
||||
public
|
||||
function getValue: single; virtual; abstract;
|
||||
function getReadOnly: Boolean;
|
||||
procedure setMinimum(const v: single); virtual; abstract;
|
||||
procedure setMaximum(const v: single); virtual; abstract;
|
||||
procedure setSingleStep(const v: single); virtual; abstract;
|
||||
procedure setReadOnly(const r: Boolean);
|
||||
procedure setValue(const v: single); virtual; abstract;
|
||||
|
||||
property LineEdit: QLineEditH read GetLineEdit;
|
||||
public
|
||||
procedure AttachEvents; override;
|
||||
procedure DetachEvents; override;
|
||||
@ -565,6 +573,10 @@ type
|
||||
function CreateWidget(const AParams: TCreateParams):QWidgetH; override;
|
||||
public
|
||||
function getValue: single; override;
|
||||
procedure setDecimals(const v: integer);
|
||||
procedure setMinimum(const v: single); override;
|
||||
procedure setMaximum(const v: single); override;
|
||||
procedure setSingleStep(const v: single); override;
|
||||
procedure setValue(const v: single); override;
|
||||
public
|
||||
procedure AttachEvents; override;
|
||||
@ -582,6 +594,9 @@ type
|
||||
function CreateWidget(const AParams: TCreateParams):QWidgetH; override;
|
||||
public
|
||||
function getValue: single; override;
|
||||
procedure setMinimum(const v: single); override;
|
||||
procedure setMaximum(const v: single); override;
|
||||
procedure setSingleStep(const v: single); override;
|
||||
procedure setValue(const v: single); override;
|
||||
public
|
||||
procedure AttachEvents; override;
|
||||
@ -4462,6 +4477,12 @@ end;
|
||||
|
||||
{ TQtAbstractSpinBox }
|
||||
|
||||
function TQtAbstractSpinBox.GetLineEdit: QLineEditH;
|
||||
begin
|
||||
// :( bindings has no QAbstractSpinBox_lineEdit(...)
|
||||
Result := nil;
|
||||
end;
|
||||
|
||||
function TQtAbstractSpinBox.CreateWidget(const AParams: TCreateParams): QWidgetH;
|
||||
var
|
||||
Parent: QWidgetH;
|
||||
@ -4546,6 +4567,26 @@ begin
|
||||
Result := QDoubleSpinBox_value(QDoubleSpinBoxH(Widget));
|
||||
end;
|
||||
|
||||
procedure TQtFloatSpinBox.setDecimals(const v: integer);
|
||||
begin
|
||||
QDoubleSpinBox_setDecimals(QDoubleSpinBoxH(Widget), v);
|
||||
end;
|
||||
|
||||
procedure TQtFloatSpinBox.setMinimum(const v: single);
|
||||
begin
|
||||
QDoubleSpinBox_setMinimum(QDoubleSpinBoxH(Widget), v);
|
||||
end;
|
||||
|
||||
procedure TQtFloatSpinBox.setMaximum(const v: single);
|
||||
begin
|
||||
QDoubleSpinBox_setMaximum(QDoubleSpinBoxH(Widget), v);
|
||||
end;
|
||||
|
||||
procedure TQtFloatSpinBox.setSingleStep(const v: single);
|
||||
begin
|
||||
QDoubleSpinBox_setSingleStep(QDoubleSpinBoxH(Widget), v);
|
||||
end;
|
||||
|
||||
procedure TQtFloatSpinBox.setValue(const v: single);
|
||||
begin
|
||||
QDoubleSpinBox_setValue(QDoubleSpinBoxH(Widget), v);
|
||||
@ -4595,6 +4636,21 @@ begin
|
||||
Result := QSpinBox_value(QSpinBoxH(Widget));
|
||||
end;
|
||||
|
||||
procedure TQtSpinBox.setMinimum(const v: single);
|
||||
begin
|
||||
QSpinBox_setMinimum(QSpinBoxH(Widget), round(v));
|
||||
end;
|
||||
|
||||
procedure TQtSpinBox.setMaximum(const v: single);
|
||||
begin
|
||||
QSpinBox_setMaximum(QSpinBoxH(Widget), round(v));
|
||||
end;
|
||||
|
||||
procedure TQtSpinBox.setSingleStep(const v: single);
|
||||
begin
|
||||
QSpinBox_setSingleStep(QSpinBoxH(Widget), round(v));
|
||||
end;
|
||||
|
||||
procedure TQtSpinBox.setValue(const v: single);
|
||||
begin
|
||||
QSpinBox_setValue(QSpinBoxH(Widget), round(v));
|
||||
|
@ -37,7 +37,7 @@ uses
|
||||
// LCL
|
||||
Spin, SysUtils, Controls, Classes, LCLType, LCLProc, LCLIntf, Forms, StdCtrls,
|
||||
// Widgetset
|
||||
WSSpin, WSLCLClasses;
|
||||
WsProc, WSSpin, WSLCLClasses;
|
||||
|
||||
type
|
||||
|
||||
@ -46,15 +46,17 @@ type
|
||||
TQtWSCustomFloatSpinEdit = class(TWSCustomFloatSpinEdit)
|
||||
private
|
||||
protected
|
||||
class procedure InternalUpdateControl(const ASpinWidget: TQtAbstractSpinBox;
|
||||
const ACustomFloatSpinEdit: TCustomFloatSpinEdit);
|
||||
public
|
||||
class function CreateHandle(const AWinControl: TWinControl;
|
||||
const AParams: TCreateParams): HWND; override;
|
||||
class procedure UpdateControl(const ACustomFloatSpinEdit: TCustomFloatSpinEdit); override;
|
||||
|
||||
class function GetSelStart(const ACustomEdit: TCustomEdit): integer; override;
|
||||
class function GetSelLength(const ACustomEdit: TCustomEdit): integer; override;
|
||||
class function GetText(const AWinControl: TWinControl; var AText: String): Boolean; override;
|
||||
class function GetValue(const ACustomFloatSpinEdit: TCustomFloatSpinEdit): single; override;
|
||||
class function GetSelStart(const ACustomEdit: TCustomEdit): integer; override;
|
||||
class function GetSelLength(const ACustomEdit: TCustomEdit): integer; override;
|
||||
class function GetText(const AWinControl: TWinControl; var AText: String): Boolean; override;
|
||||
class function GetValue(const ACustomFloatSpinEdit: TCustomFloatSpinEdit): single; override;
|
||||
|
||||
class procedure SetCharCase(const ACustomEdit: TCustomEdit; NewCase: TEditCharCase); override;
|
||||
class procedure SetReadOnly(const ACustomEdit: TCustomEdit; NewReadOnly: boolean); override;
|
||||
@ -84,6 +86,19 @@ implementation
|
||||
|
||||
{ TQtWSCustomFloatSpinEdit }
|
||||
|
||||
class procedure TQtWSCustomFloatSpinEdit.InternalUpdateControl(
|
||||
const ASpinWidget: TQtAbstractSpinBox;
|
||||
const ACustomFloatSpinEdit: TCustomFloatSpinEdit);
|
||||
begin
|
||||
if ASpinWidget is TQtFloatSpinBox then
|
||||
TQtFloatSpinBox(ASpinWidget).setDecimals(ACustomFloatSpinEdit.DecimalPlaces);
|
||||
|
||||
ASpinWidget.setValue(ACustomFloatSpinEdit.Value);
|
||||
ASpinWidget.setMinimum(ACustomFloatSpinEdit.MinValue);
|
||||
ASpinWidget.setMaximum(ACustomFloatSpinEdit.MaxValue);
|
||||
ASpinWidget.setSingleStep(ACustomFloatSpinEdit.Increment);
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: TQtWSCustomFloatSpinEdit.CreateHandle
|
||||
Params: None
|
||||
@ -102,6 +117,9 @@ begin
|
||||
QtSpinBox := TQtSpinBox.Create(AWinControl, AParams);
|
||||
|
||||
QtSpinBox.AttachEvents;
|
||||
|
||||
InternalUpdateControl(QtSpinBox, TCustomFloatSpinEdit(AWinControl));
|
||||
|
||||
Result := THandle(QtSpinBox);
|
||||
end;
|
||||
|
||||
@ -118,26 +136,17 @@ end;
|
||||
|
||||
class procedure TQtWSCustomFloatSpinEdit.UpdateControl(const ACustomFloatSpinEdit: TCustomFloatSpinEdit);
|
||||
var
|
||||
QtSpinEdit: TQtSpinBox;
|
||||
QtFloatSpinEdit: TQtFloatSpinBox;
|
||||
CurrentSpinWidget: TQtAbstractSpinBox;
|
||||
begin
|
||||
if ACustomFloatSpinEdit.DecimalPlaces > 0 then
|
||||
begin
|
||||
QtFloatSpinEdit := TQtFloatSpinBox(ACustomFloatSpinEdit.Handle);
|
||||
QDoubleSpinBox_setDecimals(QDoubleSpinBoxH(QtFloatSpinEdit.Widget), ACustomFloatSpinEdit.DecimalPlaces);
|
||||
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);
|
||||
end
|
||||
if not WSCheckHandleAllocated(ACustomFloatSpinEdit, 'UpdateControl') then
|
||||
Exit;
|
||||
|
||||
CurrentSpinWidget := TQtAbstractSpinBox(ACustomFloatSpinEdit.Handle);
|
||||
if ((ACustomFloatSpinEdit.DecimalPlaces > 0) and (CurrentSpinWidget is TQtSpinBox)) or
|
||||
((ACustomFloatSpinEdit.DecimalPlaces = 0) and (CurrentSpinWidget is TQtFloatSpinBox)) then
|
||||
RecreateWnd(ACustomFloatSpinEdit)
|
||||
else
|
||||
begin
|
||||
QtSpinEdit := TQtSpinBox(ACustomFloatSpinEdit.Handle);
|
||||
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));
|
||||
end;
|
||||
InternalUpdateControl(CurrentSpinWidget, ACustomFloatSpinEdit);
|
||||
end;
|
||||
|
||||
class function TQtWSCustomFloatSpinEdit.GetSelStart(
|
||||
|
Loading…
Reference in New Issue
Block a user