Changeset 32
- Timestamp:
- Nov 25, 2021, 11:32:55 AM (3 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormContact.pas
r31 r32 182 182 Photo := PhotoProperty.GetDecodedValue; 183 183 Stream := TMemoryStream.Create; 184 Stream.Write(Photo[1], Length(Photo)); 185 Stream.Position := 0; 186 JpegImage := TJPEGImage.Create; 187 JpegImage.LoadFromStream(Stream); 188 ImagePhoto.Picture.Bitmap.SetSize(JpegImage.Width, JpegImage.Height); 189 ImagePhoto.Picture.Bitmap.Canvas.Draw(0, 0, JpegImage); 190 JpegImage.Free; 191 Stream.Free; 184 try 185 Stream.Write(Photo[1], Length(Photo)); 186 Stream.Position := 0; 187 if PhotoProperty.Attributes.IndexOf('JPEG') <> -1 then begin 188 JpegImage := TJPEGImage.Create; 189 try 190 JpegImage.LoadFromStream(Stream); 191 ImagePhoto.Picture.Bitmap.SetSize(JpegImage.Width, JpegImage.Height); 192 ImagePhoto.Picture.Bitmap.Canvas.Draw(0, 0, JpegImage); 193 finally 194 JpegImage.Free; 195 end; 196 end else begin 197 ImagePhoto.Picture.Bitmap.LoadFromStream(Stream); 198 end; 199 finally 200 Stream.Free; 201 end; 192 202 end; 193 203 end; -
trunk/Forms/UFormContacts.lfm
r23 r32 14 14 object ListView1: TListView 15 15 Left = 0 16 Height = 8 6916 Height = 837 17 17 Top = 0 18 18 Width = 1210 … … 80 80 end 81 81 end 82 object ListViewFilter1: TListViewFilter 83 Left = 0 84 Height = 32 85 Top = 837 86 Width = 1210 87 OnChange = ListViewFilter1Change 88 Align = alBottom 89 end 82 90 object PopupMenuContact: TPopupMenu 83 91 Images = Core.ImageList1 … … 125 133 end 126 134 end 135 object ListViewSort1: TListViewSort 136 ListView = ListView1 137 OnCompareItem = ListViewSort1CompareItem 138 OnFilter = ListViewSort1Filter 139 OnColumnWidthChanged = ListViewSort1ColumnWidthChanged 140 Column = 0 141 Order = soNone 142 Left = 528 143 Top = 428 144 end 127 145 end -
trunk/Forms/UFormContacts.pas
r31 r32 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, 9 ComCtrls, Menus, ActnList, UContact ;9 ComCtrls, Menus, ActnList, UContact, UListViewSort, fgl, LazUTF8; 10 10 11 11 type … … 20 20 ActionList1: TActionList; 21 21 ListView1: TListView; 22 ListViewFilter1: TListViewFilter; 23 ListViewSort1: TListViewSort; 22 24 MenuItem1: TMenuItem; 23 25 MenuItem2: TMenuItem; … … 40 42 procedure ListView1SelectItem(Sender: TObject; Item: TListItem; 41 43 Selected: Boolean); 44 procedure ListViewFilter1Change(Sender: TObject); 45 procedure ListViewSort1ColumnWidthChanged(Sender: TObject); 46 function ListViewSort1CompareItem(Item1, Item2: TObject): Integer; 47 procedure ListViewSort1Filter(ListViewSort: TListViewSort); 42 48 private 43 49 FContacts: TContacts; 50 procedure FilterList(List: TFPGObjectList<TObject>); 44 51 procedure SetContacts(AValue: TContacts); 45 52 public … … 68 75 procedure TFormContacts.ListView1Data(Sender: TObject; Item: TListItem); 69 76 begin 70 if Assigned(Contacts) and (Item.Index < Contacts.Count)then71 with TContact( Contacts[Item.Index]) do begin77 if Item.Index < ListViewSort1.List.Count then 78 with TContact(ListViewSort1.List[Item.Index]) do begin 72 79 Item.Caption := Fields[cfFullName]; 73 80 Item.SubItems.Add(Fields[cfFirstName]); … … 91 98 end; 92 99 100 procedure TFormContacts.ListViewFilter1Change(Sender: TObject); 101 begin 102 ReloadList; 103 end; 104 105 procedure TFormContacts.ListViewSort1ColumnWidthChanged(Sender: TObject); 106 begin 107 ListViewFilter1.UpdateFromListView(ListView1); 108 end; 109 110 function TFormContacts.ListViewSort1CompareItem(Item1, Item2: TObject): Integer; 111 begin 112 Result := 0; 113 if Assigned(Item1) and Assigned(Item2) and (ListViewSort1.Order <> soNone) then begin 114 with ListViewSort1 do 115 case Column of 116 0: Result := CompareString(TContact(Item1).Fields[cfFullName], TContact(Item2).Fields[cfFullName]); 117 1: Result := CompareString(TContact(Item1).Fields[cfFirstName], TContact(Item2).Fields[cfFirstName]); 118 2: Result := CompareString(TContact(Item1).Fields[cfMiddleName], TContact(Item2).Fields[cfMiddleName]); 119 3: Result := CompareString(TContact(Item1).Fields[cfLastName], TContact(Item2).Fields[cfLastName]); 120 4: Result := CompareString(TContact(Item1).Fields[cfTelCell], TContact(Item2).Fields[cfTelCell]); 121 5: Result := CompareString(TContact(Item1).Fields[cfTelHome], TContact(Item2).Fields[cfTelHome]); 122 end; 123 if ListViewSort1.Order = soDown then Result := -Result; 124 end else Result := 0; 125 end; 126 127 procedure TFormContacts.ListViewSort1Filter(ListViewSort: TListViewSort); 128 begin 129 if Assigned(Contacts) then Contacts.AssignToList(ListViewSort1.List) 130 else ListViewSort1.List.Clear; 131 FilterList(ListViewSort1.List); 132 end; 133 134 procedure TFormContacts.FilterList(List: TFPGObjectList<TObject>); 135 var 136 I: Integer; 137 FoundCount: Integer; 138 EnteredCount: Integer; 139 begin 140 EnteredCount := ListViewFilter1.TextEnteredCount; 141 for I := List.Count - 1 downto 0 do begin 142 if List.Items[I] is TContact then begin 143 with TContact(List.Items[I]) do begin 144 with ListViewFilter1 do 145 if Visible and (EnteredCount > 0) then begin 146 FoundCount := 0; 147 if Pos(UTF8LowerCase(StringGrid.Cells[0, 0]), 148 UTF8LowerCase(TContact(List.Items[I]).Fields[cfFullName])) > 0 then Inc(FoundCount); 149 if Pos(UTF8LowerCase(StringGrid.Cells[1, 0]), 150 UTF8LowerCase(TContact(List.Items[I]).Fields[cfFirstName])) > 0 then Inc(FoundCount); 151 if Pos(UTF8LowerCase(StringGrid.Cells[2, 0]), 152 UTF8LowerCase(TContact(List.Items[I]).Fields[cfMiddleName])) > 0 then Inc(FoundCount); 153 if Pos(UTF8LowerCase(StringGrid.Cells[3, 0]), 154 UTF8LowerCase(TContact(List.Items[I]).Fields[cfLastName])) > 0 then Inc(FoundCount); 155 if Pos(UTF8LowerCase(StringGrid.Cells[4, 0]), 156 UTF8LowerCase(TContact(List.Items[I]).Fields[cfTelCell])) > 0 then Inc(FoundCount); 157 if Pos(UTF8LowerCase(StringGrid.Cells[5, 0]), 158 UTF8LowerCase(TContact(List.Items[I]).Fields[cfTelHome])) > 0 then Inc(FoundCount); 159 if FoundCount <> EnteredCount then List.Delete(I); 160 end; 161 end; 162 end else 163 if TContact(List.Items[I]) is TContact then begin 164 List.Delete(I); 165 end; 166 end; 167 end; 168 93 169 procedure TFormContacts.SetContacts(AValue: TContacts); 94 170 begin … … 106 182 ReloadList; 107 183 UpdateInterface; 184 ListViewFilter1.UpdateFromListView(ListView1); 108 185 end; 109 186 … … 182 259 procedure TFormContacts.ReloadList; 183 260 begin 184 if Assigned(Contacts) then 185 ListView1.Items.Count := Contacts.Count 186 else ListView1.Items.Count := 0; 187 ListView1.Refresh; 261 ListViewSort1.Refresh; 188 262 end; 189 263 -
trunk/UContact.pas
r31 r32 87 87 TContacts = class(TFPGObjectList<TContact>) 88 88 ContactsFile: TContactsFile; 89 procedure AssignToList(List: TFPGObjectList<TObject>); 89 90 function AddNew: TContact; 90 91 function Search(FullName: string): TContact; … … 185 186 procedure TContactProperty.EvaluateAttributes; 186 187 begin 188 if Attributes.IndexOf('BASE64') <> -1 then 189 Encoding := 'BASE64' 190 else 187 191 if Attributes.IndexOfName('ENCODING') <> -1 then 188 192 Encoding := Attributes.Values['ENCODING'] 189 193 else Encoding := ''; 194 190 195 if Attributes.IndexOfName('CHARSET') <> -1 then 191 196 Charset := Attributes.Values['CHARSET'] … … 245 250 246 251 { TContacts } 252 253 procedure TContacts.AssignToList(List: TFPGObjectList<TObject>); 254 var 255 I: Integer; 256 begin 257 List.Clear; 258 for I := 0 to Count - 1 do 259 List.Add(Items[I]); 260 end; 247 261 248 262 function TContacts.AddNew: TContact; … … 419 433 AddNew('TITLE', [], 'Title', cfTitle, dtString); 420 434 AddNew('CATEGORIES', [], 'Categories', cfCategories, dtString); 421 AddNew('ORG', [], 'Organization', cfOrganization, dtString); 435 AddNew('ORG', [], 'Organization', cfOrganization, dtString, 0); 436 AddNew('ORG', [], 'Division', cfOrganization, dtString, 1); 422 437 AddNew('ADR', ['HOME'], 'Home Address', cfAdrHome, dtString); 423 438 AddNew('ADR', ['HOME'], 'Home Address Street', cfHomeAddressStreet, dtString, 1);
Note:
See TracChangeset
for help on using the changeset viewer.