Feature: View Menu: Restore Defaults

Fixes issue 68
This commit is contained in:
Srivats P. 2015-05-03 23:44:35 +05:30
parent 05b73a5390
commit 2c28433533
3 changed files with 30 additions and 4 deletions

View File

@ -82,6 +82,11 @@ MainWindow::MainWindow(QWidget *parent)
portsDock->setWidget(portsWindow);
addDockWidget(Qt::TopDockWidgetArea, portsDock);
// Save the default window geometry and layout ...
defaultGeometry_ = geometry();
defaultLayout_ = saveState(0);
// ... before restoring the last used settings
QRect geom = appSettings->value(kApplicationWindowGeometryKey).toRect();
if (!geom.isNull())
setGeometry(geom);
@ -135,6 +140,17 @@ void MainWindow::on_actionPreferences_triggered()
delete preferences;
}
void MainWindow::on_actionViewRestoreDefaults_triggered()
{
// Use the saved default geometry/layout, however keep the
// window location same
defaultGeometry_.moveTo(geometry().topLeft());
setGeometry(defaultGeometry_);
restoreState(defaultLayout_, 0);
actionViewShowMyReservedPortsOnly->setChecked(false);
}
void MainWindow::on_actionHelpAbout_triggered()
{
QDialog *aboutDialog = new QDialog;

View File

@ -40,12 +40,16 @@ private:
QDockWidget *portsDock;
QDockWidget *statsDock;
QRect defaultGeometry_;
QByteArray defaultLayout_;
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
public slots:
void on_actionPreferences_triggered();
void on_actionViewRestoreDefaults_triggered();
void on_actionHelpAbout_triggered();
private slots:

View File

@ -27,7 +27,7 @@
</property>
<widget class="QMenu" name="menuFile" >
<property name="title" >
<string>File</string>
<string>&amp;File</string>
</property>
<addaction name="separator" />
<addaction name="actionPreferences" />
@ -35,7 +35,7 @@
</widget>
<widget class="QMenu" name="menuHelp" >
<property name="title" >
<string>Help</string>
<string>&amp;Help</string>
</property>
<addaction name="actionHelpAbout" />
<addaction name="actionAboutQt" />
@ -45,6 +45,7 @@
<string>&amp;View</string>
</property>
<addaction name="actionViewShowMyReservedPortsOnly" />
<addaction name="actionViewRestoreDefaults" />
</widget>
<addaction name="menuFile" />
<addaction name="menuView" />
@ -80,7 +81,7 @@
<iconset resource="ostinato.qrc" >:/icons/qt.png</iconset>
</property>
<property name="text" >
<string>About Qt</string>
<string>About &amp;Qt</string>
</property>
</action>
<action name="actionViewShowMyReservedPortsOnly" >
@ -88,7 +89,12 @@
<bool>true</bool>
</property>
<property name="text" >
<string>Show My &amp;Reserved Ports Only</string>
<string>Show &amp;My Reserved Ports Only</string>
</property>
</action>
<action name="actionViewRestoreDefaults" >
<property name="text" >
<string>Restore &amp;Defaults</string>
</property>
</action>
</widget>