Skip to content

Commit

Permalink
preferences feature added
Browse files Browse the repository at this point in the history
Signed-off-by: Vinayakjeet Singh Karki <[email protected]>
  • Loading branch information
vinayakjeet committed Mar 29, 2024
1 parent 782aa89 commit 368d0de
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 18 deletions.
20 changes: 18 additions & 2 deletions avogadro/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
******************************************************************************/

#include "mainwindow.h"

#include "preferencesdialog.h"
#include "aboutdialog.h"
#include "avogadroappconfig.h"
#include "backgroundfileformat.h"
Expand Down Expand Up @@ -300,7 +300,7 @@ MainWindow::MainWindow(const QStringList& fileNames, bool disableSettings)

// Now set up the interface.
setupInterface();

initializeActions();
// Build up the standard menus, incorporate dynamic menus.
buildMenu();
updateRecentFiles();
Expand Down Expand Up @@ -356,7 +356,23 @@ MainWindow::~MainWindow()
delete m_menuBuilder;
delete m_viewFactory;
}
void MainWindow::initializeActions()
{
// Example initialization, adjust according to your needs
m_actionPreferences = new QAction(tr("&Preferences"), this);
connect(m_actionPreferences, &QAction::triggered, this, &MainWindow::showPreferencesDialog);
// Add m_actionPreferences to the appropriate menu or toolbar
}

void MainWindow::showPreferencesDialog()
{
PreferencesDialog dialog(this);
dialog.loadSettings();

if (dialog.exec() == QDialog::Accepted) {
dialog.applySettings(); // Apply and save settings
}
}
void MainWindow::setupInterface()
{
// We take care of setting up the main interface here, along with any custom
Expand Down
11 changes: 6 additions & 5 deletions avogadro/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <QtCore/QStringList>
#include <QtCore/QVariantMap>
#include <QtWidgets/QMainWindow>

#include "preferencesdialog.h"
#ifdef QTTESTING
class pqTestUtility;
#endif
Expand All @@ -19,9 +19,9 @@ class QThread;
class QTreeView;
class QNetworkAccessManager;
class QNetworkReply;

class QAction;
namespace Ui {
class AboutDialog;
class AboutDialog;
}

namespace Avogadro {
Expand Down Expand Up @@ -74,7 +74,8 @@ public slots:
* Update internal state to reflect that the molecule has been modified.
*/
void markMoleculeDirty();

void showPreferencesDialog();
void initializeActions();
/**
* Update internal state to reflect that the molecule is not modified.
*/
Expand Down Expand Up @@ -442,7 +443,7 @@ private slots:
QAction* m_copyImage;
QAction* m_viewPerspective;
QAction* m_viewOrthographic;

QAction* m_actionPreferences;
ViewFactory* m_viewFactory;

QNetworkAccessManager* m_network = nullptr;
Expand Down
59 changes: 48 additions & 11 deletions avogadro/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,14 @@
<addaction name="actionCopy"/>
<addaction name="actionPaste"/>
<addaction name="actionClear"/>
</widget>
<widget class="QMenu" name="menuSelect">
<property name="title">
<string>&amp;Select</string>
</property>
</widget>
<addaction name="menuFile"/>

<addaction name="separator"/>
<addaction name="menuFile"/>
<addaction name="menuEdit"/>
<addaction name="menuView"/>
<addaction name="menuBuild"/>
<addaction name="menuSelect"/>
<addaction name="actionPreferences"/>
</widget>
<action name="actionOpen">
<property name="text">
Expand Down Expand Up @@ -323,6 +320,35 @@
<string>&amp;Import</string>
</property>
</action>
<action name="actionPreferences">
<property name="text">
<string>Preferences…</string>
</property>
<property name="icon">
<iconset>
<normaloff>:icons/preferences-icon.png</normaloff>:icons/preferences-icon.png
</iconset>
</property>
<property name="shortcut">
<string>Ctrl+P</string>
</property>
</action>




<property name="text">
<string>Preferences…</string>
</property>
<property name="icon">
<iconset>
<normaloff>:icons/preferences-icon.png</normaloff>:icons/preferences-icon.png</iconset>
</property>
-->
</action>
<string>Preferences…</string>
</property>
</action>
<action name="actionExport">
<property name="text">
<string>&amp;Export</string>
Expand All @@ -337,6 +363,7 @@
<sender>actionClose</sender>
<signal>triggered()</signal>
<receiver>MainWindow</receiver>
<slot>showPreferencesDialog()</slot>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
Expand All @@ -350,10 +377,20 @@
</hints>
</connection>
<connection>
<sender>actionQuit</sender>
<signal>triggered()</signal>
<receiver>MainWindow</receiver>
<slot>close()</slot>
<sender>actionQuit</sender>
<signal>triggered()</signal>
<receiver>MainWindow</receiver>
<slot>close()</slot>
</connection>

<connection>
<sender>actionPreferences</sender>
<signal>triggered()</signal>
<receiver>MainWindow</receiver>
<slot>showPreferencesDialog()</slot>
</connection>
</connections>

<hints>
<hint type="sourcelabel">
<x>-1</x>
Expand Down

0 comments on commit 368d0de

Please sign in to comment.