Skip to content

Commit

Permalink
Merge pull request #1125 from dsm/add_style_selection
Browse files Browse the repository at this point in the history
Add style selection
  • Loading branch information
ra3xdh authored Dec 6, 2024
2 parents 9e4ac5a + 1d3441e commit 1a3ce17
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 44 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ __pycache__
.vscode/settings.json
.vscode/tasks.json
/cmake-build-debug/

.cache/
/qt/
build-qucs-s-spar-viewer-Desktop-Debug/
4 changes: 3 additions & 1 deletion qucs-activefilter/qucsactivefilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,9 @@ QucsActiveFilter::QucsActiveFilter(QWidget *parent)
QSize sz;
QString s1 = ":/images/bitmaps/AFR.svg";
imgAFR = new QSvgWidget(s1);
imgAFR->setStyleSheet("background-color: white;");
sz = gpbPar->size(); // take left box size as reference size
sz *= 0.6;
sz *= 0.75;
imgAFR->setFixedSize(sz);
vl1->addWidget(imgAFR);
vl1->setAlignment(imgAFR, Qt::AlignHCenter);
Expand All @@ -234,6 +235,7 @@ QucsActiveFilter::QucsActiveFilter(QWidget *parent)
gpbSCH->setLayout(vl2);
s1 = ":/images/bitmaps/cauer.svg";
sch_pic = new QSvgWidget(s1);
sch_pic->setStyleSheet("background-color: white;");
sz = gpbFunc->size(); // take lefbox size as reference size
sz *= 0.95;
sch_pic->setFixedSize(sz);
Expand Down
1 change: 1 addition & 0 deletions qucs-attenuator/qucsattenuator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ QucsAttenuator::QucsAttenuator()
topoGrid->addWidget(ComboTopology, 1,0,1,2);

pixTopology = new QLabel(TopoGroup);//====================Pixmap for Topology
pixTopology->setStyleSheet("background-color: white;");
pixTopology->setPixmap(QPixmap((":/bitmaps/att_pi.png")));
topoGrid->addWidget(pixTopology,2,0,3,2);

Expand Down
1 change: 1 addition & 0 deletions qucs-powercombining/qucspowercombiningtool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ QucsPowerCombiningTool::QucsPowerCombiningTool()
QString s1 = ":/bitmaps/Wilkinson_idealTL.svg";
QGridLayout * imgLayout = new QGridLayout();
imgWidget = new QSvgWidget(s1);
imgWidget->setStyleSheet("background-color: white;");
sz = imgWidget->size();
imgWidget->setFixedSize(.6*sz);
imgLayout->addWidget(imgWidget);
Expand Down
114 changes: 81 additions & 33 deletions qucs/dialogs/qucssettingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,24 @@
#include <QFileDialog>
#include <QDirIterator>
#include <QDebug>
#include <QObject>
#include <QString>
#include <QList>

using namespace std;

auto getFontDescription = [](const auto& Font) -> QString {
const QChar comma(u',');
QString fontDescription = Font.family() + comma +
QString::number(Font.pointSize());

QString fontStyle = Font.styleName();
if (!fontStyle.isEmpty())
fontDescription += comma + fontStyle;

return fontDescription;
};

