Skip to content

Commit

Permalink
Allow to change font sizes in plot windows
Browse files Browse the repository at this point in the history
The user can also set default font sizes for new plot windows via settings.
Use the plot setup window to update the font sizes of the existing plot windows.
  • Loading branch information
adeas31 committed Aug 21, 2019
1 parent 0fab348 commit fa0a161
Show file tree
Hide file tree
Showing 8 changed files with 269 additions and 13 deletions.
100 changes: 96 additions & 4 deletions OMEdit/OMEdit/OMEditGUI/Options/OptionsDialog.cpp
Expand Up @@ -777,6 +777,27 @@ void OptionsDialog::readPlottingSettings()
if (mpSettings->contains("variableFilter/interval")) {
mpPlottingPage->getFilterIntervalSpinBox()->setValue(mpSettings->value("variableFilter/interval").toInt());
}
if (mpSettings->contains("plotting/titleFontSize")) {
mpPlottingPage->getTitleFontSizeSpinBox()->setValue(mpSettings->value("plotting/titleFontSize").toDouble());
}
if (mpSettings->contains("plotting/verticalAxisTitleFontSize")) {
mpPlottingPage->getVerticalAxisTitleFontSizeSpinBox()->setValue(mpSettings->value("plotting/verticalAxisTitleFontSize").toDouble());
}
if (mpSettings->contains("plotting/verticalAxisNumbersFontSize")) {
mpPlottingPage->getVerticalAxisNumbersFontSizeSpinBox()->setValue(mpSettings->value("plotting/verticalAxisNumbersFontSize").toDouble());
}
if (mpSettings->contains("plotting/horizontalAxisTitleFontSize")) {
mpPlottingPage->getHorizontalAxisTitleFontSizeSpinBox()->setValue(mpSettings->value("plotting/horizontalAxisTitleFontSize").toDouble());
}
if (mpSettings->contains("plotting/horizontalAxisNumbersFontSize")) {
mpPlottingPage->getHorizontalAxisNumbersFontSizeSpinBox()->setValue(mpSettings->value("plotting/horizontalAxisNumbersFontSize").toDouble());
}
if (mpSettings->contains("plotting/footerFontSize")) {
mpPlottingPage->getFooterFontSizeSpinBox()->setValue(mpSettings->value("plotting/footerFontSize").toDouble());
}
if (mpSettings->contains("plotting/legendFontSize")) {
mpPlottingPage->getLegendFontSizeSpinBox()->setValue(mpSettings->value("plotting/legendFontSize").toDouble());
}
}

//! Reads the Fiagro section settings from omedit.ini
Expand Down Expand Up @@ -1348,6 +1369,14 @@ void OptionsDialog::savePlottingSettings()
// save variable filter interval
mpSettings->setValue("variableFilter/interval", mpPlottingPage->getFilterIntervalSpinBox()->value());
MainWindow::instance()->getVariablesWidget()->getTreeSearchFilters()->getFilterTimer()->setInterval(mpPlottingPage->getFilterIntervalSpinBox()->value() * 1000);
// save plot font sizes
mpSettings->setValue("plotting/titleFontSize", mpPlottingPage->getTitleFontSizeSpinBox()->value());
mpSettings->setValue("plotting/verticalAxisTitleFontSize", mpPlottingPage->getVerticalAxisTitleFontSizeSpinBox()->value());
mpSettings->setValue("plotting/verticalAxisNumbersFontSize", mpPlottingPage->getVerticalAxisNumbersFontSizeSpinBox()->value());
mpSettings->setValue("plotting/horizontalAxisTitleFontSize", mpPlottingPage->getHorizontalAxisTitleFontSizeSpinBox()->value());
mpSettings->setValue("plotting/horizontalAxisNumbersFontSize", mpPlottingPage->getHorizontalAxisNumbersFontSizeSpinBox()->value());
mpSettings->setValue("plotting/footerFontSize", mpPlottingPage->getFooterFontSizeSpinBox()->value());
mpSettings->setValue("plotting/legendFontSize", mpPlottingPage->getLegendFontSizeSpinBox()->value());
}

//! Saves the Figaro section settings to omedit.ini
Expand Down Expand Up @@ -4323,10 +4352,11 @@ PlottingPage::PlottingPage(OptionsDialog *pOptionsDialog)
// set the layout
QGridLayout *pCurveStyleLayout = new QGridLayout;
pCurveStyleLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
pCurveStyleLayout->addWidget(mpCurvePatternLabel, 0, 0);
pCurveStyleLayout->addWidget(mpCurvePatternComboBox, 0, 1);
pCurveStyleLayout->addWidget(mpCurveThicknessLabel, 1, 0);
pCurveStyleLayout->addWidget(mpCurveThicknessSpinBox, 1, 1);
pCurveStyleLayout->addWidget(new Label(tr("Curve styles are used for new curves. Use plot setup window to update the existing curves.")), 0, 0, 1, 2);
pCurveStyleLayout->addWidget(mpCurvePatternLabel, 1, 0);
pCurveStyleLayout->addWidget(mpCurvePatternComboBox, 1, 1);
pCurveStyleLayout->addWidget(mpCurveThicknessLabel, 2, 0);
pCurveStyleLayout->addWidget(mpCurveThicknessSpinBox, 2, 1);
mpCurveStyleGroupBox->setLayout(pCurveStyleLayout);
// variable filter interval
mpVariableFilterGroupBox = new QGroupBox(tr("Variable Filter"));
Expand All @@ -4337,13 +4367,74 @@ PlottingPage::PlottingPage(OptionsDialog *pOptionsDialog)
mpFilterIntervalSpinBox->setSuffix(tr(" seconds"));
mpFilterIntervalSpinBox->setRange(0, std::numeric_limits<int>::max());
mpFilterIntervalSpinBox->setValue(2);
mpFilterIntervalSpinBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
// variable filter layout
QGridLayout *pVariableFilterGridLayout = new QGridLayout;
pVariableFilterGridLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
pVariableFilterGridLayout->addWidget(mpFilterIntervalHelpLabel, 0, 0, 1, 2);
pVariableFilterGridLayout->addWidget(mpFilterIntervalLabel, 1, 0);
pVariableFilterGridLayout->addWidget(mpFilterIntervalSpinBox, 1, 1);
mpVariableFilterGroupBox->setLayout(pVariableFilterGridLayout);
// font size
mpFontSizeGroupBox = new QGroupBox(tr("Font Size"));
mpTitleFontSizeLabel = new Label("Title:");
mpTitleFontSizeSpinBox = new DoubleSpinBox;
mpTitleFontSizeSpinBox->setRange(6, std::numeric_limits<double>::max());
mpTitleFontSizeSpinBox->setValue(14);
mpTitleFontSizeSpinBox->setSingleStep(1);
mpTitleFontSizeSpinBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
mpVerticalAxisTitleFontSizeLabel = new Label("Vertical Axis Title:");
mpVerticalAxisTitleFontSizeSpinBox = new DoubleSpinBox;
mpVerticalAxisTitleFontSizeSpinBox->setRange(6, std::numeric_limits<double>::max());
mpVerticalAxisTitleFontSizeSpinBox->setValue(11);
mpVerticalAxisTitleFontSizeSpinBox->setSingleStep(1);
mpVerticalAxisNumbersFontSizeLabel = new Label("Vertical Axis Numbers:");
mpVerticalAxisNumbersFontSizeSpinBox = new DoubleSpinBox;
mpVerticalAxisNumbersFontSizeSpinBox->setRange(6, std::numeric_limits<double>::max());
mpVerticalAxisNumbersFontSizeSpinBox->setValue(10);
mpVerticalAxisNumbersFontSizeSpinBox->setSingleStep(1);
mpHorizontalAxisTitleFontSizeLabel = new Label("Horizontal Axis Title:");
mpHorizontalAxisTitleFontSizeSpinBox = new DoubleSpinBox;
mpHorizontalAxisTitleFontSizeSpinBox->setRange(6, std::numeric_limits<double>::max());
mpHorizontalAxisTitleFontSizeSpinBox->setValue(11);
mpHorizontalAxisTitleFontSizeSpinBox->setSingleStep(1);
mpHorizontalAxisNumbersFontSizeLabel = new Label("Horizontal Axis Numbers:");
mpHorizontalAxisNumbersFontSizeSpinBox = new DoubleSpinBox;
mpHorizontalAxisNumbersFontSizeSpinBox->setRange(6, std::numeric_limits<double>::max());
mpHorizontalAxisNumbersFontSizeSpinBox->setValue(10);
mpHorizontalAxisNumbersFontSizeSpinBox->setSingleStep(1);
mpFooterFontSizeLabel = new Label("Footer:");
mpFooterFontSizeSpinBox = new DoubleSpinBox;
mpFooterFontSizeSpinBox->setRange(6, std::numeric_limits<double>::max());
mpFooterFontSizeSpinBox->setValue(QApplication::font().pointSizeF());
mpFooterFontSizeSpinBox->setSingleStep(1);
mpLegendFontSizeLabel = new Label("Legend:");
mpLegendFontSizeSpinBox = new DoubleSpinBox;
mpLegendFontSizeSpinBox->setRange(6, std::numeric_limits<double>::max());
mpLegendFontSizeSpinBox->setValue(QApplication::font().pointSizeF());
mpLegendFontSizeSpinBox->setSingleStep(1);
// font size layout
QGridLayout *pFontSizeGridLayout = new QGridLayout;
pFontSizeGridLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
pFontSizeGridLayout->addWidget(new Label(tr("Font sizes are used for new plot windows. Use plot setup window to update the existing plots.")), 0, 0, 1, 2);
pFontSizeGridLayout->addWidget(mpTitleFontSizeLabel, 1, 0);
pFontSizeGridLayout->addWidget(mpTitleFontSizeSpinBox, 1, 1);
pFontSizeGridLayout->addWidget(mpVerticalAxisTitleFontSizeLabel, 2, 0);
pFontSizeGridLayout->addWidget(mpVerticalAxisTitleFontSizeSpinBox, 2, 1);
pFontSizeGridLayout->addWidget(mpVerticalAxisNumbersFontSizeLabel, 3, 0);
pFontSizeGridLayout->addWidget(mpVerticalAxisNumbersFontSizeSpinBox, 3, 1);
pFontSizeGridLayout->addWidget(mpHorizontalAxisTitleFontSizeLabel, 4, 0);
pFontSizeGridLayout->addWidget(mpHorizontalAxisTitleFontSizeSpinBox, 4, 1);
pFontSizeGridLayout->addWidget(mpHorizontalAxisNumbersFontSizeLabel, 5, 0);
pFontSizeGridLayout->addWidget(mpHorizontalAxisNumbersFontSizeSpinBox, 5, 1);
int index = 6;
#if QWT_VERSION > 0x060000
pFontSizeGridLayout->addWidget(mpFooterFontSizeLabel, index, 0);
pFontSizeGridLayout->addWidget(mpFooterFontSizeSpinBox, index++, 1);
#endif
pFontSizeGridLayout->addWidget(mpLegendFontSizeLabel, index, 0);
pFontSizeGridLayout->addWidget(mpLegendFontSizeSpinBox, index, 1);
mpFontSizeGroupBox->setLayout(pFontSizeGridLayout);
// main layout
QVBoxLayout *pMainLayout = new QVBoxLayout;
pMainLayout->setAlignment(Qt::AlignTop);
Expand All @@ -4352,6 +4443,7 @@ PlottingPage::PlottingPage(OptionsDialog *pOptionsDialog)
pMainLayout->addWidget(mpPlottingViewModeGroupBox);
pMainLayout->addWidget(mpCurveStyleGroupBox);
pMainLayout->addWidget(mpVariableFilterGroupBox);
pMainLayout->addWidget(mpFontSizeGroupBox);
setLayout(pMainLayout);
}

Expand Down
23 changes: 22 additions & 1 deletion OMEdit/OMEdit/OMEditGUI/Options/OptionsDialog.h
Expand Up @@ -817,6 +817,13 @@ class PlottingPage : public QWidget
void setCurveThickness(qreal thickness);
qreal getCurveThickness();
QSpinBox* getFilterIntervalSpinBox() {return mpFilterIntervalSpinBox;}
DoubleSpinBox *getTitleFontSizeSpinBox() const {return mpTitleFontSizeSpinBox;}
DoubleSpinBox *getVerticalAxisTitleFontSizeSpinBox() const {return mpVerticalAxisTitleFontSizeSpinBox;}
DoubleSpinBox *getVerticalAxisNumbersFontSizeSpinBox() const {return mpVerticalAxisNumbersFontSizeSpinBox;}
DoubleSpinBox *getHorizontalAxisTitleFontSizeSpinBox() const {return mpHorizontalAxisTitleFontSizeSpinBox;}
DoubleSpinBox *getHorizontalAxisNumbersFontSizeSpinBox() const {return mpHorizontalAxisNumbersFontSizeSpinBox;}
DoubleSpinBox *getFooterFontSizeSpinBox() const {return mpFooterFontSizeSpinBox;}
DoubleSpinBox *getLegendFontSizeSpinBox() const {return mpLegendFontSizeSpinBox;}
private:
OptionsDialog *mpOptionsDialog;
QGroupBox *mpGeneralGroupBox;
Expand All @@ -833,7 +840,21 @@ class PlottingPage : public QWidget
Label *mpFilterIntervalHelpLabel;
Label *mpFilterIntervalLabel;
QSpinBox *mpFilterIntervalSpinBox;

QGroupBox *mpFontSizeGroupBox;
Label *mpTitleFontSizeLabel;
DoubleSpinBox *mpTitleFontSizeSpinBox;
Label *mpVerticalAxisTitleFontSizeLabel;
DoubleSpinBox *mpVerticalAxisTitleFontSizeSpinBox;
Label *mpVerticalAxisNumbersFontSizeLabel;
DoubleSpinBox *mpVerticalAxisNumbersFontSizeSpinBox;
Label *mpHorizontalAxisTitleFontSizeLabel;
DoubleSpinBox *mpHorizontalAxisTitleFontSizeSpinBox;
Label *mpHorizontalAxisNumbersFontSizeLabel;
DoubleSpinBox *mpHorizontalAxisNumbersFontSizeSpinBox;
Label *mpFooterFontSizeLabel;
DoubleSpinBox *mpFooterFontSizeSpinBox;
Label *mpLegendFontSizeLabel;
DoubleSpinBox *mpLegendFontSizeSpinBox;
};

class FigaroPage : public QWidget
Expand Down
20 changes: 20 additions & 0 deletions OMEdit/OMEdit/OMEditGUI/Plotting/PlotWindowContainer.cpp
Expand Up @@ -276,6 +276,10 @@ void PlotWindowContainer::addPlotWindow(bool maximized)
pPlotWindow->setXLabel(QString("time (%1)").arg(pPlotWindow->getTimeUnit()));
pPlotWindow->installEventFilter(this);
QMdiSubWindow *pSubWindow = addSubWindow(pPlotWindow);
PlottingPage *pPlottingPage = OptionsDialog::instance()->getPlottingPage();
pPlotWindow->getPlot()->setFontSizes(pPlottingPage->getTitleFontSizeSpinBox()->value(), pPlottingPage->getVerticalAxisTitleFontSizeSpinBox()->value(), pPlottingPage->getVerticalAxisNumbersFontSizeSpinBox()->value(),
pPlottingPage->getHorizontalAxisTitleFontSizeSpinBox()->value(), pPlottingPage->getHorizontalAxisNumbersFontSizeSpinBox()->value(), pPlottingPage->getFooterFontSizeSpinBox()->value(),
pPlottingPage->getLegendFontSizeSpinBox()->value());
addCloseActionsToSubWindowSystemMenu(pSubWindow);
pSubWindow->setWindowIcon(QIcon(":/Resources/icons/plot-window.svg"));
pPlotWindow->show();
Expand Down Expand Up @@ -304,6 +308,10 @@ void PlotWindowContainer::addParametricPlotWindow()
pPlotWindow->setTimeUnit(MainWindow::instance()->getVariablesWidget()->getSimulationTimeComboBox()->currentText());
pPlotWindow->installEventFilter(this);
QMdiSubWindow *pSubWindow = addSubWindow(pPlotWindow);
PlottingPage *pPlottingPage = OptionsDialog::instance()->getPlottingPage();
pPlotWindow->getPlot()->setFontSizes(pPlottingPage->getTitleFontSizeSpinBox()->value(), pPlottingPage->getVerticalAxisTitleFontSizeSpinBox()->value(), pPlottingPage->getVerticalAxisNumbersFontSizeSpinBox()->value(),
pPlottingPage->getHorizontalAxisTitleFontSizeSpinBox()->value(), pPlottingPage->getHorizontalAxisNumbersFontSizeSpinBox()->value(), pPlottingPage->getFooterFontSizeSpinBox()->value(),
pPlottingPage->getLegendFontSizeSpinBox()->value());
addCloseActionsToSubWindowSystemMenu(pSubWindow);
pSubWindow->setWindowIcon(QIcon(":/Resources/icons/parametric-plot-window.svg"));
pPlotWindow->show();
Expand Down Expand Up @@ -338,6 +346,10 @@ void PlotWindowContainer::addArrayPlotWindow(bool maximized)
pPlotWindow->setXLabel(QString("index"));
pPlotWindow->installEventFilter(this);
QMdiSubWindow *pSubWindow = addSubWindow(pPlotWindow);
PlottingPage *pPlottingPage = OptionsDialog::instance()->getPlottingPage();
pPlotWindow->getPlot()->setFontSizes(pPlottingPage->getTitleFontSizeSpinBox()->value(), pPlottingPage->getVerticalAxisTitleFontSizeSpinBox()->value(), pPlottingPage->getVerticalAxisNumbersFontSizeSpinBox()->value(),
pPlottingPage->getHorizontalAxisTitleFontSizeSpinBox()->value(), pPlottingPage->getHorizontalAxisNumbersFontSizeSpinBox()->value(), pPlottingPage->getFooterFontSizeSpinBox()->value(),
pPlottingPage->getLegendFontSizeSpinBox()->value());
addCloseActionsToSubWindowSystemMenu(pSubWindow);
pSubWindow->setWindowIcon(QIcon(":/Resources/icons/array-plot-window.svg"));
pPlotWindow->show();
Expand Down Expand Up @@ -369,6 +381,10 @@ PlotWindow* PlotWindowContainer::addInteractivePlotWindow(bool maximized, QStrin
pPlotWindow->setXLabel(QString("time (%1)").arg(pPlotWindow->getTimeUnit()));
pPlotWindow->installEventFilter(this);
QMdiSubWindow *pSubWindow = addSubWindow(pPlotWindow);
PlottingPage *pPlottingPage = OptionsDialog::instance()->getPlottingPage();
pPlotWindow->getPlot()->setFontSizes(pPlottingPage->getTitleFontSizeSpinBox()->value(), pPlottingPage->getVerticalAxisTitleFontSizeSpinBox()->value(), pPlottingPage->getVerticalAxisNumbersFontSizeSpinBox()->value(),
pPlottingPage->getHorizontalAxisTitleFontSizeSpinBox()->value(), pPlottingPage->getHorizontalAxisNumbersFontSizeSpinBox()->value(), pPlottingPage->getFooterFontSizeSpinBox()->value(),
pPlottingPage->getLegendFontSizeSpinBox()->value());
pPlotWindow->setSubWindow(pSubWindow);
addCloseActionsToSubWindowSystemMenu(pSubWindow);
pSubWindow->setWindowIcon(QIcon(":/Resources/icons/interaction.svg"));
Expand Down Expand Up @@ -407,6 +423,10 @@ void PlotWindowContainer::addArrayParametricPlotWindow()
pPlotWindow->setTimeUnit(unitComboBox->currentText());
pPlotWindow->installEventFilter(this);
QMdiSubWindow *pSubWindow = addSubWindow(pPlotWindow);
PlottingPage *pPlottingPage = OptionsDialog::instance()->getPlottingPage();
pPlotWindow->getPlot()->setFontSizes(pPlottingPage->getTitleFontSizeSpinBox()->value(), pPlottingPage->getVerticalAxisTitleFontSizeSpinBox()->value(), pPlottingPage->getVerticalAxisNumbersFontSizeSpinBox()->value(),
pPlottingPage->getHorizontalAxisTitleFontSizeSpinBox()->value(), pPlottingPage->getHorizontalAxisNumbersFontSizeSpinBox()->value(), pPlottingPage->getFooterFontSizeSpinBox()->value(),
pPlottingPage->getLegendFontSizeSpinBox()->value());
addCloseActionsToSubWindowSystemMenu(pSubWindow);
pSubWindow->setWindowIcon(QIcon(":/Resources/icons/array-parametric-plot-window.svg"));
pPlotWindow->show();
Expand Down
1 change: 1 addition & 0 deletions OMPlot/OMPlot/OMPlotGUI/Legend.cpp
Expand Up @@ -124,6 +124,7 @@ void Legend::legendMenu(const QPoint& pos)
QWidget* Legend::createWidget(const QwtLegendData &data) const
{
QWidget *pWidget = QwtLegend::createWidget(data);
pWidget->setFont(mpPlot->getParentPlotWindow()->getLegendFont());
pWidget->setMouseTracking(true);
return pWidget;
}
Expand Down
2 changes: 2 additions & 0 deletions OMPlot/OMPlot/OMPlotGUI/OMPlot.h
Expand Up @@ -81,6 +81,8 @@ class Plot : public QwtPlot
void addPlotCurve(PlotCurve *pCurve);
void removeCurve(PlotCurve *pCurve);
QColor getUniqueColor(int index, int total);
void setFontSizes(double titleFontSize, double verticalAxisTitleFontSize, double verticalAxisNumbersFontSize, double horizontalAxisTitleFontSize,
double horizontalAxisNumbersFontSize, double footerFontSize, double legendFontSize);
public slots:
virtual void replot();
};
Expand Down
38 changes: 38 additions & 0 deletions OMPlot/OMPlot/OMPlotGUI/Plot.cpp
Expand Up @@ -39,6 +39,7 @@
#if QWT_VERSION < 0x060000
#include "qwt_legend_item.h"
#endif
#include "qwt_text_label.h"

using namespace OMPlot;

Expand Down Expand Up @@ -181,6 +182,43 @@ QColor Plot::getUniqueColor(int index, int total)
return mColorsList.at(index);
}

void Plot::setFontSizes(double titleFontSize, double verticalAxisTitleFontSize, double verticalAxisNumbersFontSize, double horizontalAxisTitleFontSize,
double horizontalAxisNumbersFontSize, double footerFontSize, double legendFontSize)
{
// title
QFont font = titleLabel()->font();
font.setPointSizeF(titleFontSize);
titleLabel()->setFont(font);
// vertical axis title
QwtText verticalTitle = axisWidget(QwtPlot::yLeft)->title();
font = verticalTitle.font();
font.setPointSizeF(verticalAxisTitleFontSize);
verticalTitle.setFont(font);
axisWidget(QwtPlot::yLeft)->setTitle(verticalTitle);
// vertical axis numbers
font = axisWidget(QwtPlot::yLeft)->font();
font.setPointSizeF(verticalAxisNumbersFontSize);
axisWidget(QwtPlot::yLeft)->setFont(font);
// horizontal axis title
QwtText horizontalTitle = axisWidget(QwtPlot::xBottom)->title();
font = horizontalTitle.font();
font.setPointSizeF(horizontalAxisTitleFontSize);
horizontalTitle.setFont(font);
axisWidget(QwtPlot::xBottom)->setTitle(horizontalTitle);
// horizontal axis numbers
font = axisWidget(QwtPlot::xBottom)->font();
font.setPointSizeF(horizontalAxisNumbersFontSize);
axisWidget(QwtPlot::xBottom)->setFont(font);
// footer
font = footerLabel()->font();
font.setPointSizeF(footerFontSize);
footerLabel()->setFont(font);
// legend
font = mpParentPlotWindow->getLegendFont();
font.setPointSizeF(legendFontSize);
mpParentPlotWindow->setLegendFont(font);
}

// just overloaded this function to get colors for curves.
void Plot::replot()
{
Expand Down

0 comments on commit fa0a161

Please sign in to comment.