From d62d307e4da0c5cc4ae77d9d43ffc8f3fd28aed6 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Tue, 14 Dec 2021 09:50:31 +0000 Subject: [PATCH] TVPlanIt: Fix display of overlapping "same" events in DayView. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8177 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/tvplanit/source/vpconst.pas | 1 - .../tvplanit/source/vpdayviewpainter.pas | 24 +++++++++++-------- components/tvplanit/source/vpmisc.pas | 12 ++++++++++ 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/components/tvplanit/source/vpconst.pas b/components/tvplanit/source/vpconst.pas index ac30630db..e395e1c25 100644 --- a/components/tvplanit/source/vpconst.pas +++ b/components/tvplanit/source/vpconst.pas @@ -82,7 +82,6 @@ const ExtraBarWidth = 2; { The extra, draggable area on either side } { of the Contact Grid's horizontal bars. } CompareTimeEPS = 0.1 * OneSecond; { Epsilon for time comparison, 0.1 sec } -// CompareTimeEPS = 1.0 / (24*60*60*10); { Epsilon for time comparison, 0.1 sec } cmPerInch = 2.54; { 1 inch is 2.54 cm } diff --git a/components/tvplanit/source/vpdayviewpainter.pas b/components/tvplanit/source/vpdayviewpainter.pas index a25bbb9a6..2117ecfd1 100644 --- a/components/tvplanit/source/vpdayviewpainter.pas +++ b/components/tvplanit/source/vpdayviewpainter.pas @@ -187,10 +187,7 @@ begin { start time AND its end time is after or equal to the Event's } { end time, then the events overlap and we will need to increment } { the value of K. } - ( - (SameTime(tmpStart, EventStart) or (tmpStart < EventStart)) and - (SameTime(tmpEnd, EventEnd) or (tmpEnd > EventEnd)) - ) + (SameTimeOrEarlier(tmpStart, EventStart) and SameTimeOrLater(tmpEnd, EventEnd)) then begin { Count this event at this level } Inc(Levels[EArray[K].Level]); @@ -260,21 +257,28 @@ end; function TVpDayViewPainter.GetMaxOLEvents(Event: TVpEvent; const EArray: TVpDvEventArray): Integer; var K: Integer; - Tmp: TVpEvent; + tmp: TVpEvent; + tmpStart, tmpEnd: TTime; + eventStart, eventEnd: TTime; begin result := 1; K := 0; - Tmp := TVpEvent(EArray[K].Event); - while Tmp <> nil do begin + eventStart := frac(Event.StartTime); + eventEnd := frac(Event.EndTime); + tmp := TVpEvent(EArray[K].Event); + while tmp <> nil do begin + tmpStart := frac(tmp.StartTime); + tmpEnd := frac(tmp.EndTime); { if the Tmp event's StartTime or EndTime falls within the range of Event. } - if TimeInRange(frac(Tmp.StartTime), frac(Event.StartTime), frac(Event.EndTime), false) or - TimeInRange(frac(Tmp.EndTime), frac(Event.StartTime), frac(Event.EndTime), false) or + if TimeInRange(tmpStart, EventStart, EventEnd, false) or + TimeInRange(tmpEnd, EventStart, EventEnd, false) or { or the Tmp event's StartTime is before or equal to the Event's } { start time AND its end time is after or equal to the Event's } { end time, then the events overlap and we will need to check the } { value of OLLevels. If it is bigger than result, then modify } { Result accordingly. } - ((frac(Tmp.StartTime) <= frac(Event.StartTime)) and (frac(Tmp.EndTime) >= frac(Event.EndTime))) + (SameTimeOrEarlier(tmpStart, EventStart) and SameTimeOrLater(tmpEnd, EventEnd)) +// ((frac(Tmp.StartTime) <= frac(Event.StartTime)) and (frac(Tmp.EndTime) >= frac(Event.EndTime))) then begin if EArray[K].OLLevels > result then Result := EArray[K].OLLevels; diff --git a/components/tvplanit/source/vpmisc.pas b/components/tvplanit/source/vpmisc.pas index a1c971eb2..23f90f40c 100644 --- a/components/tvplanit/source/vpmisc.pas +++ b/components/tvplanit/source/vpmisc.pas @@ -147,6 +147,8 @@ function GetWeekOfYear(ADate: TDateTime): byte; function IsWeekEnd(ADate: TDateTime): Boolean; function SameDate(dt1, dt2: TDateTime): Boolean; function SameTime(t1, t2: TTime): Boolean; +function SameTimeOrEarlier(t1, t2: TTime): Boolean; +function SameTimeOrLater(t1, t2: TTime): Boolean; function DateInRange(ADate, StartDate, EndDate: TDateTime; IncludeLimits: Boolean): Boolean; function TimeInRange(ATime, StartTime, EndTime: TDateTime; IncludeLimits: Boolean): Boolean; @@ -806,6 +808,16 @@ begin Result := SameValue(t1, t2, CompareTimeEps); end; +function SameTimeOrEarlier(t1, t2: TTime): Boolean; +begin + Result := SameTime(t1, t2) or (t1 < t2); +end; + +function SameTimeOrLater(t1, t2: TTime): Boolean; +begin + Result := SameTime(t1, t2) or (t1 > t2); +end; + // Calculates ISO week number (checked with Jan 1, 2016, which is in week 53). function GetWeekOfYear(ADate: TDateTime): byte; // wp: was in TvWeekView.