summaryrefslogtreecommitdiff
authoralwin <alwin>2004-04-06 23:54:50 (UTC)
committer alwin <alwin>2004-04-06 23:54:50 (UTC)
commit1b7aaf904fa70c16eee03155bd826e921798cc22 (patch) (side-by-side diff)
treeda95ac3da9717101bfdc685e59a12a1e331f9ec0
parent5cab9e2717383faaebb44cbb57df5badc3056206 (diff)
downloadopie-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
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/opie-eye/gui/imagescrollview.cpp81
-rw-r--r--noncore/graphics/opie-eye/gui/imagescrollview.h28
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
@@ -14,3 +14,2 @@ ImageScrollView::ImageScrollView( QWidget* parent, const char* name, WFlags f )
init();
- qDebug("constructor done");
}
@@ -58,2 +57,3 @@ void ImageScrollView::init()
viewport()->setBackgroundColor(white);
+ setFocusPolicy(QWidget::StrongFocus);
if (first_resize_done) {
@@ -256,2 +256,25 @@ void ImageScrollView::resizeEvent(QResizeEvent * e)
+void ImageScrollView::keyPressEvent(QKeyEvent * e)
+{
+ if (!e) return;
+ int dx = horizontalScrollBar()->lineStep();
+ int dy = verticalScrollBar()->lineStep();
+ if (e->key()==Qt::Key_Right) {
+ scrollBy(dx,0);
+ e->accept();
+ } else if (e->key()==Qt::Key_Left) {
+ scrollBy(0-dx,0);
+ e->accept();
+ } else if (e->key()==Qt::Key_Up) {
+ scrollBy(0,0-dy);
+ e->accept();
+ } else if (e->key()==Qt::Key_Down) {
+ scrollBy(0,dy);
+ e->accept();
+ } else {
+ e->ignore();
+ }
+ QScrollView::keyPressEvent(e);
+}
+
void ImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph)
@@ -294,5 +317,21 @@ void ImageScrollView::viewportMouseMoveEvent(QMouseEvent* e)
my = e->y();
- int diffx = _mouseStartPosX-mx;
- int diffy = _mouseStartPosY-my;
- scrollBy(diffx,diffy);
+ if (_mouseStartPosX!=-1 && _mouseStartPosY!=-1) {
+ int diffx = _mouseStartPosX-mx;
+ int diffy = _mouseStartPosY-my;
+#if 0
+ QScrollBar*xbar = horizontalScrollBar();
+ QScrollBar*ybar = verticalScrollBar();
+ if (xbar->value()+diffx>xbar->maxValue()) {
+ diffx = xbar->maxValue()-xbar->value();
+ } else if (xbar->value()+diffx<0) {
+ diffx=0-xbar->value();
+ }
+ if (ybar->value()+diffy>ybar->maxValue()) {
+ diffy = ybar->maxValue()-ybar->value();
+ } else if (ybar->value()+diffy<0) {
+ diffy=0-ybar->value();
+ }
+#endif
+ scrollBy(diffx,diffy);
+ }
_mouseStartPosX=mx;
@@ -301,12 +340,11 @@ void ImageScrollView::viewportMouseMoveEvent(QMouseEvent* e)
-void ImageScrollView::contentsMouseReleaseEvent ( QMouseEvent * e)
+void ImageScrollView::contentsMousePressEvent ( QMouseEvent * )
{
- _mouseStartPosX = e->x();
- _mouseStartPosY = e->y();
-}
-
-void ImageScrollView::contentsMousePressEvent ( QMouseEvent * e)
-{
- _mouseStartPosX = e->x();
- _mouseStartPosY = e->y();
+ /* this marks the beginning of a possible mouse move. Due internal reasons of QT
+ the geometry values here may real differ from that set in MoveEvent (I don't know
+ why). For getting them in real context, we use the first move-event to set the start
+ position ;)
+ */
+ _mouseStartPosX = -1;
+ _mouseStartPosY = -1;
}
@@ -320,18 +358 @@ void ImageScrollView::setDestructiveClose() {
}
-
-
-/* for testing */
-ImageDlg::ImageDlg(const QString&fname,QWidget * parent, const char * name)
- :QDialog(parent,name,true,WStyle_ContextHelp)
-{
- QVBoxLayout*dlglayout = new QVBoxLayout(this);
- dlglayout->setSpacing(2);
- dlglayout->setMargin(1);
- ImageScrollView*inf = new ImageScrollView(fname,this);
- dlglayout->addWidget(inf);
- odebug << "Imagedlg constructor end" << oendl;
-}
-
-ImageDlg::~ImageDlg()
-{
-}
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
@@ -19,8 +19,8 @@ public:
- void setImage(const QImage&);
- void setImage( const QString& path );
- void setDestructiveClose();
+ virtual void setImage(const QImage&);
+ virtual void setImage( const QString& path );
+ virtual void setDestructiveClose();
- void setAutoRotate(bool);
- void setAutoScale(bool);
+ virtual void setAutoRotate(bool);
+ virtual void setAutoScale(bool);
@@ -50,6 +50,6 @@ protected:
QString m_lastName;
- void rescaleImage(int w, int h);
+ virtual void rescaleImage(int w, int h);
- void rotate_into_data(Rotation r);
- void generateImage();
+ virtual void rotate_into_data(Rotation r);
+ virtual void generateImage();
@@ -58,15 +58,5 @@ protected slots:
virtual void contentsMousePressEvent ( QMouseEvent * e);
- virtual void contentsMouseReleaseEvent ( QMouseEvent * e);
virtual void resizeEvent(QResizeEvent * e);
+ virtual void keyPressEvent(QKeyEvent * e);
};
-
-/* for testing */
-class ImageDlg:public QDialog
-{
- Q_OBJECT
-public:
- ImageDlg(const QString&,QWidget * parent=0, const char * name=0);
- virtual ~ImageDlg();
-};
-
#endif