Mercurial > hg > orthanc-stone
changeset 1199:922d2e61aa5d
RadiograpyScene: can now remove any layer + new key wrappers for Delete/Backspace
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Thu, 28 Nov 2019 18:28:15 +0100 |
parents | a34ba19d2060 |
children | 54cbffabdc45 ab958fd99b07 |
files | Applications/Qt/QCairoWidget.cpp Applications/Sdl/SdlEngine.cpp Framework/Radiography/RadiographyScene.cpp Framework/Radiography/RadiographyScene.h Framework/Radiography/RadiographyWidget.cpp Framework/Radiography/RadiographyWidget.h Framework/StoneEnumerations.h |
diffstat | 7 files changed, 55 insertions(+), 43 deletions(-) [+] |
line wrap: on
line diff
--- a/Applications/Qt/QCairoWidget.cpp Wed Nov 27 17:56:48 2019 +0100 +++ b/Applications/Qt/QCairoWidget.cpp Thu Nov 28 18:28:15 2019 +0100 @@ -185,6 +185,16 @@ break; } } + else if (keyChar == 127) + { + switch (event->key()) + { + CASE_QT_KEY_TO_ORTHANC(Qt::Key_Delete, KeyboardKeys_Delete); + CASE_QT_KEY_TO_ORTHANC(Qt::Key_Backspace, KeyboardKeys_Backspace); + default: + break; + } + } { OrthancStone::NativeStoneApplicationContext::GlobalMutexLocker locker(*context_);
--- a/Applications/Sdl/SdlEngine.cpp Wed Nov 27 17:56:48 2019 +0100 +++ b/Applications/Sdl/SdlEngine.cpp Thu Nov 28 18:28:15 2019 +0100 @@ -257,6 +257,10 @@ case SDLK_KP_MINUS: locker.GetCentralViewport().KeyPressed(KeyboardKeys_Generic, '-', modifiers); break; + case SDLK_DELETE: + locker.GetCentralViewport().KeyPressed(KeyboardKeys_Delete, 0, modifiers); break; + case SDLK_BACKSPACE: + locker.GetCentralViewport().KeyPressed(KeyboardKeys_Backspace, 0, modifiers); break; case SDLK_RIGHT: locker.GetCentralViewport().KeyPressed(KeyboardKeys_Right, 0, modifiers); break; case SDLK_LEFT:
--- a/Framework/Radiography/RadiographyScene.cpp Wed Nov 27 17:56:48 2019 +0100 +++ b/Framework/Radiography/RadiographyScene.cpp Thu Nov 28 18:28:15 2019 +0100 @@ -136,7 +136,7 @@ // LOG(INFO) << "Registering layer: " << countLayers_; - size_t index = countLayers_++; + size_t index = nextLayerIndex_++; raii->SetIndex(index); layers_[index] = raii.release(); @@ -165,7 +165,7 @@ RadiographyScene::RadiographyScene(MessageBroker& broker) : IObserver(broker), IObservable(broker), - countLayers_(0), + nextLayerIndex_(0), hasWindowing_(false), windowingCenter_(0), // Dummy initialization windowingWidth_(0) // Dummy initialization @@ -221,9 +221,8 @@ delete found->second; layers_.erase(found); - countLayers_--; - LOG(INFO) << "Removing layer, there are now : " << countLayers_ << " layers"; + LOG(INFO) << "Removing layer, there are now : " << layers_.size() << " layers"; BroadcastMessage(RadiographyScene::LayerRemovedMessage(*this, layerIndex)); } @@ -294,7 +293,10 @@ alpha->SetGeometry(*geometry); } - return RegisterLayer(alpha.release()); + RadiographyLayer& registeredLayer = RegisterLayer(alpha.release()); + + BroadcastMessage(RadiographyScene::LayerEditedMessage(*this, registeredLayer)); + return registeredLayer; } @@ -513,7 +515,7 @@ bool applyWindowing) const { // Render layers in the background-to-foreground order - for (size_t index = 0; index < countLayers_; index++) + for (size_t index = 0; index < nextLayerIndex_; index++) { Layers::const_iterator it = layers_.find(index); if (it != layers_.end()) @@ -530,7 +532,7 @@ double y) const { // Render layers in the foreground-to-background order - for (size_t i = countLayers_; i > 0; i--) + for (size_t i = nextLayerIndex_; i > 0; i--) { index = i - 1; Layers::const_iterator it = layers_.find(index);
--- a/Framework/Radiography/RadiographyScene.h Wed Nov 27 17:56:48 2019 +0100 +++ b/Framework/Radiography/RadiographyScene.h Thu Nov 28 18:28:15 2019 +0100 @@ -161,7 +161,7 @@ protected: typedef std::map<size_t, RadiographyLayer*> Layers; - size_t countLayers_; + size_t nextLayerIndex_; bool hasWindowing_; float windowingCenter_; float windowingWidth_;
--- a/Framework/Radiography/RadiographyWidget.cpp Wed Nov 27 17:56:48 2019 +0100 +++ b/Framework/Radiography/RadiographyWidget.cpp Thu Nov 28 18:28:15 2019 +0100 @@ -184,34 +184,6 @@ selectedLayer_ = layer; } - void RadiographyWidget::ClearSelectedLayer() - { - hasSelection_ = false; - } - - bool RadiographyWidget::SelectMaskLayer(size_t index) - { - std::vector<size_t> layerIndexes; - size_t count = 0; - scene_->GetLayersIndexes(layerIndexes); - - for (size_t i = 0; i < layerIndexes.size(); ++i) - { - const RadiographyMaskLayer* maskLayer = dynamic_cast<const RadiographyMaskLayer*>(&(scene_->GetLayer(layerIndexes[i]))); - if (maskLayer != NULL) - { - if (count == index) - { - Select(layerIndexes[i]); - return true; - } - count++; - } - } - - return false; - } - bool RadiographyWidget::LookupSelectedLayer(size_t& layer) { if (hasSelection_) @@ -244,8 +216,9 @@ size_t removedLayerIndex = message.GetLayerIndex(); if (hasSelection_ && selectedLayer_ == removedLayerIndex) { - ClearSelectedLayer(); + Unselect(); } + NotifyContentChanged(); } void RadiographyWidget::SetInvert(bool invert)
--- a/Framework/Radiography/RadiographyWidget.h Wed Nov 27 17:56:48 2019 +0100 +++ b/Framework/Radiography/RadiographyWidget.h Thu Nov 28 18:28:15 2019 +0100 @@ -71,16 +71,14 @@ void SetScene(boost::shared_ptr<RadiographyScene> scene); + void Select(size_t layer); + void Unselect() { hasSelection_ = false; } - void Select(size_t layer); - - void ClearSelectedLayer(); - - bool SelectMaskLayer(size_t index = 0); + template<typename LayerType> bool SelectLayerByType(size_t index = 0); bool LookupSelectedLayer(size_t& layer); @@ -106,4 +104,27 @@ return interpolation_; } }; + + template<typename LayerType> bool RadiographyWidget::SelectLayerByType(size_t index) + { + std::vector<size_t> layerIndexes; + size_t count = 0; + scene_->GetLayersIndexes(layerIndexes); + + for (size_t i = 0; i < layerIndexes.size(); ++i) + { + const LayerType* typedLayer = dynamic_cast<const LayerType*>(&(scene_->GetLayer(layerIndexes[i]))); + if (typedLayer != NULL) + { + if (count == index) + { + Select(layerIndexes[i]); + return true; + } + count++; + } + } + + return false; + } }
--- a/Framework/StoneEnumerations.h Wed Nov 27 17:56:48 2019 +0100 +++ b/Framework/StoneEnumerations.h Thu Nov 28 18:28:15 2019 +0100 @@ -95,10 +95,12 @@ KeyboardKeys_Generic = 0, // let's use the same ids as in javascript to avoid some conversion in WASM: https://css-tricks.com/snippets/javascript/javascript-keycodes/ + KeyboardKeys_Backspace = 8, KeyboardKeys_Left = 37, KeyboardKeys_Up = 38, KeyboardKeys_Right = 39, - KeyboardKeys_Down = 40 + KeyboardKeys_Down = 40, + KeyboardKeys_Delete = 46 }; enum SopClassUid