Isis 3 Programmer Reference
Color.cpp
1
6/* SPDX-License-Identifier: CC0-1.0 */
7#include "Color.h"
8
9#include <QColor>
10#include <QString>
11
12#include "IException.h"
13
14namespace Isis {
15
21 QColor Color::fromRGBAString(QString string) {
22 QColor result;
23
24 if (colorRGBAFormat().exactMatch(string)) {
25 result = QColor(string.mid(1, 2).toInt(NULL, 16), string.mid(3, 2).toInt(NULL, 16),
26 string.mid(5, 2).toInt(NULL, 16), string.mid(7, 2).toInt(NULL, 16));
27 }
28
29 return result;
30 }
31
32
38 QString Color::toRGBAString(QColor color) {
39 QString result;
40
41 if (color.isValid()) {
42 result = QString("#%1%2%3%4")
43 .arg(color.red(), 2, 16, QChar('0'))
44 .arg(color.green(), 2, 16, QChar('0'))
45 .arg(color.blue(), 2, 16, QChar('0'))
46 .arg(color.alpha(), 2, 16, QChar('0'));
47 }
48 else {
50 "Can not convert an invalid color to an RGBA string. There is no string representation "
51 "of an invalid color.",
52 _FILEINFO_);
53 }
54
55 return result;
56 }
57
58
65 return QRegExp("^#[0-9a-fA-F]{8}$");
66 }
67}
static QString toRGBAString(QColor)
Convert a QColor to its QString.
Definition Color.cpp:38
static QRegExp colorRGBAFormat()
Get the colorRGBAFormat.
Definition Color.cpp:64
static QColor fromRGBAString(QString)
Converts a QString to its QColor.
Definition Color.cpp:21
Isis exception class.
Definition IException.h:91
@ Unknown
A type of error that cannot be classified as any of the other error types.
Definition IException.h:118
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
int toInt(const QString &string)
Global function to convert from a string to an integer.
Definition IString.cpp:93