From 318c10ce368a6bf99f3412a2ff1ef0a9177c965a Mon Sep 17 00:00:00 2001 From: alwin Date: Sun, 04 Apr 2004 23:02:29 +0000 Subject: ok, the first - realy first - working shot of a special ImageScrollView. But the most important things are working now and can be used. Todo: - check on a pda(!) doublebuffering (bitBlt) - may be it will paint faster - implemented mouseEvents seems not working good, its just a first try. --- (limited to 'noncore') diff --git a/noncore/graphics/opie-eye/gui/iconview.cpp b/noncore/graphics/opie-eye/gui/iconview.cpp index ac4b899..de2cdf0 100644 --- a/noncore/graphics/opie-eye/gui/iconview.cpp +++ b/noncore/graphics/opie-eye/gui/iconview.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -371,7 +372,12 @@ void PIconView::slotEnd() { } void PIconView::slotShowImage() { - + qDebug("image show"); + bool isDir = false; + QString name = currentFileName(isDir); + if (isDir) return; + ImageDlg dlg(name); + QPEApplication::execDialog(&dlg); } void PIconView::slotShowImage( const QString& ) { diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.cpp b/noncore/graphics/opie-eye/gui/imagescrollview.cpp new file mode 100644 index 0000000..f36b717 --- a/dev/null +++ b/noncore/graphics/opie-eye/gui/imagescrollview.cpp @@ -0,0 +1,97 @@ +#include "imagescrollview.h" + +#include +#include + +ImageScrollView::ImageScrollView (const QImage&img, QWidget * parent, const char * name, WFlags f) + :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(img) +{ + init(); +} + +ImageScrollView::ImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f) + :QScrollView(parent,name,f/*|Qt::WRepaintNoErase*/),_image_data(img) +{ + init(); +} + +void ImageScrollView::setImage(const QImage&img) +{ + _image_data = img; + init(); +} + +/* should be called every time the QImage changed it content */ +void ImageScrollView::init() +{ + viewport()->setBackgroundColor(white); + resizeContents(_image_data.width(),_image_data.height()); +} + +ImageScrollView::~ImageScrollView() +{ +} + +void ImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph) +{ + int w = clipw; + int h = cliph; + int x = clipx; + int y = clipy; + bool erase = false; + + if (w>_image_data.width()) { + w=_image_data.width(); + x = 0; + erase = true; + } else if (x+w>_image_data.width()){ + x = _image_data.width()-w; + } + if (h>_image_data.height()) { + h=_image_data.height(); + y = 0; + erase = true; + } else if (y+h>_image_data.height()){ + y = _image_data.height()-h; + } + if (erase) { + p->fillRect(clipx,clipy,clipw,cliph,white); + } + p->drawImage(clipx,clipy,_image_data,x,y,w,h); +} + +void ImageScrollView::viewportMouseMoveEvent(QMouseEvent* e) +{ + int mx, my; + viewportToContents( e->x(), e->y(), mx, my ); + + scrollBy(_mouseStartPosX-mx,my-_mouseStartPosY); + + _mouseStartPosX=mx; + _mouseStartPosY=my; +} + +void ImageScrollView::contentsMouseReleaseEvent ( QMouseEvent * e) +{ + viewportToContents( e->x(), e->y(), _mouseStartPosX,_mouseStartPosY ); +} + +void ImageScrollView::contentsMousePressEvent ( QMouseEvent * e) +{ + viewportToContents( e->x(), e->y(), _mouseStartPosX,_mouseStartPosY ); +} + +/* 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); +} + +ImageDlg::~ImageDlg() +{ +} diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.h b/noncore/graphics/opie-eye/gui/imagescrollview.h new file mode 100644 index 0000000..5836c8d --- a/dev/null +++ b/noncore/graphics/opie-eye/gui/imagescrollview.h @@ -0,0 +1,43 @@ +#ifndef __IMAGE_SCROLL_VIEW_H +#define __IMAGE_SCROLL_VIEW_H + +#include +#include +#include +#include + +class QPainter; + +class ImageScrollView:public QScrollView +{ + Q_OBJECT +public: + ImageScrollView (const QImage&, QWidget * parent=0, const char * name=0, WFlags f=0 ); + ImageScrollView (const QString&, QWidget * parent=0, const char * name=0, WFlags f=0 ); + virtual ~ImageScrollView(); + + void setImage(const QImage&); +protected: + virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph ); + void init(); + + QImage _image_data; + + int _mouseStartPosX,_mouseStartPosY; + +protected slots: + virtual void viewportMouseMoveEvent(QMouseEvent* e); + virtual void contentsMousePressEvent ( QMouseEvent * e); + virtual void contentsMouseReleaseEvent ( QMouseEvent * e); +}; + +/* for testing */ +class ImageDlg:public QDialog +{ + Q_OBJECT +public: + ImageDlg(const QString&,QWidget * parent=0, const char * name=0); + virtual ~ImageDlg(); +}; + +#endif -- cgit v0.9.0.2