Salome HOME
Moved some functionality to VTKViewer_Utilities.h
[modules/kernel.git] / src / PatchQt / qfiledialogP.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Module      : PatchQt
3 // File        : qfiledialogP.h
4 // Description : the patch for Qt's QFileDialog class (qfiledialog.h)
5 /////////////////////////////////////////////////////////////////////////////
6
7 /****************************************************************************
8 ** $Id$
9 **
10 ** Definition of QFileDialog class
11 **
12 ** Created : 950428
13 **
14 ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
15 **
16 ** This file is part of the dialogs module of the Qt GUI Toolkit.
17 **
18 ** This file may be distributed under the terms of the Q Public License
19 ** as defined by Trolltech AS of Norway and appearing in the file
20 ** LICENSE.QPL included in the packaging of this file.
21 **
22 ** This file may be distributed and/or modified under the terms of the
23 ** GNU General Public License version 2 as published by the Free Software
24 ** Foundation and appearing in the file LICENSE.GPL included in the
25 ** packaging of this file.
26 **
27 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
28 ** licenses may use this file in accordance with the Qt Commercial License
29 ** Agreement provided with the Software.
30 **
31 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
32 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
33 **
34 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
35 **   information about Qt Commercial License Agreements.
36 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
37 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
38 **
39 ** Contact info@trolltech.com if any conditions of this licensing are
40 ** not clear to you.
41 **
42 **********************************************************************/
43
44 #ifndef QFILEDIALOGP_H
45 #define QFILEDIALOGP_H
46
47 class QPushButton;
48 class QButton;
49 class QLabel;
50 class QWidget;
51 class QFileDialog;
52 class QTimer;
53 class QNetworkOperation;
54 class QLineEdit;
55 class QListViewItem;
56 class QListBoxItem;
57 class QProgressBar;
58 class QFileDialogPrivate;
59 class QFileDialogQFileListView;
60
61 #ifndef QT_H
62 #include "qdir.h"
63 #include "qdialog.h"
64 #include "qurloperator.h"
65 #include "qurlinfo.h"
66 #include "qlistbox.h"
67 #include "qlistview.h"
68 #include "qlineedit.h"
69 #endif // QT_H
70
71 #ifndef QT_NO_FILEDIALOG
72
73 class Q_EXPORT QFileIconProviderP : public QObject
74 {
75     Q_OBJECT
76 public:
77     QFileIconProviderP( QObject * parent = 0, const char* name = 0 );
78     virtual const QPixmap * pixmap( const QFileInfo & );
79
80 private:        // Disabled copy constructor and operator=
81 #if defined(Q_DISABLE_COPY)
82     QFileIconProviderP( const QFileIconProviderP & );
83     QFileIconProviderP& operator=( const QFileIconProviderP & );
84 #endif
85 };
86
87 class Q_EXPORT QFilePreviewP
88 {
89 public:
90     QFilePreviewP();
91     virtual void previewUrl( const QUrl &url ) = 0;
92
93 };
94
95 class Q_EXPORT QFileDialogP : public QDialog
96 {
97     Q_OBJECT
98     Q_ENUMS( Mode ViewMode PreviewMode )
99     // ##### Why are this read-only properties ?
100     Q_PROPERTY( QString selectedFile READ selectedFile )
101     Q_PROPERTY( QString selectedFilter READ selectedFilter )
102     Q_PROPERTY( QStringList selectedFiles READ selectedFiles )
103     // #### Should not we be able to set the path ?
104     Q_PROPERTY( QString dirPath READ dirPath )
105     Q_PROPERTY( bool showHiddenFiles READ showHiddenFiles WRITE setShowHiddenFiles )
106     Q_PROPERTY( Mode mode READ mode WRITE setMode )
107     Q_PROPERTY( ViewMode viewMode READ viewMode WRITE setViewMode )
108     Q_PROPERTY( PreviewMode previewMode READ previewMode WRITE setPreviewMode )
109     Q_PROPERTY( bool infoPreview READ isInfoPreviewEnabled WRITE setInfoPreviewEnabled )
110     Q_PROPERTY( bool contentsPreview READ isContentsPreviewEnabled WRITE setContentsPreviewEnabled )
111
112 public:
113     QFileDialogP( const QString& dirName, const QString& filter = QString::null,
114                  QWidget* parent=0, const char* name=0, bool modal = FALSE );
115     QFileDialogP( QWidget* parent=0, const char* name=0, bool modal = FALSE );
116     ~QFileDialogP();
117
118     // recommended static functions
119
120     static QString getOpenFileName( const QString &initially = QString::null,
121                                     const QString &filter = QString::null,
122                                     QWidget *parent = 0, const char* name = 0,
123                                     const QString &caption = QString::null,
124                                     QString *selectedFilter = 0,
125                                     bool resolveSymlinks = TRUE);
126     static QString getSaveFileName( const QString &initially = QString::null,
127                                     const QString &filter = QString::null,
128                                     QWidget *parent = 0, const char* name = 0,
129                                     const QString &caption = QString::null,
130                                     QString *selectedFilter = 0,
131                                     bool resolveSymlinks = TRUE);
132     static QString getExistingDirectory( const QString &dir = QString::null,
133                                          QWidget *parent = 0,
134                                          const char* name = 0,
135                                          const QString &caption = QString::null,
136                                          bool dirOnly = TRUE,
137                                          bool resolveSymlinks = TRUE);
138     static QStringList getOpenFileNames( const QString &filter= QString::null,
139                                          const QString &dir = QString::null,
140                                          QWidget *parent = 0,
141                                          const char* name = 0,
142                                          const QString &caption = QString::null,
143                                          QString *selectedFilter = 0,
144                                          bool resolveSymlinks = TRUE);
145
146     // other static functions
147
148     static void setIconProvider( QFileIconProviderP * );
149     static QFileIconProviderP* iconProvider();
150
151     // non-static function for special needs
152
153     QString selectedFile() const;
154     QString selectedFilter() const;
155     virtual void setSelectedFilter( const QString& );
156     virtual void setSelectedFilter( int );
157
158     void setSelection( const QString &);
159
160     void selectAll( bool b );
161
162     QStringList selectedFiles() const;
163
164     QString dirPath() const;
165
166     void setDir( const QDir & );
167     const QDir *dir() const;
168
169     void setShowHiddenFiles( bool s );
170     bool showHiddenFiles() const;
171
172     void rereadDir();
173     void resortDir();
174
175     enum Mode { AnyFile, ExistingFile, Directory, ExistingFiles, DirectoryOnly };
176     void setMode( Mode );
177     Mode mode() const;
178
179     enum ViewMode { Detail, List };
180     enum PreviewMode { NoPreview, Contents, Info };
181     void setViewMode( ViewMode m );
182     ViewMode viewMode() const;
183     void setPreviewMode( PreviewMode m );
184     PreviewMode previewMode() const;
185
186     bool eventFilter( QObject *, QEvent * );
187
188     bool isInfoPreviewEnabled() const;
189     bool isContentsPreviewEnabled() const;
190     void setInfoPreviewEnabled( bool );
191     void setContentsPreviewEnabled( bool );
192
193     void setInfoPreview( QWidget *w, QFilePreviewP *preview );
194     void setContentsPreview( QWidget *w, QFilePreviewP *preview );
195
196     QUrl url() const;
197
198     void addFilter( const QString &filter );
199
200 public slots:
201     void done( int );
202     void setDir( const QString& );
203     void setUrl( const QUrlOperator &url );
204     void setFilter( const QString& );
205     void setFilters( const QString& );
206     void setFilters( const char ** );
207     void setFilters( const QStringList& );
208
209 protected:
210     void resizeEvent( QResizeEvent * );
211     void keyPressEvent( QKeyEvent * );
212
213     void addWidgets( QLabel *, QWidget *, QPushButton * );
214     void addToolButton( QButton *b, bool separator = FALSE );
215     void addLeftWidget( QWidget *w );
216     void addRightWidget( QWidget *w );
217
218 signals:
219     void fileHighlighted( const QString& );
220     void fileSelected( const QString& );
221     void filesSelected( const QStringList& );
222     void dirEntered( const QString& );
223     void filterSelected( const QString& );
224
225 private slots:
226     void detailViewSelectionChanged();
227     void listBoxSelectionChanged();
228     void changeMode( int );
229     void fileNameEditReturnPressed();
230     void stopCopy();
231     void removeProgressDia();
232
233     void fileSelected( int );
234     void fileHighlighted( int );
235     void dirSelected( int );
236     void pathSelected( int );
237
238     void updateFileNameEdit( QListViewItem *);
239     void selectDirectoryOrFile( QListViewItem * );
240     void popupContextMenu( QListViewItem *, const QPoint &, int );
241     void popupContextMenu( QListBoxItem *, const QPoint & );
242     void updateFileNameEdit( QListBoxItem *);
243     void selectDirectoryOrFile( QListBoxItem * );
244     void fileNameEditDone();
245
246     void okClicked();
247     void filterClicked(); // not used
248     void cancelClicked();
249
250     void cdUpClicked();
251     void newFolderClicked();
252
253     void fixupNameEdit();
254
255     void doMimeTypeLookup();
256
257     void updateGeometries();
258     void modeButtonsDestroyed();
259     void urlStart( QNetworkOperation *op );
260     void urlFinished( QNetworkOperation *op );
261     void dataTransferProgress( int bytesDone, int bytesTotal, QNetworkOperation * );
262     void insertEntry( const QValueList<QUrlInfo> &fi, QNetworkOperation *op );
263     void removeEntry( QNetworkOperation * );
264     void createdDirectory( const QUrlInfo &info, QNetworkOperation * );
265     void itemChanged( QNetworkOperation * );
266     void goBack();
267
268 private:
269     enum PopupAction {
270         PA_Open = 0,
271         PA_Delete,
272         PA_Rename,
273         PA_SortName,
274         PA_SortSize,
275         PA_SortType,
276         PA_SortDate,
277         PA_SortUnsorted,
278         PA_Cancel,
279         PA_Reload,
280         PA_Hidden
281     };
282
283     void init();
284     bool trySetSelection( bool isDir, const QUrlOperator &, bool );
285     void deleteFile( const QString &filename );
286     void popupContextMenu( const QString &filename, bool withSort,
287                            PopupAction &action, const QPoint &p );
288
289     QDir reserved; // was cwd
290     QString fileName;
291
292     friend class QFileDialogQFileListView;
293     friend class QFileListBox;
294
295     QFileDialogPrivate *d;
296     QFileDialogQFileListView  *files;
297
298     QLineEdit  *nameEdit; // also filter
299     QPushButton *okB;
300     QPushButton *cancelB;
301
302 #if defined(Q_WS_WIN)
303     static QString winGetOpenFileName( const QString &initialSelection,
304                                        const QString &filter,
305                                        QString* workingDirectory,
306                                        QWidget *parent = 0,
307                                        const char* name = 0,
308                                        const QString& caption = QString::null,
309                                        QString* selectedFilter = 0 );
310     static QString winGetSaveFileName( const QString &initialSelection,
311                                        const QString &filter,
312                                        QString* workingDirectory,
313                                        QWidget *parent = 0,
314                                        const char* name = 0,
315                                        const QString& caption = QString::null,
316                                        QString* selectedFilter = 0 );
317     static QStringList winGetOpenFileNames( const QString &filter,
318                                             QString* workingDirectory,
319                                             QWidget *parent = 0,
320                                             const char* name = 0,
321                                             const QString& caption = QString::null,
322                                             QString* selectedFilter = 0 );
323     static QString winGetExistingDirectory( const QString &initialDirectory,
324                                             QWidget* parent = 0,
325                                             const char* name = 0,
326                                             const QString& caption = QString::null);
327     static QString resolveLinkFile( const QString& linkfile );
328 #endif
329 #if defined(Q_WS_MACX) || defined(Q_WS_MAC9)
330     static QString macGetSaveFileName( const QString &, const QString &, 
331                                        QString *, QWidget *, const char*,
332                                        const QString& );
333     static QStringList macGetOpenFileNames( const QString &, QString*,
334                                             QWidget *, const char *,
335                                             const QString&, bool = TRUE,
336                                             bool = FALSE );
337 #endif
338
339
340 private:        // Disabled copy constructor and operator=
341 #if defined(Q_DISABLE_COPY)
342     QFileDialogP( const QFileDialogP & );
343     QFileDialogP &operator=( const QFileDialogP & );
344 #endif
345 };
346
347 /******************************************************************
348  *
349  * Definitions of view classes
350  *
351  ******************************************************************/
352
353 class QRenameEdit : public QLineEdit
354 {
355     Q_OBJECT
356
357 public:
358     QRenameEdit( QWidget *parent )
359         : QLineEdit( parent, "qt_rename_edit" )
360     {}
361
362 protected:
363     void keyPressEvent( QKeyEvent *e );
364     void focusOutEvent( QFocusEvent *e );
365
366 signals:
367     void escapePressed();
368
369 };
370
371 class QFileListBox : public QListBox
372 {
373     friend class QFileDialogP;
374
375     Q_OBJECT
376
377 private:
378     QFileListBox( QWidget *parent, QFileDialogP *d );
379
380     void clear();
381     void show();
382     void startRename( bool check = TRUE );
383     void viewportMousePressEvent( QMouseEvent *e );
384     void viewportMouseReleaseEvent( QMouseEvent *e );
385     void viewportMouseDoubleClickEvent( QMouseEvent *e );
386     void viewportMouseMoveEvent( QMouseEvent *e );
387 #ifndef QT_NO_DRAGANDDROP
388     void viewportDragEnterEvent( QDragEnterEvent *e );
389     void viewportDragMoveEvent( QDragMoveEvent *e );
390     void viewportDragLeaveEvent( QDragLeaveEvent *e );
391     void viewportDropEvent( QDropEvent *e );
392     bool acceptDrop( const QPoint &pnt, QWidget *source );
393     void setCurrentDropItem( const QPoint &pnt );
394 #endif
395     void keyPressEvent( QKeyEvent *e );
396
397 private slots:
398     void rename();
399     void cancelRename();
400     void doubleClickTimeout();
401     void changeDirDuringDrag();
402     void dragObjDestroyed();
403     void contentsMoved( int, int );
404
405 private:
406     QRenameEdit *lined;
407     QFileDialogP *filedialog;
408     bool renaming;
409     QTimer* renameTimer;
410     QListBoxItem *renameItem, *dragItem;
411     QPoint pressPos, oldDragPos;
412     bool mousePressed;
413     int urls;
414     QString startDragDir;
415     QListBoxItem *currDropItem;
416     QTimer *changeDirTimer;
417     bool firstMousePressEvent;
418     QUrlOperator startDragUrl;
419
420 };
421
422
423 class QFileDialogQFileListView : public QListView
424 {
425     Q_OBJECT
426
427 public:
428     QFileDialogQFileListView( QWidget *parent, QFileDialogP *d );
429
430     void clear();
431     void startRename( bool check = TRUE );
432     void setSorting( int column, bool increasing = TRUE );
433
434     QRenameEdit *lined;
435     bool renaming;
436     QListViewItem *renameItem;
437
438 private:
439     void viewportMousePressEvent( QMouseEvent *e );
440     void viewportMouseDoubleClickEvent( QMouseEvent *e );
441     void keyPressEvent( QKeyEvent *e );
442     void viewportMouseReleaseEvent( QMouseEvent *e );
443     void viewportMouseMoveEvent( QMouseEvent *e );
444 #ifndef QT_NO_DRAGANDDROP
445     void viewportDragEnterEvent( QDragEnterEvent *e );
446     void viewportDragMoveEvent( QDragMoveEvent *e );
447     void viewportDragLeaveEvent( QDragLeaveEvent *e );
448     void viewportDropEvent( QDropEvent *e );
449     bool acceptDrop( const QPoint &pnt, QWidget *source );
450     void setCurrentDropItem( const QPoint &pnt );
451 #endif
452
453 private slots:
454     void rename();
455     void cancelRename();
456     void changeSortColumn2( int column );
457     void doubleClickTimeout();
458     void changeDirDuringDrag();
459     void dragObjDestroyed();
460     void contentsMoved( int, int );
461
462 private:
463     QFileDialogP *filedialog;
464     QTimer* renameTimer;
465     QPoint pressPos, oldDragPos;
466     bool mousePressed;
467     int urls;
468     QString startDragDir;
469     QListViewItem *currDropItem, *dragItem;
470     QTimer *changeDirTimer;
471     bool firstMousePressEvent;
472     bool ascending;
473     int sortcolumn;
474     QUrlOperator startDragUrl;
475
476 };
477
478 /****************************************************************************
479  *
480  * Classes for copy progress dialog
481  *
482  ****************************************************************************/
483
484 class QFDProgressAnimation : public QWidget
485 {
486     Q_OBJECT
487
488 public:
489     QFDProgressAnimation( QWidget *parent );
490     void start();
491
492 private slots:
493     void next();
494
495 protected:
496     void paintEvent( QPaintEvent *e );
497
498 private:
499     int step;
500     QTimer *timer;
501
502 };
503
504 class QFDProgressDialog : public QDialog
505 {
506     Q_OBJECT
507
508 public:
509     QFDProgressDialog( QWidget *parent, const QString &fn, int steps );
510
511     void setReadProgress( int p );
512     void setWriteProgress( int p );
513     void setWriteLabel( const QString &s );
514
515 signals:
516     void cancelled();
517
518 private:
519     QProgressBar *readBar;
520     QProgressBar *writeBar;
521     QLabel *writeLabel;
522     QFDProgressAnimation *animation;
523
524 };
525
526 #endif
527
528 #endif // QFILEDIALOG_H