Isis 3.0 Programmer Reference
Back | Home
Color.cpp
1 #include "Color.h"
2 
3 #include <QColor>
4 #include <QString>
5 
6 #include "IException.h"
7 
8 namespace Isis {
9  QColor Color::fromRGBAString(QString string) {
10  QColor result;
11 
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));
15  }
16 
17  return result;
18  }
19 
20 
21  QString Color::toRGBAString(QColor color) {
22  QString result;
23 
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'));
30  }
31  else {
32  throw IException(IException::Unknown,
33  "Can not convert an invalid color to an RGBA string. There is no string representation "
34  "of an invalid color.",
35  _FILEINFO_);
36  }
37 
38  return result;
39  }
40 
41 
42  QRegExp Color::colorRGBAFormat() {
43  return QRegExp("^#[0-9a-fA-F]{8}$");
44  }
45 }
int toInt(const QString &string)
Global function to convert from a string to an integer.
Definition: IString.cpp:108
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:38
A type of error that cannot be classified as any of the other error types.
Definition: IException.h:126

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the ISIS Support Center
File Modified: 07/12/2023 23:16:05