📄 jvqbutton.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: JvButton.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].
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: JvQButton.pas,v 1.30 2005/02/06 14:06:01 asnepvangers Exp $
unit JvQButton;
{$I jvcl.inc}
interface
uses
Qt,
QWindows, QMessages, Classes, QGraphics, QControls, QMenus, QButtons,
JvQComponent, JvQConsts, JvQTypes, JvQExStdCtrls;
type
TJvButtonMouseState = (bsMouseInside, bsMouseDown);
TJvButtonMouseStates = set of TJvButtonMouseState;
TJvCustomGraphicButton = class(TJvGraphicControl)
private
FStates: TJvButtonMouseStates;
FBuffer: TBitmap;
FFlat: Boolean;
FDropDownMenu: TPopupMenu;
FDown: Boolean;
FForceSameSize: Boolean;
FAllowAllUp: Boolean;
FGroupIndex: Integer;
FHotTrack: Boolean;
FHotFont: TFont;
FHotTrackFontOptions: TJvTrackFontOptions;
FOnDropDownMenu: TContextPopupEvent;
FDropArrow: Boolean;
FOnDropDownClose: TNotifyEvent;
function GetPattern: TBitmap;
procedure SetFlat(const Value: Boolean);
procedure SetDown(Value: Boolean);
procedure CMButtonPressed(var Msg: TCMButtonPressed); message CM_BUTTONPRESSED;
procedure CMForceSize(var Msg: TCMForceSize); message CM_FORCESIZE;
procedure CMSysColorChange(var Msg: TMessage); message CM_SYSCOLORCHANGE;
procedure SetForceSameSize(const Value: Boolean);
procedure SetAllowAllUp(const Value: Boolean);
procedure SetGroupIndex(const Value: Integer);
procedure SetHotFont(const Value: TFont);
procedure SetHotTrackFontOptions(const Value: TJvTrackFontOptions);
procedure SetDropArrow(const Value: Boolean);
procedure SetDropDownMenu(const Value: TPopupMenu);
protected
procedure ButtonPressed(Sender: TJvCustomGraphicButton; AGroupIndex: Integer); virtual;
procedure ForceSize(Sender: TControl; AWidth, AHeight: Integer);
function DoDropDownMenu(Button: TMouseButton; Shift: TShiftState; X, Y: Integer): Boolean; virtual;
procedure DropDownClose;
procedure UpdateExclusive;
procedure Notification(AComponent: TComponent; Operation: TOperation); 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 MouseEnter(Control: TControl); override;
procedure MouseLeave(Control: TControl); override;
procedure Paint; override;
procedure PaintButton(Canvas: TCanvas); virtual;
procedure PaintFrame(Canvas: TCanvas); virtual;
function InsideBtn(X, Y: Integer): Boolean; virtual;
function WantKey(Key: Integer; Shift: TShiftState;
const KeyText: WideString): Boolean; override;
procedure EnabledChanged; override;
procedure FontChanged; override;
procedure RepaintBackground; virtual;
procedure TextChanged; override;
property AllowAllUp: Boolean read FAllowAllUp write SetAllowAllUp default False;
property GroupIndex: Integer read FGroupIndex write SetGroupIndex default 0;
property MouseStates: TJvButtonMouseStates read FStates write FStates default [];
property ForceSameSize: Boolean read FForceSameSize write SetForceSameSize default False;
property Pattern: TBitmap read GetPattern;
property Flat: Boolean read FFlat write SetFlat default False;
property HotTrack: Boolean read FHotTrack write FHotTrack default False;
property HotTrackFont: TFont read FHotFont write SetHotFont;
property HotTrackFontOptions: TJvTrackFontOptions read FHotTrackFontOptions write SetHotTrackFontOptions default
DefaultTrackFontOptions;
property Down: Boolean read FDown write SetDown default False;
property DropDownMenu: TPopupMenu read FDropDownMenu write SetDropDownMenu;
property DropArrow: Boolean read FDropArrow write SetDropArrow default False;
property OnDropDownMenu: TContextPopupEvent read FOnDropDownMenu write FOnDropDownMenu;
property OnDropDownClose: TNotifyEvent read FOnDropDownClose write FOnDropDownClose;
public
procedure Click; override;
procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure DrawDropArrow(Canvas: TCanvas; ArrowRect: TRect); virtual;
end;
TJvCustomButton = class(TJvExButton)
private
FDropDownMenu: TPopupMenu;
FHotTrack: Boolean;
FHotFont: TFont;
FFontSave: TFont;
FWordWrap: Boolean;
FForceSameSize: Boolean;
FHotTrackFontOptions: TJvTrackFontOptions;
FOnDropDownMenu: TContextPopupEvent;
FDropArrow: Boolean;
procedure SetHotFont(const Value: TFont);
procedure SetWordWrap(const Value: Boolean);
procedure SetForceSameSize(const Value: Boolean);
procedure CMForceSize(var Msg: TCMForceSize); message CM_FORCESIZE;
procedure SetHotTrackFontOptions(const Value: TJvTrackFontOptions);
procedure SetDropArrow(const Value: Boolean);
procedure SetDropDownMenu(const Value: TPopupMenu);
protected
function DoDropDownMenu(X, Y: Integer): Boolean; virtual;
procedure ForceSize(Sender: TControl; AWidth, AHeight: Integer);
procedure MouseEnter(Control: TControl); override;
procedure MouseLeave(Control: TControl); override;
procedure FontChanged; override;
function GetRealCaption: string; dynamic;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
property WordWrap: Boolean read FWordWrap write SetWordWrap default True;
property ForceSameSize: Boolean read FForceSameSize write SetForceSameSize default False;
property DropArrow: Boolean read FDropArrow write SetDropArrow default False;
property DropDownMenu: TPopupMenu read FDropDownMenu write SetDropDownMenu;
property HotTrack: Boolean read FHotTrack write FHotTrack default False;
property HotTrackFont: TFont read FHotFont write SetHotFont;
property HotTrackFontOptions: TJvTrackFontOptions read FHotTrackFontOptions write SetHotTrackFontOptions default
DefaultTrackFontOptions;
property HintColor;
property OnParentColorChange;
property OnDropDownMenu: TContextPopupEvent read FOnDropDownMenu write FOnDropDownMenu;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Click;override;
procedure DrawDropArrow(Canvas: TCanvas; ArrowRect: TRect); virtual;
procedure SetBounds(ALeft: Integer; ATop: Integer; AWidth: Integer; AHeight: Integer); override;
end;
// TJvDropDownButton draws a DropDown button with the DropDown glyph
// (also themed). It ignores the properties Glyph and Flat
TJvDropDownButton = class(TSpeedButton)
protected
procedure Paint; override;
public
constructor Create(AOwner: TComponent); override;
end;
implementation
uses
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
SysUtils, QForms,
JvQJVCLUtils, JvQThemes, Math;
const
JvBtnLineSeparator = '|';
var
GlobalPattern: TBitmap = nil;
function CreateBrushPattern: TBitmap;
var
X, Y: Integer;
begin
if GlobalPattern = nil then
begin
GlobalPattern := TBitmap.Create;
try
GlobalPattern.Width := 8; { must have this size }
GlobalPattern.Height := 8;
with GlobalPattern.Canvas do
begin
Brush.Style := bsSolid;
Brush.Color := clBtnFace;
FillRect(Rect(0, 0, GlobalPattern.Width, GlobalPattern.Height));
for Y := 0 to 7 do
for X := 0 to 7 do
if (Y mod 2) = (X mod 2) then { toggles between even/odd pixels }
Pixels[X, Y] := clWhite; { on even/odd rows }
end;
except
FreeAndNil(GlobalPattern);
end;
end;
Result := GlobalPattern;
end;
//=== { TJvCustomGraphicButton } =============================================
constructor TJvCustomGraphicButton.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle -
[csOpaque, csDoubleClicks , csCaptureMouse ];
FStates := [];
SetBounds(0, 0, 40, 40);
FBuffer := TBitmap.Create;
FFlat := False;
FDropArrow := False;
FForceSameSize := False;
FHotFont := TFont.Create;
FHotTrackFontOptions := DefaultTrackFontOptions;
end;
destructor TJvCustomGraphicButton.Destroy;
begin
FBuffer.Free;
FHotFont.Free;
inherited Destroy;
end;
procedure TJvCustomGraphicButton.DrawDropArrow(Canvas: TCanvas; ArrowRect: TRect);
var
I: Integer;
begin
if not Enabled then
Canvas.Pen.Color := clInactiveCaption
else
Canvas.Pen.Color := clWindowText;
for I := 0 to 3 do
begin
if ArrowRect.Left + I <= ArrowRect.Right - I then
begin
Canvas.MoveTo(ArrowRect.Left + I, ArrowRect.Top + I);
Canvas.LineTo(ArrowRect.Right - I, ArrowRect.Top + I);
end;
end;
end;
{ Handle speedkeys (Alt + key) }
function TJvCustomGraphicButton.WantKey(Key: Integer; Shift: TShiftState;
const KeyText: WideString): Boolean;
begin
Result := IsAccel(Key, Caption) and Enabled and (Shift * KeyboardShiftStates = [ssAlt]);
if Result then
Click
else
Result := inherited WantKey(Key, Shift, KeyText);
end;
procedure TJvCustomGraphicButton.EnabledChanged;
begin
inherited EnabledChanged;
if not Enabled then
FStates := [];
RepaintBackground;
end;
procedure TJvCustomGraphicButton.MouseEnter(Control: TControl);
begin
if csDesigning in ComponentState then
Exit;
if Enabled and not MouseOver then
begin
Include(FStates, bsMouseInside);
inherited MouseEnter(Control);
if Flat then
RepaintBackground;
if HotTrack then
Repaint;
end;
end;
procedure TJvCustomGraphicButton.MouseLeave(Control: TControl);
begin
if Enabled and MouseOver then
begin
Exclude(FStates, bsMouseInside);
inherited MouseLeave(Control);
if Flat then
RepaintBackground;
if HotTrack then
Repaint;
end;
end;
procedure TJvCustomGraphicButton.Paint;
var
ArrowRect: TRect;
begin
// FBuffer.Width := Width;
// FBuffer.Height := Height;
PaintFrame(Canvas);
PaintButton(Canvas);
if DropArrow and Assigned(DropDownMenu) then
begin
ArrowRect := Rect(Width - 16, Height div 2, Width - 9, Height div 2 + 9);
if bsMouseDown in FStates then OffsetRect(ArrowRect, 1, 1);
DrawDropArrow(Canvas, ArrowRect);
end;
// BitBlt(Canvas.Handle,0,0,Width,Height,FBuffer.Canvas.Handle,0,0,SRCCOPY);
end;
procedure TJvCustomGraphicButton.PaintFrame(Canvas: TCanvas);
begin
// do nothing
end;
procedure TJvCustomGraphicButton.PaintButton(Canvas: TCanvas);
begin
if (bsMouseInside in FStates) and HotTrack then
Canvas.Font := FHotFont
else
Canvas.Font := Font;
end;
function TJvCustomGraphicButton.InsideBtn(X, Y: Integer): Boolean;
begin
Result := PtInRect(Rect(0, 0, Width, Height), Point(X, Y));
end;
procedure TJvCustomGraphicButton.MouseDown(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
Tmp: TPoint;
begin
if not Enabled then
Exit;
inherited MouseDown(Button, Shift, X, Y);
if InsideBtn(X, Y) then
begin
FStates := [bsMouseDown, bsMouseInside];
RepaintBackground;
end;
Tmp := ClientToScreen(Point(0, Height));
DoDropDownMenu(Button, Shift, Tmp.X, Tmp.Y);
end;
procedure TJvCustomGraphicButton.MouseMove(Shift: TShiftState;
X, Y: Integer);
begin
inherited MouseMove(Shift, X, Y);
if MouseCapture then
begin
if not InsideBtn(X, Y) then
begin
Exclude(FStates, bsMouseInside);
RepaintBackground;
end
else
begin
Include(FStates, bsMouseInside);
RepaintBackground;
end;
end;
end;
procedure TJvCustomGraphicButton.MouseUp(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if not Enabled then
Exit;
inherited MouseUp(Button, Shift, X, Y);
Exclude(FStates, bsMouseDown);
RepaintBackground;
end;
function TJvCustomGraphicButton.DoDropDownMenu(Button: TMouseButton; Shift: TShiftState; X, Y: Integer): Boolean;
var
Handled: Boolean;
begin
Result := (Button = mbLeft) and (DropDownMenu <> nil);
if Result then
begin
DropDownMenu.PopupComponent := Self;
case DropDownMenu.Alignment of
paRight:
Inc(X, Width);
paCenter:
Inc(X, Width div 2);
end;
Handled := False;
if Assigned(FOnDropDownMenu) then
FOnDropDownMenu(Self, Point(X, Y), Handled);
if not Handled then
DropDownMenu.Popup(X, Y)
else
Exit;
repeat
Application.ProcessMessages;
until not QWidget_isVisible(DropDownMenu.Handle);
{ release button }
MouseUp(Button, Shift, X, Y);
DropDownClose;
end;
end;
procedure TJvCustomGraphicButton.SetFlat(const Value: Boolean);
begin
if FFlat <> Value then
begin
FFlat := Value;
if FFlat then
ControlStyle := ControlStyle - [csOpaque]
else
ControlStyle := ControlStyle + [csOpaque];
RepaintBackground;
end;
end;
procedure TJvCustomGraphicButton.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (AComponent = DropDownMenu) then
DropDownMenu := nil;
end;
procedure TJvCustomGraphicButton.SetDown(Value: Boolean);
begin
if GroupIndex = 0 then
Value := False;
if FDown <> Value then
begin
if FDown and not AllowAllUp then
Exit;
FDown := Value;
UpdateExclusive;
Invalidate;
end;
end;
procedure TJvCustomGraphicButton.SetForceSameSize(const Value: Boolean);
begin
if FForceSameSize <> Value then
begin
FForceSameSize := Value;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -