From kde-commits Thu Sep 30 21:48:26 2004 From: Nicolas Goutte Date: Thu, 30 Sep 2004 21:48:26 +0000 To: kde-commits Subject: kdelibs/kdeui Message-Id: <20040930214826.2D7DB996F () office ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=109658091629708 CVS commit by goutte: Use QColor directly for the HTML colour input. (The character # is automatically added if missing. This makes that named colours are not possible. But it was not possible defore this change either and anyway it would be only the English names.) CCMAIL:90327-close@bugs.kde.org M +14 -14 kcolordialog.cpp 1.121 --- kdelibs/kdeui/kcolordialog.cpp #1.120:1.121 @@ -1119,6 +1119,6 @@ KColorDialog::KColorDialog( QWidget *par d->htmlName = new QLineEdit( page ); - d->htmlName->setMaxLength( 7 ); - d->htmlName->setText("#FFFFFF"); + d->htmlName->setMaxLength( 13 ); // Qt's QColor allows 12 hexa-digits + d->htmlName->setText("#FFFFFF"); // But HTML uses only 6, so do not worry about the size w = d->htmlName->fontMetrics().width(QString::fromLatin1("#DDDDDDD")); d->htmlName->setFixedWidth(w); @@ -1330,18 +1330,18 @@ void KColorDialog::slotHtmlChanged( void if (d->bRecursion || d->htmlName->text().isEmpty()) return; - unsigned int red = 256; - unsigned int grn = 256; - unsigned int blu = 256; - - if (sscanf(d->htmlName->text().latin1(), "#%02x%02x%02x", &red, &grn, &blu)!=3) - return; + QString strColor( d->htmlName->text() ); + // Assume that a user does not want to type the # all the time + if ( strColor[0] != '#' ) + strColor.prepend("#"); - if ( red > 255 || grn > 255 || blu > 255) return; + const QColor color( strColor ); - KColor col; - col.setRgb( red, grn, blu ); + if ( color.isValid() ) + { + KColor col( color ); d->bEditHtml = true; _setColor( col ); d->bEditHtml = false; + } }