diff --git a/VirtualReality/Widgets/Resources/UI/qMRMLVirtualRealityHomeWidget.ui b/VirtualReality/Widgets/Resources/UI/qMRMLVirtualRealityHomeWidget.ui index c324360..8cd2672 100644 --- a/VirtualReality/Widgets/Resources/UI/qMRMLVirtualRealityHomeWidget.ui +++ b/VirtualReality/Widgets/Resources/UI/qMRMLVirtualRealityHomeWidget.ui @@ -6,134 +6,184 @@ 0 0 - 512 - 233 + 532 + 262 VR Home - - - - - - - 0.1x - - - - - - - 10x - - - - - - - 100x - - - - - - - 1x - - - - - - - 0.01x - - - - - - - Lock magnification - - - - - - - - - Sync view to reference view - - - - - - - 1 - - - 0.500000000000000 - - - 2.000000000000000 - - - 0.100000000000000 - - - 10.000000000000000 - - - 1.660000000000000 - - - m/s - - - - - + + + - Magnification: + Back - - - - Motion sensitivity: - + + + + QFrame::NoFrame + + + QFrame::Raised + + + + + + Sync view to reference view + + + + + + + Fly speed: + + + Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft + + + + + + + 1 + + + 0.500000000000000 + + + 2.000000000000000 + + + 0.100000000000000 + + + 10.000000000000000 + + + 1.660000000000000 + + + m/s + + + + + + + Magnification: + + + Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft + + + + + + + + + 10x + + + + + + + Lock magnification + + + + + + + 0.01x + + + + + + + 1x + + + + + + + 0.1x + + + + + + + 100x + + + + + + + + + + 0 + 13 + + + + Motion sensitivity: + + + Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft + + + + + + + 0 + + + 100.000000000000000 + + + 50.000000000000000 + + + % + + + + - - - - 0 - - - 100.000000000000000 + + + + QFrame::NoFrame - - 50.000000000000000 - - - % - - - - - - - Fly speed: + + QFrame::Raised + - + Modules + + + + + diff --git a/VirtualReality/Widgets/qMRMLVirtualRealityHomeWidget.cxx b/VirtualReality/Widgets/qMRMLVirtualRealityHomeWidget.cxx index b313a70..e35b25c 100644 --- a/VirtualReality/Widgets/qMRMLVirtualRealityHomeWidget.cxx +++ b/VirtualReality/Widgets/qMRMLVirtualRealityHomeWidget.cxx @@ -32,6 +32,7 @@ // Qt includes #include +#include //----------------------------------------------------------------------------- class qMRMLVirtualRealityHomeWidgetPrivate : public Ui_qMRMLVirtualRealityHomeWidget @@ -40,11 +41,15 @@ class qMRMLVirtualRealityHomeWidgetPrivate : public Ui_qMRMLVirtualRealityHomeWi protected: qMRMLVirtualRealityHomeWidget* const q_ptr; + public: qMRMLVirtualRealityHomeWidgetPrivate(qMRMLVirtualRealityHomeWidget& object); virtual ~qMRMLVirtualRealityHomeWidgetPrivate(); + void init(); + QMap ModuleWidgetsMap; + public: /// Virtual reality view MRML node vtkWeakPointer VirtualRealityViewNode; @@ -68,6 +73,8 @@ void qMRMLVirtualRealityHomeWidgetPrivate::init() Q_Q(qMRMLVirtualRealityHomeWidget); this->setupUi(q); + this->backButton->setVisible(false); + QObject::connect(this->MotionSensitivitySliderWidget, SIGNAL(valueChanged(double)), q, SLOT(onMotionSensitivityChanged(double))); QObject::connect(this->FlySpeedSliderWidget, SIGNAL(valueChanged(double)), q, SLOT(onFlySpeedChanged(double))); QObject::connect(this->Magnification001xButton, SIGNAL(clicked()), q, SLOT(onMagnification001xPressed())); @@ -79,7 +86,6 @@ void qMRMLVirtualRealityHomeWidgetPrivate::init() //QObject::connect(this->LockMagnificationCheckBox, SIGNAL(toggled(bool)), q, SLOT(setMagnificationLock(bool))); //TODO: Magnification lock of view node not implemented yet - } //----------------------------------------------------------------------------- @@ -106,6 +112,67 @@ vtkMRMLVirtualRealityViewNode* qMRMLVirtualRealityHomeWidget::virtualRealityView return d->VirtualRealityViewNode; } +//----------------------------------------------------------------------------- +void qMRMLVirtualRealityHomeWidget::addModuleButton(QWidget* moduleWidget, QIcon& icon) +{ + Q_D(qMRMLVirtualRealityHomeWidget); + + if (!moduleWidget) + { + qCritical() << Q_FUNC_INFO << "Failed: widget is null"; + return; + } + + QPushButton* moduleButton = new QPushButton(d->ModulesGroupBox); + d->ModulesGroupBoxLayout->addWidget(moduleButton); + moduleButton->setIcon(icon); + + moduleWidget->setParent(d->ModuleWidgetFrame); + d->ModuleWidgetsMap[moduleButton] = moduleWidget; + + QObject::connect(moduleButton, SIGNAL(clicked()), this, SLOT(onModuleButtonPressed())); + QObject::connect(d->backButton, SIGNAL(clicked()), this, SLOT(onBackButtonPressed())); + + moduleButton->setVisible(true); + moduleWidget->setVisible(false); + d->backButton->setVisible(false); +} + +//----------------------------------------------------------------------------- +void qMRMLVirtualRealityHomeWidget::onModuleButtonPressed() +{ + Q_D(qMRMLVirtualRealityHomeWidget); + + QPushButton* moduleButton = qobject_cast(sender()); + + if (!moduleButton) + { + qCritical() << Q_FUNC_INFO << "Failed: moduleButton is null"; + return; + } + + d->HomeWidgetFrame->setVisible(false); + d->ModulesGroupBox->setVisible(false); + d->ModuleWidgetsMap[moduleButton]->setVisible(true); + d->backButton->setVisible(true); +} + +//----------------------------------------------------------------------------- +void qMRMLVirtualRealityHomeWidget::onBackButtonPressed() +{ + Q_D(qMRMLVirtualRealityHomeWidget); + d->HomeWidgetFrame->setVisible(true); + d->ModulesGroupBox->setVisible(true); + d->backButton->setVisible(false); + + QMap::const_iterator iteratorForMap; + for (iteratorForMap = d->ModuleWidgetsMap.constBegin(); iteratorForMap != d->ModuleWidgetsMap.constEnd(); ++iteratorForMap) + { + iteratorForMap.value()->setVisible(false); + } + +} + //----------------------------------------------------------------------------- QString qMRMLVirtualRealityHomeWidget::virtualRealityViewNodeID()const { @@ -159,7 +226,7 @@ void qMRMLVirtualRealityHomeWidget::updateWidgetFromMRML() d->Magnification01xButton->setEnabled(vrViewNode != nullptr && vrViewNode->GetMagnification() != NULL); d->Magnification1xButton->setEnabled(vrViewNode != nullptr && vrViewNode->GetMagnification() != NULL); d->Magnification10xButton->setEnabled(vrViewNode != nullptr && vrViewNode->GetMagnification() != NULL); - d->Magnification100xButton->setEnabled(vrViewNode != nullptr && vrViewNode->GetMagnification() != NULL); + d->Magnification100xButton->setEnabled(vrViewNode != nullptr && vrViewNode->GetMagnification() != NULL); } //----------------------------------------------------------------------------- @@ -173,7 +240,6 @@ void qMRMLVirtualRealityHomeWidget::onMotionSensitivityChanged(double percent) qCritical() << Q_FUNC_INFO << " Failed: view node is null"; return; } - vrViewNode->SetMotionSensitivity(percent * 0.01); } diff --git a/VirtualReality/Widgets/qMRMLVirtualRealityHomeWidget.h b/VirtualReality/Widgets/qMRMLVirtualRealityHomeWidget.h index 6d24950..470699f 100644 --- a/VirtualReality/Widgets/qMRMLVirtualRealityHomeWidget.h +++ b/VirtualReality/Widgets/qMRMLVirtualRealityHomeWidget.h @@ -32,6 +32,10 @@ #include #include +// Qt includes +#include +#include + class vtkMRMLVirtualRealityViewNode; class qMRMLVirtualRealityHomeWidgetPrivate; @@ -66,6 +70,10 @@ public slots: //void updateViewFromReferenceViewCamera(); //void setMagnificationLock(bool); + void addModuleButton(QWidget* moduleWidget, QIcon& icon); + void onModuleButtonPressed(); + void onBackButtonPressed(); + protected slots: /// Update widgets from the MRML node void updateWidgetFromMRML(); diff --git a/VirtualReality/Widgets/qMRMLVirtualRealityView.cxx b/VirtualReality/Widgets/qMRMLVirtualRealityView.cxx index e2b5b2a..4dc3da8 100644 --- a/VirtualReality/Widgets/qMRMLVirtualRealityView.cxx +++ b/VirtualReality/Widgets/qMRMLVirtualRealityView.cxx @@ -58,7 +58,7 @@ #include "vtkSlicerCamerasModuleLogic.h" #include // For Slicer_VERSION_MAJOR, Slicer_VERSION_MINOR -// VirtualReality includes +// VirtualReality MRML includes #include "vtkMRMLVirtualRealityViewNode.h" // MRMLDisplayableManager includes @@ -121,6 +121,7 @@ qMRMLVirtualRealityViewPrivate::qMRMLVirtualRealityViewPrivate(qMRMLVirtualReali , CamerasLogic(NULL) { this->MRMLVirtualRealityViewNode = 0; + this->HomeWidget = new qMRMLVirtualRealityHomeWidget(q_ptr); } //--------------------------------------------------------------------------- @@ -622,7 +623,6 @@ void qMRMLVirtualRealityViewPrivate::updateTransformNodesWithTrackerPoses() #endif } - //---------------------------------------------------------------------------- void qMRMLVirtualRealityViewPrivate::updateTransformNodeWithPose(vtkMRMLTransformNode* node, vr::TrackedDevicePose_t& pose) { @@ -642,7 +642,6 @@ void qMRMLVirtualRealityViewPrivate::updateTransformNodeWithPose(vtkMRMLTransfor node->SetAttribute("VirtualReality.PoseStatus", PoseStatusToString(pose.eTrackingResult).c_str()); } - // -------------------------------------------------------------------------- // qMRMLVirtualRealityView methods @@ -659,6 +658,13 @@ qMRMLVirtualRealityView::~qMRMLVirtualRealityView() { } +//------------------------------------------------------------------------------ +void qMRMLVirtualRealityView::registerModule(QWidget* widget, QIcon& icon) +{ + Q_D(qMRMLVirtualRealityView); + d->HomeWidget->addModuleButton(widget, icon); +} + //------------------------------------------------------------------------------ void qMRMLVirtualRealityView::addDisplayableManager(const QString& displayableManagerName) { @@ -698,6 +704,13 @@ vtkMRMLVirtualRealityViewNode* qMRMLVirtualRealityView::mrmlVirtualRealityViewNo return d->MRMLVirtualRealityViewNode; } +//---------------------------------------------------------------------------- +qMRMLVirtualRealityHomeWidget* qMRMLVirtualRealityView::vrHomeWidget()const +{ + Q_D(const qMRMLVirtualRealityView); + return d->HomeWidget; +} + //------------------------------------------------------------------------------ void qMRMLVirtualRealityView::getDisplayableManagers(vtkCollection* displayableManagers) { diff --git a/VirtualReality/Widgets/qMRMLVirtualRealityView.h b/VirtualReality/Widgets/qMRMLVirtualRealityView.h index de9316b..6e36771 100644 --- a/VirtualReality/Widgets/qMRMLVirtualRealityView.h +++ b/VirtualReality/Widgets/qMRMLVirtualRealityView.h @@ -33,6 +33,7 @@ // CTK includes #include +class qMRMLVirtualRealityHomeWidget; class qMRMLVirtualRealityViewPrivate; class vtkMRMLVirtualRealityViewNode; class vtkCollection; @@ -84,6 +85,8 @@ class Q_SLICER_QTMODULES_VIRTUALREALITY_WIDGETS_EXPORT qMRMLVirtualRealityView : /// Get the 3D View node observed by view. Q_INVOKABLE vtkMRMLVirtualRealityViewNode* mrmlVirtualRealityViewNode()const; + Q_INVOKABLE qMRMLVirtualRealityHomeWidget* vrHomeWidget()const; + /// Get a reference to the associated vtkRenderer vtkOpenVRRenderer* renderer()const; @@ -100,6 +103,8 @@ class Q_SLICER_QTMODULES_VIRTUALREALITY_WIDGETS_EXPORT qMRMLVirtualRealityView : /// Get underlying RenderWindow Q_INVOKABLE bool isHardwareConnected()const; + void registerModule(QWidget* widget, QIcon& icon); + signals: void physicalToWorldMatrixModified(); @@ -113,7 +118,6 @@ public slots: void setVirtualWidget(QWidget*); protected: - QScopedPointer d_ptr; private: diff --git a/VirtualReality/Widgets/qMRMLVirtualRealityView_p.h b/VirtualReality/Widgets/qMRMLVirtualRealityView_p.h index f109afc..26c81db 100644 --- a/VirtualReality/Widgets/qMRMLVirtualRealityView_p.h +++ b/VirtualReality/Widgets/qMRMLVirtualRealityView_p.h @@ -40,6 +40,9 @@ #include #include +// VirtualReality Widgets includes +#include "qMRMLVirtualRealityHomeWidget.h" + // qMRML includes #include "qMRMLVirtualRealityView.h" @@ -115,6 +118,8 @@ public slots: double LastViewPosition[3]; QTimer VirtualRealityLoopTimer; + + qMRMLVirtualRealityHomeWidget* HomeWidget; }; #endif