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

Provides event filter for ScientificPlot. More...

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)
 

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
 

Detailed 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.

Constructor & Destructor Documentation

◆ FontScalingEvent()

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

Definition at line 26 of file FontScalingEvent.cpp.

27  : QObject(parent), m_plot(plot)
28 {
29 }
ScientificPlot * m_plot

Member Function Documentation

◆ backupFonts()

void FontScalingEvent::backupFonts ( )
private

Backup all fonts.

Definition at line 54 of file FontScalingEvent.cpp.

55 {
56  m_fonts[tick_font] = m_plot->customPlot()->xAxis->tickLabelFont();
57 }
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 
)
protected

Definition at line 31 of file FontScalingEvent.cpp.

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 }
#define ASSERT(condition)
Definition: Assert.h:31
void scaleFonts(double factor)
void backupFonts()
Backup all fonts.

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

Here is the call graph for this function:

◆ restoreFonts()

void FontScalingEvent::restoreFonts ( )
private

Definition at line 59 of file FontScalingEvent.cpp.

60 {
61  QFont ff = m_fonts[tick_font];
62  setTickLabelFont(ff);
63 }
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 65 of file FontScalingEvent.cpp.

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

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 72 of file FontScalingEvent.cpp.

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 }
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: