[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-bugs-dist
Subject:    [Bug 90327] kcolorchooser: short forms for HTML color
From:       Nicolas Goutte <nicolasg () snafu ! de>
Date:       2004-09-30 21:48:34
Message-ID: 20040930214834.11859.qmail () ktown ! kde ! org
[Download RAW message or body]

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
        
http://bugs.kde.org/show_bug.cgi?id=90327        
nicolasg snafu de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED



------- Additional Comments From nicolasg snafu de  2004-09-30 23:48 -------
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;
+  }
 }
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic