tvplanit: Fix layout issues in printing/preview of TVpMonthView (due to navigation buttons missing in print mode).

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8536 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-10-11 21:54:09 +00:00
parent d42c10d9af
commit d78a678e70

View File

@ -12,6 +12,8 @@ type
TVpMonthViewPainter = class(TVpBasePainter) TVpMonthViewPainter = class(TVpBasePainter)
private private
FMonthView: TVpMonthView; FMonthView: TVpMonthView;
FScaledMonthMargin: Integer;
FScaledDaysMargin: Integer;
// local parameters of the old TVpMonthView method // local parameters of the old TVpMonthView method
DisplayDate: TDateTime; DisplayDate: TDateTime;
@ -206,12 +208,12 @@ begin
// Calculate size of rect for the day number at the top of the TextRect. // Calculate size of rect for the day number at the top of the TextRect.
if ACol = 6 then if ACol = 6 then
tmpRect.Left := ATextRect.Left + mvColWidth - TextAdjust - FMonthView.DaysMargin tmpRect.Left := ATextRect.Left + mvColWidth - TextAdjust - FScaledDaysMargin
else else
tmpRect.Left := ATextRect.Right - TextAdjust - FMonthView.DaysMargin; tmpRect.Left := ATextRect.Right - TextAdjust - FScaledDaysMargin;
if fsItalic in RenderCanvas.Font.Style then if fsItalic in RenderCanvas.Font.Style then
dec(tmpRect.Left, 2); dec(tmpRect.Left, 2);
tmpRect.Top := ATextRect.Top + FMonthView.DaysMargin; tmpRect.Top := ATextRect.Top + FScaledDaysMargin;
tmpRect.Right := tmpRect.Left + textAdjust; tmpRect.Right := tmpRect.Left + textAdjust;
tmpRect.Bottom := tmpRect.Top + textHeight; tmpRect.Bottom := tmpRect.Top + textHeight;
@ -356,8 +358,8 @@ begin
{ Fix header string } { Fix header string }
strLen := RenderCanvas.TextWidth(str); strLen := RenderCanvas.TextWidth(str);
if (strLen > mvColWidth - FMonthView.DaysMargin * 2) then if (strLen > mvColWidth - FScaledDaysMargin * 2) then
str := GetDisplayString(RenderCanvas, str, 0, mvColWidth - FMonthView.DaysMargin * 2); str := GetDisplayString(RenderCanvas, str, 0, mvColWidth - FScaledDaysMargin * 2);
strLen := RenderCanvas.TextWidth(str); strLen := RenderCanvas.TextWidth(str);
{ Draw header text } { Draw header text }
@ -490,7 +492,7 @@ begin
RenderCanvas.Pen.Style := psSolid; RenderCanvas.Pen.Style := psSolid;
RenderCanvas.Brush.Color := RealColor; RenderCanvas.Brush.Color := RealColor;
txtMargin := FMonthView.DaysMargin; txtMargin := FScaledDaysMargin;
{ write the events } { write the events }
if (FMonthView.DataStore <> nil) and FMonthView.ShowEvents and if (FMonthView.DataStore <> nil) and FMonthView.ShowEvents and
@ -641,26 +643,35 @@ begin
// Position the spinner buttons // Position the spinner buttons
with TVpMonthViewOpener(FMonthView) do begin with TVpMonthViewOpener(FMonthView) do begin
FPrevYearBtn.Width := FPrevYearBtn.Height; FPrevYearBtn.Visible := not DisplayOnly;
FPrevYearBtn.Left := MonthMargin; FPrevMonthBtn.Visible := not DisplayOnly;
FPrevYearBtn.Top := (HeadRect.Top + HeadRect.Bottom - FPrevYearBtn.Height) div 2 + 1; FNextMonthBtn.Visible := not DisplayOnly;
FNextYearBtn.Visible := not DisplayOnly;
FPrevMonthBtn.Height := FPrevYearBtn.Height;
FPrevMonthBtn.Width := FPrevYearBtn.Height;
FPrevMonthBtn.Left := FPrevYearBtn.Left + FPrevYearBtn.Width;
FPrevMonthBtn.Top := FPrevYearBtn.Top;
FNextMonthBtn.Height := FPrevYearBtn.Height;
FNextMonthBtn.Width := FPrevYearBtn.Height;
FNextMonthBtn.Left := FPrevMonthBtn.Left + FPrevMonthBtn.Width;
FNextMonthBtn.Top := FPrevYearBtn.Top;
FNextYearBtn.Height := FPrevYearBtn.Height; if not DisplayOnly then
FNextYearBtn.Width := FPrevYearBtn.Height; begin
FNextYearBtn.Left := FNextMonthBtn.Left + FNextMonthBtn.Width; FPrevYearBtn.Width := FPrevYearBtn.Height;
FNextYearBtn.Top := FPrevYearBtn.Top; FPrevYearBtn.Left := FScaledMonthMargin;
FPrevYearBtn.Top := (HeadRect.Top + HeadRect.Bottom - FPrevYearBtn.Height) div 2 + 1;
txtStart := FNextYearBtn.Left + FNextYearBtn.Width + 2*MonthMargin;
FPrevMonthBtn.Height := FPrevYearBtn.Height;
FPrevMonthBtn.Width := FPrevYearBtn.Height;
FPrevMonthBtn.Left := FPrevYearBtn.Left + FPrevYearBtn.Width;
FPrevMonthBtn.Top := FPrevYearBtn.Top;
FNextMonthBtn.Height := FPrevYearBtn.Height;
FNextMonthBtn.Width := FPrevYearBtn.Height;
FNextMonthBtn.Left := FPrevMonthBtn.Left + FPrevMonthBtn.Width;
FNextMonthBtn.Top := FPrevYearBtn.Top;
FNextYearBtn.Height := FPrevYearBtn.Height;
FNextYearBtn.Width := FPrevYearBtn.Height;
FNextYearBtn.Left := FNextMonthBtn.Left + FNextMonthBtn.Width;
FNextYearBtn.Top := FPrevYearBtn.Top;
txtStart := FNextYearBtn.Left + FNextYearBtn.Width + 2*FScaledMonthMargin;
end else
txtStart := RealLeft + FScaledMonthMargin;
end; end;
{ Acquire startdate and end date } { Acquire startdate and end date }
@ -675,12 +686,12 @@ begin
RenderCanvas.Font.Size := ScaleY(RenderCanvas.Font.Size, DesignTimeDPI); RenderCanvas.Font.Size := ScaleY(RenderCanvas.Font.Size, DesignTimeDPI);
{$ENDIF} {$ENDIF}
if DisplayOnly and (RenderCanvas.TextWidth(HeadStr) >= RealWidth) then if DisplayOnly and (RenderCanvas.TextWidth(HeadStr) >= RealWidth) then
HeadTextRect.Left := RealLeft + FMonthView.MonthMargin * 2 HeadTextRect.Left := RealLeft + FScaledMonthMargin * 2
else else
if DisplayOnly then if DisplayOnly then
HeadTextRect.Left := RealLeft + (RealWidth - RenderCanvas.TextWidth(HeadStr)) div 2 HeadTextRect.Left := RealLeft + (RealWidth - RenderCanvas.TextWidth(HeadStr)) div 2
else else
HeadTextRect.Left := RealLeft + 30 + FMonthView.MonthMargin * 2; HeadTextRect.Left := RealLeft + 30 + FScaledMonthMargin * 2;
HeadTextRect.Top := (HeadRect.Top + HeadRect.Bottom - RenderCanvas.TextHeight('Tg')) div 2; HeadTextRect.Top := (HeadRect.Top + HeadRect.Bottom - RenderCanvas.TextHeight('Tg')) div 2;
HeadTextRect.BottomRight := HeadRect.BottomRight; HeadTextRect.BottomRight := HeadRect.BottomRight;
@ -692,7 +703,7 @@ begin
RenderCanvas, RenderCanvas,
HeadStr, HeadStr,
0, 0,
HeadTextRect.Right - HeadTextRect.Left - FMonthView.MonthMargin HeadTextRect.Right - HeadTextRect.Left - FScaledMonthMargin
); );
end; end;
@ -821,7 +832,7 @@ end;
procedure TVpMonthViewPainter.SetMeasurements; procedure TVpMonthViewPainter.SetMeasurements;
var var
h: Integer; h, scaledMargin: Integer;
txt: String = VpProductName; txt: String = VpProductName;
// We use the VpProductName since it is a good representation of some generic text // We use the VpProductName since it is a good representation of some generic text
begin begin
@ -831,18 +842,21 @@ begin
with TVpMonthViewOpener(FMonthView) do with TVpMonthViewOpener(FMonthView) do
begin begin
FScaledMonthMargin := round(Scale * MonthMargin);
FScaledDaysMargin := round(Scale * DaysMargin);
h := GetCanvasTextHeight(RenderCanvas, HeadAttributes.Font, txt); h := GetCanvasTextHeight(RenderCanvas, HeadAttributes.Font, txt);
mvMonthHeadHeight := Max(h, FPrevYearBtn.Height) + MonthMargin; mvMonthHeadHeight := Max(h, FPrevYearBtn.Height) + FScaledMonthMargin;
h := GetCanvasTextHeight(RenderCanvas, DayHeadAttributes.Font, txt); h := GetCanvasTextHeight(RenderCanvas, DayHeadAttributes.Font, txt);
mvDayHeadHeight := Max(h, FPrevYearBtn.Height) + DaysMargin; mvDayHeadHeight := Max(h, FPrevYearBtn.Height) + FScaledDaysMargin;
mvHeaderHeight := mvMonthHeadHeight + mvDayHeadHeight; mvHeaderHeight := mvMonthHeadHeight + mvDayHeadHeight;
mvDayNumberHeight := GetCanvasTextHeight(RenderCanvas, DayNumberFont, '00'); mvDayNumberHeight := GetCanvasTextHeight(RenderCanvas, DayNumberFont, '00');
mvEventTextHeight := GetCanvasTextHeight(RenderCanvas, EventFont, txt); mvEventTextHeight := GetCanvasTextHeight(RenderCanvas, EventFont, txt);
mvLineHeight := GetCanvasTextHeight(RenderCanvas, Font, txt) + 2; mvLineHeight := GetCanvasTextHeight(RenderCanvas, Font, txt) + 2;
mvColWidth := (RealWidth - 4) div 7; mvColWidth := (RealWidth - 2) div 7;
FMonthHeadHeight := mvMonthHeadHeight; FMonthHeadHeight := mvMonthHeadHeight;
FDayHeadHeight := mvDayHeadHeight; FDayHeadHeight := mvDayHeadHeight;