* ./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:
parent
1c572fe188
commit
1a33586cf9
|
@ -94,6 +94,7 @@ int main ( int argc, char* argv[] )
|
||||||
|
|
||||||
ConfEditorWidget* editor = new ConfEditorWidget ();
|
ConfEditorWidget* editor = new ConfEditorWidget ();
|
||||||
editor->show ();
|
editor->show ();
|
||||||
|
//QFileDialog::getOpenFileName(NULL, "Choose file", "", "");
|
||||||
|
|
||||||
returnCode = qa->exec ();
|
returnCode = qa->exec ();
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,17 +36,21 @@ namespace Cfg {
|
||||||
|
|
||||||
FilePathEdit::FilePathEdit ( Type type, std::string filter, QWidget* parent )
|
FilePathEdit::FilePathEdit ( Type type, std::string filter, QWidget* parent )
|
||||||
: QLineEdit (parent)
|
: QLineEdit (parent)
|
||||||
|
, _chooseButton (new QToolButton(this))
|
||||||
|
, _filePathDialog(NULL)
|
||||||
, _type (type)
|
, _type (type)
|
||||||
, _filter (filter)
|
, _filter (filter)
|
||||||
{
|
{
|
||||||
_chooseButton = new QToolButton(this);
|
|
||||||
QPixmap pixmap(":/images/choose.png");
|
QPixmap pixmap(":/images/choose.png");
|
||||||
|
|
||||||
_chooseButton->setIcon (QIcon(pixmap));
|
_chooseButton->setIcon (QIcon(pixmap));
|
||||||
_chooseButton->setIconSize (pixmap.size());
|
_chooseButton->setIconSize (pixmap.size());
|
||||||
_chooseButton->setCursor (Qt::ArrowCursor);
|
_chooseButton->setCursor (Qt::ArrowCursor);
|
||||||
_chooseButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
|
_chooseButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
|
||||||
_chooseButton->setToolTip(tr( (type&Filename)?"Choose file ...":"Choose directory ..." ));
|
_chooseButton->setToolTip (tr( (type&FileName)?"Choose file ...":"Choose directory ..." ));
|
||||||
|
|
||||||
connect ( _chooseButton, SIGNAL(clicked()), this, SLOT(updateLineEdit()) );
|
connect ( _chooseButton, SIGNAL(clicked()), this, SLOT(updateLineEdit()) );
|
||||||
|
|
||||||
setStyleSheet(QString("QLineEdit { padding-right: %1px; } ").arg(_chooseButton->sizeHint().width() + 1));
|
setStyleSheet(QString("QLineEdit { padding-right: %1px; } ").arg(_chooseButton->sizeHint().width() + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,11 +66,36 @@ namespace Cfg {
|
||||||
|
|
||||||
void FilePathEdit::updateLineEdit()
|
void FilePathEdit::updateLineEdit()
|
||||||
{
|
{
|
||||||
if (_type == FilePathEdit::Filename) {
|
QString result;
|
||||||
setText(QFileDialog::getOpenFileName(this, tr("Choose file"), "", tr(_filter.c_str())));
|
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
if (_type == FileName) {
|
||||||
|
result = QFileDialog::getOpenFileName ( this, tr("Choose File"), "", tr(_filter.c_str()) );
|
||||||
} else {
|
} 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 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -64,8 +64,8 @@ namespace Cfg {
|
||||||
case Parameter::String:
|
case Parameter::String:
|
||||||
{
|
{
|
||||||
QLineEdit* lineEdit = NULL;
|
QLineEdit* lineEdit = NULL;
|
||||||
if ( hasFlags(IsFileName) ) lineEdit = new FilePathEdit ( FilePathEdit::Filename );
|
if ( hasFlags(IsFileName) ) lineEdit = new FilePathEdit ( FilePathEdit::FileName );
|
||||||
else if ( hasFlags(IsPathName) ) lineEdit = new FilePathEdit ( FilePathEdit::Pathname );
|
else if ( hasFlags(IsPathName) ) lineEdit = new FilePathEdit ( FilePathEdit::PathName );
|
||||||
else lineEdit = new QLineEdit();
|
else lineEdit = new QLineEdit();
|
||||||
|
|
||||||
lineEdit->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Fixed );
|
lineEdit->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Fixed );
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
class QToolButton;
|
class QToolButton;
|
||||||
|
class QFileDialog;
|
||||||
|
|
||||||
|
|
||||||
namespace Cfg {
|
namespace Cfg {
|
||||||
|
@ -38,15 +39,16 @@ namespace Cfg {
|
||||||
{
|
{
|
||||||
Q_OBJECT;
|
Q_OBJECT;
|
||||||
public:
|
public:
|
||||||
enum Type { Filename=0x1, Pathname=0x2 };
|
enum Type { FileName=0x1, PathName=0x2 };
|
||||||
public:
|
public:
|
||||||
FilePathEdit ( Type type=Filename, std::string filter="", QWidget* parent=NULL );
|
FilePathEdit ( Type type=FileName, std::string filter="", QWidget* parent=NULL );
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent ( QResizeEvent* );
|
void resizeEvent ( QResizeEvent* );
|
||||||
private slots:
|
private slots:
|
||||||
void updateLineEdit ();
|
void updateLineEdit ();
|
||||||
private:
|
private:
|
||||||
QToolButton* _chooseButton;
|
QToolButton* _chooseButton;
|
||||||
|
QFileDialog* _filePathDialog;
|
||||||
Type _type;
|
Type _type;
|
||||||
std::string _filter;
|
std::string _filter;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue