Geometrize  1.0
An application for geometrizing images into geometric primitives
Namespaces | Classes | Functions | Variables
geometrize Namespace Reference

Namespaces

 cli
 
 common
 
 constants
 
 dialog
 
 exporter
 
 format
 
 image
 
 layout
 
 logging
 
 network
 
 preferences
 
 scene
 
 script
 
 searchpaths
 
 serialization
 
 strings
 
 task
 
 test
 
 util
 
 version
 

Classes

class  RecentItem
 The RecentItem class models an item that was recently interacted with. More...
 
class  RecentItems
 The RecentItems class encapsulates a list of items that were recently interacted with. The class keeps a record of these items stored in preferences. Useful for keeping track of recently opened files. More...
 
class  TabletProximityEventFilter
 The TabletProximityEventFilter captures tablet enter/exit proximity events (like when Wacom pens are held close to the screen) Used to hide the cursor so it doesn't get in the way of wherever the pen is being held. More...
 
class  TemplateManifest
 The TemplateManifest class represents the metadata for a task template. More...
 

Functions

QString getBinaryTranslationFileExtension ()
 getBinaryTranslationFileExtension Gets the file extension for Qt binary translation files. More...
 
QString getAppTranslationResourceDirectory ()
 getAppTranslationResourceDirectory Gets the resource path where translation files specific to the app are stored. More...
 
QString getQtTranslationResourceDirectory ()
 getQtTranslationResourceDirectory Gets the resource path where translation files for Qt itself are stored. More...
 
void setTranslatorsForLocale (const QString &locale)
 installTranslatorsForLocale Installs translators for the application. More...
 
QIcon getFlagIconForLocaleCode (const QString &localeCode)
 getFlagIconForLocaleCode Gets a representative national flag for the given locale code. More...
 
QLocale 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. More...
 
void setGlobalPreferencesForLocale (const QLocale &locale)
 setGlobalPreferencesForLocale Sets the locale settings based on the given locale name. More...
 
QStringList getSupportedLocaleCodes ()
 getSupportedLocaleCodes Iterates over the embedded .qm files and extracts the ISO language codes from their filenames More...
 
void setLocaleAndUserInterfaceLanguage (const QString &isoCode)
 setLocaleAndUserInterfaceLanguage Sets the application locale and user interface language to the given language code More...
 
RecentItemsgetRecentItems ()
 getRecentItems Gets a reference to the recent files list. More...
 
template<typename Archive >
void serialize (Archive &ar, geometrize::ImageRunnerShapeBoundsOptions &bounds)
 
TabletProximityEventFiltergetSharedTabletProximityEventFilterInstance ()
 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) More...
 

Variables

const QString flagIconResourceDirectory {":/flags/"}
 
const QString flagIconFileExtension {".png"}
 
const QString errorFlagResourcePath {":/icons/error.png"}
 
const QString qtTranslationFilePrefix {"qt_"}
 
const QString qtBaseTranslationFilePrefix {"qtbase_"}
 
const QString geometrizeTranslationFilePrefix {"geometrize_"}
 

Function Documentation

◆ 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.
67 {
68  return ":/translations/app/";
69 }
Here is the caller graph for this function:

◆ 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".
62 {
63  return ".qm";
64 }
Here is the caller graph for this function:

◆ getFlagIconForLocaleCode()

QIcon geometrize::getFlagIconForLocaleCode ( const QString &  localeCode)

getFlagIconForLocaleCode Gets a representative national flag for the given locale code.

