{
********************************************************************************

YaPeTaVi - Yet another Periodic Table Viewer
Copyright (C) 2010 Geoffray Levasseur <geoffray.levasseurbrandin@numericable.fr>.
All rights reserved.
http://www.geoffray-levasseur.org/

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.  See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA  02111-1307, USA.

********************************************************************************

Description:
  option form

}
unit frmOptions;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  Buttons, ComCtrls, StdCtrls, EditBtn, ExtCtrls;

type

  { TOptionsForm }

  TOptionsForm = class(TForm)
    btnSBlocBG: TBitBtn;
    btnAlkalieMetalBG: TBitBtn;
    btnMetalloidBG: TBitBtn;
    btnTransMetalBG: TBitBtn;
    btnAlkalineFG: TBitBtn;
    btnAlkalieMetalFG: TBitBtn;
    btnMetalloidFG: TBitBtn;
    btnTransMetalFG: TBitBtn;
    btnMinGrad: TBitBtn;
    btnMaxGrad: TBitBtn;
    btnUnknowGrad: TBitBtn;
    btnSBlocFG: TBitBtn;
    btnOtherMetalBG: TBitBtn;
    btnTextGrad: TBitBtn;
    btnOtherMetalFG: TBitBtn;
    btnNonMetalBG: TBitBtn;
    btnNonMetalFG: TBitBtn;
    btnHalogenBG: TBitBtn;
    btnHalogenFG: TBitBtn;
    btnNobleGasBG: TBitBtn;
    btnPBlocBG: TBitBtn;
    btnNobleGasFG: TBitBtn;
    btnRareEarthBG: TBitBtn;
    btnRareEarthFG: TBitBtn;
    btnPBlocFG: TBitBtn;
    btnFBlocBG: TBitBtn;
    btnFBlocFG: TBitBtn;
    btnDBlocBG: TBitBtn;
    btnDBlocFG: TBitBtn;
    btnAlkalineBG: TBitBtn;
    btnOk: TBitBtn;
    btnCancel: TBitBtn;
    CheckBox1: TCheckBox;
    cbIconTheme: TComboBox;
    ColorDialog: TColorDialog;
    DirectoryEdit1: TDirectoryEdit;
    DirectoryEdit2: TDirectoryEdit;
    DirectoryEdit3: TDirectoryEdit;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    GroupBox3: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    pcMain: TPageControl;
    pcColors: TPageControl;
    pnSBloc: TPanel;
    pnMaxGrad: TPanel;
    pnUnknowGrad: TPanel;
    pnOtherMetal: TPanel;
    pnNonMetal: TPanel;
    pnHalogen: TPanel;
    pnNobleGas: TPanel;
    pnRareEarth: TPanel;
    pnPBloc: TPanel;
    pnFBloc: TPanel;
    pnDBloc: TPanel;
    pnAlkaline: TPanel;
    pnAlkalieMetal: TPanel;
    pnMetalloid: TPanel;
    pnTransMetal: TPanel;
    pnMinGrad: TPanel;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    TabSheet3: TTabSheet;
    tsAppearance: TTabSheet;
    tsAdvanced: TTabSheet;
    procedure btnAlkalieMetalBGClick(Sender: TObject);
    procedure btnAlkalieMetalFGClick(Sender: TObject);
    procedure btnAlkalineBGClick(Sender: TObject);
    procedure btnAlkalineFGClick(Sender: TObject);
    procedure btnDBlocBGClick(Sender: TObject);
    procedure btnDBlocFGClick(Sender: TObject);
    procedure btnFBlocBGClick(Sender: TObject);
    procedure btnFBlocFGClick(Sender: TObject);
    procedure btnHalogenBGClick(Sender: TObject);
    procedure btnHalogenFGClick(Sender: TObject);
    procedure btnMaxGradClick(Sender: TObject);
    procedure btnMetalloidBGClick(Sender: TObject);
    procedure btnMetalloidFGClick(Sender: TObject);
    procedure btnMinGradClick(Sender: TObject);
    procedure btnNobleGasBGClick(Sender: TObject);
    procedure btnNobleGasFGClick(Sender: TObject);
    procedure btnNonMetalBGClick(Sender: TObject);
    procedure btnNonMetalFGClick(Sender: TObject);
    procedure btnOtherMetalBGClick(Sender: TObject);
    procedure btnOtherMetalFGClick(Sender: TObject);
    procedure btnPBlocBGClick(Sender: TObject);
    procedure btnPBlocFGClick(Sender: TObject);
    procedure btnRareEarthBGClick(Sender: TObject);
    procedure btnRareEarthFGClick(Sender: TObject);
    procedure btnSBlocBGClick(Sender: TObject);
    procedure btnSBlocFGClick(Sender: TObject);
    procedure btnTextGradClick(Sender: TObject);
    procedure btnTransMetalBGClick(Sender: TObject);
    procedure btnTransMetalFGClick(Sender: TObject);
    procedure btnUnknowGradClick(Sender: TObject);
    procedure cbIconThemeChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
    ChangedColors: Boolean;
    ChangedIconSet: Boolean;
    ChangedPaths: Boolean;
    ChangedBackup: Boolean;
  end; 

