Skip to content
Permalink
Browse files

Merge branch 'label_rotation'

  • Loading branch information
mhugent committed Jun 29, 2012
2 parents 53dd796 + 663f5ad commit dbd573b4853340f245f3a465d5e6465f49f4aacd
@@ -172,6 +172,17 @@ void QgsComposerLabelWidget::on_mLabelIdLineEdit_textChanged( const QString& tex
}
}

void QgsComposerLabelWidget::on_mRotationSpinBox_valueChanged( double v )
{
if ( mComposerLabel )
{
mComposerLabel->beginCommand( tr( "Label rotation changed" ), QgsComposerMergeCommand::ComposerLabelRotation );
mComposerLabel->setRotation( v );
mComposerLabel->update();
mComposerLabel->endCommand();
}
}

void QgsComposerLabelWidget::setGuiElementValues()
{
blockAllSignals( true );
@@ -184,6 +195,7 @@ void QgsComposerLabelWidget::setGuiElementValues()
mLeftRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignLeft );
mCenterRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignHCenter );
mRightRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignRight );
mRotationSpinBox->setValue( mComposerLabel->rotation() );
blockAllSignals( false );
}

@@ -197,5 +209,5 @@ void QgsComposerLabelWidget::blockAllSignals( bool block )
mLeftRadioButton->blockSignals( block );
mCenterRadioButton->blockSignals( block );
mRightRadioButton->blockSignals( block );

mRotationSpinBox->blockSignals( block );
}
@@ -43,6 +43,7 @@ class QgsComposerLabelWidget: public QWidget, private Ui::QgsComposerLabelWidget
void on_mBottomRadioButton_clicked();
void on_mMiddleRadioButton_clicked();
void on_mLabelIdLineEdit_textChanged( const QString& text );
void on_mRotationSpinBox_valueChanged( double v );

private slots:
void setGuiElementValues();
@@ -276,6 +276,7 @@ SET(QGIS_CORE_MOC_HDRS
composer/qgscomposerscalebar.h
composer/qgscomposeritem.h
composer/qgscomposeritemgroup.h
composer/qgscomposerlabel.h
composer/qgscomposershape.h
composer/qgscomposerattributetable.h
composer/qgscomposition.h
@@ -88,7 +88,7 @@ QgsComposerMergeCommand::~QgsComposerMergeCommand()
bool QgsComposerMergeCommand::mergeWith( const QUndoCommand * command )
{
const QgsComposerItemCommand* c = dynamic_cast<const QgsComposerItemCommand*>( command );
if ( !c )
if ( !c || mItem != c->item() )
{
return false;
}
@@ -46,6 +46,8 @@ class CORE_EXPORT QgsComposerItemCommand: public QUndoCommand
/**Returns true if previous state and after state are valid and different*/
bool containsChange() const;

const QgsComposerItem* item() const { return mItem; }

protected:
/**Target item of the command*/
QgsComposerItem* mItem;
@@ -72,6 +74,7 @@ class CORE_EXPORT QgsComposerMergeCommand: public QgsComposerItemCommand
//composer label
ComposerLabelSetText,
ComposerLabelSetId,
ComposerLabelRotation,
//composer map
ComposerMapRotation,
ComposerMapAnnotationDistance,
@@ -107,7 +110,8 @@ class CORE_EXPORT QgsComposerMergeCommand: public QgsComposerItemCommand
ArrowOutlineWidth,
ArrowHeadWidth,
//item
ItemOutlineWidth
ItemOutlineWidth,
ItemMove
};

QgsComposerMergeCommand( Context c, QgsComposerItem* item, const QString& text );
@@ -41,18 +41,26 @@ void QgsComposerLabel::paint( QPainter* painter, const QStyleOptionGraphicsItem*
}

drawBackground( painter );
painter->save();
painter->setPen( QPen( QColor( mFontColor ) ) ); //draw all text black
painter->setFont( mFont );

QFontMetricsF fontSize( mFont );

//support multiline labels
double penWidth = pen().widthF();
QRectF painterRect( penWidth + mMargin, penWidth + mMargin, rect().width() - 2 * penWidth - 2 * mMargin,
rect().height() - 2 * penWidth - 2 * mMargin );
QRectF painterRect( penWidth + mMargin, penWidth + mMargin, mTextBoxWidth - 2 * penWidth - 2 * mMargin, mTextBoxHeight - 2 * penWidth - 2 * mMargin );
painter->translate( rect().width() / 2.0, rect().height() / 2.0 );
painter->rotate( mRotation );
painter->translate( -mTextBoxWidth / 2.0, -mTextBoxHeight / 2.0 );

//debug
painter->setPen( QColor( Qt::red ) );
painter->drawRect( painterRect );
drawText( painter, painterRect, displayText(), mFont, mHAlignment, mVAlignment );


drawText( painter, painterRect, displayText(), mFont, mHAlignment, mVAlignment );
painter->restore();

drawFrame( painter );
if ( isSelected() )
@@ -105,15 +113,47 @@ void QgsComposerLabel::adjustSizeToText()
double textWidth = textWidthMillimeters( mFont, displayText() );
double fontAscent = fontAscentMillimeters( mFont );

setSceneRect( QRectF( transform().dx(), transform().dy(), textWidth + 2 * mMargin + 2 * pen().widthF() + 1,
fontAscent + 2 * mMargin + 2 * pen().widthF() + 1 ) );
mTextBoxWidth = textWidth + 2 * mMargin + 2 * pen().widthF() + 1;
mTextBoxHeight = fontAscent + 2 * mMargin + 2 * pen().widthF() + 1;

double width = mTextBoxWidth;
double height = mTextBoxHeight;

sizeChangedByRotation( width, height );

QgsComposerItem::setSceneRect( QRectF( transform().dx(), transform().dy(), width, height ) );
}

