diff --git a/GUI/View/Canvas/ColorMapCanvas.cpp b/GUI/View/Canvas/ColorMapCanvas.cpp index 4a8f0f965ebaa288c6f10c3580ab378d09476bb3..1275ad8fed50b3969c8ff994f2f492041ed88b28 100644 --- a/GUI/View/Canvas/ColorMapCanvas.cpp +++ b/GUI/View/Canvas/ColorMapCanvas.cpp @@ -14,18 +14,14 @@ #include "GUI/View/Canvas/ColorMapCanvas.h" #include "GUI/Model/Data/Data2DItem.h" -#include "GUI/View/PlotScale/FontScalingEvent.h" #include "GUI/View/Plotter/ColorMap.h" #include "GUI/View/Plotter/PlotStatusLabel.h" #include <QVBoxLayout> ColorMapCanvas::ColorMapCanvas() : m_color_map(new ColorMap) - , m_canvas_event(new FontScalingEvent(m_color_map, this)) , m_status_label(new PlotStatusLabel(m_color_map)) { - QObject::installEventFilter(m_canvas_event); - auto* layout = new QVBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); diff --git a/GUI/View/Canvas/ColorMapCanvas.h b/GUI/View/Canvas/ColorMapCanvas.h index 8010a39cbcddd0ec70ce7d5e6e8e8c3f563a85c0..edd9dee79aa742847ecd07ee97789c755bf054f9 100644 --- a/GUI/View/Canvas/ColorMapCanvas.h +++ b/GUI/View/Canvas/ColorMapCanvas.h @@ -19,7 +19,6 @@ class ColorMap; class Data2DItem; -class FontScalingEvent; class PlotStatusLabel; class QCustomPlot; @@ -39,7 +38,6 @@ public: private: ColorMap* m_color_map; - FontScalingEvent* m_canvas_event; PlotStatusLabel* m_status_label; }; diff --git a/GUI/View/Canvas/SpecularPlotCanvas.cpp b/GUI/View/Canvas/SpecularPlotCanvas.cpp index 0f9641f3b0b97175aa389bc5c2267ae1549a1edb..11d8b3fddade7c1f92c8362964c6211fbe82ce0b 100644 --- a/GUI/View/Canvas/SpecularPlotCanvas.cpp +++ b/GUI/View/Canvas/SpecularPlotCanvas.cpp @@ -14,17 +14,13 @@ #include "GUI/View/Canvas/SpecularPlotCanvas.h" #include "GUI/Model/Data/Data1DItem.h" -#include "GUI/View/PlotScale/FontScalingEvent.h" #include "GUI/View/Plotter/PlotStatusLabel.h" #include "GUI/View/Plotter/SpecularPlot.h" SpecularPlotCanvas::SpecularPlotCanvas() : m_plot(new SpecularPlot) - , m_canvas_event(new FontScalingEvent(m_plot, this)) , m_status_label(new PlotStatusLabel(m_plot)) { - this->installEventFilter(m_canvas_event); - auto* layout = new QVBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); @@ -39,6 +35,7 @@ void SpecularPlotCanvas::setData1DItems(const QList<Data1DItem*>& data_items) { m_plot->setData1DItems(data_items); } + QCustomPlot* SpecularPlotCanvas::customPlot() { return m_plot->customPlot(); diff --git a/GUI/View/Canvas/SpecularPlotCanvas.h b/GUI/View/Canvas/SpecularPlotCanvas.h index a112918fba38ba11b3195851424485206e435ca1..32f0185a1a42053fbe3f7bc6f5cf02ef3c4d7e33 100644 --- a/GUI/View/Canvas/SpecularPlotCanvas.h +++ b/GUI/View/Canvas/SpecularPlotCanvas.h @@ -18,7 +18,6 @@ #include <QWidget> class Data1DItem; -class FontScalingEvent; class PlotStatusLabel; class QCustomPlot; class SpecularPlot; @@ -39,7 +38,6 @@ public: private: SpecularPlot* m_plot; - FontScalingEvent* m_canvas_event; PlotStatusLabel* m_status_label; }; diff --git a/GUI/View/PlotScale/FontScalingEvent.cpp b/GUI/View/PlotScale/FontScalingEvent.cpp deleted file mode 100644 index bca0d5f1d066e516e4071f2d5e0ae0a183dd74af..0000000000000000000000000000000000000000 --- a/GUI/View/PlotScale/FontScalingEvent.cpp +++ /dev/null @@ -1,79 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file GUI/View/PlotScale/FontScalingEvent.cpp -//! @brief Implements class FontScalingEvent. -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2018 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************************************ - -#include "GUI/View/PlotScale/FontScalingEvent.h" -#include "Base/Util/Assert.h" -#include "GUI/View/Plotter/ColorMap.h" -#include <QResizeEvent> -#include <qcustomplot.h> - -namespace { - -const QString tick_font = "tick-font-key"; -const int widget_size_to_switch_font = 500; - -} // namespace - -FontScalingEvent::FontScalingEvent(ScientificPlot* plot, QWidget* parent) - : QObject(parent) - , m_plot(plot) -{ -} - -bool FontScalingEvent::eventFilter(QObject* obj, QEvent* event) -{ - if (event->type() == QEvent::Resize) { - auto* resizeEvent = dynamic_cast<QResizeEvent*>(event); - ASSERT(resizeEvent); - - if (!m_fonts.contains(tick_font)) - backupFonts(); - else { - if (resizeEvent->size().width() < widget_size_to_switch_font) - scaleFonts(0.8); - else - restoreFonts(); - } - } - - return QObject::eventFilter(obj, event); -} - -//! Backup all fonts. - -void FontScalingEvent::backupFonts() -{ - m_fonts[tick_font] = m_plot->customPlot()->xAxis->tickLabelFont(); -} - -void FontScalingEvent::restoreFonts() -{ - QFont ff = m_fonts[tick_font]; - setTickLabelFont(ff); -} - -void FontScalingEvent::scaleFonts(double factor) -{ - QFont ff = m_fonts[tick_font]; - ff.setPointSizeF(ff.pointSizeF() * factor); - setTickLabelFont(ff); -} - -void FontScalingEvent::setTickLabelFont(const QFont& font) -{ - m_plot->customPlot()->xAxis->setTickLabelFont(font); - m_plot->customPlot()->yAxis->setTickLabelFont(font); - if (auto* color_map = dynamic_cast<ColorMap*>(m_plot)) // 2D plots only - color_map->colorScale()->axis()->setTickLabelFont(font); -} diff --git a/GUI/View/PlotScale/FontScalingEvent.h b/GUI/View/PlotScale/FontScalingEvent.h deleted file mode 100644 index 1c41f49b2df9801cfe2e2c8dd52c83ada787752a..0000000000000000000000000000000000000000 --- a/GUI/View/PlotScale/FontScalingEvent.h +++ /dev/null @@ -1,45 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file GUI/View/PlotScale/FontScalingEvent.h -//! @brief Defines class FontScalingEvent. -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2018 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************************************ - -#ifndef BORNAGAIN_GUI_VIEW_PLOTSCALE_FONTSCALINGEVENT_H -#define BORNAGAIN_GUI_VIEW_PLOTSCALE_FONTSCALINGEVENT_H - -#include <QEvent> -#include <QFont> -#include <QMap> -#include <QObject> - -class ScientificPlot; - -//! Provides event filter for ScientificPlot. Its goal is to make font size adjustments -//! on resize events. - -class FontScalingEvent : public QObject { - Q_OBJECT -public: - explicit FontScalingEvent(ScientificPlot* plot, QWidget* parent); - -private: - bool eventFilter(QObject* obj, QEvent* event) override; - - void backupFonts(); - void restoreFonts(); - void scaleFonts(double factor); - void setTickLabelFont(const QFont& font); - - ScientificPlot* m_plot; - QMap<QString, QFont> m_fonts; -}; - -#endif // BORNAGAIN_GUI_VIEW_PLOTSCALE_FONTSCALINGEVENT_H