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