TheWorstTimeTrackerEver/mainwindow.cpp
/**
 * @brief get the current time and subtract it from the lunch break and the time in
 */
@brief get the current time and subtract it from the lunch break and the time in
@brief get the current time and subtract it from the lunch break and the time in
void MainWindow::calculateTime()
{
  QTime timeNow = QTime::currentTime();
  QTime timeIn = this->ui->timeInTimeEdit->time();
  if(timeIn > timeNow)
  {
    this->ui->durationOfTimeLabel->setText(QString("Man, time travel would be cool"));
    this->ui->lengthOfTimeProgressBar->reset();
    this->ui->yesOrNoLabel->setText(QString("No"));
    return;
  } 
  double hours;
  double minutes;
  if(timeIn.minute() > timeNow.minute())
  {
    minutes = (timeNow.minute()/60.0 + 1.0) - timeIn.minute()/60.0;
    hours = timeNow.hour() - timeIn.hour() - 1;
  } else {
    minutes = timeNow.minute()/60.0 - timeIn.minute()/60.0;
    hours = timeNow.hour() - timeIn.hour();
  } 
  QString hoursOrMinutes = this->ui->hoursOrMinutesComboBox->currentText();
  double lunchBreak = this->ui->lunchBreakDoubleSpinner->value();
  if(QString::compare(hoursOrMinutes, "minute(s)", Qt::CaseInsensitive) == 0)
  {
    lunchBreak /= 60.0;
    if(lunchBreak > minutes)
    {
      minutes = (minutes+1) - lunchBreak;
      hours -= 1;
      setDurationOfTimeLabel(hours + minutes);
    } else{
      minutes -= lunchBreak;
      setDurationOfTimeLabel(hours + minutes);
    } 
  } else if(QString::compare(hoursOrMinutes, "hour(s)", Qt::CaseInsensitive) == 0){
    double durationStayed = hours + minutes;
    setDurationOfTimeLabel(durationStayed - lunchBreak);
  } 
  if(hours >= 9.0)
  {
    this->ui->lengthOfTimeProgressBar->setValue(this->ui->lengthOfTimeProgressBar->maximum());
    this->ui->yesOrNoLabel->setText(QString("Yes"));
  } else {
    this->ui->lengthOfTimeProgressBar->setValue(static_cast<int>(hours));
    this->ui->yesOrNoLabel->setText(QString("No"));
  } 
}
void MainWindow :: calculateTime ( ) { QTime timeNow = QTime :: currentTime ( ) ; QTime timeIn = this -> ui -> timeInTimeEdit -> time ( ) ; if ( timeIn > timeNow ) { this -> ui -> durationOfTimeLabel -> setText ( QString ( " " ) ) ; this -> ui -> lengthOfTimeProgressBar -> reset ( ) ; this -> ui -> yesOrNoLabel -> setText ( QString ( " " ) ) ; return ; } double hours ; double minutes ; if ( timeIn . minute ( ) > timeNow . minute ( ) ) { minutes = ( timeNow . minute ( ) / 60.0 + 1.0 ) - timeIn . minute ( ) / 60.0 ; hours = timeNow . hour ( ) - timeIn . hour ( ) - 1 ; } else { minutes = timeNow . minute ( ) / 60.0 - timeIn . minute ( ) / 60.0 ; hours = timeNow . hour ( ) - timeIn . hour ( ) ; } QString hoursOrMinutes = this -> ui -> hoursOrMinutesComboBox -> currentText ( ) ; double lunchBreak = this -> ui -> lunchBreakDoubleSpinner -> value ( ) ; if ( QString :: compare ( hoursOrMinutes , " " , Qt :: CaseInsensitive ) == 0 ) { lunchBreak /= 60.0 ; if ( lunchBreak > minutes ) { minutes = ( minutes + 1 ) - lunchBreak ; hours -= 1 ; setDurationOfTimeLabel ( hours + minutes ) ; } else { minutes -= lunchBreak ; setDurationOfTimeLabel ( hours + minutes ) ; } } else if ( QString :: compare ( hoursOrMinutes , " " , Qt :: CaseInsensitive ) == 0 ) { double durationStayed = hours + minutes ; setDurationOfTimeLabel ( durationStayed - lunchBreak ) ; } if ( hours >= 9.0 ) { this -> ui -> lengthOfTimeProgressBar -> setValue ( this -> ui -> lengthOfTimeProgressBar -> maximum ( ) ) ; this -> ui -> yesOrNoLabel -> setText ( QString ( " " ) ) ; } else { this -> ui -> lengthOfTimeProgressBar -> setValue ( static_cast < int > ( hours ) ) ; this -> ui -> yesOrNoLabel -> setText ( QString ( " " ) ) ; } }
@brief get the current time and subtract it from the lunch break and the time in
@brief get the current time and subtract it from the lunch break and the time in
// end if timeIn > timeNow /* do some time calculations */ // end if timeIn.minute() > timeNow.minute() /* factor in the lunch break */ /* tell the user how long (s)he has been there */ /* tell the user how long (s)he has been there */ // end if lunchBreak > minutes // end if QString::compare(hoursOrMinutes, "minute(s)", Qt::CaseInsensitive /* now set the progress bar*/ // end if hours >= 9.0