Skip to content

Commit

Permalink
Now compacting status bar fields after timeout if no cursor above map.
Browse files Browse the repository at this point in the history
  • Loading branch information
albar965 committed Oct 3, 2023
1 parent 5665182 commit 03da99a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 10 deletions.
50 changes: 43 additions & 7 deletions src/gui/mainwindow.cpp
Expand Up @@ -105,7 +105,10 @@

#include "ui_mainwindow.h"

static const int MAX_STATUS_MESSAGES = 10;
const static int MAX_STATUS_MESSAGES = 10;
const static int CLOCK_TIMER_MS = 1000;
const static int RENDER_STATUS_TIMER_MS = 5000;
const static int SHRINK_STATUS_BAR_TIMER_MS = 10000;

using namespace Marble;
using atools::settings::Settings;
Expand Down Expand Up @@ -392,15 +395,19 @@ MainWindow::MainWindow()
optionsDialog->updateTooltipOption();

// Update clock =====================
clockTimer.setInterval(1000);
clockTimer.setInterval(CLOCK_TIMER_MS);
connect(&clockTimer, &QTimer::timeout, this, &MainWindow::updateClock);
clockTimer.start();

// Reset render status - change to done after ten seconds =====================
renderStatusTimer.setInterval(5000);
renderStatusTimer.setInterval(RENDER_STATUS_TIMER_MS);
renderStatusTimer.setSingleShot(true);
connect(&renderStatusTimer, &QTimer::timeout, this, &MainWindow::renderStatusReset);

shrinkStatusBarTimer.setInterval(SHRINK_STATUS_BAR_TIMER_MS);
shrinkStatusBarTimer.setSingleShot(true);
connect(&shrinkStatusBarTimer, &QTimer::timeout, this, &MainWindow::shrinkStatusBar);

// Print the size of all container classes to detect overflow or memory leak conditions
// Do this every 30 seconds if enabled with "[Options] StorageDebug=true" in ini file
if(Settings::instance().getAndStoreValue(lnm::OPTIONS_STORAGE_DEBUG, false).toBool())
Expand Down Expand Up @@ -993,11 +1000,11 @@ void MainWindow::updateStatusBarStyle()

mapPositionLabel->setAlignment(align);
mapPositionLabel->setMinimumWidth(20);
mapPositionLabel->setText(tr(""));
mapPositionLabel->setText(tr(""));

mapMagvarLabel->setAlignment(align);
mapMagvarLabel->setMinimumWidth(20);
mapMagvarLabel->setText(tr(""));
mapMagvarLabel->setText(tr(""));

timeLabel->setAlignment(align);
timeLabel->setMinimumWidth(20);
Expand Down Expand Up @@ -1967,6 +1974,29 @@ void MainWindow::routeCenter()
}
}

void MainWindow::shrinkStatusBar()
{
#ifdef DEBUG_INFORMATION
qDebug() << Q_FUNC_INFO << statusBar()->geometry() << QCursor::pos();
#endif

// Do not shrink status bar if cursor is above
if(!statusBar()->rect().contains(statusBar()->mapFromGlobal(QCursor::pos())))
{
mapPositionLabel->clear();
mapPositionLabel->setText(tr(""));
mapPositionLabel->setMinimumWidth(20);
mapPositionLabel->resize(20, mapPositionLabel->height());

mapMagvarLabel->clear();
mapMagvarLabel->setText(tr(""));
mapMagvarLabel->setMinimumWidth(20);
mapMagvarLabel->resize(20, mapMagvarLabel->height());
}
else
shrinkStatusBarTimer.start();
}

void MainWindow::updateMapPosLabel(const atools::geo::Pos& pos, int x, int y)
{
Q_UNUSED(x)
Expand Down Expand Up @@ -1994,12 +2024,18 @@ void MainWindow::updateMapPosLabel(const atools::geo::Pos& pos, int x, int y)

mapPositionLabel->setText(text);
mapPositionLabel->setMinimumWidth(mapPositionLabel->width());

// Stop status bar time to avoid shrinking
shrinkStatusBarTimer.stop();
}
else
{
mapPositionLabel->setText(tr(""));
mapPositionLabel->setText(tr(""));
mapPositionLabel->setMinimumWidth(mapPositionLabel->width());
mapMagvarLabel->setText(tr(""));
mapMagvarLabel->setText(tr(""));

// Reduce status fields bar after timeout
shrinkStatusBarTimer.start();
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/gui/mainwindow.h
Expand Up @@ -454,6 +454,9 @@ class MainWindow :
/* Print the size of all container classes to detect overflow or memory leak conditions */
void debugDumpContainerSizes() const;

/* Reduce status bar size if no mouse movement */
void shrinkStatusBar();

#ifdef DEBUG_INFORMATION
void debugActionTriggered1();
void debugActionTriggered2();
Expand Down Expand Up @@ -544,7 +547,9 @@ class MainWindow :
bool databasesErased = false;
QSize defaultToolbarIconSize;
QString aboutMessage, layoutWarnText;
QTimer clockTimer, renderStatusTimer;
QTimer clockTimer /* MainWindow::updateClock() every second */,
renderStatusTimer /* MainWindow::renderStatusReset() if render status is stalled */,
shrinkStatusBarTimer /* calls MainWindow::shrinkStatusBar() once map pos and magvar are "-" */;
Marble::RenderStatus lastRenderStatus = Marble::Incomplete;

/* Show hint dialog only once per session */
Expand Down
4 changes: 2 additions & 2 deletions src/mapgui/mapvisible.cpp
Expand Up @@ -433,13 +433,13 @@ void MapVisible::updateVisibleObjectsStatusBar()
label.append(routeLabel.join(tr(",")));

if(label.isEmpty())
label.append(tr(""));
label.append(tr(""));

// Update the statusbar label text and tooltip of the label
NavApp::getMainWindow()->setMapObjectsShownMessageText(atools::elideTextShort(label.join(tr("/")), 40), tooltip.getHtml());
} // if(layer != nullptr && !paintLayer->noRender())
else
NavApp::getMainWindow()->setMapObjectsShownMessageText(tr(""), tr("Nothing shown. Zoom in to see map features."));
NavApp::getMainWindow()->setMapObjectsShownMessageText(tr(""), tr("Nothing shown. Zoom in to see map features."));
} // if(!NavApp::hasDataInDatabase()) ... else
}

Expand Down

0 comments on commit 03da99a

Please sign in to comment.