Skip to content

Commit

Permalink
GUI : add view tab to menubar, setting theme
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaslepoix committed Sep 30, 2024
1 parent 7a96403 commit 5b737da
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 67 deletions.
3 changes: 0 additions & 3 deletions src/data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 4 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand All @@ -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";
Expand Down
27 changes: 20 additions & 7 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
using namespace std;

//******************************************************************************
MainWindow::MainWindow(Data& _data, QWidget* parent) :
QMainWindow(parent),
ui(std::make_unique<Ui::MainWindow>()),
data(_data),
converter(_data),
openfile_path(QDir::currentPath()) {
MainWindow::MainWindow(Data& _data, string const& gui_theme, QWidget* parent)
: QMainWindow(parent)
, ui(std::make_unique<Ui::MainWindow>())
, 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()));
Expand All @@ -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<QAction>(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<unsigned long, std::string, std::string> arg : data.port_shift_args) {
add_action("Shift port",
QString::number(get<0>(arg)),
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion src/mainwindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

#ifndef QRFL_MINIMAL

#include <QAction>
#include <QMainWindow>
#include <QObject>

#include <memory>
#include <sstream>
#include <vector>

#include "converter.hpp"
#include "data.hpp"
Expand All @@ -28,6 +30,7 @@ class MainWindow : public QMainWindow, public Loggable {
Converter converter;

QString openfile_path;
std::vector<std::unique_ptr<QAction>> a_themes;

void add_action(QString const action_str="Shift port", QString const val1="", QString const val2="", QString const val3="");
void read();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
};

Expand Down
13 changes: 13 additions & 0 deletions src/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,19 @@ Should be a component label</string>
<addaction name="m_oems_mesh"/>
<addaction name="a_table_orientation"/>
</widget>
<widget class="QMenu" name="m_view">
<property name="title">
<string>View</string>
</property>
<widget class="QMenu" name="m_theme">
<property name="title">
<string>Theme</string>
</property>
<widget class="QActionGroup" name="ag_themes"/>
</widget>
<addaction name="m_theme"/>
</widget>
<addaction name="m_view"/>
<addaction name="m_help"/>
</widget>
<widget class="QStatusBar" name="statusBar"/>
Expand Down
108 changes: 67 additions & 41 deletions src/preview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

#define _USE_MATH_DEFINES

#include <algorithm>
#include <cmath>
#include <optional>

#include "preview.hpp"
using namespace std;
Expand Down Expand Up @@ -45,64 +47,72 @@ struct Preview::Colors {
};

//******************************************************************************
map<string const, Preview::Theme const> 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<Preview::Theme> 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
}}
}
};

//******************************************************************************
Expand All @@ -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);
Expand All @@ -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

Expand Down Expand Up @@ -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<Theme> {
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;
Expand Down
26 changes: 14 additions & 12 deletions src/preview.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <QOpenGLFunctions_2_0>

#include <array>
#include <map>
#include <memory>
#include <vector>

Expand All @@ -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<std::shared_ptr<Element>> const& all_elements, std::array<long double, 4> 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<Theme> 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);
Expand All @@ -63,7 +66,6 @@ public :
void setYRotation(int angle);
void setZRotation(int angle);

static std::map<std::string const, Theme const> const Themes;
Theme theme;

int xRot=0;
Expand Down

0 comments on commit 5b737da

Please sign in to comment.