aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-05-18 20:42:59 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-05-18 17:06:48 -0700
commitc5e7a025e4c1abcc1ad5d701991fc8f15ae82be6 (patch)
tree6c2e53fb064aecb53ddfd21296a353f86987c63b
parentde50f6625746928711d7fb7f0fa579d194931970 (diff)
downloadsubsurface-c5e7a025e4c1abcc1ad5d701991fc8f15ae82be6.tar.gz
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 <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--qt-ui/maintab.cpp103
-rw-r--r--qt-ui/maintab.h20
-rw-r--r--qt-ui/maintab.ui134
-rw-r--r--qt-ui/starwidget.cpp11
-rw-r--r--qt-ui/starwidget.h2
5 files changed, 242 insertions, 28 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 <QLabel>
+#include <QDebug>
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<QObject *> 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 @@
<x>0</x>
<y>0</y>
<width>400</width>
- <height>325</height>
+ <height>368</height>
</rect>
</property>
<property name="windowTitle">
@@ -21,66 +21,106 @@
<string>Dive Notes</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_3">
- <item row="0" column="0">
+ <item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Location</string>
</property>
</widget>
</item>
- <item row="1" column="0" colspan="2">
- <widget class="QLineEdit" name="location"/>
+ <item row="2" column="0" colspan="2">
+ <widget class="QLineEdit" name="location">
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ </widget>
</item>
- <item row="2" column="0">
+ <item row="3" column="0">
<widget class="QLabel" name="label_15">
<property name="text">
<string>Divemaster</string>
</property>
</widget>
</item>
- <item row="2" column="1">
+ <item row="3" column="1">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Buddy</string>
</property>
</widget>
</item>
- <item row="3" column="0">
- <widget class="QLineEdit" name="divemaster"/>
+ <item row="4" column="0">
+ <widget class="QLineEdit" name="divemaster">
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ </widget>
</item>
- <item row="3" column="1">
- <widget class="QLineEdit" name="buddy"/>
+ <item row="6" column="1">
+ <widget class="QLineEdit" name="suit">
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ </widget>
</item>
- <item row="4" column="0">
+ <item row="4" column="1">
+ <widget class="QLineEdit" name="buddy">
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="9" column="0" colspan="2">
+ <widget class="QTextEdit" name="notes">
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string>Rating</string>
</property>
</widget>
</item>
- <item row="4" column="1">
+ <item row="5" column="1">
<widget class="QLabel" name="label_19">
<property name="text">
<string>Suit</string>
</property>
</widget>
</item>
- <item row="5" column="1">
- <widget class="QLineEdit" name="suit"/>
- </item>
- <item row="6" column="0">
+ <item row="7" column="0">
<widget class="QLabel" name="label_16">
<property name="text">
<string>Notes</string>
</property>
</widget>
</item>
- <item row="7" column="0" colspan="2">
- <widget class="QTextEdit" name="notes"/>
- </item>
- <item row="5" column="0">
+ <item row="6" column="0">
<widget class="StarWidget" name="rating" native="true"/>
</item>
+ <item row="10" column="1">
+ <widget class="QPushButton" name="resetNotes">
+ <property name="text">
+ <string>reset</string>
+ </property>
+ </widget>
+ </item>
+ <item row="10" column="0">
+ <widget class="QPushButton" name="editNotes">
+ <property name="text">
+ <string>edit</string>
+ </property>
+ <property name="checkable">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0" colspan="2">
+ <widget class="KMessageWidget" name="diveNotesMessage" native="true"/>
+ </item>
</layout>
</widget>
<widget class="QWidget" name="equipmentTab">
@@ -213,15 +253,24 @@
</item>
<item>
<layout class="QGridLayout" name="diveInfoUpperGridLayout">
+ <property name="leftMargin">
+ <number>10</number>
+ </property>
+ <property name="topMargin">
+ <number>10</number>
+ </property>
+ <property name="rightMargin">
+ <number>10</number>
+ </property>
+ <property name="bottomMargin">
+ <number>10</number>
+ </property>
<property name="horizontalSpacing">
<number>10</number>
</property>
<property name="verticalSpacing">
<number>15</number>
</property>
- <property name="margin">
- <number>10</number>
- </property>
<item row="0" column="0">
<widget class="QLabel" name="sacLabel">
<property name="font">
@@ -319,7 +368,16 @@
</item>
<item>
<layout class="QGridLayout" name="diveInfoLowerGridLayout">
- <property name="margin">
+ <property name="leftMargin">
+ <number>10</number>
+ </property>
+ <property name="topMargin">
+ <number>10</number>
+ </property>
+ <property name="rightMargin">
+ <number>10</number>
+ </property>
+ <property name="bottomMargin">
<number>10</number>
</property>
<property name="spacing">
@@ -542,7 +600,16 @@
</item>
<item>
<layout class="QGridLayout" name="statsUpperGridLayout">
- <property name="margin">
+ <property name="leftMargin">
+ <number>10</number>
+ </property>
+ <property name="topMargin">
+ <number>10</number>
+ </property>
+ <property name="rightMargin">
+ <number>10</number>
+ </property>
+ <property name="bottomMargin">
<number>10</number>
</property>
<property name="spacing">
@@ -685,7 +752,16 @@
</item>
<item>
<layout class="QGridLayout" name="statsLowerGridLayout">
- <property name="margin">
+ <property name="leftMargin">
+ <number>10</number>
+ </property>
+ <property name="topMargin">
+ <number>10</number>
+ </property>
+ <property name="rightMargin">
+ <number>10</number>
+ </property>
+ <property name="bottomMargin">
<number>10</number>
</property>
<property name="spacing">
@@ -874,6 +950,12 @@
</widget>
<customwidgets>
<customwidget>
+ <class>KMessageWidget</class>
+ <extends>QWidget</extends>
+ <header>kmessagewidget.h</header>
+ <container>1</container>
+ </customwidget>
+ <customwidget>
<class>StarWidget</class>
<extends>QWidget</extends>
<header>starwidget.h</header>
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 <QPaintEvent>
#include <QDebug>
#include <QMouseEvent>
+#include <unistd.h>
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