Isis 3 Programmer Reference
Color.cpp
1 #include "Color.h"
2 
3 #include <QColor>
4 #include <QString>
5 
6 #include "IException.h"
7 
8 namespace Isis {
9 
15  QColor Color::fromRGBAString(QString string) {
16  QColor result;
17 
18  if (colorRGBAFormat().exactMatch(string)) {
19  result = QColor(string.mid(1, 2).toInt(NULL, 16), string.mid(3, 2).toInt(NULL, 16),
20  string.mid(5, 2).toInt(NULL, 16), string.mid(7, 2).toInt(NULL, 16));
21  }
22 
23  return result;
24  }
25 
26 
32  QString Color::toRGBAString(QColor color) {
33  QString result;
34 
35  if (color.isValid()) {
36  result = QString("#%1%2%3%4")
37  .arg(color.red(), 2, 16, QChar('0'))
38  .arg(color.green(), 2, 16, QChar('0'))
39  .arg(color.blue(), 2, 16, QChar('0'))
40  .arg(color.alpha(), 2, 16, QChar('0'));
41  }
42  else {
44  "Can not convert an invalid color to an RGBA string. There is no string representation "
45  "of an invalid color.",
46  _FILEINFO_);
47  }
48 
49  return result;
50  }
51 
52 
59  return QRegExp("^#[0-9a-fA-F]{8}$");
60  }
61 }
int toInt(const QString &string)
Global function to convert from a string to an integer.
Definition: IString.cpp:108
static QColor fromRGBAString(QString)
Converts a QString to its QColor.
Definition: Color.cpp:15
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
A type of error that cannot be classified as any of the other error types.
Definition: IException.h:134
static QRegExp colorRGBAFormat()
Get the colorRGBAFormat.
Definition: Color.cpp:58
static QString toRGBAString(QColor)
Convert a QColor to its QString.
Definition: Color.cpp:32
Isis exception class.
Definition: IException.h:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31