mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-08 09:56:46 +02:00
Qt: fixed spacing & margin properties of TBitBtn. issue #24531
git-svn-id: trunk@41511 -
This commit is contained in:
parent
805c867bae
commit
3d4a0ec11b
@ -1818,6 +1818,7 @@ const
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
|
Buttons,
|
||||||
qtCaret,
|
qtCaret,
|
||||||
qtproc,
|
qtproc,
|
||||||
qtprivate,
|
qtprivate,
|
||||||
@ -5509,8 +5510,6 @@ function TQtBitBtn.EventFilter(Sender: QObjectH; Event: QEventH): Boolean;
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function PaintBtn: Boolean;
|
function PaintBtn: Boolean;
|
||||||
const
|
|
||||||
IconDistance = 4; // hardcoded in qt libs (distance between icon and text)
|
|
||||||
var
|
var
|
||||||
APainter: QPainterH;
|
APainter: QPainterH;
|
||||||
R: TRect;
|
R: TRect;
|
||||||
@ -5524,6 +5523,8 @@ function TQtBitBtn.EventFilter(Sender: QObjectH; Event: QEventH): Boolean;
|
|||||||
AText: WideString;
|
AText: WideString;
|
||||||
DTFLAGS: DWord;
|
DTFLAGS: DWord;
|
||||||
ContentSize: TSize;
|
ContentSize: TSize;
|
||||||
|
IconDistance: Integer;
|
||||||
|
IconMargin: Integer;
|
||||||
begin
|
begin
|
||||||
Result := False;
|
Result := False;
|
||||||
if (FIcon = nil) then
|
if (FIcon = nil) then
|
||||||
@ -5532,6 +5533,12 @@ function TQtBitBtn.EventFilter(Sender: QObjectH; Event: QEventH): Boolean;
|
|||||||
// paint button
|
// paint button
|
||||||
QObject_event(Widget, Event);
|
QObject_event(Widget, Event);
|
||||||
|
|
||||||
|
IconDistance := TCustomBitBtn(LCLObject).Spacing;
|
||||||
|
if IconDistance < 0 then
|
||||||
|
IconDistance := 4; {qt default}
|
||||||
|
|
||||||
|
IconMargin := TCustomBitBtn(LCLObject).Margin;
|
||||||
|
|
||||||
// now we paint icon & text
|
// now we paint icon & text
|
||||||
APainter := QPainter_create(QWidget_to_QPaintDevice(Widget));
|
APainter := QPainter_create(QWidget_to_QPaintDevice(Widget));
|
||||||
AText := FText;
|
AText := FText;
|
||||||
@ -5631,6 +5638,9 @@ function TQtBitBtn.EventFilter(Sender: QObjectH; Event: QEventH): Boolean;
|
|||||||
end else
|
end else
|
||||||
CenterOffset := ((R.Bottom - R.Top) div 2) - (ContentSize.cy div 2);
|
CenterOffset := ((R.Bottom - R.Top) div 2) - (ContentSize.cy div 2);
|
||||||
|
|
||||||
|
if IconMargin >= 0 then
|
||||||
|
CenterOffset := IconMargin;
|
||||||
|
|
||||||
if FText <> '' then
|
if FText <> '' then
|
||||||
begin
|
begin
|
||||||
if FGlyphLayout = 0 then
|
if FGlyphLayout = 0 then
|
||||||
@ -5650,11 +5660,18 @@ function TQtBitBtn.EventFilter(Sender: QObjectH; Event: QEventH): Boolean;
|
|||||||
|
|
||||||
R := R2;
|
R := R2;
|
||||||
if FGlyphLayout = 0 then
|
if FGlyphLayout = 0 then
|
||||||
inc(R.Left, CenterOffset)
|
inc(R.Left, CenterOffset + IconDistance)
|
||||||
else
|
else
|
||||||
if FGlyphLayout = 1 then
|
if FGlyphLayout = 1 then
|
||||||
dec(R.Right, CenterOffset);
|
dec(R.Right, CenterOffset + IconDistance)
|
||||||
|
else
|
||||||
|
if FGlyphLayout = 2 then
|
||||||
|
inc(R.Top, CenterOffset + IconDistance)
|
||||||
|
else
|
||||||
|
if FGlyphLayout = 3 then
|
||||||
|
dec(R.Bottom, CenterOffset + IconDistance);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if AText <> '' then
|
if AText <> '' then
|
||||||
QPainter_drawText(APainter, R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top,
|
QPainter_drawText(APainter, R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top,
|
||||||
DTFlagsToQtFlags(DTFLAGS), @AText);
|
DTFlagsToQtFlags(DTFLAGS), @AText);
|
||||||
|
@ -42,6 +42,8 @@ type
|
|||||||
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
|
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
|
||||||
class procedure SetGlyph(const ABitBtn: TCustomBitBtn; const AValue: TButtonGlyph); override;
|
class procedure SetGlyph(const ABitBtn: TCustomBitBtn; const AValue: TButtonGlyph); override;
|
||||||
class procedure SetLayout(const ABitBtn: TCustomBitBtn; const AValue: TButtonLayout); override;
|
class procedure SetLayout(const ABitBtn: TCustomBitBtn; const AValue: TButtonLayout); override;
|
||||||
|
class procedure SetMargin(const ABitBtn: TCustomBitBtn; const AValue: Integer); virtual;
|
||||||
|
class procedure SetSpacing(const ABitBtn: TCustomBitBtn; const AValue: Integer); virtual;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TQtWSSpeedButton }
|
{ TQtWSSpeedButton }
|
||||||
@ -130,4 +132,22 @@ begin
|
|||||||
TQtBitBtn(ABitBtn.Handle).Update(nil);
|
TQtBitBtn(ABitBtn.Handle).Update(nil);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
class procedure TQtWSBitBtn.SetMargin(const ABitBtn: TCustomBitBtn;
|
||||||
|
const AValue: Integer);
|
||||||
|
begin
|
||||||
|
if not WSCheckHandleAllocated(ABitBtn, 'SetMargin') then
|
||||||
|
Exit;
|
||||||
|
if TQtBitBtn(ABitBtn.Handle).getVisible then
|
||||||
|
TQtBitBtn(ABitBtn.Handle).Update(nil);
|
||||||
|
end;
|
||||||
|
|
||||||
|
class procedure TQtWSBitBtn.SetSpacing(const ABitBtn: TCustomBitBtn;
|
||||||
|
const AValue: Integer);
|
||||||
|
begin
|
||||||
|
if not WSCheckHandleAllocated(ABitBtn, 'SetSpacing') then
|
||||||
|
Exit;
|
||||||
|
if TQtBitBtn(ABitBtn.Handle).getVisible then
|
||||||
|
TQtBitBtn(ABitBtn.Handle).Update(nil);
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user