📄 gmthumbnails.pas
字号:
end;
procedure TGmThumbnails.Notification(AComponent: TComponent; Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (AComponent = FPreview) then
begin
FThumbnailList.Clear;
FPreview := nil;
end;
end;
function TGmThumbnails.AddThumbnail: TGmThumbnail;
begin
Result := TGmThumbnail.Create(Self);
Result.Shadow := FShadow;
Result.OnMouseDown := ThumbMouseDown;
FThumbnailList.Add(Result);
end;
function TGmThumbnails.GetThumbnail(index: integer): TGmThumbnail;
begin
if (index = -1) or (index > FThumbnailList.Count-1) then Result := nil
else
Result := TGmThumbnail(FThumbnailList[index]);
end;
procedure TGmThumbnails.Changed;
begin
UpdateThumbnails;
end;
procedure TGmThumbnails.DeleteThumbnail;
begin
FThumbnailList.Delete(FThumbnailList.Count-1);
end;
procedure TGmThumbnails.FontChanged(Sender: TObject);
begin
UpdateThumbnails;
end;
procedure TGmThumbnails.SetCaptionFont(Value: TFont);
begin
FCaptionFont.Assign(Value);
UpdateThumbnails;
end;
procedure TGmThumbnails.SetCaptions(Value: string);
begin
if FCaptions = Value then Exit;
FCaptions := Value;
Invalidate;
end;
procedure TGmThumbnails.SetGridWidth(Value: integer);
begin
if FGridWidth < 0 then
begin
//ShowGmError(
end;
if FGridWidth = Value then Exit;
FGridWidth := Value;
RedrawThumbnails;
end;
procedure TGmThumbnails.SetHighlight(Value: Boolean);
begin
if FHighlight = Value then Exit;
FHighlight := Value;
Invalidate;
end;
procedure TGmThumbnails.SetHighlightStyle(Value: TGmHighlightStyle);
begin
if FHighlightStyle = Value then Exit;
FHighlightStyle := Value;
Invalidate;
end;
procedure TGmThumbnails.SetItemIndex(Value: integer);
begin
if FItemIndex = Value then Exit;
if Assigned(Thumbnail[FItemIndex]) then
Thumbnail[FItemIndex].Selected := False;
FItemIndex := Value;
if Assigned(Thumbnail[FItemIndex]) then
if FHighlight then Thumbnail[FItemIndex].Selected := True;
if (Assigned(FPreview)) and (FScrollIntoView) then
begin
if Assigned(Thumbnail[FItemIndex]) then
ScrollInView(Thumbnail[FItemIndex]);
end;
end;
procedure TGmThumbnails.SetLayout(Value: TGmThumbNailLayout);
begin
if FLayout = Value then Exit;
FLayout := Value;
RedrawThumbnails;
end;
procedure TGmThumbnails.SetPlainPages(Value: Boolean);
begin
if FPlainPages = Value then Exit;
FPlainPages := Value;
Invalidate;
end;
procedure TGmThumbnails.ResizeThumbList;
begin
if not Assigned(FPreview) then Exit;
if FThumbnailList.Count = FPreview.NumPages then Exit;
while FThumbnailList.Count < FPreview.NumPages do AddThumbnail;
while FThumbnailList.Count > FPreview.NumPages do DeleteThumbnail;
Repaginate;
end;
procedure TGmThumbnails.RescaleThumbnails;
var
ICount: integer;
TextHeight: Integer;
begin
for ICount := 0 to FThumbnailList.Count-1 do
begin
with Thumbnail[ICount] do
begin
if FShowCaption then
TextHeight := (0-FCaptionFont.Height)+4
else
TextHeight := 0;
Gutters := Rect(FThumbSpacing, FThumbSpacing, FThumbSpacing, FThumbSpacing + TextHeight);
Zoom := FThumbSize+2;
Width := PageExtent[96].cx + (Gutters.Left + Gutters.Right);
Height := PageExtent[96].cy + (Gutters.Top + Gutters.Bottom);
end;
end;
end;
procedure TGmThumbnails.RedrawThumbnails;
var
ICount: integer;
CurrentXY: TPoint;
begin
CurrentXY := Point(0,0);
for ICount := 0 to FThumbnailList.Count-1 do
begin
with Thumbnail[ICount] do
begin
Selected := Page = FPreview.CurrentPage;
SetBounds(CurrentXY.X-HorzScrollBar.Position,
CurrentXY.Y-VertScrollBar.Position,
Width,
Height);
Parent := Self;
if FLayout = gmThumbHorz then Inc(CurrentXY.X, Width-1)
else
if FLayout = gmThumbVert then Inc(CurrentXY.Y, Height-1)
else
begin
if (ICount+1) mod FGridWidth = 0 then
begin
Inc(CurrentXY.Y, Height-1);
CurrentXY.X := 0;
end
else
Inc(CurrentXY.X, Width-1);
end;
end;
end;
end;
procedure TGmThumbnails.Repaginate;
var
ICount: integer;
begin
for ICount := 0 to FThumbnailList.Count-1 do
Thumbnail[ICount].Page := FPreview.Pages[ICount+1];
end;
procedure TGmThumbnails.SetPreview(APreview: TGmPreview);
begin
if Assigned(FPreview) then
begin
FThumbnailList.Clear;
FPreview.RemoveAssociatedComponent(Self);
end;
FPreview := APreview;
if Assigned(FPreview) then
begin
FPreview.AddAssociatedComponent(Self);
UpdateThumbnails;
end;
end;
procedure TGmThumbnails.SetSelectedColor(Value: TColor);
begin
if FSelectedColor = Value then Exit;
FSelectedColor := Value;
Invalidate;
end;
procedure TGmThumbnails.SetShadow(Value: TGmShadow);
begin
FShadow.Assign(Value);
Invalidate;
end;
procedure TGmThumbnails.SetShowCaption(Value: Boolean);
begin
if FShowCaption = Value then Exit;
FShowCaption := Value;
UpdateThumbnails;
end;
procedure TGmThumbnails.SetThumbnail(index: integer;
const Value: TGmThumbnail);
begin
FThumbnailList[index] := Value;
end;
procedure TGmThumbnails.SetThumbPopup(Value: TPopupMenu);
var
ICount: integer;
begin
if FThumbPopup = Value then Exit;
FThumbPopup := Value;
for ICount := 0 to FThumbnailList.Count-1 do
Thumbnail[ICount].PopupMenu := FThumbPopup;
end;
procedure TGmThumbnails.SetThumbSize(Value: integer);
begin
if FThumbSize = Value then Exit;
FThumbSize := Value;
Changed;
end;
procedure TGmThumbnails.SetThumbSpacing(Value: integer);
begin
if FThumbSpacing = Value then Exit;
FThumbSpacing := Value;
UpdateThumbnails;
end;
procedure TGmThumbnails.ThumbMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: integer);
var
LastItemIndex: integer;
begin
if FUpdateCount > 0 then Exit;
LastItemIndex := FThumbnailList.IndexOf(Sender);
//if Assigned(FOnThumbMouseDown) then FOnThumbMouseDown(Self, Button, Shift, TGmPage(TGmThumbnail(Sender).Page));
if FThumbnailList.IndexOf(Sender) <> -1 then
ItemIndex := FThumbnailList.IndexOf(Sender)
else
ItemIndex := LastItemIndex;
if Assigned(FPreview) then
FPreview.CurrentPageNum := ItemIndex+1;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -