mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Radio button groups in composer label widget, consider label alignment in adjustSizeToText (important if replacing label text in server)
This commit is contained in:
parent
c182e8a9bb
commit
12f09471a4
@ -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
|
||||
@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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">
|
||||
@ -164,6 +164,9 @@
|
||||
<property name="text">
|
||||
<string>Top</string>
|
||||
</property>
|
||||
<attribute name="buttonGroup">
|
||||
<string notr="true">buttonGroup</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@ -171,6 +174,9 @@
|
||||
<property name="text">
|
||||
<string>Middle</string>
|
||||
</property>
|
||||
<attribute name="buttonGroup">
|
||||
<string notr="true">buttonGroup</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@ -178,6 +184,9 @@
|
||||
<property name="text">
|
||||
<string>Bottom</string>
|
||||
</property>
|
||||
<attribute name="buttonGroup">
|
||||
<string notr="true">buttonGroup</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@ -202,6 +211,9 @@
|
||||
<property name="text">
|
||||
<string>Left</string>
|
||||
</property>
|
||||
<attribute name="buttonGroup">
|
||||
<string notr="true">buttonGroup_2</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@ -209,6 +221,9 @@
|
||||
<property name="text">
|
||||
<string>Center</string>
|
||||
</property>
|
||||
<attribute name="buttonGroup">
|
||||
<string notr="true">buttonGroup_2</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@ -216,6 +231,9 @@
|
||||
<property name="text">
|
||||
<string>Right</string>
|
||||
</property>
|
||||
<attribute name="buttonGroup">
|
||||
<string notr="true">buttonGroup_2</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@ -330,4 +348,8 @@
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
<buttongroups>
|
||||
<buttongroup name="buttonGroup"/>
|
||||
<buttongroup name="buttonGroup_2"/>
|
||||
</buttongroups>
|
||||
</ui>
|
||||
|
Loading…
x
Reference in New Issue
Block a user