Small fixes
[kitchenalert] / src / kitchenalertmainwindow.cpp
index 3d4dc22..f65a002 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);
@@ -173,12 +173,17 @@ void KitchenAlertMainWindow::alert(QModelIndex indexOfAlerter)
 
     // The program is brought to front and activated when alerted
 
-    raise();
+
     activateWindow();
+    raise();
 
     // The alerting timer is selected
     ui->ComingAlertsTableView->selectionModel()->select(QItemSelection(indexOfAlerter,indexOfAlerter),QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows );
-    qDebug() << "Should be selected now";
+
+    //Scrolls the view so that the alerting timer is visible
+    ui->ComingAlertsTableView->scrollTo(indexOfAlerter);
+
+   // qDebug() << "Should be selected now";
 
 
     //Snooze button is enabled
@@ -204,6 +209,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
@@ -260,17 +266,19 @@ 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
 }
 
 void KitchenAlertMainWindow::openSelectSoundDialog()
 {
-    //THIS CEASED TO WORK WHEN SOUND WAS MOVED TO TIMERS THEMSELVES
+
     SelectSoundDialog dialog;
    if ( dialog.exec() == QDialog::Accepted) //if user pressed OK
     {
@@ -302,12 +310,14 @@ bool KitchenAlertMainWindow::event(QEvent *event)
         case QEvent::WindowActivate:
 
             model_.setUpdateViewOnChanges(true);
+            ui->debugLabel->setText("Returned to the application!");
 
 
               break;
 
        case QEvent::WindowDeactivate:
             model_.setUpdateViewOnChanges(false);
+            ui->debugLabel->setText("");
             break;
 
        default:
@@ -322,6 +332,7 @@ void KitchenAlertMainWindow::disableSelectionDependentButtons()
     ui->DoneButton->setDisabled(true);
     ui->SnoozeButton->setDisabled(true);
     ui->RestartButton->setDisabled(true);
+    ui->RemoveButton->setDisabled(true);
 
 }
 
@@ -350,3 +361,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);
+}