-rw-r--r-- | library/imageedit.cpp | 1 |
1 files changed, 0 insertions, 1 deletions
diff --git a/library/imageedit.cpp b/library/imageedit.cpp index caa538a..3a559f4 100644 --- a/library/imageedit.cpp +++ b/library/imageedit.cpp | |||
@@ -1,97 +1,96 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include "imageedit.h" | 20 | #include "imageedit.h" |
21 | #include <qpainter.h> | ||
22 | 21 | ||
23 | ImageEdit::ImageEdit( QWidget *parent, const char *name) | 22 | ImageEdit::ImageEdit( QWidget *parent, const char *name) |
24 | : QScrollView( parent, name, WNorthWestGravity | WResizeNoErase ), buffer() | 23 | : QScrollView( parent, name, WNorthWestGravity | WResizeNoErase ), buffer() |
25 | { | 24 | { |
26 | buffer.resize( size() ); | 25 | buffer.resize( size() ); |
27 | buffer.fill( colorGroup().color( QColorGroup::Base ) ); | 26 | buffer.fill( colorGroup().color( QColorGroup::Base ) ); |
28 | } | 27 | } |
29 | 28 | ||
30 | ImageEdit::~ImageEdit() | 29 | ImageEdit::~ImageEdit() |
31 | { | 30 | { |
32 | 31 | ||
33 | } | 32 | } |
34 | 33 | ||
35 | void ImageEdit::contentsMousePressEvent( QMouseEvent *e ) | 34 | void ImageEdit::contentsMousePressEvent( QMouseEvent *e ) |
36 | { | 35 | { |
37 | lastPos = e->pos(); | 36 | lastPos = e->pos(); |
38 | } | 37 | } |
39 | 38 | ||
40 | void ImageEdit::contentsMouseMoveEvent( QMouseEvent *e ) | 39 | void ImageEdit::contentsMouseMoveEvent( QMouseEvent *e ) |
41 | { | 40 | { |
42 | QPainter pw( viewport() ); | 41 | QPainter pw( viewport() ); |
43 | QPainter pb( &buffer ); | 42 | QPainter pb( &buffer ); |
44 | pb.drawLine( lastPos, e->pos() ); | 43 | pb.drawLine( lastPos, e->pos() ); |
45 | pw.drawLine( contentsToViewport( lastPos ), | 44 | pw.drawLine( contentsToViewport( lastPos ), |
46 | contentsToViewport( e->pos() ) ); | 45 | contentsToViewport( e->pos() ) ); |
47 | lastPos = e->pos(); | 46 | lastPos = e->pos(); |
48 | } | 47 | } |
49 | 48 | ||
50 | void ImageEdit::contentsMouseReleaseEvent( QMouseEvent * ) | 49 | void ImageEdit::contentsMouseReleaseEvent( QMouseEvent * ) |
51 | { | 50 | { |
52 | } | 51 | } |
53 | 52 | ||
54 | void ImageEdit::viewportResizeEvent( QResizeEvent *e ) | 53 | void ImageEdit::viewportResizeEvent( QResizeEvent *e ) |
55 | { | 54 | { |
56 | enlargeBuffer(e->size()); | 55 | enlargeBuffer(e->size()); |
57 | } | 56 | } |
58 | 57 | ||
59 | void ImageEdit::enlargeBuffer( const QSize& sz ) | 58 | void ImageEdit::enlargeBuffer( const QSize& sz ) |
60 | { | 59 | { |
61 | QSize osz = buffer.size(); | 60 | QSize osz = buffer.size(); |
62 | QSize nsz( QMAX( osz.width(), sz.width() ), QMAX( osz.height(), sz.height() ) ); | 61 | QSize nsz( QMAX( osz.width(), sz.width() ), QMAX( osz.height(), sz.height() ) ); |
63 | buffer.resize( nsz.width(), nsz.height() ); | 62 | buffer.resize( nsz.width(), nsz.height() ); |
64 | // clear new area | 63 | // clear new area |
65 | QPainter p( &buffer ); | 64 | QPainter p( &buffer ); |
66 | if ( sz.width() > osz.width() ) | 65 | if ( sz.width() > osz.width() ) |
67 | p.fillRect( osz.width(), 0, sz.width() - osz.width(), nsz.height(), colorGroup().color( QColorGroup::Base ) ); | 66 | p.fillRect( osz.width(), 0, sz.width() - osz.width(), nsz.height(), colorGroup().color( QColorGroup::Base ) ); |
68 | if ( sz.height() > osz.height() ) | 67 | if ( sz.height() > osz.height() ) |
69 | p.fillRect( 0, osz.height(), nsz.width(), sz.height() - osz.height(), colorGroup().color( QColorGroup::Base ) ); | 68 | p.fillRect( 0, osz.height(), nsz.width(), sz.height() - osz.height(), colorGroup().color( QColorGroup::Base ) ); |
70 | p.end(); | 69 | p.end(); |
71 | } | 70 | } |
72 | 71 | ||
73 | void ImageEdit::drawContents( QPainter *p, int cx, int cy, int cw, int ch ) | 72 | void ImageEdit::drawContents( QPainter *p, int cx, int cy, int cw, int ch ) |
74 | { | 73 | { |
75 | p->drawPixmap( cx, cy, buffer, cx, cy, cw, ch ); | 74 | p->drawPixmap( cx, cy, buffer, cx, cy, cw, ch ); |
76 | } | 75 | } |
77 | 76 | ||
78 | void ImageEdit::setPixmap( const QPixmap &pm ) | 77 | void ImageEdit::setPixmap( const QPixmap &pm ) |
79 | { | 78 | { |
80 | QSize osz = buffer.size(); | 79 | QSize osz = buffer.size(); |
81 | if ( pm.width() < osz.width() || pm.height() < osz.height() ) { | 80 | if ( pm.width() < osz.width() || pm.height() < osz.height() ) { |
82 | buffer.fill(white); | 81 | buffer.fill(white); |
83 | enlargeBuffer( pm.size() ); | 82 | enlargeBuffer( pm.size() ); |
84 | QPainter p(&buffer); | 83 | QPainter p(&buffer); |
85 | p.drawPixmap(0,0,pm); | 84 | p.drawPixmap(0,0,pm); |
86 | } else { | 85 | } else { |
87 | buffer = pm; | 86 | buffer = pm; |
88 | } | 87 | } |
89 | resizeContents( buffer.width(), buffer.height() ); | 88 | resizeContents( buffer.width(), buffer.height() ); |
90 | viewport()->repaint( FALSE ); | 89 | viewport()->repaint( FALSE ); |
91 | } | 90 | } |
92 | 91 | ||
93 | QPixmap ImageEdit::pixmap() const | 92 | QPixmap ImageEdit::pixmap() const |
94 | { | 93 | { |
95 | return buffer; | 94 | return buffer; |
96 | } | 95 | } |
97 | 96 | ||