summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2013-11-07 11:37:27 -0500
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-11-09 15:30:51 +0900
commitd84cdb655e883960f783e2cb55e13a9f21f7d4c2 (patch)
tree0532f6c0b2d8eb0ffc8e79afd3f0a88135c36043
parent460aa4c1bdee64f25e1c846ac9a6182e4e8e9820 (diff)
downloadsubsurface-d84cdb655e883960f783e2cb55e13a9f21f7d4c2.tar.gz
Fix inconsistent position of screen splitters
I basically rewrote the way we handled the splitters. It now uses a state to know what it's doing, and will only update the value of the saved-to-disk splitter size if the state shows the splitters (currently only VIEWALL), where all the other states should hide the splitters, and the values of the splitters don't matter. Fixes #225 Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--qt-ui/mainwindow.cpp81
-rw-r--r--qt-ui/mainwindow.h4
2 files changed, 55 insertions, 30 deletions
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 4489569fb..ed56d58c0 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -349,12 +349,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 +364,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 +379,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,29 +557,15 @@ 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);
+ 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;
}
- 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 */
@@ -625,10 +645,11 @@ 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");
diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h
index e35230a3c..9a8deb1a0 100644
--- a/qt-ui/mainwindow.h
+++ b/qt-ui/mainwindow.h
@@ -36,6 +36,7 @@ public:
enum {COLLAPSED, EXPANDED};
enum StackWidgetIndexes{ PROFILE, PLANNERPROFILE};
enum InfoWidgetIndexes{ MAINTAB, PLANNERWIDGET};
+ enum CurrentState{ VIEWALL, GLOBE_MAXIMIZED, INFO_MAXIMIZED, PROFILE_MAXIMIZED, LIST_MAXIMIZED};
MainWindow();
ProfileGraphicsView *graphics();
@@ -116,12 +117,15 @@ private:
QAction *actionNextDive;
QAction *actionPreviousDive;
QWebView *helpView;
+ CurrentState state;
QString filter();
bool askSaveChanges();
void writeSettings();
void redrawProfile();
void file_save();
void file_save_as();
+ void beginChangeState(CurrentState s);
+ void saveSplitterSizes();
};
MainWindow *mainWindow();