tvplanit: Fix painting of GanttView events in hour mode.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8940 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2023-10-09 15:47:05 +00:00
parent 966da9ab85
commit 897e036a0c
2 changed files with 61 additions and 9 deletions

View File

@@ -483,6 +483,8 @@ begin
end;
function TVpGanttEventList.AddSingleEvent(AEvent: TVpEvent): PVpGanttEventRec;
const
EPS = 1e-9;
var
eventRec: PVpGanttEventRec;
dt1, dt2: TDateTime;
@@ -491,7 +493,7 @@ begin
if AEvent.AllDayEvent then
begin
dt1 := DatePart(AEvent.StartTime);
dt2 := DatePart(AEvent.EndTime) + 1;
dt2 := DatePart(AEvent.EndTime) + 1 - EPS;
end else
begin
dt1 := AEvent.StartTime;
@@ -786,10 +788,21 @@ begin
end;
procedure TVpGanttColHeaderAttributes.SetVisible(AValue: TVpGanttColHeaderKinds);
var
HourModeChanged: Boolean;
d: TDateTime;
begin
if FVisible <> AValue then
begin
HourModeChanged := (gchHour in FVisible) <> (gchHour in AValue);
FVisible := AValue;
if HourModeChanged then
begin
d := FGanttView.ActiveDate;
FGanttView.Init;
FGanttView.FActiveDate := 0; // Enforce execution of SetActiveDate
FGanttView.SetActiveDate(d);
end;
UpdateGanttView;
end;
end;
@@ -806,7 +819,7 @@ end;
{******************************************************************************}
{ TVpGanttView }
{ TVpGanttView }
{******************************************************************************}
constructor TVpGanttView.Create(AOwner: TComponent);
begin
@@ -1781,7 +1794,9 @@ var
i: Integer;
xh1, xh2, y1, xe1, xe2, y2: Integer;
t1, t2: TDateTime;
totalWidth: Integer;
startHr, endHr: TDateTime;
dayWidth, totalWidth: Integer;
dayFactor, hourFactor: Double;
begin
if (Datastore = nil) or (DataStore.Resource = nil) then
exit;
@@ -1817,6 +1832,11 @@ begin
xh2 := FixedColWidth;
y1 := FTotalColHeaderHeight;
totalWidth := CalcDaysWidth(GetNumDays);
dayWidth := CalcDaysWidth(1);
startHr := ord(FStartHour) / 24;
endHr := (ord(FEndHour) + 1) / 24; // extend to the end of the endhour box
dayFactor := totalWidth / GetNumDays;
hourFactor := dayWidth / HoursPerDay * 24;
for i := 0 to FEventRecords.Count-1 do
begin
eventRec := FEventRecords[i];
@@ -1825,8 +1845,25 @@ begin
// Store event rectangle coordinates in the EventRec
y2 := y1 + FRowHeight;
xe1 := round((t1 - FRealStartDate) / numDays * totalWidth) + FixedColWidth;
xe2 := round((t2 - FRealStartDate) / numDays * totalWidth) + FixedColWidth;
if HourMode then
begin
// Visible beginning of day at which the event starts
xe1 := round((DatePart(t1) - FRealStartDate) * dayFactor) + FixedColWidth;
// Add time part if event starts after FStartHour
if TimePart(t1) >= startHr then
xe1 := xe1 + round((TimePart(t1) - startHr) * hourFactor);
// Visible beginning of day at which the event ends
xe2 := round((DatePart(t2) - FRealStartDate) * dayFactor) + FixedColWidth;
// Add time part of event end, clipped at end of EndHour.
if TimePart(t2) <= endHr then
xe2 := xe2 + round((TimePart(t2) - startHr) * hourFactor)
else
xe2 := xe2 + round((endHr - startHr) * hourFactor);
end else
begin
xe1 := round((t1 - FRealStartDate) / numDays * totalWidth) + FixedColWidth;
xe2 := round((t2 - FRealStartDate) / numDays * totalWidth) + FixedColWidth;
end;
if xe1 = xe2 then xe2 := xe1 + 1;
eventRec^.HeadRect := Rect(xh1, y1, xh2, y2);