Jump to content


Photo

TNxTimeEdit question


  • Please log in to reply
18 replies to this topic

#1 array81

array81

    Senior Member

  • Members
  • PipPip
  • 290 posts
  • Gender:Male

Posted 04 February 2011 - 01:38 PM

I think I don't understand how TNxTimeEdit works: when I try to use spin button to change hours, minutes or seconds nothing happens... I don't understand why.

Besides there is NOT TNxTimeEdit.AsTime property. I find onlt TNxTimeEdit.AsDateTime but if I use it also the date (not only the time) will be show on edit.

I need show only only time in HH:MM format (no second, besides I need time in 24h format, no AM/PM) and the user can use the spin button to change hours or minitus. Can you tell me how can I do it?

#2 array81

array81

    Senior Member

  • Members
  • PipPip
  • 290 posts
  • Gender:Male

Posted 11 February 2011 - 04:33 PM

I have check TNxTimeEdit code, I think it is not finish! In this way it cannot works. You will finished it?

#3 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,195 posts
  • Gender:Male

Posted 11 February 2011 - 06:12 PM

Hello,

It will be finished.

Best regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#4 array81

array81

    Senior Member

  • Members
  • PipPip
  • 290 posts
  • Gender:Male

Posted 11 February 2011 - 07:39 PM

And you have a date for it? I need understand if I can wait it or I need find another component, I have almost finish my project...

#5 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,195 posts
  • Gender:Male

Posted 12 February 2011 - 12:28 AM

I have try to add support for all date-time formats, but this give me some troubles.

I will start to work on it again, but if you are in hurry I suggest that you use other component.

Best regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#6 array81

array81

    Senior Member

  • Members
  • PipPip
  • 290 posts
  • Gender:Male

Posted 14 February 2011 - 01:28 PM

I'm working on TNxTimePicker I hope to finish it today. I will send you the code so I hope you include on next version.

#7 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,195 posts
  • Gender:Male

Posted 14 February 2011 - 10:40 PM

Hello,

If is appropriate, I will be glad to include it.

Best regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#8 array81

array81

    Senior Member

  • Members
  • PipPip
  • 290 posts
  • Gender:Male

Posted 15 February 2011 - 12:32 PM

I'm developing my TNxTimePicker, I think it's almost finish but I need of your help to fix a couple of bug:
1) when I click on a hour or a minute I don't see selected box;
2) when I close the popup, the popup don't pass the seleted time to edit.

I think there are 2 stupid bugs but I cannot found them.
I have attacthed a screenshot of the new component.

Thi is the code of NxEdit:
CODE
  TNxTimePicker = class(TNxPopupEdit)
  private
    FHoursString: string;
    FMinutesString: string;
    procedure SetHoursString(const Value: string);
    procedure SetMinutesString(const Value: string);
  protected
    function GetAsDateTime: TDateTime; override;
    function GetPopupControlClass: TNxPopupControlClass; override;
    procedure BeforeDrop(var APoint: TPoint); override;
    procedure KeyDown(var Key: Word; Shift: TShiftState); override;
    procedure SetAsDateTime(const Value: TDateTime); override;
    procedure SetValueToText(SendValue: TDateTime);
    procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
    procedure WMKillFocus(var Msg: TWMKillFocus); message WM_KILLFOCUS;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
      property Time: TDateTime read GetAsDateTime write SetAsDateTime;
    property HoursString: string read FHoursString write SetHoursString;
    property MinutesString: string read FMinutesString write SetMinutesString;
  end;

........

{ TNxTimePicker }

constructor TNxTimePicker.Create(AOwner: TComponent);
begin
  inherited;
  AsDateTime := Now;
  FHoursString := 'H';
  FMinutesString := 'M';
end;

destructor TNxTimePicker.Destroy;
begin
  inherited;
end;

procedure TNxTimePicker.BeforeDrop(var APoint: TPoint);
var
    h, m, s, ms: Word;
begin
  inherited;
  with FPopupControl as TNxTimePopup do
  begin
    Font.Assign(Self.Font);

    SelectedTime := GetAsDateTime;
    DecodeTime(SelectedTime, h, m, s, ms);
    HoursString := Self.FHoursString;
    MinutesString := Self.FMinutesString;
    Hours := h;
    Minutes := m;
      Height := 207;
      Width := 100;
  end;
end;

function TNxTimePicker.GetAsDateTime: TDateTime;
begin
    if (Text = '') or (Text = '0') then Result := Time
    else if not TryStrToTime(Text, Result) then Result := 0;
end;

function TNxTimePicker.GetPopupControlClass: TNxPopupControlClass;
begin
  Result := TNxTimePopup;
end;

procedure TNxTimePicker.SetAsDateTime(const Value: TDateTime);
var
  y, m, d : Word;
  h, mm, s, ms : Word;
  t: TTime;
begin
  DecodeDateTime(Value, y, m, d, h, mm, s, ms);
  t := EncodeTime(h, mm, 0, 0);
  Text := TimeToStr(t);
end;

procedure TNxTimePicker.SetHoursString(const Value: string);
begin
  FHoursString := Value;
end;

procedure TNxTimePicker.SetMinutesString(const Value: string);
begin
  FMinutesString := Value;
end;

procedure TNxTimePicker.SetValueToText(SendValue: TDateTime);
begin

end;

procedure TNxTimePicker.KeyDown(var Key: Word; Shift: TShiftState);
var
    h, m, s, ms: Word;
begin
  inherited;
  if DroppedDown then
  begin
    if Key <> 0 then
    begin
      with FPopupControl as TNxTimePopup do
      begin
        DecodeTime(GetAsDateTime, h, m, s, ms);
        Hours := h;
        Minutes := m;
        SelectedTime := GetAsDateTime;
        Invalidate;
      end;
    end;
  end;
end;

procedure TNxTimePicker.WMKillFocus(var Msg: TWMKillFocus);
begin  
  inherited;
  if Text <> '' then
  begin
    AsDateTime := StrToDateDef(Text, Time);
  end;
end;

procedure TNxTimePicker.WMPaint(var Message: TWMPaint);
begin
  inherited;
  if (Text = '') and not Focused then
  begin
    Canvas.Font.Assign(Font);
    Canvas.Font.Color := clGrayText;
    DrawText(Canvas, ClientRect, taLeftJustify, '');
  end;
end;



and this the code of NxPopupControl.pas:

CODE
  TNxTimePopup = class(TNxPopupControl)
  private
    FDown: Boolean;
    FHours: Word;
    FHoursString: string;
    FSelectedTime: TTime;
    FMinutes: Word;
    FMinutesString: string;
    FOldHourRect: TRect;
    FOldMinuteRect: TRect;
    FTime: TTime;
    procedure SelectHour(X, Y: Integer);
    procedure SelectMinute(X, Y: Integer);
    procedure SetHour(const Value: Word);
    procedure SetHourString(Value: string);
    procedure SetMinute(const Value: Word);
    procedure SetTime(const Value: TTime);
    procedure SetMinuteString(Value: string);
  protected
      procedure CreateWnd; override;
    function GetHourRect: TRect;
    function GetMinuteRect: TRect;
    function GetTitleRect: TRect;
    procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
    procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    procedure Paint; override;
    procedure PaintItem(Day: Integer; DayRect: TRect);
    procedure PaintTitle(TitleRect: TRect);
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
        property Hours: Word read FHours write SetHour;
    property HoursString: string read FHoursString write SetHourString;
    property Minutes: Word read FMinutes write SetMinute;
    property MinutesString: string read FMinutesString write SetMinuteString;
    property SelectedTime: TTime read FSelectedTime write FSelectedTime;
    property Time: TTime read FTime write SetTime;
  end;

.......

  { TNxTimePopup }

