Changeset 512 for Common/UJobProgressView.pas
- Timestamp:
- Apr 19, 2018, 4:05:54 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Common/UJobProgressView.pas
r510 r512 7 7 uses 8 8 SysUtils, Variants, Classes, Graphics, Controls, Forms, Syncobjs, 9 Dialogs, ComCtrls, StdCtrls, ExtCtrls, Contnrs, UThreading, 9 Dialogs, ComCtrls, StdCtrls, ExtCtrls, Contnrs, UThreading, Math, 10 10 DateUtils; 11 11 … … 13 13 EstimatedTimeShowTreshold = 4; 14 14 EstimatedTimeShowTresholdTotal = 1; 15 MemoLogHeight = 200;16 15 UpdateInterval = 100; // ms 17 16 … … 24 23 FLock: TCriticalSection; 25 24 FOnChange: TNotifyEvent; 25 FText: string; 26 26 FValue: Integer; 27 27 FMax: Integer; 28 28 procedure SetMax(const AValue: Integer); 29 procedure SetText(AValue: string); 29 30 procedure SetValue(const AValue: Integer); 30 31 public … … 35 36 property Value: Integer read FValue write SetValue; 36 37 property Max: Integer read FMax write SetMax; 38 property Text: string read FText write SetText; 37 39 property OnChange: TNotifyEvent read FOnChange write FOnChange; 38 40 end; … … 69 71 end; 70 72 73 TJobs = class(TObjectList) 74 end; 75 71 76 TJobThread = class(TListedThread) 72 77 procedure Execute; override; … … 80 85 TFormJobProgressView = class(TForm) 81 86 ImageList1: TImageList; 87 LabelText: TLabel; 82 88 Label2: TLabel; 83 89 LabelOperation: TLabel; … … 86 92 ListViewJobs: TListView; 87 93 MemoLog: TMemo; 94 PanelText: TPanel; 88 95 PanelProgressTotal: TPanel; 89 96 PanelOperationsTitle: TPanel; … … 94 101 ProgressBarTotal: TProgressBar; 95 102 TimerUpdate: TTimer; 103 procedure FormHide(Sender: TObject); 104 procedure FormShow(Sender: TObject); 105 procedure ReloadJobList; 96 106 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); 97 107 procedure FormDestroy(Sender: TObject); … … 100 110 procedure FormCreate(Sender: TObject); 101 111 procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); 112 procedure UpdateHeight; 102 113 public 103 114 JobProgressView: TJobProgressView; … … 120 131 procedure SetTerminate(const AValue: Boolean); 121 132 procedure UpdateProgress; 122 procedure ReloadJobList;123 procedure StartJobs;124 procedure UpdateHeight;125 133 procedure JobProgressChange(Sender: TObject); 126 134 public 127 135 Form: TFormJobProgressView; 128 Jobs: T ObjectList; // TListObject<TJob>136 Jobs: TJobs; 129 137 CurrentJob: TJob; 130 138 CurrentJobIndex: Integer; … … 134 142 procedure AddJob(Title: string; Method: TJobProgressViewMethod; 135 143 NoThreaded: Boolean = False; WaitFor: Boolean = False); 136 procedure Start (AAutoClose: Boolean = True);144 procedure Start; 137 145 procedure Stop; 138 146 procedure TermSleep(Delay: Integer); … … 166 174 STotalEstimatedTime = 'Total estimated time: %s'; 167 175 SFinished = 'Finished'; 176 SOperations = 'Operations:'; 168 177 169 178 procedure Register; … … 207 216 end; 208 217 209 procedure TJobProgressView.Start(AAutoClose: Boolean = True); 210 begin 211 AutoClose := AAutoClose; 212 StartJobs; 213 end; 214 215 procedure TJobProgressView.StartJobs; 218 procedure TJobProgressView.Start; 216 219 var 217 220 I: Integer; … … 228 231 Form.MemoLog.Clear; 229 232 233 Form.PanelText.Visible := False; 230 234 Form.LabelEstimatedTimePart.Visible := False; 231 235 Form.LabelEstimatedTimeTotal.Visible := False; … … 257 261 Form.ProgressBarPart.Visible := False; 258 262 //Show; 259 ReloadJobList;263 Form.ReloadJobList; 260 264 Application.ProcessMessages; 261 265 if NoThreaded then begin … … 295 299 //if Visible then Hide; 296 300 Form.MemoLog.Lines.Assign(Log); 297 if (Form.MemoLog.Lines.Count = 0) and AutoClose then begin301 if (Form.MemoLog.Lines.Count = 0) and FAutoClose then begin 298 302 Form.Hide; 299 303 end; 300 Clear;304 //Clear; 301 305 Form.Caption := SFinished; 302 306 //LabelEstimatedTimePart.Visible := False; 303 307 Finished := True; 304 308 CurrentJobIndex := -1; 305 ReloadJobList;306 end; 307 end; 308 309 procedure T JobProgressView.UpdateHeight;309 Form.ReloadJobList; 310 end; 311 end; 312 313 procedure TFormJobProgressView.UpdateHeight; 310 314 var 311 315 H: Integer; … … 315 319 PanelProgressTotalVisible: Boolean; 316 320 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; 325 begin 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; 347 363 end; 348 364 … … 373 389 if not JobProgressView.OwnerDraw then Show; 374 390 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; 375 398 end; 376 399 … … 394 417 var CloseAction: TCloseAction); 395 418 begin 396 ListViewJobs.Clear;397 419 end; 398 420 … … 407 429 408 430 end; 431 end; 432 433 procedure TFormJobProgressView.ReloadJobList; 434 begin 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; 444 end; 445 446 procedure TFormJobProgressView.FormShow(Sender: TObject); 447 begin 448 ReloadJobList; 449 end; 450 451 procedure TFormJobProgressView.FormHide(Sender: TObject); 452 begin 453 JobProgressView.Jobs.Clear; 454 ReloadJobList; 409 455 end; 410 456 … … 489 535 end; 490 536 491 procedure TJobProgressView.ReloadJobList;492 begin493 UpdateHeight;494 // Workaround for not showing first line495 Form.ListViewJobs.Items.Count := Jobs.Count + 1;496 Form.ListViewJobs.Refresh;497 498 if Form.ListViewJobs.Items.Count <> Jobs.Count then499 Form.ListViewJobs.Items.Count := Jobs.Count;500 Form.ListViewJobs.Refresh;501 //Application.ProcessMessages;502 end;503 504 537 constructor TJobProgressView.Create(TheOwner: TComponent); 505 538 begin … … 509 542 Form.JobProgressView := Self; 510 543 end; 511 Jobs := T ObjectList.Create;544 Jobs := TJobs.Create; 512 545 Log := TStringList.Create; 513 546 //PanelOperationsTitle.Height := 80; … … 535 568 if FMax < 1 then FMax := 1; 536 569 if FValue >= FMax then FValue := FMax; 570 finally 571 FLock.Release; 572 end; 573 end; 574 575 procedure TProgress.SetText(AValue: string); 576 begin 577 try 578 FLock.Acquire; 579 if FText = AValue then Exit; 580 FText := AValue; 537 581 finally 538 582 FLock.Release;
Note:
See TracChangeset
for help on using the changeset viewer.