author | zecke <zecke> | 2004-04-07 19:13:22 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-04-07 19:13:22 (UTC) |
commit | f8e633dea182beabbb665a25136b43a9dd7d0558 (patch) (side-by-side diff) | |
tree | 2bec7c5b73ec358ac44e7158cd4bc3a708521cd2 | |
parent | 673b99175f7447cbae8eff237f2f9d07be8e0087 (diff) | |
download | opie-f8e633dea182beabbb665a25136b43a9dd7d0558.zip opie-f8e633dea182beabbb665a25136b43a9dd7d0558.tar.gz opie-f8e633dea182beabbb665a25136b43a9dd7d0558.tar.bz2 |
Add the ImageZoomer now alwin connect some signals and slots
-rw-r--r-- | noncore/graphics/opie-eye/lib/oimagezoomer.cpp | 116 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/lib/oimagezoomer.h | 66 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/phunk_view.pro | 6 |
3 files changed, 186 insertions, 2 deletions
diff --git a/noncore/graphics/opie-eye/lib/oimagezoomer.cpp b/noncore/graphics/opie-eye/lib/oimagezoomer.cpp new file mode 100644 index 0000000..178fbd4 --- a/dev/null +++ b/noncore/graphics/opie-eye/lib/oimagezoomer.cpp @@ -0,0 +1,116 @@ +#include "oimagezoomer.h" + +#include <qimage.h> +#include <qpixmap.h> +#include <qpainter.h> +#include <qrect.h> +#include <qpoint.h> +#include <qsize.h> + +namespace Opie { +namespace MM { +OImageZoomer::OImageZoomer( QWidget* parent, const char* name, WFlags fl ) + : QFrame( parent, name, fl ) { + init(); +} + +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(); +} + +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(); +} + +void OImageZoomer::setVisiblePoint( const QPoint& pt ) { + m_visPt = pt; + repaint(); +} + +void OImageZoomer::setImage( const QImage& img) { + m_img = img; + resizeEvent( 0 ); + repaint(); +} + +void OImageZoomer::setImage( const QPixmap& pix) { + setImage( pix.convertToImage() ); +} + +void OImageZoomer::resizeEvent( QResizeEvent* ev ) { + QFrame::resizeEvent( ev ); + setBackgroundOrigin( QWidget::WidgetOrigin ); + // TODO Qt3 use PalettePixmap and use size + QPixmap pix; pix.convertFromImage( m_img.smoothScale( size().width(), size().height() ) ); + setBackgroundPixmap( pix); +} + +void OImageZoomer::drawContents( QPainter* p ) { + /* + * if the page size + */ + if ( m_imgSize.isEmpty() ) + return; + + /* + * paint a red rect which represents the visible size + * + * We need to recalculate x,y and width and height of the + * rect. So image size relates to contentRect + * + */ + QRect c( contentsRect() ); + p->setPen( Qt::red ); + + int len = m_imgSize.width(); + int x = (c.width()*m_visPt.x())/len + c.x(); + 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* ) { + +} + +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( + } + m_mouseX = mx; + m_mouseY = my; +} + + +} +} diff --git a/noncore/graphics/opie-eye/lib/oimagezoomer.h b/noncore/graphics/opie-eye/lib/oimagezoomer.h new file mode 100644 index 0000000..605416c --- a/dev/null +++ b/noncore/graphics/opie-eye/lib/oimagezoomer.h @@ -0,0 +1,66 @@ +#ifndef OPIE_ODP_IMAGE_ZOOMER_H +#define OPIE_ODP_IMAGE_ZOOMER_H + +#include <qframe.h> +#include <qimage.h> + +class QPixmap; +class QRect; +class QPoint; + + +namespace Opie { +namespace MM { + +/** + * \brief small class to zoom over a widget + * This class takes a QImage or QPixmap + * and gets the size of the original image + * and provides depending of this widgets size + * a zoomer and emits the region which should + * be shown / zoomed to + */ +class OImageZoomer : public QFrame { + Q_OBJECT +public: + OImageZoomer( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); + OImageZoomer( const QPixmap&,QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); + OImageZoomer( const QImage&, QWidget* parent = 0, const char* name= 0, WFlags fl = 0 ); + OImageZoomer( const QSize&, const QSize&, QWidget* par, const char*, WFlags fl ); + ~OImageZoomer(); + +public slots: + void setImageSize( const QSize& ); + void setViewPortSize( const QSize& ); + void setVisiblePoint( const QPoint& ); + void setVisiblePoint( int x, int y ); + void setImage( const QImage& ); + void setImage( const QPixmap& ); + +signals: + void zoomAreaRel( int,int ); + void zoomArea( int,int ); + +public: + void resizeEvent( QResizeEvent* ); + +protected: + void drawContents( QPainter* p ); + void mousePressEvent( QMouseEvent* ev ); + void mouseMoveEvent( QMouseEvent* ev ); + +private: + void init(); + QImage m_img; + QSize m_imgSize, m_visSize; + QPoint m_visPt; + int m_mouseX, m_mouseY; +}; + +inline void OImageZoomer::setVisiblePoint( int x, int y ) { + setVisiblePoint( QPoint( x, y ) ); +} + +} +} +#endif diff --git a/noncore/graphics/opie-eye/phunk_view.pro b/noncore/graphics/opie-eye/phunk_view.pro index a825580..e9abe72 100644 --- a/noncore/graphics/opie-eye/phunk_view.pro +++ b/noncore/graphics/opie-eye/phunk_view.pro @@ -1,38 +1,40 @@ CONFIG += qt warn_on quick-app DESTDIR = $(OPIEDIR)/bin TEMPLATE = app TARGET = opie-eye # the name of the resulting object HEADERS = gui/iconview.h gui/filesystem.h gui/mainwindow.h \ lib/imagecache.h impl/dir/dir_dirview.h \ iface/dirview.h iface/dirlister.h iface/ifaceinfo.h \ impl/dir/dir_lister.h impl/dir/dir_ifaceinfo.h \ lib/slavemaster.h \ iface/slaveiface.h \ gui/imageinfoui.h gui/imagescrollview.h \ - gui/imageview.h + gui/imageview.h \ + lib/oimagezoomer.h # A list header files SOURCES = gui/iconview.cpp gui/filesystem.cpp gui/mainwindow.cpp \ lib/imagecache.cpp lib/viewmap.cpp \ impl/dir/dir_dirview.cpp iface/dirlister.cpp \ iface/dirview.cpp impl/dir/dir_lister.cpp \ impl/dir/dir_ifaceinfo.cpp lib/slavemaster.cpp \ gui/imageinfoui.cpp gui/imagescrollview.cpp \ - gui/imageview.cpp + gui/imageview.cpp \ + lib/oimagezoomer.cpp # A list of source files INTERFACES = # list of ui files INCLUDEPATH += . $(OPIEDIR)/include DEPENDPATH += $(OPIEDIR)/include LIBS += -lqpe -lopiecore2 -lopieui2 include ( $(OPIEDIR)/include.pro ) |