QucsSettingsDialog::QucsSettingsDialog(QucsApp *parent)
: QDialog(parent)
{
Expand All @@ -75,30 +90,34 @@ QucsSettingsDialog::QucsSettingsDialog(QucsApp *parent)
QWidget *appSettingsTab = new QWidget(t);
QGridLayout *appSettingsGrid = new QGridLayout(appSettingsTab);

const QStringList appLanguages = {
tr("system language"),
tr("English") + " (en)",
tr("Arabic") + " (ar)",
tr("Catalan") + " (ca)",
tr("Chinese") + " (zh_CN)",
tr("Czech") + " (cs)",
tr("French") + " (fr)",
tr("German") + " (de)",
tr("Hebrew") + " (he)",
tr("Hungarian") + " (hu)",
tr("Italian") + " (it)",
tr("Japanese") + " (jp)",
tr("Kazakh") + " (kk)",
tr("Polish") + " (pl)",
tr("Portuguese-BR") + " (pt_BR)",
tr("Portuguese-PT") + " (pt_PT)",
tr("Romanian") + " (ro)",
tr("Russian") + " (ru)",
tr("Spanish") + " (es)",
tr("Swedish") + " (sv)",
tr("Turkish") + " (tr)",
tr("Ukrainian") + " (uk)"
};

appSettingsGrid->addWidget(new QLabel(tr("Language (set after reload):"), appSettingsTab) ,1, 0);
LanguageCombo = new QComboBox(appSettingsTab);
LanguageCombo->insertItem(-1, tr("Ukrainian")+" (uk)");
LanguageCombo->insertItem(-1, tr("Turkish")+" (tr)");
LanguageCombo->insertItem(-1, tr("Swedish")+" (sv)");
LanguageCombo->insertItem(-1, tr("Spanish")+" (es)");
LanguageCombo->insertItem(-1, tr("Russian")+" (ru)");
LanguageCombo->insertItem(-1, tr("Romanian")+" (ro)");
LanguageCombo->insertItem(-1, tr("Portuguese-PT")+" (pt_PT)");
LanguageCombo->insertItem(-1, tr("Portuguese-BR")+" (pt_BR)");
LanguageCombo->insertItem(-1, tr("Polish")+" (pl)");
LanguageCombo->insertItem(-1, tr("Kazakh")+" (kk)");
LanguageCombo->insertItem(-1, tr("Japanese")+" (jp)");
LanguageCombo->insertItem(-1, tr("Italian")+" (it)");
LanguageCombo->insertItem(-1, tr("Hungarian")+" (hu)");
LanguageCombo->insertItem(-1, tr("Hebrew")+" (he)");
LanguageCombo->insertItem(-1, tr("German")+" (de)");
LanguageCombo->insertItem(-1, tr("French")+" (fr)");
LanguageCombo->insertItem(-1, tr("Chinese")+" (zh_CN)");
LanguageCombo->insertItem(-1, tr("Czech")+" (cs)");
LanguageCombo->insertItem(-1, tr("Catalan")+" (ca)");
LanguageCombo->insertItem(-1, tr("Arabic")+" (ar)");
LanguageCombo->insertItem(-1, tr("English")+" (en)");
LanguageCombo->insertItem(-1, tr("system language"));
LanguageCombo->addItems(appLanguages);
appSettingsGrid->addWidget(LanguageCombo, 1, 1);

val200 = new QIntValidator(0, 200, this);
Expand Down Expand Up @@ -181,7 +200,21 @@ QucsSettingsDialog::QucsSettingsDialog(QucsApp *parent)
appAppearanceGrid->addWidget(new QLabel(tr("Default graph line thickness:"), appSettingsTab), 8, 0);
graphLineWidthEdit = new QLineEdit(appSettingsTab);
graphLineWidthEdit->setValidator(val50);
appAppearanceGrid->addWidget(graphLineWidthEdit, 8, 1);
appAppearanceGrid->addWidget(graphLineWidthEdit, 8, 1);

appAppearanceGrid->addWidget(new QLabel(tr("App Style:"), appSettingsTab), 9, 0);
QStringList styles = QStyleFactory::keys(); // Get available styles
StyleCombo = new QComboBox(appSettingsTab);
StyleCombo->addItems(styles);
appAppearanceGrid->addWidget(StyleCombo,9,1);


// Retrieve the current style and set it as selected
QString currentStyle = QApplication::style()->objectName();
int index = StyleCombo->findText(currentStyle, Qt::MatchFixedString);
if (index != -1) {
StyleCombo->setCurrentIndex(index);
}

t->addTab(appAppearanceTab, tr("Appearance"));

Expand Down Expand Up @@ -456,9 +489,12 @@ QucsSettingsDialog::QucsSettingsDialog(QucsApp *parent)
Font = QucsSettings.font;
AppFont = QucsSettings.appFont;
TextFont = QucsSettings.textFont;
FontButton->setText(Font.toString());
AppFontButton->setText(AppFont.toString());
TextFontButton->setText(TextFont.toString());



FontButton->setText(getFontDescription(Font));
AppFontButton->setText(getFontDescription(AppFont));
TextFontButton->setText(getFontDescription(TextFont));
QString s = QString::number(QucsSettings.largeFontSize, 'f', 1);
LargeFontSizeEdit->setText(s);
graphLineWidthEdit->setText(_settings::Get().item<QString>("DefaultGraphLineWidth"));
Expand Down Expand Up @@ -595,10 +631,22 @@ void QucsSettingsDialog::slotApply()
QPalette p = vp->palette();
p.setColor(vp->backgroundRole(), QucsSettings.BGColor);
vp->setPalette(p);

}
changed = true;
}

