summaryrefslogtreecommitdiff
path: root/noncore
authorwarmi <warmi>2002-08-15 03:16:42 (UTC)
committer warmi <warmi>2002-08-15 03:16:42 (UTC)
commit92640e4094075342138796065040441210348c76 (patch) (side-by-side diff)
tree852d55ce130c9e2222b0c5456ca1640d592428c8 /noncore
parent43b6d43015dc2a28035a2d914815c8eb2b93a798 (diff)
downloadopie-92640e4094075342138796065040441210348c76.zip
opie-92640e4094075342138796065040441210348c76.tar.gz
opie-92640e4094075342138796065040441210348c76.tar.bz2
FileSelector with the optional thumbnail preview for images.
Work in progress...
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/showimg/ImageFileSelector.cpp277
-rw-r--r--noncore/multimedia/showimg/ImageFileSelector.h135
2 files changed, 412 insertions, 0 deletions
diff --git a/noncore/multimedia/showimg/ImageFileSelector.cpp b/noncore/multimedia/showimg/ImageFileSelector.cpp
new file mode 100644
index 0000000..347300f
--- a/dev/null
+++ b/noncore/multimedia/showimg/ImageFileSelector.cpp
@@ -0,0 +1,277 @@
+
+
+#include "qpe/global.h"
+#include "qpe/applnk.h"
+#include "qpe/lnkproperties.h"
+#include "qpe/applnk.h"
+#include "qpe/qpeapplication.h"
+
+#include <stdlib.h>
+
+#include <qdir.h>
+#include <qwidget.h>
+#include <qheader.h>
+#include <qimage.h>
+#include <qpixmap.h>
+#include <qlabel.h>
+#include <qfileinfo.h>
+#include <qpainter.h>
+#include <qscrollview.h>
+
+#include "ImageFileSelector.h"
+
+
+
+
+
+ThumbWidget::ThumbWidget(QPixmap p,QString text,const DocLnk& f,QWidget *parent,int w) : QWidget( parent ),fl(f)
+{
+ setBackgroundMode(NoBackground);
+ if ( w!=-1 )
+ setMinimumSize(w,p.height()+24);
+ else
+ setMinimumSize(p.width(),p.height()+24);
+ description=new QLabel(text,this);
+ description->setBackgroundColor(colorGroup().base());
+ description->setAlignment(AlignCenter);
+ description->setGeometry(0,height()-24,width(),24);
+ pixmap=p;
+}
+
+void ThumbWidget::resizeEvent(QResizeEvent *e)
+{
+ description->setGeometry(0,height()-24,width(),24);
+}
+
+void ThumbWidget::paintEvent( QPaintEvent *e )
+{
+ QPainter painter(this);
+
+ painter.setClipRect(e->rect());
+ painter.fillRect(0,0,width(),height(),QColor(255,255,255));
+ painter.drawPixmap((width() - pixmap.width()) / 2,0, pixmap);
+
+}
+
+void ThumbWidget::mouseReleaseEvent(QMouseEvent* event)
+{
+ emit clicked(fl);
+}
+
+
+
+
+ImageFileSelectorItem::ImageFileSelectorItem( QListView *parent, const DocLnk &f): QListViewItem( parent ), fl( f )
+{
+ setText( 0, f.name() );
+ QFileInfo fi(f.file());
+ setText( 1, (fi.extension()).upper() );
+ setPixmap( 0, f.pixmap() );
+
+
+}
+
+
+ImageFileSelectorItem::~ImageFileSelectorItem()
+{
+
+}
+
+
+ImageFileSelector::ImageFileSelector( CURRENT_VIEW scv,QWidget *parent,const char *name ):QWidgetStack(parent)
+{
+
+ detailed=new QListView(this);
+
+ detailed->addColumn (tr("Title"));
+ detailed->addColumn (tr("Type"));
+ detailed->setAllColumnsShowFocus( true );
+
+ tList.setAutoDelete(true);
+
+ thumb =new QScrollView(this);
+ thumb->setVScrollBarMode (QScrollView::Auto );
+ thumb->viewport()->setBackgroundColor(colorGroup().base());
+
+ background=new QWidget(0);
+ background->setBackgroundColor(colorGroup().base());
+ thumb->addChild(background);
+ gl = new QGridLayout(background,1,2,4,4);
+
+
+
+ connect( detailed, SIGNAL( mouseButtonClicked( int, QListViewItem *, const QPoint &, int ) ),
+ this, SLOT( fileClicked( int, QListViewItem *, const QPoint &, int ) ) );
+ connect( detailed, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint &, int ) ),
+ this, SLOT( filePressed( int, QListViewItem *, const QPoint &, int ) ) );
+ connect( detailed, SIGNAL( returnPressed( QListViewItem * ) ),
+ this, SLOT( fileClicked( QListViewItem * ) ) );
+
+ cView=UNKNOWN;
+ setView(scv);
+ reread();
+
+}
+ImageFileSelector::~ImageFileSelector()
+{
+
+}
+
+
+void ImageFileSelector::switchView()
+{
+ CURRENT_VIEW v=cView;
+
+ if ( v==DETAILED )
+ v=THUMBNAIL;
+ else
+ v=DETAILED;
+ setView(v);
+}
+
+void ImageFileSelector::setView(CURRENT_VIEW v)
+{
+
+ if ( v==cView )
+ return;
+ cView=v;
+
+ if ( cView!=DETAILED )
+ {
+ raiseWidget(thumb);
+ updateSizes();
+ }
+ else
+ {
+ raiseWidget(detailed);
+ updateSizes();
+ }
+
+
+}
+
+void ImageFileSelector::resizeEvent(QResizeEvent *)
+{
+ updateSizes();
+}
+
+void ImageFileSelector::updateSizes()
+{
+ int ww=(detailed->width()-detailed->frameWidth()*2);
+ double w=(double)ww*0.70;
+ detailed->setColumnWidth(0,(int)w);
+ detailed->setColumnWidth(1,ww-(int)w);
+ background->setMinimumWidth(thumb->visibleWidth());
+ thumb->updateScrollBars();
+}
+
+void ImageFileSelector::reread(bool purgeCache)
+{
+ ImageFileSelectorItem *item = (ImageFileSelectorItem *)detailed->selectedItem();
+ QString oldFile;
+ if ( item )
+ oldFile = item->file().file();
+ detailed->clear();
+ tList.clear();
+ DocLnkSet files;
+ Global::findDocuments(&files, "image/*");
+ count = files.children().count();
+ QListIterator<DocLnk> dit( files.children() );
+ int y=0;
+ int x=4;
+ int totalHeight=4;
+ ThumbWidget *l=0;
+ int width=80;
+ gl->expand(dit.count()/2,2);
+
+ int i,j;
+
+ i=j=0;
+
+ detailed->setUpdatesEnabled(false);
+ thumb->setUpdatesEnabled(false);
+ for ( ; dit.current(); ++dit )
+ {
+ item = new ImageFileSelectorItem( detailed, **dit );
+ if ( item->file().file() == oldFile )
+ detailed->setCurrentItem( item );
+ }
+
+ QListViewItemIterator it( detailed );
+ ImageFileSelectorItem *ii;
+ // iterate through all items of the listview
+ for ( ; it.current(); ++it )
+ {
+ ii=(ImageFileSelectorItem *)it.current();
+ QImage img(ii->file().file());
+ img=img.smoothScale(64,64);
+ QPixmap pix;
+ pix.convertFromImage(img);
+ l=new ThumbWidget(pix,ii->file().name(),ii->file(),background,width);
+ l->setBackgroundColor(colorGroup().base());
+ gl->addWidget(l,j,i);
+ i++;
+ if ( i==2 )
+ {
+ i=0;
+ j++;
+ }
+ tList.append(l);
+ connect(l,SIGNAL(clicked(const DocLnk &)),this,SLOT(thumbClicked(const DocLnk &)));
+
+ }
+
+
+
+ if ( !detailed->selectedItem() )
+ detailed->setCurrentItem( detailed->firstChild() );
+
+ detailed->setUpdatesEnabled(true);
+ thumb->setUpdatesEnabled(true);
+ detailed->update();
+ thumb->update();
+
+}
+
+int ImageFileSelector::fileCount()
+{
+ return count;
+}
+const DocLnk * ImageFileSelector::selected()
+{
+ ImageFileSelectorItem *item = (ImageFileSelectorItem *) detailed->selectedItem();
+ if ( item )
+ return new DocLnk( item->file() );
+ return 0;
+}
+
+
+
+void ImageFileSelector::fileClicked( int button, QListViewItem *i, const QPoint &, int )
+{
+ if ( !i )
+ return;
+ if ( button == Qt::LeftButton )
+ {
+ fileClicked( i );
+ }
+}
+ // pressed to get 'right down'
+void ImageFileSelector::filePressed( int, QListViewItem *, const QPoint &, int )
+{
+
+}
+void ImageFileSelector::fileClicked( QListViewItem *i)
+{
+ if ( !i )
+ return;
+ emit fileSelected( ( (ImageFileSelectorItem*)i )->file() );
+ emit closeMe();
+}
+
+void ImageFileSelector::thumbClicked(const DocLnk &f)
+{
+ emit fileSelected( f );
+ emit closeMe();
+}
+
diff --git a/noncore/multimedia/showimg/ImageFileSelector.h b/noncore/multimedia/showimg/ImageFileSelector.h
new file mode 100644
index 0000000..2c346c4
--- a/dev/null
+++ b/noncore/multimedia/showimg/ImageFileSelector.h
@@ -0,0 +1,135 @@
+#ifndef IMAGEFILE_SELECTOR_H
+#define IMAGEFILE_SELECTOR_H
+
+
+#include <qtoolbutton.h>
+#include <qlistview.h>
+#include <qwidgetstack.h>
+#include <qlayout.h>
+
+#include "qpe/filemanager.h"
+#include "qpe/applnk.h"
+
+class QScrollView;
+class QLabel;
+
+class ThumbWidget : public QWidget
+{
+ Q_OBJECT
+ public:
+ ThumbWidget(QPixmap p,QString text,const DocLnk& f,QWidget *parent=0,int width=-1);
+ ~ThumbWidget()
+ {
+
+ }
+
+ DocLnk file() const
+ {
+ return fl;
+ }
+
+
+ signals:
+ void clicked(const DocLnk &);
+
+protected:
+ void paintEvent( QPaintEvent * );
+ void resizeEvent(QResizeEvent *);
+
+ void mouseReleaseEvent(QMouseEvent* event);
+
+private:
+ QPixmap pixmap;
+ QLabel *description;
+ DocLnk fl;
+};
+
+
+class ImageFileSelector : public QWidgetStack
+{
+ Q_OBJECT
+
+ public:
+
+ enum CURRENT_VIEW
+ {
+ THUMBNAIL,
+ DETAILED,
+ UNKNOWN
+ };
+
+
+ ImageFileSelector(CURRENT_VIEW scv=DETAILED, QWidget *parent=0, const char *name=0 );
+ ~ImageFileSelector();
+
+ void reread(bool purgeCache=false);
+ int fileCount();
+ const DocLnk *selected();
+
+ void setView(CURRENT_VIEW v);
+
+ CURRENT_VIEW view()
+ {
+ return cView;
+ }
+
+
+public slots:
+
+ void switchView();
+
+signals:
+ void fileSelected( const DocLnk & );
+ void closeMe();
+
+protected:
+
+ void resizeEvent(QResizeEvent *);
+
+
+private slots:
+ void fileClicked( int, QListViewItem *, const QPoint &, int );
+ // pressed to get 'right down'
+ void filePressed( int, QListViewItem *, const QPoint &, int );
+ void fileClicked( QListViewItem *);
+ void thumbClicked(const DocLnk &);
+
+private:
+
+ void updateSizes();
+
+
+ CURRENT_VIEW cView;
+ int count;
+
+ QListView *detailed;
+ QScrollView *thumb;
+ QList<ThumbWidget> tList;
+ QWidget *background;
+ QGridLayout *gl;
+
+};
+
+
+class ImageFileSelectorItem : public QListViewItem
+{
+public:
+ ImageFileSelectorItem( QListView *parent, const DocLnk& f );
+ ~ImageFileSelectorItem();
+
+ DocLnk file() const
+ {
+ return fl;
+ }
+
+
+private:
+ DocLnk fl;
+};
+
+
+
+
+#endif // IMAGEFILE_SELECTOR_H
+
+