Commit 1032899a authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[ADD] - added preferences to walnut.cfg allowing the user to turn off the...

[ADD] - added preferences to walnut.cfg allowing the user to turn off the window state load/save feature and to specify some name prefix for the state which allows developer to have different window configurations for different builds.
parent 11cbea9c
...@@ -61,6 +61,14 @@ deleteROIKey = Del ...@@ -61,6 +61,14 @@ deleteROIKey = Del
#################################################################### ####################################################################
# Other GUI settings # Other GUI settings
# With this option, you are able to let OpenWalnut load another window state. OpenWalnut stores and resotres the window
# positions, sizes and so on on quit and startup. If you are an developer and have multiple compiled OW versions and you want
# each version to have other window state files set some name here which is unique.
# stateNamePostfix = someName
# This option allows you to turn off that the GUI stores its state.
# saveState = no
# hideMenuBar = yes # hide the menu bar # hideMenuBar = yes # hide the menu bar
[ge] ## Settings for the graphics engine [ge] ## Settings for the graphics engine
......
...@@ -64,6 +64,14 @@ deleteROIKey = Del ...@@ -64,6 +64,14 @@ deleteROIKey = Del
#################################################################### ####################################################################
# Other GUI settings # Other GUI settings
# With this option, you are able to let OpenWalnut load another window state. OpenWalnut stores and resotres the window
# positions, sizes and so on on quit and startup. If you are an developer and have multiple compiled OW versions and you want
# each version to have other window state files set some name here which is unique.
# stateNamePostfix = someName
# This option allows you to turn off that the GUI stores its state.
# saveState = no
# hideMenuBar = yes # hide the menu bar # hideMenuBar = yes # hide the menu bar
[ge] ## Settings for the graphics engine [ge] ## Settings for the graphics engine
......
...@@ -281,10 +281,7 @@ void WMainWindow::setupGUI() ...@@ -281,10 +281,7 @@ void WMainWindow::setupGUI()
} }
// after creating the GUI, restore its saved state // after creating the GUI, restore its saved state
QSettings setting( "OpenWalnut.org", "OpenWalnut" ); restoreSavedState();
QByteArray state = setting.value( "MainWindowState", "" ).toByteArray();
restoreGeometry( setting.value( "MainWindowGeometry", "" ).toByteArray() );
restoreState( state );
} }
void WMainWindow::setupPermanentToolBar() void WMainWindow::setupPermanentToolBar()
...@@ -942,12 +939,7 @@ void WMainWindow::closeEvent( QCloseEvent* e ) ...@@ -942,12 +939,7 @@ void WMainWindow::closeEvent( QCloseEvent* e )
// handle close event // handle close event
if( reallyClose ) if( reallyClose )
{ {
// this saves the window state to some common location on the target OS in user scope. saveWindowState();
QByteArray state = saveState();
QSettings setting( "OpenWalnut.org", "OpenWalnut" );
setting.setValue( "MainWindowState", state );
// NOTE: Qt Doc says that saveState also saves geometry. But this somehow is wrong (at least for 4.6.3)
setting.setValue( "MainWindowGeometry", saveGeometry() );
// signal everybody to shut down properly. // signal everybody to shut down properly.
WKernel::getRunningKernel()->finalize(); WKernel::getRunningKernel()->finalize();
...@@ -1123,3 +1115,51 @@ void WMainWindow::openConfigDialog() ...@@ -1123,3 +1115,51 @@ void WMainWindow::openConfigDialog()
m_configWidget->initAndShow(); m_configWidget->initAndShow();
} }
void WMainWindow::restoreSavedState()
{
// should we do it?
bool saveStateEnabled = true;
WPreferences::getPreference( "qt4gui.saveState", &saveStateEnabled );
if ( !saveStateEnabled )
{
return;
}
// the state name postfix allows especially developers to have multiple OW with different GUI settings.
std::string postfix = "";
if ( WPreferences::getPreference( "qt4gui.stateNamePostfix", &postfix ) )
{
postfix = "-" + postfix;
}
QSettings setting( "OpenWalnut.org", "OpenWalnut" + QString::fromStdString( postfix ) );
QByteArray state = setting.value( "MainWindowState", "" ).toByteArray();
restoreGeometry( setting.value( "MainWindowGeometry", "" ).toByteArray() );
restoreState( state );
}
void WMainWindow::saveWindowState()
{
// should we do it?
bool saveStateEnabled = true;
WPreferences::getPreference( "qt4gui.saveState", &saveStateEnabled );
if ( !saveStateEnabled )
{
return;
}
// the state name postfix allows especially developers to have multiple OW with different GUI settings.
std::string postfix = "";
if ( WPreferences::getPreference( "qt4gui.stateNamePostfix", &postfix ) )
{
postfix = "-" + postfix;
}
// this saves the window state to some common location on the target OS in user scope.
QByteArray state = saveState();
QSettings setting( "OpenWalnut.org", "OpenWalnut" + QString::fromStdString( postfix ) );
setting.setValue( "MainWindowState", state );
// NOTE: Qt Doc says that saveState also saves geometry. But this somehow is wrong (at least for 4.6.3)
setting.setValue( "MainWindowGeometry", saveGeometry() );
}
...@@ -371,6 +371,16 @@ private: ...@@ -371,6 +371,16 @@ private:
* if the module is removed. * if the module is removed.
*/ */
std::map< boost::shared_ptr< WPropertyBase >, WQtPropertyBoolAction* > propertyActionMap; std::map< boost::shared_ptr< WPropertyBase >, WQtPropertyBoolAction* > propertyActionMap;
/**
* Loads the window states and geometries from a file.
*/
void restoreSavedState();
/**
* Saves the current window states and geometries to a file.
*/
void saveWindowState();
}; };
#endif // WMAINWINDOW_H #endif // WMAINWINDOW_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment