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 { 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 | 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 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 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... | |
The class implements a set of the static functions which can be used for the different purposes:
enum Qtx::AlignmentFlags |
enum Qtx::Appropriate |
enum Qtx::BackgroundMode |
enum Qtx::CustomDataType |
enum Qtx::HeaderViewFlags |
enum Qtx::PathType |
enum Qtx::SubstMode |
enum Qtx::TextureMode |
enum Qtx::VisibilityState |
|
static |
path | directory path |
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 |
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().
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 colorToString().
|
static |
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 |
|
static |
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().
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 |
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 References dir().
path | file path |
full | if true complete extension (all extensions, dot separated) is returned, otherwise (default) only last extension is returned |
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 |
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.
obj | current object |
className | class name of the parent |
|
static |
|
static |
|
static |
gradient | linear gradient to be converted |
References colorToString().
|
static |
gradient | radial gradient to be converted |
References colorToString().
|
static |
gradient | conical gradient to be converted |
References colorToString().
|
static |
img | initial image |
|
static |
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 References obj.
|
static |
The function appends platform-specific prefix (lib) and suffix (.dll/.so) to the library file name. For example, if str = "mylib", "libmylib.so" is returned for Linux and mylib.dll for Windows.
str | short library name |
References addSlash(), dir(), extension(), and file().
|
static |
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().
Environment variable is substituted by its value.
str | string to be processed |
References Always, findEnvVar(), and Never.
|
static |
true
if the directory is successfully created and false
otherwise 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 |
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 |
|
static |
c | unpacked color |
r | red component |
g | green component |
b | blue component |
|
static |
|
static |
rgb | packed color |
r | returned unpacked red component |
g | returned unpacked green component |
b | returned unpacked blue component |
|
static |
true
if the directory is successfully removed and false
otherwise index | color index |
min | required minimum hue value |
max | required maximum hue value |
|
static |
num | required number of colors |
lst | returned set of colors |
References scaleColor().
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 |
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 |
widgets | list of widgets |
wid | widget, should be of QMenu* or QToolBar* class |
|
static |
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 |
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 stringToColor().
|
static |
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 rgbSet().
|
static |
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 |
str | string representation of the linear gradient |
gradient | resulting linear gradient object |
true
if the conversion is successful and false
otherwise References stringToColor().
|
static |
str | string representation of the radial gradient |
gradient | resulting radial gradient object |
true
if the conversion is successful and false
otherwise References stringToColor().
|
static |
str | character array |
len | array length, if < 0, the array should be zero-terminated |
str | integer array |
len | array length, if < 0, the array should be zero-terminated |
References toQString().
str | character array |
len | array length, if < 0, the array should be zero-terminated |
References s.
str | integer array |
len | array length, if < 0, the array should be zero-terminated |
References s.
w | required image width |
h | required image height |
d | required image depth |
w | required image width |
h | required pixmap height |
d | required pixmap depth |
References transparentImage().
|
static |
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 |