diff --git a/libs/librepcb/common/common.pro b/libs/librepcb/common/common.pro index 7f86eb2547..df155657e7 100644 --- a/libs/librepcb/common/common.pro +++ b/libs/librepcb/common/common.pro @@ -140,9 +140,13 @@ SOURCES += \ widgets/numbereditbase.cpp \ widgets/patheditorwidget.cpp \ widgets/plaintextedit.cpp \ + widgets/positivelengthedit.cpp \ + widgets/ratioedit.cpp \ widgets/signalrolecombobox.cpp \ widgets/statusbar.cpp \ widgets/tabwidget.cpp \ + widgets/unsignedlengthedit.cpp \ + widgets/unsignedratioedit.cpp \ HEADERS += \ alignment.h \ @@ -274,9 +278,13 @@ HEADERS += \ widgets/numbereditbase.h \ widgets/patheditorwidget.h \ widgets/plaintextedit.h \ + widgets/positivelengthedit.h \ + widgets/ratioedit.h \ widgets/signalrolecombobox.h \ widgets/statusbar.h \ widgets/tabwidget.h \ + widgets/unsignedlengthedit.h \ + widgets/unsignedratioedit.h \ FORMS += \ dialogs/aboutdialog.ui \ diff --git a/libs/librepcb/common/dialogs/boarddesignrulesdialog.cpp b/libs/librepcb/common/dialogs/boarddesignrulesdialog.cpp index 6b74336e27..81bca64e0c 100644 --- a/libs/librepcb/common/dialogs/boarddesignrulesdialog.cpp +++ b/libs/librepcb/common/dialogs/boarddesignrulesdialog.cpp @@ -39,6 +39,19 @@ BoardDesignRulesDialog::BoardDesignRulesDialog(const BoardDesignRules& rules, QWidget* parent) : QDialog(parent), mUi(new Ui::BoardDesignRulesDialog), mDesignRules(rules) { mUi->setupUi(this); + mUi->edtStopMaskClrRatio->setSingleStep(5.0); // [%] + mUi->edtStopMaskClrMin->setSingleStep(0.1); // [mm] + mUi->edtStopMaskClrMax->setSingleStep(0.1); // [mm] + mUi->edtStopMaskMaxViaDia->setSingleStep(0.1); // [mm] + mUi->edtCreamMaskClrRatio->setSingleStep(5.0); // [%] + mUi->edtCreamMaskClrMin->setSingleStep(0.1); // [mm] + mUi->edtCreamMaskClrMax->setSingleStep(0.1); // [mm] + mUi->edtRestringPadsRatio->setSingleStep(5.0); // [%] + mUi->edtRestringPadsMin->setSingleStep(0.1); // [mm] + mUi->edtRestringPadsMax->setSingleStep(0.1); // [mm] + mUi->edtRestringViasRatio->setSingleStep(5.0); // [%] + mUi->edtRestringViasMin->setSingleStep(0.1); // [mm] + mUi->edtRestringViasMax->setSingleStep(0.1); // [mm] updateWidgets(); } @@ -80,30 +93,22 @@ void BoardDesignRulesDialog::updateWidgets() noexcept { mUi->edtName->setText(*mDesignRules.getName()); mUi->txtDescription->setPlainText(mDesignRules.getDescription()); // stop mask - mUi->spbxStopMaskClrRatio->setValue( - mDesignRules.getStopMaskClearanceRatio()->toPercent()); - mUi->spbxStopMaskClrMin->setValue( - mDesignRules.getStopMaskClearanceMin()->toMm()); - mUi->spbxStopMaskClrMax->setValue( - mDesignRules.getStopMaskClearanceMax()->toMm()); - mUi->spbxStopMaskMaxViaDia->setValue( - mDesignRules.getStopMaskMaxViaDiameter()->toMm()); + mUi->edtStopMaskClrRatio->setValue(mDesignRules.getStopMaskClearanceRatio()); + mUi->edtStopMaskClrMin->setValue(mDesignRules.getStopMaskClearanceMin()); + mUi->edtStopMaskClrMax->setValue(mDesignRules.getStopMaskClearanceMax()); + mUi->edtStopMaskMaxViaDia->setValue(mDesignRules.getStopMaskMaxViaDiameter()); // cream mask - mUi->spbxCreamMaskClrRatio->setValue( - mDesignRules.getCreamMaskClearanceRatio()->toPercent()); - mUi->spbxCreamMaskClrMin->setValue( - mDesignRules.getCreamMaskClearanceMin()->toMm()); - mUi->spbxCreamMaskClrMax->setValue( - mDesignRules.getCreamMaskClearanceMax()->toMm()); + mUi->edtCreamMaskClrRatio->setValue( + mDesignRules.getCreamMaskClearanceRatio()); + mUi->edtCreamMaskClrMin->setValue(mDesignRules.getCreamMaskClearanceMin()); + mUi->edtCreamMaskClrMax->setValue(mDesignRules.getCreamMaskClearanceMax()); // restring - mUi->spbxRestringPadsRatio->setValue( - mDesignRules.getRestringPadRatio()->toPercent()); - mUi->spbxRestringPadsMin->setValue(mDesignRules.getRestringPadMin()->toMm()); - mUi->spbxRestringPadsMax->setValue(mDesignRules.getRestringPadMax()->toMm()); - mUi->spbxRestringViasRatio->setValue( - mDesignRules.getRestringViaRatio()->toPercent()); - mUi->spbxRestringViasMin->setValue(mDesignRules.getRestringViaMin()->toMm()); - mUi->spbxRestringViasMax->setValue(mDesignRules.getRestringViaMax()->toMm()); + mUi->edtRestringPadsRatio->setValue(mDesignRules.getRestringPadRatio()); + mUi->edtRestringPadsMin->setValue(mDesignRules.getRestringPadMin()); + mUi->edtRestringPadsMax->setValue(mDesignRules.getRestringPadMax()); + mUi->edtRestringViasRatio->setValue(mDesignRules.getRestringViaRatio()); + mUi->edtRestringViasMin->setValue(mDesignRules.getRestringViaMin()); + mUi->edtRestringViasMax->setValue(mDesignRules.getRestringViaMax()); } void BoardDesignRulesDialog::applyRules() noexcept { @@ -112,34 +117,28 @@ void BoardDesignRulesDialog::applyRules() noexcept { mDesignRules.setName(ElementName(mUi->edtName->text())); // can throw mDesignRules.setDescription(mUi->txtDescription->toPlainText()); // stop mask - mDesignRules.setStopMaskClearanceRatio(UnsignedRatio( - Ratio::fromPercent(mUi->spbxStopMaskClrRatio->value()))); // can throw + mDesignRules.setStopMaskClearanceRatio( + mUi->edtStopMaskClrRatio->getValue()); mDesignRules.setStopMaskClearanceBounds( - UnsignedLength(Length::fromMm(mUi->spbxStopMaskClrMin->value())), - UnsignedLength( - Length::fromMm(mUi->spbxStopMaskClrMax->value()))); // can throw - mDesignRules.setStopMaskMaxViaDiameter(UnsignedLength( - Length::fromMm(mUi->spbxStopMaskMaxViaDia->value()))); // can throw + mUi->edtStopMaskClrMin->getValue(), + mUi->edtStopMaskClrMax->getValue()); // can throw + mDesignRules.setStopMaskMaxViaDiameter( + mUi->edtStopMaskMaxViaDia->getValue()); // cream mask - mDesignRules.setCreamMaskClearanceRatio(UnsignedRatio( - Ratio::fromPercent(mUi->spbxCreamMaskClrRatio->value()))); // can throw + mDesignRules.setCreamMaskClearanceRatio( + mUi->edtCreamMaskClrRatio->getValue()); mDesignRules.setCreamMaskClearanceBounds( - UnsignedLength(Length::fromMm(mUi->spbxCreamMaskClrMin->value())), - UnsignedLength( - Length::fromMm(mUi->spbxCreamMaskClrMax->value()))); // can throw + mUi->edtCreamMaskClrMin->getValue(), + mUi->edtCreamMaskClrMax->getValue()); // can throw // restring - mDesignRules.setRestringPadRatio(UnsignedRatio( - Ratio::fromPercent(mUi->spbxRestringPadsRatio->value()))); // can throw + mDesignRules.setRestringPadRatio(mUi->edtRestringPadsRatio->getValue()); mDesignRules.setRestringPadBounds( - UnsignedLength(Length::fromMm(mUi->spbxRestringPadsMin->value())), - UnsignedLength( - Length::fromMm(mUi->spbxRestringPadsMax->value()))); // can throw - mDesignRules.setRestringViaRatio(UnsignedRatio( - Ratio::fromPercent(mUi->spbxRestringViasRatio->value()))); // can throw + mUi->edtRestringPadsMin->getValue(), + mUi->edtRestringPadsMax->getValue()); // can throw + mDesignRules.setRestringViaRatio(mUi->edtRestringViasRatio->getValue()); mDesignRules.setRestringViaBounds( - UnsignedLength(Length::fromMm(mUi->spbxRestringViasMin->value())), - UnsignedLength( - Length::fromMm(mUi->spbxRestringViasMax->value()))); // can throw + mUi->edtRestringViasMin->getValue(), + mUi->edtRestringViasMax->getValue()); // can throw } catch (const Exception& e) { QMessageBox::warning(this, tr("Could not apply settings"), e.getMsg()); } diff --git a/libs/librepcb/common/dialogs/boarddesignrulesdialog.ui b/libs/librepcb/common/dialogs/boarddesignrulesdialog.ui index f5b8514f86..4964491d0b 100644 --- a/libs/librepcb/common/dialogs/boarddesignrulesdialog.ui +++ b/libs/librepcb/common/dialogs/boarddesignrulesdialog.ui @@ -56,22 +56,6 @@ - - - - mm - - - 3 - - - 999.999000000000024 - - - 0.100000000000000 - - - @@ -79,54 +63,6 @@ - - - - mm - - - 3 - - - 999.999000000000024 - - - 0.100000000000000 - - - - - - - % - - - 2 - - - 1000.000000000000000 - - - 10.000000000000000 - - - - - - - mm - - - 3 - - - 999.999000000000024 - - - 0.100000000000000 - - - @@ -134,54 +70,6 @@ - - - - mm - - - 3 - - - 999.999000000000024 - - - 0.100000000000000 - - - - - - - % - - - 2 - - - 1000.000000000000000 - - - 10.000000000000000 - - - - - - - mm - - - 3 - - - 999.999000000000024 - - - 0.100000000000000 - - - @@ -189,54 +77,6 @@ - - - - mm - - - 3 - - - 999.999000000000024 - - - 0.100000000000000 - - - - - - - % - - - 2 - - - 1000.000000000000000 - - - 10.000000000000000 - - - - - - - mm - - - 3 - - - 999.999000000000024 - - - 0.100000000000000 - - - @@ -244,54 +84,6 @@ - - - - mm - - - 3 - - - 999.999000000000024 - - - 0.100000000000000 - - - - - - - % - - - 2 - - - 1000.000000000000000 - - - 10.000000000000000 - - - - - - - mm - - - 3 - - - 999.999000000000024 - - - 0.100000000000000 - - - @@ -308,8 +100,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + librepcb::UnsignedLengthEdit + QWidget +
librepcb/common/widgets/unsignedlengthedit.h
+ 1 +
+ + librepcb::UnsignedRatioEdit + QWidget +
librepcb/common/widgets/unsignedratioedit.h
+ 1 +
+
diff --git a/libs/librepcb/common/dialogs/circlepropertiesdialog.cpp b/libs/librepcb/common/dialogs/circlepropertiesdialog.cpp index 119e7f2c5e..4c846fa29e 100644 --- a/libs/librepcb/common/dialogs/circlepropertiesdialog.cpp +++ b/libs/librepcb/common/dialogs/circlepropertiesdialog.cpp @@ -45,6 +45,8 @@ CirclePropertiesDialog::CirclePropertiesDialog(Circle& circle, mUndoStack(undoStack), mUi(new Ui::CirclePropertiesDialog) { mUi->setupUi(this); + mUi->edtLineWidth->setSingleStep(0.1); // [mm] + mUi->edtDiameter->setSingleStep(0.1); // [mm] foreach (const GraphicsLayer* layer, layers) { mUi->cbxLayer->addItem(layer->getNameTr(), layer->getName()); @@ -55,12 +57,12 @@ CirclePropertiesDialog::CirclePropertiesDialog(Circle& circle, // load circle attributes selectLayerNameInCombobox(*mCircle.getLayerName()); - mUi->spbLineWidth->setValue(mCircle.getLineWidth()->toMm()); + mUi->edtLineWidth->setValue(mCircle.getLineWidth()); mUi->cbxFillArea->setChecked(mCircle.isFilled()); mUi->cbxIsGrabArea->setChecked(mCircle.isGrabArea()); - mUi->spbDiameter->setValue(mCircle.getDiameter()->toMm()); - mUi->spbPosX->setValue(mCircle.getCenter().getX().toMm()); - mUi->spbPosY->setValue(mCircle.getCenter().getY().toMm()); + mUi->edtDiameter->setValue(mCircle.getDiameter()); + mUi->edtPosX->setValue(mCircle.getCenter().getX()); + mUi->edtPosY->setValue(mCircle.getCenter().getY()); } CirclePropertiesDialog::~CirclePropertiesDialog() noexcept { @@ -92,9 +94,6 @@ void CirclePropertiesDialog::buttonBoxClicked( bool CirclePropertiesDialog::applyChanges() noexcept { try { - PositiveLength diameter = - PositiveLength(Length::fromMm(mUi->spbDiameter->value())); // can throw - QScopedPointer cmd(new CmdCircleEdit(mCircle)); if (mUi->cbxLayer->currentIndex() >= 0 && mUi->cbxLayer->currentData().isValid()) { @@ -104,11 +103,9 @@ bool CirclePropertiesDialog::applyChanges() noexcept { } cmd->setIsFilled(mUi->cbxFillArea->isChecked(), false); cmd->setIsGrabArea(mUi->cbxIsGrabArea->isChecked(), false); - cmd->setLineWidth( - UnsignedLength(Length::fromMm(mUi->spbLineWidth->value())), - false); // can throw - cmd->setDiameter(diameter, false); - cmd->setCenter(Point::fromMm(mUi->spbPosX->value(), mUi->spbPosY->value()), + cmd->setLineWidth(mUi->edtLineWidth->getValue(), false); + cmd->setDiameter(mUi->edtDiameter->getValue(), false); + cmd->setCenter(Point(mUi->edtPosX->getValue(), mUi->edtPosY->getValue()), false); mUndoStack.execCmd(cmd.take()); return true; diff --git a/libs/librepcb/common/dialogs/circlepropertiesdialog.ui b/libs/librepcb/common/dialogs/circlepropertiesdialog.ui index 2c0bad2281..ee9fd30984 100644 --- a/libs/librepcb/common/dialogs/circlepropertiesdialog.ui +++ b/libs/librepcb/common/dialogs/circlepropertiesdialog.ui @@ -7,7 +7,7 @@ 0 0 312 - 205 + 176 @@ -61,19 +61,6 @@
- - - - 6 - - - 999.000000000000000 - - - 0.100000000000000 - - - @@ -81,22 +68,6 @@ - - - - 6 - - - 0.254000000000000 - - - 999.000000000000000 - - - 0.254000000000000 - - - @@ -107,39 +78,19 @@ - - - 6 - - - -9999.000000000000000 - - - 9999.000000000000000 - - - 2.540000000000000 - - + - - - 6 - - - -9999.000000000000000 - - - 9999.000000000000000 - - - 2.540000000000000 - - + + + + + + + @@ -154,6 +105,26 @@ + + + librepcb::LengthEdit + QWidget +
librepcb/common/widgets/lengthedit.h
+ 1 +
+ + librepcb::UnsignedLengthEdit + QWidget +
librepcb/common/widgets/unsignedlengthedit.h
+ 1 +
+ + librepcb::PositiveLengthEdit + QWidget +
librepcb/common/widgets/positivelengthedit.h
+ 1 +
+
diff --git a/libs/librepcb/common/dialogs/holepropertiesdialog.cpp b/libs/librepcb/common/dialogs/holepropertiesdialog.cpp index c7eceda657..4ce77e1287 100644 --- a/libs/librepcb/common/dialogs/holepropertiesdialog.cpp +++ b/libs/librepcb/common/dialogs/holepropertiesdialog.cpp @@ -42,13 +42,14 @@ HolePropertiesDialog::HolePropertiesDialog(Hole& hole, UndoStack& undoStack, mUndoStack(undoStack), mUi(new Ui::HolePropertiesDialog) { mUi->setupUi(this); + mUi->edtDiameter->setSingleStep(0.1); // [mm] connect(mUi->buttonBox, &QDialogButtonBox::clicked, this, &HolePropertiesDialog::on_buttonBox_clicked); // load text attributes - mUi->spbDiameter->setValue(mHole.getDiameter()->toMm()); - mUi->spbPosX->setValue(mHole.getPosition().getX().toMm()); - mUi->spbPosY->setValue(mHole.getPosition().getY().toMm()); + mUi->edtDiameter->setValue(mHole.getDiameter()); + mUi->edtPosX->setValue(mHole.getPosition().getX()); + mUi->edtPosY->setValue(mHole.getPosition().getY()); } HolePropertiesDialog::~HolePropertiesDialog() noexcept { @@ -80,10 +81,9 @@ void HolePropertiesDialog::on_buttonBox_clicked(QAbstractButton* button) { bool HolePropertiesDialog::applyChanges() noexcept { try { QScopedPointer cmd(new CmdHoleEdit(mHole)); - cmd->setDiameter(PositiveLength(Length::fromMm(mUi->spbDiameter->value())), - false); // can throw - cmd->setPosition( - Point::fromMm(mUi->spbPosX->value(), mUi->spbPosY->value()), false); + cmd->setDiameter(mUi->edtDiameter->getValue(), false); + cmd->setPosition(Point(mUi->edtPosX->getValue(), mUi->edtPosY->getValue()), + false); mUndoStack.execCmd(cmd.take()); return true; } catch (const Exception& e) { diff --git a/libs/librepcb/common/dialogs/holepropertiesdialog.ui b/libs/librepcb/common/dialogs/holepropertiesdialog.ui index c8ed6289cb..6976fae582 100644 --- a/libs/librepcb/common/dialogs/holepropertiesdialog.ui +++ b/libs/librepcb/common/dialogs/holepropertiesdialog.ui @@ -7,7 +7,7 @@ 0 0 304 - 111 + 91 @@ -23,25 +23,6 @@ - - - - 6 - - - 0.000100000000000 - - - 999.000000000000000 - - - 0.100000000000000 - - - 0.500000000000000 - - - @@ -52,39 +33,16 @@ - - - 6 - - - -9999.000000000000000 - - - 9999.000000000000000 - - - 2.540000000000000 - - + - - - 6 - - - -9999.000000000000000 - - - 9999.000000000000000 - - - 2.540000000000000 - - + + + + @@ -99,6 +57,20 @@ + + + librepcb::LengthEdit + QWidget +
librepcb/common/widgets/lengthedit.h
+ 1 +
+ + librepcb::PositiveLengthEdit + QWidget +
librepcb/common/widgets/positivelengthedit.h
+ 1 +
+
diff --git a/libs/librepcb/common/dialogs/polygonpropertiesdialog.cpp b/libs/librepcb/common/dialogs/polygonpropertiesdialog.cpp index e170747c70..20b5a2b755 100644 --- a/libs/librepcb/common/dialogs/polygonpropertiesdialog.cpp +++ b/libs/librepcb/common/dialogs/polygonpropertiesdialog.cpp @@ -45,6 +45,7 @@ PolygonPropertiesDialog::PolygonPropertiesDialog(Polygon& polygon, mUndoStack(undoStack), mUi(new Ui::PolygonPropertiesDialog) { mUi->setupUi(this); + mUi->edtLineWidth->setSingleStep(0.1); // [mm] foreach (const GraphicsLayer* layer, layers) { mUi->cbxLayer->addItem(layer->getNameTr(), layer->getName()); @@ -55,7 +56,7 @@ PolygonPropertiesDialog::PolygonPropertiesDialog(Polygon& polygon, // load polygon attributes selectLayerNameInCombobox(*mPolygon.getLayerName()); - mUi->spbLineWidth->setValue(mPolygon.getLineWidth()->toMm()); + mUi->edtLineWidth->setValue(mPolygon.getLineWidth()); mUi->cbxFillArea->setChecked(mPolygon.isFilled()); mUi->cbxIsGrabArea->setChecked(mPolygon.isGrabArea()); @@ -101,9 +102,7 @@ bool PolygonPropertiesDialog::applyChanges() noexcept { } cmd->setIsFilled(mUi->cbxFillArea->isChecked(), false); cmd->setIsGrabArea(mUi->cbxIsGrabArea->isChecked(), false); - cmd->setLineWidth( - UnsignedLength(Length::fromMm(mUi->spbLineWidth->value())), - false); // can throw + cmd->setLineWidth(mUi->edtLineWidth->getValue(), false); cmd->setPath(mUi->pathEditorWidget->getPath(), false); // can throw mUndoStack.execCmd(cmd.take()); return true; diff --git a/libs/librepcb/common/dialogs/polygonpropertiesdialog.ui b/libs/librepcb/common/dialogs/polygonpropertiesdialog.ui index f495be0dd9..9b65631b50 100644 --- a/libs/librepcb/common/dialogs/polygonpropertiesdialog.ui +++ b/libs/librepcb/common/dialogs/polygonpropertiesdialog.ui @@ -62,17 +62,7 @@ - - - 6 - - - 999.000000000000000 - - - 0.100000000000000 - - + @@ -105,6 +95,12 @@
librepcb/common/widgets/patheditorwidget.h
1 + + librepcb::UnsignedLengthEdit + QWidget +
librepcb/common/widgets/unsignedlengthedit.h
+ 1 +
diff --git a/libs/librepcb/common/dialogs/stroketextpropertiesdialog.cpp b/libs/librepcb/common/dialogs/stroketextpropertiesdialog.cpp index 984907c8d2..019e357324 100644 --- a/libs/librepcb/common/dialogs/stroketextpropertiesdialog.cpp +++ b/libs/librepcb/common/dialogs/stroketextpropertiesdialog.cpp @@ -45,6 +45,9 @@ StrokeTextPropertiesDialog::StrokeTextPropertiesDialog( mUndoStack(undoStack), mUi(new Ui::StrokeTextPropertiesDialog) { mUi->setupUi(this); + mUi->edtHeight->setSingleStep(0.5); // [mm] + mUi->edtStrokeWidth->setSingleStep(0.1); // [mm] + mUi->edtRotation->setSingleStep(90.0); // [°] foreach (const GraphicsLayer* layer, layers) { mUi->cbxLayer->addItem(layer->getNameTr(), layer->getName()); @@ -53,43 +56,41 @@ StrokeTextPropertiesDialog::StrokeTextPropertiesDialog( connect(mUi->buttonBox, &QDialogButtonBox::clicked, this, &StrokeTextPropertiesDialog::on_buttonBox_clicked); connect(mUi->cbxLetterSpacingAuto, &QCheckBox::toggled, - mUi->spbxLetterSpacingRatio, &QDoubleSpinBox::setDisabled); + mUi->edtLetterSpacingRatio, &RatioEdit::setDisabled); connect(mUi->cbxLineSpacingAuto, &QCheckBox::toggled, - mUi->spbxLineSpacingRatio, &QDoubleSpinBox::setDisabled); + mUi->edtLineSpacingRatio, &RatioEdit::setDisabled); // load text attributes selectLayerNameInCombobox(*mText.getLayerName()); mUi->edtText->setPlainText(mText.getText()); mUi->alignmentSelector->setAlignment(mText.getAlign()); - mUi->spbHeight->setValue(mText.getHeight()->toMm()); - mUi->spbxStrokeWidth->setValue(mText.getStrokeWidth()->toMm()); + mUi->edtHeight->setValue(mText.getHeight()); + mUi->edtStrokeWidth->setValue(mText.getStrokeWidth()); if (mText.getLetterSpacing().isAuto()) { mUi->cbxLetterSpacingAuto->setChecked(true); - mUi->spbxLetterSpacingRatio->setEnabled(false); + mUi->edtLetterSpacingRatio->setEnabled(false); const StrokeFont* font = text.getCurrentFont(); Ratio ratio = font ? font->getLetterSpacing() : Ratio::percent100(); - mUi->spbxLetterSpacingRatio->setValue(ratio.toPercent()); + mUi->edtLetterSpacingRatio->setValue(ratio); } else { mUi->cbxLetterSpacingAuto->setChecked(false); - mUi->spbxLetterSpacingRatio->setEnabled(true); - mUi->spbxLetterSpacingRatio->setValue( - mText.getLetterSpacing().getRatio().toPercent()); + mUi->edtLetterSpacingRatio->setEnabled(true); + mUi->edtLetterSpacingRatio->setValue(mText.getLetterSpacing().getRatio()); } if (mText.getLineSpacing().isAuto()) { mUi->cbxLineSpacingAuto->setChecked(true); - mUi->spbxLineSpacingRatio->setEnabled(false); + mUi->edtLineSpacingRatio->setEnabled(false); const StrokeFont* font = text.getCurrentFont(); Ratio ratio = font ? font->getLineSpacing() : Ratio::percent100(); - mUi->spbxLineSpacingRatio->setValue(ratio.toPercent()); + mUi->edtLineSpacingRatio->setValue(ratio); } else { mUi->cbxLineSpacingAuto->setChecked(false); - mUi->spbxLineSpacingRatio->setEnabled(true); - mUi->spbxLineSpacingRatio->setValue( - mText.getLineSpacing().getRatio().toPercent()); + mUi->edtLineSpacingRatio->setEnabled(true); + mUi->edtLineSpacingRatio->setValue(mText.getLineSpacing().getRatio()); } - mUi->spbPosX->setValue(mText.getPosition().getX().toMm()); - mUi->spbPosY->setValue(mText.getPosition().getY().toMm()); - mUi->spbRotation->setValue(mText.getRotation().toDeg()); + mUi->edtPosX->setValue(mText.getPosition().getX()); + mUi->edtPosY->setValue(mText.getPosition().getY()); + mUi->edtRotation->setValue(mText.getRotation()); mUi->cbxMirrored->setChecked(mText.getMirrored()); mUi->cbxAutoRotate->setChecked(mText.getAutoRotate()); } @@ -131,28 +132,23 @@ bool StrokeTextPropertiesDialog::applyChanges() noexcept { } cmd->setText(mUi->edtText->toPlainText(), false); cmd->setAlignment(mUi->alignmentSelector->getAlignment(), false); - cmd->setStrokeWidth( - UnsignedLength(Length::fromMm(mUi->spbxStrokeWidth->value())), - false); // can throw + cmd->setStrokeWidth(mUi->edtStrokeWidth->getValue(), false); if (mUi->cbxLetterSpacingAuto->isChecked()) { cmd->setLetterSpacing(StrokeTextSpacing(), false); } else { - cmd->setLetterSpacing(StrokeTextSpacing(Ratio::fromPercent( - mUi->spbxLetterSpacingRatio->value())), - false); + cmd->setLetterSpacing( + StrokeTextSpacing(mUi->edtLetterSpacingRatio->getValue()), false); } if (mUi->cbxLineSpacingAuto->isChecked()) { cmd->setLineSpacing(StrokeTextSpacing(), false); } else { - cmd->setLineSpacing(StrokeTextSpacing(Ratio::fromPercent( - mUi->spbxLineSpacingRatio->value())), - false); + cmd->setLineSpacing( + StrokeTextSpacing(mUi->edtLineSpacingRatio->getValue()), false); } - cmd->setHeight(PositiveLength(Length::fromMm(mUi->spbHeight->value())), - false); // can throw - cmd->setPosition( - Point::fromMm(mUi->spbPosX->value(), mUi->spbPosY->value()), false); - cmd->setRotation(Angle::fromDeg(mUi->spbRotation->value()), false); + cmd->setHeight(mUi->edtHeight->getValue(), false); + cmd->setPosition(Point(mUi->edtPosX->getValue(), mUi->edtPosY->getValue()), + false); + cmd->setRotation(mUi->edtRotation->getValue(), false); cmd->setMirrored(mUi->cbxMirrored->isChecked(), false); cmd->setAutoRotate(mUi->cbxAutoRotate->isChecked(), false); mUndoStack.execCmd(cmd.take()); diff --git a/libs/librepcb/common/dialogs/stroketextpropertiesdialog.ui b/libs/librepcb/common/dialogs/stroketextpropertiesdialog.ui index f77d4f1526..a8d193539e 100644 --- a/libs/librepcb/common/dialogs/stroketextpropertiesdialog.ui +++ b/libs/librepcb/common/dialogs/stroketextpropertiesdialog.ui @@ -6,8 +6,8 @@ 0 0 - 328 - 388 + 333 + 411 @@ -59,28 +59,6 @@ - - - - mm - - - 6 - - - 0.010000000000000 - - - 999.000000000000000 - - - 0.100000000000000 - - - 1.000000000000000 - - - @@ -91,36 +69,10 @@ - - - 6 - - - -9999.000000000000000 - - - 9999.000000000000000 - - - 2.540000000000000 - - + - - - 6 - - - -9999.000000000000000 - - - 9999.000000000000000 - - - 2.540000000000000 - - + @@ -131,22 +83,6 @@ - - - - 6 - - - -360.000000000000000 - - - 360.000000000000000 - - - 45.000000000000000 - - - @@ -154,22 +90,6 @@ - - - - mm - - - 6 - - - 999.000000000000000 - - - 0.050000000000000 - - - @@ -198,23 +118,7 @@ - - - % - - - 4 - - - -999.990000000000009 - - - 999.990000000000009 - - - 10.000000000000000 - - + @@ -242,23 +146,7 @@ - - - % - - - 4 - - - -999.990000000000009 - - - 999.990000000000009 - - - 5.000000000000000 - - + @@ -269,6 +157,15 @@ + + + + + + + + + @@ -284,12 +181,42 @@ + + librepcb::LengthEdit + QWidget +
librepcb/common/widgets/lengthedit.h
+ 1 +
librepcb::AlignmentSelector QWidget
widgets/alignmentselector.h
1
+ + librepcb::AngleEdit + QWidget +
librepcb/common/widgets/angleedit.h
+ 1 +
+ + librepcb::UnsignedLengthEdit + QWidget +
librepcb/common/widgets/unsignedlengthedit.h
+ 1 +
+ + librepcb::PositiveLengthEdit + QWidget +
librepcb/common/widgets/positivelengthedit.h
+ 1 +
+ + librepcb::RatioEdit + QWidget +
librepcb/common/widgets/ratioedit.h
+ 1 +
diff --git a/libs/librepcb/common/dialogs/textpropertiesdialog.cpp b/libs/librepcb/common/dialogs/textpropertiesdialog.cpp index f967c60732..1ac29592fb 100644 --- a/libs/librepcb/common/dialogs/textpropertiesdialog.cpp +++ b/libs/librepcb/common/dialogs/textpropertiesdialog.cpp @@ -44,6 +44,8 @@ TextPropertiesDialog::TextPropertiesDialog(Text& text, UndoStack& undoStack, mUndoStack(undoStack), mUi(new Ui::TextPropertiesDialog) { mUi->setupUi(this); + mUi->edtHeight->setSingleStep(0.5); // [mm] + mUi->edtRotation->setSingleStep(90.0); // [°] foreach (const GraphicsLayer* layer, layers) { mUi->cbxLayer->addItem(layer->getNameTr(), layer->getName()); @@ -56,10 +58,10 @@ TextPropertiesDialog::TextPropertiesDialog(Text& text, UndoStack& undoStack, selectLayerNameInCombobox(*mText.getLayerName()); mUi->edtText->setPlainText(mText.getText()); mUi->alignmentSelector->setAlignment(mText.getAlign()); - mUi->spbHeight->setValue(mText.getHeight()->toMm()); - mUi->spbPosX->setValue(mText.getPosition().getX().toMm()); - mUi->spbPosY->setValue(mText.getPosition().getY().toMm()); - mUi->spbRotation->setValue(mText.getRotation().toDeg()); + mUi->edtHeight->setValue(mText.getHeight()); + mUi->edtPosX->setValue(mText.getPosition().getX()); + mUi->edtPosY->setValue(mText.getPosition().getY()); + mUi->edtRotation->setValue(mText.getRotation()); } TextPropertiesDialog::~TextPropertiesDialog() noexcept { @@ -99,11 +101,10 @@ bool TextPropertiesDialog::applyChanges() noexcept { } cmd->setText(mUi->edtText->toPlainText().trimmed(), false); cmd->setAlignment(mUi->alignmentSelector->getAlignment(), false); - cmd->setHeight(PositiveLength(Length::fromMm(mUi->spbHeight->value())), - false); // can throw - cmd->setPosition( - Point::fromMm(mUi->spbPosX->value(), mUi->spbPosY->value()), false); - cmd->setRotation(Angle::fromDeg(mUi->spbRotation->value()), false); + cmd->setHeight(mUi->edtHeight->getValue(), false); + cmd->setPosition(Point(mUi->edtPosX->getValue(), mUi->edtPosY->getValue()), + false); + cmd->setRotation(mUi->edtRotation->getValue(), false); mUndoStack.execCmd(cmd.take()); return true; } catch (const Exception& e) { diff --git a/libs/librepcb/common/dialogs/textpropertiesdialog.ui b/libs/librepcb/common/dialogs/textpropertiesdialog.ui index d9431d0694..bdc6032e9c 100644 --- a/libs/librepcb/common/dialogs/textpropertiesdialog.ui +++ b/libs/librepcb/common/dialogs/textpropertiesdialog.ui @@ -7,7 +7,7 @@ 0 0 310 - 273 + 244 @@ -59,22 +59,6 @@
- - - - 6 - - - 0.254000000000000 - - - 999.000000000000000 - - - 0.254000000000000 - - - @@ -85,36 +69,10 @@ - - - 6 - - - -9999.000000000000000 - - - 9999.000000000000000 - - - 2.540000000000000 - - + - - - 6 - - - -9999.000000000000000 - - - 9999.000000000000000 - - - 2.540000000000000 - - + @@ -125,21 +83,11 @@ + + + - - - 6 - - - -360.000000000000000 - - - 360.000000000000000 - - - 45.000000000000000 - - + @@ -162,6 +110,24 @@
widgets/alignmentselector.h
1 + + librepcb::PositiveLengthEdit + QWidget +
librepcb/common/widgets/positivelengthedit.h
+ 1 +
+ + librepcb::LengthEdit + QWidget +
librepcb/common/widgets/lengthedit.h
+ 1 +
+ + librepcb::AngleEdit + QWidget +
librepcb/common/widgets/angleedit.h
+ 1 +
diff --git a/libs/librepcb/common/utils/toolbarproxy.cpp b/libs/librepcb/common/utils/toolbarproxy.cpp index b8c1344bd2..ab07fcc88a 100644 --- a/libs/librepcb/common/utils/toolbarproxy.cpp +++ b/libs/librepcb/common/utils/toolbarproxy.cpp @@ -105,13 +105,17 @@ QAction* ToolBarProxy::addLabel(const QString& text, int indent) noexcept { return addWidget(std::move(label)); } -QAction* ToolBarProxy::addWidget(std::unique_ptr widget) noexcept { +QAction* ToolBarProxy::addWidget(std::unique_ptr widget, + int indent) noexcept { Q_ASSERT(widget); Q_ASSERT((widget->parent() == nullptr) || (widget->parent() == this)); + if (indent > 0) { + addLabel("", indent); // A bit ugly, but simple and works :) + } + std::unique_ptr action(new QWidgetAction(this)); - action->setDefaultWidget( - widget.release()); // transfer ownership to the action + action->setDefaultWidget(widget.release()); // transfer ownership to action return addAction(std::move(action)); } diff --git a/libs/librepcb/common/utils/toolbarproxy.h b/libs/librepcb/common/utils/toolbarproxy.h index 8aab8c33df..00644a531d 100644 --- a/libs/librepcb/common/utils/toolbarproxy.h +++ b/libs/librepcb/common/utils/toolbarproxy.h @@ -58,7 +58,7 @@ class ToolBarProxy final : public QObject { void clear() noexcept; QAction* addAction(std::unique_ptr action) noexcept; QAction* addLabel(const QString& text, int indent = 0) noexcept; - QAction* addWidget(std::unique_ptr widget) noexcept; + QAction* addWidget(std::unique_ptr widget, int indent = 0) noexcept; QAction* addSeparator() noexcept; void removeAction(QAction* action) noexcept; diff --git a/libs/librepcb/common/widgets/numbereditbase.cpp b/libs/librepcb/common/widgets/numbereditbase.cpp index c2eccfb0f2..1d44e9e908 100644 --- a/libs/librepcb/common/widgets/numbereditbase.cpp +++ b/libs/librepcb/common/widgets/numbereditbase.cpp @@ -43,7 +43,7 @@ NumberEditBase::NumberEditBase(QWidget* parent) noexcept // errors (e.g. when converting between different units), we need some more // decimals. mSpinBox->setDecimals(10); - mSpinBox->setButtonSymbols(QDoubleSpinBox::NoButtons); + setSingleStep(tl::nullopt); setFocusProxy(mSpinBox.data()); connect(mSpinBox.data(), @@ -61,6 +61,16 @@ NumberEditBase::~NumberEditBase() noexcept { * General Methods ******************************************************************************/ +void NumberEditBase::setSingleStep(tl::optional step) noexcept { + if (step) { + mSpinBox->setSingleStep(*step); + mSpinBox->setButtonSymbols(QDoubleSpinBox::UpDownArrows); + } else { + mSpinBox->setSingleStep(0.0); + mSpinBox->setButtonSymbols(QDoubleSpinBox::NoButtons); + } +} + void NumberEditBase::setFrame(bool frame) noexcept { mSpinBox->setFrame(frame); } diff --git a/libs/librepcb/common/widgets/numbereditbase.h b/libs/librepcb/common/widgets/numbereditbase.h index 4f47ba8b4e..3b50edaafd 100644 --- a/libs/librepcb/common/widgets/numbereditbase.h +++ b/libs/librepcb/common/widgets/numbereditbase.h @@ -23,6 +23,8 @@ /******************************************************************************* * Includes ******************************************************************************/ +#include + #include #include @@ -53,6 +55,7 @@ class NumberEditBase : public QWidget { virtual ~NumberEditBase() noexcept; // General Methods + void setSingleStep(tl::optional step) noexcept; void setFrame(bool frame) noexcept; void selectAll() noexcept; diff --git a/libs/librepcb/common/widgets/positivelengthedit.cpp b/libs/librepcb/common/widgets/positivelengthedit.cpp new file mode 100644 index 0000000000..73a73e3c79 --- /dev/null +++ b/libs/librepcb/common/widgets/positivelengthedit.cpp @@ -0,0 +1,99 @@ +/* + * LibrePCB - Professional EDA for everyone! + * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors. + * https://librepcb.org/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/******************************************************************************* + * Includes + ******************************************************************************/ +#include "positivelengthedit.h" + +#include "doublespinbox.h" + +/******************************************************************************* + * Namespace + ******************************************************************************/ +namespace librepcb { + +/******************************************************************************* + * Constructors / Destructor + ******************************************************************************/ + +PositiveLengthEdit::PositiveLengthEdit(QWidget* parent) noexcept + : NumberEditBase(parent), + mMinValue(1), + mMaxValue(2000000000L), // 2'000mm should be sufficient for everything + mValue(1), + mUnit(LengthUnit::millimeters()) { + updateSpinBox(); +} + +PositiveLengthEdit::~PositiveLengthEdit() noexcept { +} + +/******************************************************************************* + * Setters + ******************************************************************************/ + +void PositiveLengthEdit::setValue(const PositiveLength& value) noexcept { + if (value != mValue) { + mValue = value; + // Extend allowed range e.g. if a lower/higher value is loaded from file. + // Otherwise the edit will clip the value, i.e. the value gets modified + // even without user interaction. + if (mValue > mMaxValue) mMaxValue = mValue; + if (mValue < mMinValue) mMinValue = mValue; + updateSpinBox(); + } +} + +void PositiveLengthEdit::setUnit(const LengthUnit& unit) noexcept { + if (unit != mUnit) { + mUnit = unit; + updateSpinBox(); + } +} + +/******************************************************************************* + * Private Methods + ******************************************************************************/ + +void PositiveLengthEdit::updateSpinBox() noexcept { + mSpinBox->setMinimum(mUnit.convertToUnit(*mMinValue)); + mSpinBox->setMaximum(mUnit.convertToUnit(*mMaxValue)); + mSpinBox->setValue(mUnit.convertToUnit(*mValue)); + mSpinBox->setSuffix(" " % mUnit.toShortStringTr()); +} + +void PositiveLengthEdit::spinBoxValueChanged(double value) noexcept { + try { + mValue = PositiveLength(mUnit.convertFromUnit(value)); // can throw + // Clip value with integer arithmetic to avoid floating point issues. + if (mValue < mMinValue) mValue = mMinValue; + if (mValue > mMaxValue) mValue = mMaxValue; + emit valueChanged(mValue); + } catch (const Exception& e) { + // This should actually never happen, thus no user visible message here. + qWarning() << "Invalid positive length entered:" << e.getMsg(); + } +} + +/******************************************************************************* + * End of File + ******************************************************************************/ + +} // namespace librepcb diff --git a/libs/librepcb/common/widgets/positivelengthedit.h b/libs/librepcb/common/widgets/positivelengthedit.h new file mode 100644 index 0000000000..e5086a1d62 --- /dev/null +++ b/libs/librepcb/common/widgets/positivelengthedit.h @@ -0,0 +1,85 @@ +/* + * LibrePCB - Professional EDA for everyone! + * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors. + * https://librepcb.org/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef LIBREPCB_POSITIVELENGTHEDIT_H +#define LIBREPCB_POSITIVELENGTHEDIT_H + +/******************************************************************************* + * Includes + ******************************************************************************/ +#include "../units/length.h" +#include "../units/lengthunit.h" +#include "numbereditbase.h" + +#include +#include + +/******************************************************************************* + * Namespace / Forward Declarations + ******************************************************************************/ +namespace librepcb { + +/******************************************************************************* + * Class PositiveLengthEdit + ******************************************************************************/ + +/** + * @brief The PositiveLengthEdit class is a widget to view/edit + * ::librepcb::PositiveLength values + */ +class PositiveLengthEdit final : public NumberEditBase { + Q_OBJECT + +public: + // Constructors / Destructor + explicit PositiveLengthEdit(QWidget* parent = nullptr) noexcept; + PositiveLengthEdit(const PositiveLengthEdit& other) = delete; + virtual ~PositiveLengthEdit() noexcept; + + // Getters + const PositiveLength& getValue() const noexcept { return mValue; } + + // Setters + void setValue(const PositiveLength& value) noexcept; + void setUnit(const LengthUnit& unit) noexcept; + + // Operator Overloadings + PositiveLengthEdit& operator=(const PositiveLengthEdit& rhs) = delete; + +signals: + void valueChanged(const PositiveLength& value); + +private: // Methods + void updateSpinBox() noexcept override; + void spinBoxValueChanged(double value) noexcept override; + +private: // Data + PositiveLength mMinValue; + PositiveLength mMaxValue; + PositiveLength mValue; + LengthUnit mUnit; +}; + +/******************************************************************************* + * End of File + ******************************************************************************/ + +} // namespace librepcb + +#endif // LIBREPCB_POSITIVELENGTHEDIT_H diff --git a/libs/librepcb/common/widgets/ratioedit.cpp b/libs/librepcb/common/widgets/ratioedit.cpp new file mode 100644 index 0000000000..eeb897e755 --- /dev/null +++ b/libs/librepcb/common/widgets/ratioedit.cpp @@ -0,0 +1,91 @@ +/* + * LibrePCB - Professional EDA for everyone! + * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors. + * https://librepcb.org/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/******************************************************************************* + * Includes + ******************************************************************************/ +#include "ratioedit.h" + +#include "doublespinbox.h" + +/******************************************************************************* + * Namespace + ******************************************************************************/ +namespace librepcb { + +/******************************************************************************* + * Constructors / Destructor + ******************************************************************************/ + +RatioEdit::RatioEdit(QWidget* parent) noexcept + : NumberEditBase(parent), + mMinValue(-2000000000L), // -2'000% should be sufficient for everything + mMaxValue(2000000000L), // 2'000% should be sufficient for everything + mValue(0) { + mSpinBox->setSuffix("%"); + updateSpinBox(); +} + +RatioEdit::~RatioEdit() noexcept { +} + +/******************************************************************************* + * Setters + ******************************************************************************/ + +void RatioEdit::setValue(const Ratio& value) noexcept { + if (value != mValue) { + mValue = value; + // Extend allowed range e.g. if a lower/higher value is loaded from file. + // Otherwise the edit will clip the value, i.e. the value gets modified + // even without user interaction. + if (mValue > mMaxValue) mMaxValue = mValue; + if (mValue < mMinValue) mMinValue = mValue; + updateSpinBox(); + } +} + +/******************************************************************************* + * Private Methods + ******************************************************************************/ + +void RatioEdit::updateSpinBox() noexcept { + mSpinBox->setMinimum(mMinValue.toPercent()); + mSpinBox->setMaximum(mMaxValue.toPercent()); + mSpinBox->setValue(mValue.toPercent()); +} + +void RatioEdit::spinBoxValueChanged(double value) noexcept { + try { + mValue = Ratio::fromPercent(value); // can throw + // Clip value with integer arithmetic to avoid floating point issues. + if (mValue < mMinValue) mValue = mMinValue; + if (mValue > mMaxValue) mValue = mMaxValue; + emit valueChanged(mValue); + } catch (const Exception& e) { + // This should actually never happen, thus no user visible message here. + qWarning() << "Invalid ratio entered:" << e.getMsg(); + } +} + +/******************************************************************************* + * End of File + ******************************************************************************/ + +} // namespace librepcb diff --git a/libs/librepcb/common/widgets/ratioedit.h b/libs/librepcb/common/widgets/ratioedit.h new file mode 100644 index 0000000000..816812a930 --- /dev/null +++ b/libs/librepcb/common/widgets/ratioedit.h @@ -0,0 +1,81 @@ +/* + * LibrePCB - Professional EDA for everyone! + * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors. + * https://librepcb.org/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef LIBREPCB_RATIOEDIT_H +#define LIBREPCB_RATIOEDIT_H + +/******************************************************************************* + * Includes + ******************************************************************************/ +#include "../units/ratio.h" +#include "numbereditbase.h" + +#include +#include + +/******************************************************************************* + * Namespace / Forward Declarations + ******************************************************************************/ +namespace librepcb { + +/******************************************************************************* + * Class RatioEdit + ******************************************************************************/ + +/** + * @brief The RatioEdit class is a widget to view/edit ::librepcb::Ratio values + */ +class RatioEdit final : public NumberEditBase { + Q_OBJECT + +public: + // Constructors / Destructor + explicit RatioEdit(QWidget* parent = nullptr) noexcept; + RatioEdit(const RatioEdit& other) = delete; + virtual ~RatioEdit() noexcept; + + // Getters + const Ratio& getValue() const noexcept { return mValue; } + + // Setters + void setValue(const Ratio& value) noexcept; + + // Operator Overloadings + RatioEdit& operator=(const RatioEdit& rhs) = delete; + +signals: + void valueChanged(const Ratio& value); + +private: // Methods + void updateSpinBox() noexcept override; + void spinBoxValueChanged(double value) noexcept override; + +private: // Data + Ratio mMinValue; + Ratio mMaxValue; + Ratio mValue; +}; + +/******************************************************************************* + * End of File + ******************************************************************************/ + +} // namespace librepcb + +#endif // LIBREPCB_RATIOEDIT_H diff --git a/libs/librepcb/common/widgets/unsignedlengthedit.cpp b/libs/librepcb/common/widgets/unsignedlengthedit.cpp new file mode 100644 index 0000000000..47bf05a83a --- /dev/null +++ b/libs/librepcb/common/widgets/unsignedlengthedit.cpp @@ -0,0 +1,99 @@ +/* + * LibrePCB - Professional EDA for everyone! + * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors. + * https://librepcb.org/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/******************************************************************************* + * Includes + ******************************************************************************/ +#include "unsignedlengthedit.h" + +#include "doublespinbox.h" + +/******************************************************************************* + * Namespace + ******************************************************************************/ +namespace librepcb { + +/******************************************************************************* + * Constructors / Destructor + ******************************************************************************/ + +UnsignedLengthEdit::UnsignedLengthEdit(QWidget* parent) noexcept + : NumberEditBase(parent), + mMinValue(0), + mMaxValue(2000000000L), // 2'000mm should be sufficient for everything + mValue(0), + mUnit(LengthUnit::millimeters()) { + updateSpinBox(); +} + +UnsignedLengthEdit::~UnsignedLengthEdit() noexcept { +} + +/******************************************************************************* + * Setters + ******************************************************************************/ + +void UnsignedLengthEdit::setValue(const UnsignedLength& value) noexcept { + if (value != mValue) { + mValue = value; + // Extend allowed range e.g. if a lower/higher value is loaded from file. + // Otherwise the edit will clip the value, i.e. the value gets modified + // even without user interaction. + if (mValue > mMaxValue) mMaxValue = mValue; + if (mValue < mMinValue) mMinValue = mValue; + updateSpinBox(); + } +} + +void UnsignedLengthEdit::setUnit(const LengthUnit& unit) noexcept { + if (unit != mUnit) { + mUnit = unit; + updateSpinBox(); + } +} + +/******************************************************************************* + * Private Methods + ******************************************************************************/ + +void UnsignedLengthEdit::updateSpinBox() noexcept { + mSpinBox->setMinimum(mUnit.convertToUnit(*mMinValue)); + mSpinBox->setMaximum(mUnit.convertToUnit(*mMaxValue)); + mSpinBox->setValue(mUnit.convertToUnit(*mValue)); + mSpinBox->setSuffix(" " % mUnit.toShortStringTr()); +} + +void UnsignedLengthEdit::spinBoxValueChanged(double value) noexcept { + try { + mValue = UnsignedLength(mUnit.convertFromUnit(value)); // can throw + // Clip value with integer arithmetic to avoid floating point issues. + if (mValue < mMinValue) mValue = mMinValue; + if (mValue > mMaxValue) mValue = mMaxValue; + emit valueChanged(mValue); + } catch (const Exception& e) { + // This should actually never happen, thus no user visible message here. + qWarning() << "Invalid unsigned length entered:" << e.getMsg(); + } +} + +/******************************************************************************* + * End of File + ******************************************************************************/ + +} // namespace librepcb diff --git a/libs/librepcb/common/widgets/unsignedlengthedit.h b/libs/librepcb/common/widgets/unsignedlengthedit.h new file mode 100644 index 0000000000..6012ba7f97 --- /dev/null +++ b/libs/librepcb/common/widgets/unsignedlengthedit.h @@ -0,0 +1,85 @@ +/* + * LibrePCB - Professional EDA for everyone! + * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors. + * https://librepcb.org/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef LIBREPCB_UNSIGNEDLENGTHEDIT_H +#define LIBREPCB_UNSIGNEDLENGTHEDIT_H + +/******************************************************************************* + * Includes + ******************************************************************************/ +#include "../units/length.h" +#include "../units/lengthunit.h" +#include "numbereditbase.h" + +#include +#include + +/******************************************************************************* + * Namespace / Forward Declarations + ******************************************************************************/ +namespace librepcb { + +/******************************************************************************* + * Class UnsignedLengthEdit + ******************************************************************************/ + +/** + * @brief The UnsignedLengthEdit class is a widget to view/edit + * ::librepcb::UnsignedLength values + */ +class UnsignedLengthEdit final : public NumberEditBase { + Q_OBJECT + +public: + // Constructors / Destructor + explicit UnsignedLengthEdit(QWidget* parent = nullptr) noexcept; + UnsignedLengthEdit(const UnsignedLengthEdit& other) = delete; + virtual ~UnsignedLengthEdit() noexcept; + + // Getters + const UnsignedLength& getValue() const noexcept { return mValue; } + + // Setters + void setValue(const UnsignedLength& value) noexcept; + void setUnit(const LengthUnit& unit) noexcept; + + // Operator Overloadings + UnsignedLengthEdit& operator=(const UnsignedLengthEdit& rhs) = delete; + +signals: + void valueChanged(const UnsignedLength& value); + +private: // Methods + void updateSpinBox() noexcept override; + void spinBoxValueChanged(double value) noexcept override; + +private: // Data + UnsignedLength mMinValue; + UnsignedLength mMaxValue; + UnsignedLength mValue; + LengthUnit mUnit; +}; + +/******************************************************************************* + * End of File + ******************************************************************************/ + +} // namespace librepcb + +#endif // LIBREPCB_UNSIGNEDLENGTHEDIT_H diff --git a/libs/librepcb/common/widgets/unsignedratioedit.cpp b/libs/librepcb/common/widgets/unsignedratioedit.cpp new file mode 100644 index 0000000000..045f696595 --- /dev/null +++ b/libs/librepcb/common/widgets/unsignedratioedit.cpp @@ -0,0 +1,91 @@ +/* + * LibrePCB - Professional EDA for everyone! + * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors. + * https://librepcb.org/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/******************************************************************************* + * Includes + ******************************************************************************/ +#include "unsignedratioedit.h" + +#include "doublespinbox.h" + +/******************************************************************************* + * Namespace + ******************************************************************************/ +namespace librepcb { + +/******************************************************************************* + * Constructors / Destructor + ******************************************************************************/ + +UnsignedRatioEdit::UnsignedRatioEdit(QWidget* parent) noexcept + : NumberEditBase(parent), + mMinValue(Ratio(0)), + mMaxValue(Ratio(2000000000L)), // 2000% should be sufficient for everything + mValue(Ratio(0)) { + mSpinBox->setSuffix("%"); + updateSpinBox(); +} + +UnsignedRatioEdit::~UnsignedRatioEdit() noexcept { +} + +/******************************************************************************* + * Setters + ******************************************************************************/ + +void UnsignedRatioEdit::setValue(const UnsignedRatio& value) noexcept { + if (value != mValue) { + mValue = value; + // Extend allowed range e.g. if a lower/higher value is loaded from file. + // Otherwise the edit will clip the value, i.e. the value gets modified + // even without user interaction. + if (mValue > mMaxValue) mMaxValue = mValue; + if (mValue < mMinValue) mMinValue = mValue; + updateSpinBox(); + } +} + +/******************************************************************************* + * Private Methods + ******************************************************************************/ + +void UnsignedRatioEdit::updateSpinBox() noexcept { + mSpinBox->setMinimum(mMinValue->toPercent()); + mSpinBox->setMaximum(mMaxValue->toPercent()); + mSpinBox->setValue(mValue->toPercent()); +} + +void UnsignedRatioEdit::spinBoxValueChanged(double value) noexcept { + try { + mValue = UnsignedRatio(Ratio::fromPercent(value)); // can throw + // Clip value with integer arithmetic to avoid floating point issues. + if (mValue < mMinValue) mValue = mMinValue; + if (mValue > mMaxValue) mValue = mMaxValue; + emit valueChanged(mValue); + } catch (const Exception& e) { + // This should actually never happen, thus no user visible message here. + qWarning() << "Invalid unsigned ratio entered:" << e.getMsg(); + } +} + +/******************************************************************************* + * End of File + ******************************************************************************/ + +} // namespace librepcb diff --git a/libs/librepcb/common/widgets/unsignedratioedit.h b/libs/librepcb/common/widgets/unsignedratioedit.h new file mode 100644 index 0000000000..928704bc0c --- /dev/null +++ b/libs/librepcb/common/widgets/unsignedratioedit.h @@ -0,0 +1,82 @@ +/* + * LibrePCB - Professional EDA for everyone! + * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors. + * https://librepcb.org/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef LIBREPCB_UNSIGNEDRATIOEDIT_H +#define LIBREPCB_UNSIGNEDRATIOEDIT_H + +/******************************************************************************* + * Includes + ******************************************************************************/ +#include "../units/ratio.h" +#include "numbereditbase.h" + +#include +#include + +/******************************************************************************* + * Namespace / Forward Declarations + ******************************************************************************/ +namespace librepcb { + +/******************************************************************************* + * Class UnsignedRatioEdit + ******************************************************************************/ + +/** + * @brief The UnsignedRatioEdit class is a widget to view/edit + * ::librepcb::UnsignedRatio values + */ +class UnsignedRatioEdit final : public NumberEditBase { + Q_OBJECT + +public: + // Constructors / Destructor + explicit UnsignedRatioEdit(QWidget* parent = nullptr) noexcept; + UnsignedRatioEdit(const UnsignedRatioEdit& other) = delete; + virtual ~UnsignedRatioEdit() noexcept; + + // Getters + const UnsignedRatio& getValue() const noexcept { return mValue; } + + // Setters + void setValue(const UnsignedRatio& value) noexcept; + + // Operator Overloadings + UnsignedRatioEdit& operator=(const UnsignedRatioEdit& rhs) = delete; + +signals: + void valueChanged(const UnsignedRatio& value); + +private: // Methods + void updateSpinBox() noexcept override; + void spinBoxValueChanged(double value) noexcept override; + +private: // Data + UnsignedRatio mMinValue; + UnsignedRatio mMaxValue; + UnsignedRatio mValue; +}; + +/******************************************************************************* + * End of File + ******************************************************************************/ + +} // namespace librepcb + +#endif // LIBREPCB_UNSIGNEDRATIOEDIT_H diff --git a/libs/librepcb/libraryeditor/pkg/dialogs/footprintpadpropertiesdialog.cpp b/libs/librepcb/libraryeditor/pkg/dialogs/footprintpadpropertiesdialog.cpp index 4dc71d8cca..59ff90bc50 100644 --- a/libs/librepcb/libraryeditor/pkg/dialogs/footprintpadpropertiesdialog.cpp +++ b/libs/librepcb/libraryeditor/pkg/dialogs/footprintpadpropertiesdialog.cpp @@ -47,6 +47,10 @@ FootprintPadPropertiesDialog::FootprintPadPropertiesDialog( mUndoStack(undoStack), mUi(new Ui::FootprintPadPropertiesDialog) { mUi->setupUi(this); + mUi->edtWidth->setSingleStep(0.1); // [mm] + mUi->edtHeight->setSingleStep(0.1); // [mm] + mUi->edtDrillDiameter->setSingleStep(0.1); // [mm] + mUi->edtRotation->setSingleStep(90.0); // [°] connect(mUi->buttonBox, &QDialogButtonBox::clicked, this, &FootprintPadPropertiesDialog::on_buttonBox_clicked); @@ -91,17 +95,17 @@ FootprintPadPropertiesDialog::FootprintPadPropertiesDialog( Q_ASSERT(false); break; } - mUi->spbWidth->setValue(mPad.getWidth()->toMm()); - mUi->spbHeight->setValue(mPad.getHeight()->toMm()); - mUi->spbDrillDiameter->setValue(mPad.getDrillDiameter()->toMm()); - mUi->spbPosX->setValue(mPad.getPosition().getX().toMm()); - mUi->spbPosY->setValue(mPad.getPosition().getY().toMm()); - mUi->spbRotation->setValue(mPad.getRotation().toDeg()); + mUi->edtWidth->setValue(mPad.getWidth()); + mUi->edtHeight->setValue(mPad.getHeight()); + mUi->edtDrillDiameter->setValue(mPad.getDrillDiameter()); + mUi->edtPosX->setValue(mPad.getPosition().getX()); + mUi->edtPosY->setValue(mPad.getPosition().getY()); + mUi->edtRotation->setValue(mPad.getRotation()); // disable drill diameter for SMT pads - mUi->spbDrillDiameter->setEnabled(mUi->rbtnBoardSideTht->isChecked()); - connect(mUi->rbtnBoardSideTht, &QRadioButton::toggled, mUi->spbDrillDiameter, - &QDoubleSpinBox::setEnabled); + mUi->edtDrillDiameter->setEnabled(mUi->rbtnBoardSideTht->isChecked()); + connect(mUi->rbtnBoardSideTht, &QRadioButton::toggled, mUi->edtDrillDiameter, + &LengthEdit::setEnabled); } FootprintPadPropertiesDialog::~FootprintPadPropertiesDialog() noexcept { @@ -155,16 +159,12 @@ bool FootprintPadPropertiesDialog::applyChanges() noexcept { } else { Q_ASSERT(false); } - cmd->setWidth(PositiveLength(Length::fromMm(mUi->spbWidth->value())), - false); // can throw - cmd->setHeight(PositiveLength(Length::fromMm(mUi->spbHeight->value())), - false); // can throw - cmd->setDrillDiameter( - UnsignedLength(Length::fromMm(mUi->spbDrillDiameter->value())), - false); // can throw - cmd->setPosition( - Point::fromMm(mUi->spbPosX->value(), mUi->spbPosY->value()), false); - cmd->setRotation(Angle::fromDeg(mUi->spbRotation->value()), false); + cmd->setWidth(mUi->edtWidth->getValue(), false); + cmd->setHeight(mUi->edtHeight->getValue(), false); + cmd->setDrillDiameter(mUi->edtDrillDiameter->getValue(), false); + cmd->setPosition(Point(mUi->edtPosX->getValue(), mUi->edtPosY->getValue()), + false); + cmd->setRotation(mUi->edtRotation->getValue(), false); mUndoStack.execCmd(cmd.take()); return true; } catch (const Exception& e) { diff --git a/libs/librepcb/libraryeditor/pkg/dialogs/footprintpadpropertiesdialog.ui b/libs/librepcb/libraryeditor/pkg/dialogs/footprintpadpropertiesdialog.ui index 6d5258678f..e3467778db 100644 --- a/libs/librepcb/libraryeditor/pkg/dialogs/footprintpadpropertiesdialog.ui +++ b/libs/librepcb/libraryeditor/pkg/dialogs/footprintpadpropertiesdialog.ui @@ -7,7 +7,7 @@ 0 0 330 - 266 + 226 @@ -125,19 +125,6 @@ - - - - 6 - - - 9999.000000000000000 - - - 0.200000000000000 - - - @@ -148,36 +135,10 @@ - - - 6 - - - -9999.000000000000000 - - - 9999.000000000000000 - - - 0.200000000000000 - - + - - - 6 - - - -9999.000000000000000 - - - 9999.000000000000000 - - - 0.200000000000000 - - + @@ -191,36 +152,10 @@ - - - 6 - - - -9999.000000000000000 - - - 9999.000000000000000 - - - 2.540000000000000 - - + - - - 6 - - - -9999.000000000000000 - - - 9999.000000000000000 - - - 2.540000000000000 - - + @@ -231,21 +166,11 @@ + + + - - - 6 - - - -360.000000000000000 - - - 360.000000000000000 - - - 45.000000000000000 - - + @@ -261,6 +186,32 @@ + + + librepcb::LengthEdit + QWidget +
librepcb/common/widgets/lengthedit.h
+ 1 +
+ + librepcb::AngleEdit + QWidget +
librepcb/common/widgets/angleedit.h
+ 1 +
+ + librepcb::UnsignedLengthEdit + QWidget +
librepcb/common/widgets/unsignedlengthedit.h
+ 1 +
+ + librepcb::PositiveLengthEdit + QWidget +
librepcb/common/widgets/positivelengthedit.h
+ 1 +
+
diff --git a/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_addholes.cpp b/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_addholes.cpp index 83a049f592..6d9476fdbf 100644 --- a/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_addholes.cpp +++ b/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_addholes.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -71,17 +72,12 @@ bool PackageEditorState_AddHoles::entry() noexcept { // populate command toolbar mContext.commandToolBar.addLabel(tr("Diameter:"), 10); - std::unique_ptr diameterSpinBox(new QDoubleSpinBox()); - diameterSpinBox->setMinimum(0.0001); - diameterSpinBox->setMaximum(100); - diameterSpinBox->setSingleStep(0.2); - diameterSpinBox->setDecimals(6); - diameterSpinBox->setValue(mLastDiameter->toMm()); - connect(diameterSpinBox.get(), - static_cast( - &QDoubleSpinBox::valueChanged), - this, &PackageEditorState_AddHoles::diameterSpinBoxValueChanged); - mContext.commandToolBar.addWidget(std::move(diameterSpinBox)); + std::unique_ptr edtDiameter(new PositiveLengthEdit()); + edtDiameter->setSingleStep(0.1); // [mm] + edtDiameter->setValue(mLastDiameter); + connect(edtDiameter.get(), &PositiveLengthEdit::valueChanged, this, + &PackageEditorState_AddHoles::diameterEditValueChanged); + mContext.commandToolBar.addWidget(std::move(edtDiameter)); Point pos = mContext.graphicsView.mapGlobalPosToScenePos(QCursor::pos(), true, true); @@ -186,9 +182,9 @@ bool PackageEditorState_AddHoles::abortAddHole() noexcept { } } -void PackageEditorState_AddHoles::diameterSpinBoxValueChanged( - double value) noexcept { - mLastDiameter = Length::fromMm(value); +void PackageEditorState_AddHoles::diameterEditValueChanged( + const PositiveLength& value) noexcept { + mLastDiameter = value; if (mEditCmd) { mEditCmd->setDiameter(mLastDiameter, true); } diff --git a/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_addholes.h b/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_addholes.h index 1bbe29f5a4..e55f42cd9a 100644 --- a/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_addholes.h +++ b/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_addholes.h @@ -77,7 +77,7 @@ class PackageEditorState_AddHoles final : public PackageEditorState { bool startAddHole(const Point& pos) noexcept; bool finishAddHole(const Point& pos) noexcept; bool abortAddHole() noexcept; - void diameterSpinBoxValueChanged(double value) noexcept; + void diameterEditValueChanged(const PositiveLength& value) noexcept; private: // Data Point mStartPos; diff --git a/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_addpads.cpp b/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_addpads.cpp index e87d47656a..552df52e90 100644 --- a/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_addpads.cpp +++ b/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_addpads.cpp @@ -29,6 +29,8 @@ #include #include +#include +#include #include #include #include @@ -120,47 +122,32 @@ bool PackageEditorState_AddPads::entry() noexcept { // width mContext.commandToolBar.addLabel(tr("Width:"), 10); - std::unique_ptr widthSpinBox(new QDoubleSpinBox()); - widthSpinBox->setMinimum(0); - widthSpinBox->setMaximum(999); - widthSpinBox->setSingleStep(0.1); - widthSpinBox->setDecimals(6); - widthSpinBox->setValue(mLastPad.getWidth()->toMm()); - connect(widthSpinBox.get(), - static_cast( - &QDoubleSpinBox::valueChanged), - this, &PackageEditorState_AddPads::widthSpinBoxValueChanged); - mContext.commandToolBar.addWidget(std::move(widthSpinBox)); + std::unique_ptr edtWidth(new PositiveLengthEdit()); + edtWidth->setSingleStep(0.1); // [mm] + edtWidth->setValue(mLastPad.getWidth()); + connect(edtWidth.get(), &PositiveLengthEdit::valueChanged, this, + &PackageEditorState_AddPads::widthEditValueChanged); + mContext.commandToolBar.addWidget(std::move(edtWidth)); // height mContext.commandToolBar.addLabel(tr("Height:"), 10); - std::unique_ptr heightSpinBox(new QDoubleSpinBox()); - heightSpinBox->setMinimum(0); - heightSpinBox->setMaximum(999); - heightSpinBox->setSingleStep(0.1); - heightSpinBox->setDecimals(6); - heightSpinBox->setValue(mLastPad.getHeight()->toMm()); - connect(heightSpinBox.get(), - static_cast( - &QDoubleSpinBox::valueChanged), - this, &PackageEditorState_AddPads::heightSpinBoxValueChanged); - mContext.commandToolBar.addWidget(std::move(heightSpinBox)); + std::unique_ptr edtHeight(new PositiveLengthEdit()); + edtHeight->setSingleStep(0.1); // [mm] + edtHeight->setValue(mLastPad.getHeight()); + connect(edtHeight.get(), &PositiveLengthEdit::valueChanged, this, + &PackageEditorState_AddPads::heightEditValueChanged); + mContext.commandToolBar.addWidget(std::move(edtHeight)); // drill diameter if (mPadType == PadType::THT) { mContext.commandToolBar.addLabel(tr("Drill Diameter:"), 10); - std::unique_ptr drillDiameterSpinBox(new QDoubleSpinBox()); - drillDiameterSpinBox->setMinimum(0); - drillDiameterSpinBox->setMaximum(100); - drillDiameterSpinBox->setSingleStep(0.2); - drillDiameterSpinBox->setDecimals(6); - drillDiameterSpinBox->setValue(mLastPad.getDrillDiameter()->toMm()); - connect(drillDiameterSpinBox.get(), - static_cast( - &QDoubleSpinBox::valueChanged), - this, - &PackageEditorState_AddPads::drillDiameterSpinBoxValueChanged); - mContext.commandToolBar.addWidget(std::move(drillDiameterSpinBox)); + std::unique_ptr edtDrillDiameter( + new UnsignedLengthEdit()); + edtDrillDiameter->setSingleStep(0.1); // [mm] + edtDrillDiameter->setValue(mLastPad.getDrillDiameter()); + connect(edtDrillDiameter.get(), &UnsignedLengthEdit::valueChanged, this, + &PackageEditorState_AddPads::drillDiameterEditValueChanged); + mContext.commandToolBar.addWidget(std::move(edtDrillDiameter)); } Point pos = @@ -322,31 +309,25 @@ void PackageEditorState_AddPads::shapeSelectorCurrentShapeChanged( } } -void PackageEditorState_AddPads::widthSpinBoxValueChanged( - double value) noexcept { - Length width = Length::fromMm(value); - if (width <= 0) return; - mLastPad.setWidth(PositiveLength(width)); +void PackageEditorState_AddPads::widthEditValueChanged( + const PositiveLength& value) noexcept { + mLastPad.setWidth(value); if (mEditCmd) { mEditCmd->setWidth(mLastPad.getWidth(), true); } } -void PackageEditorState_AddPads::heightSpinBoxValueChanged( - double value) noexcept { - Length height = Length::fromMm(value); - if (height <= 0) return; - mLastPad.setHeight(PositiveLength(height)); +void PackageEditorState_AddPads::heightEditValueChanged( + const PositiveLength& value) noexcept { + mLastPad.setHeight(value); if (mEditCmd) { mEditCmd->setHeight(mLastPad.getHeight(), true); } } -void PackageEditorState_AddPads::drillDiameterSpinBoxValueChanged( - double value) noexcept { - Length diameter = Length::fromMm(value); - if (diameter < 0) return; - mLastPad.setDrillDiameter(UnsignedLength(diameter)); +void PackageEditorState_AddPads::drillDiameterEditValueChanged( + const UnsignedLength& value) noexcept { + mLastPad.setDrillDiameter(value); if (mEditCmd) { mEditCmd->setDrillDiameter(mLastPad.getDrillDiameter(), true); } diff --git a/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_addpads.h b/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_addpads.h index 52fd9847ec..16784da84b 100644 --- a/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_addpads.h +++ b/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_addpads.h @@ -89,9 +89,9 @@ class PackageEditorState_AddPads : public PackageEditorState { void boardSideSelectorCurrentSideChanged( FootprintPad::BoardSide side) noexcept; void shapeSelectorCurrentShapeChanged(FootprintPad::Shape shape) noexcept; - void widthSpinBoxValueChanged(double value) noexcept; - void heightSpinBoxValueChanged(double value) noexcept; - void drillDiameterSpinBoxValueChanged(double value) noexcept; + void widthEditValueChanged(const PositiveLength& value) noexcept; + void heightEditValueChanged(const PositiveLength& value) noexcept; + void drillDiameterEditValueChanged(const UnsignedLength& value) noexcept; private: // Types / Data PadType mPadType; diff --git a/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_drawcircle.cpp b/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_drawcircle.cpp index c7ecafc019..6d3e89388b 100644 --- a/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_drawcircle.cpp +++ b/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_drawcircle.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -84,23 +85,18 @@ bool PackageEditorState_DrawCircle::entry() noexcept { mContext.commandToolBar.addWidget(std::move(layerComboBox)); mContext.commandToolBar.addLabel(tr("Line Width:"), 10); - std::unique_ptr lineWidthSpinBox(new QDoubleSpinBox()); - lineWidthSpinBox->setMinimum(0); - lineWidthSpinBox->setMaximum(100); - lineWidthSpinBox->setSingleStep(0.1); - lineWidthSpinBox->setDecimals(6); - lineWidthSpinBox->setValue(mLastLineWidth->toMm()); - connect(lineWidthSpinBox.get(), - static_cast( - &QDoubleSpinBox::valueChanged), - this, &PackageEditorState_DrawCircle::lineWidthSpinBoxValueChanged); - mContext.commandToolBar.addWidget(std::move(lineWidthSpinBox)); + std::unique_ptr edtLineWidth(new UnsignedLengthEdit()); + edtLineWidth->setSingleStep(0.1); // [mm] + edtLineWidth->setValue(mLastLineWidth); + connect(edtLineWidth.get(), &UnsignedLengthEdit::valueChanged, this, + &PackageEditorState_DrawCircle::lineWidthEditValueChanged); + mContext.commandToolBar.addWidget(std::move(edtLineWidth)); std::unique_ptr fillCheckBox(new QCheckBox(tr("Fill"))); fillCheckBox->setChecked(mLastFill); connect(fillCheckBox.get(), &QCheckBox::toggled, this, &PackageEditorState_DrawCircle::fillCheckBoxCheckedChanged); - mContext.commandToolBar.addWidget(std::move(fillCheckBox)); + mContext.commandToolBar.addWidget(std::move(fillCheckBox), 10); std::unique_ptr grabAreaCheckBox(new QCheckBox(tr("Grab Area"))); grabAreaCheckBox->setChecked(mLastGrabArea); @@ -240,9 +236,9 @@ void PackageEditorState_DrawCircle::layerComboBoxValueChanged( } } -void PackageEditorState_DrawCircle::lineWidthSpinBoxValueChanged( - double value) noexcept { - mLastLineWidth = Length::fromMm(value); +void PackageEditorState_DrawCircle::lineWidthEditValueChanged( + const UnsignedLength& value) noexcept { + mLastLineWidth = value; if (mEditCmd) { mEditCmd->setLineWidth(mLastLineWidth, true); } diff --git a/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_drawcircle.h b/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_drawcircle.h index d56536bbc1..156f09affe 100644 --- a/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_drawcircle.h +++ b/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_drawcircle.h @@ -82,7 +82,7 @@ class PackageEditorState_DrawCircle final : public PackageEditorState { bool abortAddCircle() noexcept; void layerComboBoxValueChanged(const QString& layerName) noexcept; - void lineWidthSpinBoxValueChanged(double value) noexcept; + void lineWidthEditValueChanged(const UnsignedLength& value) noexcept; void fillCheckBoxCheckedChanged(bool checked) noexcept; void grabAreaCheckBoxCheckedChanged(bool checked) noexcept; diff --git a/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_drawpolygonbase.cpp b/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_drawpolygonbase.cpp index 917d11e3e2..080fbdddfd 100644 --- a/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_drawpolygonbase.cpp +++ b/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_drawpolygonbase.cpp @@ -30,7 +30,9 @@ #include #include #include +#include #include +#include #include #include @@ -87,33 +89,21 @@ bool PackageEditorState_DrawPolygonBase::entry() noexcept { mContext.commandToolBar.addWidget(std::move(layerComboBox)); mContext.commandToolBar.addLabel(tr("Line Width:"), 10); - std::unique_ptr lineWidthSpinBox(new QDoubleSpinBox()); - lineWidthSpinBox->setMinimum(0); - lineWidthSpinBox->setMaximum(100); - lineWidthSpinBox->setSingleStep(0.1); - lineWidthSpinBox->setDecimals(6); - lineWidthSpinBox->setValue(mLastLineWidth->toMm()); - connect(lineWidthSpinBox.get(), - static_cast( - &QDoubleSpinBox::valueChanged), - this, - &PackageEditorState_DrawPolygonBase::lineWidthSpinBoxValueChanged); - mContext.commandToolBar.addWidget(std::move(lineWidthSpinBox)); + std::unique_ptr edtLineWidth(new UnsignedLengthEdit()); + edtLineWidth->setValue(mLastLineWidth); + edtLineWidth->setSingleStep(0.1); // [mm] + connect(edtLineWidth.get(), &UnsignedLengthEdit::valueChanged, this, + &PackageEditorState_DrawPolygonBase::lineWidthEditValueChanged); + mContext.commandToolBar.addWidget(std::move(edtLineWidth)); if (mMode != Mode::RECT) { mContext.commandToolBar.addLabel(tr("Angle:"), 10); - std::unique_ptr angleSpinBox(new QDoubleSpinBox()); - angleSpinBox->setMinimum(-360); - angleSpinBox->setMaximum(360); - angleSpinBox->setSingleStep(30); - angleSpinBox->setDecimals(6); - angleSpinBox->setValue(mLastAngle.toDeg()); - connect(angleSpinBox.get(), - static_cast( - &QDoubleSpinBox::valueChanged), - this, - &PackageEditorState_DrawPolygonBase::angleSpinBoxValueChanged); - mContext.commandToolBar.addWidget(std::move(angleSpinBox)); + std::unique_ptr edtAngle(new AngleEdit()); + edtAngle->setSingleStep(90.0); // [°] + edtAngle->setValue(mLastAngle); + connect(edtAngle.get(), &AngleEdit::valueChanged, this, + &PackageEditorState_DrawPolygonBase::angleEditValueChanged); + mContext.commandToolBar.addWidget(std::move(edtAngle)); } if (mMode != Mode::LINE) { @@ -121,7 +111,7 @@ bool PackageEditorState_DrawPolygonBase::entry() noexcept { fillCheckBox->setChecked(mLastFill); connect(fillCheckBox.get(), &QCheckBox::toggled, this, &PackageEditorState_DrawPolygonBase::fillCheckBoxCheckedChanged); - mContext.commandToolBar.addWidget(std::move(fillCheckBox)); + mContext.commandToolBar.addWidget(std::move(fillCheckBox), 10); } if (mMode != Mode::LINE) { @@ -300,17 +290,17 @@ void PackageEditorState_DrawPolygonBase::layerComboBoxValueChanged( } } -void PackageEditorState_DrawPolygonBase::lineWidthSpinBoxValueChanged( - double value) noexcept { - mLastLineWidth = Length::fromMm(value); +void PackageEditorState_DrawPolygonBase::lineWidthEditValueChanged( + const UnsignedLength& value) noexcept { + mLastLineWidth = value; if (mEditCmd) { mEditCmd->setLineWidth(mLastLineWidth, true); } } -void PackageEditorState_DrawPolygonBase::angleSpinBoxValueChanged( - double value) noexcept { - mLastAngle = Angle::fromDeg(value); +void PackageEditorState_DrawPolygonBase::angleEditValueChanged( + const Angle& value) noexcept { + mLastAngle = value; if (mCurrentPolygon && mEditCmd) { Path path = mCurrentPolygon->getPath(); if (path.getVertices().count() > 1) { diff --git a/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_drawpolygonbase.h b/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_drawpolygonbase.h index 2c4d9c138d..854e644e0c 100644 --- a/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_drawpolygonbase.h +++ b/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_drawpolygonbase.h @@ -89,8 +89,8 @@ class PackageEditorState_DrawPolygonBase : public PackageEditorState { bool updateCurrentPosition(const Point& pos) noexcept; void layerComboBoxValueChanged(const QString& layerName) noexcept; - void lineWidthSpinBoxValueChanged(double value) noexcept; - void angleSpinBoxValueChanged(double value) noexcept; + void lineWidthEditValueChanged(const UnsignedLength& value) noexcept; + void angleEditValueChanged(const Angle& value) noexcept; void fillCheckBoxCheckedChanged(bool checked) noexcept; void grabAreaCheckBoxCheckedChanged(bool checked) noexcept; diff --git a/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_drawtextbase.cpp b/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_drawtextbase.cpp index fbb525e7cd..49600f86ca 100644 --- a/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_drawtextbase.cpp +++ b/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_drawtextbase.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -103,17 +104,12 @@ bool PackageEditorState_DrawTextBase::entry() noexcept { } mContext.commandToolBar.addLabel(tr("Height:"), 10); - std::unique_ptr lineWidthSpinBox(new QDoubleSpinBox()); - lineWidthSpinBox->setMinimum(0.1); - lineWidthSpinBox->setMaximum(100); - lineWidthSpinBox->setSingleStep(0.1); - lineWidthSpinBox->setDecimals(6); - lineWidthSpinBox->setValue(mLastHeight->toMm()); - connect(lineWidthSpinBox.get(), - static_cast( - &QDoubleSpinBox::valueChanged), - this, &PackageEditorState_DrawTextBase::heightSpinBoxValueChanged); - mContext.commandToolBar.addWidget(std::move(lineWidthSpinBox)); + std::unique_ptr edtLineWidth(new PositiveLengthEdit()); + edtLineWidth->setSingleStep(0.5); // [mm] + edtLineWidth->setValue(mLastHeight); + connect(edtLineWidth.get(), &PositiveLengthEdit::valueChanged, this, + &PackageEditorState_DrawTextBase::heightEditValueChanged); + mContext.commandToolBar.addWidget(std::move(edtLineWidth)); Point pos = mContext.graphicsView.mapGlobalPosToScenePos(QCursor::pos(), true, true); @@ -280,9 +276,9 @@ void PackageEditorState_DrawTextBase::layerComboBoxValueChanged( } } -void PackageEditorState_DrawTextBase::heightSpinBoxValueChanged( - double value) noexcept { - mLastHeight = Length::fromMm(value); +void PackageEditorState_DrawTextBase::heightEditValueChanged( + const PositiveLength& value) noexcept { + mLastHeight = value; if (mEditCmd) { mEditCmd->setHeight(mLastHeight, true); } diff --git a/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_drawtextbase.h b/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_drawtextbase.h index e3584714d5..da5c5897da 100644 --- a/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_drawtextbase.h +++ b/libs/librepcb/libraryeditor/pkg/fsm/packageeditorstate_drawtextbase.h @@ -90,7 +90,7 @@ class PackageEditorState_DrawTextBase : public PackageEditorState { void resetToDefaultParameters() noexcept; void layerComboBoxValueChanged(const QString& layerName) noexcept; - void heightSpinBoxValueChanged(double value) noexcept; + void heightEditValueChanged(const PositiveLength& value) noexcept; void textComboBoxValueChanged(const QString& value) noexcept; private: // Types / Data diff --git a/libs/librepcb/libraryeditor/sym/dialogs/symbolpinpropertiesdialog.cpp b/libs/librepcb/libraryeditor/sym/dialogs/symbolpinpropertiesdialog.cpp index 1f6bb95a3f..f9fc659f0f 100644 --- a/libs/librepcb/libraryeditor/sym/dialogs/symbolpinpropertiesdialog.cpp +++ b/libs/librepcb/libraryeditor/sym/dialogs/symbolpinpropertiesdialog.cpp @@ -46,15 +46,17 @@ SymbolPinPropertiesDialog::SymbolPinPropertiesDialog(SymbolPin& pin, mUndoStack(undoStack), mUi(new Ui::SymbolPinPropertiesDialog) { mUi->setupUi(this); + mUi->edtLength->setSingleStep(2.54); // [mm] + mUi->edtRotation->setSingleStep(90.0); // [°] connect(mUi->buttonBox, &QDialogButtonBox::clicked, this, &SymbolPinPropertiesDialog::on_buttonBox_clicked); // load pin attributes mUi->edtName->setText(*mSymbolPin.getName()); - mUi->spbPosX->setValue(mSymbolPin.getPosition().getX().toMm()); - mUi->spbPosY->setValue(mSymbolPin.getPosition().getY().toMm()); - mUi->spbRotation->setValue(mSymbolPin.getRotation().toDeg()); - mUi->spbLength->setValue(mSymbolPin.getLength()->toMm()); + mUi->edtPosX->setValue(mSymbolPin.getPosition().getX()); + mUi->edtPosY->setValue(mSymbolPin.getPosition().getY()); + mUi->edtRotation->setValue(mSymbolPin.getRotation()); + mUi->edtLength->setValue(mSymbolPin.getLength()); // preselect name mUi->edtName->selectAll(); @@ -91,11 +93,10 @@ bool SymbolPinPropertiesDialog::applyChanges() noexcept { CircuitIdentifier name(mUi->edtName->text().trimmed()); // can throw QScopedPointer cmd(new CmdSymbolPinEdit(mSymbolPin)); cmd->setName(name, false); - cmd->setLength(UnsignedLength(Length::fromMm(mUi->spbLength->value())), - false); // can throw - cmd->setPosition( - Point::fromMm(mUi->spbPosX->value(), mUi->spbPosY->value()), false); - cmd->setRotation(Angle::fromDeg(mUi->spbRotation->value()), false); + cmd->setLength(mUi->edtLength->getValue(), false); + cmd->setPosition(Point(mUi->edtPosX->getValue(), mUi->edtPosY->getValue()), + false); + cmd->setRotation(mUi->edtRotation->getValue(), false); mUndoStack.execCmd(cmd.take()); return true; } catch (const Exception& e) { diff --git a/libs/librepcb/libraryeditor/sym/dialogs/symbolpinpropertiesdialog.ui b/libs/librepcb/libraryeditor/sym/dialogs/symbolpinpropertiesdialog.ui index 44bdedd41f..674516f071 100644 --- a/libs/librepcb/libraryeditor/sym/dialogs/symbolpinpropertiesdialog.ui +++ b/libs/librepcb/libraryeditor/sym/dialogs/symbolpinpropertiesdialog.ui @@ -7,7 +7,7 @@ 0 0 313 - 174 + 145 @@ -37,19 +37,6 @@ - - - - 6 - - - 9999.000000000000000 - - - 2.540000000000000 - - - @@ -60,36 +47,10 @@ - - - 6 - - - -9999.000000000000000 - - - 9999.000000000000000 - - - 2.540000000000000 - - + - - - 6 - - - -9999.000000000000000 - - - 9999.000000000000000 - - - 2.540000000000000 - - + @@ -100,21 +61,11 @@ + + + - - - 6 - - - -360.000000000000000 - - - 360.000000000000000 - - - 45.000000000000000 - - + @@ -130,6 +81,26 @@ + + + librepcb::LengthEdit + QWidget +
librepcb/common/widgets/lengthedit.h
+ 1 +
+ + librepcb::AngleEdit + QWidget +
librepcb/common/widgets/angleedit.h
+ 1 +
+ + librepcb::UnsignedLengthEdit + QWidget +
librepcb/common/widgets/unsignedlengthedit.h
+ 1 +
+
diff --git a/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_addpins.cpp b/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_addpins.cpp index a03816a322..fbe47949be 100644 --- a/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_addpins.cpp +++ b/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_addpins.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -79,17 +80,12 @@ bool SymbolEditorState_AddPins::entry() noexcept { mContext.commandToolBar.addWidget(std::move(nameLineEdit)); mContext.commandToolBar.addLabel(tr("Length:"), 10); - std::unique_ptr lengthSpinBox(new QDoubleSpinBox()); - lengthSpinBox->setMinimum(0); - lengthSpinBox->setMaximum(100); - lengthSpinBox->setSingleStep(1.27); - lengthSpinBox->setDecimals(6); - lengthSpinBox->setValue(mLastLength->toMm()); - connect(lengthSpinBox.get(), - static_cast( - &QDoubleSpinBox::valueChanged), - this, &SymbolEditorState_AddPins::lengthSpinBoxValueChanged); - mContext.commandToolBar.addWidget(std::move(lengthSpinBox)); + std::unique_ptr edtLength(new UnsignedLengthEdit()); + edtLength->setSingleStep(2.54); // [mm] + edtLength->setValue(mLastLength); + connect(edtLength.get(), &UnsignedLengthEdit::valueChanged, this, + &SymbolEditorState_AddPins::lengthEditValueChanged); + mContext.commandToolBar.addWidget(std::move(edtLength)); Point pos = mContext.graphicsView.mapGlobalPosToScenePos(QCursor::pos(), true, true); @@ -204,9 +200,9 @@ void SymbolEditorState_AddPins::nameLineEditTextChanged( } } -void SymbolEditorState_AddPins::lengthSpinBoxValueChanged( - double value) noexcept { - mLastLength = Length::fromMm(value); +void SymbolEditorState_AddPins::lengthEditValueChanged( + const UnsignedLength& value) noexcept { + mLastLength = value; if (mEditCmd) { mEditCmd->setLength(mLastLength, true); } diff --git a/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_addpins.h b/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_addpins.h index a620304bf0..4776e7bfd7 100644 --- a/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_addpins.h +++ b/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_addpins.h @@ -78,7 +78,7 @@ class SymbolEditorState_AddPins final : public SymbolEditorState { private: // Methods bool addNextPin(const Point& pos, const Angle& rot) noexcept; void nameLineEditTextChanged(const QString& text) noexcept; - void lengthSpinBoxValueChanged(double value) noexcept; + void lengthEditValueChanged(const UnsignedLength& value) noexcept; QString determineNextPinName() const noexcept; bool hasPin(const QString& name) const noexcept; diff --git a/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_drawcircle.cpp b/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_drawcircle.cpp index 4266b96696..4c7fc9903b 100644 --- a/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_drawcircle.cpp +++ b/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_drawcircle.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -84,23 +85,18 @@ bool SymbolEditorState_DrawCircle::entry() noexcept { mContext.commandToolBar.addWidget(std::move(layerComboBox)); mContext.commandToolBar.addLabel(tr("Line Width:"), 10); - std::unique_ptr lineWidthSpinBox(new QDoubleSpinBox()); - lineWidthSpinBox->setMinimum(0); - lineWidthSpinBox->setMaximum(100); - lineWidthSpinBox->setSingleStep(0.1); - lineWidthSpinBox->setDecimals(6); - lineWidthSpinBox->setValue(mLastLineWidth->toMm()); - connect(lineWidthSpinBox.get(), - static_cast( - &QDoubleSpinBox::valueChanged), - this, &SymbolEditorState_DrawCircle::lineWidthSpinBoxValueChanged); - mContext.commandToolBar.addWidget(std::move(lineWidthSpinBox)); + std::unique_ptr edtLineWidth(new UnsignedLengthEdit()); + edtLineWidth->setSingleStep(0.1); // [mm] + edtLineWidth->setValue(mLastLineWidth); + connect(edtLineWidth.get(), &UnsignedLengthEdit::valueChanged, this, + &SymbolEditorState_DrawCircle::lineWidthEditValueChanged); + mContext.commandToolBar.addWidget(std::move(edtLineWidth)); std::unique_ptr fillCheckBox(new QCheckBox(tr("Fill"))); fillCheckBox->setChecked(mLastFill); connect(fillCheckBox.get(), &QCheckBox::toggled, this, &SymbolEditorState_DrawCircle::fillCheckBoxCheckedChanged); - mContext.commandToolBar.addWidget(std::move(fillCheckBox)); + mContext.commandToolBar.addWidget(std::move(fillCheckBox), 10); std::unique_ptr grabAreaCheckBox(new QCheckBox(tr("Grab Area"))); grabAreaCheckBox->setChecked(mLastGrabArea); @@ -239,9 +235,9 @@ void SymbolEditorState_DrawCircle::layerComboBoxValueChanged( } } -void SymbolEditorState_DrawCircle::lineWidthSpinBoxValueChanged( - double value) noexcept { - mLastLineWidth = Length::fromMm(value); +void SymbolEditorState_DrawCircle::lineWidthEditValueChanged( + const UnsignedLength& value) noexcept { + mLastLineWidth = value; if (mEditCmd) { mEditCmd->setLineWidth(mLastLineWidth, true); } diff --git a/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_drawcircle.h b/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_drawcircle.h index deb4f3eae9..6acc3b8a1f 100644 --- a/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_drawcircle.h +++ b/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_drawcircle.h @@ -82,7 +82,7 @@ class SymbolEditorState_DrawCircle final : public SymbolEditorState { bool abortAddCircle() noexcept; void layerComboBoxValueChanged(const QString& layerName) noexcept; - void lineWidthSpinBoxValueChanged(double value) noexcept; + void lineWidthEditValueChanged(const UnsignedLength& value) noexcept; void fillCheckBoxCheckedChanged(bool checked) noexcept; void grabAreaCheckBoxCheckedChanged(bool checked) noexcept; diff --git a/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_drawpolygonbase.cpp b/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_drawpolygonbase.cpp index a01a612e71..d16c419087 100644 --- a/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_drawpolygonbase.cpp +++ b/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_drawpolygonbase.cpp @@ -30,7 +30,9 @@ #include #include #include +#include #include +#include #include #include @@ -87,32 +89,21 @@ bool SymbolEditorState_DrawPolygonBase::entry() noexcept { mContext.commandToolBar.addWidget(std::move(layerComboBox)); mContext.commandToolBar.addLabel(tr("Line Width:"), 10); - std::unique_ptr lineWidthSpinBox(new QDoubleSpinBox()); - lineWidthSpinBox->setMinimum(0); - lineWidthSpinBox->setMaximum(100); - lineWidthSpinBox->setSingleStep(0.1); - lineWidthSpinBox->setDecimals(6); - lineWidthSpinBox->setValue(mLastLineWidth->toMm()); - connect(lineWidthSpinBox.get(), - static_cast( - &QDoubleSpinBox::valueChanged), - this, - &SymbolEditorState_DrawPolygonBase::lineWidthSpinBoxValueChanged); - mContext.commandToolBar.addWidget(std::move(lineWidthSpinBox)); + std::unique_ptr edtLineWidth(new UnsignedLengthEdit()); + edtLineWidth->setSingleStep(0.1); // [mm] + edtLineWidth->setValue(mLastLineWidth); + connect(edtLineWidth.get(), &UnsignedLengthEdit::valueChanged, this, + &SymbolEditorState_DrawPolygonBase::lineWidthEditValueChanged); + mContext.commandToolBar.addWidget(std::move(edtLineWidth)); if (mMode != Mode::RECT) { mContext.commandToolBar.addLabel(tr("Angle:"), 10); - std::unique_ptr angleSpinBox(new QDoubleSpinBox()); - angleSpinBox->setMinimum(-360); - angleSpinBox->setMaximum(360); - angleSpinBox->setSingleStep(30); - angleSpinBox->setDecimals(6); - angleSpinBox->setValue(mLastAngle.toDeg()); - connect(angleSpinBox.get(), - static_cast( - &QDoubleSpinBox::valueChanged), - this, &SymbolEditorState_DrawPolygonBase::angleSpinBoxValueChanged); - mContext.commandToolBar.addWidget(std::move(angleSpinBox)); + std::unique_ptr edtAngle(new AngleEdit()); + edtAngle->setSingleStep(90.0); // [°] + edtAngle->setValue(mLastAngle); + connect(edtAngle.get(), &AngleEdit::valueChanged, this, + &SymbolEditorState_DrawPolygonBase::angleEditValueChanged); + mContext.commandToolBar.addWidget(std::move(edtAngle)); } if (mMode != Mode::LINE) { @@ -120,7 +111,7 @@ bool SymbolEditorState_DrawPolygonBase::entry() noexcept { fillCheckBox->setChecked(mLastFill); connect(fillCheckBox.get(), &QCheckBox::toggled, this, &SymbolEditorState_DrawPolygonBase::fillCheckBoxCheckedChanged); - mContext.commandToolBar.addWidget(std::move(fillCheckBox)); + mContext.commandToolBar.addWidget(std::move(fillCheckBox), 10); } if (mMode != Mode::LINE) { @@ -298,17 +289,17 @@ void SymbolEditorState_DrawPolygonBase::layerComboBoxValueChanged( } } -void SymbolEditorState_DrawPolygonBase::lineWidthSpinBoxValueChanged( - double value) noexcept { - mLastLineWidth = Length::fromMm(value); +void SymbolEditorState_DrawPolygonBase::lineWidthEditValueChanged( + const UnsignedLength& value) noexcept { + mLastLineWidth = value; if (mEditCmd) { mEditCmd->setLineWidth(mLastLineWidth, true); } } -void SymbolEditorState_DrawPolygonBase::angleSpinBoxValueChanged( - double value) noexcept { - mLastAngle = Angle::fromDeg(value); +void SymbolEditorState_DrawPolygonBase::angleEditValueChanged( + const Angle& value) noexcept { + mLastAngle = value; if (mCurrentPolygon && mEditCmd) { Path path = mCurrentPolygon->getPath(); if (path.getVertices().count() > 1) { diff --git a/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_drawpolygonbase.h b/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_drawpolygonbase.h index 95b0a9969b..c18795ea17 100644 --- a/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_drawpolygonbase.h +++ b/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_drawpolygonbase.h @@ -89,8 +89,8 @@ class SymbolEditorState_DrawPolygonBase : public SymbolEditorState { bool updateCurrentPosition(const Point& pos) noexcept; void layerComboBoxValueChanged(const QString& layerName) noexcept; - void lineWidthSpinBoxValueChanged(double value) noexcept; - void angleSpinBoxValueChanged(double value) noexcept; + void lineWidthEditValueChanged(const UnsignedLength& value) noexcept; + void angleEditValueChanged(const Angle& value) noexcept; void fillCheckBoxCheckedChanged(bool checked) noexcept; void grabAreaCheckBoxCheckedChanged(bool checked) noexcept; diff --git a/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_drawtextbase.cpp b/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_drawtextbase.cpp index 6124682aac..0538533b9c 100644 --- a/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_drawtextbase.cpp +++ b/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_drawtextbase.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -104,17 +105,12 @@ bool SymbolEditorState_DrawTextBase::entry() noexcept { } mContext.commandToolBar.addLabel(tr("Height:"), 10); - std::unique_ptr lineWidthSpinBox(new QDoubleSpinBox()); - lineWidthSpinBox->setMinimum(0.1); - lineWidthSpinBox->setMaximum(100); - lineWidthSpinBox->setSingleStep(0.5); - lineWidthSpinBox->setDecimals(6); - lineWidthSpinBox->setValue(mLastHeight->toMm()); - connect(lineWidthSpinBox.get(), - static_cast( - &QDoubleSpinBox::valueChanged), - this, &SymbolEditorState_DrawTextBase::heightSpinBoxValueChanged); - mContext.commandToolBar.addWidget(std::move(lineWidthSpinBox)); + std::unique_ptr edtHeight(new PositiveLengthEdit()); + edtHeight->setSingleStep(0.5); // [mm] + edtHeight->setValue(mLastHeight); + connect(edtHeight.get(), &PositiveLengthEdit::valueChanged, this, + &SymbolEditorState_DrawTextBase::heightEditValueChanged); + mContext.commandToolBar.addWidget(std::move(edtHeight)); Point pos = mContext.graphicsView.mapGlobalPosToScenePos(QCursor::pos(), true, true); @@ -285,9 +281,9 @@ void SymbolEditorState_DrawTextBase::layerComboBoxValueChanged( } } -void SymbolEditorState_DrawTextBase::heightSpinBoxValueChanged( - double value) noexcept { - mLastHeight = Length::fromMm(value); +void SymbolEditorState_DrawTextBase::heightEditValueChanged( + const PositiveLength& value) noexcept { + mLastHeight = value; if (mEditCmd) { mEditCmd->setHeight(mLastHeight, true); } diff --git a/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_drawtextbase.h b/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_drawtextbase.h index 922ed8642b..c001d62ab1 100644 --- a/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_drawtextbase.h +++ b/libs/librepcb/libraryeditor/sym/fsm/symboleditorstate_drawtextbase.h @@ -92,7 +92,7 @@ class SymbolEditorState_DrawTextBase : public SymbolEditorState { Alignment getAlignment() const noexcept; void layerComboBoxValueChanged(const QString& layerName) noexcept; - void heightSpinBoxValueChanged(double value) noexcept; + void heightEditValueChanged(const PositiveLength& value) noexcept; void textComboBoxValueChanged(const QString& value) noexcept; private: // Types / Data diff --git a/libs/librepcb/project/boards/cmd/cmddeviceinstanceeditall.cpp b/libs/librepcb/project/boards/cmd/cmddeviceinstanceeditall.cpp index df0ad905fd..56d05d93ad 100644 --- a/libs/librepcb/project/boards/cmd/cmddeviceinstanceeditall.cpp +++ b/libs/librepcb/project/boards/cmd/cmddeviceinstanceeditall.cpp @@ -60,8 +60,8 @@ CmdDeviceInstanceEditAll::~CmdDeviceInstanceEditAll() noexcept { * General Methods ******************************************************************************/ -void CmdDeviceInstanceEditAll::setPosition(Point& pos, - bool immediate) noexcept { +void CmdDeviceInstanceEditAll::setPosition(const Point& pos, + bool immediate) noexcept { Q_ASSERT(!wasEverExecuted()); translate(pos - mDevEditCmd->mNewPos, immediate); } diff --git a/libs/librepcb/project/boards/cmd/cmddeviceinstanceeditall.h b/libs/librepcb/project/boards/cmd/cmddeviceinstanceeditall.h index 365cb9dc1b..c364dbdf65 100644 --- a/libs/librepcb/project/boards/cmd/cmddeviceinstanceeditall.h +++ b/libs/librepcb/project/boards/cmd/cmddeviceinstanceeditall.h @@ -54,7 +54,7 @@ class CmdDeviceInstanceEditAll final : public UndoCommandGroup { ~CmdDeviceInstanceEditAll() noexcept; // General Methods - void setPosition(Point& pos, bool immediate) noexcept; + void setPosition(const Point& pos, bool immediate) noexcept; void translate(const Point& deltaPos, bool immediate) noexcept; void setRotation(const Angle& angle, bool immediate) noexcept; void rotate(const Angle& angle, const Point& center, bool immediate) noexcept; diff --git a/libs/librepcb/projecteditor/boardeditor/boardplanepropertiesdialog.cpp b/libs/librepcb/projecteditor/boardeditor/boardplanepropertiesdialog.cpp index 715f2650d8..cde7cf7781 100644 --- a/libs/librepcb/projecteditor/boardeditor/boardplanepropertiesdialog.cpp +++ b/libs/librepcb/projecteditor/boardeditor/boardplanepropertiesdialog.cpp @@ -56,6 +56,8 @@ BoardPlanePropertiesDialog::BoardPlanePropertiesDialog(Project& project, mUi(new Ui::BoardPlanePropertiesDialog), mUndoStack(undoStack) { mUi->setupUi(this); + mUi->edtMinWidth->setSingleStep(0.1); // [mm] + mUi->edtMinClearance->setSingleStep(0.1); // [mm] connect(mUi->buttonBox, &QDialogButtonBox::clicked, this, &BoardPlanePropertiesDialog::buttonBoxClicked); @@ -79,8 +81,8 @@ BoardPlanePropertiesDialog::BoardPlanePropertiesDialog(Project& project, mUi->cbxLayer->findData(*mPlane.getLayerName())); // minimum width / clearance spinbox - mUi->spbMinWidth->setValue(mPlane.getMinWidth()->toMm()); - mUi->spbMinClearance->setValue(mPlane.getMinClearance()->toMm()); + mUi->edtMinWidth->setValue(mPlane.getMinWidth()); + mUi->edtMinClearance->setValue(mPlane.getMinClearance()); // connect style combobox mUi->cbxConnectStyle->addItem(tr("None"), @@ -154,10 +156,8 @@ bool BoardPlanePropertiesDialog::applyChanges() noexcept { } // min width/clearance - cmd->setMinWidth(UnsignedLength( - Length::fromMm(mUi->spbMinWidth->value()))); // can throw - cmd->setMinClearance(UnsignedLength( - Length::fromMm(mUi->spbMinClearance->value()))); // can throw + cmd->setMinWidth(mUi->edtMinWidth->getValue()); + cmd->setMinClearance(mUi->edtMinClearance->getValue()); // connect style cmd->setConnectStyle(static_cast( diff --git a/libs/librepcb/projecteditor/boardeditor/boardplanepropertiesdialog.ui b/libs/librepcb/projecteditor/boardeditor/boardplanepropertiesdialog.ui index 0ba98ff801..5d1dfc862a 100644 --- a/libs/librepcb/projecteditor/boardeditor/boardplanepropertiesdialog.ui +++ b/libs/librepcb/projecteditor/boardeditor/boardplanepropertiesdialog.ui @@ -46,19 +46,6 @@ - - - - 6 - - - 999.000000000000000 - - - 0.100000000000000 - - - @@ -66,19 +53,6 @@ - - - - 6 - - - 999.000000000000000 - - - 0.100000000000000 - - - @@ -119,6 +93,12 @@ + + + + + + @@ -150,6 +130,12 @@
librepcb/common/widgets/patheditorwidget.h
1 + + librepcb::UnsignedLengthEdit + QWidget +
librepcb/common/widgets/unsignedlengthedit.h
+ 1 +
diff --git a/libs/librepcb/projecteditor/boardeditor/boardviapropertiesdialog.cpp b/libs/librepcb/projecteditor/boardeditor/boardviapropertiesdialog.cpp index 19151e75e2..2fd63035d6 100644 --- a/libs/librepcb/projecteditor/boardeditor/boardviapropertiesdialog.cpp +++ b/libs/librepcb/projecteditor/boardeditor/boardviapropertiesdialog.cpp @@ -53,6 +53,8 @@ BoardViaPropertiesDialog::BoardViaPropertiesDialog(Project& project, mUi(new Ui::BoardViaPropertiesDialog), mUndoStack(undoStack) { mUi->setupUi(this); + mUi->edtSize->setSingleStep(0.1); // [mm] + mUi->edtDrillDiameter->setSingleStep(0.1); // [mm] // shape combobox mUi->cbxShape->addItem(tr("Round"), static_cast(BI_Via::Shape::Round)); @@ -63,14 +65,14 @@ BoardViaPropertiesDialog::BoardViaPropertiesDialog(Project& project, mUi->cbxShape->findData(static_cast(mVia.getShape()))); // Position spinboxes - mUi->spbxPosX->setValue(mVia.getPosition().getX().toMm()); - mUi->spbxPosY->setValue(mVia.getPosition().getY().toMm()); + mUi->edtPosX->setValue(mVia.getPosition().getX()); + mUi->edtPosY->setValue(mVia.getPosition().getY()); // size spinbox - mUi->spbxSize->setValue(mVia.getSize()->toMm()); + mUi->edtSize->setValue(mVia.getSize()); // drill diameter spinbox - mUi->spbxDrillDiameter->setValue(mVia.getDrillDiameter()->toMm()); + mUi->edtDrillDiameter->setValue(mVia.getDrillDiameter()); // netsignal combobox mUi->lblNetSignal->setText(*mVia.getNetSignalOfNetSegment().getName()); @@ -114,14 +116,10 @@ bool BoardViaPropertiesDialog::applyChanges() noexcept { cmd->setShape( static_cast(mUi->cbxShape->currentData().toInt()), false); - cmd->setPosition(Point(Length::fromMm(mUi->spbxPosX->value()), - Length::fromMm(mUi->spbxPosY->value())), + cmd->setPosition(Point(mUi->edtPosX->getValue(), mUi->edtPosY->getValue()), false); - cmd->setSize(PositiveLength(Length::fromMm(mUi->spbxSize->value())), - false); // can throw - cmd->setDrillDiameter( - PositiveLength(Length::fromMm(mUi->spbxDrillDiameter->value())), - false); // can throw + cmd->setSize(mUi->edtSize->getValue(), false); + cmd->setDrillDiameter(mUi->edtDrillDiameter->getValue(), false); mUndoStack.execCmd(cmd.take()); return true; } catch (const Exception& e) { diff --git a/libs/librepcb/projecteditor/boardeditor/boardviapropertiesdialog.ui b/libs/librepcb/projecteditor/boardeditor/boardviapropertiesdialog.ui index 07d0bd8b95..9a6363541f 100644 --- a/libs/librepcb/projecteditor/boardeditor/boardviapropertiesdialog.ui +++ b/libs/librepcb/projecteditor/boardeditor/boardviapropertiesdialog.ui @@ -7,7 +7,7 @@ 0 0 346 - 197 + 168 @@ -50,72 +50,10 @@ - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - QAbstractSpinBox::UpDownArrows - - - mm - - - 6 - - - -2000.000000000000000 - - - 2000.000000000000000 - - - 2.540000000000000 - - + - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - QAbstractSpinBox::UpDownArrows - - - mm - - - 6 - - - -2000.000000000000000 - - - 2000.000000000000000 - - - 2.540000000000000 - - + @@ -126,19 +64,6 @@
- - - - mm - - - 0.010000000000000 - - - 0.100000000000000 - - - @@ -146,18 +71,11 @@ + + + - - - mm - - - 0.010000000000000 - - - 0.100000000000000 - - + @@ -173,6 +91,20 @@ + + + librepcb::LengthEdit + QWidget +
librepcb/common/widgets/lengthedit.h
+ 1 +
+ + librepcb::PositiveLengthEdit + QWidget +
librepcb/common/widgets/positivelengthedit.h
+ 1 +
+
diff --git a/libs/librepcb/projecteditor/boardeditor/deviceinstancepropertiesdialog.cpp b/libs/librepcb/projecteditor/boardeditor/deviceinstancepropertiesdialog.cpp index 5f535a8e5a..1c1afd976a 100644 --- a/libs/librepcb/projecteditor/boardeditor/deviceinstancepropertiesdialog.cpp +++ b/libs/librepcb/projecteditor/boardeditor/deviceinstancepropertiesdialog.cpp @@ -58,6 +58,7 @@ DeviceInstancePropertiesDialog::DeviceInstancePropertiesDialog( mAttributes(mDevice.getComponentInstance().getAttributes()), mUi(new Ui::DeviceInstancePropertiesDialog) { mUi->setupUi(this); + mUi->edtRotation->setSingleStep(90.0); // [°] connect(mUi->buttonBox, &QDialogButtonBox::clicked, this, &DeviceInstancePropertiesDialog::buttonBoxClicked); setWindowTitle(QString(tr("Properties of %1")) @@ -93,9 +94,9 @@ DeviceInstancePropertiesDialog::DeviceInstancePropertiesDialog( mDevice.getLibFootprint().getDescriptions().value(localeOrder)); // Device/Footprint Attributes - mUi->spbxPosX->setValue(mDevice.getPosition().getX().toMm()); - mUi->spbxPosY->setValue(mDevice.getPosition().getY().toMm()); - mUi->spbxRotation->setValue(mDevice.getRotation().toDeg()); + mUi->edtPosX->setValue(mDevice.getPosition().getX()); + mUi->edtPosY->setValue(mDevice.getPosition().getY()); + mUi->edtRotation->setValue(mDevice.getRotation()); mUi->cbxMirror->setChecked(mDevice.getIsMirrored()); // set focus to component instance name @@ -166,13 +167,11 @@ bool DeviceInstancePropertiesDialog::applyChanges() noexcept { transaction.append(cmdCmp.take()); // can throw // Device Instance - Point pos(Length::fromMm(mUi->spbxPosX->value()), - Length::fromMm(mUi->spbxPosY->value())); - Angle rotation = Angle::fromDeg(mUi->spbxRotation->value()); QScopedPointer cmdDev( new CmdDeviceInstanceEditAll(mDevice)); - cmdDev->setPosition(pos, false); - cmdDev->setRotation(rotation, false); + cmdDev->setPosition( + Point(mUi->edtPosX->getValue(), mUi->edtPosY->getValue()), false); + cmdDev->setRotation(mUi->edtRotation->getValue(), false); cmdDev->setMirrored(mUi->cbxMirror->isChecked(), false); // can throw transaction.append(cmdDev.take()); // can throw diff --git a/libs/librepcb/projecteditor/boardeditor/deviceinstancepropertiesdialog.ui b/libs/librepcb/projecteditor/boardeditor/deviceinstancepropertiesdialog.ui index f56d3707f2..1ddcf9618a 100644 --- a/libs/librepcb/projecteditor/boardeditor/deviceinstancepropertiesdialog.ui +++ b/libs/librepcb/projecteditor/boardeditor/deviceinstancepropertiesdialog.ui @@ -38,40 +38,6 @@ - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - QAbstractSpinBox::UpDownArrows - - - mm - - - 6 - - - -2000.000000000000000 - - - 2000.000000000000000 - - - 2.540000000000000 - - - @@ -79,37 +45,6 @@ - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - mm - - - 6 - - - -2000.000000000000000 - - - 2000.000000000000000 - - - 2.540000000000000 - - - @@ -117,37 +52,6 @@ - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - ° - - - 6 - - - -360.000000000000000 - - - 360.000000000000000 - - - 45.000000000000000 - - - @@ -162,6 +66,15 @@ + + + + + + + + + @@ -363,6 +276,18 @@ + + librepcb::LengthEdit + QWidget +
librepcb/common/widgets/lengthedit.h
+ 1 +
+ + librepcb::AngleEdit + QWidget +
librepcb/common/widgets/angleedit.h
+ 1 +
librepcb::AttributeListEditorWidget QWidget diff --git a/libs/librepcb/projecteditor/boardeditor/fsm/bes_addhole.cpp b/libs/librepcb/projecteditor/boardeditor/fsm/bes_addhole.cpp index 24c95f16c3..a847bb40f2 100644 --- a/libs/librepcb/projecteditor/boardeditor/fsm/bes_addhole.cpp +++ b/libs/librepcb/projecteditor/boardeditor/fsm/bes_addhole.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -91,17 +92,12 @@ bool BES_AddHole::entry(BEE_Base* event) noexcept { mEditorUi.commandToolbar->addWidget(mDiameterLabel.data()); // add the diameter spinbox to the toolbar - mDiameterSpinBox.reset(new QDoubleSpinBox()); - mDiameterSpinBox->setMinimum(0.0001); - mDiameterSpinBox->setMaximum(100); - mDiameterSpinBox->setSingleStep(0.2); - mDiameterSpinBox->setDecimals(6); - mDiameterSpinBox->setValue(mCurrentDiameter->toMm()); - connect(mDiameterSpinBox.data(), - static_cast( - &QDoubleSpinBox::valueChanged), - this, &BES_AddHole::diameterSpinBoxValueChanged); - mEditorUi.commandToolbar->addWidget(mDiameterSpinBox.data()); + mDiameterEdit.reset(new PositiveLengthEdit()); + mDiameterEdit->setSingleStep(0.1); // [mm] + mDiameterEdit->setValue(mCurrentDiameter); + connect(mDiameterEdit.data(), &PositiveLengthEdit::valueChanged, this, + &BES_AddHole::diameterEditValueChanged); + mEditorUi.commandToolbar->addWidget(mDiameterEdit.data()); // change the cursor mEditorGraphicsView.setCursor(Qt::CrossCursor); @@ -123,7 +119,7 @@ bool BES_AddHole::exit(BEE_Base* event) noexcept { } // Remove actions / widgets from the "command" toolbar - mDiameterSpinBox.reset(); + mDiameterEdit.reset(); mDiameterLabel.reset(); // change the cursor @@ -240,8 +236,9 @@ bool BES_AddHole::fixHole(const Point& pos) noexcept { } } -void BES_AddHole::diameterSpinBoxValueChanged(double value) noexcept { - mCurrentDiameter = Length::fromMm(value); +void BES_AddHole::diameterEditValueChanged( + const PositiveLength& value) noexcept { + mCurrentDiameter = value; if (mEditCmd) { mEditCmd->setDiameter(mCurrentDiameter, true); } diff --git a/libs/librepcb/projecteditor/boardeditor/fsm/bes_addhole.h b/libs/librepcb/projecteditor/boardeditor/fsm/bes_addhole.h index 42b825a98c..ffc57d8471 100644 --- a/libs/librepcb/projecteditor/boardeditor/fsm/bes_addhole.h +++ b/libs/librepcb/projecteditor/boardeditor/fsm/bes_addhole.h @@ -35,6 +35,7 @@ namespace librepcb { class CmdHoleEdit; +class PositiveLengthEdit; namespace project { @@ -69,7 +70,7 @@ class BES_AddHole final : public BES_Base { bool addHole(Board& board, const Point& pos) noexcept; void updateHolePosition(const Point& pos) noexcept; bool fixHole(const Point& pos) noexcept; - void diameterSpinBoxValueChanged(double value) noexcept; + void diameterEditValueChanged(const PositiveLength& value) noexcept; void makeLayerVisible() noexcept; // State @@ -79,8 +80,8 @@ class BES_AddHole final : public BES_Base { PositiveLength mCurrentDiameter; // Widgets for the command toolbar - QScopedPointer mDiameterLabel; - QScopedPointer mDiameterSpinBox; + QScopedPointer mDiameterLabel; + QScopedPointer mDiameterEdit; }; /******************************************************************************* diff --git a/libs/librepcb/projecteditor/boardeditor/fsm/bes_addstroketext.cpp b/libs/librepcb/projecteditor/boardeditor/fsm/bes_addstroketext.cpp index 1a3b406143..98ff5fb0d0 100644 --- a/libs/librepcb/projecteditor/boardeditor/fsm/bes_addstroketext.cpp +++ b/libs/librepcb/projecteditor/boardeditor/fsm/bes_addstroketext.cpp @@ -30,20 +30,13 @@ #include #include #include +#include #include #include #include #include #include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include /******************************************************************************* * Namespace @@ -149,17 +142,12 @@ bool BES_AddStrokeText::entry(BEE_Base* event) noexcept { mEditorUi.commandToolbar->addWidget(mHeightLabel.data()); // add the height spinbox to the toolbar - mHeightSpinBox.reset(new QDoubleSpinBox()); - mHeightSpinBox->setMinimum(0.1); - mHeightSpinBox->setMaximum(100); - mHeightSpinBox->setSingleStep(0.1); - mHeightSpinBox->setDecimals(6); - mHeightSpinBox->setValue(mCurrentHeight->toMm()); - connect(mHeightSpinBox.data(), - static_cast( - &QDoubleSpinBox::valueChanged), - this, &BES_AddStrokeText::heightSpinBoxValueChanged); - mEditorUi.commandToolbar->addWidget(mHeightSpinBox.data()); + mHeightEdit.reset(new PositiveLengthEdit()); + mHeightEdit->setSingleStep(0.5); // [mm] + mHeightEdit->setValue(mCurrentHeight); + connect(mHeightEdit.data(), &PositiveLengthEdit::valueChanged, this, + &BES_AddStrokeText::heightEditValueChanged); + mEditorUi.commandToolbar->addWidget(mHeightEdit.data()); // add the "Mirror:" label to the toolbar mMirrorLabel.reset(new QLabel(tr("Mirror:"))); @@ -195,7 +183,7 @@ bool BES_AddStrokeText::exit(BEE_Base* event) noexcept { // Remove actions / widgets from the "command" toolbar mMirrorCheckBox.reset(); mMirrorLabel.reset(); - mHeightSpinBox.reset(); + mHeightEdit.reset(); mHeightLabel.reset(); mTextComboBox.reset(); mTextLabel.reset(); @@ -373,8 +361,9 @@ void BES_AddStrokeText::textComboBoxValueChanged( } } -void BES_AddStrokeText::heightSpinBoxValueChanged(double value) noexcept { - mCurrentHeight = Length::fromMm(value); +void BES_AddStrokeText::heightEditValueChanged( + const PositiveLength& value) noexcept { + mCurrentHeight = value; if (mEditCmd) { mEditCmd->setHeight(mCurrentHeight, true); } diff --git a/libs/librepcb/projecteditor/boardeditor/fsm/bes_addstroketext.h b/libs/librepcb/projecteditor/boardeditor/fsm/bes_addstroketext.h index e1a5aa8942..24dcda6d9d 100644 --- a/libs/librepcb/projecteditor/boardeditor/fsm/bes_addstroketext.h +++ b/libs/librepcb/projecteditor/boardeditor/fsm/bes_addstroketext.h @@ -36,6 +36,7 @@ namespace librepcb { class GraphicsLayerComboBox; class CmdStrokeTextEdit; +class PositiveLengthEdit; namespace project { @@ -75,7 +76,7 @@ class BES_AddStrokeText final : public BES_Base { bool fixText(const Point& pos) noexcept; void layerComboBoxLayerChanged(const QString& layerName) noexcept; void textComboBoxValueChanged(const QString& value) noexcept; - void heightSpinBoxValueChanged(double value) noexcept; + void heightEditValueChanged(const PositiveLength& value) noexcept; void mirrorCheckBoxToggled(bool checked) noexcept; void makeSelectedLayerVisible() noexcept; @@ -95,7 +96,7 @@ class BES_AddStrokeText final : public BES_Base { QScopedPointer mTextLabel; QScopedPointer mTextComboBox; QScopedPointer mHeightLabel; - QScopedPointer mHeightSpinBox; + QScopedPointer mHeightEdit; QScopedPointer mMirrorLabel; QScopedPointer mMirrorCheckBox; }; diff --git a/libs/librepcb/projecteditor/boardeditor/fsm/bes_addvia.cpp b/libs/librepcb/projecteditor/boardeditor/fsm/bes_addvia.cpp index 83fdf8a0a5..f2397d28d3 100644 --- a/libs/librepcb/projecteditor/boardeditor/fsm/bes_addvia.cpp +++ b/libs/librepcb/projecteditor/boardeditor/fsm/bes_addvia.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -62,9 +63,9 @@ BES_AddVia::BES_AddVia(BoardEditor& editor, Ui::BoardEditor& editorUi, mCurrentViaNetSignal(nullptr), // command toolbar actions / widgets: mSizeLabel(nullptr), - mSizeComboBox(nullptr), + mSizeEdit(nullptr), mDrillLabel(nullptr), - mDrillComboBox(nullptr), + mDrillEdit(nullptr), mNetSignalLabel(nullptr), mNetSignalComboBox(nullptr) { } @@ -131,25 +132,12 @@ bool BES_AddVia::entry(BEE_Base* event) noexcept { mEditorUi.commandToolbar->addWidget(mSizeLabel); // add the size combobox to the toolbar - mSizeComboBox = new QComboBox(); - mSizeComboBox->setMinimumContentsLength(6); - mSizeComboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents); - mSizeComboBox->setInsertPolicy(QComboBox::NoInsert); - mSizeComboBox->setEditable(true); - mSizeComboBox->addItem("0.7"); - mSizeComboBox->addItem("0.8"); - mSizeComboBox->addItem("1"); - mSizeComboBox->addItem("1.2"); - mSizeComboBox->setCurrentIndex( - mSizeComboBox->findText(QString::number(mCurrentViaSize->toMm()))); - mEditorUi.commandToolbar->addWidget(mSizeComboBox); - connect(mSizeComboBox, &QComboBox::currentTextChanged, - [this](const QString& value) { - try { - mCurrentViaSize = Length::fromMm(value); - } catch (...) { - } - }); + mSizeEdit = new PositiveLengthEdit(); + mSizeEdit->setValue(mCurrentViaSize); + mSizeEdit->setSingleStep(0.1); // [mm] + mEditorUi.commandToolbar->addWidget(mSizeEdit); + connect(mSizeEdit, &PositiveLengthEdit::valueChanged, this, + &BES_AddVia::sizeEditValueChanged); // add the "Drill:" label to the toolbar mDrillLabel = new QLabel(tr("Drill:")); @@ -157,25 +145,12 @@ bool BES_AddVia::entry(BEE_Base* event) noexcept { mEditorUi.commandToolbar->addWidget(mDrillLabel); // add the drill combobox to the toolbar - mDrillComboBox = new QComboBox(); - mDrillComboBox->setMinimumContentsLength(6); - mDrillComboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents); - mDrillComboBox->setInsertPolicy(QComboBox::NoInsert); - mDrillComboBox->setEditable(true); - mDrillComboBox->addItem("0.3"); - mDrillComboBox->addItem("0.4"); - mDrillComboBox->addItem("0.6"); - mDrillComboBox->addItem("0.8"); - mDrillComboBox->setCurrentIndex(mDrillComboBox->findText( - QString::number(mCurrentViaDrillDiameter->toMm()))); - mEditorUi.commandToolbar->addWidget(mDrillComboBox); - connect(mDrillComboBox, &QComboBox::currentTextChanged, - [this](const QString& value) { - try { - mCurrentViaDrillDiameter = Length::fromMm(value); - } catch (...) { - } - }); + mDrillEdit = new PositiveLengthEdit(); + mDrillEdit->setValue(mCurrentViaDrillDiameter); + mDrillEdit->setSingleStep(0.1); // [mm] + mEditorUi.commandToolbar->addWidget(mDrillEdit); + connect(mDrillEdit, &PositiveLengthEdit::valueChanged, this, + &BES_AddVia::drillDiameterEditValueChanged); // add the "Signal:" label to the toolbar mNetSignalLabel = new QLabel(tr("Signal:")); @@ -222,12 +197,12 @@ bool BES_AddVia::exit(BEE_Base* event) noexcept { mNetSignalComboBox = nullptr; delete mNetSignalLabel; mNetSignalLabel = nullptr; - delete mDrillComboBox; - mDrillComboBox = nullptr; + delete mDrillEdit; + mDrillEdit = nullptr; delete mDrillLabel; mDrillLabel = nullptr; - delete mSizeComboBox; - mSizeComboBox = nullptr; + delete mSizeEdit; + mSizeEdit = nullptr; delete mSizeLabel; mSizeLabel = nullptr; qDeleteAll(mShapeActions); @@ -349,8 +324,6 @@ bool BES_AddVia::updateVia(Board& board, const Point& pos) noexcept { try { mViaEditCmd->setPosition(pos, true); mViaEditCmd->setShape(mCurrentViaShape, true); - mViaEditCmd->setSize(mCurrentViaSize, true); - mViaEditCmd->setDrillDiameter(mCurrentViaDrillDiameter, true); board.triggerAirWiresRebuild(); return true; } catch (Exception& e) { @@ -390,6 +363,21 @@ void BES_AddVia::updateShapeActionsCheckedState() noexcept { } } +void BES_AddVia::sizeEditValueChanged(const PositiveLength& value) noexcept { + mCurrentViaSize = value; + if (mViaEditCmd) { + mViaEditCmd->setSize(mCurrentViaSize, true); + } +} + +void BES_AddVia::drillDiameterEditValueChanged( + const PositiveLength& value) noexcept { + mCurrentViaDrillDiameter = value; + if (mViaEditCmd) { + mViaEditCmd->setDrillDiameter(mCurrentViaDrillDiameter, true); + } +} + void BES_AddVia::setNetSignal(NetSignal* netsignal) noexcept { try { if (!netsignal) throw LogicError(__FILE__, __LINE__); diff --git a/libs/librepcb/projecteditor/boardeditor/fsm/bes_addvia.h b/libs/librepcb/projecteditor/boardeditor/fsm/bes_addvia.h index 321f0b0dc5..566b2eae44 100644 --- a/libs/librepcb/projecteditor/boardeditor/fsm/bes_addvia.h +++ b/libs/librepcb/projecteditor/boardeditor/fsm/bes_addvia.h @@ -33,6 +33,9 @@ * Namespace / Forward Declarations ******************************************************************************/ namespace librepcb { + +class PositiveLengthEdit; + namespace project { class Board; @@ -69,7 +72,9 @@ class BES_AddVia final : public BES_Base { bool updateVia(Board& board, const Point& pos) noexcept; bool fixVia(const Point& pos) noexcept; void updateShapeActionsCheckedState() noexcept; - void setNetSignal(NetSignal* netsignal) noexcept; + void sizeEditValueChanged(const PositiveLength& value) noexcept; + void drillDiameterEditValueChanged(const PositiveLength& value) noexcept; + void setNetSignal(NetSignal* netsignal) noexcept; // General Attributes bool mUndoCmdActive; @@ -84,9 +89,9 @@ class BES_AddVia final : public BES_Base { QHash mShapeActions; QList mActionSeparators; QLabel* mSizeLabel; - QComboBox* mSizeComboBox; + PositiveLengthEdit* mSizeEdit; QLabel* mDrillLabel; - QComboBox* mDrillComboBox; + PositiveLengthEdit* mDrillEdit; QLabel* mNetSignalLabel; QComboBox* mNetSignalComboBox; }; diff --git a/libs/librepcb/projecteditor/boardeditor/fsm/bes_drawpolygon.cpp b/libs/librepcb/projecteditor/boardeditor/fsm/bes_drawpolygon.cpp index 5c7f06ab6d..2d65d91a22 100644 --- a/libs/librepcb/projecteditor/boardeditor/fsm/bes_drawpolygon.cpp +++ b/libs/librepcb/projecteditor/boardeditor/fsm/bes_drawpolygon.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -61,7 +62,7 @@ BES_DrawPolygon::BES_DrawPolygon(BoardEditor& editor, Ui::BoardEditor& editorUi, mLayerLabel(nullptr), mLayerComboBox(nullptr), mWidthLabel(nullptr), - mWidthComboBox(nullptr), + mWidthEdit(nullptr), mFillLabel(nullptr), mFillCheckBox(nullptr) { } @@ -115,25 +116,12 @@ bool BES_DrawPolygon::entry(BEE_Base* event) noexcept { mEditorUi.commandToolbar->addWidget(mWidthLabel); // add the widths combobox to the toolbar - mWidthComboBox = new QComboBox(); - mWidthComboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents); - mWidthComboBox->setInsertPolicy(QComboBox::NoInsert); - mWidthComboBox->setEditable(true); - mWidthComboBox->addItem("0"); - mWidthComboBox->addItem("0.2"); - mWidthComboBox->addItem("0.3"); - mWidthComboBox->addItem("0.5"); - mWidthComboBox->addItem("0.8"); - mWidthComboBox->addItem("1"); - mWidthComboBox->addItem("1.5"); - mWidthComboBox->addItem("2"); - mWidthComboBox->addItem("2.5"); - mWidthComboBox->addItem("3"); - mWidthComboBox->setCurrentIndex( - mWidthComboBox->findText(QString::number(mCurrentWidth->toMm()))); - mEditorUi.commandToolbar->addWidget(mWidthComboBox); - connect(mWidthComboBox, &QComboBox::currentTextChanged, this, - &BES_DrawPolygon::widthComboBoxTextChanged); + mWidthEdit = new UnsignedLengthEdit(); + mWidthEdit->setValue(mCurrentWidth); + mWidthEdit->setSingleStep(0.1); // [mm] + mEditorUi.commandToolbar->addWidget(mWidthEdit); + connect(mWidthEdit, &UnsignedLengthEdit::valueChanged, this, + &BES_DrawPolygon::widthEditValueChanged); // add the "Filled:" label to the toolbar mFillLabel = new QLabel(tr("Filled:")); @@ -164,8 +152,8 @@ bool BES_DrawPolygon::exit(BEE_Base* event) noexcept { mFillCheckBox = nullptr; delete mFillLabel; mFillLabel = nullptr; - delete mWidthComboBox; - mWidthComboBox = nullptr; + delete mWidthEdit; + mWidthEdit = nullptr; delete mWidthLabel; mWidthLabel = nullptr; delete mLayerComboBox; @@ -379,12 +367,9 @@ void BES_DrawPolygon::layerComboBoxLayerChanged( } } -void BES_DrawPolygon::widthComboBoxTextChanged(const QString& width) noexcept { - try { - mCurrentWidth = Length::fromMm(width); - } catch (...) { - return; - } +void BES_DrawPolygon::widthEditValueChanged( + const UnsignedLength& value) noexcept { + mCurrentWidth = value; if (mCmdEditCurrentPolygon) { mCmdEditCurrentPolygon->setLineWidth(mCurrentWidth, true); } diff --git a/libs/librepcb/projecteditor/boardeditor/fsm/bes_drawpolygon.h b/libs/librepcb/projecteditor/boardeditor/fsm/bes_drawpolygon.h index e515389947..9dfc5274aa 100644 --- a/libs/librepcb/projecteditor/boardeditor/fsm/bes_drawpolygon.h +++ b/libs/librepcb/projecteditor/boardeditor/fsm/bes_drawpolygon.h @@ -37,6 +37,7 @@ namespace librepcb { class CmdPolygonEdit; class GraphicsLayerComboBox; +class UnsignedLengthEdit; namespace project { @@ -76,7 +77,7 @@ class BES_DrawPolygon final : public BES_Base { bool abort(bool showErrMsgBox) noexcept; void updateSegmentPosition(const Point& cursorPos) noexcept; void layerComboBoxLayerChanged(const QString& layerName) noexcept; - void widthComboBoxTextChanged(const QString& width) noexcept; + void widthEditValueChanged(const UnsignedLength& value) noexcept; void filledCheckBoxCheckedChanged(bool checked) noexcept; void makeSelectedLayerVisible() noexcept; @@ -102,7 +103,7 @@ class BES_DrawPolygon final : public BES_Base { QLabel* mLayerLabel; GraphicsLayerComboBox* mLayerComboBox; QLabel* mWidthLabel; - QComboBox* mWidthComboBox; + UnsignedLengthEdit* mWidthEdit; QLabel* mFillLabel; QCheckBox* mFillCheckBox; }; diff --git a/libs/librepcb/projecteditor/boardeditor/fsm/bes_drawtrace.cpp b/libs/librepcb/projecteditor/boardeditor/fsm/bes_drawtrace.cpp index 1a6f8b61f4..03de44c227 100644 --- a/libs/librepcb/projecteditor/boardeditor/fsm/bes_drawtrace.cpp +++ b/libs/librepcb/projecteditor/boardeditor/fsm/bes_drawtrace.cpp @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -69,7 +70,7 @@ BES_DrawTrace::BES_DrawTrace(BoardEditor& editor, Ui::BoardEditor& editorUi, mLayerLabel(nullptr), mLayerComboBox(nullptr), mWidthLabel(nullptr), - mWidthComboBox(nullptr) { + mWidthEdit(nullptr) { } BES_DrawTrace::~BES_DrawTrace() { @@ -158,24 +159,12 @@ bool BES_DrawTrace::entry(BEE_Base* event) noexcept { mEditorUi.commandToolbar->addWidget(mWidthLabel); // add the widths combobox to the toolbar - mWidthComboBox = new QComboBox(); - mWidthComboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents); - mWidthComboBox->setInsertPolicy(QComboBox::NoInsert); - mWidthComboBox->setEditable(true); - mWidthComboBox->addItem("0.2"); - mWidthComboBox->addItem("0.3"); - mWidthComboBox->addItem("0.5"); - mWidthComboBox->addItem("0.8"); - mWidthComboBox->addItem("1"); - mWidthComboBox->addItem("1.5"); - mWidthComboBox->addItem("2"); - mWidthComboBox->addItem("2.5"); - mWidthComboBox->addItem("3"); - mWidthComboBox->setCurrentIndex( - mWidthComboBox->findText(QString::number(mCurrentWidth->toMm()))); - mEditorUi.commandToolbar->addWidget(mWidthComboBox); - connect(mWidthComboBox, &QComboBox::currentTextChanged, this, - &BES_DrawTrace::wireWidthComboBoxTextChanged); + mWidthEdit = new PositiveLengthEdit(); + mWidthEdit->setValue(mCurrentWidth); + mWidthEdit->setSingleStep(0.1); // [mm] + mEditorUi.commandToolbar->addWidget(mWidthEdit); + connect(mWidthEdit, &PositiveLengthEdit::valueChanged, this, + &BES_DrawTrace::wireWidthEditValueChanged); // change the cursor mEditorGraphicsView.setCursor(Qt::CrossCursor); @@ -190,8 +179,8 @@ bool BES_DrawTrace::exit(BEE_Base* event) noexcept { if (mSubState != SubState_Idle) abortPositioning(true); // Remove actions / widgets from the "command" toolbar - delete mWidthComboBox; - mWidthComboBox = nullptr; + delete mWidthEdit; + mWidthEdit = nullptr; delete mWidthLabel; mWidthLabel = nullptr; delete mLayerComboBox; @@ -426,7 +415,7 @@ bool BES_DrawTrace::startPositioning(Board& board, const Point& pos, // update line width if (mFixedStartAnchor->getMaxLineWidth() > 0) { mCurrentWidth = PositiveLength(*mFixedStartAnchor->getMedianLineWidth()); - mWidthComboBox->setCurrentText(QString::number(mCurrentWidth->toMm())); + mWidthEdit->setValue(mCurrentWidth); } // add more netpoints & netlines @@ -665,13 +654,9 @@ void BES_DrawTrace::layerComboBoxIndexChanged(int index) noexcept { // TODO: add a via to change the layer of the current netline? } -void BES_DrawTrace::wireWidthComboBoxTextChanged( - const QString& width) noexcept { - try { - mCurrentWidth = Length::fromMm(width); - } catch (...) { - return; - } +void BES_DrawTrace::wireWidthEditValueChanged( + const PositiveLength& value) noexcept { + mCurrentWidth = value; if (mSubState != SubState::SubState_PositioningNetPoint) return; if (mPositioningNetLine1) mPositioningNetLine1->setWidth(mCurrentWidth); if (mPositioningNetLine2) mPositioningNetLine2->setWidth(mCurrentWidth); diff --git a/libs/librepcb/projecteditor/boardeditor/fsm/bes_drawtrace.h b/libs/librepcb/projecteditor/boardeditor/fsm/bes_drawtrace.h index 15ba4eccb7..5b73c57f3a 100644 --- a/libs/librepcb/projecteditor/boardeditor/fsm/bes_drawtrace.h +++ b/libs/librepcb/projecteditor/boardeditor/fsm/bes_drawtrace.h @@ -34,6 +34,7 @@ namespace librepcb { class GraphicsLayer; +class PositiveLengthEdit; namespace project { @@ -116,7 +117,7 @@ class BES_DrawTrace final : public BES_Base { const QSet& except = {}) const noexcept; void updateNetpointPositions(const Point& cursorPos) noexcept; void layerComboBoxIndexChanged(int index) noexcept; - void wireWidthComboBoxTextChanged(const QString& width) noexcept; + void wireWidthEditValueChanged(const PositiveLength& value) noexcept; void updateWireModeActionsCheckedState() noexcept; Point calcMiddlePointPos(const Point& p1, const Point p2, WireMode mode) const noexcept; @@ -139,7 +140,7 @@ class BES_DrawTrace final : public BES_Base { QLabel* mLayerLabel; QComboBox* mLayerComboBox; QLabel* mWidthLabel; - QComboBox* mWidthComboBox; + PositiveLengthEdit* mWidthEdit; }; /******************************************************************************* diff --git a/libs/librepcb/projecteditor/schematiceditor/symbolinstancepropertiesdialog.cpp b/libs/librepcb/projecteditor/schematiceditor/symbolinstancepropertiesdialog.cpp index 99962c38a9..44e973c25e 100644 --- a/libs/librepcb/projecteditor/schematiceditor/symbolinstancepropertiesdialog.cpp +++ b/libs/librepcb/projecteditor/schematiceditor/symbolinstancepropertiesdialog.cpp @@ -62,6 +62,7 @@ SymbolInstancePropertiesDialog::SymbolInstancePropertiesDialog( mAttributes(mComponentInstance.getAttributes()), mUi(new Ui::SymbolInstancePropertiesDialog) { mUi->setupUi(this); + mUi->edtSymbInstRotation->setSingleStep(90.0); // [°] setWindowTitle(QString(tr("Properties of %1")).arg(mSymbol.getName())); // Component Instance Attributes @@ -96,9 +97,9 @@ SymbolInstancePropertiesDialog::SymbolInstancePropertiesDialog( // Symbol Instance Attributes mUi->lblSymbInstName->setText(mSymbol.getName()); - mUi->spbxSymbInstPosX->setValue(mSymbol.getPosition().getX().toMm()); - mUi->spbxSymbInstPosY->setValue(mSymbol.getPosition().getY().toMm()); - mUi->spbxSymbInstAngle->setValue(mSymbol.getRotation().toDeg()); + mUi->edtSymbInstPosX->setValue(mSymbol.getPosition().getX()); + mUi->edtSymbInstPosY->setValue(mSymbol.getPosition().getY()); + mUi->edtSymbInstRotation->setValue(mSymbol.getRotation()); mUi->cbxMirror->setChecked(mSymbol.getMirrored()); // Symbol Library Element Attributes @@ -159,14 +160,13 @@ bool SymbolInstancePropertiesDialog::applyChanges() noexcept { transaction.append(cmdCmp.take()); // Symbol Instance - Point pos(Length::fromMm(mUi->spbxSymbInstPosX->value()), - Length::fromMm(mUi->spbxSymbInstPosY->value())); - Angle rotation = Angle::fromDeg(mUi->spbxSymbInstAngle->value()); - bool mirrored = mUi->cbxMirror->isChecked(); + bool mirrored = mUi->cbxMirror->isChecked(); QScopedPointer cmdSym( new CmdSymbolInstanceEdit(mSymbol)); - cmdSym->setPosition(pos, false); - cmdSym->setRotation(rotation, false); + cmdSym->setPosition(Point(mUi->edtSymbInstPosX->getValue(), + mUi->edtSymbInstPosY->getValue()), + false); + cmdSym->setRotation(mUi->edtSymbInstRotation->getValue(), false); cmdSym->setMirrored(mirrored, false); transaction.append(cmdSym.take()); diff --git a/libs/librepcb/projecteditor/schematiceditor/symbolinstancepropertiesdialog.ui b/libs/librepcb/projecteditor/schematiceditor/symbolinstancepropertiesdialog.ui index 0a71e42f5d..8769e36668 100644 --- a/libs/librepcb/projecteditor/schematiceditor/symbolinstancepropertiesdialog.ui +++ b/libs/librepcb/projecteditor/schematiceditor/symbolinstancepropertiesdialog.ui @@ -58,40 +58,6 @@ - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - QAbstractSpinBox::UpDownArrows - - - mm - - - 6 - - - -2000.000000000000000 - - - 2000.000000000000000 - - - 2.540000000000000 - - - @@ -99,37 +65,6 @@ - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - mm - - - 6 - - - -2000.000000000000000 - - - 2000.000000000000000 - - - 2.540000000000000 - - - @@ -137,37 +72,6 @@ - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - ° - - - 6 - - - -360.000000000000000 - - - 360.000000000000000 - - - 45.000000000000000 - - - @@ -182,6 +86,15 @@ + + + + + + + + + @@ -383,6 +296,18 @@ + + librepcb::LengthEdit + QWidget +
librepcb/common/widgets/lengthedit.h
+ 1 +
+ + librepcb::AngleEdit + QWidget +
librepcb/common/widgets/angleedit.h
+ 1 +
librepcb::AttributeListEditorWidget QWidget