1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
| procedure TForm1.Grid1DrawColumnHeader(Sender: TObject; const Canvas: TCanvas;
const Column: TColumn; const Bounds: TRectF);
var
Header: THeader;
HeaderItem: THeaderItem;
function typetri(tritype : smallint) : string; // todo ajouter valeur par défaut 0 pour tritype et couleurs (traits, cercle)
// tritype contient le sens si >0 DESC si<0 ASC et l'ordre de tri
const svgsort = '''
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 511.993 511.993" xml:space="preserve" fill="#000000">
<g color="#00A1A7">
<rect x="0.000" y="$T1" fill="currentColor" width="100.000" height="73.038"></rect>
<rect x="0.000" y="$T2" fill="currentColor" width="150.000" height="73.038"></rect>
<rect x="0.000" y="$T3" fill="currentColor" width="250.000" height="73.038"></rect>
<rect x="0.000" y="$T4" fill="currentColor" width="300.000" height="73.038"></rect>
</g>
<circle cx="400" cy="$CPOS" r="100" style="stroke:none; fill:$CFIL" />
<text x="370" y="$TPOS" style="font-family: Times New Roman;
font-size : 150;
fill : white;">$TRI</text>
<g>
</g>
</svg>
''';
begin
result:=svgsort;
if tritype=0 then
begin
result:=StringReplace(result,'$T1','146.444',[]);
result:=StringReplace(result,'$T2','0.362',[]);
result:=StringReplace(result,'$T3','438.594',[]);
result:=StringReplace(result,'$T4','292.519',[]);
result:=StringReplace(result,'g color="#00A1A7"','g color="silver"',[rfreplaceall]);
result:=StringReplace(result,'$CFIL','none',[]);
result:=StringReplace(result,'$TRI','',[]);
end
else begin
if tritype>0 then begin
// type de tri Descendant
result:=StringReplace(result,'$T1','0.362',[]);
result:=StringReplace(result,'$T2','146.444',[]);
result:=StringReplace(result,'$T3','292.519',[]);
result:=StringReplace(result,'$T4','438.594',[]);
result:=StringReplace(result,'$CFIL','red',[]);
result:=StringReplace(result,'$CPOS','100',[]);
result:=StringReplace(result,'$TPOS','150',[]);
result:=StringReplace(result,'$TRI',tritype.ToString,[]);
end
else begin
// type de tri Ascendant
result:=StringReplace(result,'$T1','438.594',[]);
result:=StringReplace(result,'$T2','292.519',[]);
result:=StringReplace(result,'$T3','146.444',[]);
result:=StringReplace(result,'$T4','0.362',[]);
result:=StringReplace(result,'$CFIL','red',[]);
result:=StringReplace(result,'$CPOS','400',[]);
result:=StringReplace(result,'$TRI',Abs(tritype).ToString,[]);
result:=StringReplace(result,'$TPOS','450',[]);
end;
end;
end;
begin
// svgfinal:=svgsort;
// svgfinal:=StringReplace(svgfinal,'fill:#00A1A7;','fill:green;',[rfreplaceall]);
Header:= THeader(Grid1.FindStyleResource('header'));
if assigned(Header) then HeaderItem:= Header.Items[column.index] else exit;
case Column.Index of
0 : begin
if HeaderItem.ComponentCount>1 then HeaderItem.Components[1].Destroy;
with TSKSvg.Create(HeaderItem) do
begin
Margins.Right:=2;
Margins.Top:=1;
Margins.Bottom:=1;
Height:=Header.Height-2;
Width:=Height;
Align:=TalignLayout.Right;
Parent:=HeaderItem;
HeaderItem.TextSettings.HorzAlign := TTextAlign.Leading;
SVG.Source:=typetri(1);
Width:=Header.Height;
// OnClick:=ClickSort;
end;
end;
1 : begin
if HeaderItem.ComponentCount>1 then HeaderItem.Components[1].Destroy;
with TSKSvg.Create(HeaderItem) do
begin
Margins.Right:=2;
Margins.Top:=1;
Margins.Bottom:=1;
Height:=Header.Height-2;
Width:=Height;
Align:=TalignLayout.Right;
Parent:=HeaderItem;
HeaderItem.TextSettings.HorzAlign := TTextAlign.Leading;
SVG.Source:=typetri(-2);
Width:=Header.Height;
// OnClick:=ClickSort;
end;
end;
2 : begin
if HeaderItem.ComponentCount>1 then HeaderItem.Components[1].Destroy;
with TSKSvg.Create(HeaderItem) do
begin
Margins.Right:=2;
Margins.Top:=1;
Margins.Bottom:=1;
Height:=Header.Height-2;
Width:=Height;
Align:=TalignLayout.Right;
Parent:=HeaderItem;
HeaderItem.TextSettings.HorzAlign := TTextAlign.Leading;
SVG.Source:=typetri(0);
Width:=Header.Height;
// OnClick:=ClickSort;
end;
end;
end; |
Partager