Buggy but tolerable
[kitchenalert] / src / kitchenalertmainwindow.cpp
index 13b2454..5d60117 100644 (file)
@@ -88,7 +88,7 @@ KitchenAlertMainWindow::KitchenAlertMainWindow(QWidget *parent) :
   connect(ui->DoneButton,SIGNAL(clicked()),this,SLOT(stop()));
   connect(ui->RestartButton,SIGNAL(clicked()),this,SLOT(restart()));
   connect(ui->SnoozeButton,SIGNAL(clicked()),this, SLOT(snooze()));
-
+  connect(ui->RemoveButton,SIGNAL(clicked()),this,SLOT(remove()));
   // menu setup
 
   QAction * p_SelectSoundAction = new QAction(tr("Select alert sound"),this);
@@ -137,7 +137,7 @@ void KitchenAlertMainWindow::newTimerSequence()
 
        connect(timer1,SIGNAL(alert(QModelIndex)),this,SLOT(alert(QModelIndex)));
 
-       //TODO: FIND A WAY TO INFORM THE TIMERS' ALERTSOUND'S OF A CHANGE OF THE SOUND FILE THEY SHOULD USE!!!!
+
 
        connect(this,SIGNAL(defaultSoundEnabled()),timer1,SLOT(enableDefaultSound()));
        connect(this,SIGNAL(soundChanged(QString)),timer1,SLOT(changeAlertSound(QString)));
@@ -173,30 +173,27 @@ void KitchenAlertMainWindow::alert(QModelIndex indexOfAlerter)
 
     // The program is brought to front and activated when alerted
 
-    raise();
+
     activateWindow();
 
+// removing everything below does not solve the bug #6752!
+
+    raise();  //this may be unnecessary
+
     // The alerting timer is selected
     ui->ComingAlertsTableView->selectionModel()->select(QItemSelection(indexOfAlerter,indexOfAlerter),QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows );
+
+    //Scrolls the view so that the alerting timer is visible
     ui->ComingAlertsTableView->scrollTo(indexOfAlerter);
-    qDebug() << "Should be selected now";
+
+   // qDebug() << "Should be selected now";
 
 
     //Snooze button is enabled
 
 
     ui->SnoozeButton->setEnabled(true);
-
-    //Debug message
-
-
-
-    ui->debugLabel->setText(tr("Alert received from row %1").arg(indexOfAlerter.row()));
-    qDebug() << "Wrote the debug message";
-
-    //The alert sound is played
-   //TESTING TO MOVE THIS OPERATION TO THE TIMER ITSELF
-//    alertSound_.play();
+qDebug ("Snooze päälle hälytyksessä");
 
 }
 
@@ -205,6 +202,7 @@ void KitchenAlertMainWindow::timerSelected(QItemSelection selected,QItemSelectio
 {
     ui->DoneButton->setEnabled(true);
     ui->RestartButton->setEnabled(true);
+    ui->RemoveButton->setEnabled(true);
 
 
     //snooze button enabled only when alerting
@@ -217,8 +215,13 @@ void KitchenAlertMainWindow::timerSelected(QItemSelection selected,QItemSelectio
         if (model_.isThisTimerAlerting(index) == true)
         {
              ui->SnoozeButton->setEnabled(true);
+qDebug() << "Snooze päälle";
+        }
+        else
+        {
+            ui->SnoozeButton->setDisabled(true);
+qDebug() << "Snooze pois päältä";
         }
-        else ui->SnoozeButton->setDisabled(true);
     }
 
 }
@@ -243,7 +246,10 @@ void KitchenAlertMainWindow::restart()
 
         model_.startTimer(row);
     }
+
+
     ui->SnoozeButton->setDisabled(true);
+    qDebug () << "disabled snooze because of restart";
  //   alertSound_.stop();
 
 }
@@ -261,10 +267,12 @@ void KitchenAlertMainWindow::stop()
 
 QModelIndex KitchenAlertMainWindow::selectedRow()
 {
+    //Returns the cells in row 0 that have the whole row selected (the selection mode used allows only selecting whole rows
+
     QModelIndexList chosenRows = ui->ComingAlertsTableView->selectionModel()->selectedRows();
 
     //The selection mode used allows only one row to be selected at time, so we just take the first
-    //There are indexes for all columns in the row in the list, but as we only use the row, it does not matter which one we take
+
 
     return chosenRows.value(0); //gives an invalid QModelIndex if the list is empty
 }
@@ -294,8 +302,6 @@ void KitchenAlertMainWindow::openAbout()
 
 bool KitchenAlertMainWindow::event(QEvent *event)
 {
-    QMainWindow::event(event);
-
 
 
     switch (event->type())
@@ -303,19 +309,20 @@ bool KitchenAlertMainWindow::event(QEvent *event)
         case QEvent::WindowActivate:
 
             model_.setUpdateViewOnChanges(true);
-
-
-              break;
+//            ui->debugLabel->setText("Returned to the application!");
+            break;
 
        case QEvent::WindowDeactivate:
             model_.setUpdateViewOnChanges(false);
+//            ui->debugLabel->setText("");
             break;
 
        default:
             break;
 
-
     }
+
+    return QMainWindow::event(event); // Send the event to the base class implementation (also when handling the event in this function): necessary for the program to work!
 }
 
 void KitchenAlertMainWindow::disableSelectionDependentButtons()
@@ -323,6 +330,7 @@ void KitchenAlertMainWindow::disableSelectionDependentButtons()
     ui->DoneButton->setDisabled(true);
     ui->SnoozeButton->setDisabled(true);
     ui->RestartButton->setDisabled(true);
+    ui->RemoveButton->setDisabled(true);
 
 }
 
@@ -351,3 +359,18 @@ void KitchenAlertMainWindow::initializeAlertSound()
    }
 
 }
+
+void KitchenAlertMainWindow::remove()
+{
+    QModelIndex row = selectedRow();
+    if (row.isValid()) //If there was no row selected invalid row was returned
+    {
+        QString text = tr("Are you sure you want to remove this timer from the list:\n");
+        text.append((row.data().toString()));
+        if (QMessageBox::question(this,tr("Confirm timer removal"),text,QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
+        {
+            model_.removeTimer(row);
+        }
+    }
+    ui->SnoozeButton->setDisabled(true);
+}