Skip to content

Commit

Permalink
Radio button groups in composer label widget, consider label alignmen…
Browse files Browse the repository at this point in the history
…t in adjustSizeToText (important if replacing label text in server)
  • Loading branch information
mhugent committed Mar 21, 2013
1 parent c182e8a commit 12f0947
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 3 deletions.
93 changes: 92 additions & 1 deletion src/core/composer/qgscomposerlabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,12 @@ void QgsComposerLabel::adjustSizeToText()

sizeChangedByRotation( width, height );

QgsComposerItem::setSceneRect( QRectF( transform().dx(), transform().dy(), width, height ) );
//keep alignment point constant
double xShift = 0;
double yShift = 0;
itemShiftAdjustSize( width, height, xShift, yShift );

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

QFont QgsComposerLabel::font() const
Expand Down Expand Up @@ -304,3 +309,89 @@ bool QgsComposerLabel::readXML( const QDomElement& itemElem, const QDomDocument&
emit itemChanged();
return true;
}

void QgsComposerLabel::itemShiftAdjustSize( double newWidth, double newHeight, double& xShift, double& yShift ) const
{
//keep alignment point constant
double currentWidth = rect().width();
double currentHeight = rect().height();
xShift = 0;
yShift = 0;

if ( mRotation >= 0 && mRotation < 90 )
{
if ( mHAlignment == Qt::AlignHCenter )
{
xShift = - ( newWidth - currentWidth ) / 2.0;
}
else if ( mHAlignment == Qt::AlignRight )
{
xShift = - ( newWidth - currentWidth );
}
if ( mVAlignment == Qt::AlignVCenter )
{
yShift = -( newHeight - currentHeight ) / 2.0;
}
else if ( mVAlignment == Qt::AlignBottom )
{
yShift = - ( newHeight - currentHeight );
}
}
if ( mRotation >= 90 && mRotation < 180 )
{
if ( mHAlignment == Qt::AlignHCenter )
{
yShift = -( newHeight - currentHeight ) / 2.0;
}
else if ( mHAlignment == Qt::AlignRight )
{
yShift = -( newHeight - currentHeight );
}
if ( mVAlignment == Qt::AlignTop )
{
xShift = -( newWidth - currentWidth );
}
else if ( mVAlignment == Qt::AlignVCenter )
{
xShift = -( newWidth - currentWidth / 2.0 );
}
}
else if ( mRotation >= 180 && mRotation < 270 )
{
if ( mHAlignment == Qt::AlignHCenter )
{
xShift = -( newWidth - currentWidth ) / 2.0;
}
else if ( mHAlignment == Qt::AlignLeft )
{
xShift = -( newWidth - currentWidth );
}
if ( mVAlignment == Qt::AlignVCenter )
{
yShift = ( newHeight - currentHeight ) / 2.0;
}
else if ( mVAlignment == Qt::AlignTop )
{
yShift = ( newHeight - currentHeight );
}
}
else if ( mRotation >= 270 && mRotation < 360 )
{
if ( mHAlignment == Qt::AlignHCenter )
{
yShift = -( newHeight - currentHeight ) / 2.0;
}
else if ( mHAlignment == Qt::AlignLeft )
{
yShift = -( newHeight - currentHeight );
}
if ( mVAlignment == Qt::AlignBottom )
{
xShift = -( newWidth - currentWidth );
}
else if ( mVAlignment == Qt::AlignVCenter )
{
xShift = -( newWidth - currentWidth / 2.0 );
}
}
}
3 changes: 3 additions & 0 deletions src/core/composer/qgscomposerlabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ class CORE_EXPORT QgsComposerLabel: public QgsComposerItem
double mHtmlUnitsToMM;
double htmlUnitsToMM(); //calculate scale factor

/**Helper function to calculate x/y shift for adjustSizeToText() depending on rotation, current size and alignment*/
void itemShiftAdjustSize( double newWidth, double newHeight, double& xShift, double& yShift ) const;

// Font
QFont mFont;

Expand Down
26 changes: 24 additions & 2 deletions src/ui/qgscomposerlabelwidgetbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>302</width>
<height>683</height>
<width>298</width>
<height>681</height>
</rect>
</property>
<layout class="QVBoxLayout" name="mainLayout">
Expand Down Expand Up @@ -164,20 +164,29 @@
<property name="text">
<string>Top</string>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="mMiddleRadioButton">
<property name="text">
<string>Middle</string>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="mBottomRadioButton">
<property name="text">
<string>Bottom</string>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</item>
<item>
Expand All @@ -202,20 +211,29 @@
<property name="text">
<string>Left</string>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup_2</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="mCenterRadioButton">
<property name="text">
<string>Center</string>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup_2</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="mRightRadioButton">
<property name="text">
<string>Right</string>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup_2</string>
</attribute>
</widget>
</item>
<item>
Expand Down Expand Up @@ -330,4 +348,8 @@
</customwidgets>
<resources/>
<connections/>
<buttongroups>
<buttongroup name="buttonGroup"/>
<buttongroup name="buttonGroup_2"/>
</buttongroups>
</ui>

0 comments on commit 12f0947

Please sign in to comment.