author | zecke <zecke> | 2002-09-29 16:53:10 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-09-29 16:53:10 (UTC) |
commit | 33ebc68a530393697724428f0e0db3a4807f3a9e (patch) (unidiff) | |
tree | f13affe84a0a4fce01c642c18b6b3c3f42d68e6b | |
parent | 3e8ee39d31b43f01524670df6cb048efc2194b9a (diff) | |
download | opie-33ebc68a530393697724428f0e0db3a4807f3a9e.zip opie-33ebc68a530393697724428f0e0db3a4807f3a9e.tar.gz opie-33ebc68a530393697724428f0e0db3a4807f3a9e.tar.bz2 |
Add the possibility to hide/show the TypeCombo/CategorySelect
-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 | |||
@@ -131,433 +131,453 @@ void TypeCombo::reread( DocLnkSet &files, const QString &filter ) | |||
131 | } | 131 | } |
132 | for (it = filters.begin(); it!=filters.end(); ++it) { | 132 | for (it = filters.begin(); it!=filters.end(); ++it) { |
133 | typelist.append( *it ); | 133 | typelist.append( *it ); |
134 | int pos = (*it).find( '/' ); | 134 | int pos = (*it).find( '/' ); |
135 | if ( pos >= 0 ) { | 135 | if ( pos >= 0 ) { |
136 | QString maj = (*it).left( pos ); | 136 | QString maj = (*it).left( pos ); |
137 | maj[0] = maj[0].upper(); | 137 | maj[0] = maj[0].upper(); |
138 | types << tr("All %1 files").arg(maj); | 138 | types << tr("All %1 files").arg(maj); |
139 | } | 139 | } |
140 | } | 140 | } |
141 | if ( filters.count() > 1 ) { | 141 | if ( filters.count() > 1 ) { |
142 | typelist.append( filter ); | 142 | typelist.append( filter ); |
143 | types << tr("All files"); | 143 | types << tr("All files"); |
144 | } | 144 | } |
145 | prev = currentText(); | 145 | prev = currentText(); |
146 | clear(); | 146 | clear(); |
147 | insertStringList(types); | 147 | insertStringList(types); |
148 | for (int i=0; i<count(); i++) { | 148 | for (int i=0; i<count(); i++) { |
149 | if ( text(i) == prev ) { | 149 | if ( text(i) == prev ) { |
150 | setCurrentItem(i); | 150 | setCurrentItem(i); |
151 | break; | 151 | break; |
152 | } | 152 | } |
153 | } | 153 | } |
154 | if ( prev.isNull() ) | 154 | if ( prev.isNull() ) |
155 | setCurrentItem(count()-1); | 155 | setCurrentItem(count()-1); |
156 | setEnabled( TRUE ); | 156 | setEnabled( TRUE ); |
157 | } | 157 | } |
158 | 158 | ||
159 | 159 | ||
160 | //=========================================================================== | 160 | //=========================================================================== |
161 | 161 | ||
162 | FileSelectorItem::FileSelectorItem( QListView *parent, const DocLnk &f ) | 162 | FileSelectorItem::FileSelectorItem( QListView *parent, const DocLnk &f ) |
163 | : QListViewItem( parent ), fl( f ) | 163 | : QListViewItem( parent ), fl( f ) |
164 | { | 164 | { |
165 | setText( 0, f.name() ); | 165 | setText( 0, f.name() ); |
166 | setPixmap( 0, f.pixmap() ); | 166 | setPixmap( 0, f.pixmap() ); |
167 | } | 167 | } |
168 | 168 | ||
169 | FileSelectorItem::~FileSelectorItem() | 169 | FileSelectorItem::~FileSelectorItem() |
170 | { | 170 | { |
171 | } | 171 | } |
172 | 172 | ||
173 | FileSelectorView::FileSelectorView( QWidget *parent, const char *name ) | 173 | FileSelectorView::FileSelectorView( QWidget *parent, const char *name ) |
174 | : QListView( parent, name ) | 174 | : QListView( parent, name ) |
175 | { | 175 | { |
176 | setAllColumnsShowFocus( TRUE ); | 176 | setAllColumnsShowFocus( TRUE ); |
177 | addColumn( tr( "Name" ) ); | 177 | addColumn( tr( "Name" ) ); |
178 | header()->hide(); | 178 | header()->hide(); |
179 | } | 179 | } |
180 | 180 | ||
181 | FileSelectorView::~FileSelectorView() | 181 | FileSelectorView::~FileSelectorView() |
182 | { | 182 | { |
183 | } | 183 | } |
184 | 184 | ||
185 | void FileSelectorView::keyPressEvent( QKeyEvent *e ) | 185 | void FileSelectorView::keyPressEvent( QKeyEvent *e ) |
186 | { | 186 | { |
187 | QString txt = e->text(); | 187 | QString txt = e->text(); |
188 | if (e->key() == Key_Space) | 188 | if (e->key() == Key_Space) |
189 | emit returnPressed( currentItem() ); | 189 | emit returnPressed( currentItem() ); |
190 | else if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) | 190 | else if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) |
191 | e->ignore(); | 191 | e->ignore(); |
192 | else | 192 | else |
193 | QListView::keyPressEvent(e); | 193 | QListView::keyPressEvent(e); |
194 | } | 194 | } |
195 | 195 | ||
196 | class NewDocItem : public FileSelectorItem | 196 | class NewDocItem : public FileSelectorItem |
197 | { | 197 | { |
198 | public: | 198 | public: |
199 | NewDocItem( QListView *parent, const DocLnk &f ) | 199 | NewDocItem( QListView *parent, const DocLnk &f ) |
200 | : FileSelectorItem( parent, f ) { | 200 | : FileSelectorItem( parent, f ) { |
201 | setText( 0, QObject::tr("New Document") ); | 201 | setText( 0, QObject::tr("New Document") ); |
202 | QImage img( Resource::loadImage( "new" ) ); | 202 | QImage img( Resource::loadImage( "new" ) ); |
203 | QPixmap pm; | 203 | QPixmap pm; |
204 | pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); | 204 | pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); |
205 | setPixmap( 0, pm ); | 205 | setPixmap( 0, pm ); |
206 | } | 206 | } |
207 | QString key ( int, bool ) const { | 207 | QString key ( int, bool ) const { |
208 | return QString("\n"); | 208 | return QString("\n"); |
209 | } | 209 | } |
210 | 210 | ||
211 | void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ) { | 211 | void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ) { |
212 | QFont oldFont = p->font(); | 212 | QFont oldFont = p->font(); |
213 | QFont newFont = p->font(); | 213 | QFont newFont = p->font(); |
214 | newFont.setWeight( QFont::Bold ); | 214 | newFont.setWeight( QFont::Bold ); |
215 | p->setFont( newFont ); | 215 | p->setFont( newFont ); |
216 | FileSelectorItem::paintCell( p, cg, column, width, alignment ); | 216 | FileSelectorItem::paintCell( p, cg, column, width, alignment ); |
217 | p->setFont( oldFont ); | 217 | p->setFont( oldFont ); |
218 | } | 218 | } |
219 | 219 | ||
220 | int width( const QFontMetrics &fm, const QListView *v, int c ) const { | 220 | int width( const QFontMetrics &fm, const QListView *v, int c ) const { |
221 | return FileSelectorItem::width( fm, v, c )*4/3; // allow for bold font | 221 | return FileSelectorItem::width( fm, v, c )*4/3; // allow for bold font |
222 | } | 222 | } |
223 | }; | 223 | }; |
224 | 224 | ||
225 | //=========================================================================== | 225 | //=========================================================================== |
226 | 226 | ||
227 | class FileSelectorPrivate | 227 | class FileSelectorPrivate |
228 | { | 228 | { |
229 | public: | 229 | public: |
230 | TypeCombo *typeCombo; | 230 | TypeCombo *typeCombo; |
231 | CategorySelect *catSelect; | 231 | CategorySelect *catSelect; |
232 | QValueList<QRegExp> mimeFilters; | 232 | QValueList<QRegExp> mimeFilters; |
233 | int catId; | 233 | int catId; |
234 | bool showNew; | 234 | bool showNew; |
235 | NewDocItem *newDocItem; | 235 | NewDocItem *newDocItem; |
236 | DocLnkSet files; | 236 | DocLnkSet files; |
237 | QHBox *toolbar; | 237 | QHBox *toolbar; |
238 | }; | 238 | }; |
239 | 239 | ||
240 | /*! | 240 | /*! |
241 | \class FileSelector fileselector.h | 241 | \class FileSelector fileselector.h |
242 | \brief The FileSelector widget allows the user to select DocLnk objects. | 242 | \brief The FileSelector widget allows the user to select DocLnk objects. |
243 | 243 | ||
244 | This class presents a file selection dialog to the user. This widget | 244 | This class presents a file selection dialog to the user. This widget |
245 | is usually the first widget seen in a \link docwidget.html | 245 | is usually the first widget seen in a \link docwidget.html |
246 | document-oriented application\endlink. The developer will most often | 246 | document-oriented application\endlink. The developer will most often |
247 | create this widget in combination with a <a | 247 | create this widget in combination with a <a |
248 | href="../qt/qwidgetstack.html"> QWidgetStack</a> and the appropriate | 248 | href="../qt/qwidgetstack.html"> QWidgetStack</a> and the appropriate |
249 | editor and/or viewer widget for their application. This widget | 249 | editor and/or viewer widget for their application. This widget |
250 | should be shown first and the user can the select which document | 250 | should be shown first and the user can the select which document |
251 | they wish to operate on. Please refer to the implementation of | 251 | they wish to operate on. Please refer to the implementation of |
252 | texteditor for an example of how to tie these classes together. | 252 | texteditor for an example of how to tie these classes together. |
253 | 253 | ||
254 | Use setNewVisible() depending on whether the application can be used | 254 | Use setNewVisible() depending on whether the application can be used |
255 | to create new files or not. Use setCloseVisible() depending on | 255 | to create new files or not. Use setCloseVisible() depending on |
256 | whether the user may leave the dialog without creating or selecting | 256 | whether the user may leave the dialog without creating or selecting |
257 | a document or not. The number of files in the view is available from | 257 | a document or not. The number of files in the view is available from |
258 | fileCount(). To force the view to be updated call reread(). | 258 | fileCount(). To force the view to be updated call reread(). |
259 | 259 | ||
260 | If the user presses the 'New Document' button the newSelected() | 260 | If the user presses the 'New Document' button the newSelected() |
261 | signal is emitted. If the user selects an existing file the | 261 | signal is emitted. If the user selects an existing file the |
262 | fileSelected() signal is emitted. The selected file's \link | 262 | fileSelected() signal is emitted. The selected file's \link |
263 | doclnk.html DocLnk\endlink is available from the selected() | 263 | doclnk.html DocLnk\endlink is available from the selected() |
264 | function. If the file selector is no longer necessary the closeMe() | 264 | function. If the file selector is no longer necessary the closeMe() |
265 | signal is emitted. | 265 | signal is emitted. |
266 | 266 | ||
267 | \ingroup qtopiaemb | 267 | \ingroup qtopiaemb |
268 | \sa FileManager | 268 | \sa FileManager |
269 | */ | 269 | */ |
270 | 270 | ||
271 | /*! | 271 | /*! |
272 | Constructs a FileSelector with mime filter \a f. | 272 | Constructs a FileSelector with mime filter \a f. |
273 | The standard Qt \a parent and \a name parameters are passed to the | 273 | The standard Qt \a parent and \a name parameters are passed to the |
274 | parent widget. | 274 | parent widget. |
275 | 275 | ||
276 | If \a newVisible is TRUE, the widget has a button to allow the user | 276 | If \a newVisible is TRUE, the widget has a button to allow the user |
277 | the create "new" documents; this is useful for applications that can | 277 | the create "new" documents; this is useful for applications that can |
278 | create and edit documents but not suitable for applications that | 278 | create and edit documents but not suitable for applications that |
279 | only provide viewing. | 279 | only provide viewing. |
280 | 280 | ||
281 | \a closeVisible is deprecated | 281 | \a closeVisible is deprecated |
282 | 282 | ||
283 | \sa DocLnkSet::DocLnkSet() | 283 | \sa DocLnkSet::DocLnkSet() |
284 | */ | 284 | */ |
285 | FileSelector::FileSelector( const QString &f, QWidget *parent, const char *name, bool newVisible, bool closeVisible ) | 285 | FileSelector::FileSelector( const QString &f, QWidget *parent, const char *name, bool newVisible, bool closeVisible ) |
286 | : QVBox( parent, name ), filter( f ) | 286 | : QVBox( parent, name ), filter( f ) |
287 | { | 287 | { |
288 | setMargin( 0 ); | 288 | setMargin( 0 ); |
289 | setSpacing( 0 ); | 289 | setSpacing( 0 ); |
290 | 290 | ||
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 | } |
355 | 356 | ||
356 | /*! | 357 | /*! |
357 | Returns the number of files in the view. If this is zero, an editor | 358 | Returns the number of files in the view. If this is zero, an editor |
358 | application might bypass the selector and immediately start with | 359 | application might bypass the selector and immediately start with |
359 | a "new" document. | 360 | a "new" document. |
360 | */ | 361 | */ |
361 | int FileSelector::fileCount() | 362 | int FileSelector::fileCount() |
362 | { | 363 | { |
363 | return d->files.children().count();; | 364 | return d->files.children().count();; |
364 | } | 365 | } |
365 | 366 | ||
366 | /*! | 367 | /*! |
367 | Calling this function is the programmatic equivalent of the user | 368 | Calling this function is the programmatic equivalent of the user |
368 | pressing the "new" button. | 369 | pressing the "new" button. |
369 | 370 | ||
370 | \sa newSelected(), closeMe() | 371 | \sa newSelected(), closeMe() |
371 | */ | 372 | */ |
372 | void FileSelector::createNew() | 373 | void FileSelector::createNew() |
373 | { | 374 | { |
374 | DocLnk f; | 375 | DocLnk f; |
375 | emit newSelected( f ); | 376 | emit newSelected( f ); |
376 | emit closeMe(); | 377 | emit closeMe(); |
377 | } | 378 | } |
378 | 379 | ||
379 | void FileSelector::fileClicked( int button, QListViewItem *i, const QPoint &, int ) | 380 | void FileSelector::fileClicked( int button, QListViewItem *i, const QPoint &, int ) |
380 | { | 381 | { |
381 | if ( !i ) | 382 | if ( !i ) |
382 | return; | 383 | return; |
383 | if ( button == Qt::LeftButton ) { | 384 | if ( button == Qt::LeftButton ) { |
384 | fileClicked( i ); | 385 | fileClicked( i ); |
385 | } | 386 | } |
386 | } | 387 | } |
387 | 388 | ||
388 | void FileSelector::filePressed( int button, QListViewItem *i, const QPoint &, int ) | 389 | void FileSelector::filePressed( int button, QListViewItem *i, const QPoint &, int ) |
389 | { | 390 | { |
390 | if ( !i || i == d->newDocItem ) | 391 | if ( !i || i == d->newDocItem ) |
391 | return; | 392 | return; |
392 | if ( button == Qt::RightButton ) { | 393 | if ( button == Qt::RightButton ) { |
393 | DocLnk l = ((FileSelectorItem *)i)->file(); | 394 | DocLnk l = ((FileSelectorItem *)i)->file(); |
394 | LnkProperties prop( &l ); | 395 | LnkProperties prop( &l ); |
395 | prop.showMaximized(); | 396 | prop.showMaximized(); |
396 | prop.exec(); | 397 | prop.exec(); |
397 | reread(); | 398 | reread(); |
398 | } | 399 | } |
399 | } | 400 | } |
400 | 401 | ||
401 | void FileSelector::fileClicked( QListViewItem *i ) | 402 | void FileSelector::fileClicked( QListViewItem *i ) |
402 | { | 403 | { |
403 | if ( !i ) | 404 | if ( !i ) |
404 | return; | 405 | return; |
405 | if ( i == d->newDocItem ) { | 406 | if ( i == d->newDocItem ) { |
406 | createNew(); | 407 | createNew(); |
407 | } else { | 408 | } else { |
408 | emit fileSelected( ( (FileSelectorItem*)i )->file() ); | 409 | emit fileSelected( ( (FileSelectorItem*)i )->file() ); |
409 | emit closeMe(); | 410 | emit closeMe(); |
410 | } | 411 | } |
411 | } | 412 | } |
412 | 413 | ||
413 | void FileSelector::typeSelected( const QString &type ) | 414 | void FileSelector::typeSelected( const QString &type ) |
414 | { | 415 | { |
415 | d->mimeFilters.clear(); | 416 | d->mimeFilters.clear(); |
416 | QStringList subFilter = QStringList::split(";", type); | 417 | QStringList subFilter = QStringList::split(";", type); |
417 | for( QStringList::Iterator it = subFilter.begin(); it != subFilter.end(); ++it ) | 418 | for( QStringList::Iterator it = subFilter.begin(); it != subFilter.end(); ++it ) |
418 | d->mimeFilters.append( QRegExp(*it, FALSE, TRUE) ); | 419 | d->mimeFilters.append( QRegExp(*it, FALSE, TRUE) ); |
419 | updateView(); | 420 | updateView(); |
420 | } | 421 | } |
421 | 422 | ||
422 | void FileSelector::catSelected( int c ) | 423 | void FileSelector::catSelected( int c ) |
423 | { | 424 | { |
424 | d->catId = c; | 425 | d->catId = c; |
425 | updateView(); | 426 | updateView(); |
426 | } | 427 | } |
427 | 428 | ||
428 | void FileSelector::cardMessage( const QCString &msg, const QByteArray &) | 429 | void FileSelector::cardMessage( const QCString &msg, const QByteArray &) |
429 | { | 430 | { |
430 | if ( msg == "mtabChanged()" ) | 431 | if ( msg == "mtabChanged()" ) |
431 | reread(); | 432 | reread(); |
432 | } | 433 | } |
433 | 434 | ||
434 | 435 | ||
435 | /*! | 436 | /*! |
436 | Returns the selected \link doclnk.html DocLnk\endlink. The caller is | 437 | Returns the selected \link doclnk.html DocLnk\endlink. The caller is |
437 | responsible for deleting the returned value. | 438 | responsible for deleting the returned value. |
438 | */ | 439 | */ |
439 | const DocLnk *FileSelector::selected() | 440 | const DocLnk *FileSelector::selected() |
440 | { | 441 | { |
441 | FileSelectorItem *item = (FileSelectorItem *)view->selectedItem(); | 442 | FileSelectorItem *item = (FileSelectorItem *)view->selectedItem(); |
442 | if ( item && item != d->newDocItem ) | 443 | if ( item && item != d->newDocItem ) |
443 | return new DocLnk( item->file() ); | 444 | return new DocLnk( item->file() ); |
444 | return NULL; | 445 | return NULL; |
445 | } | 446 | } |
446 | 447 | ||
447 | /*! | 448 | /*! |
448 | \fn void FileSelector::fileSelected( const DocLnk &f ) | 449 | \fn void FileSelector::fileSelected( const DocLnk &f ) |
449 | 450 | ||
450 | This signal is emitted when the user selects a document. | 451 | This signal is emitted when the user selects a document. |
451 | \a f is the document. | 452 | \a f is the document. |
452 | */ | 453 | */ |
453 | 454 | ||
454 | /*! | 455 | /*! |
455 | \fn void FileSelector::newSelected( const DocLnk &f ) | 456 | \fn void FileSelector::newSelected( const DocLnk &f ) |
456 | 457 | ||
457 | This signal is emitted when the user selects a "new" document. | 458 | This signal is emitted when the user selects a "new" document. |
458 | \a f is a DocLnk for the document. You will need to set the type | 459 | \a f is a DocLnk for the document. You will need to set the type |
459 | of the document after copying it. | 460 | of the document after copying it. |
460 | */ | 461 | */ |
461 | 462 | ||
462 | /*! | 463 | /*! |
463 | \fn void FileSelector::closeMe() | 464 | \fn void FileSelector::closeMe() |
464 | 465 | ||
465 | This signal is emitted when the user no longer needs to view the widget. | 466 | This signal is emitted when the user no longer needs to view the widget. |
466 | */ | 467 | */ |
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; |
531 | } | 551 | } |
532 | if ( mimeMatch && | 552 | if ( mimeMatch && |
533 | (d->catId == -2 || (*dit)->categories().contains(d->catId) || | 553 | (d->catId == -2 || (*dit)->categories().contains(d->catId) || |
534 | (d->catId == -1 && (*dit)->categories().isEmpty())) ) { | 554 | (d->catId == -1 && (*dit)->categories().isEmpty())) ) { |
535 | item = new FileSelectorItem( view, **dit ); | 555 | item = new FileSelectorItem( view, **dit ); |
536 | if ( item->file().file() == oldFile ) | 556 | if ( item->file().file() == oldFile ) |
537 | view->setCurrentItem( item ); | 557 | view->setCurrentItem( item ); |
538 | } | 558 | } |
539 | } | 559 | } |
540 | 560 | ||
541 | if ( d->showNew ) | 561 | if ( d->showNew ) |
542 | d->newDocItem = new NewDocItem( view, DocLnk() ); | 562 | d->newDocItem = new NewDocItem( view, DocLnk() ); |
543 | else | 563 | else |
544 | d->newDocItem = 0; | 564 | d->newDocItem = 0; |
545 | 565 | ||
546 | if ( !view->selectedItem() || view->childCount() == 1 ) { | 566 | if ( !view->selectedItem() || view->childCount() == 1 ) { |
547 | view->setCurrentItem( view->firstChild() ); | 567 | view->setCurrentItem( view->firstChild() ); |
548 | view->setSelected( view->firstChild(), TRUE ); | 568 | view->setSelected( view->firstChild(), TRUE ); |
549 | } | 569 | } |
550 | } | 570 | } |
551 | 571 | ||
552 | void FileSelector::updateWhatsThis() | 572 | void FileSelector::updateWhatsThis() |
553 | { | 573 | { |
554 | QWhatsThis::remove( this ); | 574 | QWhatsThis::remove( this ); |
555 | QString text = tr("Click to select a document from the list"); | 575 | QString text = tr("Click to select a document from the list"); |
556 | if ( d->showNew ) | 576 | if ( d->showNew ) |
557 | text += tr(", or select <b>New Document</b> to create a new document."); | 577 | text += tr(", or select <b>New Document</b> to create a new document."); |
558 | text += tr("<br><br>Click and hold for document properties."); | 578 | text += tr("<br><br>Click and hold for document properties."); |
559 | QWhatsThis::add( this, text ); | 579 | QWhatsThis::add( this, text ); |
560 | } | 580 | } |
561 | 581 | ||
562 | #include "fileselector.moc" | 582 | #include "fileselector.moc" |
563 | 583 | ||
diff --git a/library/fileselector.h b/library/fileselector.h index f1c9eb1..e3ae891 100644 --- a/library/fileselector.h +++ b/library/fileselector.h | |||
@@ -1,113 +1,115 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #ifndef FILESELECTOR_H | 20 | #ifndef FILESELECTOR_H |
21 | #define FILESELECTOR_H | 21 | #define FILESELECTOR_H |
22 | 22 | ||
23 | #include <qhbox.h> | 23 | #include <qhbox.h> |
24 | #include <qvbox.h> | 24 | #include <qvbox.h> |
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(); |
89 | 91 | ||
90 | private slots: | 92 | private slots: |
91 | void createNew(); | 93 | void createNew(); |
92 | void fileClicked( int, QListViewItem *, const QPoint &, int ); | 94 | void fileClicked( int, QListViewItem *, const QPoint &, int ); |
93 | // pressed to get 'right down' | 95 | // pressed to get 'right down' |
94 | void filePressed( int, QListViewItem *, const QPoint &, int ); | 96 | void filePressed( int, QListViewItem *, const QPoint &, int ); |
95 | void fileClicked( QListViewItem *); | 97 | void fileClicked( QListViewItem *); |
96 | void typeSelected( const QString &type ); | 98 | void typeSelected( const QString &type ); |
97 | void catSelected( int ); | 99 | void catSelected( int ); |
98 | void cardMessage( const QCString &, const QByteArray &); | 100 | void cardMessage( const QCString &, const QByteArray &); |
99 | 101 | ||
100 | private: | 102 | private: |
101 | void updateView(); | 103 | void updateView(); |
102 | void updateWhatsThis(); | 104 | void updateWhatsThis(); |
103 | 105 | ||
104 | private: | 106 | private: |
105 | // RESOLVE please -zecke@handhelds.org | 107 | // RESOLVE please -zecke@handhelds.org |
106 | const DocLnk *selected(); // use selectedDocument() luckily no compiler is putting the access into the symbol name | 108 | const DocLnk *selected(); // use selectedDocument() luckily no compiler is putting the access into the symbol name |
107 | FileSelectorView *view; | 109 | FileSelectorView *view; |
108 | QString filter; | 110 | QString filter; |
109 | QToolButton *buttonNew, *buttonClose; | 111 | QToolButton *buttonNew, *buttonClose; |
110 | FileSelectorPrivate *d; | 112 | FileSelectorPrivate *d; |
111 | }; | 113 | }; |
112 | 114 | ||
113 | #endif | 115 | #endif |