Recent

Author Topic: Questions about a new Calendar component.  (Read 71537 times)

wp

  • Hero Member
  • *****
  • Posts: 12622
Re: Questions about a new Calendar component.
« Reply #30 on: June 14, 2013, 10:22:35 pm »
Here's an update of the version that I posted above:
  • Use system colors wherever possible
  • Pass DayNames and MonthNames as comma-separated strings allowing to change them in the object inspector. Empty (or missing) strings means using of system names. DayNames start with Sunday.
  • Highlight the first row by its own background color (TopRowColor and TopRowTextColor, option coUseTopRowColors).
  • Add an optional separating line between rows 2 and 3 (option coDayLine)
  • Add a popupmenu activated by clicking on month or year in first row. The popup menu allows a quick change to a different month/year. Tried a spin edit for the year but this would require to inherit the control from TWinControl
Have fun.


howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Questions about a new Calendar component.
« Reply #31 on: June 15, 2013, 12:41:10 am »
wp, you're a hero. Very impressive enhancements. I particularly like the clever way you exploit TMenuItem.Tag to program a popup menu in only 10 lines of code.
I'm reworking the layout algorithm hopefully to make it both more robust and slightly optimised, and provide a Goto Today option.
Thanks for your work so far. I'll report back in due course.

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1255
Re: Questions about a new Calendar component.
« Reply #32 on: June 15, 2013, 02:10:12 am »
wp, very good job. Nothing to do for me  :D , just to check the component. 
Howardpc, it seems that there is a bug when using the component on linux Ubuntu. Look at the attachment. There are  strange arrows above the daysname.

Friendly, J.P
« Last Edit: June 15, 2013, 02:19:35 am by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1255
Re: Questions about a new Calendar component.
« Reply #33 on: June 15, 2013, 03:59:34 am »
howardpc , at the end of the procedure TCalDrawer.DrawArrow i don't know why there is this code :
Code: [Select]
           end;
            FCanvas.Polygon(pts);  end;
  end;
end;             

When i comment   FCanvas.Polygon(pts);  the strange arrows are gone.

Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Questions about a new Calendar component.
« Reply #34 on: June 15, 2013, 08:45:02 am »
Indeed, and this is not the only bug to be eliminated. I'll post updated code in due course after further testing here.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Questions about a new Calendar component.
« Reply #35 on: June 17, 2013, 05:39:48 pm »
Attached is an updated TCalendarLite component and demo with a few bug fixes and additional features:
  • An optional row displays today's date (and optional day name), which can be clicked to go to today
  • Right-clicking anywhere lists holidays for the current year (if any)
  • Several text items are published to make it easy to internationalise (you can use utf8-encoded text for this)
  • Going to 29 Feb in a leap year and clicking the year shown in the top row lists other nearby leap years
The demo program allows you to play with various property settings to see the effect of changes in width, colours etc.
I've changed the licence text to show me as 'originator' rather than author, since the most interesting parts of the code were written by wp.
I hope the BiDi functionality is working correctly now, so Avishai could you test this for us?

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Questions about a new Calendar component.
« Reply #36 on: June 17, 2013, 07:38:30 pm »
This is so far beyond TCalendar!  Beautiful work!  And I'm learning a lot from your code.  I checked out the Hebrew aspect and it works perfectly now.  Thanks for taking the time. :)

I did notice one thing and although I see no problem with it the way it is, I'm sure someone will bring this up.  On months where the first day of the week is also the first day of the month (Sept. 2013 with "Starting day of week" = Sunday), there are no "Previous Month Days" showing.  With TCalendar, it shows the entire first row as "Previous Month Days".
Lazarus Trunk / fpc 2.6.2 / Win32

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Questions about a new Calendar component.
« Reply #37 on: June 17, 2013, 10:17:02 pm »
howardpc, I just noticed that the Top row chops off the bottom of letters that extend down, like "y" or "g".  I know it's a small detail, but I thought I would say something anyway.
Lazarus Trunk / fpc 2.6.2 / Win32

wp

  • Hero Member
  • *****
  • Posts: 12622
Re: Questions about a new Calendar component.
« Reply #38 on: June 18, 2013, 09:56:58 am »
Great improvements!

Here are some ideas for further progress:

A simple modification (I could do it myself but don't want to interfere with your current changes): Initially the "day line" was below the days row, now it is above. Maybe you extend the options with coTopDayLine and coBottomDayLine (and drop coDayLine, of course).

An idea which requires some deeper knowledge of the column/row layout of your component: Add a column with week numbers just as the original TCalendar has.

Maybe the arrows require some attention: Since the entire cell rectangle is accepted for a mouse click, but the arrows are left/right aligned within the cells I usually hit year when I want to click month. Maybe, centering of the arrows should improve this behavior. In the long run, however, I'd prefer to have SpeedButtons in place of the arrows which would add further flexibility by using glyphs. This idea, however, provides some hassle of inserting a control into a TGraphicControl. It would be much simpler if the calender would inherit from TWinControl instead of TGraphicControl. Was there a special reason for this selection? TWinControl would also give access to the keyboard allowing to navigate with the arrow keys.

Don't declare the texts as const but as resourcestring. This opens the component for localization using i18n as provided by Lazarus - btw: under this aspect, I don't know if it is necessary to have the display texts, month names etc. in the user interface at all. Using resource strings and po files, you can translate to any language.

The DisplayTexts might have a translation issue because you use them as a base to which you append additional strings. Depending on language, the end of the string may not always be the correct position of the added string. Use format specifiers and the Format function instead. I.e:

Code: [Select]
resourcestring
  DefaultDisplayText = '"Today is %s","dd/mm/yyyy","Holidays during %d","There are no holidays set for %d"';
...
    item.Caption := Format(GetDisplayText(dtHolidaysDuring), [FCalDrawer.FThisYear]);
// instead of
//    item.Caption:= Format('%s %d',[GetDisplayText(dtHolidaysDuring), FCalDrawer.FThisYear]);

In a new translation, the added text can be put to the correct position this way.

I added quotation marks around the individual display text items because a comma provided by the user within a display text would lead to incorrect splitting of the item by means of the CommaText of the stringlist. You'll have to use StrictDelimiter = false to hide the quotation marks.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Questions about a new Calendar component.
« Reply #39 on: June 18, 2013, 11:35:17 am »
An idea which requires some deeper knowledge of the column/row layout of your component: Add a column with week numbers just as the original TCalendar has.
I'll chew on this, and draft an implementation in the next few days. Good suggestion, though I think it should be optional.
Quote
It would be much simpler if the calender would inherit from TWinControl instead of TGraphicControl. Was there a special reason for this selection? TWinControl would also give access to the keyboard allowing to navigate with the arrow keys.
The only reason was to make it a lightweight control, deliberately discarding all that keyboard-support and window-focus code and use of system resources in TWinControl which I thought this control could manage without, which also then made the control independent of widgetset. However, perhaps that makes the control too limited, and your suggestion for using speedbuttons is probably the right way to go. I agree that it is a shame to thereby cut out use of the arrow keys for navigation.
Thanks for your insights about use of string resources and comma-delimited text, which are noted.

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Questions about a new Calendar component.
« Reply #40 on: June 18, 2013, 12:51:56 pm »
This is the latest of my AviCalendar, but I stopped working on it after I saw what you guys were working on.  However, notice the way I handled changing Month/Year.  I don't know if it's "better" but it works.

As for the SpeedButtons, they have some problems in RightToLeft.  But I'm not sure you should take that into consideration.  Lazarus doesn't have that many RightToLeft users.
Lazarus Trunk / fpc 2.6.2 / Win32

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Questions about a new Calendar component.
« Reply #41 on: June 18, 2013, 01:12:49 pm »
TCalendarLite is already using translations based on Locale.  I checked that in my Hebrew login.  I thought that you had planned it that way so I didn't say anything.  As you can see in the image, the calendar on the right is in Hebrew and RightToLeft regardless of any settings.  That was a pleasant surprise for me when I first checked it in my Hebrew login.
Lazarus Trunk / fpc 2.6.2 / Win32

wp

  • Hero Member
  • *****
  • Posts: 12622
Re: Questions about a new Calendar component.
« Reply #42 on: June 18, 2013, 01:24:51 pm »
If you don't specify month and day names the locale strings are used. So if you are working an a Hebrew system you will get Hebrew strings automatically. Except for the "Today is..." which is hard-coded in English so far. To get this in Hebrew you'll either have to enter the DisplayTexts in Hebrew, or - once the DefaultDisplayText is declared as a resource string - you follow the instructions on http://wiki.lazarus.freepascal.org/Translations_/_i18n_/_localizations_for_programs and create a Hebrew language file for your application.

wimogan

  • Newbie
  • Posts: 2
Re: Questions about a new Calendar component.
« Reply #43 on: September 12, 2013, 05:33:24 pm »
Hello guys, interesting thread ...
For those who wish to take a look, I took the dare to create the ".lpk" package for "CalLite" and at the same time I added a property "Languages" for you to establish it a language...
Criticisms and suggestions are open ...
Thanks ...

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Questions about a new Calendar component.
« Reply #44 on: September 12, 2013, 06:18:22 pm »
Nice!  :)  Even the Icon looks great!
Lazarus Trunk / fpc 2.6.2 / Win32

 

TinyPortal © 2005-2018