BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
FontScalingEvent.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/PlotUtil/FontScalingEvent.cpp
6 //! @brief Implements class FontScalingEvent
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
16 #include "Base/Util/Assert.h"
18 #include <QResizeEvent>
19 #include <qcustomplot.h>
20 
21 namespace {
22 
23 const QString tick_font = "tick-font-key";
24 const int widget_size_to_switch_font = 500;
25 
26 } // namespace
27 
29  : QObject(parent)
30  , m_plot(plot)
31 {
32 }
33 
34 bool FontScalingEvent::eventFilter(QObject* obj, QEvent* event)
35 {
36  if (event->type() == QEvent::Resize) {
37  auto* resizeEvent = dynamic_cast<QResizeEvent*>(event);
38  ASSERT(resizeEvent);
39 
40  if (!m_fonts.contains(tick_font))
41  backupFonts();
42  else {
43  if (resizeEvent->size().width() < widget_size_to_switch_font)
44  scaleFonts(0.8);
45  else
46  restoreFonts();
47  }
48  }
49 
50  return QObject::eventFilter(obj, event);
51 }
52 
53 //! Backup all fonts.
54 
56 {
57  m_fonts[tick_font] = m_plot->customPlot()->xAxis->tickLabelFont();
58 }
59 
61 {
62  QFont ff = m_fonts[tick_font];
63  setTickLabelFont(ff);
64 }
65 
66 void FontScalingEvent::scaleFonts(double factor)
67 {
68  QFont ff = m_fonts[tick_font];
69  ff.setPointSizeF(ff.pointSizeF() * factor);
70  setTickLabelFont(ff);
71 }
72 
73 void FontScalingEvent::setTickLabelFont(const QFont& font)
74 {
75  m_plot->customPlot()->xAxis->setTickLabelFont(font);
76  m_plot->customPlot()->yAxis->setTickLabelFont(font);
78  return;
79 
80  auto* color_map = dynamic_cast<ColorMap*>(m_plot);
81  color_map->colorScale()->axis()->setTickLabelFont(font);
82 }
Defines class ColorMap.
Defines class FontScalingEvent.
The ColorMap class presents 2D intensity data from IntensityDataItem as color map.
Definition: ColorMap.h:36
QCPColorScale * colorScale()
Definition: ColorMap.h:47
ScientificPlot * m_plot
bool eventFilter(QObject *obj, QEvent *event) override
void setTickLabelFont(const QFont &font)
void scaleFonts(double factor)
FontScalingEvent(ScientificPlot *plot, QWidget *parent)
QMap< QString, QFont > m_fonts
void backupFonts()
Backup all fonts.
Common interface for plot-descriptor interaction.
PLOT_TYPE plotType() const
Returns the type of current plot.
virtual QCustomPlot * customPlot()=0