/**************************************************************************** ** ** This file is part of the LibreCAD project, a 2D CAD program ** ** Copyright (C) 2010-2011 R. van Twisk (librecad@rvt.dds.nl) ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved. ** ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file gpl-2.0.txt included in the ** packaging of this file. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ** ** This copyright notice MUST APPEAR in all copies of the script! ** **********************************************************************/ #include "qg_colorbox.h" #include #include #include #include /** * Default Constructor. You must call init manually if you choose * to use this constructor. */ QG_ColorBox::QG_ColorBox(QWidget* parent, const char* name) : QComboBox(parent) { setObjectName(name); setEditable ( false ); showByLayer = false; showUnchanged = false; unchanged = false; } /** * Constructor that calls init and provides a fully functional * combobox for choosing colors. * * @param showByLayer true: Show attribute ByLayer, ByBlock. */ QG_ColorBox::QG_ColorBox(bool showByLayer, bool showUnchanged, QWidget* parent, const char* name) : QComboBox(parent) { setObjectName(name); setEditable ( false ); unchanged = false; init(showByLayer, showUnchanged); } /** * Destructor */ QG_ColorBox::~QG_ColorBox() {} /** * Initialisation (called from constructor or manually but only * once). * * @param showByLayer true: Show attribute ByLayer, ByBlock. */ void QG_ColorBox::init(bool showByLayer, bool showUnchanged) { this->showByLayer = showByLayer; this->showUnchanged = showUnchanged; if (showUnchanged) { addItem(QIcon(":/ui/color00.png"), tr("Unchanged")); } if (showByLayer) { addItem(QIcon(":/ui/color00.png"), tr("By Layer")); addItem(QIcon(":/ui/color00.png"), tr("By Block")); } //static colors starts here //addColor(QIcon(":/ui/color01.png"), red,Qt::red); QString red(tr("Red")); addColor(Qt::red,red); colorIndexStart=findText(red); // keep the starting point of static colors addColor(Qt::darkRed,tr("Dark Red")); addColor(Qt::yellow,tr("Yellow")); addColor(Qt::darkYellow,tr("Dark Yellow")); addColor(Qt::green,tr("Green")); addColor(Qt::darkGreen,tr("Dark Green")); addColor(Qt::cyan,tr("Cyan")); addColor(Qt::darkCyan,tr("Dark Cyan")); addColor(Qt::blue,tr("Blue")); addColor(Qt::darkBlue,tr("Dark Blue")); addColor(Qt::magenta,tr("Magenta")); addColor(Qt::darkMagenta,tr("Dark Magenta")); addItem(QIcon(":/ui/color07.png"), tr("Black / White"),Qt::black); //colorIndexBlack=findData(Qt::black); //record the number for special color black/white //std::cout<<"colorIndexBlack="<()); if( abs(q.red() - color.red()) +abs(q.green() - color.green()) +abs(q.blue() - color.blue()) <= 3 ) { break; } } if(cIndex == count() - 1) { cIndex=findData(Qt::black); //default to Qt::black } } setCurrentIndex(cIndex); //std::cout<<"Default color for choosing: cIndex="<())<= colorIndexStart ) { if(index < count() -1 ) { QVariant q0=itemData(index); if(q0 != QVariant::Invalid ) { currentColor=itemData(index).value(); } else { currentColor=Qt::black; //default to black color } } else { // color picker for "Others.." currentColor = QColorDialog::getColor(currentColor, this); } } //printf("Current color is (%d): %s\n", // index, currentColor.name().latin1()); emit colorChanged(currentColor); }