summaryrefslogtreecommitdiff
authormouse <mouse>2004-03-31 13:23:53 (UTC)
committer mouse <mouse>2004-03-31 13:23:53 (UTC)
commit859e524e4c55bedc4a73e3208f34a75013cb37f5 (patch) (unidiff)
treee46dc8a969254869e8a5d3cdc99b2c845f3e59e5
parentc74a24cbd04cb74d832908eb2b373aed7b3cea71 (diff)
downloadopie-859e524e4c55bedc4a73e3208f34a75013cb37f5.zip
opie-859e524e4c55bedc4a73e3208f34a75013cb37f5.tar.gz
opie-859e524e4c55bedc4a73e3208f34a75013cb37f5.tar.bz2
added missed include file for QColorDrag
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,1628 +1,1632 @@
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();
823 int x; 827 int x;
824 for ( x = 0; x < wi; x++ ) 828 for ( x = 0; x < wi; x++ )
825 img.setPixel( x, y, r ); 829 img.setPixel( x, y, r );
826 } 830 }
827 pix = new QPixmap; 831 pix = new QPixmap;
828 pix->convertFromImage(img); 832 pix->convertFromImage(img);
829 } 833 }
830 QPainter p(this); 834 QPainter p(this);
831 p.drawPixmap( 1, coff, *pix ); 835 p.drawPixmap( 1, coff, *pix );
832 QColorGroup g = colorGroup(); 836 QColorGroup g = colorGroup();
833 qDrawShadePanel( &p, r, g, TRUE ); 837 qDrawShadePanel( &p, r, g, TRUE );
834 p.setPen( g.foreground() ); 838 p.setPen( g.foreground() );
835 p.setBrush( g.foreground() ); 839 p.setBrush( g.foreground() );
836 QPointArray a; 840 QPointArray a;
837 int y = val2y(val); 841 int y = val2y(val);
838 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 );
839 erase( w, 0, 5, height() ); 843 erase( w, 0, 5, height() );
840 p.drawPolygon( a ); 844 p.drawPolygon( a );
841} 845}
842 846
843void QColorLuminancePicker::setCol( int h, int s , int v ) 847void QColorLuminancePicker::setCol( int h, int s , int v )
844{ 848{
845 val = v; 849 val = v;
846 hue = h; 850 hue = h;
847 sat = s; 851 sat = s;
848 delete pix; pix=0; 852 delete pix; pix=0;
849 repaint( FALSE );//#### 853 repaint( FALSE );//####
850} 854}
851 855
852QPoint QColorPicker::colPt() 856QPoint QColorPicker::colPt()
853{ 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 ); }
854int QColorPicker::huePt( const QPoint &pt ) 858int QColorPicker::huePt( const QPoint &pt )
855{ return 360 - pt.x()*360/(pWidth-1); } 859{ return 360 - pt.x()*360/(pWidth-1); }
856int QColorPicker::satPt( const QPoint &pt ) 860int QColorPicker::satPt( const QPoint &pt )
857{ return 255 - pt.y()*255/(pHeight-1) ; } 861{ return 255 - pt.y()*255/(pHeight-1) ; }
858void QColorPicker::setCol( const QPoint &pt ) 862void QColorPicker::setCol( const QPoint &pt )
859{ setCol( huePt(pt), satPt(pt) ); } 863{ setCol( huePt(pt), satPt(pt) ); }
860 864
861QColorPicker::QColorPicker(QWidget* parent, const char* name ) 865QColorPicker::QColorPicker(QWidget* parent, const char* name )
862 : QFrame( parent, name ) 866 : QFrame( parent, name )
863{ 867{
864 hue = 0; sat = 0; 868 hue = 0; sat = 0;
865 setCol( 150, 255 ); 869 setCol( 150, 255 );
866 870
867 QImage img( pWidth, pHeight, 32 ); 871 QImage img( pWidth, pHeight, 32 );
868 int x,y; 872 int x,y;
869 for ( y = 0; y < pHeight; y++ ) 873 for ( y = 0; y < pHeight; y++ )
870 for ( x = 0; x < pWidth; x++ ) { 874 for ( x = 0; x < pWidth; x++ ) {
871 QPoint p( x, y ); 875 QPoint p( x, y );
872 img.setPixel( x, y, QColor(huePt(p), satPt(p), 876 img.setPixel( x, y, QColor(huePt(p), satPt(p),
873 200, QColor::Hsv).rgb() ); 877 200, QColor::Hsv).rgb() );
874 } 878 }
875 pix = new QPixmap; 879 pix = new QPixmap;
876 pix->convertFromImage(img); 880 pix->convertFromImage(img);
877 setBackgroundMode( NoBackground ); 881 setBackgroundMode( NoBackground );
878} 882}
879 883
880QColorPicker::~QColorPicker() 884QColorPicker::~QColorPicker()
881{ 885{
882 delete pix; 886 delete pix;
883} 887}
884 888
885QSize QColorPicker::sizeHint() const 889QSize QColorPicker::sizeHint() const
886{ 890{
887 return QSize( pWidth + 2*frameWidth(), pHeight + 2*frameWidth() ); 891 return QSize( pWidth + 2*frameWidth(), pHeight + 2*frameWidth() );
888} 892}
889 893
890QSizePolicy QColorPicker::sizePolicy() const 894QSizePolicy QColorPicker::sizePolicy() const
891{ 895{
892 return QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); 896 return QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
893} 897}
894 898
895void QColorPicker::setCol( int h, int s ) 899void QColorPicker::setCol( int h, int s )
896{ 900{
897 int nhue = QMIN( QMAX(0,h), 360 ); 901 int nhue = QMIN( QMAX(0,h), 360 );
898 int nsat = QMIN( QMAX(0,s), 255); 902 int nsat = QMIN( QMAX(0,s), 255);
899 if ( nhue == hue && nsat == sat ) 903 if ( nhue == hue && nsat == sat )
900 return; 904 return;
901 QRect r( colPt(), QSize(20,20) ); 905 QRect r( colPt(), QSize(20,20) );
902 hue = nhue; sat = nsat; 906 hue = nhue; sat = nsat;
903 r = r.unite( QRect( colPt(), QSize(20,20) ) ); 907 r = r.unite( QRect( colPt(), QSize(20,20) ) );
904 r.moveBy( contentsRect().x()-9, contentsRect().y()-9 ); 908 r.moveBy( contentsRect().x()-9, contentsRect().y()-9 );
905 // update( r ); 909 // update( r );
906 repaint( r, FALSE ); 910 repaint( r, FALSE );
907} 911}
908 912
909void QColorPicker::mouseMoveEvent( QMouseEvent *m ) 913void QColorPicker::mouseMoveEvent( QMouseEvent *m )
910{ 914{
911 QPoint p = m->pos() - contentsRect().topLeft(); 915 QPoint p = m->pos() - contentsRect().topLeft();
912 setCol( p ); 916 setCol( p );
913 emit newCol( hue, sat ); 917 emit newCol( hue, sat );
914} 918}
915 919
916void QColorPicker::mousePressEvent( QMouseEvent *m ) 920void QColorPicker::mousePressEvent( QMouseEvent *m )
917{ 921{
918 QPoint p = m->pos() - contentsRect().topLeft(); 922 QPoint p = m->pos() - contentsRect().topLeft();
919 setCol( p ); 923 setCol( p );
920 emit newCol( hue, sat ); 924 emit newCol( hue, sat );
921} 925}
922 926
923void QColorPicker::drawContents(QPainter* p) 927void QColorPicker::drawContents(QPainter* p)
924{ 928{
925 QRect r = contentsRect(); 929 QRect r = contentsRect();
926 930
927 p->drawPixmap( r.topLeft(), *pix ); 931 p->drawPixmap( r.topLeft(), *pix );
928 QPoint pt = colPt() + r.topLeft(); 932 QPoint pt = colPt() + r.topLeft();
929 p->setPen( QPen(black) ); 933 p->setPen( QPen(black) );
930 934
931 p->fillRect( pt.x()-9, pt.y(), 20, 2, black ); 935 p->fillRect( pt.x()-9, pt.y(), 20, 2, black );
932 p->fillRect( pt.x(), pt.y()-9, 2, 20, black ); 936 p->fillRect( pt.x(), pt.y()-9, 2, 20, black );
933 937
934} 938}
935 939
936class QColorShowLabel; 940class QColorShowLabel;
937 941
938 942
939 943
940class QColIntValidator: public QIntValidator 944class QColIntValidator: public QIntValidator
941{ 945{
942public: 946public:
943 QColIntValidator( int bottom, int top, 947 QColIntValidator( int bottom, int top,
944 QWidget * parent, const char *name = 0 ) 948 QWidget * parent, const char *name = 0 )
945 :QIntValidator( bottom, top, parent, name ) {} 949 :QIntValidator( bottom, top, parent, name ) {}
946 950
947 QValidator::State validate( QString &, int & ) const; 951 QValidator::State validate( QString &, int & ) const;
948}; 952};
949 953
950QValidator::State QColIntValidator::validate( QString &s, int &pos ) const 954QValidator::State QColIntValidator::validate( QString &s, int &pos ) const
951{ 955{
952 State state = QIntValidator::validate(s,pos); 956 State state = QIntValidator::validate(s,pos);
953 if ( state == Valid ) { 957 if ( state == Valid ) {
954 long int val = s.toLong(); 958 long int val = s.toLong();
955 // This is not a general solution, assumes that top() > 0 and 959 // This is not a general solution, assumes that top() > 0 and
956 // bottom >= 0 960 // bottom >= 0
957 if ( val < 0 ) { 961 if ( val < 0 ) {
958 s = "0"; 962 s = "0";
959 pos = 1; 963 pos = 1;
960 } else if ( val > top() ) { 964 } else if ( val > top() ) {
961 s.setNum( top() ); 965 s.setNum( top() );
962 pos = s.length(); 966 pos = s.length();
963 } 967 }
964 } 968 }
965 return state; 969 return state;
966} 970}
967 971
968 972
969 973
970class QColNumLineEdit : public QLineEdit 974class QColNumLineEdit : public QLineEdit
971{ 975{
972public: 976public:
973 QColNumLineEdit( QWidget *parent, const char* name = 0 ) 977 QColNumLineEdit( QWidget *parent, const char* name = 0 )
974 : QLineEdit( parent, name ) { setMaxLength( 3 );} 978 : QLineEdit( parent, name ) { setMaxLength( 3 );}
975 QSize sizeHint() const { 979 QSize sizeHint() const {
976 return QSize( 30, //##### 980 return QSize( 30, //#####
977 QLineEdit::sizeHint().height() ); } 981 QLineEdit::sizeHint().height() ); }
978 void setNum( int i ) { 982 void setNum( int i ) {
979 QString s; 983 QString s;
980 s.setNum(i); 984 s.setNum(i);
981 bool block = signalsBlocked(); 985 bool block = signalsBlocked();
982 blockSignals(TRUE); 986 blockSignals(TRUE);
983 setText( s ); 987 setText( s );
984 blockSignals(block); 988 blockSignals(block);
985 } 989 }
986 int val() const { return text().toInt(); } 990 int val() const { return text().toInt(); }
987}; 991};
988 992
989 993
990class QColorShower : public QWidget 994class QColorShower : public QWidget
991{ 995{
992 Q_OBJECT 996 Q_OBJECT
993public: 997public:
994 QColorShower( QWidget *parent, const char *name = 0 ); 998 QColorShower( QWidget *parent, const char *name = 0 );
995 999
996 //things that don't emit signals 1000 //things that don't emit signals
997 void setHsv( int h, int s, int v ); 1001 void setHsv( int h, int s, int v );
998 1002
999 int currentAlpha() const { return alphaEd->val(); } 1003 int currentAlpha() const { return alphaEd->val(); }
1000 void setCurrentAlpha( int a ) { alphaEd->setNum( a ); } 1004 void setCurrentAlpha( int a ) { alphaEd->setNum( a ); }
1001 void showAlpha( bool b ); 1005 void showAlpha( bool b );
1002 1006
1003 1007
1004 QRgb currentColor() const { return curCol; } 1008 QRgb currentColor() const { return curCol; }
1005 1009
1006public slots: 1010public slots:
1007 void setRgb( QRgb rgb ); 1011 void setRgb( QRgb rgb );
1008 1012
1009signals: 1013signals:
1010 void newCol( QRgb rgb ); 1014 void newCol( QRgb rgb );
1011private slots: 1015private slots:
1012 void rgbEd(); 1016 void rgbEd();
1013 void hsvEd(); 1017 void hsvEd();
1014private: 1018private:
1015 void showCurrentColor(); 1019 void showCurrentColor();
1016 int hue, sat, val; 1020 int hue, sat, val;
1017 QRgb curCol; 1021 QRgb curCol;
1018 QColNumLineEdit *hEd; 1022 QColNumLineEdit *hEd;
1019 QColNumLineEdit *sEd; 1023 QColNumLineEdit *sEd;
1020 QColNumLineEdit *vEd; 1024 QColNumLineEdit *vEd;
1021 QColNumLineEdit *rEd; 1025 QColNumLineEdit *rEd;
1022 QColNumLineEdit *gEd; 1026 QColNumLineEdit *gEd;
1023 QColNumLineEdit *bEd; 1027 QColNumLineEdit *bEd;
1024 QColNumLineEdit *alphaEd; 1028 QColNumLineEdit *alphaEd;
1025 QLabel *alphaLab; 1029 QLabel *alphaLab;
1026 QColorShowLabel *lab; 1030 QColorShowLabel *lab;
1027 bool rgbOriginal; 1031 bool rgbOriginal;
1028}; 1032};
1029 1033
1030class QColorShowLabel : public QFrame 1034class QColorShowLabel : public QFrame
1031{ 1035{
1032 Q_OBJECT 1036 Q_OBJECT
1033 1037
1034public: 1038public:
1035 QColorShowLabel( QWidget *parent ) :QFrame( parent ) { 1039 QColorShowLabel( QWidget *parent ) :QFrame( parent ) {
1036 setFrameStyle( QFrame::Panel|QFrame::Sunken ); 1040 setFrameStyle( QFrame::Panel|QFrame::Sunken );
1037 setBackgroundMode( PaletteBackground ); 1041 setBackgroundMode( PaletteBackground );
1038 setAcceptDrops( TRUE ); 1042 setAcceptDrops( TRUE );
1039 mousePressed = FALSE; 1043 mousePressed = FALSE;
1040 } 1044 }
1041 void setColor( QColor c ) { col = c; } 1045 void setColor( QColor c ) { col = c; }
1042 1046
1043signals: 1047signals:
1044 void colorDropped( QRgb ); 1048 void colorDropped( QRgb );
1045 1049
1046protected: 1050protected:
1047 void drawContents( QPainter *p ); 1051 void drawContents( QPainter *p );
1048 void mousePressEvent( QMouseEvent *e ); 1052 void mousePressEvent( QMouseEvent *e );
1049 void mouseMoveEvent( QMouseEvent *e ); 1053 void mouseMoveEvent( QMouseEvent *e );
1050 void mouseReleaseEvent( QMouseEvent *e ); 1054 void mouseReleaseEvent( QMouseEvent *e );
1051#ifndef QT_NO_DRAGANDDROP 1055#ifndef QT_NO_DRAGANDDROP
1052 void dragEnterEvent( QDragEnterEvent *e ); 1056 void dragEnterEvent( QDragEnterEvent *e );
1053 void dragLeaveEvent( QDragLeaveEvent *e ); 1057 void dragLeaveEvent( QDragLeaveEvent *e );
1054 void dropEvent( QDropEvent *e ); 1058 void dropEvent( QDropEvent *e );
1055#endif 1059#endif
1056 1060
1057private: 1061private:
1058 QColor col; 1062 QColor col;
1059 bool mousePressed; 1063 bool mousePressed;
1060 QPoint pressPos; 1064 QPoint pressPos;
1061 1065
1062}; 1066};
1063 1067
1064void QColorShowLabel::drawContents( QPainter *p ) 1068void QColorShowLabel::drawContents( QPainter *p )
1065{ 1069{
1066 p->fillRect( contentsRect(), col ); 1070 p->fillRect( contentsRect(), col );
1067} 1071}
1068 1072
1069void QColorShower::showAlpha( bool b ) 1073void QColorShower::showAlpha( bool b )
1070{ 1074{
1071 if ( b ) { 1075 if ( b ) {
1072 alphaLab->show(); 1076 alphaLab->show();
1073 alphaEd->show(); 1077 alphaEd->show();
1074 } else { 1078 } else {
1075 alphaLab->hide(); 1079 alphaLab->hide();
1076 alphaEd->hide(); 1080 alphaEd->hide();
1077 } 1081 }
1078} 1082}
1079 1083
1080void QColorShowLabel::mousePressEvent( QMouseEvent *e ) 1084void QColorShowLabel::mousePressEvent( QMouseEvent *e )
1081{ 1085{
1082 mousePressed = TRUE; 1086 mousePressed = TRUE;
1083 pressPos = e->pos(); 1087 pressPos = e->pos();
1084} 1088}
1085 1089
1086void QColorShowLabel::mouseMoveEvent( QMouseEvent *e ) 1090void QColorShowLabel::mouseMoveEvent( QMouseEvent *e )
1087{ 1091{
1088#ifndef QT_NO_DRAGANDDROP 1092#ifndef QT_NO_DRAGANDDROP
1089 if ( !mousePressed ) 1093 if ( !mousePressed )
1090 return; 1094 return;
1091 if ( ( pressPos - e->pos() ).manhattanLength() > QApplication::startDragDistance() ) { 1095 if ( ( pressPos - e->pos() ).manhattanLength() > QApplication::startDragDistance() ) {
1092 QColorDrag *drg = new QColorDrag( col, this ); 1096 QColorDrag *drg = new QColorDrag( col, this );
1093 QPixmap pix( 30, 20 ); 1097 QPixmap pix( 30, 20 );
1094 pix.fill( col ); 1098 pix.fill( col );
1095 QPainter p( &pix ); 1099 QPainter p( &pix );
1096 p.drawRect( 0, 0, pix.width(), pix.height() ); 1100 p.drawRect( 0, 0, pix.width(), pix.height() );
1097 p.end(); 1101 p.end();
1098 drg->setPixmap( pix ); 1102 drg->setPixmap( pix );
1099 mousePressed = FALSE; 1103 mousePressed = FALSE;
1100 drg->dragCopy(); 1104 drg->dragCopy();
1101 } 1105 }
1102#endif 1106#endif
1103} 1107}
1104 1108
1105#ifndef QT_NO_DRAGANDDROP 1109#ifndef QT_NO_DRAGANDDROP
1106void QColorShowLabel::dragEnterEvent( QDragEnterEvent *e ) 1110void QColorShowLabel::dragEnterEvent( QDragEnterEvent *e )
1107{ 1111{
1108 if ( QColorDrag::canDecode( e ) ) 1112 if ( QColorDrag::canDecode( e ) )
1109 e->accept(); 1113 e->accept();
1110 else 1114 else
1111 e->ignore(); 1115 e->ignore();
1112} 1116}
1113 1117
1114void QColorShowLabel::dragLeaveEvent( QDragLeaveEvent * ) 1118void QColorShowLabel::dragLeaveEvent( QDragLeaveEvent * )
1115{ 1119{
1116} 1120}
1117 1121
1118void QColorShowLabel::dropEvent( QDropEvent *e ) 1122void QColorShowLabel::dropEvent( QDropEvent *e )
1119{ 1123{
1120 if ( QColorDrag::canDecode( e ) ) { 1124 if ( QColorDrag::canDecode( e ) ) {
1121 QColorDrag::decode( e, col ); 1125 QColorDrag::decode( e, col );
1122 repaint( FALSE ); 1126 repaint( FALSE );
1123 emit colorDropped( col.rgb() ); 1127 emit colorDropped( col.rgb() );
1124 e->accept(); 1128 e->accept();
1125 } else { 1129 } else {
1126 e->ignore(); 1130 e->ignore();
1127 } 1131 }
1128} 1132}
1129#endif // QT_NO_DRAGANDDROP 1133#endif // QT_NO_DRAGANDDROP
1130 1134
1131void QColorShowLabel::mouseReleaseEvent( QMouseEvent * ) 1135void QColorShowLabel::mouseReleaseEvent( QMouseEvent * )
1132{ 1136{
1133 if ( !mousePressed ) 1137 if ( !mousePressed )
1134 return; 1138 return;
1135 mousePressed = FALSE; 1139 mousePressed = FALSE;
1136} 1140}
1137 1141
1138QColorShower::QColorShower( QWidget *parent, const char *name ) 1142QColorShower::QColorShower( QWidget *parent, const char *name )
1139 :QWidget( parent, name) 1143 :QWidget( parent, name)
1140{ 1144{
1141 curCol = qRgb( -1, -1, -1 ); 1145 curCol = qRgb( -1, -1, -1 );
1142 QColIntValidator *val256 = new QColIntValidator( 0, 255, this ); 1146 QColIntValidator *val256 = new QColIntValidator( 0, 255, this );
1143 QColIntValidator *val360 = new QColIntValidator( 0, 360, this ); 1147 QColIntValidator *val360 = new QColIntValidator( 0, 360, this );
1144 1148
1145 QGridLayout *gl = new QGridLayout( this, 1, 1, 6 ); 1149 QGridLayout *gl = new QGridLayout( this, 1, 1, 6 );
1146 lab = new QColorShowLabel( this ); 1150 lab = new QColorShowLabel( this );
1147 lab->setMinimumWidth( 60 ); //### 1151 lab->setMinimumWidth( 60 ); //###
1148 gl->addMultiCellWidget(lab, 0,-1,0,0); 1152 gl->addMultiCellWidget(lab, 0,-1,0,0);
1149 connect( lab, SIGNAL( colorDropped(QRgb) ), 1153 connect( lab, SIGNAL( colorDropped(QRgb) ),
1150 this, SIGNAL( newCol(QRgb) ) ); 1154 this, SIGNAL( newCol(QRgb) ) );
1151 connect( lab, SIGNAL( colorDropped(QRgb) ), 1155 connect( lab, SIGNAL( colorDropped(QRgb) ),
1152 this, SLOT( setRgb(QRgb) ) ); 1156 this, SLOT( setRgb(QRgb) ) );
1153 1157
1154 hEd = new QColNumLineEdit( this ); 1158 hEd = new QColNumLineEdit( this );
1155 hEd->setValidator( val360 ); 1159 hEd->setValidator( val360 );
1156 QLabel *l = new QLabel( hEd, QColorDialog::tr("Hu&e:"), this ); 1160 QLabel *l = new QLabel( hEd, QColorDialog::tr("Hu&e:"), this );
1157 l->setAlignment( AlignRight|AlignVCenter ); 1161 l->setAlignment( AlignRight|AlignVCenter );
1158 gl->addWidget( l, 0, 1 ); 1162 gl->addWidget( l, 0, 1 );
1159 gl->addWidget( hEd, 0, 2 ); 1163 gl->addWidget( hEd, 0, 2 );
1160 1164
1161 sEd = new QColNumLineEdit( this ); 1165 sEd = new QColNumLineEdit( this );
1162 sEd->setValidator( val256 ); 1166 sEd->setValidator( val256 );
1163 l = new QLabel( sEd, QColorDialog::tr("&Sat:"), this ); 1167 l = new QLabel( sEd, QColorDialog::tr("&Sat:"), this );
1164 l->setAlignment( AlignRight|AlignVCenter ); 1168 l->setAlignment( AlignRight|AlignVCenter );
1165 gl->addWidget( l, 1, 1 ); 1169 gl->addWidget( l, 1, 1 );
1166 gl->addWidget( sEd, 1, 2 ); 1170 gl->addWidget( sEd, 1, 2 );
1167 1171
1168 vEd = new QColNumLineEdit( this ); 1172 vEd = new QColNumLineEdit( this );
1169 vEd->setValidator( val256 ); 1173 vEd->setValidator( val256 );
1170 l = new QLabel( vEd, QColorDialog::tr("&Val:"), this ); 1174 l = new QLabel( vEd, QColorDialog::tr("&Val:"), this );
1171 l->setAlignment( AlignRight|AlignVCenter ); 1175 l->setAlignment( AlignRight|AlignVCenter );
1172 gl->addWidget( l, 2, 1 ); 1176 gl->addWidget( l, 2, 1 );
1173 gl->addWidget( vEd, 2, 2 ); 1177 gl->addWidget( vEd, 2, 2 );
1174 1178
1175 rEd = new QColNumLineEdit( this ); 1179 rEd = new QColNumLineEdit( this );
1176 rEd->setValidator( val256 ); 1180 rEd->setValidator( val256 );
1177 l = new QLabel( rEd, QColorDialog::tr("&Red:"), this ); 1181 l = new QLabel( rEd, QColorDialog::tr("&Red:"), this );
1178 l->setAlignment( AlignRight|AlignVCenter ); 1182 l->setAlignment( AlignRight|AlignVCenter );
1179 gl->addWidget( l, 0, 3 ); 1183 gl->addWidget( l, 0, 3 );
1180 gl->addWidget( rEd, 0, 4 ); 1184 gl->addWidget( rEd, 0, 4 );
1181 1185
1182 gEd = new QColNumLineEdit( this ); 1186 gEd = new QColNumLineEdit( this );
1183 gEd->setValidator( val256 ); 1187 gEd->setValidator( val256 );
1184 l = new QLabel( gEd, QColorDialog::tr("&Green:"), this ); 1188 l = new QLabel( gEd, QColorDialog::tr("&Green:"), this );
1185 l->setAlignment( AlignRight|AlignVCenter ); 1189 l->setAlignment( AlignRight|AlignVCenter );
1186 gl->addWidget( l, 1, 3 ); 1190 gl->addWidget( l, 1, 3 );
1187 gl->addWidget( gEd, 1, 4 ); 1191 gl->addWidget( gEd, 1, 4 );
1188 1192
1189 bEd = new QColNumLineEdit( this ); 1193 bEd = new QColNumLineEdit( this );
1190 bEd->setValidator( val256 ); 1194 bEd->setValidator( val256 );
1191 l = new QLabel( bEd, QColorDialog::tr("Bl&ue:"), this ); 1195 l = new QLabel( bEd, QColorDialog::tr("Bl&ue:"), this );
1192 l->setAlignment( AlignRight|AlignVCenter ); 1196 l->setAlignment( AlignRight|AlignVCenter );
1193 gl->addWidget( l, 2, 3 ); 1197 gl->addWidget( l, 2, 3 );
1194 gl->addWidget( bEd, 2, 4 ); 1198 gl->addWidget( bEd, 2, 4 );
1195 1199
1196 alphaEd = new QColNumLineEdit( this ); 1200 alphaEd = new QColNumLineEdit( this );
1197 alphaEd->setValidator( val256 ); 1201 alphaEd->setValidator( val256 );
1198 alphaLab = new QLabel( alphaEd, QColorDialog::tr("A&lpha channel:"), this ); 1202 alphaLab = new QLabel( alphaEd, QColorDialog::tr("A&lpha channel:"), this );
1199 alphaLab->setAlignment( AlignRight|AlignVCenter ); 1203 alphaLab->setAlignment( AlignRight|AlignVCenter );
1200 gl->addMultiCellWidget( alphaLab, 3, 3, 1, 3 ); 1204 gl->addMultiCellWidget( alphaLab, 3, 3, 1, 3 );
1201 gl->addWidget( alphaEd, 3, 4 ); 1205 gl->addWidget( alphaEd, 3, 4 );
1202 alphaEd->hide(); 1206 alphaEd->hide();
1203 alphaLab->hide(); 1207 alphaLab->hide();
1204 1208
1205 connect( hEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) ); 1209 connect( hEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) );
1206 connect( sEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) ); 1210 connect( sEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) );
1207 connect( vEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) ); 1211 connect( vEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) );
1208 1212
1209 connect( rEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) ); 1213 connect( rEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) );
1210 connect( gEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) ); 1214 connect( gEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) );
1211 connect( bEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) ); 1215 connect( bEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) );
1212} 1216}
1213 1217
1214void QColorShower::showCurrentColor() 1218void QColorShower::showCurrentColor()
1215{ 1219{
1216 lab->setColor( currentColor() ); 1220 lab->setColor( currentColor() );
1217 lab->repaint(FALSE); //### 1221 lab->repaint(FALSE); //###
1218} 1222}
1219 1223
1220void QColorShower::rgbEd() 1224void QColorShower::rgbEd()
1221{ 1225{
1222 rgbOriginal = TRUE; 1226 rgbOriginal = TRUE;
1223 curCol = qRgb( rEd->val(), gEd->val(), bEd->val() ); 1227 curCol = qRgb( rEd->val(), gEd->val(), bEd->val() );
1224 rgb2hsv(currentColor(), hue, sat, val ); 1228 rgb2hsv(currentColor(), hue, sat, val );
1225 1229
1226 hEd->setNum( hue ); 1230 hEd->setNum( hue );
1227 sEd->setNum( sat ); 1231 sEd->setNum( sat );
1228 vEd->setNum( val ); 1232 vEd->setNum( val );
1229 1233
1230 showCurrentColor(); 1234 showCurrentColor();
1231 emit newCol( currentColor() ); 1235 emit newCol( currentColor() );
1232} 1236}
1233 1237
1234void QColorShower::hsvEd() 1238void QColorShower::hsvEd()
1235{ 1239{
1236 rgbOriginal = FALSE; 1240 rgbOriginal = FALSE;
1237 hue = hEd->val(); 1241 hue = hEd->val();
1238 sat = sEd->val(); 1242 sat = sEd->val();
1239 val = vEd->val(); 1243 val = vEd->val();
1240 1244
1241 curCol = QColor( hue, sat, val, QColor::Hsv ).rgb(); 1245 curCol = QColor( hue, sat, val, QColor::Hsv ).rgb();
1242 1246
1243 rEd->setNum( qRed(currentColor()) ); 1247 rEd->setNum( qRed(currentColor()) );
1244 gEd->setNum( qGreen(currentColor()) ); 1248 gEd->setNum( qGreen(currentColor()) );
1245 bEd->setNum( qBlue(currentColor()) ); 1249 bEd->setNum( qBlue(currentColor()) );
1246 1250
1247 showCurrentColor(); 1251 showCurrentColor();
1248 emit newCol( currentColor() ); 1252 emit newCol( currentColor() );
1249} 1253}
1250 1254
1251void QColorShower::setRgb( QRgb rgb ) 1255void QColorShower::setRgb( QRgb rgb )
1252{ 1256{
1253 rgbOriginal = TRUE; 1257 rgbOriginal = TRUE;
1254 curCol = rgb; 1258 curCol = rgb;
1255 1259
1256 rgb2hsv( currentColor(), hue, sat, val ); 1260 rgb2hsv( currentColor(), hue, sat, val );
1257 1261
1258 hEd->setNum( hue ); 1262 hEd->setNum( hue );
1259 sEd->setNum( sat ); 1263 sEd->setNum( sat );
1260 vEd->setNum( val ); 1264 vEd->setNum( val );
1261 1265
1262 rEd->setNum( qRed(currentColor()) ); 1266 rEd->setNum( qRed(currentColor()) );
1263 gEd->setNum( qGreen(currentColor()) ); 1267 gEd->setNum( qGreen(currentColor()) );
1264 bEd->setNum( qBlue(currentColor()) ); 1268 bEd->setNum( qBlue(currentColor()) );
1265 1269
1266 showCurrentColor(); 1270 showCurrentColor();
1267} 1271}
1268 1272
1269void QColorShower::setHsv( int h, int s, int v ) 1273void QColorShower::setHsv( int h, int s, int v )
1270{ 1274{
1271 rgbOriginal = FALSE; 1275 rgbOriginal = FALSE;
1272 hue = h; val = v; sat = s; //Range check### 1276 hue = h; val = v; sat = s; //Range check###
1273 curCol = QColor( hue, sat, val, QColor::Hsv ).rgb(); 1277 curCol = QColor( hue, sat, val, QColor::Hsv ).rgb();
1274 1278
1275 hEd->setNum( hue ); 1279 hEd->setNum( hue );
1276 sEd->setNum( sat ); 1280 sEd->setNum( sat );
1277 vEd->setNum( val ); 1281 vEd->setNum( val );
1278 1282
1279 rEd->setNum( qRed(currentColor()) ); 1283 rEd->setNum( qRed(currentColor()) );
1280 gEd->setNum( qGreen(currentColor()) ); 1284 gEd->setNum( qGreen(currentColor()) );
1281 bEd->setNum( qBlue(currentColor()) ); 1285 bEd->setNum( qBlue(currentColor()) );
1282 1286
1283 1287
1284 showCurrentColor(); 1288 showCurrentColor();
1285} 1289}
1286 1290
1287class QColorDialogPrivate : public QObject 1291class QColorDialogPrivate : public QObject
1288{ 1292{
1289Q_OBJECT 1293Q_OBJECT
1290public: 1294public:
1291 QColorDialogPrivate( QColorDialog *p ); 1295 QColorDialogPrivate( QColorDialog *p );
1292 QRgb currentColor() const { return cs->currentColor(); } 1296 QRgb currentColor() const { return cs->currentColor(); }
1293 void setCurrentColor( QRgb rgb ); 1297 void setCurrentColor( QRgb rgb );
1294 1298
1295 int currentAlpha() const { return cs->currentAlpha(); } 1299 int currentAlpha() const { return cs->currentAlpha(); }
1296 void setCurrentAlpha( int a ) { cs->setCurrentAlpha( a ); } 1300 void setCurrentAlpha( int a ) { cs->setCurrentAlpha( a ); }
1297 void showAlpha( bool b ) { cs->showAlpha( b ); } 1301 void showAlpha( bool b ) { cs->showAlpha( b ); }
1298 1302
1299private slots: 1303private slots:
1300 void addCustom(); 1304 void addCustom();
1301 1305
1302 void newHsv( int h, int s, int v ); 1306 void newHsv( int h, int s, int v );
1303 void newColorTypedIn( QRgb rgb ); 1307 void newColorTypedIn( QRgb rgb );
1304 void newCustom( int, int ); 1308 void newCustom( int, int );
1305 void newStandard( int, int ); 1309 void newStandard( int, int );
1306private: 1310private:
1307 QColorPicker *cp; 1311 QColorPicker *cp;
1308 QColorLuminancePicker *lp; 1312 QColorLuminancePicker *lp;
1309 QWellArray *custom; 1313 QWellArray *custom;
1310 QWellArray *standard; 1314 QWellArray *standard;
1311 QColorShower *cs; 1315 QColorShower *cs;
1312 int nextCust; 1316 int nextCust;
1313 bool compact; 1317 bool compact;
1314}; 1318};
1315 1319
1316//sets all widgets to display h,s,v 1320//sets all widgets to display h,s,v
1317void QColorDialogPrivate::newHsv( int h, int s, int v ) 1321void QColorDialogPrivate::newHsv( int h, int s, int v )
1318{ 1322{
1319 cs->setHsv( h, s, v ); 1323 cs->setHsv( h, s, v );
1320 cp->setCol( h, s ); 1324 cp->setCol( h, s );
1321 lp->setCol( h, s, v ); 1325 lp->setCol( h, s, v );
1322} 1326}
1323 1327
1324//sets all widgets to display rgb 1328//sets all widgets to display rgb
1325void QColorDialogPrivate::setCurrentColor( QRgb rgb ) 1329void QColorDialogPrivate::setCurrentColor( QRgb rgb )
1326{ 1330{
1327 cs->setRgb( rgb ); 1331 cs->setRgb( rgb );
1328 newColorTypedIn( rgb ); 1332 newColorTypedIn( rgb );
1329} 1333}
1330 1334
1331//sets all widgets exept cs to display rgb 1335//sets all widgets exept cs to display rgb
1332void QColorDialogPrivate::newColorTypedIn( QRgb rgb ) 1336void QColorDialogPrivate::newColorTypedIn( QRgb rgb )
1333{ 1337{
1334 int h, s, v; 1338 int h, s, v;
1335 rgb2hsv(rgb, h, s, v ); 1339 rgb2hsv(rgb, h, s, v );
1336 cp->setCol( h, s ); 1340 cp->setCol( h, s );
1337 lp->setCol( h, s, v); 1341 lp->setCol( h, s, v);
1338} 1342}
1339 1343
1340void QColorDialogPrivate::newCustom( int r, int c ) 1344void QColorDialogPrivate::newCustom( int r, int c )
1341{ 1345{
1342 int i = r+2*c; 1346 int i = r+2*c;
1343 setCurrentColor( cusrgb[i] ); 1347 setCurrentColor( cusrgb[i] );
1344 nextCust = i; 1348 nextCust = i;
1345 standard->setSelected(-1,-1); 1349 standard->setSelected(-1,-1);
1346} 1350}
1347 1351
1348void QColorDialogPrivate::newStandard( int r, int c ) 1352void QColorDialogPrivate::newStandard( int r, int c )
1349{ 1353{
1350 setCurrentColor( stdrgb[r+c*6] ); 1354 setCurrentColor( stdrgb[r+c*6] );
1351 custom->setSelected(-1,-1); 1355 custom->setSelected(-1,-1);
1352} 1356}
1353 1357
1354QColorDialogPrivate::QColorDialogPrivate( QColorDialog *dialog ) : 1358QColorDialogPrivate::QColorDialogPrivate( QColorDialog *dialog ) :
1355 QObject(dialog) 1359 QObject(dialog)
1356{ 1360{
1357 compact = FALSE; 1361 compact = FALSE;
1358 // small displays (e.g. PDAs cannot fit the full color dialog, 1362 // small displays (e.g. PDAs cannot fit the full color dialog,
1359 // so just use the color picker. 1363 // so just use the color picker.
1360 if ( qApp->desktop()->width() < 480 || qApp->desktop()->height() < 350 ) 1364 if ( qApp->desktop()->width() < 480 || qApp->desktop()->height() < 350 )
1361 compact = TRUE; 1365 compact = TRUE;
1362 1366
1363 nextCust = 0; 1367 nextCust = 0;
1364 const int lumSpace = 3; 1368 const int lumSpace = 3;
1365 int border = 12; 1369 int border = 12;
1366 if ( compact ) 1370 if ( compact )
1367 border = 6; 1371 border = 6;
1368 QHBoxLayout *topLay = new QHBoxLayout( dialog, border, 6 ); 1372 QHBoxLayout *topLay = new QHBoxLayout( dialog, border, 6 );
1369 QVBoxLayout *leftLay = 0; 1373 QVBoxLayout *leftLay = 0;
1370 1374
1371 if ( !compact ) 1375 if ( !compact )
1372 leftLay = new QVBoxLayout( topLay ); 1376 leftLay = new QVBoxLayout( topLay );
1373 1377
1374 initRGB(); 1378 initRGB();
1375 1379
1376 if ( !compact ) { 1380 if ( !compact ) {
1377 standard = new QColorWell( dialog, 6, 8, stdrgb ); 1381 standard = new QColorWell( dialog, 6, 8, stdrgb );
1378 standard->setCellSize( 28, 24 ); 1382 standard->setCellSize( 28, 24 );
1379 QLabel * lab = new QLabel( standard, 1383 QLabel * lab = new QLabel( standard,
1380 QColorDialog::tr( "&Basic colors"), dialog ); 1384 QColorDialog::tr( "&Basic colors"), dialog );
1381 connect( standard, SIGNAL(selected(int,int)), SLOT(newStandard(int,int))); 1385 connect( standard, SIGNAL(selected(int,int)), SLOT(newStandard(int,int)));
1382 leftLay->addWidget( lab ); 1386 leftLay->addWidget( lab );
1383 leftLay->addWidget( standard ); 1387 leftLay->addWidget( standard );
1384 1388
1385 1389
1386 leftLay->addStretch(); 1390 leftLay->addStretch();
1387 1391
1388 custom = new QColorWell( dialog, 2, 8, cusrgb ); 1392 custom = new QColorWell( dialog, 2, 8, cusrgb );
1389 custom->setCellSize( 28, 24 ); 1393 custom->setCellSize( 28, 24 );
1390 custom->setAcceptDrops( TRUE ); 1394 custom->setAcceptDrops( TRUE );
1391 1395
1392 connect( custom, SIGNAL(selected(int,int)), SLOT(newCustom(int,int))); 1396 connect( custom, SIGNAL(selected(int,int)), SLOT(newCustom(int,int)));
1393 lab = new QLabel( custom, QColorDialog::tr( "&Custom colors") , dialog ); 1397 lab = new QLabel( custom, QColorDialog::tr( "&Custom colors") , dialog );
1394 leftLay->addWidget( lab ); 1398 leftLay->addWidget( lab );
1395 leftLay->addWidget( custom ); 1399 leftLay->addWidget( custom );
1396 1400
1397 QPushButton *custbut = 1401 QPushButton *custbut =
1398 new QPushButton( QColorDialog::tr("&Define Custom Colors >>"), 1402 new QPushButton( QColorDialog::tr("&Define Custom Colors >>"),
1399 dialog ); 1403 dialog );
1400 custbut->setEnabled( FALSE ); 1404 custbut->setEnabled( FALSE );
1401 leftLay->addWidget( custbut ); 1405 leftLay->addWidget( custbut );
1402 } else { 1406 } else {
1403 // better color picker size for small displays 1407 // better color picker size for small displays
1404 pWidth = 150; 1408 pWidth = 150;
1405 pHeight = 100; 1409 pHeight = 100;
1406 } 1410 }
1407 1411
1408 QVBoxLayout *rightLay = new QVBoxLayout( topLay ); 1412 QVBoxLayout *rightLay = new QVBoxLayout( topLay );
1409 1413
1410 QHBoxLayout *pickLay = new QHBoxLayout( rightLay ); 1414 QHBoxLayout *pickLay = new QHBoxLayout( rightLay );
1411 1415
1412 1416
1413 QVBoxLayout *cLay = new QVBoxLayout( pickLay ); 1417 QVBoxLayout *cLay = new QVBoxLayout( pickLay );
1414 cp = new QColorPicker( dialog ); 1418 cp = new QColorPicker( dialog );
1415 cp->setFrameStyle( QFrame::Panel + QFrame::Sunken ); 1419 cp->setFrameStyle( QFrame::Panel + QFrame::Sunken );
1416 cLay->addSpacing( lumSpace ); 1420 cLay->addSpacing( lumSpace );
1417 cLay->addWidget( cp ); 1421 cLay->addWidget( cp );
1418 cLay->addSpacing( lumSpace ); 1422 cLay->addSpacing( lumSpace );
1419 1423
1420 lp = new QColorLuminancePicker( dialog ); 1424 lp = new QColorLuminancePicker( dialog );
1421 lp->setFixedWidth( 20 ); //### 1425 lp->setFixedWidth( 20 ); //###
1422 pickLay->addWidget( lp ); 1426 pickLay->addWidget( lp );
1423 1427
1424 connect( cp, SIGNAL(newCol(int,int)), lp, SLOT(setCol(int,int)) ); 1428 connect( cp, SIGNAL(newCol(int,int)), lp, SLOT(setCol(int,int)) );
1425 connect( lp, SIGNAL(newHsv(int,int,int)), this, SLOT(newHsv(int,int,int)) ); 1429 connect( lp, SIGNAL(newHsv(int,int,int)), this, SLOT(newHsv(int,int,int)) );
1426 1430
1427 rightLay->addStretch(); 1431 rightLay->addStretch();
1428 1432
1429 cs = new QColorShower( dialog ); 1433 cs = new QColorShower( dialog );
1430 connect( cs, SIGNAL(newCol(QRgb)), this, SLOT(newColorTypedIn(QRgb))); 1434 connect( cs, SIGNAL(newCol(QRgb)), this, SLOT(newColorTypedIn(QRgb)));
1431 rightLay->addWidget( cs ); 1435 rightLay->addWidget( cs );
1432 1436
1433 QHBoxLayout *buttons; 1437 QHBoxLayout *buttons;
1434 if ( compact ) 1438 if ( compact )
1435 buttons = new QHBoxLayout( rightLay ); 1439 buttons = new QHBoxLayout( rightLay );
1436 else 1440 else
1437 buttons = new QHBoxLayout( leftLay ); 1441 buttons = new QHBoxLayout( leftLay );
1438 1442
1439 QPushButton *ok, *cancel; 1443 QPushButton *ok, *cancel;
1440 ok = new QPushButton( QColorDialog::tr("OK"), dialog ); 1444 ok = new QPushButton( QColorDialog::tr("OK"), dialog );
1441 connect( ok, SIGNAL(clicked()), dialog, SLOT(accept()) ); 1445 connect( ok, SIGNAL(clicked()), dialog, SLOT(accept()) );
1442 ok->setDefault(TRUE); 1446 ok->setDefault(TRUE);
1443 cancel = new QPushButton( QColorDialog::tr("Cancel"), dialog ); 1447 cancel = new QPushButton( QColorDialog::tr("Cancel"), dialog );
1444 connect( cancel, SIGNAL(clicked()), dialog, SLOT(reject()) ); 1448 connect( cancel, SIGNAL(clicked()), dialog, SLOT(reject()) );
1445 buttons->addWidget( ok ); 1449 buttons->addWidget( ok );
1446 buttons->addWidget( cancel ); 1450 buttons->addWidget( cancel );
1447 buttons->addStretch(); 1451 buttons->addStretch();
1448 1452
1449 if ( !compact ) { 1453 if ( !compact ) {
1450 QPushButton *addCusBt = new QPushButton( 1454 QPushButton *addCusBt = new QPushButton(
1451 QColorDialog::tr("&Add To Custom Colors"), 1455 QColorDialog::tr("&Add To Custom Colors"),
1452 dialog ); 1456 dialog );
1453 rightLay->addWidget( addCusBt ); 1457 rightLay->addWidget( addCusBt );
1454 connect( addCusBt, SIGNAL(clicked()), this, SLOT(addCustom()) ); 1458 connect( addCusBt, SIGNAL(clicked()), this, SLOT(addCustom()) );
1455 } 1459 }
1456} 1460}
1457 1461
1458void QColorDialogPrivate::addCustom() 1462void QColorDialogPrivate::addCustom()
1459{ 1463{
1460 cusrgb[nextCust] = cs->currentColor(); 1464 cusrgb[nextCust] = cs->currentColor();
1461 custom->repaint( FALSE ); //### 1465 custom->repaint( FALSE ); //###
1462 nextCust = (nextCust+1) % 16; 1466 nextCust = (nextCust+1) % 16;
1463} 1467}
1464 1468
1465 1469
1466// BEING REVISED: jo 1470// BEING REVISED: jo
1467/*! 1471/*!
1468 \class QColorDialog qcolordialog.h 1472 \class QColorDialog qcolordialog.h
1469 \brief The QColorDialog class provides a dialog widget for specifying colors. 1473 \brief The QColorDialog class provides a dialog widget for specifying colors.
1470 \ingroup dialogs 1474 \ingroup dialogs
1471 1475
1472 The color dialog's function is to allow users to choose colors - 1476 The color dialog's function is to allow users to choose colors -
1473 for instance, you might use this in a drawing program to allow the 1477 for instance, you might use this in a drawing program to allow the
1474 user to set the brush color. 1478 user to set the brush color.
1475 1479
1476 This version of Qt only provides modal color dialogs. The static 1480 This version of Qt only provides modal color dialogs. The static
1477 getColor() function shows the dialog and allows the user to specify a color, 1481 getColor() function shows the dialog and allows the user to specify a color,
1478 while getRgba() does the same but allows the user to specify a color with an 1482 while getRgba() does the same but allows the user to specify a color with an
1479 alpha channel (transparency) value. 1483 alpha channel (transparency) value.
1480 1484
1481 The user can store customCount() different custom colors. The custom 1485 The user can store customCount() different custom colors. The custom
1482 colors are shared by all color dialogs, and remembered during the 1486 colors are shared by all color dialogs, and remembered during the
1483 execution of the program. Use setCustomColor() to set the 1487 execution of the program. Use setCustomColor() to set the
1484 custom colors, and customColor() to get them. 1488 custom colors, and customColor() to get them.
1485 1489
1486 <img src=qcolordlg-m.png> <img src=qcolordlg-w.png> 1490 <img src=qcolordlg-m.png> <img src=qcolordlg-w.png>
1487*/ 1491*/
1488 1492
1489/*! 1493/*!
1490 Constructs a default color dialog. Use setColor() for setting an initial value. 1494 Constructs a default color dialog. Use setColor() for setting an initial value.
1491 1495
1492 \sa getColor() 1496 \sa getColor()
1493*/ 1497*/
1494 1498
1495QColorDialog::QColorDialog(QWidget* parent, const char* name, bool modal) : 1499QColorDialog::QColorDialog(QWidget* parent, const char* name, bool modal) :
1496 QDialog(parent, name, modal ) 1500 QDialog(parent, name, modal )
1497{ 1501{
1498 setSizeGripEnabled( TRUE ); 1502 setSizeGripEnabled( TRUE );
1499 d = new QColorDialogPrivate( this ); 1503 d = new QColorDialogPrivate( this );
1500} 1504}
1501 1505
1502 1506
1503/*! 1507/*!
1504 Pops up a modal color dialog letting the user choose a color and returns 1508 Pops up a modal color dialog letting the user choose a color and returns
1505 that color. The color is initially set to \a initial. Returns an \link QColor::isValid() invalid\endlink color if the user cancels 1509 that color. The color is initially set to \a initial. Returns an \link QColor::isValid() invalid\endlink color if the user cancels
1506 the dialog. All colors allocated by the dialog will be deallocated 1510 the dialog. All colors allocated by the dialog will be deallocated
1507 before this function returns. 1511 before this function returns.
1508*/ 1512*/
1509 1513
1510QColor QColorDialog::getColor( QColor initial, QWidget *parent, 1514QColor QColorDialog::getColor( QColor initial, QWidget *parent,
1511 const char *name ) 1515 const char *name )
1512{ 1516{
1513 int allocContext = QColor::enterAllocContext(); 1517 int allocContext = QColor::enterAllocContext();
1514 QColorDialog *dlg = new QColorDialog( parent, name, TRUE ); //modal 1518 QColorDialog *dlg = new QColorDialog( parent, name, TRUE ); //modal
1515 if ( parent && parent->icon() && !parent->icon()->isNull() ) 1519 if ( parent && parent->icon() && !parent->icon()->isNull() )
1516 dlg->setIcon( *parent->icon() ); 1520 dlg->setIcon( *parent->icon() );
1517 else if ( qApp->mainWidget() && qApp->mainWidget()->icon() && !qApp->mainWidget()->icon()->isNull() ) 1521 else if ( qApp->mainWidget() && qApp->mainWidget()->icon() && !qApp->mainWidget()->icon()->isNull() )
1518 dlg->setIcon( *qApp->mainWidget()->icon() ); 1522 dlg->setIcon( *qApp->mainWidget()->icon() );
1519 1523
1520 dlg->setCaption( QColorDialog::tr( "Select color" ) ); 1524 dlg->setCaption( QColorDialog::tr( "Select color" ) );
1521 dlg->setColor( initial ); 1525 dlg->setColor( initial );
1522 int resultCode = dlg->exec(); 1526 int resultCode = dlg->exec();
1523 QColor::leaveAllocContext(); 1527 QColor::leaveAllocContext();
1524 QColor result; 1528 QColor result;
1525 if ( resultCode == QDialog::Accepted ) 1529 if ( resultCode == QDialog::Accepted )
1526 result = dlg->color(); 1530 result = dlg->color();
1527 QColor::destroyAllocContext(allocContext); 1531 QColor::destroyAllocContext(allocContext);
1528 delete dlg; 1532 delete dlg;
1529 return result; 1533 return result;
1530} 1534}
1531 1535
1532 1536
1533/*! 1537/*!
1534 Pops up a modal color dialog, letting the user choose a color and an 1538 Pops up a modal color dialog, letting the user choose a color and an
1535 alpha channel value. The color+alpha is initially set to \a initial. 1539 alpha channel value. The color+alpha is initially set to \a initial.
1536 1540
1537 If \a ok is non-null, \c *ok is set to TRUE if the user clicked OK, 1541 If \a ok is non-null, \c *ok is set to TRUE if the user clicked OK,
1538 and FALSE if the user clicked Cancel. 1542 and FALSE if the user clicked Cancel.
1539 1543
1540 If the user clicks Cancel the \a initial value is returned. 1544 If the user clicks Cancel the \a initial value is returned.
1541*/ 1545*/
1542 1546
1543QRgb QColorDialog::getRgba( QRgb initial, bool *ok, 1547QRgb QColorDialog::getRgba( QRgb initial, bool *ok,
1544 QWidget *parent, const char* name ) 1548 QWidget *parent, const char* name )
1545{ 1549{
1546 int allocContext = QColor::enterAllocContext(); 1550 int allocContext = QColor::enterAllocContext();
1547 QColorDialog *dlg = new QColorDialog( parent, name, TRUE ); //modal 1551 QColorDialog *dlg = new QColorDialog( parent, name, TRUE ); //modal
1548 dlg->setColor( initial ); 1552 dlg->setColor( initial );
1549 dlg->setSelectedAlpha( qAlpha(initial) ); 1553 dlg->setSelectedAlpha( qAlpha(initial) );
1550 int resultCode = dlg->exec(); 1554 int resultCode = dlg->exec();
1551 QColor::leaveAllocContext(); 1555 QColor::leaveAllocContext();
1552 QRgb result = initial; 1556 QRgb result = initial;
1553 if ( resultCode == QDialog::Accepted ) { 1557 if ( resultCode == QDialog::Accepted ) {
1554 QRgb c = dlg->color().rgb(); 1558 QRgb c = dlg->color().rgb();
1555 int alpha = dlg->selectedAlpha(); 1559 int alpha = dlg->selectedAlpha();
1556 result = qRgba( qRed(c), qGreen(c), qBlue(c), alpha ); 1560 result = qRgba( qRed(c), qGreen(c), qBlue(c), alpha );
1557 } 1561 }
1558 if ( ok ) 1562 if ( ok )
1559 *ok = resultCode == QDialog::Accepted; 1563 *ok = resultCode == QDialog::Accepted;
1560 1564
1561 QColor::destroyAllocContext(allocContext); 1565 QColor::destroyAllocContext(allocContext);
1562 delete dlg; 1566 delete dlg;
1563 return result; 1567 return result;
1564} 1568}
1565 1569
1566 1570
1567 1571
1568 1572
1569 1573
1570/*! 1574/*!
1571 Returns the color currently selected in the dialog. 1575 Returns the color currently selected in the dialog.
1572 1576
1573 \sa setColor() 1577 \sa setColor()
1574*/ 1578*/
1575 1579
1576QColor QColorDialog::color() const 1580QColor QColorDialog::color() const
1577{ 1581{
1578 return QColor(d->currentColor()); 1582 return QColor(d->currentColor());
1579} 1583}
1580 1584
1581 1585
1582/*! Destructs the dialog and frees any memory it allocated. 1586/*! Destructs the dialog and frees any memory it allocated.
1583 1587
1584*/ 1588*/
1585 1589
1586QColorDialog::~QColorDialog() 1590QColorDialog::~QColorDialog()
1587{ 1591{
1588 //d inherits QObject, so it is deleted by Qt. 1592 //d inherits QObject, so it is deleted by Qt.
1589} 1593}
1590 1594
1591 1595
1592/*! 1596/*!
1593 Sets the color shown in the dialog to \a c. 1597 Sets the color shown in the dialog to \a c.
1594 1598
1595 \sa color() 1599 \sa color()
1596*/ 1600*/
1597 1601
1598void QColorDialog::setColor( QColor c ) 1602void QColorDialog::setColor( QColor c )
1599{ 1603{
1600 d->setCurrentColor( c.rgb() ); 1604 d->setCurrentColor( c.rgb() );
1601} 1605}
1602 1606
1603 1607
1604 1608
1605 1609
1606/*! 1610/*!
1607 Sets the initial alpha channel value to \a a, and show the alpha channel 1611 Sets the initial alpha channel value to \a a, and show the alpha channel
1608 entry box. 1612 entry box.
1609*/ 1613*/
1610 1614
1611void QColorDialog::setSelectedAlpha( int a ) 1615void QColorDialog::setSelectedAlpha( int a )
1612{ 1616{
1613 d->showAlpha( TRUE ); 1617 d->showAlpha( TRUE );
1614 d->setCurrentAlpha( a ); 1618 d->setCurrentAlpha( a );
1615} 1619}
1616 1620
1617 1621
1618/*! 1622/*!
1619 Returns the value selected for the alpha channel. 1623 Returns the value selected for the alpha channel.
1620*/ 1624*/
1621 1625
1622int QColorDialog::selectedAlpha() const 1626int QColorDialog::selectedAlpha() const
1623{ 1627{
1624 return d->currentAlpha(); 1628 return d->currentAlpha();
1625} 1629}
1626 1630
1627 1631
1628#include "qcolordialog.moc" \ No newline at end of file 1632#include "qcolordialog.moc" \ No newline at end of file