mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-21 09:58:13 +00:00
FIX: Blurry TBitBtn icons under Qt6 with Lazarus 4.6
This commit is contained in:
parent
13c1a12a8e
commit
b33bb79302
2 changed files with 104 additions and 0 deletions
|
|
@ -49,6 +49,9 @@ uses
|
|||
{$ENDIF}
|
||||
{$IFDEF LCLQT6}
|
||||
uQtWSControls,
|
||||
{$IFNDEF LCL_VER_499}
|
||||
uQtWSButtons,
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
{$IFDEF LCLGTK2}
|
||||
uGtk2FixCursorPos,
|
||||
|
|
|
|||
101
src/platform/unix/qt6/uqtwsbuttons.pas
Normal file
101
src/platform/unix/qt6/uqtwsbuttons.pas
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
unit uQtWSButtons;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
QtWSButtons, Buttons, Graphics, GraphType;
|
||||
|
||||
type
|
||||
|
||||
{ TCustomBitBtnEx }
|
||||
|
||||
TCustomBitBtnEx = class(TCustomBitBtn);
|
||||
|
||||
{ TQtWSBitBtnEx }
|
||||
|
||||
TQtWSBitBtnEx = class(TQtWSBitBtn)
|
||||
published
|
||||
class procedure SetGlyph(const ABitBtn: TCustomBitBtn; const AValue: TButtonGlyph); override;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
Types, ImgList, Qt6, QtObjects, QtWidgets, WSProc, WSLCLClasses, LResources;
|
||||
|
||||
{ TQtWSBitBtnEx }
|
||||
|
||||
class procedure TQtWSBitBtnEx.SetGlyph(const ABitBtn: TCustomBitBtn; const AValue: TButtonGlyph);
|
||||
const
|
||||
IconModeToButtonState: array[QIconMode] of TButtonState =
|
||||
(
|
||||
{ QIconNormal } bsUp,
|
||||
{ QIconDisabled } bsDisabled,
|
||||
{ QIconActive } bsHot,
|
||||
{ QIconSelected } bsDown
|
||||
);
|
||||
|
||||
var
|
||||
AIcon: QIconH;
|
||||
APixmap: QPixmapH;
|
||||
AGlyph: TBitmap;
|
||||
AIndex: Integer;
|
||||
AEffect: TGraphicsDrawEffect;
|
||||
Mode: QIconMode;
|
||||
ASize: TSize;
|
||||
AImageRes: TScaledImageListResolution;
|
||||
AScaleFactor: Double;
|
||||
begin
|
||||
if not WSCheckHandleAllocated(ABitBtn, 'SetGlyph') then
|
||||
Exit;
|
||||
|
||||
TQtBitBtn(ABitBtn.Handle).GlyphLayout := Ord(ABitBtn.Layout);
|
||||
AIcon := QIcon_create();
|
||||
if ABitBtn.CanShowGlyph(True) then
|
||||
begin
|
||||
AGlyph := TBitmap.Create;
|
||||
APixmap := QPixmap_create();
|
||||
AScaleFactor:= ABitBtn.GetCanvasScaleFactor;
|
||||
|
||||
for Mode := QIconNormal to QIconSelected do
|
||||
begin
|
||||
AValue.GetImageIndexAndEffect(IconModeToButtonState[Mode],
|
||||
ABitBtn.Font.PixelsPerInch, 1, AImageRes, AIndex, AEffect);
|
||||
AImageRes.GetBitmap(AIndex, AGlyph, AEffect);
|
||||
QPixmap_fromImage(APixmap, TQtImage(AGlyph.Handle).Handle);
|
||||
QIcon_addPixmap(AIcon, APixmap, Mode, QIconOn);
|
||||
|
||||
if AScaleFactor <> 1 then
|
||||
begin
|
||||
AValue.GetImageIndexAndEffect(IconModeToButtonState[Mode],
|
||||
ABitBtn.Font.PixelsPerInch, AScaleFactor, AImageRes, AIndex, AEffect);
|
||||
AImageRes.GetBitmap(AIndex, AGlyph, AEffect);
|
||||
QImage_setDevicePixelRatio(TQtImage(AGlyph.Handle).Handle, AScaleFactor);
|
||||
QPixmap_fromImage(APixmap, TQtImage(AGlyph.Handle).Handle);
|
||||
QIcon_addPixmap(AIcon, APixmap, Mode, QIconOn);
|
||||
end;
|
||||
end;
|
||||
QPixmap_destroy(APixmap);
|
||||
AGlyph.Free;
|
||||
|
||||
ASize.cx := AImageRes.Width;
|
||||
ASize.cy := AImageRes.Height;
|
||||
TQtBitBtn(ABitBtn.Handle).setIconSize(@ASize);
|
||||
end;
|
||||
|
||||
TQtBitBtn(ABitBtn.Handle).setIcon(AIcon);
|
||||
QIcon_destroy(AIcon);
|
||||
end;
|
||||
|
||||
procedure Initialize;
|
||||
begin
|
||||
TCustomBitBtnEx.WSRegisterClass;
|
||||
RegisterWSComponent(TCustomBitBtn, TQtWSBitBtnEx);
|
||||
end;
|
||||
|
||||
initialization
|
||||
Initialize;
|
||||
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue