📄 qisevensegmentclock.pas
字号:
{*******************************************************}
{ }
{ TiSevenSegmentClock Component }
{ }
{ Copyright (c) 1997,2003 Iocomp Software }
{ }
{*******************************************************}
{$I iInclude.inc}
{$ifdef iVCL}unit iSevenSegmentClock;{$endif}
{$ifdef iCLX}unit QiSevenSegmentClock;{$endif}
interface
uses
{$I iIncludeUses.inc}
{$IFDEF iVCL} iTypes, iGPFunctions, iMath, iSevenSegmentCharacter, iSevenSegmentDisplay;{$ENDIF}
{$IFDEF iCLX}QiTypes, QiGPFunctions, QiMath, QiSevenSegmentCharacter, QiSevenSegmentDisplay;{$ENDIF}
type
TiSevenSegmentClock = class(TiSevenSegmentDisplay)
private
FStartTime : TDateTime;
FOriginalTime : TDateTime;
FTime : Double;
FShowSeconds : Boolean;
FShowHours : Boolean;
FHourStyle : TiClockHourStyle;
FCountDirection : TiCountDirection;
FOnCountDownComplete : TNotifyEvent;
procedure SetTime (const Value: Double);
procedure SetShowHours (const Value: Boolean);
procedure SetShowSeconds (const Value: Boolean);
procedure SetHourStyle (const Value: TiClockHourStyle);
procedure SetHours (const Value: Integer);
procedure SetMinutes (const Value: Integer);
procedure SetSeconds (const Value: Integer);
procedure SetCountDirection (const Value: TiCountDirection);
procedure SetCountTimerEnabled(const Value: Boolean);
function GetCountTimerEnabled : Boolean;
function GetHours : Integer;
function GetMinutes : Integer;
function GetSeconds : Integer;
protected
procedure iPaintTo(Canvas: TCanvas); override;
function GetAutoSize : TPoint; override;
procedure TimerEvent(Sender : TObject);
procedure DoChange;
public
constructor Create(AOwner: TComponent); override;
procedure SetTimeNoEvent(const Value: Double);
procedure ResetToZero;
procedure SetTimeInSeconds(Value: Integer);
property CountTimerEnabled : Boolean read GetCountTimerEnabled write SetCountTimerEnabled;
published
property Time : Double read FTime write SetTime;
property ShowSeconds : Boolean read FShowSeconds write SetShowSeconds default True;
property ShowHours : Boolean read FShowHours write SetShowHours default True;
property HourStyle : TiClockHourStyle read FHourStyle write SetHourStyle default ichs24;
property Hours : Integer read GetHours write SetHours default 0;
property Minutes : Integer read GetMinutes write SetMinutes default 0;
property Seconds : Integer read GetSeconds write SetSeconds default 0;
property CountDirection : TiCountDirection read FCountDirection write SetCountDirection default icdDown;
property OnCountDownComplete : TNotifyEvent read FOnCountDownComplete write FOnCountDownComplete;
end;
implementation
//****************************************************************************************************************************************************
constructor TiSevenSegmentClock.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FShowSeconds := True;
FShowHours := True;
OnInternalTimer := TimerEvent;
DoAutoSize;
end;
//****************************************************************************************************************************************************
procedure TiSevenSegmentClock.DoChange;
begin
if Assigned(OnChangeProtected) then OnChangeProtected(Self, 'Time');
if Assigned(OnValueChange) then OnValueChange(Self);
end;
//****************************************************************************************************************************************************
function TiSevenSegmentClock.GetAutoSize: TPoint;
var
TotalWidth : Integer;
begin
TotalWidth := 2*SegmentMargin - DigitSpacing;
SevenSegmentCharacter.Character := '0';
TotalWidth := TotalWidth + (SevenSegmentCharacter.GetCharacterWidth + DigitSpacing) * 2;
if FShowHours then
begin
SevenSegmentCharacter.Character := '0';
TotalWidth := TotalWidth + (SevenSegmentCharacter.GetCharacterWidth + DigitSpacing) * 2;
SevenSegmentCharacter.Character := ':';
TotalWidth := TotalWidth + (SevenSegmentCharacter.GetCharacterWidth + DigitSpacing);
end;
if ShowSeconds then
begin
SevenSegmentCharacter.Character := '0';
TotalWidth := TotalWidth + (SevenSegmentCharacter.GetCharacterWidth + DigitSpacing) * 2;
SevenSegmentCharacter.Character := ':';
TotalWidth := TotalWidth + (SevenSegmentCharacter.GetCharacterWidth + DigitSpacing);
end;
Result.X := TotalWidth;
Result.Y := SevenSegmentCharacter.GetCharacterHeight + 2*SegmentMargin;
end;
//****************************************************************************************************************************************************
procedure TiSevenSegmentClock.SetTimeNoEvent(const Value: Double);
var
TempOnValueChange : TNotifyEvent;
begin
TempOnValueChange := OnValueChange;
OnValueChange := nil;
try
SetTime(Value);
finally
OnValueChange := TempOnValueChange;
end;
end;
//****************************************************************************************************************************************************
procedure TiSevenSegmentClock.SetTime(const Value: Double);
var
CanEdit : Boolean;
begin
if FTime <> Value then
begin
CanEdit := True;
if Assigned(OnRequestEditProtected) then OnRequestEditProtected(Self, 'Time', CanEdit);
if CanEdit then
begin
FTime := Value;
FOriginalTime := FTime;
FStartTime := Now;
InvalidateChange;
DoChange;
end;
end;
end;
//****************************************************************************************************************************************************
procedure TiSevenSegmentClock.SetShowHours(const Value: Boolean);
begin
if FShowHours <> Value then
begin
FShowHours := Value;
DoAutoSize;
InvalidateChange;
end;
end;
//****************************************************************************************************************************************************
procedure TiSevenSegmentClock.SetShowSeconds(const Value: Boolean);
begin
if FShowSeconds <> Value then
begin
FShowSeconds := Value;
DoAutoSize;
InvalidateChange;
end;
end;
//****************************************************************************************************************************************************
procedure TiSevenSegmentClock.SetHourStyle(const Value: TiClockHourStyle);
begin
if FHourStyle <> Value then
begin
FHourStyle := Value;
InvalidateChange;
end;
end;
//****************************************************************************************************************************************************
function TiSevenSegmentClock.GetHours: Integer;
var
Hour : Word;
Min : Word;
Sec : Word;
MSec : Word;
begin
DecodeTime(FTime, Hour, Min, Sec, MSec);
Result := Hour + Trunc(FTime) * 24;
end;
//****************************************************************************************************************************************************
function TiSevenSegmentClock.GetMinutes: Integer;
var
Hour : Word;
Min : Word;
Sec : Word;
MSec : Word;
begin
DecodeTime(FTime, Hour, Min, Sec, MSec);
Result := Min;
end;
//****************************************************************************************************************************************************
function TiSevenSegmentClock.GetSeconds: Integer;
var
Hour : Word;
Min : Word;
Sec : Word;
MSec : Word;
begin
DecodeTime(FTime, Hour, Min, Sec, MSec);
Result := Sec;
end;
//****************************************************************************************************************************************************
procedure TiSevenSegmentClock.SetHours(const Value: Integer);
var
Hour : Word;
Min : Word;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -