📄 jvqrollout.pas
字号:
//=== { TJvRollOutColors } ===================================================
constructor TJvRollOutColors.Create;
begin
inherited Create;
FButtonBottom := clBtnShadow;
FButtonTop := clBtnHighlight;
FButtonColor := clBtnFace;
FHotTrackText := clWindowText;
FColor := clBtnFace;
FFrameBottom := clBtnHighlight;
FFrameTop := clBtnShadow;
end;
procedure TJvRollOutColors.Change;
begin
if Assigned(FOnChange) then
FOnChange(Self);
end;
procedure TJvRollOutColors.SetButtonBottom(const Value: TColor);
begin
if FButtonBottom <> Value then
begin
FButtonBottom := Value;
Change;
end;
end;
procedure TJvRollOutColors.SetButtonColor(const Value: TColor);
begin
if FButtonColor <> Value then
begin
FButtonColor := Value;
Change;
end;
end;
procedure TJvRollOutColors.SetButtonTop(const Value: TColor);
begin
if FButtonTop <> Value then
begin
FButtonTop := Value;
Change;
end;
end;
procedure TJvRollOutColors.SetColor(const Value: TColor);
begin
if FColor <> Value then
begin
FColor := Value;
Change;
end;
end;
procedure TJvRollOutColors.SetFrameBottom(const Value: TColor);
begin
if FFrameBottom <> Value then
begin
FFrameBottom := Value;
Change;
end;
end;
procedure TJvRollOutColors.SetFrameTop(const Value: TColor);
begin
if FFrameTop <> Value then
begin
FFrameTop := Value;
Change;
end;
end;
procedure TJvRollOutColors.SetHotTrackText(const Value: TColor);
begin
if FHotTrackText <> Value then
begin
FHotTrackText := Value;
Change;
end;
end;
//=== { TJvCustomRollOut } ===================================================
constructor TJvCustomRollOut.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
IncludeThemeStyle(Self, [csNeedsBorderPaint, csParentBackground]);
FImageOptions := TJvRollOutImageOptions.Create;
FImageOptions.FOwner := Self;
FImageOptions.OnChange := DoImageOptionsChange;
FColors := TJvRollOutColors.Create;
FColors.OnChange := DoColorsChange;
FToggleAnywhere := True;
FGroupIndex := 0;
FCollapsed := False;
FMouseDown := False;
FInsideButton := False;
FChildOffset := 0;
FButtonHeight := 20;
FPlacement := plTop;
SetBounds(0, 0, 145, 170);
FAWidth := 145;
FAHeight := 170;
FCWidth := 22;
FCHeight := 22;
FShowFocus := True;
QWidget_setBackgroundMode(Handle, QWidgetBackgroundMode_NoBackground);
end;
destructor TJvCustomRollOut.Destroy;
begin
FreeAndNil(FImageOptions);
FreeAndNil(FTabStops);
FreeAndNil(FColors);
inherited Destroy;
end;
procedure TJvCustomRollOut.Click;
begin
if (Action = nil) and (MouseIsOnButton or ToggleAnywhere) then
Collapsed := not FCollapsed;
inherited Click;
RedrawControl(False);
end;
procedure TJvCustomRollOut.CreateWnd;
begin
inherited CreateWnd;
if not Collapsed then
UpdateGroup;
end;
procedure TJvCustomRollOut.AlignControls(AControl: TControl; var Rect: TRect);
begin
Rect.Left := Rect.Left + ChildOffset;
if FPlacement = plTop then
Rect.Top := Rect.Top + FButtonHeight
else
Rect.Left := Rect.Left + FButtonHeight;
inherited AlignControls(AControl, Rect);
end;
procedure TJvCustomRollOut.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
inherited MouseDown(Button, Shift, X, Y);
if not FMouseDown then
begin
FMouseDown := True;
RedrawControl(False);
if CanFocus {and not (csDesigning in ComponentState)} then
SetFocus;
end;
end;
procedure TJvCustomRollOut.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
inherited MouseUp(Button, Shift, X, Y);
if FMouseDown then
begin
FMouseDown := False;
RedrawControl(False);
end;
end;
procedure TJvCustomRollOut.MouseMove(Shift: TShiftState; X, Y: Integer);
var
B: Boolean;
begin
B := FInsideButton;
inherited MouseMove(Shift, X, Y);
FInsideButton := PtInRect(FButtonRect, Point(X, Y));
if FInsideButton <> B then
RedrawControl(False);
end;
procedure TJvCustomRollOut.RedrawControl(DrawAll: Boolean);
begin
if DrawAll then
begin
Canvas.Brush.Style := bsSolid;
Invalidate;
end
else
begin
Canvas.Brush.Style := bsClear;
DrawButtonFrame;
end;
end;
procedure TJvCustomRollOut.SetGroupIndex(Value: Integer);
begin
if FGroupIndex <> Value then
begin
FGroupIndex := Value;
if not Collapsed then
UpdateGroup;
end;
end;
procedure TJvCustomRollOut.SetPlacement(Value: TJvPlacement);
begin
if FPlacement <> Value then
begin
FPlacement := Value;
if Collapsed then
begin
if FPlacement = plTop then
Height := FCHeight
else
Width := FCWidth;
end
else
begin
if FPlacement = plTop then
Height := FAHeight
else
Width := FAWidth;
end;
if FPlacement = plTop then
FButtonRect := Rect(1, 1, Width - 1, FButtonHeight - 1)
else
FButtonRect := Rect(1, 1, FButtonHeight - 1, Height - 1);
Realign;
RedrawControl(True);
end;
end;
procedure TJvCustomRollOut.SetCollapsed(Value: Boolean);
begin
if FCollapsed <> Value then
begin
FCollapsed := Value;
if Value then
begin
if Placement = plTop then
ChangeHeight(FCHeight)
else
ChangeWidth(FCWidth);
DoCollapse;
end
else
begin
if Placement = plTop then
ChangeHeight(FAHeight)
else
ChangeWidth(FAWidth);
DoExpand;
UpdateGroup;
end;
CheckChildTabStops;
end;
end;
procedure TJvCustomRollOut.ChangeHeight(NewHeight: Integer);
var
OldHeight: Integer;
begin
OldHeight := Height;
Parent.DisableAlign;
DisableAlign;
try
Height := NewHeight;
if Align = alBottom then
Top := Top + (OldHeight - NewHeight);
finally
EnableAlign;
Parent.EnableAlign;
end;
end;
procedure TJvCustomRollOut.ChangeWidth(NewWidth: Integer);
var
OldWidth: Integer;
begin
Parent.DisableAlign;
DisableAlign;
try
OldWidth := Width;
Width := NewWidth;
if Align = alRight then
Left := Left + (OldWidth - NewWidth);
finally
EnableAlign;
Parent.EnableAlign;
end;
end;
procedure TJvCustomRollOut.DoExpand;
begin
if Assigned(FOnExpand) then
FOnExpand(Self);
end;
procedure TJvCustomRollOut.DoCollapse;
begin
if Assigned(FOnCollapse) then
FOnCollapse(Self);
end;
procedure TJvCustomRollOut.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
begin
if FCollapsed then
begin
if Placement = plTop then
FCHeight := AHeight
else
FCWidth := AWidth;
end
else
begin
if Placement = plTop then
FAHeight := AHeight
else
FAWidth := AWidth;
end;
inherited SetBounds(ALeft, ATop, AWidth, AHeight);
if not Collapsed then
UpdateGroup;
end;
procedure TJvCustomRollOut.DefineProperties(Filer: TFiler);
begin
inherited DefineProperties(Filer);
Filer.DefineProperty('FAWidth', ReadAWidth, WriteAWidth, True);
Filer.DefineProperty('FAHeight', ReadAHeight, WriteAHeight, True);
Filer.DefineProperty('FCWidth', ReadCWidth, WriteCWidth, True);
Filer.DefineProperty('FCHeight', ReadCHeight, WriteCHeight, True);
end;
procedure TJvCustomRollOut.WriteAWidth(Writer: TWriter);
begin
Writer.WriteInteger(FAWidth);
end;
procedure TJvCustomRollOut.WriteAHeight(Writer: TWriter);
begin
Writer.WriteInteger(FAHeight);
end;
procedure TJvCustomRollOut.WriteCWidth(Writer: TWriter);
begin
Writer.WriteInteger(FCWidth);
end;
procedure TJvCustomRollOut.WriteCHeight(Writer: TWriter);
begin
Writer.WriteInteger(FCHeight);
end;
procedure TJvCustomRollOut.ReadAWidth(Reader: TReader);
begin
FAWidth := Reader.ReadInteger;
if not Collapsed and (Placement = plLeft) then
SetBounds(Left, Top, FAWidth, Height);
end;
procedure TJvCustomRollOut.ReadAHeight(Reader: TReader);
begin
FAHeight := Reader.ReadInteger;
if not Collapsed and (Placement = plTop) then
SetBounds(Left, Top, Width, FAHeight);
end;
procedure TJvCustomRollOut.ReadCWidth(Reader: TReader);
begin
FCWidth := Reader.ReadInteger;
if Collapsed and (Placement = plLeft) then
SetBounds(Left, Top, FCWidth, Height);
end;
procedure TJvCustomRollOut.ReadCHeight(Reader: TReader);
begin
FCHeight := Reader.ReadInteger;
if Collapsed and (Placement = plTop) then
SetBounds(Left, Top, Width, FCHeight);
end;
procedure TJvCustomRollOut.SetButtonHeight(Value: Integer);
begin
if FButtonHeight <> Value then
begin
FButtonHeight := Value;
FCHeight := Value + 2;
if FPlacement = plTop then
FButtonRect := Rect(BevelWidth, BevelWidth, Width - BevelWidth, FButtonHeight + BevelWidth)
else
FButtonRect := Rect(BevelWidth, BevelWidth, FButtonHeight + BevelWidth, Height - BevelWidth);
Realign;
RedrawControl(True);
end;
end;
procedure TJvCustomRollOut.SetChildOffset(Value: Integer);
begin
if FChildOffset <> Value then
begin
FChildOffset := Value;
Realign;
// R := ClientRect;
// AlignControls(nil,R);
end;
end;
procedure TJvCustomRollOut.MouseEnter(Control: TControl);
begin
inherited MouseEnter(Control);
if csDesigning in ComponentState then
Exit;
RedrawControl(False);
end;
procedure TJvCustomRollOut.MouseLeave(Control: TControl);
begin
inherited MouseLeave(Control);
if csDesigning in ComponentState then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -