PDA

View Full Version : how to get the color of the widget from mouse move



xiongxiongchuan
24th December 2010, 09:05
i draw a colorpanel used the below code ,but how to get the color from mouse move event?


void ColorPanel::paintEvent(QPaintEvent *event)
{

QPainter painter(this);

QStringList colors;

colors<<"FFFFFF"<<"FFFAFA"<<"FFF68F"<<"FFEFD5"<<"FFE4E1"<<"FFDEAD"<<"FFC1C1"<<"FFB90F"<<"FFA54F "<<"FF8C00 "<<"FF7F50 "<<"FF6EB4 "<<"FF4500 "<<"FF3030 "<<"FDF5E6 "<<"FAF0E6 "<<"F7F7F7 "<<"F5DEB3 "<<"F0FFFF "<<"F0E68C "<<"EEEE00 "<<"EEE8AA "<<"EEDFCC "<<"EED5B7 "<<"EEC900 "<<"EEAEEE "<<"EE9A49 "<<"EE8262 "<<"EE7621 "<<"EE6363 "<<"EE3A8C "<<"EE00EE "<<"EAEAEA "<<"E5E5E5 "<<"E0EEE0 "<<"DEB887 "<<"DBDBDB "<<"D9D9D9 "<<"D3D3D3 "<<"D1D1D1 "<<"CDCDC1 "<<"CDC9A5 "<<"CDC1C5 "<<"CDB7B5 "<<"CDAF95 "<<"CD9B1D "<<"CD8C95 "<<"CD7054 "<<"CD661D "<<"CD5B45 "<<"CD3333 "<<"CD1076 "<<"CAFF70 "<<"C71585 "<<"C4C4C4 "<<"C1CDC1 "<<"BFBFBF "<<"BDB76B "<<"BBFFFF "<<"B8B8B8 "<<"B4EEB4 "<<"B3B3B3 "<<"B0E2FF "<<"B03060 "<<"ADADAD "<<"A9A9A9 "<<"A4D3EE "<<"A1A1A1 "<<"9F79EE "<<"9B30FF "<<"9A32CD "<<"98F5FF "<<"949494 "<<"912CEE "<<"8EE5EE "<<"8DEEEE "<<"8B8B7A "<<"8B8878 "<<"8B8378 "<<"8B7D6B "<<"8B7500 "<<"8B668B "<<"8B5A2B "<<"8B4789 "<<"8B4500 "<<"8B3626 "<<"8B1C62 "<<"8B0000 "<<"87CEFF "<<"858585 "<<"838B83 "<<"7FFF00 "<<"7D7D7D "<<"7B68EE "<<"7A67EE "<<"778899 "<<"737373 "<<"707070 "<<"6CA6CD "<<"6A5ACD "<<"6959CD "<<"66CD00 "<<"63B8FF "<<"5F9EA0 "<<"5C5C5C "<<"556B2F "<<"548B54 "<<"525252 "<<"4EEE94 "<<"4A4A4A "<<"474747 "<<"458B00 "<<"424242 "<<"3D3D3D "<<"388E8E "<<"333333 "<<"2E8B57 "<<"282828 "<<"228B22 "<<"1F1F1F "<<"1C1C1C "<<"171717 "<<"0F0F0F "<<"050505 "<<"00FF00 "<<"00EE76 "<<"00CDCD "<<"00BFFF "<<"008B45 "<<"006400 "<<"0000AA"
<<"FFFFF0 "<<"FFFAF0 "<<"FFF5EE "<<"FFEC8B "<<"FFE4C4 "<<"FFDAB9 "<<"FFC125 "<<"FFB6C1 "<<"FFA500 "<<"FF83FA "<<"FF7F24 "<<"FF6A6A "<<"FF4040 "<<"FF1493 "<<"FCFCFC "<<"FAEBD7 "<<"F5FFFA "<<"F4F4F4 "<<"F0FFF0 "<<"F08080 "<<"EEE9E9 "<<"EEE685 "<<"EEDC82 "<<"EED2EE "<<"EEC591 "<<"EEAD0E "<<"EE9A00 "<<"EE7AE9 "<<"EE7600 "<<"EE5C42 "<<"EE30A7 "<<"EE0000 "<<"E9967A "<<"E3E3E3 "<<"E0E0E0 "<<"DDA0DD "<<"DB7093 "<<"D8BFD8 "<<"D2B48C "<<"D15FEE "<<"CDCDB4 "<<"CDC8B1 "<<"CDC0B0 "<<"CDB79E "<<"CDAD00 "<<"CD96CD "<<"CD853F "<<"CD69C9 "<<"CD6600 "<<"CD5555 "<<"CD3278 "<<"CD00CD "<<"CAE1FF "<<"C6E2FF "<<"C2C2C2 "<<"C1C1C1 "<<"BF3EFF "<<"BCEE68 "<<"BABABA "<<"B8860B "<<"B4CDCD "<<"B2DFEE "<<"B0E0E6 "<<"AEEEEE "<<"ABABAB "<<"A8A8A8 "<<"A3A3A3 "<<"A0522D "<<"9E9E9E "<<"9AFF9A "<<"999999 "<<"97FFFF "<<"9400D3 "<<"90EE90 "<<"8E8E8E "<<"8DB6CD "<<"8B8B00 "<<"8B8682 "<<"8B814C "<<"8B7B8B "<<"8B7355 "<<"8B6508 "<<"8B5A00 "<<"8B475D "<<"8B3E2F "<<"8B2500 "<<"8B1A1A "<<"8A8A8A "<<"87CEFA "<<"848484 "<<"836FFF "<<"7F7F7F "<<"7D26CD "<<"7AC5CD "<<"7A378B "<<"76EEC6 "<<"71C671 "<<"6E8B3D "<<"6C7B8B "<<"698B69 "<<"68838B "<<"668B8B "<<"636363 "<<"5E5E5E "<<"5B5B5B "<<"555555 "<<"545454 "<<"515151 "<<"4D4D4D "<<"48D1CC "<<"473C8B "<<"454545 "<<"4169E1 "<<"3CB371 "<<"383838 "<<"32CD32 "<<"2E2E2E "<<"27408B "<<"218868 "<<"1E90FF "<<"1A1A1A "<<"141414 "<<"0D0D0D "<<"030303 "<<"00FA9A "<<"00EE00 "<<"00CD66 "<<"00B2EE "<<"008B00 "<<"0000FF "<<"00008B"
<<"FFFFE0 "<<"FFFACD "<<"FFF0F5 "<<"FFEBCD "<<"FFE4B5 "<<"FFD700 "<<"FFC0CB "<<"FFB5C5 "<<"FFA07A "<<"FF82AB "<<"FF7F00 "<<"FF69B4 "<<"FF3E96 "<<"FF00FF "<<"FAFAFA "<<"FA8072 "<<"F5F5F5 "<<"F4A460 "<<"F0F8FF "<<"EEEEE0 "<<"EEE9BF "<<"EEE5DE "<<"EED8AE "<<"EECFA1 "<<"EEB4B4 "<<"EEA9B8 "<<"EE9572 "<<"EE799F "<<"EE6AA7 "<<"EE4000 "<<"EE2C2C "<<"EDEDED "<<"E8E8E8 "<<"E0FFFF "<<"E066FF "<<"DCDCDC "<<"DAA520 "<<"D6D6D6 "<<"D2691E "<<"D02090 "<<"CDCD00 "<<"CDC673 "<<"CDBE70 "<<"CDB5CD "<<"CDAA7D "<<"CD950C "<<"CD8500 "<<"CD6889 "<<"CD6090 "<<"CD4F39 "<<"CD2990 "<<"CD0000 "<<"C9C9C9 "<<"C67171 "<<"C1FFC1 "<<"C0FF3E "<<"BEBEBE "<<"BCD2EE "<<"BA55D3 "<<"B7B7B7 "<<"B452CD "<<"B23AEE "<<"B0C4DE "<<"ADFF2F "<<"AB82FF "<<"A6A6A6 "<<"A2CD5A "<<"A020F0 "<<"9C9C9C "<<"9ACD32 "<<"9932CC "<<"96CDCD "<<"9370DB "<<"8FBC8F "<<"8E8E38 "<<"8C8C8C "<<"8B8989 "<<"8B864E "<<"8B7E66 "<<"8B795E "<<"8B6969 "<<"8B636C "<<"8B5742 "<<"8B4726 "<<"8B3A62 "<<"8B2323 "<<"8B0A50 "<<"8A2BE2 "<<"87CEEB "<<"8470FF "<<"828282 "<<"7EC0EE "<<"7CFC00 "<<"7A8B8B "<<"79CDCD "<<"76EE00 "<<"7171C6 "<<"6E7B8B "<<"6B8E23 "<<"698B22 "<<"68228B "<<"666666 "<<"616161 "<<"5D478B "<<"595959 "<<"551A8B "<<"53868B "<<"4F94CD "<<"4B0082 "<<"4876FF "<<"4682B4 "<<"43CD80 "<<"40E0D0 "<<"3B3B3B "<<"36648B "<<"303030 "<<"2B2B2B "<<"262626 "<<"212121 "<<"1E1E1E "<<"191970 "<<"121212 "<<"0A0A0A "<<"00FFFF "<<"00F5FF "<<"00E5EE "<<"00CD00 "<<"009ACD "<<"00868B "<<"0000EE "<<"000080"
<<"FFFF00 "<<"FFF8DC "<<"FFEFDB "<<"FFE7BA "<<"FFE1FF "<<"FFD39B "<<"FFBBFF "<<"FFAEB9 "<<"FF8C69 "<<"FF8247 "<<"FF7256 "<<"FF6347 "<<"FF34B3 "<<"FF0000 "<<"FAFAD2 "<<"F8F8FF "<<"F5F5DC "<<"F2F2F2 "<<"F0F0F0 "<<"EEEED1 "<<"EEE8CD "<<"EEE0E5 "<<"EED5D2 "<<"EECBAD "<<"EEB422 "<<"EEA2AD "<<"EE82EE "<<"EE7942 "<<"EE6A50 "<<"EE3B3B "<<"EE1289 "<<"EBEBEB "<<"E6E6FA "<<"E0EEEE "<<"DEDEDE "<<"DC143C "<<"DA70D6 "<<"D4D4D4 "<<"D1EEEE "<<"CFCFCF "<<"CDC9C9 "<<"CDC5BF "<<"CDBA96 "<<"CDB38B "<<"CD9B9B "<<"CD919E "<<"CD8162 "<<"CD6839 "<<"CD5C5C "<<"CD3700 "<<"CD2626 "<<"CCCCCC "<<"C7C7C7 "<<"C5C1AA "<<"C1CDCD "<<"BFEFFF "<<"BDBDBD "<<"BC8F8F "<<"B9D3EE "<<"B5B5B5 "<<"B3EE3A "<<"B22222 "<<"B0B0B0 "<<"ADD8E6 "<<"AAAAAA "<<"A52A2A "<<"A2B5CD "<<"9FB6CD "<<"9BCD9B "<<"9AC0CD "<<"98FB98 "<<"969696 "<<"919191 "<<"8F8F8F "<<"8E388E "<<"8B8B83 "<<"8B8970 "<<"8B8386 "<<"8B7D7B "<<"8B7765 "<<"8B6914 "<<"8B5F65 "<<"8B4C39 "<<"8B4513 "<<"8B3A3A "<<"8B2252 "<<"8B008B "<<"8968CD "<<"878787 "<<"838B8B "<<"7FFFD4 "<<"7D9EC0 "<<"7CCD7C "<<"7A7A7A "<<"787878 "<<"757575 "<<"708090 "<<"6E6E6E "<<"6B6B6B "<<"696969 "<<"66CDAA "<<"6495ED "<<"607B8B "<<"5CACEE "<<"575757 "<<"54FF9F "<<"528B8B "<<"4F4F4F "<<"4A708B "<<"483D8B "<<"458B74 "<<"436EEE "<<"404040 "<<"3A5FCD "<<"363636 "<<"2F4F4F "<<"292929 "<<"242424 "<<"20B2AA "<<"1C86EE "<<"1874CD "<<"104E8B "<<"080808 "<<"00FF7F "<<"00EEEE "<<"00CED1 "<<"00C5CD "<<"008B8B "<<"00688B "<<"0000CD "<<"000000";

int colorsCount=0;
for (int i=0;i<widthCount;i++)
{
for (int j=0;j<heightCount;j++)
{

if (colorsCount<colors.count())
{
painter.setPen(QPen(Qt::black,1));
painter.setPen(palette().foreground().color());
painter.setBrush(QBrush(QColor("#"+colors[colorsCount].trimmed())));
painter.drawRect(i*boxSize->width(),j*boxSize->height(),boxSize->width(),boxSize->height());
colorsCount++;
}

}
}
}

