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 void removeColor(const QString& cn);
75  static RColor createFromCadIndex(const QString& code) {
76  return createFromCadIndex(code.toInt());
77  }
78  static RColor createFromCadIndex(int code);
79  static RColor createFromCadCustom(const QString& code) {
80  return createFromCadCustom(code.toInt());
81  }
82  static RColor createFromCadCustom(int code);
83  static RColor createFromName(const QString& name);
84 
85  static QList<QPair<QString, RColor> > getList(bool onlyFixed = false);
86  static QIcon getIcon(const RColor& color, const QSize& size = RDEFAULT_QSIZE_ICON);
87 
88  unsigned long long getHash() const;
89 
90  bool isValid() const;
91  QString getName() const;
92  bool isByLayer() const;
93  bool isByBlock() const;
94  bool isFixed() const;
95 
96  QColor toCompat() const;
97  void setCompat(const QColor& col);
98 
99  static RColor getHighlighted(const RColor& color, const QColor& bgColor, int minDist = 75);
100 
101  //bool equalsCorrected(const RColor & color) const;
102 
103  bool operator==(const RColor & color) const;
104  bool operator!=(const RColor & color) const;
105  bool operator<(const RColor & color) const;
106 
107 public:
108  static QColor CompatByLayer;
109  static QColor CompatByBlock;
110 
111 private:
112  static void init();
113  static void init(const QString& cn, const RColor& c);
114 
115 private:
116  static bool isInitialized;
117  static QList<QPair<QString, RColor> > list;
118  static QMap<QPair<RColor, QPair<int, int> >, QIcon> iconMap;
119  //static QVector<RColor> cadColors;
121 
122 private:
123  static const double cadColors[][3];
124 };
125 
129 QCADCORE_EXPORT QDataStream& operator<<(QDataStream& stream, const RColor& color);
130 
134 QCADCORE_EXPORT QDataStream& operator>>(QDataStream& stream, RColor& color);
135 
136 QCADCORE_EXPORT QDebug operator<<(QDebug dbg, const RColor& c);
137 
140 typedef QPair<QString, RColor> _RPairStringRColor;
141 Q_DECLARE_METATYPE(_RPairStringRColor)
142 Q_DECLARE_METATYPE(QList< _RPairStringRColor >)
144 
145 #endif /* RCOLOR_H_ */
static RColor createFromCadIndex(const QString &code)
Definition: RColor.h:75
static QColor CompatByLayer
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RColor.h:108
Mode mode
Definition: RColor.h:120
#define QCADCORE_EXPORT
Definition: core_global.h:10
static RColor createFromCadCustom(const QString &code)
Definition: RColor.h:79
Mode
Definition: RColor.h:52
static QList< QPair< QString, RColor > > list
Definition: RColor.h:117
static bool isInitialized
Definition: RColor.h:116
Color.
Definition: RColor.h:42
static QColor CompatByBlock
Definition: RColor.h:109
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:633
QCADCORE_EXPORT QDataStream & operator>>(QDataStream &stream, RColor &color)
Deserializes the given RColor object.
Definition: RColor.cpp:437
QCADCORE_EXPORT QDataStream & operator<<(QDataStream &stream, const RColor &color)
Serializes the given RColor object.
Definition: RColor.cpp:428
QPair< QString, RColor > _RPairStringRColor
Definition: RColor.h:140
void init(void basePath)
Definition: AddBlockInit.js:2
static QMap< QPair< RColor, QPair< int, int > >, QIcon > iconMap
Definition: RColor.h:118
#define RDEFAULT_QSIZE_ICON
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RColor.h:33
Definition: RColor.h:53