diff --git a/src/data.hpp b/src/data.hpp index 61a509f..4f57f6d 100644 --- a/src/data.hpp +++ b/src/data.hpp @@ -85,9 +85,6 @@ class Data { bool oems_sort_metalresmesh; bool oems_pkg; -#ifndef QRFL_MINIMAL - std::string gui_theme; -#endif // QRFL_MINIMAL Data(); void reset(); diff --git a/src/main.cpp b/src/main.cpp index 47b9539..c4edae8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -43,6 +43,7 @@ int main(int argc, char* argv[]) { //variables bool verbose=false; [[maybe_unused]] bool gui=false; + [[maybe_unused]] string gui_theme; Data data; //argument parser @@ -74,7 +75,7 @@ int main(int argc, char* argv[]) { " - .kicad_mod : KiCad module\n" " - .lht : pcb-rnd layout\n" " - .m : OpenEMS Octave script\n" - " - .svg : SVG image\n" + " - .svg : SVG image\n" " -n NETLIST Specify a netlist to use instead of calling Qucs to create it from the schematic.\n" " Useful when Qucs is not installed, if you use QucsStudio for example.\n" " -q, --qucs PATH Specify Qucs executable to call for netlist creation, otherwise qucs, then qucs-s will\n" @@ -208,7 +209,7 @@ int main(int argc, char* argv[]) { #ifndef QRFL_MINIMAL } else if(string(argv[i])=="--gui-theme" && argv[i+1]) { i++; - data.gui_theme=string(argv[i]); + gui_theme=string(argv[i]); #endif // QRFL_MINIMAL } else if(string(argv[i])=="-v" || string(argv[i])=="--verbose") { verbose=true; @@ -233,7 +234,7 @@ int main(int argc, char* argv[]) { QApplication a(argc, argv); // Avoid a stold() bug introduced by QApplication() performing setlocale(LC_ALL, "") setlocale(LC_NUMERIC, "C"); - MainWindow w(data); + MainWindow w(data, gui_theme); log_err.obj=&w; log_err.set_mode(gui); // log_err << "WARNING : GUI and circuit preview are not up to date yet, take a look at the command line. ;)\n"; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 10f6d40..5f06875 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -19,12 +19,12 @@ using namespace std; //****************************************************************************** -MainWindow::MainWindow(Data& _data, QWidget* parent) : - QMainWindow(parent), - ui(std::make_unique()), - data(_data), - converter(_data), - openfile_path(QDir::currentPath()) { +MainWindow::MainWindow(Data& _data, string const& gui_theme, QWidget* parent) +: QMainWindow(parent) +, ui(std::make_unique()) +, data(_data) +, converter(_data) +, openfile_path(QDir::currentPath()) { ui->setupUi(this); ui->le_path_in->setText(QString::fromStdString(_data.n_sch.generic_string())); ui->le_path_net->setText(QString::fromStdString(_data.n_net.generic_string())); @@ -49,9 +49,16 @@ MainWindow::MainWindow(Data& _data, QWidget* parent) : ui->cb_oems_pkg->setCheckState(_data.oems_pkg ? Qt::Checked : Qt::Unchecked); ui->cb_oems_sort_metalresmesh->setCheckState(_data.oems_sort_metalresmesh ? Qt::Checked : Qt::Unchecked); ui->cb_transparency->setCheckState(Qt::Unchecked); - ui->glw_preview->setTheme(_data.gui_theme); ui->tw_actions->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); + ui->glw_preview->setTheme(gui_theme); + for(auto const& theme : ui->glw_preview->themes) { + auto* const action = a_themes.emplace_back(make_unique(QString::fromStdString(string(theme.name)), ui->ag_themes)).get(); + action->setCheckable(true); + action->setChecked((theme.name==ui->glw_preview->getTheme()) ? true : false); + ui->m_theme->addAction(action); + } + for(std::tuple arg : data.port_shift_args) { add_action("Shift port", QString::number(get<0>(arg)), @@ -233,6 +240,12 @@ void MainWindow::on_a_topology_mstep_triggered() { open_doc_file("topology_mstep void MainWindow::on_a_topology_mtee_triggered() { open_doc_file("topology_mtee"); } void MainWindow::on_a_topology_mvia_triggered() { open_doc_file("topology_mvia"); } +//****************************************************************************** +void MainWindow::on_ag_themes_triggered(QAction* const action) { + ui->glw_preview->setTheme(action->text().toStdString()); + ui->glw_preview->update(); + } + //****************************************************************************** void MainWindow::on_cb_format_currentTextChanged(QString const& out_format) { ui->gb_oems->setEnabled((out_format==".m") ? true : false); diff --git a/src/mainwindow.hpp b/src/mainwindow.hpp index c4cdd4b..1b4be8c 100644 --- a/src/mainwindow.hpp +++ b/src/mainwindow.hpp @@ -8,11 +8,13 @@ #ifndef QRFL_MINIMAL +#include #include #include #include #include +#include #include "converter.hpp" #include "data.hpp" @@ -28,6 +30,7 @@ class MainWindow : public QMainWindow, public Loggable { Converter converter; QString openfile_path; + std::vector> a_themes; void add_action(QString const action_str="Shift port", QString const val1="", QString const val2="", QString const val3=""); void read(); @@ -70,6 +73,7 @@ private slots: void on_a_topology_mstep_triggered(); void on_a_topology_mtee_triggered(); void on_a_topology_mvia_triggered(); + void on_ag_themes_triggered(QAction* const action); void on_cb_format_currentTextChanged(QString const& out_format); void on_cb_specify_netlist_stateChanged(int const state); void on_cb_transparency_stateChanged(int const state); @@ -99,7 +103,7 @@ private slots: void on_rb_export_whole_toggled(bool const is_checked); public: - explicit MainWindow(Data& _data, QWidget* parent=0); + explicit MainWindow(Data& _data, std::string const& gui_theme, QWidget* parent=0); ~MainWindow()=default; }; diff --git a/src/mainwindow.ui b/src/mainwindow.ui index ed917dd..1a045bc 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -444,6 +444,19 @@ Should be a component label + + + View + + + + Theme + + + + + + diff --git a/src/preview.cpp b/src/preview.cpp index 0029ff9..2fc2057 100644 --- a/src/preview.cpp +++ b/src/preview.cpp @@ -8,7 +8,9 @@ #define _USE_MATH_DEFINES +#include #include +#include #include "preview.hpp" using namespace std; @@ -45,64 +47,72 @@ struct Preview::Colors { }; //****************************************************************************** -map const Preview::Themes { - { "QucsIcon", { // not much contrast when transparent - .background = Colors::QUCS_GUI_CREAM_BACKGROUND, - .substrate = Colors::QUCS_LOGO_ORANGE_DARK, - .track = Colors::QUCS_LOGO_ORANGE_MAIN, - .port = Colors::QUCS_GUI_DARK_BLUE, - .via = Colors::QUCS_LOGO_ORANGE_BACK - }}, - { "QucsGUI", { +vector const Preview::themes { + { + .name = "Flashy", + .background = Colors::GREY_DARK, + .substrate = Colors::SLVS_GUI_GREEN, + .track = Colors::YELLOW, + .port = Colors::BLACK, + .via = Colors::ORANGE + }, + { + .name = "HighContrast", // Not much contrast when transparent + .background = Colors::GREY_MID, + .substrate = Colors::BLACK, + .track = Colors::WHITE, + .port = Colors::BLUE, + .via = Colors::GREEN + }, + { + .name = "HighContrast2", + .background = Colors::BLACK, + .substrate = Colors::GREY_MID, + .track = Colors::WHITE, + .port = Colors::BLUE, + .via = Colors::GREEN + }, + { + .name = "QucsGUI", .background = Colors::QUCS_GUI_CREAM_BACKGROUND, .substrate = Colors::BLACK, .track = Colors::QUCS_GUI_DARK_BLUE, .port = Colors::RED, // .via = Colors::QUCS_LOGO_ORANGE_MAIN .via = Colors::QUCS_GUI_DARK_RED - }}, -// { "CAD", { + }, + { + .name = "QucsIcon", // not much contrast when transparent + .background = Colors::QUCS_GUI_CREAM_BACKGROUND, + .substrate = Colors::QUCS_LOGO_ORANGE_DARK, + .track = Colors::QUCS_LOGO_ORANGE_MAIN, + .port = Colors::QUCS_GUI_DARK_BLUE, + .via = Colors::QUCS_LOGO_ORANGE_BACK + }, +// { +// .name = "CAD", // .background = Colors::GREY_DARK, // .substrate = Colors::GREEN_DARK, // .track = Colors::QRFL_DOC_ORANGE, //// .port = Colors::, // .via = Colors::QUCS_LOGO_ORANGE_BACK -// }}, - { "Solvespace", { +// }, + { + .name = "Solvespace", .background = Colors::BLACK, .substrate = Colors::SLVS_GUI_GREY, .track = Colors::SLVS_LOGO_PINK, .port = Colors::SLVS_LOGO_GREEN, .via = Colors::SLVS_GUI_TEAL - }}, - { "Transcalc", { // Not much contrast when transparent + }, + { + .name = "Transcalc", // Not much contrast when transparent .background = Colors::WHITE, .substrate = Colors::QUCS_TRANSCALC_GREY, .track = Colors::QUCS_TRANSCALC_ORANGE, .port = Colors::BLUE, .via = Colors::BLACK - }}, - { "Flashy", { - .background = Colors::GREY_DARK, - .substrate = Colors::SLVS_GUI_GREEN, - .track = Colors::YELLOW, - .port = Colors::BLACK, - .via = Colors::ORANGE - }}, - { "HighContrast", { // Not much contrast when transparent - .background = Colors::GREY_MID, - .substrate = Colors::BLACK, - .track = Colors::WHITE, - .port = Colors::BLUE, - .via = Colors::GREEN - }}, - { "HighContrast2", { - .background = Colors::BLACK, - .substrate = Colors::GREY_MID, - .track = Colors::WHITE, - .port = Colors::BLUE, - .via = Colors::GREEN - }} + } }; //****************************************************************************** @@ -113,7 +123,6 @@ Preview::Preview(QWidget* parent) : QOpenGLWidget(parent), QOpenGLFunctions_2_0( void Preview::initializeGL() { initializeOpenGLFunctions(); - glClearColor(theme.background.r, theme.background.g, theme.background.b, 1.0f); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glEnable(GL_STENCIL_TEST); @@ -131,6 +140,7 @@ void Preview::initializeGL() { //****************************************************************************** void Preview::paintGL() { + glClearColor(theme.background.r, theme.background.g, theme.background.b, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); // To operate on model-view matrix @@ -275,13 +285,29 @@ void Preview::setTransparency(bool _flag_transparent) { //****************************************************************************** void Preview::setTheme(string const& _theme) { - if(Themes.contains(_theme)) { - theme=Themes.at(_theme); + auto const find_theme = [](string const& name) -> optional { + auto const& it = find_if(begin(themes), end(themes), + [&name](Theme const& theme) { + return (theme.name == name); + }); + if(it != end(themes)) + return *it; + else + return nullopt; + }; + + if(auto const t = find_theme(_theme); t) { + theme=t.value(); } else { - theme=Themes.at("Flashy"); + theme=find_theme("Flashy").value(); } } +//****************************************************************************** +string_view Preview::getTheme() { + return theme.name; + } + //****************************************************************************** void Preview::setF2D(bool _flag_2d) { flag_2d=_flag_2d; diff --git a/src/preview.hpp b/src/preview.hpp index b9107c6..7eaca8c 100644 --- a/src/preview.hpp +++ b/src/preview.hpp @@ -13,7 +13,6 @@ #include #include -#include #include #include @@ -23,28 +22,32 @@ class Preview : public QOpenGLWidget, protected QOpenGLFunctions_2_0 { Q_OBJECT public : + struct Color { double r=0.0, g=0.0, b=0.0; }; + struct Colors; + struct Theme { + std::string_view name; + Color background; + Color substrate; + Color track; + Color port; + Color via; + }; + explicit Preview(QWidget* parent=0); ~Preview()=default; void set(std::vector> const& all_elements, std::array const& extrem_pos); void resetView(); + std::string_view getTheme(); void setTheme(std::string const& _theme); void setTransparency(bool _flag_transparent); void setF2D(bool _flag_2d); void setFCtrl(bool _flag_ctrl); void setFShift(bool _flag_shift); -private: - struct Color { double r=0.0, g=0.0, b=0.0; }; - struct Colors; - struct Theme { - Color background; - Color substrate; - Color track; - Color port; - Color via; - }; + static std::vector const themes; +private: void drawAll(); void drawShape3D(int npoint, long double tab_x[], long double tab_y[], long double z_min, long double z_max, Color color); void drawShape(int npoint, long double tab_x[], long double tab_y[], long double z); @@ -63,7 +66,6 @@ public : void setYRotation(int angle); void setZRotation(int angle); - static std::map const Themes; Theme theme; int xRot=0;