]> Shamusworld >> Repos - architektonas/blob - src/base/rs_color.cpp
Initial import
[architektonas] / src / base / rs_color.cpp
1 // rs_color.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // (C) 2010 Underground Software
7 //
8 // JLH = James L. Hammons <jlhamm@acm.org>
9 //
10 // Who  When        What
11 // ---  ----------  -----------------------------------------------------------
12 // JLH  05/05/2010  Moved implementation from header to this file. :-)
13 //
14
15 #include "rs_color.h"
16
17 RS_Color::RS_Color(): QColor(), RS_Flags()
18 {
19 }
20
21 RS_Color::RS_Color(int r, int g, int b): QColor(r, g, b), RS_Flags()
22 {
23 }
24
25 RS_Color::RS_Color(const QColor & c): QColor(c), RS_Flags()
26 {
27 }
28
29 RS_Color::RS_Color(const RS_Color & c): QColor(c), RS_Flags()
30 {
31         setFlags(c.getFlags());
32 }
33
34 RS_Color::RS_Color(unsigned int f): QColor(), RS_Flags(f)
35 {
36 }
37
38 /** @return A copy of this color without flags. */
39 RS_Color RS_Color::stripFlags() const
40 {
41         return RS_Color(red(), green(), blue());
42 }
43
44 /** @return true if the color is defined by layer. */
45 bool RS_Color::isByLayer() const
46 {
47         return getFlag(RS2::FlagByLayer);
48 }
49
50 /** @return true if the color is defined by block. */
51 bool RS_Color::isByBlock() const
52 {
53         return getFlag(RS2::FlagByBlock);
54 }
55
56 RS_Color & RS_Color::operator=(const RS_Color & c)
57 {
58         setRgb(c.red(), c.green(), c.blue());
59         setFlags(c.getFlags());
60
61         return *this;
62 }
63
64 bool RS_Color::operator==(const RS_Color & c) const
65 {
66         return (red() == c.red() && green() == c.green() && blue() == c.blue()
67                 && getFlags() == c.getFlags());
68 }
69
70 #if 0
71 bool RS_Color::operator==(const QColor & c) const
72 {
73         return (red() == c.red() && green() == c.green() && blue() == c.blue());
74 }
75 #endif
76
77 /*friend*/ std::ostream & operator<<(std::ostream & os, const RS_Color & c)
78 {
79         os << " color: " << c.name().toLatin1().data()
80                 << " flags: " << (c.getFlag(RS2::FlagByLayer) ? "RS2::FlagByLayer " : "")
81                 << (c.getFlag(RS2::FlagByBlock) ? "RS2::FlagByBlock " : "");
82         return os;
83 }