bug2868fix.diff
src/app/composer/qgscomposerlabelwidget.cpp (copie de travail) | ||
---|---|---|
34 | 34 |
{ |
35 | 35 |
mTextEdit->setText( mComposerLabel->text() ); |
36 | 36 |
mMarginDoubleSpinBox->setValue( mComposerLabel->margin() ); |
37 |
mTopRadioButton->setChecked( mComposerLabel->vAlign() == Qt::AlignTop ? true : false); |
|
38 |
mMiddleRadioButton->setChecked( mComposerLabel->vAlign() == Qt::AlignVCenter ? true : false); |
|
39 |
mBottomRadioButton->setChecked( mComposerLabel->vAlign() == Qt::AlignBottom ? true : false); |
|
40 |
mLeftRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignLeft ? true : false); |
|
41 |
mCenterRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignHCenter ? true : false); |
|
42 |
mRightRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignRight ? true : false); |
|
37 | 43 |
} |
38 | 44 |
} |
39 | 45 | |
... | ... | |
88 | 94 |
mComposerLabel->setFontColor( newColor ); |
89 | 95 |
} |
90 | 96 | |
97 |
void QgsComposerLabelWidget::on_mCenterRadioButton_clicked() |
|
98 |
{ |
|
99 |
if ( mComposerLabel ) |
|
100 |
{ |
|
101 |
mComposerLabel->setHAlign( Qt::AlignHCenter ); |
|
102 |
mComposerLabel->update(); |
|
103 |
} |
|
104 |
} |
|
105 | ||
106 |
void QgsComposerLabelWidget::on_mRightRadioButton_clicked() |
|
107 |
{ |
|
108 |
if ( mComposerLabel ) |
|
109 |
{ |
|
110 |
mComposerLabel->setHAlign( Qt::AlignRight ); |
|
111 |
mComposerLabel->update(); |
|
112 |
} |
|
113 |
} |
|
114 | ||
115 |
void QgsComposerLabelWidget::on_mLeftRadioButton_clicked() |
|
116 |
{ |
|
117 |
if ( mComposerLabel ) |
|
118 |
{ |
|
119 |
mComposerLabel->setHAlign( Qt::AlignLeft ); |
|
120 |
mComposerLabel->update(); |
|
121 |
} |
|
122 |
} |
|
123 | ||
124 |
void QgsComposerLabelWidget::on_mTopRadioButton_clicked() |
|
125 |
{ |
|
126 |
if ( mComposerLabel ) |
|
127 |
{ |
|
128 |
mComposerLabel->setVAlign( Qt::AlignTop ); |
|
129 |
mComposerLabel->update(); |
|
130 |
} |
|
131 |
} |
|
132 | ||
133 |
void QgsComposerLabelWidget::on_mBottomRadioButton_clicked() |
|
134 |
{ |
|
135 |
if ( mComposerLabel ) |
|
136 |
{ |
|
137 |
mComposerLabel->setVAlign( Qt::AlignBottom ); |
|
138 |
mComposerLabel->update(); |
|
139 |
} |
|
140 |
} |
|
141 | ||
142 |
void QgsComposerLabelWidget::on_mMiddleRadioButton_clicked() |
|
143 |
{ |
|
144 |
if ( mComposerLabel ) |
|
145 |
{ |
|
146 |
mComposerLabel->setVAlign( Qt::AlignVCenter ); |
|
147 |
mComposerLabel->update(); |
|
148 |
} |
|
149 |
} |
src/app/composer/qgscomposerlabelwidget.h (copie de travail) | ||
---|---|---|
36 | 36 |
void on_mFontButton_clicked(); |
37 | 37 |
void on_mMarginDoubleSpinBox_valueChanged( double d ); |
38 | 38 |
void on_mFontColorButton_clicked(); |
39 |
void on_mCenterRadioButton_clicked(); |
|
40 |
void on_mLeftRadioButton_clicked(); |
|
41 |
void on_mRightRadioButton_clicked(); |
|
42 |
void on_mTopRadioButton_clicked(); |
|
43 |
void on_mBottomRadioButton_clicked(); |
|
44 |
void on_mMiddleRadioButton_clicked(); |
|
39 | 45 | |
40 | 46 |
private: |
41 | 47 |
QgsComposerLabel* mComposerLabel; |
src/core/composer/qgscomposerlabel.h (copie de travail) | ||
---|---|---|
43 | 43 | |
44 | 44 |
QFont font() const; |
45 | 45 |
void setFont( const QFont& f ); |
46 |
int vAlign() const; |
|
47 |
int hAlign() const; |
|
48 |
void setHAlign( int a ) {mHAlignment = a;} |
|
49 |
void setVAlign( int a ) {mVAlignment = a;} |
|
46 | 50 |
double margin() {return mMargin;} |
47 | 51 |
void setMargin( double m ) {mMargin = m;} |
48 | 52 | |
... | ... | |
68 | 72 |
// Text |
69 | 73 |
QString mText; |
70 | 74 | |
75 |
// Horizontal Alignment |
|
76 |
int mHAlignment; |
|
77 | ||
78 |
// Vertical Alignment |
|
79 |
int mVAlignment; |
|
80 |
|
|
71 | 81 |
// Font |
72 | 82 |
QFont mFont; |
73 | 83 |
src/core/composer/qgscomposeritem.h (copie de travail) | ||
---|---|---|
144 | 144 | |
145 | 145 |
/**Like the above, but with a rectangle for multiline text*/ |
146 | 146 |
void drawText( QPainter* p, const QRectF& rect, const QString& text, const QFont& font ) const; |
147 |
/** Alignment management */ |
|
148 |
void drawText( QPainter* p, const QRectF& rect, const QString& text, const QFont& font, const int halignement, const int valignement ) const; |
|
147 | 149 | |
148 | 150 |
/**Returns the font width in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE*/ |
149 | 151 |
double textWidthMillimeters( const QFont& font, const QString& text ) const; |
src/core/composer/qgscomposerlabel.cpp (copie de travail) | ||
---|---|---|
24 | 24 |
{ |
25 | 25 |
//default font size is 10 point |
26 | 26 |
mFont.setPointSizeF( 10 ); |
27 |
//default Horizontal Alignment is Left |
|
28 |
mHAlignment = Qt::AlignLeft; |
|
29 |
// default Vertical Alignment is Top |
|
30 |
mVAlignment = Qt::AlignTop; |
|
27 | 31 |
} |
28 | 32 | |
29 | 33 |
QgsComposerLabel::~QgsComposerLabel() |
... | ... | |
49 | 53 |
rect().height() - 2 * penWidth - 2 * mMargin ); |
50 | 54 | |
51 | 55 | |
52 |
drawText( painter, painterRect, displayText(), mFont ); |
|
56 |
drawText( painter, painterRect, displayText(), mFont, mHAlignment, mVAlignment );
|
|
53 | 57 | |
54 | 58 |
drawFrame( painter ); |
55 | 59 |
if ( isSelected() ) |
... | ... | |
110 | 114 |
return mFont; |
111 | 115 |
} |
112 | 116 | |
117 |
int QgsComposerLabel::vAlign() const |
|
118 |
{ |
|
119 |
return mVAlignment; |
|
120 |
} |
|
121 | ||
122 |
int QgsComposerLabel::hAlign() const |
|
123 |
{ |
|
124 |
return mHAlignment; |
|
125 |
} |
|
126 | ||
113 | 127 |
bool QgsComposerLabel::writeXML( QDomElement& elem, QDomDocument & doc ) const |
114 | 128 |
{ |
129 |
QString alignment; |
|
130 | ||
115 | 131 |
if ( elem.isNull() ) |
116 | 132 |
{ |
117 | 133 |
return false; |
... | ... | |
122 | 138 |
composerLabelElem.setAttribute( "labelText", mText ); |
123 | 139 |
composerLabelElem.setAttribute( "margin", QString::number( mMargin ) ); |
124 | 140 | |
141 |
// Horizontal alignment |
|
142 |
if ( mHAlignment == Qt::AlignHCenter ) |
|
143 |
alignment = "center"; |
|
144 |
else if ( mHAlignment == Qt::AlignLeft ) |
|
145 |
alignment = "left"; |
|
146 |
else if ( mHAlignment == Qt::AlignRight ) |
|
147 |
alignment = "right"; |
|
148 |
else |
|
149 |
alignment = "left"; |
|
150 |
composerLabelElem.setAttribute( "halign", alignment); |
|
125 | 151 | |
152 |
// Vertical alignment |
|
153 |
if ( mVAlignment == Qt::AlignVCenter ) |
|
154 |
alignment = "center"; |
|
155 |
else if ( mVAlignment == Qt::AlignTop ) |
|
156 |
alignment = "top"; |
|
157 |
else if ( mVAlignment == Qt::AlignBottom ) |
|
158 |
alignment = "bottom"; |
|
159 |
else |
|
160 |
alignment = "top"; |
|
161 |
composerLabelElem.setAttribute( "valign", alignment); |
|
162 | ||
163 | ||
126 | 164 |
//font |
127 | 165 |
QDomElement labelFontElem = doc.createElement( "LabelFont" ); |
128 | 166 |
labelFontElem.setAttribute( "description", mFont.toString() ); |
... | ... | |
141 | 179 | |
142 | 180 |
bool QgsComposerLabel::readXML( const QDomElement& itemElem, const QDomDocument& doc ) |
143 | 181 |
{ |
182 |
QString alignment; |
|
183 | ||
144 | 184 |
if ( itemElem.isNull() ) |
145 | 185 |
{ |
146 | 186 |
return false; |
... | ... | |
154 | 194 |
//margin |
155 | 195 |
mMargin = itemElem.attribute( "margin" ).toDouble(); |
156 | 196 | |
197 |
//Horizontal alignment |
|
198 |
alignment = itemElem.attribute( "halign" ); |
|
199 | ||
200 |
if (alignment.compare( "center", Qt::CaseInsensitive) == 0 ) |
|
201 |
mHAlignment = Qt::AlignHCenter; |
|
202 |
else if (alignment.compare( "left", Qt::CaseInsensitive) == 0 ) |
|
203 |
mHAlignment = Qt::AlignLeft; |
|
204 |
else if (alignment.compare( "right", Qt::CaseInsensitive) == 0 ) |
|
205 |
mHAlignment = Qt::AlignRight; |
|
206 |
else |
|
207 |
mHAlignment = Qt::AlignLeft; |
|
208 | ||
209 |
//Vertical alignment |
|
210 |
alignment = itemElem.attribute( "valign" ); |
|
211 | ||
212 |
if (alignment.compare( "top", Qt::CaseInsensitive) == 0 ) |
|
213 |
mVAlignment = Qt::AlignTop; |
|
214 |
else if (alignment.compare( "center", Qt::CaseInsensitive) == 0 ) |
|
215 |
mVAlignment = Qt::AlignVCenter; |
|
216 |
else if (alignment.compare( "bottom", Qt::CaseInsensitive) == 0 ) |
|
217 |
mVAlignment = Qt::AlignBottom; |
|
218 |
else |
|
219 |
mVAlignment = Qt::AlignTop; |
|
220 | ||
221 | ||
157 | 222 |
//font |
158 | 223 |
QDomNodeList labelFontList = itemElem.elementsByTagName( "LabelFont" ); |
159 | 224 |
if ( labelFontList.size() > 0 ) |
src/core/composer/qgscomposeritem.cpp (copie de travail) | ||
---|---|---|
721 | 721 |
p->restore(); |
722 | 722 |
} |
723 | 723 | |
724 |
void QgsComposerItem::drawText( QPainter* p, const QRectF& rect, const QString& text, const QFont& font, const int halignement, const int valignment ) const |
|
725 |
{ |
|
726 |
QFont textFont = scaledFontPixelSize( font ); |
|
727 | ||
728 |
QRectF scaledRect( rect.x() * FONT_WORKAROUND_SCALE, rect.y() * FONT_WORKAROUND_SCALE, |
|
729 |
rect.width() * FONT_WORKAROUND_SCALE, rect.height() * FONT_WORKAROUND_SCALE ); |
|
730 | ||
731 |
p->save(); |
|
732 |
p->setFont( textFont ); |
|
733 |
double scaleFactor = 1.0 / FONT_WORKAROUND_SCALE; |
|
734 |
p->scale( scaleFactor, scaleFactor ); |
|
735 |
p->drawText( scaledRect, halignement | valignment | Qt::TextWordWrap, text ); |
|
736 |
p->restore(); |
|
737 |
} |
|
724 | 738 |
void QgsComposerItem::drawArrowHead( QPainter* p, double x, double y, double angle, double arrowHeadWidth ) const |
725 | 739 |
{ |
726 | 740 |
if ( !p ) |
src/ui/qgscomposerlabelwidgetbase.ui (copie de travail) | ||
---|---|---|
6 | 6 |
<rect> |
7 | 7 |
<x>0</x> |
8 | 8 |
<y>0</y> |
9 |
<width>203</width>
|
|
9 |
<width>519</width>
|
|
10 | 10 |
<height>362</height> |
11 | 11 |
</rect> |
12 | 12 |
</property> |
... | ... | |
30 | 30 |
<rect> |
31 | 31 |
<x>0</x> |
32 | 32 |
<y>0</y> |
33 |
<width>185</width>
|
|
34 |
<height>317</height>
|
|
33 |
<width>486</width>
|
|
34 |
<height>320</height>
|
|
35 | 35 |
</rect> |
36 | 36 |
</property> |
37 | 37 |
<attribute name="label"> |
... | ... | |
65 | 65 |
</property> |
66 | 66 |
</widget> |
67 | 67 |
</item> |
68 |
<item row="3" column="0">
|
|
68 |
<item row="5" column="0">
|
|
69 | 69 |
<widget class="QLabel" name="mMarginTextLabel"> |
70 | 70 |
<property name="text"> |
71 | 71 |
<string>Margin (mm)</string> |
... | ... | |
75 | 75 |
</property> |
76 | 76 |
</widget> |
77 | 77 |
</item> |
78 |
<item row="4" column="0">
|
|
78 |
<item row="6" column="0">
|
|
79 | 79 |
<widget class="QDoubleSpinBox" name="mMarginDoubleSpinBox"/> |
80 | 80 |
</item> |
81 |
<item row="3" column="0"> |
|
82 |
<widget class="QGroupBox" name="buttonGroup1"> |
|
83 |
<property name="title"> |
|
84 |
<string>Horizontal Alignment:</string> |
|
85 |
</property> |
|
86 |
<layout class="QHBoxLayout" name="horizontalLayout"> |
|
87 |
<property name="sizeConstraint"> |
|
88 |
<enum>QLayout::SetMinimumSize</enum> |
|
89 |
</property> |
|
90 |
<item> |
|
91 |
<widget class="QRadioButton" name="mLeftRadioButton"> |
|
92 |
<property name="text"> |
|
93 |
<string>Left</string> |
|
94 |
</property> |
|
95 |
</widget> |
|
96 |
</item> |
|
97 |
<item> |
|
98 |
<widget class="QRadioButton" name="mCenterRadioButton"> |
|
99 |
<property name="text"> |
|
100 |
<string>Center</string> |
|
101 |
</property> |
|
102 |
</widget> |
|
103 |
</item> |
|
104 |
<item> |
|
105 |
<widget class="QRadioButton" name="mRightRadioButton"> |
|
106 |
<property name="text"> |
|
107 |
<string>Right</string> |
|
108 |
</property> |
|
109 |
</widget> |
|
110 |
</item> |
|
111 |
</layout> |
|
112 |
</widget> |
|
113 |
</item> |
|
114 |
<item row="4" column="0"> |
|
115 |
<widget class="QGroupBox" name="buttonGroup2"> |
|
116 |
<property name="title"> |
|
117 |
<string>Vertical Alignment:</string> |
|
118 |
</property> |
|
119 |
<layout class="QHBoxLayout" name="horizontalLayout_2"> |
|
120 |
<item> |
|
121 |
<widget class="QRadioButton" name="mTopRadioButton"> |
|
122 |
<property name="text"> |
|
123 |
<string>Top</string> |
|
124 |
</property> |
|
125 |
</widget> |
|
126 |
</item> |
|
127 |
<item> |
|
128 |
<widget class="QRadioButton" name="mMiddleRadioButton"> |
|
129 |
<property name="text"> |
|
130 |
<string>Middle</string> |
|
131 |
</property> |
|
132 |
</widget> |
|
133 |
</item> |
|
134 |
<item> |
|
135 |
<widget class="QRadioButton" name="mBottomRadioButton"> |
|
136 |
<property name="text"> |
|
137 |
<string>Bottom</string> |
|
138 |
</property> |
|
139 |
</widget> |
|
140 |
</item> |
|
141 |
</layout> |
|
142 |
</widget> |
|
143 |
</item> |
|
81 | 144 |
</layout> |
82 | 145 |
</widget> |
83 | 146 |
</widget> |