A set of helpful utility functions. More...
#include <Qtx.h>

Classes | |
| class | BackgroundData |
| Stores background data. More... | |
| class | CmdLineArgs |
| Get access to the command line arguments in the C-like manner. More... | |
| class | Localizer |
| Localization helper. More... | |
Public Types | |
| enum | AlignmentFlags { AlignLeft = Qt::AlignLeft , AlignLeading = Qt::AlignLeading , AlignRight = Qt::AlignRight , AlignTrailing = Qt::AlignTrailing , AlignHCenter = Qt::AlignHCenter , AlignJustify = Qt::AlignJustify , AlignAbsolute = Qt::AlignAbsolute , AlignHorizontal_Mask = Qt::AlignHorizontal_Mask , AlignTop = Qt::AlignTop , AlignBottom = Qt::AlignBottom , AlignVCenter = Qt::AlignVCenter , AlignVertical_Mask = Qt::AlignVertical_Mask , AlignCenter = Qt::AlignCenter , AlignOutLeft = Qt::AlignVCenter << 2 , AlignOutRight = AlignOutLeft << 2 , AlignOutTop = AlignOutRight << 2 , AlignOutBottom = AlignOutTop << 2 } |
| Widget alignment flags. More... | |
| enum | PathType { PT_OpenFile , PT_SaveFile , PT_Directory } |
| Path type, indicates required directory/file operation. More... | |
| enum | { AppropriateRole = Qt::UserRole + 100 } |
| Custom data roles. More... | |
| enum | Appropriate { Shown , Hidden , Toggled } |
| enum | SubstMode { Always , Never , Auto } |
| Environment variables substitution mode. More... | |
| enum | VisibilityState { ShownState , HiddenState , UnpresentableState } |
| object visibility state More... | |
| enum | HeaderViewFlags { ShowNone = 0x000 , ShowText = 0x001 , ShowIcon = 0x010 , ShowAll = ShowText | ShowIcon } |
| Header view flags. More... | |
| enum | CustomDataType { IdType } |
| Type of the custom data (for custom tree model) More... | |
| enum | BackgroundMode { NoBackground , ColorBackground , SimpleGradientBackground , CustomGradientBackground } |
| Background mode. More... | |
| enum | TextureMode { CenterTexture , TileTexture , StretchTexture } |
| Texture mode. More... | |
Static Public Member Functions | |
| static QString | toQString (const char *, const int=-1) |
| Convert character array (ASCII string) to the QString. More... | |
| static QString | toQString (const short *, const int=-1) |
| Convert integer array (UNICODE string) to the QString. More... | |
| static QString | toQString (const unsigned char *, const int=-1) |
| Convert character array (ASCII string) to the QString. More... | |
| static QString | toQString (const unsigned short *, const int=-1) |
| Convert integer array (UNICODE string) to the QString. More... | |
| static void | setTabOrder (QWidget *,...) |
| Set tab order for specified list of widgets. More... | |
| static void | setTabOrder (const QWidgetList &) |
| Set tab order for specified list of widgets. More... | |
| static void | alignWidget (QWidget *, const QWidget *, const int) |
| Align widget src relative to widget ref acording to the alignment flags alignFlags. More... | |
| static void | simplifySeparators (QWidget *, const bool=true) |
| Remove (recursively) unnecessary separators from the menu or toolbar. More... | |
| static bool | isParent (QObject *, QObject *) |
Return true if specified parent is a parent object of given child (in terms of QObject). More... | |
| static QObject * | findParent (QObject *, const char *) |
| Find the parent object of class specified by className (in terms of QObject). More... | |
| static QString | dir (const QString &, const bool=true) |
| Return directory part of the file path. More... | |
| static QString | file (const QString &, const bool=true) |
| Return file name part of the file path. More... | |
| static QString | extension (const QString &, const bool=false) |
| Return extension part of the file path. More... | |
| static QString | libraryName (const QString &) |
| EXtract base library name. More... | |
| static QString | library (const QString &) |
| Convert the given parameter to the platform-specific library name. More... | |
| static QString | tmpDir () |
| Get the temporary directory name. More... | |
| static bool | mkDir (const QString &) |
| Create directory recursively including all intermediate sub directories. More... | |
| static bool | rmDir (const QString &) |
| Remove directory recursively including all subdirectories and files. More... | |
| static bool | dos2unix (const QString &) |
| Convert text file from DOS format to UNIX. More... | |
| static QString | addSlash (const QString &) |
| Add a slash (platform-specific) to the end of path if it is not already there. More... | |
| static QString | joinPath (const QStringList &) |
| Return full path obtained by joining given components with the native directory separator. More... | |
| static QCompleter * | pathCompleter (const PathType, const QString &=QString()) |
| Create path completer which can be used in the widgets to provide auto completions. More... | |
| static QString | findEnvVar (const QString &, int &, int &) |
| Parse given string to retrieve environment variable. More... | |
| static QString | makeEnvVarSubst (const QString &, const SubstMode=Auto) |
| Substitute environment variables by their values. More... | |
| static int | rgbSet (const QColor &) |
| Pack the specified color into integer RGB set. More... | |
| static int | rgbSet (const int, const int, const int) |
| Pack the specified RGB color components into integer RGB set. More... | |
| static QColor | rgbSet (const int) |
| Unpack the specified integer RGB set to the color. More... | |
| static void | rgbSet (const int, int &, int &, int &) |
| Unpack the specified integer RGB set to the three RGB components. More... | |
| static QColor | scaleColor (const int, const int, const int) |
| Return the color specified by the index between min (blue) and max (red). More... | |
| static void | scaleColors (const int, QColorList &) |
| Generate required number of colors aligned from blue to red. More... | |
| static QPixmap | scaleIcon (const QPixmap &, const unsigned, const unsigned=0) |
| Scale the pixmap to the required size. More... | |
| static QImage | grayscale (const QImage &) |
| Convert given image to the grayscale format. More... | |
| static QPixmap | grayscale (const QPixmap &) |
| Convert given pixmap to the grayscale format. More... | |
| static QImage | transparentImage (const int, const int, const int=-1) |
| Create transparent image. More... | |
| static QPixmap | transparentPixmap (const int, const int, const int=-1) |
| Create transparent pixmap. More... | |
| static QPixmap | composite (const QPixmap &, const int, const int, const QPixmap &=QPixmap()) |
| Create composite pixmap. More... | |
| static QString | colorToString (const QColor &) |
| Convert color to the string representation. More... | |
| static bool | stringToColor (const QString &, QColor &) |
| Create color from the string representation. More... | |
| static QString | biColorToString (const QColor &, const int) |
| Convert bi-color value to the string representation. More... | |
| static bool | stringToBiColor (const QString &, QColor &, int &) |
| Restore bi-color value from the string representation. More... | |
| static QColor | mainColorToSecondary (const QColor &, int) |
| Compute secondary color value from specified main color and delta. More... | |
| static QString | gradientToString (const QLinearGradient &) |
| Dump linear gradient to the string description. More... | |
| static QString | gradientToString (const QRadialGradient &) |
| Dump radial gradient to the string description. More... | |
| static QString | gradientToString (const QConicalGradient &) |
| Dump conical gradient to the string description. More... | |
| static bool | stringToLinearGradient (const QString &, QLinearGradient &) |
| Create linear gradient from its string representation. More... | |
| static bool | stringToRadialGradient (const QString &, QRadialGradient &) |
| Create radial gradient from its string representation. More... | |
| static bool | stringToConicalGradient (const QString &, QConicalGradient &) |
| Create conical gradient from its string representation. More... | |
| static QString | backgroundToString (const BackgroundData &) |
| Convert background data to the string representation. The resulting string consists of several sub-strings separated by ';' symbol. These sub-strings represent: More... | |
| static BackgroundData | stringToBackground (const QString &) |
| Restore background data from the string representation. More... | |
| static long | versionToId (const QString &) |
| Convert string representation of version identifier to the numerical value. Resulting value can be used for comparison of different versions (lower, higher, equal). More... | |
| static QString | qtDir (const QString &=QString()) |
| Get Qt installation directory. More... | |
| static QFont | stringToFont (const QString &fontDescription) |
| static QString | getenv (const QString &envVar) |
| static void * | getDisplay () |
| Open the default X display and returns pointer to it. This method is available on Linux only. More... | |
| static Qt::HANDLE | getVisual () |
| Returns pointer to X visual suitable for 3D rendering. This method is available on Linux only. More... | |
| static void | initDefaultSurfaceFormat () |
| Set default QSurfaceFormat for an application. More... | |
A set of helpful utility functions.
The class implements a set of the static functions which can be used for the different purposes:
| anonymous enum |
| enum Qtx::AlignmentFlags |
Widget alignment flags.
| enum Qtx::Appropriate |
| enum Qtx::BackgroundMode |
| enum Qtx::CustomDataType |
| enum Qtx::HeaderViewFlags |
| enum Qtx::PathType |
| enum Qtx::SubstMode |
Environment variables substitution mode.
| enum Qtx::TextureMode |
| enum Qtx::VisibilityState |
|
static |
Add a slash (platform-specific) to the end of path if it is not already there.
| path | directory path |
Align widget src relative to widget ref acording to the alignment flags alignFlags.
| src | source widget (being aligned) |
| ref | reference widget (source widget being aligned to) |
| alignFlags | alignment flags (Qtx::AlignmentFlags) |
References AlignBottom, AlignHCenter, AlignLeft, AlignOutBottom, AlignOutLeft, AlignOutRight, AlignOutTop, AlignRight, AlignTop, and AlignVCenter.
|
static |
Convert background data to the string representation. The resulting string consists of several sub-strings separated by ';' symbol. These sub-strings represent:
Backward conversion can be done with stringToBackground() method.
| bgData | background data |
References colorToString(), Qtx::BackgroundData::gradient(), gradientToString(), Qtx::BackgroundData::isTextureShown(), Qtx::BackgroundData::mode(), and Qtx::BackgroundData::texture().
|
static |
Convert bi-color value to the string representation.
Bi-color value is specified as main color and integer delta value that is used to calculate secondary color by changing paremeters of the main color ("saturation" and "value" components in HSV notation).
The resulting string consists of two sub-strings separated by '|' symbol. The first part represents main color (see colorToString() for more details), the second part is a delta value.
Backward conversion can be done with stringToBiColor() method.
| color | color to be converted |
| delta | delta value |
References OCCViewer::color(), and colorToString().
|
static |
Convert color to the string representation.
The resulting string is in the one of two possible formats (RR, GG, BB and AA value represent red, green, blue and alpha components of the color):
If color is invalid, null string is returned.
Backward conversion can be done with stringToColor() method.
| color | color to be converted |
References OCCViewer::color().
|
static |
Create composite pixmap.
Pixmap pix is drawn over pixmap dest with coordinates specified relatively to the upper left corner of dest. If dest is not given, the new empty pixmap with appropriate size created instead.
| pix | source pixmap |
| x | horizontal shift |
| y | vertical shift |
| dest | background pixmap |
References transparentImage().
|
static |
Return directory part of the file path.
If the file path does not include directory part (the file is in the current directory), null string is returned.
| path | file path |
| abs | if true (default) path parameter is treated as absolute file path |
|
static |
Convert text file from DOS format to UNIX.
The function replaces "LF/CR" symbols sequence by "LF" symbol.
| absName | file name |
true if the file is converted successfully and false in case of any error < TODO: conversion from 'size_t' to 'int'
< TODO: conversion from 'size_t' to 'int'
References dir().
|
static |
Return extension part of the file path.
| path | file path |
| full | if true complete extension (all extensions, dot separated) is returned, otherwise (default) only last extension is returned |
|
static |
Return file name part of the file path.
| path | file path |
| withExt | if true (default) complete file name (with all extension except the last) is returned, otherwise only base name is returned |
|
static |
Parse given string to retrieve environment variable.
Looks through the string for the environment variable patterns. If string contains variable satisfying any pattern, the variable name is returned, start index of the variable is returned in the start parameter, and length of the variable is returned in the len parameter.
Supported environment variables definitions:
| str | string being processed |
| start | if variable is found, this parameter contains its starting position in the str |
| len | if variable is found, this parameter contains its length |
References rx.
Find the parent object of class specified by className (in terms of QObject).
| obj | current object |
| className | class name of the parent |
|
static |
Open the default X display and returns pointer to it. This method is available on Linux only.
|
static |
|
static |
Returns pointer to X visual suitable for 3D rendering. This method is available on Linux only.
References getDisplay(), hex(), and Plot2d::None.
|
static |
Dump conical gradient to the string description.
| gradient | conical gradient to be converted |
References colorToString().
|
static |
Dump linear gradient to the string description.
| gradient | linear gradient to be converted |
References colorToString().
|
static |
Dump radial gradient to the string description.
| gradient | radial gradient to be converted |
References colorToString().
|
static |
Convert given image to the grayscale format.
| img | initial image |
|
static |
Convert given pixmap to the grayscale format.
| pix | initial pixmap |
References grayscale().
|
static |
Set default QSurfaceFormat for an application.
This application property should be set before a creation of the QApplication.
Return true if specified parent is a parent object of given child (in terms of QObject).
This function works recursively. It means that true is also returned if parent is a grand-father, grand-grand-father, etc of child. If the same object is given as both parent and child, true is also returned.
| child | child object |
| parent | parent object |
true if the parent is a parent of child
|
static |
Return full path obtained by joining given components with the native directory separator.
| path | Separate path components |
|
static |
Convert the given parameter to the platform-specific library name.
The function appends platform-specific prefix (lib) and suffix (.dll/.so) to the library file name. For example, if libName = "mylib", "libmylib.so" is returned for Linux and mylib.dll for Windows.
| libName | short library name |
References addSlash(), dir(), extension(), and file().
|
static |
EXtract base library name.
The function removes platform-specific prefix (lib) and suffix (.dll/.so) from the library file name. For example, if str = "libmylib.so", "mylib" is returned..
| libName | library name |
References extension(), and file().
|
static |
Compute secondary color value from specified main color and delta.
Secondary color is calculated by changing paremeters of the main color ("saturation" and "value" components in HSV notation) using specified delta.
If main color is invalid, result of the function is also invalid color.
| color | source main color |
| delta | delta value |
References OCCViewer::color().
Substitute environment variables by their values.
Environment variable is substituted by its value.
| str | string to be processed |
References Always, findEnvVar(), getenv(), and Never.
|
static |
Create directory recursively including all intermediate sub directories.
true if the directory is successfully created and false otherwise
|
static |
Create path completer which can be used in the widgets to provide auto completions.
Create an instance of QCompleter class and returns the pointer on it. The calling function is responsible to the desstroying of the created completer object.
The QCompleter class provides completions based on a item model and can be used in such as QLineEdit and QComboBox. When the user starts typing a word, QCompleter suggests possible ways of completing the word, based on a word list.
| type | path type (Qtx::PathType) |
| filter | file/directory filters (list of wildcards, separated by ";;") |
References PT_Directory, PT_OpenFile, PT_SaveFile, and rx.
|
static |
Get Qt installation directory.
The function tries to detect qt installation directory by analyzing the system variables in the following order:
Optional parameter context allows obtaining subdirectory in the Qt installation directory.
| context | optional sub-directory |
References getenv().
|
static |
Unpack the specified integer RGB set to the color.
| rgb | packed color |
References rgbSet().
|
static |
Pack the specified RGB color components into integer RGB set.
| r | red component |
| g | green component |
| b | blue component |
|
static |
Unpack the specified integer RGB set to the three RGB components.
| rgb | packed color |
| r | returned unpacked red component |
| g | returned unpacked green component |
| b | returned unpacked blue component |
|
static |
Pack the specified color into integer RGB set.
| c | unpacked color |
|
static |
Remove directory recursively including all subdirectories and files.
true if the directory is successfully removed and false otherwise
|
static |
Return the color specified by the index between min (blue) and max (red).
| index | color index |
| min | required minimum hue value |
| max | required maximum hue value |
|
static |
Generate required number of colors aligned from blue to red.
| num | required number of colors |
| lst | returned set of colors |
References scaleColor().
|
static |
Scale the pixmap to the required size.
If h is 0 (default) the value of w is used instead (to create square pixmap).
| icon | pixmap to be resized |
| w | required pixmap width |
| h | required pixmap height |
|
static |
Set tab order for specified list of widgets.
| widgets | list of widgets |
|
static |
Set tab order for specified list of widgets.
The function has arbitrary number of parameters, each should be hovewer of QWidget* type. Last parameter should be null pointer.
| first | first widget in the sequence |
|
static |
Remove (recursively) unnecessary separators from the menu or toolbar.
| wid | widget, should be of QMenu* or QToolBar* class |
|
static |
Restore background data from the string representation.
The string should consist of several sub-strings separated by ';' symbol. Each sub-string consists of keyword/value couple, in form of "<keyword>=<value>". The sub-strings can follow in arbitrary order, some keywords can be missing. The background data is described by the following values:
Also, for backward compatibility, background data can be represented by single color value, see stringToColor().
Backward conversion can be done with backgroundToString() method. Returns invalid background if conversion could not be done.
| theString | string representation of the background data |
References CenterTexture, ColorBackground, CustomGradientBackground, NoBackground, Qtx::BackgroundData::setColor(), Qtx::BackgroundData::setGradient(), Qtx::BackgroundData::setMode(), Qtx::BackgroundData::setTexture(), Qtx::BackgroundData::setTextureShown(), StretchTexture, stringToColor(), stringToConicalGradient(), stringToInt(), stringToLinearGradient(), and stringToRadialGradient().
|
static |
Restore bi-color value from the string representation.
Bi-color value is specified as main color and integer delta value that is used to calculate secondary color by changing paremeters of the main color ("saturation" and "value" components in HSV notation).
The parameter str should consist of two sub-strings separated by '|' symbol. The first part represents main color (see stringToColor() for more details), the second part is a delta value.
Backward conversion can be done with biColorToString() method.
| str | string representation of the bi-color value |
| color | resulting color value |
| delta | resulting delta value |
true if the conversion is successful and false otherwiseReferences OCCViewer::color(), and stringToColor().
|
static |
Create color from the string representation.
The parameter str must be in the one of following formats (RR, GG, BB and AA value represent red, green, blue and alpha components of the color):
RR, GG, BB and optional AA values represent red, green, blue and alpha components of the color in hexadecimal form)RR, GG, BB and optional AA values represent red, green, blue and alpha components of the color in decimal form)RR, GG and BB values represent red, green and blue components of the color in hexadecimal form)Backward conversion can be done with colorToString() method.
| str | string representation of the color |
| color | resulting color value |
true if the conversion is successful and false otherwiseReferences OCCViewer::color(), and rgbSet().
|
static |
Create conical gradient from its string representation.
| str | string representation of the conical gradient |
| gradient | resulting conical gradient object |
true if the conversion is successful and false otherwise References stringToColor().
|
static |
Creates font from string description
|
static |
Create linear gradient from its string representation.
| str | string representation of the linear gradient |
| gradient | resulting linear gradient object |
true if the conversion is successful and false otherwise References stringToColor().
|
static |
Create radial gradient from its string representation.
| str | string representation of the radial gradient |
| gradient | resulting radial gradient object |
true if the conversion is successful and false otherwise References stringToColor().
|
static |
Get the temporary directory name.
References getenv().
|
static |
Convert character array (ASCII string) to the QString.
| str | character array |
| len | array length, if < 0, the array should be zero-terminated |
|
static |
Convert integer array (UNICODE string) to the QString.
| str | integer array |
| len | array length, if < 0, the array should be zero-terminated |
References toQString().
|
static |
Convert character array (ASCII string) to the QString.
| str | character array |
| len | array length, if < 0, the array should be zero-terminated |
|
static |
Convert integer array (UNICODE string) to the QString.
| str | integer array |
| len | array length, if < 0, the array should be zero-terminated |
|
static |
Create transparent image.
| w | required image width |
| h | required image height |
| d | required image depth |
|
static |
Create transparent pixmap.
| w | required image width |
| h | required pixmap height |
| d | required pixmap depth |
References transparentImage().
|
static |
Convert string representation of version identifier to the numerical value. Resulting value can be used for comparison of different versions (lower, higher, equal).
String representation of the version consists of zero or more components:
[major[.minor[.release[patchid]]]]
where
If version string does not include any component or has invalid format, the function returns 0.
Examples: 1.0 - version 1.0 1.2.3a - version 1.2.3 alpha 3.3.3b1 - version 3.3.3 beta 1 7.4.0rc1 - version 7.4.0 release candidate 1 7.4.0dev - dev version, i.e. future version 7.4.1 (or 7.5.0)
| version | string representation of version |