diff --git a/src/Gui/TaskView/TaskImage.cpp b/src/Gui/TaskView/TaskImage.cpp index b56e59de1f..ef84205011 100644 --- a/src/Gui/TaskView/TaskImage.cpp +++ b/src/Gui/TaskView/TaskImage.cpp @@ -70,8 +70,7 @@ TaskImage::TaskImage(Image::ImagePlane* obj, QWidget* parent) , aspectRatio(1.0) { ui->setupUi(this); - ui->pushButtonApply->hide(); - ui->pushButtonCancel->hide(); + ui->groupBoxCalibration->hide(); initialiseTransparency(); @@ -214,8 +213,8 @@ void TaskImage::startScale() { scale->activate(qAsConst(ui->pushButtonScale)->actions()[0]->isChecked()); ui->pushButtonScale->hide(); - ui->pushButtonApply->show(); - ui->pushButtonCancel->show(); + ui->groupBoxCalibration->show(); + ui->pushButtonApply->setEnabled(false); } void TaskImage::acceptScale() @@ -224,12 +223,16 @@ void TaskImage::acceptScale() rejectScale(); } +void TaskImage::enableApplyBtn() +{ + ui->pushButtonApply->setEnabled(true); +} + void TaskImage::rejectScale() { scale->deactivate(); ui->pushButtonScale->show(); - ui->pushButtonApply->hide(); - ui->pushButtonCancel->hide(); + ui->groupBoxCalibration->hide(); } void TaskImage::onInteractiveScale() @@ -244,6 +247,8 @@ void TaskImage::onInteractiveScale() this, &TaskImage::acceptScale); connect(scale, &InteractiveScale::scaleCanceled, this, &TaskImage::rejectScale); + connect(scale, &InteractiveScale::enableApplyBtn, + this, &TaskImage::enableApplyBtn); } } @@ -432,8 +437,6 @@ InteractiveScale::InteractiveScale(View3DInventorViewer* view, ViewProvider* vp, distanceBox->setKeyboardTracking(false); distanceBox->installEventFilter(this); - this->installEventFilter(this); - //track camera movements to update spinbox position. NodeData* info = new NodeData{ this }; cameraSensor = new SoNodeSensor([](void* data, SoSensor* sensor) { @@ -457,7 +460,7 @@ void InteractiveScale::activate(bool allowOutside) static_cast(viewer->getSceneGraph())->addChild(root); viewer->setEditing(true); viewer->addEventCallback(SoLocation2Event::getClassTypeId(), InteractiveScale::getMousePosition, this); - viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), InteractiveScale::getMouseClick, this); + viewer->addEventCallback(SoButtonEvent::getClassTypeId(), InteractiveScale::soEventFilter, this); viewer->setSelectionEnabled(false); viewer->getWidget()->setCursor(QCursor(Qt::CrossCursor)); active = true; @@ -474,7 +477,7 @@ void InteractiveScale::deactivate() static_cast(viewer->getSceneGraph())->removeChild(root); viewer->setEditing(false); viewer->removeEventCallback(SoLocation2Event::getClassTypeId(), InteractiveScale::getMousePosition, this); - viewer->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), InteractiveScale::getMouseClick, this); + viewer->removeEventCallback(SoButtonEvent::getClassTypeId(), InteractiveScale::soEventFilter, this); viewer->setSelectionEnabled(true); viewer->getWidget()->setCursor(QCursor(Qt::ArrowCursor)); active = false; @@ -545,13 +548,15 @@ void InteractiveScale::collectPoint(const SbVec3f& pos3d) midPoint = points[0] + (points[1] - points[0]) / 2; measureLabel->string = ""; - positionWidget(); distanceBox->show(); - distanceBox->adjustSize(); QSignalBlocker block(distanceBox); distanceBox->setValue((points[1] - points[0]).length()); + distanceBox->adjustSize(); + positionWidget(); distanceBox->selectNumber(); distanceBox->setFocus(); + + Q_EMIT enableApplyBtn(); } else { Base::Console().Warning(std::string("Image scale"), "The second point is too close. Retry!\n"); @@ -568,17 +573,6 @@ void InteractiveScale::positionWidget() distanceBox->move(pxCoord); } -void InteractiveScale::getMouseClick(void * ud, SoEventCallback * ecb) -{ - InteractiveScale* scale = static_cast(ud); - const SoMouseButtonEvent * mbe = static_cast(ecb->getEvent()); - - if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 && mbe->getState() == SoButtonEvent::DOWN) { - ecb->setHandled(); - scale->findPointOnPlane(ecb); - } -} - void InteractiveScale::getMousePosition(void * ud, SoEventCallback * ecb) { InteractiveScale* scale = static_cast(ud); @@ -621,9 +615,40 @@ void InteractiveScale::getMousePosition(void * ud, SoEventCallback * ecb) } } +void InteractiveScale::soEventFilter(void* ud, SoEventCallback* ecb) +{ + InteractiveScale* scale = static_cast(ud); + + const SoEvent* soEvent = ecb->getEvent(); + if (soEvent->isOfType(SoKeyboardEvent::getClassTypeId())) { + /* If user press escape, then we cancel the tool.*/ + const auto kbe = static_cast(soEvent); + + if (kbe->getKey() == SoKeyboardEvent::ESCAPE && kbe->getState() == SoButtonEvent::UP) { + ecb->setHandled(); + ecb->getAction()->setHandled(); + Q_EMIT scale->scaleCanceled(); + } + } + else if (soEvent->isOfType(SoMouseButtonEvent::getClassTypeId())) { + const auto mbe = static_cast(soEvent); + + if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 && mbe->getState() == SoButtonEvent::DOWN) + { + ecb->setHandled(); + scale->findPointOnPlane(ecb); + } + if (mbe->getButton() == SoMouseButtonEvent::BUTTON2 && mbe->getState() == SoButtonEvent::DOWN) + { + ecb->setHandled(); + Q_EMIT scale->scaleCanceled(); + } + } +} + bool InteractiveScale::eventFilter(QObject* object, QEvent* event) { - if (event->type() == QEvent::KeyRelease) { + if (event->type() == QEvent::KeyPress) { QKeyEvent* keyEvent = static_cast(event); /* If user press enter in the spinbox, then we validate the tool.*/ @@ -631,12 +656,11 @@ bool InteractiveScale::eventFilter(QObject* object, QEvent* event) Q_EMIT scaleRequired(); } - /* If user press escape, then we cancel the tool.*/ + /* If user press escape, then we cancel the tool. Required here as well for when checkbox has focus.*/ if (keyEvent->key() == Qt::Key_Escape) { Q_EMIT scaleCanceled(); } } - return false; } @@ -674,7 +698,7 @@ TaskImageDialog::TaskImageDialog(Image::ImagePlane* obj) { widget = new TaskImage(obj); Gui::TaskView::TaskBox* taskbox = new Gui::TaskView::TaskBox( - QPixmap(), widget->windowTitle(), true, nullptr); + Gui::BitmapFactory().pixmap("image-plane"), widget->windowTitle(), true, nullptr); taskbox->groupLayout()->addWidget(widget); Content.push_back(taskbox); } diff --git a/src/Gui/TaskView/TaskImage.h b/src/Gui/TaskView/TaskImage.h index aef78d8c8b..41ffc97b05 100644 --- a/src/Gui/TaskView/TaskImage.h +++ b/src/Gui/TaskView/TaskImage.h @@ -62,7 +62,7 @@ public: void setPlacement(Base::Placement plc); private: - static void getMouseClick(void * ud, SoEventCallback * ecb); + static void soEventFilter(void * ud, SoEventCallback * ecb); static void getMousePosition(void * ud, SoEventCallback * ecb); void findPointOnPlane(SoEventCallback * ecb); void findPointOnImagePlane(SoEventCallback * ecb); @@ -76,6 +76,7 @@ private: Q_SIGNALS: void scaleRequired(); void scaleCanceled(); + void enableApplyBtn(); private: bool active; @@ -115,6 +116,7 @@ private: void startScale(); void acceptScale(); void rejectScale(); + void enableApplyBtn(); void restore(const Base::Placement&); void onPreview(); diff --git a/src/Gui/TaskView/TaskImage.ui b/src/Gui/TaskView/TaskImage.ui index 96eedc9eab..346b2f6520 100644 --- a/src/Gui/TaskView/TaskImage.ui +++ b/src/Gui/TaskView/TaskImage.ui @@ -192,50 +192,46 @@ - - - - - Width: - - - - - - - mm - - - 0.00000001 - - - 999999999.000000000000000 - - - - - - - Height: - - - - - - - mm - - - 0.00000001 - - - 999999999.000000000000000 - - - - + + + Width: + + + + + + + mm + + + 0.00000001 + + + 999999999.000000000000000 + + + + + Height: + + + + + + + mm + + + 0.00000001 + + + 999999999.000000000000000 + + + + Keep aspect ratio @@ -245,49 +241,41 @@ - - - - - - Interactively scale the image by setting a length between two points of the image. - - - Calibrate - - - QToolButton::MenuButtonPopup - - - - - - - Apply - - - - - - - Cancel - - - - - - - Qt::Horizontal - - - - 136 - 20 - - - - - + + + + Interactively scale the image by setting a length between two points of the image. + + + Calibrate + + + QToolButton::MenuButtonPopup + + + + + + + Calibration + + + + + + Apply + + + + + + + Cancel + + + + +