Skip to content

Commit

Permalink
Avoid gps toolbar changing size too regularly by restricting when
Browse files Browse the repository at this point in the history
the information label is allowed to shrink in size
  • Loading branch information
nyalldawson committed Jan 11, 2023
1 parent a70a1d9 commit 210860b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/app/gps/qgsgpstoolbar.cpp
Expand Up @@ -301,6 +301,33 @@ void QgsGpsToolBar::updateLocationLabel()
}

mInformationButton->setText( parts.join( ' ' ) );

//ensure the label is big (and small) enough
const int width = mInformationButton->fontMetrics().boundingRect( mInformationButton->text() ).width() + 16;
bool allowResize = false;
if ( mIsFirstSizeChange )
{
allowResize = true;
}
else if ( mInformationButton->minimumWidth() < width )
{
// always immediately grow to fit
allowResize = true;
}
else if ( ( mInformationButton->minimumWidth() - width ) > mInformationButton->fontMetrics().averageCharWidth() * 2 )
{
// only allow shrinking when a sufficient time has expired since we last resized.
// this avoids extraneous shrinking/growing resulting in distracting UI changes
allowResize = mLastLabelSizeChangeTimer.hasExpired( 5000 );
}

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

adjustSize();
Expand Down
4 changes: 4 additions & 0 deletions src/app/gps/qgsgpstoolbar.h
Expand Up @@ -18,6 +18,7 @@

#include <QToolBar>
#include <QPointer>
#include <QElapsedTimer>

#include "qgscoordinatereferencesystem.h"
#include "qgssettingsentryenumflag.h"
Expand Down Expand Up @@ -89,6 +90,9 @@ class QgsGpsToolBar : public QToolBar
bool mEnableAddVertexButton = true;

QgsMapLayerProxyModel *mDestinationLayerModel = nullptr;

bool mIsFirstSizeChange = true;
QElapsedTimer mLastLabelSizeChangeTimer;
};

#endif // QGSGPSTOOLBAR_H

0 comments on commit 210860b

Please sign in to comment.