Skip to content

Commit

Permalink
Don't allow status bar coordinate widget to change sizes so regularly
Browse files Browse the repository at this point in the history
Now, the widget will always immediately grow to fit the coordinates,
but won't immediately reshrink until a short timeout has occurred.
This avoids yuck UI movement which occurs when the mouse is moved
over a map and the coordinate widget size jumps all around the place.
  • Loading branch information
nyalldawson committed Jan 10, 2023
1 parent c6e4351 commit 2722040
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
23 changes: 21 additions & 2 deletions src/app/qgsstatusbarcoordinateswidget.cpp
Expand Up @@ -371,13 +371,32 @@ void QgsStatusBarCoordinatesWidget::showExtent()

void QgsStatusBarCoordinatesWidget::ensureCoordinatesVisible()
{

//ensure the label is big (and small) enough
const int width = std::max( mLineEdit->fontMetrics().boundingRect( mLineEdit->text() ).width() + 16, mMinimumWidth );
if ( mLineEdit->minimumWidth() < width || ( mLineEdit->minimumWidth() - width ) > mTwoCharSize )

bool allowResize = false;
if ( mIsFirstSizeChange )
{
allowResize = true;
}
else if ( mLineEdit->minimumWidth() < width )
{
// always immediately grow to fit
allowResize = true;
}
else if ( ( mLineEdit->minimumWidth() - width ) > mTwoCharSize )
{
// only allow shrinking when a sufficient time has expired since we last resized.
// this avoids extraneous shrinking/growing resulting in distracting UI changes
allowResize = mLastSizeChangeTimer.hasExpired( 2000 );
}

if ( allowResize )
{
mLineEdit->setMinimumWidth( width );
mLineEdit->setMaximumWidth( width );
mLastSizeChangeTimer.restart();
mIsFirstSizeChange = false;
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/app/qgsstatusbarcoordinateswidget.h
Expand Up @@ -26,10 +26,12 @@ class QValidator;

class QgsMapCanvas;

#include <QWidget>
#include "qgis_app.h"
#include "qgspointxy.h"

#include <QWidget>
#include <QElapsedTimer>

class APP_EXPORT QgsStatusBarCoordinatesWidget : public QWidget
{
Q_OBJECT
Expand Down Expand Up @@ -87,6 +89,9 @@ class APP_EXPORT QgsStatusBarCoordinatesWidget : public QWidget

QgsPointXY mLastCoordinate;

bool mIsFirstSizeChange = true;
QElapsedTimer mLastSizeChangeTimer;

};

#endif // QGSSTATUSBARCOORDINATESWIDGET_H

0 comments on commit 2722040

Please sign in to comment.