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

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

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

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.
154 {
155  const auto& prefs = geometrize::preferences::getGlobalPreferences();
156 
157  const QString language{QString::fromStdString(prefs.getLanguageIsoCode())};
158  const QString country{QString::fromStdString(prefs.getCountryIsoCode())};
159  const QString script{QString::fromStdString(prefs.getScriptIsoCode())};
160 
161  QString localeCode = "";
162  if(!language.isEmpty()) {
163  localeCode += language;
164  }
165  if(!script.isEmpty()) {
166  localeCode += "_" + script;
167  }
168  if(!country.isEmpty()) {
169  localeCode += "_" + country;
170  }
171 
172  return QLocale(localeCode);
173 }
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.
71 {
72  return ":/translations/qt/";
73 }

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.
176 {
178 
179  const QStringList parts{locale.name().split("-")};
180 
181  if(parts.length() == 0 || parts.length() > 3) {
182  assert(0 && "Failed to extract locale name, will fail to set preferences");
183  return;
184  }
185 
186  if(parts.length() == 1) {
187  prefs.setLanguageIsoCode(parts[0].toStdString());
188  return;
189  }
190 
191  if(parts.length() == 2) {
192  prefs.setLanguageIsoCode(parts[0].toStdString());
193  prefs.setCountryIsoCode(parts[1].toStdString());
194  return;
195  }
196 
197  if(parts.length() == 3) {
198  prefs.setLanguageIsoCode(parts[0].toStdString());
199  prefs.setScriptIsoCode(parts[1].toStdString());
200 
201  const QStringList countryAndMaybeCodesetOrModifier{parts[2].split(".")};
202  assert(countryAndMaybeCodesetOrModifier.length() > 0 && countryAndMaybeCodesetOrModifier.length() <= 3);
203 
204  if(countryAndMaybeCodesetOrModifier.length() > 0) {
205  prefs.setCountryIsoCode(countryAndMaybeCodesetOrModifier[0].toStdString());
206  }
207  return;
208  }
209 }
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.
76 {
77  QCoreApplication* application{QCoreApplication::instance()};
78  if(application == nullptr) {
79  assert(0 && "Attempting to set application translator before app is created");
80  return;
81  }
82 
83  // Remove and destroy old translators
84  purgeTranslators(application);
85 
86  // Install the new translators
87  const auto loadAndAddTranslator = [&application](const QString& file, const QString& directory) {
88  QTranslator* translator{new QTranslator()};
89  translator->load(file, directory);
90  installTranslator(application, translator);
91  };
95 }
const QString geometrizeTranslationFilePrefix
Definition: localization.cpp:58
const QString qtTranslationFilePrefix
Definition: localization.cpp:56
QString getAppTranslationResourceDirectory()
getAppTranslationResourceDirectory Gets the resource path where translation files specific to the app...
Definition: localization.cpp:65
const QString qtBaseTranslationFilePrefix
Definition: localization.cpp:57
QString getBinaryTranslationFileExtension()
getBinaryTranslationFileExtension Gets the file extension for Qt binary translation files...
Definition: localization.cpp:60
QString getQtTranslationResourceDirectory()
getQtTranslationResourceDirectory Gets the resource path where translation files for Qt itself are st...
Definition: localization.cpp:70

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_"}