45 mUseRelativePath =
false;
50 mLayout =
new QGridLayout(
this);
51 mLayout->setMargin(0);
53 mFilenameEdit =
new QTextEdit(
this);
54 mFilenameEdit->setToolTip(
"File names");
57 connect(mFilenameEdit, SIGNAL(textChanged()),
this, SLOT(evaluateTextChanges()));
58 mLayout->addWidget(mFilenameEdit, 0, 1);
60 mBrowseAction =
new QAction(QIcon(
":/icons/open.png"),
"Browse",
this);
61 mBrowseAction->setStatusTip(
"Browse the file system");
62 connect(mBrowseAction, SIGNAL(triggered()),
this, SLOT(browse()));
64 mBrowseButton =
new QToolButton();
65 mBrowseButton->setDefaultAction(mBrowseAction);
66 mLayout->addWidget(mBrowseButton, 0, 2);
73 mDescription =
new QLabel(
this);
74 mLayout->addWidget(mDescription, 0,0);
77 mDescription->setText(text);
82 QStringList files = this->convertToAbsoluteFilenames(text);
88 QString output = this->convertFilenamesToTextEditText(files);
89 mFilenameEdit->setText(output);
97 this->widgetHasBeenChanged();
100 QStringList MultiFileInputWidget::convertToAbsoluteFilenames(QStringList text)
const
103 for (
unsigned i=0; i<text.size(); ++i)
104 retval << this->convertToAbsoluteFilename(text[i]);
107 QString MultiFileInputWidget::convertToAbsoluteFilename(QString text)
const
111 QString absolute = QDir(mBasePath).absoluteFilePath(text.trimmed());
112 QString cleaned = QDir().cleanPath(absolute);
113 if (!QFileInfo(cleaned).exists())
117 QString MultiFileInputWidget::convertFilenamesToTextEditText(QStringList files)
const
120 for (
unsigned i=0; i<files.size(); ++i)
122 retval << this->convertToPresentableFilename(files[i]);
124 return retval.join(
"\n");
127 QString MultiFileInputWidget::convertToPresentableFilename(QString absoluteFilename)
const
129 QString retval = absoluteFilename;
130 if (!QFileInfo(absoluteFilename).exists())
133 if (mUseRelativePath)
135 retval = QDir(mBasePath).relativeFilePath(absoluteFilename);
136 if (retval.isEmpty())
144 void MultiFileInputWidget::widgetHasBeenChanged()
146 this->updateHelpInternal();
154 this->updateHelpInternal();
157 void MultiFileInputWidget::updateHelpInternal()
160 QString text = QString(
"%1\n\n%2").arg(mBaseHelp).arg(files);
161 mFilenameEdit->setToolTip(text);
162 mFilenameEdit->setStatusTip(text);
167 mBrowseAction->setToolTip(text);
168 mBrowseAction->setStatusTip(text);
174 this->widgetHasBeenChanged();
177 void MultiFileInputWidget::browse()
179 QString text =
"Select file";
180 if (mUseRelativePath)
181 text = QString(
"Select file relative to %1").arg(mBasePath);
183 QString filename = QFileDialog::getExistingDirectory(
this, text, mBasePath);
184 if (filename.isEmpty())
200 return mFilenameEdit->toPlainText().split(
'\n');
205 return this->convertToAbsoluteFilenames(mFilenameEdit->toPlainText().split(
"\n"));
213 mUseRelativePath = on;
214 this->widgetHasBeenChanged();
217 void MultiFileInputWidget::evaluateTextChanges()
219 this->updateHelpInternal();
222 if (current!=mLastFilenames)
224 mLastFilenames = current;
229 void MultiFileInputWidget::updateColor()
231 mFilenameEdit->blockSignals(
true);
232 QTextCursor cursor = mFilenameEdit->textCursor();
233 int pos = cursor.position();
235 QStringList org = mFilenameEdit->toPlainText().split(
"\n");
236 mFilenameEdit->setPlainText(
"");
237 for (
int i=0; i<org.size(); ++i)
239 bool exists = QFileInfo(this->convertToAbsoluteFilename(org[i])).exists();
242 mFilenameEdit->setTextColor(QColor(
"black"));
244 mFilenameEdit->setTextColor(QColor(
"red"));
246 mFilenameEdit->textCursor().insertText(
"\n");
247 mFilenameEdit->textCursor().insertText(org[i]);
250 cursor.setPosition(pos);
255 mFilenameEdit->setTextCursor(cursor);
256 mFilenameEdit->blockSignals(
false);