summaryrefslogtreecommitdiff
authorzecke <zecke>2004-02-25 19:59:21 (UTC)
committer zecke <zecke>2004-02-25 19:59:21 (UTC)
commita73e8d51528b6c073d56f389f22fb95d99e9407f (patch) (unidiff)
tree6b898768b914933341a42c1b411448d1df84405a
parentbea97f98bfb31994425908e7ce982b2450696706 (diff)
downloadopie-a73e8d51528b6c073d56f389f22fb95d99e9407f.zip
opie-a73e8d51528b6c073d56f389f22fb95d99e9407f.tar.gz
opie-a73e8d51528b6c073d56f389f22fb95d99e9407f.tar.bz2
Revert drw s commit
Do not expose private API Better include the .moc
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libqtaux/libqtaux.pro1
-rw-r--r--libqtaux/qcolordialog.cpp838
-rw-r--r--libqtaux/qcolordialog.h315
3 files changed, 590 insertions, 564 deletions
diff --git a/libqtaux/libqtaux.pro b/libqtaux/libqtaux.pro
index 56ccc65..a1440e3 100644
--- a/libqtaux/libqtaux.pro
+++ b/libqtaux/libqtaux.pro
@@ -18,8 +18,7 @@ SOURCES = qcolordialog.cpp \
18 18
19TARGET = qtaux2 19TARGET = qtaux2
20INCLUDEPATH += $(OPIEDIR)/include 20INCLUDEPATH += $(OPIEDIR)/include
21DESTDIR = $(OPIEDIR)/lib 21DESTDIR = $(OPIEDIR)/lib
22INTERFACES =
23 22
24 23
25include ( $(OPIEDIR)/include.pro ) 24include ( $(OPIEDIR)/include.pro )
diff --git a/libqtaux/qcolordialog.cpp b/libqtaux/qcolordialog.cpp
index 1574841..b960b04 100644
--- a/libqtaux/qcolordialog.cpp
+++ b/libqtaux/qcolordialog.cpp
@@ -36,21 +36,24 @@
36**********************************************************************/ 36**********************************************************************/
37 37
38#include "qcolordialog.h" 38#include "qcolordialog.h"
39 39
40#include <qpainter.h> 40#include "qpainter.h"
41#include <qlayout.h> 41#include "qlayout.h"
42#include <qpushbutton.h> 42#include "qlabel.h"
43#include <qimage.h> 43#include "qpushbutton.h"
44#include <qpixmap.h> 44#include "qlineedit.h"
45#include <qdrawutil.h> 45#include "qimage.h"
46#include <qdragobject.h> 46#include "qpixmap.h"
47#include <qapplication.h> 47#include "qdrawutil.h"
48#include <qdragobject.h> 48#include "qvalidator.h"
49#include "qdragobject.h"
50#include "qapplication.h"
51#include "qdragobject.h"
49 52
50//////////// QWellArray BEGIN 53//////////// QWellArray BEGIN
51 54
52#include <qobjectdict.h> 55#include "qobjectdict.h"
53 56
54// 57//
55// W A R N I N G 58// W A R N I N G
56// ------------- 59// -------------
@@ -61,29 +64,128 @@
61// or even be removed. 64// or even be removed.
62// 65//
63// 66//
64 67
68
69#include "qtableview.h"
70
71
72struct QWellArrayData;
73
74class QWellArray : public QTableView
75{
76 Q_OBJECT
77 Q_PROPERTY( int numCols READ numCols )
78 Q_PROPERTY( int numRows READ numRows )
79 Q_PROPERTY( int selectedColumn READ selectedColumn )
80 Q_PROPERTY( int selectedRow READ selectedRow )
81
82public:
83 QWellArray( QWidget *parent=0, const char *name=0, bool popup = FALSE );
84
85 ~QWellArray() {}
86 QString cellContent( int row, int col ) const;
87 // ### Paul !!! virtual void setCellContent( int row, int col, const QString &);
88
89 // ##### Obsolete since not const
90 int numCols() { return nCols; }
91 int numRows() { return nRows; }
92
93 int numCols() const { return nCols; }
94 int numRows() const { return nRows; }
95
96 // ##### Obsolete since not const
97 int selectedColumn() { return selCol; }
98 int selectedRow() { return selRow; }
99
100 int selectedColumn() const { return selCol; }
101 int selectedRow() const { return selRow; }
102
103 virtual void setSelected( int row, int col );
104
105 void setCellSize( int w, int h ) { setCellWidth(w);setCellHeight( h ); }
106
107 QSize sizeHint() const;
108
109 virtual void setDimension( int rows, int cols );
110 virtual void setCellBrush( int row, int col, const QBrush & );
111 QBrush cellBrush( int row, int col );
112
113signals:
114 void selected( int row, int col );
115
116protected:
117 virtual void setCurrent( int row, int col );
118
119 virtual void drawContents( QPainter *, int row, int col, const QRect& );
120 void drawContents( QPainter * );
121
122 void paintCell( QPainter*, int row, int col );
123 void mousePressEvent( QMouseEvent* );
124 void mouseReleaseEvent( QMouseEvent* );
125 void mouseMoveEvent( QMouseEvent* );
126 void keyPressEvent( QKeyEvent* );
127 void focusInEvent( QFocusEvent* );
128 void focusOutEvent( QFocusEvent* );
129
130private:
131 int curRow;
132 int curCol;
133 int selRow;
134 int selCol;
135 int nCols;
136 int nRows;
137 bool smallStyle;
138 QWellArrayData *d;
139
140 private:// Disabled copy constructor and operator=
141#if defined(Q_DISABLE_COPY)
142 QWellArray( const QWellArray & );
143 QWellArray& operator=( const QWellArray & );
144#endif
145};
146
147
148
149// non-interface ...
150
151
152
153struct QWellArrayData {
154 QBrush *brush;
155};
156
157// NOT REVISED
158/* WARNING, NOT
159 \class QWellArray qwellarray_p.h
160 \brief ....
161
162 ....
163
164 \ingroup advanced
165*/
166
65QWellArray::QWellArray( QWidget *parent, const char * name, bool popup ) 167QWellArray::QWellArray( QWidget *parent, const char * name, bool popup )
66 : QTableView( parent, name, 168 : QTableView( parent, name,
67 popup ? (WStyle_Customize|WStyle_Tool|WStyle_NoBorder) : 0 ) 169 popup ? (WStyle_Customize|WStyle_Tool|WStyle_NoBorder) : 0 )
68{ 170{
69 d = 0; 171 d = 0;
70 setFocusPolicy( StrongFocus ); 172 setFocusPolicy( StrongFocus );
71 setBackgroundMode( PaletteButton ); 173 setBackgroundMode( PaletteButton );
72 nCols = 7; 174 nCols = 7;
73 nRows = 7; 175 nRows = 7;
74 int w = 24; // cell width 176 int w = 24; // cell width
75 int h = 21; // cell height 177 int h = 21; // cell height
76 smallStyle = popup; 178 smallStyle = popup;
77 179
78 if ( popup ) { 180 if ( popup ) {
79 w = h = 18; 181 w = h = 18;
80 if ( style() == WindowsStyle ) 182 if ( style() == WindowsStyle )
81 setFrameStyle( QFrame::WinPanel | QFrame::Raised ); 183 setFrameStyle( QFrame::WinPanel | QFrame::Raised );
82 else 184 else
83 setFrameStyle( QFrame::Panel | QFrame::Raised ); 185 setFrameStyle( QFrame::Panel | QFrame::Raised );
84 setMargin( 1 ); 186 setMargin( 1 );
85 setLineWidth( 2 ); 187 setLineWidth( 2 );
86 } 188 }
87 setNumCols( nCols ); 189 setNumCols( nCols );
88 setNumRows( nRows ); 190 setNumRows( nRows );
89 setCellWidth( w ); 191 setCellWidth( w );
@@ -93,9 +195,9 @@ QWellArray::QWellArray( QWidget *parent, const char * name, bool popup )
93 selCol = -1; 195 selCol = -1;
94 selRow = -1; 196 selRow = -1;
95 197
96 if ( smallStyle ) 198 if ( smallStyle )
97 setMouseTracking( TRUE ); 199 setMouseTracking( TRUE );
98 setOffset( 5 , 10 ); 200 setOffset( 5 , 10 );
99 201
100 resize( sizeHint() ); 202 resize( sizeHint() );
101 203
@@ -113,54 +215,54 @@ QSize QWellArray::sizeHint() const
113 215
114 216
115void QWellArray::paintCell( QPainter* p, int row, int col ) 217void QWellArray::paintCell( QPainter* p, int row, int col )
116{ 218{
117 int w = cellWidth( col ); // width of cell in pixels 219 int w = cellWidth( col ); // width of cell in pixels
118 int h = cellHeight( row ); // height of cell in pixels 220 int h = cellHeight( row ); // height of cell in pixels
119 int b = 1; 221 int b = 1;
120 222
121 if ( !smallStyle ) 223 if ( !smallStyle )
122 b = 3; 224 b = 3;
123 225
124 const QColorGroup & g = colorGroup(); 226 const QColorGroup & g = colorGroup();
125 p->setPen( QPen( black, 0, SolidLine ) ); 227 p->setPen( QPen( black, 0, SolidLine ) );
126 if ( !smallStyle && row ==selRow && col == selCol && 228 if ( !smallStyle && row ==selRow && col == selCol &&
127 style() != MotifStyle ) { 229 style() != MotifStyle ) {
128 int n = 2; 230 int n = 2;
129 p->drawRect( n, n, w-2*n, h-2*n ); 231 p->drawRect( n, n, w-2*n, h-2*n );
130 } 232 }
131 233
132 234
133 if ( style() == WindowsStyle ) { 235 if ( style() == WindowsStyle ) {
134 qDrawWinPanel( p, b, b , w - 2*b, h - 2*b, 236 qDrawWinPanel( p, b, b , w - 2*b, h - 2*b,
135 g, TRUE ); 237 g, TRUE );
136 b += 2; 238 b += 2;
137 } else { 239 } else {
138 if ( smallStyle ) { 240 if ( smallStyle ) {
139 qDrawShadePanel( p, b, b , w - 2*b, h - 2*b, 241 qDrawShadePanel( p, b, b , w - 2*b, h - 2*b,
140 g, TRUE, 2 ); 242 g, TRUE, 2 );
141 b += 2; 243 b += 2;
142 } else { 244 } else {
143 int t = ( row == selRow && col == selCol ) ? 2 : 0; 245 int t = ( row == selRow && col == selCol ) ? 2 : 0;
144 b -= t; 246 b -= t;
145 qDrawShadePanel( p, b, b , w - 2*b, h - 2*b, 247 qDrawShadePanel( p, b, b , w - 2*b, h - 2*b,
146 g, TRUE, 2 ); 248 g, TRUE, 2 );
147 b += 2 + t; 249 b += 2 + t;
148 } 250 }
149 } 251 }
150 252
151 253
152 if ( (row == curRow) && (col == curCol) ) { 254 if ( (row == curRow) && (col == curCol) ) {
153 if ( smallStyle ) { 255 if ( smallStyle ) {
154 p->setPen ( white ); 256 p->setPen ( white );
155 p->drawRect( 1, 1, w-2, h-2 ); 257 p->drawRect( 1, 1, w-2, h-2 );
156 p->setPen ( black ); 258 p->setPen ( black );
157 p->drawRect( 0, 0, w, h ); 259 p->drawRect( 0, 0, w, h );
158 p->drawRect( 2, 2, w-4, h-4 ); 260 p->drawRect( 2, 2, w-4, h-4 );
159 b = 3; 261 b = 3;
160 } else if ( hasFocus() ) { 262 } else if ( hasFocus() ) {
161 style().drawFocusRect(p, QRect(0,0,w,h), g ); 263 style().drawFocusRect(p, QRect(0,0,w,h), g );
162 } 264 }
163 } 265 }
164 drawContents( p, row, col, QRect(b, b, w - 2*b, h - 2*b) ); 266 drawContents( p, row, col, QRect(b, b, w - 2*b, h - 2*b) );
165} 267}
166 268
@@ -178,14 +280,14 @@ void QWellArray::drawContents( QPainter *p )
178void QWellArray::drawContents( QPainter *p, int row, int col, const QRect &r ) 280void QWellArray::drawContents( QPainter *p, int row, int col, const QRect &r )
179{ 281{
180 282
181 if ( d ) { 283 if ( d ) {
182 p->fillRect( r, d->brush[row*nCols+col] ); 284 p->fillRect( r, d->brush[row*nCols+col] );
183 } else { 285 } else {
184 p->fillRect( r, white ); 286 p->fillRect( r, white );
185 p->setPen( black ); 287 p->setPen( black );
186 p->drawLine( r.topLeft(), r.bottomRight() ); 288 p->drawLine( r.topLeft(), r.bottomRight() );
187 p->drawLine( r.topRight(), r.bottomLeft() ); 289 p->drawLine( r.topRight(), r.bottomLeft() );
188 } 290 }
189} 291}
190 292
191 293
@@ -215,10 +317,10 @@ void QWellArray::mouseMoveEvent( QMouseEvent* e )
215{ 317{
216 // The current cell marker is set to the cell the mouse is 318 // The current cell marker is set to the cell the mouse is
217 // clicked in. 319 // clicked in.
218 if ( smallStyle ) { 320 if ( smallStyle ) {
219 QPoint pos = e->pos(); 321 QPoint pos = e->pos();
220 setCurrent( findRow( pos.y() ), findCol( pos.x() ) ); 322 setCurrent( findRow( pos.y() ), findCol( pos.x() ) );
221 } 323 }
222} 324}
223 325
224/* 326/*
@@ -229,12 +331,12 @@ void QWellArray::mouseMoveEvent( QMouseEvent* e )
229void QWellArray::setCurrent( int row, int col ) 331void QWellArray::setCurrent( int row, int col )
230{ 332{
231 333
232 if ( (curRow == row) && (curCol == col) ) 334 if ( (curRow == row) && (curCol == col) )
233 return; 335 return;
234 336
235 if ( row < 0 || col < 0 ) 337 if ( row < 0 || col < 0 )
236 row = col = -1; 338 row = col = -1;
237 339
238 int oldRow = curRow; 340 int oldRow = curRow;
239 int oldCol = curCol; 341 int oldCol = curCol;
240 342
@@ -255,26 +357,26 @@ void QWellArray::setCurrent( int row, int col )
255 357
256void QWellArray::setSelected( int row, int col ) 358void QWellArray::setSelected( int row, int col )
257{ 359{
258 if ( (selRow == row) && (selCol == col) ) 360 if ( (selRow == row) && (selCol == col) )
259 return; 361 return;
260 362
261 int oldRow = selRow; 363 int oldRow = selRow;
262 int oldCol = selCol; 364 int oldCol = selCol;
263 365
264 if ( row < 0 || col < 0 ) 366 if ( row < 0 || col < 0 )
265 row = col = -1; 367 row = col = -1;
266 368
267 selCol = col; 369 selCol = col;
268 selRow = row; 370 selRow = row;
269 371
270 updateCell( oldRow, oldCol ); 372 updateCell( oldRow, oldCol );
271 updateCell( selRow, selCol ); 373 updateCell( selRow, selCol );
272 if ( row >= 0 ) 374 if ( row >= 0 )
273 emit selected( row, col ); 375 emit selected( row, col );
274 376
275 if ( isVisible() && parentWidget() && parentWidget()->inherits("QPopupMenu") ) 377 if ( isVisible() && parentWidget() && parentWidget()->inherits("QPopupMenu") )
276 parentWidget()->close(); 378 parentWidget()->close();
277 379
278} 380}
279 381
280 382
@@ -297,28 +399,28 @@ void QWellArray::setDimension( int rows, int cols )
297{ 399{
298 nRows = rows; 400 nRows = rows;
299 nCols = cols; 401 nCols = cols;
300 if ( d ) { 402 if ( d ) {
301 if ( d->brush ) 403 if ( d->brush )
302 delete[] d->brush; 404 delete[] d->brush;
303 delete d; 405 delete d;
304 d = 0; 406 d = 0;
305 } 407 }
306 setNumCols( nCols ); 408 setNumCols( nCols );
307 setNumRows( nRows ); 409 setNumRows( nRows );
308} 410}
309 411
310void QWellArray::setCellBrush( int row, int col, const QBrush &b ) 412void QWellArray::setCellBrush( int row, int col, const QBrush &b )
311{ 413{
312 if ( !d ) { 414 if ( !d ) {
313 d = new QWellArrayData; 415 d = new QWellArrayData;
314 d->brush = new QBrush[nRows*nCols]; 416 d->brush = new QBrush[nRows*nCols];
315 } 417 }
316 if ( row >= 0 && row < nRows && col >= 0 && col < nCols ) 418 if ( row >= 0 && row < nRows && col >= 0 && col < nCols )
317 d->brush[row*nCols+col] = b; 419 d->brush[row*nCols+col] = b;
318#ifdef CHECK_RANGE 420#ifdef CHECK_RANGE
319 else 421 else
320 qWarning( "QWellArray::setCellBrush( %d, %d ) out of range", row, col ); 422 qWarning( "QWellArray::setCellBrush( %d, %d ) out of range", row, col );
321#endif 423#endif
322} 424}
323 425
324 426
@@ -330,9 +432,9 @@ void QWellArray::setCellBrush( int row, int col, const QBrush &b )
330 432
331QBrush QWellArray::cellBrush( int row, int col ) 433QBrush QWellArray::cellBrush( int row, int col )
332{ 434{
333 if ( d && row >= 0 && row < nRows && col >= 0 && col < nCols ) 435 if ( d && row >= 0 && row < nRows && col >= 0 && col < nCols )
334 return d->brush[row*nCols+col]; 436 return d->brush[row*nCols+col];
335 return NoBrush; 437 return NoBrush;
336} 438}
337 439
338 440
@@ -348,51 +450,51 @@ void QWellArray::focusOutEvent( QFocusEvent* )
348/*\reimp 450/*\reimp
349*/ 451*/
350void QWellArray::keyPressEvent( QKeyEvent* e ) 452void QWellArray::keyPressEvent( QKeyEvent* e )
351{ 453{
352 switch( e->key() ) { // Look at the key code 454 switch( e->key() ) { // Look at the key code
353 case Key_Left: // If 'left arrow'-key, 455 case Key_Left: // If 'left arrow'-key,
354 if( curCol > 0 ) { // and cr't not in leftmost col 456 if( curCol > 0 ) { // and cr't not in leftmost col
355 setCurrent( curRow, curCol - 1); // set cr't to next left column 457 setCurrent( curRow, curCol - 1);// set cr't to next left column
356 int edge = leftCell(); // find left edge 458 int edge = leftCell(); // find left edge
357 if ( curCol < edge ) // if we have moved off edge, 459 if ( curCol < edge ) // if we have moved off edge,
358 setLeftCell( edge - 1 ); // scroll view to rectify 460 setLeftCell( edge - 1 );// scroll view to rectify
359 } 461 }
360 break; 462 break;
361 case Key_Right: // Correspondingly... 463 case Key_Right: // Correspondingly...
362 if( curCol < numCols()-1 ) { 464 if( curCol < numCols()-1 ) {
363 setCurrent( curRow, curCol + 1); 465 setCurrent( curRow, curCol + 1);
364 int edge = lastColVisible(); 466 int edge = lastColVisible();
365 if ( curCol >= edge ) 467 if ( curCol >= edge )
366 setLeftCell( leftCell() + 1 ); 468 setLeftCell( leftCell() + 1 );
367 } 469 }
368 break; 470 break;
369 case Key_Up: 471 case Key_Up:
370 if( curRow > 0 ) { 472 if( curRow > 0 ) {
371 setCurrent( curRow - 1, curCol); 473 setCurrent( curRow - 1, curCol);
372 int edge = topCell(); 474 int edge = topCell();
373 if ( curRow < edge ) 475 if ( curRow < edge )
374 setTopCell( edge - 1 ); 476 setTopCell( edge - 1 );
375 } else if ( smallStyle ) 477 } else if ( smallStyle )
376 focusNextPrevChild( FALSE ); 478 focusNextPrevChild( FALSE );
377 break; 479 break;
378 case Key_Down: 480 case Key_Down:
379 if( curRow < numRows()-1 ) { 481 if( curRow < numRows()-1 ) {
380 setCurrent( curRow + 1, curCol); 482 setCurrent( curRow + 1, curCol);
381 int edge = lastRowVisible(); 483 int edge = lastRowVisible();
382 if ( curRow >= edge ) 484 if ( curRow >= edge )
383 setTopCell( topCell() + 1 ); 485 setTopCell( topCell() + 1 );
384 } else if ( smallStyle ) 486 } else if ( smallStyle )
385 focusNextPrevChild( TRUE ); 487 focusNextPrevChild( TRUE );
386 break; 488 break;
387 case Key_Space: 489 case Key_Space:
388 case Key_Return: 490 case Key_Return:
389 case Key_Enter: 491 case Key_Enter:
390 setSelected( curRow, curCol ); 492 setSelected( curRow, curCol );
391 break; 493 break;
392 default: // If not an interesting key, 494 default: // If not an interesting key,
393 e->ignore(); // we don't accept the event 495 e->ignore(); // we don't accept the event
394 return; 496 return;
395 } 497 }
396 498
397} 499}
398 500
@@ -405,18 +507,18 @@ static QRgb cusrgb[2*8];
405 507
406static void initRGB() 508static void initRGB()
407{ 509{
408 if ( initrgb ) 510 if ( initrgb )
409 return; 511 return;
410 initrgb = TRUE; 512 initrgb = TRUE;
411 int i = 0; 513 int i = 0;
412 for ( int g = 0; g < 4; g++ ) 514 for ( int g = 0; g < 4; g++ )
413 for ( int r = 0; r < 4; r++ ) 515 for ( int r = 0; r < 4; r++ )
414 for ( int b = 0; b < 3; b++ ) 516 for ( int b = 0; b < 3; b++ )
415 stdrgb[i++] = qRgb( r*255/3, g*255/3, b*255/2 ); 517 stdrgb[i++] = qRgb( r*255/3, g*255/3, b*255/2 );
416 518
417 for ( i = 0; i < 2*8; i++ ) 519 for ( i = 0; i < 2*8; i++ )
418 cusrgb[i] = qRgb(0xff,0xff,0xff); 520 cusrgb[i] = qRgb(0xff,0xff,0xff);
419} 521}
420 522
421/*! 523/*!
422 Returns the number of custom colors supported by 524 Returns the number of custom colors supported by
@@ -434,11 +536,11 @@ QRgb QColorDialog::customColor( int i )
434{ 536{
435 initRGB(); 537 initRGB();
436 if ( i < 0 || i >= customCount() ) { 538 if ( i < 0 || i >= customCount() ) {
437#ifdef CHECK_RANGE 539#ifdef CHECK_RANGE
438 qWarning( "QColorDialog::customColor() index %d out of range", i ); 540 qWarning( "QColorDialog::customColor() index %d out of range", i );
439#endif 541 #endif
440 i = 0; 542 i = 0;
441 } 543 }
442 return cusrgb[i]; 544 return cusrgb[i];
443} 545}
444 546
@@ -449,11 +551,11 @@ void QColorDialog::setCustomColor( int i, QRgb c )
449{ 551{
450 initRGB(); 552 initRGB();
451 if ( i < 0 || i >= customCount() ) { 553 if ( i < 0 || i >= customCount() ) {
452#ifdef CHECK_RANGE 554#ifdef CHECK_RANGE
453 qWarning( "QColorDialog::customColor() index %d out of range", i ); 555 qWarning( "QColorDialog::customColor() index %d out of range", i );
454#endif 556 #endif
455 return; 557 return;
456 } 558 }
457 cusrgb[i] = c; 559 cusrgb[i] = c;
458} 560}
459 561
@@ -463,8 +565,37 @@ static inline void rgb2hsv( QRgb rgb, int&h, int&s, int&v )
463 c.setRgb( rgb ); 565 c.setRgb( rgb );
464 c.getHsv(h,s,v); 566 c.getHsv(h,s,v);
465} 567}
466 568
569class QColorWell : public QWellArray
570{
571public:
572 QColorWell( QWidget *parent, int r, int c, QRgb *vals )
573 :QWellArray( parent, "" ), values( vals ), mousePressed( FALSE ), oldCurrent( -1, -1 )
574 { setDimension(r,c); setWFlags( WResizeNoErase ); }
575 QSizePolicy sizePolicy() const;
576
577protected:
578 void drawContents( QPainter *, int row, int col, const QRect& );
579 void drawContents( QPainter *p ) { QWellArray::drawContents(p); }
580 void mousePressEvent( QMouseEvent *e );
581 void mouseMoveEvent( QMouseEvent *e );
582 void mouseReleaseEvent( QMouseEvent *e );
583#ifndef QT_NO_DRAGANDDROP
584 void dragEnterEvent( QDragEnterEvent *e );
585 void dragLeaveEvent( QDragLeaveEvent *e );
586 void dragMoveEvent( QDragMoveEvent *e );
587 void dropEvent( QDropEvent *e );
588#endif
589
590private:
591 QRgb *values;
592 bool mousePressed;
593 QPoint pressPos;
594 QPoint oldCurrent;
595
596};
597
467QSizePolicy QColorWell::sizePolicy() const 598QSizePolicy QColorWell::sizePolicy() const
468{ 599{
469 return QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ); 600 return QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
470} 601}
@@ -487,22 +618,22 @@ void QColorWell::mouseMoveEvent( QMouseEvent *e )
487{ 618{
488 QWellArray::mouseMoveEvent( e ); 619 QWellArray::mouseMoveEvent( e );
489#ifndef QT_NO_DRAGANDDROP 620#ifndef QT_NO_DRAGANDDROP
490 if ( !mousePressed ) 621 if ( !mousePressed )
491 return; 622 return;
492 if ( ( pressPos - e->pos() ).manhattanLength() > QApplication::startDragDistance() ) { 623 if ( ( pressPos - e->pos() ).manhattanLength() > QApplication::startDragDistance() ) {
493 setCurrent( oldCurrent.x(), oldCurrent.y() ); 624 setCurrent( oldCurrent.x(), oldCurrent.y() );
494 int i = findRow( e->y() ) + findCol( e->x() ) * numRows(); 625 int i = findRow( e->y() ) + findCol( e->x() ) * numRows();
495 QColor col( values[ i ] ); 626 QColor col( values[ i ] );
496 QColorDrag *drg = new QColorDrag( col, this ); 627 QColorDrag *drg = new QColorDrag( col, this );
497 QPixmap pix( cellWidth(), cellHeight() ); 628 QPixmap pix( cellWidth(), cellHeight() );
498 pix.fill( col ); 629 pix.fill( col );
499 QPainter p( &pix ); 630 QPainter p( &pix );
500 p.drawRect( 0, 0, pix.width(), pix.height() ); 631 p.drawRect( 0, 0, pix.width(), pix.height() );
501 p.end(); 632 p.end();
502 drg->setPixmap( pix ); 633 drg->setPixmap( pix );
503 mousePressed = FALSE; 634 mousePressed = FALSE;
504 drg->dragCopy(); 635 drg->dragCopy();
505 } 636 }
506#endif 637#endif
507} 638}
508 639
@@ -510,55 +641,122 @@ void QColorWell::mouseMoveEvent( QMouseEvent *e )
510void QColorWell::dragEnterEvent( QDragEnterEvent *e ) 641void QColorWell::dragEnterEvent( QDragEnterEvent *e )
511{ 642{
512 setFocus(); 643 setFocus();
513 if ( QColorDrag::canDecode( e ) ) 644 if ( QColorDrag::canDecode( e ) )
514 e->accept(); 645 e->accept();
515 else 646 else
516 e->ignore(); 647 e->ignore();
517} 648}
518 649
519void QColorWell::dragLeaveEvent( QDragLeaveEvent * ) 650void QColorWell::dragLeaveEvent( QDragLeaveEvent * )
520{ 651{
521 if ( hasFocus() ) 652 if ( hasFocus() )
522 parentWidget()->setFocus(); 653 parentWidget()->setFocus();
523} 654}
524 655
525void QColorWell::dragMoveEvent( QDragMoveEvent *e ) 656void QColorWell::dragMoveEvent( QDragMoveEvent *e )
526{ 657{
527 if ( QColorDrag::canDecode( e ) ) { 658 if ( QColorDrag::canDecode( e ) ) {
528 setCurrent( findRow( e->pos().y() ), findCol( e->pos().x() ) ); 659 setCurrent( findRow( e->pos().y() ), findCol( e->pos().x() ) );
529 e->accept(); 660 e->accept();
530 } else 661 } else
531 e->ignore(); 662 e->ignore();
532} 663}
533 664
534void QColorWell::dropEvent( QDropEvent *e ) 665void QColorWell::dropEvent( QDropEvent *e )
535{ 666{
536 if ( QColorDrag::canDecode( e ) ) { 667 if ( QColorDrag::canDecode( e ) ) {
537 int i = findRow( e->pos().y() ) + findCol( e->pos().x() ) * numRows(); 668 int i = findRow( e->pos().y() ) + findCol( e->pos().x() ) * numRows();
538 QColor col; 669 QColor col;
539 QColorDrag::decode( e, col ); 670 QColorDrag::decode( e, col );
540 values[ i ] = col.rgb(); 671 values[ i ] = col.rgb();
541 repaint( FALSE ); 672 repaint( FALSE );
542 e->accept(); 673 e->accept();
543 } else { 674 } else {
544 e->ignore(); 675 e->ignore();
545 } 676 }
546} 677}
547 678
548#endif // QT_NO_DRAGANDDROP 679#endif // QT_NO_DRAGANDDROP
549 680
550void QColorWell::mouseReleaseEvent( QMouseEvent *e ) 681void QColorWell::mouseReleaseEvent( QMouseEvent *e )
551{ 682{
552 if ( !mousePressed ) 683 if ( !mousePressed )
553 return; 684 return;
554 QWellArray::mouseReleaseEvent( e ); 685 QWellArray::mouseReleaseEvent( e );
555 mousePressed = FALSE; 686 mousePressed = FALSE;
556} 687}
557 688
689class QColorPicker : public QFrame
690{
691 Q_OBJECT
692public:
693 QColorPicker(QWidget* parent=0, const char* name=0);
694 ~QColorPicker();
695
696public slots:
697 void setCol( int h, int s );
698
699signals:
700 void newCol( int h, int s );
701
702protected:
703 QSize sizeHint() const;
704 QSizePolicy sizePolicy() const;
705 void drawContents(QPainter* p);
706 void mouseMoveEvent( QMouseEvent * );
707 void mousePressEvent( QMouseEvent * );
708
709private:
710 int hue;
711 int sat;
712
713 QPoint colPt();
714 int huePt( const QPoint &pt );
715 int satPt( const QPoint &pt );
716 void setCol( const QPoint &pt );
717
718 QPixmap *pix;
719};
720
558static int pWidth = 200; 721static int pWidth = 200;
559static int pHeight = 200; 722static int pHeight = 200;
560 723
724class QColorLuminancePicker : public QWidget
725{
726 Q_OBJECT
727public:
728 QColorLuminancePicker(QWidget* parent=0, const char* name=0);
729 ~QColorLuminancePicker();
730
731public slots:
732 void setCol( int h, int s, int v );
733 void setCol( int h, int s );
734
735signals:
736 void newHsv( int h, int s, int v );
737
738protected:
739// QSize sizeHint() const;
740// QSizePolicy sizePolicy() const;
741 void paintEvent( QPaintEvent*);
742 void mouseMoveEvent( QMouseEvent * );
743 void mousePressEvent( QMouseEvent * );
744
745private:
746 enum { foff = 3, coff = 4 }; //frame and contents offset
747 int val;
748 int hue;
749 int sat;
750
751 int y2val( int y );
752 int val2y( int val );
753 void setVal( int v );
754
755 QPixmap *pix;
756};
757
758
561int QColorLuminancePicker::y2val( int y ) 759int QColorLuminancePicker::y2val( int y )
562{ 760{
563 int d = height() - 2*coff - 1; 761 int d = height() - 2*coff - 1;
564 return 255 - (y - coff)*255/d; 762 return 255 - (y - coff)*255/d;
@@ -570,9 +768,9 @@ int QColorLuminancePicker::val2y( int v )
570 return coff + (255-v)*d/255; 768 return coff + (255-v)*d/255;
571} 769}
572 770
573QColorLuminancePicker::QColorLuminancePicker(QWidget* parent, 771QColorLuminancePicker::QColorLuminancePicker(QWidget* parent,
574 const char* name) 772 const char* name)
575 :QWidget( parent, name ) 773 :QWidget( parent, name )
576{ 774{
577 hue = 100; val = 100; sat = 100; 775 hue = 100; val = 100; sat = 100;
578 pix = 0; 776 pix = 0;
@@ -595,9 +793,9 @@ void QColorLuminancePicker::mousePressEvent( QMouseEvent *m )
595 793
596void QColorLuminancePicker::setVal( int v ) 794void QColorLuminancePicker::setVal( int v )
597{ 795{
598 if ( val == v ) 796 if ( val == v )
599 return; 797 return;
600 val = QMAX( 0, QMIN(v,255)); 798 val = QMAX( 0, QMIN(v,255));
601 delete pix; pix=0; 799 delete pix; pix=0;
602 repaint( FALSE ); //### 800 repaint( FALSE ); //###
603 emit newHsv( hue, sat, val ); 801 emit newHsv( hue, sat, val );
@@ -617,20 +815,20 @@ void QColorLuminancePicker::paintEvent( QPaintEvent * )
617 QRect r( 0, foff, w, height() - 2*foff ); 815 QRect r( 0, foff, w, height() - 2*foff );
618 int wi = r.width() - 2; 816 int wi = r.width() - 2;
619 int hi = r.height() - 2; 817 int hi = r.height() - 2;
620 if ( !pix || pix->height() != hi || pix->width() != wi ) { 818 if ( !pix || pix->height() != hi || pix->width() != wi ) {
621 delete pix; 819 delete pix;
622 QImage img( wi, hi, 32 ); 820 QImage img( wi, hi, 32 );
623 int y; 821 int y;
624 for ( y = 0; y < hi; y++ ) { 822 for ( y = 0; y < hi; y++ ) {
625 QColor c( hue, sat, y2val(y+coff), QColor::Hsv ); 823 QColor c( hue, sat, y2val(y+coff), QColor::Hsv );
626 QRgb r = c.rgb(); 824 QRgb r = c.rgb();
627 int x; 825 int x;
628 for ( x = 0; x < wi; x++ ) 826 for ( x = 0; x < wi; x++ )
629 img.setPixel( x, y, r ); 827 img.setPixel( x, y, r );
630 } 828 }
631 pix = new QPixmap; 829 pix = new QPixmap;
632 pix->convertFromImage(img); 830 pix->convertFromImage(img);
633 } 831 }
634 QPainter p(this); 832 QPainter p(this);
635 p.drawPixmap( 1, coff, *pix ); 833 p.drawPixmap( 1, coff, *pix );
636 QColorGroup g = colorGroup(); 834 QColorGroup g = colorGroup();
@@ -670,13 +868,13 @@ QColorPicker::QColorPicker(QWidget* parent, const char* name )
670 868
671 QImage img( pWidth, pHeight, 32 ); 869 QImage img( pWidth, pHeight, 32 );
672 int x,y; 870 int x,y;
673 for ( y = 0; y < pHeight; y++ ) 871 for ( y = 0; y < pHeight; y++ )
674 for ( x = 0; x < pWidth; x++ ) { 872 for ( x = 0; x < pWidth; x++ ) {
675 QPoint p( x, y ); 873 QPoint p( x, y );
676 img.setPixel( x, y, QColor(huePt(p), satPt(p), 874 img.setPixel( x, y, QColor(huePt(p), satPt(p),
677 200, QColor::Hsv).rgb() ); 875 200, QColor::Hsv).rgb() );
678 } 876 }
679 pix = new QPixmap; 877 pix = new QPixmap;
680 pix->convertFromImage(img); 878 pix->convertFromImage(img);
681 setBackgroundMode( NoBackground ); 879 setBackgroundMode( NoBackground );
682} 880}
@@ -700,9 +898,9 @@ void QColorPicker::setCol( int h, int s )
700{ 898{
701 int nhue = QMIN( QMAX(0,h), 360 ); 899 int nhue = QMIN( QMAX(0,h), 360 );
702 int nsat = QMIN( QMAX(0,s), 255); 900 int nsat = QMIN( QMAX(0,s), 255);
703 if ( nhue == hue && nsat == sat ) 901 if ( nhue == hue && nsat == sat )
704 return; 902 return;
705 QRect r( colPt(), QSize(20,20) ); 903 QRect r( colPt(), QSize(20,20) );
706 hue = nhue; sat = nsat; 904 hue = nhue; sat = nsat;
707 r = r.unite( QRect( colPt(), QSize(20,20) ) ); 905 r = r.unite( QRect( colPt(), QSize(20,20) ) );
708 r.moveBy( contentsRect().x()-9, contentsRect().y()-9 ); 906 r.moveBy( contentsRect().x()-9, contentsRect().y()-9 );
@@ -736,39 +934,149 @@ void QColorPicker::drawContents(QPainter* p)
736 p->fillRect( pt.x(), pt.y()-9, 2, 20, black ); 934 p->fillRect( pt.x(), pt.y()-9, 2, 20, black );
737 935
738} 936}
739 937
938class QColorShowLabel;
939
940
941
942class QColIntValidator: public QIntValidator
943{
944public:
945 QColIntValidator( int bottom, int top,
946 QWidget * parent, const char *name = 0 )
947 :QIntValidator( bottom, top, parent, name ) {}
948
949 QValidator::State validate( QString &, int & ) const;
950};
951
740QValidator::State QColIntValidator::validate( QString &s, int &pos ) const 952QValidator::State QColIntValidator::validate( QString &s, int &pos ) const
741{ 953{
742 State state = QIntValidator::validate(s,pos); 954 State state = QIntValidator::validate(s,pos);
743 if ( state == Valid ) { 955 if ( state == Valid ) {
744 long int val = s.toLong(); 956 long int val = s.toLong();
745 // This is not a general solution, assumes that top() > 0 and 957 // This is not a general solution, assumes that top() > 0 and
746 // bottom >= 0 958 // bottom >= 0
747 if ( val < 0 ) { 959 if ( val < 0 ) {
748 s = "0"; 960 s = "0";
749 pos = 1; 961 pos = 1;
750 } else if ( val > top() ) { 962 } else if ( val > top() ) {
751 s.setNum( top() ); 963 s.setNum( top() );
752 pos = s.length(); 964 pos = s.length();
753 } 965 }
754 } 966 }
755 return state; 967 return state;
756} 968}
757 969
970
971
972class QColNumLineEdit : public QLineEdit
973{
974public:
975 QColNumLineEdit( QWidget *parent, const char* name = 0 )
976 : QLineEdit( parent, name ) { setMaxLength( 3 );}
977 QSize sizeHint() const {
978 return QSize( 30, //#####
979 QLineEdit::sizeHint().height() ); }
980 void setNum( int i ) {
981 QString s;
982 s.setNum(i);
983 bool block = signalsBlocked();
984 blockSignals(TRUE);
985 setText( s );
986 blockSignals(block);
987 }
988 int val() const { return text().toInt(); }
989};
990
991
992class QColorShower : public QWidget
993{
994 Q_OBJECT
995public:
996 QColorShower( QWidget *parent, const char *name = 0 );
997
998 //things that don't emit signals
999 void setHsv( int h, int s, int v );
1000
1001 int currentAlpha() const { return alphaEd->val(); }
1002 void setCurrentAlpha( int a ) { alphaEd->setNum( a ); }
1003 void showAlpha( bool b );
1004
1005
1006 QRgb currentColor() const { return curCol; }
1007
1008public slots:
1009 void setRgb( QRgb rgb );
1010
1011signals:
1012 void newCol( QRgb rgb );
1013private slots:
1014 void rgbEd();
1015 void hsvEd();
1016private:
1017 void showCurrentColor();
1018 int hue, sat, val;
1019 QRgb curCol;
1020 QColNumLineEdit *hEd;
1021 QColNumLineEdit *sEd;
1022 QColNumLineEdit *vEd;
1023 QColNumLineEdit *rEd;
1024 QColNumLineEdit *gEd;
1025 QColNumLineEdit *bEd;
1026 QColNumLineEdit *alphaEd;
1027 QLabel *alphaLab;
1028 QColorShowLabel *lab;
1029 bool rgbOriginal;
1030};
1031
1032class QColorShowLabel : public QFrame
1033{
1034 Q_OBJECT
1035
1036public:
1037 QColorShowLabel( QWidget *parent ) :QFrame( parent ) {
1038 setFrameStyle( QFrame::Panel|QFrame::Sunken );
1039 setBackgroundMode( PaletteBackground );
1040 setAcceptDrops( TRUE );
1041 mousePressed = FALSE;
1042 }
1043 void setColor( QColor c ) { col = c; }
1044
1045signals:
1046 void colorDropped( QRgb );
1047
1048protected:
1049 void drawContents( QPainter *p );
1050 void mousePressEvent( QMouseEvent *e );
1051 void mouseMoveEvent( QMouseEvent *e );
1052 void mouseReleaseEvent( QMouseEvent *e );
1053#ifndef QT_NO_DRAGANDDROP
1054 void dragEnterEvent( QDragEnterEvent *e );
1055 void dragLeaveEvent( QDragLeaveEvent *e );
1056 void dropEvent( QDropEvent *e );
1057#endif
1058
1059private:
1060 QColor col;
1061 bool mousePressed;
1062 QPoint pressPos;
1063
1064};
1065
758void QColorShowLabel::drawContents( QPainter *p ) 1066void QColorShowLabel::drawContents( QPainter *p )
759{ 1067{
760 p->fillRect( contentsRect(), col ); 1068 p->fillRect( contentsRect(), col );
761} 1069}
762 1070
763void QColorShower::showAlpha( bool b ) 1071void QColorShower::showAlpha( bool b )
764{ 1072{
765 if ( b ) { 1073 if ( b ) {
766 alphaLab->show(); 1074 alphaLab->show();
767 alphaEd->show(); 1075 alphaEd->show();
768 } else { 1076 } else {
769 alphaLab->hide(); 1077 alphaLab->hide();
770 alphaEd->hide(); 1078 alphaEd->hide();
771 } 1079 }
772} 1080}
773 1081
774void QColorShowLabel::mousePressEvent( QMouseEvent *e ) 1082void QColorShowLabel::mousePressEvent( QMouseEvent *e )
@@ -780,30 +1088,30 @@ void QColorShowLabel::mousePressEvent( QMouseEvent *e )
780void QColorShowLabel::mouseMoveEvent( QMouseEvent *e ) 1088void QColorShowLabel::mouseMoveEvent( QMouseEvent *e )
781{ 1089{
782#ifndef QT_NO_DRAGANDDROP 1090#ifndef QT_NO_DRAGANDDROP
783 if ( !mousePressed ) 1091 if ( !mousePressed )
784 return; 1092 return;
785 if ( ( pressPos - e->pos() ).manhattanLength() > QApplication::startDragDistance() ) { 1093 if ( ( pressPos - e->pos() ).manhattanLength() > QApplication::startDragDistance() ) {
786 QColorDrag *drg = new QColorDrag( col, this ); 1094 QColorDrag *drg = new QColorDrag( col, this );
787 QPixmap pix( 30, 20 ); 1095 QPixmap pix( 30, 20 );
788 pix.fill( col ); 1096 pix.fill( col );
789 QPainter p( &pix ); 1097 QPainter p( &pix );
790 p.drawRect( 0, 0, pix.width(), pix.height() ); 1098 p.drawRect( 0, 0, pix.width(), pix.height() );
791 p.end(); 1099 p.end();
792 drg->setPixmap( pix ); 1100 drg->setPixmap( pix );
793 mousePressed = FALSE; 1101 mousePressed = FALSE;
794 drg->dragCopy(); 1102 drg->dragCopy();
795 } 1103 }
796#endif 1104#endif
797} 1105}
798 1106
799#ifndef QT_NO_DRAGANDDROP 1107#ifndef QT_NO_DRAGANDDROP
800void QColorShowLabel::dragEnterEvent( QDragEnterEvent *e ) 1108void QColorShowLabel::dragEnterEvent( QDragEnterEvent *e )
801{ 1109{
802 if ( QColorDrag::canDecode( e ) ) 1110 if ( QColorDrag::canDecode( e ) )
803 e->accept(); 1111 e->accept();
804 else 1112 else
805 e->ignore(); 1113 e->ignore();
806} 1114}
807 1115
808void QColorShowLabel::dragLeaveEvent( QDragLeaveEvent * ) 1116void QColorShowLabel::dragLeaveEvent( QDragLeaveEvent * )
809{ 1117{
@@ -811,22 +1119,22 @@ void QColorShowLabel::dragLeaveEvent( QDragLeaveEvent * )
811 1119
812void QColorShowLabel::dropEvent( QDropEvent *e ) 1120void QColorShowLabel::dropEvent( QDropEvent *e )
813{ 1121{
814 if ( QColorDrag::canDecode( e ) ) { 1122 if ( QColorDrag::canDecode( e ) ) {
815 QColorDrag::decode( e, col ); 1123 QColorDrag::decode( e, col );
816 repaint( FALSE ); 1124 repaint( FALSE );
817 emit colorDropped( col.rgb() ); 1125 emit colorDropped( col.rgb() );
818 e->accept(); 1126 e->accept();
819 } else { 1127 } else {
820 e->ignore(); 1128 e->ignore();
821 } 1129 }
822} 1130}
823#endif // QT_NO_DRAGANDDROP 1131#endif // QT_NO_DRAGANDDROP
824 1132
825void QColorShowLabel::mouseReleaseEvent( QMouseEvent * ) 1133void QColorShowLabel::mouseReleaseEvent( QMouseEvent * )
826{ 1134{
827 if ( !mousePressed ) 1135 if ( !mousePressed )
828 return; 1136 return;
829 mousePressed = FALSE; 1137 mousePressed = FALSE;
830} 1138}
831 1139
832QColorShower::QColorShower( QWidget *parent, const char *name ) 1140QColorShower::QColorShower( QWidget *parent, const char *name )
@@ -840,11 +1148,11 @@ QColorShower::QColorShower( QWidget *parent, const char *name )
840 lab = new QColorShowLabel( this ); 1148 lab = new QColorShowLabel( this );
841 lab->setMinimumWidth( 60 ); //### 1149 lab->setMinimumWidth( 60 ); //###
842 gl->addMultiCellWidget(lab, 0,-1,0,0); 1150 gl->addMultiCellWidget(lab, 0,-1,0,0);
843 connect( lab, SIGNAL( colorDropped(QRgb) ), 1151 connect( lab, SIGNAL( colorDropped(QRgb) ),
844 this, SIGNAL( newCol(QRgb) ) ); 1152 this, SIGNAL( newCol(QRgb) ) );
845 connect( lab, SIGNAL( colorDropped(QRgb) ), 1153 connect( lab, SIGNAL( colorDropped(QRgb) ),
846 this, SLOT( setRgb(QRgb) ) ); 1154 this, SLOT( setRgb(QRgb) ) );
847 1155
848 hEd = new QColNumLineEdit( this ); 1156 hEd = new QColNumLineEdit( this );
849 hEd->setValidator( val360 ); 1157 hEd->setValidator( val360 );
850 QLabel *l = new QLabel( hEd, QColorDialog::tr("Hu&e:"), this ); 1158 QLabel *l = new QLabel( hEd, QColorDialog::tr("Hu&e:"), this );
@@ -977,8 +1285,37 @@ void QColorShower::setHsv( int h, int s, int v )
977 1285
978 showCurrentColor(); 1286 showCurrentColor();
979} 1287}
980 1288
1289class QColorDialogPrivate : public QObject
1290{
1291Q_OBJECT
1292public:
1293 QColorDialogPrivate( QColorDialog *p );
1294 QRgb currentColor() const { return cs->currentColor(); }
1295 void setCurrentColor( QRgb rgb );
1296
1297 int currentAlpha() const { return cs->currentAlpha(); }
1298 void setCurrentAlpha( int a ) { cs->setCurrentAlpha( a ); }
1299 void showAlpha( bool b ) { cs->showAlpha( b ); }
1300
1301private slots:
1302 void addCustom();
1303
1304 void newHsv( int h, int s, int v );
1305 void newColorTypedIn( QRgb rgb );
1306 void newCustom( int, int );
1307 void newStandard( int, int );
1308private:
1309 QColorPicker *cp;
1310 QColorLuminancePicker *lp;
1311 QWellArray *custom;
1312 QWellArray *standard;
1313 QColorShower *cs;
1314 int nextCust;
1315 bool compact;
1316};
1317
981//sets all widgets to display h,s,v 1318//sets all widgets to display h,s,v
982void QColorDialogPrivate::newHsv( int h, int s, int v ) 1319void QColorDialogPrivate::newHsv( int h, int s, int v )
983{ 1320{
984 cs->setHsv( h, s, v ); 1321 cs->setHsv( h, s, v );
@@ -1022,53 +1359,53 @@ QColorDialogPrivate::QColorDialogPrivate( QColorDialog *dialog ) :
1022 compact = FALSE; 1359 compact = FALSE;
1023 // small displays (e.g. PDAs cannot fit the full color dialog, 1360 // small displays (e.g. PDAs cannot fit the full color dialog,
1024 // so just use the color picker. 1361 // so just use the color picker.
1025 if ( qApp->desktop()->width() < 480 || qApp->desktop()->height() < 350 ) 1362 if ( qApp->desktop()->width() < 480 || qApp->desktop()->height() < 350 )
1026 compact = TRUE; 1363 compact = TRUE;
1027 1364
1028 nextCust = 0; 1365 nextCust = 0;
1029 const int lumSpace = 3; 1366 const int lumSpace = 3;
1030 int border = 12; 1367 int border = 12;
1031 if ( compact ) 1368 if ( compact )
1032 border = 6; 1369 border = 6;
1033 QHBoxLayout *topLay = new QHBoxLayout( dialog, border, 6 ); 1370 QHBoxLayout *topLay = new QHBoxLayout( dialog, border, 6 );
1034 QVBoxLayout *leftLay = 0; 1371 QVBoxLayout *leftLay = 0;
1035 1372
1036 if ( !compact ) 1373 if ( !compact )
1037 leftLay = new QVBoxLayout( topLay ); 1374 leftLay = new QVBoxLayout( topLay );
1038 1375
1039 initRGB(); 1376 initRGB();
1040 1377
1041 if ( !compact ) { 1378 if ( !compact ) {
1042 standard = new QColorWell( dialog, 6, 8, stdrgb ); 1379 standard = new QColorWell( dialog, 6, 8, stdrgb );
1043 standard->setCellSize( 28, 24 ); 1380 standard->setCellSize( 28, 24 );
1044 QLabel * lab = new QLabel( standard, 1381 QLabel * lab = new QLabel( standard,
1045 QColorDialog::tr( "&Basic colors"), dialog ); 1382 QColorDialog::tr( "&Basic colors"), dialog );
1046 connect( standard, SIGNAL(selected(int,int)), SLOT(newStandard(int,int))); 1383 connect( standard, SIGNAL(selected(int,int)), SLOT(newStandard(int,int)));
1047 leftLay->addWidget( lab ); 1384 leftLay->addWidget( lab );
1048 leftLay->addWidget( standard ); 1385 leftLay->addWidget( standard );
1049 1386
1050 1387
1051 leftLay->addStretch(); 1388 leftLay->addStretch();
1052 1389
1053 custom = new QColorWell( dialog, 2, 8, cusrgb ); 1390 custom = new QColorWell( dialog, 2, 8, cusrgb );
1054 custom->setCellSize( 28, 24 ); 1391 custom->setCellSize( 28, 24 );
1055 custom->setAcceptDrops( TRUE ); 1392 custom->setAcceptDrops( TRUE );
1056 1393
1057 connect( custom, SIGNAL(selected(int,int)), SLOT(newCustom(int,int))); 1394 connect( custom, SIGNAL(selected(int,int)), SLOT(newCustom(int,int)));
1058 lab = new QLabel( custom, QColorDialog::tr( "&Custom colors") , dialog ); 1395 lab = new QLabel( custom, QColorDialog::tr( "&Custom colors") , dialog );
1059 leftLay->addWidget( lab ); 1396 leftLay->addWidget( lab );
1060 leftLay->addWidget( custom ); 1397 leftLay->addWidget( custom );
1061 1398
1062 QPushButton *custbut = 1399 QPushButton *custbut =
1063 new QPushButton( QColorDialog::tr("&Define Custom Colors >>"), 1400 new QPushButton( QColorDialog::tr("&Define Custom Colors >>"),
1064 dialog ); 1401 dialog );
1065 custbut->setEnabled( FALSE ); 1402 custbut->setEnabled( FALSE );
1066 leftLay->addWidget( custbut ); 1403 leftLay->addWidget( custbut );
1067 } else { 1404 } else {
1068 // better color picker size for small displays 1405 // better color picker size for small displays
1069 pWidth = 150; 1406 pWidth = 150;
1070 pHeight = 100; 1407 pHeight = 100;
1071 } 1408 }
1072 1409
1073 QVBoxLayout *rightLay = new QVBoxLayout( topLay ); 1410 QVBoxLayout *rightLay = new QVBoxLayout( topLay );
1074 1411
@@ -1096,11 +1433,11 @@ QColorDialogPrivate::QColorDialogPrivate( QColorDialog *dialog ) :
1096 rightLay->addWidget( cs ); 1433 rightLay->addWidget( cs );
1097 1434
1098 QHBoxLayout *buttons; 1435 QHBoxLayout *buttons;
1099 if ( compact ) 1436 if ( compact )
1100 buttons = new QHBoxLayout( rightLay ); 1437 buttons = new QHBoxLayout( rightLay );
1101 else 1438 else
1102 buttons = new QHBoxLayout( leftLay ); 1439 buttons = new QHBoxLayout( leftLay );
1103 1440
1104 QPushButton *ok, *cancel; 1441 QPushButton *ok, *cancel;
1105 ok = new QPushButton( QColorDialog::tr("OK"), dialog ); 1442 ok = new QPushButton( QColorDialog::tr("OK"), dialog );
1106 connect( ok, SIGNAL(clicked()), dialog, SLOT(accept()) ); 1443 connect( ok, SIGNAL(clicked()), dialog, SLOT(accept()) );
@@ -1111,13 +1448,13 @@ QColorDialogPrivate::QColorDialogPrivate( QColorDialog *dialog ) :
1111 buttons->addWidget( cancel ); 1448 buttons->addWidget( cancel );
1112 buttons->addStretch(); 1449 buttons->addStretch();
1113 1450
1114 if ( !compact ) { 1451 if ( !compact ) {
1115 QPushButton *addCusBt = new QPushButton( 1452 QPushButton *addCusBt = new QPushButton(
1116 QColorDialog::tr("&Add To Custom Colors"), 1453 QColorDialog::tr("&Add To Custom Colors"),
1117 dialog ); 1454 dialog );
1118 rightLay->addWidget( addCusBt ); 1455 rightLay->addWidget( addCusBt );
1119 connect( addCusBt, SIGNAL(clicked()), this, SLOT(addCustom()) ); 1456 connect( addCusBt, SIGNAL(clicked()), this, SLOT(addCustom()) );
1120 } 1457 }
1121} 1458}
1122 1459
1123void QColorDialogPrivate::addCustom() 1460void QColorDialogPrivate::addCustom()
@@ -1172,24 +1509,24 @@ QColorDialog::QColorDialog(QWidget* parent, const char* name, bool modal) :
1172 before this function returns. 1509 before this function returns.
1173*/ 1510*/
1174 1511
1175QColor QColorDialog::getColor( QColor initial, QWidget *parent, 1512QColor QColorDialog::getColor( QColor initial, QWidget *parent,
1176 const char *name ) 1513 const char *name )
1177{ 1514{
1178 int allocContext = QColor::enterAllocContext(); 1515 int allocContext = QColor::enterAllocContext();
1179 QColorDialog *dlg = new QColorDialog( parent, name, TRUE ); //modal 1516 QColorDialog *dlg = new QColorDialog( parent, name, TRUE ); //modal
1180 if ( parent && parent->icon() && !parent->icon()->isNull() ) 1517 if ( parent && parent->icon() && !parent->icon()->isNull() )
1181 dlg->setIcon( *parent->icon() ); 1518 dlg->setIcon( *parent->icon() );
1182 else if ( qApp->mainWidget() && qApp->mainWidget()->icon() && !qApp->mainWidget()->icon()->isNull() ) 1519 else if ( qApp->mainWidget() && qApp->mainWidget()->icon() && !qApp->mainWidget()->icon()->isNull() )
1183 dlg->setIcon( *qApp->mainWidget()->icon() ); 1520 dlg->setIcon( *qApp->mainWidget()->icon() );
1184 1521
1185 dlg->setCaption( QColorDialog::tr( "Select color" ) ); 1522 dlg->setCaption( QColorDialog::tr( "Select color" ) );
1186 dlg->setColor( initial ); 1523 dlg->setColor( initial );
1187 int resultCode = dlg->exec(); 1524 int resultCode = dlg->exec();
1188 QColor::leaveAllocContext(); 1525 QColor::leaveAllocContext();
1189 QColor result; 1526 QColor result;
1190 if ( resultCode == QDialog::Accepted ) 1527 if ( resultCode == QDialog::Accepted )
1191 result = dlg->color(); 1528 result = dlg->color();
1192 QColor::destroyAllocContext(allocContext); 1529 QColor::destroyAllocContext(allocContext);
1193 delete dlg; 1530 delete dlg;
1194 return result; 1531 return result;
1195} 1532}
@@ -1205,9 +1542,9 @@ QColor QColorDialog::getColor( QColor initial, QWidget *parent,
1205 If the user clicks Cancel the \a initial value is returned. 1542 If the user clicks Cancel the \a initial value is returned.
1206*/ 1543*/
1207 1544
1208QRgb QColorDialog::getRgba( QRgb initial, bool *ok, 1545QRgb QColorDialog::getRgba( QRgb initial, bool *ok,
1209 QWidget *parent, const char* name ) 1546 QWidget *parent, const char* name )
1210{ 1547{
1211 int allocContext = QColor::enterAllocContext(); 1548 int allocContext = QColor::enterAllocContext();
1212 QColorDialog *dlg = new QColorDialog( parent, name, TRUE ); //modal 1549 QColorDialog *dlg = new QColorDialog( parent, name, TRUE ); //modal
1213 dlg->setColor( initial ); 1550 dlg->setColor( initial );
@@ -1215,14 +1552,14 @@ QRgb QColorDialog::getRgba( QRgb initial, bool *ok,
1215 int resultCode = dlg->exec(); 1552 int resultCode = dlg->exec();
1216 QColor::leaveAllocContext(); 1553 QColor::leaveAllocContext();
1217 QRgb result = initial; 1554 QRgb result = initial;
1218 if ( resultCode == QDialog::Accepted ) { 1555 if ( resultCode == QDialog::Accepted ) {
1219 QRgb c = dlg->color().rgb(); 1556 QRgb c = dlg->color().rgb();
1220 int alpha = dlg->selectedAlpha(); 1557 int alpha = dlg->selectedAlpha();
1221 result = qRgba( qRed(c), qGreen(c), qBlue(c), alpha ); 1558 result = qRgba( qRed(c), qGreen(c), qBlue(c), alpha );
1222 } 1559 }
1223 if ( ok ) 1560 if ( ok )
1224 *ok = resultCode == QDialog::Accepted; 1561 *ok = resultCode == QDialog::Accepted;
1225 1562
1226 QColor::destroyAllocContext(allocContext); 1563 QColor::destroyAllocContext(allocContext);
1227 delete dlg; 1564 delete dlg;
1228 return result; 1565 return result;
@@ -1289,4 +1626,5 @@ int QColorDialog::selectedAlpha() const
1289 return d->currentAlpha(); 1626 return d->currentAlpha();
1290} 1627}
1291 1628
1292 1629
1630#include "qcolordialog.moc" \ No newline at end of file
diff --git a/libqtaux/qcolordialog.h b/libqtaux/qcolordialog.h
index 50c6482..89c6283 100644
--- a/libqtaux/qcolordialog.h
+++ b/libqtaux/qcolordialog.h
@@ -41,290 +41,8 @@
41#ifndef QT_H 41#ifndef QT_H
42#include <qdialog.h> 42#include <qdialog.h>
43#endif // QT_H 43#endif // QT_H
44 44
45#include <qlabel.h>
46#include <qlineedit.h>
47#include <qtableview.h>
48#include <qvalidator.h>
49
50struct QWellArrayData;
51
52class QWellArray : public QTableView
53{
54 Q_OBJECT
55// Q_PROPERTY( int numCols READ numCols )
56// Q_PROPERTY( int numRows READ numRows )
57// Q_PROPERTY( int selectedColumn READ selectedColumn )
58// Q_PROPERTY( int selectedRow READ selectedRow )
59
60public:
61 QWellArray( QWidget *parent=0, const char *name=0, bool popup = FALSE );
62
63 ~QWellArray() {}
64 QString cellContent( int row, int col ) const;
65 // ### Paul !!! virtual void setCellContent( int row, int col, const QString &);
66
67 // ##### Obsolete since not const
68 int numCols() { return nCols; }
69 int numRows() { return nRows; }
70
71 int numCols() const { return nCols; }
72 int numRows() const { return nRows; }
73
74 // ##### Obsolete since not const
75 int selectedColumn() { return selCol; }
76 int selectedRow() { return selRow; }
77
78 int selectedColumn() const { return selCol; }
79 int selectedRow() const { return selRow; }
80
81 virtual void setSelected( int row, int col );
82
83 void setCellSize( int w, int h ) { setCellWidth(w);setCellHeight( h ); }
84
85 QSize sizeHint() const;
86
87 virtual void setDimension( int rows, int cols );
88 virtual void setCellBrush( int row, int col, const QBrush & );
89 QBrush cellBrush( int row, int col );
90
91signals:
92 void selected( int row, int col );
93
94protected:
95 virtual void setCurrent( int row, int col );
96
97 virtual void drawContents( QPainter *, int row, int col, const QRect& );
98 void drawContents( QPainter * );
99
100 void paintCell( QPainter*, int row, int col );
101 void mousePressEvent( QMouseEvent* );
102 void mouseReleaseEvent( QMouseEvent* );
103 void mouseMoveEvent( QMouseEvent* );
104 void keyPressEvent( QKeyEvent* );
105 void focusInEvent( QFocusEvent* );
106 void focusOutEvent( QFocusEvent* );
107
108private:
109 int curRow;
110 int curCol;
111 int selRow;
112 int selCol;
113 int nCols;
114 int nRows;
115 bool smallStyle;
116 QWellArrayData *d;
117
118private: // Disabled copy constructor and operator=
119#if defined(Q_DISABLE_COPY)
120 QWellArray( const QWellArray & );
121 QWellArray& operator=( const QWellArray & );
122#endif
123};
124
125struct QWellArrayData {
126 QBrush *brush;
127};
128
129class QColNumLineEdit : public QLineEdit
130{
131public:
132 QColNumLineEdit( QWidget *parent, const char* name = 0 )
133 : QLineEdit( parent, name ) { setMaxLength( 3 );}
134 QSize sizeHint() const {
135 return QSize( 30, //#####
136 QLineEdit::sizeHint().height() ); }
137 void setNum( int i ) {
138 QString s;
139 s.setNum(i);
140 bool block = signalsBlocked();
141 blockSignals(TRUE);
142 setText( s );
143 blockSignals(block);
144 }
145 int val() const { return text().toInt(); }
146};
147
148class QColorShowLabel : public QFrame
149{
150 Q_OBJECT
151
152public:
153 QColorShowLabel( QWidget *parent ) :QFrame( parent ) {
154 setFrameStyle( QFrame::Panel|QFrame::Sunken );
155 setBackgroundMode( PaletteBackground );
156 setAcceptDrops( TRUE );
157 mousePressed = FALSE;
158 }
159 void setColor( QColor c ) { col = c; }
160
161signals:
162 void colorDropped( QRgb );
163
164protected:
165 void drawContents( QPainter *p );
166 void mousePressEvent( QMouseEvent *e );
167 void mouseMoveEvent( QMouseEvent *e );
168 void mouseReleaseEvent( QMouseEvent *e );
169#ifndef QT_NO_DRAGANDDROP
170 void dragEnterEvent( QDragEnterEvent *e );
171 void dragLeaveEvent( QDragLeaveEvent *e );
172 void dropEvent( QDropEvent *e );
173#endif
174
175private:
176 QColor col;
177 bool mousePressed;
178 QPoint pressPos;
179
180};
181
182class QColorShower : public QWidget
183{
184 Q_OBJECT
185public:
186 QColorShower( QWidget *parent, const char *name = 0 );
187
188 //things that don't emit signals
189 void setHsv( int h, int s, int v );
190
191 int currentAlpha() const { return alphaEd->val(); }
192 void setCurrentAlpha( int a ) { alphaEd->setNum( a ); }
193 void showAlpha( bool b );
194
195
196 QRgb currentColor() const { return curCol; }
197
198public slots:
199 void setRgb( QRgb rgb );
200
201signals:
202 void newCol( QRgb rgb );
203private slots:
204 void rgbEd();
205 void hsvEd();
206private:
207 void showCurrentColor();
208 int hue, sat, val;
209 QRgb curCol;
210 QColNumLineEdit *hEd;
211 QColNumLineEdit *sEd;
212 QColNumLineEdit *vEd;
213 QColNumLineEdit *rEd;
214 QColNumLineEdit *gEd;
215 QColNumLineEdit *bEd;
216 QColNumLineEdit *alphaEd;
217 QLabel *alphaLab;
218 QColorShowLabel *lab;
219 bool rgbOriginal;
220};
221
222class QColorPicker : public QFrame
223{
224 Q_OBJECT
225public:
226 QColorPicker(QWidget* parent=0, const char* name=0);
227 ~QColorPicker();
228
229public slots:
230 void setCol( int h, int s );
231
232signals:
233 void newCol( int h, int s );
234
235protected:
236 QSize sizeHint() const;
237 QSizePolicy sizePolicy() const;
238 void drawContents(QPainter* p);
239 void mouseMoveEvent( QMouseEvent * );
240 void mousePressEvent( QMouseEvent * );
241
242private:
243 int hue;
244 int sat;
245
246 QPoint colPt();
247 int huePt( const QPoint &pt );
248 int satPt( const QPoint &pt );
249 void setCol( const QPoint &pt );
250
251 QPixmap *pix;
252};
253
254class QColorLuminancePicker : public QWidget
255{
256 Q_OBJECT
257public:
258 QColorLuminancePicker(QWidget* parent=0, const char* name=0);
259 ~QColorLuminancePicker();
260
261public slots:
262 void setCol( int h, int s, int v );
263 void setCol( int h, int s );
264
265signals:
266 void newHsv( int h, int s, int v );
267
268protected:
269// QSize sizeHint() const;
270// QSizePolicy sizePolicy() const;
271 void paintEvent( QPaintEvent*);
272 void mouseMoveEvent( QMouseEvent * );
273 void mousePressEvent( QMouseEvent * );
274
275private:
276 enum { foff = 3, coff = 4 }; //frame and contents offset
277 int val;
278 int hue;
279 int sat;
280
281 int y2val( int y );
282 int val2y( int val );
283 void setVal( int v );
284
285 QPixmap *pix;
286};
287
288class QColorWell : public QWellArray
289{
290public:
291 QColorWell( QWidget *parent, int r, int c, QRgb *vals )
292 :QWellArray( parent, "" ), values( vals ), mousePressed( FALSE ), oldCurrent( -1, -1 )
293 { setDimension(r,c); setWFlags( WResizeNoErase ); }
294 QSizePolicy sizePolicy() const;
295
296protected:
297 void drawContents( QPainter *, int row, int col, const QRect& );
298 void drawContents( QPainter *p ) { QWellArray::drawContents(p); }
299 void mousePressEvent( QMouseEvent *e );
300 void mouseMoveEvent( QMouseEvent *e );
301 void mouseReleaseEvent( QMouseEvent *e );
302#ifndef QT_NO_DRAGANDDROP
303 void dragEnterEvent( QDragEnterEvent *e );
304 void dragLeaveEvent( QDragLeaveEvent *e );
305 void dragMoveEvent( QDragMoveEvent *e );
306 void dropEvent( QDropEvent *e );
307#endif
308
309private:
310 QRgb *values;
311 bool mousePressed;
312 QPoint pressPos;
313 QPoint oldCurrent;
314
315};
316
317class QColIntValidator: public QIntValidator
318{
319public:
320 QColIntValidator( int bottom, int top,
321 QWidget * parent, const char *name = 0 )
322 :QIntValidator( bottom, top, parent, name ) {}
323
324 QValidator::State validate( QString &, int & ) const;
325};
326
327class QColorDialogPrivate; 45class QColorDialogPrivate;
328 46
329class Q_EXPORT QColorDialog : public QDialog 47class Q_EXPORT QColorDialog : public QDialog
330{ 48{
@@ -332,9 +50,9 @@ class Q_EXPORT QColorDialog : public QDialog
332 50
333public: 51public:
334 static QColor getColor( QColor, QWidget *parent=0, const char* name=0 ); // ### 3.0: make const QColor& 52 static QColor getColor( QColor, QWidget *parent=0, const char* name=0 ); // ### 3.0: make const QColor&
335 static QRgb getRgba( QRgb, bool* ok = 0, 53 static QRgb getRgba( QRgb, bool* ok = 0,
336 QWidget *parent=0, const char* name=0 ); 54 QWidget *parent=0, const char* name=0 );
337 55
338 56
339 static int customCount(); 57 static int customCount();
340 static QRgb customColor( int ); 58 static QRgb customColor( int );
@@ -355,41 +73,12 @@ private:
355private: 73private:
356 QColorDialogPrivate *d; 74 QColorDialogPrivate *d;
357 friend class QColorDialogPrivate; 75 friend class QColorDialogPrivate;
358 76
359private: // Disabled copy constructor and operator= 77 private:// Disabled copy constructor and operator=
360#if defined(Q_DISABLE_COPY) 78#if defined(Q_DISABLE_COPY)
361 QColorDialog( const QColorDialog & ); 79 QColorDialog( const QColorDialog & );
362 QColorDialog& operator=( const QColorDialog & ); 80 QColorDialog& operator=( const QColorDialog & );
363#endif 81#endif
364}; 82};
365 83
366class QColorDialogPrivate : public QObject
367{
368Q_OBJECT
369public:
370 QColorDialogPrivate( QColorDialog *p );
371 QRgb currentColor() const { return cs->currentColor(); }
372 void setCurrentColor( QRgb rgb );
373
374 int currentAlpha() const { return cs->currentAlpha(); }
375 void setCurrentAlpha( int a ) { cs->setCurrentAlpha( a ); }
376 void showAlpha( bool b ) { cs->showAlpha( b ); }
377
378private slots:
379 void addCustom();
380
381 void newHsv( int h, int s, int v );
382 void newColorTypedIn( QRgb rgb );
383 void newCustom( int, int );
384 void newStandard( int, int );
385private:
386 QColorPicker *cp;
387 QColorLuminancePicker *lp;
388 QWellArray *custom;
389 QWellArray *standard;
390 QColorShower *cs;
391 int nextCust;
392 bool compact;
393};
394
395#endif 84#endif