tvplanit: Fix centering of vertical dividing lines between contacts in print-out

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8522 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-10-07 21:06:11 +00:00
parent 469cf2e19e
commit f5514b9ad3

View File

@ -13,7 +13,6 @@ type
TVpContactGridPainter = class(TVpBasePainter) TVpContactGridPainter = class(TVpBasePainter)
private private
FContactGrid: TVpContactGrid; FContactGrid: TVpContactGrid;
// FScaledRowHeight: Integer;
FScaledTextMargin: Integer; FScaledTextMargin: Integer;
// local variables of the original TVpContactGrid method // local variables of the original TVpContactGrid method
@ -234,9 +233,9 @@ var
contactCount: Integer; contactCount: Integer;
baseTextHeight: Integer; baseTextHeight: Integer;
maxTextWidth: Integer; maxTextWidth: Integer;
px2: Integer; // Scaled 2, 3, 4 pixels anchorMargin: Integer;
px3: Integer; px2, px4: Integer; // Scaled 2, 4 pixels
px4: Integer; px3: Integer; // 3 pixels scaled for high-dpi
begin begin
// If the component is sufficiently small then no sense in painting it // If the component is sufficiently small then no sense in painting it
if (FContactGrid.Height < 20) then if (FContactGrid.Height < 20) then
@ -257,8 +256,13 @@ begin
TextXOffset := 0; TextXOffset := 0;
TextYOffset := 0; TextYOffset := 0;
px2 := Round(2 * Scale); px2 := Round(2 * Scale);
px3 := Round(3 * Scale);
px4 := Round(4 * Scale); px4 := Round(4 * Scale);
{$IF VP_LCL_SCALING > 0}
px3 := FContactGrid.Scale96ToFont(3);
{$ELSE}
px3 := ScaleY(3, DesigntimeDPI);
{$IFEND}
// Create a temporary bitmap for painting the items // Create a temporary bitmap for painting the items
TmpBmp := TBitmap.Create; TmpBmp := TBitmap.Create;
@ -280,8 +284,6 @@ begin
{$ENDIF} {$ENDIF}
baseTextHeight := TmpBmp.Canvas.TextHeight(VpProductName); baseTextHeight := TmpBmp.Canvas.TextHeight(VpProductName);
DebugLn('baseTextHeight: ' + IntToStr(baseTextHeight));
// Calculate max phone label width // Calculate max phone label width
PhoneLblWidth := TmpBmp.Canvas.TextWidth(RSEmail); PhoneLblWidth := TmpBmp.Canvas.TextWidth(RSEmail);
for I := 0 to 7 do begin for I := 0 to 7 do begin
@ -291,34 +293,23 @@ begin
PhoneLblWidth := w; PhoneLblWidth := w;
end; end;
Col := 1;
// Clear the bitmap /// wp: this is done in the loop also?
TmpBmp.Canvas.FillRect(Rect(0, 0, TmpBmp.Width, TmpBmp.Height));
// Set the anchor starting point // Set the anchor starting point
anchorMargin := px2 + FScaledTextMargin * 2;
case Angle of case Angle of
ra0: ra0, ra90:
Anchor := Point(2 + FScaledTextMargin * 2, px2 + FScaledTextMargin * 2); Anchor := Point(anchorMargin, anchorMargin);
ra90:
Anchor := Point(2 + FScaledTextMargin * 2, px2 + FScaledTextMargin * 2);
ra180: ra180:
Anchor := Point( Anchor := Point(WidthOf(RenderIn) - TmpBmp.Width - anchorMargin, TmpBmp.Height - anchorMargin);
RenderIn.Right - RenderIn.Left - TmpBmp.Width - px2 - FScaledTextMargin * 2,
TmpBmp.Height - px2 - FScaledTextMargin * 2
);
ra270: ra270:
Anchor := Point( Anchor := Point(anchorMargin, HeightOf(RenderIn) - TmpBmp.Height - anchorMargin);
px2 + FScaledTextMargin * 2,
RenderIn.Bottom - RenderIn.Top - TmpBmp.Height - px2 - FScaledTextMargin * 2
);
end; end;
RecsInCol := 0;
// Sort the records // Sort the records
FContactGrid.DataStore.Resource.Contacts.Sort; FContactGrid.DataStore.Resource.Contacts.Sort;
// Iterate over all contacts // Iterate over all contacts
Col := 1;
RecsInCol := 0;
for I := StartContact to pred(contactCount) do begin for I := StartContact to pred(contactCount) do begin
TmpCon := FContactGrid.DataStore.Resource.Contacts.GetContact(I); TmpCon := FContactGrid.DataStore.Resource.Contacts.GetContact(I);
if (TmpCon <> nil) then begin if (TmpCon <> nil) then begin
@ -554,28 +545,36 @@ begin
cgContactArray[I].Phone5Rect := MoveRect(Phone5Rect, Anchor); cgContactArray[I].Phone5Rect := MoveRect(Phone5Rect, Anchor);
end; end;
{ move the drawn record from the bitmap to the component canvas } // Move the drawn record from the bitmap to the component canvas.
case Angle of case Angle of
ra0 : R := Rect(Anchor.X + WholeRect.Left + RenderIn.Left, ra0 : R := Rect(Anchor.X + WholeRect.Left + RenderIn.Left,
Anchor.Y + WholeRect.Top + RenderIn.Top, Anchor.Y + WholeRect.Top + RenderIn.Top,
Anchor.X + TmpBmp.Width + RenderIn.Left, Anchor.X + TmpBmp.Width + RenderIn.Left,
Anchor.Y + WholeRect.Bottom + RenderIn.Top); Anchor.Y + WholeRect.Bottom + RenderIn.Top
);
ra90 : R := Rect(WholeRect.Left + RenderIn.Left - Anchor.X, ra90 : R := Rect(WholeRect.Left + RenderIn.Left - Anchor.X,
Anchor.Y + WholeRect.Top + RenderIn.Top, Anchor.Y + WholeRect.Top + RenderIn.Top,
WholeRect.Right + RenderIn.Left - Anchor.X, WholeRect.Right + RenderIn.Left - Anchor.X,
Anchor.Y + WholeRect.Bottom + RenderIn.Top); Anchor.Y + WholeRect.Bottom + RenderIn.Top
);
ra180 : R := Rect(Anchor.X + WholeRect.Left + RenderIn.Left, ra180 : R := Rect(Anchor.X + WholeRect.Left + RenderIn.Left,
Anchor.Y - (WholeRect.Bottom - WholeRect.Top) + RenderIn.Top, Anchor.Y - HeightOf(WholeRect) + RenderIn.Top,
Anchor.X + TmpBmp.Width + RenderIn.Left, Anchor.X + TmpBmp.Width + RenderIn.Left,
Anchor.Y + RenderIn.Top); Anchor.Y + RenderIn.Top
);
ra270 : R := Rect(Anchor.X + RenderIn.Left, ra270 : R := Rect(Anchor.X + RenderIn.Left,
Anchor.Y + RenderIn.Top, Anchor.Y + RenderIn.Top,
Anchor.X + RenderIn.Left + (WholeRect.Right - WholeRect.Left), Anchor.X + RenderIn.Left + WidthOf(WholeRect),
Anchor.Y + RenderIn.Top + (WholeRect.Bottom - WholeRect.Top)); Anchor.Y + RenderIn.Top + HeightOf(WholeRect)
);
end; end;
//debugln(['wholerect: ', wholerect.left, ' ', wholerect.top, ' ', wholerect.right, ' ', wholerect.bottom]);
//debugLn(['scaledtextmargin: ', fscaledtextmargin]);
RenderCanvas.CopyRect(R, TmpBmp.Canvas, WholeRect); RenderCanvas.CopyRect(R, TmpBmp.Canvas, WholeRect);
{ draw focusrect around selected record } // Draw focus rect around selected record
if FContactGrid.Focused and (TmpCon = FContactGrid.ActiveContact) then begin if FContactGrid.Focused and (TmpCon = FContactGrid.ActiveContact) then begin
with TVpContactGridOpener(FContactGrid).cgContactArray[I] do begin with TVpContactGridOpener(FContactGrid).cgContactArray[I] do begin
R := WholeRect; R := WholeRect;
@ -594,7 +593,7 @@ begin
end; end;
Inc(RecsInCol); Inc(RecsInCol);
end; // for I := StartCont to ... end;
if not DisplayOnly then if not DisplayOnly then
case Angle of case Angle of
@ -647,7 +646,7 @@ begin
FVisibleContacts := contactCount - StartContact; FVisibleContacts := contactCount - StartContact;
end; end;
end; end;
end; end; // for I := StartCont to ...
finally finally
TmpBmp.Free; TmpBmp.Free;
end; end;
@ -667,7 +666,6 @@ procedure TVpContactGridPainter.DrawVerticalBars;
var var
BarPos, BarCount, I: Integer; BarPos, BarCount, I: Integer;
scaledExtraBarWidth: Integer; scaledExtraBarWidth: Integer;
scaledPenWidth: Integer;
px2: Integer; // scaled 2 pixels px2: Integer; // scaled 2 pixels
begin begin
// If the component is sufficiently small then no sense in painting it. // If the component is sufficiently small then no sense in painting it.
@ -675,13 +673,15 @@ begin
exit; exit;
scaledExtraBarWidth := round(ExtraBarWidth * Scale); scaledExtraBarWidth := round(ExtraBarWidth * Scale);
scaledPenWidth := round(1 * Scale); //scaledPenWidth := round(1 * Scale);
px2 := round(2 * Scale); px2 := round(2 * Scale);
debugln([Realcolumnwidth]);
// Draw vertical bars. // Draw vertical bars.
RenderCanvas.Pen.Color := RealBarColor; RenderCanvas.Pen.Color := RealBarColor;
RenderCanvas.Pen.Style := psSolid; RenderCanvas.Pen.Style := psSolid;
RenderCanvas.Pen.Width := scaledPenWidth; RenderCanvas.Pen.Width := 1; //scaledPenWidth;
BarPos := RealLeft + px2 + RealColumnWidth + scaledExtraBarWidth; BarPos := RealLeft + px2 + RealColumnWidth + scaledExtraBarWidth;
BarCount := 0; BarCount := 0;
while (BarPos < RealRight) and (BarCount < Pred(MaxColumns)) do begin while (BarPos < RealRight) and (BarCount < Pred(MaxColumns)) do begin
@ -784,8 +784,6 @@ end;
procedure TVpContactGridPainter.RenderToCanvas(ARenderIn: TRect; procedure TVpContactGridPainter.RenderToCanvas(ARenderIn: TRect;
AAngle: TVpRotationAngle; AScale: Extended; ARenderDate: TDateTime; AAngle: TVpRotationAngle; AScale: Extended; ARenderDate: TDateTime;
AStartLine, AStopLine: Integer; AUseGran: TVpGranularity; ADisplayOnly: Boolean); AStartLine, AStopLine: Integer; AUseGran: TVpGranularity; ADisplayOnly: Boolean);
var
nc: Integer;
begin begin
inherited; inherited;
@ -805,12 +803,6 @@ begin
SetMeasurements; SetMeasurements;
nc := FContactGrid.PrintNumColumns;
if DisplayOnly and (nc > 0) then
RealColumnWidth := (RealWidth - (2 + ExtraBarWidth) * (nc - 1)) div nc
else
RealColumnWidth := FContactGrid.ColumnWidth;
{ clear the control } { clear the control }
Clear; Clear;
@ -836,10 +828,17 @@ begin
end; end;
procedure TVpContactGridPainter.SetMeasurements; procedure TVpContactGridPainter.SetMeasurements;
var
numCols: Integer;
begin begin
inherited; inherited;
// FScaledRowHeight := round(FContactGrid.RowHeight * Scale);
FScaledTextMargin := round(FContactGrid.TextMargin * Scale); FScaledTextMargin := round(FContactGrid.TextMargin * Scale);
numCols := FContactGrid.PrintNumColumns;
if DisplayOnly and (numCols > 0) then
RealColumnWidth := (RealWidth - round((2 + ExtraBarWidth) * Scale * (numCols - 1))) div numCols
else
RealColumnWidth := FContactGrid.ColumnWidth;
end; end;
end. end.