author | alwin <alwin> | 2004-04-06 23:54:50 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-04-06 23:54:50 (UTC) |
commit | 1b7aaf904fa70c16eee03155bd826e921798cc22 (patch) (unidiff) | |
tree | da95ac3da9717101bfdc685e59a12a1e331f9ec0 | |
parent | 5cab9e2717383faaebb44cbb57df5badc3056206 (diff) | |
download | opie-1b7aaf904fa70c16eee03155bd826e921798cc22.zip opie-1b7aaf904fa70c16eee03155bd826e921798cc22.tar.gz opie-1b7aaf904fa70c16eee03155bd826e921798cc22.tar.bz2 |
fixed mousescroll handling so users kann move image with mouse/pen
implement key handler for arrow keys
-rw-r--r-- | noncore/graphics/opie-eye/gui/imagescrollview.cpp | 81 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/imagescrollview.h | 28 |
2 files changed, 60 insertions, 49 deletions
diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.cpp b/noncore/graphics/opie-eye/gui/imagescrollview.cpp index 99fdc51..98054ff 100644 --- a/noncore/graphics/opie-eye/gui/imagescrollview.cpp +++ b/noncore/graphics/opie-eye/gui/imagescrollview.cpp | |||
@@ -1,337 +1,358 @@ | |||
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),m_lastName("") | 12 | rotate_to_fit(true),first_resize_done(false),m_lastName("") |
13 | { | 13 | { |
14 | init(); | 14 | init(); |
15 | qDebug("constructor done"); | ||
16 | } | 15 | } |
17 | 16 | ||
18 | ImageScrollView::ImageScrollView (const QImage&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) | 17 | ImageScrollView::ImageScrollView (const QImage&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) |
19 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(img),scale_to_fit(always_scale), | 18 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(img),scale_to_fit(always_scale), |
20 | rotate_to_fit(rfit),first_resize_done(false),m_lastName("") | 19 | rotate_to_fit(rfit),first_resize_done(false),m_lastName("") |
21 | { | 20 | { |
22 | init(); | 21 | init(); |
23 | } | 22 | } |
24 | 23 | ||
25 | ImageScrollView::ImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) | 24 | ImageScrollView::ImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) |
26 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(),scale_to_fit(always_scale), | 25 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(),scale_to_fit(always_scale), |
27 | rotate_to_fit(rfit),first_resize_done(false),m_lastName("") | 26 | rotate_to_fit(rfit),first_resize_done(false),m_lastName("") |
28 | { | 27 | { |
29 | init(); | 28 | init(); |
30 | setImage(img); | 29 | setImage(img); |
31 | } | 30 | } |
32 | 31 | ||
33 | void ImageScrollView::setImage(const QImage&img) | 32 | void ImageScrollView::setImage(const QImage&img) |
34 | { | 33 | { |
35 | _image_data = QImage(); | 34 | _image_data = QImage(); |
36 | _original_data=img; | 35 | _original_data=img; |
37 | m_lastName = ""; | 36 | m_lastName = ""; |
38 | if (first_resize_done) { | 37 | if (first_resize_done) { |
39 | generateImage(); | 38 | generateImage(); |
40 | } | 39 | } |
41 | } | 40 | } |
42 | 41 | ||
43 | void ImageScrollView::setImage( const QString& path ) { | 42 | void ImageScrollView::setImage( const QString& path ) { |
44 | odebug << "load new image " << oendl; | 43 | odebug << "load new image " << oendl; |
45 | if (m_lastName == path) return; | 44 | if (m_lastName == path) return; |
46 | m_lastName = path; | 45 | m_lastName = path; |
47 | _original_data.load(path); | 46 | _original_data.load(path); |
48 | _image_data = QImage(); | 47 | _image_data = QImage(); |
49 | if (first_resize_done) { | 48 | if (first_resize_done) { |
50 | generateImage(); | 49 | generateImage(); |
51 | } | 50 | } |
52 | } | 51 | } |
53 | 52 | ||
54 | /* should be called every time the QImage changed it content */ | 53 | /* should be called every time the QImage changed it content */ |
55 | void ImageScrollView::init() | 54 | void ImageScrollView::init() |
56 | { | 55 | { |
57 | odebug << "init " << oendl; | 56 | odebug << "init " << oendl; |
58 | viewport()->setBackgroundColor(white); | 57 | viewport()->setBackgroundColor(white); |
58 | setFocusPolicy(QWidget::StrongFocus); | ||
59 | if (first_resize_done) { | 59 | if (first_resize_done) { |
60 | last_rot = Rotate0; | 60 | last_rot = Rotate0; |
61 | generateImage(); | 61 | generateImage(); |
62 | odebug << "reinit display " << oendl; | 62 | odebug << "reinit display " << oendl; |
63 | } else if (_original_data.size().isValid()) { | 63 | } else if (_original_data.size().isValid()) { |
64 | resizeContents(_original_data.width(),_original_data.height()); | 64 | resizeContents(_original_data.width(),_original_data.height()); |
65 | } | 65 | } |
66 | } | 66 | } |
67 | 67 | ||
68 | void ImageScrollView::setAutoRotate(bool how) | 68 | void ImageScrollView::setAutoRotate(bool how) |
69 | { | 69 | { |
70 | /* to avoid double repaints */ | 70 | /* to avoid double repaints */ |
71 | if (rotate_to_fit != how) { | 71 | if (rotate_to_fit != how) { |
72 | rotate_to_fit = how; | 72 | rotate_to_fit = how; |
73 | _image_data = QImage(); | 73 | _image_data = QImage(); |
74 | generateImage(); | 74 | generateImage(); |
75 | } | 75 | } |
76 | } | 76 | } |
77 | 77 | ||
78 | void ImageScrollView::setAutoScale(bool how) | 78 | void ImageScrollView::setAutoScale(bool how) |
79 | { | 79 | { |
80 | scale_to_fit = how; | 80 | scale_to_fit = how; |
81 | if (!how) { | 81 | if (!how) { |
82 | rotate_to_fit = false; | 82 | rotate_to_fit = false; |
83 | } | 83 | } |
84 | _image_data = QImage(); | 84 | _image_data = QImage(); |
85 | generateImage(); | 85 | generateImage(); |
86 | } | 86 | } |
87 | 87 | ||
88 | ImageScrollView::~ImageScrollView() | 88 | ImageScrollView::~ImageScrollView() |
89 | { | 89 | { |
90 | } | 90 | } |
91 | 91 | ||
92 | void ImageScrollView::rescaleImage(int w, int h) | 92 | void ImageScrollView::rescaleImage(int w, int h) |
93 | { | 93 | { |
94 | if (_image_data.width()==w && _image_data.height()==h) { | 94 | if (_image_data.width()==w && _image_data.height()==h) { |
95 | return; | 95 | return; |
96 | } | 96 | } |
97 | double hs = (double)h / (double)_image_data.height() ; | 97 | double hs = (double)h / (double)_image_data.height() ; |
98 | double ws = (double)w / (double)_image_data.width() ; | 98 | double ws = (double)w / (double)_image_data.width() ; |
99 | double scaleFactor = (hs > ws) ? ws : hs; | 99 | double scaleFactor = (hs > ws) ? ws : hs; |
100 | int smoothW = (int)(scaleFactor * _image_data.width()); | 100 | int smoothW = (int)(scaleFactor * _image_data.width()); |
101 | int smoothH = (int)(scaleFactor * _image_data.height()); | 101 | int smoothH = (int)(scaleFactor * _image_data.height()); |
102 | _image_data = _image_data.smoothScale(smoothW,smoothH); | 102 | _image_data = _image_data.smoothScale(smoothW,smoothH); |
103 | } | 103 | } |
104 | 104 | ||
105 | void ImageScrollView::rotate_into_data(Rotation r) | 105 | void ImageScrollView::rotate_into_data(Rotation r) |
106 | { | 106 | { |
107 | /* 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 |
108 | segfault :( */ | 108 | segfault :( */ |
109 | QImage dest; | 109 | QImage dest; |
110 | int x, y; | 110 | int x, y; |
111 | if ( _original_data.depth() > 8 ) | 111 | if ( _original_data.depth() > 8 ) |
112 | { | 112 | { |
113 | unsigned int *srcData, *destData; | 113 | unsigned int *srcData, *destData; |
114 | switch ( r ) | 114 | switch ( r ) |
115 | { | 115 | { |
116 | case Rotate90: | 116 | case Rotate90: |
117 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); | 117 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); |
118 | for ( y=0; y < _original_data.height(); ++y ) | 118 | for ( y=0; y < _original_data.height(); ++y ) |
119 | { | 119 | { |
120 | srcData = (unsigned int *)_original_data.scanLine(y); | 120 | srcData = (unsigned int *)_original_data.scanLine(y); |
121 | for ( x=0; x < _original_data.width(); ++x ) | 121 | for ( x=0; x < _original_data.width(); ++x ) |
122 | { | 122 | { |
123 | destData = (unsigned int *)dest.scanLine(x); | 123 | destData = (unsigned int *)dest.scanLine(x); |
124 | destData[_original_data.height()-y-1] = srcData[x]; | 124 | destData[_original_data.height()-y-1] = srcData[x]; |
125 | } | 125 | } |
126 | } | 126 | } |
127 | break; | 127 | break; |
128 | case Rotate180: | 128 | case Rotate180: |
129 | dest.create(_original_data.width(), _original_data.height(), _original_data.depth()); | 129 | dest.create(_original_data.width(), _original_data.height(), _original_data.depth()); |
130 | for ( y=0; y < _original_data.height(); ++y ) | 130 | for ( y=0; y < _original_data.height(); ++y ) |
131 | { | 131 | { |
132 | srcData = (unsigned int *)_original_data.scanLine(y); | 132 | srcData = (unsigned int *)_original_data.scanLine(y); |
133 | destData = (unsigned int *)dest.scanLine(_original_data.height()-y-1); | 133 | destData = (unsigned int *)dest.scanLine(_original_data.height()-y-1); |
134 | for ( x=0; x < _original_data.width(); ++x ) | 134 | for ( x=0; x < _original_data.width(); ++x ) |
135 | destData[_original_data.width()-x-1] = srcData[x]; | 135 | destData[_original_data.width()-x-1] = srcData[x]; |
136 | } | 136 | } |
137 | break; | 137 | break; |
138 | case Rotate270: | 138 | case Rotate270: |
139 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); | 139 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); |
140 | for ( y=0; y < _original_data.height(); ++y ) | 140 | for ( y=0; y < _original_data.height(); ++y ) |
141 | { | 141 | { |
142 | srcData = (unsigned int *)_original_data.scanLine(y); | 142 | srcData = (unsigned int *)_original_data.scanLine(y); |
143 | for ( x=0; x < _original_data.width(); ++x ) | 143 | for ( x=0; x < _original_data.width(); ++x ) |
144 | { | 144 | { |
145 | destData = (unsigned int *)dest.scanLine(_original_data.width()-x-1); | 145 | destData = (unsigned int *)dest.scanLine(_original_data.width()-x-1); |
146 | destData[y] = srcData[x]; | 146 | destData[y] = srcData[x]; |
147 | } | 147 | } |
148 | } | 148 | } |
149 | break; | 149 | break; |
150 | default: | 150 | default: |
151 | dest = _original_data; | 151 | dest = _original_data; |
152 | break; | 152 | break; |
153 | } | 153 | } |
154 | } | 154 | } |
155 | else | 155 | else |
156 | { | 156 | { |
157 | unsigned char *srcData, *destData; | 157 | unsigned char *srcData, *destData; |
158 | unsigned int *srcTable, *destTable; | 158 | unsigned int *srcTable, *destTable; |
159 | switch ( r ) | 159 | switch ( r ) |
160 | { | 160 | { |
161 | case Rotate90: | 161 | case Rotate90: |
162 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); | 162 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); |
163 | dest.setNumColors(_original_data.numColors()); | 163 | dest.setNumColors(_original_data.numColors()); |
164 | srcTable = (unsigned int *)_original_data.colorTable(); | 164 | srcTable = (unsigned int *)_original_data.colorTable(); |
165 | destTable = (unsigned int *)dest.colorTable(); | 165 | destTable = (unsigned int *)dest.colorTable(); |
166 | for ( x=0; x < _original_data.numColors(); ++x ) | 166 | for ( x=0; x < _original_data.numColors(); ++x ) |
167 | destTable[x] = srcTable[x]; | 167 | destTable[x] = srcTable[x]; |
168 | for ( y=0; y < _original_data.height(); ++y ) | 168 | for ( y=0; y < _original_data.height(); ++y ) |
169 | { | 169 | { |
170 | srcData = (unsigned char *)_original_data.scanLine(y); | 170 | srcData = (unsigned char *)_original_data.scanLine(y); |
171 | for ( x=0; x < _original_data.width(); ++x ) | 171 | for ( x=0; x < _original_data.width(); ++x ) |
172 | { | 172 | { |
173 | destData = (unsigned char *)dest.scanLine(x); | 173 | destData = (unsigned char *)dest.scanLine(x); |
174 | destData[_original_data.height()-y-1] = srcData[x]; | 174 | destData[_original_data.height()-y-1] = srcData[x]; |
175 | } | 175 | } |
176 | } | 176 | } |
177 | break; | 177 | break; |
178 | case Rotate180: | 178 | case Rotate180: |
179 | dest.create(_original_data.width(), _original_data.height(), _original_data.depth()); | 179 | dest.create(_original_data.width(), _original_data.height(), _original_data.depth()); |
180 | dest.setNumColors(_original_data.numColors()); | 180 | dest.setNumColors(_original_data.numColors()); |
181 | srcTable = (unsigned int *)_original_data.colorTable(); | 181 | srcTable = (unsigned int *)_original_data.colorTable(); |
182 | destTable = (unsigned int *)dest.colorTable(); | 182 | destTable = (unsigned int *)dest.colorTable(); |
183 | for ( x=0; x < _original_data.numColors(); ++x ) | 183 | for ( x=0; x < _original_data.numColors(); ++x ) |
184 | destTable[x] = srcTable[x]; | 184 | destTable[x] = srcTable[x]; |
185 | for ( y=0; y < _original_data.height(); ++y ) | 185 | for ( y=0; y < _original_data.height(); ++y ) |
186 | { | 186 | { |
187 | srcData = (unsigned char *)_original_data.scanLine(y); | 187 | srcData = (unsigned char *)_original_data.scanLine(y); |
188 | destData = (unsigned char *)dest.scanLine(_original_data.height()-y-1); | 188 | destData = (unsigned char *)dest.scanLine(_original_data.height()-y-1); |
189 | for ( x=0; x < _original_data.width(); ++x ) | 189 | for ( x=0; x < _original_data.width(); ++x ) |
190 | destData[_original_data.width()-x-1] = srcData[x]; | 190 | destData[_original_data.width()-x-1] = srcData[x]; |
191 | } | 191 | } |
192 | break; | 192 | break; |
193 | case Rotate270: | 193 | case Rotate270: |
194 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); | 194 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); |
195 | dest.setNumColors(_original_data.numColors()); | 195 | dest.setNumColors(_original_data.numColors()); |
196 | srcTable = (unsigned int *)_original_data.colorTable(); | 196 | srcTable = (unsigned int *)_original_data.colorTable(); |
197 | destTable = (unsigned int *)dest.colorTable(); | 197 | destTable = (unsigned int *)dest.colorTable(); |
198 | for ( x=0; x < _original_data.numColors(); ++x ) | 198 | for ( x=0; x < _original_data.numColors(); ++x ) |
199 | destTable[x] = srcTable[x]; | 199 | destTable[x] = srcTable[x]; |
200 | for ( y=0; y < _original_data.height(); ++y ) | 200 | for ( y=0; y < _original_data.height(); ++y ) |
201 | { | 201 | { |
202 | srcData = (unsigned char *)_original_data.scanLine(y); | 202 | srcData = (unsigned char *)_original_data.scanLine(y); |
203 | for ( x=0; x < _original_data.width(); ++x ) | 203 | for ( x=0; x < _original_data.width(); ++x ) |
204 | { | 204 | { |
205 | destData = (unsigned char *)dest.scanLine(_original_data.width()-x-1); | 205 | destData = (unsigned char *)dest.scanLine(_original_data.width()-x-1); |
206 | destData[y] = srcData[x]; | 206 | destData[y] = srcData[x]; |
207 | } | 207 | } |
208 | } | 208 | } |
209 | break; | 209 | break; |
210 | default: | 210 | default: |
211 | dest = _original_data; | 211 | dest = _original_data; |
212 | break; | 212 | break; |
213 | } | 213 | } |
214 | 214 | ||
215 | } | 215 | } |
216 | _image_data = dest; | 216 | _image_data = dest; |
217 | } | 217 | } |
218 | 218 | ||
219 | void ImageScrollView::generateImage() | 219 | void ImageScrollView::generateImage() |
220 | { | 220 | { |
221 | Rotation r = Rotate0; | 221 | Rotation r = Rotate0; |
222 | if (width()>height()&&_original_data.width()<_original_data.height() || | 222 | if (width()>height()&&_original_data.width()<_original_data.height() || |
223 | width()<height()&&_original_data.width()>_original_data.height()) { | 223 | width()<height()&&_original_data.width()>_original_data.height()) { |
224 | if (rotate_to_fit) r = Rotate90; | 224 | if (rotate_to_fit) r = Rotate90; |
225 | } | 225 | } |
226 | odebug << " r = " << r << oendl; | 226 | odebug << " r = " << r << oendl; |
227 | if (scale_to_fit) { | 227 | if (scale_to_fit) { |
228 | 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()) { |
229 | odebug << "Rescaling data" << oendl; | 229 | odebug << "Rescaling data" << oendl; |
230 | if (r==Rotate0) { | 230 | if (r==Rotate0) { |
231 | _image_data = _original_data; | 231 | _image_data = _original_data; |
232 | } else { | 232 | } else { |
233 | rotate_into_data(r); | 233 | rotate_into_data(r); |
234 | } | 234 | } |
235 | } | 235 | } |
236 | rescaleImage(width(),height()); | 236 | rescaleImage(width(),height()); |
237 | resizeContents(_image_data.width(),_image_data.height()); | 237 | resizeContents(_image_data.width(),_image_data.height()); |
238 | } 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) { |
239 | if (r==Rotate0) { | 239 | if (r==Rotate0) { |
240 | _image_data = _original_data; | 240 | _image_data = _original_data; |
241 | } else { | 241 | } else { |
242 | rotate_into_data(r); | 242 | rotate_into_data(r); |
243 | } | 243 | } |
244 | last_rot = r; | 244 | last_rot = r; |
245 | resizeContents(_image_data.width(),_image_data.height()); | 245 | resizeContents(_image_data.width(),_image_data.height()); |
246 | } | 246 | } |
247 | } | 247 | } |
248 | 248 | ||
249 | void ImageScrollView::resizeEvent(QResizeEvent * e) | 249 | void ImageScrollView::resizeEvent(QResizeEvent * e) |
250 | { | 250 | { |
251 | odebug << "ImageScrollView resizeEvent" << oendl; | 251 | odebug << "ImageScrollView resizeEvent" << oendl; |
252 | QScrollView::resizeEvent(e); | 252 | QScrollView::resizeEvent(e); |
253 | generateImage(); | 253 | generateImage(); |
254 | first_resize_done = true; | 254 | first_resize_done = true; |
255 | } | 255 | } |
256 | 256 | ||
257 | void ImageScrollView::keyPressEvent(QKeyEvent * e) | ||
258 | { | ||
259 | if (!e) return; | ||
260 | int dx = horizontalScrollBar()->lineStep(); | ||
261 | int dy = verticalScrollBar()->lineStep(); | ||
262 | if (e->key()==Qt::Key_Right) { | ||
263 | scrollBy(dx,0); | ||
264 | e->accept(); | ||
265 | } else if (e->key()==Qt::Key_Left) { | ||
266 | scrollBy(0-dx,0); | ||
267 | e->accept(); | ||
268 | } else if (e->key()==Qt::Key_Up) { | ||
269 | scrollBy(0,0-dy); | ||
270 | e->accept(); | ||
271 | } else if (e->key()==Qt::Key_Down) { | ||
272 | scrollBy(0,dy); | ||
273 | e->accept(); | ||
274 | } else { | ||
275 | e->ignore(); | ||
276 | } | ||
277 | QScrollView::keyPressEvent(e); | ||
278 | } | ||
279 | |||
257 | void ImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph) | 280 | void ImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph) |
258 | { | 281 | { |
259 | int w = clipw; | 282 | int w = clipw; |
260 | int h = cliph; | 283 | int h = cliph; |
261 | int x = clipx; | 284 | int x = clipx; |
262 | int y = clipy; | 285 | int y = clipy; |
263 | bool erase = false; | 286 | bool erase = false; |
264 | 287 | ||
265 | if (!_image_data.size().isValid()) { | 288 | if (!_image_data.size().isValid()) { |
266 | p->fillRect(clipx,clipy,clipw,cliph,white); | 289 | p->fillRect(clipx,clipy,clipw,cliph,white); |
267 | return; | 290 | return; |
268 | } | 291 | } |
269 | if (w>_image_data.width()) { | 292 | if (w>_image_data.width()) { |
270 | w=_image_data.width(); | 293 | w=_image_data.width(); |
271 | x = 0; | 294 | x = 0; |
272 | erase = true; | 295 | erase = true; |
273 | } else if (x+w>_image_data.width()){ | 296 | } else if (x+w>_image_data.width()){ |
274 | x = _image_data.width()-w; | 297 | x = _image_data.width()-w; |
275 | } | 298 | } |
276 | if (h>_image_data.height()) { | 299 | if (h>_image_data.height()) { |
277 | h=_image_data.height(); | 300 | h=_image_data.height(); |
278 | y = 0; | 301 | y = 0; |
279 | erase = true; | 302 | erase = true; |
280 | } else if (y+h>_image_data.height()){ | 303 | } else if (y+h>_image_data.height()){ |
281 | y = _image_data.height()-h; | 304 | y = _image_data.height()-h; |
282 | } | 305 | } |
283 | if (erase||_image_data.hasAlphaBuffer()) { | 306 | if (erase||_image_data.hasAlphaBuffer()) { |
284 | p->fillRect(clipx,clipy,clipw,cliph,white); | 307 | p->fillRect(clipx,clipy,clipw,cliph,white); |
285 | } | 308 | } |
286 | p->drawImage(clipx,clipy,_image_data,x,y,w,h); | 309 | p->drawImage(clipx,clipy,_image_data,x,y,w,h); |
287 | } | 310 | } |
288 | 311 | ||
289 | /* using the real geometry points and not the translated points is wanted! */ | 312 | /* using the real geometry points and not the translated points is wanted! */ |
290 | void ImageScrollView::viewportMouseMoveEvent(QMouseEvent* e) | 313 | void ImageScrollView::viewportMouseMoveEvent(QMouseEvent* e) |
291 | { | 314 | { |
292 | int mx, my; | 315 | int mx, my; |
293 | mx = e->x(); | 316 | mx = e->x(); |
294 | my = e->y(); | 317 | my = e->y(); |
295 | int diffx = _mouseStartPosX-mx; | 318 | if (_mouseStartPosX!=-1 && _mouseStartPosY!=-1) { |
296 | int diffy = _mouseStartPosY-my; | 319 | int diffx = _mouseStartPosX-mx; |
297 | scrollBy(diffx,diffy); | 320 | int diffy = _mouseStartPosY-my; |
321 | #if 0 | ||
322 | QScrollBar*xbar = horizontalScrollBar(); | ||
323 | QScrollBar*ybar = verticalScrollBar(); | ||
324 | if (xbar->value()+diffx>xbar->maxValue()) { | ||
325 | diffx = xbar->maxValue()-xbar->value(); | ||
326 | } else if (xbar->value()+diffx<0) { | ||
327 | diffx=0-xbar->value(); | ||
328 | } | ||
329 | if (ybar->value()+diffy>ybar->maxValue()) { | ||
330 | diffy = ybar->maxValue()-ybar->value(); | ||
331 | } else if (ybar->value()+diffy<0) { | ||
332 | diffy=0-ybar->value(); | ||
333 | } | ||
334 | #endif | ||
335 | scrollBy(diffx,diffy); | ||
336 | } | ||
298 | _mouseStartPosX=mx; | 337 | _mouseStartPosX=mx; |
299 | _mouseStartPosY=my; | 338 | _mouseStartPosY=my; |
300 | } | 339 | } |
301 | 340 | ||
302 | void ImageScrollView::contentsMouseReleaseEvent ( QMouseEvent * e) | 341 | void ImageScrollView::contentsMousePressEvent ( QMouseEvent * ) |
303 | { | 342 | { |
304 | _mouseStartPosX = e->x(); | 343 | /* this marks the beginning of a possible mouse move. Due internal reasons of QT |
305 | _mouseStartPosY = e->y(); | 344 | the geometry values here may real differ from that set in MoveEvent (I don't know |
306 | } | 345 | why). For getting them in real context, we use the first move-event to set the start |
307 | 346 | position ;) | |
308 | void ImageScrollView::contentsMousePressEvent ( QMouseEvent * e) | 347 | */ |
309 | { | 348 | _mouseStartPosX = -1; |
310 | _mouseStartPosX = e->x(); | 349 | _mouseStartPosY = -1; |
311 | _mouseStartPosY = e->y(); | ||
312 | } | 350 | } |
313 | 351 | ||
314 | void ImageScrollView::setDestructiveClose() { | 352 | void ImageScrollView::setDestructiveClose() { |
315 | WFlags fl = getWFlags(); | 353 | WFlags fl = getWFlags(); |
316 | /* clear it just in case */ | 354 | /* clear it just in case */ |
317 | fl &= ~WDestructiveClose; | 355 | fl &= ~WDestructiveClose; |
318 | fl |= WDestructiveClose; | 356 | fl |= WDestructiveClose; |
319 | setWFlags( fl ); | 357 | setWFlags( fl ); |
320 | } | 358 | } |
321 | |||
322 | |||
323 | /* for testing */ | ||
324 | ImageDlg::ImageDlg(const QString&fname,QWidget * parent, const char * name) | ||
325 | :QDialog(parent,name,true,WStyle_ContextHelp) | ||
326 | { | ||
327 | QVBoxLayout*dlglayout = new QVBoxLayout(this); | ||
328 | dlglayout->setSpacing(2); | ||
329 | dlglayout->setMargin(1); | ||
330 | ImageScrollView*inf = new ImageScrollView(fname,this); | ||
331 | dlglayout->addWidget(inf); | ||
332 | odebug << "Imagedlg constructor end" << oendl; | ||
333 | } | ||
334 | |||
335 | ImageDlg::~ImageDlg() | ||
336 | { | ||
337 | } | ||
diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.h b/noncore/graphics/opie-eye/gui/imagescrollview.h index 44f2a64..17e2f5f 100644 --- a/noncore/graphics/opie-eye/gui/imagescrollview.h +++ b/noncore/graphics/opie-eye/gui/imagescrollview.h | |||
@@ -1,72 +1,62 @@ | |||
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 | virtual void setImage(const QImage&); |
21 | void setImage( const QString& path ); | 21 | virtual void setImage( const QString& path ); |
22 | void setDestructiveClose(); | 22 | virtual void setDestructiveClose(); |
23 | 23 | ||
24 | void setAutoRotate(bool); | 24 | virtual void setAutoRotate(bool); |
25 | void setAutoScale(bool); | 25 | virtual 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 | QString m_lastName; | 50 | QString m_lastName; |
51 | void rescaleImage(int w, int h); | 51 | virtual void rescaleImage(int w, int h); |
52 | 52 | ||
53 | void rotate_into_data(Rotation r); | 53 | virtual void rotate_into_data(Rotation r); |
54 | void generateImage(); | 54 | virtual 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); | ||
60 | virtual void resizeEvent(QResizeEvent * e); | 59 | virtual void resizeEvent(QResizeEvent * e); |
60 | virtual void keyPressEvent(QKeyEvent * e); | ||
61 | }; | 61 | }; |
62 | |||
63 | /* for testing */ | ||
64 | class ImageDlg:public QDialog | ||
65 | { | ||
66 | Q_OBJECT | ||
67 | public: | ||
68 | ImageDlg(const QString&,QWidget * parent=0, const char * name=0); | ||
69 | virtual ~ImageDlg(); | ||
70 | }; | ||
71 | |||
72 | #endif | 62 | #endif |