var
  OptionsForm: TOptionsForm;

implementation

uses
  uIconManager, uConst;

{ TOptionsForm }

procedure TOptionsForm.FormCreate(Sender: TObject);
var
  I: integer;
begin
  InitBtnGlyphs(Self);
  //I := 0;
  for I := 0 to 127 do
    if IconSetsList[I] <> '' then
    begin
      cbIconTheme.Items.Add(IconSetsList[I]);
    end;

  pnSBloc.Color := clSBlocBG;
  btnSBlocBG.Glyph := CreateColorGlyph(clSBlocBG, 16, 16);
  pnSBloc.Font.Color := clSBlocFG;
  btnSBlocFG.Glyph := CreateColorGlyph(clSBlocFG, 16, 16);

  pnPBloc.Color := clPBlocBG;
  btnPBlocBG.Glyph := CreateColorGlyph(clPBlocBG, 16, 16);
  pnPBloc.Font.Color := clPBlocFG;
  btnPBlocFG.Glyph := CreateColorGlyph(clPBlocFG, 16, 16);

  pnFBloc.Color := clFBlocBG;
  btnFBlocBG.Glyph := CreateColorGlyph(clFBlocBG, 16, 16);
  pnFBloc.Font.Color := clFBlocFG;
  btnFBlocFG.Glyph := CreateColorGlyph(clFBlocFG, 16, 16);

  pnDBloc.Color := clDBlocBG;
  btnDBlocBG.Glyph := CreateColorGlyph(clDBlocBG, 16, 16);
  pnDBloc.Font.Color := clDBlocFG;
  btnDBlocFG.Glyph := CreateColorGlyph(clDBlocFG, 16, 16);

  pnAlkaline.Color := clAlkalineBG;
  btnAlkalineBG.Glyph := CreateColorGlyph(clAlkalineBG, 16, 16);
  pnAlkaline.Font.Color := clAlkalineFG;
  btnAlkalineFG.Glyph := CreateColorGlyph(clAlkalineFG, 16, 16);

  pnAlkalieMetal.Color := clAlkalieMetalBG;
  btnAlkalieMetalBG.Glyph := CreateColorGlyph(clAlkalieMetalBG, 16, 16);
  pnAlkalieMetal.Font.Color := clAlkalieMetalFG;
  btnAlkalieMetalFG.Glyph := CreateColorGlyph(clAlkalieMetalFG, 16, 16);

  pnNonMetal.Color := clNonMetalBG;
  btnNonMetalBG.Glyph := CreateColorGlyph(clNonMetalBG, 16, 16);
  pnNonMetal.Font.Color := clNonMetalFG;
  btnNonMetalFG.Glyph := CreateColorGlyph(clNonMetalFG, 16, 16);

  pnHalogen.Color := clHalogenBG;
  btnHalogenBG.Glyph := CreateColorGlyph(clHalogenBG, 16, 16);
  pnHalogen.Font.Color := clHalogenFG;
  btnHalogenFG.Glyph := CreateColorGlyph(clHalogenFG, 16, 16);

  pnNobleGas.Color := clNobleGasBG;
  btnNobleGasBG.Glyph := CreateColorGlyph(clNobleGasBG, 16, 16);
  pnNobleGas.Font.Color := clNobleGasFG;
  btnNobleGasFG.Glyph := CreateColorGlyph(clNobleGasFG, 16, 16);

  pnTransMetal.Color := clTransMetalBG;
  btnTransMetalBG.Glyph := CreateColorGlyph(clTransMetalBG, 16, 16);
  pnTransMetal.Font.Color := clTransMetalFG;
  btnTransMetalFG.Glyph := CreateColorGlyph(clTransMetalFG, 16, 16);

  pnMetalloid.Color := clMetalloidBG;
  btnMetalloidBG.Glyph := CreateColorGlyph(clMetalloidBG, 16, 16);
  pnMetalloid.Font.Color := clMetalloidFG;
  btnMetalloidFG.Glyph := CreateColorGlyph(clMetalloidFG, 16, 16);

  pnRareEarth.Color := clRareEarthBG;
  btnRareEarthBG.Glyph := CreateColorGlyph(clRareEarthBG, 16, 16);
  pnRareEarth.Font.Color := clRareEarthFG;
  btnRareEarthFG.Glyph := CreateColorGlyph(clRareEarthFG, 16, 16);

  pnOtherMetal.Color := clOtherMetalBG;
  btnOtherMetalBG.Glyph := CreateColorGlyph(clOtherMetalBG, 16, 16);
  pnOtherMetal.Font.Color := clOtherMetalFG;
  btnOtherMetalFG.Glyph := CreateColorGlyph(clOtherMetalFG, 16, 16);

  pnMinGrad.Color := clGradientMin;
  btnMinGrad.Glyph := CreateColorGlyph(clGradientMin, 16, 16);
  pnMaxGrad.Color := clGradientMax;
  btnMaxGrad.Glyph := CreateColorGlyph(clGradientMax, 16, 16);
  pnUnknowGrad.Color := clGradientUnknow;
  btnUnknowGrad.Glyph := CreateColorGlyph(clGradientUnknow, 16, 16);
  pnMinGrad.Font.Color := clGradientText;
  pnMaxGrad.Font.Color := clGradientText;
  pnUnknowGrad.Font.Color := clGradientText;
  btnTextGrad.Glyph := CreateColorGlyph(clGradientText, 16, 16);
  pcMain.ActivePageIndex := 0;
  pcColors.ActivePageIndex := 0;
  ChangedBackup := False;
  ChangedColors := False;
  ChangedIconSet := False;
  ChangedPaths := False;