constructor TNxTimePopup.Create(AOwner: TComponent);
begin
  inherited;
  FHours := 12;
  FMinutes := 0;

  DoubleBuffered := True;

  FHoursString := 'H';
  FMinutesString := 'M';
end;

destructor TNxTimePopup.Destroy;
begin
  inherited;
end;

procedure TNxTimePopup.CreateWnd;
begin
  inherited;
  VertScrollBar.Visible := False;
end;

function TNxTimePopup.GetTitleRect: TRect;
begin
  Result := Rect(5, 5, ClientWidth - 5, 5 + 16);
end;

function TNxTimePopup.GetHourRect: TRect;
begin
  Result := Rect(5, 5, 10 + (ClientWidth - 10) div 3 * 2, 5 + 16);
end;

function TNxTimePopup.GetMinuteRect: TRect;
begin
  Result := Rect(5 + (ClientWidth - 10) div 3 * 2, 5, ClientWidth - 5, 5 + 16);
end;

procedure TNxTimePopup.SetTime(const Value: TTime);
begin
  FTime := Value;
  FSelectedTime := Value;
  FHours := HourOf(FTime);
  FMinutes := MinuteOf(FTime);
end;

procedure TNxTimePopup.SelectHour(X, Y: Integer);
var
    l, t, col, row: Integer;
    r: TRect;
begin
  if (X - 5) < ((ClientWidth-10) div 3) then
    col := 1
  else
    col := 2;

  row := (y - 21) div 15 + 1;

  if col = 1 then
    begin
      if (row-1) = FHours then
        Exit;

      FHours := row-1;
    end
  else
    begin
      if (2*row)-1 = FHours then
        Exit;

      FHours := (2*row)-1;
    end;

  SelectedTime := EncodeTime(FHours, FMinutes, 0, 0);

  l := 6 + col * 30;
  t := 22 + row * 15;
  r := Rect(l, t, l + 28, t + 13);
  InvalidateRect(Handle, @FOldHourRect, False);
  InvalidateRect(Handle, @r, False);
end;

procedure TNxTimePopup.SelectMinute(X, Y: Integer);
var
    l, t, col, row: Integer;
    r: TRect;
begin
    col := 3;
  row := (y - 21) div 15 + 1;

  if (row-1)*5 = FMinutes then
    Exit;

  FMinutes := (row-1)*5;

  SelectedTime := EncodeTime(FHours, FMinutes, 0, 0);

  l := 6 + col * 30;
  t := 22 + row * 15;
  r := Rect(l, t, l + 28, t + 13);
  InvalidateRect(Handle, @FOldMinuteRect, False);
  InvalidateRect(Handle, @r, False);
end;

procedure TNxTimePopup.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
  Y: Integer);
begin
  inherited;
  if PtInRect(Rect(5, 21, (ClientWidth div 3 * 2) + 5, ClientHeight - 5), Point(X, Y)) then
  begin
    FDown := True;
    SelectHour(X, Y);
  end;

  if PtInRect(Rect((ClientWidth div 3 * 2) + 5, 21, ClientWidth - 5, ClientHeight - 5), Point(X, Y)) then
  begin
    FDown := True;
    SelectMinute(X, Y);
  end;
end;

procedure TNxTimePopup.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
  inherited;

  if (FDown) then
  begin
    if PtInRect(Rect(5, 21, (ClientWidth div 3 * 2) + 5, ClientHeight - 5), Point(X, Y)) then
    begin
      FDown := True;
      SelectHour(X, Y);
    end;

    if PtInRect(Rect((ClientWidth div 3 * 2) + 5, 21, ClientWidth - 5, ClientHeight - 5), Point(X, Y)) then
    begin
      FDown := True;
      SelectMinute(X, Y);
    end;
  end;
end;

procedure TNxTimePopup.MouseUp(Button: TMouseButton; Shift: TShiftState; X,
  Y: Integer);
begin
    if not PtInRect(Rect(0, 0, ClientWidth, ClientHeight), Point(X, Y)) then inherited;
  FDown := False;
end;

procedure TNxTimePopup.Paint;
var
    X, Y, p, dx: Integer;
  r1, r2, r3: TRect;
  h, m, s, ms : Word;
begin
  inherited;
  X := 5;
  Y := 22;
  p := 0;

  dx := (ClientWidth - 10) div 3;

  with Canvas do
  begin
    Font.Assign(Self.Font);
    Font.Color := clWindowText;
    Brush.Color := Self.Color;
    Pen.Color := clGrayText;
    Rectangle(0, 0, ClientWidth, ClientHeight);
    PaintTitle(GetTitleRect);

    Font.Color := clWindowText;
    DrawTextRect(Canvas, GetHourRect, taCenter, FHoursString);
    Font.Color := clWindowText;
    DrawTextRect(Canvas, GetMinuteRect, taCenter, FMinutesString);

    Pen.Color := clGrayText;
    MoveTo(5, 21);
    LineTo(ClientWidth - 5, 21);
    Pen.Color := clGrayText;
    MoveTo(5 + ((ClientWidth - 10) div 3 * 2), 21);
    LineTo(5 + ((ClientWidth - 10) div 3 * 2), 202);
    Pen.Color := clGrayText;
    MoveTo(5 + ((ClientWidth - 10) div 3 * 1), 21);
    LineTo(5 + ((ClientWidth - 10) div 3 * 1), 202);
    Pen.Color := clGrayText;
    MoveTo(5, 202);
    LineTo(ClientWidth - 5, 202);

    DecodeTime(SelectedTime, h, m, s, ms);

    while p < 12 do
    begin
        r1 := Rect(X + 3, Y, X + dx - 3, Y + 15);
      r2 := Rect(X + dx + 3, Y, X + dx + dx - 3, Y + 15);
      r3 := Rect(X + 2*dx + 3, Y, X + 2*dx + dx - 3, Y + 15);

      Font.Color := clWindowText;

      if p = h then
      begin
          if IsThemed then
          Brush.Color := RGB(251, 230, 148)
        else
          Brush.Color := clSilver;

        FillRect(Rect(X + 1, Y + 1, X + dx - 1, Y + 15 - 1));
        FOldHourRect := Rect(X + 1, Y + 1, X + dx - 1, Y + 15 - 1);
      end
      else if (p+12) = h then
      begin
          if IsThemed then
          Brush.Color := RGB(251, 230, 148)
        else
          Brush.Color := clSilver;

        FillRect(Rect(X + dx + 2, Y + 1, X + dx + dx - 1, Y + 15 - 1));
        FOldHourRect := Rect(X + dx + 2, Y + 1, X + dx + dx - 1, Y + 15 - 1);
      end;

      PaintItem(p, r1);
      PaintItem(p + 12, r2);

      Font.Color := clGrayText;

      if p = (m div 5) then
      begin
          if IsThemed then
          Brush.Color := RGB(251, 230, 148)
        else
          Brush.Color := clSilver;
        FillRect(Rect(X + 2*dx + 2, Y + 1, X + 2*dx + dx - 1, Y + 15 - 1));
        FOldMinuteRect := Rect(X + 2*dx + 2, Y + 1, X + 2*dx + dx - 1, Y + 15 - 1);
      end;

      PaintItem(p*5, r3);

      Inc(Y, 15);
      Inc(p, 1)
    end;
  end;
end;

procedure TNxTimePopup.PaintItem(Day: Integer; DayRect: TRect);
var
  StringText: string;
begin
  with Canvas.Brush do
  begin
    Style := bsClear;
    StringText := IntToStr(Day);
    TGraphicsProvider.DrawWrapedTextRect(Canvas, DayRect, taRightJustify, taVerticalCenter,
      False, StringText, bdLeftToRight);
    Style := bsSolid;
  end;
end;