QString selectedStyle = StyleCombo->currentText();
if (_settings::Get().item<QString>("AppStyle") != selectedStyle )
{
QStyle* style = QStyleFactory::create(selectedStyle);
if (style) {
QApplication::setStyle(style);
_settings::Get().setItem<QString>("AppStyle", selectedStyle);
changed = true;
}
}

// Update all open schematics with the new grid color.
if (_settings::Get().item<QColor>("GridColor") != GridColorButton->palette().color(GridColorButton->backgroundRole())) {
_settings::Get().setItem<QColor>("GridColor", GridColorButton->palette().color(GridColorButton->backgroundRole()));
Expand Down Expand Up @@ -769,7 +817,7 @@ void QucsSettingsDialog::slotFontDialog()
if(ok)
{
Font = tmpFont;
FontButton->setText(Font.toString());
FontButton->setText(getFontDescription(Font));
}
}

Expand All @@ -780,7 +828,7 @@ void QucsSettingsDialog::slotAppFontDialog()
if(ok)
{
AppFont = tmpFont;
AppFontButton->setText(AppFont.toString());
AppFontButton->setText(getFontDescription(AppFont));
}
}

Expand All @@ -791,7 +839,7 @@ void QucsSettingsDialog::slotTextFontDialog()
if(ok)
{
TextFont = tmpFont;
TextFontButton->setText(TextFont.toString());
TextFontButton->setText(getFontDescription(TextFont));
}
}

Expand Down Expand Up @@ -828,13 +876,13 @@ void QucsSettingsDialog::slotDefaultValues()
Font = QApplication::font();
AppFont = QucsSettings.sysDefaultFont;
TextFont = QFontDatabase::systemFont(QFontDatabase::FixedFont);
FontButton->setText(Font.toString());
AppFontButton->setText(AppFont.toString());
TextFontButton->setText(TextFont.toString());
FontButton->setText(getFontDescription(Font));
AppFontButton->setText(getFontDescription(AppFont));
TextFontButton->setText(getFontDescription(TextFont));
LargeFontSizeEdit->setText(QString::number(16.0));

LanguageCombo->setCurrentIndex(0);

p = BGColorButton->palette();
p.setColor(BGColorButton->backgroundRole(), QColor(255,250,225));
BGColorButton->setPalette(p);
Expand Down
5 changes: 3 additions & 2 deletions qucs/dialogs/qucssettingsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ private slots:
QCheckBox *checkWiring, *checkLoadFromFutureVersions,
*checkAntiAliasing, *checkTextAntiAliasing,
*checkFullTraceNames;
QComboBox *LanguageCombo;
QComboBox *LanguageCombo,
*StyleCombo;
QPushButton *FontButton, *AppFontButton, *TextFontButton, *BGColorButton, *GridColorButton;
QLineEdit *LargeFontSizeEdit, *undoNumEdit, *editorEdit, *Input_Suffix,
*Input_Program, *homeEdit, *admsXmlEdit, *ascoEdit, *octaveEdit,
Expand All @@ -108,7 +109,7 @@ private slots:

private:
QStringList currentPaths;


