diff options
Diffstat (limited to 'qt-ui/mainwindow.cpp')
-rw-r--r-- | qt-ui/mainwindow.cpp | 129 |
1 files changed, 74 insertions, 55 deletions
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 4489569fb..61fa76bfe 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -54,12 +54,14 @@ MainWindow::MainWindow() : helpView(0) connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), ui.ListWidget, SLOT(reloadHeaderActions())); connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), ui.ProfileWidget, SLOT(refresh())); ui.mainErrorMessage->hide(); - ui.ListWidget->reload(DiveTripModel::TREE); initialUiSetup(); readSettings(); + ui.ListWidget->reload(DiveTripModel::TREE); ui.ListWidget->reloadHeaderActions(); ui.ListWidget->setFocus(); ui.globe->reload(); + ui.ListWidget->expand(ui.ListWidget->model()->index(0,0)); + ui.ListWidget->scrollTo(ui.ListWidget->model()->index(0,0), QAbstractItemView::PositionAtCenter); } // this gets called after we download dives from a divecomputer @@ -217,8 +219,13 @@ void MainWindow::enableDcShortcuts() void MainWindow::on_actionDivePlanner_triggered() { + if(DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING){ + QMessageBox::warning(this, tr("Warning"), "First finish the current edition before trying to do another." ); + return; + } disableDcShortcuts(); - DivePlannerPointsModel::instance()->setPlanMode(true); + DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN); + DivePlannerPointsModel::instance()->clear(); ui.stackedWidget->setCurrentIndex(PLANNERPROFILE); ui.infoPane->setCurrentIndex(PLANNERWIDGET); } @@ -269,6 +276,11 @@ void MainWindow::on_actionEditDeviceNames_triggered() void MainWindow::on_actionAddDive_triggered() { + if(DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING){ + QMessageBox::warning(this, tr("Warning"), "First finish the current edition before trying to do another." ); + return; + } + // clear the selection for (int i = 0; i < dive_table.nr; i++) { struct dive *d = get_dive(i); @@ -276,7 +288,8 @@ void MainWindow::on_actionAddDive_triggered() deselect_dive(i); } disableDcShortcuts(); - DivePlannerPointsModel::instance()->setPlanMode(false); + DivePlannerPointsModel::instance()->clear(); + DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD); // now cheat - create one dive that we use to store the info tab data in struct dive *dive = alloc_dive(); dive->when = QDateTime::currentMSecsSinceEpoch() / 1000L + gettimezoneoffset(); @@ -349,12 +362,14 @@ void MainWindow::on_infoProfileSplitter_splitterMoved(int pos, int idx) #define BEHAVIOR QList<int>() void MainWindow::on_actionViewList_triggered() { + beginChangeState(LIST_MAXIMIZED); ui.listGlobeSplitter->setSizes( BEHAVIOR << EXPANDED << COLLAPSED); ui.mainSplitter->setSizes( BEHAVIOR << COLLAPSED << EXPANDED); } void MainWindow::on_actionViewProfile_triggered() { + beginChangeState(PROFILE_MAXIMIZED); ui.infoProfileSplitter->setSizes(BEHAVIOR << COLLAPSED << EXPANDED); ui.mainSplitter->setSizes( BEHAVIOR << EXPANDED << COLLAPSED); redrawProfile(); @@ -362,12 +377,14 @@ void MainWindow::on_actionViewProfile_triggered() void MainWindow::on_actionViewInfo_triggered() { + beginChangeState(INFO_MAXIMIZED); ui.infoProfileSplitter->setSizes(BEHAVIOR << EXPANDED << COLLAPSED); ui.mainSplitter->setSizes( BEHAVIOR << EXPANDED << COLLAPSED); } void MainWindow::on_actionViewGlobe_triggered() { + beginChangeState(GLOBE_MAXIMIZED); ui.mainSplitter->setSizes(BEHAVIOR << COLLAPSED << EXPANDED); ui.listGlobeSplitter->setSizes(BEHAVIOR << COLLAPSED << EXPANDED); } @@ -375,17 +392,47 @@ void MainWindow::on_actionViewGlobe_triggered() void MainWindow::on_actionViewAll_triggered() { - // big number squash the info profile to it's minimum. - ui.infoProfileSplitter->setSizes(QList<int>() << 1 << 20000); + beginChangeState(VIEWALL); + QSettings settings; + settings.beginGroup("MainWindow"); + if (settings.value("mainSplitter").isValid()){ + ui.mainSplitter->restoreState(settings.value("mainSplitter").toByteArray()); + ui.infoProfileSplitter->restoreState(settings.value("infoProfileSplitter").toByteArray()); + ui.listGlobeSplitter->restoreState(settings.value("listGlobeSplitter").toByteArray()); + } else { + QList<int> mainSizes; + mainSizes.append( qApp->desktop()->size().height() * 0.7 ); + mainSizes.append( qApp->desktop()->size().height() * 0.3 ); + ui.mainSplitter->setSizes( mainSizes ); - // big number squash the globe view. - ui.listGlobeSplitter->setSizes(QList<int>() << 2000 << 1 ); + QList<int> infoProfileSizes; + infoProfileSizes.append( qApp->desktop()->size().width() * 0.3 ); + infoProfileSizes.append( qApp->desktop()->size().width() * 0.7 ); + ui.infoProfileSplitter->setSizes(infoProfileSizes); - // half and half? - ui.mainSplitter->setSizes( QList<int>() << 1 << 1); + QList<int> listGlobeSizes; + listGlobeSizes.append( qApp->desktop()->size().width() * 0.7 ); + listGlobeSizes.append( qApp->desktop()->size().width() * 0.3 ); + ui.listGlobeSplitter->setSizes(listGlobeSizes); + } redrawProfile(); } +void MainWindow::beginChangeState(CurrentState s){ + if (state == VIEWALL){ + saveSplitterSizes(); + } + state = s; +} + +void MainWindow::saveSplitterSizes(){ + QSettings settings; + settings.beginGroup("MainWindow"); + settings.setValue("mainSplitter", ui.mainSplitter->saveState()); + settings.setValue("infoProfileSplitter", ui.infoProfileSplitter->saveState()); + settings.setValue("listGlobeSplitter", ui.listGlobeSplitter->saveState()); +} + void MainWindow::on_actionPreviousDC_triggered() { dc_number--; @@ -523,43 +570,14 @@ void MainWindow::initialUiSetup() QSize sz = settings.value("size", qApp->desktop()->size()).value<QSize>(); resize(sz); - if (settings.value("mainSplitter").isValid()){ - ui.mainSplitter->restoreState(settings.value("mainSplitter").toByteArray()); - ui.infoProfileSplitter->restoreState(settings.value("infoProfileSplitter").toByteArray()); - ui.listGlobeSplitter->restoreState(settings.value("listGlobeSplitter").toByteArray()); - } else { - QList<int> mainSizes; - mainSizes.append( qApp->desktop()->size().height() * 0.7 ); - mainSizes.append( qApp->desktop()->size().height() * 0.3 ); - ui.mainSplitter->setSizes( mainSizes ); - - QList<int> infoProfileSizes; - infoProfileSizes.append( qApp->desktop()->size().width() * 0.3 ); - infoProfileSizes.append( qApp->desktop()->size().width() * 0.7 ); - ui.infoProfileSplitter->setSizes(infoProfileSizes); - - QList<int> listGlobeSizes; - listGlobeSizes.append( qApp->desktop()->size().width() * 0.7 ); - listGlobeSizes.append( qApp->desktop()->size().width() * 0.3 ); - ui.listGlobeSplitter->setSizes(listGlobeSizes); - } - - settings.endGroup(); - - settings.beginGroup("ListWidget"); - /* if no width are set, use the calculated width for each column; - * for that to work we need to temporarily expand all rows */ - ui.ListWidget->expandAll(); - for (i = DiveTripModel::NR; i < DiveTripModel::COLUMNS; i++) { - QVariant width = settings.value(QString("colwidth%1").arg(i)); - if (width.isValid()) - ui.ListWidget->setColumnWidth(i, width.toInt()); - else - ui.ListWidget->resizeColumnToContents(i); + CurrentState state = (CurrentState) settings.value("lastState", 0).toInt(); + switch(state){ + case VIEWALL: on_actionViewAll_triggered(); break; + case GLOBE_MAXIMIZED : on_actionViewGlobe_triggered(); break; + case INFO_MAXIMIZED : on_actionViewInfo_triggered(); break; + case LIST_MAXIMIZED : on_actionViewList_triggered(); break; + case PROFILE_MAXIMIZED : on_actionViewProfile_triggered(); break; } - ui.ListWidget->collapseAll(); - ui.ListWidget->expand(ui.ListWidget->model()->index(0,0)); - ui.ListWidget->scrollTo(ui.ListWidget->model()->index(0,0), QAbstractItemView::PositionAtCenter); settings.endGroup(); } @@ -625,17 +643,13 @@ void MainWindow::writeSettings() QSettings settings; settings.beginGroup("MainWindow"); + settings.setValue("lastState", (int) state); settings.setValue("size",size()); - settings.setValue("mainSplitter", ui.mainSplitter->saveState()); - settings.setValue("infoProfileSplitter", ui.infoProfileSplitter->saveState()); - settings.setValue("listGlobeSplitter", ui.listGlobeSplitter->saveState()); + if (state == VIEWALL){ + saveSplitterSizes(); + } settings.endGroup(); - settings.beginGroup("ListWidget"); - for (i = DiveTripModel::NR; i < DiveTripModel::COLUMNS; i++) - if (!ui.ListWidget->isColumnHidden(i)) - settings.setValue(QString("colwidth%1").arg(i), ui.ListWidget->columnWidth(i)); - settings.endGroup(); settings.beginGroup("Units"); SAVE_VALUE("length", units.length); SAVE_VALUE("pressure", units.pressure); @@ -822,12 +836,17 @@ void MainWindow::on_actionImportCSV_triggered() void MainWindow::editCurrentDive() { + if(DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING){ + QMessageBox::warning(this, tr("Warning"), "First finish the current edition before trying to do another." ); + return; + } + struct dive *d = current_dive; QString defaultDC(d->dc.model); - + DivePlannerPointsModel::instance()->clear(); if (defaultDC == "manually added dive"){ disableDcShortcuts(); - DivePlannerPointsModel::instance()->setPlanMode(false); + DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD); ui.stackedWidget->setCurrentIndex(PLANNERPROFILE); // Planner. ui.infoPane->setCurrentIndex(MAINTAB); DivePlannerPointsModel::instance()->loadFromDive(d); |