Geometrize  1.0
An application for geometrizing images into geometric primitives
Namespaces | Functions
util.cpp File Reference
#include "util.h"
#include <cassert>
#include <cmath>
#include <csignal>
#include <fstream>
#include <random>
#include <QApplication>
#include <QClipboard>
#include <QCoreApplication>
#include <QCursor>
#include <QDateTime>
#include <QDesktopServices>
#include <QDir>
#include <QDirIterator>
#include <QFileInfo>
#include <QGuiApplication>
#include <QMessageBox>
#include <QObject>
#include <QPixmap>
#include <QPoint>
#include <QScreen>
#include <QStandardPaths>
#include <QTextStream>
#include <QUrl>
#include <QUuid>
#include <QWindow>
#include "dialog/imagetaskwindow.h"
#include "dialog/scriptconsole.h"
#include "script/command.h"
#include "script/commandhandler.h"
#include "geometrize/commonutil.h"

Namespaces

 geometrize
 
 geometrize::util
 

Functions

void geometrize::util::debugBreak ()
 debugBreak Forces the debugger to break/halt the application when this is called. More...
 
void geometrize::util::printToConsole (const std::string &str)
 printToConsole A convenience function for printing a string to the command-line console. More...
 
void geometrize::util::printToAllScriptConsoleWidgets (const std::string &str)
 printToAllScriptConsoleWidgets A convenience function for printing a string to all the GUI console widgets in the application More...
 
void geometrize::util::messageBox (const std::string &str)
 messageBox A convenience function for displaying a message box containing a message. More...
 
void geometrize::util::processApplicationEvents ()
 processApplicationEvents Processes all pending application events for the calling thread. More...
 
bool geometrize::util::fileExists (const std::string &filePath)
 fileExists Checks if a file exists, returns true if it does. More...
 
bool geometrize::util::directoryExists (const std::string &dirPath)
 directoryExists Checks if a directory exists, returns true if it does. More...
 
bool geometrize::util::directoriesExist (const std::vector< std::string > &dirPaths)
 directoriesExist Checks if the given directories exist, returns true if all do. More...
 
bool geometrize::util::directoryContainsFile (const std::string &dirPath, const std::string &fileName)
 directoryContainsFile Checks if the directory contains the given file, returns true if it does. More...
 
bool geometrize::util::createDirectory (const std::string &dirPath)
 createDirectory Creates the directory at the given path, recursively creating subdirectories if needed More...
 
std::string geometrize::util::readFileAsString (const std::string &filePath)
 readFileAsString Reads a file, returning a string containing the contents. More...
 
std::vector< std::string > geometrize::util::getFilePathsForDirectory (const std::string &dirPath)
 getFilePathsForDirectory Gets the absolute file paths to the files in the given directory. More...
 
std::vector< std::string > geometrize::util::getSubdirectoriesForDirectory (const std::string &dirPath)
 getSubdirectoriesForDirectory Gets the absolute paths for direct subdirectories of the given directory. More...
 
bool geometrize::util::endsWith (const std::string &value, const std::string &ending)
 
std::vector< std::string > geometrize::util::getFilesWithExtension (const std::string &dirPath, const std::string &extension)
 getFilesWithExtension Gets the absolute file paths to the files with the given extension in the given directory. More...
 
std::string geometrize::util::getFirstFileWithExtension (const std::string &dirPath, const std::string &extension)
 getFirstFileWithExtension Gets the absolute file path to the first file with the given extension in the given directory. More...
 
std::string geometrize::util::getFirstFileWithExtensions (const std::string &dirPath, const std::vector< std::string > &extensions)
 getFirstFileWithExtensions Gets the absolute file path to the first file with one of the given extensions in the given directory. More...
 
std::vector< std::string > geometrize::util::getScriptsForPath (const std::string &path)
 getScriptsForPath Gets the absolute file paths to the script files (*.chai) for the given directory, using recursive search. More...
 
std::vector< std::string > geometrize::util::getScriptsForPaths (const std::vector< std::string > &dirPaths)
 getScriptsForPaths Gets the absolute file paths to the script files (*.chai) for the given directories, using recursive search. More...
 
std::string geometrize::util::getDirectoryForFilePath (const std::string &filePath)
 getDirectoryForFilePath Gets the directory path from the given local file path. More...
 
std::string geometrize::util::getFileNameForFilePath (const std::string &filePath)
 getFileNameForFilePath Gets the filename from the given local file path. More...
 
bool geometrize::util::openInDefaultApplication (const std::string &path)
 openInDefaultApplication Opens the given path in the default application. More...
 
bool geometrize::util::revealInDefaultApplication (const std::string &path)
 revealInDefaultApplication Reveals the given path in the parent folder (or path with the filename trimmed). More...
 
void geometrize::util::clearGlobalClipboard ()
 clearGlobalClipboard Clears the global system clipboard contents. More...
 
std::string geometrize::util::getGlobalClipboardText ()
 getGlobalClipboardText Gets the global system clipboard text. More...
 
void geometrize::util::setGlobalClipboardText (const std::string &text)
 setClipboardText Sets the global system clipboard text. More...
 
bool geometrize::util::stringBeginsWith (const std::string &str, const std::string &prefix)
 stringBeginsWith Checks if a string begins with the given prefix. More...
 
bool geometrize::util::stringEndsWith (const std::string &str, const std::string &suffix)
 stringEndsWith Checks if a string ends with the given suffix. More...
 
std::string geometrize::util::getApplicationDirectoryLocation ()
 getApplicationDirectory Get directory that the application is in. More...
 
std::string geometrize::util::getAppDataLocation ()
 getAppDataLocation Returns a directory location where persistent application data can be stored. More...
 
std::string geometrize::util::getHomeDirectoryLocation ()
 getHomeDirectoryLocation Returns a path to where the user's home directory is. More...
 
std::string geometrize::util::getDesktopDirectoryLocation ()
 getDesktopDirectoryLocation Returns a path to where the user's desktop is. More...
 
bool geometrize::util::writeStringToFile (const std::string &str, const std::string &path)
 writeStringToFile Writes the string to the file path, attempting to overwrite any existing file at the path. More...
 
std::string geometrize::util::percentEncode (const std::string &str)
 percentEncode Returns a percent-encoded copy of the input string. More...
 
int geometrize::util::randomInRange (int lower, int upper)
 randomInRange Returns a random integer in the range [lower, upper], inclusive. Note that this uses thread-local RNGs under the hood. This must not be called on the same thread as the Geometrize shape mutation code - otherwise the shape generation may not be deterministic. More...
 
std::vector< std::string > geometrize::util::split (const std::string &s, char delimiter)
 split Splits a given string into a vector of tokens using the given delimiter. More...
 
int geometrize::util::getCursorX ()
 getCursorX Gets the x-coordinate of the cursor in global screen coordinates. More...
 
int geometrize::util::getCursorY ()
 getCursorY Gets the y-coordinate of the cursor in global screen coordinates. More...
 
void geometrize::util::setCursorPos (int x, int y)
 setCursorPos Sets the cursor position in global screen coordinates. More...
 
std::string geometrize::util::getOperatingSystemProductType ()
 getOperatingSystemProductType Returns the product name of the operating system this application is running in. More...
 
bool geometrize::util::saveWidgetScreenshot (const std::string &path, QWidget *widget)
 saveWidgetScreenshot Takes a screenshot of the given widget and saves it as a .png image to the given path. More...
 
std::vector< std::string > geometrize::util::getAllNamedWidgets ()
 getAllWidgetNames Returns a vector containing the names of all the existing widgets in the application More...
 
std::vector< std::string > geometrize::util::getAllNamedGeometrizeWidgets ()
 getAllWidgetNames Returns a vector containing the names of all the widgets in the application with "geometrize" in their name More...
 
QWidget * geometrize::util::getWidgetByName (const std::string &widgetName)
 getWidgetByName Returns the first found instance of the existing widget with the given name More...
 
std::vector< std::string > geometrize::util::getAllNamedCommandHandlers ()
 getAllNamedCommandHandlers Gets all of the existing objects in the application that implement the CommandHandler interface and can be addressed by name More...
 
geometrize::script::CommandHandlergeometrize::util::getCommandHandlerByName (const std::string &name)
 getCommandHandlerByName Returns the first found instance of the existing command handler with the given name More...
 
void geometrize::util::sendCommand (const std::string &target, const std::string &command)
 sendCommand Sends a command to the given command handler More...
 
void geometrize::util::sendCommand (const std::string &target, geometrize::script::Command &command)
 sendCommand Sends a command to the given command handler More...
 
void geometrize::util::broadcastCommand (const std::string &command)
 broadcastCommand Sends a command to all command handlers More...
 
void geometrize::util::broadcastCommand (geometrize::script::Command &command)
 broadcastCommand Sends a command to all command handlers More...
 
std::string geometrize::util::getFormattedTimestamp (const std::string &formatString)
 getFormattedTimestamp Gets a formatted timestamp for the current local time More...
 
std::string geometrize::util::getFilenameTimestamp ()
 getFilenameTimestamp Gets a filename timestamp string for the current local time More...
 
std::string geometrize::util::getUuidString ()
 getUuidString Gets a Universally Unique Identifier (UUID) as a string More...
 
void geometrize::util::setWidgetSize (QWidget *widget, int width, int height)
 setWidgetSize Sets the size of the given widget in pixels. More...
 
void geometrize::util::setWidgetPosition (QWidget *widget, int x, int y)
 setWidgetPosition Sets the widget to the given position. More...
 
void geometrize::util::arrangeWidgetsInGrid (const std::vector< QWidget * > &widgets, int centerX, int centerY, int xDim, int yDim, int resizeX, int resizeY)
 arrangeWidgetsInGrid Arranges the given widgets into a grid shape More...
 
void geometrize::util::arrangeImageTaskWidgetsInGrid (int centerX, int centerY, int xDim, int yDim, int resizeX, int resizeY)
 arrangeImageTaskWidgetsInGrid Arranges all the open image task widgets into a grid shape More...
 
void geometrize::util::arrangeWidgetsInGridOnMonitor (const std::vector< QWidget * > &widgets, int screenIdx, int resizeX, int resizeY)
 arrangeWidgetsInGridOnMonitor Arranges the given widgets into a grid on the given monitor More...
 
void geometrize::util::arrangeImageTaskWidgetsInGridOnMonitor (int screenIdx, int resizeX, int resizeY)
 arrangeImageTaskWidgetsInGridOnMonitor Arranges all the open image task widgets into a grid on the given monitor More...
 
void geometrize::util::arrangeWidgetsInGridOnPrimaryMonitor (const std::vector< QWidget * > &widgets, int resizeX, int resizeY)
 arrangeWidgetsInGridOnPrimaryMonitor Arranges the given widgets into a grid on the primary monitor More...
 
void geometrize::util::arrangeImageTaskWidgetsInGridOnPrimaryMonitor (int resizeX, int resizeY)
 arrangeImageTaskWidgetsInGridOnPrimaryMonitor Arranges all the open image task widgets into a grid on the given monitor More...
 
void geometrize::util::fitWidgetsInGridOnMonitor (const std::vector< QWidget * > &widgets, int screenIdx)
 fitWidgetsInGridOnMonitor Fits the given widgets into a grid on the given monitor More...
 
void geometrize::util::fitImageTaskWidgetsInGridOnMonitor (int screenIdx)
 fitImageTaskWidgetsInGridOnMonitor Fits all of the open image task widgets into a grid on the given monitor More...
 
void geometrize::util::fitWidgetsInGridOnPrimaryMonitor (const std::vector< QWidget * > &widgets)
 fitWidgetsInGridOnPrimaryMonitor Fits the given widgets into a grid on the primary monitor More...
 
void geometrize::util::fitImageTaskWidgetsInGridOnPrimaryMonitor ()
 fitImageTaskWidgetsInGridOnPrimaryMonitor Fits all of the open image task widgets into a grid on the primary monitor More...