summaryrefslogtreecommitdiff
path: root/noncore
Side-by-side diff
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/opie-eye/gui/iconview.cpp8
-rw-r--r--noncore/graphics/opie-eye/gui/imagescrollview.cpp97
-rw-r--r--noncore/graphics/opie-eye/gui/imagescrollview.h43
3 files changed, 147 insertions, 1 deletions
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
@@ -1,105 +1,106 @@
/*
* GPLv2 zecke@handhelds.org
* No WArranty...
*/
#include "iconview.h"
#include <lib/imagecache.h>
#include <gui/imageinfoui.h>
+#include <gui/imagescrollview.h>
#include <iface/dirview.h>
#include <iface/dirlister.h>
#include <opie2/oconfig.h>
#include <opie2/okeyconfigwidget.h>
#include <opie2/odebug.h>
#include <qpe/resource.h>
#include <qpe/qpemessagebox.h>
#include <qpe/ir.h>
#include <qpe/qcopenvelope_qws.h>
#include <qpe/qpeapplication.h>
#include <qiconview.h>
#include <qlabel.h>
#include <qhbox.h>
#include <qcombobox.h>
#include <qdir.h>
#include <qapplication.h>
#include <qmainwindow.h>
#include <qtimer.h>
#include <qstyle.h>
using Opie::Ui::OKeyConfigItem;
namespace {
QPixmap* _dirPix = 0;
QPixmap* _unkPix = 0;
class IconViewItem : public QIconViewItem {
public:
IconViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false);
QPixmap* pixmap()const;
QString path()const { return m_path; }
bool isDir()const { return m_isDir; }
void setText( const QString& );
private:
mutable QPixmap* m_pix;
QString m_path;
bool m_isDir : 1;
bool m_noInfo :1;
};
/*
* If we request an Image or String
* we add it to the map
*/
QMap<QString, IconViewItem*> g_stringInf;
QMap<QString, IconViewItem*> g_stringPix;
IconViewItem::IconViewItem( QIconView* view,const QString& path,
const QString& name, bool isDir )
: QIconViewItem( view, name ), m_path( path ), m_isDir( isDir ),
m_noInfo( false )
{
if ( isDir && !_dirPix )
_dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser"));
else if ( !isDir && !_unkPix )
_unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) );
}
inline QPixmap* IconViewItem::pixmap()const {
// qWarning( "Name is " + m_path.right( 15 ) + " rect is %d %d %d %d | %d %d",
// rect().x(),rect().y(),rect().width(),rect().height(),
// iconView()->contentsX(), iconView()->contentsY());
if ( m_isDir )
return _dirPix;
else{
if (!m_noInfo && !g_stringInf.contains( m_path ) ) {
currentView()->dirLister()->imageInfo( m_path );
g_stringInf.insert( m_path, const_cast<IconViewItem*>(this));
}
m_pix = PPixmapCache::self()->cachedImage( m_path, 64, 64 );
if ( !m_pix && !g_stringPix.contains( m_path )) {
currentView()->dirLister()->thumbNail( m_path, 64, 64 );
g_stringPix.insert( m_path, const_cast<IconViewItem*>(this));
}
return m_pix ? m_pix : _unkPix;
}
}
inline void IconViewItem::setText( const QString& str ) {
QString text = QIconViewItem::text()+"\n"+str;
m_noInfo = true;
QIconViewItem::setText( text );
}
}
PIconView::PIconView( QWidget* wid, Opie::Core::OConfig* cfg )
: QVBox( wid ), m_cfg( cfg ), m_updatet( false )
{
@@ -278,113 +279,118 @@ void PIconView::slotViewChanged( int i) {
void PIconView::slotReloadDir() {
slotChangeDir( m_path );
}
void PIconView::addFolders( const QStringList& lst) {
QStringList::ConstIterator it;
for(it=lst.begin(); it != lst.end(); ++it ) {
(void)new IconViewItem( m_view, m_path+"/"+(*it), (*it), true );
}
}
void PIconView::addFiles( const QStringList& lst) {
QStringList::ConstIterator it;
for (it=lst.begin(); it!= lst.end(); ++it )
(void)new IconViewItem( m_view, m_path+"/"+(*it), (*it) );
}
void PIconView::slotClicked(QIconViewItem* _it) {
if(!_it )
return;
IconViewItem* it = static_cast<IconViewItem*>(_it);
if( it->isDir() )
slotChangeDir( it->path() );
else // view image
;
}
void PIconView::slotThumbInfo( const QString& _path, const QString& str ) {
IconViewItem* item = g_stringInf[_path];
if (!item )
return;
if ( item->intersects(QRect( m_view->contentsX(),m_view->contentsY(),
m_view->contentsWidth(), m_view->contentsHeight() ) ) )
m_updatet = true;
item->setText( str );
g_stringInf.remove( _path );
}
void PIconView::slotThumbNail(const QString& _path, const QPixmap &pix) {
IconViewItem* item = g_stringPix[_path];
if (!item )
return;
if ( item->intersects(QRect( m_view->contentsX(),m_view->contentsY(),
m_view->contentsWidth(), m_view->contentsHeight() ) ) )
m_updatet = true;
if (pix.width()>0)
PPixmapCache::self()->insertImage( _path, pix, 64, 64 );
g_stringPix.remove( _path );
}
void PIconView::slotRename() {
}
void PIconView::slotBeam() {
bool isDir;
QString pa = currentFileName( isDir );
if ( isDir && pa.isEmpty() )
return;
Ir* ir = new Ir( this );
connect( ir, SIGNAL(done(Ir*)),
this, SLOT(slotBeamDone(Ir*)));
ir->send(pa, tr( "Image" ) );
}
void PIconView::slotBeamDone( Ir* ir) {
delete ir;
}
void PIconView::slotStart() {
m_view->viewport()->setUpdatesEnabled( false );
qWarning( "Sig Start" );
}
void PIconView::slotEnd() {
qWarning( "SLot End" );
if ( m_updatet )
m_view->arrangeItemsInGrid( );
m_view->viewport()->setUpdatesEnabled( true );
m_updatet = false;
}
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& ) {
}
void PIconView::slotImageInfo() {
qDebug("image info");
bool isDir = false;
QString name = currentFileName(isDir);
if (isDir) return;
infoDlg dlg(name);
QPEApplication::execDialog(&dlg);
}
void PIconView::slotImageInfo( 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 <qimage.h>
+#include <qlayout.h>
+
+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 <qscrollview.h>
+#include <qimage.h>
+#include <qstring.h>
+#include <qdialog.h>
+
+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