Skip to content

Commit 6add51c

Browse files
committed
fix: render VirtualTreeView correctly on Qt
1 parent 59a6b09 commit 6add51c

16 files changed

Lines changed: 175 additions & 41 deletions

source/apphelpers.pas

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,11 +1510,34 @@ procedure FixVT(VT: TVirtualStringTree; IsResultGrid: Boolean=False);
15101510
VT.EndUpdate;
15111511
end;
15121512
VT.DefaultText := '-'; // "Node" by default
1513-
{$IFNDEF WINDOWS}
1514-
// Disable grid lines, looks ok on Windows with dotted light lines, but not on macOS and Linux
1515-
if (toHotTrack in VT.TreeOptions.PaintOptions) then
1516-
VT.TreeOptions.PaintOptions := VT.TreeOptions.PaintOptions - [toShowHorzGridLines, toShowVertGridLines];
1513+
1514+
{$IFDEF LINUX}
1515+
{$if defined(LCLQt) or defined(LCLQt5) or defined(LCLQt6)}
1516+
if VT is THeidiVirtualStringTree then begin
1517+
VT.LineStyle := lsSolid;
1518+
VT.Colors.TreeLineColor := clGray;
1519+
THeidiVirtualStringTree(VT).ConfigureQtGridLines(
1520+
toShowHorzGridLines in VT.TreeOptions.PaintOptions,
1521+
toShowVertGridLines in VT.TreeOptions.PaintOptions);
1522+
if (toShowHorzGridLines in VT.TreeOptions.PaintOptions) or
1523+
(toShowVertGridLines in VT.TreeOptions.PaintOptions) then
1524+
VT.Colors.GridLineColor := clGray;
1525+
VT.TreeOptions.PaintOptions := VT.TreeOptions.PaintOptions -
1526+
[toShowHorzGridLines, toShowVertGridLines];
1527+
end;
1528+
{$else}
1529+
if not IsResultGrid then
1530+
VT.TreeOptions.PaintOptions := VT.TreeOptions.PaintOptions -
1531+
[toShowHorzGridLines, toShowVertGridLines];
1532+
{$endif}
1533+
{$ELSE}
1534+
{$IFNDEF WINDOWS}
1535+
if not IsResultGrid then
1536+
VT.TreeOptions.PaintOptions := VT.TreeOptions.PaintOptions -
1537+
[toShowHorzGridLines, toShowVertGridLines];
1538+
{$ENDIF}
15171539
{$ENDIF}
1540+
15181541
VT.OnGetHint := MainForm.AnyGridGetHint;
15191542
VT.OnScroll := MainForm.AnyGridScroll;
15201543
VT.OnMouseWheel := MainForm.AnyGridMouseWheel;

source/connections.lfm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,7 @@ object connform: Tconnform
11481148
Constraints.MinWidth = 100
11491149
ParentBackground = False
11501150
TabOrder = 2
1151-
object ListSessions: TLazVirtualStringTree
1151+
object ListSessions: THeidiVirtualStringTree
11521152
Left = 0
11531153
Height = 427
11541154
Top = 28

source/copytable.lfm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ object CopyTableForm: TCopyTableForm
113113
TabOrder = 4
114114
OnClick = btnOKClick
115115
end
116-
object TreeElements: TLazVirtualStringTree
116+
object TreeElements: THeidiVirtualStringTree
117117
AnchorSideLeft.Control = comboDatabase
118118
AnchorSideTop.Control = lblItems
119119
AnchorSideTop.Side = asrBottom

