1- #include < QFile>
2- #include < QFileDialog>
31#include " Editor.h"
42
5- Editor::Editor (QWidget *parent, const QString &title, const QString& filePath) {
3+ void Editor::actualiserTextEditor (QString path) {
4+ QFile file (path);
5+ QString fileContent;
6+
7+ if (file.open (QIODevice::ReadOnly | QIODevice::Text)) {
8+ QTextStream in (&file);
9+ while (!in.atEnd ()) {
10+ QString line = in.readLine ();
11+ fileContent += line + " \n " ; // Ajouter la ligne au contenu du fichier avec un saut de ligne
12+ }
13+ file.close ();
14+ }
15+
16+ this ->editor_text ->setText (fileContent);
17+ }
18+
19+ Editor::Editor (const QString &title, const QString &filePath) {
620 QString Window_StyleSheet = " "
721 " QMainWindow {"
822 " background: rgb(51,54,56);"
@@ -56,7 +70,9 @@ Editor::Editor(QWidget *parent, const QString &title, const QString& filePath) {
5670 this ->setStyleSheet (Window_StyleSheet);
5771 this ->setWindowIcon (QIcon (" images/icon.png" ));
5872
73+ this ->titleApp = title;
5974 this ->filePath = filePath;
75+ this ->possiblePathInterpreter = " N/A" ;
6076
6177 // Interface :
6278
@@ -76,11 +92,11 @@ Editor::Editor(QWidget *parent, const QString &title, const QString& filePath) {
7692 this ->editor_menu = new QMenuBar (this );
7793 this ->menuEditor_files = new QMenu (tr (" Fichier" ), this );
7894 this ->menuEditor_run = new QMenu (tr (" Executer" ), this );
79- this ->menuEditor_files_new = new QAction (tr (" Nouveau" ), this );;
80- this ->menuEditor_files_open = new QAction (tr (" Ouvrir" ), this );;
95+ this ->menuEditor_files_new = new QAction (tr (" Nouveau" ), this );
96+ this ->menuEditor_files_open = new QAction (tr (" Ouvrir" ), this );
8197 this ->menuEditor_files_save = new QAction (tr (" Sauvegarder" ), this );
8298 this ->menuEditor_files_saveas = new QAction (tr (" Sauvegarder sous" ), this );
83- this ->menuEditor_run_run = new QAction (tr (" Executer..." ), this );;
99+ this ->menuEditor_run_run = new QAction (tr (" Executer..." ), this );
84100 this ->menuEditor_run_settings = new QAction (tr (" Paramètres" ), this );
85101 this ->menuEditor_files ->addAction (this ->menuEditor_files_new );
86102 this ->menuEditor_files ->addAction (this ->menuEditor_files_open );
@@ -91,7 +107,7 @@ Editor::Editor(QWidget *parent, const QString &title, const QString& filePath) {
91107 this ->editor_menu ->addMenu (this ->menuEditor_files );
92108 this ->editor_menu ->addMenu (this ->menuEditor_run );
93109
94- QWidget * centralWidget = new QWidget (this );
110+ auto * centralWidget = new QWidget (this );
95111 centralWidget->setLayout (this ->editor_layout );
96112 this ->setCentralWidget (centralWidget);
97113 this ->setMenuBar (this ->editor_menu );
@@ -117,6 +133,7 @@ Editor::Editor(QWidget *parent, const QString &title, const QString& filePath) {
117133 connect (this ->menuEditor_files_open , &QAction::triggered, this , &Editor::menu_file_open);
118134
119135 connect (this ->menuEditor_run_run , &QAction::triggered, this , &Editor::menu_run_run);
136+ connect (this ->menuEditor_run_settings , &QAction::triggered, this , &Editor::menu_run_settings);
120137}
121138
122139void Editor::menu_file_open ()
@@ -129,28 +146,155 @@ void Editor::menu_file_open()
129146 );
130147
131148 if (!fileName.isEmpty ()) {
132- QFile file (fileName);
133- QString fileContent;
134-
135- if (file.open (QIODevice::ReadOnly | QIODevice::Text)) {
136- QTextStream in (&file);
137- while (!in.atEnd ()) {
138- QString line = in.readLine ();
139- fileContent += line + " \n " ; // Ajouter la ligne au contenu du fichier avec un saut de ligne
140- }
141- file.close ();
142- }
143-
144- this ->editor_text ->setText (fileContent);
149+ actualiserTextEditor (fileName);
145150 }
151+
152+ actualiserTextEditor (fileName);
153+ this ->currentEditFile_Path = fileName;
146154}
147155
148156void Editor::menu_file_new () {
157+ std::ofstream newF {" unknown.fpl" };
158+ if (newF.is_open ()) {
159+ newF << " envoyer \" Bienvenue !\" ;" << std::endl;
160+ newF.close ();
161+ }
149162
163+ actualiserTextEditor (" unknown.fpl" );
164+ this ->currentEditFile_Path = " unknown.fpl" ;
150165}
151166
152167void Editor::menu_run_run () {
153- system (" interpreters\\ V2-FPL.exe" );
168+ auto *process = new QProcess (this );
169+ if (this ->currentEditFile_Path != " N/A" ) {
170+ QString program;
171+ QStringList arguments;
172+ if (this ->possiblePathInterpreter == " N/A" ) {
173+ program = " interpreters/V2-FPL.exe" ;
174+ arguments << this ->currentEditFile_Path ;
175+ } else {
176+ program = this ->possiblePathInterpreter ;
177+ arguments << this ->currentEditFile_Path ;
178+ }
179+
180+ process->setProgram (program);
181+ process->setArguments (arguments);
182+ process->setProcessChannelMode (QProcess::MergedChannels);
183+
184+ connect (process, &QProcess::readyReadStandardOutput, [this , process](){
185+ QByteArray output = process->readAllStandardOutput ();
186+ this ->editor_terminal ->appendPlainText (QString (output));
187+ });
188+
189+ process->start ();
190+
191+ if (!process->waitForStarted ()) {
192+ qDebug () << " Process failed to start" ;
193+ }
194+
195+ if (!process->waitForFinished ()) {
196+ qDebug () << " Process execution failed" ;
197+ }
198+ }
199+ }
200+
201+
202+
203+ void Editor::menu_run_settings () {
204+ QString Window_StyleSheet = " "
205+ " QWidget {"
206+ " background: rgb(51,54,56);"
207+ " }"
208+ ;
209+
210+
211+ QString Title_StyleSheet = " "
212+ " QLabel {"
213+ " border: none;"
214+ " color: white;"
215+ " font-size: 15px;"
216+ " text-align: center;"
217+ " padding: 10px 0;"
218+ " }"
219+ ;
220+
221+ QString Title_Sec_StyleSheet = " "
222+ " QLabel {"
223+ " border: none;"
224+ " color: rgb(190,190,190);"
225+ " font-size: 15px;"
226+ " text-align: center;"
227+ " padding: 10px 0;"
228+ " }"
229+ ;
230+
231+ QString Button_StyleSheet = " "
232+ " QPushButton {"
233+ " width: 150px;"
234+ " font-weight: italic;"
235+ " height: auto;"
236+ " border: none;"
237+ " background: rgb(50, 92, 134);"
238+ " color: rgb(200,200,200);"
239+ " font-size: 13px;"
240+ " text-align: center;"
241+ " border-radius: 5px;"
242+ " }"
243+ " QPushButton:hover {"
244+ " color: white;"
245+ " border-radius: 10px;"
246+ " background: rgb(50, 111, 193);"
247+ " }"
248+ ;
249+
250+ QString Path_StyleSheet = " "
251+ " QLineEdit {"
252+ " background: rgb(30,30,30);"
253+ " color: rgb(230,230,230);"
254+ " font-size: 12px;"
255+ " border: 1.5px solid rgb(200,200,200);"
256+ " }"
257+ ;
258+
259+ this ->settings_W = new QWidget (nullptr );
260+ this ->layout_settings = new VerticalLayout (nullptr , Qt::AlignCenter);
261+ this ->title_settings = new TextLabel (nullptr , " Paramètres de l'IDE" , Qt::AlignCenter);
262+ this ->settings_W ->resize (500 ,150 );
263+ this ->settings_W ->setMaximumSize (settings_W->size ());
264+ this ->settings_W ->setMinimumSize (settings_W->size ());
265+ this ->settings_W ->setWindowTitle (this ->titleApp + QString (" (Paramètres)" ));
266+ this ->settings_W ->setStyleSheet (Window_StyleSheet);
267+
268+ this ->title_settings ->setStyleSheet (Title_StyleSheet);
269+
270+ this ->title_pathInter = new TextLabel (nullptr , " Interpréteur : " , Qt::AlignTop);
271+ this ->title_pathInter ->setStyleSheet (Title_Sec_StyleSheet);
272+ this ->pathLineEdit = new QLineEdit ();
273+ this ->pathLineEdit ->setStyleSheet (Path_StyleSheet);
274+ this ->selectFileButton = new TextButton (nullptr , " Sélectionner un fichier" );
275+ this ->selectFileButton ->setStyleSheet (Button_StyleSheet);
276+ this ->layout_selectfile = new HorizontalLayout (nullptr , Qt::AlignLeft);
277+ this ->layout_selectfile ->addWidget (title_pathInter);
278+ this ->layout_selectfile ->addItem (new QSpacerItem (5 , 0 , QSizePolicy::Minimum, QSizePolicy::Minimum));
279+ this ->layout_selectfile ->addWidget (pathLineEdit);
280+ this ->layout_selectfile ->addItem (new QSpacerItem (20 , 0 , QSizePolicy::Minimum, QSizePolicy::Minimum));
281+ this ->layout_selectfile ->addWidget (selectFileButton);
282+
283+ this ->layout_settings ->addWidget (title_settings);
284+ this ->layout_settings ->addItem (layout_selectfile);
285+
286+ this ->settings_W ->setLayout (layout_settings);
287+ this ->settings_W ->show ();
288+
289+
290+
291+ connect (selectFileButton, &QPushButton::clicked, [=, this ]() {
292+ QString fileP = QFileDialog::getOpenFileName (this , " Sélectionner un fichier" , " " , " Fichiers exécutables (*.exe)" );
293+ if (!fileP.isEmpty ()) {
294+ this ->pathLineEdit ->setText (fileP);
295+ this ->possiblePathInterpreter = fileP;
296+ }
297+ });
154298}
155299
156300
0 commit comments