9 QColor Color::fromRGBAString(QString
string) {
12 if (colorRGBAFormat().exactMatch(
string)) {
13 result = QColor(
string.mid(1, 2).
toInt(NULL, 16),
string.mid(3, 2).
toInt(NULL, 16),
14 string.mid(5, 2).
toInt(NULL, 16),
string.mid(7, 2).
toInt(NULL, 16));
21 QString Color::toRGBAString(QColor color) {
24 if (color.isValid()) {
25 result = QString(
"#%1%2%3%4")
26 .arg(color.red(), 2, 16, QChar(
'0'))
27 .arg(color.green(), 2, 16, QChar(
'0'))
28 .arg(color.blue(), 2, 16, QChar(
'0'))
29 .arg(color.alpha(), 2, 16, QChar(
'0'));
33 "Can not convert an invalid color to an RGBA string. There is no string representation "
34 "of an invalid color.",
42 QRegExp Color::colorRGBAFormat() {
43 return QRegExp(
"^#[0-9a-fA-F]{8}$");