Ignore:
Timestamp:
Dec 3, 2021, 6:52:12 PM (3 years ago)
Author:
chronos
Message:
  • Added: Context menu action to clear profile image.
  • Fixed: Correctly show contact profile image.
  • Added: Remember last selected tab index in contact form.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormContact.pas

    r48 r49  
    1414
    1515  TFormContact = class(TForm)
     16    APhotoClear: TAction;
    1617    APhotoSave: TAction;
    1718    APhotoLoad: TAction;
     
    116117    MenuItem1: TMenuItem;
    117118    MenuItem2: TMenuItem;
     119    MenuItem3: TMenuItem;
    118120    OpenPictureDialog1: TOpenPictureDialog;
    119121    PageControlContact: TPageControl;
     
    125127    TabSheetGeneral: TTabSheet;
    126128    TabSheetAll: TTabSheet;
     129    procedure APhotoClearExecute(Sender: TObject);
    127130    procedure APhotoLoadExecute(Sender: TObject);
    128131    procedure APhotoSaveExecute(Sender: TObject);
     
    143146    procedure TabSheetWorkShow(Sender: TObject);
    144147  private
     148    FProfilePhotoActive: Boolean;
     149    procedure SetProfilePhotoActive(AValue: Boolean);
     150  private
    145151    FContact: TContact;
    146152    FOnNext: TNotifyEvent;
    147153    FOnPrevious: TNotifyEvent;
    148154    FormProperties: TFormProperties;
    149     ProfilePhotoActive: Boolean;
    150     procedure DefaultPhoto;
    151155    procedure SetContact(AValue: TContact);
    152156    procedure ReloadAllPropertiesTab;
     157    property ProfilePhotoActive: Boolean read FProfilePhotoActive
     158      write SetProfilePhotoActive;
    153159  public
    154160    procedure UpdateInterface;
     
    178184  FormProperties.Align := alClient;
    179185  FormProperties.Show;
     186
     187  // Force to load default profile image
     188  ProfilePhotoActive := True;
     189  ProfilePhotoActive := False;
     190
     191  PageControlContact.TabIndex := Core.LastContactTabIndex;
    180192  UpdateInterface;
    181193end;
     
    249261      Stream.Free;
    250262    end;
     263  end else begin
     264    PhotoProperty := Contact.GetProperty(cfPhoto);
     265    if Assigned(PhotoProperty) then
     266       Contact.Properties.Remove(PhotoProperty);
    251267  end;
    252268
     
    278294
    279295  // Photo
    280   ImagePhoto.Picture.Bitmap.Clear;
    281296  PhotoProperty := Contact.GetProperty(cfPhoto);
    282297  if Assigned(PhotoProperty) then begin
     
    292307            try
    293308              JpegImage.LoadFromStream(Stream);
     309              ImagePhoto.Picture.Bitmap.Clear;
    294310              ImagePhoto.Picture.Bitmap.SetSize(JpegImage.Width, JpegImage.Height);
    295311              ImagePhoto.Picture.Bitmap.Canvas.Draw(0, 0, JpegImage);
    296312              ProfilePhotoActive := True;
    297313            except
    298               DefaultPhoto;
     314              ProfilePhotoActive := False;
    299315            end;
    300316          finally
     
    306322            ProfilePhotoActive := True;
    307323          except
    308             DefaultPhoto;
     324            ProfilePhotoActive := False;
    309325          end;
    310326        end;
     
    312328        Stream.Free;
    313329      end;
    314     end else DefaultPhoto;
    315   end else DefaultPhoto;
     330    end else ProfilePhotoActive := False;
     331  end else ProfilePhotoActive := False;
    316332end;
    317333
     
    406422end;
    407423
    408 procedure TFormContact.DefaultPhoto;
    409 begin
    410   ProfilePhotoActive := False;
    411   ImagePhoto.Picture.Assign(Core.GetProfileImage.Picture);
     424procedure TFormContact.SetProfilePhotoActive(AValue: Boolean);
     425begin
     426  if FProfilePhotoActive = AValue then Exit;
     427  FProfilePhotoActive := AValue;
     428  if not FProfilePhotoActive then begin
     429    ImagePhoto.Picture.Assign(Core.GetProfileImage.Picture);
     430  end;
     431  UpdateInterface;
    412432end;
    413433
     
    428448  );
    429449begin
     450  // Hide PageControl to fire TabSheet OnHide event on form close
     451  PageControlContact.ActivePage.Hide;
     452
     453  Core.LastContactTabIndex := PageControlContact.TabIndex;
    430454  Core.PersistentForm1.Save(Self);
    431455end;
     
    440464  if OpenPictureDialog1.Execute then begin
    441465    ImagePhoto.Picture.LoadFromFile(OpenPictureDialog1.FileName);
     466    ProfilePhotoActive := True;
    442467  end;
     468end;
     469
     470procedure TFormContact.APhotoClearExecute(Sender: TObject);
     471begin
     472  ProfilePhotoActive := False;
    443473end;
    444474
     
    471501begin
    472502  APhotoSave.Enabled := ProfilePhotoActive;
     503  APhotoClear.Enabled := ProfilePhotoActive;
    473504end;
    474505
Note: See TracChangeset for help on using the changeset viewer.