author | llornkcor <llornkcor> | 2002-11-03 17:59:00 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-11-03 17:59:00 (UTC) |
commit | 16e8fad81f7ee6045990f48edc84542638bf07d7 (patch) (unidiff) | |
tree | 96d836f914e0d1104d7c84830acac08a43ee4ac2 /noncore/multimedia/showimg/ImageFileSelector.cpp | |
parent | 2981b8f55f4a33860452f4571ef9f04781267489 (diff) | |
download | opie-16e8fad81f7ee6045990f48edc84542638bf07d7.zip opie-16e8fad81f7ee6045990f48edc84542638bf07d7.tar.gz opie-16e8fad81f7ee6045990f48edc84542638bf07d7.tar.bz2 |
added preferences dialog, and added slidshow
Diffstat (limited to 'noncore/multimedia/showimg/ImageFileSelector.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/multimedia/showimg/ImageFileSelector.cpp | 72 |
1 files changed, 33 insertions, 39 deletions
diff --git a/noncore/multimedia/showimg/ImageFileSelector.cpp b/noncore/multimedia/showimg/ImageFileSelector.cpp index 347300f..7872c09 100644 --- a/noncore/multimedia/showimg/ImageFileSelector.cpp +++ b/noncore/multimedia/showimg/ImageFileSelector.cpp | |||
@@ -12,82 +12,81 @@ | |||
12 | #include <qwidget.h> | 12 | #include <qwidget.h> |
13 | #include <qheader.h> | 13 | #include <qheader.h> |
14 | #include <qimage.h> | 14 | #include <qimage.h> |
15 | #include <qpixmap.h> | 15 | #include <qpixmap.h> |
16 | #include <qlabel.h> | 16 | #include <qlabel.h> |
17 | #include <qfileinfo.h> | 17 | #include <qfileinfo.h> |
18 | #include <qpainter.h> | 18 | #include <qpainter.h> |
19 | #include <qscrollview.h> | 19 | #include <qscrollview.h> |
20 | 20 | ||
21 | #include "ImageFileSelector.h" | 21 | #include "ImageFileSelector.h" |
22 | 22 | ||
23 | 23 | ||
24 | 24 | ThumbWidget::ThumbWidget(QPixmap p,QString text,const DocLnk& f,QWidget *parent,int w) | |
25 | 25 | : QWidget( parent ),fl(f) | |
26 | |||
27 | ThumbWidget::ThumbWidget(QPixmap p,QString text,const DocLnk& f,QWidget *parent,int w) : QWidget( parent ),fl(f) | ||
28 | { | 26 | { |
29 | setBackgroundMode(NoBackground); | 27 | setBackgroundMode(NoBackground); |
30 | if ( w!=-1 ) | 28 | if ( w!=-1 ) |
31 | setMinimumSize(w,p.height()+24); | 29 | setMinimumSize(w,p.height()+24); |
32 | else | 30 | else |
33 | setMinimumSize(p.width(),p.height()+24); | 31 | setMinimumSize(p.width(),p.height()+24); |
34 | description=new QLabel(text,this); | 32 | description=new QLabel(text,this); |
35 | description->setBackgroundColor(colorGroup().base()); | 33 | description->setBackgroundColor(colorGroup().base()); |
36 | description->setAlignment(AlignCenter); | 34 | description->setAlignment(AlignCenter); |
37 | description->setGeometry(0,height()-24,width(),24); | 35 | description->setGeometry(0,height()-24,width(),24); |
38 | pixmap=p; | 36 | pixmap=p; |
39 | } | 37 | } |
40 | 38 | ||
41 | void ThumbWidget::resizeEvent(QResizeEvent *e) | 39 | void ThumbWidget::resizeEvent(QResizeEvent *) |
42 | { | 40 | { |
43 | description->setGeometry(0,height()-24,width(),24); | 41 | description->setGeometry(0,height()-24,width(),24); |
44 | } | 42 | } |
45 | 43 | ||
46 | void ThumbWidget::paintEvent( QPaintEvent *e ) | 44 | void ThumbWidget::paintEvent( QPaintEvent *e ) |
47 | { | 45 | { |
48 | QPainter painter(this); | 46 | QPainter painter(this); |
49 | 47 | ||
50 | painter.setClipRect(e->rect()); | 48 | painter.setClipRect(e->rect()); |
51 | painter.fillRect(0,0,width(),height(),QColor(255,255,255)); | 49 | painter.fillRect(0,0,width(),height(),QColor(255,255,255)); |
52 | painter.drawPixmap((width() - pixmap.width()) / 2,0, pixmap); | 50 | painter.drawPixmap((width() - pixmap.width()) / 2,0, pixmap); |
53 | 51 | ||
54 | } | 52 | } |
55 | 53 | ||
56 | void ThumbWidget::mouseReleaseEvent(QMouseEvent* event) | 54 | void ThumbWidget::mouseReleaseEvent(QMouseEvent* ) |
57 | { | 55 | { |
58 | emit clicked(fl); | 56 | emit clicked(fl); |
59 | } | 57 | } |
60 | 58 | ||
61 | 59 | ||
62 | 60 | ||
63 | 61 | ImageFileSelectorItem::ImageFileSelectorItem( QListView *parent, const DocLnk &f) | |
64 | ImageFileSelectorItem::ImageFileSelectorItem( QListView *parent, const DocLnk &f): QListViewItem( parent ), fl( f ) | 62 | : QListViewItem( parent ), fl( f ) |
65 | { | 63 | { |
66 | setText( 0, f.name() ); | 64 | setText( 0, f.name() ); |
67 | QFileInfo fi(f.file()); | 65 | QFileInfo fi(f.file()); |
68 | setText( 1, (fi.extension()).upper() ); | 66 | setText( 1, (fi.extension()).upper() ); |
69 | setPixmap( 0, f.pixmap() ); | 67 | setPixmap( 0, f.pixmap() ); |
70 | 68 | ||
71 | 69 | ||
72 | } | 70 | } |
73 | 71 | ||
74 | 72 | ||
75 | ImageFileSelectorItem::~ImageFileSelectorItem() | 73 | ImageFileSelectorItem::~ImageFileSelectorItem() |
76 | { | 74 | { |
77 | 75 | ||
78 | } | 76 | } |
79 | 77 | ||
80 | 78 | ||
81 | ImageFileSelector::ImageFileSelector( CURRENT_VIEW scv,QWidget *parent,const char *name ):QWidgetStack(parent) | 79 | ImageFileSelector::ImageFileSelector( CURRENT_VIEW scv,QWidget *parent,const char * ) |
80 | : QWidgetStack(parent) | ||
82 | { | 81 | { |
83 | 82 | ||
84 | detailed=new QListView(this); | 83 | detailed=new QListView(this); |
85 | 84 | ||
86 | detailed->addColumn (tr("Title")); | 85 | detailed->addColumn (tr("Title")); |
87 | detailed->addColumn (tr("Type")); | 86 | detailed->addColumn (tr("Type")); |
88 | detailed->setAllColumnsShowFocus( true ); | 87 | detailed->setAllColumnsShowFocus( true ); |
89 | 88 | ||
90 | tList.setAutoDelete(true); | 89 | tList.setAutoDelete(true); |
91 | 90 | ||
92 | thumb =new QScrollView(this); | 91 | thumb =new QScrollView(this); |
93 | thumb->setVScrollBarMode (QScrollView::Auto ); | 92 | thumb->setVScrollBarMode (QScrollView::Auto ); |
@@ -156,98 +155,93 @@ void ImageFileSelector::resizeEvent(QResizeEvent *) | |||
156 | } | 155 | } |
157 | 156 | ||
158 | void ImageFileSelector::updateSizes() | 157 | void ImageFileSelector::updateSizes() |
159 | { | 158 | { |
160 | int ww=(detailed->width()-detailed->frameWidth()*2); | 159 | int ww=(detailed->width()-detailed->frameWidth()*2); |
161 | double w=(double)ww*0.70; | 160 | double w=(double)ww*0.70; |
162 | detailed->setColumnWidth(0,(int)w); | 161 | detailed->setColumnWidth(0,(int)w); |
163 | detailed->setColumnWidth(1,ww-(int)w); | 162 | detailed->setColumnWidth(1,ww-(int)w); |
164 | background->setMinimumWidth(thumb->visibleWidth()); | 163 | background->setMinimumWidth(thumb->visibleWidth()); |
165 | thumb->updateScrollBars(); | 164 | thumb->updateScrollBars(); |
166 | } | 165 | } |
167 | 166 | ||
168 | void ImageFileSelector::reread(bool purgeCache) | 167 | void ImageFileSelector::reread(bool) |
169 | { | 168 | { |
169 | // qDebug("reread"); | ||
170 | ImageFileSelectorItem *item = (ImageFileSelectorItem *)detailed->selectedItem(); | 170 | ImageFileSelectorItem *item = (ImageFileSelectorItem *)detailed->selectedItem(); |
171 | QString oldFile; | 171 | QString oldFile; |
172 | if ( item ) | 172 | if ( item ) |
173 | oldFile = item->file().file(); | 173 | oldFile = item->file().file(); |
174 | detailed->clear(); | 174 | detailed->clear(); |
175 | tList.clear(); | 175 | tList.clear(); |
176 | DocLnkSet files; | 176 | DocLnkSet files; |
177 | Global::findDocuments(&files, "image/*"); | 177 | Global::findDocuments(&files, "image/*"); |
178 | count = files.children().count(); | 178 | count = files.children().count(); |
179 | QListIterator<DocLnk> dit( files.children() ); | 179 | QListIterator<DocLnk> dit( files.children() ); |
180 | int y=0; | 180 | // int y=0; |
181 | int x=4; | 181 | // int x=4; |
182 | int totalHeight=4; | 182 | // int totalHeight=4; |
183 | ThumbWidget *l=0; | 183 | ThumbWidget *l=0; |
184 | int width=80; | 184 | int width=80; |
185 | gl->expand(dit.count()/2,2); | 185 | gl->expand(dit.count()/2,2); |
186 | |||
187 | int i,j; | 186 | int i,j; |
188 | |||
189 | i=j=0; | 187 | i=j=0; |
190 | |||
191 | detailed->setUpdatesEnabled(false); | 188 | detailed->setUpdatesEnabled(false); |
192 | thumb->setUpdatesEnabled(false); | 189 | thumb->setUpdatesEnabled(false); |
193 | for ( ; dit.current(); ++dit ) | 190 | |
194 | { | 191 | for ( ; dit.current(); ++dit ) { |
195 | item = new ImageFileSelectorItem( detailed, **dit ); | 192 | item = new ImageFileSelectorItem( detailed, **dit ); |
196 | if ( item->file().file() == oldFile ) | 193 | if ( item->file().file() == oldFile ) |
197 | detailed->setCurrentItem( item ); | 194 | detailed->setCurrentItem( item ); |
198 | } | 195 | } |
199 | 196 | ||
200 | QListViewItemIterator it( detailed ); | 197 | QListViewItemIterator it( detailed ); |
201 | ImageFileSelectorItem *ii; | 198 | ImageFileSelectorItem *ii; |
202 | // iterate through all items of the listview | 199 | // iterate through all items of the listview |
203 | for ( ; it.current(); ++it ) | 200 | for ( ; it.current(); ++it ) { |
204 | { | ||
205 | ii=(ImageFileSelectorItem *)it.current(); | 201 | ii=(ImageFileSelectorItem *)it.current(); |
206 | QImage img(ii->file().file()); | 202 | QImage img( ii->file().file() ); |
207 | img=img.smoothScale(64,64); | 203 | if( !img.isNull()) { |
208 | QPixmap pix; | 204 | img=img.smoothScale(64,64); |
209 | pix.convertFromImage(img); | 205 | QPixmap pix; |
210 | l=new ThumbWidget(pix,ii->file().name(),ii->file(),background,width); | 206 | pix.convertFromImage(img); |
211 | l->setBackgroundColor(colorGroup().base()); | 207 | l=new ThumbWidget(pix,ii->file().name(),ii->file(),background,width); |
212 | gl->addWidget(l,j,i); | 208 | l->setBackgroundColor(colorGroup().base()); |
213 | i++; | 209 | gl->addWidget(l,j,i); |
214 | if ( i==2 ) | 210 | i++; |
215 | { | 211 | if ( i==2 ) { |
216 | i=0; | 212 | i=0; |
217 | j++; | 213 | j++; |
214 | } | ||
215 | tList.append(l); | ||
216 | connect(l,SIGNAL(clicked(const DocLnk &)),this,SLOT(thumbClicked(const DocLnk &))); | ||
218 | } | 217 | } |
219 | tList.append(l); | ||
220 | connect(l,SIGNAL(clicked(const DocLnk &)),this,SLOT(thumbClicked(const DocLnk &))); | ||
221 | |||
222 | } | 218 | } |
223 | 219 | ||
224 | |||
225 | |||
226 | if ( !detailed->selectedItem() ) | 220 | if ( !detailed->selectedItem() ) |
227 | detailed->setCurrentItem( detailed->firstChild() ); | 221 | detailed->setCurrentItem( detailed->firstChild() ); |
228 | 222 | ||
229 | detailed->setUpdatesEnabled(true); | 223 | detailed->setUpdatesEnabled(true); |
230 | thumb->setUpdatesEnabled(true); | 224 | thumb->setUpdatesEnabled(true); |
231 | detailed->update(); | 225 | detailed->update(); |
232 | thumb->update(); | 226 | thumb->update(); |
233 | |||
234 | } | 227 | } |
235 | 228 | ||
236 | int ImageFileSelector::fileCount() | 229 | int ImageFileSelector::fileCount() |
237 | { | 230 | { |
238 | return count; | 231 | return count; |
239 | } | 232 | } |
240 | const DocLnk * ImageFileSelector::selected() | 233 | const DocLnk * ImageFileSelector::selected() |
241 | { | 234 | { |
235 | qDebug("image selected"); | ||
242 | ImageFileSelectorItem *item = (ImageFileSelectorItem *) detailed->selectedItem(); | 236 | ImageFileSelectorItem *item = (ImageFileSelectorItem *) detailed->selectedItem(); |
243 | if ( item ) | 237 | if ( item ) |
244 | return new DocLnk( item->file() ); | 238 | return new DocLnk( item->file() ); |
245 | return 0; | 239 | return 0; |
246 | } | 240 | } |
247 | 241 | ||
248 | 242 | ||
249 | 243 | ||
250 | void ImageFileSelector::fileClicked( int button, QListViewItem *i, const QPoint &, int ) | 244 | void ImageFileSelector::fileClicked( int button, QListViewItem *i, const QPoint &, int ) |
251 | { | 245 | { |
252 | if ( !i ) | 246 | if ( !i ) |
253 | return; | 247 | return; |