QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
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 <QColor>
27#include <QMetaType>
28#include <QIcon>
29
30class QDebug;
31
32#ifndef RDEFAULT_QSIZE_ICON
33#define RDEFAULT_QSIZE_ICON QSize(32,10)
34#endif
35
43class QCADCORE_EXPORT RColor: public QColor {
44
46
47
48public:
49 friend QCADCORE_EXPORT QDataStream& operator<<(QDataStream& stream, const RColor& color);
50
51 friend QCADCORE_EXPORT QDataStream& operator>>(QDataStream& stream, RColor& color);
52
53 enum Mode {
54 ByLayer, ByBlock, Fixed
55 };
56
57public:
58 RColor();
59 RColor(int r, int g, int b, int a = 255, RColor::Mode mode = RColor::Fixed);
60 RColor(RColor::Mode mode);
61 explicit RColor(const QString& name, RColor::Mode mode = RColor::Fixed);
62
66 RColor(Qt::GlobalColor color, RColor::Mode mode = RColor::Fixed);
70 RColor(const QColor& color, RColor::Mode mode = RColor::Fixed);
71
72 int getCustomColorCode() const;
73 int getColorIndex() const;
74
75 static void removeColor(const QString& cn);
76 static void addColor(const QString& cn, const RColor& c);
77 static RColor createFromCadIndex(const QString& code) {
78 return createFromCadIndex(code.toInt());
79 }
80 static RColor createFromCadIndex(int code);
81 static RColor createFromCadCustom(const QString& code) {
82 return createFromCadCustom(code.toInt());
83 }
84 static RColor createFromCadCustom(int code);
85 static RColor createFromName(const QString& name);
86
87 static QList<QPair<QString, RColor> > getList(bool onlyFixed = false);
88 static QStringList getNameList(bool onlyFixed = false);
89 static QList<RColor> getColorList(bool onlyFixed = false);
90 static QIcon getIcon(const RColor& color, const QSize& size = RDEFAULT_QSIZE_ICON);
91
92 unsigned long long getHash() const;
93
94 bool isValid() const;
95 QString getName() const;
96 bool isByLayer() const;
97 bool isByBlock() const;
98 bool isFixed() const;
99
100 QColor toCompat() const;
101 void setCompat(const QColor& col);
102
103 static RColor getHighlighted(const RColor& color, const QColor& bgColor, int minDist = 75);
104 static RColor getFaded(const RColor& color, const QColor& bgColor, double factor = 1);
105
106 //bool equalsCorrected(const RColor & color) const;
107
108 bool operator==(const RColor & color) const;
109 bool operator!=(const RColor & color) const;
110 bool operator<(const RColor & color) const;
111
112 static void reinit() {
113 isInitialized = false;
114 list.clear();
115 init();
116 }
117
118public:
119 static QColor CompatByLayer;
120 static QColor CompatByBlock;
121
122private:
123 static void init();
124 static void init(const QString& cn, const RColor& c);
125
126private:
127 static bool isInitialized;
128 static QList<QPair<QString, RColor> > list;
130 //static QVector<RColor> cadColors;
132
133private:
134 static const double cadColors[][3];
135};
136
140QCADCORE_EXPORT QDataStream& operator<<(QDataStream& stream, const RColor& color);
141
145QCADCORE_EXPORT QDataStream& operator>>(QDataStream& stream, RColor& color);
146
147QCADCORE_EXPORT QDebug operator<<(QDebug dbg, const RColor& c);
148
151typedef QPair<QString, RColor> _RPairStringRColor;
155
156#endif /* RCOLOR_H_ */
void init(void basePath)
Definition AddBlockInit.js:2
QDebug operator<<(QDebug dbg, const RBox &b)
Stream operator for QDebug.
Definition RBox.cpp:640
QCADCORE_EXPORT QDataStream & operator>>(QDataStream &stream, RColor &color)
Deserializes the given RColor object.
Definition RColor.cpp:526
#define RDEFAULT_QSIZE_ICON
Definition RColor.h:33
QPair< QString, RColor > _RPairStringRColor
Definition RColor.h:151
QCADCORE_EXPORT QDataStream & operator<<(QDataStream &stream, const RColor &color)
Serializes the given RColor object.
Definition RColor.cpp:517
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:765
QDataStream & operator>>(QDataStream &stream, RVector &vector)
Deserializes the given RColor object.
Definition RVector.cpp:1246
Definition RDebug.h:38
Color.
Definition RColor.h:43
static RColor createFromCadCustom(const QString &code)
Definition RColor.h:81
Mode mode
Definition RColor.h:131
static bool isInitialized
Definition RColor.h:127
Mode
Definition RColor.h:53
@ Fixed
Definition RColor.h:54
@ ByBlock
Definition RColor.h:54
static QColor CompatByLayer
Copyright (c) 2011-2018 by Andrew Mustun.
Definition RColor.h:119
Q_DECLARE_TR_FUNCTIONS(RColor)
static QList< QPair< QString, RColor > > list
Definition RColor.h:128
static QMap< QPair< RColor, QPair< int, int > >, QIcon > iconMap
Definition RColor.h:129
static QColor CompatByBlock
Definition RColor.h:120
static void reinit()
Definition RColor.h:112
static RColor createFromCadIndex(const QString &code)
Definition RColor.h:77
#define QCADCORE_EXPORT
Definition core_global.h:10
Definition inftrees.h:24