From 0995e1d5ec377a111ceedd5befea86694709c783 Mon Sep 17 00:00:00 2001 From: xtemp09 Date: Mon, 2 Sep 2024 15:30:03 +0700 Subject: [PATCH] [GUI] Enable sort of zoom in Light Sources dialog --- .../DlgSettingsLightSources.cpp | 63 ++- .../PreferencePages/DlgSettingsLightSources.h | 7 + .../DlgSettingsLightSources.ui | 442 +++++++++++------- 3 files changed, 345 insertions(+), 167 deletions(-) diff --git a/src/Gui/PreferencePages/DlgSettingsLightSources.cpp b/src/Gui/PreferencePages/DlgSettingsLightSources.cpp index 23231b506c..563d203b1e 100644 --- a/src/Gui/PreferencePages/DlgSettingsLightSources.cpp +++ b/src/Gui/PreferencePages/DlgSettingsLightSources.cpp @@ -31,6 +31,8 @@ #include #include #include +#include +#include #endif #include "DlgSettingsLightSources.h" @@ -52,12 +54,6 @@ DlgSettingsLightSources::DlgSettingsLightSources(QWidget* parent) view = ui->viewer; createViewer(); - - QSizePolicy sp {QSizePolicy::Expanding, QSizePolicy::Expanding}; - sp.setHeightForWidth(true); - sp.setHorizontalStretch(1); - sp.setVerticalStretch(1); - view->setSizePolicy(sp); } static inline @@ -111,9 +107,37 @@ void DlgSettingsLightSources::dragMotionCallback(void *data, SoDragger *drag) setValueSilently(self->ui->z_spnBox, dir[2]); } +static inline +SoMaterial *createMaterial(void) +{ + const QColor ambientColor {0xff333333}, + diffuseColor {0xffd2d2ff}, + emissiveColor {0xff000000}, + specularColor {0xffcccccc}; + + auto material = new SoMaterial (); + material->ambientColor.setValue (ambientColor.redF(), ambientColor.greenF(), ambientColor.blueF()); + material->diffuseColor.setValue (diffuseColor.redF(), diffuseColor.greenF(), diffuseColor.blueF()); + material->emissiveColor.setValue(emissiveColor.redF(), emissiveColor.greenF(), emissiveColor.blueF()); + material->specularColor.setValue(specularColor.redF(), specularColor.greenF(), specularColor.blueF()); + + material->shininess = 0.9f; + + return material; +} + +static inline +SoSphere *createSphere(void) +{ + auto sphere = new SoSphere(); + sphere->radius = 2; + + return sphere; +} + void DlgSettingsLightSources::createViewer() { - const QColor default_bg_color {200, 200, 200}; + const QColor default_bg_color {180, 180, 180}; const SbVec3f default_view_direction {1.0f, 1.0f, -5.0f}; // NOLINTBEGIN @@ -127,6 +151,8 @@ void DlgSettingsLightSources::createViewer() auto root = static_cast(view->getSceneGraph()); root->addChild(createDragger()); + root->addChild(createMaterial()); + root->addChild(createSphere()); auto callback = new SoEventCallback(); root->addChild(callback); @@ -139,8 +165,11 @@ void DlgSettingsLightSources::createViewer() view->setCameraType(SoOrthographicCamera::getClassTypeId()); view->setViewDirection(default_view_direction); view->viewAll(); - auto cam = dynamic_cast (view->getCamera()); - cam->height = cam->height.getValue() * 2.0f; + + camera = dynamic_cast (view->getCamera()); + const float camera_height = camera->height.getValue() * 2.0f; + camera->height = camera_height; + cam_step = camera_height / 14.0f; // NOLINTEND } @@ -270,6 +299,22 @@ void DlgSettingsLightSources::lightColor() } } +void DlgSettingsLightSources::pushIn(void) +{ + if (camera == nullptr) + return; + + camera->height = camera->height.getValue() - cam_step; +} + +void DlgSettingsLightSources::pullOut(void) +{ + if (camera == nullptr) + return; + + camera->height = camera->height.getValue() + cam_step; +} + void DlgSettingsLightSources::changeEvent(QEvent* event) { if (event->type() == QEvent::LanguageChange) { diff --git a/src/Gui/PreferencePages/DlgSettingsLightSources.h b/src/Gui/PreferencePages/DlgSettingsLightSources.h index e3d36901cc..60145bf42b 100644 --- a/src/Gui/PreferencePages/DlgSettingsLightSources.h +++ b/src/Gui/PreferencePages/DlgSettingsLightSources.h @@ -31,6 +31,7 @@ class SoDragger; class SoDirectionalLightDragger; +class SoOrthographicCamera; namespace Gui { class View3DInventorViewer; @@ -61,6 +62,9 @@ public Q_SLOTS: void lightIntensity(int value); void lightColor(); + void pushIn (void); + void pullOut(void); + protected: void changeEvent(QEvent* event) override; @@ -75,6 +79,9 @@ private: std::unique_ptr ui; QPointer view; SoDirectionalLightDragger* lightDragger = nullptr; + SoOrthographicCamera *camera = nullptr; + + float cam_step = 3.0f; }; } // namespace Dialog diff --git a/src/Gui/PreferencePages/DlgSettingsLightSources.ui b/src/Gui/PreferencePages/DlgSettingsLightSources.ui index fbd1b5e40f..484387eb9e 100644 --- a/src/Gui/PreferencePages/DlgSettingsLightSources.ui +++ b/src/Gui/PreferencePages/DlgSettingsLightSources.ui @@ -14,18 +14,245 @@ Light Sources - - - - Qt::Vertical + + + + + 0 + 2 + - - - 428 - 376 - + + Adjust the orientation of the directional light source by dragging the handle with the mouse or use the spin boxes for fine tuning. - + + Direction + + + + + + -100.000000000000000 + + + 0.100000000000000 + + + + + + + -100.000000000000000 + + + 0.100000000000000 + + + + + + + <html><head/><body><p>z</p></body></html> + + + + + + + x + + + + + + + 2 + + + -100.000000000000000 + + + 0.100000000000000 + + + + + + + 2 + + + -100.000000000000000 + + + 0.100000000000000 + + + + + + + 2 + + + -100.000000000000000 + + + 0.100000000000000 + + + + + + + y + + + + + + + q2 + + + + + + + q0 + + + + + + + 2 + + + -100.000000000000000 + + + 0.100000000000000 + + + + + + + q1 + + + + + + + q3 + + + + + + + -100.000000000000000 + + + 0.100000000000000 + + + + + + + + 0 + 0 + + + + Qt::NoFocus + + + + 2 + + + 2 + + + + + Qt::Horizontal + + + + 0 + 0 + + + + + + + + + + Qt::Vertical + + + + 0 + 0 + + + + + + + + Qt::NoFocus + + + Push In + + + + :/icons/FreeCAD-default/scalable/zoom-in.svg:/icons/FreeCAD-default/scalable/zoom-in.svg + + + + 32 + 32 + + + + + + + + Qt::NoFocus + + + Pull Out + + + + :/icons/FreeCAD-default/scalable/zoom-out.svg:/icons/FreeCAD-default/scalable/zoom-out.svg + + + + 32 + 32 + + + + + + + + + + + @@ -114,155 +341,18 @@ - - - - Adjust the orientation of the directional light source by dragging the handle with the mouse or use the spin boxes for fine tuning. + + + + Qt::Vertical - - Direction + + + 20 + 40 + - - - - - Qt::NoFocus - - - - - - - -100.000000000000000 - - - 0.100000000000000 - - - - - - - 2 - - - -100.000000000000000 - - - 0.100000000000000 - - - - - - - q1 - - - - - - - 2 - - - -100.000000000000000 - - - 0.100000000000000 - - - - - - - <html><head/><body><p>z</p></body></html> - - - - - - - q2 - - - - - - - q3 - - - - - - - -100.000000000000000 - - - 0.100000000000000 - - - - - - - y - - - - - - - 2 - - - -100.000000000000000 - - - 0.100000000000000 - - - - - - - 2 - - - -100.000000000000000 - - - 0.100000000000000 - - - - - - - -100.000000000000000 - - - 0.100000000000000 - - - - - - - q0 - - - - - - - x - - - - - + @@ -305,7 +395,9 @@ q2_spnBox q3_spnBox - + + + checkBoxLight1 @@ -515,9 +607,43 @@ + + pushInTB + clicked() + Gui::Dialog::DlgSettingsLightSources + pushIn(void) + + + 126 + 224 + + + 241 + 257 + + + + + pullOutTB + clicked() + Gui::Dialog::DlgSettingsLightSources + pullOut(void) + + + 126 + 255 + + + 241 + 257 + + + updateDraggerQS(void) updateDraggerXYZ(void) + pushIn(void) + pullOut(void)