Diffstat (limited to 'noncore/multimedia/showimg/ImageFileSelector.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/multimedia/showimg/ImageFileSelector.cpp | 277 |
1 files changed, 277 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 | |||
27 | ThumbWidget::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 | |||
41 | void ThumbWidget::resizeEvent(QResizeEvent *e) | ||
42 | { | ||
43 | description->setGeometry(0,height()-24,width(),24); | ||
44 | } | ||
45 | |||
46 | void 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 | |||
56 | void ThumbWidget::mouseReleaseEvent(QMouseEvent* event) | ||
57 | { | ||
58 | emit clicked(fl); | ||
59 | } | ||
60 | |||
61 | |||
62 | |||
63 | |||
64 | ImageFileSelectorItem::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 | |||
75 | ImageFileSelectorItem::~ImageFileSelectorItem() | ||
76 | { | ||
77 | |||
78 | } | ||
79 | |||
80 | |||
81 | ImageFileSelector::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 | } | ||
115 | ImageFileSelector::~ImageFileSelector() | ||
116 | { | ||
117 | |||
118 | } | ||
119 | |||
120 | |||
121 | void 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 | |||
132 | void 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 | |||
153 | void ImageFileSelector::resizeEvent(QResizeEvent *) | ||
154 | { | ||
155 | updateSizes(); | ||
156 | } | ||
157 | |||
158 | void 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 | |||
168 | void 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 | |||
236 | int ImageFileSelector::fileCount() | ||
237 | { | ||
238 | return count; | ||
239 | } | ||
240 | const 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 | |||
250 | void 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' | ||
260 | void ImageFileSelector::filePressed( int, QListViewItem *, const QPoint &, int ) | ||
261 | { | ||
262 | |||
263 | } | ||
264 | void ImageFileSelector::fileClicked( QListViewItem *i) | ||
265 | { | ||
266 | if ( !i ) | ||
267 | return; | ||
268 | emit fileSelected( ( (ImageFileSelectorItem*)i )->file() ); | ||
269 | emit closeMe(); | ||
270 | } | ||
271 | |||
272 | void ImageFileSelector::thumbClicked(const DocLnk &f) | ||
273 | { | ||
274 | emit fileSelected( f ); | ||
275 | emit closeMe(); | ||
276 | } | ||
277 | |||