-rw-r--r-- | core/launcher/launcherview.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/core/launcher/launcherview.cpp b/core/launcher/launcherview.cpp index 30afe64..0ced256 100644 --- a/core/launcher/launcherview.cpp +++ b/core/launcher/launcherview.cpp | |||
@@ -122,480 +122,480 @@ public: | |||
122 | void addCatsAndMimes(AppLnk* app) | 122 | void addCatsAndMimes(AppLnk* app) |
123 | { | 123 | { |
124 | // QStringList c = app->categories(); | 124 | // QStringList c = app->categories(); |
125 | // for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) { | 125 | // for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) { |
126 | // cats.replace(*cit,(void*)1); | 126 | // cats.replace(*cit,(void*)1); |
127 | // } | 127 | // } |
128 | QString maj=app->type(); | 128 | QString maj=app->type(); |
129 | int sl=maj.find('/'); | 129 | int sl=maj.find('/'); |
130 | if (sl>=0) { | 130 | if (sl>=0) { |
131 | QString k = maj.left(sl); | 131 | QString k = maj.left(sl); |
132 | mimes.replace(k,(void*)1); | 132 | mimes.replace(k,(void*)1); |
133 | } | 133 | } |
134 | } | 134 | } |
135 | 135 | ||
136 | void drawBackground( QPainter *p, const QRect &r ) | 136 | void drawBackground( QPainter *p, const QRect &r ) |
137 | { | 137 | { |
138 | Config config("qpe"); | 138 | Config config("qpe"); |
139 | config.setGroup("Appearance"); | 139 | config.setGroup("Appearance"); |
140 | QString backgroundImage = config.readEntry("BackgroundImage","launcher/opie-background"); | 140 | QString backgroundImage = config.readEntry("BackgroundImage","launcher/opie-background"); |
141 | // if (backgroundImage.isNull()) backgroundImage="launcher/opie-background"; | 141 | // if (backgroundImage.isNull()) backgroundImage="launcher/opie-background"; |
142 | int backgroundMode = QPixmap::defaultDepth() >= 12 ? 1 : 0; | 142 | int backgroundMode = QPixmap::defaultDepth() >= 12 ? 1 : 0; |
143 | //int backgroundMode = 2; | 143 | //int backgroundMode = 2; |
144 | 144 | ||
145 | if ( backgroundMode == 1 ) { | 145 | if ( backgroundMode == 1 ) { |
146 | 146 | ||
147 | // Double buffer the background | 147 | // Double buffer the background |
148 | static QPixmap *bg = NULL; | 148 | static QPixmap *bg = NULL; |
149 | static QColor bgColor; | 149 | static QColor bgColor; |
150 | 150 | ||
151 | if ( (bg == NULL) || (bgColor != colorGroup().button()) ) { | 151 | if ( (bg == NULL) || (bgColor != colorGroup().button()) ) { |
152 | // Create a new background double buffer | 152 | // Create a new background double buffer |
153 | if (bg == NULL) | 153 | if (bg == NULL) |
154 | bg = new QPixmap( width(), height() ); | 154 | bg = new QPixmap( width(), height() ); |
155 | bgColor = colorGroup().button(); | 155 | bgColor = colorGroup().button(); |
156 | QPainter painter( bg ); | 156 | QPainter painter( bg ); |
157 | 157 | ||
158 | // painter.fillRect( QRect( 0, 0, width(), height() ), colorGroup().background().light(110)); | 158 | // painter.fillRect( QRect( 0, 0, width(), height() ), colorGroup().background().light(110)); |
159 | painter.fillRect( QRect( 0, 0, width(), height() ), background); | 159 | painter.fillRect( QRect( 0, 0, width(), height() ), background); |
160 | // Overlay the Qtopia logo in the center | 160 | // Overlay the Qtopia logo in the center |
161 | QImage logo; | 161 | QImage logo; |
162 | if (QFile::exists(backgroundImage)) { | 162 | if (QFile::exists(backgroundImage)) { |
163 | logo = QImage(backgroundImage); | 163 | logo = QImage(backgroundImage); |
164 | } else { | 164 | } else { |
165 | logo = Resource::loadImage(backgroundImage ); | 165 | logo = Resource::loadImage(backgroundImage ); |
166 | } | 166 | } |
167 | if ( !logo.isNull() && config.readBoolEntry( "UseBackgroundImage", TRUE ) ) | 167 | if ( !logo.isNull() && config.readBoolEntry( "UseBackgroundImage", TRUE ) ) |
168 | painter.drawImage( (width() - logo.width()) / 2, | 168 | painter.drawImage( (width() - logo.width()) / 2, |
169 | (height() - logo.height()) / 2, logo ); | 169 | (height() - logo.height()) / 2, logo ); |
170 | } | 170 | } |
171 | 171 | ||
172 | // Draw the double buffer to the widget (it is tiled for when the icon view is large) | 172 | // Draw the double buffer to the widget (it is tiled for when the icon view is large) |
173 | p->drawTiledPixmap( r, *bg, QPoint( (r.x() + contentsX()) % bg->width(), | 173 | p->drawTiledPixmap( r, *bg, QPoint( (r.x() + contentsX()) % bg->width(), |
174 | (r.y() + contentsY()) % bg->height() ) ); | 174 | (r.y() + contentsY()) % bg->height() ) ); |
175 | } else if ( backgroundMode == 2 ) { | 175 | } else if ( backgroundMode == 2 ) { |
176 | static QPixmap *bg = 0; | 176 | static QPixmap *bg = 0; |
177 | static QColor bgColor; | 177 | static QColor bgColor; |
178 | if ( !bg || (bgColor != colorGroup().background()) ) { | 178 | if ( !bg || (bgColor != colorGroup().background()) ) { |
179 | bgColor = colorGroup().background(); | 179 | bgColor = colorGroup().background(); |
180 | bg = new QPixmap( width(), 9 ); | 180 | bg = new QPixmap( width(), 9 ); |
181 | QPainter painter( bg ); | 181 | QPainter painter( bg ); |
182 | for ( int i = 0; i < 3; i++ ) { | 182 | for ( int i = 0; i < 3; i++ ) { |
183 | painter.setPen( colorGroup().background().light(130) ); | 183 | painter.setPen( colorGroup().background().light(130) ); |
184 | painter.drawLine( 0, i*3, width()-1, i*3 ); | 184 | painter.drawLine( 0, i*3, width()-1, i*3 ); |
185 | painter.drawLine( 0, i*3+1, width()-1, i*3+1 ); | 185 | painter.drawLine( 0, i*3+1, width()-1, i*3+1 ); |
186 | painter.setPen( colorGroup().background().light(105) ); | 186 | painter.setPen( colorGroup().background().light(105) ); |
187 | painter.drawLine( 0, i*3+2, width()-1, i*3+2 ); | 187 | painter.drawLine( 0, i*3+2, width()-1, i*3+2 ); |
188 | } | 188 | } |
189 | } | 189 | } |
190 | p->drawTiledPixmap( r, *bg, QPoint( (r.x() + contentsX()) % bg->width(), | 190 | p->drawTiledPixmap( r, *bg, QPoint( (r.x() + contentsX()) % bg->width(), |
191 | (r.y() + contentsY()) % bg->height() ) ); | 191 | (r.y() + contentsY()) % bg->height() ) ); |
192 | } else { | 192 | } else { |
193 | p->fillRect( r, QBrush( colorGroup().background().light(110) ) ); | 193 | p->fillRect( r, QBrush( colorGroup().background().light(110) ) ); |
194 | } | 194 | } |
195 | } | 195 | } |
196 | 196 | ||
197 | void hideOrShowItems(bool resort); | 197 | void hideOrShowItems(bool resort); |
198 | 198 | ||
199 | void setTypeFilter(const QString& typefilter, bool resort) | 199 | void setTypeFilter(const QString& typefilter, bool resort) |
200 | { | 200 | { |
201 | tf = QRegExp(typefilter,FALSE,TRUE); | 201 | tf = QRegExp(typefilter,FALSE,TRUE); |
202 | hideOrShowItems(resort); | 202 | hideOrShowItems(resort); |
203 | } | 203 | } |
204 | 204 | ||
205 | void setCategoryFilter( int catfilter, bool resort ) | 205 | void setCategoryFilter( int catfilter, bool resort ) |
206 | { | 206 | { |
207 | Categories cat; | 207 | Categories cat; |
208 | cat.load( categoryFileName() ); | 208 | cat.load( categoryFileName() ); |
209 | QString str; | 209 | QString str; |
210 | if ( catfilter == -2 ) | 210 | if ( catfilter == -2 ) |
211 | cf = 0; | 211 | cf = 0; |
212 | else | 212 | else |
213 | cf = catfilter; | 213 | cf = catfilter; |
214 | hideOrShowItems(resort); | 214 | hideOrShowItems(resort); |
215 | } | 215 | } |
216 | 216 | ||
217 | enum SortMethod { Name, Date, Type }; | 217 | enum SortMethod { Name, Date, Type }; |
218 | 218 | ||
219 | void setSortMethod( SortMethod m ) | 219 | void setSortMethod( SortMethod m ) |
220 | { | 220 | { |
221 | if ( sortmeth != m ) { | 221 | if ( sortmeth != m ) { |
222 | sortmeth = m; | 222 | sortmeth = m; |
223 | sort(); | 223 | sort(); |
224 | } | 224 | } |
225 | } | 225 | } |
226 | 226 | ||
227 | int compare(const AppLnk* a, const AppLnk* b) | 227 | int compare(const AppLnk* a, const AppLnk* b) |
228 | { | 228 | { |
229 | switch (sortmeth) { | 229 | switch (sortmeth) { |
230 | case Name: | 230 | case Name: |
231 | return a->name().compare(b->name()); | 231 | return a->name().compare(b->name()); |
232 | case Date: { | 232 | case Date: { |
233 | QFileInfo fa(a->linkFileKnown() ? a->linkFile() : a->file()); | 233 | QFileInfo fa(a->linkFileKnown() ? a->linkFile() : a->file()); |
234 | QFileInfo fb(b->linkFileKnown() ? b->linkFile() : b->file()); | 234 | QFileInfo fb(b->linkFileKnown() ? b->linkFile() : b->file()); |
235 | return fa.lastModified().secsTo(fb.lastModified()); | 235 | return fa.lastModified().secsTo(fb.lastModified()); |
236 | } | 236 | } |
237 | case Type: | 237 | case Type: |
238 | return a->type().compare(b->type()); | 238 | return a->type().compare(b->type()); |
239 | } | 239 | } |
240 | return 0; | 240 | return 0; |
241 | } | 241 | } |
242 | 242 | ||
243 | protected: | 243 | protected: |
244 | 244 | ||
245 | void styleChange( QStyle &old ) | 245 | void styleChange( QStyle &old ) |
246 | { | 246 | { |
247 | QIconView::styleChange( old ); | 247 | QIconView::styleChange( old ); |
248 | //### duplicated code from LauncherView constructor | 248 | //### duplicated code from LauncherView constructor |
249 | int dw = QApplication::desktop()->width(); | 249 | int dw = QApplication::desktop()->width(); |
250 | setGridX( (dw-13-style().scrollBarExtent().width())/3 ); // tweaked for 8pt+dw=176 and 10pt+dw=240 | 250 | setGridX( (dw-13-style().scrollBarExtent().width())/ (dw/80) ); // tweaked for 8pt+dw=176 and 10pt+dw=240 |
251 | } | 251 | } |
252 | 252 | ||
253 | private: | 253 | private: |
254 | QList<AppLnk> hidden; | 254 | QList<AppLnk> hidden; |
255 | QDict<void> mimes; | 255 | QDict<void> mimes; |
256 | QDict<void> cats; | 256 | QDict<void> cats; |
257 | SortMethod sortmeth; | 257 | SortMethod sortmeth; |
258 | QRegExp tf; | 258 | QRegExp tf; |
259 | int cf; | 259 | int cf; |
260 | QIconViewItem* bsy; | 260 | QIconViewItem* bsy; |
261 | bool ike; | 261 | bool ike; |
262 | 262 | ||
263 | }; | 263 | }; |
264 | 264 | ||
265 | 265 | ||
266 | bool LauncherView::bsy=FALSE; | 266 | bool LauncherView::bsy=FALSE; |
267 | 267 | ||
268 | void LauncherView::setBusy(bool on) | 268 | void LauncherView::setBusy(bool on) |
269 | { | 269 | { |
270 | icons->setBusy(on); | 270 | icons->setBusy(on); |
271 | } | 271 | } |
272 | 272 | ||
273 | class LauncherItem : public QIconViewItem | 273 | class LauncherItem : public QIconViewItem |
274 | { | 274 | { |
275 | public: | 275 | public: |
276 | LauncherItem( QIconView *parent, AppLnk* applnk ); | 276 | LauncherItem( QIconView *parent, AppLnk* applnk ); |
277 | ~LauncherItem() | 277 | ~LauncherItem() |
278 | { | 278 | { |
279 | LauncherIconView* liv = (LauncherIconView*)iconView(); | 279 | LauncherIconView* liv = (LauncherIconView*)iconView(); |
280 | if ( liv->busyItem() == this ) | 280 | if ( liv->busyItem() == this ) |
281 | liv->setBusy(FALSE); | 281 | liv->setBusy(FALSE); |
282 | delete app; | 282 | delete app; |
283 | } | 283 | } |
284 | 284 | ||
285 | AppLnk* appLnk() const { return app; } | 285 | AppLnk* appLnk() const { return app; } |
286 | AppLnk* takeAppLnk() { AppLnk* r=app; app=0; return r; } | 286 | AppLnk* takeAppLnk() { AppLnk* r=app; app=0; return r; } |
287 | 287 | ||
288 | virtual int compare ( QIconViewItem * i ) const; | 288 | virtual int compare ( QIconViewItem * i ) const; |
289 | 289 | ||
290 | void paintItem( QPainter *p, const QColorGroup &cg ) | 290 | void paintItem( QPainter *p, const QColorGroup &cg ) |
291 | { | 291 | { |
292 | LauncherIconView* liv = (LauncherIconView*)iconView(); | 292 | LauncherIconView* liv = (LauncherIconView*)iconView(); |
293 | QBrush oldBrush( liv->itemTextBackground() ); | 293 | QBrush oldBrush( liv->itemTextBackground() ); |
294 | QColorGroup mycg( cg ); | 294 | QColorGroup mycg( cg ); |
295 | if ( liv->currentItem() == this ) { | 295 | if ( liv->currentItem() == this ) { |
296 | liv->setItemTextBackground( cg.brush( QColorGroup::Highlight ) ); | 296 | liv->setItemTextBackground( cg.brush( QColorGroup::Highlight ) ); |
297 | mycg.setColor( QColorGroup::Text, cg.color( QColorGroup::HighlightedText ) ); | 297 | mycg.setColor( QColorGroup::Text, cg.color( QColorGroup::HighlightedText ) ); |
298 | } | 298 | } |
299 | else { | 299 | else { |
300 | mycg.setColor( QColorGroup::Text, liv->iconText ); | 300 | mycg.setColor( QColorGroup::Text, liv->iconText ); |
301 | } | 301 | } |
302 | 302 | ||
303 | QIconViewItem::paintItem(p,mycg); | 303 | QIconViewItem::paintItem(p,mycg); |
304 | if ( liv->currentItem() == this ) | 304 | if ( liv->currentItem() == this ) |
305 | liv->setItemTextBackground( oldBrush ); | 305 | liv->setItemTextBackground( oldBrush ); |
306 | if ( liv->busyItem() == this ) { | 306 | if ( liv->busyItem() == this ) { |
307 | static QPixmap* busypm=0; | 307 | static QPixmap* busypm=0; |
308 | if ( !busypm ) | 308 | if ( !busypm ) |
309 | busypm = new QPixmap(Resource::loadPixmap("launching")); | 309 | busypm = new QPixmap(Resource::loadPixmap("launching")); |
310 | p->drawPixmap(x()+(width()-busypm->width())/2, y(),*busypm); | 310 | p->drawPixmap(x()+(width()-busypm->width())/2, y(),*busypm); |
311 | } | 311 | } |
312 | } | 312 | } |
313 | 313 | ||
314 | protected: | 314 | protected: |
315 | AppLnk* app; | 315 | AppLnk* app; |
316 | }; | 316 | }; |
317 | 317 | ||
318 | 318 | ||
319 | LauncherItem::LauncherItem( QIconView *parent, AppLnk *applnk ) | 319 | LauncherItem::LauncherItem( QIconView *parent, AppLnk *applnk ) |
320 | : QIconViewItem( parent, applnk->name(), applnk->bigPixmap() ), | 320 | : QIconViewItem( parent, applnk->name(), applnk->bigPixmap() ), |
321 | app(applnk) // Takes ownership | 321 | app(applnk) // Takes ownership |
322 | { | 322 | { |
323 | } | 323 | } |
324 | 324 | ||
325 | int LauncherItem::compare ( QIconViewItem * i ) const | 325 | int LauncherItem::compare ( QIconViewItem * i ) const |
326 | { | 326 | { |
327 | LauncherIconView* view = (LauncherIconView*)iconView(); | 327 | LauncherIconView* view = (LauncherIconView*)iconView(); |
328 | return view->compare(app,((LauncherItem *)i)->appLnk()); | 328 | return view->compare(app,((LauncherItem *)i)->appLnk()); |
329 | } | 329 | } |
330 | 330 | ||
331 | QStringList LauncherIconView::mimeTypes() const | 331 | QStringList LauncherIconView::mimeTypes() const |
332 | { | 332 | { |
333 | QStringList r; | 333 | QStringList r; |
334 | QDictIterator<void> it(mimes); | 334 | QDictIterator<void> it(mimes); |
335 | while (it.current()) { | 335 | while (it.current()) { |
336 | r.append(it.currentKey()); | 336 | r.append(it.currentKey()); |
337 | ++it; | 337 | ++it; |
338 | } | 338 | } |
339 | r.sort(); | 339 | r.sort(); |
340 | return r; | 340 | return r; |
341 | } | 341 | } |
342 | 342 | ||
343 | void LauncherIconView::addItem(AppLnk* app, bool resort) | 343 | void LauncherIconView::addItem(AppLnk* app, bool resort) |
344 | { | 344 | { |
345 | addCatsAndMimes(app); | 345 | addCatsAndMimes(app); |
346 | 346 | ||
347 | if ( (tf.isEmpty() || tf.match(app->type()) >= 0) | 347 | if ( (tf.isEmpty() || tf.match(app->type()) >= 0) |
348 | && (cf == 0 || app->categories().contains(cf) | 348 | && (cf == 0 || app->categories().contains(cf) |
349 | || cf == -1 && app->categories().count() == 0 ) ) | 349 | || cf == -1 && app->categories().count() == 0 ) ) |
350 | (void) new LauncherItem( this, app ); | 350 | (void) new LauncherItem( this, app ); |
351 | else | 351 | else |
352 | hidden.append(app); | 352 | hidden.append(app); |
353 | if ( resort ) | 353 | if ( resort ) |
354 | sort(); | 354 | sort(); |
355 | } | 355 | } |
356 | 356 | ||
357 | void LauncherIconView::updateCategoriesAndMimeTypes() | 357 | void LauncherIconView::updateCategoriesAndMimeTypes() |
358 | { | 358 | { |
359 | mimes.clear(); | 359 | mimes.clear(); |
360 | cats.clear(); | 360 | cats.clear(); |
361 | LauncherItem* item = (LauncherItem*)firstItem(); | 361 | LauncherItem* item = (LauncherItem*)firstItem(); |
362 | while (item) { | 362 | while (item) { |
363 | addCatsAndMimes(item->appLnk()); | 363 | addCatsAndMimes(item->appLnk()); |
364 | item = (LauncherItem*)item->nextItem(); | 364 | item = (LauncherItem*)item->nextItem(); |
365 | } | 365 | } |
366 | QListIterator<AppLnk> it(hidden); | 366 | QListIterator<AppLnk> it(hidden); |
367 | AppLnk* l; | 367 | AppLnk* l; |
368 | while ((l=it.current())) { | 368 | while ((l=it.current())) { |
369 | addCatsAndMimes(l); | 369 | addCatsAndMimes(l); |
370 | ++it; | 370 | ++it; |
371 | } | 371 | } |
372 | } | 372 | } |
373 | 373 | ||
374 | void LauncherIconView::hideOrShowItems(bool resort) | 374 | void LauncherIconView::hideOrShowItems(bool resort) |
375 | { | 375 | { |
376 | hidden.setAutoDelete(FALSE); | 376 | hidden.setAutoDelete(FALSE); |
377 | QList<AppLnk> links=hidden; | 377 | QList<AppLnk> links=hidden; |
378 | hidden.clear(); | 378 | hidden.clear(); |
379 | hidden.setAutoDelete(TRUE); | 379 | hidden.setAutoDelete(TRUE); |
380 | LauncherItem* item = (LauncherItem*)firstItem(); | 380 | LauncherItem* item = (LauncherItem*)firstItem(); |
381 | while (item) { | 381 | while (item) { |
382 | links.append(item->takeAppLnk()); | 382 | links.append(item->takeAppLnk()); |
383 | item = (LauncherItem*)item->nextItem(); | 383 | item = (LauncherItem*)item->nextItem(); |
384 | } | 384 | } |
385 | bool oldAutoArrange = autoArrange(); | 385 | bool oldAutoArrange = autoArrange(); |
386 | setAutoArrange( FALSE ); | 386 | setAutoArrange( FALSE ); |
387 | clear(); | 387 | clear(); |
388 | QListIterator<AppLnk> it(links); | 388 | QListIterator<AppLnk> it(links); |
389 | AppLnk* l; | 389 | AppLnk* l; |
390 | while ((l=it.current())) { | 390 | while ((l=it.current())) { |
391 | addItem(l,FALSE); | 391 | addItem(l,FALSE); |
392 | ++it; | 392 | ++it; |
393 | } | 393 | } |
394 | if ( resort ) | 394 | if ( resort ) |
395 | sort(); | 395 | sort(); |
396 | setAutoArrange( oldAutoArrange ); | 396 | setAutoArrange( oldAutoArrange ); |
397 | } | 397 | } |
398 | 398 | ||
399 | bool LauncherIconView::removeLink(const QString& linkfile) | 399 | bool LauncherIconView::removeLink(const QString& linkfile) |
400 | { | 400 | { |
401 | LauncherItem* item = (LauncherItem*)firstItem(); | 401 | LauncherItem* item = (LauncherItem*)firstItem(); |
402 | AppLnk* l; | 402 | AppLnk* l; |
403 | bool did = FALSE; | 403 | bool did = FALSE; |
404 | DocLnk dl(linkfile); | 404 | DocLnk dl(linkfile); |
405 | while (item) { | 405 | while (item) { |
406 | l = item->appLnk(); | 406 | l = item->appLnk(); |
407 | if ( l->linkFileKnown() && l->linkFile() == linkfile/* || l->file() == linkfile || dl.isValid() && dl.file() == l->file()*/ ) { | 407 | if ( l->linkFileKnown() && l->linkFile() == linkfile/* || l->file() == linkfile || dl.isValid() && dl.file() == l->file()*/ ) { |
408 | delete item; | 408 | delete item; |
409 | did = TRUE; | 409 | did = TRUE; |
410 | } | 410 | } |
411 | item = (LauncherItem*)item->nextItem(); | 411 | item = (LauncherItem*)item->nextItem(); |
412 | } | 412 | } |
413 | QListIterator<AppLnk> it(hidden); | 413 | QListIterator<AppLnk> it(hidden); |
414 | while ((l=it.current())) { | 414 | while ((l=it.current())) { |
415 | ++it; | 415 | ++it; |
416 | if ( l->linkFileKnown() && l->linkFile() == linkfile/* || l->file() == linkfile || dl.isValid() && dl.file() == l->file()*/ ) { | 416 | if ( l->linkFileKnown() && l->linkFile() == linkfile/* || l->file() == linkfile || dl.isValid() && dl.file() == l->file()*/ ) { |
417 | hidden.removeRef(l); | 417 | hidden.removeRef(l); |
418 | did = TRUE; | 418 | did = TRUE; |
419 | } | 419 | } |
420 | } | 420 | } |
421 | return did; | 421 | return did; |
422 | } | 422 | } |
423 | 423 | ||
424 | LauncherView::LauncherView( QWidget* parent, const char* name, WFlags fl ) | 424 | LauncherView::LauncherView( QWidget* parent, const char* name, WFlags fl ) |
425 | : QVBox( parent, name, fl ) | 425 | : QVBox( parent, name, fl ) |
426 | { | 426 | { |
427 | icons = new LauncherIconView( this ); | 427 | icons = new LauncherIconView( this ); |
428 | setFocusProxy(icons); | 428 | setFocusProxy(icons); |
429 | QPEApplication::setStylusOperation( icons->viewport(), QPEApplication::RightOnHold ); | 429 | QPEApplication::setStylusOperation( icons->viewport(), QPEApplication::RightOnHold ); |
430 | 430 | ||
431 | int dw = QApplication::desktop()->width(); | 431 | int dw = QApplication::desktop()->width(); |
432 | icons->setItemsMovable( FALSE ); | 432 | icons->setItemsMovable( FALSE ); |
433 | icons->setAutoArrange( TRUE ); | 433 | icons->setAutoArrange( TRUE ); |
434 | icons->setSorting( TRUE ); | 434 | icons->setSorting( TRUE ); |
435 | icons->setGridX( (dw-13-style().scrollBarExtent().width())/3 ); // tweaked for 8pt+dw=176 and 10pt+dw=240 | 435 | icons->setGridX( (dw-13-style().scrollBarExtent().width())/ (dw/80) ); // tweaked for 8pt+dw=176 and 10pt+dw=240 |
436 | icons->setGridY( fontMetrics().height()*2+24 ); | 436 | icons->setGridY( fontMetrics().height()*2+24 ); |
437 | icons->setFrameStyle( QFrame::NoFrame ); | 437 | icons->setFrameStyle( QFrame::NoFrame ); |
438 | icons->setSpacing( 4 ); | 438 | icons->setSpacing( 4 ); |
439 | icons->setMargin( 0 ); | 439 | icons->setMargin( 0 ); |
440 | icons->setSelectionMode( QIconView::Multi ); | 440 | icons->setSelectionMode( QIconView::Multi ); |
441 | icons->setBackgroundMode( PaletteBase ); | 441 | icons->setBackgroundMode( PaletteBase ); |
442 | 442 | ||
443 | connect( icons, SIGNAL(mouseButtonClicked(int, QIconViewItem *, const QPoint&)), | 443 | connect( icons, SIGNAL(mouseButtonClicked(int, QIconViewItem *, const QPoint&)), |
444 | SLOT(itemClicked(int, QIconViewItem *)) ); | 444 | SLOT(itemClicked(int, QIconViewItem *)) ); |
445 | connect( icons, SIGNAL(selectionChanged()), | 445 | connect( icons, SIGNAL(selectionChanged()), |
446 | SLOT(selectionChanged()) ); | 446 | SLOT(selectionChanged()) ); |
447 | connect( icons, SIGNAL(returnPressed(QIconViewItem *)), | 447 | connect( icons, SIGNAL(returnPressed(QIconViewItem *)), |
448 | SLOT(returnPressed(QIconViewItem *)) ); | 448 | SLOT(returnPressed(QIconViewItem *)) ); |
449 | connect( icons, SIGNAL(mouseButtonPressed(int, QIconViewItem *, const QPoint&)), | 449 | connect( icons, SIGNAL(mouseButtonPressed(int, QIconViewItem *, const QPoint&)), |
450 | SLOT(itemPressed(int, QIconViewItem *)) ); | 450 | SLOT(itemPressed(int, QIconViewItem *)) ); |
451 | 451 | ||
452 | tools = 0; | 452 | tools = 0; |
453 | } | 453 | } |
454 | 454 | ||
455 | LauncherView::~LauncherView() | 455 | LauncherView::~LauncherView() |
456 | { | 456 | { |
457 | } | 457 | } |
458 | 458 | ||
459 | void LauncherView::setToolsEnabled(bool y) | 459 | void LauncherView::setToolsEnabled(bool y) |
460 | { | 460 | { |
461 | if ( !y != !tools ) { | 461 | if ( !y != !tools ) { |
462 | if ( y ) { | 462 | if ( y ) { |
463 | tools = new QHBox(this); | 463 | tools = new QHBox(this); |
464 | 464 | ||
465 | // Type filter | 465 | // Type filter |
466 | typemb = new MenuButton(tools); | 466 | typemb = new MenuButton(tools); |
467 | typemb->setLabel(tr("Type: %1")); | 467 | typemb->setLabel(tr("Type: %1")); |
468 | typemb->setFixedHeight ( 20 ); | 468 | typemb->setFixedHeight ( 20 ); |
469 | 469 | ||
470 | // Category filter | 470 | // Category filter |
471 | catmb = new CategorySelect(tools); | 471 | catmb = new CategorySelect(tools); |
472 | catmb->setFixedHeight ( 20 ); | 472 | catmb->setFixedHeight ( 20 ); |
473 | 473 | ||
474 | updateTools(); | 474 | updateTools(); |
475 | tools->show(); | 475 | tools->show(); |
476 | } else { | 476 | } else { |
477 | delete tools; | 477 | delete tools; |
478 | tools = 0; | 478 | tools = 0; |
479 | } | 479 | } |
480 | } | 480 | } |
481 | } | 481 | } |
482 | 482 | ||
483 | void LauncherView::updateTools() | 483 | void LauncherView::updateTools() |
484 | { | 484 | { |
485 | disconnect( typemb, SIGNAL(selected(const QString&)), | 485 | disconnect( typemb, SIGNAL(selected(const QString&)), |
486 | this, SLOT(showType(const QString&)) ); | 486 | this, SLOT(showType(const QString&)) ); |
487 | disconnect( catmb, SIGNAL(signalSelected(int)), | 487 | disconnect( catmb, SIGNAL(signalSelected(int)), |
488 | this, SLOT(showCategory(int)) ); | 488 | this, SLOT(showCategory(int)) ); |
489 | 489 | ||
490 | icons->updateCategoriesAndMimeTypes(); | 490 | icons->updateCategoriesAndMimeTypes(); |
491 | 491 | ||
492 | QString prev; | 492 | QString prev; |
493 | 493 | ||
494 | // Type filter | 494 | // Type filter |
495 | QStringList types; | 495 | QStringList types; |
496 | types << tr("All"); | 496 | types << tr("All"); |
497 | types << "--"; | 497 | types << "--"; |
498 | types += icons->mimeTypes(); | 498 | types += icons->mimeTypes(); |
499 | prev = typemb->currentText(); | 499 | prev = typemb->currentText(); |
500 | typemb->clear(); | 500 | typemb->clear(); |
501 | typemb->insertItems(types); | 501 | typemb->insertItems(types); |
502 | typemb->select(prev); | 502 | typemb->select(prev); |
503 | 503 | ||
504 | Categories cats( 0 ); | 504 | Categories cats( 0 ); |
505 | cats.load( categoryFileName() ); | 505 | cats.load( categoryFileName() ); |
506 | QArray<int> vl( 0 ); | 506 | QArray<int> vl( 0 ); |
507 | catmb->setCategories( vl, "Document View", tr("Document View") ); | 507 | catmb->setCategories( vl, "Document View", tr("Document View") ); |
508 | catmb->setRemoveCategoryEdit( TRUE ); | 508 | catmb->setRemoveCategoryEdit( TRUE ); |
509 | catmb->setAllCategories( TRUE ); | 509 | catmb->setAllCategories( TRUE ); |
510 | 510 | ||
511 | connect(typemb, SIGNAL(selected(const QString&)), this, SLOT(showType(const QString&))); | 511 | connect(typemb, SIGNAL(selected(const QString&)), this, SLOT(showType(const QString&))); |
512 | connect(catmb, SIGNAL(signalSelected(int)), this, SLOT(showCategory(int))); | 512 | connect(catmb, SIGNAL(signalSelected(int)), this, SLOT(showCategory(int))); |
513 | } | 513 | } |
514 | 514 | ||
515 | void LauncherView::sortBy(int s) | 515 | void LauncherView::sortBy(int s) |
516 | { | 516 | { |
517 | icons->setSortMethod((LauncherIconView::SortMethod)s); | 517 | icons->setSortMethod((LauncherIconView::SortMethod)s); |
518 | } | 518 | } |
519 | 519 | ||
520 | void LauncherView::showType(const QString& t) | 520 | void LauncherView::showType(const QString& t) |
521 | { | 521 | { |
522 | if ( t == tr("All") ) { | 522 | if ( t == tr("All") ) { |
523 | icons->setTypeFilter("",TRUE); | 523 | icons->setTypeFilter("",TRUE); |
524 | } else { | 524 | } else { |
525 | icons->setTypeFilter(t+"/*",TRUE); | 525 | icons->setTypeFilter(t+"/*",TRUE); |
526 | } | 526 | } |
527 | } | 527 | } |
528 | 528 | ||
529 | void LauncherView::showCategory( int c ) | 529 | void LauncherView::showCategory( int c ) |
530 | { | 530 | { |
531 | icons->setCategoryFilter( c, TRUE ); | 531 | icons->setCategoryFilter( c, TRUE ); |
532 | } | 532 | } |
533 | 533 | ||
534 | void LauncherView::resizeEvent(QResizeEvent *e) | 534 | void LauncherView::resizeEvent(QResizeEvent *e) |
535 | { | 535 | { |
536 | QVBox::resizeEvent( e ); | 536 | QVBox::resizeEvent( e ); |
537 | if ( e->size().width() != e->oldSize().width() ) | 537 | if ( e->size().width() != e->oldSize().width() ) |
538 | sort(); | 538 | sort(); |
539 | } | 539 | } |
540 | 540 | ||
541 | void LauncherView::populate( AppLnkSet *folder, const QString& typefilter ) | 541 | void LauncherView::populate( AppLnkSet *folder, const QString& typefilter ) |
542 | { | 542 | { |
543 | icons->clear(); | 543 | icons->clear(); |
544 | internalPopulate( folder, typefilter ); | 544 | internalPopulate( folder, typefilter ); |
545 | } | 545 | } |
546 | 546 | ||
547 | void LauncherView::selectionChanged() | 547 | void LauncherView::selectionChanged() |
548 | { | 548 | { |
549 | QIconViewItem* item = icons->currentItem(); | 549 | QIconViewItem* item = icons->currentItem(); |
550 | if ( item && item->isSelected() ) { | 550 | if ( item && item->isSelected() ) { |
551 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); | 551 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); |
552 | if ( icons->inKeyEvent() ) // not for mouse press | 552 | if ( icons->inKeyEvent() ) // not for mouse press |
553 | emit clicked( appLnk ); | 553 | emit clicked( appLnk ); |
554 | item->setSelected(FALSE); | 554 | item->setSelected(FALSE); |
555 | } | 555 | } |
556 | } | 556 | } |
557 | 557 | ||
558 | void LauncherView::returnPressed( QIconViewItem *item ) | 558 | void LauncherView::returnPressed( QIconViewItem *item ) |
559 | { | 559 | { |
560 | if ( item ) { | 560 | if ( item ) { |
561 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); | 561 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); |
562 | emit clicked( appLnk ); | 562 | emit clicked( appLnk ); |
563 | } | 563 | } |
564 | } | 564 | } |
565 | 565 | ||
566 | void LauncherView::itemClicked( int btn, QIconViewItem *item ) | 566 | void LauncherView::itemClicked( int btn, QIconViewItem *item ) |
567 | { | 567 | { |
568 | if ( item ) { | 568 | if ( item ) { |
569 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); | 569 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); |
570 | if ( btn == LeftButton ) { | 570 | if ( btn == LeftButton ) { |
571 | // Make sure it's the item we execute that gets highlighted | 571 | // Make sure it's the item we execute that gets highlighted |
572 | icons->setCurrentItem( item ); | 572 | icons->setCurrentItem( item ); |
573 | emit clicked( appLnk ); | 573 | emit clicked( appLnk ); |
574 | } | 574 | } |
575 | item->setSelected(FALSE); | 575 | item->setSelected(FALSE); |
576 | } | 576 | } |
577 | } | 577 | } |
578 | 578 | ||
579 | void LauncherView::itemPressed( int btn, QIconViewItem *item ) | 579 | void LauncherView::itemPressed( int btn, QIconViewItem *item ) |
580 | { | 580 | { |
581 | if ( item ) { | 581 | if ( item ) { |
582 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); | 582 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); |
583 | if ( btn == RightButton ) | 583 | if ( btn == RightButton ) |
584 | emit rightPressed( appLnk ); | 584 | emit rightPressed( appLnk ); |
585 | /* | 585 | /* |
586 | else if ( btn == LeftButton ) | 586 | else if ( btn == LeftButton ) |
587 | emit clicked( appLnk ); | 587 | emit clicked( appLnk ); |
588 | */ | 588 | */ |
589 | item->setSelected(FALSE); | 589 | item->setSelected(FALSE); |
590 | } | 590 | } |
591 | } | 591 | } |
592 | 592 | ||
593 | void LauncherView::internalPopulate( AppLnkSet *folder, const QString& typefilter ) | 593 | void LauncherView::internalPopulate( AppLnkSet *folder, const QString& typefilter ) |
594 | { | 594 | { |
595 | QListIterator<AppLnk> it( folder->children() ); | 595 | QListIterator<AppLnk> it( folder->children() ); |
596 | icons->setTypeFilter(typefilter,FALSE); | 596 | icons->setTypeFilter(typefilter,FALSE); |
597 | 597 | ||
598 | while ( it.current() ) { | 598 | while ( it.current() ) { |
599 | // show only the icons for existing files | 599 | // show only the icons for existing files |
600 | if (!QFile(it.current()->file()).exists() ) | 600 | if (!QFile(it.current()->file()).exists() ) |
601 | { | 601 | { |