|
2 | 2 |
|
3 | 3 | {$mode delphi}{$H+} |
4 | 4 |
|
| 5 | +{$IFDEF LINUX} |
| 6 | + {$if defined(LCLQt) or defined(LCLQt5) or defined(LCLQt6)} |
| 7 | + {$DEFINE HEIDI_LINUX_QT} |
| 8 | + {$endif} |
| 9 | +{$ENDIF} |
| 10 | + |
5 | 11 | interface |
6 | 12 |
|
7 | 13 | uses |
8 | 14 | Classes, SysUtils, SynEdit, SynEditKeyCmds, SynEditHighlighter, laz.VirtualTrees, |
9 | | - Graphics, SynCompletion; |
| 15 | + Graphics, SynCompletion, Types; |
10 | 16 |
|
11 | 17 | type |
12 | 18 |
|
13 | 19 | // Delphi type aliases |
14 | 20 | TSynMemo = TSynEdit; |
15 | 21 | 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 | + |
16 | 41 | TProgressBarState = (pbsNormal, pbsError, pbsPaused); |
17 | 42 |
|
18 | 43 | // Add methods which exist in Delphi but not in Lazarus |
@@ -44,6 +69,8 @@ TStringsHelper = class helper for TStrings |
44 | 69 | function IsEmpty: Boolean; |
45 | 70 | end; |
46 | 71 |
|
| 72 | +function CreateVirtualStringTree(AOwner: TComponent): TVirtualStringTree; |
| 73 | + |
47 | 74 | const |
48 | 75 | {$IFDEF SYN_CodeFolding} |
49 | 76 | EditorCommandStrs: array[0..109] of TIdentMapEntry = ( |
@@ -172,6 +199,86 @@ TStringsHelper = class helper for TStrings |
172 | 199 |
|
173 | 200 | implementation |
174 | 201 |
|
| 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 | + |
175 | 282 |
|
176 | 283 | function TSynEditHelper.GetTextLen: Integer; |
177 | 284 | begin |
@@ -267,5 +374,8 @@ function TStringsHelper.IsEmpty: Boolean; |
267 | 374 | Result := Count = 0; |
268 | 375 | end; |
269 | 376 |
|
| 377 | +initialization |
| 378 | + RegisterClass(THeidiVirtualStringTree); |
| 379 | + |
270 | 380 | end. |
271 | 381 |
|
0 commit comments