Skip to content
Permalink
Browse files

Also disable color buttons which don't apply for numeric scale bars

Make numeric scale bars respect font color and alignment settings (fix #7830)
  • Loading branch information
nyalldawson committed Jun 12, 2013
1 parent e253cd3 commit 7879d37f5a689a68ed96ebf80aa9e08e01c63068
@@ -460,6 +460,8 @@ void QgsComposerScaleBarWidget::toggleStyleSpecificControls( const QString& styl
mGroupBoxSegments->setCollapsed( true );
mLabelBarSpaceSpinBox->setEnabled( false );
mLineWidthSpinBox->setEnabled( false );
mColorPushButton->setEnabled( false );
mStrokeColorPushButton->setEnabled( false );
}
else
{
@@ -468,6 +470,8 @@ void QgsComposerScaleBarWidget::toggleStyleSpecificControls( const QString& styl
mGroupBoxSegments->setEnabled( true );
mLabelBarSpaceSpinBox->setEnabled( true );
mLineWidthSpinBox->setEnabled( true );
mColorPushButton->setEnabled( true );
mStrokeColorPushButton->setEnabled( true );
}
}

@@ -202,6 +202,13 @@ double QgsComposerScaleBar::mapWidth() const
}
}

void QgsComposerScaleBar::setAlignment( Alignment a )
{
mAlignment = a;
update();
emit itemChanged();
}

void QgsComposerScaleBar::setUnits( ScaleBarUnits u )
{
mUnits = u;
@@ -505,6 +512,12 @@ bool QgsComposerScaleBar::readXML( const QDomElement& itemElem, const QDomDocume

void QgsComposerScaleBar::correctXPositionAlignment( double width, double widthAfter )
{
//Don't adjust position for numeric scale bars:
if ( mStyle->name() == "Numeric" )
{
return;
}

if ( mAlignment == Middle )
{
move( -( widthAfter - width ) / 2.0, 0 );
@@ -106,7 +106,7 @@ class CORE_EXPORT QgsComposerScaleBar: public QgsComposerItem
Alignment alignment() const { return mAlignment; }

/**@note: this method was added in version 1.8*/
void setAlignment( Alignment a ) { mAlignment = a; }
void setAlignment( Alignment a );

/**@note: this method was added in version 1.9*/
ScaleBarUnits units() const { return mUnits; }
@@ -50,8 +50,35 @@ void QgsNumericScaleBarStyle::draw( QPainter* p, double xOffset ) const

p->save();
p->setFont( mScaleBar->font() );
p->setPen( QColor( 0, 0, 0 ) );
mScaleBar->drawText( p, mScaleBar->pen().widthF() + mScaleBar->boxContentSpace(), mScaleBar->boxContentSpace() + mScaleBar->fontAscentMillimeters( mScaleBar->font() ), scaleText(), mScaleBar->font() );
p->setPen( mScaleBar->fontColor() );

//call QgsComposerItem's pen() function, since that refers to the frame pen
//and QgsComposerScalebar's pen() function refers to the scale bar line width,
//which is not used for numeric scale bars. Divide the pen width by 2 since
//half the width of the frame is drawn outside the item.
double penWidth = mScaleBar->QgsComposerItem::pen().widthF() / 2.0;
double margin = mScaleBar->boxContentSpace();
//map scalebar alignment to Qt::AlignmentFlag type
Qt::AlignmentFlag hAlign;
switch ( mScaleBar->alignment() )
{
case QgsComposerScaleBar::Left:
hAlign = Qt::AlignLeft;
break;
case QgsComposerScaleBar::Middle:
hAlign = Qt::AlignHCenter;
break;
case QgsComposerScaleBar::Right:
hAlign = Qt::AlignRight;
break;
default:
hAlign = Qt::AlignLeft;
break;
}

//text destination is item's rect, excluding the margin and frame
QRectF painterRect( penWidth + margin, penWidth + margin, mScaleBar->rect().width() - 2 * penWidth - 2 * margin, mScaleBar->rect().height() - 2 * penWidth - 2 * margin );
mScaleBar->drawText( p, painterRect, scaleText(), mScaleBar->font(), hAlign, Qt::AlignTop );

p->restore();
}

0 comments on commit 7879d37

Please sign in to comment.
You can’t perform that action at this time.