Subversion Repositories autosfx

Rev

Blame | Last modification | View Log | RSS feed

  1. Unit SortGridPreview;
  2. (************************************************************************
  3.  Copyright (C) 2009, 2010  by Russell J. Peters, Roger Aelbrecht,
  4.       Eric W. Engler and Chris Vleghert.
  5.  
  6.    This file is part of TZipMaster Version 1.9.
  7.  
  8.     TZipMaster is free software: you can redistribute it and/or modify
  9.     it under the terms of the GNU Lesser General Public License as published by
  10.     the Free Software Foundation, either version 3 of the License, or
  11.     (at your option) any later version.
  12.  
  13.     TZipMaster is distributed in the hope that it will be useful,
  14.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.     GNU Lesser General Public License for more details.
  17.  
  18.     You should have received a copy of the GNU Lesser General Public License
  19.     along with TZipMaster.  If not, see <http://www.gnu.org/licenses/>.
  20.  
  21.     contact: problems@delphizip.org (include ZipMaster in the subject).
  22.     updates: http://www.delphizip.org
  23.     DelphiZip maillist subscribe at http://www.freelists.org/list/delphizip
  24. ************************************************************************)
  25.  
  26. INTERFACE
  27.  
  28. uses
  29.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  30.   ExtCtrls, StdCtrls, ComCtrls, Buttons, Printers,
  31.   ExtDlgs, SortGrid;
  32.  
  33. type
  34.   TSortGridPreviewForm = class( TForm )
  35.     ScrollBox1:          TScrollBox;
  36.     PreviewImage:        TImage;
  37.     Panel1:              TPanel;
  38.     Header:              TEdit;
  39.     Headers:             TListBox;
  40.     Margins:             TListBox;
  41.     ckborders:           TCheckBox;
  42.     btnprint:            TSpeedButton;
  43.     btnshow:             TSpeedButton;
  44.     btnsetup:            TSpeedButton;
  45.     btnfull:             TSpeedButton;
  46.     btnpic:              TSpeedButton;
  47.     lblpages:            TLabel;
  48.     cklive:              TCheckBox;
  49.     PrinterSetupDialog1: TPrinterSetupDialog;
  50.     OpenPictureDialog1:  TOpenPictureDialog;
  51.     PreviewPage: TEdit;
  52.     Margin: TEdit;
  53.  
  54.     procedure btnshowClick( Sender: TObject );
  55.     procedure MarginsClick( Sender: TObject );
  56.     procedure btnprintClick( Sender: TObject );
  57.     procedure MarginChange( Sender: TObject );
  58.     procedure HeaderChange( Sender: TObject );
  59.     procedure FormShow( Sender: TObject );
  60.     procedure ckbordersClick( Sender: TObject );
  61.     procedure previewpageChange( Sender: TObject );
  62.     procedure HeadersClick( Sender: TObject );
  63.     procedure ckliveClick( Sender: TObject );
  64.     procedure btnsetupClick( Sender: TObject );
  65.     procedure btnfullClick( Sender: TObject );
  66.     procedure FormCreate( Sender: TObject );
  67.     procedure FormDestroy( Sender: TObject );
  68.     procedure PreviewImageClick( Sender: TObject );
  69.     procedure btnpicClick( Sender: TObject );
  70.  
  71.   private
  72.     fGrid:       TSortGrid;
  73.     fPrintImage: TBitmap;
  74.  
  75.     procedure SetGrid( Const Value: TSortGrid );
  76.     procedure FullSize;
  77.     procedure SetPrintImage( Const Value: TBitmap );
  78.     procedure Zoom( factor: Extended );
  79.  
  80.   published
  81.    property Grid: TSortGrid read fGrid write SetGrid;
  82.    property PrintImage: TBitmap read fPrintImage write SetPrintImage;
  83. end;
  84.  
  85. var
  86.   SortGridPreviewForm: TSortGridPreviewForm;
  87.  
  88. IMPLEMENTATION
  89.  
  90. {$R *.DFM}
  91.  
  92. procedure TSortGridPreviewForm.SetGrid( const Value: TSortGrid );
  93. begin
  94.    fGrid := Value;
  95. end;
  96.  
  97. procedure TSortGridPreviewForm.btnshowClick( Sender: TObject );
  98. begin
  99.    if Assigned( fGrid ) then
  100.    begin
  101.       fGrid.UpdatePreview( fPrintImage.Canvas );
  102.       PreviewImage.Picture.Bitmap.Assign( fPrintImage );
  103.    end;
  104. end;
  105.  
  106. procedure TSortGridPreviewForm.MarginsClick( Sender: TObject );
  107. var
  108.    index, s: Integer;
  109. begin
  110.    index := margins.ItemIndex;
  111.    case index of
  112.      0: s := Grid.PrintOptions.MarginTop;
  113.      1: s := Grid.PrintOptions.PageTitleMargin;
  114.      2: s := Grid.PrintOptions.MarginLeft;
  115.      3: s := Grid.PrintOptions.MarginRight;
  116.      4: s := Grid.PrintOptions.MarginBottom;
  117.      5: s := Grid.PrintOptions.Leftpadding;
  118.      6: s := Grid.PrintOptions.HeaderSize;
  119.      7: s := Grid.PrintOptions.FooterSize;
  120.      else
  121.        Exit;
  122.    end;
  123.    Margin.Text := IntToStr( s );
  124. end;
  125.  
  126. procedure TSortGridPreviewForm.btnprintClick( Sender: TObject );
  127. begin
  128.    Grid.Print;
  129. end;
  130.  
  131. procedure TSortGridPreviewForm.MarginChange( Sender: TObject );
  132. var
  133.    index, v: Integer;
  134. begin
  135.    index := margins.ItemIndex;
  136.    v := StrToInt( Margin.Text );
  137.    case index of
  138.      0: Grid.PrintOptions.MarginTop := v;
  139.      1: Grid.PrintOptions.PageTitleMargin := v;
  140.      2: Grid.PrintOptions.MarginLeft := v;
  141.      3: Grid.PrintOptions.MarginRight := v;
  142.      4: Grid.PrintOptions.MarginBottom := v;
  143.      5: Grid.PrintOptions.Leftpadding := v;
  144.      6: Grid.PrintOptions.HeaderSize := v;
  145.      7: Grid.PrintOptions.FooterSize := v;
  146.    else
  147.      Exit;
  148.    end;
  149.    if cklive.Checked then btnshow.Click;
  150. end;
  151.  
  152. procedure TSortGridPreviewForm.HeaderChange( Sender: TObject );
  153. var
  154.    index: Integer;
  155. begin
  156.    index := headers.ItemIndex ;
  157.    if index = -1 then Exit;
  158.    if index = 0 then
  159.       Grid.PrintOptions.PageTitle := header.Text
  160.    else if index=1 then
  161.       Grid.PrintOptions.PageFooter := header.Text
  162.    else if index=2 then
  163.       Grid.PrintOptions.DateFormat :=header.Text
  164.    else if index=3 then
  165.      Grid.PrintOptions.TimeFormat := header.Text
  166.    else if index=4 then
  167.      Grid.PrintOptions.Logo := header.Text;
  168.    if cklive.Checked then btnshow.Click;
  169. end;
  170.  
  171. procedure TSortGridPreviewForm.FormShow( Sender: TObject );
  172. begin
  173.    Header.Text := Grid.PrintOptions.PageTitle;
  174.    Margin.Text := IntToStr( Grid.Printoptions.MarginTop );
  175.    Margins.ItemIndex := 0;
  176. //   Previewpage.MaxValue := Grid.PageCount;
  177.    lblpages.Caption := 'of ' + IntToStr( Grid.PageCount );
  178.    Grid.PrintOptions.PreviewPage := 1;
  179.    PreviewPage.Text := '1';
  180.    ckBorders.Checked := (Grid.PrintOptions.Borderstyle = bsSingle);
  181.    Header.Text := Grid.PrintOptions.PageTitle;
  182.    Headers.ItemIndex := 0;
  183. end;
  184.  
  185. procedure TSortGridPreviewForm.ckbordersClick( Sender: TObject );
  186. begin
  187.    if ckborders.Checked then
  188.       Grid.PrintOptions.BorderStyle := bsSingle
  189.    else
  190.      Grid.PrintOptions.BorderStyle := bsNone;
  191.    if cklive.Checked then btnshow.Click;
  192. end;
  193.  
  194. procedure TSortGridPreviewForm.previewPageChange( Sender: TObject );
  195. begin
  196.    Grid.PrintOptions.PreviewPage := StrToInt( PreviewPage.Text );
  197.    if cklive.Checked then btnshow.Click;
  198. end;
  199.  
  200. procedure TSortGridPreviewForm.HeadersClick( Sender: TObject );
  201. var
  202.    index: Integer;
  203. begin
  204.    index := headers.ItemIndex;
  205.    if index = -1 then Exit;
  206.    btnpic.Enabled := False;
  207.    if index = 0 then
  208.      header.Text := Grid.PrintOptions.PageTitle
  209.    else if index = 1 then
  210.      header.Text := Grid.PrintOptions.PageFooter
  211.    else if index = 2 then
  212.      header.Text := Grid.PrintOptions.DateFormat
  213.    else if index = 3 then
  214.      header.Text := Grid.PrintOptions.TimeFormat
  215.    else if index = 4 then
  216.    begin
  217.      header.Text := Grid.PrintOptions.Logo;
  218.      btnpic.Enabled := True;
  219.    end;
  220. end;
  221.  
  222. procedure TSortGridPreviewForm.ckliveClick( Sender: TObject );
  223. begin
  224.    if cklive.checked then btnshow.Click ;
  225. end;
  226.  
  227. procedure TSortGridPreviewForm.btnsetupClick( Sender: TObject );
  228. begin
  229.    if PrinterSetupDialog1.Execute then
  230.    begin
  231.       Grid.PrintOptions.Orientation := Printer.Orientation;
  232. //      Previewpage.MaxValue := Grid.PageCount;
  233.       lblpages.Caption := 'of ' + IntToStr( Grid.PageCount );
  234.       if cklive.checked then btnshow.Click;
  235.    end;
  236. end;
  237.  
  238. procedure TSortGridPreviewForm.FullSize;
  239. var
  240.    bm:   TBitmap;
  241.    w, h: Integer;
  242. begin
  243.    w := PrintImage.Width;
  244.    h := PrintImage.Height ;
  245.    bm := TBitmap.Create;
  246.    bm.Width := Scrollbox1.ClientWidth;
  247.    bm.Height := Round( h / w * bm.Width );
  248.    PrintImage.PixelFormat := pf24bit;
  249.    bm.PixelFormat := pf24bit;
  250.    fGrid.SmoothResize( fPrintImage, bm );
  251.    PreviewImage.Picture.Bitmap.Assign( bm );
  252.    bm.Free;
  253. end;
  254.  
  255. procedure TSortGridPreviewForm.btnfullClick( Sender: TObject );
  256. begin
  257.    FullSize;
  258. end;
  259.  
  260. procedure TSortGridPreviewForm.SetPrintImage( const Value: TBitmap );
  261. begin
  262.    fPrintImage := Value;
  263. end;
  264.  
  265. procedure TSortGridPreviewForm.FormCreate( Sender: TObject );
  266. begin
  267.    fPrintImage := TBitmap.Create ;
  268. end;
  269.  
  270. procedure TSortGridPreviewForm.FormDestroy( Sender: TObject );
  271. begin
  272.    fPrintImage.Free;
  273. end;
  274.  
  275. procedure TSortGridPreviewForm.PreviewImageClick( Sender: TObject );
  276. var
  277.    w, w1: Integer;
  278. begin
  279.    w1 := PreviewImage.Picture.Bitmap.Width;
  280.    w  := fPrintImage.Width;
  281.    if ( Round( w * 0.8 ) < w1 ) then
  282.    begin
  283.       PreviewImage.Picture.Bitmap.Assign( fPrintImage );
  284.    end else
  285.    begin
  286.       Zoom( w1 / w / 0.8 );
  287.    end;
  288. end;
  289.  
  290. procedure TSortGridPreviewForm.Zoom( factor: Extended );
  291. var bm:   TBitmap;
  292.     w, h: Integer;
  293. begin
  294.    w := PrintImage.Width;
  295.    h := PrintImage.Height ;
  296.    bm := TBitmap.Create;
  297.    bm.Width := Round( factor * w );
  298.    bm.Height:= Round( h / w * bm.Width );
  299.    PrintImage.PixelFormat := pf24bit;
  300.    bm.PixelFormat := pf24bit;
  301.    fGrid.SmoothResize( fPrintImage, bm );
  302.    Previewimage.Picture.Bitmap.Assign( bm );
  303.    bm.Free;
  304. end;
  305.  
  306. procedure TSortGridPreviewForm.btnpicClick( Sender: TObject );
  307. begin
  308.    if OpenPictureDialog1.Execute then if Headers.ItemIndex = 4 then
  309.    begin
  310.       header.Text := OpenPictureDialog1.Filename;
  311.       Grid.PrintOptions.Logo := OpenPictureDialog1.Filename;
  312.    end;
  313. end;
  314.  
  315. End.
  316.