QCAD Application Framework
CAD Application Development and Automation.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RColor.h
Go to the documentation of this file.
1 #ifndef RCOLOR_H_
2 #define RCOLOR_H_
3 
4 #include <QCoreApplication>
5 #include <QObject>
6 #include <QColor>
7 #include <QMetaType>
8 #include <QMap>
9 #include <QIcon>
10 #include <QDebug>
11 
12 #define RDEFAULT_QSIZE_ICON QSize(32,10)
13 
21 class RColor: public QColor {
22 
24 
25 
26 public:
27  friend QDataStream& operator<<(QDataStream& stream, const RColor& color);
28 
29  friend QDataStream& operator>>(QDataStream& stream, RColor& color);
30 
31  enum Mode {
33  };
34 
35 public:
36  RColor();
37  RColor(int r, int g, int b, int a = 255, RColor::Mode mode = RColor::Fixed);
39  RColor(const QString & name, RColor::Mode mode = RColor::Fixed);
40 
44  RColor(Qt::GlobalColor color, RColor::Mode mode = RColor::Fixed);
48  RColor(const QColor& color, RColor::Mode mode = RColor::Fixed);
49 
50  int getCustomColorCode() const;
51  int getColorIndex() const;
52 
53  static RColor createFromCadIndex(const QString& code) {
54  return createFromCadIndex(code.toInt());
55  }
56  static RColor createFromCadIndex(int code);
57  static RColor createFromCadCustom(const QString& code) {
58  return createFromCadCustom(code.toInt());
59  }
60  static RColor createFromCadCustom(int code);
61  static RColor createFromName(const QString& name);
62 
63  static QList<QPair<QString, RColor> > getList(bool onlyFixed = false);
64  static QIcon getIcon(const RColor& color, const QSize& size = RDEFAULT_QSIZE_ICON);
65 
66  unsigned long long getHash() const;
67 
68  bool isValid() const;
69  QString getName() const;
70  bool isByLayer() const;
71  bool isByBlock() const;
72  bool isFixed() const;
73 
74  QColor toCompat() const;
75 
76  static RColor getHighlighted(const RColor& color, const QColor& bgColor);
77 
78  //bool equalsCorrected(const RColor & color) const;
79 
80  bool operator==(const RColor & color) const;
81  bool operator!=(const RColor & color) const;
82  bool operator<(const RColor & color) const;
83 
84 public:
85  static QColor CompatByLayer;
86  static QColor CompatByBlock;
87 
88 private:
89  static void init();
90  static void init(const QString& cn, const RColor& c);
91 
92 private:
93  static bool isInitialized;
94  static QList<QPair<QString, RColor> > list;
95  static QMap<RColor, QIcon> iconMap;
96  //static QVector<RColor> cadColors;
98 
99 private:
100  static const double cadColors[][3];
101 };
102 
106 QDataStream& operator<<(QDataStream& stream, const RColor& color);
107 
111 QDataStream& operator>>(QDataStream& stream, RColor& color);
112 
113 QDebug operator<<(QDebug dbg, const RColor& c);
114 
117 typedef QPair<QString, RColor> _RPairStringRColor;
118 Q_DECLARE_METATYPE(_RPairStringRColor)
119 Q_DECLARE_METATYPE(QList< _RPairStringRColor >)
121 
122 #endif /* RCOLOR_H_ */