summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libqtaux/qcolordialog.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/libqtaux/qcolordialog.cpp b/libqtaux/qcolordialog.cpp
index 907c2aa..ccef0ad 100644
--- a/libqtaux/qcolordialog.cpp
+++ b/libqtaux/qcolordialog.cpp
@@ -1,822 +1,826 @@
1/**************************************************************************** 1/****************************************************************************
2** $Id$ 2** $Id$
3** 3**
4** Implementation of QColorDialog class 4** Implementation of QColorDialog class
5** 5**
6** Created : 990222 6** Created : 990222
7** 7**
8** Copyright (C) 1999-2000 Trolltech AS. All rights reserved. 8** Copyright (C) 1999-2000 Trolltech AS. All rights reserved.
9** 9**
10** This file is part of the dialogs module of the Qt GUI Toolkit. 10** This file is part of the dialogs module of the Qt GUI Toolkit.
11** 11**
12** This file may be distributed under the terms of the Q Public License 12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file 13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file. 14** LICENSE.QPL included in the packaging of this file.
15** 15**
16** This file may be distributed and/or modified under the terms of the 16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software 17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the 18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file. 19** packaging of this file.
20** 20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition 21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License 22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software. 23** Agreement provided with the Software.
24** 24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27** 27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements. 29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information. 30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information. 31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32** 32**
33** Contact info@trolltech.com if any conditions of this licensing are 33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you. 34** not clear to you.
35** 35**
36**********************************************************************/ 36**********************************************************************/
37 37
38#include "qcolordialog.h" 38#include "qcolordialog.h"
39 39
40#include "qpainter.h" 40#include "qpainter.h"
41#include "qlayout.h" 41#include "qlayout.h"
42#include "qlabel.h" 42#include "qlabel.h"
43#include "qpushbutton.h" 43#include "qpushbutton.h"
44#include "qlineedit.h" 44#include "qlineedit.h"
45#include "qimage.h" 45#include "qimage.h"
46#include "qpixmap.h" 46#include "qpixmap.h"
47#include "qdrawutil.h" 47#include "qdrawutil.h"
48#include "qvalidator.h" 48#include "qvalidator.h"
49#include "qapplication.h" 49#include "qapplication.h"
50 50
51//////////// QWellArray BEGIN 51//////////// QWellArray BEGIN
52 52
53#include "qobjectdict.h" 53#include "qobjectdict.h"
54 54
55#ifndef QT_NO_DRAGANDDROP
56#include "qdragobject.h"
57#endif
58
55// 59//
56// W A R N I N G 60// W A R N I N G
57// ------------- 61// -------------
58// 62//
59// This file is not part of the Qt API. It exists for the convenience 63// This file is not part of the Qt API. It exists for the convenience
60// of qwellarray.cpp and qcolordialog.cpp. 64// of qwellarray.cpp and qcolordialog.cpp.
61// This header file may change from version to version without notice, 65// This header file may change from version to version without notice,
62// or even be removed. 66// or even be removed.
63// 67//
64// 68//
65 69
66 70
67#include "qtableview.h" 71#include "qtableview.h"
68 72
69 73
70struct QWellArrayData; 74struct QWellArrayData;
71 75
72class QWellArray : public QTableView 76class QWellArray : public QTableView
73{ 77{
74 Q_OBJECT 78 Q_OBJECT
75 Q_PROPERTY( int numCols READ numCols ) 79 Q_PROPERTY( int numCols READ numCols )
76 Q_PROPERTY( int numRows READ numRows ) 80 Q_PROPERTY( int numRows READ numRows )
77 Q_PROPERTY( int selectedColumn READ selectedColumn ) 81 Q_PROPERTY( int selectedColumn READ selectedColumn )
78 Q_PROPERTY( int selectedRow READ selectedRow ) 82 Q_PROPERTY( int selectedRow READ selectedRow )
79 83
80public: 84public:
81 QWellArray( QWidget *parent=0, const char *name=0, bool popup = FALSE ); 85 QWellArray( QWidget *parent=0, const char *name=0, bool popup = FALSE );
82 86
83 ~QWellArray() {} 87 ~QWellArray() {}
84 QString cellContent( int row, int col ) const; 88 QString cellContent( int row, int col ) const;
85 // ### Paul !!! virtual void setCellContent( int row, int col, const QString &); 89 // ### Paul !!! virtual void setCellContent( int row, int col, const QString &);
86 90
87 // ##### Obsolete since not const 91 // ##### Obsolete since not const
88 int numCols() { return nCols; } 92 int numCols() { return nCols; }
89 int numRows() { return nRows; } 93 int numRows() { return nRows; }
90 94
91 int numCols() const { return nCols; } 95 int numCols() const { return nCols; }
92 int numRows() const { return nRows; } 96 int numRows() const { return nRows; }
93 97
94 // ##### Obsolete since not const 98 // ##### Obsolete since not const
95 int selectedColumn() { return selCol; } 99 int selectedColumn() { return selCol; }
96 int selectedRow() { return selRow; } 100 int selectedRow() { return selRow; }
97 101
98 int selectedColumn() const { return selCol; } 102 int selectedColumn() const { return selCol; }
99 int selectedRow() const { return selRow; } 103 int selectedRow() const { return selRow; }
100 104
101 virtual void setSelected( int row, int col ); 105 virtual void setSelected( int row, int col );
102 106
103 void setCellSize( int w, int h ) { setCellWidth(w);setCellHeight( h ); } 107 void setCellSize( int w, int h ) { setCellWidth(w);setCellHeight( h ); }
104 108
105 QSize sizeHint() const; 109 QSize sizeHint() const;
106 110
107 virtual void setDimension( int rows, int cols ); 111 virtual void setDimension( int rows, int cols );
108 virtual void setCellBrush( int row, int col, const QBrush & ); 112 virtual void setCellBrush( int row, int col, const QBrush & );
109 QBrush cellBrush( int row, int col ); 113 QBrush cellBrush( int row, int col );
110 114
111signals: 115signals:
112 void selected( int row, int col ); 116 void selected( int row, int col );
113 117
114protected: 118protected:
115 virtual void setCurrent( int row, int col ); 119 virtual void setCurrent( int row, int col );
116 120
117 virtual void drawContents( QPainter *, int row, int col, const QRect& ); 121 virtual void drawContents( QPainter *, int row, int col, const QRect& );
118 void drawContents( QPainter * ); 122 void drawContents( QPainter * );
119 123
120 void paintCell( QPainter*, int row, int col ); 124 void paintCell( QPainter*, int row, int col );
121 void mousePressEvent( QMouseEvent* ); 125 void mousePressEvent( QMouseEvent* );
122 void mouseReleaseEvent( QMouseEvent* ); 126 void mouseReleaseEvent( QMouseEvent* );
123 void mouseMoveEvent( QMouseEvent* ); 127 void mouseMoveEvent( QMouseEvent* );
124 void keyPressEvent( QKeyEvent* ); 128 void keyPressEvent( QKeyEvent* );
125 void focusInEvent( QFocusEvent* ); 129 void focusInEvent( QFocusEvent* );
126 void focusOutEvent( QFocusEvent* ); 130 void focusOutEvent( QFocusEvent* );
127 131
128private: 132private:
129 int curRow; 133 int curRow;
130 int curCol; 134 int curCol;
131 int selRow; 135 int selRow;
132 int selCol; 136 int selCol;
133 int nCols; 137 int nCols;
134 int nRows; 138 int nRows;
135 bool smallStyle; 139 bool smallStyle;
136 QWellArrayData *d; 140 QWellArrayData *d;
137 141
138 private:// Disabled copy constructor and operator= 142 private:// Disabled copy constructor and operator=
139#if defined(Q_DISABLE_COPY) 143#if defined(Q_DISABLE_COPY)
140 QWellArray( const QWellArray & ); 144 QWellArray( const QWellArray & );
141 QWellArray& operator=( const QWellArray & ); 145 QWellArray& operator=( const QWellArray & );
142#endif 146#endif
143}; 147};
144 148
145 149
146 150
147// non-interface ... 151// non-interface ...
148 152
149 153
150 154
151struct QWellArrayData { 155struct QWellArrayData {
152 QBrush *brush; 156 QBrush *brush;
153}; 157};
154 158
155// NOT REVISED 159// NOT REVISED
156/* WARNING, NOT 160/* WARNING, NOT
157 \class QWellArray qwellarray_p.h 161 \class QWellArray qwellarray_p.h
158 \brief .... 162 \brief ....
159 163
160 .... 164 ....
161 165
162 \ingroup advanced 166 \ingroup advanced
163*/ 167*/
164 168
165QWellArray::QWellArray( QWidget *parent, const char * name, bool popup ) 169QWellArray::QWellArray( QWidget *parent, const char * name, bool popup )
166 : QTableView( parent, name, 170 : QTableView( parent, name,
167 popup ? (WStyle_Customize|WStyle_Tool|WStyle_NoBorder) : 0 ) 171 popup ? (WStyle_Customize|WStyle_Tool|WStyle_NoBorder) : 0 )
168{ 172{
169 d = 0; 173 d = 0;
170 setFocusPolicy( StrongFocus ); 174 setFocusPolicy( StrongFocus );
171 setBackgroundMode( PaletteButton ); 175 setBackgroundMode( PaletteButton );
172 nCols = 7; 176 nCols = 7;
173 nRows = 7; 177 nRows = 7;
174 int w = 24; // cell width 178 int w = 24; // cell width
175 int h = 21; // cell height 179 int h = 21; // cell height
176 smallStyle = popup; 180 smallStyle = popup;
177 181
178 if ( popup ) { 182 if ( popup ) {
179 w = h = 18; 183 w = h = 18;
180 if ( style() == WindowsStyle ) 184 if ( style() == WindowsStyle )
181 setFrameStyle( QFrame::WinPanel | QFrame::Raised ); 185 setFrameStyle( QFrame::WinPanel | QFrame::Raised );
182 else 186 else
183 setFrameStyle( QFrame::Panel | QFrame::Raised ); 187 setFrameStyle( QFrame::Panel | QFrame::Raised );
184 setMargin( 1 ); 188 setMargin( 1 );
185 setLineWidth( 2 ); 189 setLineWidth( 2 );
186 } 190 }
187 setNumCols( nCols ); 191 setNumCols( nCols );
188 setNumRows( nRows ); 192 setNumRows( nRows );
189 setCellWidth( w ); 193 setCellWidth( w );
190 setCellHeight( h ); 194 setCellHeight( h );
191 curCol = 0; 195 curCol = 0;
192 curRow = 0; 196 curRow = 0;
193 selCol = -1; 197 selCol = -1;
194 selRow = -1; 198 selRow = -1;
195 199
196 if ( smallStyle ) 200 if ( smallStyle )
197 setMouseTracking( TRUE ); 201 setMouseTracking( TRUE );
198 setOffset( 5 , 10 ); 202 setOffset( 5 , 10 );
199 203
200 resize( sizeHint() ); 204 resize( sizeHint() );
201 205
202} 206}
203 207
204 208
205QSize QWellArray::sizeHint() const 209QSize QWellArray::sizeHint() const
206{ 210{
207 constPolish(); 211 constPolish();
208 int f = frameWidth() * 2; 212 int f = frameWidth() * 2;
209 int w = nCols * cellWidth() + f; 213 int w = nCols * cellWidth() + f;
210 int h = nRows * cellHeight() + f; 214 int h = nRows * cellHeight() + f;
211 return QSize( w, h ); 215 return QSize( w, h );
212} 216}
213 217
214 218
215void QWellArray::paintCell( QPainter* p, int row, int col ) 219void QWellArray::paintCell( QPainter* p, int row, int col )
216{ 220{
217 int w = cellWidth( col ); // width of cell in pixels 221 int w = cellWidth( col ); // width of cell in pixels
218 int h = cellHeight( row ); // height of cell in pixels 222 int h = cellHeight( row ); // height of cell in pixels
219 int b = 1; 223 int b = 1;
220 224
221 if ( !smallStyle ) 225 if ( !smallStyle )
222 b = 3; 226 b = 3;
223 227
224 const QColorGroup & g = colorGroup(); 228 const QColorGroup & g = colorGroup();
225 p->setPen( QPen( black, 0, SolidLine ) ); 229 p->setPen( QPen( black, 0, SolidLine ) );
226 if ( !smallStyle && row ==selRow && col == selCol && 230 if ( !smallStyle && row ==selRow && col == selCol &&
227 style() != MotifStyle ) { 231 style() != MotifStyle ) {
228 int n = 2; 232 int n = 2;
229 p->drawRect( n, n, w-2*n, h-2*n ); 233 p->drawRect( n, n, w-2*n, h-2*n );
230 } 234 }
231 235
232 236
233 if ( style() == WindowsStyle ) { 237 if ( style() == WindowsStyle ) {
234 qDrawWinPanel( p, b, b , w - 2*b, h - 2*b, 238 qDrawWinPanel( p, b, b , w - 2*b, h - 2*b,
235 g, TRUE ); 239 g, TRUE );
236 b += 2; 240 b += 2;
237 } else { 241 } else {
238 if ( smallStyle ) { 242 if ( smallStyle ) {
239 qDrawShadePanel( p, b, b , w - 2*b, h - 2*b, 243 qDrawShadePanel( p, b, b , w - 2*b, h - 2*b,
240 g, TRUE, 2 ); 244 g, TRUE, 2 );
241 b += 2; 245 b += 2;
242 } else { 246 } else {
243 int t = ( row == selRow && col == selCol ) ? 2 : 0; 247 int t = ( row == selRow && col == selCol ) ? 2 : 0;
244 b -= t; 248 b -= t;
245 qDrawShadePanel( p, b, b , w - 2*b, h - 2*b, 249 qDrawShadePanel( p, b, b , w - 2*b, h - 2*b,
246 g, TRUE, 2 ); 250 g, TRUE, 2 );
247 b += 2 + t; 251 b += 2 + t;
248 } 252 }
249 } 253 }
250 254
251 255
252 if ( (row == curRow) && (col == curCol) ) { 256 if ( (row == curRow) && (col == curCol) ) {
253 if ( smallStyle ) { 257 if ( smallStyle ) {
254 p->setPen ( white ); 258 p->setPen ( white );
255 p->drawRect( 1, 1, w-2, h-2 ); 259 p->drawRect( 1, 1, w-2, h-2 );
256 p->setPen ( black ); 260 p->setPen ( black );
257 p->drawRect( 0, 0, w, h ); 261 p->drawRect( 0, 0, w, h );
258 p->drawRect( 2, 2, w-4, h-4 ); 262 p->drawRect( 2, 2, w-4, h-4 );
259 b = 3; 263 b = 3;
260 } else if ( hasFocus() ) { 264 } else if ( hasFocus() ) {
261 style().drawFocusRect(p, QRect(0,0,w,h), g ); 265 style().drawFocusRect(p, QRect(0,0,w,h), g );
262 } 266 }
263 } 267 }
264 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) );
265} 269}
266 270
267/*! 271/*!
268 Pass-through to QTableView::drawContents() to avoid hiding. 272 Pass-through to QTableView::drawContents() to avoid hiding.
269*/ 273*/
270void QWellArray::drawContents( QPainter *p ) 274void QWellArray::drawContents( QPainter *p )
271{ 275{
272 QTableView::drawContents(p); 276 QTableView::drawContents(p);
273} 277}
274 278
275/*! 279/*!
276 Reimplement this function to change the contents of the well array. 280 Reimplement this function to change the contents of the well array.
277 */ 281 */
278void QWellArray::drawContents( QPainter *p, int row, int col, const QRect &r ) 282void QWellArray::drawContents( QPainter *p, int row, int col, const QRect &r )
279{ 283{
280 284
281 if ( d ) { 285 if ( d ) {
282 p->fillRect( r, d->brush[row*nCols+col] ); 286 p->fillRect( r, d->brush[row*nCols+col] );
283 } else { 287 } else {
284 p->fillRect( r, white ); 288 p->fillRect( r, white );
285 p->setPen( black ); 289 p->setPen( black );
286 p->drawLine( r.topLeft(), r.bottomRight() ); 290 p->drawLine( r.topLeft(), r.bottomRight() );
287 p->drawLine( r.topRight(), r.bottomLeft() ); 291 p->drawLine( r.topRight(), r.bottomLeft() );
288 } 292 }
289} 293}
290 294
291 295
292/*\reimp 296/*\reimp
293*/ 297*/
294void QWellArray::mousePressEvent( QMouseEvent* e ) 298void QWellArray::mousePressEvent( QMouseEvent* e )
295{ 299{
296 // 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
297 // in. 301 // in.
298 QPoint pos = e->pos(); 302 QPoint pos = e->pos();
299 setCurrent( findRow( pos.y() ), findCol( pos.x() ) ); 303 setCurrent( findRow( pos.y() ), findCol( pos.x() ) );
300} 304}
301 305
302/*\reimp 306/*\reimp
303*/ 307*/
304void QWellArray::mouseReleaseEvent( QMouseEvent* ) 308void QWellArray::mouseReleaseEvent( QMouseEvent* )
305{ 309{
306 // 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
307 // in. 311 // in.
308 setSelected( curRow, curCol ); 312 setSelected( curRow, curCol );
309} 313}
310 314
311 315
312/*\reimp 316/*\reimp
313*/ 317*/
314void QWellArray::mouseMoveEvent( QMouseEvent* e ) 318void QWellArray::mouseMoveEvent( QMouseEvent* e )
315{ 319{
316 // 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
317 // clicked in. 321 // clicked in.
318 if ( smallStyle ) { 322 if ( smallStyle ) {
319 QPoint pos = e->pos(); 323 QPoint pos = e->pos();
320 setCurrent( findRow( pos.y() ), findCol( pos.x() ) ); 324 setCurrent( findRow( pos.y() ), findCol( pos.x() ) );
321 } 325 }
322} 326}
323 327
324/* 328/*
325 Sets the cell currently having the focus. This is not necessarily 329 Sets the cell currently having the focus. This is not necessarily
326 the same as the currently selected cell. 330 the same as the currently selected cell.
327*/ 331*/
328 332
329void QWellArray::setCurrent( int row, int col ) 333void QWellArray::setCurrent( int row, int col )
330{ 334{
331 335
332 if ( (curRow == row) && (curCol == col) ) 336 if ( (curRow == row) && (curCol == col) )
333 return; 337 return;
334 338
335 if ( row < 0 || col < 0 ) 339 if ( row < 0 || col < 0 )
336 row = col = -1; 340 row = col = -1;
337 341
338 int oldRow = curRow; 342 int oldRow = curRow;
339 int oldCol = curCol; 343 int oldCol = curCol;
340 344
341 curRow = row; 345 curRow = row;
342 curCol = col; 346 curCol = col;
343 347
344 updateCell( oldRow, oldCol ); 348 updateCell( oldRow, oldCol );
345 updateCell( curRow, curCol ); 349 updateCell( curRow, curCol );
346} 350}
347 351
348 352
349/*! 353/*!
350 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
351 col are less than zero, the current cell is unselected. 355 col are less than zero, the current cell is unselected.
352 356
353 Does not set the position of the focus indicator. 357 Does not set the position of the focus indicator.
354*/ 358*/
355 359
356void QWellArray::setSelected( int row, int col ) 360void QWellArray::setSelected( int row, int col )
357{ 361{
358 if ( (selRow == row) && (selCol == col) ) 362 if ( (selRow == row) && (selCol == col) )
359 return; 363 return;
360 364
361 int oldRow = selRow; 365 int oldRow = selRow;
362 int oldCol = selCol; 366 int oldCol = selCol;
363 367
364 if ( row < 0 || col < 0 ) 368 if ( row < 0 || col < 0 )
365 row = col = -1; 369 row = col = -1;
366 370
367 selCol = col; 371 selCol = col;
368 selRow = row; 372 selRow = row;
369 373
370 updateCell( oldRow, oldCol ); 374 updateCell( oldRow, oldCol );
371 updateCell( selRow, selCol ); 375 updateCell( selRow, selCol );
372 if ( row >= 0 ) 376 if ( row >= 0 )
373 emit selected( row, col ); 377 emit selected( row, col );
374 378
375 if ( isVisible() && parentWidget() && parentWidget()->inherits("QPopupMenu") ) 379 if ( isVisible() && parentWidget() && parentWidget()->inherits("QPopupMenu") )
376 parentWidget()->close(); 380 parentWidget()->close();
377 381
378} 382}
379 383
380 384
381 385
382/*!\reimp 386/*!\reimp
383*/ 387*/
384void QWellArray::focusInEvent( QFocusEvent* ) 388void QWellArray::focusInEvent( QFocusEvent* )
385{ 389{
386 updateCell( curRow, curCol ); 390 updateCell( curRow, curCol );
387} 391}
388 392
389 393
390/*! 394/*!
391 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.
392 Resets any brush info set by setCellBrush(). 396 Resets any brush info set by setCellBrush().
393 397
394 Must be called by reimplementors. 398 Must be called by reimplementors.
395 */ 399 */
396void QWellArray::setDimension( int rows, int cols ) 400void QWellArray::setDimension( int rows, int cols )
397{ 401{
398 nRows = rows; 402 nRows = rows;
399 nCols = cols; 403 nCols = cols;
400 if ( d ) { 404 if ( d ) {
401 if ( d->brush ) 405 if ( d->brush )
402 delete[] d->brush; 406 delete[] d->brush;
403 delete d; 407 delete d;
404 d = 0; 408 d = 0;
405 } 409 }
406 setNumCols( nCols ); 410 setNumCols( nCols );
407 setNumRows( nRows ); 411 setNumRows( nRows );
408} 412}
409 413
410void QWellArray::setCellBrush( int row, int col, const QBrush &b ) 414void QWellArray::setCellBrush( int row, int col, const QBrush &b )
411{ 415{
412 if ( !d ) { 416 if ( !d ) {
413 d = new QWellArrayData; 417 d = new QWellArrayData;
414 d->brush = new QBrush[nRows*nCols]; 418 d->brush = new QBrush[nRows*nCols];
415 } 419 }
416 if ( row >= 0 && row < nRows && col >= 0 && col < nCols ) 420 if ( row >= 0 && row < nRows && col >= 0 && col < nCols )
417 d->brush[row*nCols+col] = b; 421 d->brush[row*nCols+col] = b;
418#ifdef CHECK_RANGE 422#ifdef CHECK_RANGE
419 else 423 else
420 qWarning( "QWellArray::setCellBrush( %d, %d ) out of range", row, col ); 424 qWarning( "QWellArray::setCellBrush( %d, %d ) out of range", row, col );
421#endif 425#endif
422} 426}
423 427
424 428
425 429
426/*! 430/*!
427 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,
428 \c NoBrush is returned. 432 \c NoBrush is returned.
429*/ 433*/
430 434
431QBrush QWellArray::cellBrush( int row, int col ) 435QBrush QWellArray::cellBrush( int row, int col )
432{ 436{
433 if ( d && row >= 0 && row < nRows && col >= 0 && col < nCols ) 437 if ( d && row >= 0 && row < nRows && col >= 0 && col < nCols )
434 return d->brush[row*nCols+col]; 438 return d->brush[row*nCols+col];
435 return NoBrush; 439 return NoBrush;
436} 440}
437 441
438 442
439 443
440/*!\reimp 444/*!\reimp
441*/ 445*/
442 446
443void QWellArray::focusOutEvent( QFocusEvent* ) 447void QWellArray::focusOutEvent( QFocusEvent* )
444{ 448{
445 updateCell( curRow, curCol ); 449 updateCell( curRow, curCol );
446} 450}
447 451
448/*\reimp 452/*\reimp
449*/ 453*/
450void QWellArray::keyPressEvent( QKeyEvent* e ) 454void QWellArray::keyPressEvent( QKeyEvent* e )
451{ 455{
452 switch( e->key() ) { // Look at the key code 456 switch( e->key() ) { // Look at the key code
453 case Key_Left: // If 'left arrow'-key, 457 case Key_Left: // If 'left arrow'-key,
454 if( curCol > 0 ) { // and cr't not in leftmost col 458 if( curCol > 0 ) { // and cr't not in leftmost col
455 setCurrent( curRow, curCol - 1);// set cr't to next left column 459 setCurrent( curRow, curCol - 1);// set cr't to next left column
456 int edge = leftCell(); // find left edge 460 int edge = leftCell(); // find left edge
457 if ( curCol < edge ) // if we have moved off edge, 461 if ( curCol < edge ) // if we have moved off edge,
458 setLeftCell( edge - 1 );// scroll view to rectify 462 setLeftCell( edge - 1 );// scroll view to rectify
459 } 463 }
460 break; 464 break;
461 case Key_Right: // Correspondingly... 465 case Key_Right: // Correspondingly...
462 if( curCol < numCols()-1 ) { 466 if( curCol < numCols()-1 ) {
463 setCurrent( curRow, curCol + 1); 467 setCurrent( curRow, curCol + 1);
464 int edge = lastColVisible(); 468 int edge = lastColVisible();
465 if ( curCol >= edge ) 469 if ( curCol >= edge )
466 setLeftCell( leftCell() + 1 ); 470 setLeftCell( leftCell() + 1 );
467 } 471 }
468 break; 472 break;
469 case Key_Up: 473 case Key_Up:
470 if( curRow > 0 ) { 474 if( curRow > 0 ) {
471 setCurrent( curRow - 1, curCol); 475 setCurrent( curRow - 1, curCol);
472 int edge = topCell(); 476 int edge = topCell();
473 if ( curRow < edge ) 477 if ( curRow < edge )
474 setTopCell( edge - 1 ); 478 setTopCell( edge - 1 );
475 } else if ( smallStyle ) 479 } else if ( smallStyle )
476 focusNextPrevChild( FALSE ); 480 focusNextPrevChild( FALSE );
477 break; 481 break;
478 case Key_Down: 482 case Key_Down:
479 if( curRow < numRows()-1 ) { 483 if( curRow < numRows()-1 ) {
480 setCurrent( curRow + 1, curCol); 484 setCurrent( curRow + 1, curCol);
481 int edge = lastRowVisible(); 485 int edge = lastRowVisible();
482 if ( curRow >= edge ) 486 if ( curRow >= edge )
483 setTopCell( topCell() + 1 ); 487 setTopCell( topCell() + 1 );
484 } else if ( smallStyle ) 488 } else if ( smallStyle )
485 focusNextPrevChild( TRUE ); 489 focusNextPrevChild( TRUE );
486 break; 490 break;
487 case Key_Space: 491 case Key_Space:
488 case Key_Return: 492 case Key_Return:
489 case Key_Enter: 493 case Key_Enter:
490 setSelected( curRow, curCol ); 494 setSelected( curRow, curCol );
491 break; 495 break;
492 default: // If not an interesting key, 496 default: // If not an interesting key,
493 e->ignore(); // we don't accept the event 497 e->ignore(); // we don't accept the event
494 return; 498 return;
495 } 499 }
496 500
497} 501}
498 502
499//////////// QWellArray END 503//////////// QWellArray END
500 504
501static bool initrgb = FALSE; 505static bool initrgb = FALSE;
502static QRgb stdrgb[6*8]; 506static QRgb stdrgb[6*8];
503static QRgb cusrgb[2*8]; 507static QRgb cusrgb[2*8];
504 508
505 509
506static void initRGB() 510static void initRGB()
507{ 511{
508 if ( initrgb ) 512 if ( initrgb )
509 return; 513 return;
510 initrgb = TRUE; 514 initrgb = TRUE;
511 int i = 0; 515 int i = 0;
512 for ( int g = 0; g < 4; g++ ) 516 for ( int g = 0; g < 4; g++ )
513 for ( int r = 0; r < 4; r++ ) 517 for ( int r = 0; r < 4; r++ )
514 for ( int b = 0; b < 3; b++ ) 518 for ( int b = 0; b < 3; b++ )
515 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 );
516 520
517 for ( i = 0; i < 2*8; i++ ) 521 for ( i = 0; i < 2*8; i++ )
518 cusrgb[i] = qRgb(0xff,0xff,0xff); 522 cusrgb[i] = qRgb(0xff,0xff,0xff);
519} 523}
520 524
521/*! 525/*!
522 Returns the number of custom colors supported by 526 Returns the number of custom colors supported by
523 QColorDialog. All color dialogs share the same custom colors. 527 QColorDialog. All color dialogs share the same custom colors.
524*/ 528*/
525int QColorDialog::customCount() 529int QColorDialog::customCount()
526{ 530{
527 return 2*8; 531 return 2*8;
528} 532}
529 533
530/*! 534/*!
531 Returns custom color number \a i as a QRgb. 535 Returns custom color number \a i as a QRgb.
532 */ 536 */
533QRgb QColorDialog::customColor( int i ) 537QRgb QColorDialog::customColor( int i )
534{ 538{
535 initRGB(); 539 initRGB();
536 if ( i < 0 || i >= customCount() ) { 540 if ( i < 0 || i >= customCount() ) {
537#ifdef CHECK_RANGE 541#ifdef CHECK_RANGE
538 qWarning( "QColorDialog::customColor() index %d out of range", i ); 542 qWarning( "QColorDialog::customColor() index %d out of range", i );
539 #endif 543 #endif
540 i = 0; 544 i = 0;
541 } 545 }
542 return cusrgb[i]; 546 return cusrgb[i];
543} 547}
544 548
545/*! 549/*!
546 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.
547*/ 551*/
548void QColorDialog::setCustomColor( int i, QRgb c ) 552void QColorDialog::setCustomColor( int i, QRgb c )
549{ 553{
550 initRGB(); 554 initRGB();
551 if ( i < 0 || i >= customCount() ) { 555 if ( i < 0 || i >= customCount() ) {
552#ifdef CHECK_RANGE 556#ifdef CHECK_RANGE
553 qWarning( "QColorDialog::customColor() index %d out of range", i ); 557 qWarning( "QColorDialog::customColor() index %d out of range", i );
554 #endif 558 #endif
555 return; 559 return;
556 } 560 }
557 cusrgb[i] = c; 561 cusrgb[i] = c;
558} 562}
559 563
560static inline void rgb2hsv( QRgb rgb, int&h, int&s, int&v ) 564static inline void rgb2hsv( QRgb rgb, int&h, int&s, int&v )
561{ 565{
562 QColor c; 566 QColor c;
563 c.setRgb( rgb ); 567 c.setRgb( rgb );
564 c.getHsv(h,s,v); 568 c.getHsv(h,s,v);
565} 569}
566 570
567class QColorWell : public QWellArray 571class QColorWell : public QWellArray
568{ 572{
569public: 573public:
570 QColorWell( QWidget *parent, int r, int c, QRgb *vals ) 574 QColorWell( QWidget *parent, int r, int c, QRgb *vals )
571 :QWellArray( parent, "" ), values( vals ), mousePressed( FALSE ), oldCurrent( -1, -1 ) 575 :QWellArray( parent, "" ), values( vals ), mousePressed( FALSE ), oldCurrent( -1, -1 )
572 { setDimension(r,c); setWFlags( WResizeNoErase ); } 576 { setDimension(r,c); setWFlags( WResizeNoErase ); }
573 QSizePolicy sizePolicy() const; 577 QSizePolicy sizePolicy() const;
574 578
575protected: 579protected:
576 void drawContents( QPainter *, int row, int col, const QRect& ); 580 void drawContents( QPainter *, int row, int col, const QRect& );
577 void drawContents( QPainter *p ) { QWellArray::drawContents(p); } 581 void drawContents( QPainter *p ) { QWellArray::drawContents(p); }
578 void mousePressEvent( QMouseEvent *e ); 582 void mousePressEvent( QMouseEvent *e );
579 void mouseMoveEvent( QMouseEvent *e ); 583 void mouseMoveEvent( QMouseEvent *e );
580 void mouseReleaseEvent( QMouseEvent *e ); 584 void mouseReleaseEvent( QMouseEvent *e );
581#ifndef QT_NO_DRAGANDDROP 585#ifndef QT_NO_DRAGANDDROP
582 void dragEnterEvent( QDragEnterEvent *e ); 586 void dragEnterEvent( QDragEnterEvent *e );
583 void dragLeaveEvent( QDragLeaveEvent *e ); 587 void dragLeaveEvent( QDragLeaveEvent *e );
584 void dragMoveEvent( QDragMoveEvent *e ); 588 void dragMoveEvent( QDragMoveEvent *e );
585 void dropEvent( QDropEvent *e ); 589 void dropEvent( QDropEvent *e );
586#endif 590#endif
587 591
588private: 592private:
589 QRgb *values; 593 QRgb *values;
590 bool mousePressed; 594 bool mousePressed;
591 QPoint pressPos; 595 QPoint pressPos;
592 QPoint oldCurrent; 596 QPoint oldCurrent;
593 597
594}; 598};
595 599
596QSizePolicy QColorWell::sizePolicy() const 600QSizePolicy QColorWell::sizePolicy() const
597{ 601{
598 return QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ); 602 return QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
599} 603}
600 604
601void QColorWell::drawContents( QPainter *p, int row, int col, const QRect &r ) 605void QColorWell::drawContents( QPainter *p, int row, int col, const QRect &r )
602{ 606{
603 int i = row + col*numRows(); 607 int i = row + col*numRows();
604 p->fillRect( r, QColor( values[i] ) ); 608 p->fillRect( r, QColor( values[i] ) );
605} 609}
606 610
607void QColorWell::mousePressEvent( QMouseEvent *e ) 611void QColorWell::mousePressEvent( QMouseEvent *e )
608{ 612{
609 oldCurrent = QPoint( selectedRow(), selectedColumn() ); 613 oldCurrent = QPoint( selectedRow(), selectedColumn() );
610 QWellArray::mousePressEvent( e ); 614 QWellArray::mousePressEvent( e );
611 mousePressed = TRUE; 615 mousePressed = TRUE;
612 pressPos = e->pos(); 616 pressPos = e->pos();
613} 617}
614 618
615void QColorWell::mouseMoveEvent( QMouseEvent *e ) 619void QColorWell::mouseMoveEvent( QMouseEvent *e )
616{ 620{
617 QWellArray::mouseMoveEvent( e ); 621 QWellArray::mouseMoveEvent( e );
618#ifndef QT_NO_DRAGANDDROP 622#ifndef QT_NO_DRAGANDDROP
619 if ( !mousePressed ) 623 if ( !mousePressed )
620 return; 624 return;
621 if ( ( pressPos - e->pos() ).manhattanLength() > QApplication::startDragDistance() ) { 625 if ( ( pressPos - e->pos() ).manhattanLength() > QApplication::startDragDistance() ) {
622 setCurrent( oldCurrent.x(), oldCurrent.y() ); 626 setCurrent( oldCurrent.x(), oldCurrent.y() );
623 int i = findRow( e->y() ) + findCol( e->x() ) * numRows(); 627 int i = findRow( e->y() ) + findCol( e->x() ) * numRows();
624 QColor col( values[ i ] ); 628 QColor col( values[ i ] );
625 QColorDrag *drg = new QColorDrag( col, this ); 629 QColorDrag *drg = new QColorDrag( col, this );
626 QPixmap pix( cellWidth(), cellHeight() ); 630 QPixmap pix( cellWidth(), cellHeight() );
627 pix.fill( col ); 631 pix.fill( col );
628 QPainter p( &pix ); 632 QPainter p( &pix );
629 p.drawRect( 0, 0, pix.width(), pix.height() ); 633 p.drawRect( 0, 0, pix.width(), pix.height() );
630 p.end(); 634 p.end();
631 drg->setPixmap( pix ); 635 drg->setPixmap( pix );
632 mousePressed = FALSE; 636 mousePressed = FALSE;
633 drg->dragCopy(); 637 drg->dragCopy();
634 } 638 }
635#endif 639#endif
636} 640}
637 641
638#ifndef QT_NO_DRAGANDDROP 642#ifndef QT_NO_DRAGANDDROP
639void QColorWell::dragEnterEvent( QDragEnterEvent *e ) 643void QColorWell::dragEnterEvent( QDragEnterEvent *e )
640{ 644{
641 setFocus(); 645 setFocus();
642 if ( QColorDrag::canDecode( e ) ) 646 if ( QColorDrag::canDecode( e ) )
643 e->accept(); 647 e->accept();
644 else 648 else
645 e->ignore(); 649 e->ignore();
646} 650}
647 651
648void QColorWell::dragLeaveEvent( QDragLeaveEvent * ) 652void QColorWell::dragLeaveEvent( QDragLeaveEvent * )
649{ 653{
650 if ( hasFocus() ) 654 if ( hasFocus() )
651 parentWidget()->setFocus(); 655 parentWidget()->setFocus();
652} 656}
653 657
654void QColorWell::dragMoveEvent( QDragMoveEvent *e ) 658void QColorWell::dragMoveEvent( QDragMoveEvent *e )
655{ 659{
656 if ( QColorDrag::canDecode( e ) ) { 660 if ( QColorDrag::canDecode( e ) ) {
657 setCurrent( findRow( e->pos().y() ), findCol( e->pos().x() ) ); 661 setCurrent( findRow( e->pos().y() ), findCol( e->pos().x() ) );
658 e->accept(); 662 e->accept();
659 } else 663 } else
660 e->ignore(); 664 e->ignore();
661} 665}
662 666
663void QColorWell::dropEvent( QDropEvent *e ) 667void QColorWell::dropEvent( QDropEvent *e )
664{ 668{
665 if ( QColorDrag::canDecode( e ) ) { 669 if ( QColorDrag::canDecode( e ) ) {
666 int i = findRow( e->pos().y() ) + findCol( e->pos().x() ) * numRows(); 670 int i = findRow( e->pos().y() ) + findCol( e->pos().x() ) * numRows();
667 QColor col; 671 QColor col;
668 QColorDrag::decode( e, col ); 672 QColorDrag::decode( e, col );
669 values[ i ] = col.rgb(); 673 values[ i ] = col.rgb();
670 repaint( FALSE ); 674 repaint( FALSE );
671 e->accept(); 675 e->accept();
672 } else { 676 } else {
673 e->ignore(); 677 e->ignore();
674 } 678 }
675} 679}
676 680
677#endif // QT_NO_DRAGANDDROP 681#endif // QT_NO_DRAGANDDROP
678 682
679void QColorWell::mouseReleaseEvent( QMouseEvent *e ) 683void QColorWell::mouseReleaseEvent( QMouseEvent *e )
680{ 684{
681 if ( !mousePressed ) 685 if ( !mousePressed )
682 return; 686 return;
683 QWellArray::mouseReleaseEvent( e ); 687 QWellArray::mouseReleaseEvent( e );
684 mousePressed = FALSE; 688 mousePressed = FALSE;
685} 689}
686 690
687class QColorPicker : public QFrame 691class QColorPicker : public QFrame
688{ 692{
689 Q_OBJECT 693 Q_OBJECT
690public: 694public:
691 QColorPicker(QWidget* parent=0, const char* name=0); 695 QColorPicker(QWidget* parent=0, const char* name=0);
692 ~QColorPicker(); 696 ~QColorPicker();
693 697
694public slots: 698public slots:
695 void setCol( int h, int s ); 699 void setCol( int h, int s );
696 700
697signals: 701signals:
698 void newCol( int h, int s ); 702 void newCol( int h, int s );
699 703
700protected: 704protected:
701 QSize sizeHint() const; 705 QSize sizeHint() const;
702 QSizePolicy sizePolicy() const; 706 QSizePolicy sizePolicy() const;
703 void drawContents(QPainter* p); 707 void drawContents(QPainter* p);
704 void mouseMoveEvent( QMouseEvent * ); 708 void mouseMoveEvent( QMouseEvent * );
705 void mousePressEvent( QMouseEvent * ); 709 void mousePressEvent( QMouseEvent * );
706 710
707private: 711private:
708 int hue; 712 int hue;
709 int sat; 713 int sat;
710 714
711 QPoint colPt(); 715 QPoint colPt();
712 int huePt( const QPoint &pt ); 716 int huePt( const QPoint &pt );
713 int satPt( const QPoint &pt ); 717 int satPt( const QPoint &pt );
714 void setCol( const QPoint &pt ); 718 void setCol( const QPoint &pt );
715 719
716 QPixmap *pix; 720 QPixmap *pix;
717}; 721};
718 722
719static int pWidth = 200; 723static int pWidth = 200;
720static int pHeight = 200; 724static int pHeight = 200;
721 725
722class QColorLuminancePicker : public QWidget 726class QColorLuminancePicker : public QWidget
723{ 727{
724 Q_OBJECT 728 Q_OBJECT
725public: 729public:
726 QColorLuminancePicker(QWidget* parent=0, const char* name=0); 730 QColorLuminancePicker(QWidget* parent=0, const char* name=0);
727 ~QColorLuminancePicker(); 731 ~QColorLuminancePicker();
728 732
729public slots: 733public slots:
730 void setCol( int h, int s, int v ); 734 void setCol( int h, int s, int v );
731 void setCol( int h, int s ); 735 void setCol( int h, int s );
732 736
733signals: 737signals:
734 void newHsv( int h, int s, int v ); 738 void newHsv( int h, int s, int v );
735 739
736protected: 740protected:
737// QSize sizeHint() const; 741// QSize sizeHint() const;
738// QSizePolicy sizePolicy() const; 742// QSizePolicy sizePolicy() const;
739 void paintEvent( QPaintEvent*); 743 void paintEvent( QPaintEvent*);
740 void mouseMoveEvent( QMouseEvent * ); 744 void mouseMoveEvent( QMouseEvent * );
741 void mousePressEvent( QMouseEvent * ); 745 void mousePressEvent( QMouseEvent * );
742 746
743private: 747private:
744 enum { foff = 3, coff = 4 }; //frame and contents offset 748 enum { foff = 3, coff = 4 }; //frame and contents offset
745 int val; 749 int val;
746 int hue; 750 int hue;
747 int sat; 751 int sat;
748 752
749 int y2val( int y ); 753 int y2val( int y );
750 int val2y( int val ); 754 int val2y( int val );
751 void setVal( int v ); 755 void setVal( int v );
752 756
753 QPixmap *pix; 757 QPixmap *pix;
754}; 758};
755 759
756 760
757int QColorLuminancePicker::y2val( int y ) 761int QColorLuminancePicker::y2val( int y )
758{ 762{
759 int d = height() - 2*coff - 1; 763 int d = height() - 2*coff - 1;
760 return 255 - (y - coff)*255/d; 764 return 255 - (y - coff)*255/d;
761} 765}
762 766
763int QColorLuminancePicker::val2y( int v ) 767int QColorLuminancePicker::val2y( int v )
764{ 768{
765 int d = height() - 2*coff - 1; 769 int d = height() - 2*coff - 1;
766 return coff + (255-v)*d/255; 770 return coff + (255-v)*d/255;
767} 771}
768 772
769QColorLuminancePicker::QColorLuminancePicker(QWidget* parent, 773QColorLuminancePicker::QColorLuminancePicker(QWidget* parent,
770 const char* name) 774 const char* name)
771 :QWidget( parent, name ) 775 :QWidget( parent, name )
772{ 776{
773 hue = 100; val = 100; sat = 100; 777 hue = 100; val = 100; sat = 100;
774 pix = 0; 778 pix = 0;
775 // setBackgroundMode( NoBackground ); 779 // setBackgroundMode( NoBackground );
776} 780}
777 781
778QColorLuminancePicker::~QColorLuminancePicker() 782QColorLuminancePicker::~QColorLuminancePicker()
779{ 783{
780 delete pix; 784 delete pix;
781} 785}
782 786
783void QColorLuminancePicker::mouseMoveEvent( QMouseEvent *m ) 787void QColorLuminancePicker::mouseMoveEvent( QMouseEvent *m )
784{ 788{
785 setVal( y2val(m->y()) ); 789 setVal( y2val(m->y()) );
786} 790}
787void QColorLuminancePicker::mousePressEvent( QMouseEvent *m ) 791void QColorLuminancePicker::mousePressEvent( QMouseEvent *m )
788{ 792{
789 setVal( y2val(m->y()) ); 793 setVal( y2val(m->y()) );
790} 794}
791 795
792void QColorLuminancePicker::setVal( int v ) 796void QColorLuminancePicker::setVal( int v )
793{ 797{
794 if ( val == v ) 798 if ( val == v )
795 return; 799 return;
796 val = QMAX( 0, QMIN(v,255)); 800 val = QMAX( 0, QMIN(v,255));
797 delete pix; pix=0; 801 delete pix; pix=0;
798 repaint( FALSE ); //### 802 repaint( FALSE ); //###
799 emit newHsv( hue, sat, val ); 803 emit newHsv( hue, sat, val );
800} 804}
801 805
802//receives from a hue,sat chooser and relays. 806//receives from a hue,sat chooser and relays.
803void QColorLuminancePicker::setCol( int h, int s ) 807void QColorLuminancePicker::setCol( int h, int s )
804{ 808{
805 setCol( h, s, val ); 809 setCol( h, s, val );
806 emit newHsv( h, s, val ); 810 emit newHsv( h, s, val );
807} 811}
808 812
809void QColorLuminancePicker::paintEvent( QPaintEvent * ) 813void QColorLuminancePicker::paintEvent( QPaintEvent * )
810{ 814{
811 int w = width() - 5; 815 int w = width() - 5;
812 816
813 QRect r( 0, foff, w, height() - 2*foff ); 817 QRect r( 0, foff, w, height() - 2*foff );
814 int wi = r.width() - 2; 818 int wi = r.width() - 2;
815 int hi = r.height() - 2; 819 int hi = r.height() - 2;
816 if ( !pix || pix->height() != hi || pix->width() != wi ) { 820 if ( !pix || pix->height() != hi || pix->width() != wi ) {
817 delete pix; 821 delete pix;
818 QImage img( wi, hi, 32 ); 822 QImage img( wi, hi, 32 );
819 int y; 823 int y;
820 for ( y = 0; y < hi; y++ ) { 824 for ( y = 0; y < hi; y++ ) {
821 QColor c( hue, sat, y2val(y+coff), QColor::Hsv ); 825 QColor c( hue, sat, y2val(y+coff), QColor::Hsv );
822 QRgb r = c.rgb(); 826 QRgb r = c.rgb();