⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rm_gedit.pas

📁 进销存·完整的·有数据库的·非常完整·只得参考
💻 PAS
字号:

{*****************************************}
{                                         }
{         Report Machine v2.0             }
{              Picture editor             }
{                                         }
{*****************************************}

unit RM_gedit;

interface

{$I RM.inc}

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, RM_Const, RM_Class;

type
  TRMGEditorForm = class(TRMObjEditorForm)
    btnOK: TButton;
    btnCancel: TButton;
    GroupBox1: TGroupBox;
    ScrollBox1: TScrollBox;
    ImagePaintBox: TPaintBox;
    btnLoadImage: TButton;
    btnClearImage: TButton;
    procedure btnClearImageClick(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure ImagePaintBoxPaint(Sender: TObject);
    procedure btnLoadImageClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
    FPic: TPicture;
    procedure Localize;
  public
    { Public declarations }
    function ShowEditor(View: TRMView): TModalResult; override;
    function ShowbkPicture(page: TRMPage): TModalResult;
  end;

implementation

{$R *.DFM}

uses RM_Utils, ClipBrd{$IFDEF OPENPICTUREDLG}, ExtDlgs{$ENDIF};

procedure TRMGEditorForm.Localize;
begin
	Font.Name := RMLoadStr(SRMDefaultFontName);
  Font.Size := StrToInt(RMLoadStr(SRMDefaultFontSize));
  Font.Charset := StrToInt(RMLoadStr(SCharset));

  RMSetStrProp(Self, 'Caption', rmRes + 460);
  RMSetStrProp(btnLoadImage, 'Caption', rmRes + 462);
  RMSetStrProp(btnClearImage, 'Caption', rmRes + 463);

  btnOK.Caption := RMLoadStr(SOk);
  btnCancel.Caption := RMLoadStr(SCancel);
end;

type
	THackPage = class(TRMPage)
  end;

function TRMGEditorForm.ShowbkPicture(page: TRMPage): TModalResult;
begin
  FPic.Assign(THackPage(page).FbkPicture);
  Result := ShowModal;
  if Result = mrOk then
  begin
    RMDesigner.BeforeChange;
    Page.SetbkPicture(FPic.Graphic);
  end;
end;

function TRMGEditorForm.ShowEditor(View: TRMView): TModalResult;
begin
  FPic.Assign((View as TRMPictureView).Picture);
  Result := ShowModal;
  if Result = mrOk then
  begin
    RMDesigner.BeforeChange;
    TRMPictureView(View).Picture.Assign(FPic);
  end;
end;

procedure TRMGEditorForm.btnClearImageClick(Sender: TObject);
begin
  FPic.Graphic := nil;
  ImagePaintBox.Invalidate;
end;

procedure TRMGEditorForm.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if ((Key = vk_Insert) and (ssShift in Shift)) or
    ((Chr(Key) = 'V') and (ssCtrl in Shift)) then
  begin
    FPic.Assign(Clipboard);
    ImagePaintBox.Invalidate;
  end;
end;

procedure TRMGEditorForm.ImagePaintBoxPaint(Sender: TObject);
var
  DrawRect: TRect;
begin
  with TPaintBox(Sender) do
  begin
    Canvas.Brush.Color := {Self.} Color;
    DrawRect := ClientRect; //Rect(Left, Top, Left + Width, Top + Height);
    if FPic.Width > 0 then
    begin
      with DrawRect do
      begin
        if (FPic.Width > Right - Left) or (FPic.Height > Bottom - Top) then
        begin
          if FPic.Width > FPic.Height then
            Bottom := Top + MulDiv(FPic.Height, Right - Left, FPic.Width)
          else
            Right := Left + MulDiv(FPic.Width, Bottom - Top, FPic.Height);
          Canvas.StretchDraw(DrawRect, FPic.Graphic);
        end
        else
        begin
          with DrawRect do
          begin
            Canvas.Draw(Left + (Right - Left - FPic.Width) div 2, Top + (Bottom - Top -
              FPic.Height) div 2, FPic.Graphic);
          end;
        end;
      end;
    end
    else
    begin
      with DrawRect, Canvas do
      begin
        TextOut(Left + (Right - Left - TextWidth(RMLoadStr(SNotAssigned))) div 2, Top + (Bottom -
          Top - TextHeight(RMLoadStr(SNotAssigned))) div 2, RMLoadStr(SNotAssigned));
      end;
    end;
  end;
end;

procedure TRMGEditorForm.btnLoadImageClick(Sender: TObject);
var
{$IFDEF OPENPICTUREDLG}
  OpenDlg: TOpenPictureDialog;
{$ELSE}
  OpenDlg: TOpenDialog;
{$ENDIF}
  s, s1: string;
begin
{$IFDEF OPENPICTUREDLG}
  OpenDlg := TOpenPictureDialog.Create(nil);
{$ELSE}
  OpenDlg := TOpenDialog.Create(nil);
{$ENDIF}
  try
    OpenDlg.Options := [ofHideReadOnly];
    s := '*.bmp *.ico *.wmf *.emf';
    s1 := '*.bmp;*.ico;*.wmf;*.emf';
{$IFDEF JPEG}
    s := s + ' *.jpg';
    s1 := s1 + ';*.jpg';
{$ENDIF}
{$IFDEF RXGIF}
    s := s + ' *.gif';
    s1 := s1 + ';*.gif';
{$ENDIF}
    OpenDlg.Filter := RMLoadStr(SPictFile) + ' (' + s + ')|' + s1 + '|' + RMLoadStr(SAllFiles) + '|*.*';
    if OpenDlg.Execute then
    begin
      FPic.LoadFromFile(OpenDlg.FileName);
      ImagePaintBox.Invalidate;
    end;
  finally
    OpenDlg.Free;
  end;
end;

procedure TRMGEditorForm.FormCreate(Sender: TObject);
begin
	Localize;
  FPic := TPicture.Create;
end;

procedure TRMGEditorForm.FormDestroy(Sender: TObject);
begin
  FPic.Free;
end;

end.

 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -