Skip to content

Commit 210860b

Browse files
committedJan 11, 2023
Avoid gps toolbar changing size too regularly by restricting when
the information label is allowed to shrink in size
1 parent a70a1d9 commit 210860b

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
 

‎src/app/gps/qgsgpstoolbar.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,33 @@ void QgsGpsToolBar::updateLocationLabel()
301301
}
302302

303303
mInformationButton->setText( parts.join( ' ' ) );
304+
305+
//ensure the label is big (and small) enough
306+
const int width = mInformationButton->fontMetrics().boundingRect( mInformationButton->text() ).width() + 16;
307+
bool allowResize = false;
308+
if ( mIsFirstSizeChange )
309+
{
310+
allowResize = true;
311+
}
312+
else if ( mInformationButton->minimumWidth() < width )
313+
{
314+
// always immediately grow to fit
315+
allowResize = true;
316+
}
317+
else if ( ( mInformationButton->minimumWidth() - width ) > mInformationButton->fontMetrics().averageCharWidth() * 2 )
318+
{
319+
// only allow shrinking when a sufficient time has expired since we last resized.
320+
// this avoids extraneous shrinking/growing resulting in distracting UI changes
321+
allowResize = mLastLabelSizeChangeTimer.hasExpired( 5000 );
322+
}
323+
324+
if ( allowResize )
325+
{
326+
mInformationButton->setMinimumWidth( width );
327+
mInformationButton->setMaximumWidth( width );
328+
mLastLabelSizeChangeTimer.restart();
329+
mIsFirstSizeChange = false;
330+
}
304331
}
305332

306333
adjustSize();

‎src/app/gps/qgsgpstoolbar.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <QToolBar>
2020
#include <QPointer>
21+
#include <QElapsedTimer>
2122

2223
#include "qgscoordinatereferencesystem.h"
2324
#include "qgssettingsentryenumflag.h"
@@ -89,6 +90,9 @@ class QgsGpsToolBar : public QToolBar
8990
bool mEnableAddVertexButton = true;
9091

9192
QgsMapLayerProxyModel *mDestinationLayerModel = nullptr;
93+
94+
bool mIsFirstSizeChange = true;
95+
QElapsedTimer mLastLabelSizeChangeTimer;
9296
};
9397

9498
#endif // QGSGPSTOOLBAR_H

0 commit comments

Comments
 (0)
Please sign in to comment.