Diffstat (limited to 'noncore/multimedia/showimg/ImageFileSelector.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/multimedia/showimg/ImageFileSelector.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/noncore/multimedia/showimg/ImageFileSelector.cpp b/noncore/multimedia/showimg/ImageFileSelector.cpp index 7872c09..d2b65a9 100644 --- a/noncore/multimedia/showimg/ImageFileSelector.cpp +++ b/noncore/multimedia/showimg/ImageFileSelector.cpp | |||
@@ -1,271 +1,271 @@ | |||
1 | 1 | ||
2 | 2 | ||
3 | #include "qpe/global.h" | 3 | #include "qpe/global.h" |
4 | #include "qpe/applnk.h" | 4 | #include "qpe/applnk.h" |
5 | #include "qpe/lnkproperties.h" | 5 | #include "qpe/lnkproperties.h" |
6 | #include "qpe/applnk.h" | 6 | #include "qpe/applnk.h" |
7 | #include "qpe/qpeapplication.h" | 7 | #include "qpe/qpeapplication.h" |
8 | 8 | ||
9 | #include <stdlib.h> | 9 | #include <stdlib.h> |
10 | 10 | ||
11 | #include <qdir.h> | 11 | #include <qdir.h> |
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 | ThumbWidget::ThumbWidget(QPixmap p,QString text,const DocLnk& f,QWidget *parent,int w) | 24 | ThumbWidget::ThumbWidget(QPixmap p,QString text,const DocLnk& f,QWidget *parent,int w) |
25 | : QWidget( parent ),fl(f) | 25 | : QWidget( parent ),fl(f) |
26 | { | 26 | { |
27 | setBackgroundMode(NoBackground); | 27 | setBackgroundMode(NoBackground); |
28 | if ( w!=-1 ) | 28 | if ( w!=-1 ) |
29 | setMinimumSize(w,p.height()+24); | 29 | setMinimumSize(w,p.height()+24); |
30 | else | 30 | else |
31 | setMinimumSize(p.width(),p.height()+24); | 31 | setMinimumSize(p.width(),p.height()+24); |
32 | description=new QLabel(text,this); | 32 | description=new QLabel(text,this); |
33 | description->setBackgroundColor(colorGroup().base()); | 33 | description->setBackgroundColor(colorGroup().base()); |
34 | description->setAlignment(AlignCenter); | 34 | description->setAlignment(AlignCenter); |
35 | description->setGeometry(0,height()-24,width(),24); | 35 | description->setGeometry(0,height()-24,width(),24); |
36 | pixmap=p; | 36 | pixmap=p; |
37 | } | 37 | } |
38 | 38 | ||
39 | void ThumbWidget::resizeEvent(QResizeEvent *) | 39 | void ThumbWidget::resizeEvent(QResizeEvent *) |
40 | { | 40 | { |
41 | description->setGeometry(0,height()-24,width(),24); | 41 | description->setGeometry(0,height()-24,width(),24); |
42 | } | 42 | } |
43 | 43 | ||
44 | void ThumbWidget::paintEvent( QPaintEvent *e ) | 44 | void ThumbWidget::paintEvent( QPaintEvent *e ) |
45 | { | 45 | { |
46 | QPainter painter(this); | 46 | QPainter painter(this); |
47 | 47 | ||
48 | painter.setClipRect(e->rect()); | 48 | painter.setClipRect(e->rect()); |
49 | painter.fillRect(0,0,width(),height(),QColor(255,255,255)); | 49 | painter.fillRect(0,0,width(),height(),QColor(255,255,255)); |
50 | painter.drawPixmap((width() - pixmap.width()) / 2,0, pixmap); | 50 | painter.drawPixmap((width() - pixmap.width()) / 2,0, pixmap); |
51 | 51 | ||
52 | } | 52 | } |
53 | 53 | ||
54 | void ThumbWidget::mouseReleaseEvent(QMouseEvent* ) | 54 | void ThumbWidget::mouseReleaseEvent(QMouseEvent* ) |
55 | { | 55 | { |
56 | emit clicked(fl); | 56 | emit clicked(fl); |
57 | } | 57 | } |
58 | 58 | ||
59 | 59 | ||
60 | 60 | ||
61 | ImageFileSelectorItem::ImageFileSelectorItem( QListView *parent, const DocLnk &f) | 61 | ImageFileSelectorItem::ImageFileSelectorItem( QListView *parent, const DocLnk &f) |
62 | : QListViewItem( parent ), fl( f ) | 62 | : QListViewItem( parent ), fl( f ) |
63 | { | 63 | { |
64 | setText( 0, f.name() ); | 64 | setText( 0, f.name() ); |
65 | QFileInfo fi(f.file()); | 65 | QFileInfo fi(f.file()); |
66 | setText( 1, (fi.extension()).upper() ); | 66 | setText( 1, (fi.extension()).upper() ); |
67 | setPixmap( 0, f.pixmap() ); | 67 | setPixmap( 0, f.pixmap() ); |
68 | 68 | ||
69 | 69 | ||
70 | } | 70 | } |
71 | 71 | ||
72 | 72 | ||
73 | ImageFileSelectorItem::~ImageFileSelectorItem() | 73 | ImageFileSelectorItem::~ImageFileSelectorItem() |
74 | { | 74 | { |
75 | 75 | ||
76 | } | 76 | } |
77 | 77 | ||
78 | 78 | ||
79 | ImageFileSelector::ImageFileSelector( CURRENT_VIEW scv,QWidget *parent,const char * ) | 79 | ImageFileSelector::ImageFileSelector( CURRENT_VIEW scv,QWidget *parent,const char * ) |
80 | : QWidgetStack(parent) | 80 | : QWidgetStack(parent) |
81 | { | 81 | { |
82 | 82 | ||
83 | detailed=new QListView(this); | 83 | detailed=new QListView(this); |
84 | 84 | ||
85 | detailed->addColumn (tr("Title")); | 85 | detailed->addColumn (tr("Title")); |
86 | detailed->addColumn (tr("Type")); | 86 | detailed->addColumn (tr("Type")); |
87 | detailed->setAllColumnsShowFocus( true ); | 87 | detailed->setAllColumnsShowFocus( true ); |
88 | 88 | ||
89 | tList.setAutoDelete(true); | 89 | tList.setAutoDelete(true); |
90 | 90 | ||
91 | thumb =new QScrollView(this); | 91 | thumb =new QScrollView(this); |
92 | thumb->setVScrollBarMode (QScrollView::Auto ); | 92 | thumb->setVScrollBarMode (QScrollView::Auto ); |
93 | thumb->viewport()->setBackgroundColor(colorGroup().base()); | 93 | thumb->viewport()->setBackgroundColor(colorGroup().base()); |
94 | 94 | ||
95 | background=new QWidget(0); | 95 | background=new QWidget(0); |
96 | background->setBackgroundColor(colorGroup().base()); | 96 | background->setBackgroundColor(colorGroup().base()); |
97 | thumb->addChild(background); | 97 | thumb->addChild(background); |
98 | gl = new QGridLayout(background,1,2,4,4); | 98 | gl = new QGridLayout(background,1,2,4,4); |
99 | 99 | ||
100 | 100 | ||
101 | 101 | ||
102 | connect( detailed, SIGNAL( mouseButtonClicked( int, QListViewItem *, const QPoint &, int ) ), | 102 | connect( detailed, SIGNAL( mouseButtonClicked(int,QListViewItem*,const QPoint&,int) ), |
103 | this, SLOT( fileClicked( int, QListViewItem *, const QPoint &, int ) ) ); | 103 | this, SLOT( fileClicked(int,QListViewItem*,const QPoint&,int) ) ); |
104 | connect( detailed, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint &, int ) ), | 104 | connect( detailed, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ), |
105 | this, SLOT( filePressed( int, QListViewItem *, const QPoint &, int ) ) ); | 105 | this, SLOT( filePressed(int,QListViewItem*,const QPoint&,int) ) ); |
106 | connect( detailed, SIGNAL( returnPressed( QListViewItem * ) ), | 106 | connect( detailed, SIGNAL( returnPressed(QListViewItem*) ), |
107 | this, SLOT( fileClicked( QListViewItem * ) ) ); | 107 | this, SLOT( fileClicked(QListViewItem*) ) ); |
108 | 108 | ||
109 | cView=UNKNOWN; | 109 | cView=UNKNOWN; |
110 | setView(scv); | 110 | setView(scv); |
111 | reread(); | 111 | reread(); |
112 | 112 | ||
113 | } | 113 | } |
114 | ImageFileSelector::~ImageFileSelector() | 114 | ImageFileSelector::~ImageFileSelector() |
115 | { | 115 | { |
116 | 116 | ||
117 | } | 117 | } |
118 | 118 | ||
119 | 119 | ||
120 | void ImageFileSelector::switchView() | 120 | void ImageFileSelector::switchView() |
121 | { | 121 | { |
122 | CURRENT_VIEW v=cView; | 122 | CURRENT_VIEW v=cView; |
123 | 123 | ||
124 | if ( v==DETAILED ) | 124 | if ( v==DETAILED ) |
125 | v=THUMBNAIL; | 125 | v=THUMBNAIL; |
126 | else | 126 | else |
127 | v=DETAILED; | 127 | v=DETAILED; |
128 | setView(v); | 128 | setView(v); |
129 | } | 129 | } |
130 | 130 | ||
131 | void ImageFileSelector::setView(CURRENT_VIEW v) | 131 | void ImageFileSelector::setView(CURRENT_VIEW v) |
132 | { | 132 | { |
133 | 133 | ||
134 | if ( v==cView ) | 134 | if ( v==cView ) |
135 | return; | 135 | return; |
136 | cView=v; | 136 | cView=v; |
137 | 137 | ||
138 | if ( cView!=DETAILED ) | 138 | if ( cView!=DETAILED ) |
139 | { | 139 | { |
140 | raiseWidget(thumb); | 140 | raiseWidget(thumb); |
141 | updateSizes(); | 141 | updateSizes(); |
142 | } | 142 | } |
143 | else | 143 | else |
144 | { | 144 | { |
145 | raiseWidget(detailed); | 145 | raiseWidget(detailed); |
146 | updateSizes(); | 146 | updateSizes(); |
147 | } | 147 | } |
148 | 148 | ||
149 | 149 | ||
150 | } | 150 | } |
151 | 151 | ||
152 | void ImageFileSelector::resizeEvent(QResizeEvent *) | 152 | void ImageFileSelector::resizeEvent(QResizeEvent *) |
153 | { | 153 | { |
154 | updateSizes(); | 154 | updateSizes(); |
155 | } | 155 | } |
156 | 156 | ||
157 | void ImageFileSelector::updateSizes() | 157 | void ImageFileSelector::updateSizes() |
158 | { | 158 | { |
159 | int ww=(detailed->width()-detailed->frameWidth()*2); | 159 | int ww=(detailed->width()-detailed->frameWidth()*2); |
160 | double w=(double)ww*0.70; | 160 | double w=(double)ww*0.70; |
161 | detailed->setColumnWidth(0,(int)w); | 161 | detailed->setColumnWidth(0,(int)w); |
162 | detailed->setColumnWidth(1,ww-(int)w); | 162 | detailed->setColumnWidth(1,ww-(int)w); |
163 | background->setMinimumWidth(thumb->visibleWidth()); | 163 | background->setMinimumWidth(thumb->visibleWidth()); |
164 | thumb->updateScrollBars(); | 164 | thumb->updateScrollBars(); |
165 | } | 165 | } |
166 | 166 | ||
167 | void ImageFileSelector::reread(bool) | 167 | void ImageFileSelector::reread(bool) |
168 | { | 168 | { |
169 | // qDebug("reread"); | 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 | int i,j; | 186 | int i,j; |
187 | i=j=0; | 187 | i=j=0; |
188 | detailed->setUpdatesEnabled(false); | 188 | detailed->setUpdatesEnabled(false); |
189 | thumb->setUpdatesEnabled(false); | 189 | thumb->setUpdatesEnabled(false); |
190 | 190 | ||
191 | for ( ; dit.current(); ++dit ) { | 191 | for ( ; dit.current(); ++dit ) { |
192 | item = new ImageFileSelectorItem( detailed, **dit ); | 192 | item = new ImageFileSelectorItem( detailed, **dit ); |
193 | if ( item->file().file() == oldFile ) | 193 | if ( item->file().file() == oldFile ) |
194 | detailed->setCurrentItem( item ); | 194 | detailed->setCurrentItem( item ); |
195 | } | 195 | } |
196 | 196 | ||
197 | QListViewItemIterator it( detailed ); | 197 | QListViewItemIterator it( detailed ); |
198 | ImageFileSelectorItem *ii; | 198 | ImageFileSelectorItem *ii; |
199 | // iterate through all items of the listview | 199 | // iterate through all items of the listview |
200 | for ( ; it.current(); ++it ) { | 200 | for ( ; it.current(); ++it ) { |
201 | ii=(ImageFileSelectorItem *)it.current(); | 201 | ii=(ImageFileSelectorItem *)it.current(); |
202 | QImage img( ii->file().file() ); | 202 | QImage img( ii->file().file() ); |
203 | if( !img.isNull()) { | 203 | if( !img.isNull()) { |
204 | img=img.smoothScale(64,64); | 204 | img=img.smoothScale(64,64); |
205 | QPixmap pix; | 205 | QPixmap pix; |
206 | pix.convertFromImage(img); | 206 | pix.convertFromImage(img); |
207 | l=new ThumbWidget(pix,ii->file().name(),ii->file(),background,width); | 207 | l=new ThumbWidget(pix,ii->file().name(),ii->file(),background,width); |
208 | l->setBackgroundColor(colorGroup().base()); | 208 | l->setBackgroundColor(colorGroup().base()); |
209 | gl->addWidget(l,j,i); | 209 | gl->addWidget(l,j,i); |
210 | i++; | 210 | i++; |
211 | if ( i==2 ) { | 211 | if ( i==2 ) { |
212 | i=0; | 212 | i=0; |
213 | j++; | 213 | j++; |
214 | } | 214 | } |
215 | tList.append(l); | 215 | tList.append(l); |
216 | connect(l,SIGNAL(clicked(const DocLnk &)),this,SLOT(thumbClicked(const DocLnk &))); | 216 | connect(l,SIGNAL(clicked(const DocLnk&)),this,SLOT(thumbClicked(const DocLnk&))); |
217 | } | 217 | } |
218 | } | 218 | } |
219 | 219 | ||
220 | if ( !detailed->selectedItem() ) | 220 | if ( !detailed->selectedItem() ) |
221 | detailed->setCurrentItem( detailed->firstChild() ); | 221 | detailed->setCurrentItem( detailed->firstChild() ); |
222 | 222 | ||
223 | detailed->setUpdatesEnabled(true); | 223 | detailed->setUpdatesEnabled(true); |
224 | thumb->setUpdatesEnabled(true); | 224 | thumb->setUpdatesEnabled(true); |
225 | detailed->update(); | 225 | detailed->update(); |
226 | thumb->update(); | 226 | thumb->update(); |
227 | } | 227 | } |
228 | 228 | ||
229 | int ImageFileSelector::fileCount() | 229 | int ImageFileSelector::fileCount() |
230 | { | 230 | { |
231 | return count; | 231 | return count; |
232 | } | 232 | } |
233 | const DocLnk * ImageFileSelector::selected() | 233 | const DocLnk * ImageFileSelector::selected() |
234 | { | 234 | { |
235 | qDebug("image selected"); | 235 | qDebug("image selected"); |
236 | ImageFileSelectorItem *item = (ImageFileSelectorItem *) detailed->selectedItem(); | 236 | ImageFileSelectorItem *item = (ImageFileSelectorItem *) detailed->selectedItem(); |
237 | if ( item ) | 237 | if ( item ) |
238 | return new DocLnk( item->file() ); | 238 | return new DocLnk( item->file() ); |
239 | return 0; | 239 | return 0; |
240 | } | 240 | } |
241 | 241 | ||
242 | 242 | ||
243 | 243 | ||
244 | void ImageFileSelector::fileClicked( int button, QListViewItem *i, const QPoint &, int ) | 244 | void ImageFileSelector::fileClicked( int button, QListViewItem *i, const QPoint &, int ) |
245 | { | 245 | { |
246 | if ( !i ) | 246 | if ( !i ) |
247 | return; | 247 | return; |
248 | if ( button == Qt::LeftButton ) | 248 | if ( button == Qt::LeftButton ) |
249 | { | 249 | { |
250 | fileClicked( i ); | 250 | fileClicked( i ); |
251 | } | 251 | } |
252 | } | 252 | } |
253 | // pressed to get 'right down' | 253 | // pressed to get 'right down' |
254 | void ImageFileSelector::filePressed( int, QListViewItem *, const QPoint &, int ) | 254 | void ImageFileSelector::filePressed( int, QListViewItem *, const QPoint &, int ) |
255 | { | 255 | { |
256 | 256 | ||
257 | } | 257 | } |
258 | void ImageFileSelector::fileClicked( QListViewItem *i) | 258 | void ImageFileSelector::fileClicked( QListViewItem *i) |
259 | { | 259 | { |
260 | if ( !i ) | 260 | if ( !i ) |
261 | return; | 261 | return; |
262 | emit fileSelected( ( (ImageFileSelectorItem*)i )->file() ); | 262 | emit fileSelected( ( (ImageFileSelectorItem*)i )->file() ); |
263 | emit closeMe(); | 263 | emit closeMe(); |
264 | } | 264 | } |
265 | 265 | ||
266 | void ImageFileSelector::thumbClicked(const DocLnk &f) | 266 | void ImageFileSelector::thumbClicked(const DocLnk &f) |
267 | { | 267 | { |
268 | emit fileSelected( f ); | 268 | emit fileSelected( f ); |
269 | emit closeMe(); | 269 | emit closeMe(); |
270 | } | 270 | } |
271 | 271 | ||