summaryrefslogtreecommitdiff
authorwarmi <warmi>2002-08-15 03:16:42 (UTC)
committer warmi <warmi>2002-08-15 03:16:42 (UTC)
commit92640e4094075342138796065040441210348c76 (patch) (unidiff)
tree852d55ce130c9e2222b0c5456ca1640d592428c8
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 (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 @@
1
2
3#include "qpe/global.h"
4#include "qpe/applnk.h"
5#include "qpe/lnkproperties.h"
6#include "qpe/applnk.h"
7#include "qpe/qpeapplication.h"
8
9#include <stdlib.h>
10
11#include <qdir.h>
12#include <qwidget.h>
13#include <qheader.h>
14#include <qimage.h>
15#include <qpixmap.h>
16#include <qlabel.h>
17#include <qfileinfo.h>
18#include <qpainter.h>
19#include <qscrollview.h>
20
21#include "ImageFileSelector.h"
22
23
24
25
26
27ThumbWidget::ThumbWidget(QPixmap p,QString text,const DocLnk& f,QWidget *parent,int w) : QWidget( parent ),fl(f)
28{
29 setBackgroundMode(NoBackground);
30 if ( w!=-1 )
31 setMinimumSize(w,p.height()+24);
32 else
33 setMinimumSize(p.width(),p.height()+24);
34 description=new QLabel(text,this);
35 description->setBackgroundColor(colorGroup().base());
36 description->setAlignment(AlignCenter);
37 description->setGeometry(0,height()-24,width(),24);
38 pixmap=p;
39}
40
41void ThumbWidget::resizeEvent(QResizeEvent *e)
42{
43 description->setGeometry(0,height()-24,width(),24);
44}
45
46void ThumbWidget::paintEvent( QPaintEvent *e )
47{
48 QPainter painter(this);
49
50 painter.setClipRect(e->rect());
51 painter.fillRect(0,0,width(),height(),QColor(255,255,255));
52 painter.drawPixmap((width() - pixmap.width()) / 2,0, pixmap);
53
54}
55
56void ThumbWidget::mouseReleaseEvent(QMouseEvent* event)
57{
58 emit clicked(fl);
59}
60
61
62
63
64ImageFileSelectorItem::ImageFileSelectorItem( QListView *parent, const DocLnk &f): QListViewItem( parent ), fl( f )
65{
66 setText( 0, f.name() );
67 QFileInfo fi(f.file());
68 setText( 1, (fi.extension()).upper() );
69 setPixmap( 0, f.pixmap() );
70
71
72}
73
74
75ImageFileSelectorItem::~ImageFileSelectorItem()
76{
77
78}
79
80
81ImageFileSelector::ImageFileSelector( CURRENT_VIEW scv,QWidget *parent,const char *name ):QWidgetStack(parent)
82{
83
84 detailed=new QListView(this);
85
86 detailed->addColumn (tr("Title"));
87 detailed->addColumn (tr("Type"));
88 detailed->setAllColumnsShowFocus( true );
89
90 tList.setAutoDelete(true);
91
92 thumb =new QScrollView(this);
93 thumb->setVScrollBarMode (QScrollView::Auto );
94 thumb->viewport()->setBackgroundColor(colorGroup().base());
95
96 background=new QWidget(0);
97 background->setBackgroundColor(colorGroup().base());
98 thumb->addChild(background);
99 gl = new QGridLayout(background,1,2,4,4);
100
101
102
103 connect( detailed, SIGNAL( mouseButtonClicked( int, QListViewItem *, const QPoint &, int ) ),
104 this, SLOT( fileClicked( int, QListViewItem *, const QPoint &, int ) ) );
105 connect( detailed, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint &, int ) ),
106 this, SLOT( filePressed( int, QListViewItem *, const QPoint &, int ) ) );
107 connect( detailed, SIGNAL( returnPressed( QListViewItem * ) ),
108 this, SLOT( fileClicked( QListViewItem * ) ) );
109
110 cView=UNKNOWN;
111 setView(scv);
112 reread();
113
114}
115ImageFileSelector::~ImageFileSelector()
116{
117
118}
119
120
121void ImageFileSelector::switchView()
122{
123 CURRENT_VIEW v=cView;
124
125 if ( v==DETAILED )
126 v=THUMBNAIL;
127 else
128 v=DETAILED;
129 setView(v);
130}
131
132void ImageFileSelector::setView(CURRENT_VIEW v)
133{
134
135 if ( v==cView )
136 return;
137 cView=v;
138
139 if ( cView!=DETAILED )
140 {
141 raiseWidget(thumb);
142 updateSizes();
143 }
144 else
145 {
146 raiseWidget(detailed);
147 updateSizes();
148 }
149
150
151}
152
153void ImageFileSelector::resizeEvent(QResizeEvent *)
154{
155 updateSizes();
156}
157
158void ImageFileSelector::updateSizes()
159{
160 int ww=(detailed->width()-detailed->frameWidth()*2);
161 double w=(double)ww*0.70;
162 detailed->setColumnWidth(0,(int)w);
163 detailed->setColumnWidth(1,ww-(int)w);
164 background->setMinimumWidth(thumb->visibleWidth());
165 thumb->updateScrollBars();
166}
167
168void ImageFileSelector::reread(bool purgeCache)
169{
170 ImageFileSelectorItem *item = (ImageFileSelectorItem *)detailed->selectedItem();
171 QString oldFile;
172 if ( item )
173 oldFile = item->file().file();
174 detailed->clear();
175 tList.clear();
176 DocLnkSet files;
177 Global::findDocuments(&files, "image/*");
178 count = files.children().count();
179 QListIterator<DocLnk> dit( files.children() );
180 int y=0;
181 int x=4;
182 int totalHeight=4;
183 ThumbWidget *l=0;
184 int width=80;
185 gl->expand(dit.count()/2,2);
186
187 int i,j;
188
189 i=j=0;
190
191 detailed->setUpdatesEnabled(false);
192 thumb->setUpdatesEnabled(false);
193 for ( ; dit.current(); ++dit )
194 {
195 item = new ImageFileSelectorItem( detailed, **dit );
196 if ( item->file().file() == oldFile )
197 detailed->setCurrentItem( item );
198 }
199
200 QListViewItemIterator it( detailed );
201 ImageFileSelectorItem *ii;
202 // iterate through all items of the listview
203 for ( ; it.current(); ++it )
204 {
205 ii=(ImageFileSelectorItem *)it.current();
206 QImage img(ii->file().file());
207 img=img.smoothScale(64,64);
208 QPixmap pix;
209 pix.convertFromImage(img);
210 l=new ThumbWidget(pix,ii->file().name(),ii->file(),background,width);
211 l->setBackgroundColor(colorGroup().base());
212 gl->addWidget(l,j,i);
213 i++;
214 if ( i==2 )
215 {
216 i=0;
217 j++;
218 }
219 tList.append(l);
220 connect(l,SIGNAL(clicked(const DocLnk &)),this,SLOT(thumbClicked(const DocLnk &)));
221
222 }
223
224
225
226 if ( !detailed->selectedItem() )
227 detailed->setCurrentItem( detailed->firstChild() );
228
229 detailed->setUpdatesEnabled(true);
230 thumb->setUpdatesEnabled(true);
231 detailed->update();
232 thumb->update();
233
234}
235
236int ImageFileSelector::fileCount()
237{
238 return count;
239}
240const DocLnk * ImageFileSelector::selected()
241{
242 ImageFileSelectorItem *item = (ImageFileSelectorItem *) detailed->selectedItem();
243 if ( item )
244 return new DocLnk( item->file() );
245 return 0;
246}
247
248
249
250void ImageFileSelector::fileClicked( int button, QListViewItem *i, const QPoint &, int )
251{
252 if ( !i )
253 return;
254 if ( button == Qt::LeftButton )
255 {
256 fileClicked( i );
257 }
258}
259 // pressed to get 'right down'
260void ImageFileSelector::filePressed( int, QListViewItem *, const QPoint &, int )
261{
262
263}
264void ImageFileSelector::fileClicked( QListViewItem *i)
265{
266 if ( !i )
267 return;
268 emit fileSelected( ( (ImageFileSelectorItem*)i )->file() );
269 emit closeMe();
270}
271
272void ImageFileSelector::thumbClicked(const DocLnk &f)
273{
274 emit fileSelected( f );
275 emit closeMe();
276}
277
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 @@
1#ifndef IMAGEFILE_SELECTOR_H
2#define IMAGEFILE_SELECTOR_H
3
4
5#include <qtoolbutton.h>
6#include <qlistview.h>
7#include <qwidgetstack.h>
8#include <qlayout.h>
9
10#include "qpe/filemanager.h"
11#include "qpe/applnk.h"
12
13class QScrollView;
14class QLabel;
15
16class ThumbWidget : public QWidget
17{
18 Q_OBJECT
19 public:
20 ThumbWidget(QPixmap p,QString text,const DocLnk& f,QWidget *parent=0,int width=-1);
21 ~ThumbWidget()
22 {
23
24 }
25
26 DocLnk file() const
27 {
28 return fl;
29 }
30
31
32 signals:
33 void clicked(const DocLnk &);
34
35protected:
36 void paintEvent( QPaintEvent * );
37 void resizeEvent(QResizeEvent *);
38
39 void mouseReleaseEvent(QMouseEvent* event);
40
41private:
42 QPixmap pixmap;
43 QLabel *description;
44 DocLnk fl;
45};
46
47
48class ImageFileSelector : public QWidgetStack
49{
50 Q_OBJECT
51
52 public:
53
54 enum CURRENT_VIEW
55 {
56 THUMBNAIL,
57 DETAILED,
58 UNKNOWN
59 };
60
61
62 ImageFileSelector(CURRENT_VIEW scv=DETAILED, QWidget *parent=0, const char *name=0 );
63 ~ImageFileSelector();
64
65 void reread(bool purgeCache=false);
66 int fileCount();
67 const DocLnk *selected();
68
69 void setView(CURRENT_VIEW v);
70
71 CURRENT_VIEW view()
72 {
73 return cView;
74 }
75
76
77public slots:
78
79 void switchView();
80
81signals:
82 void fileSelected( const DocLnk & );
83 void closeMe();
84
85protected:
86
87 void resizeEvent(QResizeEvent *);
88
89
90private slots:
91 void fileClicked( int, QListViewItem *, const QPoint &, int );
92 // pressed to get 'right down'
93 void filePressed( int, QListViewItem *, const QPoint &, int );
94 void fileClicked( QListViewItem *);
95 void thumbClicked(const DocLnk &);
96
97private:
98
99 void updateSizes();
100
101
102 CURRENT_VIEW cView;
103 int count;
104
105 QListView *detailed;
106 QScrollView *thumb;
107 QList<ThumbWidget> tList;
108 QWidget *background;
109 QGridLayout *gl;
110
111};
112
113
114class ImageFileSelectorItem : public QListViewItem
115{
116public:
117 ImageFileSelectorItem( QListView *parent, const DocLnk& f );
118 ~ImageFileSelectorItem();
119
120 DocLnk file() const
121 {
122 return fl;
123 }
124
125
126private:
127 DocLnk fl;
128};
129
130
131
132
133#endif // IMAGEFILE_SELECTOR_H
134
135