QtFileDialog.cc

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 6743 $                                                       *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2009-08-05 11:03:10 +0200 (Mi, 05. Aug 2009) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 //=============================================================================
00046 //
00047 //  CLASS QtFileDialog - IMPLEMENTATION
00048 //
00049 //=============================================================================
00050 
00051 //== INCLUDES =================================================================
00052 
00053 #include "QtFileDialog.hh"
00054 
00055 #include <OpenMesh/Core/IO/IOManager.hh>
00056 
00057 #include <QFileDialog>
00058 #include <QMessageBox>
00059 #include <QString>
00060 
00061 
00062 //== NAMESPACES ===============================================================
00063 
00064 namespace ACG {
00065 
00066 //== IMPLEMENTATION ========================================================== 
00067 
00068 
00069 QString
00070 getOpenFileName(QWidget*        _parent, 
00071                 const QString&  _caption,
00072                 const QString&  _filter,
00073                 const QString&  _start)
00074 {
00075   return  
00076     QFileDialog::getOpenFileName( _parent,  // parent
00077                                   _caption, // caption
00078                                   _start,   // dir
00079                                   _filter,  // filter
00080                                   0,        // selected filter
00081                                   0        // options
00082                                   );
00083 }
00084 
00085 
00086 QString
00087 getOpenMeshName(QWidget*        _parent, 
00088                 const QString&  _caption,
00089                 const QString&  _start)
00090 {
00091   return  
00092     ACG::getOpenFileName(_parent, 
00093                          _caption,
00094                          OpenMesh::IO::IOManager().qt_read_filters().c_str(),
00095                          _start);
00096 }
00097 
00098 
00099 //-----------------------------------------------------------------------------
00100 
00101 
00102 QStringList
00103 getOpenFileNames(QWidget*        _parent,
00104                  const QString&  _caption,
00105                  const QString&  _filter,
00106                  const QString&  _start)
00107 {
00108   return
00109     QFileDialog::getOpenFileNames( _parent, // parent
00110                                    _caption, // caption
00111                                    _start, // dir
00112                                    _filter, //_filter
00113                                    0, // selected filter
00114                                    0 // options
00115                                    );
00116 }
00117 
00118 
00119 QStringList
00120 getOpenMeshNames(QWidget*        _parent,
00121                  const QString&  _caption,
00122                  const QString&  _start)
00123 {
00124   return
00125     ACG::getOpenFileNames(_parent, 
00126                           _caption,
00127                           OpenMesh::IO::IOManager().qt_read_filters().c_str(),
00128                           _start);
00129 }
00130 
00131 
00132 //-----------------------------------------------------------------------------
00133 
00134 
00135 QString
00136 getSaveFileName(QWidget*        _parent, 
00137                 const QString&  _caption, 
00138                 const QString&  _filter, 
00139                 bool            _askOW,
00140                 const QString&  _start)
00141 {
00142   QString filename = 
00143     QFileDialog::getSaveFileName ( _parent, // parent
00144                                    _caption, // caption
00145                                    _start, // dir
00146                                    _filter, // filter,
00147                                    0, // selected filter
00148                                    0 // options
00149                                    );
00150 
00151   if (_askOW && !filename.isEmpty() && QFile(filename).exists())
00152   {
00153     QString s;
00154     s += QString("The file\n  ");
00155     s += filename;
00156     s += QString("\nalready exists.\n\n");
00157     s += QString("Do you want to overwrite it?");
00158 
00159     if (QMessageBox::warning(_parent, "Overwrite", s,
00160                              QMessageBox::Yes | QMessageBox::Default,
00161                              QMessageBox::No  | QMessageBox::Escape)
00162         != QMessageBox::Yes)
00163       return QString::null;
00164   }
00165 
00166   return filename;
00167 }
00168 
00169 
00170 QString
00171 getSaveMeshName(QWidget*        _parent, 
00172                 const QString&  _caption, 
00173                 bool            _askOW,
00174                 const QString&  _start)
00175 {
00176   return
00177     ACG::getSaveFileName(_parent, 
00178                          _caption,
00179                          OpenMesh::IO::IOManager().
00180                          qt_write_filters().c_str(),
00181                          _askOW,
00182                          _start);
00183 }
00184 
00185 
00186 //=============================================================================
00187 } // namespace ACG
00188 //=============================================================================

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .