author | alwin <alwin> | 2004-04-16 07:39:26 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-04-16 07:39:26 (UTC) |
commit | 9692c199f1f8b4c334687081e0d75bfbf9375ad8 (patch) (unidiff) | |
tree | 3ab64a3de58d5f266229d99d0eeae20a1d49f254 | |
parent | 7c29eeaecc8301fb500851382b3d94092ae72719 (diff) | |
download | opie-9692c199f1f8b4c334687081e0d75bfbf9375ad8.zip opie-9692c199f1f8b4c334687081e0d75bfbf9375ad8.tar.gz opie-9692c199f1f8b4c334687081e0d75bfbf9375ad8.tar.bz2 |
- displaying a busy makes no sense here. It results in double paintings
- method to set autoscale/autorotate at once
-rw-r--r-- | libopie2/opiemm/oimagescrollview.cpp | 31 | ||||
-rw-r--r-- | libopie2/opiemm/oimagescrollview.h | 13 |
2 files changed, 19 insertions, 25 deletions
diff --git a/libopie2/opiemm/oimagescrollview.cpp b/libopie2/opiemm/oimagescrollview.cpp index 30a8fba..61b2062 100644 --- a/libopie2/opiemm/oimagescrollview.cpp +++ b/libopie2/opiemm/oimagescrollview.cpp | |||
@@ -1,577 +1,558 @@ | |||
1 | #include "oimagescrollview.h" | 1 | #include "oimagescrollview.h" |
2 | 2 | ||
3 | #include <opie2/oimagezoomer.h> | 3 | #include <opie2/oimagezoomer.h> |
4 | #include <opie2/odebug.h> | 4 | #include <opie2/odebug.h> |
5 | #include <opie2/oapplication.h> | 5 | #include <opie2/oapplication.h> |
6 | #include <opie2/owait.h> | 6 | #include <opie2/owait.h> |
7 | 7 | ||
8 | #include <qimage.h> | 8 | #include <qimage.h> |
9 | #include <qlayout.h> | 9 | #include <qlayout.h> |
10 | #include <qpe/qcopenvelope_qws.h> | ||
11 | 10 | ||
12 | /* for usage with the bitset */ | 11 | /* for usage with the bitset */ |
13 | #define AUTO_SCALE 0 | 12 | #define AUTO_SCALE 0 |
14 | #define AUTO_ROTATE 1 | 13 | #define AUTO_ROTATE 1 |
15 | #define SHOW_ZOOMER 2 | 14 | #define SHOW_ZOOMER 2 |
16 | #define FIRST_RESIZE_DONE 3 | 15 | #define FIRST_RESIZE_DONE 3 |
17 | #define IMAGE_IS_JPEG 4 | 16 | #define IMAGE_IS_JPEG 4 |
18 | #define IMAGE_SCALED_LOADED 5 | 17 | #define IMAGE_SCALED_LOADED 5 |
19 | 18 | ||
20 | #define SCROLLVIEW_BITSET_SIZE 6 | 19 | #define SCROLLVIEW_BITSET_SIZE 6 |
21 | 20 | ||
22 | namespace Opie { | 21 | namespace Opie { |
23 | namespace MM { | 22 | namespace MM { |
24 | OImageScrollView::OImageScrollView( QWidget* parent, const char* name, WFlags f ) | 23 | OImageScrollView::OImageScrollView( QWidget* parent, const char* name, WFlags f ) |
25 | :QScrollView(parent,name,f|Qt::WRepaintNoErase ),_image_data(),_original_data(), | 24 | :QScrollView(parent,name,f|Qt::WRepaintNoErase ),_image_data(),_original_data(), |
26 | m_states(SCROLLVIEW_BITSET_SIZE),m_lastName("") | 25 | m_states(SCROLLVIEW_BITSET_SIZE),m_lastName("") |
27 | { | 26 | { |
28 | _zoomer = 0; | 27 | _zoomer = 0; |
29 | m_states[AUTO_SCALE]=true; | 28 | m_states[AUTO_SCALE]=true; |
30 | m_states[AUTO_ROTATE]=true; | 29 | m_states[AUTO_ROTATE]=true; |
31 | m_states[FIRST_RESIZE_DONE]=false; | 30 | m_states[FIRST_RESIZE_DONE]=false; |
32 | m_states[IMAGE_IS_JPEG]=false; | 31 | m_states[IMAGE_IS_JPEG]=false; |
33 | m_states[IMAGE_SCALED_LOADED]=false; | 32 | m_states[IMAGE_SCALED_LOADED]=false; |
34 | m_states[SHOW_ZOOMER]=true; | 33 | m_states[SHOW_ZOOMER]=true; |
35 | init(); | 34 | init(); |
36 | } | 35 | } |
37 | 36 | ||
38 | OImageScrollView::OImageScrollView (const QImage&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) | 37 | OImageScrollView::OImageScrollView (const QImage&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) |
39 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(img), | 38 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(img), |
40 | m_states(SCROLLVIEW_BITSET_SIZE),m_lastName("") | 39 | m_states(SCROLLVIEW_BITSET_SIZE),m_lastName("") |
41 | { | 40 | { |
42 | _zoomer = 0; | 41 | _zoomer = 0; |
43 | m_states[AUTO_SCALE]=always_scale; | 42 | m_states[AUTO_SCALE]=always_scale; |
44 | m_states[AUTO_ROTATE]=rfit; | 43 | m_states[AUTO_ROTATE]=rfit; |
45 | m_states[FIRST_RESIZE_DONE]=false; | 44 | m_states[FIRST_RESIZE_DONE]=false; |
46 | m_states[IMAGE_IS_JPEG]=false; | 45 | m_states[IMAGE_IS_JPEG]=false; |
47 | m_states[IMAGE_SCALED_LOADED]=false; | 46 | m_states[IMAGE_SCALED_LOADED]=false; |
48 | m_states[SHOW_ZOOMER]=true; | 47 | m_states[SHOW_ZOOMER]=true; |
49 | _original_data.convertDepth(QPixmap::defaultDepth()); | 48 | _original_data.convertDepth(QPixmap::defaultDepth()); |
50 | _original_data.setAlphaBuffer(false); | 49 | _original_data.setAlphaBuffer(false); |
51 | init(); | 50 | init(); |
52 | } | 51 | } |
53 | 52 | ||
54 | OImageScrollView::OImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) | 53 | OImageScrollView::OImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) |
55 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(),m_states(SCROLLVIEW_BITSET_SIZE),m_lastName("") | 54 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(),m_states(SCROLLVIEW_BITSET_SIZE),m_lastName("") |
56 | { | 55 | { |
57 | _zoomer = 0; | 56 | _zoomer = 0; |
58 | m_states.resize(SCROLLVIEW_BITSET_SIZE); | 57 | m_states.resize(SCROLLVIEW_BITSET_SIZE); |
59 | m_states[AUTO_SCALE]=always_scale; | 58 | m_states[AUTO_SCALE]=always_scale; |
60 | m_states[AUTO_ROTATE]=rfit; | 59 | m_states[AUTO_ROTATE]=rfit; |
61 | m_states[FIRST_RESIZE_DONE]=false; | 60 | m_states[FIRST_RESIZE_DONE]=false; |
62 | m_states[IMAGE_IS_JPEG]=false; | 61 | m_states[IMAGE_IS_JPEG]=false; |
63 | m_states[IMAGE_SCALED_LOADED]=false; | 62 | m_states[IMAGE_SCALED_LOADED]=false; |
64 | m_states[SHOW_ZOOMER]=true; | 63 | m_states[SHOW_ZOOMER]=true; |
65 | init(); | 64 | init(); |
66 | setImage(img); | 65 | setImage(img); |
67 | } | 66 | } |
68 | 67 | ||
69 | void OImageScrollView::setImage(const QImage&img) | 68 | void OImageScrollView::setImage(const QImage&img) |
70 | { | 69 | { |
71 | _image_data = QImage(); | 70 | _image_data = QImage(); |
72 | _original_data=img; | 71 | _original_data=img; |
73 | _original_data.convertDepth(QPixmap::defaultDepth()); | 72 | _original_data.convertDepth(QPixmap::defaultDepth()); |
74 | _original_data.setAlphaBuffer(false); | 73 | _original_data.setAlphaBuffer(false); |
75 | m_lastName = ""; | 74 | m_lastName = ""; |
76 | setImageIsJpeg(false); | 75 | setImageIsJpeg(false); |
77 | setImageScaledLoaded(false); | 76 | setImageScaledLoaded(false); |
78 | if (FirstResizeDone()) { | 77 | if (FirstResizeDone()) { |
79 | generateImage(); | 78 | generateImage(); |
80 | } | 79 | } |
81 | } | 80 | } |
82 | 81 | ||
83 | void OImageScrollView::loadJpeg(bool interncall) | 82 | void OImageScrollView::loadJpeg(bool interncall) |
84 | { | 83 | { |
85 | if (m_lastName.isEmpty()) return; | 84 | if (m_lastName.isEmpty()) return; |
86 | QImageIO iio( m_lastName, 0l ); | 85 | QImageIO iio( m_lastName, 0l ); |
87 | QString param; | 86 | QString param; |
88 | bool real_load = false; | 87 | bool real_load = false; |
89 | if (AutoScale()) { | 88 | if (AutoScale()) { |
90 | if (!interncall) { | 89 | if (!interncall) { |
91 | int wid, hei; | 90 | int wid, hei; |
92 | wid = QApplication::desktop()->width(); | 91 | wid = QApplication::desktop()->width(); |
93 | hei = QApplication::desktop()->height(); | 92 | hei = QApplication::desktop()->height(); |
94 | if (hei>wid) { | 93 | if (hei>wid) { |
95 | wid = hei; | 94 | wid = hei; |
96 | } else { | 95 | } else { |
97 | hei = wid; | 96 | hei = wid; |
98 | } | 97 | } |
99 | param = QString( "Fast Shrink( 3 ) Scale( %1, %2, ScaleMin)" ).arg( wid ).arg( hei ); | 98 | param = QString( "Fast Shrink( 3 ) Scale( %1, %2, ScaleMin)" ).arg( wid ).arg( hei ); |
100 | odebug << "Load jpeg scaled \"" << param << "\"" << oendl; | 99 | odebug << "Load jpeg scaled \"" << param << "\"" << oendl; |
101 | iio.setParameters(param.latin1()); | 100 | iio.setParameters(param.latin1()); |
102 | setImageScaledLoaded(true); | 101 | setImageScaledLoaded(true); |
103 | real_load = true; | 102 | real_load = true; |
104 | } | 103 | } |
105 | } else { | 104 | } else { |
106 | if (ImageScaledLoaded()||!interncall) { | 105 | if (ImageScaledLoaded()||!interncall) { |
107 | odebug << "Load jpeg unscaled" << oendl; | 106 | odebug << "Load jpeg unscaled" << oendl; |
108 | real_load = true; | 107 | real_load = true; |
109 | } | 108 | } |
110 | setImageScaledLoaded(false); | 109 | setImageScaledLoaded(false); |
111 | } | 110 | } |
112 | if (real_load) { | 111 | if (real_load) { |
113 | { | ||
114 | QCopEnvelope( "QPE/System", "busy()" ); | ||
115 | } | ||
116 | _original_data = iio.read() ? iio.image() : QImage(); | 112 | _original_data = iio.read() ? iio.image() : QImage(); |
117 | { | ||
118 | QCopEnvelope env( "QPE/System", "notBusy(QString)" ); | ||
119 | env << "Image loaded"; | ||
120 | } | ||
121 | } | 113 | } |
122 | } | 114 | } |
123 | 115 | ||
124 | void OImageScrollView::setImage( const QString& path ) { | 116 | void OImageScrollView::setImage( const QString& path ) { |
125 | odebug << "load new image " << oendl; | 117 | odebug << "load new image " << oendl; |
126 | if (m_lastName == path) return; | 118 | if (m_lastName == path) return; |
127 | m_lastName = path; | 119 | m_lastName = path; |
128 | _original_data = QImage(); | 120 | _original_data = QImage(); |
129 | QString itype = QImage::imageFormat(m_lastName); | 121 | QString itype = QImage::imageFormat(m_lastName); |
130 | odebug << "Image type = " << itype << oendl; | 122 | odebug << "Image type = " << itype << oendl; |
131 | if (itype == "JPEG") { | 123 | if (itype == "JPEG") { |
132 | setImageIsJpeg(true); | 124 | setImageIsJpeg(true); |
133 | loadJpeg(); | 125 | loadJpeg(); |
134 | } else { | 126 | } else { |
135 | { | ||
136 | QCopEnvelope( "QPE/System", "busy()" ); | ||
137 | } | ||
138 | setImageIsJpeg(false); | 127 | setImageIsJpeg(false); |
139 | _original_data.load(path); | 128 | _original_data.load(path); |
140 | _original_data.convertDepth(QPixmap::defaultDepth()); | 129 | _original_data.convertDepth(QPixmap::defaultDepth()); |
141 | _original_data.setAlphaBuffer(false); | 130 | _original_data.setAlphaBuffer(false); |
142 | { | ||
143 | QCopEnvelope env( "QPE/System", "notBusy(QString)" ); | ||
144 | env << "Image loaded"; | ||
145 | } | ||
146 | } | 131 | } |
147 | _image_data = QImage(); | 132 | _image_data = QImage(); |
148 | if (FirstResizeDone()) { | 133 | if (FirstResizeDone()) { |
149 | generateImage(); | 134 | generateImage(); |
150 | if (isVisible()) viewport()->repaint(true); | 135 | if (isVisible()) viewport()->repaint(true); |
151 | } | 136 | } |
152 | } | 137 | } |
153 | 138 | ||
154 | /* should be called every time the QImage changed it content */ | 139 | /* should be called every time the QImage changed it content */ |
155 | void OImageScrollView::init() | 140 | void OImageScrollView::init() |
156 | { | 141 | { |
157 | odebug << "init " << oendl; | 142 | odebug << "init " << oendl; |
158 | 143 | ||
159 | /* | 144 | /* |
160 | * create the zoomer | 145 | * create the zoomer |
161 | * and connect ther various signals | 146 | * and connect ther various signals |
162 | */ | 147 | */ |
163 | _zoomer = new Opie::MM::OImageZoomer( this, "The Zoomer" ); | 148 | _zoomer = new Opie::MM::OImageZoomer( this, "The Zoomer" ); |
164 | connect(_zoomer, SIGNAL( zoomAreaRel(int,int)), | 149 | connect(_zoomer, SIGNAL( zoomAreaRel(int,int)), |
165 | this, SLOT(scrollBy(int,int)) ); | 150 | this, SLOT(scrollBy(int,int)) ); |
166 | connect(_zoomer, SIGNAL( zoomArea(int,int)), | 151 | connect(_zoomer, SIGNAL( zoomArea(int,int)), |
167 | this, SLOT(center(int,int)) ); | 152 | this, SLOT(center(int,int)) ); |
168 | connect(this,SIGNAL(contentsMoving(int,int)), | 153 | connect(this,SIGNAL(contentsMoving(int,int)), |
169 | _zoomer, (SLOT(setVisiblePoint(int,int))) ); | 154 | _zoomer, (SLOT(setVisiblePoint(int,int))) ); |
170 | connect(this,SIGNAL(imageSizeChanged(const QSize&)), | 155 | connect(this,SIGNAL(imageSizeChanged(const QSize&)), |
171 | _zoomer, SLOT(setImageSize(const QSize&)) ); | 156 | _zoomer, SLOT(setImageSize(const QSize&)) ); |
172 | connect(this,SIGNAL(viewportSizeChanged(const QSize&)), | 157 | connect(this,SIGNAL(viewportSizeChanged(const QSize&)), |
173 | _zoomer, SLOT(setViewPortSize(const QSize&)) ); | 158 | _zoomer, SLOT(setViewPortSize(const QSize&)) ); |
174 | 159 | ||
175 | viewport()->setBackgroundColor(white); | 160 | viewport()->setBackgroundColor(white); |
176 | setFocusPolicy(QWidget::StrongFocus); | 161 | setFocusPolicy(QWidget::StrongFocus); |
177 | setImageScaledLoaded(false); | 162 | setImageScaledLoaded(false); |
178 | setImageIsJpeg(false); | 163 | setImageIsJpeg(false); |
179 | if (FirstResizeDone()) { | 164 | if (FirstResizeDone()) { |
180 | m_last_rot = Rotate0; | 165 | m_last_rot = Rotate0; |
181 | generateImage(); | 166 | generateImage(); |
182 | } else if (_original_data.size().isValid()) { | 167 | } else if (_original_data.size().isValid()) { |
183 | if (image_fit_into(_original_data.size()) || !ShowZoomer()) _zoomer->hide(); | 168 | if (image_fit_into(_original_data.size()) || !ShowZoomer()) _zoomer->hide(); |
184 | resizeContents(_original_data.width(),_original_data.height()); | 169 | resizeContents(_original_data.width(),_original_data.height()); |
185 | } | 170 | } |
186 | } | 171 | } |
187 | 172 | ||
188 | void OImageScrollView::setAutoRotate(bool how) | 173 | void OImageScrollView::setAutoRotate(bool how) |
189 | { | 174 | { |
190 | /* to avoid double repaints */ | 175 | /* to avoid double repaints */ |
191 | if (AutoRotate() != how) { | 176 | if (AutoRotate() != how) { |
192 | m_states.setBit(AUTO_ROTATE,how); | 177 | m_states.setBit(AUTO_ROTATE,how); |
193 | _image_data = QImage(); | 178 | _image_data = QImage(); |
194 | generateImage(); | 179 | generateImage(); |
195 | } | 180 | } |
196 | } | 181 | } |
197 | 182 | ||
198 | bool OImageScrollView::AutoRotate()const | 183 | bool OImageScrollView::AutoRotate()const |
199 | { | 184 | { |
200 | return m_states.testBit(AUTO_ROTATE); | 185 | return m_states.testBit(AUTO_ROTATE); |
201 | } | 186 | } |
202 | 187 | ||
188 | void OImageScrollView::setAutoScaleRotate(bool scale, bool rotate) | ||
189 | { | ||
190 | m_states.setBit(AUTO_ROTATE,rotate); | ||
191 | setAutoScale(scale); | ||
192 | } | ||
193 | |||
203 | void OImageScrollView::setAutoScale(bool how) | 194 | void OImageScrollView::setAutoScale(bool how) |
204 | { | 195 | { |
205 | m_states.setBit(AUTO_SCALE,how); | 196 | m_states.setBit(AUTO_SCALE,how); |
206 | if (!how) { | ||
207 | setAutoRotate(false); | ||
208 | } | ||
209 | _image_data = QImage(); | 197 | _image_data = QImage(); |
210 | if (ImageIsJpeg() && how == false && ImageScaledLoaded()==true) { | 198 | if (ImageIsJpeg() && how == false && ImageScaledLoaded()==true) { |
211 | loadJpeg(true); | 199 | loadJpeg(true); |
212 | } | 200 | } |
213 | generateImage(); | 201 | generateImage(); |
214 | } | 202 | } |
215 | 203 | ||
216 | bool OImageScrollView::AutoScale()const | 204 | bool OImageScrollView::AutoScale()const |
217 | { | 205 | { |
218 | return m_states.testBit(AUTO_SCALE); | 206 | return m_states.testBit(AUTO_SCALE); |
219 | } | 207 | } |
220 | 208 | ||
221 | OImageScrollView::~OImageScrollView() | 209 | OImageScrollView::~OImageScrollView() |
222 | { | 210 | { |
223 | } | 211 | } |
224 | 212 | ||
225 | void OImageScrollView::rescaleImage(int w, int h) | 213 | void OImageScrollView::rescaleImage(int w, int h) |
226 | { | 214 | { |
227 | if (_image_data.width()==w && _image_data.height()==h) { | 215 | if (_image_data.width()==w && _image_data.height()==h) { |
228 | return; | 216 | return; |
229 | } | 217 | } |
230 | double hs = (double)h / (double)_image_data.height() ; | 218 | double hs = (double)h / (double)_image_data.height() ; |
231 | double ws = (double)w / (double)_image_data.width() ; | 219 | double ws = (double)w / (double)_image_data.width() ; |
232 | double scaleFactor = (hs > ws) ? ws : hs; | 220 | double scaleFactor = (hs > ws) ? ws : hs; |
233 | int smoothW = (int)(scaleFactor * _image_data.width()); | 221 | int smoothW = (int)(scaleFactor * _image_data.width()); |
234 | int smoothH = (int)(scaleFactor * _image_data.height()); | 222 | int smoothH = (int)(scaleFactor * _image_data.height()); |
235 | _image_data = _image_data.smoothScale(smoothW,smoothH); | 223 | _image_data = _image_data.smoothScale(smoothW,smoothH); |
236 | } | 224 | } |
237 | 225 | ||
238 | void OImageScrollView::rotate_into_data(Rotation r) | 226 | void OImageScrollView::rotate_into_data(Rotation r) |
239 | { | 227 | { |
240 | /* realy - we must do this that way, 'cause when acting direct on _image_data the app will | 228 | /* realy - we must do this that way, 'cause when acting direct on _image_data the app will |
241 | segfault :( */ | 229 | segfault :( */ |
242 | QImage dest; | 230 | QImage dest; |
243 | int x, y; | 231 | int x, y; |
244 | if ( _original_data.depth() > 8 ) | 232 | if ( _original_data.depth() > 8 ) |
245 | { | 233 | { |
246 | unsigned int *srcData, *destData; | 234 | unsigned int *srcData, *destData; |
247 | switch ( r ) | 235 | switch ( r ) |
248 | { | 236 | { |
249 | case Rotate90: | 237 | case Rotate90: |
250 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); | 238 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); |
251 | for ( y=0; y < _original_data.height(); ++y ) | 239 | for ( y=0; y < _original_data.height(); ++y ) |
252 | { | 240 | { |
253 | srcData = (unsigned int *)_original_data.scanLine(y); | 241 | srcData = (unsigned int *)_original_data.scanLine(y); |
254 | for ( x=0; x < _original_data.width(); ++x ) | 242 | for ( x=0; x < _original_data.width(); ++x ) |
255 | { | 243 | { |
256 | destData = (unsigned int *)dest.scanLine(x); | 244 | destData = (unsigned int *)dest.scanLine(x); |
257 | destData[_original_data.height()-y-1] = srcData[x]; | 245 | destData[_original_data.height()-y-1] = srcData[x]; |
258 | } | 246 | } |
259 | } | 247 | } |
260 | break; | 248 | break; |
261 | case Rotate180: | 249 | case Rotate180: |
262 | dest.create(_original_data.width(), _original_data.height(), _original_data.depth()); | 250 | dest.create(_original_data.width(), _original_data.height(), _original_data.depth()); |
263 | for ( y=0; y < _original_data.height(); ++y ) | 251 | for ( y=0; y < _original_data.height(); ++y ) |
264 | { | 252 | { |
265 | srcData = (unsigned int *)_original_data.scanLine(y); | 253 | srcData = (unsigned int *)_original_data.scanLine(y); |
266 | destData = (unsigned int *)dest.scanLine(_original_data.height()-y-1); | 254 | destData = (unsigned int *)dest.scanLine(_original_data.height()-y-1); |
267 | for ( x=0; x < _original_data.width(); ++x ) | 255 | for ( x=0; x < _original_data.width(); ++x ) |
268 | destData[_original_data.width()-x-1] = srcData[x]; | 256 | destData[_original_data.width()-x-1] = srcData[x]; |
269 | } | 257 | } |
270 | break; | 258 | break; |
271 | case Rotate270: | 259 | case Rotate270: |
272 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); | 260 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); |
273 | for ( y=0; y < _original_data.height(); ++y ) | 261 | for ( y=0; y < _original_data.height(); ++y ) |
274 | { | 262 | { |
275 | srcData = (unsigned int *)_original_data.scanLine(y); | 263 | srcData = (unsigned int *)_original_data.scanLine(y); |
276 | for ( x=0; x < _original_data.width(); ++x ) | 264 | for ( x=0; x < _original_data.width(); ++x ) |
277 | { | 265 | { |
278 | destData = (unsigned int *)dest.scanLine(_original_data.width()-x-1); | 266 | destData = (unsigned int *)dest.scanLine(_original_data.width()-x-1); |
279 | destData[y] = srcData[x]; | 267 | destData[y] = srcData[x]; |
280 | } | 268 | } |
281 | } | 269 | } |
282 | break; | 270 | break; |
283 | default: | 271 | default: |
284 | dest = _original_data; | 272 | dest = _original_data; |
285 | break; | 273 | break; |
286 | } | 274 | } |
287 | } | 275 | } |
288 | else | 276 | else |
289 | { | 277 | { |
290 | unsigned char *srcData, *destData; | 278 | unsigned char *srcData, *destData; |
291 | unsigned int *srcTable, *destTable; | 279 | unsigned int *srcTable, *destTable; |
292 | switch ( r ) | 280 | switch ( r ) |
293 | { | 281 | { |
294 | case Rotate90: | 282 | case Rotate90: |
295 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); | 283 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); |
296 | dest.setNumColors(_original_data.numColors()); | 284 | dest.setNumColors(_original_data.numColors()); |
297 | srcTable = (unsigned int *)_original_data.colorTable(); | 285 | srcTable = (unsigned int *)_original_data.colorTable(); |
298 | destTable = (unsigned int *)dest.colorTable(); | 286 | destTable = (unsigned int *)dest.colorTable(); |
299 | for ( x=0; x < _original_data.numColors(); ++x ) | 287 | for ( x=0; x < _original_data.numColors(); ++x ) |
300 | destTable[x] = srcTable[x]; | 288 | destTable[x] = srcTable[x]; |
301 | for ( y=0; y < _original_data.height(); ++y ) | 289 | for ( y=0; y < _original_data.height(); ++y ) |
302 | { | 290 | { |
303 | srcData = (unsigned char *)_original_data.scanLine(y); | 291 | srcData = (unsigned char *)_original_data.scanLine(y); |
304 | for ( x=0; x < _original_data.width(); ++x ) | 292 | for ( x=0; x < _original_data.width(); ++x ) |
305 | { | 293 | { |
306 | destData = (unsigned char *)dest.scanLine(x); | 294 | destData = (unsigned char *)dest.scanLine(x); |
307 | destData[_original_data.height()-y-1] = srcData[x]; | 295 | destData[_original_data.height()-y-1] = srcData[x]; |
308 | } | 296 | } |
309 | } | 297 | } |
310 | break; | 298 | break; |
311 | case Rotate180: | 299 | case Rotate180: |
312 | dest.create(_original_data.width(), _original_data.height(), _original_data.depth()); | 300 | dest.create(_original_data.width(), _original_data.height(), _original_data.depth()); |
313 | dest.setNumColors(_original_data.numColors()); | 301 | dest.setNumColors(_original_data.numColors()); |
314 | srcTable = (unsigned int *)_original_data.colorTable(); | 302 | srcTable = (unsigned int *)_original_data.colorTable(); |
315 | destTable = (unsigned int *)dest.colorTable(); | 303 | destTable = (unsigned int *)dest.colorTable(); |
316 | for ( x=0; x < _original_data.numColors(); ++x ) | 304 | for ( x=0; x < _original_data.numColors(); ++x ) |
317 | destTable[x] = srcTable[x]; | 305 | destTable[x] = srcTable[x]; |
318 | for ( y=0; y < _original_data.height(); ++y ) | 306 | for ( y=0; y < _original_data.height(); ++y ) |
319 | { | 307 | { |
320 | srcData = (unsigned char *)_original_data.scanLine(y); | 308 | srcData = (unsigned char *)_original_data.scanLine(y); |
321 | destData = (unsigned char *)dest.scanLine(_original_data.height()-y-1); | 309 | destData = (unsigned char *)dest.scanLine(_original_data.height()-y-1); |
322 | for ( x=0; x < _original_data.width(); ++x ) | 310 | for ( x=0; x < _original_data.width(); ++x ) |
323 | destData[_original_data.width()-x-1] = srcData[x]; | 311 | destData[_original_data.width()-x-1] = srcData[x]; |
324 | } | 312 | } |
325 | break; | 313 | break; |
326 | case Rotate270: | 314 | case Rotate270: |
327 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); | 315 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); |
328 | dest.setNumColors(_original_data.numColors()); | 316 | dest.setNumColors(_original_data.numColors()); |
329 | srcTable = (unsigned int *)_original_data.colorTable(); | 317 | srcTable = (unsigned int *)_original_data.colorTable(); |
330 | destTable = (unsigned int *)dest.colorTable(); | 318 | destTable = (unsigned int *)dest.colorTable(); |
331 | for ( x=0; x < _original_data.numColors(); ++x ) | 319 | for ( x=0; x < _original_data.numColors(); ++x ) |
332 | destTable[x] = srcTable[x]; | 320 | destTable[x] = srcTable[x]; |
333 | for ( y=0; y < _original_data.height(); ++y ) | 321 | for ( y=0; y < _original_data.height(); ++y ) |
334 | { | 322 | { |
335 | srcData = (unsigned char *)_original_data.scanLine(y); | 323 | srcData = (unsigned char *)_original_data.scanLine(y); |
336 | for ( x=0; x < _original_data.width(); ++x ) | 324 | for ( x=0; x < _original_data.width(); ++x ) |
337 | { | 325 | { |
338 | destData = (unsigned char *)dest.scanLine(_original_data.width()-x-1); | 326 | destData = (unsigned char *)dest.scanLine(_original_data.width()-x-1); |
339 | destData[y] = srcData[x]; | 327 | destData[y] = srcData[x]; |
340 | } | 328 | } |
341 | } | 329 | } |
342 | break; | 330 | break; |
343 | default: | 331 | default: |
344 | dest = _original_data; | 332 | dest = _original_data; |
345 | break; | 333 | break; |
346 | } | 334 | } |
347 | 335 | ||
348 | } | 336 | } |
349 | _image_data = dest; | 337 | _image_data = dest; |
350 | } | 338 | } |
351 | 339 | ||
352 | void OImageScrollView::generateImage() | 340 | void OImageScrollView::generateImage() |
353 | { | 341 | { |
354 | Rotation r = Rotate0; | 342 | Rotation r = Rotate0; |
355 | _pdata = QPixmap(); | 343 | _pdata = QPixmap(); |
356 | if (_original_data.isNull()) { | 344 | if (_original_data.isNull()) { |
357 | emit imageSizeChanged( _image_data.size() ); | 345 | emit imageSizeChanged( _image_data.size() ); |
358 | if (_zoomer) _zoomer->setImage( _image_data ); | 346 | if (_zoomer) _zoomer->setImage( _image_data ); |
359 | return; | 347 | return; |
360 | } | 348 | } |
361 | { | ||
362 | QCopEnvelope( "QPE/System", "busy()" ); | ||
363 | } | ||
364 | if (width()>height()&&_original_data.width()<_original_data.height() || | 349 | if (width()>height()&&_original_data.width()<_original_data.height() || |
365 | width()<height()&&_original_data.width()>_original_data.height()) { | 350 | width()<height()&&_original_data.width()>_original_data.height()) { |
366 | if (AutoRotate()) r = Rotate90; | 351 | if (AutoRotate()) r = Rotate90; |
367 | } | 352 | } |
368 | 353 | ||
369 | 354 | ||
370 | odebug << " r = " << r << oendl; | 355 | odebug << " r = " << r << oendl; |
371 | if (AutoScale() && (_original_data.width()>width() || _original_data.height() > height()) ) { | 356 | if (AutoScale() && (_original_data.width()>width() || _original_data.height() > height()) ) { |
372 | if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) { | 357 | if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) { |
373 | odebug << "Rescaling data" << oendl; | 358 | odebug << "Rescaling data" << oendl; |
374 | if (r==Rotate0) { | 359 | if (r==Rotate0) { |
375 | _image_data = _original_data; | 360 | _image_data = _original_data; |
376 | } else { | 361 | } else { |
377 | rotate_into_data(r); | 362 | rotate_into_data(r); |
378 | } | 363 | } |
379 | } | 364 | } |
380 | rescaleImage(width(),height()); | 365 | rescaleImage(width(),height()); |
381 | resizeContents(_image_data.width(),_image_data.height()); | 366 | resizeContents(_image_data.width(),_image_data.height()); |
382 | } else if (!FirstResizeDone()||r!=m_last_rot||_image_data.width()==0) { | 367 | } else if (!FirstResizeDone()||r!=m_last_rot||_image_data.width()==0) { |
383 | if (r==Rotate0) { | 368 | if (r==Rotate0) { |
384 | _image_data = _original_data; | 369 | _image_data = _original_data; |
385 | } else { | 370 | } else { |
386 | rotate_into_data(r); | 371 | rotate_into_data(r); |
387 | } | 372 | } |
388 | m_last_rot = r; | 373 | m_last_rot = r; |
389 | resizeContents(_image_data.width(),_image_data.height()); | 374 | resizeContents(_image_data.width(),_image_data.height()); |
390 | } | 375 | } |
391 | _pdata.convertFromImage(_image_data); | 376 | _pdata.convertFromImage(_image_data); |
392 | 377 | ||
393 | /* | 378 | /* |
394 | * update the zoomer | 379 | * update the zoomer |
395 | */ | 380 | */ |
396 | check_zoomer(); | 381 | check_zoomer(); |
397 | emit imageSizeChanged( _image_data.size() ); | 382 | emit imageSizeChanged( _image_data.size() ); |
398 | rescaleImage( 128, 128 ); | 383 | rescaleImage( 128, 128 ); |
399 | /* | 384 | /* |
400 | * move scrollbar | 385 | * move scrollbar |
401 | */ | 386 | */ |
402 | if (_zoomer) { | 387 | if (_zoomer) { |
403 | _zoomer->setGeometry( viewport()->width()-_image_data.width()/2, viewport()->height()-_image_data.height()/2, | 388 | _zoomer->setGeometry( viewport()->width()-_image_data.width()/2, viewport()->height()-_image_data.height()/2, |
404 | _image_data.width()/2, _image_data.height()/2 ); | 389 | _image_data.width()/2, _image_data.height()/2 ); |
405 | _zoomer->setImage( _image_data ); | 390 | _zoomer->setImage( _image_data ); |
406 | } | 391 | } |
407 | /* | 392 | /* |
408 | * invalidate | 393 | * invalidate |
409 | */ | 394 | */ |
410 | _image_data=QImage(); | 395 | _image_data=QImage(); |
411 | { | ||
412 | QCopEnvelope env( "QPE/System", "notBusy(QString)" ); | ||
413 | env << "Image generated"; | ||
414 | } | ||
415 | } | 396 | } |
416 | 397 | ||
417 | void OImageScrollView::resizeEvent(QResizeEvent * e) | 398 | void OImageScrollView::resizeEvent(QResizeEvent * e) |
418 | { | 399 | { |
419 | odebug << "OImageScrollView resizeEvent" << oendl; | 400 | odebug << "OImageScrollView resizeEvent" << oendl; |
420 | QScrollView::resizeEvent(e); | 401 | QScrollView::resizeEvent(e); |
421 | generateImage(); | 402 | generateImage(); |
422 | setFirstResizeDone(true); | 403 | setFirstResizeDone(true); |
423 | emit viewportSizeChanged( viewport()->size() ); | 404 | emit viewportSizeChanged( viewport()->size() ); |
424 | 405 | ||
425 | } | 406 | } |
426 | 407 | ||
427 | void OImageScrollView::keyPressEvent(QKeyEvent * e) | 408 | void OImageScrollView::keyPressEvent(QKeyEvent * e) |
428 | { | 409 | { |
429 | if (!e) return; | 410 | if (!e) return; |
430 | int dx = horizontalScrollBar()->lineStep(); | 411 | int dx = horizontalScrollBar()->lineStep(); |
431 | int dy = verticalScrollBar()->lineStep(); | 412 | int dy = verticalScrollBar()->lineStep(); |
432 | if (e->key()==Qt::Key_Right) { | 413 | if (e->key()==Qt::Key_Right) { |
433 | scrollBy(dx,0); | 414 | scrollBy(dx,0); |
434 | e->accept(); | 415 | e->accept(); |
435 | } else if (e->key()==Qt::Key_Left) { | 416 | } else if (e->key()==Qt::Key_Left) { |
436 | scrollBy(0-dx,0); | 417 | scrollBy(0-dx,0); |
437 | e->accept(); | 418 | e->accept(); |
438 | } else if (e->key()==Qt::Key_Up) { | 419 | } else if (e->key()==Qt::Key_Up) { |
439 | scrollBy(0,0-dy); | 420 | scrollBy(0,0-dy); |
440 | e->accept(); | 421 | e->accept(); |
441 | } else if (e->key()==Qt::Key_Down) { | 422 | } else if (e->key()==Qt::Key_Down) { |
442 | scrollBy(0,dy); | 423 | scrollBy(0,dy); |
443 | e->accept(); | 424 | e->accept(); |
444 | } else { | 425 | } else { |
445 | e->ignore(); | 426 | e->ignore(); |
446 | } | 427 | } |
447 | QScrollView::keyPressEvent(e); | 428 | QScrollView::keyPressEvent(e); |
448 | } | 429 | } |
449 | 430 | ||
450 | void OImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph) | 431 | void OImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph) |
451 | { | 432 | { |
452 | int w = clipw; | 433 | int w = clipw; |
453 | int h = cliph; | 434 | int h = cliph; |
454 | int x = clipx; | 435 | int x = clipx; |
455 | int y = clipy; | 436 | int y = clipy; |
456 | bool erase = false; | 437 | bool erase = false; |
457 | 438 | ||
458 | if (!_pdata.size().isValid()) { | 439 | if (!_pdata.size().isValid()) { |
459 | p->fillRect(clipx,clipy,clipw,cliph,white); | 440 | p->fillRect(clipx,clipy,clipw,cliph,white); |
460 | return; | 441 | return; |
461 | } | 442 | } |
462 | if (w>_pdata.width()) { | 443 | if (w>_pdata.width()) { |
463 | w=_pdata.width(); | 444 | w=_pdata.width(); |
464 | x = 0; | 445 | x = 0; |
465 | erase = true; | 446 | erase = true; |
466 | } else if (x+w>_pdata.width()){ | 447 | } else if (x+w>_pdata.width()){ |
467 | x = _pdata.width()-w; | 448 | x = _pdata.width()-w; |
468 | } | 449 | } |
469 | if (h>_pdata.height()) { | 450 | if (h>_pdata.height()) { |
470 | h=_pdata.height(); | 451 | h=_pdata.height(); |
471 | y = 0; | 452 | y = 0; |
472 | erase = true; | 453 | erase = true; |
473 | } else if (y+h>_pdata.height()){ | 454 | } else if (y+h>_pdata.height()){ |
474 | y = _pdata.height()-h; | 455 | y = _pdata.height()-h; |
475 | } | 456 | } |
476 | if (erase||_original_data.hasAlphaBuffer()) { | 457 | if (erase||_original_data.hasAlphaBuffer()) { |
477 | p->fillRect(clipx,clipy,clipw,cliph,white); | 458 | p->fillRect(clipx,clipy,clipw,cliph,white); |
478 | } | 459 | } |
479 | p->drawPixmap(clipx,clipy,_pdata,x,y,w,h); | 460 | p->drawPixmap(clipx,clipy,_pdata,x,y,w,h); |
480 | } | 461 | } |
481 | 462 | ||
482 | /* using the real geometry points and not the translated points is wanted! */ | 463 | /* using the real geometry points and not the translated points is wanted! */ |
483 | void OImageScrollView::viewportMouseMoveEvent(QMouseEvent* e) | 464 | void OImageScrollView::viewportMouseMoveEvent(QMouseEvent* e) |
484 | { | 465 | { |
485 | int mx, my; | 466 | int mx, my; |
486 | mx = e->x(); | 467 | mx = e->x(); |
487 | my = e->y(); | 468 | my = e->y(); |
488 | if (_mouseStartPosX!=-1 && _mouseStartPosY!=-1) { | 469 | if (_mouseStartPosX!=-1 && _mouseStartPosY!=-1) { |
489 | int diffx = _mouseStartPosX-mx; | 470 | int diffx = _mouseStartPosX-mx; |
490 | int diffy = _mouseStartPosY-my; | 471 | int diffy = _mouseStartPosY-my; |
491 | scrollBy(diffx,diffy); | 472 | scrollBy(diffx,diffy); |
492 | } | 473 | } |
493 | _mouseStartPosX=mx; | 474 | _mouseStartPosX=mx; |
494 | _mouseStartPosY=my; | 475 | _mouseStartPosY=my; |
495 | } | 476 | } |
496 | 477 | ||
497 | void OImageScrollView::contentsMousePressEvent ( QMouseEvent * e) | 478 | void OImageScrollView::contentsMousePressEvent ( QMouseEvent * e) |
498 | { | 479 | { |
499 | odebug << " X and Y " << e->x() << " " << e->y() << oendl; | 480 | odebug << " X and Y " << e->x() << " " << e->y() << oendl; |
500 | /* this marks the beginning of a possible mouse move. Due internal reasons of QT | 481 | /* this marks the beginning of a possible mouse move. Due internal reasons of QT |
501 | the geometry values here may real differ from that set in MoveEvent (I don't know | 482 | the geometry values here may real differ from that set in MoveEvent (I don't know |
502 | why). For getting them in real context, we use the first move-event to set the start | 483 | why). For getting them in real context, we use the first move-event to set the start |
503 | position ;) | 484 | position ;) |
504 | */ | 485 | */ |
505 | _mouseStartPosX = -1; | 486 | _mouseStartPosX = -1; |
506 | _mouseStartPosY = -1; | 487 | _mouseStartPosY = -1; |
507 | } | 488 | } |
508 | 489 | ||
509 | void OImageScrollView::setDestructiveClose() { | 490 | void OImageScrollView::setDestructiveClose() { |
510 | WFlags fl = getWFlags(); | 491 | WFlags fl = getWFlags(); |
511 | /* clear it just in case */ | 492 | /* clear it just in case */ |
512 | fl &= ~WDestructiveClose; | 493 | fl &= ~WDestructiveClose; |
513 | fl |= WDestructiveClose; | 494 | fl |= WDestructiveClose; |
514 | setWFlags( fl ); | 495 | setWFlags( fl ); |
515 | } | 496 | } |
516 | 497 | ||
517 | bool OImageScrollView::image_fit_into(const QSize&s ) | 498 | bool OImageScrollView::image_fit_into(const QSize&s ) |
518 | { | 499 | { |
519 | if (s.width()>width()||s.height()>height()) { | 500 | if (s.width()>width()||s.height()>height()) { |
520 | return false; | 501 | return false; |
521 | } | 502 | } |
522 | return true; | 503 | return true; |
523 | } | 504 | } |
524 | 505 | ||
525 | void OImageScrollView::setShowZoomer(bool how) | 506 | void OImageScrollView::setShowZoomer(bool how) |
526 | { | 507 | { |
527 | m_states.setBit(SHOW_ZOOMER,how); | 508 | m_states.setBit(SHOW_ZOOMER,how); |
528 | check_zoomer(); | 509 | check_zoomer(); |
529 | } | 510 | } |
530 | 511 | ||
531 | bool OImageScrollView::ShowZoomer()const | 512 | bool OImageScrollView::ShowZoomer()const |
532 | { | 513 | { |
533 | return m_states.testBit(SHOW_ZOOMER); | 514 | return m_states.testBit(SHOW_ZOOMER); |
534 | } | 515 | } |
535 | 516 | ||
536 | void OImageScrollView::check_zoomer() | 517 | void OImageScrollView::check_zoomer() |
537 | { | 518 | { |
538 | if (!_zoomer) return; | 519 | if (!_zoomer) return; |
539 | if ( (!ShowZoomer()||image_fit_into(_pdata.size()) ) && _zoomer->isVisible()) { | 520 | if ( (!ShowZoomer()||image_fit_into(_pdata.size()) ) && _zoomer->isVisible()) { |
540 | _zoomer->hide(); | 521 | _zoomer->hide(); |
541 | } else if ( ShowZoomer() && !image_fit_into(_pdata.size()) && _zoomer->isHidden()){ | 522 | } else if ( ShowZoomer() && !image_fit_into(_pdata.size()) && _zoomer->isHidden()){ |
542 | _zoomer->show(); | 523 | _zoomer->show(); |
543 | } | 524 | } |
544 | } | 525 | } |
545 | 526 | ||
546 | bool OImageScrollView::FirstResizeDone()const | 527 | bool OImageScrollView::FirstResizeDone()const |
547 | { | 528 | { |
548 | return m_states.testBit(FIRST_RESIZE_DONE); | 529 | return m_states.testBit(FIRST_RESIZE_DONE); |
549 | } | 530 | } |
550 | 531 | ||
551 | void OImageScrollView::setFirstResizeDone(bool how) | 532 | void OImageScrollView::setFirstResizeDone(bool how) |
552 | { | 533 | { |
553 | m_states.setBit(FIRST_RESIZE_DONE,how); | 534 | m_states.setBit(FIRST_RESIZE_DONE,how); |
554 | } | 535 | } |
555 | 536 | ||
556 | bool OImageScrollView::ImageIsJpeg()const | 537 | bool OImageScrollView::ImageIsJpeg()const |
557 | { | 538 | { |
558 | return m_states.testBit(IMAGE_IS_JPEG); | 539 | return m_states.testBit(IMAGE_IS_JPEG); |
559 | } | 540 | } |
560 | 541 | ||
561 | void OImageScrollView::setImageIsJpeg(bool how) | 542 | void OImageScrollView::setImageIsJpeg(bool how) |
562 | { | 543 | { |
563 | m_states.setBit(IMAGE_IS_JPEG,how); | 544 | m_states.setBit(IMAGE_IS_JPEG,how); |
564 | } | 545 | } |
565 | 546 | ||
566 | bool OImageScrollView::ImageScaledLoaded()const | 547 | bool OImageScrollView::ImageScaledLoaded()const |
567 | { | 548 | { |
568 | return m_states.testBit(IMAGE_SCALED_LOADED); | 549 | return m_states.testBit(IMAGE_SCALED_LOADED); |
569 | } | 550 | } |
570 | 551 | ||
571 | void OImageScrollView::setImageScaledLoaded(bool how) | 552 | void OImageScrollView::setImageScaledLoaded(bool how) |
572 | { | 553 | { |
573 | m_states.setBit(IMAGE_SCALED_LOADED,how); | 554 | m_states.setBit(IMAGE_SCALED_LOADED,how); |
574 | } | 555 | } |
575 | 556 | ||
576 | } // namespace MM | 557 | } // namespace MM |
577 | } // namespace Opie | 558 | } // namespace Opie |
diff --git a/libopie2/opiemm/oimagescrollview.h b/libopie2/opiemm/oimagescrollview.h index 94fddb6..01a2d56 100644 --- a/libopie2/opiemm/oimagescrollview.h +++ b/libopie2/opiemm/oimagescrollview.h | |||
@@ -1,180 +1,193 @@ | |||
1 | #ifndef _IMAGE_SCROLL_VIEW_H | 1 | #ifndef _IMAGE_SCROLL_VIEW_H |
2 | #define _IMAGE_SCROLL_VIEW_H | 2 | #define _IMAGE_SCROLL_VIEW_H |
3 | 3 | ||
4 | #include <qscrollview.h> | 4 | #include <qscrollview.h> |
5 | #include <qimage.h> | 5 | #include <qimage.h> |
6 | #include <qpixmap.h> | 6 | #include <qpixmap.h> |
7 | #include <qstring.h> | 7 | #include <qstring.h> |
8 | #include <qdialog.h> | 8 | #include <qdialog.h> |
9 | #include <qbitarray.h> | 9 | #include <qbitarray.h> |
10 | 10 | ||
11 | 11 | ||
12 | class QPainter; | 12 | class QPainter; |
13 | 13 | ||
14 | namespace Opie { namespace MM { | 14 | namespace Opie { namespace MM { |
15 | 15 | ||
16 | class OImageZoomer; | 16 | class OImageZoomer; |
17 | /** | 17 | /** |
18 | * \brief Class displaying an image with scrollbars | 18 | * \brief Class displaying an image with scrollbars |
19 | * | 19 | * |
20 | * This class displays various image formats supported by QT an | 20 | * This class displays various image formats supported by QT an |
21 | * gives a small interface for basics display modifications. | 21 | * gives a small interface for basics display modifications. |
22 | * | 22 | * |
23 | * @see QScrollView | 23 | * @see QScrollView |
24 | * | 24 | * |
25 | * @since 1.2 | 25 | * @since 1.2 |
26 | */ | 26 | */ |
27 | class OImageScrollView:public QScrollView | 27 | class OImageScrollView:public QScrollView |
28 | { | 28 | { |
29 | Q_OBJECT | 29 | Q_OBJECT |
30 | public: | 30 | public: |
31 | enum Rotation { | 31 | enum Rotation { |
32 | Rotate0, | 32 | Rotate0, |
33 | Rotate90, | 33 | Rotate90, |
34 | Rotate180, | 34 | Rotate180, |
35 | Rotate270 | 35 | Rotate270 |
36 | }; | 36 | }; |
37 | 37 | ||
38 | /** | 38 | /** |
39 | * Standard constructor | 39 | * Standard constructor |
40 | * @param parent the parent widget | 40 | * @param parent the parent widget |
41 | * @param name the name of the widget | 41 | * @param name the name of the widget |
42 | * @param fl widget flags. The flag Qt::WRepaintNoErase will be always set. | 42 | * @param fl widget flags. The flag Qt::WRepaintNoErase will be always set. |
43 | */ | 43 | */ |
44 | OImageScrollView( QWidget* parent, const char* name = 0, WFlags fl = 0 ); | 44 | OImageScrollView( QWidget* parent, const char* name = 0, WFlags fl = 0 ); |
45 | /** | 45 | /** |
46 | * constructor | 46 | * constructor |
47 | * @param aImage QImage object to display | 47 | * @param aImage QImage object to display |
48 | * @param parent the parent widget | 48 | * @param parent the parent widget |
49 | * @param name the name of the widget | 49 | * @param name the name of the widget |
50 | * @param fl widget flags. The flag Qt::WRepaintNoErase will be always set. | 50 | * @param fl widget flags. The flag Qt::WRepaintNoErase will be always set. |
51 | * @param always_scale if the image should be scaled into the display | 51 | * @param always_scale if the image should be scaled into the display |
52 | * @param rfit the image will be rotated to fit | 52 | * @param rfit the image will be rotated to fit |
53 | */ | 53 | */ |
54 | OImageScrollView (const QImage&aImage, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false ); | 54 | OImageScrollView (const QImage&aImage, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false ); |
55 | /** | 55 | /** |
56 | * constructor | 56 | * constructor |
57 | * @param aFile image file to display | 57 | * @param aFile image file to display |
58 | * @param parent the parent widget | 58 | * @param parent the parent widget |
59 | * @param name the name of the widget | 59 | * @param name the name of the widget |
60 | * @param fl widget flags. The flag Qt::WRepaintNoErase will be always set. | 60 | * @param fl widget flags. The flag Qt::WRepaintNoErase will be always set. |
61 | * @param always_scale if the image should be scaled into the display | 61 | * @param always_scale if the image should be scaled into the display |
62 | * @param rfit the image will be rotated to fit | 62 | * @param rfit the image will be rotated to fit |
63 | */ | 63 | */ |
64 | OImageScrollView (const QString&aFile, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false ); | 64 | OImageScrollView (const QString&aFile, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false ); |
65 | virtual ~OImageScrollView(); | 65 | virtual ~OImageScrollView(); |
66 | 66 | ||
67 | /** | 67 | /** |
68 | * sets the WDestructiveClose flag to the view | 68 | * sets the WDestructiveClose flag to the view |
69 | */ | 69 | */ |
70 | virtual void setDestructiveClose(); | 70 | virtual void setDestructiveClose(); |
71 | 71 | ||
72 | /** | 72 | /** |
73 | * set if the image should be rotate to best fit | 73 | * set if the image should be rotate to best fit |
74 | * and repaint it if set to a new value. | 74 | * and repaint it if set to a new value. |
75 | * | 75 | * |
76 | * Be carefull - autorating real large images cost time! | 76 | * Be carefull - autorating real large images cost time! |
77 | * @param how if true then autorotate otherwise not | 77 | * @param how if true then autorotate otherwise not |
78 | */ | 78 | */ |
79 | virtual void setAutoRotate(bool how); | 79 | virtual void setAutoRotate(bool how); |
80 | /** | 80 | /** |
81 | * set if the image should be scaled to the size of the viewport if larger(!) | 81 | * set if the image should be scaled to the size of the viewport if larger(!) |
82 | * | 82 | * |
83 | * if autoscaling is set when loading a jpeg image, it will use a feature of | 83 | * if autoscaling is set when loading a jpeg image, it will use a feature of |
84 | * jpeg lib to load the image scaled to display size. If switch of later the | 84 | * jpeg lib to load the image scaled to display size. If switch of later the |
85 | * image will reloaded. | 85 | * image will reloaded. |
86 | * | 86 | * |
87 | * @param how true - display image scaled down otherwise not | 87 | * @param how true - display image scaled down otherwise not |
88 | */ | 88 | */ |
89 | virtual void setAutoScale(bool how); | 89 | virtual void setAutoScale(bool how); |
90 | /** | 90 | /** |
91 | * set if the image should be scaled to the size of the viewport if larger(!) | ||
92 | * and/or rotate to best fit. You avoid double repainting when you want to switch | ||
93 | * booth values. | ||
94 | * | ||
95 | * if autoscaling is set when loading a jpeg image, it will use a feature of | ||
96 | * jpeg lib to load the image scaled to display size. If switch of later the | ||
97 | * image will reloaded. | ||
98 | * | ||
99 | * @param scale true - display image scaled down otherwise not | ||
100 | * @param rotate true - the image will rotate for best fit | ||
101 | */ | ||
102 | virtual void setAutoScaleRotate(bool scale, bool rotate); | ||
103 | /** | ||
91 | * set if there should be displayed a small zoomer widget at the right bottom of | 104 | * set if there should be displayed a small zoomer widget at the right bottom of |
92 | * the view when the image is larger than the viewport. | 105 | * the view when the image is larger than the viewport. |
93 | * | 106 | * |
94 | * @param how true - display zoomer | 107 | * @param how true - display zoomer |
95 | */ | 108 | */ |
96 | virtual void setShowZoomer(bool how); | 109 | virtual void setShowZoomer(bool how); |
97 | 110 | ||
98 | /** | 111 | /** |
99 | * return the current value of the autorotate flag. | 112 | * return the current value of the autorotate flag. |
100 | */ | 113 | */ |
101 | virtual bool AutoRotate()const; | 114 | virtual bool AutoRotate()const; |
102 | /** | 115 | /** |
103 | * return the current value of the autoscale flag. | 116 | * return the current value of the autoscale flag. |
104 | */ | 117 | */ |
105 | virtual bool AutoScale()const; | 118 | virtual bool AutoScale()const; |
106 | /** | 119 | /** |
107 | * return the current value of the show zoomer flag. | 120 | * return the current value of the show zoomer flag. |
108 | */ | 121 | */ |
109 | virtual bool ShowZoomer()const; | 122 | virtual bool ShowZoomer()const; |
110 | 123 | ||
111 | public slots: | 124 | public slots: |
112 | /** | 125 | /** |
113 | * Displays a new image, calculations will made immediately. | 126 | * Displays a new image, calculations will made immediately. |
114 | * | 127 | * |
115 | * @param aImage the image to display | 128 | * @param aImage the image to display |
116 | */ | 129 | */ |
117 | virtual void setImage(const QImage&aImage); | 130 | virtual void setImage(const QImage&aImage); |
118 | /** | 131 | /** |
119 | * Displays a new image, calculations will made immediately. | 132 | * Displays a new image, calculations will made immediately. |
120 | * | 133 | * |
121 | * @param path the image to display | 134 | * @param path the image to display |
122 | */ | 135 | */ |
123 | virtual void setImage( const QString& path ); | 136 | virtual void setImage( const QString& path ); |
124 | 137 | ||
125 | 138 | ||
126 | signals: | 139 | signals: |
127 | /** | 140 | /** |
128 | * emitted when the display image size has changed. | 141 | * emitted when the display image size has changed. |
129 | */ | 142 | */ |
130 | void imageSizeChanged( const QSize& ); | 143 | void imageSizeChanged( const QSize& ); |
131 | /** | 144 | /** |
132 | * emitted when the size of the viewport has changed, eg. in resizeEvent of | 145 | * emitted when the size of the viewport has changed, eg. in resizeEvent of |
133 | * the view. | 146 | * the view. |
134 | * | 147 | * |
135 | * @see QWidget::resizeEvent | 148 | * @see QWidget::resizeEvent |
136 | */ | 149 | */ |
137 | void viewportSizeChanged( const QSize& ); | 150 | void viewportSizeChanged( const QSize& ); |
138 | 151 | ||
139 | protected: | 152 | protected: |
140 | virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph ); | 153 | virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph ); |
141 | void init(); | 154 | void init(); |
142 | 155 | ||
143 | Opie::MM::OImageZoomer *_zoomer; | 156 | Opie::MM::OImageZoomer *_zoomer; |
144 | QImage _image_data; | 157 | QImage _image_data; |
145 | QImage _original_data; | 158 | QImage _original_data; |
146 | QPixmap _pdata; | 159 | QPixmap _pdata; |
147 | 160 | ||
148 | int _mouseStartPosX,_mouseStartPosY; | 161 | int _mouseStartPosX,_mouseStartPosY; |
149 | 162 | ||
150 | QBitArray m_states; | 163 | QBitArray m_states; |
151 | 164 | ||
152 | Rotation m_last_rot; | 165 | Rotation m_last_rot; |
153 | QString m_lastName; | 166 | QString m_lastName; |
154 | virtual void rescaleImage(int w, int h); | 167 | virtual void rescaleImage(int w, int h); |
155 | 168 | ||
156 | virtual void rotate_into_data(Rotation r); | 169 | virtual void rotate_into_data(Rotation r); |
157 | virtual void generateImage(); | 170 | virtual void generateImage(); |
158 | virtual void loadJpeg(bool interncall = false); | 171 | virtual void loadJpeg(bool interncall = false); |
159 | bool image_fit_into(const QSize&s); | 172 | bool image_fit_into(const QSize&s); |
160 | void check_zoomer(); | 173 | void check_zoomer(); |
161 | 174 | ||
162 | /* internal bitset manipulation */ | 175 | /* internal bitset manipulation */ |
163 | virtual bool ImageIsJpeg()const; | 176 | virtual bool ImageIsJpeg()const; |
164 | virtual void setImageIsJpeg(bool how); | 177 | virtual void setImageIsJpeg(bool how); |
165 | virtual bool ImageScaledLoaded()const; | 178 | virtual bool ImageScaledLoaded()const; |
166 | virtual void setImageScaledLoaded(bool how); | 179 | virtual void setImageScaledLoaded(bool how); |
167 | virtual bool FirstResizeDone()const; | 180 | virtual bool FirstResizeDone()const; |
168 | virtual void setFirstResizeDone(bool how); | 181 | virtual void setFirstResizeDone(bool how); |
169 | 182 | ||
170 | protected slots: | 183 | protected slots: |
171 | virtual void viewportMouseMoveEvent(QMouseEvent* e); | 184 | virtual void viewportMouseMoveEvent(QMouseEvent* e); |
172 | virtual void contentsMousePressEvent ( QMouseEvent * e); | 185 | virtual void contentsMousePressEvent ( QMouseEvent * e); |
173 | virtual void resizeEvent(QResizeEvent * e); | 186 | virtual void resizeEvent(QResizeEvent * e); |
174 | virtual void keyPressEvent(QKeyEvent * e); | 187 | virtual void keyPressEvent(QKeyEvent * e); |
175 | }; | 188 | }; |
176 | 189 | ||
177 | } | 190 | } |
178 | } | 191 | } |
179 | 192 | ||
180 | #endif | 193 | #endif |