"Fossies" - the Fresh Open Source Software Archive

Member "mathmod-branches-r508-trunk/ui_modules/parametersoptions.cpp" (8 Mar 2021, 36869 Bytes) of package /linux/misc/mathmod-11.0-source.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "parametersoptions.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 10.1_vs_11.0.

    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 
   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 
   47 void Parametersoptions::slot_about_clicked()
   48 {
   49     this->close();
   50 }
   51 
   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 
   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 
  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 
  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 
  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 
  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 
  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 
  276 void Parametersoptions::on_loadconfig_clicked()
  277 {
  278     ReadConfigFile(fullpath, JConfig);
  279     GuiUpdate();
  280 }
  281 
  282 ListeModelTexture
  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())["ParIso"].isArray())
  358         {
  359             jpariso newjpariso;
  360             jpar newjpar;
  361             jiso newjiso;
  362             jsarray = ((array[i].toObject())["ParIso"].toArray());
  363             for(int i=0; i<jsarray.size(); i++)
  364             {
  365                 if ((jsarray[i].toObject())["Param3D"].isObject())
  366                 {
  367                    jsobj =  (jsarray[i].toObject())["Param3D"].toObject();
  368                    newjpar.read(jsobj);
  369                    newjpariso.JPar = newjpar;
  370                 } else if ((jsarray[i].toObject())["Iso3D"].isObject())
  371                 {
  372                    jsobj =  (jsarray[i].toObject())["Iso3D"].toObject();
  373                    newjiso.read(jsobj);
  374                    newjpariso.JIso = newjiso;
  375                 }
  376             }
  377             a = newjpariso.Name = (array[i].toObject())["Name"].toString();
  378             pariso.JParIso.append(newjpariso);
  379             lst.append(a);
  380         }
  381     }
  382 
  383     lst.sort();
  384     lst.insert(0, "Examples (" + QString::number(lst.count()) + ")");
  385 
  386     ListeModelTexture str;
  387     str.listeModels = lst;
  388     str.listeTextures = lst_2;
  389     str.listePigments = lst_3;
  390     return str;
  391 }
  392 
  393 void Parametersoptions::SaveToFile_CurentMathModel(
  394     QJsonObject CurrentJsonObject)
  395 {
  396     QString fileName = QFileDialog::getSaveFileName(this, tr("Save to file"), "",
  397                        tr("JSON Files (*.js)"));
  398     if (fileName != "")
  399     {
  400         QJsonObject collection;
  401         ReadCollectionFile(fileName, collection);
  402         QJsonDocument document;
  403         if (collection["MathModels"].isArray())
  404         {
  405             QJsonArray array = collection["MathModels"].toArray();
  406             array.append(CurrentJsonObject);
  407             collection["MathModels"] = array;
  408             document.setObject(collection);
  409             QFile f(fileName);
  410             if (f.open(QIODevice::ReadWrite | QIODevice::Text))
  411             {
  412                 QTextStream t(&f);
  413                 QString tmp = QString(document.toJson()).toLatin1();
  414                 t << tmp.toUtf8();
  415                 f.close();
  416             }
  417         }
  418     }
  419 }
  420 
  421 bool Parametersoptions::isFloat(std::string myString)
  422 {
  423     std::istringstream iss(myString);
  424     float f;
  425     iss >> std::noskipws >> f;
  426     return iss.eof() && !iss.fail();
  427 }
  428 
  429 void Parametersoptions::LoadConfig(QApplication &app, int argc, char *argv[])
  430 {
  431     QString argv1;
  432     if (argc > 1)
  433     {
  434         argv1 = QString(argv[1]);
  435         if (!argv1.endsWith("/"))
  436             argv1 += "/";
  437         filecollection = argv1 + filecollection;
  438         fileconfig = argv1 + fileconfig;
  439         advancedmodels = argv1 + advancedmodels;
  440     }
  441     /*
  442         #ifdef Q_OS_MACOS
  443             else
  444             {
  445                 MACOS = true;
  446                 argv1 ="../Resources/";
  447                 filecollection   = argv1 + filecollection;
  448                 fileconfig       = argv1 + fileconfig;
  449                 advancedmodels   = argv1 + advancedmodels;
  450              }
  451         #endif
  452     */
  453     QFile mathmodfileconfig(fileconfig);
  454     if (!mathmodfileconfig.exists() && ((argc > 1) || MACOS))
  455     {
  456         QFile file3(":/mathmodconfig.js");
  457         file3.copy(fileconfig);
  458         QFile::setPermissions(fileconfig,
  459                               QFileDevice::ReadOwner | QFileDevice::WriteOwner);
  460     }
  461 
  462     QFile fconf(fileconfig);
  463     if (fconf.exists())
  464         ReadJsonFile(fileconfig, JConfig);
  465     else
  466         ReadJsonFile(":/mathmodconfig.js", JConfig);
  467 
  468     {
  469         if (JConfig["Localization"].isObject())
  470         {
  471             QJsonObject tmp;
  472             tmp = JConfig["Localization"].toObject();
  473             if (tmp["AutomaticDetection"].isBool() &&
  474                     tmp["AutomaticDetection"].toBool())
  475             {
  476                 FunctionParser ff;
  477                 if ((ff.Parse("1.02", "t")) >= 0)
  478                     dotsymbol = ",";
  479                 else
  480                     dotsymbol = ".";
  481             }
  482             else
  483                 dotsymbol = tmp["DotSymbol"].toString();
  484         }
  485 
  486         if (JConfig["StartOptions"].isObject())
  487         {
  488             QJsonObject tmp;
  489             tmp = JConfig["StartOptions"].toObject();
  490             model = tmp["Model"].toString();
  491         }
  492 
  493         if (JConfig["Parameters"].isObject())
  494         {
  495             IsoParam = JConfig["Parameters"].toObject();
  496             if ((IsoParam)["IsoMaxGrid"].isDouble())
  497                 IsoMaxGrid = ((IsoParam)["IsoMaxGrid"]).toInt();
  498 
  499             if ((IsoParam)["ParMaxGrid"].isDouble())
  500                 ParMaxGrid = ((IsoParam)["ParMaxGrid"]).toInt();
  501 
  502             if ((IsoParam)["InitParGrid"].isDouble())
  503                 InitParGrid = (IsoParam)["InitParGrid"].toInt();
  504 
  505             if ((IsoParam)["InitIsoGrid"].isDouble())
  506                 InitIsoGrid = (IsoParam)["InitIsoGrid"].toInt();
  507         }
  508 
  509         QJsonObject tmp;
  510         if (JConfig["WindowPosition"].isObject())
  511         {
  512             tmp = JConfig["WindowPosition"].toObject();
  513             ControlX = tmp["ControlX"].toInt();
  514             ControlY = tmp["ControlY"].toInt();
  515             GlwinX = tmp["GlwinX"].toInt();
  516             GlwinY = tmp["GlwinY"].toInt();
  517         }
  518 
  519         if (JConfig["WindowSize"].isObject())
  520         {
  521             tmp = JConfig["WindowSize"].toObject();
  522             ControlW = tmp["ControlW"].toInt();
  523             ControlH = tmp["ControlH"].toInt();
  524             GlwinW = tmp["GlwinW"].toInt();
  525             GlwinH = tmp["GlwinH"].toInt();
  526         }
  527 
  528         if (JConfig["OpenGlConfig"].isObject())
  529         {
  530             QJsonObject tmp1, tmp2;
  531             tmp1 = JConfig["OpenGlConfig"].toObject();
  532             Shininess = tmp1["GL_SHININESS"].toInt();
  533 
  534             tmp2 = JConfig["OpenGlConfig"].toObject();
  535             if (tmp2["GL_SPECULAR"].isArray())
  536             {
  537                 Specular[0] =
  538                     (tmp2["GL_SPECULAR"].toArray())[0].toInt();
  539                 Specular[1]=(tmp2["GL_SPECULAR"].toArray())[1].toInt();
  540                 Specular[2]=(tmp2["GL_SPECULAR"].toArray())[2].toInt();
  541                 Specular[3]=(tmp2["GL_SPECULAR"].toArray())[3].toInt();
  542             }
  543 
  544             if (tmp2["GL_AMBIENT"].isArray())
  545             {
  546                 Ambient[0]=(tmp2["GL_AMBIENT"].toArray())[0].toInt();
  547                 Ambient[1]=(tmp2["GL_AMBIENT"].toArray())[1].toInt();
  548                 Ambient[2]=(tmp2["GL_AMBIENT"].toArray())[2].toInt();
  549                 Ambient[3]=(tmp2["GL_AMBIENT"].toArray())[3].toInt();
  550             }
  551 
  552             if (tmp2["GL_DIFFUSE"].isArray())
  553             {
  554                 Diffuse[0]=(tmp2["GL_DIFFUSE"].toArray())[0].toInt();
  555                 Diffuse[1]=(tmp2["GL_DIFFUSE"].toArray())[1].toInt();
  556                 Diffuse[2]=(tmp2["GL_DIFFUSE"].toArray())[2].toInt();
  557                 Diffuse[3]=(tmp2["GL_DIFFUSE"].toArray())[3].toInt();
  558             }
  559         }
  560 
  561         if (JConfig["CalculFactorConfig"].isObject())
  562         {
  563             QJsonObject tmp = JConfig["CalculFactorConfig"].toObject();
  564             CalculFactor[0] = tmp["FactX"].toInt();
  565             CalculFactor[1] = tmp["FactY"].toInt();
  566             CalculFactor[2] = tmp["FactZ"].toInt();
  567         }
  568 
  569         if (JConfig["ThreadsConfig"].isObject())
  570         {
  571             QJsonObject tmp = JConfig["ThreadsConfig"].toObject();
  572             if (tmp["AutoDetect"].isBool() && tmp["AutoDetect"].toBool())
  573                 Threads[0] = QThread::idealThreadCount();
  574             else
  575                 Threads[0] = tmp["ThreadsNumber"].toInt();
  576             Threads[1] = tmp["MinThreadsNumber"].toInt();
  577             Threads[2] = tmp["MaxThreadsNumber"].toInt();
  578         }
  579 
  580         if (JConfig["Themes"].isObject() && JConfig["Styles"].isObject())
  581         {
  582             QJsonObject tmp1, tmp2, MyTheme;
  583             tmp2 = JConfig["Styles"].toObject();
  584             QString style = tmp2["UsedStyle"].toString();
  585             tmp1 = JConfig["Themes"].toObject();
  586             QString theme = tmp1["UsedTheme"].toString();
  587             if (theme == "MyTheme")
  588             {
  589                 MyTheme = tmp1["MyTheme"].toObject();
  590                 mypalette.setColor(QPalette::Window,
  591                                    QColor((MyTheme["Window"].toArray())[0].toInt(),
  592                                           (MyTheme["Window"].toArray())[1].toInt(),
  593                                           (MyTheme["Window"].toArray())[2].toInt()));
  594                 mypalette.setColor(
  595                     QPalette::WindowText,
  596                     QColor((MyTheme["WindowText"].toArray())[0].toInt(),
  597                            (MyTheme["WindowText"].toArray())[1].toInt(),
  598                            (MyTheme["WindowText"].toArray())[2].toInt()));
  599                 mypalette.setColor(QPalette::Base,
  600                                    QColor((MyTheme["Base"].toArray())[0].toInt(),
  601                                           (MyTheme["Base"].toArray())[1].toInt(),
  602                                           (MyTheme["Base"].toArray())[2].toInt()));
  603                 mypalette.setColor(
  604                     QPalette::AlternateBase,
  605                     QColor((MyTheme["AlternateBase"].toArray())[0].toInt(),
  606                            (MyTheme["AlternateBase"].toArray())[1].toInt(),
  607                            (MyTheme["AlternateBase"].toArray())[2].toInt()));
  608                 mypalette.setColor(
  609                     QPalette::ToolTipBase,
  610                     QColor((MyTheme["ToolTipBase"].toArray())[0].toInt(),
  611                            (MyTheme["ToolTipBase"].toArray())[1].toInt(),
  612                            (MyTheme["ToolTipBase"].toArray())[2].toInt()));
  613                 mypalette.setColor(
  614                     QPalette::ToolTipText,
  615                     QColor((MyTheme["ToolTipText"].toArray())[0].toInt(),
  616                            (MyTheme["ToolTipText"].toArray())[1].toInt(),
  617                            (MyTheme["ToolTipText"].toArray())[2].toInt()));
  618                 mypalette.setColor(QPalette::Text,
  619                                    QColor((MyTheme["Text"].toArray())[0].toInt(),
  620                                           (MyTheme["Text"].toArray())[1].toInt(),
  621                                           (MyTheme["Text"].toArray())[2].toInt()));
  622                 mypalette.setColor(QPalette::Button,
  623                                    QColor((MyTheme["Button"].toArray())[0].toInt(),
  624                                           (MyTheme["Button"].toArray())[1].toInt(),
  625                                           (MyTheme["Button"].toArray())[2].toInt()));
  626                 mypalette.setColor(
  627                     QPalette::BrightText,
  628                     QColor((MyTheme["BrightText"].toArray())[0].toInt(),
  629                            (MyTheme["BrightText"].toArray())[1].toInt(),
  630                            (MyTheme["BrightText"].toArray())[2].toInt()));
  631                 mypalette.setColor(
  632                     QPalette::ButtonText,
  633                     QColor((MyTheme["ButtonText"].toArray())[0].toInt(),
  634                            (MyTheme["ButtonText"].toArray())[1].toInt(),
  635                            (MyTheme["ButtonText"].toArray())[2].toInt()));
  636                 mypalette.setColor(QPalette::Highlight,
  637                                    QColor((MyTheme["Highlight"].toArray())[0].toInt(),
  638                                           (MyTheme["Highlight"].toArray())[1].toInt(),
  639                                           (MyTheme["Highlight"].toArray())[2].toInt()));
  640                 mypalette.setColor(
  641                     QPalette::HighlightedText,
  642                     QColor((MyTheme["HighlightedText"].toArray())[0].toInt(),
  643                            (MyTheme["HighlightedText"].toArray())[1].toInt(),
  644                            (MyTheme["HighlightedText"].toArray())[2].toInt()));
  645                 mypalette2 = mypalette;
  646             }
  647             SetStyleAndTheme(app, style, theme);
  648         }
  649     }
  650     fullpath = fileconfig;
  651 
  652     QFile advancedmodelsfile(advancedmodels);
  653     if (!advancedmodelsfile.exists() && ((argc > 1) || MACOS))
  654     {
  655         QFile file2(":/advancedmodels.js");
  656         QString str;
  657         file2.open(QIODevice::ReadOnly | QIODevice::Text);
  658         QTextStream stream(&file2);
  659         str.append(stream.readAll());
  660         str.replace("DOTSYMBOL", dotsymbol.toStdString().c_str());
  661 
  662         QFile file(advancedmodels);
  663         if (!file.open(QIODevice::WriteOnly))
  664         {
  665             std::cerr << "Cannot open file for writing: "
  666                       << qPrintable(file.errorString()) << std::endl;
  667             return;
  668         }
  669         QTextStream out(&file);
  670         out << str << endl;
  671         file.close();
  672         file.copy(advancedmodels);
  673         QFile::setPermissions(advancedmodels,
  674                               QFileDevice::ReadOwner | QFileDevice::WriteOwner);
  675     }
  676 
  677     QFile mathmodfile(filecollection);
  678     if (!mathmodfile.exists() && ((argc > 1) || MACOS))
  679     {
  680         QFile file2(":/mathmodcollection.js");
  681         QString str;
  682         file2.open(QIODevice::ReadOnly | QIODevice::Text);
  683         QTextStream stream(&file2);
  684         str.append(stream.readAll());
  685         str.replace("DOTSYMBOL", dotsymbol.toStdString().c_str());
  686         QFile file(filecollection);
  687         if (!file.open(QIODevice::WriteOnly))
  688         {
  689             std::cerr << "Cannot open file for writing: "
  690                       << qPrintable(file.errorString()) << std::endl;
  691             return;
  692         }
  693         QTextStream out(&file);
  694         out << str << endl;
  695         file.close();
  696         file.copy(filecollection);
  697         QFile::setPermissions(filecollection,
  698                               QFileDevice::ReadOwner | QFileDevice::WriteOwner);
  699     }
  700 }
  701 void Parametersoptions::on_save_clicked()
  702 {
  703     QJsonDocument document;
  704     document.setObject(JConfig);
  705 
  706     QFile f(fullpath);
  707     if (f.open(QIODevice::ReadWrite | QIODevice::Text))
  708     {
  709         QTextStream t(&f);
  710         t << QString(document.toJson());
  711         f.close();
  712     }
  713 }
  714 
  715 void Parametersoptions::on_comboBox_2_activated(const QString &arg1)
  716 {
  717     QJsonObject style = JConfig["Styles"].toObject();
  718     style["UsedStyle"] = arg1;
  719     JConfig["Styles"] = style;
  720 }
  721 
  722 void Parametersoptions::on_comboBox_3_activated(const QString &arg1)
  723 {
  724     QJsonObject style = JConfig["Themes"].toObject();
  725     style["UsedTheme"] = arg1;
  726     JConfig["Themes"] = style;
  727     if (arg1 == "MyTheme")
  728         // ui.groupBox->setEnabled(true);
  729         ui.groupBox->show();
  730     else
  731         // ui.groupBox->setDisabled(true);
  732         ui.groupBox->hide();
  733 }
  734 
  735 void Parametersoptions::on_comboBox_activated(const QString &arg1)
  736 {
  737     QPalette tmp;
  738     QJsonObject tmp1, MyTheme;
  739     tmp1 = JConfig["Themes"].toObject();
  740     MyTheme = tmp1["MyTheme"].toObject();
  741 
  742     if (arg1 == "Text")
  743     {
  744         tmp.setColor(QPalette::ButtonText,
  745                      QColor((MyTheme["Text"].toArray())[0].toInt(),
  746                             (MyTheme["Text"].toArray())[1].toInt(),
  747                             (MyTheme["Text"].toArray())[2].toInt()));
  748     }
  749     else if (arg1 == "BrightText")
  750     {
  751         tmp.setColor(QPalette::ButtonText,
  752                      QColor((MyTheme["BrightText"].toArray())[0].toInt(),
  753                             (MyTheme["BrightText"].toArray())[1].toInt(),
  754                             (MyTheme["BrightText"].toArray())[2].toInt()));
  755     }
  756     else if (arg1 == "ButtonText")
  757     {
  758         tmp.setColor(QPalette::ButtonText,
  759                      QColor((MyTheme["ButtonText"].toArray())[0].toInt(),
  760                             (MyTheme["ButtonText"].toArray())[1].toInt(),
  761                             (MyTheme["ButtonText"].toArray())[2].toInt()));
  762     }
  763     else if (arg1 == "Button")
  764     {
  765         tmp.setColor(QPalette::ButtonText,
  766                      QColor((MyTheme["Button"].toArray())[0].toInt(),
  767                             (MyTheme["Button"].toArray())[1].toInt(),
  768                             (MyTheme["Button"].toArray())[2].toInt()));
  769     }
  770     else if (arg1 == "Base")
  771     {
  772         tmp.setColor(QPalette::ButtonText,
  773                      QColor((MyTheme["Base"].toArray())[0].toInt(),
  774                             (MyTheme["Base"].toArray())[1].toInt(),
  775                             (MyTheme["Base"].toArray())[2].toInt()));
  776     }
  777     else if (arg1 == "AlternateBase")
  778     {
  779         tmp.setColor(QPalette::ButtonText,
  780                      QColor((MyTheme["AlternateBase"].toArray())[0].toInt(),
  781                             (MyTheme["AlternateBase"].toArray())[1].toInt(),
  782                             (MyTheme["AlternateBase"].toArray())[2].toInt()));
  783     }
  784     else if (arg1 == "Highlight")
  785     {
  786         tmp.setColor(QPalette::ButtonText,
  787                      QColor((MyTheme["Highlight"].toArray())[0].toInt(),
  788                             (MyTheme["Highlight"].toArray())[1].toInt(),
  789                             (MyTheme["Highlight"].toArray())[2].toInt()));
  790     }
  791     else if (arg1 == "HighlightedText")
  792     {
  793         tmp.setColor(QPalette::ButtonText,
  794                      QColor((MyTheme["HighlightedText"].toArray())[0].toInt(),
  795                             (MyTheme["HighlightedText"].toArray())[1].toInt(),
  796                             (MyTheme["HighlightedText"].toArray())[2].toInt()));
  797     }
  798     else if (arg1 == "ToolTipBase")
  799     {
  800         tmp.setColor(QPalette::ButtonText,
  801                      QColor((MyTheme["ToolTipBase"].toArray())[0].toInt(),
  802                             (MyTheme["ToolTipBase"].toArray())[1].toInt(),
  803                             (MyTheme["ToolTipBase"].toArray())[2].toInt()));
  804     }
  805     else if (arg1 == "ToolTipText")
  806     {
  807         tmp.setColor(QPalette::ButtonText,
  808                      QColor((MyTheme["ToolTipText"].toArray())[0].toInt(),
  809                             (MyTheme["ToolTipText"].toArray())[1].toInt(),
  810                             (MyTheme["ToolTipText"].toArray())[2].toInt()));
  811     }
  812     else if (arg1 == "WindowText")
  813     {
  814         tmp.setColor(QPalette::ButtonText,
  815                      QColor((MyTheme["WindowText"].toArray())[0].toInt(),
  816                             (MyTheme["WindowText"].toArray())[1].toInt(),
  817                             (MyTheme["WindowText"].toArray())[2].toInt()));
  818     }
  819     else if (arg1 == "Window")
  820     {
  821         tmp.setColor(QPalette::ButtonText,
  822                      QColor((MyTheme["Window"].toArray())[0].toInt(),
  823                             (MyTheme["Window"].toArray())[1].toInt(),
  824                             (MyTheme["Window"].toArray())[2].toInt()));
  825     }
  826     ui.ColorsButton->setPalette(tmp);
  827 }
  828 
  829 void Parametersoptions::onred_2valueChanged(int value)
  830 {
  831     QString choice = ui.comboBox->currentText();
  832     QJsonArray tmp =
  833         ((JConfig["Themes"].toObject())["MyTheme"].toObject())[choice].toArray();
  834     tmp[0] = value;
  835     QJsonObject t1 = JConfig["Themes"].toObject();
  836     QJsonObject t2 = t1["MyTheme"].toObject();
  837     t2[choice] = tmp;
  838     t1["MyTheme"] = t2;
  839     JConfig["Themes"] = t1;
  840     on_comboBox_activated(choice);
  841 }
  842 
  843 void Parametersoptions::ongreen_2valueChanged(int value)
  844 {
  845     QString choice = ui.comboBox->currentText();
  846     QJsonArray tmp =
  847         ((JConfig["Themes"].toObject())["MyTheme"].toObject())[choice].toArray();
  848     tmp[1] = value;
  849     QJsonObject t1 = JConfig["Themes"].toObject();
  850     QJsonObject t2 = t1["MyTheme"].toObject();
  851     t2[choice] = tmp;
  852     t1["MyTheme"] = t2;
  853     JConfig["Themes"] = t1;
  854     on_comboBox_activated(choice);
  855 }
  856 
  857 void Parametersoptions::onblue_2valueChanged(int value)
  858 {
  859     QString choice = ui.comboBox->currentText();
  860     QJsonArray tmp =
  861         ((JConfig["Themes"].toObject())["MyTheme"].toObject())[choice].toArray();
  862     tmp[2] = value;
  863     QJsonObject t1 = JConfig["Themes"].toObject();
  864     QJsonObject t2 = t1["MyTheme"].toObject();
  865     t2[choice] = tmp;
  866     t1["MyTheme"] = t2;
  867     JConfig["Themes"] = t1;
  868     on_comboBox_activated(choice);
  869 }
  870 
  871 void Parametersoptions::on_TestConfig_clicked()
  872 {
  873     if (JConfig["Themes"].isObject() && JConfig["Styles"].isObject())
  874     {
  875         QJsonObject tmp1, tmp2, MyTheme;
  876         tmp2 = JConfig["Styles"].toObject();
  877         QString style = tmp2["UsedStyle"].toString();
  878 
  879         tmp1 = JConfig["Themes"].toObject();
  880         QString theme = tmp1["UsedTheme"].toString();
  881 
  882         if (theme == "MyTheme")
  883         {
  884             MyTheme = tmp1["MyTheme"].toObject();
  885             mypalette.setColor(QPalette::Window,
  886                                QColor((MyTheme["Window"].toArray())[0].toInt(),
  887                                       (MyTheme["Window"].toArray())[1].toInt(),
  888                                       (MyTheme["Window"].toArray())[2].toInt()));
  889             mypalette.setColor(QPalette::WindowText,
  890                                QColor((MyTheme["WindowText"].toArray())[0].toInt(),
  891                                       (MyTheme["WindowText"].toArray())[1].toInt(),
  892                                       (MyTheme["WindowText"].toArray())[2].toInt()));
  893             mypalette.setColor(QPalette::Base,
  894                                QColor((MyTheme["Base"].toArray())[0].toInt(),
  895                                       (MyTheme["Base"].toArray())[1].toInt(),
  896                                       (MyTheme["Base"].toArray())[2].toInt()));
  897             mypalette.setColor(
  898                 QPalette::AlternateBase,
  899                 QColor((MyTheme["AlternateBase"].toArray())[0].toInt(),
  900                        (MyTheme["AlternateBase"].toArray())[1].toInt(),
  901                        (MyTheme["AlternateBase"].toArray())[2].toInt()));
  902             mypalette.setColor(QPalette::ToolTipBase,
  903                                QColor((MyTheme["ToolTipBase"].toArray())[0].toInt(),
  904                                       (MyTheme["ToolTipBase"].toArray())[1].toInt(),
  905                                       (MyTheme["ToolTipBase"].toArray())[2].toInt()));
  906             mypalette.setColor(QPalette::ToolTipText,
  907                                QColor((MyTheme["ToolTipText"].toArray())[0].toInt(),
  908                                       (MyTheme["ToolTipText"].toArray())[1].toInt(),
  909                                       (MyTheme["ToolTipText"].toArray())[2].toInt()));
  910             mypalette.setColor(QPalette::Text,
  911                                QColor((MyTheme["Text"].toArray())[0].toInt(),
  912                                       (MyTheme["Text"].toArray())[1].toInt(),
  913                                       (MyTheme["Text"].toArray())[2].toInt()));
  914             mypalette.setColor(QPalette::Button,
  915                                QColor((MyTheme["Button"].toArray())[0].toInt(),
  916                                       (MyTheme["Button"].toArray())[1].toInt(),
  917                                       (MyTheme["Button"].toArray())[2].toInt()));
  918             mypalette.setColor(QPalette::BrightText,
  919                                QColor((MyTheme["BrightText"].toArray())[0].toInt(),
  920                                       (MyTheme["BrightText"].toArray())[1].toInt(),
  921                                       (MyTheme["BrightText"].toArray())[2].toInt()));
  922             mypalette.setColor(QPalette::ButtonText,
  923                                QColor((MyTheme["ButtonText"].toArray())[0].toInt(),
  924                                       (MyTheme["ButtonText"].toArray())[1].toInt(),
  925                                       (MyTheme["ButtonText"].toArray())[2].toInt()));
  926             mypalette.setColor(QPalette::Highlight,
  927                                QColor((MyTheme["Highlight"].toArray())[0].toInt(),
  928                                       (MyTheme["Highlight"].toArray())[1].toInt(),
  929                                       (MyTheme["Highlight"].toArray())[2].toInt()));
  930             mypalette.setColor(
  931                 QPalette::HighlightedText,
  932                 QColor((MyTheme["HighlightedText"].toArray())[0].toInt(),
  933                        (MyTheme["HighlightedText"].toArray())[1].toInt(),
  934                        (MyTheme["HighlightedText"].toArray())[2].toInt()));
  935             mypalette2 = mypalette;
  936         }
  937         SetStyleAndTheme(*MainApp, style, theme);
  938     }
  939 }