-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMmlMtdNode.cpp
152 lines (122 loc) · 3.79 KB
/
MmlMtdNode.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#ifndef MMLMTDNODE_CPP
#define MMLMTDNODE_CPP
#include "MmlMtdNode.h"
int MmlMtdNode::scriptlevel( const MmlNode *child ) const
{
int sl = MmlNode::scriptlevel();
if ( child != 0 && child == firstChild() )
return sl + m_scriptlevel_adjust;
else
return sl;
}
void MmlMtdNode::setMyRect( const QRectF &rect )
{
MmlNode::setMyRect( rect );
MmlNode *child = firstChild();
if ( child == 0 )
return;
if ( rect.width() < child->myRect().width() )
{
while ( rect.width() < child->myRect().width()
&& child->font().pointSize() > g_min_font_point_size )
{
qWarning() << "MmlMtdNode::setMyRect(): rect.width()=" << rect.width()
<< ", child->myRect().width=" << child->myRect().width()
<< " sl=" << m_scriptlevel_adjust;
++m_scriptlevel_adjust;
child->layout();
}
qWarning() << "MmlMtdNode::setMyRect(): rect.width()=" << rect.width()
<< ", child->myRect().width=" << child->myRect().width()
<< " sl=" << m_scriptlevel_adjust;
}
QRectF mr = myRect();
QRectF cmr = child->myRect();
QPointF child_rel_origin;
switch ( columnalign() )
{
case ColAlignLeft:
child_rel_origin.setX( 0.0 );
break;
case ColAlignCenter:
child_rel_origin.setX( mr.left() + 0.5 * ( mr.width() - cmr.width() ) );
break;
case ColAlignRight:
child_rel_origin.setX( mr.right() - cmr.width() );
break;
}
switch ( rowalign() )
{
case RowAlignTop:
child_rel_origin.setY( mr.top() - cmr.top() );
break;
case RowAlignCenter:
case RowAlignBaseline:
child_rel_origin.setY( mr.top() - cmr.top() + 0.5 * ( mr.height() - cmr.height() ) );
break;
case RowAlignBottom:
child_rel_origin.setY( mr.bottom() - cmr.bottom() );
break;
case RowAlignAxis:
child_rel_origin.setY( 0.0 );
break;
}
child->setRelOrigin( child_rel_origin );
}
int MmlMtdNode::colNum() const
{
MmlNode *syb = previousSibling();
int i = 0;
for ( ; syb != 0; syb = syb->previousSibling() )
++i;
return i;
}
int MmlMtdNode::rowNum() const
{
MmlNode *row = parent()->previousSibling();
int i = 0;
for ( ; row != 0; row = row->previousSibling() )
++i;
return i;
}
MmlMtdNode::ColAlign MmlMtdNode::columnalign()
{
QString val = explicitAttribute( "columnalign" );
if ( !val.isNull() )
return Helpers::mmlInterpretColAlign( val, 0, 0 );
MmlNode *node = parent(); // <mtr>
if ( node == 0 )
return ColAlignCenter;
int colnum = colNum();
val = node->explicitAttribute( "columnalign" );
if ( !val.isNull() )
return Helpers::mmlInterpretColAlign( val, colnum, 0 );
node = node->parent(); // <mtable>
if ( node == 0 )
return ColAlignCenter;
val = node->explicitAttribute( "columnalign" );
if ( !val.isNull() )
return Helpers::mmlInterpretColAlign( val, colnum, 0 );
return ColAlignCenter;
}
MmlMtdNode::RowAlign MmlMtdNode::rowalign()
{
QString val = explicitAttribute( "rowalign" );
if ( !val.isNull() )
return Helpers::mmlInterpretRowAlign( val, 0, 0 );
MmlNode *node = parent(); // <mtr>
if ( node == 0 )
return RowAlignAxis;
int rownum = rowNum();
val = node->explicitAttribute( "rowalign" );
if ( !val.isNull() )
return Helpers::mmlInterpretRowAlign( val, rownum, 0 );
node = node->parent(); // <mtable>
if ( node == 0 )
return RowAlignAxis;
val = node->explicitAttribute( "rowalign" );
if ( !val.isNull() )
return Helpers::mmlInterpretRowAlign( val, rownum, 0 );
return RowAlignAxis;
}
#endif//MMLMTDNODE_CPP