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 | |||
@@ -9,13 +9,12 @@ using namespace Opie::Core; | |||
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 | { |
@@ -53,12 +52,13 @@ void ImageScrollView::setImage( const QString& path ) { | |||
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()); |
@@ -251,12 +251,35 @@ void ImageScrollView::resizeEvent(QResizeEvent * e) | |||
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; |
@@ -289,49 +312,47 @@ void ImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw | |||
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 | |||
@@ -14,18 +14,18 @@ class ImageScrollView:public QScrollView | |||
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 |
@@ -45,28 +45,18 @@ protected: | |||
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 |