Parameters
localeCodeA string in the form language_country_locale.
Returns
An icon for the code, or an error symbol if no suitable icon could be found.
99 {
100  static const QIcon errorIcon{errorFlagResourcePath};
101  assert(!errorIcon.isNull());
102 
103  // Should start with a minimum-two digit language code
104  if(localeCode.length() < 2) {
105  return errorIcon;
106  }
107 
108  const auto iconExists = [](const QString& file) {
109  const QString path{flagIconResourceDirectory + file + flagIconFileExtension};
110  const QFileInfo info(path);
111  return info.exists() && info.isFile();
112  };
113 
114  const auto makeIcon = [](const QString& file) {
115  const QIcon icon(flagIconResourceDirectory + file + flagIconFileExtension);
116  assert(!icon.isNull());
117  return icon;
118  };
119 
120  // Try to find flag for locale code, with fallback
121  // If "language_country_locale" fails, then "language_country" and lastly "language" will be tried
122  const auto makeIconPaths = [](const QString& localeCode) {
123  const QString separator{"_"};
124 
125  #if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0))
126  const QStringList parts{localeCode.split(separator, QString::SkipEmptyParts)};
127  #else
128  const QStringList parts{localeCode.split(separator, Qt::SkipEmptyParts)};
129  #endif
130 
131  QStringList paths;
132  if(parts.length() >= 3) {
133  paths.push_back(parts[0] + "_" + parts[1] + "_" + parts[2]);
134  }
135  if(parts.length() >= 2) {
136  paths.push_back(parts[0] + "_" + parts[1]);
137  }
138  if(parts.length() >= 1) {
139  paths.push_back(parts[0]);
140  }
141  return paths;
142  };
143 
144  const QStringList paths{makeIconPaths(localeCode)};
145  for(const auto& path : paths) {
146  if(iconExists(path)) {
147  return makeIcon(path);
148  }
149  }
150 
151  return errorIcon;
152 }
Here is the caller graph for this function:

◆ 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.
155 {
156  const auto& prefs = geometrize::preferences::getGlobalPreferences();
157 
158  const QString language{QString::fromStdString(prefs.getLanguageIsoCode())};
159  const QString country{QString::fromStdString(prefs.getCountryIsoCode())};
160  const QString script{QString::fromStdString(prefs.getScriptIsoCode())};
161 
162  QString localeCode = "";
163  if(!language.isEmpty()) {
164  localeCode += language;
165  }
166  if(!script.isEmpty()) {
167  localeCode += "_" + script;
168  }
169  if(!country.isEmpty()) {
170  localeCode += "_" + country;
171  }
172 
173  return QLocale(localeCode);
174 }
Here is the call graph for this function:

◆ 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.
72 {
73  return ":/translations/qt/";
74 }
Here is the caller graph for this function:

◆ getRecentItems()

RecentItems & geometrize::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.
207 {
208  const QString recentlyOpenedItemsSettingsGroup = "recently_opened_items";
209  const unsigned int maxRecentlyOpenedItems = 75;
210 
211  static geometrize::RecentItems items{recentlyOpenedItemsSettingsGroup, maxRecentlyOpenedItems};
212  return items;
213 }
Here is the caller graph for this function:

◆ getSharedTabletProximityEventFilterInstance()

TabletProximityEventFilter & geometrize::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
33 {
34  static TabletProximityEventFilter* sharedInstance = new TabletProximityEventFilter(QApplication::instance());
35  return *sharedInstance;
36 }
Here is the caller graph for this function:

◆ 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
213 {
214  QStringList supportedLocaleCodes;
216  while (it.hasNext()) {
217  it.next();
218  QString fileName{it.fileName()};
219  const QString localeCode{fileName.remove("geometrize_").remove(geometrize::getBinaryTranslationFileExtension())};
220  supportedLocaleCodes.append(localeCode);
221  }
222  supportedLocaleCodes.sort();
223  return supportedLocaleCodes;
224 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ serialize()

template<typename Archive >
void geometrize::serialize ( Archive &  ar,
geometrize::ImageRunnerShapeBoundsOptions &  bounds 
)
17 {
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));
23 }

◆ setGlobalPreferencesForLocale()

void geometrize::setGlobalPreferencesForLocale ( const QLocale &  locale)

setGlobalPreferencesForLocale Sets the locale settings based on the given locale name.

Parameters
localeNameThe 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.
177 {
179 
180  const QStringList parts{locale.name().split("-")};
181 
182  if(parts.length() == 0 || parts.length() > 3) {
183  assert(0 && "Failed to extract locale name, will fail to set preferences");
184  return;
185  }
186 
187  if(parts.length() == 1) {
188  prefs.setLanguageIsoCode(parts[0].toStdString());
189  return;
190  }
191 
192  if(parts.length() == 2) {
193  prefs.setLanguageIsoCode(parts[0].toStdString());
194  prefs.setCountryIsoCode(parts[1].toStdString());
195  return;
196  }
197 
198  if(parts.length() == 3) {
199  prefs.setLanguageIsoCode(parts[0].toStdString());
200  prefs.setScriptIsoCode(parts[1].toStdString());
201 
202  const QStringList countryAndMaybeCodesetOrModifier{parts[2].split(".")};
203  assert(countryAndMaybeCodesetOrModifier.length() > 0 && countryAndMaybeCodesetOrModifier.length() <= 3);
204 
205  if(countryAndMaybeCodesetOrModifier.length() > 0) {
206  prefs.setCountryIsoCode(countryAndMaybeCodesetOrModifier[0].toStdString());
207  }
208  return;
209  }
210 }
Here is the call graph for this function:

◆ setLocaleAndUserInterfaceLanguage()

void geometrize::setLocaleAndUserInterfaceLanguage ( const QString &  isoCode)

setLocaleAndUserInterfaceLanguage Sets the application locale and user interface language to the given language code

Parameters
isoCodeThe 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.
227 {
228  QString code = isoCode;
229  if(code == "pt") {
230  // NOTE hack - the default Portuguese translations are pt_PT not pt_BR, we make that explicit here
231  // This is because Qt defaults to Brazilian version, whereas we preferred to default to Portugal
232  code = "pt_PT";
233  }
234 
236  prefs.setLanguageIsoCode(code.toStdString());
237  QLocale::setDefault(QLocale(code));
239 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setTranslatorsForLocale()

void geometrize::setTranslatorsForLocale ( const QString &  locale)

installTranslatorsForLocale Installs translators for the application.

Parameters
localeA string in the form language_country. Note this is not threadsafe.
77 {
78  QCoreApplication* application{QCoreApplication::instance()};
79  if(application == nullptr) {
80  assert(0 && "Attempting to set application translator before app is created");
81  return;
82  }
83 
84  // Remove and destroy old translators
85  purgeTranslators(application);
86 
87  // Install the new translators
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);
92  };
96 }
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ 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_"}
geometrize::getBinaryTranslationFileExtension
QString getBinaryTranslationFileExtension()
getBinaryTranslationFileExtension Gets the file extension for Qt binary translation files.
Definition: localization.cpp:61
geometrize::getQtTranslationResourceDirectory
QString getQtTranslationResourceDirectory()
getQtTranslationResourceDirectory Gets the resource path where translation files for Qt itself are st...
Definition: localization.cpp:71
geometrize::preferences::GlobalPreferences::setLanguageIsoCode
void setLanguageIsoCode(const std::string &languageIsoCode)
setLanguageIsoCode Sets the ISO 639-1 language preference for the application.
Definition: globalpreferences.cpp:643
geometrize::geometrizeTranslationFilePrefix
const QString geometrizeTranslationFilePrefix
Definition: localization.cpp:59
geometrize::RecentItems
The RecentItems class encapsulates a list of items that were recently interacted with....
Definition: recentitems.h:17
geometrize::flagIconFileExtension
const QString flagIconFileExtension
Definition: localization.cpp:54
geometrize::preferences::GlobalPreferences
The GlobalPreferences class models the preferences associated with the application as a whole....
Definition: globalpreferences.h:44
geometrize::setTranslatorsForLocale
void setTranslatorsForLocale(const QString &locale)
installTranslatorsForLocale Installs translators for the application.
Definition: localization.cpp:76
geometrize::errorFlagResourcePath
const QString errorFlagResourcePath
Definition: localization.cpp:55
geometrize::qtBaseTranslationFilePrefix
const QString qtBaseTranslationFilePrefix
Definition: localization.cpp:58
geometrize::flagIconResourceDirectory
const QString flagIconResourceDirectory
Definition: localization.cpp:53
geometrize::qtTranslationFilePrefix
const QString qtTranslationFilePrefix
Definition: localization.cpp:57
geometrize::getAppTranslationResourceDirectory
QString getAppTranslationResourceDirectory()
getAppTranslationResourceDirectory Gets the resource path where translation files specific to the app...
Definition: localization.cpp:66
geometrize::preferences::getGlobalPreferences
geometrize::preferences::GlobalPreferences & getGlobalPreferences()
getGlobalPreferences Shorthand function that gets a reference to the shared global preferences object...
Definition: globalpreferences.cpp:32