ymalaika
24th December 2010, 15:35
You are two steps away:

1. The mouse event functions are separate from the paint functions, so the color data will need to be available outside the paint event. As a general rule I like to keep event handling and data in separate routines, but for this example, I've just moved the color list data into a member variable.

2. You need to re-implement mouse event handling. There, you can calculate the index by remapping from the widget pixel coordinates to the the row/column of the grid being drawn.




class ColorPanel : public QWidget
{
Q_OBJECT

public:
ColorPanel(QWidget *parent = 0);

signals:
void colorHighlightedChanged( QColor color );
void indexHighlightedChanged( int index );

protected:
void paintEvent(QPaintEvent *event);
void mouseMoveEvent(QMouseEvent *event);

private:
int indexHighlighted;

QStringList colors;

int widthCount;
int heightCount;
QRect* boxSize;

};





ColorPanel::ColorPanel( QWidget* parent ) :
QWidget( parent )
{
indexHighlighted = -1;

setMouseTracking(true);

widthCount = 15;
heightCount = 15;
boxSize = new QRect(0, 0, 7, 7);

colors<<"FFFFFF"<<"FFFAFA"<<"FFF68F"<<"FFEFD5"<<"FFE4E1"<<"FFDEAD"<<"FFC1C1"<<"FFB90F"<<"FFA54F "<<"FF8C00 "<<"FF7F50 "<<"FF6EB4 "<<"FF4500 "<<"FF3030 "<<"FDF5E6 "<<"FAF0E6 "<<"F7F7F7 "<<"F5DEB3 "<<"F0FFFF "<<"F0E68C "<<"EEEE00 "<<"EEE8AA "<<"EEDFCC "<<"EED5B7 "<<"EEC900 "<<"EEAEEE "<<"EE9A49 "<<"EE8262 "<<"EE7621 "<<"EE6363 "<<"EE3A8C "<<"EE00EE "<<"EAEAEA "<<"E5E5E5 "<<"E0EEE0 "<<"DEB887 "<<"DBDBDB "<<"D9D9D9 "<<"D3D3D3 "<<"D1D1D1 "<<"CDCDC1 "<<"CDC9A5 "<<"CDC1C5 "<<"CDB7B5 "<<"CDAF95 "<<"CD9B1D "<<"CD8C95 "<<"CD7054 "<<"CD661D "<<"CD5B45 "<<"CD3333 "<<"CD1076 "<<"CAFF70 "<<"C71585 "<<"C4C4C4 "<<"C1CDC1 "<<"BFBFBF "<<"BDB76B "<<"BBFFFF "<<"B8B8B8 "<<"B4EEB4 "<<"B3B3B3 "<<"B0E2FF "<<"B03060 "<<"ADADAD "<<"A9A9A9 "<<"A4D3EE "<<"A1A1A1 "<<"9F79EE "<<"9B30FF "<<"9A32CD "<<"98F5FF "<<"949494 "<<"912CEE "<<"8EE5EE "<<"8DEEEE "<<"8B8B7A "<<"8B8878 "<<"8B8378 "<<"8B7D6B "<<"8B7500 "<<"8B668B "<<"8B5A2B "<<"8B4789 "<<"8B4500 "<<"8B3626 "<<"8B1C62 "<<"8B0000 "<<"87CEFF "<<"858585 "<<"838B83 "<<"7FFF00 "<<"7D7D7D "<<"7B68EE "<<"7A67EE "<<"778899 "<<"737373 "<<"707070 "<<"6CA6CD "<<"6A5ACD "<<"6959CD "<<"66CD00 "<<"63B8FF "<<"5F9EA0 "<<"5C5C5C "<<"556B2F "<<"548B54 "<<"525252 "<<"4EEE94 "<<"4A4A4A "<<"474747 "<<"458B00 "<<"424242 "<<"3D3D3D "<<"388E8E "<<"333333 "<<"2E8B57 "<<"282828 "<<"228B22 "<<"1F1F1F "<<"1C1C1C "<<"171717 "<<"0F0F0F "<<"050505 "<<"00FF00 "<<"00EE76 "<<"00CDCD "<<"00BFFF "<<"008B45 "<<"006400 "<<"0000AA"
<<"FFFFF0 "<<"FFFAF0 "<<"FFF5EE "<<"FFEC8B "<<"FFE4C4 "<<"FFDAB9 "<<"FFC125 "<<"FFB6C1 "<<"FFA500 "<<"FF83FA "<<"FF7F24 "<<"FF6A6A "<<"FF4040 "<<"FF1493 "<<"FCFCFC "<<"FAEBD7 "<<"F5FFFA "<<"F4F4F4 "<<"F0FFF0 "<<"F08080 "<<"EEE9E9 "<<"EEE685 "<<"EEDC82 "<<"EED2EE "<<"EEC591 "<<"EEAD0E "<<"EE9A00 "<<"EE7AE9 "<<"EE7600 "<<"EE5C42 "<<"EE30A7 "<<"EE0000 "<<"E9967A "<<"E3E3E3 "<<"E0E0E0 "<<"DDA0DD "<<"DB7093 "<<"D8BFD8 "<<"D2B48C "<<"D15FEE "<<"CDCDB4 "<<"CDC8B1 "<<"CDC0B0 "<<"CDB79E "<<"CDAD00 "<<"CD96CD "<<"CD853F "<<"CD69C9 "<<"CD6600 "<<"CD5555 "<<"CD3278 "<<"CD00CD "<<"CAE1FF "<<"C6E2FF "<<"C2C2C2 "<<"C1C1C1 "<<"BF3EFF "<<"BCEE68 "<<"BABABA "<<"B8860B "<<"B4CDCD "<<"B2DFEE "<<"B0E0E6 "<<"AEEEEE "<<"ABABAB "<<"A8A8A8 "<<"A3A3A3 "<<"A0522D "<<"9E9E9E "<<"9AFF9A "<<"999999 "<<"97FFFF "<<"9400D3 "<<"90EE90 "<<"8E8E8E "<<"8DB6CD "<<"8B8B00 "<<"8B8682 "<<"8B814C "<<"8B7B8B "<<"8B7355 "<<"8B6508 "<<"8B5A00 "<<"8B475D "<<"8B3E2F "<<"8B2500 "<<"8B1A1A "<<"8A8A8A "<<"87CEFA "<<"848484 "<<"836FFF "<<"7F7F7F "<<"7D26CD "<<"7AC5CD "<<"7A378B "<<"76EEC6 "<<"71C671 "<<"6E8B3D "<<"6C7B8B "<<"698B69 "<<"68838B "<<"668B8B "<<"636363 "<<"5E5E5E "<<"5B5B5B "<<"555555 "<<"545454 "<<"515151 "<<"4D4D4D "<<"48D1CC "<<"473C8B "<<"454545 "<<"4169E1 "<<"3CB371 "<<"383838 "<<"32CD32 "<<"2E2E2E "<<"27408B "<<"218868 "<<"1E90FF "<<"1A1A1A "<<"141414 "<<"0D0D0D "<<"030303 "<<"00FA9A "<<"00EE00 "<<"00CD66 "<<"00B2EE "<<"008B00 "<<"0000FF "<<"00008B"
<<"FFFFE0 "<<"FFFACD "<<"FFF0F5 "<<"FFEBCD "<<"FFE4B5 "<<"FFD700 "<<"FFC0CB "<<"FFB5C5 "<<"FFA07A "<<"FF82AB "<<"FF7F00 "<<"FF69B4 "<<"FF3E96 "<<"FF00FF "<<"FAFAFA "<<"FA8072 "<<"F5F5F5 "<<"F4A460 "<<"F0F8FF "<<"EEEEE0 "<<"EEE9BF "<<"EEE5DE "<<"EED8AE "<<"EECFA1 "<<"EEB4B4 "<<"EEA9B8 "<<"EE9572 "<<"EE799F "<<"EE6AA7 "<<"EE4000 "<<"EE2C2C "<<"EDEDED "<<"E8E8E8 "<<"E0FFFF "<<"E066FF "<<"DCDCDC "<<"DAA520 "<<"D6D6D6 "<<"D2691E "<<"D02090 "<<"CDCD00 "<<"CDC673 "<<"CDBE70 "<<"CDB5CD "<<"CDAA7D "<<"CD950C "<<"CD8500 "<<"CD6889 "<<"CD6090 "<<"CD4F39 "<<"CD2990 "<<"CD0000 "<<"C9C9C9 "<<"C67171 "<<"C1FFC1 "<<"C0FF3E "<<"BEBEBE "<<"BCD2EE "<<"BA55D3 "<<"B7B7B7 "<<"B452CD "<<"B23AEE "<<"B0C4DE "<<"ADFF2F "<<"AB82FF "<<"A6A6A6 "<<"A2CD5A "<<"A020F0 "<<"9C9C9C "<<"9ACD32 "<<"9932CC "<<"96CDCD "<<"9370DB "<<"8FBC8F "<<"8E8E38 "<<"8C8C8C "<<"8B8989 "<<"8B864E "<<"8B7E66 "<<"8B795E "<<"8B6969 "<<"8B636C "<<"8B5742 "<<"8B4726 "<<"8B3A62 "<<"8B2323 "<<"8B0A50 "<<"8A2BE2 "<<"87CEEB "<<"8470FF "<<"828282 "<<"7EC0EE "<<"7CFC00 "<<"7A8B8B "<<"79CDCD "<<"76EE00 "<<"7171C6 "<<"6E7B8B "<<"6B8E23 "<<"698B22 "<<"68228B "<<"666666 "<<"616161 "<<"5D478B "<<"595959 "<<"551A8B "<<"53868B "<<"4F94CD "<<"4B0082 "<<"4876FF "<<"4682B4 "<<"43CD80 "<<"40E0D0 "<<"3B3B3B "<<"36648B "<<"303030 "<<"2B2B2B "<<"262626 "<<"212121 "<<"1E1E1E "<<"191970 "<<"121212 "<<"0A0A0A "<<"00FFFF "<<"00F5FF "<<"00E5EE "<<"00CD00 "<<"009ACD "<<"00868B "<<"0000EE "<<"000080"
<<"FFFF00 "<<"FFF8DC "<<"FFEFDB "<<"FFE7BA "<<"FFE1FF "<<"FFD39B "<<"FFBBFF "<<"FFAEB9 "<<"FF8C69 "<<"FF8247 "<<"FF7256 "<<"FF6347 "<<"FF34B3 "<<"FF0000 "<<"FAFAD2 "<<"F8F8FF "<<"F5F5DC "<<"F2F2F2 "<<"F0F0F0 "<<"EEEED1 "<<"EEE8CD "<<"EEE0E5 "<<"EED5D2 "<<"EECBAD "<<"EEB422 "<<"EEA2AD "<<"EE82EE "<<"EE7942 "<<"EE6A50 "<<"EE3B3B "<<"EE1289 "<<"EBEBEB "<<"E6E6FA "<<"E0EEEE "<<"DEDEDE "<<"DC143C "<<"DA70D6 "<<"D4D4D4 "<<"D1EEEE "<<"CFCFCF "<<"CDC9C9 "<<"CDC5BF "<<"CDBA96 "<<"CDB38B "<<"CD9B9B "<<"CD919E "<<"CD8162 "<<"CD6839 "<<"CD5C5C "<<"CD3700 "<<"CD2626 "<<"CCCCCC "<<"C7C7C7 "<<"C5C1AA "<<"C1CDCD "<<"BFEFFF "<<"BDBDBD "<<"BC8F8F "<<"B9D3EE "<<"B5B5B5 "<<"B3EE3A "<<"B22222 "<<"B0B0B0 "<<"ADD8E6 "<<"AAAAAA "<<"A52A2A "<<"A2B5CD "<<"9FB6CD "<<"9BCD9B "<<"9AC0CD "<<"98FB98 "<<"969696 "<<"919191 "<<"8F8F8F "<<"8E388E "<<"8B8B83 "<<"8B8970 "<<"8B8386 "<<"8B7D7B "<<"8B7765 "<<"8B6914 "<<"8B5F65 "<<"8B4C39 "<<"8B4513 "<<"8B3A3A "<<"8B2252 "<<"8B008B "<<"8968CD "<<"878787 "<<"838B8B "<<"7FFFD4 "<<"7D9EC0 "<<"7CCD7C "<<"7A7A7A "<<"787878 "<<"757575 "<<"708090 "<<"6E6E6E "<<"6B6B6B "<<"696969 "<<"66CDAA "<<"6495ED "<<"607B8B "<<"5CACEE "<<"575757 "<<"54FF9F "<<"528B8B "<<"4F4F4F "<<"4A708B "<<"483D8B "<<"458B74 "<<"436EEE "<<"404040 "<<"3A5FCD "<<"363636 "<<"2F4F4F "<<"292929 "<<"242424 "<<"20B2AA "<<"1C86EE "<<"1874CD "<<"104E8B "<<"080808 "<<"00FF7F "<<"00EEEE "<<"00CED1 "<<"00C5CD "<<"008B8B "<<"00688B "<<"0000CD "<<"000000";
}


