Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit UnitFlashCards;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
- Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls,
- Vcl.Imaging.pngimage, Vcl.Grids, Vcl.ValEdit;
- type
- TFrameFlashCards = class(TFrame)
- PanelTopBorder: TPanel;
- PanelForFaQ: TPanel;
- ButtonHowWork: TButton;
- PanelLeftBorder: TPanel;
- PanelRightBorder: TPanel;
- PanelBottomBorder: TPanel;
- PanelUnderCard: TPanel;
- ButtonPrevCard: TImage;
- PanelFlashCard: TPanel;
- ButtonNextCard: TImage;
- ButtonChangeWordSet: TButton;
- LabelFlipWord: TLabel;
- LabelStartWord: TLabel;
- PanelEditWordSet: TPanel;
- Panel1: TPanel;
- ButtonAdd: TButton;
- ButtonSaveAndExit: TButton;
- DictionaryChangeWordSet: TValueListEditor;
- ButtonDelete: TButton;
- procedure FrameResize(Sender: TObject);
- procedure PanelFlashCardClick(Sender: TObject);
- procedure LabelFlipWordClick(Sender: TObject);
- procedure LabelStartWordClick(Sender: TObject);
- procedure ButtonChangeWordSetClick(Sender: TObject);
- procedure ButtonSaveAndExitClick(Sender: TObject);
- procedure ButtonDeleteClick(Sender: TObject);
- procedure ButtonAddClick(Sender: TObject);
- procedure ButtonNextCardClick(Sender: TObject);
- procedure ButtonPrevCardClick(Sender: TObject);
- procedure ButtonHowWorkClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- implementation
- {$R *.dfm}
- uses MainForm, UnitChangeWord, UnitHelp;
- const
- BETWEEN_CONTROLS = 6;
- DEFAULT_FONT_SIZE = 9;
- FILE_FLASHCARDS = MainForm.FILE_FLASHCARDS;
- type
- TPElem = MainForm.TPElem;
- var
- Curr: TPElem;
- procedure TFrameFlashCards.ButtonAddClick(Sender: TObject);
- var
- EnglishWord: EnglStr;
- RussianWord: RussStr;
- PartOfSpeech: TPartsOfSpeech;
- EnglishPresence, RussianPresence: Boolean;
- begin
- //очищение строк ввода от информации, оставшейся после предыдущего
- //добавления слова
- UnitChangeWord.FormChangeWord.EditEnglishWord.Text := '';
- UnitChangeWord.FormChangeWord.EditRussianWord.Text := '';
- UnitChangeWord.FormChangeWord.RadioGroupPartsOfSpeech.ItemIndex := -1;
- if UnitChangeWord.FormChangeWord.ShowModal = mrOk then //если в окне добавления слова
- begin //было нажато "Добавить"
- ButtonDelete.Enabled := true;
- with UnitChangeWord.FormChangeWord do
- begin
- RussianWord := EditRussianWord.Text;
- PartOfSpeech := MainForm.FormMenu.GetPartOfSpeech(EnglishWord, RadioGroupPartsOfSpeech, true);
- EnglishWord := MainForm.FormMenu.GetFinalAppearance(PartOfSpeech, EditEnglishWord.Text);
- EnglishPresence := MainForm.FormMenu.IsWordInDictionary(DictionaryChangeWordSet, EnglishWord);
- RussianPresence := MainForm.FormMenu.IsWordInDictionary(DictionaryChangeWordSet, RussianWord);
- //если в списке нет такой пары слов, то
- if not(EnglishPresence) and not(RussianPresence) then
- begin
- DictionaryChangeWordSet.InsertRow(RussianWord, EnglishWord, true);
- end;
- end;
- end;
- end;
- procedure TFrameFlashCards.ButtonChangeWordSetClick(Sender: TObject);
- begin
- ButtonChangeWordSet.Enabled := false;
- PanelUnderCard.Visible := false;
- PanelEditWordSet.Visible := true;
- end;
- procedure TFrameFlashCards.ButtonDeleteClick(Sender: TObject);
- begin
- if not(MainForm.FormMenu.IsRowEmpty(DictionaryChangeWordSet, DictionaryChangeWordSet.Row)) then
- begin
- MainForm.FormMenu.DeleteWord(DictionaryChangeWordSet);
- end;
- end;
- procedure TFrameFlashCards.ButtonHowWorkClick(Sender: TObject);
- begin
- UnitHelp.FormHelp.Show;
- end;
- procedure TFrameFlashCards.ButtonNextCardClick(Sender: TObject);
- begin
- Curr := Curr^.Next;
- LabelStartWord.Caption := Curr^.StartPage;
- LabelFlipWord.Caption := Curr^.FlipPage;
- end;
- procedure TFrameFlashCards.ButtonPrevCardClick(Sender: TObject);
- begin
- Curr := Curr^.Prev;
- LabelStartWord.Caption := Curr^.StartPage;
- LabelFlipWord.Caption := Curr^.FlipPage;
- end;
- procedure AddNewElement(Start, Flip: EnglStr; var CurrElem: TPElem);
- var
- AddElem: TPElem;
- begin
- New(AddElem);
- CurrElem^.Next := AddElem;
- AddElem^.Prev := CurrElem;
- AddElem^.StartPage := Start;
- AddElem^.FlipPage := Flip;
- AddElem^.Next := nil;
- CurrElem := AddElem;
- end;
- procedure CreateList(Dict: TValueListEditor);
- var
- Temp, Head: TPElem;
- I: Integer;
- begin
- New(Temp);
- Temp^.Prev := nil;
- Temp^.Next := nil;
- Temp^.StartPage := Dict.Keys[1];
- Temp^.FlipPage := Dict.Cells[1, 1];
- Head := Temp;
- I := 2;
- while (I < Dict.RowCount) do
- begin
- AddNewElement(Dict.Keys[I], Dict.Cells[1, I], Temp);
- Inc(I);
- end;
- Temp^.Next := Head;
- Head^.Prev := Temp;
- Curr := Head;
- end;
- procedure TFrameFlashCards.ButtonSaveAndExitClick(Sender: TObject);
- begin
- MainForm.FormMenu.SaveDictionaryToFile(DictionaryChangeWordSet, FILE_FLASHCARDS);
- ButtonChangeWordSet.Enabled := true;
- PanelUnderCard.Visible := true;
- PanelEditWordSet.Visible := false;
- if (DictionaryChangeWordSet.RowCount > 1) then
- begin
- CreateList(DictionaryChangeWordSet);
- LabelStartWord.Caption := Curr^.StartPage;
- LabelFlipWord.Caption := Curr^.FlipPage;
- end;
- end;
- procedure TFrameFlashCards.FrameResize(Sender: TObject);
- var
- SizeChange: Integer;
- begin
- PanelFlashCard.Width := (PanelUnderCard.Width * 58) div 100;
- PanelFlashCard.Height := (PanelUnderCard.Height * 5) div 10;
- SizeChange := PanelFlashCard.Width div 30;
- LabelFlipWord.Font.Size := DEFAULT_FONT_SIZE + SizeChange;
- LabelFlipWord.Font.Color := clBlack;
- LabelStartWord.Font.Size := DEFAULT_FONT_SIZE + SizeChange;
- LabelStartWord.Font.Color := clBlack;
- PanelFlashCard.Left := (PanelUnderCard.Width div 2) - (PanelFlashCard.Width div 2);
- PanelFlashCard.Top := (PanelUnderCard.Height div 2) - (PanelFlashCard.Height div 2);
- ButtonPrevCard.Left := PanelFlashCard.Left - BETWEEN_CONTROLS - ButtonPrevCard.Width;
- ButtonPrevCard.Top := (PanelUnderCard.Height div 2) - (ButtonPrevCard.Height div 2);
- ButtonNextCard.Left := PanelFlashCard.Left + BETWEEN_CONTROLS + PanelFlashCard.Width;
- ButtonNextCard.Top := (PanelUnderCard.Height div 2) - (ButtonNextCard.Height div 2);
- end;
- procedure TFrameFlashCards.LabelFlipWordClick(Sender: TObject);
- begin
- LabelStartWord.Visible := true;
- LabelFlipWord.VIsible := false;
- end;
- procedure TFrameFlashCards.LabelStartWordClick(Sender: TObject);
- begin
- LabelFlipWord.Visible := true;
- LabelStartWord.Visible := false;
- end;
- procedure TFrameFlashCards.PanelFlashCardClick(Sender: TObject);
- begin
- LabelStartWord.Visible := LabelFlipWord.Visible;
- LabelFlipWord.Visible := not(LabelStartWord.Visible);
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement