QCAD
Open Source 2D CAD
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RColor.h
Go to the documentation of this file.
1 
20 #ifndef RCOLOR_H_
21 #define RCOLOR_H_
22 
23 #include "core_global.h"
24 
25 #include <QCoreApplication>
26 #include <QObject>
27 #include <QColor>
28 #include <QMetaType>
29 #include <QMap>
30 #include <QIcon>
31 #include <QDebug>
32 
33 #define RDEFAULT_QSIZE_ICON QSize(32,10)
34 
42 class QCADCORE_EXPORT RColor: public QColor {
43 
44  Q_DECLARE_TR_FUNCTIONS(RColor);
45 
46 
47 public:
48  friend QCADCORE_EXPORT QDataStream& operator<<(QDataStream& stream, const RColor& color);
49 
50  friend QCADCORE_EXPORT QDataStream& operator>>(QDataStream& stream, RColor& color);
51 
52  enum Mode {
53  ByLayer, ByBlock, Fixed
54  };
55 
56 public:
57  RColor();
58  RColor(int r, int g, int b, int a = 255, RColor::Mode mode = RColor::Fixed);
59  RColor(RColor::Mode mode);
60  RColor(const QString & name, RColor::Mode mode = RColor::Fixed);
61 
65  RColor(Qt::GlobalColor color, RColor::Mode mode = RColor::Fixed);
69  RColor(const QColor& color, RColor::Mode mode = RColor::Fixed);
70 
71  int getCustomColorCode() const;
72  int getColorIndex() const;
73 
74  static RColor createFromCadIndex(const QString& code) {
75  return createFromCadIndex(code.toInt());
76  }
77  static RColor createFromCadIndex(int code);
78  static RColor createFromCadCustom(const QString& code) {
79  return createFromCadCustom(code.toInt());
80  }
81  static RColor createFromCadCustom(int code);
82  static RColor createFromName(const QString& name);
83 
84  static QList<QPair<QString, RColor> > getList(bool onlyFixed = false);
85  static QIcon getIcon(const RColor& color, const QSize& size = RDEFAULT_QSIZE_ICON);
86 
87  unsigned long long getHash() const;
88 
89  bool isValid() const;
90  QString getName() const;
91  bool isByLayer() const;
92  bool isByBlock() const;
93  bool isFixed() const;
94 
95  QColor toCompat() const;
96 
97  static RColor getHighlighted(const RColor& color, const QColor& bgColor);
98 
99  //bool equalsCorrected(const RColor & color) const;
100 
101  bool operator==(const RColor & color) const;
102  bool operator!=(const RColor & color) const;
103  bool operator<(const RColor & color) const;
104 
105 public:
106  static QColor CompatByLayer;
107  static QColor CompatByBlock;
108 
109 private:
110  static void init();
111  static void init(const QString& cn, const RColor& c);
112 
113 private:
114  static bool isInitialized;
115  static QList<QPair<QString, RColor> > list;
116  static QMap<QPair<RColor, QPair<int, int> >, QIcon> iconMap;
117  //static QVector<RColor> cadColors;
119 
120 private:
121  static const double cadColors[][3];
122 };
123 
127 QCADCORE_EXPORT QDataStream& operator<<(QDataStream& stream, const RColor& color);
128 
132 QCADCORE_EXPORT QDataStream& operator>>(QDataStream& stream, RColor& color);
133 
134 QCADCORE_EXPORT QDebug operator<<(QDebug dbg, const RColor& c);
135 
138 typedef QPair<QString, RColor> _RPairStringRColor;
139 Q_DECLARE_METATYPE(_RPairStringRColor)
140 Q_DECLARE_METATYPE(QList< _RPairStringRColor >)
142 
143 #endif /* RCOLOR_H_ */