Ignore:
Timestamp:
Mar 16, 2022, 11:35:08 AM (2 years ago)
Author:
chronos
Message:
  • Added: QR code image visible in contact others tab. It can be saved as image to file.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormContact.pas

    r110 r123  
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    99  ComCtrls, ActnList, Menus, ExtCtrls, ExtDlgs, Buttons, UContact, LCLIntf,
    10   UFormProperties, DateUtils{$IFDEF LCLGTK2}, Gtk2Globals{$ENDIF}, UContactImage;
     10  UFormProperties, DateUtils, Gtk2Globals, UContactImage, ubarcodes;
    1111
    1212type
     
    2121    APhotoLoad: TAction;
    2222    ActionList1: TActionList;
     23    BarcodeQR1: TBarcodeQR;
    2324    ButtonCancel: TButton;
    2425    ButtonHomeAddressShow: TButton;
     
    9697    GroupBox2: TGroupBox;
    9798    ImagePhoto: TImage;
     99    Label1: TLabel;
    98100    Label10: TLabel;
    99101    Label11: TLabel;
     
    167169    MenuItem4: TMenuItem;
    168170    MenuItem5: TMenuItem;
     171    MenuItemSaveQrToFile: TMenuItem;
    169172    OpenPictureDialog1: TOpenPictureDialog;
    170173    PageControlContact: TPageControl;
     174    PopupMenuQrCode: TPopupMenu;
    171175    PopupMenuPhoto: TPopupMenu;
    172176    SavePictureDialog1: TSavePictureDialog;
     
    202206    procedure FormShow(Sender: TObject);
    203207    procedure ImagePhotoClick(Sender: TObject);
     208    procedure MenuItemSaveQrToFileClick(Sender: TObject);
    204209    procedure SpeedButtonHomeWebClick(Sender: TObject);
    205210    procedure SpeedButtonAniversaryClick(Sender: TObject);
     
    249254
    250255uses
    251   UCore, UCommon, UFormImage, UFormNameDetails;
     256  UCore, UCommon, UFormImage, UFormNameDetails, UDataFile;
    252257
    253258resourcestring
     
    255260  SPhotoUrl = 'Photo URL';
    256261  SPhotoUrlQuery = 'Enter URL for profile photo';
     262  SImageTypeNotSupported = 'Image type not supported.';
    257263
    258264function DateToISO(Date: TDateTime): string;
     
    341347end;
    342348
     349procedure TFormContact.MenuItemSaveQrToFileClick(Sender: TObject);
     350var
     351  F: string;
     352begin
     353  SavePictureDialog1.Filter := 'Windows bitmap files (*.bmp)|*.bmp|' +
     354   'Portable network graphic files (*.png)|*.png|' +
     355   'JPEG image files (*.jpg;*.jpeg)|*.jpg;*.jpeg|' +
     356   'TIFF image files (*.tiff; *.tif)|*.tiff;*.tif|'+
     357   'XPM image files (*.xpm)|*.xpm|' +
     358   'Scalable vector graphics files (*.svg)|*.svg|'+
     359   'Encapsulated PostScript files (*.eps;*.ps)|*.eps;*.ps|'+
     360   SAllFiles + ' (*.*)|*.*';
     361  SavePictureDialog1.FilterIndex := 2;
     362  SavePictureDialog1.DefaultExt := '.png';
     363  if Core.LastQrCodeFileName = '' then
     364    Core.LastQrCodeFileName := 'QR code.png';
     365  SavePictureDialog1.InitialDir := ExtractFileDir(Core.LastQrCodeFileName);
     366  SavePictureDialog1.FileName := ExtractFileName(Core.LastQrCodeFileName);
     367  if SavePictureDialog1.Execute then begin
     368    F := LowerCase(ExtractFileExt(SavePictureDialog1.FileName));
     369    if F = '.bmp' then BarcodeQR1.SaveToFile(SavePictureDialog1.FileName, TBitmap)
     370    else if F = '.png' then BarcodeQR1.SaveToFile(SavePictureDialog1.FileName, TPortableNetworkGraphic)
     371    else if (F = '.jpg') or (F = '.jpeg') then BarcodeQR1.SaveTofile(SavePictureDialog1.FileName, TJpegImage)
     372    else if (F = '.tif') or (F = '.tiff') then BarcodeQR1.SaveToFile(SavePictureDialog1.FileName, TTiffImage)
     373    else if F = '.xpm' then BarcodeQR1.SaveToFile(SavePictureDialog1.FileName, TPixmap)
     374    else if F = '.svg' then BarcodeQR1.SaveToSvgFile(SavePictureDialog1.FileName)
     375    else if (F = '.eps') or (F = '.ps') then BarcodeQR1.SaveToEpsFile(SavePictureDialog1.FileName)
     376    else raise Exception.Create(SImageTypeNotSupported);
     377    Core.LastQrCodeFileName := SavePictureDialog1.FileName;
     378  end;
     379end;
     380
    343381procedure TFormContact.SpeedButtonHomeWebClick(Sender: TObject);
    344382begin
     
    528566begin
    529567  MemoNotes.Lines.Text := Contact.Fields[cfNote];
     568  BarcodeQR1.Text := Contact.AsString;
    530569end;
    531570
     
    641680procedure TFormContact.APhotoLoadExecute(Sender: TObject);
    642681begin
    643   OpenPictureDialog1.FileName := Core.LastPhotoFileName;
     682  OpenPictureDialog1.InitialDir := ExtractFileDir(Core.LastPhotoFileName);
     683  OpenPictureDialog1.FileName := ExtractFileName(Core.LastPhotoFileName);
    644684  if OpenPictureDialog1.Execute then begin
    645685    FPhoto.LoadFromFile(OpenPictureDialog1.FileName);
     
    655695procedure TFormContact.APhotoSaveExecute(Sender: TObject);
    656696begin
    657   SavePictureDialog1.FileName := Core.LastPhotoFileName;
     697  SavePictureDialog1.InitialDir := ExtractFileDir(Core.LastPhotoFileName);
     698  SavePictureDialog1.FileName := ExtractFileName(Core.LastPhotoFileName);
    658699  if SavePictureDialog1.Execute then begin
    659700    ImagePhoto.Picture.SaveToFile(SavePictureDialog1.FileName);
     
    777818  FPhoto.FieldIndex := cfPhoto;
    778819  FPhoto.OnChange := PhotoChange;
     820
     821  // Set Barcode unpublished properties
     822  BarcodeQR1.Anchors := [akTop, akRight];
     823  BarcodeQR1.PopupMenu := PopupMenuQrCode;
    779824end;
    780825
Note: See TracChangeset for help on using the changeset viewer.