Skip to content

Commit

Permalink
Fix for some font size problems and for loading composer scalebar fro…
Browse files Browse the repository at this point in the history
…m xml

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9237 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Sep 1, 2008
1 parent 3fff44f commit 89d03eb
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 11 deletions.
15 changes: 15 additions & 0 deletions src/app/composer/qgscomposer.cpp
Expand Up @@ -1422,6 +1422,9 @@ void QgsComposer::readXML( const QDomDocument& doc )
addComposerLabel( newLabel );
mComposition->addItem( newLabel );
mComposition->update();
mComposition->clearSelection();
newLabel->setSelected(true);
showItemOptions(newLabel);
}

//composer maps
Expand All @@ -1434,6 +1437,9 @@ void QgsComposer::readXML( const QDomDocument& doc )
addComposerMap( newMap );
mComposition->addItem( newMap );
mComposition->update();
mComposition->clearSelection();
newMap->setSelected(true);
showItemOptions(newMap);
}

//composer scalebars
Expand All @@ -1446,6 +1452,9 @@ void QgsComposer::readXML( const QDomDocument& doc )
addComposerScaleBar( newScaleBar );
mComposition->addItem( newScaleBar );
mComposition->update();
mComposition->clearSelection();
newScaleBar->setSelected(true);
showItemOptions(newScaleBar);
}

//composer legends
Expand All @@ -1458,6 +1467,9 @@ void QgsComposer::readXML( const QDomDocument& doc )
addComposerLegend( newLegend );
mComposition->addItem( newLegend );
mComposition->update();
mComposition->clearSelection();
newLegend->setSelected(true);
showItemOptions(newLegend);
}

//composer pictures
Expand All @@ -1470,6 +1482,9 @@ void QgsComposer::readXML( const QDomDocument& doc )
addComposerPicture( newPicture );
mComposition->addItem( newPicture );
mComposition->update();
mComposition->clearSelection();
newPicture->setSelected(true);
showItemOptions(newPicture);
}

mComposition->sortZList();
Expand Down
1 change: 0 additions & 1 deletion src/app/composer/qgscomposerlabelwidget.cpp
Expand Up @@ -64,7 +64,6 @@ void QgsComposerLabelWidget::on_mMarginDoubleSpinBox_valueChanged( double d )
if ( mComposerLabel )
{
mComposerLabel->setMargin( d );
mComposerLabel->adjustSizeToText();
mComposerLabel->update();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/composer/qgscomposerlabel.cpp
Expand Up @@ -51,8 +51,8 @@ void QgsComposerLabel::paint( QPainter* painter, const QStyleOptionGraphicsItem*

//support multiline labels
double penWidth = pen().widthF();
QRectF painterRect( penWidth, penWidth, rect().width() - 2 * penWidth,
rect().height() - 2 * penWidth );
QRectF painterRect( penWidth + mMargin, penWidth + mMargin, rect().width() - 2 * penWidth - 2 * mMargin,
rect().height() - 2 * penWidth - 2 * mMargin);
painter->drawText( painterRect, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, mText );


Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposerpicture.cpp
Expand Up @@ -226,5 +226,5 @@ bool QgsComposerPicture::readXML( const QDomElement& itemElem, const QDomDocumen

mRotation = itemElem.attribute( "rotation" ).toDouble();

return false; //soon...
return true;
}
8 changes: 6 additions & 2 deletions src/core/composer/qgscomposerscalebar.cpp
Expand Up @@ -268,15 +268,17 @@ QString QgsComposerScaleBar::firstLabelString() const

QFont QgsComposerScaleBar::font() const
{
#if 0 //needed by scale bar style, therefore don't convert back to points
if ( mComposition ) //make pixel to point conversion to show correct point value in dialogs
{
double pointSize = mComposition->pointFontSize( mFont.pixelSize() );
QFont returnFont = mFont;
returnFont.setPointSize( pointSize );
return returnFont;
}
#endif //0
}

QFont QgsComposerScaleBar::fontPixelSize() const
{
return mFont;
}

Expand Down Expand Up @@ -311,6 +313,7 @@ bool QgsComposerScaleBar::writeXML( QDomElement& elem, QDomDocument & doc )
composerScaleBarElem.setAttribute( "numSegments", mNumSegments );
composerScaleBarElem.setAttribute( "numSegmentsLeft", mNumSegmentsLeft );
composerScaleBarElem.setAttribute( "numUnitsPerSegment", mNumUnitsPerSegment );
composerScaleBarElem.setAttribute( "segmentMM", mSegmentMM );
composerScaleBarElem.setAttribute( "numMapUnitsPerScaleBarUnit", mNumMapUnitsPerScaleBarUnit );
composerScaleBarElem.setAttribute( "font", mFont.toString() );
composerScaleBarElem.setAttribute( "outlineWidth", mPen.widthF() );
Expand Down Expand Up @@ -353,6 +356,7 @@ bool QgsComposerScaleBar::readXML( const QDomElement& itemElem, const QDomDocume
mNumSegments = itemElem.attribute( "numSegments", "2" ).toInt();
mNumSegmentsLeft = itemElem.attribute( "numSegmentsLeft", "0" ).toInt();
mNumUnitsPerSegment = itemElem.attribute( "numUnitsPerSegment", "1.0" ).toDouble();
mSegmentMM = itemElem.attribute("segmentMM", "0.0").toDouble();
mNumMapUnitsPerScaleBarUnit = itemElem.attribute( "numMapUnitsPerScaleBarUnit", "1.0" ).toDouble();
mPen.setWidthF( itemElem.attribute( "outlineWidth", "1.0" ).toDouble() );
mUnitLabeling = itemElem.attribute( "unitLabel" );
Expand Down
4 changes: 4 additions & 0 deletions src/core/composer/qgscomposerscalebar.h
Expand Up @@ -56,6 +56,10 @@ class CORE_EXPORT QgsComposerScaleBar: public QObject, public QgsComposerItem
void setUnitLabeling( const QString& label ) {mUnitLabeling = label;}

QFont font() const;

/**Returns font that has size set in pixels. Used from QgsComposerScaleBarStyle*/
QFont fontPixelSize() const;

void setFont( const QFont& font );

QPen pen() const {return mPen;}
Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposition.cpp
Expand Up @@ -139,7 +139,7 @@ int QgsComposition::pixelFontSize( double pointSize ) const
{
//in QgsComposition, one unit = one mm
double sizeMM = pointSize * 0.3527;
return sizeMM;
return (sizeMM + 0.5); //round to nearest mm
}

double QgsComposition::pointFontSize( int pixelSize ) const
Expand Down
6 changes: 3 additions & 3 deletions src/core/composer/qgsscalebarstyle.cpp
Expand Up @@ -43,9 +43,9 @@ void QgsScaleBarStyle::drawLabels( QPainter* p ) const

p->save();

p->setFont( mScaleBar->font() );
p->setFont( mScaleBar->fontPixelSize() );

QFontMetricsF fontMetrics( mScaleBar->font() );
QFontMetricsF fontMetrics( mScaleBar->fontPixelSize() );
QString firstLabel = mScaleBar->firstLabelString();
double xOffset = fontMetrics.width( firstLabel ) / 2;

Expand Down Expand Up @@ -107,7 +107,7 @@ QRectF QgsScaleBarStyle::calculateBoxSize() const
}


QFontMetricsF fontMetrics( mScaleBar->font() );
QFontMetricsF fontMetrics( mScaleBar->fontPixelSize() );

//consider centered first label
double firstLabelLeft = fontMetrics.width( mScaleBar->firstLabelString() ) / 2;
Expand Down
1 change: 0 additions & 1 deletion src/gui/qgscomposerview.cpp
Expand Up @@ -86,7 +86,6 @@ void QgsComposerView::mousePressEvent( QMouseEvent* e )
t.translate( scenePoint.x(), scenePoint.y() );
mRubberBandItem->setTransform( t );
mRubberBandItem->setZValue( 100 );

scene()->addItem( mRubberBandItem );
scene()->update();
}
Expand Down

0 comments on commit 89d03eb

Please sign in to comment.