* ./vslsisapd/src/configuration:

- Bug: In FilePathEdit, do not sets the file/path if the Dialog has been
        cancelled.
    - Bug: In FilePathEdit, do not uses the native dialog (called by static
        methods) when under Linux/GtkStyle as the native widget seems to be
        badly linked (bug in GtkStyle?).
This commit is contained in:
Jean-Paul Chaput 2010-09-16 20:41:39 +00:00
parent 1c572fe188
commit 1a33586cf9
4 changed files with 51 additions and 19 deletions

View File

@ -94,6 +94,7 @@ int main ( int argc, char* argv[] )
ConfEditorWidget* editor = new ConfEditorWidget ();
editor->show ();
//QFileDialog::getOpenFileName(NULL, "Choose file", "", "");
returnCode = qa->exec ();
}

View File

@ -35,38 +35,67 @@ namespace Cfg {
FilePathEdit::FilePathEdit ( Type type, std::string filter, QWidget* parent )
: QLineEdit(parent)
, _type (type)
, _filter (filter)
: QLineEdit (parent)
, _chooseButton (new QToolButton(this))
, _filePathDialog(NULL)
, _type (type)
, _filter (filter)
{
_chooseButton = new QToolButton(this);
QPixmap pixmap(":/images/choose.png");
_chooseButton->setIcon(QIcon(pixmap));
_chooseButton->setIconSize(pixmap.size());
_chooseButton->setCursor(Qt::ArrowCursor);
_chooseButton->setIcon (QIcon(pixmap));
_chooseButton->setIconSize (pixmap.size());
_chooseButton->setCursor (Qt::ArrowCursor);
_chooseButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
_chooseButton->setToolTip(tr( (type&Filename)?"Choose file ...":"Choose directory ..." ));
connect(_chooseButton, SIGNAL(clicked()), this, SLOT(updateLineEdit()));
_chooseButton->setToolTip (tr( (type&FileName)?"Choose file ...":"Choose directory ..." ));
connect ( _chooseButton, SIGNAL(clicked()), this, SLOT(updateLineEdit()) );
setStyleSheet(QString("QLineEdit { padding-right: %1px; } ").arg(_chooseButton->sizeHint().width() + 1));
}
void FilePathEdit::resizeEvent(QResizeEvent *)
{
QSize sz = _chooseButton->sizeHint();
QSize sz = _chooseButton->sizeHint ();
int l, t, r, b;
getContentsMargins(&l, &t, &r, &b);
_chooseButton->move(rect().right() - r - sz.width(), (rect().bottom() + 2 - sz.height())/2);
getContentsMargins (&l, &t, &r, &b );
_chooseButton->move ( rect().right() - r - sz.width(), (rect().bottom() + 2 - sz.height())/2 );
}
void FilePathEdit::updateLineEdit()
{
if (_type == FilePathEdit::Filename) {
setText(QFileDialog::getOpenFileName(this, tr("Choose file"), "", tr(_filter.c_str())));
QString result;
#if defined(__APPLE__)
if (_type == FileName) {
result = QFileDialog::getOpenFileName ( this, tr("Choose File"), "", tr(_filter.c_str()) );
} else {
setText(QFileDialog::getExistingDirectory(this, tr("Choose directory"), "", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks));
result = QFileDialog::getExistingDirectory ( this
, tr("Choose Directory")
, ""
, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks
);
}
#else
if ( _filePathDialog == NULL ) {
_filePathDialog = new QFileDialog ( this, tr((_type&FileName)?"Choose File":"Choose Directory") );
if (_type == FileName) {
_filePathDialog->setFileMode ( QFileDialog::ExistingFile );
} else {
_filePathDialog->setOption ( QFileDialog::ShowDirsOnly );
_filePathDialog->setOption ( QFileDialog::DontResolveSymlinks );
}
_filePathDialog->setViewMode ( QFileDialog::Detail );
_filePathDialog->selectNameFilter ( tr(_filter.c_str()) );
}
if ( _filePathDialog->exec() == QDialog::Accepted )
result = _filePathDialog->selectedFiles().at(0);
#endif
if ( not result.isEmpty() ) setText ( result );
}

View File

@ -64,8 +64,8 @@ namespace Cfg {
case Parameter::String:
{
QLineEdit* lineEdit = NULL;
if ( hasFlags(IsFileName) ) lineEdit = new FilePathEdit ( FilePathEdit::Filename );
else if ( hasFlags(IsPathName) ) lineEdit = new FilePathEdit ( FilePathEdit::Pathname );
if ( hasFlags(IsFileName) ) lineEdit = new FilePathEdit ( FilePathEdit::FileName );
else if ( hasFlags(IsPathName) ) lineEdit = new FilePathEdit ( FilePathEdit::PathName );
else lineEdit = new QLineEdit();
lineEdit->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Fixed );

View File

@ -29,6 +29,7 @@
#include <string>
#include <QLineEdit>
class QToolButton;
class QFileDialog;
namespace Cfg {
@ -38,15 +39,16 @@ namespace Cfg {
{
Q_OBJECT;
public:
enum Type { Filename=0x1, Pathname=0x2 };
enum Type { FileName=0x1, PathName=0x2 };
public:
FilePathEdit ( Type type=Filename, std::string filter="", QWidget* parent=NULL );
FilePathEdit ( Type type=FileName, std::string filter="", QWidget* parent=NULL );
protected:
void resizeEvent ( QResizeEvent* );
private slots:
void updateLineEdit ();
private:
QToolButton* _chooseButton;
QFileDialog* _filePathDialog;
Type _type;
std::string _filter;
};