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 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 05/22/2010 Added this text. :-)
22 * Default Constructor. You must call init manually if you choose
23 * to use this constructor.
25 ColorBox::ColorBox(QWidget * parent/*= 0*/, const char */*name = 0*/):
29 showUnchanged = false;
34 * Constructor that calls init and provides a fully functional
35 * combobox for choosing colors.
37 * @param showByLayer true: Show attribute ByLayer, ByBlock.
39 ColorBox::ColorBox(bool showByLayer, bool showUnchanged, QWidget * parent/*= 0*/,
40 const char */*name = 0*/): QComboBox(parent)
43 init(showByLayer, showUnchanged);
53 RS_Color ColorBox::getColor()
59 * Initialisation (called from constructor or manually but only
62 * @param showByLayer true: Show attribute ByLayer, ByBlock.
64 void ColorBox::init(bool showByLayer, bool showUnchanged)
66 this->showByLayer = showByLayer;
67 this->showUnchanged = showUnchanged;
70 // addItem(QIcon(color00_xpm), tr("Unchanged"));
71 addItem(QIcon(":/res/color00.xpm"), tr("Unchanged"));
75 // addItem(QIcon(color00_xpm), tr("By Layer"));
76 // addItem(QIcon(color00_xpm), tr("By Block"));
77 addItem(QIcon(":/res/color00.xpm"), tr("By Layer"));
78 addItem(QIcon(":/res/color00.xpm"), tr("By Block"));
81 /* addItem(QIcon(color01_xpm), tr("Red"));
82 addItem(QIcon(color02_xpm), tr("Yellow"));
83 addItem(QIcon(color03_xpm), tr("Green"));
84 addItem(QIcon(color04_xpm), tr("Cyan"));
85 addItem(QIcon(color05_xpm), tr("Blue"));
86 addItem(QIcon(color06_xpm), tr("Magenta"));
87 addItem(QIcon(color07_xpm), tr("Black / White"));
88 addItem(QIcon(color08_xpm), tr("Gray"));
89 addItem(QIcon(color09_xpm), tr("Light Gray"));
90 addItem(QIcon(colorxx_xpm), tr("Others.."));*/
91 addItem(QIcon(":/res/color01.xpm"), tr("Red"));
92 addItem(QIcon(":/res/color02.xpm"), tr("Yellow"));
93 addItem(QIcon(":/res/color03.xpm"), tr("Green"));
94 addItem(QIcon(":/res/color04.xpm"), tr("Cyan"));
95 addItem(QIcon(":/res/color05.xpm"), tr("Blue"));
96 addItem(QIcon(":/res/color06.xpm"), tr("Magenta"));
97 addItem(QIcon(":/res/color07.xpm"), tr("Black / White"));
98 addItem(QIcon(":/res/color08.xpm"), tr("Gray"));
99 addItem(QIcon(":/res/color09.xpm"), tr("Light Gray"));
100 addItem(QIcon(":/res/colorxx.xpm"), tr("Others.."));
102 connect(this, SIGNAL(activated(int)), this, SLOT(slotColorChanged(int)));
106 else if (showByLayer)
111 slotColorChanged(currentIndex());
114 bool ColorBox::isUnchanged()
120 * Sets the color shown in the combobox to the given color.
122 void ColorBox::setColor(const RS_Color & color)
124 //#warning "!!! Color is being misreported here !!!"
126 And fuck. Probably because the operator== in RS_Color doesn't know how to
127 convert between Qt:: style colors and RGB. Either way, have to fix this shit
128 Look at Red: Have to convert them all to RS_Color...
130 currentColor = color;
132 if (color.isByLayer() && showByLayer)
134 else if (color.isByBlock() && showByLayer)
136 else if (color == RS_Color(255, 0, 0)) //Qt::red)
137 setCurrentIndex(0 + (int)showByLayer * 2 + (int)showUnchanged);
138 else if (color == RS_Color(255, 255, 0)) //Qt::yellow)
139 setCurrentIndex(1 + (int)showByLayer * 2 + (int)showUnchanged);
140 else if (color == RS_Color(0, 255, 0)) //Qt::green)
141 setCurrentIndex(2 + (int)showByLayer * 2 + (int)showUnchanged);
142 else if (color == RS_Color(0, 255, 255)) //Qt::cyan)
143 setCurrentIndex(3 + (int)showByLayer * 2 + (int)showUnchanged);
144 else if (color == RS_Color(0, 0, 255)) //Qt::blue)
145 setCurrentIndex(4 + (int)showByLayer * 2 + (int)showUnchanged);
146 else if (color == RS_Color(255, 0, 255)) //Qt::magenta)
147 setCurrentIndex(5 + (int)showByLayer * 2 + (int)showUnchanged);
148 // else if (color == Qt::white || color == Qt::black)
149 else if (color == RS_Color(255, 255, 255) || color == RS_Color(0, 0, 0))
150 setCurrentIndex(6 + (int)showByLayer * 2 + (int)showUnchanged);
151 else if (color == RS_Color(127, 127, 127)) //Qt::gray)
152 setCurrentIndex(7 + (int)showByLayer * 2 + (int)showUnchanged);
153 else if (color == RS_Color(191, 191, 191))
154 setCurrentIndex(8 + (int)showByLayer * 2 + (int)showUnchanged);
156 setCurrentIndex(9 + (int)showByLayer * 2 + (int)showUnchanged);
158 if (currentIndex() != 9 + (int)showByLayer * 2 + (int)showUnchanged)
159 slotColorChanged(currentIndex());
163 * Sets the color of the pixmap next to the "By Layer" item
164 * to the given color.
166 void ColorBox::setLayerColor(const RS_Color & color)
172 if (color == Qt::black || color == Qt::white)
174 // pixmap = color07_xpm;
175 pixmap = QPixmap(":/res/color07.xpm");
179 // pixmap = color00_xpm;
180 pixmap = QPixmap(":/res/color00.xpm");
181 int w = pixmap.width();
182 int h = pixmap.height();
183 QPainter painter(&pixmap);
184 painter.fillRect(1, 1, w - 2, h - 2, color);
188 // changeItem(pixmap, tr("By Layer"), 0);
189 setItemIcon(0, QIcon(pixmap));
191 // needed for the first time a layer is added:
192 if (currentIndex() != 9)
193 slotColorChanged(currentIndex());
198 * Called when the color has changed. This method
199 * sets the current color to the value chosen or even
200 * offers a dialog to the user that allows him/ her to
201 * choose an individual color.
203 void ColorBox::slotColorChanged(int index)
205 currentColor.resetFlags();
217 switch (index - (int)showUnchanged)
220 currentColor = RS_Color(RS2::FlagByLayer);
223 currentColor = RS_Color(RS2::FlagByBlock);
230 switch (index - (int)showByLayer * 2 - (int)showUnchanged)
233 currentColor.setRgb(255, 0, 0);
236 currentColor.setRgb(255, 255, 0);
239 currentColor.setRgb(0, 255, 0);
242 currentColor.setRgb(0, 255, 255);
245 currentColor.setRgb(0, 0, 255);
248 currentColor.setRgb(255, 0, 255);
251 currentColor.setRgb(0, 0, 0);
254 currentColor.setRgb(127, 127, 127);
257 currentColor.setRgb(191, 191, 191);
260 currentColor = QColorDialog::getColor(currentColor, this);
266 //printf("Current color is (%d): %s\n",
267 // index, currentColor.name().latin1());
269 emit colorChanged(currentColor);