📄 jvqspecialprogress.pas
字号:
{******************************************************************************}
{* WARNING: JEDI VCL To CLX Converter generated unit. *}
{* Manual modifications will be lost on next release. *}
{******************************************************************************}
{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is: JvSpecialProgress.PAS, released on 2001-02-28.
The Initial Developer of the Original Code is S閎astien Buysse [sbuysse att buypin dott com]
Portions created by S閎astien Buysse are Copyright (C) 2001 S閎astien Buysse.
All Rights Reserved.
Contributor(s):
Michael Beck [mbeck att bigfoot dott com].
[eldorado]
You may retrieve the latest version of this file at the Project JEDI home page,
located at http://www.delphi-jedi.org
Known Issues:
-----------------------------------------------------------------------------}
// $Id: JvQSpecialProgress.pas,v 1.20 2004/12/01 22:53:20 asnepvangers Exp $
unit JvQSpecialProgress;
{$I jvcl.inc}
interface
uses
SysUtils, Classes,
QWindows, QMessages, QGraphics, QControls, QForms, QExtCtrls, // for Frame3D
JvQComponent;
type
TJvTextOption = (toCaption, toFormat, toNoText, toPercent);
TJvSpecialProgress = class(TJvGraphicControl)
private
FBorderStyle: TBorderStyle;
FEndColor: TColor;
FGradientBlocks: Boolean;
FMaximum: Integer;
FMinimum: Integer;
FPosition: Integer;
FSolid: Boolean;
FStartColor: TColor;
FStep: Integer;
FTextCentered: Boolean;
FTextOption: TJvTextOption;
FBuffer: TBitmap;
FBlock: Integer;
{ FIsChanged indicates if the buffer needs to be redrawn }
FIsChanged: Boolean;
FStart: TColor;
FEnd: TColor;
{ If Solid = False then the values of the following vars are valid: }
{ FBlockCount is # of blocks }
FBlockCount: Integer;
{ FBlockWidth is length of block in pixels + 1 {seperator }
FBlockWidth: Integer;
{ FLastBlockPartial indicates whether the last block is of length
FBlockWidth; if FLastBlockPartial is True the progressbar is totally
filled and the last block is *not* of length FBlockWidth, but of
length FLastBlockWidth; if FLastBlockPartial is False the progressbar
is not totally filled or the last block is of length FBlockWidth }
FLastBlockPartial: Boolean;
{ FLastBlockWidth specifies the length of the last block if the
progressbar is totally filled, note: *not* +1 for seperator }
FLastBlockWidth: Integer;
function GetPercentDone: Longint;
procedure SetBorderStyle(Value: TBorderStyle);
procedure SetEndColor(const Value: TColor);
procedure SetGradientBlocks(const Value: Boolean);
procedure SetMaximum(const Value: Integer);
procedure SetMinimum(const Value: Integer);
procedure SetPosition(const Value: Integer);
procedure SetSolid(const Value: Boolean);
procedure SetStartColor(const Value: TColor);
procedure SetTextCentered(const Value: Boolean);
procedure SetTextOption(const Value: TJvTextOption);
procedure PaintRectangle;
procedure PaintNonSolid;
procedure PaintSolid;
procedure PaintBackground;
procedure PaintText;
protected
procedure Paint; override;
procedure Loaded; override;
procedure ColorChanged; override;
procedure FontChanged; override;
procedure TextChanged; override;
procedure UpdateBuffer;
procedure UpdateBlock;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure StepIt;
property PercentDone: Longint read GetPercentDone;
published
property Align;
property Anchors;
property BorderStyle: TBorderStyle read FBorderStyle write SetBorderStyle default bsNone;
property Caption;
property Color;
property EndColor: TColor read FEndColor write SetEndColor default clBlack;
property Font;
property GradientBlocks: Boolean read FGradientBlocks write SetGradientBlocks default False;
property HintColor;
property Maximum: Integer read FMaximum write SetMaximum default 100;
property Minimum: Integer read FMinimum write SetMinimum default 0;
property ParentColor;
property ParentFont;
property Position: Integer read FPosition write SetPosition default 0;
property ShowHint;
property Solid: Boolean read FSolid write SetSolid default False;
property StartColor: TColor read FStartColor write SetStartColor default clWhite;
property Step: Integer read FStep write FStep default 10;
property TextCentered: Boolean read FTextCentered write SetTextCentered default False;
property TextOption: TJvTextOption read FTextOption write SetTextOption default toNoText;
property Visible;
property OnClick;
property OnDblClick;
property OnDragOver;
property OnDragDrop;
property OnEndDrag;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnStartDrag;
property OnMouseEnter;
property OnMouseLeave;
property OnParentColorChange;
end;
implementation
{$IFDEF UNITVERSIONING}
uses
JclUnitVersioning;
{$ENDIF UNITVERSIONING}
constructor TJvSpecialProgress.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FBuffer := TBitmap.Create;
ControlStyle := ControlStyle + [csOpaque]; // SMM 20020604
FBorderStyle := bsNone;
FMaximum := 100;
FMinimum := 0;
FStartColor := clWhite;
FStart := clWhite;
FEndColor := clBlack;
FEnd := clBlack;
FPosition := 0;
FSolid := False;
FTextOption := toNoText;
FTextCentered := False;
FGradientBlocks := False;
FStep := 10;
Width := 150;
Height := 15;
FIsChanged := True;
end;
destructor TJvSpecialProgress.Destroy;
begin
FBuffer.Free;
inherited Destroy;
end;
procedure TJvSpecialProgress.ColorChanged;
begin
//inherited ColorChanged; calls CM_COLORCHANGED in VCL
{ No need to call inherited; Repaint is called in UpdateBuffer }
FIsChanged := True;
UpdateBuffer;
end;
procedure TJvSpecialProgress.FontChanged;
begin
//inherited FontChanged; calls CM_COLORCHANGED in VCL
{ No need to call inherited; Repaint is called in UpdateBuffer }
FBuffer.Canvas.Font := Font;
{ Only update if text is visible }
if TextOption = toNoText then
Exit;
FIsChanged := True;
UpdateBuffer;
end;
procedure TJvSpecialProgress.TextChanged;
begin
if TextOption in [toCaption, toFormat] then
begin
FIsChanged := True;
UpdateBuffer;
end;
inherited TextChanged;
end;
function TJvSpecialProgress.GetPercentDone: Longint;
begin
if FMaximum - FMinimum = 0 then
Result := 0
else
Result := 100 * (FPosition - FMinimum) div (FMaximum - FMinimum);
end;
procedure TJvSpecialProgress.Loaded;
begin
inherited Loaded;
UpdateBlock;
UpdateBuffer;
end;
procedure TJvSpecialProgress.Paint;
begin
if (FBuffer.Width <> ClientWidth) or (FBuffer.Height <> ClientHeight) then
begin
FIsChanged := True;
UpdateBlock;
UpdateBuffer;
end;
if (ClientWidth > 2) and (ClientHeight > 2) then
begin
FBuffer.Canvas.Start;
BitBlt(Canvas, 0, 0, ClientWidth, ClientHeight,
FBuffer.Canvas, 0, 0, SRCCOPY);
FBuffer.SaveToFile('JvQSpecialProgress.bmp');
FBuffer.Canvas.Stop;
end;
end;
procedure TJvSpecialProgress.PaintBackground;
begin
if FBlock >= ClientWidth - 2 then
Exit;
FBuffer.Canvas.Brush.Color := Color;
FBuffer.Canvas.Brush.Style := bsSolid;
FBuffer.Canvas.FillRect(Rect(FBlock + 1, 1, ClientWidth - 1, ClientHeight - 1));
end;
procedure TJvSpecialProgress.PaintNonSolid;
var
RedInc, GreenInc, BlueInc: Real;
Red, Green, Blue: Real;
X: Integer;
I, J: Integer;
LBlockCount: Integer;
begin
if (FBlock = 0) or (FBlockWidth = 0) then
Exit;
X := 1;
{ LBlockCount equals # blocks of size FBlockWidth }
if FLastBlockPartial then
LBlockCount := FBlockCount - 1
else
LBlockCount := FBlockCount;
{ Are the start and end colors equal? }
if FStart = FEnd then
begin
{ No gradient fill because the start color equals the end color }
FBuffer.Canvas.Brush.Color := FStart;
FBuffer.Canvas.Brush.Style := bsSolid;
for I := 0 to LBlockCount - 1 do
begin
{ Width of block is FBlockWidth -1 [-1 for seperator] }
FBuffer.Canvas.FillRect(Bounds(X, 1, FBlockWidth - 1, ClientHeight - 2));
Inc(X, FBlockWidth);
end;
if FLastBlockPartial then
{ Width of last block is FLastBlockWidth [no seperator] }
FBuffer.Canvas.FillRect(Bounds(X, 1, FLastBlockWidth, ClientHeight - 2));
end
else
begin
RedInc := (GetRValue(FEnd) - GetRValue(FStart)) / FBlock;
GreenInc := (GetGValue(FEnd) - GetGValue(FStart)) / FBlock;
BlueInc := (GetBValue(FEnd) - GetBValue(FStart)) / FBlock;
Red := GetRValue(FStart);
Green := GetGValue(FStart);
Blue := GetBValue(FStart);
FBuffer.Canvas.Brush.Style := bsSolid;
for I := 0 to LBlockCount - 1 do
begin
if not FGradientBlocks then
begin
FBuffer.Canvas.Brush.Color := RGB(Round(Red), Round(Green), Round(Blue));
Red := Red + RedInc * FBlockWidth;
Blue := Blue + BlueInc * FBlockWidth;
Green := Green + GreenInc * FBlockWidth;
{ Width of block is FBlockWidth -1 [-1 for seperator] }
FBuffer.Canvas.FillRect(Bounds(X, 1, FBlockWidth - 1, ClientHeight - 2));
end
else
begin
{ Fill the progressbar with slices of 1 width }
for J := 0 to FBlockWidth - 2 do
begin
FBuffer.Canvas.Brush.Color := RGB(Round(Red), Round(Green), Round(Blue));
Red := Red + RedInc;
Blue := Blue + BlueInc;
Green := Green + GreenInc;
FBuffer.Canvas.FillRect(Bounds(X + J, 1, 1, ClientHeight - 2));
end;
{ Seperator is not filled, but increase the colors }
Red := Red + RedInc;
Blue := Blue + BlueInc;
Green := Green + GreenInc;
end;
Inc(X, FBlockWidth);
end;
if FLastBlockPartial then
begin
if not FGradientBlocks then
begin
FBuffer.Canvas.Brush.Color := RGB(Round(Red), Round(Green), Round(Blue));
{ Width of last block is FLastBlockWidth [no seperator] }
FBuffer.Canvas.FillRect(Bounds(X, 1, FLastBlockWidth, ClientHeight - 2));
end
else
{ Width of last block is FLastBlockWidth [no seperator] }
for J := 0 to FLastBlockWidth - 1 do
begin
FBuffer.Canvas.Brush.Color := RGB(Round(Red), Round(Green), Round(Blue));
Red := Red + RedInc;
Blue := Blue + BlueInc;
Green := Green + GreenInc;
FBuffer.Canvas.FillRect(Bounds(X + J, 1, 1, ClientHeight - 2));
end;
end;
end;
{ Draw the block seperators }
X := FBlockWidth;
FBuffer.Canvas.Brush.Color := Color;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -