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