Ignore:
Timestamp:
Apr 19, 2018, 4:05:54 PM (6 years ago)
Author:
chronos
Message:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Common/UJobProgressView.pas

    r510 r512  
    77uses
    88  SysUtils, Variants, Classes, Graphics, Controls, Forms, Syncobjs,
    9   Dialogs, ComCtrls, StdCtrls, ExtCtrls, Contnrs, UThreading,
     9  Dialogs, ComCtrls, StdCtrls, ExtCtrls, Contnrs, UThreading, Math,
    1010  DateUtils;
    1111
     
    1313  EstimatedTimeShowTreshold = 4;
    1414  EstimatedTimeShowTresholdTotal = 1;
    15   MemoLogHeight = 200;
    1615  UpdateInterval = 100; // ms
    1716
     
    2423    FLock: TCriticalSection;
    2524    FOnChange: TNotifyEvent;
     25    FText: string;
    2626    FValue: Integer;
    2727    FMax: Integer;
    2828    procedure SetMax(const AValue: Integer);
     29    procedure SetText(AValue: string);
    2930    procedure SetValue(const AValue: Integer);
    3031  public
     
    3536    property Value: Integer read FValue write SetValue;
    3637    property Max: Integer read FMax write SetMax;
     38    property Text: string read FText write SetText;
    3739    property OnChange: TNotifyEvent read FOnChange write FOnChange;
    3840  end;
     
    6971  end;
    7072
     73  TJobs = class(TObjectList)
     74  end;
     75
    7176  TJobThread = class(TListedThread)
    7277    procedure Execute; override;
     
    8085  TFormJobProgressView = class(TForm)
    8186    ImageList1: TImageList;
     87    LabelText: TLabel;
    8288    Label2: TLabel;
    8389    LabelOperation: TLabel;
     
    8692    ListViewJobs: TListView;
    8793    MemoLog: TMemo;
     94    PanelText: TPanel;
    8895    PanelProgressTotal: TPanel;
    8996    PanelOperationsTitle: TPanel;
     
    94101    ProgressBarTotal: TProgressBar;
    95102    TimerUpdate: TTimer;
     103    procedure FormHide(Sender: TObject);
     104    procedure FormShow(Sender: TObject);
     105    procedure ReloadJobList;
    96106    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    97107    procedure FormDestroy(Sender: TObject);
     
    100110    procedure FormCreate(Sender: TObject);
    101111    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
     112    procedure UpdateHeight;
    102113  public
    103114    JobProgressView: TJobProgressView;
     
    120131    procedure SetTerminate(const AValue: Boolean);
    121132    procedure UpdateProgress;
    122     procedure ReloadJobList;
    123     procedure StartJobs;
    124     procedure UpdateHeight;
    125133    procedure JobProgressChange(Sender: TObject);
    126134  public
    127135    Form: TFormJobProgressView;
    128     Jobs: TObjectList; // TListObject<TJob>
     136    Jobs: TJobs;
    129137    CurrentJob: TJob;
    130138    CurrentJobIndex: Integer;
     
    134142    procedure AddJob(Title: string; Method: TJobProgressViewMethod;
    135143      NoThreaded: Boolean = False; WaitFor: Boolean = False);
    136     procedure Start(AAutoClose: Boolean = True);
     144    procedure Start;
    137145    procedure Stop;
    138146    procedure TermSleep(Delay: Integer);
     
    166174  STotalEstimatedTime = 'Total estimated time: %s';
    167175  SFinished = 'Finished';
     176  SOperations = 'Operations:';
    168177
    169178procedure Register;
     
    207216end;
    208217
    209 procedure TJobProgressView.Start(AAutoClose: Boolean = True);
    210 begin
    211   AutoClose := AAutoClose;
    212   StartJobs;
    213 end;
    214 
    215 procedure TJobProgressView.StartJobs;
     218procedure TJobProgressView.Start;
    216219var
    217220  I: Integer;
     
    228231    Form.MemoLog.Clear;
    229232
     233    Form.PanelText.Visible := False;
    230234    Form.LabelEstimatedTimePart.Visible := False;
    231235    Form.LabelEstimatedTimeTotal.Visible := False;
     
    257261      Form.ProgressBarPart.Visible := False;
    258262      //Show;
    259       ReloadJobList;
     263      Form.ReloadJobList;
    260264      Application.ProcessMessages;
    261265      if NoThreaded then begin
     
    295299    //if Visible then Hide;
    296300    Form.MemoLog.Lines.Assign(Log);
    297     if (Form.MemoLog.Lines.Count = 0) and AutoClose then begin
     301    if (Form.MemoLog.Lines.Count = 0) and FAutoClose then begin
    298302      Form.Hide;
    299303    end;
    300     Clear;
     304    //Clear;
    301305    Form.Caption := SFinished;
    302306    //LabelEstimatedTimePart.Visible := False;
    303307    Finished := True;
    304308    CurrentJobIndex := -1;
    305     ReloadJobList;
    306   end;
    307 end;
    308 
    309 procedure TJobProgressView.UpdateHeight;
     309    Form.ReloadJobList;
     310  end;
     311end;
     312
     313procedure TFormJobProgressView.UpdateHeight;
    310314var
    311315  H: Integer;
     
    315319  PanelProgressTotalVisible: Boolean;
    316320  PanelLogVisible: Boolean;
    317 begin
    318   with Form do begin
    319   H := PanelOperationsTitle.Height;
    320   PanelOperationsVisible := Jobs.Count > 0;
    321   if PanelOperationsVisible <> PanelOperations.Visible then
    322     PanelOperations.Visible := PanelOperationsVisible;
    323   PanelOperationsHeight := 8 + 18 * Jobs.Count;
    324   if PanelOperationsHeight <> PanelOperations.Height then
    325     PanelOperations.Height := PanelOperationsHeight;
    326   if PanelOperationsVisible then
    327     H := H + PanelOperations.Height;
    328 
    329   PanelProgressVisible := (Jobs.Count > 0) and not Finished;
    330   if PanelProgressVisible <> PanelProgress.Visible then
    331     PanelProgress.Visible := PanelProgressVisible;
    332   if PanelProgressVisible then
    333     H := H + PanelProgress.Height;
    334   PanelProgressTotalVisible := (Jobs.Count > 1) and not Finished;
    335   if PanelProgressTotalVisible <> PanelProgressTotal.Visible then
    336     PanelProgressTotal.Visible := PanelProgressTotalVisible;
    337   if PanelProgressTotalVisible then
    338     H := H + PanelProgressTotal.Height;
    339   Constraints.MinHeight := H;
    340   PanelLogVisible := MemoLog.Lines.Count > 0;
    341   if PanelLogVisible <> PanelLog.Visible then
    342     PanelLog.Visible := PanelLogVisible;
    343   if PanelLogVisible then
    344     H := H + MemoLogHeight;
    345   if Height <> H then Height := H;
    346   end;
     321  MemoLogHeight: Integer = 200;
     322  I: Integer;
     323  ItemRect: TRect;
     324  MaxH: Integer;
     325begin
     326    H := PanelOperationsTitle.Height;
     327    PanelOperationsVisible := JobProgressView.Jobs.Count > 0;
     328    if PanelOperationsVisible <> PanelOperations.Visible then
     329      PanelOperations.Visible := PanelOperationsVisible;
     330    if ListViewJobs.Items.Count > 0 then begin
     331      Maxh := 0;
     332      for I := 0 to ListViewJobs.Items.Count - 1 do
     333      begin
     334        ItemRect := ListViewJobs.Items[i].DisplayRect(drBounds);
     335        Maxh := Max(Maxh, ItemRect.Top + (ItemRect.Bottom - ItemRect.Top));
     336      end;
     337      PanelOperationsHeight := Scale96ToScreen(12) + Maxh;
     338    end else PanelOperationsHeight := Scale96ToScreen(8);
     339    if PanelOperationsHeight <> PanelOperations.Height then
     340      PanelOperations.Height := PanelOperationsHeight;
     341    if PanelOperationsVisible then
     342      H := H + PanelOperations.Height;
     343
     344    PanelProgressVisible := (JobProgressView.Jobs.Count > 0) and not JobProgressView.Finished;
     345    if PanelProgressVisible <> PanelProgress.Visible then
     346      PanelProgress.Visible := PanelProgressVisible;
     347    if PanelProgressVisible then
     348      H := H + PanelProgress.Height;
     349    PanelProgressTotalVisible := (JobProgressView.Jobs.Count > 1) and not JobProgressView.Finished;
     350    if PanelProgressTotalVisible <> PanelProgressTotal.Visible then
     351      PanelProgressTotal.Visible := PanelProgressTotalVisible;
     352    if PanelProgressTotalVisible then
     353      H := H + PanelProgressTotal.Height;
     354    Constraints.MinHeight := H;
     355    PanelLogVisible := MemoLog.Lines.Count > 0;
     356    if PanelLogVisible <> PanelLog.Visible then
     357      PanelLog.Visible := PanelLogVisible;
     358    if PanelLogVisible then
     359      H := H + Scale96ToScreen(MemoLogHeight);
     360    if PanelText.Visible then
     361      H := H + PanelText.Height;
     362    if Height <> H then Height := H;
    347363end;
    348364
     
    373389    if not JobProgressView.OwnerDraw then Show;
    374390  end;
     391  if Assigned(JobProgressView.CurrentJob) then begin
     392    LabelText.Caption := JobProgressView.CurrentJob.Progress.Text;
     393    if LabelText.Caption <> '' then begin
     394      PanelText.Visible := True;
     395      UpdateHeight;
     396    end;
     397  end;
    375398end;
    376399
     
    394417  var CloseAction: TCloseAction);
    395418begin
    396   ListViewJobs.Clear;
    397419end;
    398420
     
    407429
    408430  end;
     431end;
     432
     433procedure TFormJobProgressView.ReloadJobList;
     434begin
     435  // Workaround for not showing first line
     436  //Form.ListViewJobs.Items.Count := Jobs.Count + 1;
     437  //Form.ListViewJobs.Refresh;
     438
     439  if ListViewJobs.Items.Count <> JobProgressView.Jobs.Count then
     440    ListViewJobs.Items.Count := JobProgressView.Jobs.Count;
     441  ListViewJobs.Refresh;
     442  Application.ProcessMessages;
     443  UpdateHeight;
     444end;
     445
     446procedure TFormJobProgressView.FormShow(Sender: TObject);
     447begin
     448  ReloadJobList;
     449end;
     450
     451procedure TFormJobProgressView.FormHide(Sender: TObject);
     452begin
     453  JobProgressView.Jobs.Clear;
     454  ReloadJobList;
    409455end;
    410456
     
    489535end;
    490536
    491 procedure TJobProgressView.ReloadJobList;
    492 begin
    493   UpdateHeight;
    494   // Workaround for not showing first line
    495   Form.ListViewJobs.Items.Count := Jobs.Count + 1;
    496   Form.ListViewJobs.Refresh;
    497 
    498   if Form.ListViewJobs.Items.Count <> Jobs.Count then
    499     Form.ListViewJobs.Items.Count := Jobs.Count;
    500   Form.ListViewJobs.Refresh;
    501   //Application.ProcessMessages;
    502 end;
    503 
    504537constructor TJobProgressView.Create(TheOwner: TComponent);
    505538begin
     
    509542    Form.JobProgressView := Self;
    510543  end;
    511   Jobs := TObjectList.Create;
     544  Jobs := TJobs.Create;
    512545  Log := TStringList.Create;
    513546  //PanelOperationsTitle.Height := 80;
     
    535568    if FMax < 1 then FMax := 1;
    536569    if FValue >= FMax then FValue := FMax;
     570  finally
     571    FLock.Release;
     572  end;
     573end;
     574
     575procedure TProgress.SetText(AValue: string);
     576begin
     577  try
     578    FLock.Acquire;
     579    if FText = AValue then Exit;
     580    FText := AValue;
    537581  finally
    538582    FLock.Release;
Note: See TracChangeset for help on using the changeset viewer.