45 mUseRelativePath =
false;
50 mLayout =
new QGridLayout(
this);
51 mLayout->setMargin(0);
53 mFilenameEdit =
new QLineEdit(
this);
54 mFilenameEdit->setToolTip(
"File name");
55 connect(mFilenameEdit, SIGNAL(editingFinished()),
this, SIGNAL(
fileChanged()));
56 connect(mFilenameEdit, SIGNAL(textChanged(
const QString&)),
this, SLOT(updateColor()));
57 mLayout->addWidget(mFilenameEdit, 0, 1);
59 mBrowseAction =
new QAction(QIcon(
":/icons/open.png"),
"Browse",
this);
60 mBrowseAction->setStatusTip(
"Browse the file system");
61 connect(mBrowseAction, SIGNAL(triggered()),
this, SLOT(browse()));
63 mBrowseButton =
new QToolButton();
64 mBrowseButton->setDefaultAction(mBrowseAction);
65 mLayout->addWidget(mBrowseButton, 0, 2);
72 mDescription =
new QLabel(
this);
73 mLayout->addWidget(mDescription, 0,0);
76 mDescription->setText(text);
81 if (text==mFilenameEdit->text())
83 mFilenameEdit->setText(text);
84 this->widgetHasBeenChanged();
87 void FileInputWidget::widgetHasBeenChanged()
89 this->updateHelpInternal();
97 this->updateHelpInternal();
100 void FileInputWidget::updateHelpInternal()
103 mFilenameEdit->setToolTip(text);
104 mFilenameEdit->setStatusTip(text);
109 mBrowseAction->setToolTip(text);
110 mBrowseAction->setStatusTip(text);
116 this->widgetHasBeenChanged();
119 void FileInputWidget::browse()
121 QString text =
"Select file";
122 if (mUseRelativePath)
123 text = QString(
"Select file relative to %1").arg(mBasePath);
125 QString filename = QFileDialog::getOpenFileName(
this, text, mBasePath);
126 if (filename.isEmpty())
129 if (mUseRelativePath)
130 filename = QDir(mBasePath).relativeFilePath(filename);
137 return mFilenameEdit->text();
142 QString absolute = QDir(mBasePath).absoluteFilePath(this->
getFilename().trimmed());
143 QString cleaned = QDir().cleanPath(absolute);
149 mUseRelativePath = on;
150 this->widgetHasBeenChanged();
153 void FileInputWidget::updateColor()
155 QColor color = QColor(
"black");
157 color = QColor(
"red");
159 QPalette p = mFilenameEdit->palette();
160 p.setColor(QPalette::Text, color);
161 mFilenameEdit->setPalette(p);