procedure TNxTimePopup.PaintTitle(TitleRect: TRect);
begin
  with Canvas do
  begin
    if not IsThemed    then Brush.Color := clBtnFace
      else Brush.Color := TGraphicsProvider.BlendColor(clGradientInactiveCaption, clWindow, 249);

    FillRect(TitleRect);
    Font.Color := clWindowText;
    DrawTextRect(Canvas, GetHourRect, taCenter, FHoursString);
      DrawTextRect(Canvas, GetMinuteRect, taCenter, FMinutesString);
  end;
end;

procedure TNxTimePopup.SetHourString(Value: string);
begin
  FHoursString := Value;
end;

procedure TNxTimePopup.SetMinuteString(Value: string);
begin
  FMinutesString := Value;
end;

procedure TNxTimePopup.SetHour(const Value: Word);
begin
  FHours := Value;
end;

procedure TNxTimePopup.SetMinute(const Value: Word);
begin
  FMinutes := Value;
end;


Please help me to fix it.

Component explane: from popup the user can select a hour (from 0 to 23) and a minute (0, 5, 10, ...), it's simple. This type of picker is perfect for pim application where the user not need set a "full" time.

Attached Files



#9 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,195 posts
  • Gender:Male

Posted 17 February 2011 - 02:45 AM

Hello,

Very good. I think that I will add it. Thank you.

I didn't have time to test it today, but I will do it tomorrow.

Best regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#10 array81

array81

    Senior Member

  • Members
  • PipPip
  • 290 posts
  • Gender:Male

Posted 17 February 2011 - 11:43 AM

Thanks, I'm wating for it. Can you send me the code after fix it but before next version of your suite. I need of it on my software.

#11 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,195 posts
  • Gender:Male

Posted 17 February 2011 - 11:09 PM

Hi,

I have find where are the problems.

- You didn't well calculate TRect parameters after hour or minute is selected for InvalidateRect. I have put only Invalidate and it works, but it flicker.
- I have fix selecton problem.

I generally like the component, but can you please adjust it (fix bugs, and similar) a little bit more to I include it in official release.

I am sending you NxPopupControl.pas in private message.

Best regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#12 array81

array81

    Senior Member

  • Members
  • PipPip
  • 290 posts
  • Gender:Male

Posted 18 February 2011 - 12:40 PM

Can you tell me which edit I need to do to include it on official release?

Another think: if I use TNxTimePicker on a black project I don't have problem, if I use it on my project it works but I see the time with AM/PM format. do you have any idea about why?

#13 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,195 posts
  • Gender:Male

Posted 20 February 2011 - 05:47 AM

Hello Array81,

If component become more polished, I will be happy to include it in NextEditors palette.

2) Maybe you need to set ShortTimeFormat global variable?

best regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#14 array81

array81

    Senior Member

  • Members
  • PipPip
  • 290 posts
  • Gender:Male

Posted 24 February 2011 - 08:55 PM

I think my last version just works well. You can add some options if you want (for example time format and AP/PM popup). But it just works well (I test it in these days). So please include it on your official release.

IDEA: why you don't add a special nextgrid column based on it?

#15 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,195 posts
  • Gender:Male

Posted 25 February 2011 - 01:30 AM

Hello,

Can you please send me updated files.

Thank you
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#16 array81

array81

    Senior Member

  • Members
  • PipPip
  • 290 posts
  • Gender:Male

Posted 01 March 2011 - 02:31 PM

I will send you it tomorrow.

#17 array81

array81

    Senior Member

  • Members
  • PipPip
  • 290 posts
  • Gender:Male

Posted 16 March 2011 - 12:26 PM

I send you the files by PM message smile.gif

#18 array81

array81

    Senior Member

  • Members
  • PipPip
  • 290 posts
  • Gender:Male

Posted 20 April 2011 - 10:36 AM

Do you have add it on your alst update? Can I update without problem?

#19 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,195 posts
  • Gender:Male

Posted 20 April 2011 - 07:00 PM

Hello,

I have include all fixes. You may download it from Members Section.

Best regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users