BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
FontScalingEvent Class Reference

Description

Provides event filter for ScientificPlot. Its goal is to make font size adjustments on resize events.

Definition at line 28 of file FontScalingEvent.h.

Inheritance diagram for FontScalingEvent:
[legend]
Collaboration diagram for FontScalingEvent:
[legend]

Public Member Functions

 FontScalingEvent (ScientificPlot *plot, QWidget *parent)
 

Protected Member Functions

bool eventFilter (QObject *obj, QEvent *event) override
 

Private Member Functions

void backupFonts ()
 Backup all fonts. More...
 
void restoreFonts ()
 
void scaleFonts (double factor)
 
void setTickLabelFont (const QFont &font)
 

Private Attributes

QMap< QString, QFont > m_fonts
 
ScientificPlotm_plot
 

Constructor & Destructor Documentation

◆ FontScalingEvent()

FontScalingEvent::FontScalingEvent ( ScientificPlot plot,
QWidget *  parent 
)
explicit

Definition at line 28 of file FontScalingEvent.cpp.

29  : QObject(parent)
30  , m_plot(plot)
31 {
32 }
ScientificPlot * m_plot

Member Function Documentation

◆ backupFonts()

void FontScalingEvent::backupFonts ( )
private

Backup all fonts.

Definition at line 55 of file FontScalingEvent.cpp.

56 {
57  m_fonts[tick_font] = m_plot->customPlot()->xAxis->tickLabelFont();
58 }
QMap< QString, QFont > m_fonts
virtual QCustomPlot * customPlot()=0

References ScientificPlot::customPlot(), m_fonts, and m_plot.

Referenced by eventFilter().

Here is the call graph for this function:

◆ eventFilter()

bool FontScalingEvent::eventFilter ( QObject *  obj,
QEvent *  event 
)
overrideprotected

Definition at line 34 of file FontScalingEvent.cpp.

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 }
void scaleFonts(double factor)
void backupFonts()
Backup all fonts.

References backupFonts(), m_fonts, restoreFonts(), and scaleFonts().

Here is the call graph for this function:

◆ restoreFonts()

void FontScalingEvent::restoreFonts ( )
private

Definition at line 60 of file FontScalingEvent.cpp.

61 {
62  QFont ff = m_fonts[tick_font];
63  setTickLabelFont(ff);
64 }
void setTickLabelFont(const QFont &font)

References m_fonts, and setTickLabelFont().

Referenced by eventFilter().

Here is the call graph for this function:

◆ scaleFonts()

void FontScalingEvent::scaleFonts ( double  factor)
private

Definition at line 66 of file FontScalingEvent.cpp.

67 {
68  QFont ff = m_fonts[tick_font];
69  ff.setPointSizeF(ff.pointSizeF() * factor);
70  setTickLabelFont(ff);
71 }

References m_fonts, and setTickLabelFont().

Referenced by eventFilter().

Here is the call graph for this function:

◆ setTickLabelFont()

void FontScalingEvent::setTickLabelFont ( const QFont &  font)
private

Definition at line 73 of file FontScalingEvent.cpp.

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 }
The ColorMap class presents 2D intensity data from IntensityDataItem as color map.
Definition: ColorMap.h:36
QCPColorScale * colorScale()
Definition: ColorMap.h:47
PLOT_TYPE plotType() const
Returns the type of current plot.

References ColorMap::colorScale(), ScientificPlot::customPlot(), m_plot, ScientificPlot::Plot2D, and ScientificPlot::plotType().

Referenced by restoreFonts(), and scaleFonts().

Here is the call graph for this function:

Member Data Documentation

◆ m_fonts

QMap<QString, QFont> FontScalingEvent::m_fonts
private

Definition at line 44 of file FontScalingEvent.h.

Referenced by backupFonts(), eventFilter(), restoreFonts(), and scaleFonts().

◆ m_plot

ScientificPlot* FontScalingEvent::m_plot
private

Definition at line 43 of file FontScalingEvent.h.

Referenced by backupFonts(), and setTickLabelFont().


The documentation for this class was generated from the following files: