Skip to content

Commit 1b057bd

Browse files
committed
fix: improve VirtualTreeView interaction on Qt
1 parent 6add51c commit 1b057bd

3 files changed

Lines changed: 74 additions & 1 deletion

File tree

source/apphelpers.pas

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1516,6 +1516,14 @@ procedure FixVT(VT: TVirtualStringTree; IsResultGrid: Boolean=False);
15161516
if VT is THeidiVirtualStringTree then begin
15171517
VT.LineStyle := lsSolid;
15181518
VT.Colors.TreeLineColor := clGray;
1519+
1520+
if toUseExplorerTheme in VT.TreeOptions.PaintOptions then
1521+
VT.TreeOptions.PaintOptions := VT.TreeOptions.PaintOptions + [toHotTrack]
1522+
else
1523+
VT.TreeOptions.PaintOptions := VT.TreeOptions.PaintOptions - [toHotTrack];
1524+
THeidiVirtualStringTree(VT).ConfigureQtHotTrack(
1525+
toUseExplorerTheme in VT.TreeOptions.PaintOptions);
1526+
15191527
THeidiVirtualStringTree(VT).ConfigureQtGridLines(
15201528
toShowHorzGridLines in VT.TreeOptions.PaintOptions,
15211529
toShowVertGridLines in VT.TreeOptions.PaintOptions);
@@ -1565,7 +1573,6 @@ procedure FixVT(VT: TVirtualStringTree; IsResultGrid: Boolean=False);
15651573
VT.OnContextPopup := MainForm.AnyGridContextPopup;
15661574
end;
15671575

1568-
15691576
function GetTextHeight(Font: TFont): Integer;
15701577
var
15711578
Bmp: Graphics.TBitmap;

source/grideditlinks.pas

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,6 +1695,12 @@ constructor TDataTypeEditorLink.Create(Tree: TVirtualStringTree; AllowEdit: Bool
16951695
FTreeSelect.OnExit := DoEndEdit;
16961696
// See further events in PrepareEdit
16971697
FixVT(FTreeSelect);
1698+
{$IFDEF LINUX}
1699+
{$if defined(LCLQt) or defined(LCLQt5) or defined(LCLQt6)}
1700+
FTreeSelect.TextMargin := 6;
1701+
FTreeSelect.Margin := 2;
1702+
{$endif}
1703+
{$ENDIF}
16981704
FMainControl := FTreeSelect;
16991705

17001706
FMemoHelp := TMemo.Create(FParentForm);

source/lazaruscompat.pas

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,22 @@ THeidiVirtualStringTree = class(TLazVirtualStringTree)
2626
private
2727
FQtShowHorzGridLines: Boolean;
2828
FQtShowVertGridLines: Boolean;
29+
FQtWindowsHotTrack: Boolean;
30+
function BlendQtColor(BaseColor, AccentColor: TColor; AccentPercent: Byte): TColor;
2931
procedure DrawQtSolidLine(Canvas: TCanvas; Left, Top, Right, Bottom: Integer);
3032
protected
33+
procedure DoBeforeCellPaint(Canvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
34+
CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect); override;
3135
procedure DoAfterCellPaint(Canvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
3236
const CellRect: TRect); override;
37+
procedure DoPaintText(Node: PVirtualNode; const Canvas: TCanvas; Column: TColumnIndex;
38+
TextType: TVSTTextType); override;
3339
procedure DrawDottedHLine(const PaintInfo: TVTPaintInfo; Left, Right, Top: Integer); override;
3440
procedure DrawDottedVLine(const PaintInfo: TVTPaintInfo; Top, Bottom, Left: Integer;
3541
UseSelectedBkColor: Boolean = False); override;
3642
public
3743
procedure ConfigureQtGridLines(ShowHorz, ShowVert: Boolean);
44+
procedure ConfigureQtHotTrack(Enabled: Boolean);
3845
{$ENDIF}
3946
end;
4047

@@ -203,6 +210,22 @@ implementation
203210
uses
204211
Math;
205212

213+
function THeidiVirtualStringTree.BlendQtColor(BaseColor, AccentColor: TColor;
214+
AccentPercent: Byte): TColor;
215+
var
216+
BaseRGB, AccentRGB: LongInt;
217+
BaseWeight: Integer;
218+
begin
219+
BaseRGB := ColorToRGB(BaseColor);
220+
AccentRGB := ColorToRGB(AccentColor);
221+
BaseWeight := 100 - AccentPercent;
222+
Result := RGBToColor(
223+
(((BaseRGB and $FF) * BaseWeight) + ((AccentRGB and $FF) * AccentPercent)) div 100,
224+
((((BaseRGB shr 8) and $FF) * BaseWeight) + (((AccentRGB shr 8) and $FF) * AccentPercent)) div 100,
225+
((((BaseRGB shr 16) and $FF) * BaseWeight) + (((AccentRGB shr 16) and $FF) * AccentPercent)) div 100);
226+
end;
227+
228+
206229
procedure THeidiVirtualStringTree.DrawQtSolidLine(Canvas: TCanvas; Left, Top, Right, Bottom: Integer);
207230
var
208231
OldBrushColor: TColor;
@@ -226,6 +249,43 @@ procedure THeidiVirtualStringTree.ConfigureQtGridLines(ShowHorz, ShowVert: Boole
226249
FQtShowVertGridLines := ShowVert;
227250
end;
228251

252+
procedure THeidiVirtualStringTree.ConfigureQtHotTrack(Enabled: Boolean);
253+
begin
254+
FQtWindowsHotTrack := Enabled;
255+
end;
256+
257+
procedure THeidiVirtualStringTree.DoBeforeCellPaint(Canvas: TCanvas; Node: PVirtualNode;
258+
Column: TColumnIndex; CellPaintMode: TVTCellPaintMode; CellRect: TRect;
259+
var ContentRect: TRect);
260+
var
261+
OldBrushColor: TColor;
262+
OldBrushStyle: TBrushStyle;
263+
begin
264+
inherited DoBeforeCellPaint(Canvas, Node, Column, CellPaintMode, CellRect, ContentRect);
265+
if (CellPaintMode <> cpmPaint) or (not FQtWindowsHotTrack) or
266+
(Node <> HotNode) or (vsSelected in Node.States) then
267+
Exit;
268+
269+
OldBrushColor := Canvas.Brush.Color;
270+
OldBrushStyle := Canvas.Brush.Style;
271+
try
272+
Canvas.Brush.Style := bsSolid;
273+
Canvas.Brush.Color := BlendQtColor(OldBrushColor, clHighlight, 12);
274+
Canvas.FillRect(CellRect);
275+
finally
276+
Canvas.Brush.Style := OldBrushStyle;
277+
Canvas.Brush.Color := OldBrushColor;
278+
end;
279+
end;
280+
281+
procedure THeidiVirtualStringTree.DoPaintText(Node: PVirtualNode; const Canvas: TCanvas;
282+
Column: TColumnIndex; TextType: TVSTTextType);
283+
begin
284+
inherited DoPaintText(Node, Canvas, Column, TextType);
285+
if FQtWindowsHotTrack and (Node = HotNode) then
286+
Canvas.Font.Style := Canvas.Font.Style - [fsUnderline];
287+
end;
288+
229289
procedure THeidiVirtualStringTree.DoAfterCellPaint(Canvas: TCanvas; Node: PVirtualNode;
230290
Column: TColumnIndex; const CellRect: TRect);
231291
var

0 commit comments

Comments
 (0)