author | zecke <zecke> | 2004-09-10 11:07:29 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-09-10 11:07:29 (UTC) |
commit | 0c2d61cebde30e1a6eea86beb5b28a3600de0f75 (patch) (unidiff) | |
tree | 1b1e4b2fc09f92c08254a285d3a89d82b9174cb9 | |
parent | 00b7879d0d886b642b1f1102e3a811e67f928df7 (diff) | |
download | opie-0c2d61cebde30e1a6eea86beb5b28a3600de0f75.zip opie-0c2d61cebde30e1a6eea86beb5b28a3600de0f75.tar.gz opie-0c2d61cebde30e1a6eea86beb5b28a3600de0f75.tar.bz2 |
No unused parameters, added a newline at the end
-rw-r--r-- | libqtaux/qcolordialog.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/libqtaux/qcolordialog.cpp b/libqtaux/qcolordialog.cpp index ccef0ad..830fef6 100644 --- a/libqtaux/qcolordialog.cpp +++ b/libqtaux/qcolordialog.cpp | |||
@@ -159,1474 +159,1476 @@ struct QWellArrayData { | |||
159 | // NOT REVISED | 159 | // NOT REVISED |
160 | /* WARNING, NOT | 160 | /* WARNING, NOT |
161 | \class QWellArray qwellarray_p.h | 161 | \class QWellArray qwellarray_p.h |
162 | \brief .... | 162 | \brief .... |
163 | 163 | ||
164 | .... | 164 | .... |
165 | 165 | ||
166 | \ingroup advanced | 166 | \ingroup advanced |
167 | */ | 167 | */ |
168 | 168 | ||
169 | QWellArray::QWellArray( QWidget *parent, const char * name, bool popup ) | 169 | QWellArray::QWellArray( QWidget *parent, const char * name, bool popup ) |
170 | : QTableView( parent, name, | 170 | : QTableView( parent, name, |
171 | popup ? (WStyle_Customize|WStyle_Tool|WStyle_NoBorder) : 0 ) | 171 | popup ? (WStyle_Customize|WStyle_Tool|WStyle_NoBorder) : 0 ) |
172 | { | 172 | { |
173 | d = 0; | 173 | d = 0; |
174 | setFocusPolicy( StrongFocus ); | 174 | setFocusPolicy( StrongFocus ); |
175 | setBackgroundMode( PaletteButton ); | 175 | setBackgroundMode( PaletteButton ); |
176 | nCols = 7; | 176 | nCols = 7; |
177 | nRows = 7; | 177 | nRows = 7; |
178 | int w = 24; // cell width | 178 | int w = 24; // cell width |
179 | int h = 21; // cell height | 179 | int h = 21; // cell height |
180 | smallStyle = popup; | 180 | smallStyle = popup; |
181 | 181 | ||
182 | if ( popup ) { | 182 | if ( popup ) { |
183 | w = h = 18; | 183 | w = h = 18; |
184 | if ( style() == WindowsStyle ) | 184 | if ( style() == WindowsStyle ) |
185 | setFrameStyle( QFrame::WinPanel | QFrame::Raised ); | 185 | setFrameStyle( QFrame::WinPanel | QFrame::Raised ); |
186 | else | 186 | else |
187 | setFrameStyle( QFrame::Panel | QFrame::Raised ); | 187 | setFrameStyle( QFrame::Panel | QFrame::Raised ); |
188 | setMargin( 1 ); | 188 | setMargin( 1 ); |
189 | setLineWidth( 2 ); | 189 | setLineWidth( 2 ); |
190 | } | 190 | } |
191 | setNumCols( nCols ); | 191 | setNumCols( nCols ); |
192 | setNumRows( nRows ); | 192 | setNumRows( nRows ); |
193 | setCellWidth( w ); | 193 | setCellWidth( w ); |
194 | setCellHeight( h ); | 194 | setCellHeight( h ); |
195 | curCol = 0; | 195 | curCol = 0; |
196 | curRow = 0; | 196 | curRow = 0; |
197 | selCol = -1; | 197 | selCol = -1; |
198 | selRow = -1; | 198 | selRow = -1; |
199 | 199 | ||
200 | if ( smallStyle ) | 200 | if ( smallStyle ) |
201 | setMouseTracking( TRUE ); | 201 | setMouseTracking( TRUE ); |
202 | setOffset( 5 , 10 ); | 202 | setOffset( 5 , 10 ); |
203 | 203 | ||
204 | resize( sizeHint() ); | 204 | resize( sizeHint() ); |
205 | 205 | ||
206 | } | 206 | } |
207 | 207 | ||
208 | 208 | ||
209 | QSize QWellArray::sizeHint() const | 209 | QSize QWellArray::sizeHint() const |
210 | { | 210 | { |
211 | constPolish(); | 211 | constPolish(); |
212 | int f = frameWidth() * 2; | 212 | int f = frameWidth() * 2; |
213 | int w = nCols * cellWidth() + f; | 213 | int w = nCols * cellWidth() + f; |
214 | int h = nRows * cellHeight() + f; | 214 | int h = nRows * cellHeight() + f; |
215 | return QSize( w, h ); | 215 | return QSize( w, h ); |
216 | } | 216 | } |
217 | 217 | ||
218 | 218 | ||
219 | void QWellArray::paintCell( QPainter* p, int row, int col ) | 219 | void QWellArray::paintCell( QPainter* p, int row, int col ) |
220 | { | 220 | { |
221 | int w = cellWidth( col ); // width of cell in pixels | 221 | int w = cellWidth( col ); // width of cell in pixels |
222 | int h = cellHeight( row ); // height of cell in pixels | 222 | int h = cellHeight( row ); // height of cell in pixels |
223 | int b = 1; | 223 | int b = 1; |
224 | 224 | ||
225 | if ( !smallStyle ) | 225 | if ( !smallStyle ) |
226 | b = 3; | 226 | b = 3; |
227 | 227 | ||
228 | const QColorGroup & g = colorGroup(); | 228 | const QColorGroup & g = colorGroup(); |
229 | p->setPen( QPen( black, 0, SolidLine ) ); | 229 | p->setPen( QPen( black, 0, SolidLine ) ); |
230 | if ( !smallStyle && row ==selRow && col == selCol && | 230 | if ( !smallStyle && row ==selRow && col == selCol && |
231 | style() != MotifStyle ) { | 231 | style() != MotifStyle ) { |
232 | int n = 2; | 232 | int n = 2; |
233 | p->drawRect( n, n, w-2*n, h-2*n ); | 233 | p->drawRect( n, n, w-2*n, h-2*n ); |
234 | } | 234 | } |
235 | 235 | ||
236 | 236 | ||
237 | if ( style() == WindowsStyle ) { | 237 | if ( style() == WindowsStyle ) { |
238 | qDrawWinPanel( p, b, b , w - 2*b, h - 2*b, | 238 | qDrawWinPanel( p, b, b , w - 2*b, h - 2*b, |
239 | g, TRUE ); | 239 | g, TRUE ); |
240 | b += 2; | 240 | b += 2; |
241 | } else { | 241 | } else { |
242 | if ( smallStyle ) { | 242 | if ( smallStyle ) { |
243 | qDrawShadePanel( p, b, b , w - 2*b, h - 2*b, | 243 | qDrawShadePanel( p, b, b , w - 2*b, h - 2*b, |
244 | g, TRUE, 2 ); | 244 | g, TRUE, 2 ); |
245 | b += 2; | 245 | b += 2; |
246 | } else { | 246 | } else { |
247 | int t = ( row == selRow && col == selCol ) ? 2 : 0; | 247 | int t = ( row == selRow && col == selCol ) ? 2 : 0; |
248 | b -= t; | 248 | b -= t; |
249 | qDrawShadePanel( p, b, b , w - 2*b, h - 2*b, | 249 | qDrawShadePanel( p, b, b , w - 2*b, h - 2*b, |
250 | g, TRUE, 2 ); | 250 | g, TRUE, 2 ); |
251 | b += 2 + t; | 251 | b += 2 + t; |
252 | } | 252 | } |
253 | } | 253 | } |
254 | 254 | ||
255 | 255 | ||
256 | if ( (row == curRow) && (col == curCol) ) { | 256 | if ( (row == curRow) && (col == curCol) ) { |
257 | if ( smallStyle ) { | 257 | if ( smallStyle ) { |
258 | p->setPen ( white ); | 258 | p->setPen ( white ); |
259 | p->drawRect( 1, 1, w-2, h-2 ); | 259 | p->drawRect( 1, 1, w-2, h-2 ); |
260 | p->setPen ( black ); | 260 | p->setPen ( black ); |
261 | p->drawRect( 0, 0, w, h ); | 261 | p->drawRect( 0, 0, w, h ); |
262 | p->drawRect( 2, 2, w-4, h-4 ); | 262 | p->drawRect( 2, 2, w-4, h-4 ); |
263 | b = 3; | 263 | b = 3; |
264 | } else if ( hasFocus() ) { | 264 | } else if ( hasFocus() ) { |
265 | style().drawFocusRect(p, QRect(0,0,w,h), g ); | 265 | style().drawFocusRect(p, QRect(0,0,w,h), g ); |
266 | } | 266 | } |
267 | } | 267 | } |
268 | drawContents( p, row, col, QRect(b, b, w - 2*b, h - 2*b) ); | 268 | drawContents( p, row, col, QRect(b, b, w - 2*b, h - 2*b) ); |
269 | } | 269 | } |
270 | 270 | ||
271 | /*! | 271 | /*! |
272 | Pass-through to QTableView::drawContents() to avoid hiding. | 272 | Pass-through to QTableView::drawContents() to avoid hiding. |
273 | */ | 273 | */ |
274 | void QWellArray::drawContents( QPainter *p ) | 274 | void QWellArray::drawContents( QPainter *p ) |
275 | { | 275 | { |
276 | QTableView::drawContents(p); | 276 | QTableView::drawContents(p); |
277 | } | 277 | } |
278 | 278 | ||
279 | /*! | 279 | /*! |
280 | Reimplement this function to change the contents of the well array. | 280 | Reimplement this function to change the contents of the well array. |
281 | */ | 281 | */ |
282 | void QWellArray::drawContents( QPainter *p, int row, int col, const QRect &r ) | 282 | void QWellArray::drawContents( QPainter *p, int row, int col, const QRect &r ) |
283 | { | 283 | { |
284 | 284 | ||
285 | if ( d ) { | 285 | if ( d ) { |
286 | p->fillRect( r, d->brush[row*nCols+col] ); | 286 | p->fillRect( r, d->brush[row*nCols+col] ); |
287 | } else { | 287 | } else { |
288 | p->fillRect( r, white ); | 288 | p->fillRect( r, white ); |
289 | p->setPen( black ); | 289 | p->setPen( black ); |
290 | p->drawLine( r.topLeft(), r.bottomRight() ); | 290 | p->drawLine( r.topLeft(), r.bottomRight() ); |
291 | p->drawLine( r.topRight(), r.bottomLeft() ); | 291 | p->drawLine( r.topRight(), r.bottomLeft() ); |
292 | } | 292 | } |
293 | } | 293 | } |
294 | 294 | ||
295 | 295 | ||
296 | /*\reimp | 296 | /*\reimp |
297 | */ | 297 | */ |
298 | void QWellArray::mousePressEvent( QMouseEvent* e ) | 298 | void QWellArray::mousePressEvent( QMouseEvent* e ) |
299 | { | 299 | { |
300 | // The current cell marker is set to the cell the mouse is pressed | 300 | // The current cell marker is set to the cell the mouse is pressed |
301 | // in. | 301 | // in. |
302 | QPoint pos = e->pos(); | 302 | QPoint pos = e->pos(); |
303 | setCurrent( findRow( pos.y() ), findCol( pos.x() ) ); | 303 | setCurrent( findRow( pos.y() ), findCol( pos.x() ) ); |
304 | } | 304 | } |
305 | 305 | ||
306 | /*\reimp | 306 | /*\reimp |
307 | */ | 307 | */ |
308 | void QWellArray::mouseReleaseEvent( QMouseEvent* ) | 308 | void QWellArray::mouseReleaseEvent( QMouseEvent* ) |
309 | { | 309 | { |
310 | // The current cell marker is set to the cell the mouse is clicked | 310 | // The current cell marker is set to the cell the mouse is clicked |
311 | // in. | 311 | // in. |
312 | setSelected( curRow, curCol ); | 312 | setSelected( curRow, curCol ); |
313 | } | 313 | } |
314 | 314 | ||
315 | 315 | ||
316 | /*\reimp | 316 | /*\reimp |
317 | */ | 317 | */ |
318 | void QWellArray::mouseMoveEvent( QMouseEvent* e ) | 318 | void QWellArray::mouseMoveEvent( QMouseEvent* e ) |
319 | { | 319 | { |
320 | // The current cell marker is set to the cell the mouse is | 320 | // The current cell marker is set to the cell the mouse is |
321 | // clicked in. | 321 | // clicked in. |
322 | if ( smallStyle ) { | 322 | if ( smallStyle ) { |
323 | QPoint pos = e->pos(); | 323 | QPoint pos = e->pos(); |
324 | setCurrent( findRow( pos.y() ), findCol( pos.x() ) ); | 324 | setCurrent( findRow( pos.y() ), findCol( pos.x() ) ); |
325 | } | 325 | } |
326 | } | 326 | } |
327 | 327 | ||
328 | /* | 328 | /* |
329 | Sets the cell currently having the focus. This is not necessarily | 329 | Sets the cell currently having the focus. This is not necessarily |
330 | the same as the currently selected cell. | 330 | the same as the currently selected cell. |
331 | */ | 331 | */ |
332 | 332 | ||
333 | void QWellArray::setCurrent( int row, int col ) | 333 | void QWellArray::setCurrent( int row, int col ) |
334 | { | 334 | { |
335 | 335 | ||
336 | if ( (curRow == row) && (curCol == col) ) | 336 | if ( (curRow == row) && (curCol == col) ) |
337 | return; | 337 | return; |
338 | 338 | ||
339 | if ( row < 0 || col < 0 ) | 339 | if ( row < 0 || col < 0 ) |
340 | row = col = -1; | 340 | row = col = -1; |
341 | 341 | ||
342 | int oldRow = curRow; | 342 | int oldRow = curRow; |
343 | int oldCol = curCol; | 343 | int oldCol = curCol; |
344 | 344 | ||
345 | curRow = row; | 345 | curRow = row; |
346 | curCol = col; | 346 | curCol = col; |
347 | 347 | ||
348 | updateCell( oldRow, oldCol ); | 348 | updateCell( oldRow, oldCol ); |
349 | updateCell( curRow, curCol ); | 349 | updateCell( curRow, curCol ); |
350 | } | 350 | } |
351 | 351 | ||
352 | 352 | ||
353 | /*! | 353 | /*! |
354 | Sets the currently selected cell to \a row, \a col. If \a row or \a | 354 | Sets the currently selected cell to \a row, \a col. If \a row or \a |
355 | col are less than zero, the current cell is unselected. | 355 | col are less than zero, the current cell is unselected. |
356 | 356 | ||
357 | Does not set the position of the focus indicator. | 357 | Does not set the position of the focus indicator. |
358 | */ | 358 | */ |
359 | 359 | ||
360 | void QWellArray::setSelected( int row, int col ) | 360 | void QWellArray::setSelected( int row, int col ) |
361 | { | 361 | { |
362 | if ( (selRow == row) && (selCol == col) ) | 362 | if ( (selRow == row) && (selCol == col) ) |
363 | return; | 363 | return; |
364 | 364 | ||
365 | int oldRow = selRow; | 365 | int oldRow = selRow; |
366 | int oldCol = selCol; | 366 | int oldCol = selCol; |
367 | 367 | ||
368 | if ( row < 0 || col < 0 ) | 368 | if ( row < 0 || col < 0 ) |
369 | row = col = -1; | 369 | row = col = -1; |
370 | 370 | ||
371 | selCol = col; | 371 | selCol = col; |
372 | selRow = row; | 372 | selRow = row; |
373 | 373 | ||
374 | updateCell( oldRow, oldCol ); | 374 | updateCell( oldRow, oldCol ); |
375 | updateCell( selRow, selCol ); | 375 | updateCell( selRow, selCol ); |
376 | if ( row >= 0 ) | 376 | if ( row >= 0 ) |
377 | emit selected( row, col ); | 377 | emit selected( row, col ); |
378 | 378 | ||
379 | if ( isVisible() && parentWidget() && parentWidget()->inherits("QPopupMenu") ) | 379 | if ( isVisible() && parentWidget() && parentWidget()->inherits("QPopupMenu") ) |
380 | parentWidget()->close(); | 380 | parentWidget()->close(); |
381 | 381 | ||
382 | } | 382 | } |
383 | 383 | ||
384 | 384 | ||
385 | 385 | ||
386 | /*!\reimp | 386 | /*!\reimp |
387 | */ | 387 | */ |
388 | void QWellArray::focusInEvent( QFocusEvent* ) | 388 | void QWellArray::focusInEvent( QFocusEvent* ) |
389 | { | 389 | { |
390 | updateCell( curRow, curCol ); | 390 | updateCell( curRow, curCol ); |
391 | } | 391 | } |
392 | 392 | ||
393 | 393 | ||
394 | /*! | 394 | /*! |
395 | Sets the size of the well array to be \c rows cells by \c cols. | 395 | Sets the size of the well array to be \c rows cells by \c cols. |
396 | Resets any brush info set by setCellBrush(). | 396 | Resets any brush info set by setCellBrush(). |
397 | 397 | ||
398 | Must be called by reimplementors. | 398 | Must be called by reimplementors. |
399 | */ | 399 | */ |
400 | void QWellArray::setDimension( int rows, int cols ) | 400 | void QWellArray::setDimension( int rows, int cols ) |
401 | { | 401 | { |
402 | nRows = rows; | 402 | nRows = rows; |
403 | nCols = cols; | 403 | nCols = cols; |
404 | if ( d ) { | 404 | if ( d ) { |
405 | if ( d->brush ) | 405 | if ( d->brush ) |
406 | delete[] d->brush; | 406 | delete[] d->brush; |
407 | delete d; | 407 | delete d; |
408 | d = 0; | 408 | d = 0; |
409 | } | 409 | } |
410 | setNumCols( nCols ); | 410 | setNumCols( nCols ); |
411 | setNumRows( nRows ); | 411 | setNumRows( nRows ); |
412 | } | 412 | } |
413 | 413 | ||
414 | void QWellArray::setCellBrush( int row, int col, const QBrush &b ) | 414 | void QWellArray::setCellBrush( int row, int col, const QBrush &b ) |
415 | { | 415 | { |
416 | if ( !d ) { | 416 | if ( !d ) { |
417 | d = new QWellArrayData; | 417 | d = new QWellArrayData; |
418 | d->brush = new QBrush[nRows*nCols]; | 418 | d->brush = new QBrush[nRows*nCols]; |
419 | } | 419 | } |
420 | if ( row >= 0 && row < nRows && col >= 0 && col < nCols ) | 420 | if ( row >= 0 && row < nRows && col >= 0 && col < nCols ) |
421 | d->brush[row*nCols+col] = b; | 421 | d->brush[row*nCols+col] = b; |
422 | #ifdef CHECK_RANGE | 422 | #ifdef CHECK_RANGE |
423 | else | 423 | else |
424 | qWarning( "QWellArray::setCellBrush( %d, %d ) out of range", row, col ); | 424 | qWarning( "QWellArray::setCellBrush( %d, %d ) out of range", row, col ); |
425 | #endif | 425 | #endif |
426 | } | 426 | } |
427 | 427 | ||
428 | 428 | ||
429 | 429 | ||
430 | /*! | 430 | /*! |
431 | Returns the brush set for the cell at \a row, \a col. If no brush is set, | 431 | Returns the brush set for the cell at \a row, \a col. If no brush is set, |
432 | \c NoBrush is returned. | 432 | \c NoBrush is returned. |
433 | */ | 433 | */ |
434 | 434 | ||
435 | QBrush QWellArray::cellBrush( int row, int col ) | 435 | QBrush QWellArray::cellBrush( int row, int col ) |
436 | { | 436 | { |
437 | if ( d && row >= 0 && row < nRows && col >= 0 && col < nCols ) | 437 | if ( d && row >= 0 && row < nRows && col >= 0 && col < nCols ) |
438 | return d->brush[row*nCols+col]; | 438 | return d->brush[row*nCols+col]; |
439 | return NoBrush; | 439 | return NoBrush; |
440 | } | 440 | } |
441 | 441 | ||
442 | 442 | ||
443 | 443 | ||
444 | /*!\reimp | 444 | /*!\reimp |
445 | */ | 445 | */ |
446 | 446 | ||
447 | void QWellArray::focusOutEvent( QFocusEvent* ) | 447 | void QWellArray::focusOutEvent( QFocusEvent* ) |
448 | { | 448 | { |
449 | updateCell( curRow, curCol ); | 449 | updateCell( curRow, curCol ); |
450 | } | 450 | } |
451 | 451 | ||
452 | /*\reimp | 452 | /*\reimp |
453 | */ | 453 | */ |
454 | void QWellArray::keyPressEvent( QKeyEvent* e ) | 454 | void QWellArray::keyPressEvent( QKeyEvent* e ) |
455 | { | 455 | { |
456 | switch( e->key() ) { // Look at the key code | 456 | switch( e->key() ) { // Look at the key code |
457 | case Key_Left: // If 'left arrow'-key, | 457 | case Key_Left: // If 'left arrow'-key, |
458 | if( curCol > 0 ) { // and cr't not in leftmost col | 458 | if( curCol > 0 ) { // and cr't not in leftmost col |
459 | setCurrent( curRow, curCol - 1);// set cr't to next left column | 459 | setCurrent( curRow, curCol - 1);// set cr't to next left column |
460 | int edge = leftCell(); // find left edge | 460 | int edge = leftCell(); // find left edge |
461 | if ( curCol < edge ) // if we have moved off edge, | 461 | if ( curCol < edge ) // if we have moved off edge, |
462 | setLeftCell( edge - 1 );// scroll view to rectify | 462 | setLeftCell( edge - 1 );// scroll view to rectify |
463 | } | 463 | } |
464 | break; | 464 | break; |
465 | case Key_Right: // Correspondingly... | 465 | case Key_Right: // Correspondingly... |
466 | if( curCol < numCols()-1 ) { | 466 | if( curCol < numCols()-1 ) { |
467 | setCurrent( curRow, curCol + 1); | 467 | setCurrent( curRow, curCol + 1); |
468 | int edge = lastColVisible(); | 468 | int edge = lastColVisible(); |
469 | if ( curCol >= edge ) | 469 | if ( curCol >= edge ) |
470 | setLeftCell( leftCell() + 1 ); | 470 | setLeftCell( leftCell() + 1 ); |
471 | } | 471 | } |
472 | break; | 472 | break; |
473 | case Key_Up: | 473 | case Key_Up: |
474 | if( curRow > 0 ) { | 474 | if( curRow > 0 ) { |
475 | setCurrent( curRow - 1, curCol); | 475 | setCurrent( curRow - 1, curCol); |
476 | int edge = topCell(); | 476 | int edge = topCell(); |
477 | if ( curRow < edge ) | 477 | if ( curRow < edge ) |
478 | setTopCell( edge - 1 ); | 478 | setTopCell( edge - 1 ); |
479 | } else if ( smallStyle ) | 479 | } else if ( smallStyle ) |
480 | focusNextPrevChild( FALSE ); | 480 | focusNextPrevChild( FALSE ); |
481 | break; | 481 | break; |
482 | case Key_Down: | 482 | case Key_Down: |
483 | if( curRow < numRows()-1 ) { | 483 | if( curRow < numRows()-1 ) { |
484 | setCurrent( curRow + 1, curCol); | 484 | setCurrent( curRow + 1, curCol); |
485 | int edge = lastRowVisible(); | 485 | int edge = lastRowVisible(); |
486 | if ( curRow >= edge ) | 486 | if ( curRow >= edge ) |
487 | setTopCell( topCell() + 1 ); | 487 | setTopCell( topCell() + 1 ); |
488 | } else if ( smallStyle ) | 488 | } else if ( smallStyle ) |
489 | focusNextPrevChild( TRUE ); | 489 | focusNextPrevChild( TRUE ); |
490 | break; | 490 | break; |
491 | case Key_Space: | 491 | case Key_Space: |
492 | case Key_Return: | 492 | case Key_Return: |
493 | case Key_Enter: | 493 | case Key_Enter: |
494 | setSelected( curRow, curCol ); | 494 | setSelected( curRow, curCol ); |
495 | break; | 495 | break; |
496 | default: // If not an interesting key, | 496 | default: // If not an interesting key, |
497 | e->ignore(); // we don't accept the event | 497 | e->ignore(); // we don't accept the event |
498 | return; | 498 | return; |
499 | } | 499 | } |
500 | 500 | ||
501 | } | 501 | } |
502 | 502 | ||
503 | //////////// QWellArray END | 503 | //////////// QWellArray END |
504 | 504 | ||
505 | static bool initrgb = FALSE; | 505 | static bool initrgb = FALSE; |
506 | static QRgb stdrgb[6*8]; | 506 | static QRgb stdrgb[6*8]; |
507 | static QRgb cusrgb[2*8]; | 507 | static QRgb cusrgb[2*8]; |
508 | 508 | ||
509 | 509 | ||
510 | static void initRGB() | 510 | static void initRGB() |
511 | { | 511 | { |
512 | if ( initrgb ) | 512 | if ( initrgb ) |
513 | return; | 513 | return; |
514 | initrgb = TRUE; | 514 | initrgb = TRUE; |
515 | int i = 0; | 515 | int i = 0; |
516 | for ( int g = 0; g < 4; g++ ) | 516 | for ( int g = 0; g < 4; g++ ) |
517 | for ( int r = 0; r < 4; r++ ) | 517 | for ( int r = 0; r < 4; r++ ) |
518 | for ( int b = 0; b < 3; b++ ) | 518 | for ( int b = 0; b < 3; b++ ) |
519 | stdrgb[i++] = qRgb( r*255/3, g*255/3, b*255/2 ); | 519 | stdrgb[i++] = qRgb( r*255/3, g*255/3, b*255/2 ); |
520 | 520 | ||
521 | for ( i = 0; i < 2*8; i++ ) | 521 | for ( i = 0; i < 2*8; i++ ) |
522 | cusrgb[i] = qRgb(0xff,0xff,0xff); | 522 | cusrgb[i] = qRgb(0xff,0xff,0xff); |
523 | } | 523 | } |
524 | 524 | ||
525 | /*! | 525 | /*! |
526 | Returns the number of custom colors supported by | 526 | Returns the number of custom colors supported by |
527 | QColorDialog. All color dialogs share the same custom colors. | 527 | QColorDialog. All color dialogs share the same custom colors. |
528 | */ | 528 | */ |
529 | int QColorDialog::customCount() | 529 | int QColorDialog::customCount() |
530 | { | 530 | { |
531 | return 2*8; | 531 | return 2*8; |
532 | } | 532 | } |
533 | 533 | ||
534 | /*! | 534 | /*! |
535 | Returns custom color number \a i as a QRgb. | 535 | Returns custom color number \a i as a QRgb. |
536 | */ | 536 | */ |
537 | QRgb QColorDialog::customColor( int i ) | 537 | QRgb QColorDialog::customColor( int i ) |
538 | { | 538 | { |
539 | initRGB(); | 539 | initRGB(); |
540 | if ( i < 0 || i >= customCount() ) { | 540 | if ( i < 0 || i >= customCount() ) { |
541 | #ifdef CHECK_RANGE | 541 | #ifdef CHECK_RANGE |
542 | qWarning( "QColorDialog::customColor() index %d out of range", i ); | 542 | qWarning( "QColorDialog::customColor() index %d out of range", i ); |
543 | #endif | 543 | #endif |
544 | i = 0; | 544 | i = 0; |
545 | } | 545 | } |
546 | return cusrgb[i]; | 546 | return cusrgb[i]; |
547 | } | 547 | } |
548 | 548 | ||
549 | /*! | 549 | /*! |
550 | Sets custom color number \a i to the QRgb value \a c. | 550 | Sets custom color number \a i to the QRgb value \a c. |
551 | */ | 551 | */ |
552 | void QColorDialog::setCustomColor( int i, QRgb c ) | 552 | void QColorDialog::setCustomColor( int i, QRgb c ) |
553 | { | 553 | { |
554 | initRGB(); | 554 | initRGB(); |
555 | if ( i < 0 || i >= customCount() ) { | 555 | if ( i < 0 || i >= customCount() ) { |
556 | #ifdef CHECK_RANGE | 556 | #ifdef CHECK_RANGE |
557 | qWarning( "QColorDialog::customColor() index %d out of range", i ); | 557 | qWarning( "QColorDialog::customColor() index %d out of range", i ); |
558 | #endif | 558 | #endif |
559 | return; | 559 | return; |
560 | } | 560 | } |
561 | cusrgb[i] = c; | 561 | cusrgb[i] = c; |
562 | } | 562 | } |
563 | 563 | ||
564 | static inline void rgb2hsv( QRgb rgb, int&h, int&s, int&v ) | 564 | static inline void rgb2hsv( QRgb rgb, int&h, int&s, int&v ) |
565 | { | 565 | { |
566 | QColor c; | 566 | QColor c; |
567 | c.setRgb( rgb ); | 567 | c.setRgb( rgb ); |
568 | c.getHsv(h,s,v); | 568 | c.getHsv(h,s,v); |
569 | } | 569 | } |
570 | 570 | ||
571 | class QColorWell : public QWellArray | 571 | class QColorWell : public QWellArray |
572 | { | 572 | { |
573 | public: | 573 | public: |
574 | QColorWell( QWidget *parent, int r, int c, QRgb *vals ) | 574 | QColorWell( QWidget *parent, int r, int c, QRgb *vals ) |
575 | :QWellArray( parent, "" ), values( vals ), mousePressed( FALSE ), oldCurrent( -1, -1 ) | 575 | :QWellArray( parent, "" ), values( vals ), mousePressed( FALSE ), oldCurrent( -1, -1 ) |
576 | { setDimension(r,c); setWFlags( WResizeNoErase ); } | 576 | { setDimension(r,c); setWFlags( WResizeNoErase ); } |
577 | QSizePolicy sizePolicy() const; | 577 | QSizePolicy sizePolicy() const; |
578 | 578 | ||
579 | protected: | 579 | protected: |
580 | void drawContents( QPainter *, int row, int col, const QRect& ); | 580 | void drawContents( QPainter *, int row, int col, const QRect& ); |
581 | void drawContents( QPainter *p ) { QWellArray::drawContents(p); } | 581 | void drawContents( QPainter *p ) { QWellArray::drawContents(p); } |
582 | void mousePressEvent( QMouseEvent *e ); | 582 | void mousePressEvent( QMouseEvent *e ); |
583 | void mouseMoveEvent( QMouseEvent *e ); | 583 | void mouseMoveEvent( QMouseEvent *e ); |
584 | void mouseReleaseEvent( QMouseEvent *e ); | 584 | void mouseReleaseEvent( QMouseEvent *e ); |
585 | #ifndef QT_NO_DRAGANDDROP | 585 | #ifndef QT_NO_DRAGANDDROP |
586 | void dragEnterEvent( QDragEnterEvent *e ); | 586 | void dragEnterEvent( QDragEnterEvent *e ); |
587 | void dragLeaveEvent( QDragLeaveEvent *e ); | 587 | void dragLeaveEvent( QDragLeaveEvent *e ); |
588 | void dragMoveEvent( QDragMoveEvent *e ); | 588 | void dragMoveEvent( QDragMoveEvent *e ); |
589 | void dropEvent( QDropEvent *e ); | 589 | void dropEvent( QDropEvent *e ); |
590 | #endif | 590 | #endif |
591 | 591 | ||
592 | private: | 592 | private: |
593 | QRgb *values; | 593 | QRgb *values; |
594 | bool mousePressed; | 594 | bool mousePressed; |
595 | QPoint pressPos; | 595 | QPoint pressPos; |
596 | QPoint oldCurrent; | 596 | QPoint oldCurrent; |
597 | 597 | ||
598 | }; | 598 | }; |
599 | 599 | ||
600 | QSizePolicy QColorWell::sizePolicy() const | 600 | QSizePolicy QColorWell::sizePolicy() const |
601 | { | 601 | { |
602 | return QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ); | 602 | return QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ); |
603 | } | 603 | } |
604 | 604 | ||
605 | void QColorWell::drawContents( QPainter *p, int row, int col, const QRect &r ) | 605 | void QColorWell::drawContents( QPainter *p, int row, int col, const QRect &r ) |
606 | { | 606 | { |
607 | int i = row + col*numRows(); | 607 | int i = row + col*numRows(); |
608 | p->fillRect( r, QColor( values[i] ) ); | 608 | p->fillRect( r, QColor( values[i] ) ); |
609 | } | 609 | } |
610 | 610 | ||
611 | void QColorWell::mousePressEvent( QMouseEvent *e ) | 611 | void QColorWell::mousePressEvent( QMouseEvent *e ) |
612 | { | 612 | { |
613 | oldCurrent = QPoint( selectedRow(), selectedColumn() ); | 613 | oldCurrent = QPoint( selectedRow(), selectedColumn() ); |
614 | QWellArray::mousePressEvent( e ); | 614 | QWellArray::mousePressEvent( e ); |
615 | mousePressed = TRUE; | 615 | mousePressed = TRUE; |
616 | pressPos = e->pos(); | 616 | pressPos = e->pos(); |
617 | } | 617 | } |
618 | 618 | ||
619 | void QColorWell::mouseMoveEvent( QMouseEvent *e ) | 619 | void QColorWell::mouseMoveEvent( QMouseEvent *e ) |
620 | { | 620 | { |
621 | QWellArray::mouseMoveEvent( e ); | 621 | QWellArray::mouseMoveEvent( e ); |
622 | #ifndef QT_NO_DRAGANDDROP | 622 | #ifndef QT_NO_DRAGANDDROP |
623 | if ( !mousePressed ) | 623 | if ( !mousePressed ) |
624 | return; | 624 | return; |
625 | if ( ( pressPos - e->pos() ).manhattanLength() > QApplication::startDragDistance() ) { | 625 | if ( ( pressPos - e->pos() ).manhattanLength() > QApplication::startDragDistance() ) { |
626 | setCurrent( oldCurrent.x(), oldCurrent.y() ); | 626 | setCurrent( oldCurrent.x(), oldCurrent.y() ); |
627 | int i = findRow( e->y() ) + findCol( e->x() ) * numRows(); | 627 | int i = findRow( e->y() ) + findCol( e->x() ) * numRows(); |
628 | QColor col( values[ i ] ); | 628 | QColor col( values[ i ] ); |
629 | QColorDrag *drg = new QColorDrag( col, this ); | 629 | QColorDrag *drg = new QColorDrag( col, this ); |
630 | QPixmap pix( cellWidth(), cellHeight() ); | 630 | QPixmap pix( cellWidth(), cellHeight() ); |
631 | pix.fill( col ); | 631 | pix.fill( col ); |
632 | QPainter p( &pix ); | 632 | QPainter p( &pix ); |
633 | p.drawRect( 0, 0, pix.width(), pix.height() ); | 633 | p.drawRect( 0, 0, pix.width(), pix.height() ); |
634 | p.end(); | 634 | p.end(); |
635 | drg->setPixmap( pix ); | 635 | drg->setPixmap( pix ); |
636 | mousePressed = FALSE; | 636 | mousePressed = FALSE; |
637 | drg->dragCopy(); | 637 | drg->dragCopy(); |
638 | } | 638 | } |
639 | #endif | 639 | #endif |
640 | } | 640 | } |
641 | 641 | ||
642 | #ifndef QT_NO_DRAGANDDROP | 642 | #ifndef QT_NO_DRAGANDDROP |
643 | void QColorWell::dragEnterEvent( QDragEnterEvent *e ) | 643 | void QColorWell::dragEnterEvent( QDragEnterEvent *e ) |
644 | { | 644 | { |
645 | setFocus(); | 645 | setFocus(); |
646 | if ( QColorDrag::canDecode( e ) ) | 646 | if ( QColorDrag::canDecode( e ) ) |
647 | e->accept(); | 647 | e->accept(); |
648 | else | 648 | else |
649 | e->ignore(); | 649 | e->ignore(); |
650 | } | 650 | } |
651 | 651 | ||
652 | void QColorWell::dragLeaveEvent( QDragLeaveEvent * ) | 652 | void QColorWell::dragLeaveEvent( QDragLeaveEvent * ) |
653 | { | 653 | { |
654 | if ( hasFocus() ) | 654 | if ( hasFocus() ) |
655 | parentWidget()->setFocus(); | 655 | parentWidget()->setFocus(); |
656 | } | 656 | } |
657 | 657 | ||
658 | void QColorWell::dragMoveEvent( QDragMoveEvent *e ) | 658 | void QColorWell::dragMoveEvent( QDragMoveEvent *e ) |
659 | { | 659 | { |
660 | if ( QColorDrag::canDecode( e ) ) { | 660 | if ( QColorDrag::canDecode( e ) ) { |
661 | setCurrent( findRow( e->pos().y() ), findCol( e->pos().x() ) ); | 661 | setCurrent( findRow( e->pos().y() ), findCol( e->pos().x() ) ); |
662 | e->accept(); | 662 | e->accept(); |
663 | } else | 663 | } else |
664 | e->ignore(); | 664 | e->ignore(); |
665 | } | 665 | } |
666 | 666 | ||
667 | void QColorWell::dropEvent( QDropEvent *e ) | 667 | void QColorWell::dropEvent( QDropEvent *e ) |
668 | { | 668 | { |
669 | if ( QColorDrag::canDecode( e ) ) { | 669 | if ( QColorDrag::canDecode( e ) ) { |
670 | int i = findRow( e->pos().y() ) + findCol( e->pos().x() ) * numRows(); | 670 | int i = findRow( e->pos().y() ) + findCol( e->pos().x() ) * numRows(); |
671 | QColor col; | 671 | QColor col; |
672 | QColorDrag::decode( e, col ); | 672 | QColorDrag::decode( e, col ); |
673 | values[ i ] = col.rgb(); | 673 | values[ i ] = col.rgb(); |
674 | repaint( FALSE ); | 674 | repaint( FALSE ); |
675 | e->accept(); | 675 | e->accept(); |
676 | } else { | 676 | } else { |
677 | e->ignore(); | 677 | e->ignore(); |
678 | } | 678 | } |
679 | } | 679 | } |
680 | 680 | ||
681 | #endif // QT_NO_DRAGANDDROP | 681 | #endif // QT_NO_DRAGANDDROP |
682 | 682 | ||
683 | void QColorWell::mouseReleaseEvent( QMouseEvent *e ) | 683 | void QColorWell::mouseReleaseEvent( QMouseEvent *e ) |
684 | { | 684 | { |
685 | if ( !mousePressed ) | 685 | if ( !mousePressed ) |
686 | return; | 686 | return; |
687 | QWellArray::mouseReleaseEvent( e ); | 687 | QWellArray::mouseReleaseEvent( e ); |
688 | mousePressed = FALSE; | 688 | mousePressed = FALSE; |
689 | } | 689 | } |
690 | 690 | ||
691 | class QColorPicker : public QFrame | 691 | class QColorPicker : public QFrame |
692 | { | 692 | { |
693 | Q_OBJECT | 693 | Q_OBJECT |
694 | public: | 694 | public: |
695 | QColorPicker(QWidget* parent=0, const char* name=0); | 695 | QColorPicker(QWidget* parent=0, const char* name=0); |
696 | ~QColorPicker(); | 696 | ~QColorPicker(); |
697 | 697 | ||
698 | public slots: | 698 | public slots: |
699 | void setCol( int h, int s ); | 699 | void setCol( int h, int s ); |
700 | 700 | ||
701 | signals: | 701 | signals: |
702 | void newCol( int h, int s ); | 702 | void newCol( int h, int s ); |
703 | 703 | ||
704 | protected: | 704 | protected: |
705 | QSize sizeHint() const; | 705 | QSize sizeHint() const; |
706 | QSizePolicy sizePolicy() const; | 706 | QSizePolicy sizePolicy() const; |
707 | void drawContents(QPainter* p); | 707 | void drawContents(QPainter* p); |
708 | void mouseMoveEvent( QMouseEvent * ); | 708 | void mouseMoveEvent( QMouseEvent * ); |
709 | void mousePressEvent( QMouseEvent * ); | 709 | void mousePressEvent( QMouseEvent * ); |
710 | 710 | ||
711 | private: | 711 | private: |
712 | int hue; | 712 | int hue; |
713 | int sat; | 713 | int sat; |
714 | 714 | ||
715 | QPoint colPt(); | 715 | QPoint colPt(); |
716 | int huePt( const QPoint &pt ); | 716 | int huePt( const QPoint &pt ); |
717 | int satPt( const QPoint &pt ); | 717 | int satPt( const QPoint &pt ); |
718 | void setCol( const QPoint &pt ); | 718 | void setCol( const QPoint &pt ); |
719 | 719 | ||
720 | QPixmap *pix; | 720 | QPixmap *pix; |
721 | }; | 721 | }; |
722 | 722 | ||
723 | static int pWidth = 200; | 723 | static int pWidth = 200; |
724 | static int pHeight = 200; | 724 | static int pHeight = 200; |
725 | 725 | ||
726 | class QColorLuminancePicker : public QWidget | 726 | class QColorLuminancePicker : public QWidget |
727 | { | 727 | { |
728 | Q_OBJECT | 728 | Q_OBJECT |
729 | public: | 729 | public: |
730 | QColorLuminancePicker(QWidget* parent=0, const char* name=0); | 730 | QColorLuminancePicker(QWidget* parent=0, const char* name=0); |
731 | ~QColorLuminancePicker(); | 731 | ~QColorLuminancePicker(); |
732 | 732 | ||
733 | public slots: | 733 | public slots: |
734 | void setCol( int h, int s, int v ); | 734 | void setCol( int h, int s, int v ); |
735 | void setCol( int h, int s ); | 735 | void setCol( int h, int s ); |
736 | 736 | ||
737 | signals: | 737 | signals: |
738 | void newHsv( int h, int s, int v ); | 738 | void newHsv( int h, int s, int v ); |
739 | 739 | ||
740 | protected: | 740 | protected: |
741 | // QSize sizeHint() const; | 741 | // QSize sizeHint() const; |
742 | // QSizePolicy sizePolicy() const; | 742 | // QSizePolicy sizePolicy() const; |
743 | void paintEvent( QPaintEvent*); | 743 | void paintEvent( QPaintEvent*); |
744 | void mouseMoveEvent( QMouseEvent * ); | 744 | void mouseMoveEvent( QMouseEvent * ); |
745 | void mousePressEvent( QMouseEvent * ); | 745 | void mousePressEvent( QMouseEvent * ); |
746 | 746 | ||
747 | private: | 747 | private: |
748 | enum { foff = 3, coff = 4 }; //frame and contents offset | 748 | enum { foff = 3, coff = 4 }; //frame and contents offset |
749 | int val; | 749 | int val; |
750 | int hue; | 750 | int hue; |
751 | int sat; | 751 | int sat; |
752 | 752 | ||
753 | int y2val( int y ); | 753 | int y2val( int y ); |
754 | int val2y( int val ); | 754 | int val2y( int val ); |
755 | void setVal( int v ); | 755 | void setVal( int v ); |
756 | 756 | ||
757 | QPixmap *pix; | 757 | QPixmap *pix; |
758 | }; | 758 | }; |
759 | 759 | ||
760 | 760 | ||
761 | int QColorLuminancePicker::y2val( int y ) | 761 | int QColorLuminancePicker::y2val( int y ) |
762 | { | 762 | { |
763 | int d = height() - 2*coff - 1; | 763 | int d = height() - 2*coff - 1; |
764 | return 255 - (y - coff)*255/d; | 764 | return 255 - (y - coff)*255/d; |
765 | } | 765 | } |
766 | 766 | ||
767 | int QColorLuminancePicker::val2y( int v ) | 767 | int QColorLuminancePicker::val2y( int v ) |
768 | { | 768 | { |
769 | int d = height() - 2*coff - 1; | 769 | int d = height() - 2*coff - 1; |
770 | return coff + (255-v)*d/255; | 770 | return coff + (255-v)*d/255; |
771 | } | 771 | } |
772 | 772 | ||
773 | QColorLuminancePicker::QColorLuminancePicker(QWidget* parent, | 773 | QColorLuminancePicker::QColorLuminancePicker(QWidget* parent, |
774 | const char* name) | 774 | const char* name) |
775 | :QWidget( parent, name ) | 775 | :QWidget( parent, name ) |
776 | { | 776 | { |
777 | hue = 100; val = 100; sat = 100; | 777 | hue = 100; val = 100; sat = 100; |
778 | pix = 0; | 778 | pix = 0; |
779 | // setBackgroundMode( NoBackground ); | 779 | // setBackgroundMode( NoBackground ); |
780 | } | 780 | } |
781 | 781 | ||
782 | QColorLuminancePicker::~QColorLuminancePicker() | 782 | QColorLuminancePicker::~QColorLuminancePicker() |
783 | { | 783 | { |
784 | delete pix; | 784 | delete pix; |
785 | } | 785 | } |
786 | 786 | ||
787 | void QColorLuminancePicker::mouseMoveEvent( QMouseEvent *m ) | 787 | void QColorLuminancePicker::mouseMoveEvent( QMouseEvent *m ) |
788 | { | 788 | { |
789 | setVal( y2val(m->y()) ); | 789 | setVal( y2val(m->y()) ); |
790 | } | 790 | } |
791 | void QColorLuminancePicker::mousePressEvent( QMouseEvent *m ) | 791 | void QColorLuminancePicker::mousePressEvent( QMouseEvent *m ) |
792 | { | 792 | { |
793 | setVal( y2val(m->y()) ); | 793 | setVal( y2val(m->y()) ); |
794 | } | 794 | } |
795 | 795 | ||
796 | void QColorLuminancePicker::setVal( int v ) | 796 | void QColorLuminancePicker::setVal( int v ) |
797 | { | 797 | { |
798 | if ( val == v ) | 798 | if ( val == v ) |
799 | return; | 799 | return; |
800 | val = QMAX( 0, QMIN(v,255)); | 800 | val = QMAX( 0, QMIN(v,255)); |
801 | delete pix; pix=0; | 801 | delete pix; pix=0; |
802 | repaint( FALSE ); //### | 802 | repaint( FALSE ); //### |
803 | emit newHsv( hue, sat, val ); | 803 | emit newHsv( hue, sat, val ); |
804 | } | 804 | } |
805 | 805 | ||
806 | //receives from a hue,sat chooser and relays. | 806 | //receives from a hue,sat chooser and relays. |
807 | void QColorLuminancePicker::setCol( int h, int s ) | 807 | void QColorLuminancePicker::setCol( int h, int s ) |
808 | { | 808 | { |
809 | setCol( h, s, val ); | 809 | setCol( h, s, val ); |
810 | emit newHsv( h, s, val ); | 810 | emit newHsv( h, s, val ); |
811 | } | 811 | } |
812 | 812 | ||
813 | void QColorLuminancePicker::paintEvent( QPaintEvent * ) | 813 | void QColorLuminancePicker::paintEvent( QPaintEvent * ) |
814 | { | 814 | { |
815 | int w = width() - 5; | 815 | int w = width() - 5; |
816 | 816 | ||
817 | QRect r( 0, foff, w, height() - 2*foff ); | 817 | QRect r( 0, foff, w, height() - 2*foff ); |
818 | int wi = r.width() - 2; | 818 | int wi = r.width() - 2; |
819 | int hi = r.height() - 2; | 819 | int hi = r.height() - 2; |
820 | if ( !pix || pix->height() != hi || pix->width() != wi ) { | 820 | if ( !pix || pix->height() != hi || pix->width() != wi ) { |
821 | delete pix; | 821 | delete pix; |
822 | QImage img( wi, hi, 32 ); | 822 | QImage img( wi, hi, 32 ); |
823 | int y; | 823 | int y; |
824 | for ( y = 0; y < hi; y++ ) { | 824 | for ( y = 0; y < hi; y++ ) { |
825 | QColor c( hue, sat, y2val(y+coff), QColor::Hsv ); | 825 | QColor c( hue, sat, y2val(y+coff), QColor::Hsv ); |
826 | QRgb r = c.rgb(); | 826 | QRgb r = c.rgb(); |
827 | int x; | 827 | int x; |
828 | for ( x = 0; x < wi; x++ ) | 828 | for ( x = 0; x < wi; x++ ) |
829 | img.setPixel( x, y, r ); | 829 | img.setPixel( x, y, r ); |
830 | } | 830 | } |
831 | pix = new QPixmap; | 831 | pix = new QPixmap; |
832 | pix->convertFromImage(img); | 832 | pix->convertFromImage(img); |
833 | } | 833 | } |
834 | QPainter p(this); | 834 | QPainter p(this); |
835 | p.drawPixmap( 1, coff, *pix ); | 835 | p.drawPixmap( 1, coff, *pix ); |
836 | QColorGroup g = colorGroup(); | 836 | QColorGroup g = colorGroup(); |
837 | qDrawShadePanel( &p, r, g, TRUE ); | 837 | qDrawShadePanel( &p, r, g, TRUE ); |
838 | p.setPen( g.foreground() ); | 838 | p.setPen( g.foreground() ); |
839 | p.setBrush( g.foreground() ); | 839 | p.setBrush( g.foreground() ); |
840 | QPointArray a; | 840 | QPointArray a; |
841 | int y = val2y(val); | 841 | int y = val2y(val); |
842 | a.setPoints( 3, w, y, w+5, y+5, w+5, y-5 ); | 842 | a.setPoints( 3, w, y, w+5, y+5, w+5, y-5 ); |
843 | erase( w, 0, 5, height() ); | 843 | erase( w, 0, 5, height() ); |
844 | p.drawPolygon( a ); | 844 | p.drawPolygon( a ); |
845 | } | 845 | } |
846 | 846 | ||
847 | void QColorLuminancePicker::setCol( int h, int s , int v ) | 847 | void QColorLuminancePicker::setCol( int h, int s , int v ) |
848 | { | 848 | { |
849 | val = v; | 849 | val = v; |
850 | hue = h; | 850 | hue = h; |
851 | sat = s; | 851 | sat = s; |
852 | delete pix; pix=0; | 852 | delete pix; pix=0; |
853 | repaint( FALSE );//#### | 853 | repaint( FALSE );//#### |
854 | } | 854 | } |
855 | 855 | ||
856 | QPoint QColorPicker::colPt() | 856 | QPoint QColorPicker::colPt() |
857 | { return QPoint( (360-hue)*(pWidth-1)/360, (255-sat)*(pHeight-1)/255 ); } | 857 | { return QPoint( (360-hue)*(pWidth-1)/360, (255-sat)*(pHeight-1)/255 ); } |
858 | int QColorPicker::huePt( const QPoint &pt ) | 858 | int QColorPicker::huePt( const QPoint &pt ) |
859 | { return 360 - pt.x()*360/(pWidth-1); } | 859 | { return 360 - pt.x()*360/(pWidth-1); } |
860 | int QColorPicker::satPt( const QPoint &pt ) | 860 | int QColorPicker::satPt( const QPoint &pt ) |
861 | { return 255 - pt.y()*255/(pHeight-1) ; } | 861 | { return 255 - pt.y()*255/(pHeight-1) ; } |
862 | void QColorPicker::setCol( const QPoint &pt ) | 862 | void QColorPicker::setCol( const QPoint &pt ) |
863 | { setCol( huePt(pt), satPt(pt) ); } | 863 | { setCol( huePt(pt), satPt(pt) ); } |
864 | 864 | ||
865 | QColorPicker::QColorPicker(QWidget* parent, const char* name ) | 865 | QColorPicker::QColorPicker(QWidget* parent, const char* name ) |
866 | : QFrame( parent, name ) | 866 | : QFrame( parent, name ) |
867 | { | 867 | { |
868 | hue = 0; sat = 0; | 868 | hue = 0; sat = 0; |
869 | setCol( 150, 255 ); | 869 | setCol( 150, 255 ); |
870 | 870 | ||
871 | QImage img( pWidth, pHeight, 32 ); | 871 | QImage img( pWidth, pHeight, 32 ); |
872 | int x,y; | 872 | int x,y; |
873 | for ( y = 0; y < pHeight; y++ ) | 873 | for ( y = 0; y < pHeight; y++ ) |
874 | for ( x = 0; x < pWidth; x++ ) { | 874 | for ( x = 0; x < pWidth; x++ ) { |
875 | QPoint p( x, y ); | 875 | QPoint p( x, y ); |
876 | img.setPixel( x, y, QColor(huePt(p), satPt(p), | 876 | img.setPixel( x, y, QColor(huePt(p), satPt(p), |
877 | 200, QColor::Hsv).rgb() ); | 877 | 200, QColor::Hsv).rgb() ); |
878 | } | 878 | } |
879 | pix = new QPixmap; | 879 | pix = new QPixmap; |
880 | pix->convertFromImage(img); | 880 | pix->convertFromImage(img); |
881 | setBackgroundMode( NoBackground ); | 881 | setBackgroundMode( NoBackground ); |
882 | } | 882 | } |
883 | 883 | ||
884 | QColorPicker::~QColorPicker() | 884 | QColorPicker::~QColorPicker() |
885 | { | 885 | { |
886 | delete pix; | 886 | delete pix; |
887 | } | 887 | } |
888 | 888 | ||
889 | QSize QColorPicker::sizeHint() const | 889 | QSize QColorPicker::sizeHint() const |
890 | { | 890 | { |
891 | return QSize( pWidth + 2*frameWidth(), pHeight + 2*frameWidth() ); | 891 | return QSize( pWidth + 2*frameWidth(), pHeight + 2*frameWidth() ); |
892 | } | 892 | } |
893 | 893 | ||
894 | QSizePolicy QColorPicker::sizePolicy() const | 894 | QSizePolicy QColorPicker::sizePolicy() const |
895 | { | 895 | { |
896 | return QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); | 896 | return QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); |
897 | } | 897 | } |
898 | 898 | ||
899 | void QColorPicker::setCol( int h, int s ) | 899 | void QColorPicker::setCol( int h, int s ) |
900 | { | 900 | { |
901 | int nhue = QMIN( QMAX(0,h), 360 ); | 901 | int nhue = QMIN( QMAX(0,h), 360 ); |
902 | int nsat = QMIN( QMAX(0,s), 255); | 902 | int nsat = QMIN( QMAX(0,s), 255); |
903 | if ( nhue == hue && nsat == sat ) | 903 | if ( nhue == hue && nsat == sat ) |
904 | return; | 904 | return; |
905 | QRect r( colPt(), QSize(20,20) ); | 905 | QRect r( colPt(), QSize(20,20) ); |
906 | hue = nhue; sat = nsat; | 906 | hue = nhue; sat = nsat; |
907 | r = r.unite( QRect( colPt(), QSize(20,20) ) ); | 907 | r = r.unite( QRect( colPt(), QSize(20,20) ) ); |
908 | r.moveBy( contentsRect().x()-9, contentsRect().y()-9 ); | 908 | r.moveBy( contentsRect().x()-9, contentsRect().y()-9 ); |
909 | // update( r ); | 909 | // update( r ); |
910 | repaint( r, FALSE ); | 910 | repaint( r, FALSE ); |
911 | } | 911 | } |
912 | 912 | ||
913 | void QColorPicker::mouseMoveEvent( QMouseEvent *m ) | 913 | void QColorPicker::mouseMoveEvent( QMouseEvent *m ) |
914 | { | 914 | { |
915 | QPoint p = m->pos() - contentsRect().topLeft(); | 915 | QPoint p = m->pos() - contentsRect().topLeft(); |
916 | setCol( p ); | 916 | setCol( p ); |
917 | emit newCol( hue, sat ); | 917 | emit newCol( hue, sat ); |
918 | } | 918 | } |
919 | 919 | ||
920 | void QColorPicker::mousePressEvent( QMouseEvent *m ) | 920 | void QColorPicker::mousePressEvent( QMouseEvent *m ) |
921 | { | 921 | { |
922 | QPoint p = m->pos() - contentsRect().topLeft(); | 922 | QPoint p = m->pos() - contentsRect().topLeft(); |
923 | setCol( p ); | 923 | setCol( p ); |
924 | emit newCol( hue, sat ); | 924 | emit newCol( hue, sat ); |
925 | } | 925 | } |
926 | 926 | ||
927 | void QColorPicker::drawContents(QPainter* p) | 927 | void QColorPicker::drawContents(QPainter* p) |
928 | { | 928 | { |
929 | QRect r = contentsRect(); | 929 | QRect r = contentsRect(); |
930 | 930 | ||
931 | p->drawPixmap( r.topLeft(), *pix ); | 931 | p->drawPixmap( r.topLeft(), *pix ); |
932 | QPoint pt = colPt() + r.topLeft(); | 932 | QPoint pt = colPt() + r.topLeft(); |
933 | p->setPen( QPen(black) ); | 933 | p->setPen( QPen(black) ); |
934 | 934 | ||
935 | p->fillRect( pt.x()-9, pt.y(), 20, 2, black ); | 935 | p->fillRect( pt.x()-9, pt.y(), 20, 2, black ); |
936 | p->fillRect( pt.x(), pt.y()-9, 2, 20, black ); | 936 | p->fillRect( pt.x(), pt.y()-9, 2, 20, black ); |
937 | 937 | ||
938 | } | 938 | } |
939 | 939 | ||
940 | class QColorShowLabel; | 940 | class QColorShowLabel; |
941 | 941 | ||
942 | 942 | ||
943 | 943 | ||
944 | class QColIntValidator: public QIntValidator | 944 | class QColIntValidator: public QIntValidator |
945 | { | 945 | { |
946 | public: | 946 | public: |
947 | QColIntValidator( int bottom, int top, | 947 | QColIntValidator( int bottom, int top, |
948 | QWidget * parent, const char *name = 0 ) | 948 | QWidget * parent, const char *name = 0 ) |
949 | :QIntValidator( bottom, top, parent, name ) {} | 949 | :QIntValidator( bottom, top, parent, name ) {} |
950 | 950 | ||
951 | QValidator::State validate( QString &, int & ) const; | 951 | QValidator::State validate( QString &, int & ) const; |
952 | }; | 952 | }; |
953 | 953 | ||
954 | QValidator::State QColIntValidator::validate( QString &s, int &pos ) const | 954 | QValidator::State QColIntValidator::validate( QString &s, int &pos ) const |
955 | { | 955 | { |
956 | State state = QIntValidator::validate(s,pos); | 956 | State state = QIntValidator::validate(s,pos); |
957 | if ( state == Valid ) { | 957 | if ( state == Valid ) { |
958 | long int val = s.toLong(); | 958 | long int val = s.toLong(); |
959 | // This is not a general solution, assumes that top() > 0 and | 959 | // This is not a general solution, assumes that top() > 0 and |
960 | // bottom >= 0 | 960 | // bottom >= 0 |
961 | if ( val < 0 ) { | 961 | if ( val < 0 ) { |
962 | s = "0"; | 962 | s = "0"; |
963 | pos = 1; | 963 | pos = 1; |
964 | } else if ( val > top() ) { | 964 | } else if ( val > top() ) { |
965 | s.setNum( top() ); | 965 | s.setNum( top() ); |
966 | pos = s.length(); | 966 | pos = s.length(); |
967 | } | 967 | } |
968 | } | 968 | } |
969 | return state; | 969 | return state; |
970 | } | 970 | } |
971 | 971 | ||
972 | 972 | ||
973 | 973 | ||
974 | class QColNumLineEdit : public QLineEdit | 974 | class QColNumLineEdit : public QLineEdit |
975 | { | 975 | { |
976 | public: | 976 | public: |
977 | QColNumLineEdit( QWidget *parent, const char* name = 0 ) | 977 | QColNumLineEdit( QWidget *parent, const char* name = 0 ) |
978 | : QLineEdit( parent, name ) { setMaxLength( 3 );} | 978 | : QLineEdit( parent, name ) { setMaxLength( 3 );} |
979 | QSize sizeHint() const { | 979 | QSize sizeHint() const { |
980 | return QSize( 30, //##### | 980 | return QSize( 30, //##### |
981 | QLineEdit::sizeHint().height() ); } | 981 | QLineEdit::sizeHint().height() ); } |
982 | void setNum( int i ) { | 982 | void setNum( int i ) { |
983 | QString s; | 983 | QString s; |
984 | s.setNum(i); | 984 | s.setNum(i); |
985 | bool block = signalsBlocked(); | 985 | bool block = signalsBlocked(); |
986 | blockSignals(TRUE); | 986 | blockSignals(TRUE); |
987 | setText( s ); | 987 | setText( s ); |
988 | blockSignals(block); | 988 | blockSignals(block); |
989 | } | 989 | } |
990 | int val() const { return text().toInt(); } | 990 | int val() const { return text().toInt(); } |
991 | }; | 991 | }; |
992 | 992 | ||
993 | 993 | ||
994 | class QColorShower : public QWidget | 994 | class QColorShower : public QWidget |
995 | { | 995 | { |
996 | Q_OBJECT | 996 | Q_OBJECT |
997 | public: | 997 | public: |
998 | QColorShower( QWidget *parent, const char *name = 0 ); | 998 | QColorShower( QWidget *parent, const char *name = 0 ); |
999 | 999 | ||
1000 | //things that don't emit signals | 1000 | //things that don't emit signals |
1001 | void setHsv( int h, int s, int v ); | 1001 | void setHsv( int h, int s, int v ); |
1002 | 1002 | ||
1003 | int currentAlpha() const { return alphaEd->val(); } | 1003 | int currentAlpha() const { return alphaEd->val(); } |
1004 | void setCurrentAlpha( int a ) { alphaEd->setNum( a ); } | 1004 | void setCurrentAlpha( int a ) { alphaEd->setNum( a ); } |
1005 | void showAlpha( bool b ); | 1005 | void showAlpha( bool b ); |
1006 | 1006 | ||
1007 | 1007 | ||
1008 | QRgb currentColor() const { return curCol; } | 1008 | QRgb currentColor() const { return curCol; } |
1009 | 1009 | ||
1010 | public slots: | 1010 | public slots: |
1011 | void setRgb( QRgb rgb ); | 1011 | void setRgb( QRgb rgb ); |
1012 | 1012 | ||
1013 | signals: | 1013 | signals: |
1014 | void newCol( QRgb rgb ); | 1014 | void newCol( QRgb rgb ); |
1015 | private slots: | 1015 | private slots: |
1016 | void rgbEd(); | 1016 | void rgbEd(); |
1017 | void hsvEd(); | 1017 | void hsvEd(); |
1018 | private: | 1018 | private: |
1019 | void showCurrentColor(); | 1019 | void showCurrentColor(); |
1020 | int hue, sat, val; | 1020 | int hue, sat, val; |
1021 | QRgb curCol; | 1021 | QRgb curCol; |
1022 | QColNumLineEdit *hEd; | 1022 | QColNumLineEdit *hEd; |
1023 | QColNumLineEdit *sEd; | 1023 | QColNumLineEdit *sEd; |
1024 | QColNumLineEdit *vEd; | 1024 | QColNumLineEdit *vEd; |
1025 | QColNumLineEdit *rEd; | 1025 | QColNumLineEdit *rEd; |
1026 | QColNumLineEdit *gEd; | 1026 | QColNumLineEdit *gEd; |
1027 | QColNumLineEdit *bEd; | 1027 | QColNumLineEdit *bEd; |
1028 | QColNumLineEdit *alphaEd; | 1028 | QColNumLineEdit *alphaEd; |
1029 | QLabel *alphaLab; | 1029 | QLabel *alphaLab; |
1030 | QColorShowLabel *lab; | 1030 | QColorShowLabel *lab; |
1031 | bool rgbOriginal; | 1031 | bool rgbOriginal; |
1032 | }; | 1032 | }; |
1033 | 1033 | ||
1034 | class QColorShowLabel : public QFrame | 1034 | class QColorShowLabel : public QFrame |
1035 | { | 1035 | { |
1036 | Q_OBJECT | 1036 | Q_OBJECT |
1037 | 1037 | ||
1038 | public: | 1038 | public: |
1039 | QColorShowLabel( QWidget *parent ) :QFrame( parent ) { | 1039 | QColorShowLabel( QWidget *parent ) :QFrame( parent ) { |
1040 | setFrameStyle( QFrame::Panel|QFrame::Sunken ); | 1040 | setFrameStyle( QFrame::Panel|QFrame::Sunken ); |
1041 | setBackgroundMode( PaletteBackground ); | 1041 | setBackgroundMode( PaletteBackground ); |
1042 | setAcceptDrops( TRUE ); | 1042 | setAcceptDrops( TRUE ); |
1043 | mousePressed = FALSE; | 1043 | mousePressed = FALSE; |
1044 | } | 1044 | } |
1045 | void setColor( QColor c ) { col = c; } | 1045 | void setColor( QColor c ) { col = c; } |
1046 | 1046 | ||
1047 | signals: | 1047 | signals: |
1048 | void colorDropped( QRgb ); | 1048 | void colorDropped( QRgb ); |
1049 | 1049 | ||
1050 | protected: | 1050 | protected: |
1051 | void drawContents( QPainter *p ); | 1051 | void drawContents( QPainter *p ); |
1052 | void mousePressEvent( QMouseEvent *e ); | 1052 | void mousePressEvent( QMouseEvent *e ); |
1053 | void mouseMoveEvent( QMouseEvent *e ); | 1053 | void mouseMoveEvent( QMouseEvent *e ); |
1054 | void mouseReleaseEvent( QMouseEvent *e ); | 1054 | void mouseReleaseEvent( QMouseEvent *e ); |
1055 | #ifndef QT_NO_DRAGANDDROP | 1055 | #ifndef QT_NO_DRAGANDDROP |
1056 | void dragEnterEvent( QDragEnterEvent *e ); | 1056 | void dragEnterEvent( QDragEnterEvent *e ); |
1057 | void dragLeaveEvent( QDragLeaveEvent *e ); | 1057 | void dragLeaveEvent( QDragLeaveEvent *e ); |
1058 | void dropEvent( QDropEvent *e ); | 1058 | void dropEvent( QDropEvent *e ); |
1059 | #endif | 1059 | #endif |
1060 | 1060 | ||
1061 | private: | 1061 | private: |
1062 | QColor col; | 1062 | QColor col; |
1063 | bool mousePressed; | 1063 | bool mousePressed; |
1064 | QPoint pressPos; | 1064 | QPoint pressPos; |
1065 | 1065 | ||
1066 | }; | 1066 | }; |
1067 | 1067 | ||
1068 | void QColorShowLabel::drawContents( QPainter *p ) | 1068 | void QColorShowLabel::drawContents( QPainter *p ) |
1069 | { | 1069 | { |
1070 | p->fillRect( contentsRect(), col ); | 1070 | p->fillRect( contentsRect(), col ); |
1071 | } | 1071 | } |
1072 | 1072 | ||
1073 | void QColorShower::showAlpha( bool b ) | 1073 | void QColorShower::showAlpha( bool b ) |
1074 | { | 1074 | { |
1075 | if ( b ) { | 1075 | if ( b ) { |
1076 | alphaLab->show(); | 1076 | alphaLab->show(); |
1077 | alphaEd->show(); | 1077 | alphaEd->show(); |
1078 | } else { | 1078 | } else { |
1079 | alphaLab->hide(); | 1079 | alphaLab->hide(); |
1080 | alphaEd->hide(); | 1080 | alphaEd->hide(); |
1081 | } | 1081 | } |
1082 | } | 1082 | } |
1083 | 1083 | ||
1084 | void QColorShowLabel::mousePressEvent( QMouseEvent *e ) | 1084 | void QColorShowLabel::mousePressEvent( QMouseEvent *e ) |
1085 | { | 1085 | { |
1086 | mousePressed = TRUE; | 1086 | mousePressed = TRUE; |
1087 | pressPos = e->pos(); | 1087 | pressPos = e->pos(); |
1088 | } | 1088 | } |
1089 | 1089 | ||
1090 | void QColorShowLabel::mouseMoveEvent( QMouseEvent *e ) | 1090 | void QColorShowLabel::mouseMoveEvent( QMouseEvent *e ) |
1091 | { | 1091 | { |
1092 | #ifndef QT_NO_DRAGANDDROP | 1092 | #ifndef QT_NO_DRAGANDDROP |
1093 | if ( !mousePressed ) | 1093 | if ( !mousePressed ) |
1094 | return; | 1094 | return; |
1095 | if ( ( pressPos - e->pos() ).manhattanLength() > QApplication::startDragDistance() ) { | 1095 | if ( ( pressPos - e->pos() ).manhattanLength() > QApplication::startDragDistance() ) { |
1096 | QColorDrag *drg = new QColorDrag( col, this ); | 1096 | QColorDrag *drg = new QColorDrag( col, this ); |
1097 | QPixmap pix( 30, 20 ); | 1097 | QPixmap pix( 30, 20 ); |
1098 | pix.fill( col ); | 1098 | pix.fill( col ); |
1099 | QPainter p( &pix ); | 1099 | QPainter p( &pix ); |
1100 | p.drawRect( 0, 0, pix.width(), pix.height() ); | 1100 | p.drawRect( 0, 0, pix.width(), pix.height() ); |
1101 | p.end(); | 1101 | p.end(); |
1102 | drg->setPixmap( pix ); | 1102 | drg->setPixmap( pix ); |
1103 | mousePressed = FALSE; | 1103 | mousePressed = FALSE; |
1104 | drg->dragCopy(); | 1104 | drg->dragCopy(); |
1105 | } | 1105 | } |
1106 | #else | ||
1107 | Q_UNUSED( e ) | ||
1106 | #endif | 1108 | #endif |
1107 | } | 1109 | } |
1108 | 1110 | ||
1109 | #ifndef QT_NO_DRAGANDDROP | 1111 | #ifndef QT_NO_DRAGANDDROP |
1110 | void QColorShowLabel::dragEnterEvent( QDragEnterEvent *e ) | 1112 | void QColorShowLabel::dragEnterEvent( QDragEnterEvent *e ) |
1111 | { | 1113 | { |
1112 | if ( QColorDrag::canDecode( e ) ) | 1114 | if ( QColorDrag::canDecode( e ) ) |
1113 | e->accept(); | 1115 | e->accept(); |
1114 | else | 1116 | else |
1115 | e->ignore(); | 1117 | e->ignore(); |
1116 | } | 1118 | } |
1117 | 1119 | ||
1118 | void QColorShowLabel::dragLeaveEvent( QDragLeaveEvent * ) | 1120 | void QColorShowLabel::dragLeaveEvent( QDragLeaveEvent * ) |
1119 | { | 1121 | { |
1120 | } | 1122 | } |
1121 | 1123 | ||
1122 | void QColorShowLabel::dropEvent( QDropEvent *e ) | 1124 | void QColorShowLabel::dropEvent( QDropEvent *e ) |
1123 | { | 1125 | { |
1124 | if ( QColorDrag::canDecode( e ) ) { | 1126 | if ( QColorDrag::canDecode( e ) ) { |
1125 | QColorDrag::decode( e, col ); | 1127 | QColorDrag::decode( e, col ); |
1126 | repaint( FALSE ); | 1128 | repaint( FALSE ); |
1127 | emit colorDropped( col.rgb() ); | 1129 | emit colorDropped( col.rgb() ); |
1128 | e->accept(); | 1130 | e->accept(); |
1129 | } else { | 1131 | } else { |
1130 | e->ignore(); | 1132 | e->ignore(); |
1131 | } | 1133 | } |
1132 | } | 1134 | } |
1133 | #endif // QT_NO_DRAGANDDROP | 1135 | #endif // QT_NO_DRAGANDDROP |
1134 | 1136 | ||
1135 | void QColorShowLabel::mouseReleaseEvent( QMouseEvent * ) | 1137 | void QColorShowLabel::mouseReleaseEvent( QMouseEvent * ) |
1136 | { | 1138 | { |
1137 | if ( !mousePressed ) | 1139 | if ( !mousePressed ) |
1138 | return; | 1140 | return; |
1139 | mousePressed = FALSE; | 1141 | mousePressed = FALSE; |
1140 | } | 1142 | } |
1141 | 1143 | ||
1142 | QColorShower::QColorShower( QWidget *parent, const char *name ) | 1144 | QColorShower::QColorShower( QWidget *parent, const char *name ) |
1143 | :QWidget( parent, name) | 1145 | :QWidget( parent, name) |
1144 | { | 1146 | { |
1145 | curCol = qRgb( -1, -1, -1 ); | 1147 | curCol = qRgb( -1, -1, -1 ); |
1146 | QColIntValidator *val256 = new QColIntValidator( 0, 255, this ); | 1148 | QColIntValidator *val256 = new QColIntValidator( 0, 255, this ); |
1147 | QColIntValidator *val360 = new QColIntValidator( 0, 360, this ); | 1149 | QColIntValidator *val360 = new QColIntValidator( 0, 360, this ); |
1148 | 1150 | ||
1149 | QGridLayout *gl = new QGridLayout( this, 1, 1, 6 ); | 1151 | QGridLayout *gl = new QGridLayout( this, 1, 1, 6 ); |
1150 | lab = new QColorShowLabel( this ); | 1152 | lab = new QColorShowLabel( this ); |
1151 | lab->setMinimumWidth( 60 ); //### | 1153 | lab->setMinimumWidth( 60 ); //### |
1152 | gl->addMultiCellWidget(lab, 0,-1,0,0); | 1154 | gl->addMultiCellWidget(lab, 0,-1,0,0); |
1153 | connect( lab, SIGNAL( colorDropped(QRgb) ), | 1155 | connect( lab, SIGNAL( colorDropped(QRgb) ), |
1154 | this, SIGNAL( newCol(QRgb) ) ); | 1156 | this, SIGNAL( newCol(QRgb) ) ); |
1155 | connect( lab, SIGNAL( colorDropped(QRgb) ), | 1157 | connect( lab, SIGNAL( colorDropped(QRgb) ), |
1156 | this, SLOT( setRgb(QRgb) ) ); | 1158 | this, SLOT( setRgb(QRgb) ) ); |
1157 | 1159 | ||
1158 | hEd = new QColNumLineEdit( this ); | 1160 | hEd = new QColNumLineEdit( this ); |
1159 | hEd->setValidator( val360 ); | 1161 | hEd->setValidator( val360 ); |
1160 | QLabel *l = new QLabel( hEd, QColorDialog::tr("Hu&e:"), this ); | 1162 | QLabel *l = new QLabel( hEd, QColorDialog::tr("Hu&e:"), this ); |
1161 | l->setAlignment( AlignRight|AlignVCenter ); | 1163 | l->setAlignment( AlignRight|AlignVCenter ); |
1162 | gl->addWidget( l, 0, 1 ); | 1164 | gl->addWidget( l, 0, 1 ); |
1163 | gl->addWidget( hEd, 0, 2 ); | 1165 | gl->addWidget( hEd, 0, 2 ); |
1164 | 1166 | ||
1165 | sEd = new QColNumLineEdit( this ); | 1167 | sEd = new QColNumLineEdit( this ); |
1166 | sEd->setValidator( val256 ); | 1168 | sEd->setValidator( val256 ); |
1167 | l = new QLabel( sEd, QColorDialog::tr("&Sat:"), this ); | 1169 | l = new QLabel( sEd, QColorDialog::tr("&Sat:"), this ); |
1168 | l->setAlignment( AlignRight|AlignVCenter ); | 1170 | l->setAlignment( AlignRight|AlignVCenter ); |
1169 | gl->addWidget( l, 1, 1 ); | 1171 | gl->addWidget( l, 1, 1 ); |
1170 | gl->addWidget( sEd, 1, 2 ); | 1172 | gl->addWidget( sEd, 1, 2 ); |
1171 | 1173 | ||
1172 | vEd = new QColNumLineEdit( this ); | 1174 | vEd = new QColNumLineEdit( this ); |
1173 | vEd->setValidator( val256 ); | 1175 | vEd->setValidator( val256 ); |
1174 | l = new QLabel( vEd, QColorDialog::tr("&Val:"), this ); | 1176 | l = new QLabel( vEd, QColorDialog::tr("&Val:"), this ); |
1175 | l->setAlignment( AlignRight|AlignVCenter ); | 1177 | l->setAlignment( AlignRight|AlignVCenter ); |
1176 | gl->addWidget( l, 2, 1 ); | 1178 | gl->addWidget( l, 2, 1 ); |
1177 | gl->addWidget( vEd, 2, 2 ); | 1179 | gl->addWidget( vEd, 2, 2 ); |
1178 | 1180 | ||
1179 | rEd = new QColNumLineEdit( this ); | 1181 | rEd = new QColNumLineEdit( this ); |
1180 | rEd->setValidator( val256 ); | 1182 | rEd->setValidator( val256 ); |
1181 | l = new QLabel( rEd, QColorDialog::tr("&Red:"), this ); | 1183 | l = new QLabel( rEd, QColorDialog::tr("&Red:"), this ); |
1182 | l->setAlignment( AlignRight|AlignVCenter ); | 1184 | l->setAlignment( AlignRight|AlignVCenter ); |
1183 | gl->addWidget( l, 0, 3 ); | 1185 | gl->addWidget( l, 0, 3 ); |
1184 | gl->addWidget( rEd, 0, 4 ); | 1186 | gl->addWidget( rEd, 0, 4 ); |
1185 | 1187 | ||
1186 | gEd = new QColNumLineEdit( this ); | 1188 | gEd = new QColNumLineEdit( this ); |
1187 | gEd->setValidator( val256 ); | 1189 | gEd->setValidator( val256 ); |
1188 | l = new QLabel( gEd, QColorDialog::tr("&Green:"), this ); | 1190 | l = new QLabel( gEd, QColorDialog::tr("&Green:"), this ); |
1189 | l->setAlignment( AlignRight|AlignVCenter ); | 1191 | l->setAlignment( AlignRight|AlignVCenter ); |
1190 | gl->addWidget( l, 1, 3 ); | 1192 | gl->addWidget( l, 1, 3 ); |
1191 | gl->addWidget( gEd, 1, 4 ); | 1193 | gl->addWidget( gEd, 1, 4 ); |
1192 | 1194 | ||
1193 | bEd = new QColNumLineEdit( this ); | 1195 | bEd = new QColNumLineEdit( this ); |
1194 | bEd->setValidator( val256 ); | 1196 | bEd->setValidator( val256 ); |
1195 | l = new QLabel( bEd, QColorDialog::tr("Bl&ue:"), this ); | 1197 | l = new QLabel( bEd, QColorDialog::tr("Bl&ue:"), this ); |
1196 | l->setAlignment( AlignRight|AlignVCenter ); | 1198 | l->setAlignment( AlignRight|AlignVCenter ); |
1197 | gl->addWidget( l, 2, 3 ); | 1199 | gl->addWidget( l, 2, 3 ); |
1198 | gl->addWidget( bEd, 2, 4 ); | 1200 | gl->addWidget( bEd, 2, 4 ); |
1199 | 1201 | ||
1200 | alphaEd = new QColNumLineEdit( this ); | 1202 | alphaEd = new QColNumLineEdit( this ); |
1201 | alphaEd->setValidator( val256 ); | 1203 | alphaEd->setValidator( val256 ); |
1202 | alphaLab = new QLabel( alphaEd, QColorDialog::tr("A&lpha channel:"), this ); | 1204 | alphaLab = new QLabel( alphaEd, QColorDialog::tr("A&lpha channel:"), this ); |
1203 | alphaLab->setAlignment( AlignRight|AlignVCenter ); | 1205 | alphaLab->setAlignment( AlignRight|AlignVCenter ); |
1204 | gl->addMultiCellWidget( alphaLab, 3, 3, 1, 3 ); | 1206 | gl->addMultiCellWidget( alphaLab, 3, 3, 1, 3 ); |
1205 | gl->addWidget( alphaEd, 3, 4 ); | 1207 | gl->addWidget( alphaEd, 3, 4 ); |
1206 | alphaEd->hide(); | 1208 | alphaEd->hide(); |
1207 | alphaLab->hide(); | 1209 | alphaLab->hide(); |
1208 | 1210 | ||
1209 | connect( hEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) ); | 1211 | connect( hEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) ); |
1210 | connect( sEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) ); | 1212 | connect( sEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) ); |
1211 | connect( vEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) ); | 1213 | connect( vEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) ); |
1212 | 1214 | ||
1213 | connect( rEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) ); | 1215 | connect( rEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) ); |
1214 | connect( gEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) ); | 1216 | connect( gEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) ); |
1215 | connect( bEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) ); | 1217 | connect( bEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) ); |
1216 | } | 1218 | } |
1217 | 1219 | ||
1218 | void QColorShower::showCurrentColor() | 1220 | void QColorShower::showCurrentColor() |
1219 | { | 1221 | { |
1220 | lab->setColor( currentColor() ); | 1222 | lab->setColor( currentColor() ); |
1221 | lab->repaint(FALSE); //### | 1223 | lab->repaint(FALSE); //### |
1222 | } | 1224 | } |
1223 | 1225 | ||
1224 | void QColorShower::rgbEd() | 1226 | void QColorShower::rgbEd() |
1225 | { | 1227 | { |
1226 | rgbOriginal = TRUE; | 1228 | rgbOriginal = TRUE; |
1227 | curCol = qRgb( rEd->val(), gEd->val(), bEd->val() ); | 1229 | curCol = qRgb( rEd->val(), gEd->val(), bEd->val() ); |
1228 | rgb2hsv(currentColor(), hue, sat, val ); | 1230 | rgb2hsv(currentColor(), hue, sat, val ); |
1229 | 1231 | ||
1230 | hEd->setNum( hue ); | 1232 | hEd->setNum( hue ); |
1231 | sEd->setNum( sat ); | 1233 | sEd->setNum( sat ); |
1232 | vEd->setNum( val ); | 1234 | vEd->setNum( val ); |
1233 | 1235 | ||
1234 | showCurrentColor(); | 1236 | showCurrentColor(); |
1235 | emit newCol( currentColor() ); | 1237 | emit newCol( currentColor() ); |
1236 | } | 1238 | } |
1237 | 1239 | ||
1238 | void QColorShower::hsvEd() | 1240 | void QColorShower::hsvEd() |
1239 | { | 1241 | { |
1240 | rgbOriginal = FALSE; | 1242 | rgbOriginal = FALSE; |
1241 | hue = hEd->val(); | 1243 | hue = hEd->val(); |
1242 | sat = sEd->val(); | 1244 | sat = sEd->val(); |
1243 | val = vEd->val(); | 1245 | val = vEd->val(); |
1244 | 1246 | ||
1245 | curCol = QColor( hue, sat, val, QColor::Hsv ).rgb(); | 1247 | curCol = QColor( hue, sat, val, QColor::Hsv ).rgb(); |
1246 | 1248 | ||
1247 | rEd->setNum( qRed(currentColor()) ); | 1249 | rEd->setNum( qRed(currentColor()) ); |
1248 | gEd->setNum( qGreen(currentColor()) ); | 1250 | gEd->setNum( qGreen(currentColor()) ); |
1249 | bEd->setNum( qBlue(currentColor()) ); | 1251 | bEd->setNum( qBlue(currentColor()) ); |
1250 | 1252 | ||
1251 | showCurrentColor(); | 1253 | showCurrentColor(); |
1252 | emit newCol( currentColor() ); | 1254 | emit newCol( currentColor() ); |
1253 | } | 1255 | } |
1254 | 1256 | ||
1255 | void QColorShower::setRgb( QRgb rgb ) | 1257 | void QColorShower::setRgb( QRgb rgb ) |
1256 | { | 1258 | { |
1257 | rgbOriginal = TRUE; | 1259 | rgbOriginal = TRUE; |
1258 | curCol = rgb; | 1260 | curCol = rgb; |
1259 | 1261 | ||
1260 | rgb2hsv( currentColor(), hue, sat, val ); | 1262 | rgb2hsv( currentColor(), hue, sat, val ); |
1261 | 1263 | ||
1262 | hEd->setNum( hue ); | 1264 | hEd->setNum( hue ); |
1263 | sEd->setNum( sat ); | 1265 | sEd->setNum( sat ); |
1264 | vEd->setNum( val ); | 1266 | vEd->setNum( val ); |
1265 | 1267 | ||
1266 | rEd->setNum( qRed(currentColor()) ); | 1268 | rEd->setNum( qRed(currentColor()) ); |
1267 | gEd->setNum( qGreen(currentColor()) ); | 1269 | gEd->setNum( qGreen(currentColor()) ); |
1268 | bEd->setNum( qBlue(currentColor()) ); | 1270 | bEd->setNum( qBlue(currentColor()) ); |
1269 | 1271 | ||
1270 | showCurrentColor(); | 1272 | showCurrentColor(); |
1271 | } | 1273 | } |
1272 | 1274 | ||
1273 | void QColorShower::setHsv( int h, int s, int v ) | 1275 | void QColorShower::setHsv( int h, int s, int v ) |
1274 | { | 1276 | { |
1275 | rgbOriginal = FALSE; | 1277 | rgbOriginal = FALSE; |
1276 | hue = h; val = v; sat = s; //Range check### | 1278 | hue = h; val = v; sat = s; //Range check### |
1277 | curCol = QColor( hue, sat, val, QColor::Hsv ).rgb(); | 1279 | curCol = QColor( hue, sat, val, QColor::Hsv ).rgb(); |
1278 | 1280 | ||
1279 | hEd->setNum( hue ); | 1281 | hEd->setNum( hue ); |
1280 | sEd->setNum( sat ); | 1282 | sEd->setNum( sat ); |
1281 | vEd->setNum( val ); | 1283 | vEd->setNum( val ); |
1282 | 1284 | ||
1283 | rEd->setNum( qRed(currentColor()) ); | 1285 | rEd->setNum( qRed(currentColor()) ); |
1284 | gEd->setNum( qGreen(currentColor()) ); | 1286 | gEd->setNum( qGreen(currentColor()) ); |
1285 | bEd->setNum( qBlue(currentColor()) ); | 1287 | bEd->setNum( qBlue(currentColor()) ); |
1286 | 1288 | ||
1287 | 1289 | ||
1288 | showCurrentColor(); | 1290 | showCurrentColor(); |
1289 | } | 1291 | } |
1290 | 1292 | ||
1291 | class QColorDialogPrivate : public QObject | 1293 | class QColorDialogPrivate : public QObject |
1292 | { | 1294 | { |
1293 | Q_OBJECT | 1295 | Q_OBJECT |
1294 | public: | 1296 | public: |
1295 | QColorDialogPrivate( QColorDialog *p ); | 1297 | QColorDialogPrivate( QColorDialog *p ); |
1296 | QRgb currentColor() const { return cs->currentColor(); } | 1298 | QRgb currentColor() const { return cs->currentColor(); } |
1297 | void setCurrentColor( QRgb rgb ); | 1299 | void setCurrentColor( QRgb rgb ); |
1298 | 1300 | ||
1299 | int currentAlpha() const { return cs->currentAlpha(); } | 1301 | int currentAlpha() const { return cs->currentAlpha(); } |
1300 | void setCurrentAlpha( int a ) { cs->setCurrentAlpha( a ); } | 1302 | void setCurrentAlpha( int a ) { cs->setCurrentAlpha( a ); } |
1301 | void showAlpha( bool b ) { cs->showAlpha( b ); } | 1303 | void showAlpha( bool b ) { cs->showAlpha( b ); } |
1302 | 1304 | ||
1303 | private slots: | 1305 | private slots: |
1304 | void addCustom(); | 1306 | void addCustom(); |
1305 | 1307 | ||
1306 | void newHsv( int h, int s, int v ); | 1308 | void newHsv( int h, int s, int v ); |
1307 | void newColorTypedIn( QRgb rgb ); | 1309 | void newColorTypedIn( QRgb rgb ); |
1308 | void newCustom( int, int ); | 1310 | void newCustom( int, int ); |
1309 | void newStandard( int, int ); | 1311 | void newStandard( int, int ); |
1310 | private: | 1312 | private: |
1311 | QColorPicker *cp; | 1313 | QColorPicker *cp; |
1312 | QColorLuminancePicker *lp; | 1314 | QColorLuminancePicker *lp; |
1313 | QWellArray *custom; | 1315 | QWellArray *custom; |
1314 | QWellArray *standard; | 1316 | QWellArray *standard; |
1315 | QColorShower *cs; | 1317 | QColorShower *cs; |
1316 | int nextCust; | 1318 | int nextCust; |
1317 | bool compact; | 1319 | bool compact; |
1318 | }; | 1320 | }; |
1319 | 1321 | ||
1320 | //sets all widgets to display h,s,v | 1322 | //sets all widgets to display h,s,v |
1321 | void QColorDialogPrivate::newHsv( int h, int s, int v ) | 1323 | void QColorDialogPrivate::newHsv( int h, int s, int v ) |
1322 | { | 1324 | { |
1323 | cs->setHsv( h, s, v ); | 1325 | cs->setHsv( h, s, v ); |
1324 | cp->setCol( h, s ); | 1326 | cp->setCol( h, s ); |
1325 | lp->setCol( h, s, v ); | 1327 | lp->setCol( h, s, v ); |
1326 | } | 1328 | } |
1327 | 1329 | ||
1328 | //sets all widgets to display rgb | 1330 | //sets all widgets to display rgb |
1329 | void QColorDialogPrivate::setCurrentColor( QRgb rgb ) | 1331 | void QColorDialogPrivate::setCurrentColor( QRgb rgb ) |
1330 | { | 1332 | { |
1331 | cs->setRgb( rgb ); | 1333 | cs->setRgb( rgb ); |
1332 | newColorTypedIn( rgb ); | 1334 | newColorTypedIn( rgb ); |
1333 | } | 1335 | } |
1334 | 1336 | ||
1335 | //sets all widgets exept cs to display rgb | 1337 | //sets all widgets exept cs to display rgb |
1336 | void QColorDialogPrivate::newColorTypedIn( QRgb rgb ) | 1338 | void QColorDialogPrivate::newColorTypedIn( QRgb rgb ) |
1337 | { | 1339 | { |
1338 | int h, s, v; | 1340 | int h, s, v; |
1339 | rgb2hsv(rgb, h, s, v ); | 1341 | rgb2hsv(rgb, h, s, v ); |
1340 | cp->setCol( h, s ); | 1342 | cp->setCol( h, s ); |
1341 | lp->setCol( h, s, v); | 1343 | lp->setCol( h, s, v); |
1342 | } | 1344 | } |
1343 | 1345 | ||
1344 | void QColorDialogPrivate::newCustom( int r, int c ) | 1346 | void QColorDialogPrivate::newCustom( int r, int c ) |
1345 | { | 1347 | { |
1346 | int i = r+2*c; | 1348 | int i = r+2*c; |
1347 | setCurrentColor( cusrgb[i] ); | 1349 | setCurrentColor( cusrgb[i] ); |
1348 | nextCust = i; | 1350 | nextCust = i; |
1349 | standard->setSelected(-1,-1); | 1351 | standard->setSelected(-1,-1); |
1350 | } | 1352 | } |
1351 | 1353 | ||
1352 | void QColorDialogPrivate::newStandard( int r, int c ) | 1354 | void QColorDialogPrivate::newStandard( int r, int c ) |
1353 | { | 1355 | { |
1354 | setCurrentColor( stdrgb[r+c*6] ); | 1356 | setCurrentColor( stdrgb[r+c*6] ); |
1355 | custom->setSelected(-1,-1); | 1357 | custom->setSelected(-1,-1); |
1356 | } | 1358 | } |
1357 | 1359 | ||
1358 | QColorDialogPrivate::QColorDialogPrivate( QColorDialog *dialog ) : | 1360 | QColorDialogPrivate::QColorDialogPrivate( QColorDialog *dialog ) : |
1359 | QObject(dialog) | 1361 | QObject(dialog) |
1360 | { | 1362 | { |
1361 | compact = FALSE; | 1363 | compact = FALSE; |
1362 | // small displays (e.g. PDAs cannot fit the full color dialog, | 1364 | // small displays (e.g. PDAs cannot fit the full color dialog, |
1363 | // so just use the color picker. | 1365 | // so just use the color picker. |
1364 | if ( qApp->desktop()->width() < 480 || qApp->desktop()->height() < 350 ) | 1366 | if ( qApp->desktop()->width() < 480 || qApp->desktop()->height() < 350 ) |
1365 | compact = TRUE; | 1367 | compact = TRUE; |
1366 | 1368 | ||
1367 | nextCust = 0; | 1369 | nextCust = 0; |
1368 | const int lumSpace = 3; | 1370 | const int lumSpace = 3; |
1369 | int border = 12; | 1371 | int border = 12; |
1370 | if ( compact ) | 1372 | if ( compact ) |
1371 | border = 6; | 1373 | border = 6; |
1372 | QHBoxLayout *topLay = new QHBoxLayout( dialog, border, 6 ); | 1374 | QHBoxLayout *topLay = new QHBoxLayout( dialog, border, 6 ); |
1373 | QVBoxLayout *leftLay = 0; | 1375 | QVBoxLayout *leftLay = 0; |
1374 | 1376 | ||
1375 | if ( !compact ) | 1377 | if ( !compact ) |
1376 | leftLay = new QVBoxLayout( topLay ); | 1378 | leftLay = new QVBoxLayout( topLay ); |
1377 | 1379 | ||
1378 | initRGB(); | 1380 | initRGB(); |
1379 | 1381 | ||
1380 | if ( !compact ) { | 1382 | if ( !compact ) { |
1381 | standard = new QColorWell( dialog, 6, 8, stdrgb ); | 1383 | standard = new QColorWell( dialog, 6, 8, stdrgb ); |
1382 | standard->setCellSize( 28, 24 ); | 1384 | standard->setCellSize( 28, 24 ); |
1383 | QLabel * lab = new QLabel( standard, | 1385 | QLabel * lab = new QLabel( standard, |
1384 | QColorDialog::tr( "&Basic colors"), dialog ); | 1386 | QColorDialog::tr( "&Basic colors"), dialog ); |
1385 | connect( standard, SIGNAL(selected(int,int)), SLOT(newStandard(int,int))); | 1387 | connect( standard, SIGNAL(selected(int,int)), SLOT(newStandard(int,int))); |
1386 | leftLay->addWidget( lab ); | 1388 | leftLay->addWidget( lab ); |
1387 | leftLay->addWidget( standard ); | 1389 | leftLay->addWidget( standard ); |
1388 | 1390 | ||
1389 | 1391 | ||
1390 | leftLay->addStretch(); | 1392 | leftLay->addStretch(); |
1391 | 1393 | ||
1392 | custom = new QColorWell( dialog, 2, 8, cusrgb ); | 1394 | custom = new QColorWell( dialog, 2, 8, cusrgb ); |
1393 | custom->setCellSize( 28, 24 ); | 1395 | custom->setCellSize( 28, 24 ); |
1394 | custom->setAcceptDrops( TRUE ); | 1396 | custom->setAcceptDrops( TRUE ); |
1395 | 1397 | ||
1396 | connect( custom, SIGNAL(selected(int,int)), SLOT(newCustom(int,int))); | 1398 | connect( custom, SIGNAL(selected(int,int)), SLOT(newCustom(int,int))); |
1397 | lab = new QLabel( custom, QColorDialog::tr( "&Custom colors") , dialog ); | 1399 | lab = new QLabel( custom, QColorDialog::tr( "&Custom colors") , dialog ); |
1398 | leftLay->addWidget( lab ); | 1400 | leftLay->addWidget( lab ); |
1399 | leftLay->addWidget( custom ); | 1401 | leftLay->addWidget( custom ); |
1400 | 1402 | ||
1401 | QPushButton *custbut = | 1403 | QPushButton *custbut = |
1402 | new QPushButton( QColorDialog::tr("&Define Custom Colors >>"), | 1404 | new QPushButton( QColorDialog::tr("&Define Custom Colors >>"), |
1403 | dialog ); | 1405 | dialog ); |
1404 | custbut->setEnabled( FALSE ); | 1406 | custbut->setEnabled( FALSE ); |
1405 | leftLay->addWidget( custbut ); | 1407 | leftLay->addWidget( custbut ); |
1406 | } else { | 1408 | } else { |
1407 | // better color picker size for small displays | 1409 | // better color picker size for small displays |
1408 | pWidth = 150; | 1410 | pWidth = 150; |
1409 | pHeight = 100; | 1411 | pHeight = 100; |
1410 | } | 1412 | } |
1411 | 1413 | ||
1412 | QVBoxLayout *rightLay = new QVBoxLayout( topLay ); | 1414 | QVBoxLayout *rightLay = new QVBoxLayout( topLay ); |
1413 | 1415 | ||
1414 | QHBoxLayout *pickLay = new QHBoxLayout( rightLay ); | 1416 | QHBoxLayout *pickLay = new QHBoxLayout( rightLay ); |
1415 | 1417 | ||
1416 | 1418 | ||
1417 | QVBoxLayout *cLay = new QVBoxLayout( pickLay ); | 1419 | QVBoxLayout *cLay = new QVBoxLayout( pickLay ); |
1418 | cp = new QColorPicker( dialog ); | 1420 | cp = new QColorPicker( dialog ); |
1419 | cp->setFrameStyle( QFrame::Panel + QFrame::Sunken ); | 1421 | cp->setFrameStyle( QFrame::Panel + QFrame::Sunken ); |
1420 | cLay->addSpacing( lumSpace ); | 1422 | cLay->addSpacing( lumSpace ); |
1421 | cLay->addWidget( cp ); | 1423 | cLay->addWidget( cp ); |
1422 | cLay->addSpacing( lumSpace ); | 1424 | cLay->addSpacing( lumSpace ); |
1423 | 1425 | ||
1424 | lp = new QColorLuminancePicker( dialog ); | 1426 | lp = new QColorLuminancePicker( dialog ); |
1425 | lp->setFixedWidth( 20 ); //### | 1427 | lp->setFixedWidth( 20 ); //### |
1426 | pickLay->addWidget( lp ); | 1428 | pickLay->addWidget( lp ); |
1427 | 1429 | ||
1428 | connect( cp, SIGNAL(newCol(int,int)), lp, SLOT(setCol(int,int)) ); | 1430 | connect( cp, SIGNAL(newCol(int,int)), lp, SLOT(setCol(int,int)) ); |
1429 | connect( lp, SIGNAL(newHsv(int,int,int)), this, SLOT(newHsv(int,int,int)) ); | 1431 | connect( lp, SIGNAL(newHsv(int,int,int)), this, SLOT(newHsv(int,int,int)) ); |
1430 | 1432 | ||
1431 | rightLay->addStretch(); | 1433 | rightLay->addStretch(); |
1432 | 1434 | ||
1433 | cs = new QColorShower( dialog ); | 1435 | cs = new QColorShower( dialog ); |
1434 | connect( cs, SIGNAL(newCol(QRgb)), this, SLOT(newColorTypedIn(QRgb))); | 1436 | connect( cs, SIGNAL(newCol(QRgb)), this, SLOT(newColorTypedIn(QRgb))); |
1435 | rightLay->addWidget( cs ); | 1437 | rightLay->addWidget( cs ); |
1436 | 1438 | ||
1437 | QHBoxLayout *buttons; | 1439 | QHBoxLayout *buttons; |
1438 | if ( compact ) | 1440 | if ( compact ) |
1439 | buttons = new QHBoxLayout( rightLay ); | 1441 | buttons = new QHBoxLayout( rightLay ); |
1440 | else | 1442 | else |
1441 | buttons = new QHBoxLayout( leftLay ); | 1443 | buttons = new QHBoxLayout( leftLay ); |
1442 | 1444 | ||
1443 | QPushButton *ok, *cancel; | 1445 | QPushButton *ok, *cancel; |
1444 | ok = new QPushButton( QColorDialog::tr("OK"), dialog ); | 1446 | ok = new QPushButton( QColorDialog::tr("OK"), dialog ); |
1445 | connect( ok, SIGNAL(clicked()), dialog, SLOT(accept()) ); | 1447 | connect( ok, SIGNAL(clicked()), dialog, SLOT(accept()) ); |
1446 | ok->setDefault(TRUE); | 1448 | ok->setDefault(TRUE); |
1447 | cancel = new QPushButton( QColorDialog::tr("Cancel"), dialog ); | 1449 | cancel = new QPushButton( QColorDialog::tr("Cancel"), dialog ); |
1448 | connect( cancel, SIGNAL(clicked()), dialog, SLOT(reject()) ); | 1450 | connect( cancel, SIGNAL(clicked()), dialog, SLOT(reject()) ); |
1449 | buttons->addWidget( ok ); | 1451 | buttons->addWidget( ok ); |
1450 | buttons->addWidget( cancel ); | 1452 | buttons->addWidget( cancel ); |
1451 | buttons->addStretch(); | 1453 | buttons->addStretch(); |
1452 | 1454 | ||
1453 | if ( !compact ) { | 1455 | if ( !compact ) { |
1454 | QPushButton *addCusBt = new QPushButton( | 1456 | QPushButton *addCusBt = new QPushButton( |
1455 | QColorDialog::tr("&Add To Custom Colors"), | 1457 | QColorDialog::tr("&Add To Custom Colors"), |
1456 | dialog ); | 1458 | dialog ); |
1457 | rightLay->addWidget( addCusBt ); | 1459 | rightLay->addWidget( addCusBt ); |
1458 | connect( addCusBt, SIGNAL(clicked()), this, SLOT(addCustom()) ); | 1460 | connect( addCusBt, SIGNAL(clicked()), this, SLOT(addCustom()) ); |
1459 | } | 1461 | } |
1460 | } | 1462 | } |
1461 | 1463 | ||
1462 | void QColorDialogPrivate::addCustom() | 1464 | void QColorDialogPrivate::addCustom() |
1463 | { | 1465 | { |
1464 | cusrgb[nextCust] = cs->currentColor(); | 1466 | cusrgb[nextCust] = cs->currentColor(); |
1465 | custom->repaint( FALSE ); //### | 1467 | custom->repaint( FALSE ); //### |
1466 | nextCust = (nextCust+1) % 16; | 1468 | nextCust = (nextCust+1) % 16; |
1467 | } | 1469 | } |
1468 | 1470 | ||
1469 | 1471 | ||
1470 | // BEING REVISED: jo | 1472 | // BEING REVISED: jo |
1471 | /*! | 1473 | /*! |
1472 | \class QColorDialog qcolordialog.h | 1474 | \class QColorDialog qcolordialog.h |
1473 | \brief The QColorDialog class provides a dialog widget for specifying colors. | 1475 | \brief The QColorDialog class provides a dialog widget for specifying colors. |
1474 | \ingroup dialogs | 1476 | \ingroup dialogs |
1475 | 1477 | ||
1476 | The color dialog's function is to allow users to choose colors - | 1478 | The color dialog's function is to allow users to choose colors - |
1477 | for instance, you might use this in a drawing program to allow the | 1479 | for instance, you might use this in a drawing program to allow the |
1478 | user to set the brush color. | 1480 | user to set the brush color. |
1479 | 1481 | ||
1480 | This version of Qt only provides modal color dialogs. The static | 1482 | This version of Qt only provides modal color dialogs. The static |
1481 | getColor() function shows the dialog and allows the user to specify a color, | 1483 | getColor() function shows the dialog and allows the user to specify a color, |
1482 | while getRgba() does the same but allows the user to specify a color with an | 1484 | while getRgba() does the same but allows the user to specify a color with an |
1483 | alpha channel (transparency) value. | 1485 | alpha channel (transparency) value. |
1484 | 1486 | ||
1485 | The user can store customCount() different custom colors. The custom | 1487 | The user can store customCount() different custom colors. The custom |
1486 | colors are shared by all color dialogs, and remembered during the | 1488 | colors are shared by all color dialogs, and remembered during the |
1487 | execution of the program. Use setCustomColor() to set the | 1489 | execution of the program. Use setCustomColor() to set the |
1488 | custom colors, and customColor() to get them. | 1490 | custom colors, and customColor() to get them. |
1489 | 1491 | ||
1490 | <img src=qcolordlg-m.png> <img src=qcolordlg-w.png> | 1492 | <img src=qcolordlg-m.png> <img src=qcolordlg-w.png> |
1491 | */ | 1493 | */ |
1492 | 1494 | ||
1493 | /*! | 1495 | /*! |
1494 | Constructs a default color dialog. Use setColor() for setting an initial value. | 1496 | Constructs a default color dialog. Use setColor() for setting an initial value. |
1495 | 1497 | ||
1496 | \sa getColor() | 1498 | \sa getColor() |
1497 | */ | 1499 | */ |
1498 | 1500 | ||
1499 | QColorDialog::QColorDialog(QWidget* parent, const char* name, bool modal) : | 1501 | QColorDialog::QColorDialog(QWidget* parent, const char* name, bool modal) : |
1500 | QDialog(parent, name, modal ) | 1502 | QDialog(parent, name, modal ) |
1501 | { | 1503 | { |
1502 | setSizeGripEnabled( TRUE ); | 1504 | setSizeGripEnabled( TRUE ); |
1503 | d = new QColorDialogPrivate( this ); | 1505 | d = new QColorDialogPrivate( this ); |
1504 | } | 1506 | } |
1505 | 1507 | ||
1506 | 1508 | ||
1507 | /*! | 1509 | /*! |
1508 | Pops up a modal color dialog letting the user choose a color and returns | 1510 | Pops up a modal color dialog letting the user choose a color and returns |
1509 | that color. The color is initially set to \a initial. Returns an \link QColor::isValid() invalid\endlink color if the user cancels | 1511 | that color. The color is initially set to \a initial. Returns an \link QColor::isValid() invalid\endlink color if the user cancels |
1510 | the dialog. All colors allocated by the dialog will be deallocated | 1512 | the dialog. All colors allocated by the dialog will be deallocated |
1511 | before this function returns. | 1513 | before this function returns. |
1512 | */ | 1514 | */ |
1513 | 1515 | ||
1514 | QColor QColorDialog::getColor( QColor initial, QWidget *parent, | 1516 | QColor QColorDialog::getColor( QColor initial, QWidget *parent, |
1515 | const char *name ) | 1517 | const char *name ) |
1516 | { | 1518 | { |
1517 | int allocContext = QColor::enterAllocContext(); | 1519 | int allocContext = QColor::enterAllocContext(); |
1518 | QColorDialog *dlg = new QColorDialog( parent, name, TRUE ); //modal | 1520 | QColorDialog *dlg = new QColorDialog( parent, name, TRUE ); //modal |
1519 | if ( parent && parent->icon() && !parent->icon()->isNull() ) | 1521 | if ( parent && parent->icon() && !parent->icon()->isNull() ) |
1520 | dlg->setIcon( *parent->icon() ); | 1522 | dlg->setIcon( *parent->icon() ); |
1521 | else if ( qApp->mainWidget() && qApp->mainWidget()->icon() && !qApp->mainWidget()->icon()->isNull() ) | 1523 | else if ( qApp->mainWidget() && qApp->mainWidget()->icon() && !qApp->mainWidget()->icon()->isNull() ) |
1522 | dlg->setIcon( *qApp->mainWidget()->icon() ); | 1524 | dlg->setIcon( *qApp->mainWidget()->icon() ); |
1523 | 1525 | ||
1524 | dlg->setCaption( QColorDialog::tr( "Select color" ) ); | 1526 | dlg->setCaption( QColorDialog::tr( "Select color" ) ); |
1525 | dlg->setColor( initial ); | 1527 | dlg->setColor( initial ); |
1526 | int resultCode = dlg->exec(); | 1528 | int resultCode = dlg->exec(); |
1527 | QColor::leaveAllocContext(); | 1529 | QColor::leaveAllocContext(); |
1528 | QColor result; | 1530 | QColor result; |
1529 | if ( resultCode == QDialog::Accepted ) | 1531 | if ( resultCode == QDialog::Accepted ) |
1530 | result = dlg->color(); | 1532 | result = dlg->color(); |
1531 | QColor::destroyAllocContext(allocContext); | 1533 | QColor::destroyAllocContext(allocContext); |
1532 | delete dlg; | 1534 | delete dlg; |
1533 | return result; | 1535 | return result; |
1534 | } | 1536 | } |
1535 | 1537 | ||
1536 | 1538 | ||
1537 | /*! | 1539 | /*! |
1538 | Pops up a modal color dialog, letting the user choose a color and an | 1540 | Pops up a modal color dialog, letting the user choose a color and an |
1539 | alpha channel value. The color+alpha is initially set to \a initial. | 1541 | alpha channel value. The color+alpha is initially set to \a initial. |
1540 | 1542 | ||
1541 | If \a ok is non-null, \c *ok is set to TRUE if the user clicked OK, | 1543 | If \a ok is non-null, \c *ok is set to TRUE if the user clicked OK, |
1542 | and FALSE if the user clicked Cancel. | 1544 | and FALSE if the user clicked Cancel. |
1543 | 1545 | ||
1544 | If the user clicks Cancel the \a initial value is returned. | 1546 | If the user clicks Cancel the \a initial value is returned. |
1545 | */ | 1547 | */ |
1546 | 1548 | ||
1547 | QRgb QColorDialog::getRgba( QRgb initial, bool *ok, | 1549 | QRgb QColorDialog::getRgba( QRgb initial, bool *ok, |
1548 | QWidget *parent, const char* name ) | 1550 | QWidget *parent, const char* name ) |
1549 | { | 1551 | { |
1550 | int allocContext = QColor::enterAllocContext(); | 1552 | int allocContext = QColor::enterAllocContext(); |
1551 | QColorDialog *dlg = new QColorDialog( parent, name, TRUE ); //modal | 1553 | QColorDialog *dlg = new QColorDialog( parent, name, TRUE ); //modal |
1552 | dlg->setColor( initial ); | 1554 | dlg->setColor( initial ); |
1553 | dlg->setSelectedAlpha( qAlpha(initial) ); | 1555 | dlg->setSelectedAlpha( qAlpha(initial) ); |
1554 | int resultCode = dlg->exec(); | 1556 | int resultCode = dlg->exec(); |
1555 | QColor::leaveAllocContext(); | 1557 | QColor::leaveAllocContext(); |
1556 | QRgb result = initial; | 1558 | QRgb result = initial; |
1557 | if ( resultCode == QDialog::Accepted ) { | 1559 | if ( resultCode == QDialog::Accepted ) { |
1558 | QRgb c = dlg->color().rgb(); | 1560 | QRgb c = dlg->color().rgb(); |
1559 | int alpha = dlg->selectedAlpha(); | 1561 | int alpha = dlg->selectedAlpha(); |
1560 | result = qRgba( qRed(c), qGreen(c), qBlue(c), alpha ); | 1562 | result = qRgba( qRed(c), qGreen(c), qBlue(c), alpha ); |
1561 | } | 1563 | } |
1562 | if ( ok ) | 1564 | if ( ok ) |
1563 | *ok = resultCode == QDialog::Accepted; | 1565 | *ok = resultCode == QDialog::Accepted; |
1564 | 1566 | ||
1565 | QColor::destroyAllocContext(allocContext); | 1567 | QColor::destroyAllocContext(allocContext); |
1566 | delete dlg; | 1568 | delete dlg; |
1567 | return result; | 1569 | return result; |
1568 | } | 1570 | } |
1569 | 1571 | ||
1570 | 1572 | ||
1571 | 1573 | ||
1572 | 1574 | ||
1573 | 1575 | ||
1574 | /*! | 1576 | /*! |
1575 | Returns the color currently selected in the dialog. | 1577 | Returns the color currently selected in the dialog. |
1576 | 1578 | ||
1577 | \sa setColor() | 1579 | \sa setColor() |
1578 | */ | 1580 | */ |
1579 | 1581 | ||
1580 | QColor QColorDialog::color() const | 1582 | QColor QColorDialog::color() const |
1581 | { | 1583 | { |
1582 | return QColor(d->currentColor()); | 1584 | return QColor(d->currentColor()); |
1583 | } | 1585 | } |
1584 | 1586 | ||
1585 | 1587 | ||
1586 | /*! Destructs the dialog and frees any memory it allocated. | 1588 | /*! Destructs the dialog and frees any memory it allocated. |
1587 | 1589 | ||
1588 | */ | 1590 | */ |
1589 | 1591 | ||
1590 | QColorDialog::~QColorDialog() | 1592 | QColorDialog::~QColorDialog() |
1591 | { | 1593 | { |
1592 | //d inherits QObject, so it is deleted by Qt. | 1594 | //d inherits QObject, so it is deleted by Qt. |
1593 | } | 1595 | } |
1594 | 1596 | ||
1595 | 1597 | ||
1596 | /*! | 1598 | /*! |
1597 | Sets the color shown in the dialog to \a c. | 1599 | Sets the color shown in the dialog to \a c. |
1598 | 1600 | ||
1599 | \sa color() | 1601 | \sa color() |
1600 | */ | 1602 | */ |
1601 | 1603 | ||
1602 | void QColorDialog::setColor( QColor c ) | 1604 | void QColorDialog::setColor( QColor c ) |
1603 | { | 1605 | { |
1604 | d->setCurrentColor( c.rgb() ); | 1606 | d->setCurrentColor( c.rgb() ); |
1605 | } | 1607 | } |
1606 | 1608 | ||
1607 | 1609 | ||
1608 | 1610 | ||
1609 | 1611 | ||
1610 | /*! | 1612 | /*! |
1611 | Sets the initial alpha channel value to \a a, and show the alpha channel | 1613 | Sets the initial alpha channel value to \a a, and show the alpha channel |
1612 | entry box. | 1614 | entry box. |
1613 | */ | 1615 | */ |
1614 | 1616 | ||
1615 | void QColorDialog::setSelectedAlpha( int a ) | 1617 | void QColorDialog::setSelectedAlpha( int a ) |
1616 | { | 1618 | { |
1617 | d->showAlpha( TRUE ); | 1619 | d->showAlpha( TRUE ); |
1618 | d->setCurrentAlpha( a ); | 1620 | d->setCurrentAlpha( a ); |
1619 | } | 1621 | } |
1620 | 1622 | ||
1621 | 1623 | ||
1622 | /*! | 1624 | /*! |
1623 | Returns the value selected for the alpha channel. | 1625 | Returns the value selected for the alpha channel. |
1624 | */ | 1626 | */ |
1625 | 1627 | ||
1626 | int QColorDialog::selectedAlpha() const | 1628 | int QColorDialog::selectedAlpha() const |
1627 | { | 1629 | { |
1628 | return d->currentAlpha(); | 1630 | return d->currentAlpha(); |
1629 | } | 1631 | } |
1630 | 1632 | ||
1631 | 1633 | ||
1632 | #include "qcolordialog.moc" \ No newline at end of file | 1634 | #include "qcolordialog.moc" |