Geometrize  1.0
An application for geometrizing images into geometric primitives
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
Namespaces | Classes | Functions | Variables
geometrize Namespace Reference

< Energy function passed to the image task worker thread. More...

Namespaces

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

Classes

class  TemplateManifest
 The TemplateManifest class represents the metadata for a task template. More...
 
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...
 

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...
 
RecentItemsgetRecentItems ()
 getRecentItems Gets a reference to the recent files list. More...
 
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_"}
 

Detailed Description

< Energy function passed to the image task worker thread.

Function Documentation

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.
65 {
66  return ":/translations/app/";
67 }

Here is the caller graph for this function:

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".
60 {
61  return ".qm";
62 }

Here is the caller graph for this function:

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.
97 {
98  static const QIcon errorIcon{errorFlagResourcePath};
99  assert(!errorIcon.isNull());
100 
101  // Should start with a minimum-two digit language code
102  if(localeCode.length() < 2) {
103  return errorIcon;
104  }
105 
106  const auto iconExists = [](const QString& file) {
107  const QString path{flagIconResourceDirectory + file + flagIconFileExtension};
108  const QFileInfo info(path);
109  return info.exists() && info.isFile();
110  };
111 
112  const auto makeIcon = [](const QString& file) {
113  const QIcon icon(flagIconResourceDirectory + file + flagIconFileExtension);
114  assert(!icon.isNull());
115  return icon;
116  };
117 
118  // Try to find flag for locale code, with fallback
119  // If "language_country_locale" fails, then "language_country" and lastly "language" will be tried
120  const auto makeIconPaths = [](const QString& localeCode) {
121  const QString separator{"_"};
122  const QStringList parts{localeCode.split(separator, QString::SkipEmptyParts)};
123 
124  QStringList paths;
125  if(parts.length() >= 3) {
126  paths.push_back(parts[0] + "_" + parts[1] + "_" + parts[2]);
127  }
128  if(parts.length() >= 2) {
129  paths.push_back(parts[0] + "_" + parts[1]);
130  }
131  if(parts.length() >= 1) {
132  paths.push_back(parts[0]);
133  }
134  return paths;
135  };
136 
137  const QStringList paths{makeIconPaths(localeCode)};
138  for(const auto& path : paths) {
139  if(iconExists(path)) {
140  return makeIcon(path);
141  }
142  }
143 
144  return errorIcon;
145 }
const QString flagIconResourceDirectory
Definition: localization.cpp:51
const QString flagIconFileExtension
Definition: localization.cpp:52
const QString errorFlagResourcePath
Definition: localization.cpp:53

Here is the caller graph for this function:

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.
148 {
149  const auto& prefs = geometrize::preferences::getGlobalPreferences();
150 
151  const QString language{QString::fromStdString(prefs.getLanguageIsoCode())};
152  const QString country{QString::fromStdString(prefs.getCountryIsoCode())};
153  const QString script{QString::fromStdString(prefs.getScriptIsoCode())};
154 
155  QString localeCode = "";
156  if(!language.isEmpty()) {
157  localeCode += language;
158  }
159  if(!script.isEmpty()) {
160  localeCode += "_" + script;
161  }
162  if(!country.isEmpty()) {
163  localeCode += "_" + country;
164  }
165 
166  return QLocale(localeCode);
167 }
geometrize::preferences::GlobalPreferences & getGlobalPreferences()
getGlobalPreferences Shorthand function that gets a reference to the shared global preferences object...
Definition: globalpreferences.cpp:32

Here is the call graph for this function:

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.
70 {
71  return ":/translations/qt/";
72 }

Here is the caller graph for this function:

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 }
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.
Definition: recentitems.h:16

Here is the caller graph for this function:

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:

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.
170 {
172 
173  const QStringList parts{locale.name().split("-")};
174 
175  if(parts.length() == 0 || parts.length() > 3) {
176  assert(0 && "Failed to extract locale name, will fail to set preferences");
177  return;
178  }
179 
180  if(parts.length() == 1) {
181  prefs.setLanguageIsoCode(parts[0].toStdString());
182  return;
183  }
184 
185  if(parts.length() == 2) {
186  prefs.setLanguageIsoCode(parts[0].toStdString());
187  prefs.setCountryIsoCode(parts[1].toStdString());
188  return;
189  }
190 
191  if(parts.length() == 3) {
192  prefs.setLanguageIsoCode(parts[0].toStdString());
193  prefs.setScriptIsoCode(parts[1].toStdString());
194 
195  const QStringList countryAndMaybeCodesetOrModifier{parts[2].split(".")};
196  assert(countryAndMaybeCodesetOrModifier.length() > 0 && countryAndMaybeCodesetOrModifier.length() <= 3);
197 
198  if(countryAndMaybeCodesetOrModifier.length() > 0) {
199  prefs.setCountryIsoCode(countryAndMaybeCodesetOrModifier[0].toStdString());
200  }
201  return;
202  }
203 }
geometrize::preferences::GlobalPreferences & getGlobalPreferences()
getGlobalPreferences Shorthand function that gets a reference to the shared global preferences object...
Definition: globalpreferences.cpp:32

Here is the call graph for this function:

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.
75 {
76  QCoreApplication* application{QCoreApplication::instance()};
77  if(application == nullptr) {
78  assert(0 && "Attempting to set application translator before app is created");
79  return;
80  }
81 
82  // Remove and destroy old translators
83  purgeTranslators(application);
84 
85  // Install the new translators
86  const auto loadAndAddTranslator = [&application](const QString& file, const QString& directory) {
87  QTranslator* translator{new QTranslator()};
88  translator->load(file, directory);
89  installTranslator(application, translator);
90  };
94 }
const QString geometrizeTranslationFilePrefix
Definition: localization.cpp:57
const QString qtTranslationFilePrefix
Definition: localization.cpp:55
QString getAppTranslationResourceDirectory()
getAppTranslationResourceDirectory Gets the resource path where translation files specific to the app...
Definition: localization.cpp:64
const QString qtBaseTranslationFilePrefix
Definition: localization.cpp:56
QString getBinaryTranslationFileExtension()
getBinaryTranslationFileExtension Gets the file extension for Qt binary translation files...
Definition: localization.cpp:59
QString getQtTranslationResourceDirectory()
getQtTranslationResourceDirectory Gets the resource path where translation files for Qt itself are st...
Definition: localization.cpp:69

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

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