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