QFont QgsComposerLabel::font() const
{
return mFont;
}

void QgsComposerLabel::setRotation( double r )
{
double width = mTextBoxWidth;
double height = mTextBoxHeight;
QgsComposerItem::setRotation( r );
sizeChangedByRotation( width, height );

double x = transform().dx() + rect().width() / 2.0 - width / 2.0;
double y = transform().dy() + rect().height() / 2.0 - height / 2.0;
QgsComposerItem::setSceneRect( QRectF( x, y, width, height ) );
}

void QgsComposerLabel::setSceneRect( const QRectF& rectangle )
{
if ( rectangle.width() != rect().width() || rectangle.height() != rect().height() )
{
double textBoxWidth = rectangle.width();
double textBoxHeight = rectangle.height();
imageSizeConsideringRotation( textBoxWidth, textBoxHeight );
mTextBoxWidth = textBoxWidth;
mTextBoxHeight = textBoxHeight;
}
QgsComposerItem::setSceneRect( rectangle );
}

bool QgsComposerLabel::writeXML( QDomElement& elem, QDomDocument & doc ) const
{
QString alignment;
@@ -24,6 +24,7 @@
*/
class CORE_EXPORT QgsComposerLabel: public QgsComposerItem
{
Q_OBJECT
public:
QgsComposerLabel( QgsComposition *composition );
~QgsComposerLabel();
@@ -76,6 +77,8 @@ class CORE_EXPORT QgsComposerLabel: public QgsComposerItem
@note: this function was added in version 1.4*/
QColor fontColor() const {return mFontColor;}

void setSceneRect( const QRectF& rectangle );

/** stores state in Dom element
* @param elem is Dom element corresponding to 'Composer' tag
* @param doc document
@@ -88,6 +91,9 @@ class CORE_EXPORT QgsComposerLabel: public QgsComposerItem
*/
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );

public slots:
virtual void setRotation( double r );

private:
// Text
QString mText;
@@ -109,6 +115,11 @@ class CORE_EXPORT QgsComposerLabel: public QgsComposerItem

/**Replaces replace '$CURRENT_DATE<(FORMAT)>' with the current date (e.g. $CURRENT_DATE(d 'June' yyyy)*/
void replaceDateText( QString& text ) const;

/**Width of the text box. This is different to rectangle().width() in case there is rotation*/
double mTextBoxWidth;
/**Height of the text box. This is different to rectangle().height() in case there is rotation*/
double mTextBoxHeight;
};

