 |
Geometrize
1.0
An application for geometrizing images into geometric primitives
|
◆ getAppTranslationResourceDirectory()
QString geometrize::getAppTranslationResourceDirectory |
( |
| ) |
|
getAppTranslationResourceDirectory Gets the resource path where translation files specific to the app are stored.
- Returns
- The resource path where translation files specific to the app are stored.
68 return ":/translations/app/";
◆ getBinaryTranslationFileExtension()
QString geometrize::getBinaryTranslationFileExtension |
( |
| ) |
|
getBinaryTranslationFileExtension Gets the file extension for Qt binary translation files.
- Returns
- The file extension for Qt binary file extension, including the dot prefix e.g. ".qm".
◆ getFlagIconForLocaleCode()
QIcon geometrize::getFlagIconForLocaleCode |
( |
const QString & |
localeCode | ) |
|
getFlagIconForLocaleCode Gets a representative national flag for the given locale code.
- Parameters
-
localeCode | A string in the form language_country_locale. |
- Returns
- An icon for the code, or an error symbol if no suitable icon could be found.
101 assert(!errorIcon.isNull());
104 if(localeCode.length() < 2) {
108 const auto iconExists = [](
const QString& file) {
110 const QFileInfo info(path);
111 return info.exists() && info.isFile();
114 const auto makeIcon = [](
const QString& file) {
116 assert(!icon.isNull());
122 const auto makeIconPaths = [](
const QString& localeCode) {
123 const QString separator{
"_"};
125 #if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0))
126 const QStringList parts{localeCode.split(separator, QString::SkipEmptyParts)};
128 const QStringList parts{localeCode.split(separator, Qt::SkipEmptyParts)};
132 if(parts.length() >= 3) {
133 paths.push_back(parts[0] +
"_" + parts[1] +
"_" + parts[2]);
135 if(parts.length() >= 2) {
136 paths.push_back(parts[0] +
"_" + parts[1]);
138 if(parts.length() >= 1) {
139 paths.push_back(parts[0]);
144 const QStringList paths{makeIconPaths(localeCode)};
145 for(
const auto& path : paths) {
146 if(iconExists(path)) {
147 return makeIcon(path);
◆ getGlobalPreferencesLocale()
QLocale geometrize::getGlobalPreferencesLocale |
( |
| ) |
|
getGlobalPreferencesLocale Gets a QLocale instance based on the current settings in global preferences. Note that if the string violates the locale format, the "C" locale is used instead.
- Returns
- A QLocale instance based on the global preferences.
158 const QString language{QString::fromStdString(prefs.getLanguageIsoCode())};
159 const QString country{QString::fromStdString(prefs.getCountryIsoCode())};
160 const QString script{QString::fromStdString(prefs.getScriptIsoCode())};
162 QString localeCode =
"";
163 if(!language.isEmpty()) {
164 localeCode += language;
166 if(!script.isEmpty()) {
167 localeCode +=
"_" + script;
169 if(!country.isEmpty()) {
170 localeCode +=
"_" + country;
173 return QLocale(localeCode);
◆ getQtTranslationResourceDirectory()
QString geometrize::getQtTranslationResourceDirectory |
( |
| ) |
|
getQtTranslationResourceDirectory Gets the resource path where translation files for Qt itself are stored.
- Returns
- The resource path where translation files for Qt are stored.
73 return ":/translations/qt/";
◆ getRecentItems()
getRecentItems Gets a reference to the recent files list.
getRecentItems Gets a reference to the app's recently opened files.
- Returns
- The recent files list.
-
A reference to the app's recently opened files.
208 const QString recentlyOpenedItemsSettingsGroup =
"recently_opened_items";
209 const unsigned int maxRecentlyOpenedItems = 75;
◆ getSharedTabletProximityEventFilterInstance()
getSharedTabletProximityEventFilterInstance Gets a reference to the shared instance of the tablet proximity event filter (since we currently only need one to give to the application instance)
- Returns
- A reference to the tablet proximity event filter
34 static TabletProximityEventFilter* sharedInstance =
new TabletProximityEventFilter(QApplication::instance());
35 return *sharedInstance;
◆ getSupportedLocaleCodes()
QStringList geometrize::getSupportedLocaleCodes |
( |
| ) |
|
getSupportedLocaleCodes Iterates over the embedded .qm files and extracts the ISO language codes from their filenames
- Returns
- A list of supported locale codes, sorted alphabetically e.g. "en_GB, ru_RU" etc
214 QStringList supportedLocaleCodes;
216 while (it.hasNext()) {
218 QString fileName{it.fileName()};
220 supportedLocaleCodes.append(localeCode);
222 supportedLocaleCodes.sort();
223 return supportedLocaleCodes;
◆ serialize()
template<typename Archive >
void geometrize::serialize |
( |
Archive & |
ar, |
|
|
geometrize::ImageRunnerShapeBoundsOptions & |
bounds |
|
) |
| |
18 ar(cereal::make_nvp(
"enabled", bounds.enabled),
19 cereal::make_nvp(
"xMinPercent", bounds.xMinPercent),
20 cereal::make_nvp(
"yMinPercent", bounds.yMinPercent),
21 cereal::make_nvp(
"xMaxPercent", bounds.xMaxPercent),
22 cereal::make_nvp(
"yMaxPercent", bounds.yMaxPercent));
◆ setGlobalPreferencesForLocale()
void geometrize::setGlobalPreferencesForLocale |
( |
const QLocale & |
locale | ) |
|
setGlobalPreferencesForLocale Sets the locale settings based on the given locale name.
- Parameters
-
localeName | The locale name. Note this sets only the language and country, not the script or other settings. Even if the string violates the locale format, the string may be saved to the preferences anyway. |
180 const QStringList parts{locale.name().split(
"-")};
182 if(parts.length() == 0 || parts.length() > 3) {
183 assert(0 &&
"Failed to extract locale name, will fail to set preferences");
187 if(parts.length() == 1) {
188 prefs.setLanguageIsoCode(parts[0].toStdString());
192 if(parts.length() == 2) {
193 prefs.setLanguageIsoCode(parts[0].toStdString());
194 prefs.setCountryIsoCode(parts[1].toStdString());
198 if(parts.length() == 3) {
199 prefs.setLanguageIsoCode(parts[0].toStdString());
200 prefs.setScriptIsoCode(parts[1].toStdString());
202 const QStringList countryAndMaybeCodesetOrModifier{parts[2].split(
".")};
203 assert(countryAndMaybeCodesetOrModifier.length() > 0 && countryAndMaybeCodesetOrModifier.length() <= 3);
205 if(countryAndMaybeCodesetOrModifier.length() > 0) {
206 prefs.setCountryIsoCode(countryAndMaybeCodesetOrModifier[0].toStdString());
◆ setLocaleAndUserInterfaceLanguage()
void geometrize::setLocaleAndUserInterfaceLanguage |
( |
const QString & |
isoCode | ) |
|
setLocaleAndUserInterfaceLanguage Sets the application locale and user interface language to the given language code
- Parameters
-
isoCode | The locale code to set the application to. Note: has a hack that transforms Portuguese "pt" to "pt_PT" to prefer Portuguese over Brazilian-Portuguese Also sets global preferences to remember the given code. |
228 QString code = isoCode;
237 QLocale::setDefault(QLocale(code));
◆ setTranslatorsForLocale()
void geometrize::setTranslatorsForLocale |
( |
const QString & |
locale | ) |
|
installTranslatorsForLocale Installs translators for the application.
- Parameters
-
locale | A string in the form language_country. Note this is not threadsafe. |
78 QCoreApplication* application{QCoreApplication::instance()};
79 if(application ==
nullptr) {
80 assert(0 &&
"Attempting to set application translator before app is created");
85 purgeTranslators(application);
88 const auto loadAndAddTranslator = [&application](
const QString& file,
const QString& directory) {
89 QTranslator* translator{
new QTranslator()};
90 translator->load(file, directory);
91 installTranslator(application, translator);
◆ errorFlagResourcePath
const QString geometrize::errorFlagResourcePath {":/icons/error.png"} |
◆ flagIconFileExtension
const QString geometrize::flagIconFileExtension {".png"} |
◆ flagIconResourceDirectory
const QString geometrize::flagIconResourceDirectory {":/flags/"} |
◆ geometrizeTranslationFilePrefix
const QString geometrize::geometrizeTranslationFilePrefix {"geometrize_"} |
◆ qtBaseTranslationFilePrefix
const QString geometrize::qtBaseTranslationFilePrefix {"qtbase_"} |
◆ qtTranslationFilePrefix
const QString geometrize::qtTranslationFilePrefix {"qt_"} |
QString getBinaryTranslationFileExtension()
getBinaryTranslationFileExtension Gets the file extension for Qt binary translation files.
Definition: localization.cpp:61
QString getQtTranslationResourceDirectory()
getQtTranslationResourceDirectory Gets the resource path where translation files for Qt itself are st...
Definition: localization.cpp:71
void setLanguageIsoCode(const std::string &languageIsoCode)
setLanguageIsoCode Sets the ISO 639-1 language preference for the application.
Definition: globalpreferences.cpp:643
const QString geometrizeTranslationFilePrefix
Definition: localization.cpp:59
The RecentItems class encapsulates a list of items that were recently interacted with....
Definition: recentitems.h:17
const QString flagIconFileExtension
Definition: localization.cpp:54
The GlobalPreferences class models the preferences associated with the application as a whole....
Definition: globalpreferences.h:44
void setTranslatorsForLocale(const QString &locale)
installTranslatorsForLocale Installs translators for the application.
Definition: localization.cpp:76
const QString errorFlagResourcePath
Definition: localization.cpp:55
const QString qtBaseTranslationFilePrefix
Definition: localization.cpp:58
const QString flagIconResourceDirectory
Definition: localization.cpp:53
const QString qtTranslationFilePrefix
Definition: localization.cpp:57
QString getAppTranslationResourceDirectory()
getAppTranslationResourceDirectory Gets the resource path where translation files specific to the app...
Definition: localization.cpp:66
geometrize::preferences::GlobalPreferences & getGlobalPreferences()
getGlobalPreferences Shorthand function that gets a reference to the shared global preferences object...
Definition: globalpreferences.cpp:32