[KLF Backend][KLF Tools][KLF Home]
KLatexFormula Project
src/klftools/klfcolorchooser.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002  *   file klfcolorchooser.cpp
00003  *   This file is part of the KLatexFormula Project.
00004  *   Copyright (C) 2011 by Philippe Faist
00005  *   philippe.faist at bluewin.ch
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************/
00022 /* $Id$ */
00023 
00024 #include <stdio.h>
00025 
00026 #include <QAction>
00027 #include <QMenu>
00028 #include <QDebug>
00029 #include <QColorDialog>
00030 #include <QPaintEvent>
00031 #include <QStyle>
00032 #include <QStylePainter>
00033 #include <QStyleFactory>
00034 #include <QStyleOptionButton>
00035 #include <QRegExp>
00036 
00037 #include <klfdefs.h>
00038 #include "klfflowlayout.h"
00039 #include "klfguiutil.h"
00040 #include "klfrelativefont.h"
00041 #include "klfcolorchooser.h"
00042 #include "klfcolorchooser_p.h"
00043 
00044 #include <ui_klfcolorchoosewidget.h>
00045 #include <ui_klfcolordialog.h>
00046 
00047 
00048 
00049 // -------------------------------------------------------------------
00050 
00051 
00052 KLFColorDialog::KLFColorDialog(QWidget *parent) : QDialog(parent)
00053 {
00054   u = new Ui::KLFColorDialog;
00055   u->setupUi(this);
00056   setObjectName("KLFColorDialog");
00057 }
00058 KLFColorDialog::~KLFColorDialog()
00059 {
00060   delete u;
00061 }
00062 
00063 KLFColorChooseWidget *KLFColorDialog::colorChooseWidget()
00064 {
00065   return u->mColorChooseWidget;
00066 }
00067 
00068 QColor KLFColorDialog::getColor(QColor startwith, bool alphaenabled, QWidget *parent)
00069 {
00070   KLFColorDialog dlg(parent);
00071   dlg.u->mColorChooseWidget->setAlphaEnabled(alphaenabled);
00072   dlg.u->mColorChooseWidget->setColor(startwith);
00073   int r = dlg.exec();
00074   if ( r != QDialog::Accepted )
00075     return QColor();
00076   QColor color = dlg.u->mColorChooseWidget->color();
00077   return color;
00078 }
00079 
00080 QColor KLFColorDialog::color() const
00081 {
00082   return u->mColorChooseWidget->color();
00083 }
00084 void KLFColorDialog::setColor(const QColor& color)
00085 {
00086   u->mColorChooseWidget->setColor(color);
00087 }
00088 void KLFColorDialog::slotAccepted()
00089 {
00090   KLFColorChooseWidget::addRecentColor(color());
00091 }
00092 
00093 // -------------------------------------------------------------------
00094 
00095 KLFColorClickSquare::KLFColorClickSquare(QColor color, int size, bool removable, QWidget *parent)
00096   : QWidget(parent), _color(color), _removable(removable)
00097 {
00098   initwidget();
00099   setSqSize(size);
00100 }
00101 KLFColorClickSquare::KLFColorClickSquare(QWidget *parent)
00102   : QWidget(parent), _color(Qt::white), _removable(false)
00103 {
00104   initwidget();
00105   setSqSize(16);
00106 }
00107 void KLFColorClickSquare::initwidget()
00108 {
00109   setFocusPolicy(Qt::StrongFocus);
00110   setContextMenuPolicy(Qt::DefaultContextMenu);
00111   //  setAutoFillBackground(true);
00112   //  update();
00113 }
00114 
00115 void KLFColorClickSquare::setSqSize(int sz)
00116 {
00117   if (_size == sz)
00118     return;
00119 
00120   _size = sz;
00121   setFixedSize(_size, _size);
00122 }
00123 
00124 void KLFColorClickSquare::setRemovable(bool removable)
00125 {
00126   _removable = removable;
00127 }
00128 
00129 void KLFColorClickSquare::paintEvent(QPaintEvent *event)
00130 {
00131   KLF_DEBUG_BLOCK(KLF_FUNC_NAME) ;
00132   Q_UNUSED(event) ;
00133   klfDbg("event->rect="<<event->rect()) ;
00134   {
00135     QPainter p(this);
00136     p.fillRect(0, 0, width(), height(), QBrush(_color));
00137   }
00138   if (hasFocus()) {
00139     QStylePainter p(this);
00140     QStyleOptionFocusRect option;
00141     option.initFrom(this);
00142     option.backgroundColor = QColor(0,0,0,0);
00143     p.drawPrimitive(QStyle::PE_FrameFocusRect, option);
00144   }
00145 }
00146 void KLFColorClickSquare::resizeEvent(QResizeEvent *event)
00147 {
00148   Q_UNUSED(event) ;
00149 }
00150 
00151 void KLFColorClickSquare::mousePressEvent(QMouseEvent */*event*/)
00152 {
00153   activate();
00154 }
00155 void KLFColorClickSquare::keyPressEvent(QKeyEvent *kev)
00156 {
00157   if (kev->key() == Qt::Key_Space) {
00158     activate();
00159   }
00160   return QWidget::keyPressEvent(kev);
00161 }
00162 void KLFColorClickSquare::contextMenuEvent(QContextMenuEvent *event)
00163 {
00164   if (_removable) {
00165     QMenu *menu = new QMenu(this);
00166     menu->addAction("Remove", this, SLOT(internalWantRemove()));
00167     menu->popup(event->globalPos());
00168   }
00169 }
00170 void KLFColorClickSquare::internalWantRemove()
00171 {
00172   emit wantRemove();
00173   emit wantRemoveColor(_color);
00174 }
00175 
00176 // -------------------------------------------------------------------
00177 
00178 KLFColorChooseWidgetPane::KLFColorChooseWidgetPane(QWidget *parent)
00179   : QWidget(parent), _img()
00180 {
00181   setPaneType("red+fix");
00182   _color = Qt::black;
00183 }
00184 
00185 QSize KLFColorChooseWidgetPane::sizeHint() const
00186 {
00187   return QSize((_colorcomponent == "fix") ? 16 : 50, (_colorcomponent_b == "fix") ? 16 : 50);
00188 }
00189 QSize KLFColorChooseWidgetPane::minimumSizeHint() const
00190 {
00191   return QSize(16, 16);
00192 }
00193 
00194 void KLFColorChooseWidgetPane::setColor(const QColor& newcolor)
00195 {
00196   if (_color == newcolor)
00197     return;
00198 
00199   _color = newcolor;
00200   update();
00201   emit colorChanged(_color);
00202 }
00203 void KLFColorChooseWidgetPane::setPaneType(const QString& panetype)
00204 {
00205   static QStringList okvals =
00206     QStringList() << "hue"<<"sat"<<"val"<<"red"<<"green"<<"blue"<<"alpha"<<"fix";
00207 
00208   QStringList strlist = panetype.split("+");
00209   if (strlist.size() != 2) {
00210     qWarning()<<KLF_FUNC_NAME<<": expected a pane-type string \"<pane1type>+<pane2type>\"!";
00211     return;
00212   }
00213   _colorcomponent = strlist[0].toLower();
00214   _colorcomponent_b = strlist[1].toLower();
00215   if (!okvals.contains(_colorcomponent))
00216     _colorcomponent = "fix";
00217   if (!okvals.contains(_colorcomponent_b))
00218     _colorcomponent_b = "fix";
00219 
00220   if (_colorcomponent == "fix" && _colorcomponent_b == "fix")
00221     setFocusPolicy(Qt::NoFocus);
00222   else
00223     setFocusPolicy(Qt::WheelFocus);
00224 }
00225 void KLFColorChooseWidgetPane::paintEvent(QPaintEvent */*e*/)
00226 {
00227   QStylePainter p(this);
00228   // background: a checker grid to distinguish transparency
00229   p.fillRect(0,0,width(),height(), QBrush(QPixmap(":/pics/checker.png")));
00230   // then prepare an image for our gradients
00231   int x;
00232   int y;
00233   _img = QImage(width(), height(), QImage::Format_ARGB32);
00234   double xfac = (double)valueAMax() / (_img.width()-1);
00235   double yfac = (double)valueBMax() / (_img.height()-1);
00236   for (x = 0; x < _img.width(); ++x) {
00237     for (y = 0; y < _img.height(); ++y) {
00238       _img.setPixel(x, _img.height()-y-1, colorFromValues(_color, (int)(xfac*x), (int)(yfac*y)).rgba());
00239     }
00240   }
00241   p.drawImage(0, 0, _img);
00242   // draw crosshairs
00243   QColor hairscol = qGray(_color.rgb()) > 80 ? QColor(0,0,0,180) : QColor(255,255,255,180);
00244   if ( _colorcomponent != "fix" ) {
00245     p.setPen(QPen(hairscol, 1.f, Qt::DotLine));
00246     x = (int)(valueA()/xfac);
00247     if (x < 0) { x = 0; }
00248     if (x >= width()) { x = width()-1; }
00249     p.drawLine(x, 0, x, height());
00250   }
00251   if ( _colorcomponent_b != "fix" ) {
00252     p.setPen(QPen(hairscol, 1.f, Qt::DotLine));
00253     y = (int)(valueB()/yfac);
00254     if (y < 0) { y = 0; }
00255     if (y >= height()) { y = height()-1; }
00256     p.drawLine(0, height()-y-1, width(), height()-y-1);
00257   }
00258   // draw a focus rectangle if we have focus
00259   if (hasFocus()) {
00260     QStyleOptionFocusRect option;
00261     option.initFrom(this);
00262     option.backgroundColor = QColor(0,0,0,0);
00263     p.drawPrimitive(QStyle::PE_FrameFocusRect, option);
00264   }
00265 }
00266 void KLFColorChooseWidgetPane::mousePressEvent(QMouseEvent *e)
00267 {
00268   double xfac = (double)valueAMax() / (_img.width()-1);
00269   double yfac = (double)valueBMax() / (_img.height()-1);
00270   int x = e->pos().x();
00271   int y = height() - e->pos().y() - 1;
00272 
00273   setColor(colorFromValues(_color, (int)(x*xfac), (int)(y*yfac)));
00274 }
00275 void KLFColorChooseWidgetPane::mouseMoveEvent(QMouseEvent *e)
00276 {
00277   double xfac = (double)valueAMax() / (_img.width()-1);
00278   double yfac = (double)valueBMax() / (_img.height()-1);
00279   int x = e->pos().x();
00280   int y = height() - e->pos().y() - 1;
00281   if (x < 0) { x = 0; }
00282   if (x >= width()) { x = width()-1; }
00283   if (y < 0) { y = 0; } if (y >= height()) { y = height()-1; }
00284 
00285   setColor(colorFromValues(_color, (int)(x*xfac), (int)(y*yfac)));
00286 }
00287 void KLFColorChooseWidgetPane::wheelEvent(QWheelEvent *e)
00288 {
00289   double step = - 7.5 * e->delta() / 120;
00290 
00291   if (e->modifiers() == Qt::ShiftModifier)
00292     step = step / 5.0;
00293   if (e->modifiers() == Qt::ControlModifier)
00294     step = step * 2.5;
00295 
00296   // isA: TRUE if we are modifying component A, if FALSE then modifying component B
00297   bool isA =  (e->orientation() == Qt::Horizontal);
00298   if (isA && _colorcomponent=="fix")
00299     isA = false;
00300   if (!isA && _colorcomponent_b=="fix")
00301     isA = true;
00302   if (isA) {
00303     // the first component
00304     int x = (int)(valueA()+step);
00305     if (x < 0) x = 0;
00306     if (x > valueAMax()) x = valueAMax();
00307     setColor(colorFromValues(_color, x, valueB()));
00308   } else {
00309     int x = (int)(valueB() - step);
00310     if (x < 0) x = 0;
00311     if (x > valueBMax()) x = valueBMax();
00312     setColor(colorFromValues(_color, valueA(), x));
00313   }
00314   e->accept();
00315 }
00316 void KLFColorChooseWidgetPane::keyPressEvent(QKeyEvent *e)
00317 {
00318   const int dir_step = 5;
00319   double xstep = 0;
00320   double ystep = 0;
00321 
00322   if (e->key() == Qt::Key_Left)
00323     xstep -= dir_step;
00324   if (e->key() == Qt::Key_Right)
00325     xstep += dir_step;
00326   if (e->key() == Qt::Key_Up)
00327     ystep += dir_step;
00328   if (e->key() == Qt::Key_Down)
00329     ystep -= dir_step;
00330   if (e->key() == Qt::Key_Home)
00331     xstep = -10000;
00332   if (e->key() == Qt::Key_End)
00333     xstep = 10000;
00334   if (e->key() == Qt::Key_PageUp)
00335     ystep = 10000;
00336   if (e->key() == Qt::Key_PageDown)
00337     ystep = -10000;
00338 
00339   // if a component is set to 'fix', add the deltas to the other component...
00340   if (_colorcomponent == "fix") {
00341     ystep += xstep;
00342     xstep = 0;
00343   } else if (_colorcomponent_b == "fix") {
00344     xstep += ystep;
00345     ystep = 0;
00346   }
00347 
00348   if (e->modifiers() == Qt::ShiftModifier) {
00349     xstep = xstep / 5; ystep = ystep / 5;
00350   }
00351   if (e->modifiers() == Qt::ControlModifier) {
00352     xstep = xstep * 2.5; ystep = ystep * 2.5;
00353   }
00354 
00355   int x = (int)(valueA() + xstep);
00356   int y = (int)(valueB() + ystep);
00357   if (x < 0) x = 0;
00358   if (x > valueAMax()) x = valueAMax();
00359   if (y < 0) y = 0;
00360   if (y > valueBMax()) y = valueBMax();
00361 
00362   setColor(colorFromValues(_color, x, y));
00363 }
00364 
00365 
00366 // -------------------------------------------------------------------
00367 
00368 
00369 KLFGridFlowLayout::KLFGridFlowLayout(int columns, QWidget *parent)
00370   : QGridLayout(parent), _ncols(columns),
00371     _currow(0), _curcol(0)
00372 {
00373   addItem(new QSpacerItem(1,1, QSizePolicy::Expanding, QSizePolicy::Fixed), 0, _ncols);
00374 }
00375 void KLFGridFlowLayout::insertGridFlowWidget(QWidget *w, Qt::Alignment align)
00376 {
00377   mGridFlowWidgets.append(w);
00378   QGridLayout::addWidget(w, _currow, _curcol, align);
00379   _curcol++;
00380   if (_curcol >= _ncols) {
00381     _curcol = 0;
00382     _currow++;
00383   }
00384 }
00385 void KLFGridFlowLayout::clearAll()
00386 {
00387   int k;
00388   for (k = 0; k < mGridFlowWidgets.size(); ++k) {
00389     // because KLFColorClickSquare::wantRemoveColor() can call this by a chain of
00390     // signal/slots; and we shouldn't delete an object inside one of its handlers
00391     //delete mGridFlowWidgets[k];
00392     mGridFlowWidgets[k]->deleteLater();
00393   }
00394   mGridFlowWidgets.clear();
00395   _currow = _curcol = 0;
00396 }
00397 
00398 
00399 // -------------------------------------------------------------------
00400 
00401 
00402 int KLFColorComponentsEditorBase::valueAFromNewColor(const QColor& color) const
00403 {
00404   return valueFromNewColor(color, _colorcomponent);
00405 }
00406 int KLFColorComponentsEditorBase::valueBFromNewColor(const QColor& color) const
00407 {
00408   return valueFromNewColor(color, _colorcomponent_b);
00409 }
00410 int KLFColorComponentsEditorBase::valueFromNewColor(const QColor& color, const QString& component)
00411 {
00412   int value = -1;
00413   if (component == "hue") {
00414     value = color.hue();
00415   } else if (component == "sat") {
00416     value = color.saturation();
00417   } else if (component == "val") {
00418     value = color.value();
00419   } else if (component == "red") {
00420     value = color.red();
00421   } else if (component == "green") {
00422     value = color.green();
00423   } else if (component == "blue") {
00424     value = color.blue();
00425   } else if (component == "alpha") {
00426     value = color.alpha();
00427   } else if (component == "fix" || component.isEmpty()) {
00428     value = -1;
00429   } else {
00430     qWarning("Unknown color component property : %s", component.toLocal8Bit().constData());
00431   }
00432   return value;
00433 }
00434 
00435 int KLFColorComponentsEditorBase::valueMax(const QString& component)
00436 {
00437   if (component == "hue")
00438     return 359;
00439   else if (component == "sat" || component == "val" ||
00440            component == "red" || component == "green" ||
00441            component == "blue" || component == "alpha")
00442     return 255;
00443   else if (component == "fix" || component.isEmpty())
00444     return -1;
00445 
00446   qWarning("Unknown color component property : %s", component.toLocal8Bit().constData());
00447   return -1;
00448 }
00449 
00450 QColor KLFColorComponentsEditorBase::colorFromValues(QColor base, int a, int b)
00451 {
00452   QColor col = base;
00453   /*  printf("colorFromValues(%s/alpha=%d, %d, %d): My components:(%s+%s);\n", qPrintable(col.name()),
00454       col.alpha(), a, b, qPrintable(_colorcomponent), qPrintable(_colorcomponent_b)); */
00455   if (_colorcomponent == "hue") {
00456     col.setHsv(a, col.saturation(), col.value());
00457     col.setAlpha(base.alpha());
00458   } else if (_colorcomponent == "sat") {
00459     col.setHsv(col.hue(), a, col.value());
00460     col.setAlpha(base.alpha());
00461   } else if (_colorcomponent == "val") {
00462     col.setHsv(col.hue(), col.saturation(), a);
00463     col.setAlpha(base.alpha());
00464   } else if (_colorcomponent == "red") {
00465     col.setRgb(a, col.green(), col.blue());
00466     col.setAlpha(base.alpha());
00467   } else if (_colorcomponent == "green") {
00468     col.setRgb(col.red(), a, col.blue());
00469     col.setAlpha(base.alpha());
00470   } else if (_colorcomponent == "blue") {
00471     col.setRgb(col.red(), col.green(), a);
00472     col.setAlpha(base.alpha());
00473   } else if (_colorcomponent == "alpha") {
00474     col.setAlpha(a);
00475   } else if (_colorcomponent == "fix") {
00476     // no change to col
00477   } else {
00478     qWarning("Unknown color component property : %s", _colorcomponent.toLocal8Bit().constData());
00479   }
00480   QColor base2 = col;
00481   //  printf("\tnew color is (%s/alpha=%d);\n", qPrintable(col.name()), col.alpha());
00482   if ( ! _colorcomponent_b.isEmpty() && _colorcomponent_b != "fix" ) {
00483     //    printf("\twe have a second component\n");
00484     if (_colorcomponent_b == "hue") {
00485       col.setHsv(b, col.saturation(), col.value());
00486       col.setAlpha(base2.alpha());
00487     } else if (_colorcomponent_b == "sat") {
00488       col.setHsv(col.hue(), b, col.value());
00489       col.setAlpha(base2.alpha());
00490     } else if (_colorcomponent_b == "val") {
00491       col.setHsv(col.hue(), col.saturation(), b);
00492       col.setAlpha(base2.alpha());
00493     } else if (_colorcomponent_b == "red") {
00494       col.setRgb(b, col.green(), col.blue());
00495       col.setAlpha(base2.alpha());
00496     } else if (_colorcomponent_b == "green") {
00497       col.setRgb(col.red(), b, col.blue());
00498       col.setAlpha(base2.alpha());
00499     } else if (_colorcomponent_b == "blue") {
00500       col.setRgb(col.red(), col.blue(), b);
00501       col.setAlpha(base2.alpha());
00502     } else if (_colorcomponent_b == "alpha") {
00503       col.setAlpha(b);
00504     } else {
00505       qWarning("Unknown color component property : %s", _colorcomponent_b.toLocal8Bit().constData());
00506     }
00507   }
00508   //  printf("\tand color is finally %s/alpha=%d\n", qPrintable(col.name()), col.alpha());
00509   return col;
00510 }
00511 bool KLFColorComponentsEditorBase::refreshColorFromInternalValues(int a, int b)
00512 {
00513   QColor oldcolor = _color;
00514   _color = colorFromValues(_color, a, b);
00515   /*  printf("My components:(%s+%s); New color is %s/alpha=%d\n", _colorcomponent.toLocal8Bit().constData(),
00516       _colorcomponent_b.toLocal8Bit().constData(),  _color.name().toLocal8Bit().constData(), _color.alpha()); */
00517   if ( oldcolor != _color )
00518     return true;
00519   return false;
00520 }
00521 
00522 
00523 // -------------------------------------------------------------------
00524 
00525 
00526 KLFColorComponentSpinBox::KLFColorComponentSpinBox(QWidget *parent)
00527   : QSpinBox(parent)
00528 {
00529   _color = Qt::black;
00530 
00531   setColorComponent("hue");
00532   setColor(_color);
00533 
00534   connect(this, SIGNAL(valueChanged(int)), this, SLOT(internalChanged(int)));
00535 
00536   setValue(valueAFromNewColor(_color));
00537 }
00538 
00539 void KLFColorComponentSpinBox::setColorComponent(const QString& comp)
00540 {
00541   _colorcomponent = comp.toLower();
00542   setMinimum(0);
00543   setMaximum(valueAMax());
00544 }
00545 
00546 void KLFColorComponentSpinBox::internalChanged(int newvalue)
00547 {
00548   if ( refreshColorFromInternalValues(newvalue) )
00549     emit colorChanged(_color);
00550 }
00551 
00552 void KLFColorComponentSpinBox::setColor(const QColor& color)
00553 {
00554   if (_color == color)
00555     return;
00556   int value = valueAFromNewColor(color);
00557   /*  printf("My components:(%s+%s); setColor(%s/alpha=%d); new value = %d\n",
00558       _colorcomponent.toLocal8Bit().constData(), _colorcomponent_b.toLocal8Bit().constData(),
00559       color.name().toLocal8Bit().constData(), color.alpha(), value); */
00560   _color = color;
00561   setValue(value); // will emit QSpinBox::valueChanged() --> internalChanged() --> colorChanged()
00562 }
00563 
00564 
00565 // -------------------------------------------------------------------
00566 
00567 
00568 KLFColorList * KLFColorChooseWidget::_recentcolors = 0;
00569 KLFColorList * KLFColorChooseWidget::_standardcolors = 0;
00570 KLFColorList * KLFColorChooseWidget::_customcolors = 0;
00571 
00572 // static
00573 void KLFColorChooseWidget::setRecentCustomColors(QList<QColor> recentcolors, QList<QColor> customcolors)
00574 {
00575   ensureColorListsInstance();
00576   _recentcolors->list = recentcolors;
00577   _recentcolors->notifyListChanged();
00578   _customcolors->list = customcolors;
00579   _customcolors->notifyListChanged();
00580 }
00581 // static
00582 QList<QColor> KLFColorChooseWidget::recentColors()
00583 {
00584   ensureColorListsInstance();
00585   return _recentcolors->list;
00586 }
00587 // static
00588 QList<QColor> KLFColorChooseWidget::customColors()
00589 {
00590   ensureColorListsInstance();
00591   return _customcolors->list;
00592 }
00593 
00594 
00595 KLFColorChooseWidget::KLFColorChooseWidget(QWidget *parent)
00596   : QWidget(parent)
00597 {
00598   u = new Ui::KLFColorChooseWidget;
00599   u->setupUi(this);
00600   setObjectName("KLFColorChooseWidget");
00601 
00602   _alphaenabled = true;
00603 
00604   ensureColorListsInstance();
00605 
00606   if (_standardcolors->list.size() == 0) {
00607     // add a few standard colors.
00608     QList<QRgb> rgbs;
00609     // inspired from the "Forty Colors" Palette in KDE3 color dialog
00610     rgbs << 0x000000 << 0x303030 << 0x585858 << 0x808080 << 0xa0a0a0 << 0xc3c3c3
00611          << 0xdcdcdc << 0xffffff << 0x400000 << 0x800000 << 0xc00000 << 0xff0000
00612          << 0xffc0c0 << 0x004000 << 0x008000 << 0x00c000 << 0x00ff00 << 0xc0ffc0
00613          << 0x000040 << 0x000080 << 0x0000c0 << 0x0000ff << 0xc0c0ff << 0x404000
00614          << 0x808000 << 0xc0c000 << 0xffff00 << 0xffffc0 << 0x004040 << 0x008080
00615          << 0x00c0c0 << 0x00ffff << 0xc0ffff << 0x400040 << 0x800080 << 0xc000c0
00616          << 0xff00ff << 0xffc0ff << 0xc05800 << 0xff8000 << 0xffa858 << 0xffdca8 ;
00617     for (int k = 0; k < rgbs.size(); ++k)
00618       _standardcolors->list.append(QColor(QRgb(rgbs[k])));
00619   }
00620 
00621   _connectedColorChoosers.append(u->mDisplayColor);
00622   _connectedColorChoosers.append(u->mHueSatPane);
00623   _connectedColorChoosers.append(u->mValPane);
00624   _connectedColorChoosers.append(u->mAlphaPane);
00625   _connectedColorChoosers.append(u->mColorTriangle);
00626   _connectedColorChoosers.append(u->mHueSlider);
00627   _connectedColorChoosers.append(u->mSatSlider);
00628   _connectedColorChoosers.append(u->mValSlider);
00629   _connectedColorChoosers.append(u->mRedSlider);
00630   _connectedColorChoosers.append(u->mGreenSlider);
00631   _connectedColorChoosers.append(u->mBlueSlider);
00632   _connectedColorChoosers.append(u->mAlphaSlider);
00633   _connectedColorChoosers.append(u->spnHue);
00634   _connectedColorChoosers.append(u->spnSat);
00635   _connectedColorChoosers.append(u->spnVal);
00636   _connectedColorChoosers.append(u->spnRed);
00637   _connectedColorChoosers.append(u->spnGreen);
00638   _connectedColorChoosers.append(u->spnBlue);
00639   _connectedColorChoosers.append(u->spnAlpha);
00640 
00641   /*  KLFGridFlowLayout *lytRecent = new KLFGridFlowLayout(12, u->mRecentColorsPalette);
00642       lytRecent->setSpacing(2);
00643       //  lytRecent->setSizeConstraint(QLayout::SetMinAndMaxSize);
00644       KLFGridFlowLayout *lytStandard = new KLFGridFlowLayout(12, u->mStandardColorsPalette);
00645       lytStandard->setSpacing(2);
00646       //  lytStandard->setSizeConstraint(QLayout::SetFixedSize);
00647       KLFGridFlowLayout *lytCustom = new KLFGridFlowLayout(12, u->mCustomColorsPalette);
00648       lytCustom->setSpacing(2);
00649       //  lytCustom->setSizeConstraint(QLayout::SetFixedSize);
00650       */
00651   KLFFlowLayout *lytRecent = new KLFFlowLayout(u->mRecentColorsPalette, 11, 2, 2);
00652   lytRecent->setFlush(KLFFlowLayout::FlushBegin);
00653   KLFFlowLayout *lytStandard = new KLFFlowLayout(u->mStandardColorsPalette, 11, 2, 2);
00654   lytStandard->setFlush(KLFFlowLayout::FlushBegin);
00655   KLFFlowLayout *lytCustom = new KLFFlowLayout(u->mCustomColorsPalette, 11, 2, 2);
00656   lytCustom->setFlush(KLFFlowLayout::FlushBegin);
00657 
00658   connect(_recentcolors, SIGNAL(listChanged()), this, SLOT(updatePaletteRecent()));
00659   connect(_standardcolors, SIGNAL(listChanged()), this, SLOT(updatePaletteStandard()));
00660   connect(_customcolors, SIGNAL(listChanged()), this, SLOT(updatePaletteCustom()));
00661 
00662   updatePalettes();
00663 
00664   int k;
00665   for (k = 0; k < _connectedColorChoosers.size(); ++k) {
00666     connect(_connectedColorChoosers[k], SIGNAL(colorChanged(const QColor&)),
00667             this, SLOT(internalColorChanged(const QColor&)));
00668   }
00669 
00670   connect(u->lstNames, SIGNAL(itemClicked(QListWidgetItem*)),
00671           this, SLOT(internalColorNameSelected(QListWidgetItem*)));
00672   connect(u->txtHex, SIGNAL(textChanged(const QString&)),
00673           this, SLOT(internalColorNameSet(const QString&)));
00674 
00675   QPalette p = u->txtHex->palette();
00676   u->txtHex->setProperty("paletteDefault", QVariant::fromValue<QPalette>(p));
00677   p.setColor(QPalette::Base, QColor(255,169, 184,128));
00678   u->txtHex->setProperty("paletteInvalidInput", QVariant::fromValue<QPalette>(p));
00679   
00680 
00681   connect(u->btnAddCustomColor, SIGNAL(clicked()),
00682           this, SLOT(setCurrentToCustomColor()));
00683 
00684   QStringList colornames = QColor::colorNames();
00685   for (k = 0; k < colornames.size(); ++k) {
00686     QPixmap colsample(16, 16);
00687     colsample.fill(QColor(colornames[k]));
00688     new QListWidgetItem(QIcon(colsample), colornames[k], u->lstNames);
00689   }
00690 
00691   internalColorChanged(_color);
00692 }
00693 
00694 void KLFColorChooseWidget::internalColorChanged(const QColor& wanted_newcolor)
00695 {
00696   QColor newcolor = wanted_newcolor;
00697   if (!_alphaenabled)
00698     newcolor.setAlpha(255);
00699 
00700   int k;
00701   for (k = 0; k < _connectedColorChoosers.size(); ++k) {
00702     _connectedColorChoosers[k]->blockSignals(true);
00703     _connectedColorChoosers[k]->setProperty("color", QVariant(newcolor));
00704     _connectedColorChoosers[k]->blockSignals(false);
00705   }
00706   QString newcolorname = newcolor.name();
00707   if (u->txtHex->text() != newcolorname) {
00708     u->txtHex->blockSignals(true);
00709     u->txtHex->setText(newcolorname);
00710     u->txtHex->blockSignals(false);
00711   }
00712 
00713   _color = newcolor;
00714 
00715   emit colorChanged(newcolor);
00716 }
00717 
00718 void KLFColorChooseWidget::internalColorNameSelected(QListWidgetItem *item)
00719 {
00720   if (!item)
00721     return;
00722   QColor color(item->text());
00723   internalColorChanged(color);
00724 }
00725 
00726 void KLFColorChooseWidget::internalColorNameSet(const QString& n)
00727 {
00728   klfDbg("name set: "<<n) ;
00729   QString name = n;
00730   static QRegExp rx("\\#?[0-9A-Fa-f]{6}");
00731   bool validinput = false;
00732   bool setcolor = false;
00733   int listselect = -1;
00734   QColor color;
00735   if (rx.exactMatch(name)) {
00736     if (name[0] != QLatin1Char('#'))
00737       name = "#"+name;
00738     validinput = setcolor = true;
00739     color = QColor(name);
00740   } else {
00741     // try to match a color name, or the beginning of a color name
00742     int k;
00743     for (k = 0; k < u->lstNames->count(); ++k) {
00744       QString s = u->lstNames->item(k)->text();
00745       if (s == name) {
00746         // found an exact match. Select it and set color
00747         validinput = true;
00748         listselect = k;
00749         setcolor = true;
00750         color = QColor(name);
00751         break;
00752       }
00753       if (s.startsWith(n)) {
00754         // found a matching name. Just select it for user feedback
00755         validinput = true;
00756         listselect = k;
00757         setcolor = false;
00758         break;
00759       }
00760     }
00761   }
00762   // now set the background color of the text input correctly (valid input or not)
00763   if (!validinput) {
00764     u->txtHex->setProperty("invalidInput", true);
00765     u->txtHex->setStyleSheet(u->txtHex->styleSheet()); // style sheet recalc
00766     u->txtHex->setPalette(u->txtHex->property("paletteInvalidInput").value<QPalette>());
00767   } else {
00768     u->txtHex->setProperty("invalidInput", QVariant());
00769     u->txtHex->setStyleSheet(u->txtHex->styleSheet()); // style sheet recalc
00770     u->txtHex->setPalette(u->txtHex->property("paletteDefault").value<QPalette>());
00771   }
00772   // select the appropriate list item if needed
00773   if (listselect >= 0) {
00774     u->lstNames->blockSignals(true);
00775     u->lstNames->setCurrentRow(listselect, QItemSelectionModel::ClearAndSelect);
00776     u->lstNames->blockSignals(false);
00777   }
00778   if (setcolor)
00779     internalColorChanged(color);
00780 }
00781 
00782 void KLFColorChooseWidget::setColor(const QColor& color)
00783 {
00784   if (color == _color)
00785     return;
00786   if (!_alphaenabled && color.rgb() == _color.rgb())
00787     return;
00788 
00789   internalColorChanged(color);
00790 }
00791 
00792 void KLFColorChooseWidget::setAlphaEnabled(bool enabled)
00793 {
00794   _alphaenabled = enabled;
00795   u->spnAlpha->setVisible(enabled);
00796   u->lblAlpha->setVisible(enabled);
00797   u->mAlphaPane->setVisible(enabled);
00798   u->lblsAlpha->setVisible(enabled);
00799   u->mAlphaSlider->setVisible(enabled);
00800   if (!enabled) {
00801     _color.setAlpha(255);
00802     setColor(_color);
00803   }
00804 }
00805 
00806 void KLFColorChooseWidget::fillPalette(KLFColorList *colorlist, QWidget *w)
00807 {
00808   KLF_DEBUG_BLOCK(KLF_FUNC_NAME) ;
00809   klfDbg("colorlist is "<<colorlist<<", _customcolors is "<<_customcolors<<", _recentcolors is "<<_recentcolors) ;
00810   int k;
00811   //  KLFGridFlowLayout *lyt = dynamic_cast<KLFGridFlowLayout*>( w->layout() );
00812   // KLF_ASSERT_NOT_NULL(lyt, "Layout is not a KLFGridFlowLayout !", return; ) ;
00813   KLFFlowLayout *lyt = dynamic_cast<KLFFlowLayout*>( w->layout() );
00814   KLF_ASSERT_NOT_NULL(lyt, "Layout is not a KLFFlowLayout !", return; ) ;
00815 
00816   lyt->clearAll();
00817   for (k = 0; k < colorlist->list.size(); ++k) {
00818     klfDbg("Adding a KLFColorClickSquare for color: "<<colorlist->list[k]) ;
00819     
00820     KLFColorClickSquare *sq = new KLFColorClickSquare(colorlist->list[k], 12,
00821                                                       (colorlist == _customcolors ||
00822                                                        colorlist == _recentcolors),
00823                                                       w);
00824     connect(sq, SIGNAL(colorActivated(const QColor&)),
00825             this, SLOT(internalColorChanged(const QColor&)));
00826     connect(sq, SIGNAL(wantRemoveColor(const QColor&)),
00827     colorlist, SLOT(removeColor(const QColor&)));
00828     // lyt->insertGridFlowWidget(sq);
00829     lyt->addWidget(sq);
00830     sq->show();
00831   }
00832   w->adjustSize(); // the widget is inside a scroll area
00833 }
00834 
00835 void KLFColorChooseWidget::setCurrentToCustomColor()
00836 {
00837   _customcolors->addColor(_color);
00838   updatePaletteCustom();
00839 }
00840 
00841 void KLFColorChooseWidget::updatePalettes()
00842 {
00843   updatePaletteRecent();
00844   updatePaletteStandard();
00845   updatePaletteCustom();
00846 }
00847 
00848 void KLFColorChooseWidget::updatePaletteRecent()
00849 {
00850   fillPalette(_recentcolors, u->mRecentColorsPalette);
00851 }
00852 void KLFColorChooseWidget::updatePaletteStandard()
00853 {
00854   fillPalette(_standardcolors, u->mStandardColorsPalette);
00855 }
00856 void KLFColorChooseWidget::updatePaletteCustom()
00857 {
00858   fillPalette(_customcolors, u->mCustomColorsPalette);
00859 }
00860 
00861 
00862 
00863 // static
00864 void KLFColorChooseWidget::ensureColorListsInstance()
00865 {
00866   if ( _recentcolors == 0 )
00867     _recentcolors = new KLFColorList(128);
00868   if ( _standardcolors == 0 )
00869     _standardcolors = new KLFColorList(256);
00870   if ( _customcolors == 0 )
00871     _customcolors = new KLFColorList(128);
00872 }
00873 
00874 // static
00875 void KLFColorChooseWidget::addRecentColor(const QColor& col)
00876 {
00877   ensureColorListsInstance();
00878   QList<QColor>::iterator it = _recentcolors->list.begin();
00879   while (it != _recentcolors->list.end()) {
00880     if ( (*it) == col )
00881       it = _recentcolors->list.erase(it);
00882     else
00883       ++it;
00884   }
00885   _recentcolors->list.append(col);
00886 
00887   if (_recentcolors->list.size() > MAX_RECENT_COLORS) {
00888     _recentcolors->list.removeAt(0);
00889   }
00890   _recentcolors->notifyListChanged();
00891 }
00892 
00893 
00894 
00895 // -------------------------------------------------------------------
00896 
00897 
00898 
00899 void KLFColorList::addColor(const QColor& color)
00900 {
00901   int i;
00902   if ( (i = list.indexOf(color)) >= 0 )
00903     list.removeAt(i);
00904 
00905   list.append(color);
00906   while (list.size() >= _maxsize)
00907     list.pop_front();
00908 
00909   emit listChanged();
00910 }
00911 
00912 void KLFColorList::removeColor(const QColor& color)
00913 {
00914   bool changed = false;
00915   int i;
00916   if ( (i = list.indexOf(color)) >= 0 ) {
00917     list.removeAt(i);
00918     changed = true;
00919   }
00920   if (changed)
00921     emit listChanged();
00922 }
00923 
00924 // static
00925 KLFColorList *KLFColorChooser::_colorlist = NULL;
00926 
00927 QStyle *KLFColorChooser::mReplaceButtonStyle = NULL;
00928 
00929 KLFColorChooser::KLFColorChooser(QWidget *parent)
00930   : QPushButton(parent), _color(0,0,0,255), _pix(), _allowdefaultstate(false),
00931     _defaultstatestring(tr("[ Default ]")), _autoadd(true), _size(120, 20),
00932     _xalignfactor(0.5f), _yalignfactor(0.5f), _alphaenabled(true), mMenu(NULL), menuRelFont(NULL)
00933 {
00934   ensureColorListInstance();
00935   connect(_colorlist, SIGNAL(listChanged()), this, SLOT(_makemenu()));
00936   
00937   _makemenu();
00938   _setpix();
00939 
00940 #ifdef KLF_WS_MAC
00941   if ( mReplaceButtonStyle == NULL ) {
00942     mReplaceButtonStyle = QStyleFactory::create("fusion");//new QPlastiqueStyle; // deprecated in Qt5
00943   }
00944   setStyle(mReplaceButtonStyle);
00945 #endif
00946 }
00947 
00948 
00949 KLFColorChooser::~KLFColorChooser()
00950 {
00951 }
00952 
00953 
00954 QColor KLFColorChooser::color() const
00955 {
00956   return _color;
00957 }
00958 
00959 QSize KLFColorChooser::sizeHint() const
00960 {
00961   //KLF_DEBUG_BLOCK(KLF_FUNC_NAME) ;
00962 
00963   // inspired by QPushButton::sizeHint() in qpushbutton.cpp
00964 
00965   ensurePolished();
00966 
00967   int w = 0, h = 0;
00968   QStyleOptionButton opt;
00969   initStyleOption(&opt);
00970 
00971   // calculate contents size...
00972   w = _pix.width()+4;
00973   h = _pix.height()+2;
00974 
00975   opt.rect.setSize(QSize(w,h));
00976 
00977   if (menu())
00978     w += KLF_DEBUG_TEE( style()->pixelMetric(QStyle::PM_MenuButtonIndicator, &opt, this) );
00979 
00980   //klfDbg("itermediate stage: w="<<w);
00981 
00982   QSize hint = style()->sizeFromContents(QStyle::CT_PushButton, &opt, QSize(w, h), this);
00983   //klfDbg("before expansion to app/globalstrut; hint="<<hint) ;
00984   hint = hint.expandedTo(QApplication::globalStrut());
00985   //klfDbg("mename="<<objectName()<<" _pix size="<<_pix.size()<<" _size="<<_size<<" color="<<_color<<"; sizeHint="<<hint) ;
00986   return hint;
00987 }
00988 
00989 void KLFColorChooser::setColor(const QColor& col)
00990 {
00991   if ( ! _allowdefaultstate && ! col.isValid() )
00992     return;
00993 
00994   if (_color == col)
00995     return;
00996 
00997   _color = col;
00998   _setpix();
00999 
01000   if (_autoadd && _color.isValid()) {
01001     _colorlist->addColor(_color);
01002   }
01003   emit colorChanged(_color);
01004 }
01005 
01006 void KLFColorChooser::setDefaultColor()
01007 {
01008   setColor(QColor());
01009 }
01010 
01011 void KLFColorChooser::setAllowDefaultState(bool allow)
01012 {
01013   _allowdefaultstate = allow;
01014   _makemenu();
01015 }
01016 void KLFColorChooser::setDefaultStateString(const QString& str)
01017 {
01018   _defaultstatestring = str;
01019   _makemenu();
01020 }
01021 
01022 void KLFColorChooser::setAutoAddToList(bool autoadd)
01023 {
01024   _autoadd = autoadd;
01025 }
01026 void KLFColorChooser::setShowSize(const QSize& size)
01027 {
01028   _size = size;
01029   _setpix();
01030   if (size.isValid())
01031     setMinimumSize(sizeHint());
01032   else
01033     setMinimumSize(QSize());
01034 }
01035 void KLFColorChooser::setPixXAlignFactor(float xalignfactor)
01036 {
01037   _xalignfactor = xalignfactor;
01038 }
01039 void KLFColorChooser::setPixYAlignFactor(float yalignfactor) {
01040   _yalignfactor = yalignfactor;
01041 }
01042 
01043 void KLFColorChooser::setAlphaEnabled(bool on)
01044 {
01045   _alphaenabled = on;
01046   _makemenu();
01047 }
01048 
01049 void KLFColorChooser::requestColor()
01050 {
01051   // prefer our own color selection dialog
01052   QColor col = KLFColorDialog::getColor(_color, _alphaenabled, this);
01053   // QColor col = QColorDialog::getColor(_color, this);
01054   if ( ! col.isValid() )
01055     return;
01056 
01057   setColor(col);
01058 }
01059 
01060 void KLFColorChooser::setSenderPropertyColor()
01061 {
01062   QColor c = sender()->property("setColor").value<QColor>();
01063   setColor(c);
01064 }
01065 
01066 void KLFColorChooser::_makemenu()
01067 {
01068   if (mMenu) {
01069     setMenu(0);
01070     mMenu->deleteLater();
01071   }
01072 
01073   QSize menuIconSize = QSize(16,16);
01074 
01075   mMenu = new QMenu(this);
01076 
01077   if (_allowdefaultstate) {
01078     mMenu->addAction(QIcon(colorPixmap(QColor(), menuIconSize)), _defaultstatestring,
01079                      this, SLOT(setDefaultColor()));
01080     mMenu->addSeparator();
01081   }
01082 
01083   int n, k, nk;
01084   ensureColorListInstance();
01085   n = _colorlist->list.size();
01086   for (k = 0; k < n; ++k) {
01087     nk = n - k - 1;
01088     QColor col = _colorlist->list[nk];
01089     if (!_alphaenabled)
01090       col.setAlpha(255);
01091     QString collabel;
01092     if (col.alpha() == 255)
01093       collabel = QString("%1").arg(col.name());
01094     else
01095       collabel = QString("%1 (%2%)").arg(col.name()).arg((int)(100.0*col.alpha()/255.0+0.5));
01096 
01097     QAction *a = mMenu->addAction(QIcon(colorPixmap(col, menuIconSize)), collabel,
01098                                   this, SLOT(setSenderPropertyColor()));
01099     a->setIconVisibleInMenu(true);
01100     a->setProperty("setColor", QVariant::fromValue<QColor>(col));
01101   }
01102   if (k > 0)
01103     mMenu->addSeparator();
01104 
01105   mMenu->addAction(tr("Custom ..."), this, SLOT(requestColor()));
01106 
01107   if (menuRelFont != NULL)
01108     delete menuRelFont;
01109   menuRelFont = new KLFRelativeFont(this, mMenu);
01110   menuRelFont->setRelPointSize(-1);
01111   setMenu(mMenu);
01112 }
01113 
01114 void KLFColorChooser::paintEvent(QPaintEvent *e)
01115 {
01116   QPushButton::paintEvent(e);
01117   QPainter p(this);
01118   p.setClipRect(e->rect());
01119   p.drawPixmap(QPointF(_xalignfactor*(width()-_pix.width()), _yalignfactor*(height()-_pix.height())), _pix);
01120 }
01121 
01122 void KLFColorChooser::_setpix()
01123 {
01124   //  if (_color.isValid()) {
01125   _pix = colorPixmap(_color, _size);
01126   // DON'T setIcon() because we draw ourselves ! see paintEvent() !
01127   //  setIconSize(_pix.size());
01128   //  setIcon(_pix);
01129   setText("");
01130   //  } else {
01131   //    _pix = QPixmap();
01132   //    setIcon(QIcon());
01133   //    setIconSize(QSize(0,0));
01134   //    setText("");
01135   //  }
01136 }
01137 
01138 
01139 QPixmap KLFColorChooser::colorPixmap(const QColor& color, const QSize& size)
01140 {
01141   QPixmap pix = QPixmap(size);
01142   pix.fill(Qt::transparent);
01143   if (color.isValid()) {
01144     pix.fill(Qt::black);
01145     QPainter p(&pix);
01146     // background: a checker grid to distinguish transparency
01147     p.fillRect(0,0,pix.width(),pix.height(), QBrush(QPixmap(":/pics/checker.png")));
01148     // and fill with color
01149     p.fillRect(0,0,pix.width(),pix.height(), QBrush(color));
01150     //    pix.fill(color);
01151   } else {
01152     /*
01153      // draw "transparent"-representing pixmap
01154      pix.fill(QColor(127,127,127,80));
01155      QPainter p(&pix);
01156      p.setPen(QPen(QColor(255,0,0), 2));
01157      p.drawLine(0,0,size.width(),size.height());
01158     */
01159     // draw "default"/"transparent" pixmap
01160     QPainter p(&pix);
01161     p.setRenderHint(QPainter::Antialiasing);
01162     //    QLinearGradient pgrad(0, 0, 0, 1);
01163     //    pgrad.setColorAt(0, QColor(160,160,185));
01164     //    pgrad.setColorAt(1, QColor(220,220,230));
01165     //    pgrad.setCoordinateMode(QGradient::StretchToDeviceMode);
01166     //    p.fillRect(0, 0, pix.width(), pix.height(), pgrad);
01167 
01168     QPen pen(QColor(127,0,0), 2.f, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
01169     p.setPen(pen);
01170     //    p.drawLine(QPointF(0,0), QPointF(pix.width(), pix.height()));
01171     p.drawLine(QPointF(0,pix.height()), QPointF(pix.width(), 0));
01172 
01173     /*
01174      //    p.scale((qreal)pix.width(), (qreal)pix.height());
01175      
01176      QRectF dashrect(QPointF(0.34*pix.width(), 0.40*pix.height()),
01177      QPointF(0.67*pix.width(), 0.60*pix.height()));
01178      //    QRectF dashrect(QPointF(0.1*pix.width(), 0.10*pix.height()),
01179      //                     QPointF(0.9*pix.width(), 0.90*pix.height()));
01180      p.setClipRect(dashrect);
01181      p.translate(dashrect.topLeft());
01182      p.scale(dashrect.width(), dashrect.height());
01183      
01184      p.drawLine(0,0,1,1);
01185      
01186      QRadialGradient dashgrad(QPointF(0.75, 0.3), 0.4, QPointF(0.95, 0.2));
01187      dashgrad.setColorAt(0, QColor(180, 180, 240));
01188      dashgrad.setColorAt(1, QColor(40, 40, 50));
01189      dashgrad.setCoordinateMode(QGradient::LogicalMode);
01190      p.setPen(Qt::NoPen);
01191      p.setBrush(dashgrad);
01192      p.fillRect(QRectF(0,0,1,1), dashgrad);
01193     */
01194 
01195     //    qreal yrad = 2;
01196     //    qreal xrad = 2;//yrad * dashrect.height()/dashrect.width();
01197     //    p.drawRoundedRect(QRectF(0,0,1,1), xrad, yrad, Qt::AbsoluteSize);
01198 
01199     /*
01200     //    QLinearGradient pdashgrad(0, 0, 1, 0);
01201     //    pdashgrad.setColorAt(0, QColor(120, 0, 40));
01202     //    pdashgrad.setColorAt(1, QColor(120, 0, 40));
01203     QRadialGradient dashgrad(QPointF(1.75, 1.9), 0.6, QPointF(1.9, 1.8));
01204     //    QLinearGradient dashgrad(QPointF(0,0), QPointF(1,0));
01205     dashgrad.setColorAt(0, QColor(255, 0, 0));
01206     dashgrad.setColorAt(1, QColor(0, 255, 0));
01207     dashgrad.setCoordinateMode(QGradient::StretchToDeviceMode);
01208     //    dashgrad.setColorAt(0, QColor(255, 255, 255));
01209     //    dashgrad.setColorAt(1, QColor(40, 40, 50));
01210     //    QPen pen(QBrush(dashgrad), pix.height()/5.f, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
01211     p.setPen(Qt::NoPen);
01212     p.setBrush(dashgrad);
01213     QRectF dashrect(QPointF(0.34*pix.width(), 0.40*pix.height()),
01214                     QPointF(0.67*pix.width(), 0.65*pix.height()));
01215     qreal rad = pix.height()/8.;
01216     p.drawRoundedRect(dashrect, 1.2*rad, rad, Qt::AbsoluteSize);
01217     //    p.drawLine(pix.width()*3./8., pix.height()/2., pix.width()*5./8., pix.height()/2.);
01218     //    p.fillRect(0, 0, pix.width(), pix.height(), dashgrad); // debug this gradient
01219     */
01220   }
01221   return pix;
01222 }
01223 
01224 
01225 
01226 // static
01227 int KLFColorChooser::staticUserMaxColors = 10;   // default of 10 colors
01228 
01229 
01230 // static
01231 void KLFColorChooser::setUserMaxColors(int maxColors)
01232 {
01233   staticUserMaxColors = maxColors;
01234 }
01235 
01236 // static
01237 void KLFColorChooser::ensureColorListInstance()
01238 {
01239   if ( _colorlist == 0 )
01240     _colorlist = new KLFColorList(staticUserMaxColors);
01241 }
01242 // static
01243 void KLFColorChooser::setColorList(const QList<QColor>& colors)
01244 {
01245   ensureColorListInstance();
01246   _colorlist->list = colors;
01247   _colorlist->notifyListChanged();
01248 }
01249 
01250 // static
01251 QList<QColor> KLFColorChooser::colorList()
01252 {
01253   ensureColorListInstance();
01254   QList<QColor> l = _colorlist->list;
01255   return l;
01256 }
01257 
01258 
01259 
01260 

Generated by doxygen 1.7.6.1. The KLatexFormula website is hosted on sourceforge.net