📄 jvqxslider.pas
字号:
{**************************************************************************************************}
{ WARNING: JEDI preprocessor generated unit. Do not edit. }
{**************************************************************************************************}
{-----------------------------------------------------------------------------
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: JvxSlider.PAS, released on 2002-07-04.
The Initial Developers of the Original Code are: Fedor Koshevnikov, Igor Pavluk and Serge Korolev
Copyright (c) 1997, 1998 Fedor Koshevnikov, Igor Pavluk and Serge Korolev
Copyright (c) 2001,2002 SGB Software
All Rights Reserved.
You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.sourceforge.net
Known Issues:
-----------------------------------------------------------------------------}
// $Id: JvQxSlider.pas,v 1.4 2005/02/04 08:09:28 marquardt Exp $
{$I jvcl.inc}
unit JvQxSlider;
interface
uses
SysUtils, Classes,
QForms, QControls, QExtCtrls, QGraphics, QMenus,
JvQComponent, JvQExControls;
type
TNumThumbStates = 1..2;
TSliderOrientation = (soHorizontal, soVertical);
TSliderOption = (soShowFocus, soShowPoints, soSmooth,
soRulerOpaque, soThumbOpaque);
TSliderOptions = set of TSliderOption;
TSliderImage = (siHThumb, siHRuler, siVThumb, siVRuler);
TSliderImages = set of TSliderImage;
TSliderImageArray = array [TSliderImage] of TBitmap;
TJumpMode = (jmNone, jmHome, jmEnd, jmNext, jmPrior);
TJvCustomSlider = class(TJvCustomControl)
private
FUserImages: TSliderImages;
FImages: TSliderImageArray;
FEdgeSize: Integer;
FRuler: TBitmap;
FPaintBuffered: Boolean;
FRulerOrg: TPoint;
FThumbRect: TRect;
FThumbDown: Boolean;
FNumThumbStates: TNumThumbStates;
FPointsRect: TRect;
FOrientation: TSliderOrientation;
FOptions: TSliderOptions;
FBevelStyle: TPanelBevel;
FBevelWidth: Integer;
FMinValue: Longint;
FMaxValue: Longint;
FIncrement: Longint;
FValue: Longint;
FHit: Integer;
FFocused: Boolean;
FSliding: Boolean;
FTracking: Boolean;
FTimerActive: Boolean;
FMousePos: TPoint;
FStartJump: TJumpMode;
FReadOnly: Boolean;
FOnChange: TNotifyEvent;
FOnChanged: TNotifyEvent;
FOnDrawPoints: TNotifyEvent;
function GetImage(Index: Integer): TBitmap;
procedure SetImage(Index: Integer; Value: TBitmap);
procedure SliderImageChanged(Sender: TObject);
procedure SetEdgeSize(Value: Integer);
function GetNumThumbStates: TNumThumbStates;
procedure SetNumThumbStates(Value: TNumThumbStates);
procedure SetBevelStyle(Value: TPanelBevel);
procedure SetOrientation(Value: TSliderOrientation);
procedure SetOptions(Value: TSliderOptions);
procedure SetMinValue(Value: Longint);
procedure SetMaxValue(Value: Longint);
procedure SetIncrement(Value: Longint);
procedure SetReadOnly(Value: Boolean);
function GetThumbOffset: Integer;
procedure SetThumbOffset(Value: Integer);
procedure SetValue(Value: Longint);
procedure ThumbJump(Jump: TJumpMode);
function GetThumbPosition(var Offset: Integer): TPoint;
function JumpTo(X, Y: Integer): TJumpMode;
procedure InvalidateThumb;
procedure StopTracking;
procedure TimerTrack;
function StoreImage(Index: Integer): Boolean;
procedure CreateElements;
procedure BuildRuler(R: TRect);
procedure AdjustElements;
procedure ReadUserImages(Stream: TStream);
procedure WriteUserImages(Stream: TStream);
procedure InternalDrawPoints(ACanvas: TCanvas; PointsStep, PointsHeight,
ExtremePointsHeight: Longint);
procedure DrawThumb(Canvas: TCanvas; Origin: TPoint; Highlight: Boolean);
function GetValueByOffset(Offset: Integer): Longint;
function GetOffsetByValue(Value: Longint): Integer;
function GetRulerLength: Integer;
{ TODO -cVisuaCLX : implement message handler substitutions }
protected
procedure DoBoundsChanged; override;
procedure DoFocusChanged(Control: TWinControl); override;
procedure DoGetDlgCode(var Code: TDlgCodes); override;
procedure EnabledChanged; override;
procedure AlignControls(AControl: TControl; var Rect: TRect); override;
procedure DefineProperties(Filer: TFiler); override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure Loaded; override;
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;
function CanModify: Boolean; virtual;
function GetSliderRect: TRect; virtual;
function GetSliderValue: Longint; virtual;
procedure Change; dynamic;
procedure Changed; dynamic;
procedure Sized; virtual;
procedure RangeChanged; virtual;
procedure SetRange(Min, Max: Longint);
procedure ThumbMouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); virtual;
procedure ThumbMouseMove(Shift: TShiftState; X, Y: Integer); virtual;
procedure ThumbMouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); virtual;
property ThumbOffset: Integer read GetThumbOffset write SetThumbOffset;
property SliderRect: TRect read GetSliderRect;
property BevelStyle: TPanelBevel read FBevelStyle write SetBevelStyle
default bvNone;
property ImageHThumb: TBitmap index Ord(siHThumb) read GetImage
write SetImage stored StoreImage;
property ImageHRuler: TBitmap index Ord(siHRuler) read GetImage
write SetImage stored StoreImage;
property ImageVThumb: TBitmap index Ord(siVThumb) read GetImage
write SetImage stored StoreImage;
property ImageVRuler: TBitmap index Ord(siVRuler) read GetImage
write SetImage stored StoreImage;
property NumThumbStates: TNumThumbStates read GetNumThumbStates
write SetNumThumbStates default 2;
property Orientation: TSliderOrientation read FOrientation
write SetOrientation default soHorizontal;
property EdgeSize: Integer read FEdgeSize write SetEdgeSize default 2;
property Options: TSliderOptions read FOptions write SetOptions
default [soShowFocus, soShowPoints, soSmooth];
property ReadOnly: Boolean read FReadOnly write SetReadOnly default False;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnChanged: TNotifyEvent read FOnChanged write FOnChanged;
property OnDrawPoints: TNotifyEvent read FOnDrawPoints write FOnDrawPoints;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure DefaultDrawPoints(PointsStep, PointsHeight,
ExtremePointsHeight: Longint); virtual;
property Canvas;
property Increment: Longint read FIncrement write SetIncrement default 10;
property MinValue: Longint read FMinValue write SetMinValue default 0;
property MaxValue: Longint read FMaxValue write SetMaxValue default 100;
property Value: Longint read FValue write SetValue default 0;
end;
TJvxSlider = class(TJvCustomSlider)
published
property Align;
property BevelStyle;
property Color;
property Cursor;
property DragMode;
property DragCursor;
property Enabled;
property ImageHThumb;
property ImageHRuler;
property ImageVThumb;
property ImageVRuler;
property Increment;
property MinValue;
property MaxValue;
property NumThumbStates;
property Orientation;
{ ensure Orientation is published before EdgeSize }
property EdgeSize;
property Options;
property ParentColor;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property TabOrder;
property TabStop default True;
property Value;
property Visible;
property Anchors;
property Constraints;
property DragKind;
property OnChange;
property OnChanged;
property OnDrawPoints;
property OnClick;
property OnDblClick;
property OnEnter;
property OnExit;
property OnMouseMove;
property OnMouseDown;
property OnMouseUp;
property OnKeyDown;
property OnKeyUp;
property OnKeyPress;
property OnDragOver;
property OnDragDrop;
property OnEndDrag;
property OnStartDrag;
property OnContextPopup;
property OnMouseWheelDown;
property OnMouseWheelUp;
property OnEndDock;
property OnStartDock;
end;
TJvSliderImages = class;
TJvCustomTrackBar = class(TJvCustomSlider)
private
FImages: TJvSliderImages;
protected
property Images: TJvSliderImages read FImages write FImages;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
TJvSliderImages = class(TPersistent)
private
FSlider: TJvCustomSlider;
function GetNumThumbStates: TNumThumbStates;
procedure SetNumThumbStates(Value: TNumThumbStates);
function GetEdgeSize: Integer;
procedure SetEdgeSize(Value: Integer);
function GetImage(Index: Integer): TBitmap;
procedure SetImage(Index: Integer; Value: TBitmap);
function StoreImage(Index: Integer): Boolean;
published
property HorzThumb: TBitmap index Ord(siHThumb) read GetImage
write SetImage stored StoreImage;
property HorzRuler: TBitmap index Ord(siHRuler) read GetImage
write SetImage stored StoreImage;
property VertThumb: TBitmap index Ord(siVThumb) read GetImage
write SetImage stored StoreImage;
property VertRuler: TBitmap index Ord(siVRuler) read GetImage
write SetImage stored StoreImage;
property NumThumbStates: TNumThumbStates read GetNumThumbStates
write SetNumThumbStates default 2;
property EdgeSize: Integer read GetEdgeSize write SetEdgeSize default 2;
end;
implementation
uses
QConsts,
Math,
JvQJVCLUtils, JvQJCLUtils, JvQConsts, JvQTypes, JvQThemes;
{$IFDEF MSWINDOWS}
{$R ..\Resources\JvxSlider.res}
{$ENDIF MSWINDOWS}
{$IFDEF LINUX}
{$R ../Resources/JvxSlider.res}
{$ENDIF LINUX}
//=== TJvCustomSlider ========================================================
const
ImagesResNames: array [TSliderImage] of PChar =
('JvW95HTB', 'JvW95HRL', 'JvW95VTB', 'JvW95VRL');
Indent = 6;
JumpInterval = 400;
constructor TJvCustomSlider.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlState := ControlState + [csCreating];
ControlStyle := [csClickEvents, csCaptureMouse,
csDoubleClicks, csOpaque]; // csAcceptsControls
IncludeThemeStyle(Self, [csParentBackground]);
Width := 150;
Height := 40;
FNumThumbStates := 2;
FBevelWidth := 1;
FOrientation := soHorizontal;
FOptions := [soShowFocus, soShowPoints, soSmooth];
FEdgeSize := 2;
FMinValue := 0;
FMaxValue := 100;
FIncrement := 10;
TabStop := True;
CreateElements;
ControlState := ControlState - [csCreating];
end;
destructor TJvCustomSlider.Destroy;
var
I: TSliderImage;
begin
FOnChange := nil;
FOnChanged := nil;
FOnDrawPoints := nil;
FRuler.Free;
for I := Low(FImages) to High(FImages) do
begin
FImages[I].OnChange := nil;
FImages[I].Free;
end;
inherited Destroy;
end;
procedure TJvCustomSlider.Loaded;
var
I: TSliderImage;
begin
inherited Loaded;
for I := Low(FImages) to High(FImages) do
if I in FUserImages then
SetImage(Ord(I), FImages[I]);
end;
procedure TJvCustomSlider.AlignControls(AControl: TControl; var Rect: TRect);
var
BevelSize: Integer;
begin
BevelSize := 0;
if BevelStyle <> bvNone then
Inc(BevelSize, FBevelWidth);
InflateRect(Rect, -BevelSize, -BevelSize);
inherited AlignControls(AControl, Rect);
end;
procedure TJvCustomSlider.Paint;
var
R: TRect;
TopColor, BottomColor, TransColor: TColor;
HighlightThumb: Boolean;
P: TPoint;
Offset: Integer;
begin
if csPaintCopy in ControlState then
begin
Offset := GetOffsetByValue(GetSliderValue);
P := GetThumbPosition(Offset);
end
else
P := Point(FThumbRect.Left, FThumbRect.Top);
R := GetClientRect;
if BevelStyle <> bvNone then
begin
TopColor := clBtnHighlight;
if BevelStyle = bvLowered then
TopColor := clBtnShadow;
BottomColor := clBtnShadow;
if BevelStyle = bvLowered then
BottomColor := clBtnHighlight;
Frame3D(Canvas, R, TopColor, BottomColor, FBevelWidth);
end;
if (csOpaque in ControlStyle) then
DrawThemedBackground(Self, Canvas, R, Self.Color);
if FRuler.Width > 0 then
begin
if soRulerOpaque in Options then
TransColor := clNone
else
TransColor := FRuler.TransparentColor;
DrawBitmapTransparent(Canvas, FRulerOrg.X, FRulerOrg.Y, FRuler,
TransColor);
end;
if (soShowFocus in Options) and FFocused and
not (csDesigning in ComponentState) then
begin
R := SliderRect;
InflateRect(R, -2, -2);
Canvas.DrawFocusRect(R);
end;
if (soShowPoints in Options) then
begin
if Assigned(FOnDrawPoints) then
FOnDrawPoints(Self)
else
InternalDrawPoints(Canvas, Increment, 3, 5);
end;
if csPaintCopy in ControlState then
HighlightThumb := not Enabled
else
HighlightThumb := FThumbDown or not Enabled;
DrawThumb(Canvas, P, HighlightThumb);
end;
function TJvCustomSlider.CanModify: Boolean;
begin
Result := True;
end;
function TJvCustomSlider.GetSliderValue: Longint;
begin
Result := FValue;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -