diff --git a/OMEdit/OMEdit/OMEditGUI/Options/OptionsDialog.cpp b/OMEdit/OMEdit/OMEditGUI/Options/OptionsDialog.cpp index 1a41a23a984..eb646fab12f 100644 --- a/OMEdit/OMEdit/OMEditGUI/Options/OptionsDialog.cpp +++ b/OMEdit/OMEdit/OMEditGUI/Options/OptionsDialog.cpp @@ -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 @@ -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 @@ -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")); @@ -4337,6 +4367,7 @@ PlottingPage::PlottingPage(OptionsDialog *pOptionsDialog) mpFilterIntervalSpinBox->setSuffix(tr(" seconds")); mpFilterIntervalSpinBox->setRange(0, std::numeric_limits::max()); mpFilterIntervalSpinBox->setValue(2); + mpFilterIntervalSpinBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); // variable filter layout QGridLayout *pVariableFilterGridLayout = new QGridLayout; pVariableFilterGridLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft); @@ -4344,6 +4375,66 @@ PlottingPage::PlottingPage(OptionsDialog *pOptionsDialog) 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::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::max()); + mpVerticalAxisTitleFontSizeSpinBox->setValue(11); + mpVerticalAxisTitleFontSizeSpinBox->setSingleStep(1); + mpVerticalAxisNumbersFontSizeLabel = new Label("Vertical Axis Numbers:"); + mpVerticalAxisNumbersFontSizeSpinBox = new DoubleSpinBox; + mpVerticalAxisNumbersFontSizeSpinBox->setRange(6, std::numeric_limits::max()); + mpVerticalAxisNumbersFontSizeSpinBox->setValue(10); + mpVerticalAxisNumbersFontSizeSpinBox->setSingleStep(1); + mpHorizontalAxisTitleFontSizeLabel = new Label("Horizontal Axis Title:"); + mpHorizontalAxisTitleFontSizeSpinBox = new DoubleSpinBox; + mpHorizontalAxisTitleFontSizeSpinBox->setRange(6, std::numeric_limits::max()); + mpHorizontalAxisTitleFontSizeSpinBox->setValue(11); + mpHorizontalAxisTitleFontSizeSpinBox->setSingleStep(1); + mpHorizontalAxisNumbersFontSizeLabel = new Label("Horizontal Axis Numbers:"); + mpHorizontalAxisNumbersFontSizeSpinBox = new DoubleSpinBox; + mpHorizontalAxisNumbersFontSizeSpinBox->setRange(6, std::numeric_limits::max()); + mpHorizontalAxisNumbersFontSizeSpinBox->setValue(10); + mpHorizontalAxisNumbersFontSizeSpinBox->setSingleStep(1); + mpFooterFontSizeLabel = new Label("Footer:"); + mpFooterFontSizeSpinBox = new DoubleSpinBox; + mpFooterFontSizeSpinBox->setRange(6, std::numeric_limits::max()); + mpFooterFontSizeSpinBox->setValue(QApplication::font().pointSizeF()); + mpFooterFontSizeSpinBox->setSingleStep(1); + mpLegendFontSizeLabel = new Label("Legend:"); + mpLegendFontSizeSpinBox = new DoubleSpinBox; + mpLegendFontSizeSpinBox->setRange(6, std::numeric_limits::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); @@ -4352,6 +4443,7 @@ PlottingPage::PlottingPage(OptionsDialog *pOptionsDialog) pMainLayout->addWidget(mpPlottingViewModeGroupBox); pMainLayout->addWidget(mpCurveStyleGroupBox); pMainLayout->addWidget(mpVariableFilterGroupBox); + pMainLayout->addWidget(mpFontSizeGroupBox); setLayout(pMainLayout); } diff --git a/OMEdit/OMEdit/OMEditGUI/Options/OptionsDialog.h b/OMEdit/OMEdit/OMEditGUI/Options/OptionsDialog.h index 7b5ea92c47a..0004150070a 100644 --- a/OMEdit/OMEdit/OMEditGUI/Options/OptionsDialog.h +++ b/OMEdit/OMEdit/OMEditGUI/Options/OptionsDialog.h @@ -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; @@ -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 diff --git a/OMEdit/OMEdit/OMEditGUI/Plotting/PlotWindowContainer.cpp b/OMEdit/OMEdit/OMEditGUI/Plotting/PlotWindowContainer.cpp index 95667b38557..122224e75e9 100644 --- a/OMEdit/OMEdit/OMEditGUI/Plotting/PlotWindowContainer.cpp +++ b/OMEdit/OMEdit/OMEditGUI/Plotting/PlotWindowContainer.cpp @@ -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(); @@ -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(); @@ -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(); @@ -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")); @@ -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(); diff --git a/OMPlot/OMPlot/OMPlotGUI/Legend.cpp b/OMPlot/OMPlot/OMPlotGUI/Legend.cpp index 9a9d7b48854..321e2d3d547 100644 --- a/OMPlot/OMPlot/OMPlotGUI/Legend.cpp +++ b/OMPlot/OMPlot/OMPlotGUI/Legend.cpp @@ -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; } diff --git a/OMPlot/OMPlot/OMPlotGUI/OMPlot.h b/OMPlot/OMPlot/OMPlotGUI/OMPlot.h index 85b23bd493d..23d1dd3b780 100644 --- a/OMPlot/OMPlot/OMPlotGUI/OMPlot.h +++ b/OMPlot/OMPlot/OMPlotGUI/OMPlot.h @@ -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(); }; diff --git a/OMPlot/OMPlot/OMPlotGUI/Plot.cpp b/OMPlot/OMPlot/OMPlotGUI/Plot.cpp index 17df42c3eac..a6e098ba47d 100644 --- a/OMPlot/OMPlot/OMPlotGUI/Plot.cpp +++ b/OMPlot/OMPlot/OMPlotGUI/Plot.cpp @@ -39,6 +39,7 @@ #if QWT_VERSION < 0x060000 #include "qwt_legend_item.h" #endif +#include "qwt_text_label.h" using namespace OMPlot; @@ -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() { diff --git a/OMPlot/OMPlot/OMPlotGUI/PlotWindow.cpp b/OMPlot/OMPlot/OMPlotGUI/PlotWindow.cpp index 30ffc3ae4f5..147257167a0 100644 --- a/OMPlot/OMPlot/OMPlotGUI/PlotWindow.cpp +++ b/OMPlot/OMPlot/OMPlotGUI/PlotWindow.cpp @@ -39,6 +39,8 @@ #include "qwt_plot_renderer.h" #endif #include "qwt_scale_draw.h" +#include "qwt_scale_widget.h" +#include "qwt_text_label.h" using namespace OMPlot; @@ -108,6 +110,7 @@ void PlotWindow::initializePlot(QStringList arguments) setYRange(QString(arguments[11]).toDouble(), QString(arguments[12]).toDouble()); setCurveWidth(QString(arguments[13]).toDouble()); setCurveStyle(QString(arguments[14]).toInt()); + setLegendFont(QApplication::font()); setLegendPosition(QString(arguments[15])); setFooter(QString(arguments[16])); if (QString(arguments[17]) == "true") { @@ -1503,6 +1506,16 @@ int PlotWindow::getCurveStyle() return mCurveStyle; } +void PlotWindow::setLegendFont(QFont font) +{ + mLegendFont = font; +} + +QFont PlotWindow::getLegendFont() +{ + return mLegendFont; +} + void PlotWindow::setLegendPosition(QString position) { if (position.toLower().compare("left") == 0) @@ -1523,7 +1536,7 @@ void PlotWindow::setLegendPosition(QString position) mpPlot->setLegend(new Legend(mpPlot)); mpPlot->insertLegend(mpPlot->getLegend(), QwtPlot::TopLegend); #if QWT_VERSION > 0x060000 - /* we also want to align the legend to left. Stupid Qwt align it HCenter by default. */ + /* we also want to align the legend to left. Qwt align it HCenter by default. */ QwtLegend *pQwtLegend = qobject_cast(mpPlot->legend()); pQwtLegend->contentsWidget()->layout()->setAlignment(Qt::AlignTop | Qt::AlignLeft); mpPlot->updateLegend(); @@ -1535,7 +1548,7 @@ void PlotWindow::setLegendPosition(QString position) mpPlot->setLegend(new Legend(mpPlot)); mpPlot->insertLegend(mpPlot->getLegend(), QwtPlot::BottomLegend); #if QWT_VERSION > 0x060000 - /* we also want to align the legend to left. Stupid Qwt align it HCenter by default. */ + /* we also want to align the legend to left. Qwt align it HCenter by default. */ QwtLegend *pQwtLegend = qobject_cast(mpPlot->legend()); pQwtLegend->contentsWidget()->layout()->setAlignment(Qt::AlignBottom | Qt::AlignLeft); mpPlot->updateLegend(); @@ -1967,24 +1980,66 @@ SetupDialog::SetupDialog(PlotWindow *pPlotWindow) mpTitlesTab = new QWidget; mpPlotTitleLabel = new QLabel(tr("Plot Title")); mpPlotTitleTextBox = new QLineEdit(mpPlotWindow->getPlot()->title().text()); + mpTitleFontSizeLabel = new QLabel("Title Font Size"); + mpTitleFontSizeSpinBox = new QDoubleSpinBox; + mpTitleFontSizeSpinBox->setRange(6, std::numeric_limits::max()); + mpTitleFontSizeSpinBox->setValue(mpPlotWindow->getPlot()->titleLabel()->font().pointSizeF()); + mpTitleFontSizeSpinBox->setSingleStep(1); mpVerticalAxisLabel = new QLabel(tr("Vertical Axis Title")); mpVerticalAxisTextBox = new QLineEdit(mpPlotWindow->getPlot()->axisTitle(QwtPlot::yLeft).text()); + mpVerticalAxisTitleFontSizeLabel = new QLabel("Vertical Axis Title Font Size"); + mpVerticalAxisTitleFontSizeSpinBox = new QDoubleSpinBox; + mpVerticalAxisTitleFontSizeSpinBox->setRange(6, std::numeric_limits::max()); + mpVerticalAxisTitleFontSizeSpinBox->setValue(mpPlotWindow->getPlot()->axisWidget(QwtPlot::yLeft)->title().font().pointSizeF()); + mpVerticalAxisTitleFontSizeSpinBox->setSingleStep(1); + mpVerticalAxisNumbersFontSizeLabel = new QLabel("Vertical Axis Numbers Font Size"); + mpVerticalAxisNumbersFontSizeSpinBox = new QDoubleSpinBox; + mpVerticalAxisNumbersFontSizeSpinBox->setRange(6, std::numeric_limits::max()); + mpVerticalAxisNumbersFontSizeSpinBox->setValue(mpPlotWindow->getPlot()->axisWidget(QwtPlot::yLeft)->font().pointSizeF()); + mpVerticalAxisNumbersFontSizeSpinBox->setSingleStep(1); mpHorizontalAxisLabel = new QLabel(tr("Horizontal Axis Title")); mpHorizontalAxisTextBox = new QLineEdit(mpPlotWindow->getPlot()->axisTitle(QwtPlot::xBottom).text()); + mpHorizontalAxisTitleFontSizeLabel = new QLabel("Horizontal Axis Title Font Size"); + mpHorizontalAxisTitleFontSizeSpinBox = new QDoubleSpinBox; + mpHorizontalAxisTitleFontSizeSpinBox->setRange(6, std::numeric_limits::max()); + mpHorizontalAxisTitleFontSizeSpinBox->setValue(mpPlotWindow->getPlot()->axisWidget(QwtPlot::xBottom)->title().font().pointSizeF()); + mpHorizontalAxisTitleFontSizeSpinBox->setSingleStep(1); + mpHorizontalAxisNumbersFontSizeLabel = new QLabel("Horizontal Axis Numbers Font Size"); + mpHorizontalAxisNumbersFontSizeSpinBox = new QDoubleSpinBox; + mpHorizontalAxisNumbersFontSizeSpinBox->setRange(6, std::numeric_limits::max()); + mpHorizontalAxisNumbersFontSizeSpinBox->setValue(mpPlotWindow->getPlot()->axisWidget(QwtPlot::xBottom)->font().pointSizeF()); + mpHorizontalAxisNumbersFontSizeSpinBox->setSingleStep(1); mpPlotFooterLabel = new QLabel(tr("Plot Footer")); mpPlotFooterTextBox = new QLineEdit(mpPlotWindow->getFooter()); + mpFooterFontSizeLabel = new QLabel("Footer Font Size"); + mpFooterFontSizeSpinBox = new QDoubleSpinBox; + mpFooterFontSizeSpinBox->setRange(6, std::numeric_limits::max()); + mpFooterFontSizeSpinBox->setValue(mpPlotWindow->getPlot()->footerLabel()->font().pointSizeF()); + mpFooterFontSizeSpinBox->setSingleStep(1); // title tab layout QGridLayout *pTitlesTabGridLayout = new QGridLayout; pTitlesTabGridLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft); pTitlesTabGridLayout->addWidget(mpPlotTitleLabel, 0, 0); pTitlesTabGridLayout->addWidget(mpPlotTitleTextBox, 0, 1); - pTitlesTabGridLayout->addWidget(mpVerticalAxisLabel, 1, 0); - pTitlesTabGridLayout->addWidget(mpVerticalAxisTextBox, 1, 1); - pTitlesTabGridLayout->addWidget(mpHorizontalAxisLabel, 2, 0); - pTitlesTabGridLayout->addWidget(mpHorizontalAxisTextBox, 2, 1); + pTitlesTabGridLayout->addWidget(mpTitleFontSizeLabel, 1, 0); + pTitlesTabGridLayout->addWidget(mpTitleFontSizeSpinBox, 1, 1); + pTitlesTabGridLayout->addWidget(mpVerticalAxisLabel, 2, 0); + pTitlesTabGridLayout->addWidget(mpVerticalAxisTextBox, 2, 1); + pTitlesTabGridLayout->addWidget(mpVerticalAxisTitleFontSizeLabel, 3, 0); + pTitlesTabGridLayout->addWidget(mpVerticalAxisTitleFontSizeSpinBox, 3, 1); + pTitlesTabGridLayout->addWidget(mpVerticalAxisNumbersFontSizeLabel, 4, 0); + pTitlesTabGridLayout->addWidget(mpVerticalAxisNumbersFontSizeSpinBox, 4, 1); + pTitlesTabGridLayout->addWidget(mpHorizontalAxisLabel, 5, 0); + pTitlesTabGridLayout->addWidget(mpHorizontalAxisTextBox, 5, 1); + pTitlesTabGridLayout->addWidget(mpHorizontalAxisTitleFontSizeLabel, 6, 0); + pTitlesTabGridLayout->addWidget(mpHorizontalAxisTitleFontSizeSpinBox, 6, 1); + pTitlesTabGridLayout->addWidget(mpHorizontalAxisNumbersFontSizeLabel, 7, 0); + pTitlesTabGridLayout->addWidget(mpHorizontalAxisNumbersFontSizeSpinBox, 7, 1); #if QWT_VERSION > 0x060000 - pTitlesTabGridLayout->addWidget(mpPlotFooterLabel, 3, 0); - pTitlesTabGridLayout->addWidget(mpPlotFooterTextBox, 3, 1); + pTitlesTabGridLayout->addWidget(mpPlotFooterLabel, 8, 0); + pTitlesTabGridLayout->addWidget(mpPlotFooterTextBox, 8, 1); + pTitlesTabGridLayout->addWidget(mpFooterFontSizeLabel, 9, 0); + pTitlesTabGridLayout->addWidget(mpFooterFontSizeSpinBox, 9, 1); #endif mpTitlesTab->setLayout(pTitlesTabGridLayout); // legend tab @@ -1995,11 +2050,18 @@ SetupDialog::SetupDialog(PlotWindow *pPlotWindow) mpLegendPositionComboBox->addItem(tr("Right"), "right"); mpLegendPositionComboBox->addItem(tr("Bottom"), "bottom"); mpLegendPositionComboBox->addItem(tr("Left"), "left"); + mpLegendFontSizeLabel = new QLabel(tr("Legend Font Size")); + mpLegendFontSizeSpinBox = new QDoubleSpinBox; + mpLegendFontSizeSpinBox->setRange(6, std::numeric_limits::max()); + mpLegendFontSizeSpinBox->setValue(mpPlotWindow->getLegendFont().pointSizeF()); + mpLegendFontSizeSpinBox->setSingleStep(1); // legend tab layout QGridLayout *pLegendTabGridLayout = new QGridLayout; pLegendTabGridLayout->setAlignment(Qt::AlignTop); pLegendTabGridLayout->addWidget(mpLegendPositionLabel, 0, 0); pLegendTabGridLayout->addWidget(mpLegendPositionComboBox, 0, 1); + pLegendTabGridLayout->addWidget(mpLegendFontSizeLabel, 1, 0); + pLegendTabGridLayout->addWidget(mpLegendFontSizeSpinBox, 1, 1); mpLegendTab->setLayout(pLegendTabGridLayout); // range tab mpRangeTab = new QWidget; @@ -2157,6 +2219,9 @@ void SetupDialog::applySetup() for (int i = 0 ; i < mpVariablePagesStackedWidget->count() ; i++) { setupPlotCurve(qobject_cast(mpVariablePagesStackedWidget->widget(i))); } + // set the font sizes. Don't move this line. We should set the font sizes before calling setLegendPosition + mpPlotWindow->getPlot()->setFontSizes(mpTitleFontSizeSpinBox->value(), mpVerticalAxisTitleFontSizeSpinBox->value(), mpVerticalAxisNumbersFontSizeSpinBox->value(), + mpHorizontalAxisTitleFontSizeSpinBox->value(), mpHorizontalAxisNumbersFontSizeSpinBox->value(), mpFooterFontSizeSpinBox->value(), mpLegendFontSizeSpinBox->value()); // set the titles mpPlotWindow->getPlot()->setTitle(mpPlotTitleTextBox->text()); mpPlotWindow->getPlot()->setAxisTitle(QwtPlot::yLeft, mpVerticalAxisTextBox->text()); diff --git a/OMPlot/OMPlot/OMPlotGUI/PlotWindow.h b/OMPlot/OMPlot/OMPlotGUI/PlotWindow.h index 7aeaf2a5e79..613f895fcd5 100644 --- a/OMPlot/OMPlot/OMPlotGUI/PlotWindow.h +++ b/OMPlot/OMPlot/OMPlotGUI/PlotWindow.h @@ -88,6 +88,7 @@ class PlotWindow : public QMainWindow QString mYRangeMax; double mCurveWidth; int mCurveStyle; + QFont mLegendFont; double mTime; bool mIsInteractiveSimulation; QString mInteractiveTreeItemOwner; @@ -148,6 +149,8 @@ class PlotWindow : public QMainWindow double getCurveWidth(); void setCurveStyle(int style); int getCurveStyle(); + void setLegendFont(QFont font); + QFont getLegendFont(); void setLegendPosition(QString position); QString getLegendPosition(); void setFooter(QString footer); @@ -252,16 +255,30 @@ class SetupDialog : public QDialog QWidget *mpTitlesTab; QLabel *mpPlotTitleLabel; QLineEdit *mpPlotTitleTextBox; + QLabel *mpTitleFontSizeLabel; + QDoubleSpinBox *mpTitleFontSizeSpinBox; QLabel *mpVerticalAxisLabel; QLineEdit *mpVerticalAxisTextBox; + QLabel *mpVerticalAxisTitleFontSizeLabel; + QDoubleSpinBox *mpVerticalAxisTitleFontSizeSpinBox; + QLabel *mpVerticalAxisNumbersFontSizeLabel; + QDoubleSpinBox *mpVerticalAxisNumbersFontSizeSpinBox; QLabel *mpHorizontalAxisLabel; QLineEdit *mpHorizontalAxisTextBox; + QLabel *mpHorizontalAxisTitleFontSizeLabel; + QDoubleSpinBox *mpHorizontalAxisTitleFontSizeSpinBox; + QLabel *mpHorizontalAxisNumbersFontSizeLabel; + QDoubleSpinBox *mpHorizontalAxisNumbersFontSizeSpinBox; QLabel *mpPlotFooterLabel; QLineEdit *mpPlotFooterTextBox; + QLabel *mpFooterFontSizeLabel; + QDoubleSpinBox *mpFooterFontSizeSpinBox; /* legend tab */ QWidget *mpLegendTab; QLabel *mpLegendPositionLabel; QComboBox *mpLegendPositionComboBox; + QLabel *mpLegendFontSizeLabel; + QDoubleSpinBox *mpLegendFontSizeSpinBox; /* range tab */ QWidget *mpRangeTab; QCheckBox *mpAutoScaleCheckbox;