Changeset 48


Ignore:
Timestamp:
Dec 3, 2021, 2:07:27 PM (2 years ago)
Author:
chronos
Message:
  • Added: Show default profile photo if contact image is not specified.
Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormContact.lfm

    r47 r48  
    137137        Top = 16
    138138        Width = 207
     139        Center = True
    139140        PopupMenu = PopupMenuPhoto
    140141        Proportional = True
  • trunk/Forms/UFormContact.pas

    r47 r48  
    147147    FOnPrevious: TNotifyEvent;
    148148    FormProperties: TFormProperties;
     149    ProfilePhotoActive: Boolean;
     150    procedure DefaultPhoto;
    149151    procedure SetContact(AValue: TContact);
    150152    procedure ReloadAllPropertiesTab;
     
    210212
    211213  // Photo
    212   if (ImagePhoto.Picture.Bitmap.Width <> 0) and (ImagePhoto.Picture.Bitmap.Height <> 0) then begin
     214  if ProfilePhotoActive then begin
    213215    PhotoProperty := Contact.GetProperty(cfPhoto);
    214216    if not Assigned(PhotoProperty) then begin
     
    292294              ImagePhoto.Picture.Bitmap.SetSize(JpegImage.Width, JpegImage.Height);
    293295              ImagePhoto.Picture.Bitmap.Canvas.Draw(0, 0, JpegImage);
     296              ProfilePhotoActive := True;
    294297            except
     298              DefaultPhoto;
    295299            end;
    296300          finally
     
    300304          try
    301305            ImagePhoto.Picture.LoadFromStream(Stream);
     306            ProfilePhotoActive := True;
    302307          except
     308            DefaultPhoto;
    303309          end;
    304310        end;
     
    306312        Stream.Free;
    307313      end;
    308     end;
    309   end;
     314    end else DefaultPhoto;
     315  end else DefaultPhoto;
    310316end;
    311317
     
    400406end;
    401407
     408procedure TFormContact.DefaultPhoto;
     409begin
     410  ProfilePhotoActive := False;
     411  ImagePhoto.Picture.Assign(Core.GetProfileImage.Picture);
     412end;
     413
    402414procedure TFormContact.SetContact(AValue: TContact);
    403415begin
     
    458470procedure TFormContact.UpdateInterface;
    459471begin
    460   APhotoSave.Enabled := (ImagePhoto.Picture.Bitmap.Width <> 0) and
    461     (ImagePhoto.Picture.Bitmap.Height <> 0);
     472  APhotoSave.Enabled := ProfilePhotoActive;
    462473end;
    463474
  • trunk/UCore.pas

    r43 r48  
    66
    77uses
    8   Classes, SysUtils, FileUtil, Controls, ActnList, Forms, Dialogs,
     8  Classes, SysUtils, FileUtil, Controls, ActnList, Forms, Dialogs, ExtCtrls,
    99  ULastOpenedList, UApplicationInfo, UPersistentForm, UScaleDPI, UCommon,
    1010  UTranslator, UDataFile, Menus, URegistry, UTheme, UAboutDialog, Registry;
     
    6969    InitializeFinished: Boolean;
    7070    LoadErrors: string;
     71    ProfileImage: TImage;
    7172    procedure FileModified(Sender: TObject);
    7273    function FindFirstNonOption: string;
     
    8182    ReopenLastFileOnStart: Boolean;
    8283    ToolbarVisible: Boolean;
     84    function GetProfileImage: TImage;
    8385    procedure FileNew;
    8486    procedure FileOpen(FileName: string);
     
    294296  FileClose;
    295297  SaveConfig;
     298  if Assigned(ProfileImage) then
     299    FreeAndNil(ProfileImage);
    296300end;
    297301
     
    454458end;
    455459
     460function TCore.GetProfileImage: TImage;
     461const
     462  ProfilePhotoFileName = 'Images/Profile.png';
     463begin
     464  if not Assigned(ProfileImage) then begin
     465    ProfileImage := TImage.Create(nil);
     466    ProfileImage.Picture.LoadFromFile(ProfilePhotoFileName);
     467    if FileExists(ProfilePhotoFileName) then
     468      ProfileImage.Picture.LoadFromFile(ProfilePhotoFileName);
     469  end;
     470  Result := ProfileImage;
     471end;
     472
    456473procedure TCore.UpdateInterface;
    457474begin
Note: See TracChangeset for help on using the changeset viewer.