#endif
@@ -502,28 +502,36 @@ void QgsComposerView::keyPressEvent( QKeyEvent * e )
{
for ( ; itemIt != composerItemList.end(); ++itemIt )
{
( *itemIt )->beginCommand( tr( "Item moved" ), QgsComposerMergeCommand::ItemMove );
( *itemIt )->move( -1.0, 0.0 );
( *itemIt )->endCommand();
}
}
else if ( e->key() == Qt::Key_Right )
{
for ( ; itemIt != composerItemList.end(); ++itemIt )
{
( *itemIt )->beginCommand( tr( "Item moved" ), QgsComposerMergeCommand::ItemMove );
( *itemIt )->move( 1.0, 0.0 );
( *itemIt )->endCommand();
}
}
else if ( e->key() == Qt::Key_Down )
{
for ( ; itemIt != composerItemList.end(); ++itemIt )
{
( *itemIt )->beginCommand( tr( "Item moved" ), QgsComposerMergeCommand::ItemMove );
( *itemIt )->move( 0.0, 1.0 );
( *itemIt )->endCommand();
}
}
else if ( e->key() == Qt::Key_Up )
{
for ( ; itemIt != composerItemList.end(); ++itemIt )
{
( *itemIt )->beginCommand( tr( "Item moved" ), QgsComposerMergeCommand::ItemMove );
( *itemIt )->move( 0.0, -1.0 );
( *itemIt )->endCommand();
}
}
}
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>433</width>
<height>425</height>
<width>274</width>
<height>488</height>
</rect>
</property>
<property name="sizePolicy">
@@ -30,42 +30,29 @@
<rect>
<x>0</x>
<y>0</y>
<width>415</width>
<height>378</height>
<width>256</width>
<height>444</height>
</rect>
</property>
<attribute name="label">
<string>Label</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<item row="0" column="0" colspan="2">
<widget class="QTextEdit" name="mTextEdit">
<property name="lineWrapMode">
<enum>QTextEdit::NoWrap</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="mFontButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Font</string>
</property>
</widget>
</item>
<item row="2" column="0">
<item row="2" column="0" colspan="2">
<widget class="QPushButton" name="mFontColorButton">
<property name="text">
<string>Font color...</string>
</property>
</widget>
</item>
<item row="3" column="0">
<item row="3" column="0" colspan="2">
<widget class="QGroupBox" name="buttonGroup1">
<property name="title">
<string>Horizontal Alignment:</string>
@@ -111,7 +98,7 @@
</layout>
</widget>
</item>
<item row="4" column="0">
<item row="4" column="0" colspan="2">
<widget class="QGroupBox" name="buttonGroup2">
<property name="title">
<string>Vertical Alignment:</string>
@@ -154,7 +141,7 @@
</layout>
</widget>
</item>
<item row="6" column="0">
<item row="5" column="0" colspan="2">
<widget class="QDoubleSpinBox" name="mMarginDoubleSpinBox">
<property name="prefix">
<string>Margin </string>
@@ -164,6 +151,45 @@
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="mRotationLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Rotation</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="buddy">
<cstring>mRotationSpinBox</cstring>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QDoubleSpinBox" name="mRotationSpinBox">
<property name="maximum">
<double>360.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QPushButton" name="mFontButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Font</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>

0 comments on commit dbd573b

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