source/grideditlinks.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1671,7 +1671,7 @@ constructor TDataTypeEditorLink.Create(Tree: TVirtualStringTree; AllowEdit: Bool
16711671
begin
16721672
inherited;
16731673

1674-
FTreeSelect := TVirtualStringTree.Create(FParentForm);
1674+
FTreeSelect := CreateVirtualStringTree(FParentForm);
16751675
FTreeSelect.Hide;
16761676
FTreeSelect.TreeOptions.PaintOptions := FTreeSelect.TreeOptions.PaintOptions
16771677
- [toShowTreeLines, toShowButtons, toShowRoot]

source/insertfiles.lfm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ object frmInsertFiles: TfrmInsertFiles
121121
TabOrder = 1
122122
OnChange = comboTablesChange
123123
end
124-
object ListColumns: TLazVirtualStringTree
124+
object ListColumns: THeidiVirtualStringTree
125125
AnchorSideLeft.Control = grpSelectObject
126126
AnchorSideTop.Control = lblFilecontents
127127
AnchorSideTop.Side = asrBottom
@@ -221,7 +221,7 @@ object frmInsertFiles: TfrmInsertFiles
221221
BorderSpacing.Around = 5
222222
Caption = '0 files'
223223
end
224-
object ListFiles: TLazVirtualStringTree
224+
object ListFiles: THeidiVirtualStringTree
225225
AnchorSideLeft.Control = GroupBox2
226226
AnchorSideTop.Control = ToolBar1
227227
AnchorSideTop.Side = asrBottom
@@ -260,7 +260,7 @@ object frmInsertFiles: TfrmInsertFiles
260260
TabOrder = 0
261261
TreeOptions.AutoOptions = [toAutoDropExpand, toAutoScroll, toAutoScrollOnExpand, toAutoSort, toAutoTristateTracking, toAutoDeleteMovedNodes, toAutoChangeScale]
262262
TreeOptions.MiscOptions = [toAcceptOLEDrop, toCheckSupport, toFullRepaintOnResize, toInitOnSave, toToggleOnDblClick, toWheelPanning, toEditOnClick]
263-
TreeOptions.PaintOptions = [toHotTrack, toShowButtons, toShowDropmark, toShowTreeLines, toThemeAware, toUseBlendedImages, toUseExplorerTheme, toHideTreeLinesIfThemed]
263+
TreeOptions.PaintOptions = [toHotTrack, toShowButtons, toShowDropmark, toShowTreeLines, toShowVertGridLines, toThemeAware, toUseBlendedImages, toUseExplorerTheme, toHideTreeLinesIfThemed]
264264
TreeOptions.SelectionOptions = [toFullRowSelect, toMultiSelect]
265265
OnAfterCellPaint = GridAfterCellPaint
266266
OnBeforeCellPaint = ListFilesBeforeCellPaint

source/lazaruscompat.pas

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,42 @@
22

33
{$mode delphi}{$H+}
44

5+
{$IFDEF LINUX}
6+
{$if defined(LCLQt) or defined(LCLQt5) or defined(LCLQt6)}
7+
{$DEFINE HEIDI_LINUX_QT}
8+
{$endif}
9+
{$ENDIF}
10+
511
interface
612

713
uses
814
Classes, SysUtils, SynEdit, SynEditKeyCmds, SynEditHighlighter, laz.VirtualTrees,
9-
Graphics, SynCompletion;
15+
Graphics, SynCompletion, Types;
1016

1117
type
1218

1319
// Delphi type aliases
1420
TSynMemo = TSynEdit;
1521
TVirtualStringTree = TLazVirtualStringTree;
22+
23+
// VirtualTreeView fixes for Linux Qt.
24+
THeidiVirtualStringTree = class(TLazVirtualStringTree)
25+
{$IFDEF HEIDI_LINUX_QT}
26+
private
27+
FQtShowHorzGridLines: Boolean;
28+
FQtShowVertGridLines: Boolean;
29+
procedure DrawQtSolidLine(Canvas: TCanvas; Left, Top, Right, Bottom: Integer);
30+
protected
31+
procedure DoAfterCellPaint(Canvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
32+
const CellRect: TRect); override;
33+
procedure DrawDottedHLine(const PaintInfo: TVTPaintInfo; Left, Right, Top: Integer); override;
34+
procedure DrawDottedVLine(const PaintInfo: TVTPaintInfo; Top, Bottom, Left: Integer;
35+
UseSelectedBkColor: Boolean = False); override;
36+
public
37+
procedure ConfigureQtGridLines(ShowHorz, ShowVert: Boolean);
38+
{$ENDIF}
39+
end;
40+
1641
TProgressBarState = (pbsNormal, pbsError, pbsPaused);
1742

1843
// Add methods which exist in Delphi but not in Lazarus
@@ -44,6 +69,8 @@ TStringsHelper = class helper for TStrings
4469
function IsEmpty: Boolean;
4570
end;
4671

72+
function CreateVirtualStringTree(AOwner: TComponent): TVirtualStringTree;
73+
4774
const
4875
{$IFDEF SYN_CodeFolding}
4976
EditorCommandStrs: array[0..109] of TIdentMapEntry = (
@@ -172,6 +199,86 @@ TStringsHelper = class helper for TStrings
172199

173200
implementation
174201

202+
{$IFDEF HEIDI_LINUX_QT}
203+
uses
204+
Math;
205+
206+
procedure THeidiVirtualStringTree.DrawQtSolidLine(Canvas: TCanvas; Left, Top, Right, Bottom: Integer);
207+
var
208+
OldBrushColor: TColor;
209+
OldBrushStyle: TBrushStyle;
210+
begin
211+
OldBrushColor := Canvas.Brush.Color;
212+
OldBrushStyle := Canvas.Brush.Style;
213+
try
214+
Canvas.Brush.Style := bsSolid;
215+
Canvas.Brush.Color := Colors.TreeLineColor;
216+
Canvas.FillRect(Rect(Left, Top, Right, Bottom));
217+
finally
218+
Canvas.Brush.Style := OldBrushStyle;
219+
Canvas.Brush.Color := OldBrushColor;
220+
end;
221+
end;
222+
223+
procedure THeidiVirtualStringTree.ConfigureQtGridLines(ShowHorz, ShowVert: Boolean);
224+
begin
225+
FQtShowHorzGridLines := ShowHorz;
226+
FQtShowVertGridLines := ShowVert;
227+
end;
228+
229+
procedure THeidiVirtualStringTree.DoAfterCellPaint(Canvas: TCanvas; Node: PVirtualNode;
230+
Column: TColumnIndex; const CellRect: TRect);
231+
var
232+
OldBrushColor: TColor;
233+
OldBrushStyle: TBrushStyle;
234+
begin
235+
inherited DoAfterCellPaint(Canvas, Node, Column, CellRect);
236+
if not (FQtShowHorzGridLines or FQtShowVertGridLines) then
237+
Exit;
238+
239+
OldBrushColor := Canvas.Brush.Color;
240+
OldBrushStyle := Canvas.Brush.Style;
241+
try
242+
Canvas.Brush.Style := bsSolid;
243+
Canvas.Brush.Color := Colors.GridLineColor;
244+
if FQtShowVertGridLines and (CellRect.Right > CellRect.Left) then
245+
Canvas.FillRect(Rect(CellRect.Right - 1, CellRect.Top, CellRect.Right, CellRect.Bottom));
246+
if FQtShowHorzGridLines and (CellRect.Bottom > CellRect.Top) then
247+
Canvas.FillRect(Rect(CellRect.Left, CellRect.Bottom - 1, CellRect.Right, CellRect.Bottom));
248+
finally
249+
Canvas.Brush.Style := OldBrushStyle;
250+
Canvas.Brush.Color := OldBrushColor;
251+
end;
252+
end;
253+
254+
procedure THeidiVirtualStringTree.DrawDottedHLine(const PaintInfo: TVTPaintInfo;
255+
Left, Right, Top: Integer);
256+
begin
257+
if LineStyle = lsSolid then
258+
DrawQtSolidLine(PaintInfo.Canvas, Min(Left, Right), Top, Max(Left, Right) + 1, Top + 1)
259+
else
260+
inherited DrawDottedHLine(PaintInfo, Left, Right, Top);
261+
end;
262+
263+
procedure THeidiVirtualStringTree.DrawDottedVLine(const PaintInfo: TVTPaintInfo;
264+
Top, Bottom, Left: Integer; UseSelectedBkColor: Boolean);
265+
begin
266+
if LineStyle = lsSolid then
267+
DrawQtSolidLine(PaintInfo.Canvas, Left, Min(Top, Bottom), Left + 1, Max(Top, Bottom) + 1)
268+
else
269+
inherited DrawDottedVLine(PaintInfo, Top, Bottom, Left, UseSelectedBkColor);
270+
end;
271+
{$ENDIF}
272+
273+
function CreateVirtualStringTree(AOwner: TComponent): TVirtualStringTree;
274+
begin
275+
{$IFDEF HEIDI_LINUX_QT}
276+
Result := THeidiVirtualStringTree.Create(AOwner);
277+
{$ELSE}
278+
Result := TVirtualStringTree.Create(AOwner);
279+
{$ENDIF}
280+
end;
281+
175282

176283
function TSynEditHelper.GetTextLen: Integer;
177284
begin
@@ -267,5 +374,8 @@ function TStringsHelper.IsEmpty: Boolean;
267374
Result := Count = 0;
268375
end;
269376

377+
initialization
378+
RegisterClass(THeidiVirtualStringTree);
379+
270380
end.
271381

source/main.lfm

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ object MainForm: TMainForm
940940
OnKeyPress = editDatabaseTableFilterKeyPress
941941
end
942942
end
943-
object DBtree: TLazVirtualStringTree
943+
object DBtree: THeidiVirtualStringTree
944944
AnchorSideTop.Side = asrBottom
945945
AnchorSideRight.Side = asrBottom
946946
Left = 0
@@ -1127,7 +1127,7 @@ object MainForm: TMainForm
11271127
ClientHeight = 176
11281128
ClientWidth = 607
11291129
ImageIndex = 5
1130-
object ListDatabases: TLazVirtualStringTree
1130+
object ListDatabases: THeidiVirtualStringTree
11311131
Left = 0
11321132
Height = 176
11331133
Top = 0
@@ -1211,7 +1211,7 @@ object MainForm: TMainForm
12111211
ClientHeight = 176
12121212
ClientWidth = 607
12131213
ImageIndex = 137
1214-
object ListVariables: TLazVirtualStringTree
1214+
object ListVariables: THeidiVirtualStringTree
12151215
Left = 0
12161216
Height = 176
12171217
Top = 0
@@ -1268,7 +1268,7 @@ object MainForm: TMainForm
12681268
ClientHeight = 176
12691269
ClientWidth = 607
12701270
ImageIndex = 13
1271-
object ListStatus: TLazVirtualStringTree
1271+
object ListStatus: THeidiVirtualStringTree
12721272
Left = 0
12731273
Height = 176
12741274
Top = 0
@@ -1843,7 +1843,7 @@ object MainForm: TMainForm
18431843
Align = alBottom
18441844
ResizeAnchor = akBottom
18451845
end
1846-
object ListProcesses: TLazVirtualStringTree
1846+
object ListProcesses: THeidiVirtualStringTree
18471847
Left = 0
18481848
Height = 116
18491849
Top = 0
@@ -1925,7 +1925,7 @@ object MainForm: TMainForm
19251925
ClientHeight = 176
19261926
ClientWidth = 607
19271927
ImageIndex = 145
1928-
object ListCommandStats: TLazVirtualStringTree
1928+
object ListCommandStats: THeidiVirtualStringTree
19291929
Left = 0
19301930
Height = 176
19311931
Top = 0
@@ -1996,7 +1996,7 @@ object MainForm: TMainForm
19961996
ClientHeight = 204
19971997
ClientWidth = 615
19981998
ImageIndex = 5
1999-
object ListTables: TLazVirtualStringTree
1999+
object ListTables: THeidiVirtualStringTree
20002000
Left = 0
20012001
Height = 204
20022002
Top = 0
@@ -2844,7 +2844,7 @@ object MainForm: TMainForm
28442844
end
28452845
end
28462846
end
2847-
object DataGrid: TLazVirtualStringTree
2847+
object DataGrid: THeidiVirtualStringTree
28482848
Left = 2
28492849
Height = 95
28502850
Top = 107
@@ -2938,7 +2938,7 @@ object MainForm: TMainForm
29382938
OnButtonClick = buttonedEditClear
29392939
OnChange = filterQueryHelpersChange
29402940
end
2941-
object treeQueryHelpers: TLazVirtualStringTree
2941+
object treeQueryHelpers: THeidiVirtualStringTree
29422942
AnchorSideTop.Side = asrBottom
29432943
Left = 0
29442944
Height = 81
@@ -3508,7 +3508,7 @@ object MainForm: TMainForm
35083508
ShowHint = True
35093509
TabOrder = 2
35103510
end
3511-
object QueryGrid: TLazVirtualStringTree
3511+
object QueryGrid: THeidiVirtualStringTree
35123512
Left = 0
35133513
Height = 69
35143514
Top = 135

source/main.pas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12704,7 +12704,7 @@ procedure TMainForm.actNewQueryTabExecute(Sender: TObject);
1270412704
QueryTab.filterHelpers.OnChange := filterQueryHelpers.OnChange;
1270512705
QueryTab.filterHelpers.OnButtonClick := filterQueryHelpers.OnButtonClick;
1270612706

12707-
QueryTab.treeHelpers := TVirtualStringTree.Create(QueryTab.pnlHelpers);
12707+
QueryTab.treeHelpers := CreateVirtualStringTree(QueryTab.pnlHelpers);
1270812708
QueryTab.treeHelpers.Name := treeQueryHelpers.Name + i.ToString;
1270912709
QueryTab.treeHelpers.Parent := QueryTab.pnlHelpers;
1271012710
QueryTab.treeHelpers.Align := treeQueryHelpers.Align;
@@ -15884,7 +15884,7 @@ constructor TResultTab.Create(AOwner: TQueryTab);
1588415884
inherited Create;
1588515885
QueryTab := AOwner;
1588615886
OrgGrid := Mainform.QueryGrid;
15887-
Grid := TVirtualStringTree.Create(QueryTab.TabSheet);
15887+
Grid := CreateVirtualStringTree(QueryTab.TabSheet);
1588815888
Grid.Parent := QueryTab.TabSheet;
1588915889
Grid.Tag := OrgGrid.Tag;
1589015890
Grid.BorderStyle := OrgGrid.BorderStyle;

source/preferences.lfm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1667,7 +1667,7 @@ object frmPreferences: TfrmPreferences
16671667
BorderSpacing.Around = 5
16681668
Caption = 'Secondary shortcut:'
16691669
end
1670-
object TreeShortcutItems: TLazVirtualStringTree
1670+
object TreeShortcutItems: THeidiVirtualStringTree
16711671
AnchorSideLeft.Control = tabShortcuts
16721672
AnchorSideTop.Control = editShortcutsFilter
16731673
AnchorSideTop.Side = asrBottom

source/preferences.pas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ procedure TfrmPreferences.FormCreate(Sender: TObject);
547547
begin
548548
Width := AppSettings.ReadInt(asPreferencesWindowWidth);
549549
Height := AppSettings.ReadInt(asPreferencesWindowHeight);
550+
FixVT(TreeShortcutItems);
550551

551552
// General tab
552553
editTerminal.Enabled := {$IFDEF WINDOWS} False {$ELSE} True {$ENDIF};

0 commit comments

Comments
 (0)