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
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 05/22/2010 Added this text. :-)
15 #include "qg_colorbox.h"
18 * Default Constructor. You must call init manually if you choose
19 * to use this constructor.
21 QG_ColorBox::QG_ColorBox(QWidget * parent/*= 0*/, const char */*name = 0*/):
25 showUnchanged = false;
30 * Constructor that calls init and provides a fully functional
31 * combobox for choosing colors.
33 * @param showByLayer true: Show attribute ByLayer, ByBlock.
35 QG_ColorBox::QG_ColorBox(bool showByLayer, bool showUnchanged, QWidget * parent/*= 0*/,
36 const char */*name = 0*/): QComboBox(parent)
39 init(showByLayer, showUnchanged);
45 QG_ColorBox::~QG_ColorBox()
49 RS_Color QG_ColorBox::getColor()
55 * Initialisation (called from constructor or manually but only
58 * @param showByLayer true: Show attribute ByLayer, ByBlock.
60 void QG_ColorBox::init(bool showByLayer, bool showUnchanged)
62 this->showByLayer = showByLayer;
63 this->showUnchanged = showUnchanged;
66 // addItem(QIcon(color00_xpm), tr("Unchanged"));
67 addItem(QIcon(":/res/color00.xpm"), tr("Unchanged"));
71 // addItem(QIcon(color00_xpm), tr("By Layer"));
72 // addItem(QIcon(color00_xpm), tr("By Block"));
73 addItem(QIcon(":/res/color00.xpm"), tr("By Layer"));
74 addItem(QIcon(":/res/color00.xpm"), tr("By Block"));
77 /* addItem(QIcon(color01_xpm), tr("Red"));
78 addItem(QIcon(color02_xpm), tr("Yellow"));
79 addItem(QIcon(color03_xpm), tr("Green"));
80 addItem(QIcon(color04_xpm), tr("Cyan"));
81 addItem(QIcon(color05_xpm), tr("Blue"));
82 addItem(QIcon(color06_xpm), tr("Magenta"));
83 addItem(QIcon(color07_xpm), tr("Black / White"));
84 addItem(QIcon(color08_xpm), tr("Gray"));
85 addItem(QIcon(color09_xpm), tr("Light Gray"));
86 addItem(QIcon(colorxx_xpm), tr("Others.."));*/
87 addItem(QIcon(":/res/color01.xpm"), tr("Red"));
88 addItem(QIcon(":/res/color02.xpm"), tr("Yellow"));
89 addItem(QIcon(":/res/color03.xpm"), tr("Green"));
90 addItem(QIcon(":/res/color04.xpm"), tr("Cyan"));
91 addItem(QIcon(":/res/color05.xpm"), tr("Blue"));
92 addItem(QIcon(":/res/color06.xpm"), tr("Magenta"));
93 addItem(QIcon(":/res/color07.xpm"), tr("Black / White"));
94 addItem(QIcon(":/res/color08.xpm"), tr("Gray"));
95 addItem(QIcon(":/res/color09.xpm"), tr("Light Gray"));
96 addItem(QIcon(":/res/colorxx.xpm"), tr("Others.."));
98 connect(this, SIGNAL(activated(int)), this, SLOT(slotColorChanged(int)));
102 else if (showByLayer)
107 slotColorChanged(currentIndex());
110 bool QG_ColorBox::isUnchanged()
116 * Sets the color shown in the combobox to the given color.
118 void QG_ColorBox::setColor(const RS_Color & color)
120 //#warning "!!! Color is being misreported here !!!"
122 And fuck. Probably because the operator== in RS_Color doesn't know how to
123 convert between Qt:: style colors and RGB. Either way, have to fix this shit
124 Look at Red: Have to convert them all to RS_Color...
126 currentColor = color;
128 if (color.isByLayer() && showByLayer)
130 else if (color.isByBlock() && showByLayer)
132 else if (color == RS_Color(255, 0, 0)) //Qt::red)
133 setCurrentIndex(0 + (int)showByLayer * 2 + (int)showUnchanged);
134 else if (color == RS_Color(255, 255, 0)) //Qt::yellow)
135 setCurrentIndex(1 + (int)showByLayer * 2 + (int)showUnchanged);
136 else if (color == RS_Color(0, 255, 0)) //Qt::green)
137 setCurrentIndex(2 + (int)showByLayer * 2 + (int)showUnchanged);
138 else if (color == RS_Color(0, 255, 255)) //Qt::cyan)
139 setCurrentIndex(3 + (int)showByLayer * 2 + (int)showUnchanged);
140 else if (color == RS_Color(0, 0, 255)) //Qt::blue)
141 setCurrentIndex(4 + (int)showByLayer * 2 + (int)showUnchanged);
142 else if (color == RS_Color(255, 0, 255)) //Qt::magenta)
143 setCurrentIndex(5 + (int)showByLayer * 2 + (int)showUnchanged);
144 // else if (color == Qt::white || color == Qt::black)
145 else if (color == RS_Color(255, 255, 255) || color == RS_Color(0, 0, 0))
146 setCurrentIndex(6 + (int)showByLayer * 2 + (int)showUnchanged);
147 else if (color == RS_Color(127, 127, 127)) //Qt::gray)
148 setCurrentIndex(7 + (int)showByLayer * 2 + (int)showUnchanged);
149 else if (color == RS_Color(191, 191, 191))
150 setCurrentIndex(8 + (int)showByLayer * 2 + (int)showUnchanged);
152 setCurrentIndex(9 + (int)showByLayer * 2 + (int)showUnchanged);
154 if (currentIndex() != 9 + (int)showByLayer * 2 + (int)showUnchanged)
155 slotColorChanged(currentIndex());
159 * Sets the color of the pixmap next to the "By Layer" item
160 * to the given color.
162 void QG_ColorBox::setLayerColor(const RS_Color & color)
168 if (color == Qt::black || color == Qt::white)
170 // pixmap = color07_xpm;
171 pixmap = QPixmap(":/res/color07.xpm");
175 // pixmap = color00_xpm;
176 pixmap = QPixmap(":/res/color00.xpm");
177 int w = pixmap.width();
178 int h = pixmap.height();
179 QPainter painter(&pixmap);
180 painter.fillRect(1, 1, w - 2, h - 2, color);
184 // changeItem(pixmap, tr("By Layer"), 0);
185 setItemIcon(0, QIcon(pixmap));
187 // needed for the first time a layer is added:
188 if (currentIndex() != 9)
189 slotColorChanged(currentIndex());
194 * Called when the color has changed. This method
195 * sets the current color to the value chosen or even
196 * offers a dialog to the user that allows him/ her to
197 * choose an individual color.
199 void QG_ColorBox::slotColorChanged(int index)
201 currentColor.resetFlags();
213 switch (index - (int)showUnchanged)
216 currentColor = RS_Color(RS2::FlagByLayer);
219 currentColor = RS_Color(RS2::FlagByBlock);
226 switch (index - (int)showByLayer * 2 - (int)showUnchanged)
229 currentColor.setRgb(255, 0, 0);
232 currentColor.setRgb(255, 255, 0);
235 currentColor.setRgb(0, 255, 0);
238 currentColor.setRgb(0, 255, 255);
241 currentColor.setRgb(0, 0, 255);
244 currentColor.setRgb(255, 0, 255);
247 currentColor.setRgb(0, 0, 0);
250 currentColor.setRgb(127, 127, 127);
253 currentColor.setRgb(191, 191, 191);
256 currentColor = QColorDialog::getColor(currentColor, this);
262 //printf("Current color is (%d): %s\n",
263 // index, currentColor.name().latin1());
265 emit colorChanged(currentColor);