18 setWindowTitle(title);
39 QMainWindow::closeEvent(event);
43 QString MainWindow::settingsFileName(QString objectTitle) {
44 if (QCoreApplication::applicationName() ==
"") {
45 throw IException(IException::Programmer,
"You must set QApplication's "
46 "application name before using the Isis::MainWindow class. Window "
47 "state and geometry can not be saved and restored", _FILEINFO_);
50 if (objectTitle ==
"") {
51 throw IException(IException::Programmer,
52 tr(
"You must provide a valid objectTitle to MainWindow::settingsFileName"),
56 QDir programSettings =
57 QDir(FileName(
"$HOME/.Isis/" + QCoreApplication::applicationName() +
"/").path());
58 QString windowSettings = programSettings.filePath(objectTitle +
".config");
60 return windowSettings;
82 QSettings settings(settingsFileName(), QSettings::NativeFormat);
83 restoreGeometry(settings.value(
"geometry").toByteArray());
84 restoreState(settings.value(
"windowState").toByteArray());
89 if (!settings.value(
"pos").toPoint().isNull())
90 move(settings.value(
"pos").toPoint());
92 resize(settings.value(
"size", defaultSize).toSize());
96 QString MainWindow::settingsFileName()
const {
97 if (QCoreApplication::applicationName() ==
"") {
98 throw IException(IException::Programmer,
"You must set QApplication's "
99 "application name before using the Isis::MainWindow class. Window "
100 "state and geometry can not be saved and restored", _FILEINFO_);
103 if (objectName() ==
"") {
104 throw IException(IException::Programmer,
105 tr(
"You must set the objectName of the widget titled [%1] before "
106 "using the instance. Window state and geometry can not be saved and "
107 "restored").arg(windowTitle()), _FILEINFO_);
110 QDir programSettings =
111 QDir(FileName(
"$HOME/.Isis/" + QCoreApplication::applicationName() +
"/").path());
112 QString windowSettings = programSettings.filePath(objectName() +
".config");
114 return windowSettings;
126 QSettings settings(settingsFileName(), QSettings::NativeFormat);
128 settings.setValue(
"geometry", saveGeometry());
129 settings.setValue(
"windowState", saveState());
130 settings.setValue(
"size", size());
131 settings.setValue(
"pos", pos());
MainWindow(QString title, QWidget *parent=0, Qt::WindowFlags flags=Qt::WindowFlags())
Mainwindow constructor.
virtual void closeEvent(QCloseEvent *event)
This method is overridden so that we can be sure to write the current settings of the Main window.
virtual ~MainWindow()
Free allocated memory by from this instance.
virtual void readSettings(QSize defaultSize=QSize())
This method ensure that the settings get written even if the Main window was only hidden,...
virtual void writeSettings() const
This method is called when the Main window is closed or hidden to write the size and location setting...
This is free and unencumbered software released into the public domain.