-rw-r--r-- | noncore/graphics/opie-eye/gui/imagescrollview.cpp | 13 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/imagescrollview.h | 2 |
2 files changed, 10 insertions, 5 deletions
diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.cpp b/noncore/graphics/opie-eye/gui/imagescrollview.cpp index ee20f40..99fdc51 100644 --- a/noncore/graphics/opie-eye/gui/imagescrollview.cpp +++ b/noncore/graphics/opie-eye/gui/imagescrollview.cpp | |||
@@ -1,332 +1,337 @@ | |||
1 | #include "imagescrollview.h" | 1 | #include "imagescrollview.h" |
2 | 2 | ||
3 | #include <opie2/odebug.h> | 3 | #include <opie2/odebug.h> |
4 | 4 | ||
5 | using namespace Opie::Core; | 5 | using namespace Opie::Core; |
6 | 6 | ||
7 | #include <qimage.h> | 7 | #include <qimage.h> |
8 | #include <qlayout.h> | 8 | #include <qlayout.h> |
9 | 9 | ||
10 | ImageScrollView::ImageScrollView( QWidget* parent, const char* name, WFlags f ) | 10 | ImageScrollView::ImageScrollView( QWidget* parent, const char* name, WFlags f ) |
11 | :QScrollView(parent,name,f|Qt::WRepaintNoErase ),_image_data(),_original_data(),scale_to_fit(true), | 11 | :QScrollView(parent,name,f|Qt::WRepaintNoErase ),_image_data(),_original_data(),scale_to_fit(true), |
12 | rotate_to_fit(true),first_resize_done(false) | 12 | rotate_to_fit(true),first_resize_done(false),m_lastName("") |
13 | { | 13 | { |
14 | init(); | 14 | init(); |
15 | qDebug("constructor done"); | ||
15 | } | 16 | } |
16 | 17 | ||
17 | ImageScrollView::ImageScrollView (const QImage&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) | 18 | ImageScrollView::ImageScrollView (const QImage&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) |
18 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(img),scale_to_fit(always_scale), | 19 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(img),scale_to_fit(always_scale), |
19 | rotate_to_fit(rfit),first_resize_done(false) | 20 | rotate_to_fit(rfit),first_resize_done(false),m_lastName("") |
20 | { | 21 | { |
21 | init(); | 22 | init(); |
22 | } | 23 | } |
23 | 24 | ||
24 | ImageScrollView::ImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) | 25 | ImageScrollView::ImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) |
25 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(img),scale_to_fit(always_scale), | 26 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(),scale_to_fit(always_scale), |
26 | rotate_to_fit(rfit),first_resize_done(false) | 27 | rotate_to_fit(rfit),first_resize_done(false),m_lastName("") |
27 | { | 28 | { |
28 | init(); | 29 | init(); |
30 | setImage(img); | ||
29 | } | 31 | } |
30 | 32 | ||
31 | void ImageScrollView::setImage(const QImage&img) | 33 | void ImageScrollView::setImage(const QImage&img) |
32 | { | 34 | { |
33 | _image_data = QImage(); | 35 | _image_data = QImage(); |
34 | _original_data=img; | 36 | _original_data=img; |
37 | m_lastName = ""; | ||
35 | if (first_resize_done) { | 38 | if (first_resize_done) { |
36 | generateImage(); | 39 | generateImage(); |
37 | } | 40 | } |
38 | } | 41 | } |
39 | 42 | ||
40 | void ImageScrollView::setImage( const QString& path ) { | 43 | void ImageScrollView::setImage( const QString& path ) { |
41 | odebug << "load new image " << oendl; | 44 | odebug << "load new image " << oendl; |
45 | if (m_lastName == path) return; | ||
46 | m_lastName = path; | ||
42 | _original_data.load(path); | 47 | _original_data.load(path); |
43 | _image_data = QImage(); | 48 | _image_data = QImage(); |
44 | if (first_resize_done) { | 49 | if (first_resize_done) { |
45 | generateImage(); | 50 | generateImage(); |
46 | } | 51 | } |
47 | } | 52 | } |
48 | 53 | ||
49 | /* should be called every time the QImage changed it content */ | 54 | /* should be called every time the QImage changed it content */ |
50 | void ImageScrollView::init() | 55 | void ImageScrollView::init() |
51 | { | 56 | { |
52 | odebug << "init " << oendl; | 57 | odebug << "init " << oendl; |
53 | viewport()->setBackgroundColor(white); | 58 | viewport()->setBackgroundColor(white); |
54 | if (first_resize_done) { | 59 | if (first_resize_done) { |
55 | last_rot = Rotate0; | 60 | last_rot = Rotate0; |
56 | generateImage(); | 61 | generateImage(); |
57 | odebug << "reinit display " << oendl; | 62 | odebug << "reinit display " << oendl; |
58 | } else if (_original_data.size().isValid()) { | 63 | } else if (_original_data.size().isValid()) { |
59 | resizeContents(_original_data.width(),_original_data.height()); | 64 | resizeContents(_original_data.width(),_original_data.height()); |
60 | } | 65 | } |
61 | } | 66 | } |
62 | 67 | ||
63 | void ImageScrollView::setAutoRotate(bool how) | 68 | void ImageScrollView::setAutoRotate(bool how) |
64 | { | 69 | { |
65 | /* to avoid double repaints */ | 70 | /* to avoid double repaints */ |
66 | if (rotate_to_fit != how) { | 71 | if (rotate_to_fit != how) { |
67 | rotate_to_fit = how; | 72 | rotate_to_fit = how; |
68 | _image_data = QImage(); | 73 | _image_data = QImage(); |
69 | generateImage(); | 74 | generateImage(); |
70 | } | 75 | } |
71 | } | 76 | } |
72 | 77 | ||
73 | void ImageScrollView::setAutoScale(bool how) | 78 | void ImageScrollView::setAutoScale(bool how) |
74 | { | 79 | { |
75 | scale_to_fit = how; | 80 | scale_to_fit = how; |
76 | if (!how) { | 81 | if (!how) { |
77 | rotate_to_fit = false; | 82 | rotate_to_fit = false; |
78 | } | 83 | } |
79 | _image_data = QImage(); | 84 | _image_data = QImage(); |
80 | generateImage(); | 85 | generateImage(); |
81 | } | 86 | } |
82 | 87 | ||
83 | ImageScrollView::~ImageScrollView() | 88 | ImageScrollView::~ImageScrollView() |
84 | { | 89 | { |
85 | } | 90 | } |
86 | 91 | ||
87 | void ImageScrollView::rescaleImage(int w, int h) | 92 | void ImageScrollView::rescaleImage(int w, int h) |
88 | { | 93 | { |
89 | if (_image_data.width()==w && _image_data.height()==h) { | 94 | if (_image_data.width()==w && _image_data.height()==h) { |
90 | return; | 95 | return; |
91 | } | 96 | } |
92 | double hs = (double)h / (double)_image_data.height() ; | 97 | double hs = (double)h / (double)_image_data.height() ; |
93 | double ws = (double)w / (double)_image_data.width() ; | 98 | double ws = (double)w / (double)_image_data.width() ; |
94 | double scaleFactor = (hs > ws) ? ws : hs; | 99 | double scaleFactor = (hs > ws) ? ws : hs; |
95 | int smoothW = (int)(scaleFactor * _image_data.width()); | 100 | int smoothW = (int)(scaleFactor * _image_data.width()); |
96 | int smoothH = (int)(scaleFactor * _image_data.height()); | 101 | int smoothH = (int)(scaleFactor * _image_data.height()); |
97 | _image_data = _image_data.smoothScale(smoothW,smoothH); | 102 | _image_data = _image_data.smoothScale(smoothW,smoothH); |
98 | } | 103 | } |
99 | 104 | ||
100 | void ImageScrollView::rotate_into_data(Rotation r) | 105 | void ImageScrollView::rotate_into_data(Rotation r) |
101 | { | 106 | { |
102 | /* realy - we must do this that way, 'cause when acting direct on _image_data the app will | 107 | /* realy - we must do this that way, 'cause when acting direct on _image_data the app will |
103 | segfault :( */ | 108 | segfault :( */ |
104 | QImage dest; | 109 | QImage dest; |
105 | int x, y; | 110 | int x, y; |
106 | if ( _original_data.depth() > 8 ) | 111 | if ( _original_data.depth() > 8 ) |
107 | { | 112 | { |
108 | unsigned int *srcData, *destData; | 113 | unsigned int *srcData, *destData; |
109 | switch ( r ) | 114 | switch ( r ) |
110 | { | 115 | { |
111 | case Rotate90: | 116 | case Rotate90: |
112 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); | 117 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); |
113 | for ( y=0; y < _original_data.height(); ++y ) | 118 | for ( y=0; y < _original_data.height(); ++y ) |
114 | { | 119 | { |
115 | srcData = (unsigned int *)_original_data.scanLine(y); | 120 | srcData = (unsigned int *)_original_data.scanLine(y); |
116 | for ( x=0; x < _original_data.width(); ++x ) | 121 | for ( x=0; x < _original_data.width(); ++x ) |
117 | { | 122 | { |
118 | destData = (unsigned int *)dest.scanLine(x); | 123 | destData = (unsigned int *)dest.scanLine(x); |
119 | destData[_original_data.height()-y-1] = srcData[x]; | 124 | destData[_original_data.height()-y-1] = srcData[x]; |
120 | } | 125 | } |
121 | } | 126 | } |
122 | break; | 127 | break; |
123 | case Rotate180: | 128 | case Rotate180: |
124 | dest.create(_original_data.width(), _original_data.height(), _original_data.depth()); | 129 | dest.create(_original_data.width(), _original_data.height(), _original_data.depth()); |
125 | for ( y=0; y < _original_data.height(); ++y ) | 130 | for ( y=0; y < _original_data.height(); ++y ) |
126 | { | 131 | { |
127 | srcData = (unsigned int *)_original_data.scanLine(y); | 132 | srcData = (unsigned int *)_original_data.scanLine(y); |
128 | destData = (unsigned int *)dest.scanLine(_original_data.height()-y-1); | 133 | destData = (unsigned int *)dest.scanLine(_original_data.height()-y-1); |
129 | for ( x=0; x < _original_data.width(); ++x ) | 134 | for ( x=0; x < _original_data.width(); ++x ) |
130 | destData[_original_data.width()-x-1] = srcData[x]; | 135 | destData[_original_data.width()-x-1] = srcData[x]; |
131 | } | 136 | } |
132 | break; | 137 | break; |
133 | case Rotate270: | 138 | case Rotate270: |
134 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); | 139 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); |
135 | for ( y=0; y < _original_data.height(); ++y ) | 140 | for ( y=0; y < _original_data.height(); ++y ) |
136 | { | 141 | { |
137 | srcData = (unsigned int *)_original_data.scanLine(y); | 142 | srcData = (unsigned int *)_original_data.scanLine(y); |
138 | for ( x=0; x < _original_data.width(); ++x ) | 143 | for ( x=0; x < _original_data.width(); ++x ) |
139 | { | 144 | { |
140 | destData = (unsigned int *)dest.scanLine(_original_data.width()-x-1); | 145 | destData = (unsigned int *)dest.scanLine(_original_data.width()-x-1); |
141 | destData[y] = srcData[x]; | 146 | destData[y] = srcData[x]; |
142 | } | 147 | } |
143 | } | 148 | } |
144 | break; | 149 | break; |
145 | default: | 150 | default: |
146 | dest = _original_data; | 151 | dest = _original_data; |
147 | break; | 152 | break; |
148 | } | 153 | } |
149 | } | 154 | } |
150 | else | 155 | else |
151 | { | 156 | { |
152 | unsigned char *srcData, *destData; | 157 | unsigned char *srcData, *destData; |
153 | unsigned int *srcTable, *destTable; | 158 | unsigned int *srcTable, *destTable; |
154 | switch ( r ) | 159 | switch ( r ) |
155 | { | 160 | { |
156 | case Rotate90: | 161 | case Rotate90: |
157 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); | 162 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); |
158 | dest.setNumColors(_original_data.numColors()); | 163 | dest.setNumColors(_original_data.numColors()); |
159 | srcTable = (unsigned int *)_original_data.colorTable(); | 164 | srcTable = (unsigned int *)_original_data.colorTable(); |
160 | destTable = (unsigned int *)dest.colorTable(); | 165 | destTable = (unsigned int *)dest.colorTable(); |
161 | for ( x=0; x < _original_data.numColors(); ++x ) | 166 | for ( x=0; x < _original_data.numColors(); ++x ) |
162 | destTable[x] = srcTable[x]; | 167 | destTable[x] = srcTable[x]; |
163 | for ( y=0; y < _original_data.height(); ++y ) | 168 | for ( y=0; y < _original_data.height(); ++y ) |
164 | { | 169 | { |
165 | srcData = (unsigned char *)_original_data.scanLine(y); | 170 | srcData = (unsigned char *)_original_data.scanLine(y); |
166 | for ( x=0; x < _original_data.width(); ++x ) | 171 | for ( x=0; x < _original_data.width(); ++x ) |
167 | { | 172 | { |
168 | destData = (unsigned char *)dest.scanLine(x); | 173 | destData = (unsigned char *)dest.scanLine(x); |
169 | destData[_original_data.height()-y-1] = srcData[x]; | 174 | destData[_original_data.height()-y-1] = srcData[x]; |
170 | } | 175 | } |
171 | } | 176 | } |
172 | break; | 177 | break; |
173 | case Rotate180: | 178 | case Rotate180: |
174 | dest.create(_original_data.width(), _original_data.height(), _original_data.depth()); | 179 | dest.create(_original_data.width(), _original_data.height(), _original_data.depth()); |
175 | dest.setNumColors(_original_data.numColors()); | 180 | dest.setNumColors(_original_data.numColors()); |
176 | srcTable = (unsigned int *)_original_data.colorTable(); | 181 | srcTable = (unsigned int *)_original_data.colorTable(); |
177 | destTable = (unsigned int *)dest.colorTable(); | 182 | destTable = (unsigned int *)dest.colorTable(); |
178 | for ( x=0; x < _original_data.numColors(); ++x ) | 183 | for ( x=0; x < _original_data.numColors(); ++x ) |
179 | destTable[x] = srcTable[x]; | 184 | destTable[x] = srcTable[x]; |
180 | for ( y=0; y < _original_data.height(); ++y ) | 185 | for ( y=0; y < _original_data.height(); ++y ) |
181 | { | 186 | { |
182 | srcData = (unsigned char *)_original_data.scanLine(y); | 187 | srcData = (unsigned char *)_original_data.scanLine(y); |
183 | destData = (unsigned char *)dest.scanLine(_original_data.height()-y-1); | 188 | destData = (unsigned char *)dest.scanLine(_original_data.height()-y-1); |
184 | for ( x=0; x < _original_data.width(); ++x ) | 189 | for ( x=0; x < _original_data.width(); ++x ) |
185 | destData[_original_data.width()-x-1] = srcData[x]; | 190 | destData[_original_data.width()-x-1] = srcData[x]; |
186 | } | 191 | } |
187 | break; | 192 | break; |
188 | case Rotate270: | 193 | case Rotate270: |
189 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); | 194 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); |
190 | dest.setNumColors(_original_data.numColors()); | 195 | dest.setNumColors(_original_data.numColors()); |
191 | srcTable = (unsigned int *)_original_data.colorTable(); | 196 | srcTable = (unsigned int *)_original_data.colorTable(); |
192 | destTable = (unsigned int *)dest.colorTable(); | 197 | destTable = (unsigned int *)dest.colorTable(); |
193 | for ( x=0; x < _original_data.numColors(); ++x ) | 198 | for ( x=0; x < _original_data.numColors(); ++x ) |
194 | destTable[x] = srcTable[x]; | 199 | destTable[x] = srcTable[x]; |
195 | for ( y=0; y < _original_data.height(); ++y ) | 200 | for ( y=0; y < _original_data.height(); ++y ) |
196 | { | 201 | { |
197 | srcData = (unsigned char *)_original_data.scanLine(y); | 202 | srcData = (unsigned char *)_original_data.scanLine(y); |
198 | for ( x=0; x < _original_data.width(); ++x ) | 203 | for ( x=0; x < _original_data.width(); ++x ) |
199 | { | 204 | { |
200 | destData = (unsigned char *)dest.scanLine(_original_data.width()-x-1); | 205 | destData = (unsigned char *)dest.scanLine(_original_data.width()-x-1); |
201 | destData[y] = srcData[x]; | 206 | destData[y] = srcData[x]; |
202 | } | 207 | } |
203 | } | 208 | } |
204 | break; | 209 | break; |
205 | default: | 210 | default: |
206 | dest = _original_data; | 211 | dest = _original_data; |
207 | break; | 212 | break; |
208 | } | 213 | } |
209 | 214 | ||
210 | } | 215 | } |
211 | _image_data = dest; | 216 | _image_data = dest; |
212 | } | 217 | } |
213 | 218 | ||
214 | void ImageScrollView::generateImage() | 219 | void ImageScrollView::generateImage() |
215 | { | 220 | { |
216 | Rotation r = Rotate0; | 221 | Rotation r = Rotate0; |
217 | if (width()>height()&&_original_data.width()<_original_data.height() || | 222 | if (width()>height()&&_original_data.width()<_original_data.height() || |
218 | width()<height()&&_original_data.width()>_original_data.height()) { | 223 | width()<height()&&_original_data.width()>_original_data.height()) { |
219 | if (rotate_to_fit) r = Rotate90; | 224 | if (rotate_to_fit) r = Rotate90; |
220 | } | 225 | } |
221 | odebug << " r = " << r << oendl; | 226 | odebug << " r = " << r << oendl; |
222 | if (scale_to_fit) { | 227 | if (scale_to_fit) { |
223 | if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) { | 228 | if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) { |
224 | odebug << "Rescaling data" << oendl; | 229 | odebug << "Rescaling data" << oendl; |
225 | if (r==Rotate0) { | 230 | if (r==Rotate0) { |
226 | _image_data = _original_data; | 231 | _image_data = _original_data; |
227 | } else { | 232 | } else { |
228 | rotate_into_data(r); | 233 | rotate_into_data(r); |
229 | } | 234 | } |
230 | } | 235 | } |
231 | rescaleImage(width(),height()); | 236 | rescaleImage(width(),height()); |
232 | resizeContents(_image_data.width(),_image_data.height()); | 237 | resizeContents(_image_data.width(),_image_data.height()); |
233 | } else if (!first_resize_done||r!=last_rot||_image_data.width()==0) { | 238 | } else if (!first_resize_done||r!=last_rot||_image_data.width()==0) { |
234 | if (r==Rotate0) { | 239 | if (r==Rotate0) { |
235 | _image_data = _original_data; | 240 | _image_data = _original_data; |
236 | } else { | 241 | } else { |
237 | rotate_into_data(r); | 242 | rotate_into_data(r); |
238 | } | 243 | } |
239 | last_rot = r; | 244 | last_rot = r; |
240 | resizeContents(_image_data.width(),_image_data.height()); | 245 | resizeContents(_image_data.width(),_image_data.height()); |
241 | } | 246 | } |
242 | } | 247 | } |
243 | 248 | ||
244 | void ImageScrollView::resizeEvent(QResizeEvent * e) | 249 | void ImageScrollView::resizeEvent(QResizeEvent * e) |
245 | { | 250 | { |
246 | odebug << "ImageScrollView resizeEvent" << oendl; | 251 | odebug << "ImageScrollView resizeEvent" << oendl; |
247 | QScrollView::resizeEvent(e); | 252 | QScrollView::resizeEvent(e); |
248 | generateImage(); | 253 | generateImage(); |
249 | first_resize_done = true; | 254 | first_resize_done = true; |
250 | } | 255 | } |
251 | 256 | ||
252 | void ImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph) | 257 | void ImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph) |
253 | { | 258 | { |
254 | int w = clipw; | 259 | int w = clipw; |
255 | int h = cliph; | 260 | int h = cliph; |
256 | int x = clipx; | 261 | int x = clipx; |
257 | int y = clipy; | 262 | int y = clipy; |
258 | bool erase = false; | 263 | bool erase = false; |
259 | 264 | ||
260 | if (!_image_data.size().isValid()) { | 265 | if (!_image_data.size().isValid()) { |
261 | p->fillRect(clipx,clipy,clipw,cliph,white); | 266 | p->fillRect(clipx,clipy,clipw,cliph,white); |
262 | return; | 267 | return; |
263 | } | 268 | } |
264 | if (w>_image_data.width()) { | 269 | if (w>_image_data.width()) { |
265 | w=_image_data.width(); | 270 | w=_image_data.width(); |
266 | x = 0; | 271 | x = 0; |
267 | erase = true; | 272 | erase = true; |
268 | } else if (x+w>_image_data.width()){ | 273 | } else if (x+w>_image_data.width()){ |
269 | x = _image_data.width()-w; | 274 | x = _image_data.width()-w; |
270 | } | 275 | } |
271 | if (h>_image_data.height()) { | 276 | if (h>_image_data.height()) { |
272 | h=_image_data.height(); | 277 | h=_image_data.height(); |
273 | y = 0; | 278 | y = 0; |
274 | erase = true; | 279 | erase = true; |
275 | } else if (y+h>_image_data.height()){ | 280 | } else if (y+h>_image_data.height()){ |
276 | y = _image_data.height()-h; | 281 | y = _image_data.height()-h; |
277 | } | 282 | } |
278 | if (erase||_image_data.hasAlphaBuffer()) { | 283 | if (erase||_image_data.hasAlphaBuffer()) { |
279 | p->fillRect(clipx,clipy,clipw,cliph,white); | 284 | p->fillRect(clipx,clipy,clipw,cliph,white); |
280 | } | 285 | } |
281 | p->drawImage(clipx,clipy,_image_data,x,y,w,h); | 286 | p->drawImage(clipx,clipy,_image_data,x,y,w,h); |
282 | } | 287 | } |
283 | 288 | ||
284 | /* using the real geometry points and not the translated points is wanted! */ | 289 | /* using the real geometry points and not the translated points is wanted! */ |
285 | void ImageScrollView::viewportMouseMoveEvent(QMouseEvent* e) | 290 | void ImageScrollView::viewportMouseMoveEvent(QMouseEvent* e) |
286 | { | 291 | { |
287 | int mx, my; | 292 | int mx, my; |
288 | mx = e->x(); | 293 | mx = e->x(); |
289 | my = e->y(); | 294 | my = e->y(); |
290 | int diffx = _mouseStartPosX-mx; | 295 | int diffx = _mouseStartPosX-mx; |
291 | int diffy = _mouseStartPosY-my; | 296 | int diffy = _mouseStartPosY-my; |
292 | scrollBy(diffx,diffy); | 297 | scrollBy(diffx,diffy); |
293 | _mouseStartPosX=mx; | 298 | _mouseStartPosX=mx; |
294 | _mouseStartPosY=my; | 299 | _mouseStartPosY=my; |
295 | } | 300 | } |
296 | 301 | ||
297 | void ImageScrollView::contentsMouseReleaseEvent ( QMouseEvent * e) | 302 | void ImageScrollView::contentsMouseReleaseEvent ( QMouseEvent * e) |
298 | { | 303 | { |
299 | _mouseStartPosX = e->x(); | 304 | _mouseStartPosX = e->x(); |
300 | _mouseStartPosY = e->y(); | 305 | _mouseStartPosY = e->y(); |
301 | } | 306 | } |
302 | 307 | ||
303 | void ImageScrollView::contentsMousePressEvent ( QMouseEvent * e) | 308 | void ImageScrollView::contentsMousePressEvent ( QMouseEvent * e) |
304 | { | 309 | { |
305 | _mouseStartPosX = e->x(); | 310 | _mouseStartPosX = e->x(); |
306 | _mouseStartPosY = e->y(); | 311 | _mouseStartPosY = e->y(); |
307 | } | 312 | } |
308 | 313 | ||
309 | void ImageScrollView::setDestructiveClose() { | 314 | void ImageScrollView::setDestructiveClose() { |
310 | WFlags fl = getWFlags(); | 315 | WFlags fl = getWFlags(); |
311 | /* clear it just in case */ | 316 | /* clear it just in case */ |
312 | fl &= ~WDestructiveClose; | 317 | fl &= ~WDestructiveClose; |
313 | fl |= WDestructiveClose; | 318 | fl |= WDestructiveClose; |
314 | setWFlags( fl ); | 319 | setWFlags( fl ); |
315 | } | 320 | } |
316 | 321 | ||
317 | 322 | ||
318 | /* for testing */ | 323 | /* for testing */ |
319 | ImageDlg::ImageDlg(const QString&fname,QWidget * parent, const char * name) | 324 | ImageDlg::ImageDlg(const QString&fname,QWidget * parent, const char * name) |
320 | :QDialog(parent,name,true,WStyle_ContextHelp) | 325 | :QDialog(parent,name,true,WStyle_ContextHelp) |
321 | { | 326 | { |
322 | QVBoxLayout*dlglayout = new QVBoxLayout(this); | 327 | QVBoxLayout*dlglayout = new QVBoxLayout(this); |
323 | dlglayout->setSpacing(2); | 328 | dlglayout->setSpacing(2); |
324 | dlglayout->setMargin(1); | 329 | dlglayout->setMargin(1); |
325 | ImageScrollView*inf = new ImageScrollView(fname,this); | 330 | ImageScrollView*inf = new ImageScrollView(fname,this); |
326 | dlglayout->addWidget(inf); | 331 | dlglayout->addWidget(inf); |
327 | odebug << "Imagedlg constructor end" << oendl; | 332 | odebug << "Imagedlg constructor end" << oendl; |
328 | } | 333 | } |
329 | 334 | ||
330 | ImageDlg::~ImageDlg() | 335 | ImageDlg::~ImageDlg() |
331 | { | 336 | { |
332 | } | 337 | } |
diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.h b/noncore/graphics/opie-eye/gui/imagescrollview.h index dcf54ce..44f2a64 100644 --- a/noncore/graphics/opie-eye/gui/imagescrollview.h +++ b/noncore/graphics/opie-eye/gui/imagescrollview.h | |||
@@ -1,72 +1,72 @@ | |||
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 <qstring.h> | 6 | #include <qstring.h> |
7 | #include <qdialog.h> | 7 | #include <qdialog.h> |
8 | 8 | ||
9 | class QPainter; | 9 | class QPainter; |
10 | 10 | ||
11 | class ImageScrollView:public QScrollView | 11 | class ImageScrollView:public QScrollView |
12 | { | 12 | { |
13 | Q_OBJECT | 13 | Q_OBJECT |
14 | public: | 14 | public: |
15 | ImageScrollView( QWidget* parent, const char* name = 0, WFlags fl = 0 ); | 15 | ImageScrollView( QWidget* parent, const char* name = 0, WFlags fl = 0 ); |
16 | ImageScrollView (const QImage&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false ); | 16 | ImageScrollView (const QImage&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false ); |
17 | ImageScrollView (const QString&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false ); | 17 | ImageScrollView (const QString&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false ); |
18 | virtual ~ImageScrollView(); | 18 | virtual ~ImageScrollView(); |
19 | 19 | ||
20 | void setImage(const QImage&); | 20 | void setImage(const QImage&); |
21 | void setImage( const QString& path ); | 21 | void setImage( const QString& path ); |
22 | void setDestructiveClose(); | 22 | void setDestructiveClose(); |
23 | 23 | ||
24 | void setAutoRotate(bool); | 24 | void setAutoRotate(bool); |
25 | void setAutoScale(bool); | 25 | void setAutoScale(bool); |
26 | 26 | ||
27 | enum Rotation { | 27 | enum Rotation { |
28 | Rotate0, | 28 | Rotate0, |
29 | Rotate90, | 29 | Rotate90, |
30 | Rotate180, | 30 | Rotate180, |
31 | Rotate270 | 31 | Rotate270 |
32 | }; | 32 | }; |
33 | 33 | ||
34 | signals: | 34 | signals: |
35 | void sig_return(); | 35 | void sig_return(); |
36 | 36 | ||
37 | protected: | 37 | protected: |
38 | virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph ); | 38 | virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph ); |
39 | void init(); | 39 | void init(); |
40 | 40 | ||
41 | QImage _image_data; | 41 | QImage _image_data; |
42 | QImage _original_data; | 42 | QImage _original_data; |
43 | 43 | ||
44 | int _mouseStartPosX,_mouseStartPosY; | 44 | int _mouseStartPosX,_mouseStartPosY; |
45 | 45 | ||
46 | bool scale_to_fit; | 46 | bool scale_to_fit; |
47 | bool rotate_to_fit; | 47 | bool rotate_to_fit; |
48 | bool first_resize_done; | 48 | bool first_resize_done; |
49 | Rotation last_rot; | 49 | Rotation last_rot; |
50 | 50 | QString m_lastName; | |
51 | void rescaleImage(int w, int h); | 51 | void rescaleImage(int w, int h); |
52 | 52 | ||
53 | void rotate_into_data(Rotation r); | 53 | void rotate_into_data(Rotation r); |
54 | void generateImage(); | 54 | void generateImage(); |
55 | 55 | ||
56 | protected slots: | 56 | protected slots: |
57 | virtual void viewportMouseMoveEvent(QMouseEvent* e); | 57 | virtual void viewportMouseMoveEvent(QMouseEvent* e); |
58 | virtual void contentsMousePressEvent ( QMouseEvent * e); | 58 | virtual void contentsMousePressEvent ( QMouseEvent * e); |
59 | virtual void contentsMouseReleaseEvent ( QMouseEvent * e); | 59 | virtual void contentsMouseReleaseEvent ( QMouseEvent * e); |
60 | virtual void resizeEvent(QResizeEvent * e); | 60 | virtual void resizeEvent(QResizeEvent * e); |
61 | }; | 61 | }; |
62 | 62 | ||
63 | /* for testing */ | 63 | /* for testing */ |
64 | class ImageDlg:public QDialog | 64 | class ImageDlg:public QDialog |
65 | { | 65 | { |
66 | Q_OBJECT | 66 | Q_OBJECT |
67 | public: | 67 | public: |
68 | ImageDlg(const QString&,QWidget * parent=0, const char * name=0); | 68 | ImageDlg(const QString&,QWidget * parent=0, const char * name=0); |
69 | virtual ~ImageDlg(); | 69 | virtual ~ImageDlg(); |
70 | }; | 70 | }; |
71 | 71 | ||
72 | #endif | 72 | #endif |