end;

procedure TOptionsForm.btnSBlocBGClick(Sender: TObject);
begin
  ColorDialog.Color := clSBlocBG;
  if ColorDialog.Execute then
  begin
    pnSBloc.Color := ColorDialog.Color;
    btnSBlocBG.Glyph := CreateColorGlyph(ColorDialog.Color, 16, 16);
    ChangedColors := True;
  end;
end;

procedure TOptionsForm.btnSBlocFGClick(Sender: TObject);
begin
  ColorDialog.Color := clSBlocFG;
  if ColorDialog.Execute then
  begin
    pnSBloc.Font.Color := ColorDialog.Color;
    btnSBlocFG.Glyph := CreateColorGlyph(ColorDialog.Color, 16, 16);
    ChangedColors := True;
  end;
end;

procedure TOptionsForm.btnTextGradClick(Sender: TObject);
begin
  ColorDialog.Color := clGradientText;
  if ColorDialog.Execute then
  begin
    pnMinGrad.Font.Color := ColorDialog.Color;
    pnMaxGrad.Font.Color := ColorDialog.Color;
    pnUnknowGrad.Font.Color := ColorDialog.Color;
    btnTextGrad.Glyph := CreateColorGlyph(ColorDialog.Color, 16, 16);
    ChangedColors := True;
  end;
end;

procedure TOptionsForm.btnTransMetalBGClick(Sender: TObject);
begin
  ColorDialog.Color := clTransMetalBG;
  if ColorDialog.Execute then
  begin
    pnTransMetal.Color := ColorDialog.Color;
    btnTransMetalBG.Glyph := CreateColorGlyph(ColorDialog.Color, 16, 16);
    ChangedColors := True;
  end;
end;

procedure TOptionsForm.btnTransMetalFGClick(Sender: TObject);
begin
  ColorDialog.Color := clTransMetalFG;
  if ColorDialog.Execute then
  begin
    pnTransMetal.Font.Color := ColorDialog.Color;
    btnTransMetalFG.Glyph := CreateColorGlyph(ColorDialog.Color, 16, 16);
    ChangedColors := True;
  end;
end;

procedure TOptionsForm.btnUnknowGradClick(Sender: TObject);
begin
  ColorDialog.Color := clGradientUnknow;
  if ColorDialog.Execute then
  begin
    pnUnknowGrad.Color := ColorDialog.Color;
    btnUnknowGrad.Glyph := CreateColorGlyph(ColorDialog.Color, 16, 16);
    ChangedColors := True;
  end;
end;

procedure TOptionsForm.cbIconThemeChange(Sender: TObject);
begin
  ChangedIconSet := True;
end;

procedure TOptionsForm.btnPBlocBGClick(Sender: TObject);
begin
  ColorDialog.Color := clPBlocBG;
  if ColorDialog.Execute then
  begin
    pnPBloc.Color := ColorDialog.Color;
    btnPBlocBG.Glyph := CreateColorGlyph(ColorDialog.Color, 16, 16);
    ChangedColors := True;
  end;
end;

