|
|
|
@ -18,86 +18,86 @@
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "UiGuiSettings.h"
|
|
|
|
|
|
|
|
|
|
#include "SettingsPaths.h"
|
|
|
|
|
|
|
|
|
|
#include <tqsettings.h>
|
|
|
|
|
#include <tqdatetime.h>
|
|
|
|
|
#include <tqdir.h>
|
|
|
|
|
#include <tqpoint.h>
|
|
|
|
|
#include <tqsettings.h>
|
|
|
|
|
#include <tqsize.h>
|
|
|
|
|
#include <tqdir.h>
|
|
|
|
|
#include <tqdate.h>
|
|
|
|
|
#include <tqstringlist.h>
|
|
|
|
|
#include <tqcoreapplication.h>
|
|
|
|
|
#include <tqmetamethod.h>
|
|
|
|
|
#include <tqmetaproperty.h>
|
|
|
|
|
#include <tqwidget.h>
|
|
|
|
|
|
|
|
|
|
//! \defgroup grp_Settings All concerning the settings.
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
/*
|
|
|
|
|
\class UiGuiSettings
|
|
|
|
|
\ingroup grp_Settings
|
|
|
|
|
\brief Handles the settings of the program. Reads them on startup and saves them on exit.
|
|
|
|
|
Is a singleton class and can only be accessed via getInstance().
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Inits the single class instance pointer.
|
|
|
|
|
TQWeakPointer<UiGuiSettings> UiGuiSettings::_instance;
|
|
|
|
|
|
|
|
|
|
UiGuiSettings *UiGuiSettings::m_instance = nullptr;
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
/*
|
|
|
|
|
\brief The constructor for the settings.
|
|
|
|
|
*/
|
|
|
|
|
UiGuiSettings::UiGuiSettings() :
|
|
|
|
|
TQObject()
|
|
|
|
|
UiGuiSettings::UiGuiSettings() : TQObject()
|
|
|
|
|
{
|
|
|
|
|
// Create the main application settings object from the UniversalIndentGUI.ini file.
|
|
|
|
|
_qsettings = new TQSettings(
|
|
|
|
|
SettingsPaths::getSettingsPath() + "/UniversalIndentGUI.ini", TQSettings::IniFormat, this);
|
|
|
|
|
|
|
|
|
|
_indenterDirctoryStr = SettingsPaths::getGlobalFilesPath() + "/indenters";
|
|
|
|
|
// Create the main application settings object from the UniversalIndentGUIrc file.
|
|
|
|
|
m_qsettings = new TQSettings(TQSettings::Ini);
|
|
|
|
|
// The next lines make user the settings are always stored in
|
|
|
|
|
// $HOME/.universalindentgui/universalindentguirc
|
|
|
|
|
m_qsettings->insertSearchPath(TQSettings::Unix, SettingsPaths::getSettingsPath());
|
|
|
|
|
m_qsettings->setPath("UniversalIndentGUI", "UniversalIndentGUI", TQSettings::User);
|
|
|
|
|
// settings are stored in the universalindentguirc file, group UniversalIndentGUI
|
|
|
|
|
m_qsettings->beginGroup("universalindentgui/UniversalIndentGUI");
|
|
|
|
|
|
|
|
|
|
m_indenterDirectoryStr = SettingsPaths::getGlobalFilesPath() + "/indenters";
|
|
|
|
|
readAvailableTranslations();
|
|
|
|
|
initSettings();
|
|
|
|
|
loadSettings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\brief Returns the instance of the settings class. If no instance exists, ONE will be created.
|
|
|
|
|
/*
|
|
|
|
|
\brief Returns the instance of the settings class. If no instance exists, one will be created.
|
|
|
|
|
*/
|
|
|
|
|
TQSharedPointer<UiGuiSettings> UiGuiSettings::getInstance()
|
|
|
|
|
UiGuiSettings* UiGuiSettings::getInstance()
|
|
|
|
|
{
|
|
|
|
|
TQSharedPointer<UiGuiSettings> sharedInstance = _instance.toStrongRef();
|
|
|
|
|
if (sharedInstance.isNull())
|
|
|
|
|
if (!m_instance)
|
|
|
|
|
{
|
|
|
|
|
// Create the settings object, which loads all UiGui settings from a file.
|
|
|
|
|
sharedInstance = TQSharedPointer<UiGuiSettings>(new UiGuiSettings());
|
|
|
|
|
_instance = sharedInstance.toWeakRef();
|
|
|
|
|
m_instance = new UiGuiSettings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sharedInstance;
|
|
|
|
|
return m_instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\brief The destructor saves the settings to a file.
|
|
|
|
|
/*
|
|
|
|
|
\brief Deletes the existing instance of UiGuiSettings and removes the created temp dir.
|
|
|
|
|
*/
|
|
|
|
|
UiGuiSettings::~UiGuiSettings()
|
|
|
|
|
void UiGuiSettings::deleteInstance()
|
|
|
|
|
{
|
|
|
|
|
// Convert the language setting from an integer index to a string.
|
|
|
|
|
int index = _qsettings->value("UniversalIndentGUI/language", 0).toInt();
|
|
|
|
|
if (index < 0 || index >= _availableTranslations.size())
|
|
|
|
|
SettingsPaths::cleanAndRemoveTempDir();
|
|
|
|
|
if (m_instance)
|
|
|
|
|
{
|
|
|
|
|
index = 0;
|
|
|
|
|
delete m_instance;
|
|
|
|
|
m_instance = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_qsettings->setValue("UniversalIndentGUI/language", _availableTranslations.at(index));
|
|
|
|
|
/*
|
|
|
|
|
\brief The destructor saves the settings to a file.
|
|
|
|
|
*/
|
|
|
|
|
UiGuiSettings::~UiGuiSettings()
|
|
|
|
|
{
|
|
|
|
|
saveSettings();
|
|
|
|
|
delete m_qsettings;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
/*
|
|
|
|
|
\brief Scans the translations directory for available translation files and
|
|
|
|
|
stores them in the TQList \a _availableTranslations.
|
|
|
|
|
stores them in the TQList \a m_availableTranslations.
|
|
|
|
|
*/
|
|
|
|
|
void UiGuiSettings::readAvailableTranslations()
|
|
|
|
|
{
|
|
|
|
|
TQString languageShort;
|
|
|
|
|
TQStringList languageFileList;
|
|
|
|
|
|
|
|
|
|
// English is the default language. A translation file does not exist but to have a menu entry,
|
|
|
|
@ -106,36 +106,66 @@ void UiGuiSettings::readAvailableTranslations()
|
|
|
|
|
|
|
|
|
|
// Find all translation files in the "translations" directory.
|
|
|
|
|
TQDir translationDirectory = TQDir(SettingsPaths::getGlobalFilesPath() + "/translations");
|
|
|
|
|
languageFileList << translationDirectory.entryList(TQStringList("universalindent_*.qm"));
|
|
|
|
|
for (TQString &file : translationDirectory.entryList(TQString("universalindent_*.qm")))
|
|
|
|
|
{
|
|
|
|
|
languageFileList << file;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Loop for each found translation file
|
|
|
|
|
foreach(languageShort, languageFileList)
|
|
|
|
|
for (TQString &languageShort : languageFileList)
|
|
|
|
|
{
|
|
|
|
|
// Remove the leading string "universalindent_" from the filename.
|
|
|
|
|
languageShort.remove(0, 16);
|
|
|
|
|
// Remove trailing file extension ".qm".
|
|
|
|
|
languageShort.chop(3);
|
|
|
|
|
languageShort.truncate(languageShort.length() - 3);
|
|
|
|
|
|
|
|
|
|
_availableTranslations.append(languageShort);
|
|
|
|
|
m_availableTranslations.append(languageShort);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
/*
|
|
|
|
|
\brief Returns a list of the mnemonics of the available translations.
|
|
|
|
|
*/
|
|
|
|
|
TQStringList UiGuiSettings::getAvailableTranslations()
|
|
|
|
|
TQStringList& UiGuiSettings::getAvailableTranslations()
|
|
|
|
|
{
|
|
|
|
|
return _availableTranslations;
|
|
|
|
|
return m_availableTranslations;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
/*
|
|
|
|
|
\brief Returns the value of the by \a settingsName defined setting as TQVariant.
|
|
|
|
|
|
|
|
|
|
If the named setting does not exist, 0 is being returned.
|
|
|
|
|
*/
|
|
|
|
|
TQVariant UiGuiSettings::getValueByName(TQString settingName)
|
|
|
|
|
TQVariant UiGuiSettings::getValueByName(const TQString &settingName) const
|
|
|
|
|
{
|
|
|
|
|
return _qsettings->value("UniversalIndentGUI/" + settingName);
|
|
|
|
|
// Test if the named setting really exists.
|
|
|
|
|
if (m_settings.contains(settingName))
|
|
|
|
|
{
|
|
|
|
|
return m_settings[settingName];
|
|
|
|
|
}
|
|
|
|
|
return TQVariant(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
\brief Sets the value of the by \a settingsName defined setting to the value \a value.
|
|
|
|
|
|
|
|
|
|
The to \a settingsName corresponding signal is emitted, if the value has changed.
|
|
|
|
|
*/
|
|
|
|
|
bool UiGuiSettings::setValueByName(const TQString &settingName, TQVariant value)
|
|
|
|
|
{
|
|
|
|
|
// Test if the named setting really exists.
|
|
|
|
|
if (m_settings.contains(settingName))
|
|
|
|
|
{
|
|
|
|
|
// Test if the new value is different to the one before.
|
|
|
|
|
if (m_settings[settingName] != value)
|
|
|
|
|
{
|
|
|
|
|
m_settings[settingName] = value;
|
|
|
|
|
// Emit the signal for the changed setting.
|
|
|
|
|
emitSignalForSetting(settingName);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@ -143,80 +173,130 @@ TQVariant UiGuiSettings::getValueByName(TQString settingName)
|
|
|
|
|
|
|
|
|
|
Settings are for example last selected indenter, last loaded source code file and so on.
|
|
|
|
|
*/
|
|
|
|
|
bool UiGuiSettings::initSettings()
|
|
|
|
|
void UiGuiSettings::loadSettings()
|
|
|
|
|
{
|
|
|
|
|
// Read the version string saved in the settings file.
|
|
|
|
|
_qsettings->setValue("UniversalIndentGUI/version",
|
|
|
|
|
_qsettings->value("UniversalIndentGUI/version", ""));
|
|
|
|
|
m_settings["VersionInSettingsFile"] = m_qsettings->readEntry("version", TQString::null);
|
|
|
|
|
|
|
|
|
|
// Read windows last size and position from the settings file.
|
|
|
|
|
_qsettings->setValue("UniversalIndentGUI/maximized",
|
|
|
|
|
_qsettings->value("UniversalIndentGUI/maximized", false));
|
|
|
|
|
_qsettings->setValue("UniversalIndentGUI/position",
|
|
|
|
|
_qsettings->value("UniversalIndentGUI/position", TQPoint(50, 50)));
|
|
|
|
|
_qsettings->setValue("UniversalIndentGUI/size",
|
|
|
|
|
_qsettings->value("UniversalIndentGUI/size", TQSize(800, 600)));
|
|
|
|
|
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 last selected encoding for the opened source code file.
|
|
|
|
|
_qsettings->setValue("UniversalIndentGUI/encoding",
|
|
|
|
|
_qsettings->value("UniversalIndentGUI/encoding", "UTF-8"));
|
|
|
|
|
m_settings["FileEncoding"] = m_qsettings->readEntry("encoding", "UTF-8");
|
|
|
|
|
|
|
|
|
|
// Read maximum length of list for recently opened files.
|
|
|
|
|
_qsettings->setValue("UniversalIndentGUI/recentlyOpenedListSize",
|
|
|
|
|
_qsettings->value("UniversalIndentGUI/recentlyOpenedListSize", 5));
|
|
|
|
|
m_settings["RecentlyOpenedListSize"] = m_qsettings->readNumEntry("recentlyOpenedListSize", 5);
|
|
|
|
|
|
|
|
|
|
// Read if last opened source code file should be loaded on startup.
|
|
|
|
|
_qsettings->setValue("UniversalIndentGUI/loadLastSourceCodeFileOnStartup",
|
|
|
|
|
_qsettings->value("UniversalIndentGUI/loadLastSourceCodeFileOnStartup", true));
|
|
|
|
|
m_settings["LoadLastOpenedFileOnStartup"] = m_qsettings->readBoolEntry(
|
|
|
|
|
"loadLastSourceCodeFileOnStartup", true);
|
|
|
|
|
|
|
|
|
|
// Read last opened source code file from the settings file.
|
|
|
|
|
_qsettings->setValue("UniversalIndentGUI/lastSourceCodeFile",
|
|
|
|
|
_qsettings->value("UniversalIndentGUI/lastSourceCodeFile",
|
|
|
|
|
_indenterDirctoryStr + "/example.cpp"));
|
|
|
|
|
m_settings["LastOpenedFiles"] = m_qsettings->readEntry("lastSourceCodeFile",
|
|
|
|
|
m_indenterDirectoryStr + "/example.cpp");
|
|
|
|
|
|
|
|
|
|
// Read last selected indenter from the settings file.
|
|
|
|
|
int selectedIndenter = _qsettings->value("UniversalIndentGUI/selectedIndenter", 0).toInt();
|
|
|
|
|
int selectedIndenter = m_qsettings->readNumEntry("selectedIndenter", 0);
|
|
|
|
|
if (selectedIndenter < 0)
|
|
|
|
|
{
|
|
|
|
|
selectedIndenter = 0;
|
|
|
|
|
}
|
|
|
|
|
_qsettings->setValue("UniversalIndentGUI/selectedIndenter", selectedIndenter);
|
|
|
|
|
m_settings["SelectedIndenter"] = selectedIndenter;
|
|
|
|
|
|
|
|
|
|
// Read if syntax highlighting is enabled.
|
|
|
|
|
_qsettings->setValue("UniversalIndentGUI/SyntaxHighlightingEnabled",
|
|
|
|
|
_qsettings->value("UniversalIndentGUI/SyntaxHighlightingEnabled", true));
|
|
|
|
|
m_settings["SyntaxHighlightningEnabled"] = m_qsettings->readBoolEntry(
|
|
|
|
|
"SyntaxHighlightningEnabled", true);
|
|
|
|
|
|
|
|
|
|
// Read if white space characters should be displayed.
|
|
|
|
|
_qsettings->setValue("UniversalIndentGUI/whiteSpaceIsVisible",
|
|
|
|
|
_qsettings->value("UniversalIndentGUI/whiteSpaceIsVisible", false));
|
|
|
|
|
m_settings["WhiteSpaceIsVisible"] = m_qsettings->readBoolEntry("whiteSpaceIsVisible", false);
|
|
|
|
|
|
|
|
|
|
// Read if indenter parameter tool tips are enabled.
|
|
|
|
|
_qsettings->setValue("UniversalIndentGUI/indenterParameterTooltipsEnabled",
|
|
|
|
|
_qsettings->value("UniversalIndentGUI/indenterParameterTooltipsEnabled", true));
|
|
|
|
|
m_settings["IndenterParameterTooltipsEnabled"] = m_qsettings->readBoolEntry(
|
|
|
|
|
"indenterParameterTooltipsEnabled", true);
|
|
|
|
|
|
|
|
|
|
// Read the tab width from the settings file.
|
|
|
|
|
_qsettings->setValue("UniversalIndentGUI/tabWidth",
|
|
|
|
|
_qsettings->value("UniversalIndentGUI/tabWidth", 4));
|
|
|
|
|
m_settings["TabWidth"] = m_qsettings->readNumEntry("tabWidth", 4);
|
|
|
|
|
|
|
|
|
|
// Read the last selected language and stores the index it has in the list of available
|
|
|
|
|
// translations.
|
|
|
|
|
_qsettings->setValue("UniversalIndentGUI/language",
|
|
|
|
|
_availableTranslations.indexOf(_qsettings->value("UniversalIndentGUI/language",
|
|
|
|
|
"").toString()));
|
|
|
|
|
TQString language = m_qsettings->readEntry("language", "en");
|
|
|
|
|
int idx = m_availableTranslations.findIndex(language);
|
|
|
|
|
if (idx < 0)
|
|
|
|
|
{
|
|
|
|
|
idx = m_availableTranslations.findIndex("en"); // "en" is always present
|
|
|
|
|
}
|
|
|
|
|
m_settings["Language"] = idx;
|
|
|
|
|
|
|
|
|
|
// TODO - MainWindow::saveState() missing in TQt3
|
|
|
|
|
// Read the main window state.
|
|
|
|
|
_qsettings->setValue("UniversalIndentGUI/MainWindowState",
|
|
|
|
|
_qsettings->value("UniversalIndentGUI/MainWindowState", TQByteArray()));
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
// m_settings["MainWindowState"] = m_qsettings->readEntry("MainWindowState", "@ByteArray()");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\brief Saves the settings for the main application.
|
|
|
|
|
|
|
|
|
|
Settings are for example last selected indenter, last loaded source code file and so on.
|
|
|
|
|
*/
|
|
|
|
|
void UiGuiSettings::saveSettings()
|
|
|
|
|
{
|
|
|
|
|
// Write the version string saved in the settings file.
|
|
|
|
|
m_qsettings->writeEntry("version", m_settings["VersionInSettingsFile"].toString());
|
|
|
|
|
|
|
|
|
|
// Write windows last size and position from the settings file.
|
|
|
|
|
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 last selected encoding for the opened source code file.
|
|
|
|
|
m_qsettings->writeEntry("encoding", m_settings["FileEncoding"].toString());
|
|
|
|
|
|
|
|
|
|
// Write maximum length of list for recently opened files.
|
|
|
|
|
m_qsettings->writeEntry("recentlyOpenedListSize", m_settings["RecentlyOpenedListSize"].toInt());
|
|
|
|
|
|
|
|
|
|
// Write if last opened source code file should be loaded on startup.
|
|
|
|
|
m_qsettings->writeEntry("loadLastSourceCodeFileOnStartup",
|
|
|
|
|
m_settings["LoadLastOpenedFileOnStartup"].toBool());
|
|
|
|
|
|
|
|
|
|
// Write last opened source code file from the settings file.
|
|
|
|
|
m_qsettings->writeEntry("lastSourceCodeFile", m_settings["LastOpenedFiles"].toString());
|
|
|
|
|
|
|
|
|
|
// Write last selected indenter from the settings file.
|
|
|
|
|
m_qsettings->writeEntry("selectedIndenter", m_settings["SelectedIndenter"].toInt());
|
|
|
|
|
|
|
|
|
|
// Write if syntax highlighting is enabled.
|
|
|
|
|
m_qsettings->writeEntry("SyntaxHighlightningEnabled",
|
|
|
|
|
m_settings["SyntaxHighlightningEnabled"].toBool());
|
|
|
|
|
|
|
|
|
|
// Write if white space characters should be displayed.
|
|
|
|
|
m_qsettings->writeEntry("whiteSpaceIsVisible", m_settings["WhiteSpaceIsVisible"].toBool());
|
|
|
|
|
|
|
|
|
|
// Write if indenter parameter tool tips are enabled.
|
|
|
|
|
m_qsettings->writeEntry("indenterParameterTooltipsEnabled",
|
|
|
|
|
m_settings["IndenterParameterTooltipsEnabled"].toBool());
|
|
|
|
|
|
|
|
|
|
// Write the tab width from the settings file.
|
|
|
|
|
m_qsettings->writeEntry("tabWidth", m_settings["TabWidth"].toInt());
|
|
|
|
|
|
|
|
|
|
// Write the last selected language and stores the index it has in the list of available
|
|
|
|
|
m_qsettings->writeEntry("language", m_availableTranslations[m_settings["Language"].toInt()]);
|
|
|
|
|
|
|
|
|
|
// TODO - MainWindow::saveState() missing in TQt3
|
|
|
|
|
// Write the main window state.
|
|
|
|
|
//m_qsettings->writeEntry("MainWindowState", m_settings["MainWindowState"].toByteArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UiGuiSettings::emitSignalForSetting(TQString settingName)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
\brief Register the by \a propertyName defined property of \a obj to be connected to the setting defined by \a settingName.
|
|
|
|
|
|
|
|
|
|
The \a propertyName must be one of those that are listed in the TQt "Properties" documentation section of a TQt Object.
|
|
|
|
|
All further needed info is retrieved via the \a obj's MetaObject, like the to the property bound signal.
|
|
|
|
|
*/
|
|
|
|
|
* /
|
|
|
|
|
bool UiGuiSettings::registerObjectProperty(TQObject *obj, const TQString &propertyName,
|
|
|
|
|
const TQString &settingName)
|
|
|
|
|
{
|
|
|
|
@ -247,7 +327,7 @@ bool UiGuiSettings::registerObjectProperty(TQObject *obj, const TQString &proper
|
|
|
|
|
|
|
|
|
|
if (connectSuccess)
|
|
|
|
|
{
|
|
|
|
|
_registeredObjectProperties[obj] = TQStringList() << propertyName << settingName;
|
|
|
|
|
m_registeredObjectProperties[obj] = TQStringList() << propertyName << settingName;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
@ -258,14 +338,14 @@ bool UiGuiSettings::registerObjectProperty(TQObject *obj, const TQString &proper
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If setting already exists, set the objects property to the setting value.
|
|
|
|
|
if (_qsettings->contains("UniversalIndentGUI/" + settingName))
|
|
|
|
|
if (m_qsettings->contains("UniversalIndentGUI/" + settingName))
|
|
|
|
|
{
|
|
|
|
|
mProp.write(obj, _qsettings->value("UniversalIndentGUI/" + settingName));
|
|
|
|
|
mProp.write(obj, m_qsettings->value("UniversalIndentGUI/" + settingName));
|
|
|
|
|
}
|
|
|
|
|
// Otherwise add the setting and set it to the value of the objects property.
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_qsettings->setValue("UniversalIndentGUI/" + settingName, mProp.read(obj));
|
|
|
|
|
m_qsettings->setValue("UniversalIndentGUI/" + settingName, mProp.read(obj));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -278,29 +358,12 @@ bool UiGuiSettings::registerObjectProperty(TQObject *obj, const TQString &proper
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\brief Searches the child TQObjects of \a obj for a property name and setting name definition within
|
|
|
|
|
their custom properties and registers this property name to that setting name if both were found.
|
|
|
|
|
|
|
|
|
|
The custom properties, for which are searched, are "connectedPropertyName" and "connectedSettingName",
|
|
|
|
|
where "connectedPropertyName" is the name of a TQObject property as it is documented in the TQtDocs, and
|
|
|
|
|
"connectedSettingName" is the name of a setting here within UiGuiSettings. If the mentioned setting
|
|
|
|
|
name doesn't exist, it will be created.
|
|
|
|
|
|
|
|
|
|
Returns true, if all found property and setting definitions could be successfully registered.
|
|
|
|
|
Returns false, if any of those registrations fails.
|
|
|
|
|
*/
|
|
|
|
|
bool UiGuiSettings::registerObjectPropertyRecursive(TQObject *obj)
|
|
|
|
|
{
|
|
|
|
|
return checkCustomPropertiesAndCallFunction(obj, &UiGuiSettings::registerObjectProperty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
//*
|
|
|
|
|
\brief Assigns the by \a settingName defined setting value to the by \a propertyName defined property of \a obj.
|
|
|
|
|
|
|
|
|
|
Returns true, if the value could be assigned, otherwise returns false, which is the case if settingName doesn't exist
|
|
|
|
|
within the settings or if the mentioned propertyName wasn't found for the \a obj.
|
|
|
|
|
*/
|
|
|
|
|
* /
|
|
|
|
|
bool UiGuiSettings::setObjectPropertyToSettingValue(TQObject *obj, const TQString &propertyName,
|
|
|
|
|
const TQString &settingName)
|
|
|
|
|
{
|
|
|
|
@ -312,9 +375,9 @@ bool UiGuiSettings::setObjectPropertyToSettingValue(TQObject *obj, const TQStrin
|
|
|
|
|
TQMetaProperty mProp = metaObject->property(indexOfProp);
|
|
|
|
|
|
|
|
|
|
// If setting already exists, set the objects property to the setting value.
|
|
|
|
|
if (_qsettings->contains("UniversalIndentGUI/" + settingName))
|
|
|
|
|
if (m_qsettings->contains("UniversalIndentGUI/" + settingName))
|
|
|
|
|
{
|
|
|
|
|
mProp.write(obj, _qsettings->value("UniversalIndentGUI/" + settingName));
|
|
|
|
|
mProp.write(obj, m_qsettings->value("UniversalIndentGUI/" + settingName));
|
|
|
|
|
}
|
|
|
|
|
// The setting didn't exist so return that setting the objects property failed.
|
|
|
|
|
else
|
|
|
|
@ -332,7 +395,7 @@ bool UiGuiSettings::setObjectPropertyToSettingValue(TQObject *obj, const TQStrin
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
/*
|
|
|
|
|
\brief Searches the child TQObjects of \a obj for a property name and setting name definition within
|
|
|
|
|
their custom properties and sets each property to settings value.
|
|
|
|
|
|
|
|
|
@ -342,20 +405,20 @@ bool UiGuiSettings::setObjectPropertyToSettingValue(TQObject *obj, const TQStrin
|
|
|
|
|
|
|
|
|
|
Returns true, if all found property and setting definitions could be successfully registered.
|
|
|
|
|
Returns false, if any of those registrations fails.
|
|
|
|
|
*/
|
|
|
|
|
* /
|
|
|
|
|
bool UiGuiSettings::setObjectPropertyToSettingValueRecursive(TQObject *obj)
|
|
|
|
|
{
|
|
|
|
|
return checkCustomPropertiesAndCallFunction(obj, &UiGuiSettings::setObjectPropertyToSettingValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
/*
|
|
|
|
|
\brief Assigns the by \a propertyName defined property's value of \a obj to the by \a settingName defined setting.
|
|
|
|
|
|
|
|
|
|
If the \a settingName didn't exist yet, it will be created.
|
|
|
|
|
|
|
|
|
|
Returns true, if the value could be assigned, otherwise returns false, which is the case if the mentioned
|
|
|
|
|
propertyName wasn't found for the \a obj.
|
|
|
|
|
*/
|
|
|
|
|
* /
|
|
|
|
|
bool UiGuiSettings::setSettingToObjectPropertyValue(TQObject *obj, const TQString &propertyName,
|
|
|
|
|
const TQString &settingName)
|
|
|
|
|
{
|
|
|
|
@ -377,7 +440,7 @@ bool UiGuiSettings::setSettingToObjectPropertyValue(TQObject *obj, const TQStrin
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
/*
|
|
|
|
|
\brief Searches the child TQObjects of \a obj for a property name and setting name definition within
|
|
|
|
|
their custom properties and sets each setting to the property value.
|
|
|
|
|
|
|
|
|
@ -388,17 +451,17 @@ bool UiGuiSettings::setSettingToObjectPropertyValue(TQObject *obj, const TQStrin
|
|
|
|
|
|
|
|
|
|
Returns true, if all found property and setting definitions could be successfully registered.
|
|
|
|
|
Returns false, if any of those registrations fails.
|
|
|
|
|
*/
|
|
|
|
|
* /
|
|
|
|
|
bool UiGuiSettings::setSettingToObjectPropertyValueRecursive(TQObject *obj)
|
|
|
|
|
{
|
|
|
|
|
return checkCustomPropertiesAndCallFunction(obj, &UiGuiSettings::setSettingToObjectPropertyValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
/*
|
|
|
|
|
\brief Iterates over all \a objs child TQObjects and checks whether they have the custom properties
|
|
|
|
|
"connectedPropertyName" and "connectedSettingName" set. If both are set, it invokes the \a callBackFunc
|
|
|
|
|
with both.
|
|
|
|
|
*/
|
|
|
|
|
* /
|
|
|
|
|
bool UiGuiSettings::checkCustomPropertiesAndCallFunction(TQObject *obj, bool (UiGuiSettings::*callBackFunc)(
|
|
|
|
|
TQObject *obj, const TQString &propertyName,
|
|
|
|
|
const TQString &settingName))
|
|
|
|
@ -422,16 +485,16 @@ bool UiGuiSettings::checkCustomPropertiesAndCallFunction(TQObject *obj, bool (Ui
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
/*
|
|
|
|
|
\brief The with a certain property registered \a obj gets unregistered.
|
|
|
|
|
*/
|
|
|
|
|
* /
|
|
|
|
|
void UiGuiSettings::unregisterObjectProperty(TQObject *obj)
|
|
|
|
|
{
|
|
|
|
|
if (_registeredObjectProperties.contains(obj))
|
|
|
|
|
if (m_registeredObjectProperties.contains(obj))
|
|
|
|
|
{
|
|
|
|
|
const TQMetaObject *metaObject = obj->metaObject();
|
|
|
|
|
TQString propertyName = _registeredObjectProperties[obj].first();
|
|
|
|
|
TQString settingName = _registeredObjectProperties[obj].last();
|
|
|
|
|
TQString propertyName = m_registeredObjectProperties[obj].first();
|
|
|
|
|
TQString settingName = m_registeredObjectProperties[obj].last();
|
|
|
|
|
|
|
|
|
|
bool connectSuccess = false;
|
|
|
|
|
int indexOfProp = metaObject->indexOfProperty(qPrintable(propertyName));
|
|
|
|
@ -449,18 +512,18 @@ void UiGuiSettings::unregisterObjectProperty(TQObject *obj)
|
|
|
|
|
signal.signature())), this, SLOT(handleObjectPropertyChange()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_registeredObjectProperties.remove(obj);
|
|
|
|
|
m_registeredObjectProperties.remove(obj);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
/*
|
|
|
|
|
\brief Registers a slot form the \a obj by its \a slotName to be invoked, if the by \a settingName defined
|
|
|
|
|
setting changes.
|
|
|
|
|
|
|
|
|
|
The registered slot may have no parameters or exactly one. If it accepts one parameter, whenever the setting
|
|
|
|
|
\a settingName changes the slot gets tried to be invoked with the settings value as parameter. This only works,
|
|
|
|
|
if the slot parameter is of the same type as the setting.
|
|
|
|
|
*/
|
|
|
|
|
* /
|
|
|
|
|
bool UiGuiSettings::registerObjectSlot(TQObject *obj, const TQString &slotName,
|
|
|
|
|
const TQString &settingName)
|
|
|
|
|
{
|
|
|
|
@ -483,7 +546,7 @@ bool UiGuiSettings::registerObjectSlot(TQObject *obj, const TQString &slotName,
|
|
|
|
|
// only methods taking max one argument are allowed.
|
|
|
|
|
if (mMethod.parameterTypes().size() <= 1)
|
|
|
|
|
{
|
|
|
|
|
_registeredObjectSlots.insert(obj, TQStringList() << normalizedSlotName << settingName);
|
|
|
|
|
m_registeredObjectSlots.insert(obj, TQStringList() << normalizedSlotName << settingName);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
@ -502,16 +565,16 @@ bool UiGuiSettings::registerObjectSlot(TQObject *obj, const TQString &slotName,
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
/*
|
|
|
|
|
\brief If \a obj, \a slotName and \a settingName are given, that certain connection is unregistered.
|
|
|
|
|
If only \a obj is given, all to this object registered slot-setting connections are unregistered.
|
|
|
|
|
*/
|
|
|
|
|
* /
|
|
|
|
|
void UiGuiSettings::unregisterObjectSlot(TQObject *obj, const TQString &slotName,
|
|
|
|
|
const TQString &settingName)
|
|
|
|
|
{
|
|
|
|
|
//const TQMetaObject *metaObject = obj->metaObject();
|
|
|
|
|
TQString normalizedSlotName = TQMetaObject::normalizedSignature(qPrintable(slotName));
|
|
|
|
|
TQMutableMapIterator<TQObject*, TQStringList> it(_registeredObjectSlots);
|
|
|
|
|
TQMutableMapIterator<TQObject*, TQStringList> it(m_registeredObjectSlots);
|
|
|
|
|
while (it.hasNext())
|
|
|
|
|
{
|
|
|
|
|
it.next();
|
|
|
|
@ -526,17 +589,17 @@ void UiGuiSettings::unregisterObjectSlot(TQObject *obj, const TQString &slotName
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
/*
|
|
|
|
|
\brief This private slot gets invoked whenever a registered objects property changes
|
|
|
|
|
and distributes the new value to all other to the same settingName registered objects.
|
|
|
|
|
*/
|
|
|
|
|
* /
|
|
|
|
|
void UiGuiSettings::handleObjectPropertyChange()
|
|
|
|
|
{
|
|
|
|
|
TQObject *obj = TQObject::sender();
|
|
|
|
|
TQString className = obj->metaObject()->className();
|
|
|
|
|
const TQMetaObject *metaObject = obj->metaObject();
|
|
|
|
|
TQString propertyName = _registeredObjectProperties[obj].first();
|
|
|
|
|
TQString settingName = _registeredObjectProperties[obj].last();
|
|
|
|
|
TQString propertyName = m_registeredObjectProperties[obj].first();
|
|
|
|
|
TQString settingName = m_registeredObjectProperties[obj].last();
|
|
|
|
|
|
|
|
|
|
int indexOfProp = metaObject->indexOfProperty(qPrintable(propertyName));
|
|
|
|
|
if (indexOfProp > -1)
|
|
|
|
@ -546,23 +609,23 @@ void UiGuiSettings::handleObjectPropertyChange()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
/*
|
|
|
|
|
\brief Sets the setting defined by \a settingName to \a value.
|
|
|
|
|
|
|
|
|
|
When setting a changed value, all to this settingName registered objects get
|
|
|
|
|
the changed value set too.
|
|
|
|
|
If the \a settingName didn't exist yet, it will be created.
|
|
|
|
|
*/
|
|
|
|
|
* /
|
|
|
|
|
void UiGuiSettings::setValueByName(const TQString &settingName, const TQVariant &value)
|
|
|
|
|
{
|
|
|
|
|
// Do the updating only, if the setting was really changed.
|
|
|
|
|
if (_qsettings->value("UniversalIndentGUI/" + settingName) != value)
|
|
|
|
|
if (m_qsettings->value("UniversalIndentGUI/" + settingName) != value)
|
|
|
|
|
{
|
|
|
|
|
_qsettings->setValue("UniversalIndentGUI/" + settingName, value);
|
|
|
|
|
m_qsettings->setValue("UniversalIndentGUI/" + settingName, value);
|
|
|
|
|
|
|
|
|
|
// Set the new value for all registered object properties for settingName.
|
|
|
|
|
for (TQMap<TQObject*, TQStringList>::ConstIterator it = _registeredObjectProperties.begin();
|
|
|
|
|
it != _registeredObjectProperties.end(); ++it)
|
|
|
|
|
for (TQMap<TQObject*, TQStringList>::ConstIterator it = m_registeredObjectProperties.begin();
|
|
|
|
|
it != m_registeredObjectProperties.end(); ++it)
|
|
|
|
|
{
|
|
|
|
|
if (it.value().last() == settingName)
|
|
|
|
|
{
|
|
|
|
@ -580,8 +643,8 @@ void UiGuiSettings::setValueByName(const TQString &settingName, const TQVariant
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Invoke all registered object methods for settingName.
|
|
|
|
|
for (TQMap<TQObject*, TQStringList>::ConstIterator it = _registeredObjectSlots.begin();
|
|
|
|
|
it != _registeredObjectSlots.end(); ++it)
|
|
|
|
|
for (TQMap<TQObject*, TQStringList>::ConstIterator it = m_registeredObjectSlots.begin();
|
|
|
|
|
it != m_registeredObjectSlots.end(); ++it)
|
|
|
|
|
{
|
|
|
|
|
if (it.value().last() == settingName)
|
|
|
|
|
{
|
|
|
|
@ -925,3 +988,6 @@ bool UiGuiSettings::invokeMethodWithValue(TQObject *obj, TQMetaMethod mMethod, T
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "UiGuiSettings.moc"
|