You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
RnQ/RnQ/Prefs/themedit_fr.pas

367 lines
9.5 KiB
Plaintext

{
This file is part of R&Q.
Under same license
}
unit themedit_fr;
{$I RnQConfig.inc}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, UITypes,
StdCtrls, ExtCtrls, ToolWin, ComCtrls, RnQButtons,
RDGlobal, RQUtil, RQThemes, RnQDialogs, RnQSpin, RnQPrefsLib;
{$I NoRTTI.inc}
type
TthemeditFr = class(TPrefFrame)
sizeSpin: TRnQSpinEdit;
sizeLbl: TLabel;
Label2: TLabel;
Label3: TLabel;
stringBox: TMemo;
propsBox: TComboBox;
textBox: TMemo;
fontLbl: TLabel;
MPlayerBar: TToolBar;
PlayBtn: TRnQSpeedButton;
ColorBtn: TColorPickerButton;
fnBox: TEdit;
fnBoxButton: TRnQSpeedButton;
FontBox: TEdit;
FontBoxButton: TRnQSpeedButton;
ImgPBox: TPaintBox;
addBtn: TRnQButton;
procedure ColorBtnChange(Sender: TObject);
procedure PlayBtnClick(Sender: TObject);
procedure propsBoxChange(Sender: TObject);
procedure addBtnClick(Sender: TObject);
procedure fileBox11Change(Sender: TObject);
procedure setupGUI;
procedure updateGUI;
procedure fontBox11Change(Sender: TObject);
procedure FontBoxButtonClick(Sender: TObject);
procedure fnBoxButtonClick(Sender: TObject);
procedure propsBoxKeyPress(Sender: TObject; var Key: Char);
procedure ImgPBoxPaint(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
protected
haveToApplyTheme: Boolean;
fImgElm: TRnQThemedElementDtls;
// img_PicLoc : TPicLocation;
// img_themetkn : Integer;
// img_idx : Integer;
themeprops: aTthemeproperty;
Sound_FileName: String;
public
procedure applyPage; Override; final;
procedure resetPage; Override; final;
procedure initPage; Override; final;
procedure unInitPage; Override; final;
// procedure applyPage;
// procedure resetPage;
end;
implementation
uses
Types, RDFileUtil, RDUtils,
utilLib, prefDlg, globalLib, themesLib;
{$R *.dfm}
procedure TthemeditFr.setupGUI;
const
gap = 15;
var
p: ^Tthemeproperty;
y: integer;
s: String;
// f: TFont;
begin
if propsBox.itemIndex < 0 then
begin
FontBox.visible := false;
FontBoxButton.visible := false;
sizeSpin.visible := false;
sizeLbl.visible := false;
fontLbl.visible := false;
ColorBtn.visible := false;
fnBox.visible := false;
fnBoxButton.visible := false;
MPlayerBar.visible := false;
exit;
end;
p := @themeprops[propsBox.itemIndex];
// f := TFont
case p.kind of
TP_color:
ColorBtn.SelectionColor := theme.GetColor(copy(p.name, 1, length(p.name) - 6));
TP_font:
begin
FontBox.Font.Assign(Screen.MenuFont);
s := copy(p.name, 1, length(p.name) - 5);
theme.ApplyFont(s, FontBox.Font);
// with f do
begin
ColorBtn.SelectionColor := FontBox.Font.color;
FontBox.Text := FontBox.Font.name; // findInStrings(name, fontBox.items);
// fontBox.Font := f;
sizeSpin.Value := FontBox.Font.size;
end;
end;
TP_pic, TP_ico:
begin
fImgElm.picName := p.name;
with theme.GetPicSize(fImgElm) do
begin
fImgElm.ThemeToken := -1;
ImgPBox.Width := cx;
ImgPBox.Height := cy;
end;
ImgPBox.Repaint;
// img.Refresh;
end;
// assignImgPic(img.Picture.Bitmap, p.name);
// TP_ico: assignImgIco(img,theme.GetIco(p.name));
// TP_ico: assignImgPic(img, p.name);
// TP_string: stringBox.text:=string(p.ptr^);
TP_sound:
begin
// Sound_FileName:= '';
Sound_FileName := theme.GetSound(p.name);
fnBox.Text := Sound_FileName;
// try mplayer.open except end;
end;
TP_string:
begin
stringBox.Text := theme.GetString(p.name);
// try mplayer.open except end;
end;
end;
y := propsBox.BoundsRect.Bottom + gap;
ColorBtn.visible := p.kind in [TP_color, TP_font];
if ColorBtn.visible then
begin
ColorBtn.top := y;
inc(y, ColorBtn.Height + gap);
end;
FontBox.visible := p.kind = TP_font;
FontBoxButton.visible := FontBox.visible;
sizeSpin.visible := p.kind = TP_font;
sizeLbl.visible := p.kind = TP_font;
fontLbl.visible := p.kind = TP_font;
if FontBox.visible then
begin
FontBox.top := y;
FontBoxButton.top := y;
sizeSpin.top := y;
sizeLbl.top := y;
inc(y, FontBox.Height + gap);
FontBoxButton.Height := FontBox.Height;
fontLbl.top := y;
inc(y, 150 + gap);
end;
ImgPBox.visible := p.kind in [TP_pic, TP_ico];
if ImgPBox.visible then
begin
ImgPBox.top := y;
ImgPBox.Height := Self.Height - ImgPBox.top - gap;
inc(y, ImgPBox.Height + gap);
end;
stringBox.visible := p.kind = TP_string;
if stringBox.visible then
begin
stringBox.top := y;
inc(y, stringBox.Height + gap);
end;
fnBox.visible := p.kind = TP_sound;
fnBoxButton.visible := fnBox.visible;
if fnBox.visible then
begin
fnBox.top := y;
fnBoxButton.top := y;
// inc(y, fnbox.height+gap);
fnBoxButton.Height := fnBox.Height;
end;
MPlayerBar.visible := p.kind = TP_sound;
if MPlayerBar.visible then
begin
MPlayerBar.top := y;
// inc(y, fnbox.height+gap);
end;
updateGUI;
end; // setupGUI
procedure TthemeditFr.updateGUI;
begin
fontLbl.Font := FontBox.Font;
// fontLbl.Font.name := fontBox.Text;
// fontLbl.font.size := sizeSpin.AsInteger;
// fontLbl.font.color :=colorBtn.SelectionColor;
// fontLbl.Font.Charset :=
end; // updateGUI
procedure TthemeditFr.propsBoxChange(Sender: TObject);
begin
setupGUI
end;
procedure TthemeditFr.propsBoxKeyPress(Sender: TObject; var Key: Char);
begin
setupGUI;
end;
procedure TthemeditFr.addBtnClick(Sender: TObject);
var
p: ^Tthemeproperty;
s, line: string;
lastsection: string;
color: Tcolor;
bak: Tpoint;
chrst: String;
begin
bak := textBox.caretpos;
// find the last section
s := textBox.Text;
while s > '' do
begin
line := trim(chopline(s));
if (line > '') and (line[1] = '[') and (line[length(line)] = ']') then
lastsection := line;
end;
lastsection := copy(lastsection, 2, length(lastsection) - 2);
s := textBox.Text + CRLF;
p := @themeprops[propsBox.itemIndex];
if lastsection <> p.section then
s := s + '[' + p.section + ']' + CRLF;
color := ColorBtn.SelectionColor;
case p.kind of
TP_color:
s := s + p.name + '=' + color2str(color);
TP_font:
begin
s := s + p.name + '.color=' + color2str(color) + CRLF + p.name + '.size=' + intToStr(trunc(sizeSpin.Value)) + CRLF +
p.name + '.name=' + FontBox.Text;
if CharsetToIdent(FontBox.Font.Charset, chrst) then
s := s + CRLF + p.name + '.charset=' + chrst;
if fontstyle2str(FontBox.Font.Style) > '' then
s := s + CRLF + p.name + '.style=' + fontstyle2str(FontBox.Font.Style);
end;
TP_sound:
s := s + p.name + '=' + fnBox.Text;
TP_string:
s := s + p.name + '=' + newline2slashn(stringBox.Text);
end;
textBox.Text := s;
textBox.caretpos := bak;
textBox.Modified := TRUE;
end;
procedure TthemeditFr.fileBox11Change(Sender: TObject);
begin
Sound_FileName := fnBox.Text;
end;
procedure TthemeditFr.fontBox11Change(Sender: TObject);
begin
updateGUI
end;
procedure TthemeditFr.fnBoxButtonClick(Sender: TObject);
var
fn: String;
begin
fn := openSavedlg(prefFrm, '', TRUE, '', '', fnBox.Text);
if fn > '' then
fnBox.Text := fn;
end;
procedure TthemeditFr.ImgPBoxPaint(Sender: TObject);
var
p: ^Tthemeproperty;
begin
if propsBox.itemIndex < 0 then
exit;
p := @themeprops[propsBox.itemIndex];
if p.kind in [TP_pic, TP_ico, TP_smile] then
theme.drawPic(TPaintBox(Sender).Canvas.Handle, 0, 0, p.name);
end;
procedure TthemeditFr.initPage;
var
i: integer;
begin
propsBox.items.clear();
theme.getprops(themeprops);
for i := 0 to length(themeprops) - 1 do
propsBox.items.add(format('[%s] %s', [themeprops[i].section, themeprops[i].name]));
propsBox.itemIndex := 0;
propsBoxChange(Self);
end;
procedure TthemeditFr.unInitPage;
begin
ImgPBox.visible := false;
SetLength(themeprops, 0);
SetLength(Sound_FileName, 0);
end;
procedure TthemeditFr.applyPage;
begin
// if prefPages[thisPrefIdx].frame = NIL then exit;
if textBox.Modified then
begin
savefile2(AccPath + userthemeFilename, textBox.Text);
reloadCurrentTheme;
end;
end;
procedure TthemeditFr.resetPage;
begin
textBox.Text := loadfileA(AccPath + userthemeFilename);
end;
procedure TthemeditFr.FontBoxButtonClick(Sender: TObject);
var
vF: TFont;
begin
vF := TFont.Create;
vF := FontBox.Font;
if ChooseFontDlg(Self.ParentWindow, 'Choose font', vF) then
// if FontBoxDialog.Execute then
begin
FontBox.Text := vF.name;
FontBox.Font := vF;
sizeSpin.Value := FontBox.Font.size;
ColorBtn.SelectionColor := FontBox.Font.color;
updateGUI
end;
end;
procedure TthemeditFr.FormClose(Sender: TObject; var Action: TCloseAction);
begin
SetLength(themeprops, 0);
end;
procedure TthemeditFr.PlayBtnClick(Sender: TObject);
begin
try
SoundPlay(Sound_FileName);
except
end;
end;
procedure TthemeditFr.ColorBtnChange(Sender: TObject);
begin
FontBox.Font.color := ColorBtn.SelectionColor;
updateGUI
end;
end.