From 89844b01e20429d7a5560720c786add60c67df69 Mon Sep 17 00:00:00 2001 From: mholden8 Date: Thu, 15 May 2014 14:58:35 -0400 Subject: [PATCH] Re #29: Added relevant shortcut key for all collection modes currently available. --- Widgets/qSlicerLORCollectControlsWidget.cxx | 11 ++ Widgets/qSlicerLORCollectControlsWidget.h | 3 + Widgets/qSlicerLORFiducialWidget.cxx | 28 +++++ Widgets/qSlicerLORFiducialWidget.h | 5 + Widgets/qSlicerLORManualDOFWidget.cxx | 65 ++++++++++- Widgets/qSlicerLORManualDOFWidget.h | 8 ++ .../qSlicerLORManualSegmentationWidget.cxx | 30 +++++ Widgets/qSlicerLORManualSegmentationWidget.h | 5 + Widgets/qSlicerLORModelWidget.cxx | 107 ++++++++++++++++++ Widgets/qSlicerLORModelWidget.h | 19 ++++ ...erLinearObjectRegistrationModuleWidget.cxx | 9 +- 11 files changed, 283 insertions(+), 7 deletions(-) diff --git a/Widgets/qSlicerLORCollectControlsWidget.cxx b/Widgets/qSlicerLORCollectControlsWidget.cxx index caf2fcf..daa2752 100644 --- a/Widgets/qSlicerLORCollectControlsWidget.cxx +++ b/Widgets/qSlicerLORCollectControlsWidget.cxx @@ -137,6 +137,17 @@ ::widgetDeactivated() } +void qSlicerLORCollectControlsWidget +::installShortcuts() +{ +} + + +void qSlicerLORCollectControlsWidget +::uninstallShortcuts() +{ +} + void qSlicerLORCollectControlsWidget ::SetLORNode( vtkMRMLNode* newNode ) diff --git a/Widgets/qSlicerLORCollectControlsWidget.h b/Widgets/qSlicerLORCollectControlsWidget.h index 991d2af..385bbe2 100644 --- a/Widgets/qSlicerLORCollectControlsWidget.h +++ b/Widgets/qSlicerLORCollectControlsWidget.h @@ -80,6 +80,9 @@ protected slots: vtkMRMLNode* CollectNode; + virtual void installShortcuts(); + virtual void uninstallShortcuts(); + private: Q_DECLARE_PRIVATE(qSlicerLORCollectControlsWidget); Q_DISABLE_COPY(qSlicerLORCollectControlsWidget); diff --git a/Widgets/qSlicerLORFiducialWidget.cxx b/Widgets/qSlicerLORFiducialWidget.cxx index 4469274..5962bb9 100644 --- a/Widgets/qSlicerLORFiducialWidget.cxx +++ b/Widgets/qSlicerLORFiducialWidget.cxx @@ -98,6 +98,8 @@ ::setup() this->ConnectAllButtons(); + this->ConvertShortcutC = NULL; + this->updateWidget(); } @@ -146,12 +148,38 @@ ::enter() void qSlicerLORFiducialWidget ::widgetActivated() { + this->installShortcuts(); + this->updateWidget(); } void qSlicerLORFiducialWidget ::widgetDeactivated() { + this->uninstallShortcuts(); + this->updateWidget(); +} + + +void qSlicerLORFiducialWidget +::installShortcuts() +{ + Q_D(qSlicerLORFiducialWidget); + + if ( this->ConvertShortcutC == NULL ) + { + this->ConvertShortcutC = new QShortcut( QKeySequence( QString( "c" ) ), this ); + } + connect( this->ConvertShortcutC, SIGNAL( activated() ), d->ConvertFiducialsButton, SLOT( click() ) ); +} + + +void qSlicerLORFiducialWidget +::uninstallShortcuts() +{ + Q_D(qSlicerLORFiducialWidget); + + disconnect( this->ConvertShortcutC, SIGNAL( activated() ), d->ConvertFiducialsButton, SLOT( click() ) ); } diff --git a/Widgets/qSlicerLORFiducialWidget.h b/Widgets/qSlicerLORFiducialWidget.h index 99f969b..2da76ab 100644 --- a/Widgets/qSlicerLORFiducialWidget.h +++ b/Widgets/qSlicerLORFiducialWidget.h @@ -69,6 +69,11 @@ protected slots: virtual void setup(); virtual void enter(); + virtual void installShortcuts(); + virtual void uninstallShortcuts(); + + QShortcut* ConvertShortcutC; + private: Q_DECLARE_PRIVATE(qSlicerLORFiducialWidget); Q_DISABLE_COPY(qSlicerLORFiducialWidget); diff --git a/Widgets/qSlicerLORManualDOFWidget.cxx b/Widgets/qSlicerLORManualDOFWidget.cxx index 656f5a4..61849ad 100644 --- a/Widgets/qSlicerLORManualDOFWidget.cxx +++ b/Widgets/qSlicerLORManualDOFWidget.cxx @@ -97,6 +97,11 @@ ::setup() this->ConnectAllButtons(); + this->ReferenceShortcutR = NULL; + this->PointShortcutP = NULL; + this->LineShortcutL = NULL; + this->PlaneShortcutA = NULL; + this->updateWidget(); } @@ -153,6 +158,10 @@ void qSlicerLORManualDOFWidget ::widgetActivated() { Q_D(qSlicerLORManualDOFWidget); + + this->installShortcuts(); + + this->updateWidget(); } @@ -165,9 +174,53 @@ ::widgetDeactivated() { this->LORNode->StopCollecting(); } + + this->uninstallShortcuts(); + + this->updateWidget(); } +void qSlicerLORManualDOFWidget +::installShortcuts() +{ + Q_D(qSlicerLORManualDOFWidget); + + if ( this->ReferenceShortcutR == NULL ) + { + this->ReferenceShortcutR = new QShortcut( QKeySequence( QString( "r" ) ), this ); + } + if ( this->PointShortcutP == NULL ) + { + this->PointShortcutP = new QShortcut( QKeySequence( QString( "p" ) ), this ); + } + if ( this->LineShortcutL == NULL ) + { + this->LineShortcutL = new QShortcut( QKeySequence( QString( "l" ) ), this ); + } + if ( this->PlaneShortcutA == NULL ) + { + this->PlaneShortcutA = new QShortcut( QKeySequence( QString( "a" ) ), this ); + } + + connect( this->ReferenceShortcutR, SIGNAL( activated() ), d->ReferenceButton, SLOT( toggle() ) ); + connect( this->PointShortcutP, SIGNAL( activated() ), d->PointButton, SLOT( toggle() ) ); + connect( this->LineShortcutL, SIGNAL( activated() ), d->LineButton, SLOT( toggle() ) ); + connect( this->PlaneShortcutA, SIGNAL( activated() ), d->PlaneButton, SLOT( toggle() ) ); +} + + +void qSlicerLORManualDOFWidget +::uninstallShortcuts() +{ + Q_D(qSlicerLORManualDOFWidget); + + disconnect( this->ReferenceShortcutR, SIGNAL( activated() ), d->ReferenceButton, SLOT( toggle() ) ); + disconnect( this->PointShortcutP, SIGNAL( activated() ), d->PointButton, SLOT( toggle() ) ); + disconnect( this->LineShortcutL, SIGNAL( activated() ), d->LineButton, SLOT( toggle() ) ); + disconnect( this->PlaneShortcutA, SIGNAL( activated() ), d->PlaneButton, SLOT( toggle() ) ); +} + void qSlicerLORManualDOFWidget ::onReferenceButtonToggled() @@ -182,6 +235,7 @@ ::onReferenceButtonToggled() { this->LORNode->StopCollecting(); } + this->updateWidget(); } @@ -198,6 +252,7 @@ ::onPointButtonToggled() { this->LORNode->StopCollecting(); } + this->updateWidget(); } @@ -214,6 +269,7 @@ ::onLineButtonToggled() { this->LORNode->StopCollecting(); } + this->updateWidget(); } @@ -230,6 +286,7 @@ ::onPlaneButtonToggled() { this->LORNode->StopCollecting(); } + this->updateWidget(); } @@ -246,7 +303,7 @@ ::updateWidget() this->DisconnectAllButtons(); - if ( this->LORNode->GetCollectState().compare( LORConstants::REFERENCE_COLLECT_STATE ) ) + if ( this->LORNode->GetCollectState().compare( LORConstants::REFERENCE_COLLECT_STATE ) == 0 ) { d->ReferenceButton->setChecked( true ); } @@ -255,7 +312,7 @@ ::updateWidget() d->ReferenceButton->setChecked( false ); } - if ( this->LORNode->GetCollectState().compare( LORConstants::POINT_COLLECT_STATE ) ) + if ( this->LORNode->GetCollectState().compare( LORConstants::POINT_COLLECT_STATE ) == 0 ) { d->PointButton->setChecked( true ); } @@ -264,7 +321,7 @@ ::updateWidget() d->PointButton->setChecked( false ); } - if ( this->LORNode->GetCollectState().compare( LORConstants::LINE_COLLECT_STATE ) ) + if ( this->LORNode->GetCollectState().compare( LORConstants::LINE_COLLECT_STATE ) == 0 ) { d->LineButton->setChecked( true ); } @@ -273,7 +330,7 @@ ::updateWidget() d->LineButton->setChecked( false ); } - if ( this->LORNode->GetCollectState().compare( LORConstants::PLANE_COLLECT_STATE ) ) + if ( this->LORNode->GetCollectState().compare( LORConstants::PLANE_COLLECT_STATE ) == 0 ) { d->PlaneButton->setChecked( true ); } diff --git a/Widgets/qSlicerLORManualDOFWidget.h b/Widgets/qSlicerLORManualDOFWidget.h index 0d80082..323c42c 100644 --- a/Widgets/qSlicerLORManualDOFWidget.h +++ b/Widgets/qSlicerLORManualDOFWidget.h @@ -71,6 +71,14 @@ protected slots: virtual void setup(); virtual void enter(); + virtual void installShortcuts(); + virtual void uninstallShortcuts(); + + QShortcut* ReferenceShortcutR; + QShortcut* PointShortcutP; + QShortcut* LineShortcutL; + QShortcut* PlaneShortcutA; + private: Q_DECLARE_PRIVATE(qSlicerLORManualDOFWidget); Q_DISABLE_COPY(qSlicerLORManualDOFWidget); diff --git a/Widgets/qSlicerLORManualSegmentationWidget.cxx b/Widgets/qSlicerLORManualSegmentationWidget.cxx index ec09720..543f092 100644 --- a/Widgets/qSlicerLORManualSegmentationWidget.cxx +++ b/Widgets/qSlicerLORManualSegmentationWidget.cxx @@ -97,6 +97,8 @@ ::setup() d->setupUi(this); connect( d->CollectButton, SIGNAL( toggled( bool ) ), this, SLOT( onCollectButtonToggled() ) ); + + this->CollectShortcutC = NULL; this->updateWidget(); } @@ -130,6 +132,9 @@ void qSlicerLORManualSegmentationWidget ::widgetActivated() { Q_D(qSlicerLORManualSegmentationWidget); + + this->installShortcuts(); + this->updateWidget(); } @@ -143,10 +148,35 @@ ::widgetDeactivated() { this->LORNode->StopCollecting(); } + + this->uninstallShortcuts(); + this->updateWidget(); } +void qSlicerLORManualSegmentationWidget +::installShortcuts() +{ + Q_D(qSlicerLORManualSegmentationWidget); + + if ( this->CollectShortcutC == NULL ) + { + this->CollectShortcutC = new QShortcut( QKeySequence( QString( "c" ) ), this ); + } + connect( this->CollectShortcutC, SIGNAL( activated() ), d->CollectButton, SLOT( toggle() ) ); +} + + +void qSlicerLORManualSegmentationWidget +::uninstallShortcuts() +{ + Q_D(qSlicerLORManualSegmentationWidget); + + disconnect( this->CollectShortcutC, SIGNAL( activated() ), d->CollectButton, SLOT( toggle() ) ); +} + + void qSlicerLORManualSegmentationWidget ::SetAndObserveCollectNode( vtkMRMLNode* newCollectNode ) { diff --git a/Widgets/qSlicerLORManualSegmentationWidget.h b/Widgets/qSlicerLORManualSegmentationWidget.h index 9484d67..0355f89 100644 --- a/Widgets/qSlicerLORManualSegmentationWidget.h +++ b/Widgets/qSlicerLORManualSegmentationWidget.h @@ -69,6 +69,11 @@ protected slots: virtual void setup(); virtual void enter(); + virtual void installShortcuts(); + virtual void uninstallShortcuts(); + + QShortcut* CollectShortcutC; + private: Q_DECLARE_PRIVATE(qSlicerLORManualSegmentationWidget); Q_DISABLE_COPY(qSlicerLORManualSegmentationWidget); diff --git a/Widgets/qSlicerLORModelWidget.cxx b/Widgets/qSlicerLORModelWidget.cxx index 80ce66b..e51c905 100644 --- a/Widgets/qSlicerLORModelWidget.cxx +++ b/Widgets/qSlicerLORModelWidget.cxx @@ -98,6 +98,11 @@ ::setup() this->ConnectAllButtons(); + this->ReferenceShortcutR = NULL; + this->PointShortcutP = NULL; + this->LineShortcutL = NULL; + this->PlaneShortcutA = NULL; + this->updateWidget(); } @@ -152,6 +157,8 @@ ::enter() void qSlicerLORModelWidget ::widgetActivated() { + this->installShortcuts(); + this->updateWidget(); } @@ -159,6 +166,50 @@ void qSlicerLORModelWidget ::widgetDeactivated() { this->disconnectMarkupsObservers(); + + this->uninstallShortcuts(); + this->updateWidget(); +} + + +void qSlicerLORModelWidget +::installShortcuts() +{ + Q_D(qSlicerLORModelWidget); + + if ( this->ReferenceShortcutR == NULL ) + { + this->ReferenceShortcutR = new QShortcut( QKeySequence( QString( "r" ) ), this ); + } + if ( this->PointShortcutP == NULL ) + { + this->PointShortcutP = new QShortcut( QKeySequence( QString( "p" ) ), this ); + } + if ( this->LineShortcutL == NULL ) + { + this->LineShortcutL = new QShortcut( QKeySequence( QString( "l" ) ), this ); + } + if ( this->PlaneShortcutA == NULL ) + { + this->PlaneShortcutA = new QShortcut( QKeySequence( QString( "a" ) ), this ); + } + + connect( this->ReferenceShortcutR, SIGNAL( activated() ), this, SLOT( onReferenceShortcutRActivated() ) ); + connect( this->PointShortcutP, SIGNAL( activated() ), this, SLOT( onPointShortcutPActivated() ) ); + connect( this->LineShortcutL, SIGNAL( activated() ), this, SLOT( onLineShortcutLActivated() ) ); + connect( this->PlaneShortcutA, SIGNAL( activated() ), this, SLOT( onPlaneShortcutAActivated() ) ); +} + + +void qSlicerLORModelWidget +::uninstallShortcuts() +{ + Q_D(qSlicerLORModelWidget); + + disconnect( this->ReferenceShortcutR, SIGNAL( activated() ), d->ReferenceButton, SLOT( onReferenceShortcutRActivated() ) ); + disconnect( this->PointShortcutP, SIGNAL( activated() ), d->PointButton, SLOT( onPointShortcutPActivated() ) ); + disconnect( this->LineShortcutL, SIGNAL( activated() ), d->LineButton, SLOT( onLineShortcutLActivated() ) ); + disconnect( this->PlaneShortcutA, SIGNAL( activated() ), d->PlaneButton, SLOT( onPlaneShortcutAActivated() ) ); } @@ -200,6 +251,15 @@ ::disconnectMarkupsObservers( std::string checkString ) // Note: Observe the markups PointModifiedEvent - this is when the markups value is changed to the correct coordinates +void qSlicerLORModelWidget +::onReferenceShortcutRActivated() +{ + Q_D(qSlicerLORModelWidget); + + d->ReferenceButton->toggle(); + this->onClickRequested(); +} + void qSlicerLORModelWidget ::onReferenceButtonToggled() @@ -241,6 +301,16 @@ ::onReferenceFiducialDropped() } +void qSlicerLORModelWidget +::onPointShortcutPActivated() +{ + Q_D(qSlicerLORModelWidget); + + d->PointButton->toggle(); + this->onClickRequested(); +} + + void qSlicerLORModelWidget ::onPointButtonToggled() { @@ -280,6 +350,16 @@ ::onPointFiducialDropped() } +void qSlicerLORModelWidget +::onLineShortcutLActivated() +{ + Q_D(qSlicerLORModelWidget); + + d->LineButton->toggle(); + this->onClickRequested(); +} + + void qSlicerLORModelWidget ::onLineButtonToggled() { @@ -319,6 +399,16 @@ ::onLineFiducialDropped() } +void qSlicerLORModelWidget +::onPlaneShortcutAActivated() +{ + Q_D(qSlicerLORModelWidget); + + d->PlaneButton->toggle(); + this->onClickRequested(); +} + + void qSlicerLORModelWidget ::onPlaneButtonToggled() { @@ -358,6 +448,23 @@ ::onPlaneFiducialDropped() } +// This function is a copy of the one available in the qMRMLMarkupsModuleWidget class +void qSlicerLORModelWidget +::onClickRequested() +{ + QPoint pos = QCursor::pos(); + + // find out which widget it was over + QWidget *widget = qSlicerApplication::application()->widgetAt(pos); + + // simulate a mouse press inside the widget + QPoint widgetPos = widget->mapFromGlobal(pos); + QMouseEvent click(QEvent::MouseButtonRelease, widgetPos, Qt::LeftButton, 0, 0); + click.setAccepted(true); + + // and send it to the widget + QCoreApplication::sendEvent(widget, &click); +} void qSlicerLORModelWidget diff --git a/Widgets/qSlicerLORModelWidget.h b/Widgets/qSlicerLORModelWidget.h index 475f0e7..4fa557d 100644 --- a/Widgets/qSlicerLORModelWidget.h +++ b/Widgets/qSlicerLORModelWidget.h @@ -25,6 +25,8 @@ #include "qSlicerWidget.h" #include "qSlicerLORCollectControlsWidget.h" +#include "qSlicerApplication.h" + // FooBar Widgets includes #include "qSlicerLinearObjectRegistrationModuleWidgetsExport.h" #include "ui_qSlicerLORModelWidget.h" @@ -60,15 +62,24 @@ public slots: protected slots: + void onReferenceShortcutRActivated(); void onReferenceButtonToggled(); void onReferenceFiducialDropped(); + + void onPointShortcutPActivated(); void onPointButtonToggled(); void onPointFiducialDropped(); + + void onLineShortcutLActivated(); void onLineButtonToggled(); void onLineFiducialDropped(); + + void onPlaneShortcutAActivated(); void onPlaneButtonToggled(); void onPlaneFiducialDropped(); + void onClickRequested(); + void disconnectMarkupsObservers( std::string checkString = "" ); void updateWidget(); @@ -79,6 +90,14 @@ protected slots: virtual void setup(); virtual void enter(); + virtual void installShortcuts(); + virtual void uninstallShortcuts(); + + QShortcut* ReferenceShortcutR; + QShortcut* PointShortcutP; + QShortcut* LineShortcutL; + QShortcut* PlaneShortcutA; + private: Q_DECLARE_PRIVATE(qSlicerLORModelWidget); Q_DISABLE_COPY(qSlicerLORModelWidget); diff --git a/qSlicerLinearObjectRegistrationModuleWidget.cxx b/qSlicerLinearObjectRegistrationModuleWidget.cxx index cb53b99..bfa70d3 100644 --- a/qSlicerLinearObjectRegistrationModuleWidget.cxx +++ b/qSlicerLinearObjectRegistrationModuleWidget.cxx @@ -283,11 +283,14 @@ ::UpdateCollectWidgets( vtkMRMLLinearObjectRegistrationNode* linearObjectRegistr // We must deactivate all widgets before activating the appropriate one d->CollectTabs->setCurrentIndex( tabIndex ); - // Hide all the tabs + // Hide all the non-active tabs for ( std::map< int, qSlicerLORCollectWidget* >::iterator itr = this->CollectWidgets.begin(); itr != this->CollectWidgets.end(); itr++ ) { - itr->second->SetLORNode( linearObjectRegistrationNode ); - itr->second->hide(); + if ( itr->first != tabIndex ) + { + itr->second->SetLORNode( linearObjectRegistrationNode ); + itr->second->hide(); + } } // Iterate over all tabs and show the relevant tab