private:
void makePathTable();
Expand Down
8 changes: 8 additions & 0 deletions qucs/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,14 @@ int main(int argc, char *argv[])
// load existing settings (if any)
loadSettings();

/* restore saved style */
QString savedStyle = _settings::Get().item<QString>("AppStyle");
QStyle* style = QStyleFactory::create(savedStyle);
if (style) {
QApplication::setStyle(style);
}
/* restore saved style */

QDir().mkpath(QucsSettings.qucsWorkspaceDir.absolutePath());
QDir().mkpath(QucsSettings.tempFilesDir.absolutePath());

Expand Down
1 change: 1 addition & 0 deletions qucs/qucs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ void QucsApp::initView()
QHBoxLayout *CompSearchLayout = new QHBoxLayout();

simulatorsCombobox = new QComboBox(this);
simulatorsCombobox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
connect(simulatorsCombobox, SIGNAL(activated(int)), SLOT(slotChangeSimulator(int)));

CompChoose = new QComboBox(this);
Expand Down
18 changes: 12 additions & 6 deletions qucs/qucs_actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,19 +841,22 @@ void QucsApp::slotCallEditor()
// Is called to start the filter synthesis program.
void QucsApp::slotCallFilter()
{
launchTool(QUCS_NAME "filter", "filter synthesis");
auto currentStyle = QApplication::style()->objectName();
launchTool(QUCS_NAME "filter", "filter synthesis",(QStringList() << "-style" << currentStyle));
}

void QucsApp::slotCallActiveFilter()
{
launchTool(QUCS_NAME "activefilter", "active filter synthesis");
auto currentStyle = QApplication::style()->objectName();
launchTool(QUCS_NAME "activefilter", "active filter synthesis",(QStringList() << "-style" << currentStyle));
}

// ------------------------------------------------------------------------
// Is called to start the transmission line calculation program.
void QucsApp::slotCallLine()
{
launchTool(QUCS_NAME "trans", "line calculation",QStringList());
auto currentStyle = QApplication::style()->objectName();
launchTool(QUCS_NAME "trans", "line calculation",(QStringList() << "-style" << currentStyle));
}

// --------------------------------------------------------------
Expand All @@ -868,17 +871,20 @@ void QucsApp::slotCallMatch()
// Is called to start the attenuator calculation program.
void QucsApp::slotCallAtt()
{
launchTool(QUCS_NAME "attenuator", "attenuator calculation",QStringList());
auto currentStyle = QApplication::style()->objectName();
launchTool(QUCS_NAME "attenuator", "attenuator calculation",(QStringList() << "-style" << currentStyle));
}

void QucsApp::slotCallPwrComb()
{
launchTool(QUCS_NAME "powercombining", "power combining calculation",QStringList());
auto currentStyle = QApplication::style()->objectName();
launchTool(QUCS_NAME "powercombining", "power combining calculation",(QStringList() << "-style" << currentStyle));
}

void QucsApp::slotCallSPAR_Viewer()
{
launchTool(QUCS_NAME "spar-viewer", "s-parameter viewer",QStringList());
auto currentStyle = QApplication::style()->objectName();
launchTool(QUCS_NAME "spar-viewer", "s-parameter viewer",(QStringList() << "-style" << currentStyle));
}


Expand Down
6 changes: 5 additions & 1 deletion qucs/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ void settingsManager::initDefaults()
m_Defaults["OctaveExecutable"] = "octave.exe";
#else
m_Defaults["NgspiceExecutable"] = "ngspice";
m_Defaults["XyceExecutable"] = "/usr/local/Xyce-Release-6.8.0-OPENSOURCE/bin/Xyce";
#ifndef Q_OS_MACOS
m_Defaults["XyceExecutable"] = "/usr/local/Xyce-Release-6.8.0-OPENSOURCE/bin/Xyce";
#else
m_Defaults["XyceExecutable"] = "Xyce";
#endif
m_Defaults["RFLayoutExecutable"] = "qucsrflayout";
m_Defaults["OctaveExecutable"] = "octave";
#endif
Expand Down

0 comments on commit 1a3ce17

Please sign in to comment.