⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jvqthumbviews.pas

📁 East make Tray Icon in delphi
💻 PAS
📖 第 1 页 / 共 3 页
字号:
            (width - TJvThumbnail(FThumbList.objects[number]).width -
            (TJvThumbnail(FThumbList.objects[number]).width div 2)));
      end;
  end;
  if FSelected <> Number then
  begin
    FSelected := Number;
    if Assigned(OnClick) then
      OnClick(Self);
  end;
end;
(*
function TJvThumbView.GetBufferName(AName: string): string;
var
  tst: string;
  FN: string;
  Res: string;
begin
  tst := completepath(extractFiledir(AName));
  if tst = AName then
  begin // No FileName included only A Directory;
    // the user wants us to Create A seperate file for each
    // Directory it opens in A pre-specified path
    FN := ReplaceChar(FDirectory, '\', '_', 0, False); //Create the FileName from the path
    FN := ReplaceChar(FN, ':', '_', 0, False); //Create the FileName from the path
    Res := AName + fn;
  end
  else
  begin // the user has specified either A full path and A name or just A name
    if tst = '' then
      // the user has specified only A name to use
      // in each Directory that is opened by the component there will be created
      // A file with name <ANAME> where the thumbs are been saved;
      Res := CompletePath(FDirectory) + AName
    else
      // the user has specified A full path and A file name weach is the same
      // for all the directories he/she opens.
      Res := AName;
  end;
  Result := Res;
end;
*)

//Procedure TJvThumbView.SetBufferFile(NewName:String);
//var
//  tst : string;
//begin
//  If NewName <> FBufferFile then
//    tst := GetBufferName(NewName);
//  End;
//end;

procedure TJvThumbView.SetSelected(Number: Longint);
begin
  if FThumbList.Count > 0 then
  begin
    if FSelected <> -1 then
    begin
      TJvThumbnail(FThumbList.Objects[FSelected]).titlecolor :=
        TJvThumbnail(FThumbList.Objects[FSelected]).Color;
      TJvThumbnail(FThumbList.Objects[FSelected]).TitleFont.Color :=
        TJvThumbnail(FThumbList.Objects[FSelected]).Font.Color;
    end;
    if Number <> -1 then
    begin
      TJvThumbnail(FThumbList.Objects[Number]).titlecolor := clHighlight;
      TJvThumbnail(FThumbList.Objects[Number]).TitleFont.Color := clHighlightText;
      if AutoScrolling then
      begin
        if (TJvThumbnail(FThumbList.Objects[Number]).Top +
          TJvThumbnail(FThumbList.Objects[Number]).Height > Height) or
          (TJvThumbnail(FThumbList.Objects[Number]).Top < 0) then
          ScrollTo(Number);
        if (TJvThumbnail(FThumbList.Objects[Number]).Left +
          TJvThumbnail(FThumbList.Objects[Number]).Width > Width) or
          (TJvThumbnail(FThumbList.Objects[Number]).Left < 0) then
          ScrollTo(Number);
      end
    end;
    if FSelected <> Number then
    begin
      if Assigned(FOnChanging) then
        FOnChanging(Self);

      FSelected := Number;

      if Assigned(FOnChange) then
        FOnChange(Self);
    end;
  end;
end;

function TJvThumbView.GetSelectedFile;
begin
  if Selected <> -1 then
    Result := TJvThumbnail(FThumbList.Objects[Selected]).FileName;
end;

procedure TJvThumbView.SetSelectedFile(AFile: string);
var
  I: Longint;
  Dir: string;
begin
  Dir := extractfiledir(AFile);
  if Dir[length(Dir)] = '\' then
    Dir := Copy(Dir, 0, length(Dir) - 1);
  Directory := Dir;
  for I := 0 to FThumbList.Count - 1 do
    if TJvThumbnail(FThumbList.Objects[I]).FileName = AFile then
    begin
      Selected := I;
      if not FAutoScrolling then
        ScrollTo(I);
      Exit;
    end;
end;

procedure TJvThumbView.SetDirectory(Value: string);
var
  Counter1, FStartTime: DWORD;
  Cancel: Boolean;
  ReadFileList: TStringList;
  OldCursor: TCursor;
//  Pic: TPicture;
begin
  FSelected := -1;
  //  If Not FPainted then
  //  begin
  //    postMessage(Self.Handle,WM_LoadWhenReady,0,0);
  //    Exit;
  //  end;
  FDiskSize := 0;
  if FFilling then
    Exit;
  if Value <> '' then
  begin
    ReadFileList := TStringList.Create;
    OldCursor := Cursor;
    try
      FFilling := True;
    //    if Assigned(ReadFileList) then FreeAndNil(ReadFileList);
      FStartTime := GetTickCount;
      GetFiles(Value);
      if FSorted then
        ReadFileList.Assign(FFileListSorted)
      else
        ReadFileList.Assign(FFileList);
      EmptyList;
      FDirectory := Value;
      if ReadFileList.Count > 0 then
      begin
        if Assigned(FOnStartScanning) then
          FOnStartScanning(Self, ReadFileList.Count - 1);
        Cancel := False;
        for Counter1 := 0 to ReadFileList.Count - 1 do
        begin
          if Assigned(FOnScanProgress) then
            FOnScanProgress(Self, Counter1 + 1, Cancel);
          if Cancel then
            Break;
          AddThumb(ExtractFilename(ReadFileList.Strings[Counter1]), True);
          TJvThumbnail(FThumbList.Objects[Counter1]).FileName := ReadFileList.Strings[Counter1];
          Inc(FDiskSize, TJvThumbnail(FThumbList.Objects[Counter1]).FileSize);
          if (Cursor <> crHourGlass) and (GetTickCount - FStartTime > 1000) then
            Cursor := crHourGlass;
        end;
        if Assigned(FOnStopScanning) then
          FOnStopScanning(Self);
      end;
    finally
      FreeandNil(ReadFileList);
      FFilling := False;
      Cursor := OldCursor;
    end
  end
  else
    EmptyList;
  FDirectory := Value;
  if (FThumbList.Count > 0) and (Selected < 0) then
    SetSelected(0);
  Invalidate;
end;

procedure TJvThumbView.Reposition;
var
  I: Integer;
  Tmp1: Longint;
  Tmp2: Longint;
begin
  Tmp2 := HorzScrollBar.Position;
  HorzScrollBar.Position := 0;
  Tmp1 := VertScrollBar.Position;
  VertScrollBar.Position := 0;
  if FThumbList.Count > 0 then
    for I := Start to FThumbList.Count - 1 do
    begin
      if TJvThumbnail(FThumbList.Objects[I]) <> nil then
      begin
        TJvThumbnail(FThumbList.Objects[I]).Left := CalculateXPos(I + 1);
        TJvThumbnail(FThumbList.Objects[I]).Top := CalculateYPos(I + 1);
        TJvThumbnail(FThumbList.Objects[I]).Width := FThumbSize.X;
        TJvThumbnail(FThumbList.Objects[I]).Height := FThumbSize.Y;
      end;
    end;
  HorzScrollBar.Position := Tmp2;
  VertScrollBar.Position := Tmp1;
end;

procedure TJvThumbView.CalculateMaxX;
var
  A: Longint;
begin
  case FScrollMode of
    smVertical:
      A := (Width - 20) div (FThumbSize.X + FThumbGap);
    smHorizontal:
      A := (Height - 20) div (FThumbSize.Y + FThumbGap);
    smBoth:
      A := JkCeil(Sqrt(FThumbList.Count));
  else
    A := 1;
  end;
  if A < 1 then
    A := 1;
  if A <> FMaxX then
    FMaxX := A;
end;

procedure TJvThumbView.CalculateSize;
begin
  FThumbSize.X := Trunc((MaxWidth / 100) * Size);
  FThumbSize.Y := Trunc((MaxHeight / 100) * Size);
  CalculateMaxX;
end;

function TJvThumbView.CalculateXPos(Num: Word): Longint;
var
  VPos, HPos: Longint;
  Temp: Longint;
  Tmp: Longint;
  Spact: Longint;
begin
  if Num > 0 then
  begin
    Spact := FThumbGap;
    case FScrollMode of
      smVertical, smBoth:
        begin
          if (FAlignView = vtFitToScreen) and (FScrollMode = smVertical) then
          begin
            Spact := ((Width - 20) - (FThumbSize.X * FMaxX)) div (FMaxX + 1);
          end;
          VPos := JkCeil(Num / FMaxX);
          HPos := (Num - (VPos * FMaxX)) + FMaxX;
          Temp := (FThumbSize.X * (HPos - 1)) + (HPos * Spact);
          if (FAlignView = vtCenter) and (FScrollMode = smVertical) then
          begin
            Tmp := ((Width - 20) div 2) - (((FThumbSize.X + FThumbGap) * FMaxX) div 2);
            Temp := Temp + Tmp;
          end;
        end;
      smHorizontal:
        begin
          VPos := JkCeil(Num / FMaxX);
          Temp := (FThumbSize.Y * (VPos - 1)) + (VPos * Spact);
        end
    else
      Temp := 0
    end;
  end
  else
    Temp := 0;
  Result := Temp;
end;

function TJvThumbView.CalculateYPos(Num: Word): Longint;
var
  VPos, HPos: Longint;
  Temp: Longint;
  Tmp: Longint;
  Spact: Longint;
begin
  if Num > 0 then
  begin
    Spact := FThumbGap;
    case FScrollMode of
      smVertical, smBoth:
        begin
          VPos := JkCeil(Num / FMaxX);
          Temp := (FThumbSize.Y * (VPos - 1)) + (VPos * Spact);
        end;
      smHorizontal:
        begin
          if FAlignView = vtFitToScreen then
            Spact := ((Height - 20) - ((FThumbSize.Y + FThumbGap) * FMaxX)) div (FMaxX + 1);
          HPos := JkCeil(Num / FMaxX);
          VPos := (Num - (HPos * FMaxX)) + FMaxX;
          Temp := (FThumbSize.X * (VPos - 1)) + (VPos * Spact);
          if FAlignView = vtCenter then
          begin
            Tmp := ((Height - 20) div 2) - ((FThumbSize.Y * FMaxX) div 2);
            Temp := Temp + Tmp;
          end;
        end;
    else
      Temp := 0;
    end;
  end
  else
    Temp := 0;
  Result := Temp;
end;

procedure TJvThumbView.MouseDown(Button: TMouseButton; Shift: TShiftState;
  X, Y: Integer);
var
  No: Word;
  TempX, TempY: Longint;
begin
  // Check to see if there are any problems removing the following
  // For sure it solves A focus problem I'm having in an application
 //  setfocus;
  if Count > 0 then
    case ScrollMode of
      smVertical, smBoth:
        begin
          TempX := JkCeil((X + HorzScrollBar.Position) / (FThumbSize.X + FThumbGap));
          TempY := JkCeil((Y + VertScrollBar.Position) / (FThumbSize.Y + FThumbGap));
          if TempX > FMaxX then
            TempX := FMaxX;
          if TempY < 1 then
            TempY := 1;
          No := ((TempY - 1) * FMaxX + TempX) - 1;
          if No < Count then
            if TJvThumbnail(FThumbList.Objects[No]) <> nil then
              if (X > TJvThumbnail(FThumbList.Objects[No]).Left) and
                (X < TJvThumbnail(FThumbList.Objects[No]).Left +
                TJvThumbnail(FThumbList.Objects[No]).Width) and
                (Y > TJvThumbnail(FThumbList.Objects[No]).Top) and
                (Y < TJvThumbnail(FThumbList.Objects[No]).Top +
                TJvThumbnail(FThumbList.Objects[No]).Height) then
                SetSelected(No)
              else
                SetSelected(-1)
            else
              SetSelected(-1)
          else
            SetSelected(-1);
        end;
      smHorizontal:
        begin
          TempX := JkCeil((X + HorzScrollBar.Position) / (FThumbSize.X + FThumbGap));
          TempY := JkCeil((Y + VertScrollBar.Position) / (FThumbSize.Y + FThumbGap));
          if TempY > FMaxX then
            TempY := FMaxX;
          if TempX < 1 then
            TempX := 1;
          No := ((TempX - 1) * FMaxX + TempY) - 1;
          if No < Count then
            if TJvThumbnail(FThumbList.Objects[No]) <> nil then
              if (X > TJvThumbnail(FThumbList.Objects[No]).Left) and
                (X < TJvThumbnail(FThumbList.Objects[No]).Left +
                TJvThumbnail(FThumbList.Objects[No]).Width) and
                (Y > TJvThumbnail(FThumbList.Objects[No]).Top) and
                (Y < TJvThumbnail(FThumbList.Objects[No]).Top +
                TJvThumbnail(FThumbList.Objects[No]).Height)
                then
                SetSelected(No)
              else
                SetSelected(-1)
            else
              SetSelected(-1)
          else
            SetSelected(-1);
        end;
    else
      SetSelected(-1);
    end;
  inherited MouseDown(Button, Shift, X, Y);
end;

procedure TJvThumbView.AddFromStream(AStream: TStream; AType: TGRFKind);
var
  Thb: TJvThumbnail;
begin
  Thb := TJvThumbnail.Create(Self);
  Thb.StreamFileType := AType;
  Thb.Left := CalculateXPos(Count + 1);
  Thb.Top := CalculateYPos(Count + 1);
  Thb.Width := FThumbSize.X;
  Thb.Height := FThumbSize.Y;
  Thb.OnClick := OnClick;
  Thb.Photo.OnClick := OnClick;
  Thb.OnDblClick := OnDblClick;
  Thb.Photo.OnDblClick := OnDblClick;
  //  Thb.Buffer := Vbuffer;
  Thb.Photo.LoadFromStream(AStream, Thb.StreamFileType);
  FThumbList.AddObject(Thb.Title, Thb);
  InsertControl(Thb);
  CalculateSize;
end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -