QCAD
Open Source 2D CAD
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_ */
static RColor createFromCadIndex(const QString &code)
Definition: RColor.h:74
static QColor CompatByLayer
Copyright (c) 2011-2015 by Andrew Mustun.
Definition: RColor.h:106
Mode mode
Definition: RColor.h:118
#define QCADCORE_EXPORT
Definition: core_global.h:10
static RColor createFromCadCustom(const QString &code)
Definition: RColor.h:78
Mode
Definition: RColor.h:52
static QList< QPair< QString, RColor > > list
Definition: RColor.h:115
static bool isInitialized
Definition: RColor.h:114
Color.
Definition: RColor.h:42
static QColor CompatByBlock
Definition: RColor.h:107
Q_DECLARE_METATYPE(RMath *)
bool operator<(const RPainterPath &p1, const RPainterPath &p2)
This operator allows us to sort painter paths based on z-level.
Definition: RPainterPath.cpp:498
QCADCORE_EXPORT QDataStream & operator>>(QDataStream &stream, RColor &color)
Deserializes the given RColor object.
Definition: RColor.cpp:424
QCADCORE_EXPORT QDataStream & operator<<(QDataStream &stream, const RColor &color)
Serializes the given RColor object.
Definition: RColor.cpp:415
QPair< QString, RColor > _RPairStringRColor
Definition: RColor.h:138
void init(void basePath)
Definition: AddBlockInit.js:2
static QMap< QPair< RColor, QPair< int, int > >, QIcon > iconMap
Definition: RColor.h:116
#define RDEFAULT_QSIZE_ICON
Copyright (c) 2011-2015 by Andrew Mustun.
Definition: RColor.h:33
Definition: RColor.h:53