- fixed bad time displaying (minutes were decreased for 30 seconds earlier) + this should fix the postpone counter

This commit is contained in:
Dmytro Bogovych 2022-11-19 18:54:33 +03:00
parent 21046d9c35
commit 3f8aa69945
2 changed files with 54 additions and 53 deletions

View File

@ -225,7 +225,10 @@ static QString secondsToText(int seconds)
if (seconds < 60) if (seconds < 60)
return QObject::tr("%1 seconds").arg(seconds); return QObject::tr("%1 seconds").arg(seconds);
else else
return QObject::tr("%1 minutes").arg(seconds / 60); {
int minutes = int(float(seconds) / 60 + 0.5f);
return QObject::tr("%1 minutes").arg(minutes);
}
} }
void MainWindow::createTrayIcon() void MainWindow::createTrayIcon()
@ -317,11 +320,9 @@ void MainWindow::shiftTo(AppState newState)
onUpdateUI(); onUpdateUI();
} }
void MainWindow::onUpdateUI() void MainWindow::onUpdateUI() {
{
int idle_milliseconds = 0; int idle_milliseconds = 0;
switch (mState) switch (mState) {
{
case AppState::None: case AppState::None:
// Do nothing, app is not started // Do nothing, app is not started
break; break;
@ -330,8 +331,7 @@ void MainWindow::onUpdateUI()
// Detected idle, don't count this time as working // Detected idle, don't count this time as working
// But check - maybe idle is over // But check - maybe idle is over
idle_milliseconds = get_idle_time_dynamically(); idle_milliseconds = get_idle_time_dynamically();
if (idle_milliseconds < mAppConfig.idle_timeout * 60 * 1000) if (idle_milliseconds < mAppConfig.idle_timeout * 60 * 1000) {
{
shiftTo(AppState::Counting); shiftTo(AppState::Counting);
return; return;
} }
@ -346,24 +346,24 @@ void MainWindow::onUpdateUI()
case AppState::Counting: case AppState::Counting:
// Working, break is closing // Working, break is closing
// Check maybe it is idle ? // Check maybe it is idle ?
if (!mIdleStart && mAppConfig.idle_timeout) if (!mIdleStart && mAppConfig.idle_timeout) {
{
idle_milliseconds = get_idle_time_dynamically(); idle_milliseconds = get_idle_time_dynamically();
if (idle_milliseconds >= mAppConfig.idle_timeout * 60 * 1000) if (idle_milliseconds >= mAppConfig.idle_timeout * 60 * 1000) {
{
shiftTo(AppState::Idle); shiftTo(AppState::Idle);
return; return;
} }
} }
// Update tray icon // Update tray icon
if (mTrayIcon) if (mTrayIcon) {
{
auto remaining_milliseconds = mBreakStartTimer->remainingTime(); auto remaining_milliseconds = mBreakStartTimer->remainingTime();
if (remaining_milliseconds < 60000) if (remaining_milliseconds < 60000)
mTrayIcon->setToolTip(tr("Less than a minute left until the next break.")); mTrayIcon->setToolTip(
tr("Less than a minute left until the next break."));
else else
mTrayIcon->setToolTip(tr("There are %1 minutes left until the next break.").arg(msec2min(remaining_milliseconds))); mTrayIcon->setToolTip(
tr("There are %1 minutes left until the next break.")
.arg(msec2min(remaining_milliseconds)));
} }
break; break;
@ -400,15 +400,15 @@ void MainWindow::onLongBreakStart()
// Start progress bar // Start progress bar
mProgressTimer->start(); mProgressTimer->start();
// Update title immediate
onProgress();
} }
void MainWindow::onLongBreakEnd() void MainWindow::onLongBreakEnd()
{ {
// qDebug() << "Long break ends."; // qDebug() << "Long break ends.";
// Reset postpone counter
mPostponeCount = 0;
// Prepare to next triggering // Prepare to next triggering
ui->mProgressBar->setValue(0); ui->mProgressBar->setValue(0);
@ -477,6 +477,7 @@ void MainWindow::onProgress()
if (percents > 100) if (percents > 100)
{ {
mProgressTimer->stop(); mProgressTimer->stop();
mPostponeCount = 0; // Reset postpone counter
shiftTo(AppState::Counting); shiftTo(AppState::Counting);
} }
else else

View File

@ -43,7 +43,7 @@ private:
QTimer* mBreakStartTimer; // Main timer - triggers when break occurs QTimer* mBreakStartTimer; // Main timer - triggers when break occurs
QTimer* mBreakNotifyTimer; // Timer to show notification from system tray QTimer* mBreakNotifyTimer; // Timer to show notification from system tray
QTimer* mUpdateUITimer; // Update UI timer - triggers every minute to update UI and checks for idle QTimer* mUpdateUITimer; // Update UI timer - triggers every minute to update UI and checks for idle
QTimer* mProgressTimer; // Break progress timer QTimer* mProgressTimer; // Break progress timer - updates an UI
QSystemTrayIcon* mTrayIcon; QSystemTrayIcon* mTrayIcon;
SettingsDialog* mSettingsDialog; SettingsDialog* mSettingsDialog;