Skip to content

Commit

Permalink
Create 'Appearance' tab in settings dialog and allow grid color to be…
Browse files Browse the repository at this point in the history
… set.
  • Loading branch information
iwbnwif committed Nov 14, 2024
1 parent 6abdf70 commit ae7765b
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 51 deletions.
132 changes: 84 additions & 48 deletions qucs/dialogs/qucssettingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,33 +75,7 @@ QucsSettingsDialog::QucsSettingsDialog(QucsApp *parent)
QWidget *appSettingsTab = new QWidget(t);
QGridLayout *appSettingsGrid = new QGridLayout(appSettingsTab);

appSettingsGrid->addWidget(new QLabel(tr("Schematic font (set after reload):"), appSettingsTab), 0,0);
FontButton = new QPushButton(appSettingsTab);
connect(FontButton, SIGNAL(clicked()), SLOT(slotFontDialog()));
appSettingsGrid->addWidget(FontButton,0,1);

appSettingsGrid->addWidget(new QLabel(tr("Application font (set after reload):"), appSettingsTab), 1,0);
AppFontButton = new QPushButton(appSettingsTab);
connect(AppFontButton, SIGNAL(clicked()), SLOT(slotAppFontDialog()));
appSettingsGrid->addWidget(AppFontButton,1,1);

appSettingsGrid->addWidget(new QLabel(tr("Text document font (set after reload):"), appSettingsTab), 2,0);
TextFontButton = new QPushButton(appSettingsTab);
connect(TextFontButton, SIGNAL(clicked()), SLOT(slotTextFontDialog()));
appSettingsGrid->addWidget(TextFontButton,2,1);

val50 = new QIntValidator(1, 50, this);
appSettingsGrid->addWidget(new QLabel(tr("Large font size:"), appSettingsTab), 3,0);
LargeFontSizeEdit = new QLineEdit(appSettingsTab);
LargeFontSizeEdit->setValidator(val50);
appSettingsGrid->addWidget(LargeFontSizeEdit,3,1);

appSettingsGrid->addWidget(new QLabel(tr("Document Background Color:"), appSettingsTab) ,4,0);
BGColorButton = new QPushButton(" ", appSettingsTab);
connect(BGColorButton, SIGNAL(clicked()), SLOT(slotBGColorDialog()));
appSettingsGrid->addWidget(BGColorButton,4,1);

appSettingsGrid->addWidget(new QLabel(tr("Language (set after reload):"), appSettingsTab) ,5,0);
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)");
Expand All @@ -125,48 +99,86 @@ QucsSettingsDialog::QucsSettingsDialog(QucsApp *parent)
LanguageCombo->insertItem(-1, tr("Arabic")+" (ar)");
LanguageCombo->insertItem(-1, tr("English")+" (en)");
LanguageCombo->insertItem(-1, tr("system language"));
appSettingsGrid->addWidget(LanguageCombo,5,1);
appSettingsGrid->addWidget(LanguageCombo, 1, 1);

val200 = new QIntValidator(0, 200, this);
appSettingsGrid->addWidget(new QLabel(tr("Maximum undo operations:"), appSettingsTab) ,6,0);
appSettingsGrid->addWidget(new QLabel(tr("Maximum undo operations:"), appSettingsTab) ,2, 0);
undoNumEdit = new QLineEdit(appSettingsTab);
undoNumEdit->setValidator(val200);
appSettingsGrid->addWidget(undoNumEdit,6,1);
appSettingsGrid->addWidget(undoNumEdit, 2, 1);

appSettingsGrid->addWidget(new QLabel(tr("Text editor:"), appSettingsTab) ,7,0);
appSettingsGrid->addWidget(new QLabel(tr("Text editor:"), appSettingsTab), 3, 0);
editorEdit = new QLineEdit(appSettingsTab);
editorEdit->setToolTip(tr("Set to qucs, qucsedit or the path to your favorite text editor."));
appSettingsGrid->addWidget(editorEdit,7,1);
appSettingsGrid->addWidget(editorEdit, 3, 1);

appSettingsGrid->addWidget(new QLabel(tr("Start wiring when clicking open node:"), appSettingsTab) ,8,0);
appSettingsGrid->addWidget(new QLabel(tr("Start wiring when clicking open node:"), appSettingsTab), 4, 0);
checkWiring = new QCheckBox(appSettingsTab);
appSettingsGrid->addWidget(checkWiring,8,1);
appSettingsGrid->addWidget(checkWiring, 4, 1);

appSettingsGrid->addWidget(new QLabel(tr("Load documents from future versions:")));
appSettingsGrid->addWidget(new QLabel(tr("Load documents from future versions:")), 5, 0);
checkLoadFromFutureVersions = new QCheckBox(appSettingsTab);
checkLoadFromFutureVersions->setToolTip(tr("Try to load also documents created with newer versions of Qucs."));
appSettingsGrid->addWidget(checkLoadFromFutureVersions,9,1);
appSettingsGrid->addWidget(checkLoadFromFutureVersions, 5, 1);
checkLoadFromFutureVersions->setChecked(QucsSettings.IgnoreFutureVersion);

appSettingsGrid->addWidget(new QLabel(tr("Draw diagrams with anti-aliasing feature:")));
appSettingsGrid->addWidget(new QLabel(tr("Show trace name prefix on diagrams:")), 6, 0);
checkFullTraceNames = new QCheckBox(appSettingsTab);
checkFullTraceNames->setToolTip(tr("Show prefixes for trace names on diagrams like \"ngspice/\""));
appSettingsGrid->addWidget(checkFullTraceNames, 6, 1);
checkFullTraceNames->setChecked(QucsSettings.fullTraceName);

t->addTab(appSettingsTab, tr("Settings"));

// ...........................................................
// The appearance settings tab
QWidget *appAppearanceTab = new QWidget(t);
QGridLayout *appAppearanceGrid = new QGridLayout(appAppearanceTab);

appAppearanceGrid->addWidget(new QLabel(tr("Schematic font (set after reload):"), appSettingsTab), 0, 0);
FontButton = new QPushButton(appSettingsTab);
connect(FontButton, SIGNAL(clicked()), SLOT(slotFontDialog()));
appAppearanceGrid->addWidget(FontButton, 0, 1);

appAppearanceGrid->addWidget(new QLabel(tr("Application font (set after reload):"), appSettingsTab), 1, 0);
AppFontButton = new QPushButton(appSettingsTab);
connect(AppFontButton, SIGNAL(clicked()), SLOT(slotAppFontDialog()));
appAppearanceGrid->addWidget(AppFontButton, 1, 1);

appAppearanceGrid->addWidget(new QLabel(tr("Text document font (set after reload):"), appSettingsTab), 2, 0);
TextFontButton = new QPushButton(appSettingsTab);
connect(TextFontButton, SIGNAL(clicked()), SLOT(slotTextFontDialog()));
appAppearanceGrid->addWidget(TextFontButton, 2, 1);

val50 = new QIntValidator(1, 50, this);
appAppearanceGrid->addWidget(new QLabel(tr("Large font size:"), appSettingsTab), 3, 0);
LargeFontSizeEdit = new QLineEdit(appSettingsTab);
LargeFontSizeEdit->setValidator(val50);
appAppearanceGrid->addWidget(LargeFontSizeEdit, 3, 1);

appAppearanceGrid->addWidget(new QLabel(tr("Document Background Color:"), appSettingsTab) ,4, 0);
BGColorButton = new QPushButton(" ", appSettingsTab);
connect(BGColorButton, SIGNAL(clicked()), SLOT(slotBGColorDialog()));
appAppearanceGrid->addWidget(BGColorButton, 4, 1);

appAppearanceGrid->addWidget(new QLabel(tr("Grid Color (set after reload):"), appSettingsTab) ,5, 0);
GridColorButton = new QPushButton(" ", appSettingsTab);
connect(GridColorButton, SIGNAL(clicked()), SLOT(slotGridColorDialog()));
appAppearanceGrid->addWidget(GridColorButton, 5, 1);

appAppearanceGrid->addWidget(new QLabel(tr("Draw diagrams with anti-aliasing feature:")), 6, 0);
checkAntiAliasing = new QCheckBox(appSettingsTab);
checkAntiAliasing->setToolTip(tr("Use anti-aliasing for graphs for a smoother appearance."));
appSettingsGrid->addWidget(checkAntiAliasing,10,1);
appAppearanceGrid->addWidget(checkAntiAliasing, 6, 1);
checkAntiAliasing->setChecked(QucsSettings.GraphAntiAliasing);

appSettingsGrid->addWidget(new QLabel(tr("Draw text with anti-aliasing feature:")));
appAppearanceGrid->addWidget(new QLabel(tr("Draw text with anti-aliasing feature:")), 7, 0);
checkTextAntiAliasing = new QCheckBox(appSettingsTab);
checkTextAntiAliasing->setToolTip(tr("Use anti-aliasing for text for a smoother appearance."));
appSettingsGrid->addWidget(checkTextAntiAliasing,11,1);
checkTextAntiAliasing->setChecked(QucsSettings.TextAntiAliasing);
appAppearanceGrid->addWidget(checkTextAntiAliasing, 7, 1);
checkTextAntiAliasing->setChecked(QucsSettings.TextAntiAliasing);

appSettingsGrid->addWidget(new QLabel(tr("Show trace name prefix on diagrams:")));
checkFullTraceNames = new QCheckBox(appSettingsTab);
checkFullTraceNames->setToolTip(tr("Show prefixes for trace names on diagrams like \"ngspice/\""));
appSettingsGrid->addWidget(checkFullTraceNames,12,1);
checkFullTraceNames->setChecked(QucsSettings.fullTraceName);

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

