-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathformulaview.cpp
115 lines (96 loc) · 2.25 KB
/
formulaview.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "formulaview.h"
#include "qwt_mml_document.h"
#include <qdebug.h>
#include <qevent.h>
#include <qpainter.h>
FormulaView::FormulaView( QWidget *parent ):
QWidget( parent ),
d_fontSize( 8 ),
d_transformation( true ),
d_scale( false ),
d_rotation( 0 )
{
}
QString FormulaView::formula() const
{
return d_formula;
}
void FormulaView::setFormula( const QString &formula )
{
d_formula = formula;
update();
}
void FormulaView::setFontSize( const qreal &fontSize )
{
d_fontSize = fontSize;
update();
}
void FormulaView::setTransformation( const bool &transformation )
{
d_transformation = transformation;
update();
}
void FormulaView::setScale( const bool &scale )
{
d_scale = scale;
update();
}
void FormulaView::setRotation( const qreal &rotation )
{
d_rotation = rotation;
update();
}
void FormulaView::setDrawFrames( const bool &drawFrames )
{
d_drawFrames = drawFrames;
update();
}
void FormulaView::setColors( const bool &colors )
{
d_colors = colors;
update();
}
void FormulaView::paintEvent( QPaintEvent *event )
{
QPainter painter( this );
painter.setClipRegion( event->region() );
painter.fillRect( event->rect(), Qt::white );
renderFormula( &painter );
}
void FormulaView::renderFormula( QPainter *painter ) const
{
QwtMathMLDocument doc;
doc.setContent( d_formula );
if ( d_colors )
{
doc.setBackgroundColor( Qt::darkCyan );
doc.setForegroundColor( Qt::yellow );
}
else
{
doc.setBackgroundColor( Qt::white );
doc.setForegroundColor( Qt::black );
}
doc.setBaseFontPointSize( d_fontSize );
#ifdef MML_TEST
doc.setDrawFrames( d_drawFrames );
#endif
QRectF docRect;
docRect.setSize( doc.size() );
docRect.moveCenter( rect().center() );
if ( d_transformation )
{
const double scaleF = d_scale ? 2.0 : 1.0;
painter->save();
painter->translate( docRect.center() );
painter->rotate( d_rotation );
painter->scale( scaleF, scaleF );
painter->translate( docRect.topLeft() - docRect.center() );
doc.paint( painter, QPointF( 0.0, 0.0 ) );
painter->restore();
}
else
{
doc.paint( painter, docRect.topLeft() );
}
}