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. :-)
17 #include "qg_colorbox.h"
20 * Default Constructor. You must call init manually if you choose
21 * to use this constructor.
23 QG_ColorBox::QG_ColorBox(QWidget * parent/*= 0*/, const char */*name = 0*/):
27 showUnchanged = false;
32 * Constructor that calls init and provides a fully functional
33 * combobox for choosing colors.
35 * @param showByLayer true: Show attribute ByLayer, ByBlock.
37 QG_ColorBox::QG_ColorBox(bool showByLayer, bool showUnchanged, QWidget * parent/*= 0*/,
38 const char */*name = 0*/): QComboBox(parent)
41 init(showByLayer, showUnchanged);
47 QG_ColorBox::~QG_ColorBox()
51 RS_Color QG_ColorBox::getColor()
57 * Initialisation (called from constructor or manually but only
60 * @param showByLayer true: Show attribute ByLayer, ByBlock.
62 void QG_ColorBox::init(bool showByLayer, bool showUnchanged)
64 this->showByLayer = showByLayer;
65 this->showUnchanged = showUnchanged;
68 // addItem(QIcon(color00_xpm), tr("Unchanged"));
69 addItem(QIcon(":/res/color00.xpm"), tr("Unchanged"));
73 // addItem(QIcon(color00_xpm), tr("By Layer"));
74 // addItem(QIcon(color00_xpm), tr("By Block"));
75 addItem(QIcon(":/res/color00.xpm"), tr("By Layer"));
76 addItem(QIcon(":/res/color00.xpm"), tr("By Block"));
79 /* addItem(QIcon(color01_xpm), tr("Red"));
80 addItem(QIcon(color02_xpm), tr("Yellow"));
81 addItem(QIcon(color03_xpm), tr("Green"));
82 addItem(QIcon(color04_xpm), tr("Cyan"));
83 addItem(QIcon(color05_xpm), tr("Blue"));
84 addItem(QIcon(color06_xpm), tr("Magenta"));
85 addItem(QIcon(color07_xpm), tr("Black / White"));
86 addItem(QIcon(color08_xpm), tr("Gray"));
87 addItem(QIcon(color09_xpm), tr("Light Gray"));
88 addItem(QIcon(colorxx_xpm), tr("Others.."));*/
89 addItem(QIcon(":/res/color01.xpm"), tr("Red"));
90 addItem(QIcon(":/res/color02.xpm"), tr("Yellow"));
91 addItem(QIcon(":/res/color03.xpm"), tr("Green"));
92 addItem(QIcon(":/res/color04.xpm"), tr("Cyan"));
93 addItem(QIcon(":/res/color05.xpm"), tr("Blue"));
94 addItem(QIcon(":/res/color06.xpm"), tr("Magenta"));
95 addItem(QIcon(":/res/color07.xpm"), tr("Black / White"));
96 addItem(QIcon(":/res/color08.xpm"), tr("Gray"));
97 addItem(QIcon(":/res/color09.xpm"), tr("Light Gray"));
98 addItem(QIcon(":/res/colorxx.xpm"), tr("Others.."));
100 connect(this, SIGNAL(activated(int)), this, SLOT(slotColorChanged(int)));
104 else if (showByLayer)
109 slotColorChanged(currentIndex());
112 bool QG_ColorBox::isUnchanged()
118 * Sets the color shown in the combobox to the given color.
120 void QG_ColorBox::setColor(const RS_Color & color)
122 //#warning "!!! Color is being misreported here !!!"
124 And fuck. Probably because the operator== in RS_Color doesn't know how to
125 convert between Qt:: style colors and RGB. Either way, have to fix this shit
126 Look at Red: Have to convert them all to RS_Color...
128 currentColor = color;
130 if (color.isByLayer() && showByLayer)
132 else if (color.isByBlock() && showByLayer)
134 else if (color == RS_Color(255, 0, 0)) //Qt::red)
135 setCurrentIndex(0 + (int)showByLayer * 2 + (int)showUnchanged);
136 else if (color == RS_Color(255, 255, 0)) //Qt::yellow)
137 setCurrentIndex(1 + (int)showByLayer * 2 + (int)showUnchanged);
138 else if (color == RS_Color(0, 255, 0)) //Qt::green)
139 setCurrentIndex(2 + (int)showByLayer * 2 + (int)showUnchanged);
140 else if (color == RS_Color(0, 255, 255)) //Qt::cyan)
141 setCurrentIndex(3 + (int)showByLayer * 2 + (int)showUnchanged);
142 else if (color == RS_Color(0, 0, 255)) //Qt::blue)
143 setCurrentIndex(4 + (int)showByLayer * 2 + (int)showUnchanged);
144 else if (color == RS_Color(255, 0, 255)) //Qt::magenta)
145 setCurrentIndex(5 + (int)showByLayer * 2 + (int)showUnchanged);
146 // else if (color == Qt::white || color == Qt::black)
147 else if (color == RS_Color(255, 255, 255) || color == RS_Color(0, 0, 0))
148 setCurrentIndex(6 + (int)showByLayer * 2 + (int)showUnchanged);
149 else if (color == RS_Color(127, 127, 127)) //Qt::gray)
150 setCurrentIndex(7 + (int)showByLayer * 2 + (int)showUnchanged);
151 else if (color == RS_Color(191, 191, 191))
152 setCurrentIndex(8 + (int)showByLayer * 2 + (int)showUnchanged);
154 setCurrentIndex(9 + (int)showByLayer * 2 + (int)showUnchanged);
156 if (currentIndex() != 9 + (int)showByLayer * 2 + (int)showUnchanged)
157 slotColorChanged(currentIndex());
161 * Sets the color of the pixmap next to the "By Layer" item
162 * to the given color.
164 void QG_ColorBox::setLayerColor(const RS_Color & color)
170 if (color == Qt::black || color == Qt::white)
172 // pixmap = color07_xpm;
173 pixmap = QPixmap(":/res/color07.xpm");
177 // pixmap = color00_xpm;
178 pixmap = QPixmap(":/res/color00.xpm");
179 int w = pixmap.width();
180 int h = pixmap.height();
181 QPainter painter(&pixmap);
182 painter.fillRect(1, 1, w - 2, h - 2, color);
186 // changeItem(pixmap, tr("By Layer"), 0);
187 setItemIcon(0, QIcon(pixmap));
189 // needed for the first time a layer is added:
190 if (currentIndex() != 9)
191 slotColorChanged(currentIndex());
196 * Called when the color has changed. This method
197 * sets the current color to the value chosen or even
198 * offers a dialog to the user that allows him/ her to
199 * choose an individual color.
201 void QG_ColorBox::slotColorChanged(int index)
203 currentColor.resetFlags();
215 switch (index - (int)showUnchanged)
218 currentColor = RS_Color(RS2::FlagByLayer);
221 currentColor = RS_Color(RS2::FlagByBlock);
228 switch (index - (int)showByLayer * 2 - (int)showUnchanged)
231 currentColor.setRgb(255, 0, 0);
234 currentColor.setRgb(255, 255, 0);
237 currentColor.setRgb(0, 255, 0);
240 currentColor.setRgb(0, 255, 255);
243 currentColor.setRgb(0, 0, 255);
246 currentColor.setRgb(255, 0, 255);
249 currentColor.setRgb(0, 0, 0);
252 currentColor.setRgb(127, 127, 127);
255 currentColor.setRgb(191, 191, 191);
258 currentColor = QColorDialog::getColor(currentColor, this);
264 //printf("Current color is (%d): %s\n",
265 // index, currentColor.name().latin1());
267 emit colorChanged(currentColor);