1 #include "MainBackgroundPainter.h"
2 
3 #include "BackgroundConfig.h"
4 #include "BaseBackgroundPainter.h"
5 #include "DottedBackgroundPainter.h"
6 #include "GraphBackgroundPainter.h"
7 #include "IsometricBackgroundPainter.h"
8 #include "LineBackgroundPainter.h"
9 #include "StavesBackgroundPainter.h"
10 
MainBackgroundPainter()11 MainBackgroundPainter::MainBackgroundPainter() {
12     defaultPainter = new BaseBackgroundPainter();
13 
14     painter[PageTypeFormat::Ruled] = new LineBackgroundPainter(false);
15     painter[PageTypeFormat::Lined] = new LineBackgroundPainter(true);
16     painter[PageTypeFormat::Staves] = new StavesBackgroundPainter();
17     painter[PageTypeFormat::Graph] = new GraphBackgroundPainter();
18     painter[PageTypeFormat::Dotted] = new DottedBackgroundPainter();
19     painter[PageTypeFormat::IsoDotted] = new IsometricBackgroundPainter(false);
20     painter[PageTypeFormat::IsoGraph] = new IsometricBackgroundPainter(true);
21 }
22 
~MainBackgroundPainter()23 MainBackgroundPainter::~MainBackgroundPainter() {
24     for (auto& e: painter) {
25         delete e.second;
26     }
27     painter.clear();
28 
29     delete defaultPainter;
30     defaultPainter = nullptr;
31 }
32 
33 /**
34  * Set a factor to draw the lines bolder, for previews
35  */
setLineWidthFactor(double factor)36 void MainBackgroundPainter::setLineWidthFactor(double factor) {
37     for (auto& e: painter) {
38         e.second->setLineWidthFactor(factor);
39     }
40 }
41 
paint(PageType pt,cairo_t * cr,PageRef page)42 void MainBackgroundPainter::paint(PageType pt, cairo_t* cr, PageRef page) {
43     auto it = this->painter.find(pt.format);
44 
45     BaseBackgroundPainter* painter = defaultPainter;
46     if (it != this->painter.end()) {
47         painter = it->second;
48     }
49 
50     BackgroundConfig config(pt.config);
51 
52     painter->resetConfig();
53     painter->paint(cr, page, &config);
54 }
55