author | leseb <leseb> | 2002-03-19 12:58:43 (UTC) |
---|---|---|
committer | leseb <leseb> | 2002-03-19 12:58:43 (UTC) |
commit | f298cb9f5557d88b9ff38feb4b5e090e5c164ec2 (patch) (unidiff) | |
tree | a27f4d18cf3a0b62987cc37238e78d7269b2504e | |
parent | 58a456b92ba8986d4ea2375ddcfd6dd1d84c8fe5 (diff) | |
download | opie-f298cb9f5557d88b9ff38feb4b5e090e5c164ec2.zip opie-f298cb9f5557d88b9ff38feb4b5e090e5c164ec2.tar.gz opie-f298cb9f5557d88b9ff38feb4b5e090e5c164ec2.tar.bz2 |
Better color selection
-rw-r--r-- | noncore/graphics/drawpad/colordialog.cpp | 851 | ||||
-rw-r--r-- | noncore/graphics/drawpad/colordialog.h | 77 | ||||
-rw-r--r-- | noncore/graphics/drawpad/colorpanel.cpp | 134 | ||||
-rw-r--r-- | noncore/graphics/drawpad/colorpanel.h | 65 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawmode.h | 2 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpad.cpp | 64 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpad.h | 7 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpad.pro | 10 | ||||
-rw-r--r-- | noncore/graphics/drawpad/ellipsedrawmode.cpp | 2 | ||||
-rw-r--r-- | noncore/graphics/drawpad/erasedrawmode.cpp | 2 | ||||
-rw-r--r-- | noncore/graphics/drawpad/filldrawmode.cpp | 4 | ||||
-rw-r--r-- | noncore/graphics/drawpad/linedrawmode.cpp | 2 | ||||
-rw-r--r-- | noncore/graphics/drawpad/pointdrawmode.cpp | 2 | ||||
-rw-r--r-- | noncore/graphics/drawpad/rectangledrawmode.cpp | 2 |
14 files changed, 1184 insertions, 40 deletions
diff --git a/noncore/graphics/drawpad/colordialog.cpp b/noncore/graphics/drawpad/colordialog.cpp new file mode 100644 index 0000000..6d72ff6 --- a/dev/null +++ b/noncore/graphics/drawpad/colordialog.cpp | |||
@@ -0,0 +1,851 @@ | |||
1 | /**************************************************************************** | ||
2 | ** $Id$ | ||
3 | ** | ||
4 | ** Implementation of QColorDialog class | ||
5 | ** | ||
6 | ** Created : 990222 | ||
7 | ** | ||
8 | ** Copyright (C) 1999-2000 Trolltech AS. All rights reserved. | ||
9 | ** | ||
10 | ** This file is part of the dialogs module of the Qt GUI Toolkit. | ||
11 | ** | ||
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 | ||
14 | ** LICENSE.QPL included in the packaging of this file. | ||
15 | ** | ||
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 | ||
18 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
19 | ** packaging of this file. | ||
20 | ** | ||
21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition | ||
22 | ** licenses may use this file in accordance with the Qt Commercial License | ||
23 | ** Agreement provided with the Software. | ||
24 | ** | ||
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. | ||
27 | ** | ||
28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | ||
29 | ** information about Qt Commercial License Agreements. | ||
30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. | ||
31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
32 | ** | ||
33 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
34 | ** not clear to you. | ||
35 | ** | ||
36 | **********************************************************************/ | ||
37 | |||
38 | #include "colordialog.h" | ||
39 | |||
40 | #include "qpainter.h" | ||
41 | #include "qlayout.h" | ||
42 | #include "qlabel.h" | ||
43 | #include "qpushbutton.h" | ||
44 | #include "qlineedit.h" | ||
45 | #include "qimage.h" | ||
46 | #include "qpixmap.h" | ||
47 | #include "qdrawutil.h" | ||
48 | #include "qvalidator.h" | ||
49 | #include "qdragobject.h" | ||
50 | #include "qapplication.h" | ||
51 | #include "qdragobject.h" | ||
52 | |||
53 | static inline void rgb2hsv( QRgb rgb, int&h, int&s, int&v ) | ||
54 | { | ||
55 | QColor c; | ||
56 | c.setRgb( rgb ); | ||
57 | c.getHsv(h,s,v); | ||
58 | } | ||
59 | |||
60 | class QColorPicker : public QFrame | ||
61 | { | ||
62 | Q_OBJECT | ||
63 | public: | ||
64 | QColorPicker(QWidget* parent=0, const char* name=0); | ||
65 | ~QColorPicker(); | ||
66 | |||
67 | public slots: | ||
68 | void setCol( int h, int s ); | ||
69 | |||
70 | signals: | ||
71 | void newCol( int h, int s ); | ||
72 | |||
73 | protected: | ||
74 | QSize sizeHint() const; | ||
75 | QSizePolicy sizePolicy() const; | ||
76 | void drawContents(QPainter* p); | ||
77 | void mouseMoveEvent( QMouseEvent * ); | ||
78 | void mousePressEvent( QMouseEvent * ); | ||
79 | |||
80 | private: | ||
81 | int hue; | ||
82 | int sat; | ||
83 | |||
84 | QPoint colPt(); | ||
85 | int huePt( const QPoint &pt ); | ||
86 | int satPt( const QPoint &pt ); | ||
87 | void setCol( const QPoint &pt ); | ||
88 | |||
89 | QPixmap *pix; | ||
90 | }; | ||
91 | |||
92 | static int pWidth = 200; | ||
93 | static int pHeight = 200; | ||
94 | |||
95 | class QColorLuminancePicker : public QWidget | ||
96 | { | ||
97 | Q_OBJECT | ||
98 | public: | ||
99 | QColorLuminancePicker(QWidget* parent=0, const char* name=0); | ||
100 | ~QColorLuminancePicker(); | ||
101 | |||
102 | public slots: | ||
103 | void setCol( int h, int s, int v ); | ||
104 | void setCol( int h, int s ); | ||
105 | |||
106 | signals: | ||
107 | void newHsv( int h, int s, int v ); | ||
108 | |||
109 | protected: | ||
110 | // QSize sizeHint() const; | ||
111 | // QSizePolicy sizePolicy() const; | ||
112 | void paintEvent( QPaintEvent*); | ||
113 | void mouseMoveEvent( QMouseEvent * ); | ||
114 | void mousePressEvent( QMouseEvent * ); | ||
115 | |||
116 | private: | ||
117 | enum { foff = 3, coff = 4 }; //frame and contents offset | ||
118 | int val; | ||
119 | int hue; | ||
120 | int sat; | ||
121 | |||
122 | int y2val( int y ); | ||
123 | int val2y( int val ); | ||
124 | void setVal( int v ); | ||
125 | |||
126 | QPixmap *pix; | ||
127 | }; | ||
128 | |||
129 | |||
130 | int QColorLuminancePicker::y2val( int y ) | ||
131 | { | ||
132 | int d = height() - 2*coff - 1; | ||
133 | return 255 - (y - coff)*255/d; | ||
134 | } | ||
135 | |||
136 | int QColorLuminancePicker::val2y( int v ) | ||
137 | { | ||
138 | int d = height() - 2*coff - 1; | ||
139 | return coff + (255-v)*d/255; | ||
140 | } | ||
141 | |||
142 | QColorLuminancePicker::QColorLuminancePicker(QWidget* parent, | ||
143 | const char* name) | ||
144 | :QWidget( parent, name ) | ||
145 | { | ||
146 | hue = 100; val = 100; sat = 100; | ||
147 | pix = 0; | ||
148 | // setBackgroundMode( NoBackground ); | ||
149 | } | ||
150 | |||
151 | QColorLuminancePicker::~QColorLuminancePicker() | ||
152 | { | ||
153 | delete pix; | ||
154 | } | ||
155 | |||
156 | void QColorLuminancePicker::mouseMoveEvent( QMouseEvent *m ) | ||
157 | { | ||
158 | setVal( y2val(m->y()) ); | ||
159 | } | ||
160 | void QColorLuminancePicker::mousePressEvent( QMouseEvent *m ) | ||
161 | { | ||
162 | setVal( y2val(m->y()) ); | ||
163 | } | ||
164 | |||
165 | void QColorLuminancePicker::setVal( int v ) | ||
166 | { | ||
167 | if ( val == v ) | ||
168 | return; | ||
169 | val = QMAX( 0, QMIN(v,255)); | ||
170 | delete pix; pix=0; | ||
171 | repaint( FALSE ); //### | ||
172 | emit newHsv( hue, sat, val ); | ||
173 | } | ||
174 | |||
175 | //receives from a hue,sat chooser and relays. | ||
176 | void QColorLuminancePicker::setCol( int h, int s ) | ||
177 | { | ||
178 | setCol( h, s, val ); | ||
179 | emit newHsv( h, s, val ); | ||
180 | } | ||
181 | |||
182 | void QColorLuminancePicker::paintEvent( QPaintEvent * ) | ||
183 | { | ||
184 | int w = width() - 5; | ||
185 | |||
186 | QRect r( 0, foff, w, height() - 2*foff ); | ||
187 | int wi = r.width() - 2; | ||
188 | int hi = r.height() - 2; | ||
189 | if ( !pix || pix->height() != hi || pix->width() != wi ) { | ||
190 | delete pix; | ||
191 | QImage img( wi, hi, 32 ); | ||
192 | int y; | ||
193 | for ( y = 0; y < hi; y++ ) { | ||
194 | QColor c( hue, sat, y2val(y+coff), QColor::Hsv ); | ||
195 | QRgb r = c.rgb(); | ||
196 | int x; | ||
197 | for ( x = 0; x < wi; x++ ) | ||
198 | img.setPixel( x, y, r ); | ||
199 | } | ||
200 | pix = new QPixmap; | ||
201 | pix->convertFromImage(img); | ||
202 | } | ||
203 | QPainter p(this); | ||
204 | p.drawPixmap( 1, coff, *pix ); | ||
205 | QColorGroup g = colorGroup(); | ||
206 | qDrawShadePanel( &p, r, g, TRUE ); | ||
207 | p.setPen( g.foreground() ); | ||
208 | p.setBrush( g.foreground() ); | ||
209 | QPointArray a; | ||
210 | int y = val2y(val); | ||
211 | a.setPoints( 3, w, y, w+5, y+5, w+5, y-5 ); | ||
212 | erase( w, 0, 5, height() ); | ||
213 | p.drawPolygon( a ); | ||
214 | } | ||
215 | |||
216 | void QColorLuminancePicker::setCol( int h, int s , int v ) | ||
217 | { | ||
218 | val = v; | ||
219 | hue = h; | ||
220 | sat = s; | ||
221 | delete pix; pix=0; | ||
222 | repaint( FALSE );//#### | ||
223 | } | ||
224 | |||
225 | QPoint QColorPicker::colPt() | ||
226 | { return QPoint( (360-hue)*(pWidth-1)/360, (255-sat)*(pHeight-1)/255 ); } | ||
227 | int QColorPicker::huePt( const QPoint &pt ) | ||
228 | { return 360 - pt.x()*360/(pWidth-1); } | ||
229 | int QColorPicker::satPt( const QPoint &pt ) | ||
230 | { return 255 - pt.y()*255/(pHeight-1) ; } | ||
231 | void QColorPicker::setCol( const QPoint &pt ) | ||
232 | { setCol( huePt(pt), satPt(pt) ); } | ||
233 | |||
234 | QColorPicker::QColorPicker(QWidget* parent, const char* name ) | ||
235 | : QFrame( parent, name ) | ||
236 | { | ||
237 | hue = 0; sat = 0; | ||
238 | setCol( 150, 255 ); | ||
239 | |||
240 | QImage img( pWidth, pHeight, 32 ); | ||
241 | int x,y; | ||
242 | for ( y = 0; y < pHeight; y++ ) | ||
243 | for ( x = 0; x < pWidth; x++ ) { | ||
244 | QPoint p( x, y ); | ||
245 | img.setPixel( x, y, QColor(huePt(p), satPt(p), | ||
246 | 200, QColor::Hsv).rgb() ); | ||
247 | } | ||
248 | pix = new QPixmap; | ||
249 | pix->convertFromImage(img); | ||
250 | setBackgroundMode( NoBackground ); | ||
251 | } | ||
252 | |||
253 | QColorPicker::~QColorPicker() | ||
254 | { | ||
255 | delete pix; | ||
256 | } | ||
257 | |||
258 | QSize QColorPicker::sizeHint() const | ||
259 | { | ||
260 | return QSize( pWidth + 2*frameWidth(), pHeight + 2*frameWidth() ); | ||
261 | } | ||
262 | |||
263 | QSizePolicy QColorPicker::sizePolicy() const | ||
264 | { | ||
265 | return QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); | ||
266 | } | ||
267 | |||
268 | void QColorPicker::setCol( int h, int s ) | ||
269 | { | ||
270 | int nhue = QMIN( QMAX(0,h), 360 ); | ||
271 | int nsat = QMIN( QMAX(0,s), 255); | ||
272 | if ( nhue == hue && nsat == sat ) | ||
273 | return; | ||
274 | QRect r( colPt(), QSize(20,20) ); | ||
275 | hue = nhue; sat = nsat; | ||
276 | r = r.unite( QRect( colPt(), QSize(20,20) ) ); | ||
277 | r.moveBy( contentsRect().x()-9, contentsRect().y()-9 ); | ||
278 | // update( r ); | ||
279 | repaint( r, FALSE ); | ||
280 | } | ||
281 | |||
282 | void QColorPicker::mouseMoveEvent( QMouseEvent *m ) | ||
283 | { | ||
284 | QPoint p = m->pos() - contentsRect().topLeft(); | ||
285 | setCol( p ); | ||
286 | emit newCol( hue, sat ); | ||
287 | } | ||
288 | |||
289 | void QColorPicker::mousePressEvent( QMouseEvent *m ) | ||
290 | { | ||
291 | QPoint p = m->pos() - contentsRect().topLeft(); | ||
292 | setCol( p ); | ||
293 | emit newCol( hue, sat ); | ||
294 | } | ||
295 | |||
296 | void QColorPicker::drawContents(QPainter* p) | ||
297 | { | ||
298 | QRect r = contentsRect(); | ||
299 | |||
300 | p->drawPixmap( r.topLeft(), *pix ); | ||
301 | QPoint pt = colPt() + r.topLeft(); | ||
302 | p->setPen( QPen(black) ); | ||
303 | |||
304 | p->fillRect( pt.x()-9, pt.y(), 20, 2, black ); | ||
305 | p->fillRect( pt.x(), pt.y()-9, 2, 20, black ); | ||
306 | |||
307 | } | ||
308 | |||
309 | class QColorShowLabel; | ||
310 | |||
311 | |||
312 | |||
313 | class QColIntValidator: public QIntValidator | ||
314 | { | ||
315 | public: | ||
316 | QColIntValidator( int bottom, int top, | ||
317 | QWidget * parent, const char *name = 0 ) | ||
318 | :QIntValidator( bottom, top, parent, name ) {} | ||
319 | |||
320 | QValidator::State validate( QString &, int & ) const; | ||
321 | }; | ||
322 | |||
323 | QValidator::State QColIntValidator::validate( QString &s, int &pos ) const | ||
324 | { | ||
325 | State state = QIntValidator::validate(s,pos); | ||
326 | if ( state == Valid ) { | ||
327 | long int val = s.toLong(); | ||
328 | // This is not a general solution, assumes that top() > 0 and | ||
329 | // bottom >= 0 | ||
330 | if ( val < 0 ) { | ||
331 | s = "0"; | ||
332 | pos = 1; | ||
333 | } else if ( val > top() ) { | ||
334 | s.setNum( top() ); | ||
335 | pos = s.length(); | ||
336 | } | ||
337 | } | ||
338 | return state; | ||
339 | } | ||
340 | |||
341 | |||
342 | |||
343 | class QColNumLineEdit : public QLineEdit | ||
344 | { | ||
345 | public: | ||
346 | QColNumLineEdit( QWidget *parent, const char* name = 0 ) | ||
347 | : QLineEdit( parent, name ) { setMaxLength( 3 );} | ||
348 | QSize sizeHint() const { | ||
349 | return QSize( 30, //##### | ||
350 | QLineEdit::sizeHint().height() ); } | ||
351 | void setNum( int i ) { | ||
352 | QString s; | ||
353 | s.setNum(i); | ||
354 | bool block = signalsBlocked(); | ||
355 | blockSignals(TRUE); | ||
356 | setText( s ); | ||
357 | blockSignals(block); | ||
358 | } | ||
359 | int val() const { return text().toInt(); } | ||
360 | }; | ||
361 | |||
362 | |||
363 | class QColorShower : public QWidget | ||
364 | { | ||
365 | Q_OBJECT | ||
366 | public: | ||
367 | QColorShower( QWidget *parent, const char *name = 0 ); | ||
368 | |||
369 | //things that don't emit signals | ||
370 | void setHsv( int h, int s, int v ); | ||
371 | |||
372 | int currentAlpha() const { return alphaEd->val(); } | ||
373 | void setCurrentAlpha( int a ) { alphaEd->setNum( a ); } | ||
374 | void showAlpha( bool b ); | ||
375 | |||
376 | |||
377 | QRgb currentColor() const { return curCol; } | ||
378 | |||
379 | public slots: | ||
380 | void setRgb( QRgb rgb ); | ||
381 | |||
382 | signals: | ||
383 | void newCol( QRgb rgb ); | ||
384 | private slots: | ||
385 | void rgbEd(); | ||
386 | void hsvEd(); | ||
387 | private: | ||
388 | void showCurrentColor(); | ||
389 | int hue, sat, val; | ||
390 | QRgb curCol; | ||
391 | QColNumLineEdit *hEd; | ||
392 | QColNumLineEdit *sEd; | ||
393 | QColNumLineEdit *vEd; | ||
394 | QColNumLineEdit *rEd; | ||
395 | QColNumLineEdit *gEd; | ||
396 | QColNumLineEdit *bEd; | ||
397 | QColNumLineEdit *alphaEd; | ||
398 | QLabel *alphaLab; | ||
399 | QColorShowLabel *lab; | ||
400 | bool rgbOriginal; | ||
401 | }; | ||
402 | |||
403 | class QColorShowLabel : public QFrame | ||
404 | { | ||
405 | Q_OBJECT | ||
406 | |||
407 | public: | ||
408 | QColorShowLabel( QWidget *parent ) :QFrame( parent ) { | ||
409 | setFrameStyle( QFrame::Panel|QFrame::Sunken ); | ||
410 | setBackgroundMode( PaletteBackground ); | ||
411 | setAcceptDrops( TRUE ); | ||
412 | mousePressed = FALSE; | ||
413 | } | ||
414 | void setColor( QColor c ) { col = c; } | ||
415 | |||
416 | signals: | ||
417 | void colorDropped( QRgb ); | ||
418 | |||
419 | protected: | ||
420 | void drawContents( QPainter *p ); | ||
421 | void mousePressEvent( QMouseEvent *e ); | ||
422 | void mouseReleaseEvent( QMouseEvent *e ); | ||
423 | |||
424 | private: | ||
425 | QColor col; | ||
426 | bool mousePressed; | ||
427 | QPoint pressPos; | ||
428 | |||
429 | }; | ||
430 | |||
431 | void QColorShowLabel::drawContents( QPainter *p ) | ||
432 | { | ||
433 | p->fillRect( contentsRect(), col ); | ||
434 | } | ||
435 | |||
436 | void QColorShower::showAlpha( bool b ) | ||
437 | { | ||
438 | if ( b ) { | ||
439 | alphaLab->show(); | ||
440 | alphaEd->show(); | ||
441 | } else { | ||
442 | alphaLab->hide(); | ||
443 | alphaEd->hide(); | ||
444 | } | ||
445 | } | ||
446 | |||
447 | void QColorShowLabel::mousePressEvent( QMouseEvent *e ) | ||
448 | { | ||
449 | mousePressed = TRUE; | ||
450 | pressPos = e->pos(); | ||
451 | } | ||
452 | |||
453 | void QColorShowLabel::mouseReleaseEvent( QMouseEvent * ) | ||
454 | { | ||
455 | if ( !mousePressed ) | ||
456 | return; | ||
457 | mousePressed = FALSE; | ||
458 | } | ||
459 | |||
460 | QColorShower::QColorShower( QWidget *parent, const char *name ) | ||
461 | :QWidget( parent, name) | ||
462 | { | ||
463 | curCol = qRgb( -1, -1, -1 ); | ||
464 | QColIntValidator *val256 = new QColIntValidator( 0, 255, this ); | ||
465 | QColIntValidator *val360 = new QColIntValidator( 0, 360, this ); | ||
466 | |||
467 | QGridLayout *gl = new QGridLayout( this, 1, 1, 2 ); | ||
468 | gl->setMargin( 0 ); | ||
469 | lab = new QColorShowLabel( this ); | ||
470 | lab->setMinimumWidth( 60 ); //### | ||
471 | gl->addMultiCellWidget(lab, 0,-1,0,0); | ||
472 | connect( lab, SIGNAL( colorDropped( QRgb ) ), | ||
473 | this, SIGNAL( newCol( QRgb ) ) ); | ||
474 | connect( lab, SIGNAL( colorDropped( QRgb ) ), | ||
475 | this, SLOT( setRgb( QRgb ) ) ); | ||
476 | |||
477 | hEd = new QColNumLineEdit( this ); | ||
478 | hEd->setValidator( val360 ); | ||
479 | QLabel *l = new QLabel( hEd, QColorDialog::tr("Hue:"), this ); | ||
480 | l->setAlignment( AlignRight|AlignVCenter ); | ||
481 | gl->addWidget( l, 0, 1 ); | ||
482 | gl->addWidget( hEd, 0, 2 ); | ||
483 | |||
484 | sEd = new QColNumLineEdit( this ); | ||
485 | sEd->setValidator( val256 ); | ||
486 | l = new QLabel( sEd, QColorDialog::tr("Sat:"), this ); | ||
487 | l->setAlignment( AlignRight|AlignVCenter ); | ||
488 | gl->addWidget( l, 1, 1 ); | ||
489 | gl->addWidget( sEd, 1, 2 ); | ||
490 | |||
491 | vEd = new QColNumLineEdit( this ); | ||
492 | vEd->setValidator( val256 ); | ||
493 | l = new QLabel( vEd, QColorDialog::tr("Val:"), this ); | ||
494 | l->setAlignment( AlignRight|AlignVCenter ); | ||
495 | gl->addWidget( l, 2, 1 ); | ||
496 | gl->addWidget( vEd, 2, 2 ); | ||
497 | |||
498 | rEd = new QColNumLineEdit( this ); | ||
499 | rEd->setValidator( val256 ); | ||
500 | l = new QLabel( rEd, QColorDialog::tr("Red:"), this ); | ||
501 | l->setAlignment( AlignRight|AlignVCenter ); | ||
502 | gl->addWidget( l, 0, 3 ); | ||
503 | gl->addWidget( rEd, 0, 4 ); | ||
504 | |||
505 | gEd = new QColNumLineEdit( this ); | ||
506 | gEd->setValidator( val256 ); | ||
507 | l = new QLabel( gEd, QColorDialog::tr("Green:"), this ); | ||
508 | l->setAlignment( AlignRight|AlignVCenter ); | ||
509 | gl->addWidget( l, 1, 3 ); | ||
510 | gl->addWidget( gEd, 1, 4 ); | ||
511 | |||
512 | bEd = new QColNumLineEdit( this ); | ||
513 | bEd->setValidator( val256 ); | ||
514 | l = new QLabel( bEd, QColorDialog::tr("Blue:"), this ); | ||
515 | l->setAlignment( AlignRight|AlignVCenter ); | ||
516 | gl->addWidget( l, 2, 3 ); | ||
517 | gl->addWidget( bEd, 2, 4 ); | ||
518 | |||
519 | alphaEd = new QColNumLineEdit( this ); | ||
520 | alphaEd->setValidator( val256 ); | ||
521 | alphaLab = new QLabel( alphaEd, QColorDialog::tr("Alpha channel:"), this ); | ||
522 | alphaLab->setAlignment( AlignRight|AlignVCenter ); | ||
523 | gl->addMultiCellWidget( alphaLab, 3, 3, 1, 3 ); | ||
524 | gl->addWidget( alphaEd, 3, 4 ); | ||
525 | alphaEd->hide(); | ||
526 | alphaLab->hide(); | ||
527 | |||
528 | connect( hEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) ); | ||
529 | connect( sEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) ); | ||
530 | connect( vEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) ); | ||
531 | |||
532 | connect( rEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) ); | ||
533 | connect( gEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) ); | ||
534 | connect( bEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) ); | ||
535 | } | ||
536 | |||
537 | void QColorShower::showCurrentColor() | ||
538 | { | ||
539 | lab->setColor( currentColor() ); | ||
540 | lab->repaint(FALSE); //### | ||
541 | } | ||
542 | |||
543 | void QColorShower::rgbEd() | ||
544 | { | ||
545 | rgbOriginal = TRUE; | ||
546 | curCol = qRgb( rEd->val(), gEd->val(), bEd->val() ); | ||
547 | rgb2hsv(currentColor(), hue, sat, val ); | ||
548 | |||
549 | hEd->setNum( hue ); | ||
550 | sEd->setNum( sat ); | ||
551 | vEd->setNum( val ); | ||
552 | |||
553 | showCurrentColor(); | ||
554 | emit newCol( currentColor() ); | ||
555 | } | ||
556 | |||
557 | void QColorShower::hsvEd() | ||
558 | { | ||
559 | rgbOriginal = FALSE; | ||
560 | hue = hEd->val(); | ||
561 | sat = sEd->val(); | ||
562 | val = vEd->val(); | ||
563 | |||
564 | curCol = QColor( hue, sat, val, QColor::Hsv ).rgb(); | ||
565 | |||
566 | rEd->setNum( qRed(currentColor()) ); | ||
567 | gEd->setNum( qGreen(currentColor()) ); | ||
568 | bEd->setNum( qBlue(currentColor()) ); | ||
569 | |||
570 | showCurrentColor(); | ||
571 | emit newCol( currentColor() ); | ||
572 | } | ||
573 | |||
574 | void QColorShower::setRgb( QRgb rgb ) | ||
575 | { | ||
576 | rgbOriginal = TRUE; | ||
577 | curCol = rgb; | ||
578 | |||
579 | rgb2hsv( currentColor(), hue, sat, val ); | ||
580 | |||
581 | hEd->setNum( hue ); | ||
582 | sEd->setNum( sat ); | ||
583 | vEd->setNum( val ); | ||
584 | |||
585 | rEd->setNum( qRed(currentColor()) ); | ||
586 | gEd->setNum( qGreen(currentColor()) ); | ||
587 | bEd->setNum( qBlue(currentColor()) ); | ||
588 | |||
589 | showCurrentColor(); | ||
590 | } | ||
591 | |||
592 | void QColorShower::setHsv( int h, int s, int v ) | ||
593 | { | ||
594 | rgbOriginal = FALSE; | ||
595 | hue = h; val = v; sat = s; //Range check### | ||
596 | curCol = QColor( hue, sat, val, QColor::Hsv ).rgb(); | ||
597 | |||
598 | hEd->setNum( hue ); | ||
599 | sEd->setNum( sat ); | ||
600 | vEd->setNum( val ); | ||
601 | |||
602 | rEd->setNum( qRed(currentColor()) ); | ||
603 | gEd->setNum( qGreen(currentColor()) ); | ||
604 | bEd->setNum( qBlue(currentColor()) ); | ||
605 | |||
606 | |||
607 | showCurrentColor(); | ||
608 | } | ||
609 | |||
610 | class QColorDialogPrivate : public QObject | ||
611 | { | ||
612 | Q_OBJECT | ||
613 | public: | ||
614 | QColorDialogPrivate( QColorDialog *p ); | ||
615 | QRgb currentColor() const { return cs->currentColor(); } | ||
616 | void setCurrentColor( QRgb rgb ); | ||
617 | |||
618 | int currentAlpha() const { return cs->currentAlpha(); } | ||
619 | void setCurrentAlpha( int a ) { cs->setCurrentAlpha( a ); } | ||
620 | void showAlpha( bool b ) { cs->showAlpha( b ); } | ||
621 | |||
622 | private slots: | ||
623 | void newHsv( int h, int s, int v ); | ||
624 | void newColorTypedIn( QRgb rgb ); | ||
625 | private: | ||
626 | QColorPicker *cp; | ||
627 | QColorLuminancePicker *lp; | ||
628 | QColorShower *cs; | ||
629 | }; | ||
630 | |||
631 | //sets all widgets to display h,s,v | ||
632 | void QColorDialogPrivate::newHsv( int h, int s, int v ) | ||
633 | { | ||
634 | cs->setHsv( h, s, v ); | ||
635 | cp->setCol( h, s ); | ||
636 | lp->setCol( h, s, v ); | ||
637 | } | ||
638 | |||
639 | //sets all widgets to display rgb | ||
640 | void QColorDialogPrivate::setCurrentColor( QRgb rgb ) | ||
641 | { | ||
642 | cs->setRgb( rgb ); | ||
643 | newColorTypedIn( rgb ); | ||
644 | } | ||
645 | |||
646 | //sets all widgets exept cs to display rgb | ||
647 | void QColorDialogPrivate::newColorTypedIn( QRgb rgb ) | ||
648 | { | ||
649 | int h, s, v; | ||
650 | rgb2hsv(rgb, h, s, v ); | ||
651 | cp->setCol( h, s ); | ||
652 | lp->setCol( h, s, v); | ||
653 | } | ||
654 | |||
655 | QColorDialogPrivate::QColorDialogPrivate( QColorDialog *dialog ) : | ||
656 | QObject(dialog) | ||
657 | { | ||
658 | int border = 2; | ||
659 | QVBoxLayout *topLay = new QVBoxLayout( dialog, border, 2 ); | ||
660 | |||
661 | QHBoxLayout *pickLay = new QHBoxLayout( topLay ); | ||
662 | |||
663 | |||
664 | cp = new QColorPicker( dialog ); | ||
665 | cp->setFrameStyle( QFrame::Panel + QFrame::Sunken ); | ||
666 | pickLay->addWidget( cp ); | ||
667 | |||
668 | pickLay->addStretch(); | ||
669 | |||
670 | lp = new QColorLuminancePicker( dialog ); | ||
671 | lp->setFixedWidth( 20 ); //### | ||
672 | pickLay->addWidget( lp ); | ||
673 | |||
674 | connect( cp, SIGNAL(newCol(int,int)), lp, SLOT(setCol(int,int)) ); | ||
675 | connect( lp, SIGNAL(newHsv(int,int,int)), this, SLOT(newHsv(int,int,int)) ); | ||
676 | |||
677 | topLay->addStretch(); | ||
678 | |||
679 | cs = new QColorShower( dialog ); | ||
680 | connect( cs, SIGNAL(newCol(QRgb)), this, SLOT(newColorTypedIn(QRgb))); | ||
681 | topLay->addWidget( cs ); | ||
682 | |||
683 | } | ||
684 | |||
685 | |||
686 | // BEING REVISED: jo | ||
687 | /*! | ||
688 | \class QColorDialog qcolordialog.h | ||
689 | \brief The QColorDialog class provides a dialog widget for specifying colors. | ||
690 | \ingroup dialogs | ||
691 | |||
692 | The color dialog's function is to allow users to choose colors - | ||
693 | for instance, you might use this in a drawing program to allow the | ||
694 | user to set the brush color. | ||
695 | |||
696 | This version of Qt only provides modal color dialogs. The static | ||
697 | getColor() function shows the dialog and allows the user to specify a color, | ||
698 | while getRgba() does the same but allows the user to specify a color with an | ||
699 | alpha channel (transparency) value. | ||
700 | |||
701 | The user can store customCount() different custom colors. The custom | ||
702 | colors are shared by all color dialogs, and remembered during the | ||
703 | execution of the program. Use setCustomColor() to set the | ||
704 | custom colors, and customColor() to get them. | ||
705 | |||
706 | <img src=qcolordlg-m.png> <img src=qcolordlg-w.png> | ||
707 | */ | ||
708 | |||
709 | /*! | ||
710 | Constructs a default color dialog. Use setColor() for setting an initial value. | ||
711 | |||
712 | \sa getColor() | ||
713 | */ | ||
714 | |||
715 | QColorDialog::QColorDialog(QWidget* parent, const char* name, bool modal) : | ||
716 | QDialog(parent, name, modal ) | ||
717 | { | ||
718 | d = new QColorDialogPrivate( this ); | ||
719 | } | ||
720 | |||
721 | |||
722 | /*! | ||
723 | Pops up a modal color dialog letting the user choose a color and returns | ||
724 | that color. The color is initially set to \a initial. Returns an \link QColor::isValid() invalid\endlink color if the user cancels | ||
725 | the dialog. All colors allocated by the dialog will be deallocated | ||
726 | before this function returns. | ||
727 | */ | ||
728 | |||
729 | QColor QColorDialog::getColor( QColor initial, QWidget *parent, | ||
730 | const char *name ) | ||
731 | { | ||
732 | int allocContext = QColor::enterAllocContext(); | ||
733 | QColorDialog *dlg = new QColorDialog( parent, name, TRUE ); //modal | ||
734 | if ( parent && parent->icon() && !parent->icon()->isNull() ) | ||
735 | dlg->setIcon( *parent->icon() ); | ||
736 | else if ( qApp->mainWidget() && qApp->mainWidget()->icon() && !qApp->mainWidget()->icon()->isNull() ) | ||
737 | dlg->setIcon( *qApp->mainWidget()->icon() ); | ||
738 | |||
739 | dlg->setCaption( QColorDialog::tr( "Select color" ) ); | ||
740 | dlg->setColor( initial ); | ||
741 | dlg->showMaximized(); | ||
742 | int resultCode = dlg->exec(); | ||
743 | QColor::leaveAllocContext(); | ||
744 | QColor result; | ||
745 | if ( resultCode == QDialog::Accepted ) { | ||
746 | result = dlg->color(); | ||
747 | } else { | ||
748 | result = initial; | ||
749 | } | ||
750 | QColor::destroyAllocContext(allocContext); | ||
751 | delete dlg; | ||
752 | return result; | ||
753 | } | ||
754 | |||
755 | |||
756 | /*! | ||
757 | Pops up a modal color dialog, letting the user choose a color and an | ||
758 | alpha channel value. The color+alpha is initially set to \a initial. | ||
759 | |||
760 | If \a ok is non-null, \c *ok is set to TRUE if the user clicked OK, | ||
761 | and FALSE if the user clicked Cancel. | ||
762 | |||
763 | If the user clicks Cancel the \a initial value is returned. | ||
764 | */ | ||
765 | |||
766 | QRgb QColorDialog::getRgba( QRgb initial, bool *ok, | ||
767 | QWidget *parent, const char* name ) | ||
768 | { | ||
769 | int allocContext = QColor::enterAllocContext(); | ||
770 | QColorDialog *dlg = new QColorDialog( parent, name, TRUE ); //modal | ||
771 | dlg->setColor( initial ); | ||
772 | dlg->setSelectedAlpha( qAlpha(initial) ); | ||
773 | dlg->showMaximized(); | ||
774 | int resultCode = dlg->exec(); | ||
775 | QColor::leaveAllocContext(); | ||
776 | QRgb result = initial; | ||
777 | if ( resultCode == QDialog::Accepted ) { | ||
778 | QRgb c = dlg->color().rgb(); | ||
779 | int alpha = dlg->selectedAlpha(); | ||
780 | result = qRgba( qRed(c), qGreen(c), qBlue(c), alpha ); | ||
781 | } | ||
782 | if ( ok ) | ||
783 | *ok = resultCode == QDialog::Accepted; | ||
784 | |||
785 | QColor::destroyAllocContext(allocContext); | ||
786 | delete dlg; | ||
787 | return result; | ||
788 | } | ||
789 | |||
790 | |||
791 | |||
792 | |||
793 | |||
794 | /*! | ||
795 | Returns the color currently selected in the dialog. | ||
796 | |||
797 | \sa setColor() | ||
798 | */ | ||
799 | |||
800 | QColor QColorDialog::color() const | ||
801 | { | ||
802 | return QColor(d->currentColor()); | ||
803 | } | ||
804 | |||
805 | |||
806 | /*! Destructs the dialog and frees any memory it allocated. | ||
807 | |||
808 | */ | ||
809 | |||
810 | QColorDialog::~QColorDialog() | ||
811 | { | ||
812 | //d inherits QObject, so it is deleted by Qt. | ||
813 | } | ||
814 | |||
815 | |||
816 | /*! | ||
817 | Sets the color shown in the dialog to \a c. | ||
818 | |||
819 | \sa color() | ||
820 | */ | ||
821 | |||
822 | void QColorDialog::setColor( QColor c ) | ||
823 | { | ||
824 | d->setCurrentColor( c.rgb() ); | ||
825 | } | ||
826 | |||
827 | |||
828 | |||
829 | |||
830 | /*! | ||
831 | Sets the initial alpha channel value to \a a, and show the alpha channel | ||
832 | entry box. | ||
833 | */ | ||
834 | |||
835 | void QColorDialog::setSelectedAlpha( int a ) | ||
836 | { | ||
837 | d->showAlpha( TRUE ); | ||
838 | d->setCurrentAlpha( a ); | ||
839 | } | ||
840 | |||
841 | |||
842 | /*! | ||
843 | Returns the value selected for the alpha channel. | ||
844 | */ | ||
845 | |||
846 | int QColorDialog::selectedAlpha() const | ||
847 | { | ||
848 | return d->currentAlpha(); | ||
849 | } | ||
850 | |||
851 | #include "colordialog.moc" | ||
diff --git a/noncore/graphics/drawpad/colordialog.h b/noncore/graphics/drawpad/colordialog.h new file mode 100644 index 0000000..a2d4d30 --- a/dev/null +++ b/noncore/graphics/drawpad/colordialog.h | |||
@@ -0,0 +1,77 @@ | |||
1 | /**************************************************************************** | ||
2 | ** $Id$ | ||
3 | ** | ||
4 | ** Definition of QColorDialog class | ||
5 | ** | ||
6 | ** Created : 990222 | ||
7 | ** | ||
8 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. | ||
9 | ** | ||
10 | ** This file is part of the dialogs module of the Qt GUI Toolkit. | ||
11 | ** | ||
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 | ||
14 | ** LICENSE.QPL included in the packaging of this file. | ||
15 | ** | ||
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 | ||
18 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
19 | ** packaging of this file. | ||
20 | ** | ||
21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition | ||
22 | ** licenses may use this file in accordance with the Qt Commercial License | ||
23 | ** Agreement provided with the Software. | ||
24 | ** | ||
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. | ||
27 | ** | ||
28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | ||
29 | ** information about Qt Commercial License Agreements. | ||
30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. | ||
31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
32 | ** | ||
33 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
34 | ** not clear to you. | ||
35 | ** | ||
36 | **********************************************************************/ | ||
37 | |||
38 | #ifndef QCOLORDIALOG_H | ||
39 | #define QCOLORDIALOG_H | ||
40 | |||
41 | #ifndef QT_H | ||
42 | #include <qdialog.h> | ||
43 | #endif // QT_H | ||
44 | |||
45 | class QColorDialogPrivate; | ||
46 | |||
47 | class Q_EXPORT QColorDialog : public QDialog | ||
48 | { | ||
49 | Q_OBJECT | ||
50 | |||
51 | public: | ||
52 | static QColor getColor( QColor, QWidget *parent=0, const char* name=0 ); // ### 3.0: make const QColor& | ||
53 | static QRgb getRgba( QRgb, bool* ok = 0, | ||
54 | QWidget *parent=0, const char* name=0 ); | ||
55 | |||
56 | private: | ||
57 | ~QColorDialog(); | ||
58 | |||
59 | QColorDialog( QWidget* parent=0, const char* name=0, bool modal=FALSE ); | ||
60 | void setColor( QColor ); // ### 3.0: make const QColor& | ||
61 | QColor color() const; | ||
62 | |||
63 | private: | ||
64 | void setSelectedAlpha( int ); | ||
65 | int selectedAlpha() const; | ||
66 | private: | ||
67 | QColorDialogPrivate *d; | ||
68 | friend class QColorDialogPrivate; | ||
69 | |||
70 | private:// Disabled copy constructor and operator= | ||
71 | #if defined(Q_DISABLE_COPY) | ||
72 | QColorDialog( const QColorDialog & ); | ||
73 | QColorDialog& operator=( const QColorDialog & ); | ||
74 | #endif | ||
75 | }; | ||
76 | |||
77 | #endif | ||
diff --git a/noncore/graphics/drawpad/colorpanel.cpp b/noncore/graphics/drawpad/colorpanel.cpp new file mode 100644 index 0000000..1db0d7b --- a/dev/null +++ b/noncore/graphics/drawpad/colorpanel.cpp | |||
@@ -0,0 +1,134 @@ | |||
1 | /*************************************************************************** | ||
2 | * * | ||
3 | * DrawPad - a drawing program for Opie Environment * | ||
4 | * * | ||
5 | * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * | ||
6 | * * | ||
7 | * This program is free software; you can redistribute it and/or modify * | ||
8 | * it under the terms of the GNU General Public License as published by * | ||
9 | * the Free Software Foundation; either version 2 of the License, or * | ||
10 | * (at your option) any later version. * | ||
11 | * * | ||
12 | ***************************************************************************/ | ||
13 | |||
14 | #include "colorpanel.h" | ||
15 | |||
16 | #include <qlayout.h> | ||
17 | #include <qpainter.h> | ||
18 | |||
19 | ColorPanelButton::ColorPanelButton(const QColor& color, QWidget* parent, const char* name) | ||
20 | : QFrame(parent, name) | ||
21 | { | ||
22 | m_color = color; | ||
23 | |||
24 | setFixedSize(16, 16); | ||
25 | setActive(false); | ||
26 | } | ||
27 | |||
28 | ColorPanelButton::~ColorPanelButton() | ||
29 | { | ||
30 | } | ||
31 | |||
32 | void ColorPanelButton::setActive(bool active) | ||
33 | { | ||
34 | m_active = active; | ||
35 | |||
36 | if (m_active) { | ||
37 | setFrameStyle(Panel | Sunken); | ||
38 | } else { | ||
39 | setFrameStyle(NoFrame); | ||
40 | } | ||
41 | } | ||
42 | |||
43 | void ColorPanelButton::enterEvent(QEvent* e) | ||
44 | { | ||
45 | Q_UNUSED(e) | ||
46 | |||
47 | if (!m_active) { | ||
48 | setFrameStyle(Panel | Sunken); | ||
49 | } | ||
50 | } | ||
51 | |||
52 | void ColorPanelButton::leaveEvent(QEvent* e) | ||
53 | { | ||
54 | Q_UNUSED(e) | ||
55 | |||
56 | if (!m_active) { | ||
57 | setFrameStyle(NoFrame); | ||
58 | } | ||
59 | } | ||
60 | |||
61 | void ColorPanelButton::paintEvent(QPaintEvent* e) | ||
62 | { | ||
63 | QFrame::paintEvent(e); | ||
64 | |||
65 | QPainter painter; | ||
66 | painter.begin(this); | ||
67 | painter.fillRect(2, 2, 12, 12, m_color); | ||
68 | painter.setPen(Qt::black); | ||
69 | painter.drawRect(2, 2, 12, 12); | ||
70 | painter.end(); | ||
71 | } | ||
72 | |||
73 | void ColorPanelButton::mouseReleaseEvent(QMouseEvent* e) | ||
74 | { | ||
75 | Q_UNUSED(e) | ||
76 | |||
77 | emit selected(m_color); | ||
78 | } | ||
79 | |||
80 | ColorPanel::ColorPanel(QWidget* parent, const char* name) | ||
81 | : QWidget(parent, name) | ||
82 | { | ||
83 | m_pGridLayout = new QGridLayout(this, 5, 6); | ||
84 | |||
85 | addColor(QColor(255, 255, 255), 0, 1); | ||
86 | addColor(QColor(192, 192, 192), 0, 2); | ||
87 | addColor(QColor(128, 128, 128), 0, 3); | ||
88 | addColor(QColor(64, 64, 64), 0, 4); | ||
89 | addColor(QColor(0, 0, 0), 0, 5); | ||
90 | |||
91 | addColor(QColor(255, 0, 0), 1, 0); | ||
92 | addColor(QColor(255, 128, 0), 1, 1); | ||
93 | addColor(QColor(255, 255, 0), 1, 2); | ||
94 | addColor(QColor(128, 255, 0), 1, 3); | ||
95 | addColor(QColor(0, 255, 0), 1, 4); | ||
96 | addColor(QColor(0, 255, 128), 1, 5); | ||
97 | |||
98 | addColor(QColor(128, 0, 0), 2, 0); | ||
99 | addColor(QColor(128, 64, 0), 2, 1); | ||
100 | addColor(QColor(128, 128, 0), 2, 2); | ||
101 | addColor(QColor(64, 128, 0), 2, 3); | ||
102 | addColor(QColor(0, 128, 0), 2, 4); | ||
103 | addColor(QColor(0, 128, 64), 2, 5); | ||
104 | |||
105 | addColor(QColor(0, 255, 255), 3, 0); | ||
106 | addColor(QColor(0, 128, 255), 3, 1); | ||
107 | addColor(QColor(0, 0, 255), 3, 2); | ||
108 | addColor(QColor(128, 0, 255), 3, 3); | ||
109 | addColor(QColor(255, 0, 255), 3, 4); | ||
110 | addColor(QColor(255, 0, 128), 3, 5); | ||
111 | |||
112 | addColor(QColor(0, 128, 128), 4, 0); | ||
113 | addColor(QColor(0, 64, 128), 4, 1); | ||
114 | addColor(QColor(0, 0, 128), 4, 2); | ||
115 | addColor(QColor(64, 0, 128), 4, 3); | ||
116 | addColor(QColor(128, 0, 128), 4, 4); | ||
117 | addColor(QColor(128, 0, 64), 4, 5); | ||
118 | } | ||
119 | |||
120 | ColorPanel::~ColorPanel() | ||
121 | { | ||
122 | } | ||
123 | |||
124 | void ColorPanel::addColor(const QColor& color, int row, int col) | ||
125 | { | ||
126 | ColorPanelButton* panelButton = new ColorPanelButton(color, this); | ||
127 | connect(panelButton, SIGNAL(selected(const QColor&)), this, SLOT(buttonSelected(const QColor&))); | ||
128 | m_pGridLayout->addWidget(panelButton, row, col); | ||
129 | } | ||
130 | |||
131 | void ColorPanel::buttonSelected(const QColor& color) | ||
132 | { | ||
133 | emit colorSelected(color); | ||
134 | } | ||
diff --git a/noncore/graphics/drawpad/colorpanel.h b/noncore/graphics/drawpad/colorpanel.h new file mode 100644 index 0000000..05364c1 --- a/dev/null +++ b/noncore/graphics/drawpad/colorpanel.h | |||
@@ -0,0 +1,65 @@ | |||
1 | /*************************************************************************** | ||
2 | * * | ||
3 | * DrawPad - a drawing program for Opie Environment * | ||
4 | * * | ||
5 | * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * | ||
6 | * * | ||
7 | * This program is free software; you can redistribute it and/or modify * | ||
8 | * it under the terms of the GNU General Public License as published by * | ||
9 | * the Free Software Foundation; either version 2 of the License, or * | ||
10 | * (at your option) any later version. * | ||
11 | * * | ||
12 | ***************************************************************************/ | ||
13 | |||
14 | #ifndef COLORPANEL_H | ||
15 | #define COLORPANEL_H | ||
16 | |||
17 | #include <qframe.h> | ||
18 | #include <qwidget.h> | ||
19 | |||
20 | class QGridLayout; | ||
21 | |||
22 | class ColorPanelButton : public QFrame | ||
23 | { | ||
24 | Q_OBJECT | ||
25 | |||
26 | public: | ||
27 | ColorPanelButton(const QColor& color, QWidget* parent = 0, const char* name = 0); | ||
28 | ~ColorPanelButton(); | ||
29 | |||
30 | void setActive(bool active); | ||
31 | |||
32 | void enterEvent(QEvent* e); | ||
33 | void leaveEvent(QEvent* e); | ||
34 | void paintEvent(QPaintEvent* e); | ||
35 | void mouseReleaseEvent(QMouseEvent* e); | ||
36 | |||
37 | signals: | ||
38 | void selected(const QColor&); | ||
39 | |||
40 | private: | ||
41 | QColor m_color; | ||
42 | bool m_active; | ||
43 | }; | ||
44 | |||
45 | class ColorPanel : public QWidget | ||
46 | { | ||
47 | Q_OBJECT | ||
48 | |||
49 | public: | ||
50 | ColorPanel(QWidget* parent = 0, const char* name = 0); | ||
51 | ~ColorPanel(); | ||
52 | |||
53 | void addColor(const QColor& color, int row, int col); | ||
54 | |||
55 | public slots: | ||
56 | void buttonSelected(const QColor& color); | ||
57 | |||
58 | signals: | ||
59 | void colorSelected(const QColor&); | ||
60 | |||
61 | private: | ||
62 | QGridLayout* m_pGridLayout; | ||
63 | }; | ||
64 | |||
65 | #endif // COLORPANEL_H | ||
diff --git a/noncore/graphics/drawpad/drawmode.h b/noncore/graphics/drawpad/drawmode.h index 4e80fe2..01e42cc 100644 --- a/noncore/graphics/drawpad/drawmode.h +++ b/noncore/graphics/drawpad/drawmode.h | |||
@@ -1,39 +1,39 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * DrawPad - a drawing program for Opie Environment * | 3 | * DrawPad - a drawing program for Opie Environment * |
4 | * * | 4 | * * |
5 | * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * | 5 | * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * |
6 | * * | 6 | * * |
7 | * This program is free software; you can redistribute it and/or modify * | 7 | * This program is free software; you can redistribute it and/or modify * |
8 | * it under the terms of the GNU General Public License as published by * | 8 | * it under the terms of the GNU General Public License as published by * |
9 | * the Free Software Foundation; either version 2 of the License, or * | 9 | * the Free Software Foundation; either version 2 of the License, or * |
10 | * (at your option) any later version. * | 10 | * (at your option) any later version. * |
11 | * * | 11 | * * |
12 | ***************************************************************************/ | 12 | ***************************************************************************/ |
13 | 13 | ||
14 | #ifndef DRAWMODE_H | 14 | #ifndef DRAWMODE_H |
15 | #define DRAWMODE_H | 15 | #define DRAWMODE_H |
16 | 16 | ||
17 | #include <qobject.h> | 17 | #include <qobject.h> |
18 | 18 | ||
19 | class DrawPad; | 19 | class DrawPad; |
20 | class DrawPadCanvas; | 20 | class DrawPadCanvas; |
21 | 21 | ||
22 | class DrawMode : QObject | 22 | class DrawMode : public QObject |
23 | { | 23 | { |
24 | protected: | 24 | protected: |
25 | DrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); | 25 | DrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); |
26 | 26 | ||
27 | public: | 27 | public: |
28 | virtual ~DrawMode(); | 28 | virtual ~DrawMode(); |
29 | 29 | ||
30 | virtual void mousePressEvent(QMouseEvent* e) = 0; | 30 | virtual void mousePressEvent(QMouseEvent* e) = 0; |
31 | virtual void mouseReleaseEvent(QMouseEvent* e) = 0; | 31 | virtual void mouseReleaseEvent(QMouseEvent* e) = 0; |
32 | virtual void mouseMoveEvent(QMouseEvent* e) = 0; | 32 | virtual void mouseMoveEvent(QMouseEvent* e) = 0; |
33 | 33 | ||
34 | protected: | 34 | protected: |
35 | DrawPad* m_pDrawPad; | 35 | DrawPad* m_pDrawPad; |
36 | DrawPadCanvas* m_pDrawPadCanvas; | 36 | DrawPadCanvas* m_pDrawPadCanvas; |
37 | }; | 37 | }; |
38 | 38 | ||
39 | #endif // DRAWMODE_H | 39 | #endif // DRAWMODE_H |
diff --git a/noncore/graphics/drawpad/drawpad.cpp b/noncore/graphics/drawpad/drawpad.cpp index 5cc2197..f67bef8 100644 --- a/noncore/graphics/drawpad/drawpad.cpp +++ b/noncore/graphics/drawpad/drawpad.cpp | |||
@@ -1,89 +1,81 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * DrawPad - a drawing program for Opie Environment * | 3 | * DrawPad - a drawing program for Opie Environment * |
4 | * * | 4 | * * |
5 | * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * | 5 | * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * |
6 | * * | 6 | * * |
7 | * This program is free software; you can redistribute it and/or modify * | 7 | * This program is free software; you can redistribute it and/or modify * |
8 | * it under the terms of the GNU General Public License as published by * | 8 | * it under the terms of the GNU General Public License as published by * |
9 | * the Free Software Foundation; either version 2 of the License, or * | 9 | * the Free Software Foundation; either version 2 of the License, or * |
10 | * (at your option) any later version. * | 10 | * (at your option) any later version. * |
11 | * * | 11 | * * |
12 | ***************************************************************************/ | 12 | ***************************************************************************/ |
13 | 13 | ||
14 | #include "drawpad.h" | 14 | #include "drawpad.h" |
15 | 15 | ||
16 | #include "colordialog.h" | ||
17 | #include "colorpanel.h" | ||
16 | #include "drawpadcanvas.h" | 18 | #include "drawpadcanvas.h" |
17 | #include "ellipsedrawmode.h" | 19 | #include "ellipsedrawmode.h" |
18 | #include "erasedrawmode.h" | 20 | #include "erasedrawmode.h" |
19 | #include "filldrawmode.h" | 21 | #include "filldrawmode.h" |
20 | #include "linedrawmode.h" | 22 | #include "linedrawmode.h" |
21 | #include "pointdrawmode.h" | 23 | #include "pointdrawmode.h" |
22 | #include "rectangledrawmode.h" | 24 | #include "rectangledrawmode.h" |
23 | 25 | ||
24 | #include <qpe/global.h> | 26 | #include <qpe/global.h> |
25 | #include <qpe/qpemenubar.h> | 27 | #include <qpe/qpemenubar.h> |
26 | #include <qpe/qpetoolbar.h> | 28 | #include <qpe/qpetoolbar.h> |
27 | #include <qpe/resource.h> | 29 | #include <qpe/resource.h> |
28 | 30 | ||
29 | #include <qaction.h> | 31 | #include <qaction.h> |
30 | #include <qfile.h> | 32 | #include <qfile.h> |
31 | #include <qpainter.h> | 33 | #include <qpainter.h> |
32 | #include <qspinbox.h> | 34 | #include <qspinbox.h> |
33 | #include <qtoolbutton.h> | 35 | #include <qtoolbutton.h> |
34 | #include <qtooltip.h> | 36 | #include <qtooltip.h> |
35 | 37 | ||
36 | DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f) | 38 | DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f) |
37 | : QMainWindow(parent, name, f) | 39 | : QMainWindow(parent, name, f) |
38 | { | 40 | { |
39 | setCaption(tr("DrawPad")); | 41 | setCaption(tr("DrawPad")); |
40 | 42 | ||
41 | // init members | 43 | // init members |
42 | 44 | ||
43 | m_pDrawPadCanvas = new DrawPadCanvas(this, this); | 45 | m_pDrawPadCanvas = new DrawPadCanvas(this, this); |
44 | connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateNavigationToolButtons())); | 46 | connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateNavigationToolButtons())); |
45 | connect(m_pDrawPadCanvas, SIGNAL(pageBackupsChanged()), this, SLOT(updateUndoRedoToolButtons())); | 47 | connect(m_pDrawPadCanvas, SIGNAL(pageBackupsChanged()), this, SLOT(updateUndoRedoToolButtons())); |
46 | 48 | ||
47 | QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); | 49 | QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); |
48 | 50 | ||
49 | if (file.open(IO_ReadOnly)) { | 51 | if (file.open(IO_ReadOnly)) { |
50 | m_pDrawPadCanvas->load(&file); | 52 | m_pDrawPadCanvas->load(&file); |
51 | file.close(); | 53 | file.close(); |
52 | } | 54 | } |
53 | 55 | ||
54 | setCentralWidget(m_pDrawPadCanvas); | 56 | setCentralWidget(m_pDrawPadCanvas); |
55 | 57 | ||
56 | m_colors.resize(8); | ||
57 | m_colors.at(0) = Qt::black; | ||
58 | m_colors.at(1) = Qt::white; | ||
59 | m_colors.at(2) = Qt::red; | ||
60 | m_colors.at(3) = Qt::green; | ||
61 | m_colors.at(4) = Qt::blue; | ||
62 | m_colors.at(5) = Qt::cyan; | ||
63 | m_colors.at(6) = Qt::magenta; | ||
64 | m_colors.at(7) = Qt::yellow; | ||
65 | |||
66 | // init menu | 58 | // init menu |
67 | 59 | ||
68 | setToolBarsMovable(false); | 60 | setToolBarsMovable(false); |
69 | 61 | ||
70 | QPEToolBar* menuToolBar = new QPEToolBar(this); | 62 | QPEToolBar* menuToolBar = new QPEToolBar(this); |
71 | QPEMenuBar* menuBar = new QPEMenuBar(menuToolBar); | 63 | QPEMenuBar* menuBar = new QPEMenuBar(menuToolBar); |
72 | 64 | ||
73 | QPopupMenu *toolsPopupMenu = new QPopupMenu(menuBar); | 65 | QPopupMenu *toolsPopupMenu = new QPopupMenu(menuBar); |
74 | 66 | ||
75 | QAction* clearAllAction = new QAction(tr("Clear All"), QString::null, 0, this); | 67 | QAction* clearAllAction = new QAction(tr("Clear All"), QString::null, 0, this); |
76 | connect(clearAllAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(clearAll())); | 68 | connect(clearAllAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(clearAll())); |
77 | clearAllAction->addTo(toolsPopupMenu); | 69 | clearAllAction->addTo(toolsPopupMenu); |
78 | 70 | ||
79 | toolsPopupMenu->insertSeparator(); | 71 | toolsPopupMenu->insertSeparator(); |
80 | 72 | ||
81 | QAction* setOptionsAction = new QAction(tr("Options"), tr("Options..."), 0, this); | 73 | QAction* setOptionsAction = new QAction(tr("Options"), tr("Options..."), 0, this); |
82 | setOptionsAction->addTo(toolsPopupMenu); | 74 | setOptionsAction->addTo(toolsPopupMenu); |
83 | 75 | ||
84 | menuBar->insertItem(tr("Tools"), toolsPopupMenu); | 76 | menuBar->insertItem(tr("Tools"), toolsPopupMenu); |
85 | 77 | ||
86 | // init page toolbar | 78 | // init page toolbar |
87 | 79 | ||
88 | QPEToolBar* pageToolBar = new QPEToolBar(this); | 80 | QPEToolBar* pageToolBar = new QPEToolBar(this); |
89 | 81 | ||
@@ -167,75 +159,79 @@ DrawPad::DrawPad(QWidget* parent, const char* name, WFlags f) | |||
167 | m_pEraseDrawModeAction->setToggleAction(true); | 159 | m_pEraseDrawModeAction->setToggleAction(true); |
168 | connect(m_pEraseDrawModeAction, SIGNAL(activated()), this, SLOT(setEraseDrawMode())); | 160 | connect(m_pEraseDrawModeAction, SIGNAL(activated()), this, SLOT(setEraseDrawMode())); |
169 | m_pEraseDrawModeAction->addTo(drawModeToolBar); | 161 | m_pEraseDrawModeAction->addTo(drawModeToolBar); |
170 | 162 | ||
171 | m_pDrawMode = 0; | 163 | m_pDrawMode = 0; |
172 | setPointDrawMode(); | 164 | setPointDrawMode(); |
173 | 165 | ||
174 | emptyToolBar = new QPEToolBar(this); | 166 | emptyToolBar = new QPEToolBar(this); |
175 | emptyToolBar->setHorizontalStretchable(true); | 167 | emptyToolBar->setHorizontalStretchable(true); |
176 | emptyToolBar->addSeparator(); | 168 | emptyToolBar->addSeparator(); |
177 | 169 | ||
178 | // init draw parameters toolbar | 170 | // init draw parameters toolbar |
179 | 171 | ||
180 | QPEToolBar* drawParametersToolBar = new QPEToolBar(this); | 172 | QPEToolBar* drawParametersToolBar = new QPEToolBar(this); |
181 | 173 | ||
182 | QSpinBox* penWidthSpinBox = new QSpinBox(1, 9, 1, drawParametersToolBar); | 174 | QSpinBox* penWidthSpinBox = new QSpinBox(1, 9, 1, drawParametersToolBar); |
183 | connect(penWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changePenWidth(int))); | 175 | connect(penWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changePenWidth(int))); |
184 | 176 | ||
185 | penWidthSpinBox->setValue(1); | 177 | penWidthSpinBox->setValue(1); |
186 | 178 | ||
187 | m_pPenColorToolButton = new QToolButton(drawParametersToolBar); | 179 | m_pPenColorToolButton = new QToolButton(drawParametersToolBar); |
188 | m_pPenColorToolButton->setPixmap(Resource::loadPixmap("drawpad/pencolor.png")); | 180 | m_pPenColorToolButton->setPixmap(Resource::loadPixmap("drawpad/pencolor.png")); |
189 | 181 | ||
190 | QPopupMenu* penColorPopupMenu = new QPopupMenu(m_pPenColorToolButton); | 182 | QPopupMenu* penColorPopupMenu = new QPopupMenu(m_pPenColorToolButton); |
191 | connect(penColorPopupMenu, SIGNAL(activated(int)), this, SLOT(changePenColor(int))); | ||
192 | 183 | ||
193 | QPixmap penColorPixmap(14, 14); | 184 | ColorPanel* penColorPanel = new ColorPanel(penColorPopupMenu); |
185 | connect(penColorPanel, SIGNAL(colorSelected(const QColor&)), this, SLOT(changePenColor(const QColor&))); | ||
186 | penColorPopupMenu->insertItem(penColorPanel); | ||
194 | 187 | ||
195 | for (uint i = 0; i < m_colors.size(); i++) { | 188 | penColorPopupMenu->insertSeparator(); |
196 | penColorPixmap.fill(m_colors.at(i)); | 189 | |
197 | penColorPopupMenu->insertItem(penColorPixmap, i); | 190 | QAction* choosePenColorAction = new QAction(tr("More"), tr("More..."), 0, this); |
198 | } | 191 | connect(choosePenColorAction, SIGNAL(activated()), this, SLOT(choosePenColor())); |
192 | choosePenColorAction->addTo(penColorPopupMenu); | ||
199 | 193 | ||
200 | QToolTip::add(m_pPenColorToolButton, tr("Pen Color")); | 194 | QToolTip::add(m_pPenColorToolButton, tr("Pen Color")); |
201 | m_pPenColorToolButton->setPopup(penColorPopupMenu); | 195 | m_pPenColorToolButton->setPopup(penColorPopupMenu); |
202 | m_pPenColorToolButton->setPopupDelay(0); | 196 | m_pPenColorToolButton->setPopupDelay(0); |
203 | 197 | ||
204 | penColorPopupMenu->activateItemAt(0); | 198 | penColorPopupMenu->activateItemAt(0); |
205 | 199 | ||
206 | m_pBrushColorToolButton = new QToolButton(drawParametersToolBar); | 200 | m_pBrushColorToolButton = new QToolButton(drawParametersToolBar); |
207 | m_pBrushColorToolButton->setPixmap(Resource::loadPixmap("drawpad/brushcolor.png")); | 201 | m_pBrushColorToolButton->setPixmap(Resource::loadPixmap("drawpad/brushcolor.png")); |
208 | 202 | ||
209 | QPopupMenu* brushColorPopupMenu = new QPopupMenu(m_pBrushColorToolButton); | 203 | QPopupMenu* brushColorPopupMenu = new QPopupMenu(m_pBrushColorToolButton); |
210 | connect(brushColorPopupMenu, SIGNAL(activated(int)), this, SLOT(changeBrushColor(int))); | ||
211 | 204 | ||
212 | QPixmap brushColorPixmap(14, 14); | 205 | ColorPanel* brushColorPanel = new ColorPanel(brushColorPopupMenu); |
206 | connect(brushColorPanel, SIGNAL(colorSelected(const QColor&)), this, SLOT(changeBrushColor(const QColor&))); | ||
207 | brushColorPopupMenu->insertItem(brushColorPanel); | ||
213 | 208 | ||
214 | for (uint i = 0; i < m_colors.size(); i++) { | 209 | brushColorPopupMenu->insertSeparator(); |
215 | brushColorPixmap.fill(m_colors.at(i)); | 210 | |
216 | brushColorPopupMenu->insertItem(brushColorPixmap, i); | 211 | QAction* chooseBrushColorAction = new QAction(tr("More"), tr("More..."), 0, this); |
217 | } | 212 | connect(chooseBrushColorAction, SIGNAL(activated()), this, SLOT(chooseBrushColor())); |
213 | chooseBrushColorAction->addTo(brushColorPopupMenu); | ||
218 | 214 | ||
219 | QToolTip::add(m_pBrushColorToolButton, tr("Fill Color")); | 215 | QToolTip::add(m_pBrushColorToolButton, tr("Fill Color")); |
220 | m_pBrushColorToolButton->setPopup(brushColorPopupMenu); | 216 | m_pBrushColorToolButton->setPopup(brushColorPopupMenu); |
221 | m_pBrushColorToolButton->setPopupDelay(0); | 217 | m_pBrushColorToolButton->setPopupDelay(0); |
222 | 218 | ||
223 | brushColorPopupMenu->activateItemAt(1); | 219 | brushColorPopupMenu->activateItemAt(1); |
224 | } | 220 | } |
225 | 221 | ||
226 | DrawPad::~DrawPad() | 222 | DrawPad::~DrawPad() |
227 | { | 223 | { |
228 | QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); | 224 | QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); |
229 | 225 | ||
230 | if (file.open(IO_WriteOnly)) { | 226 | if (file.open(IO_WriteOnly)) { |
231 | m_pDrawPadCanvas->save(&file); | 227 | m_pDrawPadCanvas->save(&file); |
232 | file.close(); | 228 | file.close(); |
233 | } | 229 | } |
234 | } | 230 | } |
235 | 231 | ||
236 | void DrawPad::setPointDrawMode() | 232 | void DrawPad::setPointDrawMode() |
237 | { | 233 | { |
238 | if (m_pDrawMode) { | 234 | if (m_pDrawMode) { |
239 | delete m_pDrawMode; | 235 | delete m_pDrawMode; |
240 | } | 236 | } |
241 | 237 | ||
@@ -313,57 +309,73 @@ void DrawPad::setFillDrawMode() | |||
313 | m_pEraseDrawModeAction->setOn(false); | 309 | m_pEraseDrawModeAction->setOn(false); |
314 | } | 310 | } |
315 | 311 | ||
316 | void DrawPad::setEraseDrawMode() | 312 | void DrawPad::setEraseDrawMode() |
317 | { | 313 | { |
318 | if (m_pDrawMode) { | 314 | if (m_pDrawMode) { |
319 | delete m_pDrawMode; | 315 | delete m_pDrawMode; |
320 | } | 316 | } |
321 | 317 | ||
322 | m_pDrawMode = new EraseDrawMode(this, m_pDrawPadCanvas); | 318 | m_pDrawMode = new EraseDrawMode(this, m_pDrawPadCanvas); |
323 | 319 | ||
324 | m_pPointDrawModeAction->setOn(false); | 320 | m_pPointDrawModeAction->setOn(false); |
325 | m_pLineDrawModeAction->setOn(false); | 321 | m_pLineDrawModeAction->setOn(false); |
326 | m_pRectangleDrawModeAction->setOn(false); | 322 | m_pRectangleDrawModeAction->setOn(false); |
327 | m_pEllipseDrawModeAction->setOn(false); | 323 | m_pEllipseDrawModeAction->setOn(false); |
328 | m_pFillDrawModeAction->setOn(false); | 324 | m_pFillDrawModeAction->setOn(false); |
329 | m_pEraseDrawModeAction->setOn(true); | 325 | m_pEraseDrawModeAction->setOn(true); |
330 | } | 326 | } |
331 | 327 | ||
332 | void DrawPad::changePenWidth(int value) | 328 | void DrawPad::changePenWidth(int value) |
333 | { | 329 | { |
334 | m_pen.setWidth(value); | 330 | m_pen.setWidth(value); |
335 | } | 331 | } |
336 | 332 | ||
337 | void DrawPad::changePenColor(int index) | 333 | void DrawPad::changePenColor(const QColor& color) |
338 | { | 334 | { |
339 | m_pen.setColor(m_colors.at(index)); | 335 | m_pen.setColor(color); |
340 | 336 | ||
341 | QPainter painter; | 337 | QPainter painter; |
342 | painter.begin(m_pPenColorToolButton->pixmap()); | 338 | painter.begin(m_pPenColorToolButton->pixmap()); |
343 | painter.fillRect(QRect(0, 12, 14, 2), m_pen.color()); | 339 | painter.fillRect(QRect(0, 12, 14, 2), m_pen.color()); |
344 | painter.end(); | 340 | painter.end(); |
341 | |||
342 | m_pPenColorToolButton->popup()->hide(); | ||
345 | } | 343 | } |
346 | 344 | ||
347 | void DrawPad::changeBrushColor(int index) | 345 | void DrawPad::changeBrushColor(const QColor& color) |
348 | { | 346 | { |
349 | m_brush = QBrush(m_colors.at(index)); | 347 | m_brush = QBrush(color); |
350 | 348 | ||
351 | QPainter painter; | 349 | QPainter painter; |
352 | painter.begin(m_pBrushColorToolButton->pixmap()); | 350 | painter.begin(m_pBrushColorToolButton->pixmap()); |
353 | painter.fillRect(QRect(0, 12, 14, 2), m_brush.color()); | 351 | painter.fillRect(QRect(0, 12, 14, 2), m_brush.color()); |
354 | painter.end(); | 352 | painter.end(); |
353 | |||
354 | m_pBrushColorToolButton->popup()->hide(); | ||
355 | } | ||
356 | |||
357 | void DrawPad::choosePenColor() | ||
358 | { | ||
359 | QColor newPenColor = QColorDialog::getColor(m_pen.color()); | ||
360 | changePenColor(newPenColor); | ||
361 | } | ||
362 | |||
363 | void DrawPad::chooseBrushColor() | ||
364 | { | ||
365 | QColor newBrushColor = QColorDialog::getColor(m_brush.color()); | ||
366 | changeBrushColor(newBrushColor); | ||
355 | } | 367 | } |
356 | 368 | ||
357 | void DrawPad::updateUndoRedoToolButtons() | 369 | void DrawPad::updateUndoRedoToolButtons() |
358 | { | 370 | { |
359 | m_pUndoAction->setEnabled(m_pDrawPadCanvas->undoEnabled()); | 371 | m_pUndoAction->setEnabled(m_pDrawPadCanvas->undoEnabled()); |
360 | m_pRedoAction->setEnabled(m_pDrawPadCanvas->redoEnabled()); | 372 | m_pRedoAction->setEnabled(m_pDrawPadCanvas->redoEnabled()); |
361 | } | 373 | } |
362 | 374 | ||
363 | void DrawPad::updateNavigationToolButtons() | 375 | void DrawPad::updateNavigationToolButtons() |
364 | { | 376 | { |
365 | m_pFirstPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); | 377 | m_pFirstPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); |
366 | m_pPreviousPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); | 378 | m_pPreviousPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); |
367 | m_pNextPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); | 379 | m_pNextPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); |
368 | m_pLastPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); | 380 | m_pLastPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); |
369 | } | 381 | } |
diff --git a/noncore/graphics/drawpad/drawpad.h b/noncore/graphics/drawpad/drawpad.h index ee81ddf..35b3be4 100644 --- a/noncore/graphics/drawpad/drawpad.h +++ b/noncore/graphics/drawpad/drawpad.h | |||
@@ -26,57 +26,58 @@ class QColor; | |||
26 | class QToolButton; | 26 | class QToolButton; |
27 | class QWidgetStack; | 27 | class QWidgetStack; |
28 | 28 | ||
29 | class DrawPad : public QMainWindow | 29 | class DrawPad : public QMainWindow |
30 | { | 30 | { |
31 | Q_OBJECT | 31 | Q_OBJECT |
32 | 32 | ||
33 | public: | 33 | public: |
34 | DrawPad(QWidget* parent = 0, const char* name = 0, WFlags f = WType_TopLevel); | 34 | DrawPad(QWidget* parent = 0, const char* name = 0, WFlags f = WType_TopLevel); |
35 | ~DrawPad(); | 35 | ~DrawPad(); |
36 | 36 | ||
37 | DrawMode* drawMode() { return m_pDrawMode; } | 37 | DrawMode* drawMode() { return m_pDrawMode; } |
38 | QPen pen() { return m_pen; } | 38 | QPen pen() { return m_pen; } |
39 | QBrush brush() { return m_brush; } | 39 | QBrush brush() { return m_brush; } |
40 | 40 | ||
41 | private slots: | 41 | private slots: |
42 | void setPointDrawMode(); | 42 | void setPointDrawMode(); |
43 | void setLineDrawMode(); | 43 | void setLineDrawMode(); |
44 | void setRectangleDrawMode(); | 44 | void setRectangleDrawMode(); |
45 | void setEllipseDrawMode(); | 45 | void setEllipseDrawMode(); |
46 | void setFillDrawMode(); | 46 | void setFillDrawMode(); |
47 | void setEraseDrawMode(); | 47 | void setEraseDrawMode(); |
48 | 48 | ||
49 | void changePenWidth(int value); | 49 | void changePenWidth(int value); |
50 | void changePenColor(int index); | 50 | void changePenColor(const QColor& color); |
51 | void changeBrushColor(int index); | 51 | void changeBrushColor(const QColor& color); |
52 | void choosePenColor(); | ||
53 | void chooseBrushColor(); | ||
52 | 54 | ||
53 | void updateUndoRedoToolButtons(); | 55 | void updateUndoRedoToolButtons(); |
54 | void updateNavigationToolButtons(); | 56 | void updateNavigationToolButtons(); |
55 | 57 | ||
56 | private: | 58 | private: |
57 | DrawPadCanvas* m_pDrawPadCanvas; | 59 | DrawPadCanvas* m_pDrawPadCanvas; |
58 | QArray<QColor> m_colors; | ||
59 | 60 | ||
60 | DrawMode* m_pDrawMode; | 61 | DrawMode* m_pDrawMode; |
61 | QPen m_pen; | 62 | QPen m_pen; |
62 | QBrush m_brush; | 63 | QBrush m_brush; |
63 | 64 | ||
64 | QAction* m_pUndoAction; | 65 | QAction* m_pUndoAction; |
65 | QAction* m_pRedoAction; | 66 | QAction* m_pRedoAction; |
66 | 67 | ||
67 | QAction* m_pFirstPageAction; | 68 | QAction* m_pFirstPageAction; |
68 | QAction* m_pPreviousPageAction; | 69 | QAction* m_pPreviousPageAction; |
69 | QAction* m_pNextPageAction; | 70 | QAction* m_pNextPageAction; |
70 | QAction* m_pLastPageAction; | 71 | QAction* m_pLastPageAction; |
71 | 72 | ||
72 | QAction* m_pPointDrawModeAction; | 73 | QAction* m_pPointDrawModeAction; |
73 | QAction* m_pLineDrawModeAction; | 74 | QAction* m_pLineDrawModeAction; |
74 | QAction* m_pRectangleDrawModeAction; | 75 | QAction* m_pRectangleDrawModeAction; |
75 | QAction* m_pEllipseDrawModeAction; | 76 | QAction* m_pEllipseDrawModeAction; |
76 | QAction* m_pFillDrawModeAction; | 77 | QAction* m_pFillDrawModeAction; |
77 | QAction* m_pEraseDrawModeAction; | 78 | QAction* m_pEraseDrawModeAction; |
78 | 79 | ||
79 | QToolButton* m_pPenColorToolButton; | 80 | QToolButton* m_pPenColorToolButton; |
80 | QToolButton* m_pBrushColorToolButton; | 81 | QToolButton* m_pBrushColorToolButton; |
81 | }; | 82 | }; |
82 | 83 | ||
diff --git a/noncore/graphics/drawpad/drawpad.pro b/noncore/graphics/drawpad/drawpad.pro index f41dc4f..407a039 100644 --- a/noncore/graphics/drawpad/drawpad.pro +++ b/noncore/graphics/drawpad/drawpad.pro | |||
@@ -1,27 +1,31 @@ | |||
1 | TEMPLATE= app | 1 | TEMPLATE= app |
2 | CONFIG = qt warn_on release | 2 | CONFIG = qt warn_on release |
3 | HEADERS = drawmode.h \ | 3 | HEADERS = colordialog.h \ |
4 | colorpanel.h \ | ||
5 | drawmode.h \ | ||
4 | drawpad.h \ | 6 | drawpad.h \ |
5 | drawpadcanvas.h \ | 7 | drawpadcanvas.h \ |
6 | ellipsedrawmode.h \ | 8 | ellipsedrawmode.h \ |
7 | erasedrawmode.h \ | 9 | erasedrawmode.h \ |
8 | filldrawmode.h \ | 10 | filldrawmode.h \ |
9 | linedrawmode.h \ | 11 | linedrawmode.h \ |
10 | pointdrawmode.h \ | 12 | pointdrawmode.h \ |
11 | rectangledrawmode.h | 13 | rectangledrawmode.h |
12 | SOURCES = main.cpp \ | 14 | SOURCES = colordialog.cpp \ |
15 | colorpanel.cpp \ | ||
13 | drawmode.cpp \ | 16 | drawmode.cpp \ |
14 | drawpad.cpp \ | 17 | drawpad.cpp \ |
15 | drawpadcanvas.cpp \ | 18 | drawpadcanvas.cpp \ |
16 | ellipsedrawmode.cpp \ | 19 | ellipsedrawmode.cpp \ |
17 | erasedrawmode.cpp \ | 20 | erasedrawmode.cpp \ |
18 | filldrawmode.cpp \ | 21 | filldrawmode.cpp \ |
19 | linedrawmode.cpp \ | 22 | linedrawmode.cpp \ |
23 | main.cpp \ | ||
20 | pointdrawmode.cpp \ | 24 | pointdrawmode.cpp \ |
21 | rectangledrawmode.cpp | 25 | rectangledrawmode.cpp |
22 | INCLUDEPATH+= $(OPIEDIR)/include \ | 26 | INCLUDEPATH+= $(OPIEDIR)/include \ |
23 | $(QTDIR)/src/3rdparty/zlib | 27 | $(QTDIR)/src/3rdparty/zlib |
24 | DEPENDPATH+= $(OPIEDIR)/include | 28 | DEPENDPATH+= $(OPIEDIR)/include |
25 | LIBS += -lqpe | 29 | LIBS += -lqpe |
26 | DESTDIR = $(OPIEDIR)/bin | 30 | DESTDIR = $(OPIEDIR)/bin |
27 | TARGET = drawpad | 31 | TARGET = drawpad |
diff --git a/noncore/graphics/drawpad/ellipsedrawmode.cpp b/noncore/graphics/drawpad/ellipsedrawmode.cpp index 1051335..12a1113 100644 --- a/noncore/graphics/drawpad/ellipsedrawmode.cpp +++ b/noncore/graphics/drawpad/ellipsedrawmode.cpp | |||
@@ -17,49 +17,49 @@ | |||
17 | #include "drawpadcanvas.h" | 17 | #include "drawpadcanvas.h" |
18 | 18 | ||
19 | #include <qpainter.h> | 19 | #include <qpainter.h> |
20 | #include <qpixmap.h> | 20 | #include <qpixmap.h> |
21 | 21 | ||
22 | EllipseDrawMode::EllipseDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | 22 | EllipseDrawMode::EllipseDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) |
23 | : DrawMode(drawPad, drawPadCanvas) | 23 | : DrawMode(drawPad, drawPadCanvas) |
24 | { | 24 | { |
25 | m_mousePressed = false; | 25 | m_mousePressed = false; |
26 | m_polyline.resize(3); | 26 | m_polyline.resize(3); |
27 | } | 27 | } |
28 | 28 | ||
29 | EllipseDrawMode::~EllipseDrawMode() | 29 | EllipseDrawMode::~EllipseDrawMode() |
30 | { | 30 | { |
31 | } | 31 | } |
32 | 32 | ||
33 | void EllipseDrawMode::mousePressEvent(QMouseEvent* e) | 33 | void EllipseDrawMode::mousePressEvent(QMouseEvent* e) |
34 | { | 34 | { |
35 | m_mousePressed = true; | 35 | m_mousePressed = true; |
36 | m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); | 36 | m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); |
37 | } | 37 | } |
38 | 38 | ||
39 | void EllipseDrawMode::mouseReleaseEvent(QMouseEvent* e) | 39 | void EllipseDrawMode::mouseReleaseEvent(QMouseEvent* e) |
40 | { | 40 | { |
41 | Q_UNUSED(e); | 41 | Q_UNUSED(e) |
42 | 42 | ||
43 | QPainter painter; | 43 | QPainter painter; |
44 | painter.begin(m_pDrawPadCanvas->currentPage()); | 44 | painter.begin(m_pDrawPadCanvas->currentPage()); |
45 | painter.setRasterOp(Qt::NotROP); | 45 | painter.setRasterOp(Qt::NotROP); |
46 | painter.drawRect(QRect(m_polyline[2], m_polyline[0])); | 46 | painter.drawRect(QRect(m_polyline[2], m_polyline[0])); |
47 | painter.setPen(m_pDrawPad->pen()); | 47 | painter.setPen(m_pDrawPad->pen()); |
48 | painter.setRasterOp(Qt::CopyROP); | 48 | painter.setRasterOp(Qt::CopyROP); |
49 | painter.drawEllipse(QRect(m_polyline[2], m_polyline[0])); | 49 | painter.drawEllipse(QRect(m_polyline[2], m_polyline[0])); |
50 | painter.end(); | 50 | painter.end(); |
51 | 51 | ||
52 | QRect r = m_polyline.boundingRect(); | 52 | QRect r = m_polyline.boundingRect(); |
53 | r = r.normalize(); | 53 | r = r.normalize(); |
54 | r.setLeft(r.left() - m_pDrawPad->pen().width()); | 54 | r.setLeft(r.left() - m_pDrawPad->pen().width()); |
55 | r.setTop(r.top() - m_pDrawPad->pen().width()); | 55 | r.setTop(r.top() - m_pDrawPad->pen().width()); |
56 | r.setRight(r.right() + m_pDrawPad->pen().width()); | 56 | r.setRight(r.right() + m_pDrawPad->pen().width()); |
57 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); | 57 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); |
58 | 58 | ||
59 | bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); | 59 | bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); |
60 | 60 | ||
61 | m_mousePressed = false; | 61 | m_mousePressed = false; |
62 | } | 62 | } |
63 | 63 | ||
64 | void EllipseDrawMode::mouseMoveEvent(QMouseEvent* e) | 64 | void EllipseDrawMode::mouseMoveEvent(QMouseEvent* e) |
65 | { | 65 | { |
diff --git a/noncore/graphics/drawpad/erasedrawmode.cpp b/noncore/graphics/drawpad/erasedrawmode.cpp index b8e80bc..990cecb 100644 --- a/noncore/graphics/drawpad/erasedrawmode.cpp +++ b/noncore/graphics/drawpad/erasedrawmode.cpp | |||
@@ -17,49 +17,49 @@ | |||
17 | #include "drawpadcanvas.h" | 17 | #include "drawpadcanvas.h" |
18 | 18 | ||
19 | #include <qpainter.h> | 19 | #include <qpainter.h> |
20 | #include <qpixmap.h> | 20 | #include <qpixmap.h> |
21 | 21 | ||
22 | EraseDrawMode::EraseDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | 22 | EraseDrawMode::EraseDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) |
23 | : DrawMode(drawPad, drawPadCanvas) | 23 | : DrawMode(drawPad, drawPadCanvas) |
24 | { | 24 | { |
25 | m_mousePressed = false; | 25 | m_mousePressed = false; |
26 | m_polyline.resize(3); | 26 | m_polyline.resize(3); |
27 | } | 27 | } |
28 | 28 | ||
29 | EraseDrawMode::~EraseDrawMode() | 29 | EraseDrawMode::~EraseDrawMode() |
30 | { | 30 | { |
31 | } | 31 | } |
32 | 32 | ||
33 | void EraseDrawMode::mousePressEvent(QMouseEvent* e) | 33 | void EraseDrawMode::mousePressEvent(QMouseEvent* e) |
34 | { | 34 | { |
35 | m_mousePressed = true; | 35 | m_mousePressed = true; |
36 | m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); | 36 | m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); |
37 | } | 37 | } |
38 | 38 | ||
39 | void EraseDrawMode::mouseReleaseEvent(QMouseEvent* e) | 39 | void EraseDrawMode::mouseReleaseEvent(QMouseEvent* e) |
40 | { | 40 | { |
41 | Q_UNUSED(e); | 41 | Q_UNUSED(e) |
42 | 42 | ||
43 | m_mousePressed = false; | 43 | m_mousePressed = false; |
44 | } | 44 | } |
45 | 45 | ||
46 | void EraseDrawMode::mouseMoveEvent(QMouseEvent* e) | 46 | void EraseDrawMode::mouseMoveEvent(QMouseEvent* e) |
47 | { | 47 | { |
48 | if (m_mousePressed) { | 48 | if (m_mousePressed) { |
49 | QPainter painter; | 49 | QPainter painter; |
50 | QPen pen(Qt::white, m_pDrawPad->pen().width()); | 50 | QPen pen(Qt::white, m_pDrawPad->pen().width()); |
51 | painter.begin(m_pDrawPadCanvas->currentPage()); | 51 | painter.begin(m_pDrawPadCanvas->currentPage()); |
52 | painter.setPen(pen); | 52 | painter.setPen(pen); |
53 | m_polyline[2] = m_polyline[1]; | 53 | m_polyline[2] = m_polyline[1]; |
54 | m_polyline[1] = m_polyline[0]; | 54 | m_polyline[1] = m_polyline[0]; |
55 | m_polyline[0] = e->pos(); | 55 | m_polyline[0] = e->pos(); |
56 | painter.drawPolyline(m_polyline); | 56 | painter.drawPolyline(m_polyline); |
57 | painter.end(); | 57 | painter.end(); |
58 | 58 | ||
59 | QRect r = m_polyline.boundingRect(); | 59 | QRect r = m_polyline.boundingRect(); |
60 | r = r.normalize(); | 60 | r = r.normalize(); |
61 | r.setLeft(r.left() - m_pDrawPad->pen().width()); | 61 | r.setLeft(r.left() - m_pDrawPad->pen().width()); |
62 | r.setTop(r.top() - m_pDrawPad->pen().width()); | 62 | r.setTop(r.top() - m_pDrawPad->pen().width()); |
63 | r.setRight(r.right() + m_pDrawPad->pen().width()); | 63 | r.setRight(r.right() + m_pDrawPad->pen().width()); |
64 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); | 64 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); |
65 | 65 | ||
diff --git a/noncore/graphics/drawpad/filldrawmode.cpp b/noncore/graphics/drawpad/filldrawmode.cpp index db86b63..8f68550 100644 --- a/noncore/graphics/drawpad/filldrawmode.cpp +++ b/noncore/graphics/drawpad/filldrawmode.cpp | |||
@@ -30,54 +30,54 @@ FillDrawMode::~FillDrawMode() | |||
30 | 30 | ||
31 | void FillDrawMode::mousePressEvent(QMouseEvent* e) | 31 | void FillDrawMode::mousePressEvent(QMouseEvent* e) |
32 | { | 32 | { |
33 | int x = e->x(); | 33 | int x = e->x(); |
34 | int y = e->y(); | 34 | int y = e->y(); |
35 | 35 | ||
36 | m_image = m_pDrawPadCanvas->currentPage()->convertToImage(); | 36 | m_image = m_pDrawPadCanvas->currentPage()->convertToImage(); |
37 | m_fillRgb = m_pDrawPad->brush().color().rgb(); | 37 | m_fillRgb = m_pDrawPad->brush().color().rgb(); |
38 | m_oldRgb = m_image.pixel(x, y); | 38 | m_oldRgb = m_image.pixel(x, y); |
39 | 39 | ||
40 | if (m_oldRgb != m_fillRgb) { | 40 | if (m_oldRgb != m_fillRgb) { |
41 | m_image.setPixel(x, y, m_fillRgb); | 41 | m_image.setPixel(x, y, m_fillRgb); |
42 | fillEast(x + 1, y); | 42 | fillEast(x + 1, y); |
43 | fillSouth(x, y + 1); | 43 | fillSouth(x, y + 1); |
44 | fillWest(x - 1, y); | 44 | fillWest(x - 1, y); |
45 | fillNorth(x, y - 1); | 45 | fillNorth(x, y - 1); |
46 | 46 | ||
47 | m_pDrawPadCanvas->currentPage()->convertFromImage(m_image); | 47 | m_pDrawPadCanvas->currentPage()->convertFromImage(m_image); |
48 | m_pDrawPadCanvas->repaint(); | 48 | m_pDrawPadCanvas->repaint(); |
49 | } | 49 | } |
50 | } | 50 | } |
51 | 51 | ||
52 | void FillDrawMode::mouseReleaseEvent(QMouseEvent* e) | 52 | void FillDrawMode::mouseReleaseEvent(QMouseEvent* e) |
53 | { | 53 | { |
54 | Q_UNUSED(e); | 54 | Q_UNUSED(e) |
55 | } | 55 | } |
56 | 56 | ||
57 | void FillDrawMode::mouseMoveEvent(QMouseEvent* e) | 57 | void FillDrawMode::mouseMoveEvent(QMouseEvent* e) |
58 | { | 58 | { |
59 | Q_UNUSED(e); | 59 | Q_UNUSED(e) |
60 | } | 60 | } |
61 | 61 | ||
62 | void FillDrawMode::fillEast(int x, int y) | 62 | void FillDrawMode::fillEast(int x, int y) |
63 | { | 63 | { |
64 | if (x < m_image.width()) { | 64 | if (x < m_image.width()) { |
65 | if (m_image.pixel(x, y) == m_oldRgb) { | 65 | if (m_image.pixel(x, y) == m_oldRgb) { |
66 | m_image.setPixel(x, y, m_fillRgb); | 66 | m_image.setPixel(x, y, m_fillRgb); |
67 | fillEast(x + 1, y); | 67 | fillEast(x + 1, y); |
68 | fillSouth(x, y + 1); | 68 | fillSouth(x, y + 1); |
69 | fillNorth(x, y - 1); | 69 | fillNorth(x, y - 1); |
70 | } | 70 | } |
71 | } | 71 | } |
72 | } | 72 | } |
73 | 73 | ||
74 | void FillDrawMode::fillSouth(int x, int y) | 74 | void FillDrawMode::fillSouth(int x, int y) |
75 | { | 75 | { |
76 | if (y < m_image.height()) { | 76 | if (y < m_image.height()) { |
77 | if (m_image.pixel(x, y) == m_oldRgb) { | 77 | if (m_image.pixel(x, y) == m_oldRgb) { |
78 | m_image.setPixel(x, y, m_fillRgb); | 78 | m_image.setPixel(x, y, m_fillRgb); |
79 | fillEast(x + 1, y); | 79 | fillEast(x + 1, y); |
80 | fillSouth(x, y + 1); | 80 | fillSouth(x, y + 1); |
81 | fillWest(x - 1, y); | 81 | fillWest(x - 1, y); |
82 | } | 82 | } |
83 | } | 83 | } |
diff --git a/noncore/graphics/drawpad/linedrawmode.cpp b/noncore/graphics/drawpad/linedrawmode.cpp index 57295f8..15445fc 100644 --- a/noncore/graphics/drawpad/linedrawmode.cpp +++ b/noncore/graphics/drawpad/linedrawmode.cpp | |||
@@ -17,49 +17,49 @@ | |||
17 | #include "drawpadcanvas.h" | 17 | #include "drawpadcanvas.h" |
18 | 18 | ||
19 | #include <qpainter.h> | 19 | #include <qpainter.h> |
20 | #include <qpixmap.h> | 20 | #include <qpixmap.h> |
21 | 21 | ||
22 | LineDrawMode::LineDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | 22 | LineDrawMode::LineDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) |
23 | : DrawMode(drawPad, drawPadCanvas) | 23 | : DrawMode(drawPad, drawPadCanvas) |
24 | { | 24 | { |
25 | m_mousePressed = false; | 25 | m_mousePressed = false; |
26 | m_polyline.resize(3); | 26 | m_polyline.resize(3); |
27 | } | 27 | } |
28 | 28 | ||
29 | LineDrawMode::~LineDrawMode() | 29 | LineDrawMode::~LineDrawMode() |
30 | { | 30 | { |
31 | } | 31 | } |
32 | 32 | ||
33 | void LineDrawMode::mousePressEvent(QMouseEvent* e) | 33 | void LineDrawMode::mousePressEvent(QMouseEvent* e) |
34 | { | 34 | { |
35 | m_mousePressed = true; | 35 | m_mousePressed = true; |
36 | m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); | 36 | m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); |
37 | } | 37 | } |
38 | 38 | ||
39 | void LineDrawMode::mouseReleaseEvent(QMouseEvent* e) | 39 | void LineDrawMode::mouseReleaseEvent(QMouseEvent* e) |
40 | { | 40 | { |
41 | Q_UNUSED(e); | 41 | Q_UNUSED(e) |
42 | 42 | ||
43 | QPainter painter; | 43 | QPainter painter; |
44 | painter.begin(m_pDrawPadCanvas->currentPage()); | 44 | painter.begin(m_pDrawPadCanvas->currentPage()); |
45 | painter.setPen(m_pDrawPad->pen()); | 45 | painter.setPen(m_pDrawPad->pen()); |
46 | painter.drawLine(m_polyline[2], m_polyline[0]); | 46 | painter.drawLine(m_polyline[2], m_polyline[0]); |
47 | painter.end(); | 47 | painter.end(); |
48 | 48 | ||
49 | QRect r = m_polyline.boundingRect(); | 49 | QRect r = m_polyline.boundingRect(); |
50 | r = r.normalize(); | 50 | r = r.normalize(); |
51 | r.setLeft(r.left() - m_pDrawPad->pen().width()); | 51 | r.setLeft(r.left() - m_pDrawPad->pen().width()); |
52 | r.setTop(r.top() - m_pDrawPad->pen().width()); | 52 | r.setTop(r.top() - m_pDrawPad->pen().width()); |
53 | r.setRight(r.right() + m_pDrawPad->pen().width()); | 53 | r.setRight(r.right() + m_pDrawPad->pen().width()); |
54 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); | 54 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); |
55 | 55 | ||
56 | bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); | 56 | bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); |
57 | 57 | ||
58 | m_mousePressed = false; | 58 | m_mousePressed = false; |
59 | } | 59 | } |
60 | 60 | ||
61 | void LineDrawMode::mouseMoveEvent(QMouseEvent* e) | 61 | void LineDrawMode::mouseMoveEvent(QMouseEvent* e) |
62 | { | 62 | { |
63 | if (m_mousePressed) { | 63 | if (m_mousePressed) { |
64 | QPainter painter; | 64 | QPainter painter; |
65 | painter.begin(m_pDrawPadCanvas->currentPage()); | 65 | painter.begin(m_pDrawPadCanvas->currentPage()); |
diff --git a/noncore/graphics/drawpad/pointdrawmode.cpp b/noncore/graphics/drawpad/pointdrawmode.cpp index 11722c8..30753d6 100644 --- a/noncore/graphics/drawpad/pointdrawmode.cpp +++ b/noncore/graphics/drawpad/pointdrawmode.cpp | |||
@@ -17,49 +17,49 @@ | |||
17 | #include "drawpadcanvas.h" | 17 | #include "drawpadcanvas.h" |
18 | 18 | ||
19 | #include <qpainter.h> | 19 | #include <qpainter.h> |
20 | #include <qpixmap.h> | 20 | #include <qpixmap.h> |
21 | 21 | ||
22 | PointDrawMode::PointDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | 22 | PointDrawMode::PointDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) |
23 | : DrawMode(drawPad, drawPadCanvas) | 23 | : DrawMode(drawPad, drawPadCanvas) |
24 | { | 24 | { |
25 | m_mousePressed = false; | 25 | m_mousePressed = false; |
26 | m_polyline.resize(3); | 26 | m_polyline.resize(3); |
27 | } | 27 | } |
28 | 28 | ||
29 | PointDrawMode::~PointDrawMode() | 29 | PointDrawMode::~PointDrawMode() |
30 | { | 30 | { |
31 | } | 31 | } |
32 | 32 | ||
33 | void PointDrawMode::mousePressEvent(QMouseEvent* e) | 33 | void PointDrawMode::mousePressEvent(QMouseEvent* e) |
34 | { | 34 | { |
35 | m_mousePressed = true; | 35 | m_mousePressed = true; |
36 | m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); | 36 | m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); |
37 | } | 37 | } |
38 | 38 | ||
39 | void PointDrawMode::mouseReleaseEvent(QMouseEvent* e) | 39 | void PointDrawMode::mouseReleaseEvent(QMouseEvent* e) |
40 | { | 40 | { |
41 | Q_UNUSED(e); | 41 | Q_UNUSED(e) |
42 | 42 | ||
43 | m_mousePressed = false; | 43 | m_mousePressed = false; |
44 | } | 44 | } |
45 | 45 | ||
46 | void PointDrawMode::mouseMoveEvent(QMouseEvent* e) | 46 | void PointDrawMode::mouseMoveEvent(QMouseEvent* e) |
47 | { | 47 | { |
48 | if (m_mousePressed) { | 48 | if (m_mousePressed) { |
49 | QPainter painter; | 49 | QPainter painter; |
50 | painter.begin(m_pDrawPadCanvas->currentPage()); | 50 | painter.begin(m_pDrawPadCanvas->currentPage()); |
51 | painter.setPen(m_pDrawPad->pen()); | 51 | painter.setPen(m_pDrawPad->pen()); |
52 | m_polyline[2] = m_polyline[1]; | 52 | m_polyline[2] = m_polyline[1]; |
53 | m_polyline[1] = m_polyline[0]; | 53 | m_polyline[1] = m_polyline[0]; |
54 | m_polyline[0] = e->pos(); | 54 | m_polyline[0] = e->pos(); |
55 | painter.drawPolyline(m_polyline); | 55 | painter.drawPolyline(m_polyline); |
56 | painter.end(); | 56 | painter.end(); |
57 | 57 | ||
58 | QRect r = m_polyline.boundingRect(); | 58 | QRect r = m_polyline.boundingRect(); |
59 | r = r.normalize(); | 59 | r = r.normalize(); |
60 | r.setLeft(r.left() - m_pDrawPad->pen().width()); | 60 | r.setLeft(r.left() - m_pDrawPad->pen().width()); |
61 | r.setTop(r.top() - m_pDrawPad->pen().width()); | 61 | r.setTop(r.top() - m_pDrawPad->pen().width()); |
62 | r.setRight(r.right() + m_pDrawPad->pen().width()); | 62 | r.setRight(r.right() + m_pDrawPad->pen().width()); |
63 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); | 63 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); |
64 | 64 | ||
65 | bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); | 65 | bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); |
diff --git a/noncore/graphics/drawpad/rectangledrawmode.cpp b/noncore/graphics/drawpad/rectangledrawmode.cpp index f54b47b..60d7cea 100644 --- a/noncore/graphics/drawpad/rectangledrawmode.cpp +++ b/noncore/graphics/drawpad/rectangledrawmode.cpp | |||
@@ -17,49 +17,49 @@ | |||
17 | #include "drawpadcanvas.h" | 17 | #include "drawpadcanvas.h" |
18 | 18 | ||
19 | #include <qpainter.h> | 19 | #include <qpainter.h> |
20 | #include <qpixmap.h> | 20 | #include <qpixmap.h> |
21 | 21 | ||
22 | RectangleDrawMode::RectangleDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | 22 | RectangleDrawMode::RectangleDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) |
23 | : DrawMode(drawPad, drawPadCanvas) | 23 | : DrawMode(drawPad, drawPadCanvas) |
24 | { | 24 | { |
25 | m_mousePressed = false; | 25 | m_mousePressed = false; |
26 | m_polyline.resize(3); | 26 | m_polyline.resize(3); |
27 | } | 27 | } |
28 | 28 | ||
29 | RectangleDrawMode::~RectangleDrawMode() | 29 | RectangleDrawMode::~RectangleDrawMode() |
30 | { | 30 | { |
31 | } | 31 | } |
32 | 32 | ||
33 | void RectangleDrawMode::mousePressEvent(QMouseEvent* e) | 33 | void RectangleDrawMode::mousePressEvent(QMouseEvent* e) |
34 | { | 34 | { |
35 | m_mousePressed = true; | 35 | m_mousePressed = true; |
36 | m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); | 36 | m_polyline[2] = m_polyline[1] = m_polyline[0] = e->pos(); |
37 | } | 37 | } |
38 | 38 | ||
39 | void RectangleDrawMode::mouseReleaseEvent(QMouseEvent* e) | 39 | void RectangleDrawMode::mouseReleaseEvent(QMouseEvent* e) |
40 | { | 40 | { |
41 | Q_UNUSED(e); | 41 | Q_UNUSED(e) |
42 | 42 | ||
43 | QPainter painter; | 43 | QPainter painter; |
44 | painter.begin(m_pDrawPadCanvas->currentPage()); | 44 | painter.begin(m_pDrawPadCanvas->currentPage()); |
45 | painter.setPen(m_pDrawPad->pen()); | 45 | painter.setPen(m_pDrawPad->pen()); |
46 | painter.drawRect(QRect(m_polyline[2], m_polyline[0])); | 46 | painter.drawRect(QRect(m_polyline[2], m_polyline[0])); |
47 | painter.end(); | 47 | painter.end(); |
48 | 48 | ||
49 | QRect r = m_polyline.boundingRect(); | 49 | QRect r = m_polyline.boundingRect(); |
50 | r = r.normalize(); | 50 | r = r.normalize(); |
51 | r.setLeft(r.left() - m_pDrawPad->pen().width()); | 51 | r.setLeft(r.left() - m_pDrawPad->pen().width()); |
52 | r.setTop(r.top() - m_pDrawPad->pen().width()); | 52 | r.setTop(r.top() - m_pDrawPad->pen().width()); |
53 | r.setRight(r.right() + m_pDrawPad->pen().width()); | 53 | r.setRight(r.right() + m_pDrawPad->pen().width()); |
54 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); | 54 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); |
55 | 55 | ||
56 | bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); | 56 | bitBlt(m_pDrawPadCanvas, r.x(), r.y(), m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); |
57 | 57 | ||
58 | m_mousePressed = false; | 58 | m_mousePressed = false; |
59 | } | 59 | } |
60 | 60 | ||
61 | void RectangleDrawMode::mouseMoveEvent(QMouseEvent* e) | 61 | void RectangleDrawMode::mouseMoveEvent(QMouseEvent* e) |
62 | { | 62 | { |
63 | if (m_mousePressed) { | 63 | if (m_mousePressed) { |
64 | QPainter painter; | 64 | QPainter painter; |
65 | painter.begin(m_pDrawPadCanvas->currentPage()); | 65 | painter.begin(m_pDrawPadCanvas->currentPage()); |