Difference between revisions of "CalLite: Usage/ru"

From Free Pascal wiki
Jump to navigationJump to search
Line 23: Line 23:
 
* '''WeekendColor''': цвет текста, используемый для отрисовки выходных дней (по умолчанию: clRed <span style="background: #FF0000"> &nbsp; &nbsp;&nbsp;  </span>)
 
* '''WeekendColor''': цвет текста, используемый для отрисовки выходных дней (по умолчанию: clRed <span style="background: #FF0000"> &nbsp; &nbsp;&nbsp;  </span>)
  
==Использование свойства Options календаря==
+
==Использование свойства TCalOption календаря==
Отображение календаря можно изменить, изменив свойство Options календаря, представленного как перечисление флагов:
+
Отображение календаря можно изменить, модифицируя свойство <tt>TCalOption</tt> календаря, представленного как перечисление флагов:
 
<syntaxhighlight lang="pascal">
 
<syntaxhighlight lang="pascal">
 
type
 
type

Revision as of 00:10, 2 June 2020

English (en) suomi (fi) русский (ru)

Использование

CalLite

Просто поместите компонент TCalendarLite на форму и получите функциональный календарь на месяц.

Изменения цвета

Свойство Colors календаря содержит все настройки, влияющие на цвета, используемые для различных элементов:

  • ArrowBorderColor: цвет границы стрелки над календарем (по умолчанию: clSilver      )
  • ArrowColor: цвет заливки стрелок над календарем (по умолчанию: clSilver      )
  • BackgroundColor: цвет фона всего календаря (по умолчанию: clWhite      )
  • BorderColor: цвет необязательной границы вокруг календаря (по умолчанию: clSilver      ). Добавьте coShowBorder в Options календаря, чтобы отобразить границу.
  • DayLineColor: цвет необязательной разделительной линии между верхней панелью навигации и областью дня календаря (по умолчанию: clSilver      ). Добавьте coDayLine в Options календаря, чтобы отобразить строку.
  • HolidayColor: цвет текста, используемый для отображения праздников (по умолчанию: clRed      ). Добавьте обработчик событий в OnGetHolidays, чтобы задать, какие дни являются выходными.
  • PastMonthColor: цвет текста, используемый для отображения дней предыдущего или следующего месяца (по умолчанию: clSilver      )
  • SelectedDateColor: цвет заливки текущего выбранного дня (по умолчанию: clMoneyGreen      )
  • TextColor: цвет текста, используемый для отрисовки обычных календарных дней (по умолчанию: clBlack      )
  • TodayFrameColor: цвет, используемый для отрисовки прямоугольной линии вокруг ячейки "сегодня" (по умолчанию: clLime      )
  • TopRowColor: цвет фона, используемый для верхней строке навигации (по умолчанию: clHighlight)
  • TopRowTextColor: цвет текста, используемый в верхней строке навигации (по умолчанию: clHighlightText)
  • WeekendColor: цвет текста, используемый для отрисовки выходных дней (по умолчанию: clRed      )

Использование свойства TCalOption календаря

Отображение календаря можно изменить, модифицируя свойство TCalOption календаря, представленного как перечисление флагов:

type
  TCalOption = (coBoldDayNames, coBoldHolidays, coBoldToday, coBoldTopRow,
                coBoldWeekend, coDayLine, coShowBorder, coShowHolidays,
                coShowTodayFrame, coShowTodayName, coShowTodayRow,
                coShowWeekend, coUseTopRowColors);
  • coBoldDayNames: Рисует строку с названиями дней, используя символы с жирным начертанием.
  • coBoldHolidays: Рисует число дней праздников, используя символы с жирным начертанием. Обычно праздничные дни отключены, но вы добавляете обработчик событий в OnGetHolidays для определения выходных.
  • coBoldToday: Рисует сегодняшнюю ячейку, используя символы с жирным начертанием.
  • coBoldTopRow: Рисует название месяца и номер года в верхнем ряду, используя символы с жирным начертанием.
  • coBoldWeekend: Рисует ячейки выходных дней, используя символы с жирным начертанием.
  • coDayLine: Добавляет разделительную линию между верхней навигационной линией и областью дней календаря.
  • coShowBorder: Рисует тонкий прямоугольник вокруг календаря.
  • coShowHolidays: Активирует подсветку праздников. Обратите внимание, что для OnGetHolidays также должен быть задан обработчик событий, который определяет праздники.
  • coShowTodayFrame: Рисует прямоугольник вокруг ячейки «сегодня».
  • coShowTodayName: Добавляет название дня в строку, отображающую сегодняшнюю дату (см. также: coShowTodayRow).
  • coShowTodayRow: Показывает строку внизу календаря для отображения сегодняшней даты (см. также: coShowTodayName).
  • coShowWeekend: Подсветка выходных дней (см. также: Colors.WeekendColor).
  • coUseTopRowColors: Рисует фон и текст верхней строки навигации, используя цвета, заданные в Colors.TopRowColor и Colors.TopRowTextColor.

Changing the language

The strings used by the component can be easily translated to a variety of languages by changing the value of the property Languages:

type
  TLanguage = (lgEnglish, lgFrench, lgGerman, lgHebrew, lgSpanish, lgItalian,
               lgPolish, lgFinnish);

Events

In addition to the standard events TCalendarLite fires the following events. Some events get year, month and day numbers of the currently painted cell as a parameter. A set of state flags indicates whether this day is selected, today or belongs to the previous or next month:

type
  TCalCellState = (csSelectedDay, csToday, csOtherMonth);
  TCalCellStates = set of TCalCellState;
  • OnDateChange: Fires whenever another date is selected in the calendar.
  • OnDrawCell: Can be used to override the painting process of a day cell completely or partially. If the boolean parameter AContinueDrawing is set to true the normal painting process continues after leaving the event handler; if it is false then no default painting occurs for this day. The event can be used, for example, to add birthday or holiday icons to the day cells.
  • OnGetDayText: Can be used to modify the text display for the specified day. The default is a string showing the day value. Using this event, the names of holidays can be added to calendar, for example.
  • OnGetHolidays: Defines which days of current month are holidays. The day number of the holidays are encoded as set bits in a 32-bit integer.
  • OnHint: Defines a hint which can be displayed in a popup hint window for each day. Useful, for example, to show the name of holidays if the mouse hovers over a holiday.
  • OnMonthChange: Fires whenever another month is displayed in the calendar. Can be used for more efficient holiday calculation.
  • OnPrepareCanvas: Is called immediately before a cell is painted. Can be used to override Brush and Pen properties, for example, in order to draw different backgrounds for appointments and important events.

Holidays

The calendar does not "know" any holidays. You must write an event handler to define which days in the current month are holidays. Month and year values of the respective month are passed as parameters. The information that a day is a holiday or not is encoded as set bits in a 32-bit integer. The unit callite simplifies this by providing these general-purpose procedures:

  • procedure AddHoliday(ADay: Integer; var AHolidays: THolidays): Adds the specified day to the holiday bit list in parameter AHolidays.
  • function IsHoliday(ADay: Integer; AHolidays: THolidays): Boolean: Checks whether the specified day is listed in AHolidays
  • ClearHolidays(var AHolidays: THolidays): Clears the holiday list

Here is a simple example defining the holidays New Year, Christmas, Easter and Whit Sunday:

function Easter(year:integer): TDateTime; 
var
  Day, Month    : integer;
  a,b,c,d,e,m,n : integer;
begin
  case Year div 100 of
    17    : begin m := 23; n := 3; end;
    18    : begin m := 23; n := 4; end;
    19,20 : begin m := 24; n := 5; end;
    21    : begin m := 24; n := 6; end;
    else    raise Exception.Create('Only years after 1700 supported.');
  end;
  a := Year mod 19;
  b := Year mod 4;
  c := Year mod 7;
  d := (19*a + m) mod 30;
  e := (2*b + 4*c + 6*d + n) mod 7;
  day := 22 + d + e;
  Month := 3;
  if Day>31 then begin
    Day := d + e - 9;
    Month := 4;
    if (d=28) and (e=6) and (a>10) then begin
      if day=26 then day := 19;
      if day=25 then day := 18;
    end;
  end;
  result := EncodeDate(year, month, day);
end;

procedure TForm1.CalendarLite1GetHolidays(Sender: TObject; AMonth, AYear: Integer;
  var Holidays: THolidays);
var
  d, m, y: Word;
  e: TDate;
begin
  ClearHolidays(Holidays);
  if not FNoHolidays then
  begin
    // Fixed holidays
    case AMonth of
      1: AddHoliday(1, Holidays);          // New Year
     12: AddHoliday(25, Holidays);         // Christmas
    end;
    // Easter
    e := Easter(AYear);
    DecodeDate(e, y,m,d);
    if m = AMonth then
      AddHoliday(d, Holidays);
    // Whit Sunday --> 49 days after easter
    DecodeDate(e+49, y,m,d);
    if m = AMonth then
      AddHoliday(d, Holidays);
  end;
end;

Make sure to have the calendar Option coShowHolidays set in order to highlight the holidays in the calendar.

Hints for holidays

If you want to display the holiday name as a mouse popup hint window then you should set the calendar's ShowHint to true and add this event handler for OnHint:

procedure TForm1.CalendarLite1Hint(Sender: TObject; AYear, AMonth, ADay: Word;
  var AText: String);
var
  dt, e: TDate;
begin
  AText := '';
  case AMonth of
    1: if ADay = 1 then AText := 'New Year';
   12: if ADay = 25 then AText := 'Christmas';
   else
       e := Easter(AYear);
       dt := EncodeDate(AYear, AMonth, ADay);
       if (dt = e) then
         AText := 'Easter'
       else if (dt = e + 49) then
         AText := 'Whit Sunday';
  end;
end;

Embedded holiday names

In addition, you can also add the holiday name to the calendar grid directly. Add the next event handler for OnGetDayText. Note that the size of the calendar must be large enough to provide space for the additional text:

procedure TForm1.CalendarLite1GetDayText(Sender: TObject; AYear, AMonth, ADay: Word;
  var AText: String);
var
  s: String;
begin
  GetHintText(Sender, AYear, AMonth, ADay, s);
  if s <> '' then
    AText := IntToStr(ADay) + LineEnding + s;
end;

Holidays in popup menu

If the calendar's PopupMenu property is empty a built-in popup menu is provided which displays all the holidays of the currently selected year. As usual, this popup opens with a right-click onto the component.

Drawing icons for specific days

The next example paints a birthday icon into the Nov 11 cell of each year. The icon is stored in an image list at index 0:

procedure TForm1.CalendarLite1DrawCell(Sender: TObject; ACanvas: TCanvas;
  AYear,AMonth,ADay: Word; AState: TCalCellStates; var ARect: TRect;
  var AContinueDrawing: Boolean);
var
  bmp: TBitmap;
begin
  if (AMonth = 11) and (ADay = 11) and not (csOtherMonth in AState) then begin
    bmp := TBitmap.Create;
    try
      ImageList1.GetBitmap(0, bmp);
      ACanvas.Draw(ARect.Left, (ARect.Top + ARect.Bottom - bmp.Height) div 2, bmp);
      inc(ARect.Left, bmp.Width + 2);
      // Not changing AContinueDrawing from its default value (true) means
      // that the day text is drawn by the built-in procedure into the reduced rectangle
    finally
      bmp.Free;
    end;
  end;
end;