cxprogressbar.pas
来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 1,716 行 · 第 1/5 页
PAS
1,716 行
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
function CanCompareEditValue: Boolean; override;
class function GetContainerClass: TcxContainerClass; override;
function GetDisplayText(const AEditValue: TcxEditValue;
AFullText: Boolean = False; AIsInplace: Boolean = True): WideString; override;
function GetSupportedOperations: TcxEditSupportedOperations; override;
class function GetViewInfoClass: TcxContainerViewInfoClass; override;
function IsEditValueValid(var EditValue: TcxEditValue;
AEditFocused: Boolean): Boolean; override;
procedure PrepareDisplayValue(const AEditValue: TcxEditValue;
var DisplayValue: TcxEditValue; AEditFocused: Boolean); override;
// !!!
property AnimationPath: TcxProgressBarAnimationPath read FAnimationPath
write SetAnimationPath default cxapCycle;
property AnimationRestartDelay: Cardinal read FAnimationRestartDelay write SetAnimationRestartDelay default cxProgressBarDefaultAnimationRestartDelay;
property AnimationSpeed: TcxProgressBarAnimationSpeed read FAnimationSpeed write SetAnimationSpeed default cxProgressBarDefaultAnimationSpeed;
property BarBevelOuter: TcxProgressBarBevelOuter read FBarBevelOuter
write SetBarBevelOuter default cxbvNone;
property BarStyle: TcxProgressBarBarStyle read FBarStyle write SetBarStyle
default cxbsSolid;
property BeginColor: TColor read FBeginColor write SetBeginColor
default clNavy;
property BorderWidth : TcxBorderWidth read FBorderWidth write SetBorderWidth
default 0;
property EndColor: TColor read FEndColor write SetEndColor default clWhite;
property ForegroundImage: TBitmap read GetForegroundImage
write SetForegroundImage;
property Marquee: Boolean read FMarquee write SetMarquee default False;
property Max: Double read GetMax write SetMax stored IsMaxStored;
property Min: Double read GetMin write SetMin stored IsMinStored;
property Orientation: TcxProgressBarOrientation read FOrientation
write SetOrientation default cxorHorizontal;
property OverloadBeginColor: TColor read FOverloadBeginColor
write SetOverloadBeginColor default $008080FF;
property OverloadEndColor: TColor read FOverloadEndColor
write SetOverloadEndColor default clFuchsia;
property OverloadValue: Double read FOverloadValue write SetOverloadValue
stored GetOverloadValueStored;
property PeakColor: TColor read FPeakColor write SetPeakColor default clRed;
property PeakSize: TcxNaturalNumber read FPeakSize write SetPeakSize
default 2;
property PeakValue: Double read FPeakValue write SetPeakValue
stored GetPeakValueStored;
property ShowOverload: Boolean read FShowOverload write SetShowOverload
default False;
property ShowPeak: Boolean read FShowPeak write SetShowPeak default False;
property ShowText: Boolean read FShowText write SetShowText default True;
property ShowTextStyle: TcxProgressBarTextStyle read FShowTextStyle
write SetShowTextStyle stored IsShowTextStyleStored;
property SolidTextColor: Boolean read FSolidTextColor
write SetSolidTextColor default False;
property Text: string read FText write SetText;
property TextOrientation: TcxProgressBarOrientation read FTextOrientation
write SetTextOrientation default cxorHorizontal;
property Transparent; // deprecated
property TransparentImage: Boolean read FTransparentImage
write SetTransparentImage default True;
end;
{ TcxProgressBarProperties }
TcxProgressBarProperties = class(TcxCustomProgressBarProperties)
published
property AnimationPath;
property AnimationRestartDelay;
property AnimationSpeed;
property AssignedValues;
property BarBevelOuter;
property BarStyle;
property BeginColor;
property BorderWidth;
property EndColor;
property ForegroundImage;
property Marquee;
property Max;
property Min;
property Orientation;
property OverloadBeginColor;
property OverloadEndColor;
property OverloadValue;
property PeakColor;
property PeakSize;
property PeakValue;
property ShowOverload;
property ShowPeak;
property ShowText;
property ShowTextStyle;
property SolidTextColor;
property Text;
property TextOrientation;
property Transparent; // deprecated
property TransparentImage;
end;
{ TcxCustomProgressBar }
TcxCustomProgressBar = class(TcxCustomEdit)
private
function GetPercentDone: Integer;
function GetPosition: Double;
function GetPositionStored: Boolean;
function GetProperties: TcxCustomProgressBarProperties;
function GetActiveProperties: TcxCustomProgressBarProperties;
function GetViewInfo: TcxCustomProgressBarViewInfo;
procedure SetProperties(Value: TcxCustomProgressBarProperties);
procedure SetPosition(Value: Double);
protected
procedure CheckEditorValueBounds; virtual;
procedure CheckEditValue; virtual;
function DefaultParentColor: Boolean; override;
procedure FillSizeProperties(var AEditSizeProperties: TcxEditSizeProperties); override;
procedure Initialize; override;
function InternalGetNotPublishedStyleValues: TcxEditStyleValues; override;
procedure SynchronizeDisplayValue; override;
procedure PropertiesChanged(Sender: TObject); override;
property ViewInfo: TcxCustomProgressBarViewInfo read GetViewInfo;
function CanFocusOnClick: Boolean; override;
public
class function GetPropertiesClass: TcxCustomEditPropertiesClass; override;
function CanFocus: Boolean; override;
property ActiveProperties: TcxCustomProgressBarProperties
read GetActiveProperties;
property PercentDone: Integer read GetPercentDone;
property Position: Double read GetPosition write SetPosition
stored GetPositionStored;
property Properties: TcxCustomProgressBarProperties read GetProperties
write SetProperties;
property Transparent;
end;
{ TcxCustomProgressBar }
TcxProgressBar = class(TcxCustomProgressBar)
private
function GetActiveProperties: TcxProgressBarProperties;
function GetProperties: TcxProgressBarProperties;
procedure SetProperties(Value: TcxProgressBarProperties);
public
class function GetPropertiesClass: TcxCustomEditPropertiesClass; override;
property ActiveProperties: TcxProgressBarProperties
read GetActiveProperties;
published
property Align;
property Anchors;
property AutoSize;
property Constraints;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property ParentColor;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property Position;
property Properties: TcxProgressBarProperties read GetProperties
write SetProperties;
property ShowHint;
property Style;
property StyleDisabled;
property StyleFocused;
property StyleHot;
property TabOrder;
property TabStop;
property Transparent;
property Visible;
property OnContextPopup;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnStartDock;
property OnStartDrag;
end;
implementation
uses
Math, cxEditConsts, cxDrawTextUtils, cxEditUtils, cxExtEditUtils, cxSpinEdit,
dxThemeConsts, dxThemeManager, dxUxTheme, cxGeometry, dxOffice11, cxLookAndFeels;
const
cxAnimationBarColorLightPercentage = 60;
cxAnimationBarMiddlePartWidth = 10;
cxAnimationBarTopPartWidth = 6;
cxAnimationBarTopBeginColorLightPercentage = 40;
cxAnimationBarTopEndColorLightPercentage = 80;
cxAnimationBarBorderExtPartColorLightPercentage = 90;
cxAnimationBarBorderIntPartColorLightPercentage = 80;
cxAnimationBarBorderExtPathWidth = 4;
cxAnimationBarBorderIntPathWidth = 20;
cxAnimationBarBackgroundBorderWidth = 8;
type
{ TcxFilterProgressBarHelper }
TcxFilterProgressBarHelper = class(TcxFilterSpinEditHelper)
public
class procedure InitializeProperties(AProperties,
AEditProperties: TcxCustomEditProperties; AHasButtons: Boolean); override;
end;
procedure CalculateCustomProgressBarViewInfo(ACanvas: TcxCanvas; AViewData: TcxCustomProgressBarViewData;
AViewInfo: TcxCustomProgressBarViewInfo);
procedure CheckFocusRectBounds;
begin
with AViewInfo do
begin
if FocusRect.Left < TextRect.Left - 1 then
FocusRect.Left := TextRect.Left - 1;
if FocusRect.Top < TextRect.Top - 1 then
FocusRect.Top := TextRect.Top - 1;
if FocusRect.Right > TextRect.Right + 1 then
FocusRect.Right := TextRect.Right + 1;
if FocusRect.Bottom > TextRect.Bottom + 1 then
FocusRect.Bottom := TextRect.Bottom + 1;
end;
end;
begin
with AViewInfo do
begin
if not IsInplace and Focused then
if Length(Text) = 0 then
FocusRect := cxEmptyRect
else
begin
FocusRect := TextRect;
InflateRect(FocusRect, 1, 1);
CheckFocusRectBounds;
end;
end;
end;
function CalculateDelta(const APositionDelta, ARectWidth, AMaxMinDelta: Double): Integer;
var
ACalc: Double;
begin
ACalc := (APositionDelta * ARectWidth) / AMaxMinDelta;
Result := Trunc(ACalc);
end;
{ TcxCustomProgressBarViewInfo }
constructor TcxCustomProgressBarViewInfo.Create;
begin
inherited Create;
FForegroundImage := TBitmap.Create;
ChangedBounds := False;
ChangedBoundsBarRect := False;
FMarquee := False;
FAnimationPath := cxapCycle;
FAnimationRestartDelay := cxProgressBarDefaultAnimationRestartDelay;
FUsualBitmap := TcxBitmap.Create;
end;
destructor TcxCustomProgressBarViewInfo.Destroy;
begin
FreeAndNil(FForegroundImage);
FreeAndNil(FAnimationTimer);
FreeAndNil(FAnimationRestartDelayTimer);
FreeAndNil(FUsualBitmap);
FreeAndNil(FNativeBitmap);
FreeAndNil(FPainterBitmap);
inherited Destroy;
end;
function TcxCustomProgressBarViewInfo.GetUpdateRegion(AViewInfo: TcxContainerViewInfo): TcxRegion;
begin
Result := inherited GetUpdateRegion(AViewInfo);
if not (AViewInfo is TcxCustomProgressBarViewInfo) then Exit;
end;
function TcxCustomProgressBarViewInfo.NeedShowHint(ACanvas: TcxCanvas;
const P: TPoint; out AText: TCaption; out AIsMultiLine: Boolean;
out ATextRect: TRect): Boolean;
begin
Result := False;
end;
procedure TcxCustomProgressBarViewInfo.DrawText(ACanvas: TcxCanvas);
begin
DrawBarCaption(ACanvas);
end;
function TcxCustomProgressBarViewInfo.GetPercentDone: Integer;
begin
Result := Math.Min(Round(RelativePosition * 100 / MaxMinDiff), 100);
end;
procedure TcxCustomProgressBarViewInfo.Offset(DX: Integer; DY: Integer);
begin
inherited Offset(DX, DY);
InflateRectEx(BarRect, DX, DY, DX, DY);
InflateRectEx(ProgressBarRect, DX, DY, DX, DY);
InflateRectEx(OverloadBarRect, DX, DY, DX, DY);
InflateRectEx(PeakBarRect, DX, DY, DX, DY);
end;
procedure TcxCustomProgressBarViewInfo.Paint(ACanvas: TcxCanvas);
begin
if ChangedBoundsBarRect then
CreateBarBmp;
if not Assigned(FUsualBitmap) then
Exit;
if not ChangedBounds and not (FShowText and (GetDrawText <> '')) then
Exit;
if Painter <> nil then
PaintProgressBarByPainter(ACanvas)
else
begin
if not (AreVisualStylesMustBeUsed(NativeStyle, totProgress) or
IsInplace and Transparent) then
DrawCustomEdit(ACanvas, Self, False, bpsSolid);
PaintProgressBar(ACanvas);
end;
end;
procedure TcxCustomProgressBarViewInfo.PaintProgressBar(ACanvas: TcxCanvas);
var
ALEDsWidth: Integer;
ADrawDelta: Integer;
ABarRect: TRect;
ADrawProgressBarRect: TRect;
ADrawOverloadBarRect: TRect;
ADrawPeakBarRect: TRect;
ADrawAnimationBarRect: TRect;
ASolidRect: TRect;
APrevLogFont: TLogFont;
begin
SaveCanvasFont(ACanvas, APrevLogFont);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?