summaryrefslogtreecommitdiffstats
path: root/qt-ui/maintab.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'qt-ui/maintab.cpp')
-rw-r--r--qt-ui/maintab.cpp243
1 files changed, 173 insertions, 70 deletions
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index b9b5d0ab7..c6b49da39 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -15,19 +15,26 @@
#include <QLabel>
#include <QDebug>
+#include <QSet>
+#include <QSettings>
MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
ui(new Ui::MainTab()),
weightModel(new WeightModel()),
cylindersModel(new CylindersModel()),
- currentDive(0)
+ currentDive(0),
+ editMode(NONE)
{
ui->setupUi(this);
ui->cylinders->setModel(cylindersModel);
ui->weights->setModel(weightModel);
ui->diveNotesMessage->hide();
ui->diveNotesMessage->setCloseButtonVisible(false);
-
+#ifdef __APPLE__
+ setDocumentMode(false);
+#else
+ setDocumentMode(true);
+#endif
// we start out with the fields read-only; once things are
// filled from a dive, they are made writeable
ui->location->setReadOnly(true);
@@ -73,13 +80,17 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
connect(ui->cylinders, SIGNAL(clicked(QModelIndex)), ui->cylinders->model(), SLOT(remove(QModelIndex)));
connect(ui->weights, SIGNAL(clicked(QModelIndex)), ui->weights->model(), SLOT(remove(QModelIndex)));
- ui->cylinders->setColumnWidth(CylindersModel::REMOVE, 24);
- ui->cylinders->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
+ QFontMetrics metrics(defaultModelFont());
+ QFontMetrics metrics2(font());
+
ui->cylinders->horizontalHeader()->setResizeMode(CylindersModel::REMOVE, QHeaderView::Fixed);
+ ui->cylinders->verticalHeader()->setDefaultSectionSize( metrics.height() +8 );
ui->cylinders->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate());
- ui->weights->setColumnWidth(WeightModel::REMOVE, 24);
+
ui->weights->horizontalHeader()->setResizeMode (WeightModel::REMOVE , QHeaderView::Fixed);
+ ui->weights->verticalHeader()->setDefaultSectionSize( metrics.height() +8 );
ui->weights->setItemDelegateForColumn(WeightModel::TYPE, new WSInfoDelegate());
+ initialUiSetup();
}
// We need to manually position the 'plus' on cylinder and weight.
@@ -155,15 +166,11 @@ void MainTab::clearStats()
void MainTab::updateDiveInfo(int dive)
{
- // So, this is what happens now:
- // Every tab should be populated from this method,
- // it will be called whenever a new dive is selected
- // I'm already populating the 'notes' box
- // to show how it can be done.
- // If you are unsure about the name of something,
- // open the file maintab.ui on the designer
- // click on the item and check its objectName,
- // the access is ui->objectName from here on.
+ // This method updates ALL tabs whenever a new dive or trip is
+ // selected.
+ // If exactly one trip has been selected, we show the location / notes
+ // for the trip in the Info tab, otherwise we show the info of the
+ // selected_dive
volume_t sacVal;
temperature_t temp;
struct dive *prevd;
@@ -177,18 +184,48 @@ void MainTab::updateDiveInfo(int dive)
UPDATE_TEXT(d, suit);
UPDATE_TEXT(d, divemaster);
UPDATE_TEXT(d, buddy);
- /* infoTab */
if (d) {
- /* make the fields writeable */
- ui->location->setReadOnly(false);
- ui->divemaster->setReadOnly(false);
- ui->buddy->setReadOnly(false);
- ui->suit->setReadOnly(false);
- ui->notes->setReadOnly(false);
- ui->rating->setReadOnly(false);
- ui->visibility->setReadOnly(false);
- /* and fill them from the dive */
- ui->rating->setCurrentStars(d->rating);
+ if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
+ // only use trip relevant fields
+ ui->divemaster->setVisible(false);
+ ui->DivemasterLabel->setVisible(false);
+ ui->buddy->setVisible(false);
+ ui->BuddyLabel->setVisible(false);
+ ui->suit->setVisible(false);
+ ui->SuitLabel->setVisible(false);
+ ui->rating->setVisible(false);
+ ui->RatingLabel->setVisible(false);
+ ui->visibility->setVisible(false);
+ ui->visibilityLabel->setVisible(false);
+ // rename the remaining fields and fill data from selected trip
+ dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin();
+ ui->location->setReadOnly(false);
+ ui->LocationLabel->setText(tr("Trip Location"));
+ ui->location->setText(currentTrip->location);
+ ui->notes->setReadOnly(false);
+ ui->NotesLabel->setText(tr("Trip Notes"));
+ ui->notes->setText(currentTrip->notes);
+ } else {
+ // make all the fields visible writeable
+ ui->divemaster->setVisible(true);
+ ui->buddy->setVisible(true);
+ ui->suit->setVisible(true);
+ ui->rating->setVisible(true);
+ ui->visibility->setVisible(true);
+ ui->divemaster->setReadOnly(false);
+ ui->buddy->setReadOnly(false);
+ ui->suit->setReadOnly(false);
+ ui->rating->setReadOnly(false);
+ ui->visibility->setReadOnly(false);
+ /* and fill them from the dive */
+ ui->rating->setCurrentStars(d->rating);
+ ui->visibility->setCurrentStars(d->visibility);
+ // reset labels in case we last displayed trip notes
+ ui->location->setReadOnly(false);
+ ui->LocationLabel->setText(tr("Location"));
+ ui->notes->setReadOnly(false);
+ ui->NotesLabel->setText(tr("Notes"));
+ }
ui->maximumDepthText->setText(get_depth_string(d->maxdepth, TRUE));
ui->averageDepthText->setText(get_depth_string(d->meandepth, TRUE));
ui->otuText->setText(QString("%1").arg(d->otu));
@@ -209,7 +246,6 @@ void MainTab::updateDiveInfo(int dive)
ui->airPressureText->setText(QString("%1mbar").arg(d->surface_pressure.mbar));
else
ui->airPressureText->clear();
- ui->visibility->setCurrentStars(d->visibility);
ui->depthLimits->setMaximum(get_depth_string(stats_selection.max_depth, TRUE));
ui->depthLimits->setMinimum(get_depth_string(stats_selection.min_depth, TRUE));
ui->depthLimits->setAverage(get_depth_string(stats_selection.avg_depth, TRUE));
@@ -272,13 +308,6 @@ void MainTab::updateDiveInfo(int dive)
ui->totalTimeAllText->clear();
ui->timeLimits->clear();
}
- /* statisticsTab*/
- /* we can access the stats_selection struct, but how do we ensure the relevant dives are selected
- * if we don't use the gtk widget to drive this?
- * Maybe call process_selected_dives? Or re-write to query our Qt list view.
- */
-// qDebug("max temp %u",stats_selection.max_temp);
-// qDebug("min temp %u",stats_selection.min_temp);
}
void MainTab::addCylinder_clicked()
@@ -308,30 +337,47 @@ void MainTab::on_editAccept_clicked(bool edit)
mainWindow()->dive_list()->setEnabled(!edit);
if (edit) {
- ui->diveNotesMessage->setText(tr("This dive is being edited. Select Save or Undo 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();
- notesBackup.visibility = ui->visibility->currentStars();
+ if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
+ // we are editing trip location and notes
+ ui->diveNotesMessage->setText(tr("This trip is being edited. Select Save or Undo when ready."));
+ ui->diveNotesMessage->animatedShow();
+ notesBackup.notes = ui->notes->toPlainText();
+ notesBackup.location = ui->location->text();
+ editMode = TRIP;
+ } else {
+ ui->diveNotesMessage->setText(tr("This dive is being edited. Select Save or Undo 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();
+ notesBackup.visibility = ui->visibility->currentStars();
+ editMode = DIVE;
+ }
} else {
ui->diveNotesMessage->animatedHide();
ui->editAccept->hide();
ui->editReset->hide();
/* now figure out if things have changed */
- if (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.visibility != ui->visibility->currentStars() ||
- notesBackup.rating != ui->rating->currentStars())
- mark_divelist_changed(TRUE);
- if (notesBackup.location != ui->location->text())
- mainWindow()->globe()->reload();
+ if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
+ if (notesBackup.notes != ui->notes->toPlainText() ||
+ notesBackup.location != ui->location->text())
+ mark_divelist_changed(TRUE);
+ } else {
+ if (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.visibility != ui->visibility->currentStars() ||
+ notesBackup.rating != ui->rating->currentStars())
+ mark_divelist_changed(TRUE);
+ if (notesBackup.location != ui->location->text())
+ mainWindow()->globe()->reload();
+ }
+ editMode = NONE;
}
}
@@ -340,13 +386,15 @@ void MainTab::on_editReset_clicked()
if (!ui->editAccept->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->visibility->setCurrentStars(notesBackup.visibility);
+ if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() != 1) {
+ ui->buddy->setText(notesBackup.buddy);
+ ui->suit->setText(notesBackup.suit);
+ ui->divemaster->setText(notesBackup.divemaster);
+ ui->rating->setCurrentStars(notesBackup.rating);
+ ui->visibility->setCurrentStars(notesBackup.visibility);
+ }
ui->editAccept->setChecked(false);
ui->diveNotesMessage->animatedHide();
@@ -361,49 +409,62 @@ void MainTab::on_editReset_clicked()
ui->editAccept->hide();
ui->editReset->hide();
+ editMode = NONE;
}
-#define EDIT_NOTES(what, text) \
+#define EDIT_TEXT(what, text) \
QByteArray textByteArray = text.toLocal8Bit(); \
- free(currentDive->what);\
- currentDive->what = strdup(textByteArray.data());
+ free(what);\
+ what = strdup(textByteArray.data());
void MainTab::on_buddy_textChanged(const QString& text)
{
if (!currentDive)
return;
- EDIT_NOTES(buddy, text);
+ EDIT_TEXT(currentDive->buddy, text);
}
void MainTab::on_divemaster_textChanged(const QString& text)
{
if (!currentDive)
return;
- EDIT_NOTES(divemaster, text);
+ EDIT_TEXT(currentDive->divemaster, text);
}
void MainTab::on_location_textChanged(const QString& text)
{
- if (!currentDive)
- return;
- EDIT_NOTES(location, text);
+ if (editMode == TRIP && mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
+ // we are editing a trip
+ dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin();
+ EDIT_TEXT(currentTrip->location, text);
+ } else if (editMode == DIVE){
+ if (!currentDive)
+ return;
+ EDIT_TEXT(currentDive->location, text);
+ }
}
void MainTab::on_suit_textChanged(const QString& text)
{
if (!currentDive)
return;
- EDIT_NOTES(suit, text);
+ EDIT_TEXT(currentDive->suit, text);
}
void MainTab::on_notes_textChanged()
{
- if (!currentDive)
- return;
- EDIT_NOTES(notes, ui->notes->toPlainText());
+ if (editMode == TRIP && mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
+ // we are editing a trip
+ dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin();
+ EDIT_TEXT(currentTrip->notes, ui->notes->toPlainText());
+ } else if (editMode == DIVE) {
+ if (!currentDive)
+ return;
+ EDIT_TEXT(currentDive->notes, ui->notes->toPlainText());
+ }
}
-#undef EDIT_NOTES
+#undef EDIT_TEXT
void MainTab::on_rating_valueChanged(int value)
{
@@ -418,3 +479,45 @@ void MainTab::on_visibility_valueChanged(int value)
return;
currentDive->visibility = value;
}
+
+void MainTab::hideEvent(QHideEvent* event)
+{
+ QSettings s;
+ s.beginGroup("MainTab");
+ s.beginGroup("Cylinders");
+ for (int i = 0; i < CylindersModel::COLUMNS; i++) {
+ s.setValue(QString("colwidth%1").arg(i), ui->cylinders->columnWidth(i));
+ }
+ s.endGroup();
+ s.beginGroup("Weights");
+ for (int i = 0; i < WeightModel::COLUMNS; i++) {
+ s.setValue(QString("colwidth%1").arg(i), ui->weights->columnWidth(i));
+ }
+ s.endGroup();
+ s.sync();
+}
+
+void MainTab::initialUiSetup()
+{
+ QSettings s;
+ s.beginGroup("MainTab");
+ s.beginGroup("Cylinders");
+ for (int i = 0; i < CylindersModel::COLUMNS; i++) {
+ QVariant width = s.value(QString("colwidth%1").arg(i));
+ if (width.isValid())
+ ui->cylinders->setColumnWidth(i, width.toInt());
+ else
+ ui->cylinders->resizeColumnToContents(i);
+ }
+ s.endGroup();
+ s.beginGroup("Weights");
+ for (int i = 0; i < WeightModel::COLUMNS; i++) {
+ QVariant width = s.value(QString("colwidth%1").arg(i));
+ if (width.isValid())
+ ui->weights->setColumnWidth(i, width.toInt());
+ else
+ ui->weights->resizeColumnToContents(i);
+ }
+ s.endGroup();
+
+}