Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #5861 from signedav/bugFixSH01
Widget size handling in status bar
  • Loading branch information
slarosa committed Feb 23, 2018
2 parents 2d9ee3d + 5cfe278 commit 9a62305
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
6 changes: 0 additions & 6 deletions src/app/qgisapp.cpp
Expand Up @@ -9005,12 +9005,6 @@ void QgisApp::saveLastMousePosition( const QgsPointXY &p )
void QgisApp::showScale( double scale )
{
mScaleWidget->setScale( scale );

// Not sure if the lines below do anything meaningful /Homann
if ( mScaleWidget->width() > mScaleWidget->minimumWidth() )
{
mScaleWidget->setMinimumWidth( mScaleWidget->width() );
}
}


Expand Down
25 changes: 17 additions & 8 deletions src/app/qgsstatusbarcoordinateswidget.cpp
Expand Up @@ -33,6 +33,9 @@ QgsStatusBarCoordinatesWidget::QgsStatusBarCoordinatesWidget( QWidget *parent )
: QWidget( parent )
, mMousePrecisionDecimalPlaces( 0 )
{
// calculate the size of two chars
mTwoCharSize = fontMetrics().width( QStringLiteral( "OO" ) );

// add a label to show current position
mLabel = new QLabel( QString(), this );
mLabel->setObjectName( QStringLiteral( "mCoordsLabel" ) );
Expand All @@ -46,7 +49,6 @@ QgsStatusBarCoordinatesWidget::QgsStatusBarCoordinatesWidget( QWidget *parent )

mLineEdit = new QLineEdit( this );
mLineEdit->setMinimumWidth( 10 );
mLineEdit->setMaximumWidth( 300 );
//mLineEdit->setMaximumHeight( 20 );
mLineEdit->setContentsMargins( 0, 0, 0, 0 );
mLineEdit->setAlignment( Qt::AlignCenter );
Expand Down Expand Up @@ -226,10 +228,7 @@ void QgsStatusBarCoordinatesWidget::showMouseCoordinates( const QgsPointXY &p )
mLineEdit->setText( QgsCoordinateUtils::formatCoordinateForProject( p, mMapCanvas->mapSettings().destinationCrs(),
mMousePrecisionDecimalPlaces ) );

if ( mLineEdit->width() > mLineEdit->minimumWidth() )
{
mLineEdit->setMinimumWidth( mLineEdit->width() );
}
ensureCoordinatesVisible();
}


Expand All @@ -244,9 +243,19 @@ void QgsStatusBarCoordinatesWidget::showExtent()
QgsRectangle myExtents = mMapCanvas->extent();
mLabel->setText( tr( "Extents:" ) );
mLineEdit->setText( myExtents.toString( true ) );
//ensure the label is big enough
if ( mLineEdit->width() > mLineEdit->minimumWidth() )

ensureCoordinatesVisible();
}

void QgsStatusBarCoordinatesWidget::ensureCoordinatesVisible()
{

//ensure the label is big (and small) enough
int width = mLineEdit->fontMetrics().width( mLineEdit->text() ) + 10;
if ( mLineEdit->minimumWidth() < width || ( mLineEdit->minimumWidth() - width ) > mTwoCharSize )
{
mLineEdit->setMinimumWidth( mLineEdit->width() );
mLineEdit->setMinimumWidth( width );
mLineEdit->setMaximumWidth( width );
}
}

2 changes: 2 additions & 0 deletions src/app/qgsstatusbarcoordinateswidget.h
Expand Up @@ -59,6 +59,7 @@ class APP_EXPORT QgsStatusBarCoordinatesWidget : public QWidget
void validateCoordinates();
void dizzy();
void showExtent();
void ensureCoordinatesVisible();

private:
void refreshMapCanvas();
Expand All @@ -71,6 +72,7 @@ class APP_EXPORT QgsStatusBarCoordinatesWidget : public QWidget
QValidator *mCoordsEditValidator = nullptr;
QTimer *mDizzyTimer = nullptr;
QgsMapCanvas *mMapCanvas = nullptr;
int mTwoCharSize;

//! The number of decimal places to use if not automatic
unsigned int mMousePrecisionDecimalPlaces;
Expand Down
5 changes: 5 additions & 0 deletions src/app/qgsstatusbarscalewidget.cpp
Expand Up @@ -78,6 +78,11 @@ void QgsStatusBarScaleWidget::setScale( double scale )
mScale->blockSignals( true );
mScale->setScale( scale );
mScale->blockSignals( false );

if ( mScale->width() > mScale->minimumWidth() )
{
mScale->setMinimumWidth( mScale->width() );
}
}

bool QgsStatusBarScaleWidget::isLocked() const
Expand Down

0 comments on commit 9a62305

Please sign in to comment.