Remove button, fixed column width, limited text & fixed 00:00:00
authorHeli Hyvättinen <heli.hyvattinen@kymp.net>
Sat, 14 Aug 2010 03:33:37 +0000 (06:33 +0300)
committerHeli Hyvättinen <heli.hyvattinen@kymp.net>
Sat, 14 Aug 2010 04:01:52 +0000 (07:01 +0300)
14 files changed:
src/KitchenAlert.pro.user
src/createtimersequencedialog.cpp
src/createtimersequencedialog.h
src/currentalertstablemodel.cpp
src/currentalertstablemodel.h
src/icon26.png [new file with mode: 0644]
src/icon64.png [new file with mode: 0644]
src/kitchenalert.qrc
src/kitchenalert.xcf [new file with mode: 0644]
src/kitchenalertmainwindow.cpp
src/kitchenalertmainwindow.h
src/kitchenalertmainwindow.ui
src/timer.cpp
src/timer.h

index 028ee78..337e0f2 100644 (file)
     <valuemap key="Qt4ProjectManager.MaemoRunConfiguration.DebuggingHelpersLastDeployed" type="QVariantMap"/>
     <value key="Qt4ProjectManager.MaemoRunConfiguration.DeviceId" type="qulonglong">17</value>
     <valuemap key="Qt4ProjectManager.MaemoRunConfiguration.LastDeployed" type="QVariantMap">
-     <value key="192.168.2.15" type="QDateTime">2010-07-19T23:08:40</value>
+     <value key="192.168.2.15" type="QDateTime">2010-08-12T23:08:10</value>
     </valuemap>
    </valuemap>
    <value key="ProjectExplorer.Target.RunConfigurationCount" type="int">1</value>
index d7b696c..a2ae8ce 100644 (file)
@@ -32,6 +32,7 @@ CreateTimerSequenceDialog::CreateTimerSequenceDialog(QWidget *parent) :
     ui(new Ui::CreateTimerSequenceDialog)
 {
     ui->setupUi(this);
+    ui->timer1AlertText->setMaxLength(40);
 }
 
 CreateTimerSequenceDialog::~CreateTimerSequenceDialog()
