Merge pull request #1125 from dsm/add_style_selection

Add style selection
This commit is contained in:
Vadim Kuznetsov 2024-12-06 17:28:43 +01:00 committed by GitHub
commit 1a3ce1797c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 117 additions and 44 deletions

3
.gitignore vendored
View File

@ -57,5 +57,6 @@ __pycache__
.vscode/settings.json
.vscode/tasks.json
/cmake-build-debug/
.cache/
/qt/
build-qucs-s-spar-viewer-Desktop-Debug/

View File

@ -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);
@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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)
{
@ -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);
@ -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"));
@ -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"));
@ -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()));
@ -769,7 +817,7 @@ void QucsSettingsDialog::slotFontDialog()
if(ok)
{
Font = tmpFont;
FontButton->setText(Font.toString());
FontButton->setText(getFontDescription(Font));
}
}
@ -780,7 +828,7 @@ void QucsSettingsDialog::slotAppFontDialog()
if(ok)
{
AppFont = tmpFont;
AppFontButton->setText(AppFont.toString());
AppFontButton->setText(getFontDescription(AppFont));
}
}
@ -791,7 +839,7 @@ void QucsSettingsDialog::slotTextFontDialog()
if(ok)
{
TextFont = tmpFont;
TextFontButton->setText(TextFont.toString());
TextFontButton->setText(getFontDescription(TextFont));
}
}
@ -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);

View File

@ -88,7 +88,8 @@ public:
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,
@ -108,7 +109,7 @@ public:
private:
QStringList currentPaths;
private:
void makePathTable();

View File

@ -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());

View File

@ -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);

View File

@ -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));
}
// --------------------------------------------------------------
@ -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));
}

View File

@ -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