Advertisement
ksyshshot

курсач 5

May 28th, 2023
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 7.14 KB | Source Code | 0 0
  1. unit UnitFlashCards;
  2.  
  3. interface
  4.  
  5. uses
  6.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
  7.   Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls,
  8.   Vcl.Imaging.pngimage, Vcl.Grids, Vcl.ValEdit;
  9.  
  10. type
  11.   TFrameFlashCards = class(TFrame)
  12.     PanelTopBorder: TPanel;
  13.     PanelForFaQ: TPanel;
  14.     ButtonHowWork: TButton;
  15.     PanelLeftBorder: TPanel;
  16.     PanelRightBorder: TPanel;
  17.     PanelBottomBorder: TPanel;
  18.     PanelUnderCard: TPanel;
  19.     ButtonPrevCard: TImage;
  20.     PanelFlashCard: TPanel;
  21.     ButtonNextCard: TImage;
  22.     ButtonChangeWordSet: TButton;
  23.     LabelFlipWord: TLabel;
  24.     LabelStartWord: TLabel;
  25.     PanelEditWordSet: TPanel;
  26.     Panel1: TPanel;
  27.     ButtonAdd: TButton;
  28.     ButtonSaveAndExit: TButton;
  29.     DictionaryChangeWordSet: TValueListEditor;
  30.     ButtonDelete: TButton;
  31.     procedure FrameResize(Sender: TObject);
  32.     procedure PanelFlashCardClick(Sender: TObject);
  33.     procedure LabelFlipWordClick(Sender: TObject);
  34.     procedure LabelStartWordClick(Sender: TObject);
  35.     procedure ButtonChangeWordSetClick(Sender: TObject);
  36.     procedure ButtonSaveAndExitClick(Sender: TObject);
  37.     procedure ButtonDeleteClick(Sender: TObject);
  38.     procedure ButtonAddClick(Sender: TObject);
  39.     procedure ButtonNextCardClick(Sender: TObject);
  40.     procedure ButtonPrevCardClick(Sender: TObject);
  41.     procedure ButtonHowWorkClick(Sender: TObject);
  42.   private
  43.     { Private declarations }
  44.   public
  45.     { Public declarations }
  46.   end;
  47.  
  48. implementation
  49.  
  50. {$R *.dfm}
  51.  
  52. uses MainForm, UnitChangeWord, UnitHelp;
  53.  
  54. const
  55.     BETWEEN_CONTROLS = 6;
  56.     DEFAULT_FONT_SIZE = 9;
  57.     FILE_FLASHCARDS = MainForm.FILE_FLASHCARDS;
  58.  
  59. type
  60.     TPElem = MainForm.TPElem;
  61.  
  62. var
  63.     Curr: TPElem;
  64.  
  65. procedure TFrameFlashCards.ButtonAddClick(Sender: TObject);
  66. var
  67.     EnglishWord: EnglStr;
  68.     RussianWord: RussStr;
  69.     PartOfSpeech: TPartsOfSpeech;
  70.     EnglishPresence, RussianPresence: Boolean;
  71. begin
  72.     //очищение строк ввода от информации, оставшейся после предыдущего
  73.     //добавления слова
  74.     UnitChangeWord.FormChangeWord.EditEnglishWord.Text := '';
  75.     UnitChangeWord.FormChangeWord.EditRussianWord.Text := '';
  76.     UnitChangeWord.FormChangeWord.RadioGroupPartsOfSpeech.ItemIndex := -1;
  77.     if UnitChangeWord.FormChangeWord.ShowModal = mrOk then //если в окне добавления слова
  78.     begin                                                  //было нажато "Добавить"
  79.         ButtonDelete.Enabled := true;
  80.         with UnitChangeWord.FormChangeWord do
  81.         begin
  82.             RussianWord := EditRussianWord.Text;
  83.             PartOfSpeech := MainForm.FormMenu.GetPartOfSpeech(EnglishWord, RadioGroupPartsOfSpeech, true);
  84.             EnglishWord := MainForm.FormMenu.GetFinalAppearance(PartOfSpeech, EditEnglishWord.Text);
  85.             EnglishPresence := MainForm.FormMenu.IsWordInDictionary(DictionaryChangeWordSet, EnglishWord);
  86.             RussianPresence := MainForm.FormMenu.IsWordInDictionary(DictionaryChangeWordSet, RussianWord);
  87.             //если в списке нет такой пары слов, то
  88.             if not(EnglishPresence) and not(RussianPresence) then
  89.             begin
  90.                 DictionaryChangeWordSet.InsertRow(RussianWord, EnglishWord, true);
  91.             end;
  92.         end;
  93.     end;
  94. end;
  95.  
  96. procedure TFrameFlashCards.ButtonChangeWordSetClick(Sender: TObject);
  97. begin
  98.     ButtonChangeWordSet.Enabled := false;
  99.     PanelUnderCard.Visible := false;
  100.     PanelEditWordSet.Visible := true;
  101. end;
  102.  
  103. procedure TFrameFlashCards.ButtonDeleteClick(Sender: TObject);
  104. begin
  105.     if not(MainForm.FormMenu.IsRowEmpty(DictionaryChangeWordSet, DictionaryChangeWordSet.Row)) then
  106.     begin
  107.         MainForm.FormMenu.DeleteWord(DictionaryChangeWordSet);
  108.     end;
  109. end;
  110.  
  111. procedure TFrameFlashCards.ButtonHowWorkClick(Sender: TObject);
  112. begin
  113.     UnitHelp.FormHelp.Show;
  114. end;
  115.  
  116. procedure TFrameFlashCards.ButtonNextCardClick(Sender: TObject);
  117. begin
  118.     Curr := Curr^.Next;
  119.     LabelStartWord.Caption := Curr^.StartPage;
  120.     LabelFlipWord.Caption := Curr^.FlipPage;
  121. end;
  122.  
  123. procedure TFrameFlashCards.ButtonPrevCardClick(Sender: TObject);
  124. begin
  125.     Curr := Curr^.Prev;
  126.     LabelStartWord.Caption := Curr^.StartPage;
  127.     LabelFlipWord.Caption := Curr^.FlipPage;
  128. end;
  129.  
  130. procedure AddNewElement(Start, Flip: EnglStr; var CurrElem: TPElem);
  131. var
  132.     AddElem: TPElem;
  133. begin
  134.     New(AddElem);
  135.     CurrElem^.Next := AddElem;
  136.     AddElem^.Prev := CurrElem;
  137.     AddElem^.StartPage := Start;
  138.     AddElem^.FlipPage := Flip;
  139.     AddElem^.Next := nil;
  140.     CurrElem := AddElem;
  141. end;
  142.  
  143. procedure CreateList(Dict: TValueListEditor);
  144. var
  145.     Temp, Head: TPElem;
  146.     I: Integer;
  147. begin
  148.     New(Temp);
  149.     Temp^.Prev := nil;
  150.     Temp^.Next := nil;
  151.     Temp^.StartPage := Dict.Keys[1];
  152.     Temp^.FlipPage := Dict.Cells[1, 1];
  153.     Head := Temp;
  154.     I := 2;
  155.     while (I < Dict.RowCount) do
  156.     begin
  157.         AddNewElement(Dict.Keys[I], Dict.Cells[1, I], Temp);
  158.         Inc(I);
  159.     end;
  160.     Temp^.Next := Head;
  161.     Head^.Prev := Temp;
  162.     Curr := Head;
  163. end;
  164.  
  165. procedure TFrameFlashCards.ButtonSaveAndExitClick(Sender: TObject);
  166. begin
  167.     MainForm.FormMenu.SaveDictionaryToFile(DictionaryChangeWordSet, FILE_FLASHCARDS);
  168.     ButtonChangeWordSet.Enabled := true;
  169.     PanelUnderCard.Visible := true;
  170.     PanelEditWordSet.Visible := false;
  171.     if (DictionaryChangeWordSet.RowCount > 1) then
  172.     begin
  173.         CreateList(DictionaryChangeWordSet);
  174.         LabelStartWord.Caption := Curr^.StartPage;
  175.         LabelFlipWord.Caption := Curr^.FlipPage;
  176.     end;
  177. end;
  178.  
  179. procedure TFrameFlashCards.FrameResize(Sender: TObject);
  180. var
  181.     SizeChange: Integer;
  182. begin
  183.     PanelFlashCard.Width := (PanelUnderCard.Width * 58) div 100;
  184.     PanelFlashCard.Height := (PanelUnderCard.Height * 5) div 10;
  185.     SizeChange := PanelFlashCard.Width div 30;
  186.     LabelFlipWord.Font.Size := DEFAULT_FONT_SIZE + SizeChange;
  187.     LabelFlipWord.Font.Color := clBlack;
  188.     LabelStartWord.Font.Size := DEFAULT_FONT_SIZE + SizeChange;
  189.     LabelStartWord.Font.Color := clBlack;
  190.     PanelFlashCard.Left := (PanelUnderCard.Width div 2) - (PanelFlashCard.Width div 2);
  191.     PanelFlashCard.Top := (PanelUnderCard.Height div 2) - (PanelFlashCard.Height div 2);
  192.     ButtonPrevCard.Left := PanelFlashCard.Left - BETWEEN_CONTROLS - ButtonPrevCard.Width;
  193.     ButtonPrevCard.Top := (PanelUnderCard.Height div 2) - (ButtonPrevCard.Height div 2);
  194.     ButtonNextCard.Left := PanelFlashCard.Left + BETWEEN_CONTROLS + PanelFlashCard.Width;
  195.     ButtonNextCard.Top := (PanelUnderCard.Height div 2) - (ButtonNextCard.Height div 2);
  196. end;
  197.  
  198. procedure TFrameFlashCards.LabelFlipWordClick(Sender: TObject);
  199. begin
  200.     LabelStartWord.Visible := true;
  201.     LabelFlipWord.VIsible := false;
  202. end;
  203.  
  204. procedure TFrameFlashCards.LabelStartWordClick(Sender: TObject);
  205. begin
  206.     LabelFlipWord.Visible := true;
  207.     LabelStartWord.Visible := false;
  208. end;
  209.  
  210. procedure TFrameFlashCards.PanelFlashCardClick(Sender: TObject);
  211. begin
  212.     LabelStartWord.Visible := LabelFlipWord.Visible;
  213.     LabelFlipWord.Visible := not(LabelStartWord.Visible);
  214. end;
  215.  
  216. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement