-rw-r--r-- | library/fileselector.cpp | 20 | ||||
-rw-r--r-- | library/fileselector.h | 2 |
2 files changed, 22 insertions, 0 deletions
diff --git a/library/fileselector.cpp b/library/fileselector.cpp index 382012f..7ff09b4 100644 --- a/library/fileselector.cpp +++ b/library/fileselector.cpp | |||
@@ -291,64 +291,65 @@ FileSelector::FileSelector( const QString &f, QWidget *parent, const char *name, | |||
291 | d = new FileSelectorPrivate(); | 291 | d = new FileSelectorPrivate(); |
292 | d->newDocItem = 0; | 292 | d->newDocItem = 0; |
293 | d->showNew = newVisible; | 293 | d->showNew = newVisible; |
294 | d->catId = -2; // All files | 294 | d->catId = -2; // All files |
295 | 295 | ||
296 | d->toolbar = new QHBox( this ); | 296 | d->toolbar = new QHBox( this ); |
297 | d->toolbar->setBackgroundMode( PaletteButton ); // same colour as toolbars | 297 | d->toolbar->setBackgroundMode( PaletteButton ); // same colour as toolbars |
298 | d->toolbar->setSpacing( 0 ); | 298 | d->toolbar->setSpacing( 0 ); |
299 | d->toolbar->hide(); | 299 | d->toolbar->hide(); |
300 | 300 | ||
301 | QWidget *spacer = new QWidget( d->toolbar ); | 301 | QWidget *spacer = new QWidget( d->toolbar ); |
302 | spacer->setBackgroundMode( PaletteButton ); | 302 | spacer->setBackgroundMode( PaletteButton ); |
303 | 303 | ||
304 | QToolButton *tb = new QToolButton( d->toolbar ); | 304 | QToolButton *tb = new QToolButton( d->toolbar ); |
305 | tb->setPixmap( Resource::loadPixmap( "close" ) ); | 305 | tb->setPixmap( Resource::loadPixmap( "close" ) ); |
306 | connect( tb, SIGNAL( clicked() ), this, SIGNAL( closeMe() ) ); | 306 | connect( tb, SIGNAL( clicked() ), this, SIGNAL( closeMe() ) ); |
307 | buttonClose = tb; | 307 | buttonClose = tb; |
308 | tb->setFixedSize( 18, 20 ); // tb->sizeHint() ); | 308 | tb->setFixedSize( 18, 20 ); // tb->sizeHint() ); |
309 | tb->setAutoRaise( TRUE ); | 309 | tb->setAutoRaise( TRUE ); |
310 | QToolTip::add( tb, tr( "Close the File Selector" ) ); | 310 | QToolTip::add( tb, tr( "Close the File Selector" ) ); |
311 | QPEMenuToolFocusManager::manager()->addWidget( tb ); | 311 | QPEMenuToolFocusManager::manager()->addWidget( tb ); |
312 | 312 | ||
313 | view = new FileSelectorView( this, "fileview" ); | 313 | view = new FileSelectorView( this, "fileview" ); |
314 | QPEApplication::setStylusOperation( view->viewport(), QPEApplication::RightOnHold ); | 314 | QPEApplication::setStylusOperation( view->viewport(), QPEApplication::RightOnHold ); |
315 | connect( view, SIGNAL( mouseButtonClicked( int, QListViewItem *, const QPoint &, int ) ), | 315 | connect( view, SIGNAL( mouseButtonClicked( int, QListViewItem *, const QPoint &, int ) ), |
316 | this, SLOT( fileClicked( int, QListViewItem *, const QPoint &, int ) ) ); | 316 | this, SLOT( fileClicked( int, QListViewItem *, const QPoint &, int ) ) ); |
317 | connect( view, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint &, int ) ), | 317 | connect( view, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint &, int ) ), |
318 | this, SLOT( filePressed( int, QListViewItem *, const QPoint &, int ) ) ); | 318 | this, SLOT( filePressed( int, QListViewItem *, const QPoint &, int ) ) ); |
319 | connect( view, SIGNAL( returnPressed( QListViewItem * ) ), | 319 | connect( view, SIGNAL( returnPressed( QListViewItem * ) ), |
320 | this, SLOT( fileClicked( QListViewItem * ) ) ); | 320 | this, SLOT( fileClicked( QListViewItem * ) ) ); |
321 | 321 | ||
322 | QHBox *hb = new QHBox( this ); | 322 | QHBox *hb = new QHBox( this ); |
323 | |||
323 | d->typeCombo = new TypeCombo( hb ); | 324 | d->typeCombo = new TypeCombo( hb ); |
324 | connect( d->typeCombo, SIGNAL(selected(const QString&)), | 325 | connect( d->typeCombo, SIGNAL(selected(const QString&)), |
325 | this, SLOT(typeSelected(const QString&)) ); | 326 | this, SLOT(typeSelected(const QString&)) ); |
326 | QWhatsThis::add( d->typeCombo, tr("Show documents of this type") ); | 327 | QWhatsThis::add( d->typeCombo, tr("Show documents of this type") ); |
327 | 328 | ||
328 | Categories c; | 329 | Categories c; |
329 | c.load(categoryFileName()); | 330 | c.load(categoryFileName()); |
330 | QArray<int> vl( 0 ); | 331 | QArray<int> vl( 0 ); |
331 | d->catSelect = new CategorySelect( hb ); | 332 | d->catSelect = new CategorySelect( hb ); |
332 | d->catSelect->setRemoveCategoryEdit( TRUE ); | 333 | d->catSelect->setRemoveCategoryEdit( TRUE ); |
333 | d->catSelect->setCategories( vl, "Document View", tr("Document View") ); | 334 | d->catSelect->setCategories( vl, "Document View", tr("Document View") ); |
334 | d->catSelect->setAllCategories( TRUE ); | 335 | d->catSelect->setAllCategories( TRUE ); |
335 | connect( d->catSelect, SIGNAL(signalSelected(int)), this, SLOT(catSelected(int)) ); | 336 | connect( d->catSelect, SIGNAL(signalSelected(int)), this, SLOT(catSelected(int)) ); |
336 | QWhatsThis::add( d->catSelect, tr("Show documents in this category") ); | 337 | QWhatsThis::add( d->catSelect, tr("Show documents in this category") ); |
337 | 338 | ||
338 | setCloseVisible( closeVisible ); | 339 | setCloseVisible( closeVisible ); |
339 | 340 | ||
340 | QCopChannel *channel = new QCopChannel( "QPE/Card", this ); | 341 | QCopChannel *channel = new QCopChannel( "QPE/Card", this ); |
341 | connect( channel, SIGNAL(received(const QCString &, const QByteArray &)), | 342 | connect( channel, SIGNAL(received(const QCString &, const QByteArray &)), |
342 | this, SLOT(cardMessage( const QCString &, const QByteArray &)) ); | 343 | this, SLOT(cardMessage( const QCString &, const QByteArray &)) ); |
343 | 344 | ||
344 | reread(); | 345 | reread(); |
345 | updateWhatsThis(); | 346 | updateWhatsThis(); |
346 | } | 347 | } |
347 | 348 | ||
348 | /*! | 349 | /*! |
349 | Destroys the widget. | 350 | Destroys the widget. |
350 | */ | 351 | */ |
351 | FileSelector::~FileSelector() | 352 | FileSelector::~FileSelector() |
352 | { | 353 | { |
353 | delete d; | 354 | delete d; |
354 | } | 355 | } |
@@ -467,64 +468,83 @@ const DocLnk *FileSelector::selected() | |||
467 | 468 | ||
468 | 469 | ||
469 | /*! | 470 | /*! |
470 | If \a b is TRUE a "new document" entry is visible; if \a b is FALSE | 471 | If \a b is TRUE a "new document" entry is visible; if \a b is FALSE |
471 | this entry is not visible and the user is unable to create new | 472 | this entry is not visible and the user is unable to create new |
472 | documents from the dialog. | 473 | documents from the dialog. |
473 | */ | 474 | */ |
474 | void FileSelector::setNewVisible( bool b ) | 475 | void FileSelector::setNewVisible( bool b ) |
475 | { | 476 | { |
476 | if ( d->showNew != b ) { | 477 | if ( d->showNew != b ) { |
477 | d->showNew = b; | 478 | d->showNew = b; |
478 | updateView(); | 479 | updateView(); |
479 | updateWhatsThis(); | 480 | updateWhatsThis(); |
480 | } | 481 | } |
481 | } | 482 | } |
482 | 483 | ||
483 | /*! | 484 | /*! |
484 | If \a b is TRUE a "close" or "no document" button is visible; if \a | 485 | If \a b is TRUE a "close" or "no document" button is visible; if \a |
485 | b is FALSE this button is not visible and the user is unable to | 486 | b is FALSE this button is not visible and the user is unable to |
486 | leave the dialog without creating or selecting a document. | 487 | leave the dialog without creating or selecting a document. |
487 | 488 | ||
488 | This function is deprecated. | 489 | This function is deprecated. |
489 | */ | 490 | */ |
490 | void FileSelector::setCloseVisible( bool b ) | 491 | void FileSelector::setCloseVisible( bool b ) |
491 | { | 492 | { |
492 | if ( b ) | 493 | if ( b ) |
493 | d->toolbar->show(); | 494 | d->toolbar->show(); |
494 | else | 495 | else |
495 | d->toolbar->hide(); | 496 | d->toolbar->hide(); |
496 | } | 497 | } |
497 | 498 | ||
498 | /*! | 499 | /*! |
500 | |||
501 | */ | ||
502 | void FileSelector::setTypeComboVisible( bool b ) { | ||
503 | if ( b ) | ||
504 | d->typeCombo->show(); | ||
505 | else | ||
506 | d->typeCombo->hide(); | ||
507 | } | ||
508 | /*! | ||
509 | |||
510 | */ | ||
511 | void FileSelector::setCategorySelectVisible( bool b ) { | ||
512 | if ( b ) | ||
513 | d->catSelect->show(); | ||
514 | else | ||
515 | d->catSelect->hide(); | ||
516 | } | ||
517 | |||
518 | /*! | ||
499 | Rereads the list of documents. | 519 | Rereads the list of documents. |
500 | */ | 520 | */ |
501 | void FileSelector::reread() | 521 | void FileSelector::reread() |
502 | { | 522 | { |
503 | d->files.clear(); | 523 | d->files.clear(); |
504 | Global::findDocuments(&d->files, filter); | 524 | Global::findDocuments(&d->files, filter); |
505 | d->typeCombo->reread( d->files, filter ); | 525 | d->typeCombo->reread( d->files, filter ); |
506 | updateView(); | 526 | updateView(); |
507 | } | 527 | } |
508 | 528 | ||
509 | void FileSelector::updateView() | 529 | void FileSelector::updateView() |
510 | { | 530 | { |
511 | FileSelectorItem *item = (FileSelectorItem *)view->selectedItem(); | 531 | FileSelectorItem *item = (FileSelectorItem *)view->selectedItem(); |
512 | if ( item == d->newDocItem ) | 532 | if ( item == d->newDocItem ) |
513 | item = 0; | 533 | item = 0; |
514 | QString oldFile; | 534 | QString oldFile; |
515 | if ( item ) | 535 | if ( item ) |
516 | oldFile = item->file().file(); | 536 | oldFile = item->file().file(); |
517 | view->clear(); | 537 | view->clear(); |
518 | QListIterator<DocLnk> dit( d->files.children() ); | 538 | QListIterator<DocLnk> dit( d->files.children() ); |
519 | for ( ; dit.current(); ++dit ) { | 539 | for ( ; dit.current(); ++dit ) { |
520 | bool mimeMatch = FALSE; | 540 | bool mimeMatch = FALSE; |
521 | if ( d->mimeFilters.count() ) { | 541 | if ( d->mimeFilters.count() ) { |
522 | QValueList<QRegExp>::Iterator it; | 542 | QValueList<QRegExp>::Iterator it; |
523 | for ( it = d->mimeFilters.begin(); it != d->mimeFilters.end(); ++it ) { | 543 | for ( it = d->mimeFilters.begin(); it != d->mimeFilters.end(); ++it ) { |
524 | if ( (*it).match((*dit)->type()) >= 0 ) { | 544 | if ( (*it).match((*dit)->type()) >= 0 ) { |
525 | mimeMatch = TRUE; | 545 | mimeMatch = TRUE; |
526 | break; | 546 | break; |
527 | } | 547 | } |
528 | } | 548 | } |
529 | } else { | 549 | } else { |
530 | mimeMatch = TRUE; | 550 | mimeMatch = TRUE; |
diff --git a/library/fileselector.h b/library/fileselector.h index f1c9eb1..e3ae891 100644 --- a/library/fileselector.h +++ b/library/fileselector.h | |||
@@ -25,64 +25,66 @@ | |||
25 | #include <qtoolbutton.h> | 25 | #include <qtoolbutton.h> |
26 | #include <qlistview.h> | 26 | #include <qlistview.h> |
27 | 27 | ||
28 | #include "filemanager.h" | 28 | #include "filemanager.h" |
29 | #include "applnk.h" | 29 | #include "applnk.h" |
30 | 30 | ||
31 | class QPopupMenu; | 31 | class QPopupMenu; |
32 | class QPushButton; | 32 | class QPushButton; |
33 | class FileSelectorView; | 33 | class FileSelectorView; |
34 | 34 | ||
35 | class FileSelectorItem : public QListViewItem | 35 | class FileSelectorItem : public QListViewItem |
36 | { | 36 | { |
37 | public: | 37 | public: |
38 | FileSelectorItem( QListView *parent, const DocLnk& f ); | 38 | FileSelectorItem( QListView *parent, const DocLnk& f ); |
39 | ~FileSelectorItem(); | 39 | ~FileSelectorItem(); |
40 | 40 | ||
41 | DocLnk file() const { return fl; } | 41 | DocLnk file() const { return fl; } |
42 | 42 | ||
43 | private: | 43 | private: |
44 | DocLnk fl; | 44 | DocLnk fl; |
45 | }; | 45 | }; |
46 | 46 | ||
47 | class FileSelectorPrivate; | 47 | class FileSelectorPrivate; |
48 | class FileSelector : public QVBox | 48 | class FileSelector : public QVBox |
49 | { | 49 | { |
50 | Q_OBJECT | 50 | Q_OBJECT |
51 | 51 | ||
52 | public: | 52 | public: |
53 | FileSelector( const QString &mimefilter, QWidget *parent, const char *name=0, bool newVisible = TRUE, bool closeVisible = TRUE ); | 53 | FileSelector( const QString &mimefilter, QWidget *parent, const char *name=0, bool newVisible = TRUE, bool closeVisible = TRUE ); |
54 | ~FileSelector(); | 54 | ~FileSelector(); |
55 | void setNewVisible( bool b ); | 55 | void setNewVisible( bool b ); |
56 | void setCloseVisible( bool b ); | 56 | void setCloseVisible( bool b ); |
57 | void setTypeComboVisible( bool b = TRUE ); | ||
58 | void setCategorySelectVisible( bool b = TRUE ); | ||
57 | void reread(); | 59 | void reread(); |
58 | int fileCount(); | 60 | int fileCount(); |
59 | DocLnk selectedDocument() const | 61 | DocLnk selectedDocument() const |
60 | { | 62 | { |
61 | const DocLnk* rp = ((FileSelector*)this)->selected(); | 63 | const DocLnk* rp = ((FileSelector*)this)->selected(); |
62 | if (!rp) { | 64 | if (!rp) { |
63 | DocLnk r; | 65 | DocLnk r; |
64 | return r; | 66 | return r; |
65 | } | 67 | } |
66 | DocLnk r(*rp); | 68 | DocLnk r(*rp); |
67 | delete rp; | 69 | delete rp; |
68 | return r; | 70 | return r; |
69 | } | 71 | } |
70 | 72 | ||
71 | QValueList<DocLnk> fileList() const | 73 | QValueList<DocLnk> fileList() const |
72 | { | 74 | { |
73 | ((FileSelector*)this)->fileCount(); // ensure all loaded when this is extended | 75 | ((FileSelector*)this)->fileCount(); // ensure all loaded when this is extended |
74 | 76 | ||
75 | QValueList<DocLnk> list; | 77 | QValueList<DocLnk> list; |
76 | FileSelectorItem *item = (FileSelectorItem *)((QListView*)view)->firstChild(); | 78 | FileSelectorItem *item = (FileSelectorItem *)((QListView*)view)->firstChild(); |
77 | while (item) { | 79 | while (item) { |
78 | list.append(item->file()); | 80 | list.append(item->file()); |
79 | item = (FileSelectorItem *)item->nextSibling(); | 81 | item = (FileSelectorItem *)item->nextSibling(); |
80 | } | 82 | } |
81 | 83 | ||
82 | return list; | 84 | return list; |
83 | } | 85 | } |
84 | 86 | ||
85 | signals: | 87 | signals: |
86 | void fileSelected( const DocLnk & ); | 88 | void fileSelected( const DocLnk & ); |
87 | void newSelected( const DocLnk & ); | 89 | void newSelected( const DocLnk & ); |
88 | void closeMe(); | 90 | void closeMe(); |