Core: Switch widget from 'ExpressionLineEdit' to 'ExpressionTextEdit'
+ minor dialog layout adjustments
This commit is contained in:
@@ -79,22 +79,22 @@ DlgExpressionInput::DlgExpressionInput(const App::ObjectIdentifier & _path,
|
||||
initializeVarSets();
|
||||
|
||||
// Connect signal(s)
|
||||
connect(ui->expression, &ExpressionLineEdit::textChanged,
|
||||
connect(ui->expression, &ExpressionTextEdit::textChanged,
|
||||
this, &DlgExpressionInput::textChanged);
|
||||
connect(discardBtn, &QPushButton::clicked,
|
||||
this, &DlgExpressionInput::setDiscarded);
|
||||
|
||||
if (expression) {
|
||||
ui->expression->setText(QString::fromStdString(expression->toString()));
|
||||
ui->expression->setPlainText(QString::fromStdString(expression->toString()));
|
||||
}
|
||||
else {
|
||||
QVariant text = parent->property("text");
|
||||
if (text.canConvert<QString>()) {
|
||||
ui->expression->setText(text.toString());
|
||||
ui->expression->setPlainText(text.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// Set document object on line edit to create auto completer
|
||||
// Set document object on text edit to create auto completer
|
||||
DocumentObject * docObj = path.getDocumentObject();
|
||||
ui->expression->setDocumentObject(docObj);
|
||||
|
||||
@@ -114,7 +114,7 @@ DlgExpressionInput::DlgExpressionInput(const App::ObjectIdentifier & _path,
|
||||
setAttribute(Qt::WA_TranslucentBackground, true);
|
||||
}
|
||||
else {
|
||||
ui->expression->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
ui->expression->setMinimumHeight(50);
|
||||
ui->horizontalSpacer_3->changeSize(0, 2);
|
||||
ui->verticalLayout->setContentsMargins(9, 9, 9, 9);
|
||||
this->adjustSize();
|
||||
@@ -360,8 +360,10 @@ void DlgExpressionInput::checkExpression(const QString& text)
|
||||
|
||||
static const bool NoCheckExpr = false;
|
||||
|
||||
void DlgExpressionInput::textChanged(const QString &text)
|
||||
void DlgExpressionInput::textChanged()
|
||||
{
|
||||
const QString& text = ui->expression->toPlainText();
|
||||
|
||||
if (text.isEmpty()) {
|
||||
okBtn->setDisabled(true);
|
||||
discardBtn->setDefault(true);
|
||||
@@ -371,17 +373,6 @@ void DlgExpressionInput::textChanged(const QString &text)
|
||||
okBtn->setDefault(true);
|
||||
|
||||
try {
|
||||
//resize the input field according to text size
|
||||
QFontMetrics fm(ui->expression->font());
|
||||
int width = QtTools::horizontalAdvance(fm, text) + 15;
|
||||
if (width < minimumWidth)
|
||||
ui->expression->setMinimumWidth(minimumWidth);
|
||||
else
|
||||
ui->expression->setMinimumWidth(width);
|
||||
|
||||
if(this->width() < ui->expression->minimumWidth())
|
||||
setMinimumWidth(ui->expression->minimumWidth());
|
||||
|
||||
checkExpression(text);
|
||||
if (varSetsVisible) {
|
||||
// If varsets are visible, check whether the varset info also
|
||||
@@ -917,7 +908,7 @@ void DlgExpressionInput::updateVarSetInfo(bool checkExpr)
|
||||
if (checkExpr) {
|
||||
// We have to check the text of the expression as well
|
||||
try {
|
||||
checkExpression(ui->expression->text());
|
||||
checkExpression(ui->expression->toPlainText());
|
||||
}
|
||||
catch (Base::Exception&) {
|
||||
okBtn->setEnabled(false);
|
||||
|
||||
@@ -111,7 +111,7 @@ private:
|
||||
QString& message) const;
|
||||
|
||||
private Q_SLOTS:
|
||||
void textChanged(const QString & text);
|
||||
void textChanged();
|
||||
void setDiscarded();
|
||||
void onCheckVarSets(int state);
|
||||
void onVarSetSelected(int index);
|
||||
|
||||
@@ -143,9 +143,9 @@
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
<widget class="Gui::ExpressionLineEdit" name="expression">
|
||||
<widget class="Gui::ExpressionTextEdit" name="expression">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Ignored" vsizetype="Ignored">
|
||||
<sizepolicy hsizetype="Ignored" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
@@ -312,24 +312,41 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::StandardButton::Ok|QDialogButtonBox::StandardButton::Reset</set>
|
||||
</property>
|
||||
</widget>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::StandardButton::Ok|QDialogButtonBox::StandardButton::Reset</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>Gui::ExpressionLineEdit</class>
|
||||
<extends>QLineEdit</extends>
|
||||
<class>Gui::ExpressionTextEdit</class>
|
||||
<extends>QTextEdit</extends>
|
||||
<header>ExpressionCompleter.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
|
||||
@@ -1085,6 +1085,11 @@ void ExpressionTextEdit::setExactMatch(bool enabled)
|
||||
}
|
||||
}
|
||||
|
||||
QSize ExpressionTextEdit::sizeHint() const
|
||||
{
|
||||
return QSize(200, 30);
|
||||
}
|
||||
|
||||
void ExpressionTextEdit::setDocumentObject(const App::DocumentObject* currentDocObj)
|
||||
{
|
||||
if (completer) {
|
||||
|
||||
@@ -130,6 +130,7 @@ public:
|
||||
bool completerActive() const;
|
||||
void hideCompleter();
|
||||
void setExactMatch(bool enabled=true);
|
||||
QSize sizeHint() const override;
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent * event) override;
|
||||
void contextMenuEvent(QContextMenuEvent * event) override;
|
||||
|
||||
Reference in New Issue
Block a user