void ColorPanel::paintEvent(QPaintEvent *event)
{
QPainter painter(this);

int colorsCount=0;

for (int i=0;i<widthCount;i++)
{
for (int j=0;j<heightCount;j++)
{
if (colorsCount<colors.count())
{
painter.setPen(Qt::NoPen);
painter.setBrush(QBrush(QColor("#"+colors[colorsCount].trimmed())));
painter.drawRect(i*boxSize->width(),j*boxSize->height(),boxSize->width(),boxSize->height());

//draw a highlight for hovered item
if( indexHighlighted == colorsCount )
{
QColor outline(palette().foreground().color());
outline.setAlpha( 64 );
painter.setPen( outline );
painter.setBrush(Qt::NoBrush);
painter.drawRect( (i*boxSize->width()),(j*boxSize->height()),boxSize->width()-1,boxSize->height()-1);
}
}
colorsCount++;
}
}
}


void ColorPanel::mouseMoveEvent( QMouseEvent *event )
{
QPoint pointMouseMove = event->pos();

int column = pointMouseMove.x() / boxSize->width();
int row = pointMouseMove.y() / boxSize->height();

column = qBound( 0, column, widthCount-1 );
row = qBound( 0, row, heightCount-1 );

int newIndex = (column * heightCount) + row;

if ( newIndex != indexHighlighted )
{
//qDebug() <<"ColorPanel::mouseMoveEvent"<<pointMouseMove<<" - ("<<column<<row<<") maps to "<<newIndex<<"of"<<colors.count()<<"..."<<colors[newIndex];
indexHighlighted = newIndex;
update();
emit indexHighlightedChanged( indexHighlighted );
emit colorHighlightedChanged( QColor("#"+colors[indexHighlighted].trimmed()) );
}
}