summaryrefslogtreecommitdiff
path: root/noncore/graphics/opie-eye/lib/oimagezoomer.cpp
authorzecke <zecke>2004-04-07 19:13:22 (UTC)
committer zecke <zecke>2004-04-07 19:13:22 (UTC)
commitf8e633dea182beabbb665a25136b43a9dd7d0558 (patch) (side-by-side diff)
tree2bec7c5b73ec358ac44e7158cd4bc3a708521cd2 /noncore/graphics/opie-eye/lib/oimagezoomer.cpp
parent673b99175f7447cbae8eff237f2f9d07be8e0087 (diff)
downloadopie-f8e633dea182beabbb665a25136b43a9dd7d0558.zip
opie-f8e633dea182beabbb665a25136b43a9dd7d0558.tar.gz
opie-f8e633dea182beabbb665a25136b43a9dd7d0558.tar.bz2
Add the ImageZoomer now alwin connect some signals and slots
Diffstat (limited to 'noncore/graphics/opie-eye/lib/oimagezoomer.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/opie-eye/lib/oimagezoomer.cpp116
1 files changed, 116 insertions, 0 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;
+}
+
+
+}
+}