24 mUseRelativePath =
false;
29 mLayout =
new QGridLayout(
this);
30 mLayout->setMargin(0);
32 mFilenameEdit =
new QTextEdit(
this);
33 mFilenameEdit->setToolTip(
"File names");
36 connect(mFilenameEdit, SIGNAL(textChanged()),
this, SLOT(evaluateTextChanges()));
37 mLayout->addWidget(mFilenameEdit, 0, 1);
39 mBrowseAction =
new QAction(QIcon(
":/icons/open.png"),
"Browse",
this);
40 mBrowseAction->setStatusTip(
"Browse the file system");
41 connect(mBrowseAction, SIGNAL(triggered()),
this, SLOT(browse()));
43 mBrowseButton =
new QToolButton();
44 mBrowseButton->setDefaultAction(mBrowseAction);
45 mLayout->addWidget(mBrowseButton, 0, 2);
52 mDescription =
new QLabel(
this);
53 mLayout->addWidget(mDescription, 0,0);
56 mDescription->setText(text);
61 QStringList files = this->convertToAbsoluteFilenames(text);
67 QString output = this->convertFilenamesToTextEditText(files);
68 mFilenameEdit->setText(output);
76 this->widgetHasBeenChanged();
79 QStringList MultiFileInputWidget::convertToAbsoluteFilenames(QStringList text)
const 82 for (
unsigned i=0; i<text.size(); ++i)
83 retval << this->convertToAbsoluteFilename(text[i]);
86 QString MultiFileInputWidget::convertToAbsoluteFilename(QString text)
const 90 QString absolute = QDir(mBasePath).absoluteFilePath(text.trimmed());
91 QString cleaned = QDir().cleanPath(absolute);
92 if (!QFileInfo(cleaned).exists())
96 QString MultiFileInputWidget::convertFilenamesToTextEditText(QStringList files)
const 99 for (
unsigned i=0; i<files.size(); ++i)
101 retval << this->convertToPresentableFilename(files[i]);
103 return retval.join(
"\n");
106 QString MultiFileInputWidget::convertToPresentableFilename(QString absoluteFilename)
const 108 QString retval = absoluteFilename;
109 if (!QFileInfo(absoluteFilename).exists())
112 if (mUseRelativePath)
114 retval = QDir(mBasePath).relativeFilePath(absoluteFilename);
115 if (retval.isEmpty())
123 void MultiFileInputWidget::widgetHasBeenChanged()
125 this->updateHelpInternal();
133 this->updateHelpInternal();
136 void MultiFileInputWidget::updateHelpInternal()
139 QString text = QString(
"%1\n\n%2").arg(mBaseHelp).arg(files);
140 mFilenameEdit->setToolTip(text);
141 mFilenameEdit->setStatusTip(text);
146 mBrowseAction->setToolTip(text);
147 mBrowseAction->setStatusTip(text);
153 this->widgetHasBeenChanged();
156 void MultiFileInputWidget::browse()
158 QString text =
"Select file";
159 if (mUseRelativePath)
160 text = QString(
"Select file relative to %1").arg(mBasePath);
162 QString filename = QFileDialog::getExistingDirectory(
this, text, mBasePath);
163 if (filename.isEmpty())
179 return mFilenameEdit->toPlainText().split(
'\n');
184 return this->convertToAbsoluteFilenames(mFilenameEdit->toPlainText().split(
"\n"));
192 mUseRelativePath = on;
193 this->widgetHasBeenChanged();
196 void MultiFileInputWidget::evaluateTextChanges()
198 this->updateHelpInternal();
201 if (current!=mLastFilenames)
203 mLastFilenames = current;
208 void MultiFileInputWidget::updateColor()
210 mFilenameEdit->blockSignals(
true);
211 QTextCursor cursor = mFilenameEdit->textCursor();
212 int pos = cursor.position();
214 QStringList org = mFilenameEdit->toPlainText().split(
"\n");
215 mFilenameEdit->setPlainText(
"");
216 for (
int i=0; i<org.size(); ++i)
218 bool exists = QFileInfo(this->convertToAbsoluteFilename(org[i])).exists();
221 mFilenameEdit->setTextColor(QColor(
"black"));
223 mFilenameEdit->setTextColor(QColor(
"red"));
225 mFilenameEdit->textCursor().insertText(
"\n");
226 mFilenameEdit->textCursor().insertText(org[i]);
229 cursor.setPosition(pos);
234 mFilenameEdit->setTextCursor(cursor);
235 mFilenameEdit->blockSignals(
false);
Namespace for all CustusX production code.