📄 jvqthumbviews.pas
字号:
procedure TJvThumbView.AddFromFile(AFile: string);
var
ThumbnailTitle: string;
FFont: TFont;
FColor: TColor;
Thb: TJvThumbnail;
begin
Thb := TJvThumbnail.Create(Self);
if Assigned(FOnGetTitle) then
begin
ThumbnailTitle := ExtractFilename(AFile);
FFont := TFont.Create;
FColor := clBtnFace;
if Assigned(FOnGetTitle) then
FOnGetTitle(Self, AFile, ThumbnailTitle, FFont, FColor);
Thb.SetTitlePanel(ThumbnailTitle, FFont, FColor);
FreeAndNil(FFont);
end;
Thb.OnClick := OnClick;
Thb.Photo.OnClick := OnClick;
Thb.OnDblClick := OnDblClick;
Thb.Photo.OnDblClick := OnDblClick;
Thb.MinimizeMemory := MinMemory;
// Thb.Buffer := VBuffer;
FThumbList.AddObject(AFile, Thb);
InsertControl(Thb);
CalculateSize;
Reposition(0);
TJvThumbnail(FThumbList.Objects[FThumbList.IndexOf(AFile)]).FileName := AFile;
end;
procedure TJvThumbView.Delete(No: Longint);
var
Dummy: Longint;
begin
if No >= FThumbList.Count then
begin
end //Raise an exception
else
begin
Dummy := FFileList.IndexOf(SelectedFile);
if Dummy >= 0 then
FFileList.Delete(Dummy);
Dummy := FFileListSorted.IndexOf(SelectedFile);
if Dummy >= 0 then
FFileListSorted.Delete(Dummy);
TJvThumbnail(FThumbList.Objects[No]).Free;
FThumbList.Delete(No);
FSelected := -1;
//CalculateSize;
Dec(No, 1);
if No < 0 then
No := 0;
Reposition(No);
Refresh;
Repaint;
end
end;
procedure TJvThumbView.SetThumbGap(Sp: Byte);
begin
case FAlignView of
vtNormal, vtCenter:
begin
FThumbGap := Sp;
CalculateMaxX;
Reposition(0);
end;
vtFitToScreen:
FThumbGap := Sp;
end;
end;
function TJvThumbView.GetCount: Word;
begin
Result := FThumbList.Count;
end;
procedure TJvThumbView.SortList;
begin
// add code to resort the list
FThumbList.Sort;
CalculateSize;
Reposition(0);
end;
procedure TJvThumbView.Refresh;
var
I: Longint;
begin
CalculateSize;
Reposition(0);
for I := 0 to FThumbList.Count - 1 do
FThumbList.Thumbnail[I].Refresh;
inherited Refresh;
end;
procedure TJvThumbView.EmptyList;
var
Metr: Integer;
begin
// (rom) Metr was of type Word which caused a crash here
// (rom) Count = 0 resulted in Count-1 = 65535
for Metr := 0 to Count - 1 do
if Assigned(FThumbList.Objects[0]) then
begin
TJvThumbnail(FThumbList.Objects[0]).Parent := nil;
TJvThumbnail(FThumbList.Objects[0]).Free;
FThumbList.Delete(0);
end;
end;
procedure TJvThumbView.SetMaxWidth(W: Longint);
begin
FMaxSize.X := W;
CalculateSize;
Reposition(0);
end;
procedure TJvThumbView.SetMaxHeight(H: Longint);
begin
// if FMaxSize.Y<H then
FMaxSize.Y := H;
CalculateSize;
Reposition(0);
end;
procedure TJvThumbView.Resize;
begin
CalculateMaxX;
Reposition(0);
inherited Resize;
end;
procedure TJvThumbView.SetPercent(P: TPercent);
begin
FPercent := P;
CalculateSize;
Reposition(0);
end;
procedure TJvThumbView.WMPaint(var Msg: TWMPaint);
begin
inherited;
if not FPainted then
begin
FPainted := True;
SetDirectory(FDirectory);
end;
end;
procedure TJvThumbView.SetScrollMode(AMode: TScrollMode);
begin
if FScrollMode <> AMode then
begin
FScrollMode := AMode;
CalculateSize;
Reposition(0);
if Selected > -1 then
ScrollTo(Selected);
end
end;
procedure TJvThumbView.KeyUp(var Key: Word; Shift: TShiftState);
begin
if Assigned(FOnKeyUp) then
FOnKeyUp(Self, Key, Shift);
inherited KeyUp(Key, Shift);
end;
procedure TJvThumbView.KeyDown(var Key: Word; Shift: TShiftState);
begin
if AutoHandleKeyb and (FThumbList.Count > 0) then
case Key of
39:
begin
GoRight;
ScrollTo(Selected);
end; // Right arrow pressed
40:
begin
GoDown;
ScrollTo(Selected);
end; // Down arrow pressed
37:
begin
GoLeft;
ScrollTo(Selected);
end; // Left arrow pressed
38:
begin
GoUp;
ScrollTo(Selected);
end; // Up arrow pressed
46:
begin
//Delete(FSelected);
end; // Delete Key pressed;
33:
begin // pageup;
//showmessage('Page Up');
//tscrollbox
end;
34:
begin // PageDown
//showmessage('Page Down');
end;
35:
begin // End Pressed;
//showmessage('End');
Selected := Count - 1;
ScrollTo(Selected);
end;
36:
begin // Home Pressed
Selected := 0;
ScrollTo(Selected);
end;
{ else
Showmessage(inttostr(Key));{}
end;
inherited KeyDown(Key, Shift);
end;
procedure TJvThumbView.KeyPress(var Key: Char);
begin
if Assigned(FOnKeyPress) then
FOnKeyPress(Self, Key);
inherited KeyPress(Key);
end;
procedure TJvThumbView.SetSorted(const Value: Boolean);
begin
if Value <> FSorted then
begin
FSorted := Value;
if not FPainted then
Exit;
FThumbList.Sorted := FSorted;
SetDirectory(FDirectory); // force reread
Invalidate;
end;
end;
procedure TJvThumbView.DoGetDlgCode(var Code: TDlgCodes);
begin
Code := [dcWantArrows, dcWantAllKeys];
end;
procedure TJvThumbView.GoRight;
var
Actual: Longint;
begin
Actual := 0;
if ScrollMode = smHorizontal then
Actual := Selected + FMaxX;
if (ScrollMode = smVertical) or (ScrollMode = smBoth) then
Actual := Selected + 1;
if (Actual > Count - 1) or (Actual < 0) then
Actual := Selected;
Selected := Actual;
end;
procedure TJvThumbView.GoLeft;
var
Actual: Longint;
begin
Actual := 0;
if ScrollMode = smHorizontal then
Actual := Selected - FMaxX;
if (ScrollMode = smVertical) or (ScrollMode = smBoth) then
Actual := Selected - 1;
if (Actual > Count - 1) or (Actual < 0) then
Actual := Selected;
Selected := Actual;
end;
procedure TJvThumbView.GoDown;
var
Actual: Longint;
begin
Actual := 0;
if ScrollMode = smHorizontal then
Actual := Selected + 1;
if (ScrollMode = smVertical) or (ScrollMode = smBoth) then
Actual := Selected + FMaxX;
if (Actual > Count - 1) or (Actual < 0) then
Actual := Selected;
Selected := Actual;
end;
procedure TJvThumbView.GoUp;
var
Actual: Longint;
begin
Actual := 0;
if ScrollMode = smHorizontal then
Actual := Selected - 1;
if (ScrollMode = smVertical) or (ScrollMode = smBoth) then
Actual := Selected - FMaxX;
if (Actual > Count - 1) or (Actual < 0) then
Actual := Selected;
Selected := Actual;
end;
procedure TJvThumbView.SetAsButton(const NewVal: Boolean);
var
Dummy: Longint;
begin
if NewVal <> FAsButtons then
begin
if FThumbList.Count > 0 then
for Dummy := 0 to FThumbList.Count - 1 do
FThumbList.Thumbnail[Dummy].AsButton := NewVal;
FAsButtons := NewVal;
end;
end;
procedure TJvThumbView.SetTitlePos(const NewVal: TTitlePos);
var
Dummy: Longint;
begin
if NewVal <> FTitlePlacement then
begin
if FThumbList.Count > 0 then
for Dummy := 0 to FThumbList.Count - 1 do
FThumbList.Thumbnail[Dummy].TitlePlacement := NewVal;
FTitlePlacement := NewVal;
end;
end;
function TJvThumbView.CreateFilter: string;
//var
// Res: string;
// Pos: Longint;
begin
Result := GraphicFilter(TGraphic);
end;
procedure TJvThumbView.SetFilters;
var
Cp1 {, CP2}: Integer; // CurrentPosition;
// Md: Byte; // Mode
Res: string;
// Sub: string;
Final: string;
begin
if not Assigned(FGraphicExtensions) then
FGraphicExtensions := TStringList.Create;
// Cp1 := 0;
// CP2 := 0;
Res := FFilter;
Final := '';
repeat
Cp1 := Pos('|', Res);
if Cp1 > 0 then
begin
System.Delete(Res, 1, Cp1);
Cp1 := Pos('|', Res);
if Cp1 > 0 then
begin
Final := Final + ';' + Copy(Res, 1, Cp1 - 1);
System.Delete(Res, 1, Cp1);
end
else
Final := Final + ';' + Res;
end
else
Final := Final + ';' + Res;
until Cp1 = 0;
Final := ReplaceAllstr(Final, ';', sLineBreak, False);
FGraphicExtensions.Text := Final;
Cp1 := 0;
repeat
if FGraphicExtensions[Cp1] = '' then
FGraphicExtensions.Delete(Cp1)
else
Inc(Cp1);
until Cp1 = FGraphicExtensions.Count;
end;
function TJvThumbList.GetThumbnail(Index: Longint): TJvThumbnail;
begin
Result := TJvThumbnail(Objects[Index]);
end;
function TJvThumbView.GetMaxHeight: Longint;
begin
Result := FMaxSize.Y;
end;
function TJvThumbView.GetMaxWidth: Longint;
begin
Result := FMaxSize.X;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -