From: Heli Hyvättinen Date: Sat, 14 Aug 2010 03:33:37 +0000 (+0300) Subject: Remove button, fixed column width, limited text & fixed 00:00:00 X-Git-Tag: v0.4.0~40 X-Git-Url: http://git.maemo.org/git/?p=kitchenalert;a=commitdiff_plain;h=981f6e1b3c110aa5128f08a139c47a4c2a5854cd Remove button, fixed column width, limited text & fixed 00:00:00 --- diff --git a/src/KitchenAlert.pro.user b/src/KitchenAlert.pro.user index 028ee78..337e0f2 100644 --- a/src/KitchenAlert.pro.user +++ b/src/KitchenAlert.pro.user @@ -200,7 +200,7 @@ 17 - 2010-07-19T23:08:40 + 2010-08-12T23:08:10 1 diff --git a/src/createtimersequencedialog.cpp b/src/createtimersequencedialog.cpp index d7b696c..a2ae8ce 100644 --- a/src/createtimersequencedialog.cpp +++ b/src/createtimersequencedialog.cpp @@ -32,6 +32,7 @@ CreateTimerSequenceDialog::CreateTimerSequenceDialog(QWidget *parent) : ui(new Ui::CreateTimerSequenceDialog) { ui->setupUi(this); + ui->timer1AlertText->setMaxLength(40); } CreateTimerSequenceDialog::~CreateTimerSequenceDialog() diff --git a/src/createtimersequencedialog.h b/src/createtimersequencedialog.h index 4765387..d53ac38 100644 --- a/src/createtimersequencedialog.h +++ b/src/createtimersequencedialog.h @@ -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 diff --git a/src/currentalertstablemodel.cpp b/src/currentalertstablemodel.cpp index c4dadcc..ca4b463 100644 --- a/src/currentalertstablemodel.cpp +++ b/src/currentalertstablemodel.cpp @@ -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 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; + } +} diff --git a/src/currentalertstablemodel.h b/src/currentalertstablemodel.h index 062bc11..d147c38 100644 --- a/src/currentalertstablemodel.h +++ b/src/currentalertstablemodel.h @@ -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 currentTimers_; diff --git a/src/icon26.png b/src/icon26.png new file mode 100644 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 index 0000000..1605413 Binary files /dev/null and b/src/icon64.png differ diff --git a/src/kitchenalert.qrc b/src/kitchenalert.qrc index b98d582..4d8ed66 100644 --- a/src/kitchenalert.qrc +++ b/src/kitchenalert.qrc @@ -1,5 +1,3 @@ - - Tonitrus.wav - + diff --git a/src/kitchenalert.xcf b/src/kitchenalert.xcf new file mode 100644 index 0000000..ac8c067 Binary files /dev/null and b/src/kitchenalert.xcf differ diff --git a/src/kitchenalertmainwindow.cpp b/src/kitchenalertmainwindow.cpp index bd1c1f2..49add3b 100644 --- a/src/kitchenalertmainwindow.cpp +++ b/src/kitchenalertmainwindow.cpp @@ -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 alltimers = createdialog.getTimers(); //get user input from the dialog - Timer* timer1 = alltimers.at(0); // take first timer (currently the only one!) + QList 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("

Version 0.1" + QMessageBox::about(this,tr("About KitchenAlert"),tr("

Version 0.1.1" "

Copyright © Heli Hyvättinen 2010" "

License: General Public License v3" "

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(); + } } diff --git a/src/kitchenalertmainwindow.h b/src/kitchenalertmainwindow.h index cf151f0..9ae6a8d 100644 --- a/src/kitchenalertmainwindow.h +++ b/src/kitchenalertmainwindow.h @@ -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: diff --git a/src/kitchenalertmainwindow.ui b/src/kitchenalertmainwindow.ui index 4cb1893..5aa6b80 100644 --- a/src/kitchenalertmainwindow.ui +++ b/src/kitchenalertmainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 718 - 385 + 736 + 403 @@ -40,8 +40,8 @@ 350 0 - 711 - 381 + 721 + 391 @@ -96,6 +96,13 @@ + + + Remove + + + + Qt::Horizontal diff --git a/src/timer.cpp b/src/timer.cpp index 3593008..e1dba54 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -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; } diff --git a/src/timer.h b/src/timer.h index abe6666..543e956 100644 --- a/src/timer.h +++ b/src/timer.h @@ -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.