You've already forked lazarus-ccr
tvplanit: Refactor granularity-related code
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4782 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -404,7 +404,7 @@ type
|
|||||||
{$IFDEF DRAGDROP}
|
{$IFDEF DRAGDROP}
|
||||||
procedure DragDrop(Source: TObject; X, Y: Integer); override;
|
procedure DragDrop(Source: TObject; X, Y: Integer); override;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
function HourToLine(const Value: TVpHours; const UseGran: TVpGranularity): Integer;
|
// function HourToLine(const Value: TVpHours; const UseGran: TVpGranularity): Integer;
|
||||||
procedure Invalidate; override;
|
procedure Invalidate; override;
|
||||||
procedure LinkHandler(Sender: TComponent; NotificationType: TVpNotificationType;
|
procedure LinkHandler(Sender: TComponent; NotificationType: TVpNotificationType;
|
||||||
const Value: Variant); override;
|
const Value: Variant); override;
|
||||||
@ -1346,16 +1346,7 @@ begin
|
|||||||
Result := Result + TextMargin * 2;
|
Result := Result + TextMargin * 2;
|
||||||
|
|
||||||
Result := Round(Result * Scale);
|
Result := Round(Result * Scale);
|
||||||
|
dvClientVArea := Result * MinutesInDay div GranularityMinutes[UseGran];
|
||||||
case UseGran of
|
|
||||||
gr60Min : dvClientVArea := Result * 24;
|
|
||||||
gr30Min : dvClientVArea := Result * 48;
|
|
||||||
gr20Min : dvClientVArea := Result * 72;
|
|
||||||
gr15Min : dvClientVArea := Result * 96;
|
|
||||||
gr10Min : dvClientVArea := Result * 144;
|
|
||||||
gr06Min : dvClientVArea := Result * 240;
|
|
||||||
gr05Min : dvClientVArea := Result * 288;
|
|
||||||
end;
|
|
||||||
dvRowHeight := Result;
|
dvRowHeight := Result;
|
||||||
end;
|
end;
|
||||||
{=====}
|
{=====}
|
||||||
@ -1383,21 +1374,12 @@ begin
|
|||||||
Result := FNumDays;
|
Result := FNumDays;
|
||||||
end;
|
end;
|
||||||
{=====}
|
{=====}
|
||||||
|
(*
|
||||||
function TVpDayView.HourToLine(const Value: TVpHours;
|
function TVpDayView.HourToLine(const Value: TVpHours;
|
||||||
const UseGran: TVpGranularity): Integer;
|
const UseGran: TVpGranularity): Integer;
|
||||||
begin
|
begin
|
||||||
case UseGran of
|
Result := Ord(Value) * 60 div GranularityMinutes[UseGran];
|
||||||
gr60Min : Result := Ord (Value);
|
end; *)
|
||||||
gr30Min : Result := Ord (Value) * 2;
|
|
||||||
gr20Min : Result := Ord (Value) * 3;
|
|
||||||
gr15Min : Result := Ord (Value) * 4;
|
|
||||||
gr10Min : Result := Ord (Value) * 6;
|
|
||||||
gr06Min : Result := Ord (Value) * 10;
|
|
||||||
gr05Min : Result := Ord (Value) * 12;
|
|
||||||
else Result := Ord (Value) * 2; { Default to 30 minutes }
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TVpDayView.SetDrawingStyle(Value: TVpDrawingStyle);
|
procedure TVpDayView.SetDrawingStyle(Value: TVpDrawingStyle);
|
||||||
begin
|
begin
|
||||||
@ -1430,10 +1412,7 @@ procedure TVpDayView.SetTopLine(Value: Integer);
|
|||||||
begin
|
begin
|
||||||
if Value <> FTopLine then begin
|
if Value <> FTopLine then begin
|
||||||
if Value + VisibleLines >= pred(LineCount) then begin
|
if Value + VisibleLines >= pred(LineCount) then begin
|
||||||
if Granularity = gr60Min then
|
FTopLine := pred(LineCount) - VisibleLines + 2;
|
||||||
FTopLine := pred(LineCount) - VisibleLines + 2
|
|
||||||
else
|
|
||||||
FTopLine := pred(LineCount) - VisibleLines + 2;
|
|
||||||
{ prevent the control from hanging at the bottom }
|
{ prevent the control from hanging at the bottom }
|
||||||
if (Value < FTopLine) and (Value > 0) then
|
if (Value < FTopLine) and (Value > 0) then
|
||||||
FTopLine := Value;
|
FTopLine := Value;
|
||||||
@ -1507,7 +1486,7 @@ begin
|
|||||||
FGranularity := Value;
|
FGranularity := Value;
|
||||||
|
|
||||||
SetTimeIntervals (FGranularity);
|
SetTimeIntervals (FGranularity);
|
||||||
FTopLine := HourToLine (FTopHour, FGranularity);
|
FTopLine := HourToLine(FTopHour, FGranularity);
|
||||||
|
|
||||||
Invalidate;
|
Invalidate;
|
||||||
end;
|
end;
|
||||||
@ -2561,23 +2540,6 @@ var
|
|||||||
end;
|
end;
|
||||||
{=====}
|
{=====}
|
||||||
|
|
||||||
|
|
||||||
{ Returns the time duration of one row of the DayView }
|
|
||||||
function RowDuration: Double;
|
|
||||||
begin
|
|
||||||
case Granularity of
|
|
||||||
gr60Min : result := 24 / MinutesInDay;
|
|
||||||
gr30Min : result := 30 / MinutesInDay;
|
|
||||||
gr20Min : result := 20 / MinutesInDay;
|
|
||||||
gr15Min : result := 15 / MinutesInDay;
|
|
||||||
gr10Min : result := 10 / MinutesInDay;
|
|
||||||
gr06Min : result := 6 / MinutesInDay;
|
|
||||||
gr05Min : result := 5 / MinutesInDay;
|
|
||||||
else
|
|
||||||
result := 0.0;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ Draws the all-day events at the top of the DayView in a special manner }
|
{ Draws the all-day events at the top of the DayView in a special manner }
|
||||||
procedure DrawAllDayEvents;
|
procedure DrawAllDayEvents;
|
||||||
var
|
var
|
||||||
|
@ -113,23 +113,19 @@ function IncYear (TheDate : TDateTime; NumYears : Integer) : TDateTime;
|
|||||||
|
|
||||||
function GetJulianDate(Date: TDateTime): Word;
|
function GetJulianDate(Date: TDateTime): Word;
|
||||||
|
|
||||||
function HourToLine (const Value : TVpHours;
|
function HourToLine(const Value: TVpHours; const Granularity: TVpGranularity): Integer;
|
||||||
const Granularity : TVpGranularity) : Integer;
|
|
||||||
|
|
||||||
function GetStartLine (StartTime: TDateTime;
|
function GetStartLine(StartTime: TDateTime; Granularity: TVpGranularity): Integer;
|
||||||
Granularity: TVpGranularity): Integer;
|
|
||||||
|
|
||||||
function GetEndLine (EndTime: TDateTime;
|
function GetEndLine (EndTime: TDateTime; Granularity: TVpGranularity): Integer;
|
||||||
Granularity: TVpGranularity): Integer;
|
|
||||||
|
|
||||||
function TimeInRange(Time, StartTime, EndTime: TDateTime;
|
function TimeInRange(Time, StartTime, EndTime: TDateTime; Inclusive: Boolean): Boolean;
|
||||||
Inclusive: Boolean): Boolean;
|
|
||||||
|
|
||||||
function LineToStartTime(Line: Integer; Granularity: TVpGranularity): TDateTime;
|
function LineToStartTime(Line: Integer; Granularity: TVpGranularity): TDateTime;
|
||||||
|
|
||||||
function GetLineDuration(Granularity: TVpGranularity): Double;
|
function GetLineDuration(Granularity: TVpGranularity): Double;
|
||||||
|
|
||||||
function GetLabelWidth(ALabel : TLabel) : Integer;
|
function GetLabelWidth(ALabel: TLabel): Integer;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
@ -455,9 +451,10 @@ begin
|
|||||||
end;
|
end;
|
||||||
{=====}
|
{=====}
|
||||||
|
|
||||||
function HourToLine (const Value : TVpHours;
|
function HourToLine(const Value: TVpHours; const Granularity: TVpGranularity): Integer;
|
||||||
const Granularity : TVpGranularity) : Integer;
|
|
||||||
begin
|
begin
|
||||||
|
Result := Ord(Value) * 60 div GranularityMinutes[Granularity];
|
||||||
|
(*
|
||||||
case Granularity of
|
case Granularity of
|
||||||
gr60Min : Result := Ord (Value);
|
gr60Min : Result := Ord (Value);
|
||||||
gr30Min : Result := Ord (Value) * 2;
|
gr30Min : Result := Ord (Value) * 2;
|
||||||
@ -469,18 +466,20 @@ begin
|
|||||||
else
|
else
|
||||||
Result := Ord (Value) * 2; { Default to 30 minutes }
|
Result := Ord (Value) * 2; { Default to 30 minutes }
|
||||||
end;
|
end;
|
||||||
|
*)
|
||||||
end;
|
end;
|
||||||
{=====}
|
{=====}
|
||||||
|
|
||||||
function GetStartLine (StartTime: TDateTime;
|
function GetStartLine(StartTime: TDateTime; Granularity: TVpGranularity): Integer;
|
||||||
Granularity: TVpGranularity): Integer;
|
|
||||||
var
|
var
|
||||||
LineDuration : Double; { the percentage of a day covered by each line }
|
LineDuration: Double; { the percentage of a day covered by each line }
|
||||||
Time : Double;
|
Time: Double;
|
||||||
begin
|
begin
|
||||||
{ remove the date part, and add one minute to the time }
|
{ remove the date part, and add one minute to the time }
|
||||||
Time := StartTime - trunc(StartTime) + (1 / MinutesInDay);
|
// Time := StartTime - trunc(StartTime) + (1 / MinutesInDay);
|
||||||
|
Time := frac(StartTime) + 1 / MinutesInDay;
|
||||||
|
LineDuration := GranularityMinutes[Granularity] / MinutesInDay;
|
||||||
|
(*
|
||||||
case Granularity of
|
case Granularity of
|
||||||
gr60Min : LineDuration := 60 / MinutesInDay;
|
gr60Min : LineDuration := 60 / MinutesInDay;
|
||||||
gr30Min : LineDuration := 30 / MinutesInDay;
|
gr30Min : LineDuration := 30 / MinutesInDay;
|
||||||
@ -492,19 +491,22 @@ begin
|
|||||||
else
|
else
|
||||||
LineDuration := 30 / MinutesInDay;
|
LineDuration := 30 / MinutesInDay;
|
||||||
end;
|
end;
|
||||||
|
*)
|
||||||
|
|
||||||
result := trunc(Time / LineDuration);
|
result := trunc(Time / LineDuration);
|
||||||
end;
|
end;
|
||||||
{=====}
|
{=====}
|
||||||
|
|
||||||
function GetEndLine (EndTime: TDateTime;
|
function GetEndLine(EndTime: TDateTime; Granularity: TVpGranularity): Integer;
|
||||||
Granularity: TVpGranularity): Integer;
|
|
||||||
var
|
var
|
||||||
LineDuration : Double; { the percentage of a day covered by each line }
|
LineDuration: Double; { the percentage of a day covered by each line }
|
||||||
Time : Double;
|
Time: Double;
|
||||||
begin
|
begin
|
||||||
{ remove the date part, and subtract one minute from the time }
|
{ remove the date part, and subtract one minute from the time }
|
||||||
Time := EndTime - trunc(EndTime) - (1 / MinutesInDay);
|
Time := frac(EndTime) - 1 / MinutesInDay;
|
||||||
|
// Time := EndTime - trunc(EndTime) - (1 / MinutesInDay);
|
||||||
|
LineDuration := GranularityMinutes[Granularity] / MinutesInDay;
|
||||||
|
{
|
||||||
|
|
||||||
case Granularity of
|
case Granularity of
|
||||||
gr60Min : LineDuration := 60 / MinutesInDay;
|
gr60Min : LineDuration := 60 / MinutesInDay;
|
||||||
@ -517,7 +519,7 @@ begin
|
|||||||
else
|
else
|
||||||
LineDuration := 30 / MinutesInDay;
|
LineDuration := 30 / MinutesInDay;
|
||||||
end;
|
end;
|
||||||
|
}
|
||||||
result := trunc(Time / LineDuration);
|
result := trunc(Time / LineDuration);
|
||||||
end;
|
end;
|
||||||
{=====}
|
{=====}
|
||||||
@ -528,7 +530,7 @@ begin
|
|||||||
result := 0.0;
|
result := 0.0;
|
||||||
case AdvanceType of
|
case AdvanceType of
|
||||||
atMinutes : result := Advance / MinutesInDay;
|
atMinutes : result := Advance / MinutesInDay;
|
||||||
atHours : result := (Advance * 60) / MinutesInDay;
|
atHours : result := Advance * 60 / MinutesInDay;
|
||||||
atDays : result := Advance;
|
atDays : result := Advance;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -553,8 +555,10 @@ end;
|
|||||||
|
|
||||||
function LineToStartTime(Line: Integer; Granularity: TVpGranularity): TDateTime;
|
function LineToStartTime(Line: Integer; Granularity: TVpGranularity): TDateTime;
|
||||||
begin
|
begin
|
||||||
|
Result := frac(Line * GranularityMinutes[Granularity] / MinutesInDay);
|
||||||
|
(*
|
||||||
case Granularity of
|
case Granularity of
|
||||||
gr60Min : result := (Line * 24) / MinutesInDay;
|
gr60Min : result := (Line * 24) / MinutesInDay; // shouldn't this be 60?
|
||||||
gr30Min : result := (Line * 30) / MinutesInDay;
|
gr30Min : result := (Line * 30) / MinutesInDay;
|
||||||
gr20Min : result := (Line * 20) / MinutesInDay;
|
gr20Min : result := (Line * 20) / MinutesInDay;
|
||||||
gr15Min : result := (Line * 15) / MinutesInDay;
|
gr15Min : result := (Line * 15) / MinutesInDay;
|
||||||
@ -566,13 +570,16 @@ begin
|
|||||||
end;
|
end;
|
||||||
{chop off the date portion}
|
{chop off the date portion}
|
||||||
result := result - trunc(Result);
|
result := result - trunc(Result);
|
||||||
|
*)
|
||||||
end;
|
end;
|
||||||
{=====}
|
{=====}
|
||||||
|
|
||||||
function GetLineDuration(Granularity: TVpGranularity): Double;
|
function GetLineDuration(Granularity: TVpGranularity): Double;
|
||||||
begin
|
begin
|
||||||
|
Result := GranularityMinutes[Granularity] / MinutesInDay;
|
||||||
|
(*
|
||||||
case Granularity of
|
case Granularity of
|
||||||
gr60Min : result := 24 / MinutesInDay;
|
gr60Min : result := 24 / MinutesInDay; // shouldn't this be 60?
|
||||||
gr30Min : result := 30 / MinutesInDay;
|
gr30Min : result := 30 / MinutesInDay;
|
||||||
gr20Min : result := 20 / MinutesInDay;
|
gr20Min : result := 20 / MinutesInDay;
|
||||||
gr15Min : result := 15 / MinutesInDay;
|
gr15Min : result := 15 / MinutesInDay;
|
||||||
@ -584,10 +591,11 @@ begin
|
|||||||
end;
|
end;
|
||||||
{ chop off the date portion }
|
{ chop off the date portion }
|
||||||
result := result - trunc(result);
|
result := result - trunc(result);
|
||||||
|
*)
|
||||||
end;
|
end;
|
||||||
{=====}
|
{=====}
|
||||||
|
|
||||||
function GetLabelWidth(ALabel : TLabel) : Integer;
|
function GetLabelWidth(ALabel: TLabel): Integer;
|
||||||
var
|
var
|
||||||
canvas: TControlCanvas;
|
canvas: TControlCanvas;
|
||||||
begin
|
begin
|
||||||
|
@ -1344,11 +1344,17 @@ end;
|
|||||||
{=====}
|
{=====}
|
||||||
|
|
||||||
procedure TVpPrinter.AddDefaultVariables (Date : TDateTime);
|
procedure TVpPrinter.AddDefaultVariables (Date : TDateTime);
|
||||||
|
|
||||||
function HourToStr (Hour : TVpHours; Mil : Boolean) : string;
|
function HourToStr (Hour : TVpHours; Mil : Boolean) : string;
|
||||||
begin
|
begin
|
||||||
if Mil then
|
if Mil then
|
||||||
Result := IntToStr(ord(Hour))
|
Result := IntToStr(ord(Hour))
|
||||||
else
|
else
|
||||||
|
if ord(Hour) mod 12 = 0 then
|
||||||
|
Result := '12'
|
||||||
|
else
|
||||||
|
Result := IntToStr(ord(Hour) mod 12);
|
||||||
|
{
|
||||||
case Hour of
|
case Hour of
|
||||||
h_00 : Result := '12';
|
h_00 : Result := '12';
|
||||||
h_01 : Result := '1';
|
h_01 : Result := '1';
|
||||||
@ -1375,23 +1381,15 @@ procedure TVpPrinter.AddDefaultVariables (Date : TDateTime);
|
|||||||
h_22 : Result := '10';
|
h_22 : Result := '10';
|
||||||
h_23 : Result := '11';
|
h_23 : Result := '11';
|
||||||
end;
|
end;
|
||||||
|
}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function GranularityToStr (Gran : TVpGranularity) : string;
|
function GranularityToStr(Gran: TVpGranularity): string;
|
||||||
begin
|
begin
|
||||||
Result := '';
|
Result := IntToStr(GranularityMinutes[Gran]);
|
||||||
case Gran of
|
|
||||||
gr60Min : Result := '60';
|
|
||||||
gr30Min : Result := '30';
|
|
||||||
gr20Min : Result := '20';
|
|
||||||
gr15Min : Result := '15';
|
|
||||||
gr10Min : Result := '10';
|
|
||||||
gr06Min : Result := '6';
|
|
||||||
gr05Min : Result := '5';
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function HourToAMPM (Hour : TVpHours) : string;
|
function HourToAMPM(Hour: TVpHours): string;
|
||||||
begin
|
begin
|
||||||
if (Hour >= H_00) and (Hour <= h_11) then
|
if (Hour >= H_00) and (Hour <= h_11) then
|
||||||
Result := 'AM'
|
Result := 'AM'
|
||||||
|
Reference in New Issue
Block a user