summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/opie-eye/gui/imagescrollview.cpp38
-rw-r--r--noncore/graphics/opie-eye/gui/imagescrollview.h7
-rw-r--r--noncore/graphics/opie-eye/lib/oimagezoomer.cpp14
3 files changed, 52 insertions, 7 deletions
diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.cpp b/noncore/graphics/opie-eye/gui/imagescrollview.cpp
index ad19219..5b12258 100644
--- a/noncore/graphics/opie-eye/gui/imagescrollview.cpp
+++ b/noncore/graphics/opie-eye/gui/imagescrollview.cpp
@@ -51,24 +51,39 @@ void ImageScrollView::setImage( const QString& path ) {
_original_data.convertDepth(QPixmap::defaultDepth());
_original_data.setAlphaBuffer(false);
_image_data = QImage();
if (first_resize_done) {
generateImage();
}
}
/* should be called every time the QImage changed it content */
void ImageScrollView::init()
{
odebug << "init " << oendl;
+
+ /*
+ * create the zoomer
+ * and connect ther various signals
+ */
+ _zoomer = new Opie::MM::OImageZoomer( this, "The Zoomer" );
+ connect(_zoomer, SIGNAL( zoomAreaRel(int,int)),
+ this, SLOT(scrollBy(int,int)) );
+ connect(this,SIGNAL(contentsMoving(int,int)),
+ _zoomer, (SLOT(setVisiblePoint(int,int))) );
+ connect(this,SIGNAL(imageSizeChanged(const QSize&)),
+ _zoomer, SLOT(setImageSize(const QSize&)) );
+ connect(this,SIGNAL(viewportSizeChanged(const QSize&)),
+ _zoomer, SLOT(setViewPortSize(const QSize&)) );
+
viewport()->setBackgroundColor(white);
setFocusPolicy(QWidget::StrongFocus);
if (first_resize_done) {
last_rot = Rotate0;
generateImage();
odebug << "reinit display " << oendl;
} else if (_original_data.size().isValid()) {
resizeContents(_original_data.width(),_original_data.height());
}
}
void ImageScrollView::setAutoRotate(bool how)
@@ -242,33 +257,50 @@ void ImageScrollView::generateImage()
rescaleImage(width(),height());
resizeContents(_image_data.width(),_image_data.height());
} else if (!first_resize_done||r!=last_rot||_image_data.width()==0) {
if (r==Rotate0) {
_image_data = _original_data;
} else {
rotate_into_data(r);
}
last_rot = r;
resizeContents(_image_data.width(),_image_data.height());
}
_pdata.convertFromImage(_image_data);
+
+ /*
+ * update the zoomer
+ */
+ emit imageSizeChanged( _image_data.size() );
+ rescaleImage( 128, 128 );
+ _zoomer->setImage( _image_data );
+
+ /*
+ * invalidate
+ */
_image_data=QImage();
}
void ImageScrollView::resizeEvent(QResizeEvent * e)
{
odebug << "ImageScrollView resizeEvent" << oendl;
QScrollView::resizeEvent(e);
generateImage();
first_resize_done = true;
+ emit viewportSizeChanged( viewport()->size() );
+
+ /*
+ * move scrollbar
+ */
+ _zoomer->setGeometry( viewport()->width()-100, viewport()->height()-50, 100, 50 );
}
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);
@@ -311,24 +343,25 @@ void ImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw
} else if (y+h>_pdata.height()){
y = _pdata.height()-h;
}
if (erase||_original_data.hasAlphaBuffer()) {
p->fillRect(clipx,clipy,clipw,cliph,white);
}
p->drawPixmap(clipx,clipy,_pdata,x,y,w,h);
}
/* using the real geometry points and not the translated points is wanted! */
void ImageScrollView::viewportMouseMoveEvent(QMouseEvent* e)
{
+ odebug << "Move X and Y " << e->x() << " " << e->y() << oendl;
int mx, my;
mx = e->x();
my = e->y();
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) {
@@ -337,30 +370,31 @@ void ImageScrollView::viewportMouseMoveEvent(QMouseEvent* e)
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;
_mouseStartPosY=my;
}
-void ImageScrollView::contentsMousePressEvent ( QMouseEvent * )
+void ImageScrollView::contentsMousePressEvent ( QMouseEvent * e)
{
+ odebug << " X and Y " << e->x() << " " << e->y() << oendl;
/* 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 ;)
+ position ;)
*/
_mouseStartPosX = -1;
_mouseStartPosY = -1;
}
void ImageScrollView::setDestructiveClose() {
WFlags fl = getWFlags();
/* clear it just in case */
fl &= ~WDestructiveClose;
fl |= WDestructiveClose;
setWFlags( fl );
}
diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.h b/noncore/graphics/opie-eye/gui/imagescrollview.h
index eb91dbd..1b25103 100644
--- a/noncore/graphics/opie-eye/gui/imagescrollview.h
+++ b/noncore/graphics/opie-eye/gui/imagescrollview.h
@@ -1,21 +1,25 @@
#ifndef _IMAGE_SCROLL_VIEW_H
#define _IMAGE_SCROLL_VIEW_H
+#include <lib/oimagezoomer.h>
+
#include <qscrollview.h>
#include <qimage.h>
#include <qpixmap.h>
#include <qstring.h>
#include <qdialog.h>
+
+
class QPainter;
class ImageScrollView:public QScrollView
{
Q_OBJECT
public:
ImageScrollView( QWidget* parent, const char* name = 0, WFlags fl = 0 );
ImageScrollView (const QImage&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false );
ImageScrollView (const QString&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false );
virtual ~ImageScrollView();
virtual void setImage(const QImage&);
@@ -25,29 +29,32 @@ public:
virtual void setAutoRotate(bool);
virtual void setAutoScale(bool);
enum Rotation {
Rotate0,
Rotate90,
Rotate180,
Rotate270
};
signals:
void sig_return();
+ void imageSizeChanged( const QSize& );
+ void viewportSizeChanged( const QSize& );
protected:
virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph );
void init();
+ Opie::MM::OImageZoomer *_zoomer;
QImage _image_data;
QImage _original_data;
QPixmap _pdata;
int _mouseStartPosX,_mouseStartPosY;
bool scale_to_fit;
bool rotate_to_fit;
bool first_resize_done;
Rotation last_rot;
QString m_lastName;
virtual void rescaleImage(int w, int h);
diff --git a/noncore/graphics/opie-eye/lib/oimagezoomer.cpp b/noncore/graphics/opie-eye/lib/oimagezoomer.cpp
index 178fbd4..ffa3c0c 100644
--- a/noncore/graphics/opie-eye/lib/oimagezoomer.cpp
+++ b/noncore/graphics/opie-eye/lib/oimagezoomer.cpp
@@ -17,24 +17,28 @@ OImageZoomer::OImageZoomer( QWidget* parent, const char* name, WFlags fl )
OImageZoomer::OImageZoomer( const QPixmap& pix, QWidget* par, const char* name, WFlags fl )
: QFrame( par, name, fl ) {
init();
setImage( pix );
}
OImageZoomer::OImageZoomer( const QSize& pSize, const QSize& vSize, QWidget* par,
const char* name, WFlags fl )
: QFrame( par, name, fl ), m_imgSize( pSize ),m_visSize( vSize ) {
init();
}
+OImageZoomer::~OImageZoomer() {
+
+}
+
void OImageZoomer::init() {
setFrameStyle( Panel | Sunken );
}
void OImageZoomer::setImageSize( const QSize& size ) {
m_imgSize = size;
repaint();
}
void OImageZoomer::setViewPortSize( const QSize& size ) {
m_visSize = size;
repaint();
}
@@ -84,33 +88,33 @@ void OImageZoomer::drawContents( QPainter* p ) {
int w = (c.width()*m_visSize.width() )/len + c.x();
if ( w > c.width() ) w = c.width();
len = m_imgSize.height();
int y = (c.height()*m_visPt.y() )/len + c.y();
int h = (c.height()*m_visSize.height() )/len + c.y();
if ( h > c.height() ) h = c.height();
p->drawRect( x, y, w, h );
}
void OImageZoomer::mousePressEvent( QMouseEvent* ) {
-
+ m_mouseX = m_mouseY = -1;
}
void OImageZoomer::mouseMoveEvent( QMouseEvent* ev ) {
int mx, my;
mx = ev->x();
my = ev->y();
if ( m_mouseX != -1 && m_mouseY != -1 ) {
- int diffx = m_mouseX-mx;
- int diffy = m_mouseY-my;
-// emit zoomAreaRel( diffx, diffy );
-// emit zoomArea(
+ int diffx = ( mx - m_mouseX ) * m_imgSize.width() / width();
+ int diffy = ( my - m_mouseY ) * m_imgSize.height() / height();
+ emit zoomAreaRel( diffx, diffy );
+ emit zoomArea(m_visPt.x()+diffx, m_visPt.y()+diffy );
}
m_mouseX = mx;
m_mouseY = my;
}
}
}