Window's position, size and maximized status are now saved and restored across executions

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/3/head
Michele Calgaro 2 years ago
parent e7b18a1f57
commit 191e11f6dc
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -185,31 +185,18 @@ void MainWindow::initMainWindow()
_actionClearRecentlyOpenedListId = popupMenuRecentlyOpenedFiles->idAt( _actionClearRecentlyOpenedListId = popupMenuRecentlyOpenedFiles->idAt(
popupMenuRecentlyOpenedFiles->count() - 1); popupMenuRecentlyOpenedFiles->count() - 1);
///-- // Handle last opened window size // Handle last opened window size
///-- // ------------------------------ // ------------------------------
///-- bool maximized = _settings->getValueByName("maximized").toBool(); bool maximized = m_settings->getValueByName("WindowIsMaximized").toBool();
///-- TQPoint pos = _settings->getValueByName("position").toPoint(); TQPoint pos = m_settings->getValueByName("WindowPosition").toPoint();
///-- TQSize size = _settings->getValueByName("size").toSize(); TQSize size = m_settings->getValueByName("WindowSize").toSize();
///-- resize(size); resize(size);
///-- move(pos); move(pos);
///-- if (maximized) if (maximized)
///-- { {
///-- showMaximized(); showMaximized();
///-- } }
///--
///-- // Handle if first run of this version
///-- // -----------------------------------
///-- TQString readVersion = _settings->getValueByName("version").toString();
///-- // If version strings are not equal set first run true.
///-- if (readVersion != PROGRAM_VERSION_STRING)
///-- {
///-- _isFirstRunOfThisVersion = true;
///-- }
///-- else
///-- {
///-- _isFirstRunOfThisVersion = false;
///-- }
///--
///-- // Get last selected file encoding ///-- // Get last selected file encoding
///-- // ------------------------------- ///-- // -------------------------------
///-- _currentEncoding = _settings->getValueByName("encoding").toString(); ///-- _currentEncoding = _settings->getValueByName("encoding").toString();
@ -1078,44 +1065,44 @@ void MainWindow::exportToHTML()
///-- // Update the mainwindow title to show the name of the loaded source code file. ///-- // Update the mainwindow title to show the name of the loaded source code file.
///-- updateWindowTitle(); ///-- updateWindowTitle();
///-- } ///-- }
///--
///-- /* /*
///-- \brief Saves the _settings for the main application to the file "UniversalIndentGUI.ini". \brief Saves the m_settings for the main application to the file "UniversalIndentGUI.ini".
///--
///-- Settings are for example last selected indenter, last loaded config file and so on. Settings are for example last selected indenter, last loaded config file and so on.
///-- */ */
///-- void MainWindow::saveSettings() void MainWindow::saveSettings()
///-- { {
///-- _settings->setValueByName("encoding", _currentEncoding); ///-- m_settings->setValueByName("encoding", _currentEncoding);
///-- _settings->setValueByName("version", PROGRAM_VERSION_STRING); ///-- m_settings->setValueByName("version", PROGRAM_VERSION_STRING);
///-- _settings->setValueByName("maximized", isMaximized()); m_settings->setValueByName("WindowIsMaximized", isMaximized());
///-- if (!isMaximized()) if (!isMaximized())
///-- { {
///-- _settings->setValueByName("position", pos()); m_settings->setValueByName("WindowPosition", pos());
///-- _settings->setValueByName("size", size()); m_settings->setValueByName("WindowSize", size());
///-- } }
///-- _settings->setValueByName("MainWindowState", saveState()); ///-- m_settings->setValueByName("MainWindowState", saveState());
///-- ///--
///-- // Also save the syntax highlight style for all lexers. ///-- // Also save the syntax highlight style for all lexers.
///-- _highlighter->writeCurrentSettings(""); ///-- _highlighter->writeCurrentSettings("");
///-- } }
///--
///-- /* /*
///-- \brief Is always called when the program is quit. Calls the saveSettings function before really quits. \brief Called when the program exits. Calls the saveSettings function before really quits.
///-- */ */
///-- void MainWindow::closeEvent(TQCloseEvent *event) void MainWindow::closeEvent(TQCloseEvent *event)
///-- { {
///-- if (maybeSave()) if (maybeSave())
///-- { {
///-- saveSettings(); saveSettings();
///-- event->accept(); event->accept();
///-- } }
///-- else else
///-- { {
///-- event->ignore(); event->ignore();
///-- } }
///-- } }
///--
///-- /* ///-- /*
///-- \brief This function is setup to capture tooltip events. ///-- \brief This function is setup to capture tooltip events.
///-- ///--
@ -1143,12 +1130,13 @@ void MainWindow::exportToHTML()
///-- return TQMainWindow::eventFilter(obj, event); ///-- return TQMainWindow::eventFilter(obj, event);
///-- } ///-- }
///-- } ///-- }
///--
///-- /* /*
///-- \brief Is called at application exit and asks whether to save the source code file, if it has been changed. \brief Is called at application exit and asks whether to save the source code file,
///-- */ if it has been changed.
///-- bool MainWindow::maybeSave() */
///-- { bool MainWindow::maybeSave()
{
///-- if (isWindowModified()) ///-- if (isWindowModified())
///-- { ///-- {
///-- int ret = TQMessageBox::warning(this, tr("Modified code"), tr( ///-- int ret = TQMessageBox::warning(this, tr("Modified code"), tr(
@ -1163,9 +1151,9 @@ void MainWindow::exportToHTML()
///-- return false; ///-- return false;
///-- } ///-- }
///-- } ///-- }
///-- return true; return true;
///-- } }
///--
///-- /* ///-- /*
///-- \brief This slot is called whenever a language is selected in the menu. It tries to find the ///-- \brief This slot is called whenever a language is selected in the menu. It tries to find the
///-- corresponding action in the languageInfoList and sets the language. ///-- corresponding action in the languageInfoList and sets the language.

@ -50,7 +50,7 @@ class MainWindow : public MainWindowBase
~MainWindow(); ~MainWindow();
///-- protected: ///-- protected:
///-- void closeEvent(TQCloseEvent *event); void closeEvent(TQCloseEvent *event);
///-- bool eventFilter(TQObject *obj, TQEvent *event); ///-- bool eventFilter(TQObject *obj, TQEvent *event);
///-- ///--
private slots: private slots:
@ -82,8 +82,8 @@ class MainWindow : public MainWindowBase
///-- TQString openFileDialog(TQString dialogHeaderStr, TQString startPath, TQString fileMaskStr); ///-- TQString openFileDialog(TQString dialogHeaderStr, TQString startPath, TQString fileMaskStr);
///-- void updateWindowTitle(); ///-- void updateWindowTitle();
///-- void loadLastOpenedFile(); ///-- void loadLastOpenedFile();
///-- void saveSettings(); void saveSettings();
///-- bool maybeSave(); bool maybeSave();
///-- void createEncodingMenu(); ///-- void createEncodingMenu();
///-- void createHighlighterMenu(); ///-- void createHighlighterMenu();
///-- bool initApplicationLanguage(); ///-- bool initApplicationLanguage();
@ -120,7 +120,6 @@ class MainWindow : public MainWindowBase
///-- TQActionGroup *_highlighterActionGroup; ///-- TQActionGroup *_highlighterActionGroup;
///-- TQTranslator *_uiGuiTranslator; ///-- TQTranslator *_uiGuiTranslator;
///-- TQTranslator *_qTTranslator; ///-- TQTranslator *_qTTranslator;
///-- bool _isFirstRunOfThisVersion;
///-- ///--
///-- bool _sourceCodeChanged; ///-- bool _sourceCodeChanged;
///-- bool _scrollPositionChanged; ///-- bool _scrollPositionChanged;

@ -23,6 +23,7 @@
#include <tqdatetime.h> #include <tqdatetime.h>
#include <tqdir.h> #include <tqdir.h>
#include <tqpoint.h> #include <tqpoint.h>
#include <tqregexp.h>
#include <tqsettings.h> #include <tqsettings.h>
#include <tqsize.h> #include <tqsize.h>
#include <tqwidget.h> #include <tqwidget.h>
@ -175,13 +176,35 @@ bool UiGuiSettings::setValueByName(const TQString &settingName, TQVariant value)
*/ */
void UiGuiSettings::loadSettings() void UiGuiSettings::loadSettings()
{ {
// Read the version string saved in the settings file. // Read the version string
m_settings["VersionInSettingsFile"] = m_qsettings->readEntry("version", TQString::null); m_settings["VersionInSettingsFile"] = m_qsettings->readEntry("version", TQString::null);
// Read windows last size and position from the settings file. // Read window's maximized status
m_settings["WindowIsMaximized"] = m_qsettings->readBoolEntry("maximized", false); m_settings["WindowIsMaximized"] = m_qsettings->readBoolEntry("maximized", false);
m_settings["WindowPosition"] = m_qsettings->readEntry("position", "@Point(50, 50)");
m_settings["WindowSize"] = m_qsettings->readEntry("size", "@Size(800, 600)"); // Read window's position
TQString positionString = m_qsettings->readEntry("position", "@Point(50 50)");
TQRegExp posrx("@Point\\((-?\\d+)[ \\t]+(-?\\d+)\\)");
TQPoint position(50, 50);
if (posrx.exactMatch(positionString.stripWhiteSpace()))
{
TQStringList posList = posrx.capturedTexts();
position.setX(posList[1].toInt());
position.setY(posList[2].toInt());
}
m_settings["WindowPosition"] = position;
// Read window's size
TQString sizeString = m_qsettings->readEntry("size", "@Size(800 600)");
TQRegExp sizerx("@Size\\((-?\\d+)[ \\t]+(-?\\d+)\\)");
TQSize size(800, 600);
if (sizerx.exactMatch(sizeString.stripWhiteSpace()))
{
TQStringList sizeList = sizerx.capturedTexts();
size.setWidth(sizeList[1].toInt());
size.setHeight(sizeList[2].toInt());
}
m_settings["WindowSize"] = size;
// Read last selected encoding for the opened source code file. // Read last selected encoding for the opened source code file.
m_settings["FileEncoding"] = m_qsettings->readEntry("encoding", "UTF-8"); m_settings["FileEncoding"] = m_qsettings->readEntry("encoding", "UTF-8");
@ -241,13 +264,21 @@ void UiGuiSettings::loadSettings()
*/ */
void UiGuiSettings::saveSettings() void UiGuiSettings::saveSettings()
{ {
// Write the version string saved in the settings file. // Write the version string
m_qsettings->writeEntry("version", m_settings["VersionInSettingsFile"].toString()); m_qsettings->writeEntry("version", m_settings["VersionInSettingsFile"].toString());
// Write windows last size and position from the settings file. // Write window's maximized status
m_qsettings->writeEntry("maximized", m_settings["WindowIsMaximized"].toBool()); m_qsettings->writeEntry("maximized", m_settings["WindowIsMaximized"].toBool());
m_qsettings->writeEntry("position", m_settings["WindowPosition"].toString());
m_qsettings->writeEntry("size", m_settings["WindowSize"].toString()); // Write window's position
TQPoint position = m_settings["WindowPosition"].toPoint();
TQString positionString = TQString("@Point(%1 %2)").arg(position.x()).arg(position.y());
m_qsettings->writeEntry("position", positionString);
// Write window's size
TQSize size = m_settings["WindowSize"].toSize();
TQString sizeString = TQString("@Size(%1 %2)").arg(size.width()).arg(size.height());
m_qsettings->writeEntry("size", sizeString);
// Write last selected encoding for the opened source code file. // Write last selected encoding for the opened source code file.
m_qsettings->writeEntry("encoding", m_settings["FileEncoding"].toString()); m_qsettings->writeEntry("encoding", m_settings["FileEncoding"].toString());

Loading…
Cancel
Save