procedure TOptionsForm.btnPBlocFGClick(Sender: TObject);
begin
  ColorDialog.Color := clFBlocFG;
  if ColorDialog.Execute then
  begin
    pnFBloc.Font.Color := ColorDialog.Color;
    btnFBlocFG.Glyph := CreateColorGlyph(ColorDialog.Color, 16, 16);
    ChangedColors := True;
  end;
end;

procedure TOptionsForm.btnRareEarthBGClick(Sender: TObject);
begin
  ColorDialog.Color := clRareEarthBG;
  if ColorDialog.Execute then
  begin
    pnRareEarth.Color := ColorDialog.Color;
    btnRareEarthBG.Glyph := CreateColorGlyph(ColorDialog.Color, 16, 16);
    ChangedColors := True;
  end;
end;

procedure TOptionsForm.btnRareEarthFGClick(Sender: TObject);
begin
  ColorDialog.Color := clRareEarthFG;
  if ColorDialog.Execute then
  begin
    pnRareEarth.Font.Color := ColorDialog.Color;
    btnRareEarthFG.Glyph := CreateColorGlyph(ColorDialog.Color, 16, 16);
    ChangedColors := True;
  end;
end;

procedure TOptionsForm.btnFBlocBGClick(Sender: TObject);
begin
  ColorDialog.Color := clFBlocBG;
  if ColorDialog.Execute then
  begin
    pnFBloc.Color := ColorDialog.Color;
    btnFBlocBG.Glyph := CreateColorGlyph(ColorDialog.Color, 16, 16);
    ChangedColors := True;
  end;
end;

procedure TOptionsForm.btnFBlocFGClick(Sender: TObject);
begin
  ColorDialog.Color := clFBlocFG;
  if ColorDialog.Execute then
  begin
    pnFBloc.Font.Color := ColorDialog.Color;
    btnFBlocFG.Glyph := CreateColorGlyph(ColorDialog.Color, 16, 16);
    ChangedColors := True;
  end;
end;

procedure TOptionsForm.btnHalogenBGClick(Sender: TObject);
begin
  ColorDialog.Color := clHalogenBG;
  if ColorDialog.Execute then
  begin
    pnHalogen.Color := ColorDialog.Color;
    btnHalogenBG.Glyph := CreateColorGlyph(ColorDialog.Color, 16, 16);
    ChangedColors := True;
  end;
end;

procedure TOptionsForm.btnHalogenFGClick(Sender: TObject);
begin
  ColorDialog.Color := clHalogenFG;
  if ColorDialog.Execute then
  begin
    pnHalogen.Font.Color := ColorDialog.Color;
    btnHalogenFG.Glyph := CreateColorGlyph(ColorDialog.Color, 16, 16);
    ChangedColors := True;
  end;
end;

procedure TOptionsForm.btnMaxGradClick(Sender: TObject);
begin
  ColorDialog.Color := clGradientMax;
  if ColorDialog.Execute then
  begin
    pnMaxGrad.Color := ColorDialog.Color;
    btnMaxGrad.Glyph := CreateColorGlyph(ColorDialog.Color, 16, 16);
    ChangedColors := True;
  end;
end;

procedure TOptionsForm.btnMetalloidBGClick(Sender: TObject);
begin
  ColorDialog.Color := clMetalloidBG;
  if ColorDialog.Execute then
  begin
    pnMetalloid.Color := ColorDialog.Color;
    btnMetalloidBG.Glyph := CreateColorGlyph(ColorDialog.Color, 16, 16);
    ChangedColors := True;
  end;
end;

procedure TOptionsForm.btnMetalloidFGClick(Sender: TObject);
begin
  ColorDialog.Color := clMetalloidFG;
  if ColorDialog.Execute then
  begin
    pnMetalloid.Font.Color := ColorDialog.Color;
    btnMetalloidFG.Glyph := CreateColorGlyph(ColorDialog.Color, 16, 16);
    ChangedColors := True;
  end;
end;

procedure TOptionsForm.btnMinGradClick(Sender: TObject);
begin
  ColorDialog.Color := clGradientMin;
  if ColorDialog.Execute then
  begin
    pnMinGrad.Color := ColorDialog.Color;
    btnMinGrad.Glyph := CreateColorGlyph(ColorDialog.Color, 16, 16);
    ChangedColors := True;
  end;
end;

procedure TOptionsForm.btnNobleGasBGClick(Sender: TObject);
begin
  ColorDialog.Color := clNobleGasBG;
  if ColorDialog.Execute then
  begin
    pnNobleGas.Color := ColorDialog.Color;
    btnNobleGasBG.Glyph := CreateColorGlyph(ColorDialog.Color, 16, 16);
    ChangedColors := True;
  end;
end;

procedure TOptionsForm.btnNobleGasFGClick(Sender: TObject);
begin
  ColorDialog.Color := clNobleGasFG;
  if ColorDialog.Execute then
  begin
    pnNobleGas.Font.Color := ColorDialog.Color;
    btnNobleGasFG.Glyph := CreateColorGlyph(ColorDialog.Color, 16, 16);
    ChangedColors := True;
  end;
end;

procedure TOptionsForm.btnNonMetalBGClick(Sender: TObject);
begin
  ColorDialog.Color := clNonMetalBG;
  if ColorDialog.Execute then
  begin
    pnOtherMetal.Color := ColorDialog.Color;
    btnOtherMetalBG.Glyph := CreateColorGlyph(ColorDialog.Color, 16, 16);
    ChangedColors := True;
  end;
end;

procedure TOptionsForm.btnNonMetalFGClick(Sender: TObject);
begin
  ColorDialog.Color := clNonMetalFG;
  if ColorDialog.Execute then
  begin
    pnNonMetal.Font.Color := ColorDialog.Color;
    btnNonMetalFG.Glyph := CreateColorGlyph(ColorDialog.Color, 16, 16);
    ChangedColors := True;
  end;
end;

procedure TOptionsForm.btnOtherMetalBGClick(Sender: TObject);
begin
   ColorDialog.Color := clOtherMetalBG;
  if ColorDialog.Execute then
  begin
    pnOtherMetal.Color := ColorDialog.Color;
    btnOtherMetalBG.Glyph := CreateColorGlyph(ColorDialog.Color, 16, 16);
    ChangedColors := True;
  end;
end;

procedure TOptionsForm.btnOtherMetalFGClick(Sender: TObject);
begin
   ColorDialog.Color := clOtherMetalFG;
   if ColorDialog.Execute then
   begin
     pnOtherMetal.Font.Color := ColorDialog.Color;
     btnOtherMetalFG.Glyph := CreateColorGlyph(ColorDialog.Color, 16, 16);
     ChangedColors := True;
   end;
end;

procedure TOptionsForm.btnDBlocBGClick(Sender: TObject);
begin
  ColorDialog.Color := clDBlocBG;
  if ColorDialog.Execute then
  begin
    pnDBloc.Color := ColorDialog.Color;
    btnDBlocBG.Glyph := CreateColorGlyph(ColorDialog.Color, 16, 16);
    ChangedColors := True;
  end;
end;

procedure TOptionsForm.btnAlkalineBGClick(Sender: TObject);
begin
  ColorDialog.Color := clAlkalineBG;
  if ColorDialog.Execute then
  begin
    pnAlkaline.Color := ColorDialog.Color;
    btnAlkalineBG.Glyph := CreateColorGlyph(ColorDialog.Color, 16, 16);
    ChangedColors := True;
  end;
end;

procedure TOptionsForm.btnAlkalineFGClick(Sender: TObject);
begin
  ColorDialog.Color := clAlkalineFG;
  if ColorDialog.Execute then
  begin
    pnAlkaline.Font.Color := ColorDialog.Color;
    btnAlkalineFG.Glyph := CreateColorGlyph(ColorDialog.Color, 16, 16);
    ChangedColors := True;
  end;
end;

procedure TOptionsForm.btnAlkalieMetalBGClick(Sender: TObject);
begin
  ColorDialog.Color := clAlkalieMetalBG;
  if ColorDialog.Execute then
  begin
    pnAlkalieMetal.Color := ColorDialog.Color;
    btnAlkalieMetalBG.Glyph := CreateColorGlyph(ColorDialog.Color, 16, 16);
    ChangedColors := True;
  end;
end;

procedure TOptionsForm.btnAlkalieMetalFGClick(Sender: TObject);
begin
  ColorDialog.Color := clAlkalieMetalFG;
  if ColorDialog.Execute then
  begin
    pnAlkalieMetal.Font.Color := ColorDialog.Color;
    btnAlkalieMetalFG.Glyph := CreateColorGlyph(ColorDialog.Color, 16, 16);
    ChangedColors := True;
  end;
end;

procedure TOptionsForm.btnDBlocFGClick(Sender: TObject);
begin
  ColorDialog.Color := clDBlocFG;
  if ColorDialog.Execute then
  begin
    pnDBloc.Font.Color := ColorDialog.Color;
    btnDBlocFG.Glyph := CreateColorGlyph(ColorDialog.Color, 16, 16);
    ChangedColors := True;
  end;
end;

initialization
  {$I frmoptions.lrs}

end.

