Scroom  0.14
MeasureHandler Class Reference

#include <measure.hh>

Inheritance diagram for MeasureHandler:
Inheritance graph
Collaboration diagram for MeasureHandler:
Collaboration graph

Public Types

using Ptr = boost::shared_ptr< MeasureHandler >
 
- Public Types inherited from ToolStateListener
using Ptr = boost::shared_ptr< ToolStateListener >
 
- Public Types inherited from PostRenderer
using Ptr = boost::shared_ptr< PostRenderer >
 
- Public Types inherited from SelectionListener
using Ptr = boost::shared_ptr< SelectionListener >
 

Public Member Functions

void render (ViewInterface::Ptr const &vi, cairo_t *cr, Scroom::Utils::Rectangle< double > presentationArea, int zoom) override
 
void onSelectionStart (Selection p, ViewInterface::Ptr view) override
 
void onSelectionUpdate (Selection s, ViewInterface::Ptr view) override
 
void onSelectionEnd (Selection s, ViewInterface::Ptr view) override
 
void onEnable () override
 
void onDisable () override
 
- Public Member Functions inherited from PostRenderer
virtual void render (boost::shared_ptr< ViewInterface > const &vi, cairo_t *cr, Scroom::Utils::Rectangle< double > presentationArea, int zoom)=0
 
- Public Member Functions inherited from SelectionListener
virtual std::string getSelectionType ()
 
virtual void onSelectionStart (Selection selection, boost::shared_ptr< ViewInterface > view)=0
 
virtual void onSelectionUpdate (Selection selection, boost::shared_ptr< ViewInterface > view)=0
 
virtual void onSelectionEnd (Selection selection, boost::shared_ptr< ViewInterface > view)=0
 
- Public Member Functions inherited from Scroom::Utils::Base
 Base ()=default
 
 Base (const Base &)=delete
 
 Base (Base &&)=delete
 
Baseoperator= (const Base &)=delete
 
Baseoperator= (Base &&)=delete
 
virtual ~Base ()=default
 
template<typename R >
boost::shared_ptr< R > shared_from_this ()
 
template<typename R >
boost::shared_ptr< R const > shared_from_this () const
 

Static Public Member Functions

static Ptr create ()
 

Private Member Functions

virtual void displayMeasurement (const ViewInterface::Ptr &view)
 
virtual void drawCross (cairo_t *cr, Scroom::Utils::Point< double > p)
 

Private Attributes

std::optional< Selectionselection
 
bool enabled {false}
 

Member Typedef Documentation

◆ Ptr

using MeasureHandler::Ptr = boost::shared_ptr<MeasureHandler>

Member Function Documentation

◆ create()

MeasureHandler::Ptr MeasureHandler::create ( )
static
61 { return Ptr(new MeasureHandler()); }

Referenced by Measure::viewAdded().

Here is the caller graph for this function:

◆ displayMeasurement()

void MeasureHandler::displayMeasurement ( const ViewInterface::Ptr view)
privatevirtual
64 {
65  const auto aspectRatio = view->getCurrentPresentation()->getAspectRatio();
66  const Selection tweaked(selection->start / aspectRatio, selection->end / aspectRatio);
67 
68  view->setStatusMessage(fmt::format("l: {:.1f}, dx: {}, dy: {}, from: {}, to: {}",
69  tweaked.length(),
70  tweaked.width(),
71  tweaked.height(),
72  tweaked.start,
73  tweaked.end));
74 }

Referenced by onSelectionEnd(), and onSelectionUpdate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ drawCross()

void MeasureHandler::drawCross ( cairo_t *  cr,
Scroom::Utils::Point< double >  p 
)
privatevirtual
77 {
78  static const int size = 10;
79  cairo_move_to(cr, p.x - size, p.y);
80  cairo_line_to(cr, p.x + size, p.y);
81  cairo_move_to(cr, p.x, p.y - size);
82  cairo_line_to(cr, p.x, p.y + size);
83 }

Referenced by render().

Here is the caller graph for this function:

◆ onDisable()

void MeasureHandler::onDisable ( )
overridevirtual

Then function is called whenever the tool button is deselected.

Implements ToolStateListener.

141 {
142  selection.reset();
143  enabled = false;
144 }

◆ onEnable()

void MeasureHandler::onEnable ( )
overridevirtual

This function is called whenever the tool button is selected.

Implements ToolStateListener.

146 { enabled = true; }

◆ onSelectionEnd()

void MeasureHandler::onSelectionEnd ( Selection  s,
ViewInterface::Ptr  view 
)
override
101 {
102  if(enabled)
103  {
104  selection = s;
105  displayMeasurement(view);
106  }
107 }
Here is the call graph for this function:

◆ onSelectionStart()

void MeasureHandler::onSelectionStart ( Selection  p,
ViewInterface::Ptr  view 
)
override
89 {}

◆ onSelectionUpdate()

void MeasureHandler::onSelectionUpdate ( Selection  s,
ViewInterface::Ptr  view 
)
override
92 {
93  if(enabled)
94  {
95  selection = s;
96  displayMeasurement(view);
97  }
98 }
Here is the call graph for this function:

◆ render()

void MeasureHandler::render ( ViewInterface::Ptr const &  vi,
cairo_t *  cr,
Scroom::Utils::Rectangle< double >  presentationArea,
int  zoom 
)
override
117 {
118  if(selection)
119  {
120  const auto pixelSize = pixelSizeFromZoom(zoom);
121  const auto start = (selection->start - presentationArea.getTopLeft()) * pixelSize;
122  const auto end = (selection->end - presentationArea.getTopLeft()) * pixelSize;
123 
124  cairo_set_line_width(cr, 1);
125  cairo_set_source_rgb(cr, 0.75, 0, 0); // Dark Red
126  drawCross(cr, start);
127  drawCross(cr, end);
128  cairo_stroke(cr);
129  cairo_set_source_rgb(cr, 1, 0, 0); // Red
130  cairo_move_to(cr, start.x, start.y);
131  cairo_line_to(cr, end.x, end.y);
132  cairo_stroke(cr);
133  }
134 }
Here is the call graph for this function:

Member Data Documentation

◆ enabled

bool MeasureHandler::enabled {false}
private

◆ selection

std::optional<Selection> MeasureHandler::selection
private

The documentation for this class was generated from the following files:
Scroom::Utils::Rectangle::getTopLeft
xy_type getTopLeft() const
Definition: rectangle.hh:133
MeasureHandler::displayMeasurement
virtual void displayMeasurement(const ViewInterface::Ptr &view)
Definition: measure.cc:63
MeasureHandler::drawCross
virtual void drawCross(cairo_t *cr, Scroom::Utils::Point< double > p)
Definition: measure.cc:76
MeasureHandler::Ptr
boost::shared_ptr< MeasureHandler > Ptr
Definition: measure.hh:24
Selection
Definition: viewinterface.hh:38
Scroom::Utils::Point::x
value_type x
Definition: point.hh:111
MeasureHandler
Definition: measure.hh:17
pixelSizeFromZoom
double pixelSizeFromZoom(int zoom)
Definition: cairo-helpers.cc:112
MeasureHandler::enabled
bool enabled
Definition: measure.hh:28
MeasureHandler::selection
std::optional< Selection > selection
Definition: measure.hh:27
Scroom::Utils::Point::y
value_type y
Definition: point.hh:112