VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
Classes | Functions
Util Namespace Reference

Frequently used static utility functions. More...

Classes

class  QQmlListPropertyOnQList
 Helper class which creates QQmlListProperty objects directly on QList members fields. More...
 

Functions

template<typename T >
QVariantList toVariantList (const QList< T > &list)
 Returns list converted to a QVariantList. More...
 
template<typename T >
QList< T > toList (const QVariantList &list)
 Returns list converted to a QList. More...
 
template<typename T >
QVariantMap toVariantMap (const QMap< QString, T > map)
 Returns map converted to a QVariantMap. More...
 
template<typename T >
QMap< QString, T > toMap (const QVariantMap &map)
 Returns map converted to a QMap. More...
 
template<typename T >
const T & clamp (const T &a, const T &min, const T &max)
 Returns the value a clamped between min and max. More...
 
static float smoothstep (float t)
 Computes the value of a smoothed interpolation curve between 0.0f and 1.0f. More...
 
static float qrandF ()
 Returns a pseudo-random number in the range [0, 1). More...
 
template<typename TObject >
TObject * findParentOfType (QObject *node)
 Returns our closest ancestor which is of type TObject. More...
 
QString getPathToAsset (const QString &assetPath)
 Returns the platform dependent path to assetPath. More...
 
QUrl getUrlPathToAsset (const QString &assetPath)
 Returns platform dependent path URL to assetPath. More...
 
QString getPathToFont (const QString &fontPath)
 Returns the platform dependent path to the font in fontPath. More...
 
QString getPathToImage (const QString &imagePath)
 Returns the platform dependent path to the image in imagePath. More...
 
QString getPathToMovie (const QString &moviePath)
 Returns the platform dependent path to the movie in moviePath. More...
 
QString getPathToLevel (const QString &levelPath)
 Returns the platform dependent path to the level in levelPath. More...
 
QString getPathToSound (const QString &soundPath)
 Returns the platform dependent path to the sound in soundPath. More...
 
QString getPathToData (const QString &dataPath)
 Returns the platform dependent path to the data file in dataPath. More...
 
QString readFileAsQString (const QString &path)
 Returns the entire contents of a text file as a QString. More...
 
std::string readFileAsStdString (const QString &path)
 Returns the entire contents of a text file as a std::string. More...
 
QRectF united (const QRectF &rect, const QPointF &point)
 Expands a QRectF's span to include a point. More...
 
bool javaScriptFuncExists (QObject *object, const char *method)
 Checks if a javascript function exists. More...
 
bool deviceHasTouchScreen ()
 Returns true if the device on which the game is running has a touch screen. More...
 
int getDeviceTouchScreenDeviceId ()
 Returns the device id of the touch screen on the device, or -1 if none exists. More...
 

Detailed Description

Frequently used static utility functions.

Function Documentation

template<typename T >
const T& Util::clamp ( const T &  a,
const T &  min,
const T &  max 
)
inline

Returns the value a clamped between min and max.

Parameters
aValue to clamp
minMinimum value to return
maxMaximum value to return
bool Util::deviceHasTouchScreen ( )

Returns true if the device on which the game is running has a touch screen.

template<typename TObject >
TObject* Util::findParentOfType ( QObject node)

Returns our closest ancestor which is of type TObject.

Parameters
nodeNode to search
int Util::getDeviceTouchScreenDeviceId ( )

Returns the device id of the touch screen on the device, or -1 if none exists.

QString Util::getPathToAsset ( const QString assetPath)

Returns the platform dependent path to assetPath.

Parameters
assetPathPath of asset to resolve.
QString Util::getPathToData ( const QString dataPath)

Returns the platform dependent path to the data file in dataPath.

Parameters
dataPathPath of data file to resolve
QString Util::getPathToFont ( const QString fontPath)

Returns the platform dependent path to the font in fontPath.

Parameters
fontPathPath of font to resolve
QString Util::getPathToImage ( const QString imagePath)

Returns the platform dependent path to the image in imagePath.

Parameters
imagePathPath of image to resolve
QString Util::getPathToLevel ( const QString levelPath)

Returns the platform dependent path to the level in levelPath.

Parameters
levelPathPath of level to resolve
QString Util::getPathToMovie ( const QString moviePath)

Returns the platform dependent path to the movie in moviePath.

Parameters
moviePathPath of movie to resolve
QString Util::getPathToSound ( const QString soundPath)

Returns the platform dependent path to the sound in soundPath.

Parameters
soundPathPath of sound to resolve
QUrl Util::getUrlPathToAsset ( const QString assetPath)

Returns platform dependent path URL to assetPath.

Parameters
assetPathPath of asset to resolve.
bool Util::javaScriptFuncExists ( QObject object,
const char *  method 
)

Checks if a javascript function exists.

Parameters
objectObject to check for method
methodName of method to check
static float Util::qrandF ( )
inlinestatic

Returns a pseudo-random number in the range [0, 1).

QString Util::readFileAsQString ( const QString path)

Returns the entire contents of a text file as a QString.

Parameters
pathPath to file to read
std::string Util::readFileAsStdString ( const QString path)

Returns the entire contents of a text file as a std::string.

Parameters
pathPath to file to read
static float Util::smoothstep ( float  t)
inlinestatic

Computes the value of a smoothed interpolation curve between 0.0f and 1.0f.

Note
This is a conventional smoothstep curve (see http://en.wikipedia.org/wiki/Smoothstep). It is a fifth order polynomial, with zero first and second order derivatives at the endpoints.
Parameters
tParametric value
template<typename T >
QList<T> Util::toList ( const QVariantList &  list)

Returns list converted to a QList.

Note
T must have a valid VariantConverter specialization.
Template Parameters
Typefor conversion
Parameters
listQVariantList to convert
See also
VariantConverter
template<typename T >
QMap<QString, T> Util::toMap ( const QVariantMap &  map)

Returns map converted to a QMap.

Note
T must have a valid VariantConverter specialization.
Template Parameters
Typefor conversion
Parameters
mapQVariantMap to convert
See also
VariantConverter
template<typename T >
QVariantList Util::toVariantList ( const QList< T > &  list)

Returns list converted to a QVariantList.

Note
T must have a valid VariantConverter specialization.
Template Parameters
Typefor conversion
Parameters
listQList to convert
See also
VariantConverter
template<typename T >
QVariantMap Util::toVariantMap ( const QMap< QString, T >  map)

Returns map converted to a QVariantMap.

Note
T must have a valid VariantConverter specialization.
Template Parameters
Typefor conversion
Parameters
mapQMap to convert
See also
VariantConverter
QRectF Util::united ( const QRectF rect,
const QPointF point 
)

Expands a QRectF's span to include a point.

Note
This function is needed because QRectF cannot handle unioning an "empty" rectangle.
Parameters
rectRectangle to expand
pointPoint by which we expand rect