Skip to content

Commit

Permalink
Issue #139: use alternating row background in database tab, and in al…
Browse files Browse the repository at this point in the history
…l sub tabs of the host tab
  • Loading branch information
ansgarbecker committed May 1, 2024
1 parent 538cd1e commit c5f93d2
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 24 deletions.
1 change: 1 addition & 0 deletions source/main.dfm
Expand Up @@ -587,6 +587,7 @@ object MainForm: TMainForm
TreeOptions.PaintOptions = [toHotTrack, toShowDropmark, toShowHorzGridLines, toShowVertGridLines, toThemeAware, toUseBlendedImages, toUseExplorerTheme]
TreeOptions.SelectionOptions = [toExtendedFocus, toFullRowSelect, toRightClickSelect]
OnAfterPaint = AnyGridAfterPaint
OnBeforeCellPaint = ListStatusBeforeCellPaint
OnBeforePaint = HostListBeforePaint
OnCompareNodes = AnyGridCompareNodes
OnGetText = HostListGetText
Expand Down
61 changes: 50 additions & 11 deletions source/main.pas
Expand Up @@ -1192,6 +1192,9 @@ TMainForm = class(TExtForm)
procedure menuTabsInMultipleLinesClick(Sender: TObject);
procedure actResetPanelDimensionsExecute(Sender: TObject);
procedure menuAlwaysGenerateFilterClick(Sender: TObject);
procedure ListStatusBeforeCellPaint(Sender: TBaseVirtualTree;
TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect);
private
// Executable file details
FAppVerMajor: Integer;
Expand Down Expand Up @@ -1332,6 +1335,8 @@ TMainForm = class(TExtForm)
property Connections: TDBConnectionList read FConnections;
property Delimiter: String read FDelimiter write SetDelimiter;
property FocusedTables: TDBObjectList read FFocusedTables;
function GetAlternatingRowBackground(Node: PVirtualNode): TColor;
procedure PaintAlternatingRowBackground(TargetCanvas: TCanvas; Node: PVirtualNode; CellRect: TRect);
procedure PaintColorBar(Value, Max: Extended; TargetCanvas: TCanvas; CellRect: TRect);
procedure CallSQLHelpWithKeyword( keyword: String );
procedure AddOrRemoveFromQueryLoadHistory(Filename: String; AddIt: Boolean; CheckIfFileExists: Boolean);
Expand Down Expand Up @@ -8864,6 +8869,8 @@ procedure TMainForm.ListTablesBeforeCellPaint(Sender: TBaseVirtualTree; TargetCa
var
Obj: PDBObject;
begin
PaintAlternatingRowBackground(TargetCanvas, Node, CellRect);

// Only paint bar in rows + size column
if Column in [1, 2] then begin
Obj := Sender.GetNodeData(Node);
Expand All @@ -8875,6 +8882,36 @@ procedure TMainForm.ListTablesBeforeCellPaint(Sender: TBaseVirtualTree; TargetCa
end;


function TMainForm.GetAlternatingRowBackground(Node: PVirtualNode): TColor;
var
clEven, clOdd: TColor;
isEven: Boolean;
begin
// Alternating row background. See issue #139
Result := clNone;
clEven := AppSettings.ReadInt(asRowBackgroundEven);
clOdd := AppSettings.ReadInt(asRowBackgroundOdd);
isEven := Node.Index mod 2 = 0;
if IsEven and (clEven <> clNone) then
Result := clEven
else if (not IsEven) and (clOdd <> clNone) then
Result := clOdd;
end;


procedure TMainForm.PaintAlternatingRowBackground(TargetCanvas: TCanvas; Node: PVirtualNode; CellRect: TRect);
var
BgColor: TColor;
begin
// Apply color
BgColor := GetAlternatingRowBackground(Node);
if BgColor <> clNone then begin
TargetCanvas.Brush.Color := BgColor;
TargetCanvas.FillRect(CellRect);
end;
end;


procedure TMainForm.PaintColorBar(Value, Max: Extended; TargetCanvas: TCanvas; CellRect: TRect);
var
BarWidth, CellWidth: Integer;
Expand Down Expand Up @@ -8929,6 +8966,13 @@ procedure TMainForm.ListProcessesFocusChanged(Sender: TBaseVirtualTree;
end;


procedure TMainForm.ListStatusBeforeCellPaint(Sender: TBaseVirtualTree;
TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect);
begin
PaintAlternatingRowBackground(TargetCanvas, Node, CellRect);
end;

{***
Apply a filter to a Virtual Tree.
}
Expand Down Expand Up @@ -9120,6 +9164,7 @@ procedure TMainForm.ListVariablesBeforeCellPaint(Sender: TBaseVirtualTree;
SessionVal, GlobalVal: String;
vt: TVirtualStringTree;
begin
PaintAlternatingRowBackground(TargetCanvas, Node, CellRect);
// Highlight cell if session variable is different to global variable
vt := Sender as TVirtualStringTree;
if Column = 1 then begin
Expand Down Expand Up @@ -10937,9 +10982,9 @@ procedure TMainForm.AnyGridBeforeCellPaint(Sender: TBaseVirtualTree;
CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect);
var
r: TDBQuery;
cl, clNull, clEven, clOdd, clSameData: TColor;
cl, clNull, clSameData: TColor;
RowNumber: PInt64;
isEven, FocusedIsNull, CurrentIsNull: Boolean;
FocusedIsNull, CurrentIsNull: Boolean;
FieldText, FocusedFieldText: String;
VT: TVirtualStringTree;
ResultCol: Integer;
Expand Down Expand Up @@ -10968,15 +11013,7 @@ procedure TMainForm.AnyGridBeforeCellPaint(Sender: TBaseVirtualTree;
RowNumber := Sender.GetNodeData(Node);
r.RecNo := RowNumber^;

clEven := AppSettings.ReadInt(asRowBackgroundEven);
clOdd := AppSettings.ReadInt(asRowBackgroundOdd);
isEven := Node.Index mod 2 = 0;
if IsEven and (clEven <> clNone) then
cl := clEven
else if (not IsEven) and (clOdd <> clNone) then
cl := clOdd
else
cl := clNone;
cl := GetAlternatingRowBackground(Node);

if (vsSelected in Node.States) and (Node = Sender.FocusedNode) and (Column = Sender.FocusedColumn) then begin
// Focused cell
Expand Down Expand Up @@ -11184,6 +11221,7 @@ procedure TMainForm.ListDatabasesBeforeCellPaint(Sender: TBaseVirtualTree; Targe
Val, Max: Extended;
LoopNode: PVirtualNode;
begin
PaintAlternatingRowBackground(TargetCanvas, Node, CellRect);
// Display color bars
if Column in [1,2,4..9] then begin
vt := Sender as TVirtualStringTree;
Expand Down Expand Up @@ -11541,6 +11579,7 @@ procedure TMainForm.HostListBeforeCellPaint(Sender: TBaseVirtualTree; TargetCanv
var
vt: TVirtualStringTree;
begin
PaintAlternatingRowBackground(TargetCanvas, Node, CellRect);
vt := Sender as TVirtualStringTree;
if (Column = 5) and (vt = ListProcesses) then
PaintColorBar(MakeFloat(vt.Text[Node, Column]), FProcessListMaxTime, TargetCanvas, CellRect);
Expand Down
16 changes: 3 additions & 13 deletions source/table_editor.pas
Expand Up @@ -1093,19 +1093,9 @@ procedure TfrmTableEditor.listColumnsBeforeCellPaint(Sender: TBaseVirtualTree;
TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect);
var
clEven, clOdd, BgColor: TColor;
isEven: Boolean;
begin
BgColor := clNone;

// Alternating row background. See issue #139
clEven := AppSettings.ReadInt(asRowBackgroundEven);
clOdd := AppSettings.ReadInt(asRowBackgroundOdd);
isEven := Node.Index mod 2 = 0;
if IsEven and (clEven <> clNone) then
BgColor := clEven
else if (not IsEven) and (clOdd <> clNone) then
BgColor := clOdd;
BgColor: TColor;
begin
BgColor := MainForm.GetAlternatingRowBackground(Node);

// Darken cell background to signalize it doesn't allow length/set
// Exclude non editable checkbox columns - grey looks ugly there.
Expand Down

0 comments on commit c5f93d2

Please sign in to comment.