// ...........................................................
// The source code editor settings tab
Expand Down Expand Up @@ -449,6 +461,10 @@ QucsSettingsDialog::QucsSettingsDialog(QucsApp *parent)
p.setColor(BGColorButton->backgroundRole(), QucsSettings.BGColor);
BGColorButton->setPalette(p);

p = GridColorButton->palette();
p.setColor(GridColorButton->backgroundRole(), _settings::Get().item<QColor>("GridColor"));
GridColorButton->setPalette(p);

undoNumEdit->setText(QString::number(QucsSettings.maxUndo));
editorEdit->setText(QucsSettings.Editor);
checkWiring->setChecked(QucsSettings.NodeWiring);
Expand Down Expand Up @@ -577,6 +593,13 @@ void QucsSettingsDialog::slotApply()
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()));
changed = true;
}

QucsSettings.font=Font;
QucsSettings.appFont = AppFont;
QucsSettings.textFont = TextFont;
Expand Down Expand Up @@ -766,6 +789,19 @@ void QucsSettingsDialog::slotBGColorDialog()
}
}

// -----------------------------------------------------------
void QucsSettingsDialog::slotGridColorDialog()
{
QColor c = QColorDialog::getColor(
GridColorButton->palette().color(GridColorButton->foregroundRole()),
this);
if(c.isValid()) {
QPalette p = GridColorButton->palette();
p.setColor(GridColorButton->backgroundRole(), c);
GridColorButton->setPalette(p);
}
}

// -----------------------------------------------------------
void QucsSettingsDialog::slotDefaultValues()
{
Expand Down
3 changes: 2 additions & 1 deletion qucs/dialogs/qucssettingsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private slots:
void slotAppFontDialog();
void slotTextFontDialog();
void slotBGColorDialog();
void slotGridColorDialog();
void slotDefaultValues();
void slotAddFileType();
void slotRemoveFileType();
Expand Down Expand Up @@ -88,7 +89,7 @@ private slots:
*checkAntiAliasing, *checkTextAntiAliasing,
*checkFullTraceNames;
QComboBox *LanguageCombo;
QPushButton *FontButton, *AppFontButton, *TextFontButton, *BGColorButton;
QPushButton *FontButton, *AppFontButton, *TextFontButton, *BGColorButton, *GridColorButton;
QLineEdit *LargeFontSizeEdit, *undoNumEdit, *editorEdit, *Input_Suffix,
*Input_Program, *homeEdit, *admsXmlEdit, *ascoEdit, *octaveEdit,
*OpenVAFEdit, *RFLayoutEdit;
Expand Down
5 changes: 4 additions & 1 deletion qucs/schematic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "paintings/paintings.h"
#include "qucs.h"
#include "schematic.h"
#include "settings.h"
#include "textdoc.h"

#include "misc.h"
Expand Down Expand Up @@ -87,6 +88,8 @@ Schematic::Schematic(QucsApp *App_, const QString &Name_)
setFont(QucsSettings.font);
// ...........................................................
GridX = GridY = 10;
GridColor = _settings::Get().item<QString>("GridColor");

ViewX1 = ViewY1 = 0;
ViewX2 = ViewY2 = 1;
UsedX1 = UsedY1 = INT_MAX;
Expand Down Expand Up @@ -1078,7 +1081,7 @@ void Schematic::drawGrid(QPainter* painter) {
// A grid drawn with pen of 1.0 width reportedly looks good both
// on standard and HiDPI displays.
// See here for details https://github.com/ra3xdh/qucs_s/pull/524
painter->setPen(QPen{ Qt::black, 1.0 });
painter->setPen(QPen{ GridColor, 1.0 });

{
// Draw small cross at origin of coordinates
Expand Down
3 changes: 2 additions & 1 deletion qucs/schematic.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,9 @@ class Schematic : public Q3ScrollView, public QucsDoc {
bool symbolMode; // true if in symbol painting mode
bool isSymbolOnly;

// Horizontal and vertical grid step
// Horizontal and vertical grid step, grid color.
int GridX, GridY;
QColor GridColor;

// Variables View* are the coordinates of top-level and bottom-right corners
// of a rectangle representing the schematic "model". This
Expand Down
1 change: 1 addition & 0 deletions qucs/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void settingsManager::initDefaults()
m_Defaults["font"] = QApplication::font();
m_Defaults["appFont"] = QApplication::font();
m_Defaults["LargeFontSize"] = static_cast<double>(16.0);
m_Defaults["GridColor"] = QColor(qRgb(25, 25, 25));
m_Defaults["maxUndo"] = 20;
m_Defaults["QucsHomeDir"] = QDir::homePath() + QDir::toNativeSeparators("/QucsWorkspace");

Expand Down

0 comments on commit ae7765b

Please sign in to comment.