Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / Qtx / QtxPathDialog.h
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File:      QtxPathDialog.h
23 // Author:    Sergey TELKOV
24 //
25 #ifndef QTXPATHDIALOG_H
26 #define QTXPATHDIALOG_H
27
28 #include "QtxDialog.h"
29
30 #include <QMap>
31
32 class QFrame;
33 class QLineEdit;
34 class QPushButton;
35 class QFileDialog;
36
37 #ifdef WIN32
38 #pragma warning( disable:4251 )
39 #endif
40
41 class QTX_EXPORT QtxPathDialog : public QtxDialog
42 {
43   Q_OBJECT
44
45 protected:
46   QtxPathDialog( QWidget* = 0, const bool = true, const bool = false,
47                  const int = Standard, Qt::WindowFlags = 0 );
48
49 public:
50   QtxPathDialog( const bool, QWidget* = 0, const bool = true,
51                  const bool = false, const int = Standard, Qt::WindowFlags = 0 );
52   virtual ~QtxPathDialog();
53
54   QString            fileName() const;
55   void               setFileName( const QString&, const bool = false );
56
57   QString            filter() const;
58   void               setFilter( const QString& );
59
60 signals:
61   void               fileNameChanged( QString );
62
63 public slots:
64   virtual void       setVisible( bool );
65
66 protected slots:
67   void               validate();
68
69 private slots:
70   void               onBrowse();
71   void               onReturnPressed();
72   void               onTextChanged( const QString& );
73
74 protected:
75   virtual bool       isValid();
76   virtual bool       acceptData() const;
77   virtual void       fileNameChanged( int, QString );
78
79   QFrame*            optionsFrame();
80   QString            fileName( const int ) const;
81   void               setFileName( const int, const QString&, const bool = false );
82
83   QString            filter( const int ) const;
84   void               setFilter( const int, const QString& );
85
86   QLineEdit*         fileEntry( const int ) const;
87   QLineEdit*         fileEntry( const int, int& ) const;
88   int                createFileEntry( const QString&, const int,
89                                       const QString& = QString(), const int = -1 );
90
91   int                defaultEntry() const;
92   void               setDefaultEntry( const int );
93
94 private:
95   void               initialize();
96   void               updateVisibility();
97   QStringList        prepareFilters( const QString& ) const;
98         bool               hasVisibleChildren( QWidget* ) const;
99   QStringList        filterWildCards( const QString& ) const;
100   QString            autoExtension( const QString&, const QString& = QString() ) const;
101
102 protected:
103   enum { OpenFile, SaveFile, OpenDir, SaveDir, NewDir };
104
105 private:
106   typedef struct { int mode; QLineEdit* edit; QString filter;
107                    QPushButton* btn; QFileDialog* dlg; } FileEntry;
108   typedef QMap<int, FileEntry> FileEntryMap;
109
110 private:
111   FileEntryMap       myEntries;
112   int                myDefault;
113   QWidget*           myEntriesFrame;
114   QFrame*            myOptionsFrame;
115 };
116
117 #ifdef WIN32
118 #pragma warning( default:4251 )
119 #endif
120
121 #endif