From c5e7a025e4c1abcc1ad5d701991fc8f15ae82be6 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sat, 18 May 2013 20:42:59 -0300 Subject: [PATCH] Added option to edit the selected dive. Added option to edit the selected dive. Now the user can click on 'Edit', and a nice box will appear stating that the dive is in edit mode, and the user can edit all of the 'Notes' tab fields, including the rating. When the edition is finished, the user needs to click on 'edit' again to mark as accepted, or in reset to reset the fields to it's original state Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/maintab.cpp | 103 +++++++++++++++++++++++++++++++- qt-ui/maintab.h | 20 ++++++- qt-ui/maintab.ui | 136 ++++++++++++++++++++++++++++++++++--------- qt-ui/starwidget.cpp | 11 ++++ qt-ui/starwidget.h | 2 + 5 files changed, 243 insertions(+), 29 deletions(-) diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 70cb3caea..63e4a33d2 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -12,15 +12,20 @@ #include "../statistics.h" #include +#include MainTab::MainTab(QWidget *parent) : QTabWidget(parent), ui(new Ui::MainTab()), weightModel(new WeightModel()), - cylindersModel(new CylindersModel()) + cylindersModel(new CylindersModel()), + currentDive(0) { ui->setupUi(this); ui->cylinders->setModel(cylindersModel); ui->weights->setModel(weightModel); + ui->diveNotesMessage->hide(); + ui->diveNotesMessage->setCloseButtonVisible(false); + ui->rating->setReadOnly(true); /* example of where code is more concise than Qt designer */ QList infoTabWidgets = ui->infoTab->children(); @@ -96,6 +101,7 @@ void MainTab::updateDiveInfo(int dive) // the access is ui->objectName from here on. volume_t sacVal; struct dive *d = get_dive(dive); + currentDive = d; UPDATE_TEXT(d, notes); UPDATE_TEXT(d, location); UPDATE_TEXT(d, suit); @@ -202,3 +208,98 @@ void MainTab::reload() { cylindersModel->update(); } + +void MainTab::on_editNotes_clicked(bool edit) +{ + ui->location->setReadOnly(!edit); + ui->divemaster->setReadOnly(!edit); + ui->buddy->setReadOnly(!edit); + ui->suit->setReadOnly(!edit); + ui->notes->setReadOnly(!edit); + ui->rating->setReadOnly(!edit); + + if (edit){ + ui->diveNotesMessage->setText("This dive is being edited. click on finish / reset when ready."); + ui->diveNotesMessage->animatedShow(); + notesBackup.buddy = ui->buddy->text(); + notesBackup.suit = ui->suit->text(); + notesBackup.notes = ui->notes->toPlainText(); + notesBackup.divemaster = ui->divemaster->text(); + notesBackup.location = ui->location->text(); + notesBackup.rating = ui->rating->currentStars(); + } + else{ + ui->diveNotesMessage->animatedHide(); + } +} + +void MainTab::on_resetNotes_clicked() +{ + if (!ui->editNotes->isChecked()) + return; + + ui->buddy->setText(notesBackup.buddy); + ui->suit->setText(notesBackup.suit); + ui->notes->setText(notesBackup.notes); + ui->divemaster->setText(notesBackup.divemaster); + ui->location->setText(notesBackup.location); + ui->rating->setCurrentStars(notesBackup.rating); + ui->editNotes->setChecked(false); + ui->diveNotesMessage->animatedHide(); + + ui->location->setReadOnly(false); + ui->divemaster->setReadOnly(false); + ui->buddy->setReadOnly(false); + ui->suit->setReadOnly(false); + ui->notes->setReadOnly(false); + ui->rating->setReadOnly(false); +} + +#define EDIT_NOTES(what, text) \ + QByteArray textByteArray = text.toLocal8Bit(); \ + free(currentDive->what);\ + currentDive->what = strdup(textByteArray.data()); + +void MainTab::on_buddy_textChanged(const QString& text) +{ + if (!currentDive) + return; + EDIT_NOTES(buddy, text); +} + +void MainTab::on_divemaster_textChanged(const QString& text) +{ + if (!currentDive) + return; + EDIT_NOTES(divemaster, text); +} + +void MainTab::on_location_textChanged(const QString& text) +{ + if (!currentDive) + return; + EDIT_NOTES(location, text); +} + +void MainTab::on_suit_textChanged(const QString& text) +{ + if (!currentDive) + return; + EDIT_NOTES(suit, text); +} + +void MainTab::on_notes_textChanged() +{ + if (!currentDive) + return; + EDIT_NOTES(notes, ui->notes->toPlainText()); +} + +#undef EDIT_NOTES + +void MainTab::on_rating_valueChanged(int value) +{ + if (!currentDive) + return; + currentDive->rating = value; +} diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h index e09781362..98da412ef 100644 --- a/qt-ui/maintab.h +++ b/qt-ui/maintab.h @@ -17,6 +17,15 @@ namespace Ui class MainTab; } +struct NotesBackup{ + QString location; + QString notes; + QString buddy; + QString suit; + int rating; + QString divemaster; +}; + class MainTab : public QTabWidget { Q_OBJECT @@ -34,13 +43,22 @@ public Q_SLOTS: void on_addWeight_clicked(); void on_editWeight_clicked(); void on_delWeight_clicked(); - void updateDiveInfo(int dive); + void on_editNotes_clicked(bool edit); + void on_resetNotes_clicked(); + void on_location_textChanged(const QString& text); + void on_divemaster_textChanged(const QString& text); + void on_buddy_textChanged(const QString& text); + void on_suit_textChanged(const QString& text); + void on_notes_textChanged(); + void on_rating_valueChanged(int value); private: Ui::MainTab *ui; WeightModel *weightModel; CylindersModel *cylindersModel; + NotesBackup notesBackup; + struct dive* currentDive; }; #endif diff --git a/qt-ui/maintab.ui b/qt-ui/maintab.ui index 70f88caec..74a9b15ad 100644 --- a/qt-ui/maintab.ui +++ b/qt-ui/maintab.ui @@ -7,7 +7,7 @@ 0 0 400 - 325 + 368 @@ -21,66 +21,106 @@ Dive Notes - + Location - - + + + + true + + - + Divemaster - + Buddy - - - - - - + + + true + + + + + + + true + + + + + + + true + + + + + + + true + + + + Rating - + Suit - - - - + Notes - - - - + + + + + reset + + + + + + + edit + + + true + + + + + + @@ -213,15 +253,24 @@ + + 10 + + + 10 + + + 10 + + + 10 + 10 15 - - 10 - @@ -319,7 +368,16 @@ - + + 10 + + + 10 + + + 10 + + 10 @@ -542,7 +600,16 @@ - + + 10 + + + 10 + + + 10 + + 10 @@ -685,7 +752,16 @@ - + + 10 + + + 10 + + + 10 + + 10 @@ -873,6 +949,12 @@ + + KMessageWidget + QWidget +
kmessagewidget.h
+ 1 +
StarWidget QWidget diff --git a/qt-ui/starwidget.cpp b/qt-ui/starwidget.cpp index 4d1fa066c..c43ad1111 100644 --- a/qt-ui/starwidget.cpp +++ b/qt-ui/starwidget.cpp @@ -4,6 +4,7 @@ #include #include #include +#include QPixmap* StarWidget::activeStar = 0; QPixmap* StarWidget::inactiveStar = 0; @@ -25,6 +26,10 @@ int StarWidget::currentStars() const void StarWidget::mouseReleaseEvent(QMouseEvent* event) { + if (readOnly){ + return; + } + int starClicked = event->pos().x() / IMG_SIZE + 1; if (starClicked > TOTALSTARS) starClicked = TOTALSTARS; @@ -34,6 +39,7 @@ void StarWidget::mouseReleaseEvent(QMouseEvent* event) else current = starClicked; + Q_EMIT valueChanged(current); update(); } @@ -98,3 +104,8 @@ QSize StarWidget::sizeHint() const { return QSize(IMG_SIZE * TOTALSTARS + SPACING * (TOTALSTARS-1), IMG_SIZE); } + +void StarWidget::setReadOnly(bool r) +{ + readOnly = r; +} diff --git a/qt-ui/starwidget.h b/qt-ui/starwidget.h index d92be5a98..68e3b2017 100644 --- a/qt-ui/starwidget.h +++ b/qt-ui/starwidget.h @@ -22,6 +22,7 @@ Q_SIGNALS: public Q_SLOTS: void setCurrentStars(int value); + void setReadOnly( bool readOnly); protected: /*reimp*/ void mouseReleaseEvent(QMouseEvent* ); @@ -32,6 +33,7 @@ private: static QPixmap* activeStar; static QPixmap* inactiveStar; QPixmap grayImage(QPixmap *coloredImg); + bool readOnly; }; #endif // STARWIDGET_H