1 /***************************************************************************
2 * Copyright (C) 2021 by Abderrahman Taha *
3 * *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
20 #include "parametersoptions.h"
21 #include "../fparser/fparser.hh"
22 #include <QtGui>
23 #include <math.h>
24 #include <sstream>
25 #include <string>
26
27 static bool MACOS = false;
28
Parametersoptions(QWidget * parent)29 Parametersoptions::Parametersoptions(QWidget *parent) : QWidget(parent)
30 {
31 darkpalette.setColor(QPalette::Window, QColor(53, 53, 53));
32 darkpalette.setColor(QPalette::WindowText, QColor(255, 255, 255));
33 darkpalette.setColor(QPalette::Base, QColor(15, 15, 15));
34 darkpalette.setColor(QPalette::AlternateBase, QColor(53, 53, 53));
35 darkpalette.setColor(QPalette::ToolTipBase, QColor(255, 255, 255));
36 darkpalette.setColor(QPalette::ToolTipText, QColor(255, 255, 255));
37 darkpalette.setColor(QPalette::Text, QColor(255, 255, 255));
38 darkpalette.setColor(QPalette::Button, QColor(53, 53, 53));
39 darkpalette.setColor(QPalette::ButtonText, QColor(255, 255, 255));
40 darkpalette.setColor(QPalette::BrightText, QColor(255, 0, 0));
41 darkpalette.setColor(QPalette::Highlight, QColor(142, 45, 197).lighter());
42 darkpalette.setColor(QPalette::HighlightedText, QColor(0, 0, 0));
43 this->setWindowFlags(Qt::WindowStaysOnTopHint);
44 ui.setupUi(this);
45 }
46
slot_about_clicked()47 void Parametersoptions::slot_about_clicked()
48 {
49 this->close();
50 }
51
SetStyleAndTheme(QApplication & appli,QString style,QString theme)52 void Parametersoptions::SetStyleAndTheme(QApplication &appli, QString style,
53 QString theme)
54 {
55 if (style != "Default")
56 appli.setStyle(QStyleFactory::create(style));
57 if (theme == "Dark")
58 {
59 appli.setPalette(darkpalette);
60 }
61 else if (theme == "MyTheme")
62 {
63 appli.setPalette(mypalette);
64 }
65 }
66
ReadConfigFile(QString JsonFile,QJsonObject & js)67 void Parametersoptions::ReadConfigFile(QString JsonFile, QJsonObject &js)
68 {
69 QJsonParseError err;
70 QString sortie;
71
72 QFile file1(JsonFile);
73 if (!file1.exists())
74 {
75 JsonFile = QFileDialog::getOpenFileName(
76 nullptr, QObject::tr("Open mathmodconfig.js File"), "",
77 QObject::tr("Json (*.js)"));
78 }
79 if (JsonFile == "")
80 JsonFile = ":/mathmodconfig.js";
81 QFile file(JsonFile);
82 // QFileDevice::Permissions p = file.permissions();
83 if (file.open(QIODevice::ReadOnly | QIODevice::Text))
84 {
85 QJsonDocument doc = QJsonDocument::fromJson(
86 ((file.readAll()).trimmed())
87 .replace("\n", "")
88 .replace("\t", "")
89 .replace("DOTSYMBOL", dotsymbol.toStdString().c_str()),
90 &err);
91 if (err.error)
92 {
93 QMessageBox message;
94 message.setWindowTitle("Error at : " + JsonFile);
95 file.close();
96 file.open(QIODevice::ReadOnly | QIODevice::Text);
97 sortie = (file.readAll());
98 int before, after;
99 if (sortie.length() > (err.offset + 30))
100 after = 30;
101 else
102 after = sortie.length() - err.offset;
103 sortie.truncate(err.offset + after);
104 if (err.offset - 30 > 0)
105 before = 30;
106 else
107 before = 0;
108 sortie = sortie.remove(0, err.offset - before);
109 sortie.replace("\t", " ");
110 sortie.replace("\n", " ");
111 sortie.insert(before, " >>> Error <<< ");
112 message.setText("Error : " + err.errorString() +
113 " at position: " + QString::number(err.offset) +
114 "\n\n***********\n" + "..." + sortie + "...");
115 message.adjustSize();
116 message.exec();
117 file.close();
118 return;
119 }
120 js = doc.object();
121 file.close();
122 }
123 return;
124 }
125
ReadJsonFile(QString JsonFile,QJsonObject & js)126 void Parametersoptions::ReadJsonFile(QString JsonFile, QJsonObject &js)
127 {
128 QJsonParseError err;
129 QString sortie;
130 QFile file1(JsonFile);
131 if (!file1.exists())
132 {
133 JsonFile = QFileDialog::getOpenFileName(
134 nullptr, QObject::tr("Open mathmodconfig.js File"), "",
135 QObject::tr("Json (*.js)"));
136 }
137 QFile file(JsonFile);
138 // QFileDevice::Permissions p = file.permissions();
139 if (file.open(QIODevice::ReadOnly | QIODevice::Text))
140 {
141 QJsonDocument doc = QJsonDocument::fromJson(
142 ((file.readAll()).trimmed())
143 .replace("\n", "")
144 .replace("\t", "")
145 .replace("DOTSYMBOL", dotsymbol.toStdString().c_str()),
146 &err);
147 if (err.error)
148 {
149 QMessageBox message;
150 message.setWindowTitle("Error at : " + JsonFile);
151 file.close();
152 file.open(QIODevice::ReadOnly | QIODevice::Text);
153 sortie = (file.readAll());
154 int before, after;
155 if (sortie.length() > (err.offset + 30))
156 after = 30;
157 else
158 after = sortie.length() - err.offset;
159 sortie.truncate(err.offset + after);
160 if (err.offset - 30 > 0)
161 before = 30;
162 else
163 before = 0;
164 sortie = sortie.remove(0, err.offset - before);
165 sortie.replace("\t", " ");
166 sortie.replace("\n", " ");
167 sortie.insert(before, " >>> Error <<< ");
168 message.setText("Error : " + err.errorString() +
169 " at position: " + QString::number(err.offset) +
170 "\n\n***********\n" + "..." + sortie + "...");
171 message.adjustSize();
172 message.exec();
173 file.close();
174 return;
175 }
176 js = doc.object();
177 file.close();
178 }
179 return;
180 }
181
ReadCollectionFile(QString JsonFileName,QJsonObject & js)182 void Parametersoptions::ReadCollectionFile(QString JsonFileName,
183 QJsonObject &js)
184 {
185 QJsonParseError err;
186 QString sortie;
187 QFile JsonFile(JsonFileName);
188 if (!JsonFile.exists())
189 {
190 QFile file2(":/mathmodcollection_empty.js");
191 file2.copy(JsonFileName);
192 QFile::setPermissions(JsonFileName,
193 QFileDevice::ReadOwner | QFileDevice::WriteOwner);
194 }
195 QFile file(JsonFileName);
196 if (file.open(QIODevice::ReadOnly | QIODevice::Text))
197 {
198 QJsonDocument doc = QJsonDocument::fromJson(
199 ((file.readAll()).trimmed())
200 .replace("\n", "")
201 .replace("\t", "")
202 .replace("DOTSYMBOL", dotsymbol.toStdString().c_str()),
203 &err);
204 if (err.error)
205 {
206 QMessageBox message;
207 message.setWindowTitle("Error at : " + JsonFileName);
208 file.close();
209 file.open(QIODevice::ReadOnly | QIODevice::Text);
210 sortie = (file.readAll());
211 int before, after;
212 if (sortie.length() > (err.offset + 30))
213 after = 30;
214 else
215 after = sortie.length() - err.offset;
216 sortie.truncate(err.offset + after);
217 if (err.offset - 30 > 0)
218 before = 30;
219 else
220 before = 0;
221 sortie = sortie.remove(0, err.offset - before);
222 sortie.replace("\t", " ");
223 sortie.replace("\n", " ");
224 sortie.insert(before, " >>> Error <<< ");
225 message.setText("Error : " + err.errorString() +
226 " at position: " + QString::number(err.offset) +
227 "\n\n***********\n" + "..." + sortie + "...");
228 message.adjustSize();
229 message.exec();
230 file.close();
231 return;
232 }
233 js = doc.object();
234 file.close();
235 }
236 return;
237 }
238
GuiUpdate()239 void Parametersoptions::GuiUpdate()
240 {
241 QJsonObject isoparam = (JConfig)["Parameters"].toObject();
242 // Iso Grid
243 int mg = (isoparam)["IsoMaxGrid"].toInt();
244 ui.IsoMaxGridLineEdit->setText(QString::number(mg));
245 // Par Grid
246 mg = (isoparam)["ParMaxGrid"].toInt();
247 ui.ParMaxGridLineEdit->setText(QString::number(mg));
248 // Styles:
249 QString Style = ((JConfig["Styles"].toObject())["UsedStyle"].toString());
250 ui.comboBox_2->setCurrentText(Style);
251 // Theme:
252 QString theme = ((JConfig["Themes"].toObject())["UsedTheme"].toString());
253 ui.comboBox_3->setCurrentText(theme);
254 if (theme == "MyTheme")
255 ui.groupBox->show();
256 else
257 ui.groupBox->hide();
258 }
259
maxisogri_valueChanged(int value)260 void Parametersoptions::maxisogri_valueChanged(int value)
261 {
262 IsoMaxGrid = value;
263 QJsonObject tmp = JConfig["Parameters"].toObject();
264 tmp["IsoMaxGrid"] = value;
265 JConfig["Parameters"] = tmp;
266 }
267
maxpargri_valueChanged(int value)268 void Parametersoptions::maxpargri_valueChanged(int value)
269 {
270 ParMaxGrid = value;
271 QJsonObject tmp = JConfig["Parameters"].toObject();
272 tmp["ParMaxGrid"] = value;
273 JConfig["Parameters"] = tmp;
274 }
275
on_loadconfig_clicked()276 void Parametersoptions::on_loadconfig_clicked()
277 {
278 ReadConfigFile(fullpath, JConfig);
279 GuiUpdate();
280 }
281
282 ListeModelTexture
LoadCollectionModels(QJsonObject & Jcollection,jcollection & pariso,int argc)283 Parametersoptions::LoadCollectionModels(QJsonObject &Jcollection,
284 jcollection &pariso, int argc)
285 {
286
287 QFile fconllect(filecollection);
288 if (fconllect.exists() && ((argc > 1) || MACOS))
289 ReadJsonFile(filecollection, Collection);
290 else
291 ReadJsonFile(":/mathmodcollection.js", Collection);
292
293 Jcollection = Collection;
294 QJsonArray array = Collection["MathModels"].toArray();
295 QStringList lst;
296 QJsonArray array2 = pariso.JTextures = Collection["TexturesList"].toArray();
297
298 QJsonArray array3 = pariso.JPigments = Collection["PigmentsList"].toArray();
299
300 QStringList lst_2, lst_3;
301 QString a;
302 QJsonObject jsobj;
303 QJsonArray jsarray;
304 // Textures List:
305 for (int i = 0; i < array2.size(); i++)
306 {
307 if ((array2[i].toObject())["Texture"].isObject())
308 {
309 jsobj = (array2[i].toObject())["Texture"].toObject();
310 a = (jsobj)["Name"].toString();
311 lst_2.append(a);
312 }
313 }
314 lst_2.insert(0, "Textures List (" + QString::number(lst_2.count()) + ")");
315
316 // Pigments List:
317 for (int i = 0; i < array3.size(); i++)
318 {
319 if ((array3[i].toObject())["Pigment"].isObject())
320 {
321 jsobj = (array3[i].toObject())["Pigment"].toObject();
322 a = (jsobj)["Name"].toString();
323 lst_3.append(a);
324 }
325 }
326 lst_3.insert(0, "PigmentsList (" + QString::number(lst_3.count()) + ")");
327
328 for (int i = 0; i < array.size(); i++)
329 {
330 if ((array[i].toObject())["Iso3D"].isObject())
331 {
332 jiso newjiso;
333 jsobj = (array[i].toObject())["Iso3D"].toObject();
334 newjiso.read(jsobj);
335 pariso.JIso.append(newjiso);
336 a = (jsobj)["Name"].toArray()[0].toString();
337 lst.append(a);
338 }
339 else if ((array[i].toObject())["Param3D"].isObject())
340 {
341 jpar newjpar;
342 jsobj = ((array[i].toObject())["Param3D"].toObject());
343 newjpar.read(jsobj);
344 pariso.JPar.append(newjpar);
345 a = (jsobj)["Name"].toArray()[0].toString();
346 lst.append(a);
347 }
348 else if ((array[i].toObject())["Param4D"].isObject())
349 {
350 jpar newjpar;
351 jsobj = ((array[i].toObject())["Param4D"].toObject());
352 newjpar.read(jsobj);
353 pariso.JPar.append(newjpar);
354 a = (jsobj)["Name"].toArray()[0].toString();
355 lst.append(a);
356 }
357 else if ((array[i].toObject())["Param3D_C"].isObject())
358 {
359 jpar newjpar;
360 jsobj = ((array[i].toObject())["Param3D_C"].toObject());
361 newjpar.read(jsobj);
362 pariso.JPar.append(newjpar);
363 a = (jsobj)["Name"].toArray()[0].toString();
364 lst.append(a);
365 }
366 else if ((array[i].toObject())["Param4D_C"].isObject())
367 {
368 jpar newjpar;
369 jsobj = ((array[i].toObject())["Param4D_C"].toObject());
370 newjpar.read(jsobj);
371 pariso.JPar.append(newjpar);
372 a = (jsobj)["Name"].toArray()[0].toString();
373 lst.append(a);
374 }
375 else if ((array[i].toObject())["ParIso"].isArray())
376 {
377 jpariso newjpariso;
378 jpar newjpar;
379 jiso newjiso;
380 jsarray = ((array[i].toObject())["ParIso"].toArray());
381 for(int i=0; i<jsarray.size(); i++)
382 {
383 if ((jsarray[i].toObject())["Param3D"].isObject())
384 {
385 jsobj = (jsarray[i].toObject())["Param3D"].toObject();
386 newjpar.read(jsobj);
387 newjpariso.JPar = newjpar;
388 }
389 else if ((jsarray[i].toObject())["Param3D_C"].isObject())
390 {
391 jsobj = (jsarray[i].toObject())["Param3D_C"].toObject();
392 newjpar.read(jsobj);
393 newjpariso.JPar = newjpar;
394 }
395 else if ((jsarray[i].toObject())["Param4D_C"].isObject())
396 {
397 jsobj = (jsarray[i].toObject())["Param4D_C"].toObject();
398 newjpar.read(jsobj);
399 newjpariso.JPar = newjpar;
400 }
401 else if ((jsarray[i].toObject())["Iso3D"].isObject())
402 {
403 jsobj = (jsarray[i].toObject())["Iso3D"].toObject();
404 newjiso.read(jsobj);
405 newjpariso.JIso = newjiso;
406 }
407 }
408 a = newjpariso.Name = (array[i].toObject())["Name"].toString();
409 pariso.JParIso.append(newjpariso);
410 lst.append(a);
411 }
412 }
413
414 lst.sort();
415 lst.insert(0, "Examples (" + QString::number(lst.count()) + ")");
416
417 ListeModelTexture str;
418 str.listeModels = lst;
419 str.listeTextures = lst_2;
420 str.listePigments = lst_3;
421 return str;
422 }
423
SaveToFile_CurentMathModel(QJsonObject CurrentJsonObject)424 void Parametersoptions::SaveToFile_CurentMathModel(
425 QJsonObject CurrentJsonObject)
426 {
427 QString fileName = QFileDialog::getSaveFileName(this, tr("Save to file"), "",
428 tr("JSON Files (*.js)"));
429 if (fileName != "")
430 {
431 QJsonObject collection;
432 ReadCollectionFile(fileName, collection);
433 QJsonDocument document;
434 if (collection["MathModels"].isArray())
435 {
436 QJsonArray array = collection["MathModels"].toArray();
437 array.append(CurrentJsonObject);
438 collection["MathModels"] = array;
439 document.setObject(collection);
440 QFile f(fileName);
441 if (f.open(QIODevice::ReadWrite | QIODevice::Text))
442 {
443 QTextStream t(&f);
444 QString tmp = QString(document.toJson()).toLatin1();
445 t << tmp.toUtf8();
446 f.close();
447 }
448 }
449 }
450 }
451
isFloat(std::string myString)452 bool Parametersoptions::isFloat(std::string myString)
453 {
454 std::istringstream iss(myString);
455 float f;
456 iss >> std::noskipws >> f;
457 return iss.eof() && !iss.fail();
458 }
459
LoadConfig(QApplication & app,int argc,char * argv[])460 void Parametersoptions::LoadConfig(QApplication &app, int argc, char *argv[])
461 {
462 QString argv1="";
463 if (argc > 1)
464 {
465 argv1 = QString(argv[1]);
466 if (!argv1.endsWith("/"))
467 argv1 += "/";
468 filecollection = argv1 + filecollection;
469 fileconfig = argv1 + fileconfig;
470 advancedmodels = argv1 + advancedmodels;
471 }
472 /*
473 #ifdef Q_OS_MACOS
474 else
475 {
476 MACOS = true;
477 fileconfig2 = fileconfig2.remove(fileconfig2.size()-5, 5);
478 filecollection = fileconfig2 + "Resources/" + filecollection;
479 fileconfig = fileconfig2 + "Resources/" + fileconfig;
480 advancedmodels = fileconfig2 + "Resources/" + advancedmodels;
481 }
482 #endif
483 */
484 QFile mathmodfileconfig(fileconfig);
485 if (!mathmodfileconfig.exists() && ((argc > 1) || MACOS))
486 {
487 QFile file3(":/mathmodconfig.js");
488 file3.copy(fileconfig);
489 QFile::setPermissions(fileconfig,
490 QFileDevice::ReadOwner | QFileDevice::WriteOwner);
491 }
492
493 QFile fconf(fileconfig);
494 if (fconf.exists())
495 ReadJsonFile(fileconfig, JConfig);
496 else
497 ReadJsonFile(":/mathmodconfig.js", JConfig);
498
499 {
500 if (JConfig["Localization"].isObject())
501 {
502 QJsonObject tmp;
503 tmp = JConfig["Localization"].toObject();
504 if (tmp["AutomaticDetection"].isBool() &&
505 tmp["AutomaticDetection"].toBool())
506 {
507 FunctionParser ff;
508 if ((ff.Parse("1.02", "t")) >= 0)
509 dotsymbol = ",";
510 else
511 dotsymbol = ".";
512 }
513 else
514 dotsymbol = tmp["DotSymbol"].toString();
515 }
516
517 if (JConfig["StartOptions"].isObject())
518 {
519 QJsonObject tmp;
520 tmp = JConfig["StartOptions"].toObject();
521 model = tmp["Model"].toString();
522 }
523
524 if (JConfig["Parameters"].isObject())
525 {
526 IsoParam = JConfig["Parameters"].toObject();
527 if ((IsoParam)["IsoMaxGrid"].isDouble())
528 IsoMaxGrid = ((IsoParam)["IsoMaxGrid"]).toInt();
529
530 if ((IsoParam)["ParMaxGrid"].isDouble())
531 ParMaxGrid = ((IsoParam)["ParMaxGrid"]).toInt();
532
533 if ((IsoParam)["InitParGrid"].isDouble())
534 InitParGrid = (IsoParam)["InitParGrid"].toInt();
535
536 if ((IsoParam)["InitIsoGrid"].isDouble())
537 InitIsoGrid = (IsoParam)["InitIsoGrid"].toInt();
538 }
539
540 QJsonObject tmp;
541 if (JConfig["WindowPosition"].isObject())
542 {
543 tmp = JConfig["WindowPosition"].toObject();
544 ControlX = tmp["ControlX"].toInt();
545 ControlY = tmp["ControlY"].toInt();
546 GlwinX = tmp["GlwinX"].toInt();
547 GlwinY = tmp["GlwinY"].toInt();
548 }
549
550 if (JConfig["WindowSize"].isObject())
551 {
552 tmp = JConfig["WindowSize"].toObject();
553 ControlW = tmp["ControlW"].toInt();
554 ControlH = tmp["ControlH"].toInt();
555 GlwinW = tmp["GlwinW"].toInt();
556 GlwinH = tmp["GlwinH"].toInt();
557 }
558
559 if (JConfig["OpenGlConfig"].isObject())
560 {
561 QJsonObject tmp1, tmp2;
562 tmp1 = JConfig["OpenGlConfig"].toObject();
563
564 Shininess = tmp1["GL_SHININESS"].toInt();
565
566 if (tmp1["GL_FrontFacingSupport"].isBool())
567 glFrontFacingSupport = tmp1["GL_FrontFacingSupport"].toBool();
568
569 tmp2 = JConfig["OpenGlConfig"].toObject();
570 if (tmp2["GL_SPECULAR"].isArray())
571 {
572 Specular[0] =
573 (tmp2["GL_SPECULAR"].toArray())[0].toInt();
574 Specular[1]=(tmp2["GL_SPECULAR"].toArray())[1].toInt();
575 Specular[2]=(tmp2["GL_SPECULAR"].toArray())[2].toInt();
576 Specular[3]=(tmp2["GL_SPECULAR"].toArray())[3].toInt();
577 }
578
579 if (tmp2["GL_AMBIENT"].isArray())
580 {
581 Ambient[0]=(tmp2["GL_AMBIENT"].toArray())[0].toInt();
582 Ambient[1]=(tmp2["GL_AMBIENT"].toArray())[1].toInt();
583 Ambient[2]=(tmp2["GL_AMBIENT"].toArray())[2].toInt();
584 Ambient[3]=(tmp2["GL_AMBIENT"].toArray())[3].toInt();
585 }
586
587 if (tmp2["GL_DIFFUSE"].isArray())
588 {
589 Diffuse[0]=(tmp2["GL_DIFFUSE"].toArray())[0].toInt();
590 Diffuse[1]=(tmp2["GL_DIFFUSE"].toArray())[1].toInt();
591 Diffuse[2]=(tmp2["GL_DIFFUSE"].toArray())[2].toInt();
592 Diffuse[3]=(tmp2["GL_DIFFUSE"].toArray())[3].toInt();
593 }
594 }
595
596 if (JConfig["CalculFactorConfig"].isObject())
597 {
598 QJsonObject tmp = JConfig["CalculFactorConfig"].toObject();
599 CalculFactor[0] = tmp["FactX"].toInt();
600 CalculFactor[1] = tmp["FactY"].toInt();
601 CalculFactor[2] = tmp["FactZ"].toInt();
602 }
603
604 if (JConfig["ThreadsConfig"].isObject())
605 {
606 QJsonObject tmp = JConfig["ThreadsConfig"].toObject();
607 if (tmp["AutoDetect"].isBool() && tmp["AutoDetect"].toBool())
608 Threads[0] = QThread::idealThreadCount();
609 else
610 Threads[0] = tmp["ThreadsNumber"].toInt();
611 Threads[1] = tmp["MinThreadsNumber"].toInt();
612 Threads[2] = tmp["MaxThreadsNumber"].toInt();
613 }
614
615 if (JConfig["Themes"].isObject() && JConfig["Styles"].isObject())
616 {
617 QJsonObject tmp1, tmp2, MyTheme;
618 tmp2 = JConfig["Styles"].toObject();
619 QString style = tmp2["UsedStyle"].toString();
620 tmp1 = JConfig["Themes"].toObject();
621 QString theme = tmp1["UsedTheme"].toString();
622 if (theme == "MyTheme")
623 {
624 MyTheme = tmp1["MyTheme"].toObject();
625 mypalette.setColor(QPalette::Window,
626 QColor((MyTheme["Window"].toArray())[0].toInt(),
627 (MyTheme["Window"].toArray())[1].toInt(),
628 (MyTheme["Window"].toArray())[2].toInt()));
629 mypalette.setColor(
630 QPalette::WindowText,
631 QColor((MyTheme["WindowText"].toArray())[0].toInt(),
632 (MyTheme["WindowText"].toArray())[1].toInt(),
633 (MyTheme["WindowText"].toArray())[2].toInt()));
634 mypalette.setColor(QPalette::Base,
635 QColor((MyTheme["Base"].toArray())[0].toInt(),
636 (MyTheme["Base"].toArray())[1].toInt(),
637 (MyTheme["Base"].toArray())[2].toInt()));
638 mypalette.setColor(
639 QPalette::AlternateBase,
640 QColor((MyTheme["AlternateBase"].toArray())[0].toInt(),
641 (MyTheme["AlternateBase"].toArray())[1].toInt(),
642 (MyTheme["AlternateBase"].toArray())[2].toInt()));
643 mypalette.setColor(
644 QPalette::ToolTipBase,
645 QColor((MyTheme["ToolTipBase"].toArray())[0].toInt(),
646 (MyTheme["ToolTipBase"].toArray())[1].toInt(),
647 (MyTheme["ToolTipBase"].toArray())[2].toInt()));
648 mypalette.setColor(
649 QPalette::ToolTipText,
650 QColor((MyTheme["ToolTipText"].toArray())[0].toInt(),
651 (MyTheme["ToolTipText"].toArray())[1].toInt(),
652 (MyTheme["ToolTipText"].toArray())[2].toInt()));
653 mypalette.setColor(QPalette::Text,
654 QColor((MyTheme["Text"].toArray())[0].toInt(),
655 (MyTheme["Text"].toArray())[1].toInt(),
656 (MyTheme["Text"].toArray())[2].toInt()));
657 mypalette.setColor(QPalette::Button,
658 QColor((MyTheme["Button"].toArray())[0].toInt(),
659 (MyTheme["Button"].toArray())[1].toInt(),
660 (MyTheme["Button"].toArray())[2].toInt()));
661 mypalette.setColor(
662 QPalette::BrightText,
663 QColor((MyTheme["BrightText"].toArray())[0].toInt(),
664 (MyTheme["BrightText"].toArray())[1].toInt(),
665 (MyTheme["BrightText"].toArray())[2].toInt()));
666 mypalette.setColor(
667 QPalette::ButtonText,
668 QColor((MyTheme["ButtonText"].toArray())[0].toInt(),
669 (MyTheme["ButtonText"].toArray())[1].toInt(),
670 (MyTheme["ButtonText"].toArray())[2].toInt()));
671 mypalette.setColor(QPalette::Highlight,
672 QColor((MyTheme["Highlight"].toArray())[0].toInt(),
673 (MyTheme["Highlight"].toArray())[1].toInt(),
674 (MyTheme["Highlight"].toArray())[2].toInt()));
675 mypalette.setColor(
676 QPalette::HighlightedText,
677 QColor((MyTheme["HighlightedText"].toArray())[0].toInt(),
678 (MyTheme["HighlightedText"].toArray())[1].toInt(),
679 (MyTheme["HighlightedText"].toArray())[2].toInt()));
680 mypalette2 = mypalette;
681 }
682 SetStyleAndTheme(app, style, theme);
683 }
684 }
685 fullpath = fileconfig;
686
687 QFile advancedmodelsfile(advancedmodels);
688 if (!advancedmodelsfile.exists() && ((argc > 1) || MACOS))
689 {
690 QFile file2(":/advancedmodels.js");
691 QString str;
692 file2.open(QIODevice::ReadOnly | QIODevice::Text);
693 QTextStream stream(&file2);
694 str.append(stream.readAll());
695 str.replace("DOTSYMBOL", dotsymbol.toStdString().c_str());
696
697 QFile file(advancedmodels);
698 if (!file.open(QIODevice::WriteOnly))
699 {
700 std::cerr << "Cannot open file for writing: "
701 << qPrintable(file.errorString()) << std::endl;
702 return;
703 }
704 QTextStream out(&file);
705 out << str << endl;
706 file.close();
707 file.copy(advancedmodels);
708 QFile::setPermissions(advancedmodels,
709 QFileDevice::ReadOwner | QFileDevice::WriteOwner);
710 }
711
712 QFile mathmodfile(filecollection);
713 if (!mathmodfile.exists() && ((argc > 1) || MACOS))
714 {
715 QFile file2(":/mathmodcollection.js");
716 QString str;
717 file2.open(QIODevice::ReadOnly | QIODevice::Text);
718 QTextStream stream(&file2);
719 str.append(stream.readAll());
720 str.replace("DOTSYMBOL", dotsymbol.toStdString().c_str());
721 QFile file(filecollection);
722 if (!file.open(QIODevice::WriteOnly))
723 {
724 std::cerr << "Cannot open file for writing: "
725 << qPrintable(file.errorString()) << std::endl;
726 return;
727 }
728 QTextStream out(&file);
729 out << str << endl;
730 file.close();
731 file.copy(filecollection);
732 QFile::setPermissions(filecollection,
733 QFileDevice::ReadOwner | QFileDevice::WriteOwner);
734 }
735 }
on_save_clicked()736 void Parametersoptions::on_save_clicked()
737 {
738 QJsonDocument document;
739 document.setObject(JConfig);
740
741 QFile f(fullpath);
742 if (f.open(QIODevice::ReadWrite | QIODevice::Text))
743 {
744 QTextStream t(&f);
745 t << QString(document.toJson());
746 f.close();
747 }
748 }
749
on_comboBox_2_activated(const QString & arg1)750 void Parametersoptions::on_comboBox_2_activated(const QString &arg1)
751 {
752 QJsonObject style = JConfig["Styles"].toObject();
753 style["UsedStyle"] = arg1;
754 JConfig["Styles"] = style;
755 }
756
on_comboBox_3_activated(const QString & arg1)757 void Parametersoptions::on_comboBox_3_activated(const QString &arg1)
758 {
759 QJsonObject style = JConfig["Themes"].toObject();
760 style["UsedTheme"] = arg1;
761 JConfig["Themes"] = style;
762 if (arg1 == "MyTheme")
763 // ui.groupBox->setEnabled(true);
764 ui.groupBox->show();
765 else
766 // ui.groupBox->setDisabled(true);
767 ui.groupBox->hide();
768 }
769
on_comboBox_activated(const QString & arg1)770 void Parametersoptions::on_comboBox_activated(const QString &arg1)
771 {
772 QPalette tmp;
773 QJsonObject tmp1, MyTheme;
774 tmp1 = JConfig["Themes"].toObject();
775 MyTheme = tmp1["MyTheme"].toObject();
776
777 if (arg1 == "Text")
778 {
779 tmp.setColor(QPalette::ButtonText,
780 QColor((MyTheme["Text"].toArray())[0].toInt(),
781 (MyTheme["Text"].toArray())[1].toInt(),
782 (MyTheme["Text"].toArray())[2].toInt()));
783 }
784 else if (arg1 == "BrightText")
785 {
786 tmp.setColor(QPalette::ButtonText,
787 QColor((MyTheme["BrightText"].toArray())[0].toInt(),
788 (MyTheme["BrightText"].toArray())[1].toInt(),
789 (MyTheme["BrightText"].toArray())[2].toInt()));
790 }
791 else if (arg1 == "ButtonText")
792 {
793 tmp.setColor(QPalette::ButtonText,
794 QColor((MyTheme["ButtonText"].toArray())[0].toInt(),
795 (MyTheme["ButtonText"].toArray())[1].toInt(),
796 (MyTheme["ButtonText"].toArray())[2].toInt()));
797 }
798 else if (arg1 == "Button")
799 {
800 tmp.setColor(QPalette::ButtonText,
801 QColor((MyTheme["Button"].toArray())[0].toInt(),
802 (MyTheme["Button"].toArray())[1].toInt(),
803 (MyTheme["Button"].toArray())[2].toInt()));
804 }
805 else if (arg1 == "Base")
806 {
807 tmp.setColor(QPalette::ButtonText,
808 QColor((MyTheme["Base"].toArray())[0].toInt(),
809 (MyTheme["Base"].toArray())[1].toInt(),
810 (MyTheme["Base"].toArray())[2].toInt()));
811 }
812 else if (arg1 == "AlternateBase")
813 {
814 tmp.setColor(QPalette::ButtonText,
815 QColor((MyTheme["AlternateBase"].toArray())[0].toInt(),
816 (MyTheme["AlternateBase"].toArray())[1].toInt(),
817 (MyTheme["AlternateBase"].toArray())[2].toInt()));
818 }
819 else if (arg1 == "Highlight")
820 {
821 tmp.setColor(QPalette::ButtonText,
822 QColor((MyTheme["Highlight"].toArray())[0].toInt(),
823 (MyTheme["Highlight"].toArray())[1].toInt(),
824 (MyTheme["Highlight"].toArray())[2].toInt()));
825 }
826 else if (arg1 == "HighlightedText")
827 {
828 tmp.setColor(QPalette::ButtonText,
829 QColor((MyTheme["HighlightedText"].toArray())[0].toInt(),
830 (MyTheme["HighlightedText"].toArray())[1].toInt(),
831 (MyTheme["HighlightedText"].toArray())[2].toInt()));
832 }
833 else if (arg1 == "ToolTipBase")
834 {
835 tmp.setColor(QPalette::ButtonText,
836 QColor((MyTheme["ToolTipBase"].toArray())[0].toInt(),
837 (MyTheme["ToolTipBase"].toArray())[1].toInt(),
838 (MyTheme["ToolTipBase"].toArray())[2].toInt()));
839 }
840 else if (arg1 == "ToolTipText")
841 {
842 tmp.setColor(QPalette::ButtonText,
843 QColor((MyTheme["ToolTipText"].toArray())[0].toInt(),
844 (MyTheme["ToolTipText"].toArray())[1].toInt(),
845 (MyTheme["ToolTipText"].toArray())[2].toInt()));
846 }
847 else if (arg1 == "WindowText")
848 {
849 tmp.setColor(QPalette::ButtonText,
850 QColor((MyTheme["WindowText"].toArray())[0].toInt(),
851 (MyTheme["WindowText"].toArray())[1].toInt(),
852 (MyTheme["WindowText"].toArray())[2].toInt()));
853 }
854 else if (arg1 == "Window")
855 {
856 tmp.setColor(QPalette::ButtonText,
857 QColor((MyTheme["Window"].toArray())[0].toInt(),
858 (MyTheme["Window"].toArray())[1].toInt(),
859 (MyTheme["Window"].toArray())[2].toInt()));
860 }
861 ui.ColorsButton->setPalette(tmp);
862 }
863
onred_2valueChanged(int value)864 void Parametersoptions::onred_2valueChanged(int value)
865 {
866 QString choice = ui.comboBox->currentText();
867 QJsonArray tmp =
868 ((JConfig["Themes"].toObject())["MyTheme"].toObject())[choice].toArray();
869 tmp[0] = value;
870 QJsonObject t1 = JConfig["Themes"].toObject();
871 QJsonObject t2 = t1["MyTheme"].toObject();
872 t2[choice] = tmp;
873 t1["MyTheme"] = t2;
874 JConfig["Themes"] = t1;
875 on_comboBox_activated(choice);
876 }
877
ongreen_2valueChanged(int value)878 void Parametersoptions::ongreen_2valueChanged(int value)
879 {
880 QString choice = ui.comboBox->currentText();
881 QJsonArray tmp =
882 ((JConfig["Themes"].toObject())["MyTheme"].toObject())[choice].toArray();
883 tmp[1] = value;
884 QJsonObject t1 = JConfig["Themes"].toObject();
885 QJsonObject t2 = t1["MyTheme"].toObject();
886 t2[choice] = tmp;
887 t1["MyTheme"] = t2;
888 JConfig["Themes"] = t1;
889 on_comboBox_activated(choice);
890 }
891
onblue_2valueChanged(int value)892 void Parametersoptions::onblue_2valueChanged(int value)
893 {
894 QString choice = ui.comboBox->currentText();
895 QJsonArray tmp =
896 ((JConfig["Themes"].toObject())["MyTheme"].toObject())[choice].toArray();
897 tmp[2] = value;
898 QJsonObject t1 = JConfig["Themes"].toObject();
899 QJsonObject t2 = t1["MyTheme"].toObject();
900 t2[choice] = tmp;
901 t1["MyTheme"] = t2;
902 JConfig["Themes"] = t1;
903 on_comboBox_activated(choice);
904 }
905
on_TestConfig_clicked()906 void Parametersoptions::on_TestConfig_clicked()
907 {
908 if (JConfig["Themes"].isObject() && JConfig["Styles"].isObject())
909 {
910 QJsonObject tmp1, tmp2, MyTheme;
911 tmp2 = JConfig["Styles"].toObject();
912 QString style = tmp2["UsedStyle"].toString();
913
914 tmp1 = JConfig["Themes"].toObject();
915 QString theme = tmp1["UsedTheme"].toString();
916
917 if (theme == "MyTheme")
918 {
919 MyTheme = tmp1["MyTheme"].toObject();
920 mypalette.setColor(QPalette::Window,
921 QColor((MyTheme["Window"].toArray())[0].toInt(),
922 (MyTheme["Window"].toArray())[1].toInt(),
923 (MyTheme["Window"].toArray())[2].toInt()));
924 mypalette.setColor(QPalette::WindowText,
925 QColor((MyTheme["WindowText"].toArray())[0].toInt(),
926 (MyTheme["WindowText"].toArray())[1].toInt(),
927 (MyTheme["WindowText"].toArray())[2].toInt()));
928 mypalette.setColor(QPalette::Base,
929 QColor((MyTheme["Base"].toArray())[0].toInt(),
930 (MyTheme["Base"].toArray())[1].toInt(),
931 (MyTheme["Base"].toArray())[2].toInt()));
932 mypalette.setColor(
933 QPalette::AlternateBase,
934 QColor((MyTheme["AlternateBase"].toArray())[0].toInt(),
935 (MyTheme["AlternateBase"].toArray())[1].toInt(),
936 (MyTheme["AlternateBase"].toArray())[2].toInt()));
937 mypalette.setColor(QPalette::ToolTipBase,
938 QColor((MyTheme["ToolTipBase"].toArray())[0].toInt(),
939 (MyTheme["ToolTipBase"].toArray())[1].toInt(),
940 (MyTheme["ToolTipBase"].toArray())[2].toInt()));
941 mypalette.setColor(QPalette::ToolTipText,
942 QColor((MyTheme["ToolTipText"].toArray())[0].toInt(),
943 (MyTheme["ToolTipText"].toArray())[1].toInt(),
944 (MyTheme["ToolTipText"].toArray())[2].toInt()));
945 mypalette.setColor(QPalette::Text,
946 QColor((MyTheme["Text"].toArray())[0].toInt(),
947 (MyTheme["Text"].toArray())[1].toInt(),
948 (MyTheme["Text"].toArray())[2].toInt()));
949 mypalette.setColor(QPalette::Button,
950 QColor((MyTheme["Button"].toArray())[0].toInt(),
951 (MyTheme["Button"].toArray())[1].toInt(),
952 (MyTheme["Button"].toArray())[2].toInt()));
953 mypalette.setColor(QPalette::BrightText,
954 QColor((MyTheme["BrightText"].toArray())[0].toInt(),
955 (MyTheme["BrightText"].toArray())[1].toInt(),
956 (MyTheme["BrightText"].toArray())[2].toInt()));
957 mypalette.setColor(QPalette::ButtonText,
958 QColor((MyTheme["ButtonText"].toArray())[0].toInt(),
959 (MyTheme["ButtonText"].toArray())[1].toInt(),
960 (MyTheme["ButtonText"].toArray())[2].toInt()));
961 mypalette.setColor(QPalette::Highlight,
962 QColor((MyTheme["Highlight"].toArray())[0].toInt(),
963 (MyTheme["Highlight"].toArray())[1].toInt(),
964 (MyTheme["Highlight"].toArray())[2].toInt()));
965 mypalette.setColor(
966 QPalette::HighlightedText,
967 QColor((MyTheme["HighlightedText"].toArray())[0].toInt(),
968 (MyTheme["HighlightedText"].toArray())[1].toInt(),
969 (MyTheme["HighlightedText"].toArray())[2].toInt()));
970 mypalette2 = mypalette;
971 }
972 SetStyleAndTheme(*MainApp, style, theme);
973 }
974 }
975