Skip to content

Commit

Permalink
Add fancy unit/math input to pad tool
Browse files Browse the repository at this point in the history
Pad tool does not currently save the units, so the result is still in mm.
  • Loading branch information
s7726 committed Feb 8, 2014
1 parent 2ee101d commit a40a5dd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 34 deletions.
64 changes: 32 additions & 32 deletions src/Mod/PartDesign/Gui/TaskPadParameters.cpp
Expand Up @@ -61,13 +61,13 @@ TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView,QWidget *parent)
ui->setupUi(proxy);
QMetaObject::connectSlotsByName(this);

connect(ui->doubleSpinBox, SIGNAL(valueChanged(double)),
connect(ui->lengthEdit, SIGNAL(valueChanged(double)),
this, SLOT(onLengthChanged(double)));
connect(ui->checkBoxMidplane, SIGNAL(toggled(bool)),
this, SLOT(onMidplane(bool)));
connect(ui->checkBoxReversed, SIGNAL(toggled(bool)),
this, SLOT(onReversed(bool)));
connect(ui->doubleSpinBox2, SIGNAL(valueChanged(double)),
connect(ui->lengthEdit2, SIGNAL(valueChanged(double)),
this, SLOT(onLength2Changed(double)));
connect(ui->changeMode, SIGNAL(currentIndexChanged(int)),
this, SLOT(onModeChanged(int)));
Expand All @@ -81,8 +81,8 @@ TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView,QWidget *parent)
this->groupLayout()->addWidget(proxy);

// Temporarily prevent unnecessary feature recomputes
ui->doubleSpinBox->blockSignals(true);
ui->doubleSpinBox2->blockSignals(true);
ui->lengthEdit->blockSignals(true);
ui->lengthEdit2->blockSignals(true);
ui->checkBoxMidplane->blockSignals(true);
ui->checkBoxReversed->blockSignals(true);
ui->buttonFace->blockSignals(true);
Expand All @@ -106,12 +106,12 @@ TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView,QWidget *parent)
}

// Fill data into dialog elements
ui->doubleSpinBox->setMinimum(0);
ui->doubleSpinBox->setMaximum(INT_MAX);
ui->doubleSpinBox->setValue(l);
ui->doubleSpinBox2->setMinimum(0);
ui->doubleSpinBox2->setMaximum(INT_MAX);
ui->doubleSpinBox2->setValue(l2);
ui->lengthEdit->setMinimum(0);
ui->lengthEdit->setMaximum(INT_MAX);
ui->lengthEdit->setValue(l);
ui->lengthEdit2->setMinimum(0);
ui->lengthEdit2->setMaximum(INT_MAX);
ui->lengthEdit2->setValue(l2);
ui->checkBoxMidplane->setChecked(midplane);
// According to bug #0000521 the reversed option
// shouldn't be de-activated if the pad has a support face
Expand All @@ -129,8 +129,8 @@ TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView,QWidget *parent)
ui->changeMode->setCurrentIndex(index);

// activate and de-activate dialog elements as appropriate
ui->doubleSpinBox->blockSignals(false);
ui->doubleSpinBox2->blockSignals(false);
ui->lengthEdit->blockSignals(false);
ui->lengthEdit2->blockSignals(false);
ui->checkBoxMidplane->blockSignals(false);
ui->checkBoxReversed->blockSignals(false);
ui->buttonFace->blockSignals(false);
Expand All @@ -142,45 +142,45 @@ TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView,QWidget *parent)
void TaskPadParameters::updateUI(int index)
{
if (index == 0) { // dimension
ui->doubleSpinBox->setEnabled(true);
ui->doubleSpinBox->selectAll();
ui->lengthEdit->setEnabled(true);
ui->lengthEdit->selectAll();
// Make sure that the spin box has the focus to get key events
// Calling setFocus() directly doesn't work because the spin box is not
// yet visible.
QMetaObject::invokeMethod(ui->doubleSpinBox, "setFocus", Qt::QueuedConnection);
QMetaObject::invokeMethod(ui->lengthEdit, "setFocus", Qt::QueuedConnection);
ui->checkBoxMidplane->setEnabled(true);
// Reverse only makes sense if Midplane is not true
ui->checkBoxReversed->setEnabled(!ui->checkBoxMidplane->isChecked());
ui->doubleSpinBox2->setEnabled(false);
ui->lengthEdit2->setEnabled(false);
ui->buttonFace->setEnabled(false);
ui->lineFaceName->setEnabled(false);
onButtonFace(false);
} else if (index == 1 || index == 2) { // up to first/last
ui->doubleSpinBox->setEnabled(false);
ui->lengthEdit->setEnabled(false);
ui->checkBoxMidplane->setEnabled(false);
ui->checkBoxReversed->setEnabled(true);
ui->doubleSpinBox2->setEnabled(false);
ui->lengthEdit2->setEnabled(false);
ui->buttonFace->setEnabled(false);
ui->lineFaceName->setEnabled(false);
onButtonFace(false);
} else if (index == 3) { // up to face
ui->doubleSpinBox->setEnabled(false);
ui->lengthEdit->setEnabled(false);
ui->checkBoxMidplane->setEnabled(false);
ui->checkBoxReversed->setEnabled(false);
ui->doubleSpinBox2->setEnabled(false);
ui->lengthEdit2->setEnabled(false);
ui->buttonFace->setEnabled(true);
ui->lineFaceName->setEnabled(true);
QMetaObject::invokeMethod(ui->lineFaceName, "setFocus", Qt::QueuedConnection);
// Go into reference selection mode if no face has been selected yet
if (ui->lineFaceName->text().isEmpty())
onButtonFace(true);
} else { // two dimensions
ui->doubleSpinBox->setEnabled(true);
ui->doubleSpinBox->selectAll();
QMetaObject::invokeMethod(ui->doubleSpinBox, "setFocus", Qt::QueuedConnection);
ui->lengthEdit->setEnabled(true);
ui->lengthEdit->selectAll();
QMetaObject::invokeMethod(ui->lengthEdit, "setFocus", Qt::QueuedConnection);
ui->checkBoxMidplane->setEnabled(false);
ui->checkBoxReversed->setEnabled(false);
ui->doubleSpinBox2->setEnabled(true);
ui->lengthEdit2->setEnabled(true);
ui->buttonFace->setEnabled(false);
ui->lineFaceName->setEnabled(false);
onButtonFace(false);
Expand Down Expand Up @@ -273,8 +273,8 @@ void TaskPadParameters::onModeChanged(int index)
case 0:
pcPad->Type.setValue("Length");
// Avoid error message
if (ui->doubleSpinBox->value() < Precision::Confusion())
ui->doubleSpinBox->setValue(5.0);
if (ui->lengthEdit->getQuantity() < Precision::Confusion())
ui->lengthEdit->setValue(5.0);
break;
case 1: pcPad->Type.setValue("UpToLast"); break;
case 2: pcPad->Type.setValue("UpToFirst"); break;
Expand Down Expand Up @@ -357,7 +357,7 @@ void TaskPadParameters::onUpdateView(bool on)

double TaskPadParameters::getLength(void) const
{
return ui->doubleSpinBox->value();
return ui->lengthEdit->getQuantity().getValue();
}

bool TaskPadParameters::getReversed(void) const
Expand All @@ -372,7 +372,7 @@ bool TaskPadParameters::getMidplane(void) const

double TaskPadParameters::getLength2(void) const
{
return ui->doubleSpinBox2->value();
return ui->lengthEdit2->getQuantity().getValue();
}

int TaskPadParameters::getMode(void) const
Expand All @@ -399,8 +399,8 @@ void TaskPadParameters::changeEvent(QEvent *e)
{
TaskBox::changeEvent(e);
if (e->type() == QEvent::LanguageChange) {
ui->doubleSpinBox->blockSignals(true);
ui->doubleSpinBox2->blockSignals(true);
ui->lengthEdit->blockSignals(true);
ui->lengthEdit2->blockSignals(true);
ui->lineFaceName->blockSignals(true);
ui->changeMode->blockSignals(true);
int index = ui->changeMode->currentIndex();
Expand All @@ -422,8 +422,8 @@ void TaskPadParameters::changeEvent(QEvent *e)
ui->lineFaceName->setText(ok ?
tr("Face") + QString::number(faceId) :
tr("No face selected"));
ui->doubleSpinBox->blockSignals(false);
ui->doubleSpinBox2->blockSignals(false);
ui->lengthEdit->blockSignals(false);
ui->lengthEdit2->blockSignals(false);
ui->lineFaceName->blockSignals(false);
ui->changeMode->blockSignals(false);
}
Expand Down
11 changes: 9 additions & 2 deletions src/Mod/PartDesign/Gui/TaskPadParameters.ui
Expand Up @@ -44,7 +44,7 @@
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="doubleSpinBox">
<widget class="Gui::InputField" name="lengthEdit">
<property name="minimum">
<double>0.000000000000000</double>
</property>
Expand Down Expand Up @@ -88,7 +88,7 @@
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="doubleSpinBox2">
<widget class="Gui::InputField" name="lengthEdit2">
<property name="minimum">
<double>0.000000000000000</double>
</property>
Expand Down Expand Up @@ -139,5 +139,12 @@
</layout>
</widget>
<resources/>
<customwidgets>
<customwidget>
<class>Gui::InputField</class>
<extends>QLineEdit</extends>
<header>Gui/InputField.h</header>
</customwidget>
</customwidgets>
<connections/>
</ui>

0 comments on commit a40a5dd

Please sign in to comment.