@@ -28,19 +28,10 @@ QgsComposerLegend::QgsComposerLegend( QgsComposition* composition ): QgsComposer
2828 QStringList idList = layerIdList ();
2929 mLegendModel .setLayerSet ( idList );
3030
31- // default font size
32- if ( mComposition )
33- {
34- mTitleFont .setPixelSize ( mComposition ->pixelFontSize ( 14 ) );
35- mLayerFont .setPixelSize ( mComposition ->pixelFontSize ( 12 ) );
36- mItemFont .setPixelSize ( mComposition ->pixelFontSize ( 12 ) );
37- }
38- else
39- {
40- mTitleFont .setPixelSize ( 5 );
41- mLayerFont .setPixelSize ( 4 );
42- mItemFont .setPixelSize ( 3 );
43- }
31+ mTitleFont .setPointSizeF (14.0 );
32+ mLayerFont .setPointSizeF (12.0 );
33+ mItemFont .setPointSizeF (12.0 );
34+
4435 mSymbolWidth = 7 ;
4536 mSymbolHeight = 4 ;
4637 adjustBoxSize ();
@@ -90,18 +81,15 @@ QSizeF QgsComposerLegend::paintAndDetermineSize( QPainter* painter )
9081 double currentYCoordinate = mBoxSpace ;
9182
9283 // font metrics
93- QFontMetricsF titleFontMetrics ( mTitleFont );
94- QFontMetricsF layerFontMetrics ( mLayerFont );
9584
9685 // draw title
97- currentYCoordinate += titleFontMetrics. height ( );
86+ currentYCoordinate += fontAscentMM ( mTitleFont );
9887 if ( painter )
9988 {
100- painter->setFont ( mTitleFont );
101- painter->drawText ( QPointF ( mBoxSpace , currentYCoordinate ), mTitle );
89+ drawText (painter, mBoxSpace , currentYCoordinate, mTitle , mTitleFont );
10290 }
10391
104- maxXCoord = 2 * mBoxSpace + titleFontMetrics. width ( mTitle );
92+ maxXCoord = 2 * mBoxSpace + textWidthMM ( mTitleFont , mTitle );
10593
10694 // draw layer items
10795 for ( int i = 0 ; i < numLayerItems; ++i )
@@ -110,16 +98,15 @@ QSizeF QgsComposerLegend::paintAndDetermineSize( QPainter* painter )
11098 if ( currentLayerItem )
11199 {
112100 currentYCoordinate += mLayerSpace ;
113- currentYCoordinate += layerFontMetrics. height ( );
101+ currentYCoordinate += fontAscentMM ( mLayerFont );
114102
115103 // draw layer Item
116104 if ( painter )
117105 {
118- painter->setFont ( mLayerFont );
119- painter->drawText ( QPointF ( mBoxSpace , currentYCoordinate ), currentLayerItem->text () );
106+ drawText (painter, mBoxSpace , currentYCoordinate, currentLayerItem->text (), mLayerFont );
120107 }
121108
122- maxXCoord = std::max ( maxXCoord, 2 * mBoxSpace + layerFontMetrics. width ( currentLayerItem->text () ) );
109+ maxXCoord = std::max ( maxXCoord, 2 * mBoxSpace + textWidthMM ( mLayerFont , currentLayerItem->text ()) );
123110
124111 // and child items
125112 drawLayerChildItems ( painter, currentLayerItem, currentYCoordinate, maxXCoord );
@@ -161,20 +148,13 @@ void QgsComposerLegend::drawLayerChildItems( QPainter* p, QStandardItem* layerIt
161148 return ;
162149 }
163150
164- QFontMetricsF itemFontMetrics ( mItemFont );
165-
166151 // standerd item height
167- double itemHeight = std::max ( mSymbolHeight , itemFontMetrics. ascent () );
152+ double itemHeight = std::max ( mSymbolHeight , fontAscentMM ( mItemFont ) );
168153
169154 QStandardItem* currentItem;
170155
171156 int numChildren = layerItem->rowCount ();
172157
173- if ( p )
174- {
175- p->setFont ( mItemFont );
176- }
177-
178158 for ( int i = 0 ; i < numChildren; ++i )
179159 {
180160 // real symbol height. Can be different from standard height in case of point symbols
@@ -221,10 +201,10 @@ void QgsComposerLegend::drawLayerChildItems( QPainter* p, QStandardItem* layerIt
221201 // finally draw text
222202 if ( p )
223203 {
224- p-> drawText ( QPointF ( currentXCoord, currentYCoord + itemFontMetrics. ascent ( ) + ( realItemHeight - itemFontMetrics. ascent () ) / 2 ) , currentItem->text () );
204+ drawText (p, currentXCoord, currentYCoord + fontAscentMM ( mItemFont ) + ( realItemHeight - fontAscentMM ( mItemFont ) ) / 2 , currentItem->text (), mItemFont );
225205 }
226206
227- maxXCoord = std::max ( maxXCoord, currentXCoord + itemFontMetrics. width ( currentItem->text () ) + mBoxSpace );
207+ maxXCoord = std::max ( maxXCoord, currentXCoord + textWidthMM ( mItemFont , currentItem->text ()) + mBoxSpace );
228208
229209 currentYCoord += realItemHeight;
230210 }
@@ -353,88 +333,37 @@ void QgsComposerLegend::synchronizeWithModel()
353333
354334void QgsComposerLegend::setTitleFont ( const QFont& f )
355335{
356- if ( mComposition )
357- {
358- int pixelSize = mComposition ->pixelFontSize ( f.pointSizeF () );
359- mTitleFont = f;
360- mTitleFont .setPixelSize ( pixelSize );
361- }
362- else
363- {
364- mTitleFont = f;
365- }
366-
336+ mTitleFont = f;
367337 adjustBoxSize ();
368338 update ();
369339}
370340
371341void QgsComposerLegend::setLayerFont ( const QFont& f )
372342{
373- if ( mComposition )
374- {
375- int pixelSize = mComposition ->pixelFontSize ( f.pointSizeF () );
376- mLayerFont = f;
377- mLayerFont .setPixelSize ( pixelSize );
378- }
379- else
380- {
381- mLayerFont = f;
382- }
383-
343+ mLayerFont = f;
384344 adjustBoxSize ();
385345 update ();
386346}
387347
388348void QgsComposerLegend::setItemFont ( const QFont& f )
389349{
390- if ( mComposition )
391- {
392- int pixelSize = mComposition ->pixelFontSize ( f.pointSizeF () );
393- mItemFont = f;
394- mItemFont .setPixelSize ( pixelSize );
395- }
396- else
397- {
398- mItemFont = f;
399- }
400-
350+ mItemFont = f;
401351 adjustBoxSize ();
402352 update ();
403353}
404354
405355QFont QgsComposerLegend::titleFont () const
406356{
407- if ( mComposition ) // make pixel to point conversion to show correct point value in dialogs
408- {
409- double pointSize = mComposition ->pointFontSize ( mTitleFont .pixelSize () );
410- QFont returnFont = mTitleFont ;
411- returnFont.setPointSize ( pointSize );
412- return returnFont;
413- }
414357 return mTitleFont ;
415358}
416359
417360QFont QgsComposerLegend::layerFont () const
418361{
419- if ( mComposition ) // make pixel to point conversion to show correct point value in dialogs
420- {
421- double pointSize = mComposition ->pointFontSize ( mLayerFont .pixelSize () );
422- QFont returnFont = mLayerFont ;
423- returnFont.setPointSize ( pointSize );
424- return returnFont;
425- }
426362 return mLayerFont ;
427363}
428364
429365QFont QgsComposerLegend::itemFont () const
430366{
431- if ( mComposition ) // make pixel to point conversion to show correct point value in dialogs
432- {
433- double pointSize = mComposition ->pointFontSize ( mItemFont .pixelSize () );
434- QFont returnFont = mItemFont ;
435- returnFont.setPointSize ( pointSize );
436- return returnFont;
437- }
438367 return mItemFont ;
439368}
440369
0 commit comments