24 mUseRelativePath =
false;
29 mLayout =
new QGridLayout(
this);
30 mLayout->setMargin(0);
32 mFilenameEdit =
new QLineEdit(
this);
33 mFilenameEdit->setToolTip(
"File name");
34 connect(mFilenameEdit, SIGNAL(editingFinished()),
this, SIGNAL(
fileChanged()));
35 connect(mFilenameEdit, SIGNAL(textChanged(
const QString&)),
this, SLOT(updateColor()));
36 mLayout->addWidget(mFilenameEdit, 0, 1);
38 mBrowseAction =
new QAction(QIcon(
":/icons/open.png"),
"Browse",
this);
39 mBrowseAction->setStatusTip(
"Browse the file system");
40 connect(mBrowseAction, SIGNAL(triggered()),
this, SLOT(browse()));
42 mBrowseButton =
new QToolButton();
43 mBrowseButton->setDefaultAction(mBrowseAction);
44 mLayout->addWidget(mBrowseButton, 0, 2);
51 mDescription =
new QLabel(
this);
52 mLayout->addWidget(mDescription, 0,0);
55 mDescription->setText(text);
60 if (text==mFilenameEdit->text())
62 mFilenameEdit->setText(text);
63 this->widgetHasBeenChanged();
66 void FileInputWidget::widgetHasBeenChanged()
68 this->updateHelpInternal();
76 this->updateHelpInternal();
79 void FileInputWidget::updateHelpInternal()
82 mFilenameEdit->setToolTip(text);
83 mFilenameEdit->setStatusTip(text);
88 mBrowseAction->setToolTip(text);
89 mBrowseAction->setStatusTip(text);
95 this->widgetHasBeenChanged();
98 void FileInputWidget::browse()
100 QString text =
"Select file";
101 if (mUseRelativePath)
102 text = QString(
"Select file relative to %1").arg(mBasePath);
104 QString filename = QFileDialog::getOpenFileName(
this, text, mBasePath);
105 if (filename.isEmpty())
108 if (mUseRelativePath)
109 filename = QDir(mBasePath).relativeFilePath(filename);
116 return mFilenameEdit->text();
121 QString absolute = QDir(mBasePath).absoluteFilePath(this->
getFilename().trimmed());
122 QString cleaned = QDir().cleanPath(absolute);
128 mUseRelativePath = on;
129 this->widgetHasBeenChanged();
132 void FileInputWidget::updateColor()
134 QColor color = QColor(
"black");
136 color = QColor(
"red");
138 QPalette p = mFilenameEdit->palette();
139 p.setColor(QPalette::Text, color);
140 mFilenameEdit->setPalette(p);
Namespace for all CustusX production code.