BornAgain  1.19.0
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/coregui/Views/IntensityDataWidgets/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/Utils/Assert.h"
18 #include <QResizeEvent>
19 #include <qcustomplot.h>
20 
21 namespace {
22 const QString tick_font = "tick-font-key";
23 const int widget_size_to_switch_font = 500;
24 } // namespace
25 
27  : QObject(parent), m_plot(plot)
28 {
29 }
30 
31 bool FontScalingEvent::eventFilter(QObject* obj, QEvent* event)
32 {
33  if (event->type() == QEvent::Resize) {
34  QResizeEvent* resizeEvent = static_cast<QResizeEvent*>(event);
35  ASSERT(resizeEvent);
36 
37  if (!m_fonts.contains(tick_font)) {
38  backupFonts();
39 
40  } else {
41  if (resizeEvent->size().width() < widget_size_to_switch_font) {
42  scaleFonts(0.8);
43  } else {
44  restoreFonts();
45  }
46  }
47  }
48 
49  return QObject::eventFilter(obj, event);
50 }
51 
52 //! Backup all fonts.
53 
55 {
56  m_fonts[tick_font] = m_plot->customPlot()->xAxis->tickLabelFont();
57 }
58 
60 {
61  QFont ff = m_fonts[tick_font];
62  setTickLabelFont(ff);
63 }
64 
65 void FontScalingEvent::scaleFonts(double factor)
66 {
67  QFont ff = m_fonts[tick_font];
68  ff.setPointSizeF(ff.pointSizeF() * factor);
69  setTickLabelFont(ff);
70 }
71 
72 void FontScalingEvent::setTickLabelFont(const QFont& font)
73 {
74  m_plot->customPlot()->xAxis->setTickLabelFont(font);
75  m_plot->customPlot()->yAxis->setTickLabelFont(font);
77  return;
78 
79  auto color_map = dynamic_cast<ColorMap*>(m_plot);
80  color_map->colorScale()->axis()->setTickLabelFont(font);
81 }
Defines the macro ASSERT.
#define ASSERT(condition)
Definition: Assert.h:31
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
void setTickLabelFont(const QFont &font)
void scaleFonts(double factor)
FontScalingEvent(ScientificPlot *plot, QWidget *parent)
QMap< QString, QFont > m_fonts
void backupFonts()
Backup all fonts.
bool eventFilter(QObject *obj, QEvent *event)
Common interface for plot-descriptor interaction.
PLOT_TYPE plotType() const
Returns the type of current plot.
virtual QCustomPlot * customPlot()=0