index 4765387..d53ac38 100644 (file)
@@ -39,8 +39,8 @@ namespace Ui {
 /*! Class for the dialog for creating timers'
 
   @author Heli Hyvättinen
-  @date 2010-07-20
-  @version 0.1
+  @date 2010-08-12
+  @version 0.1.1
 
 Class for the dialog for creating timers
 
index c4dadcc..ca4b463 100644 (file)
@@ -45,9 +45,9 @@ int CurrentAlertsTableModel::rowCount(const QModelIndex &parent) const
 
 //No need to mind about the parameter, it has no meaning for table models.
 
-    qDebug () << "rowCount asked";
+//    qDebug () << "rowCount asked";
 
-    qDebug () << currentTimers_.length();
+//    qDebug () << currentTimers_.length();
 
     return currentTimers_.length();
 }
@@ -138,9 +138,9 @@ QVariant CurrentAlertsTableModel::data(const QModelIndex &index, int role) const
 
 
 
-                    qDebug () << timeAsText;
+//                    qDebug () << timeAsText;
 
-                    return timeAsText;
+                   return timeAsText;
 
 
                 case statusColumnNumber_:
@@ -171,16 +171,16 @@ QVariant CurrentAlertsTableModel::data(const QModelIndex &index, int role) const
 
             //No need to care for the column number, all have the same color
 
-            qDebug() << "BackgroundRole asked";
+//            qDebug() << "BackgroundRole asked";
 
             if (currentTimers_.at(index.row())->isAlerting())
             {
-                qDebug() << "black background";
+//                qDebug() << "black background";
                 return QBrush (QColor(Qt::black));
             }
             else
             {
-                qDebug() << "red background";
+//                qDebug() << "red background";
                 return QBrush (QColor(Qt::red));
             }
         default:
@@ -200,12 +200,17 @@ void CurrentAlertsTableModel::addTimers(QList <Timer *> timers)
     foreach (Timer* timer, timers)
     {
         connect (timer,SIGNAL(remainingTimeChanged()),this,SLOT(refreshTimeColumn()));
-        qDebug() << "timer connected";
+//        qDebug() << "timer connected";
         timer->setParent(this); //The model becomes the timers parent giving the timer access to model
     }
+
+    int nextRow = rowCount(QModelIndex()); //As row numbering starts from zero, number of the rows is the row number of the row after current ones
+    int lastRow = nextRow + timers.length()-1;
+    beginInsertRows(QModelIndex(),nextRow,lastRow);
     currentTimers_.append(timers);
-    qDebug() << "Timers should be appended";
-    reset();
+    endInsertRows();
+//    qDebug() << "Timers should be appended";
+//    reset();
 }
 
 
@@ -214,7 +219,7 @@ void CurrentAlertsTableModel::refreshTimeColumn()
     if (updateViewOnChanges_ == true) //Only update GUI if active to save battery
     {
         emit dataChanged(createIndex(0,1),createIndex(rowCount(QModelIndex())-1,1));  //Entire time column refreshed
-        qDebug() << "Refresh time column";
+//        qDebug() << "Refresh time column";
 
     }
 
@@ -291,3 +296,15 @@ bool CurrentAlertsTableModel::isThisTimerAlerting(QModelIndex index)
     }
     return false;
 }
+
+void CurrentAlertsTableModel::removeTimer(QModelIndex index)
+{
+    if (index.isValid())
+    {
+        int row = index.row();
+        beginRemoveRows(QModelIndex(),row,row);
+        Timer* p_timer = currentTimers_.takeAt(row);
+        endRemoveRows();
+        delete p_timer;
+    }
+}
index 062bc11..d147c38 100644 (file)
@@ -35,8 +35,8 @@
 /*! Class that contains the model that holds the timers'
 
   @author Heli Hyvättinen
-  @date 2010-07-20
-  @version 0.1
+  @date 2010-08-08
+  @version 0.1.1
 
 Class that contains the model that holds the timers
 
@@ -76,6 +76,8 @@ public slots:
 
     void setUpdateViewOnChanges(bool update);
 
+    void removeTimer(QModelIndex index);
+
 private:
     QList <Timer * > currentTimers_;
 
diff --git a/src/icon26.png b/src/icon26.png
new file mode 100644 (file)
index 0000000..17413e5
Binary files /dev/null and b/src/icon26.png differ
diff --git a/src/icon64.png b/src/icon64.png
new file mode 100644 (file)
index 0000000..1605413
Binary files /dev/null and b/src/icon64.png differ
index b98d582..4d8ed66 100644 (file)
@@ -1,5 +1,3 @@
 <RCC>
-    <qresource prefix="/">
-        <file alias="defaultsound">Tonitrus.wav</file>
-    </qresource>
+    <qresource prefix="/"/>
 </RCC>
diff --git a/src/kitchenalert.xcf b/src/kitchenalert.xcf
new file mode 100644 (file)
index 0000000..ac8c067
Binary files /dev/null and b/src/kitchenalert.xcf differ
index bd1c1f2..49add3b 100644 (file)
@@ -52,31 +52,39 @@ KitchenAlertMainWindow::KitchenAlertMainWindow(QWidget *parent) :
     ui->setupUi(this);
 
 
-
-
-  connect(ui->CreateNewScheduleButton, SIGNAL (pressed()), this, SLOT (newTimerSequence()));
-
-
   //alerts' tableview setup
 
 
   ui->ComingAlertsTableView->setModel(&model_);
   ui->ComingAlertsTableView->setSelectionMode(QAbstractItemView::SingleSelection);
   ui->ComingAlertsTableView->setSelectionBehavior(QAbstractItemView::SelectRows);
-  ui->ComingAlertsTableView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
+  ui->ComingAlertsTableView->horizontalHeader()->setResizeMode(QHeaderView::Fixed);
+  ui->ComingAlertsTableView->horizontalHeader()->resizeSection(0,460);
+  ui->ComingAlertsTableView->horizontalHeader()->resizeSection(1,140);
+  ui->ComingAlertsTableView->horizontalHeader()->resizeSection(2,100);
+
+  ui->ComingAlertsTableView->verticalHeader()->setResizeMode(QHeaderView::Fixed);
+  ui->ComingAlertsTableView->verticalHeader()->setDefaultSectionSize(40);
+
+
+
+
   ui->ComingAlertsTableView->horizontalHeader()->hide();
+  ui->ComingAlertsTableView->setWordWrap(true);
 
 
-  //Buttons used to reacting an alarm are hidden by default
+  //Buttons used when a timer is selected are disabled by default and enabled upon selection
 
   disableSelectionDependentButtons();
 
-
   connect(ui->ComingAlertsTableView->selectionModel(),SIGNAL(selectionChanged(QItemSelection,QItemSelection)),this,SLOT(timerSelected(QItemSelection,QItemSelection)));
 
+  //connect buttons to respective functions
+  connect(ui->CreateNewScheduleButton, SIGNAL (pressed()), this, SLOT (newTimerSequence()));
   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
 
@@ -117,27 +125,38 @@ void KitchenAlertMainWindow::newTimerSequence()
     if (createdialog.exec() == QDialog::Accepted) //if user pressed OK
     {
 
+        //get user input from the dialog
 
-       QList<Timer *>  alltimers = createdialog.getTimers();  //get user input from the dialog
 
-       Timer* timer1 = alltimers.at(0); // take first timer (currently the only one!)
+       QList<Timer *>  alltimers = createdialog.getTimers();
+
+       // take first timer (currently the only one!)
+
+
+       Timer* timer1 = alltimers.at(0);
+
+
+       //connect alert
 
 
-       timer1->start();
        connect(timer1,SIGNAL(alert(QModelIndex)),this,SLOT(alert(QModelIndex)));
 
 
+       //Disable buttons, as selection is cleared when view is refreshed to show the new timer
+
+       disableSelectionDependentButtons();
 
-        model_.addTimers(alltimers); // give timers to the model
 
- //       ui->ComingAlertsTableView->resizeColumnsToContents();
+       // give timers to the model
 
+       model_.addTimers(alltimers);
 
-        //Disable buttons, as selection is cleared when view is refreshed to show the new timer
 
-        disableSelectionDependentButtons();
+       //start the timer when it's safely in the model (consider moving this to the model's addTimers function)
 
 
+       timer1->start();
+
 
     }
     // if cancelled, do nothing
@@ -160,7 +179,7 @@ void KitchenAlertMainWindow::alert(QModelIndex indexOfAlerter)
 
     // The alerting timer is selected
     ui->ComingAlertsTableView->selectionModel()->select(QItemSelection(indexOfAlerter,indexOfAlerter),QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows );
-    qDebug() << "Should be selected now";
+//    qDebug() << "Should be selected now";
 
 
     //Snooze button is enabled
@@ -168,7 +187,7 @@ void KitchenAlertMainWindow::alert(QModelIndex indexOfAlerter)
 
     ui->SnoozeButton->setEnabled(true);
 
-    //The alert sound is played
+    //The alert sound is played (consider moving this operation inside timer, as now stopping one alert will silence all alerting alerts)
 
     alertSound_.play();
 
@@ -179,6 +198,7 @@ void KitchenAlertMainWindow::timerSelected(QItemSelection selected,QItemSelectio
 {
     ui->DoneButton->setEnabled(true);
     ui->RestartButton->setEnabled(true);
+    ui->RemoveButton->setEnabled(true);
 
 
     //enabled only when alerting
@@ -231,6 +251,7 @@ void KitchenAlertMainWindow::stop()
     }
     ui->SnoozeButton->setDisabled(true);
     alertSound_.stop();
+    qDebug() << "Stopped.";
 }
 
 QModelIndex KitchenAlertMainWindow::selectedRow()
@@ -260,7 +281,7 @@ void KitchenAlertMainWindow::openSelectSoundDialog()
 
 void KitchenAlertMainWindow::openAbout()
 {
-    QMessageBox::about(this,tr("About KitchenAlert"),tr("<p>Version 0.1"
+    QMessageBox::about(this,tr("About KitchenAlert"),tr("<p>Version 0.1.1"
                                                         "<p>Copyright &copy; Heli Hyv&auml;ttinen 2010"
                                                          "<p>License: General Public License v3"
                                                          "<p>Bugtracker and project page: https://garage.maemo.org/projects/kitchenalert/"));
@@ -291,5 +312,17 @@ void KitchenAlertMainWindow::disableSelectionDependentButtons()
     ui->DoneButton->setDisabled(true);
     ui->SnoozeButton->setDisabled(true);
     ui->RestartButton->setDisabled(true);
+    ui->RemoveButton->setDisabled(true);
+}
 
+void KitchenAlertMainWindow::remove()
+{
+   QModelIndex row = selectedRow();
+   if (row.isValid())
+   {
+    model_.removeTimer(row);
+    alertSound_.stop();
+    ui->ComingAlertsTableView->clearSelection();
+    disableSelectionDependentButtons();
+   }
 }
index cf151f0..9ae6a8d 100644 (file)
@@ -40,8 +40,8 @@ namespace Ui {
 /*! The main window class of KitchenAlert'
 
   @author Heli Hyvättinen
-  @date 2010-07-20
-  @version 0.1
+  @date 2010-08-08
+  @version 0.1.1
 
 Operates the UI.
 
@@ -70,6 +70,7 @@ public slots:
     void snooze();
     void restart();
     void stop();
+    void remove();
 
 
 protected:
index 4cb1893..5aa6b80 100644 (file)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>718</width>
-    <height>385</height>
+    <width>736</width>
+    <height>403</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -40,8 +40,8 @@
        <rect>
         <x>350</x>
         <y>0</y>
-        <width>711</width>
-        <height>381</height>
+        <width>721</width>
+        <height>391</height>
        </rect>
       </property>
       <layout class="QVBoxLayout" name="verticalLayout">
           </widget>
          </item>
          <item>
+          <widget class="QPushButton" name="RemoveButton">
+           <property name="text">
+            <string>Remove</string>
+           </property>
+          </widget>
+         </item>
+         <item>
           <spacer name="horizontalSpacer_2">
            <property name="orientation">
             <enum>Qt::Horizontal</enum>
index 3593008..e1dba54 100644 (file)
@@ -40,6 +40,7 @@ Timer::Timer(QObject *parent) :
 }
 
 
+
 int Timer::getOriginalTimeInSeconds()
 {
     return _originalTime;
@@ -74,7 +75,7 @@ void Timer::secondPassed()
     {
         alerting_ = true;
         emit alert(whereAmI());
-        qDebug() << "alerting";
+        qDebug() << "alerted";
     }
 
     emit remainingTimeChanged(); //after alerting in case of alert so that status gets updated immediately
@@ -87,13 +88,20 @@ void Timer::start()
 
     alerting_ = false;
 
+    if (_originalTime == 0) //has to be checked here, since 00:00:00 alert will already be negative when checked next time
+    //THIS ALERTS EVERY SECOND TIME THE TIMER IS STARTED! //This bug disappeared without explanation...
+    {
+        alerting_ = true;
+        emit alert(whereAmI());
+        qDebug () << "Alerted for 00:00:00 alert";
+    }
 }
 
 
 void Timer::stop()
 {
     _actualTimer.stop();
-    _remainingTime = 0; //Stopped timer shows 00:00:00 (which unfortunately makes it red...)
+    _remainingTime = 0; //Stopped timer shows 00:00:00
 
     alerting_ = false;
 }
index abe6666..543e956 100644 (file)
@@ -39,8 +39,8 @@
 /*! The timer class of KitchenAlert'
 
   @author Heli Hyvättinen
-  @date 2010-07-20
-  @version 0.1
+  @date 2010-08-12
+  @version 0.1.1
 
 The timer class of KitchenAlert.