diff --git a/Modules/QtWidgets/include/QmitkCustomMultiWidget.h b/Modules/QtWidgets/include/QmitkCustomMultiWidget.h index 56a93600ce..7de4a04481 100644 --- a/Modules/QtWidgets/include/QmitkCustomMultiWidget.h +++ b/Modules/QtWidgets/include/QmitkCustomMultiWidget.h @@ -1,222 +1,166 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical Image Computing. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef QMITKCUSTOMMULTIWIDGET_H #define QMITKCUSTOMMULTIWIDGET_H // qt widgets module #include "MitkQtWidgetsExports.h" #include "QmitkRenderWindowWidget.h" // mitk core #include #include #include #include #include // qt -#include +#include class QHBoxLayout; class QVBoxLayout; class QGridLayout; class QSpacerItem; class QmitkLevelWindowWidget; class QmitkRenderWindow; -class vtkCornerAnnotation; namespace mitk { class RenderingManager; } /** * @brief The 'QmitkCustomMultiWidget' is a 'QWidget' that is used to display multiple render windows at once. * * Render windows can dynamically be added and removed to change the layout of the multi widget. */ class MITKQTWIDGETS_EXPORT QmitkCustomMultiWidget : public QWidget { Q_OBJECT public: QmitkCustomMultiWidget(QWidget* parent = 0, Qt::WindowFlags f = 0, mitk::RenderingManager* renderingManager = nullptr, mitk::BaseRenderer::RenderingMode::Type renderingMode = mitk::BaseRenderer::RenderingMode::Standard, const QString& multiWidgetName = "custommulti"); virtual ~QmitkCustomMultiWidget(); void SetDataStorage(mitk::DataStorage* dataStorage); - void InitRenderWindowWidgets(); + void InitializeRenderWindowWidgets(); using RenderWindowWidgetMap = std::map; using RenderWindowHash = QHash; RenderWindowWidgetMap GetRenderWindowWidgets() const; QmitkRenderWindowWidget* GetRenderWindowWidget(const QString& widgetID) const; + void AddRenderWindowWidget(int row, int column, const std::string& cornerAnnotation = ""); QmitkRenderWindow* GetRenderWindow(const QString& widgetID) const; QmitkRenderWindowWidget* GetActiveRenderWindowWidget() const; QmitkRenderWindowWidget* GetFirstRenderWindowWidget() const; QmitkRenderWindowWidget* GetLastRenderWindowWidget() const; unsigned int GetNumberOfRenderWindowWidgets() const; void RequestUpdate(const QString& widgetID); void RequestUpdateAll(); void ForceImmediateUpdate(const QString& widgetID); void ForceImmediateUpdateAll(); mitk::MouseModeSwitcher* GetMouseModeSwitcher(); const mitk::Point3D GetCrossPosition(const QString& widgetID) const; public slots: void ShowLevelWindowWidget(const QString& widgetID, bool show); void ShowAllLevelWindowWidgets(bool show); - /** - * @brief Set a background color gradient for a specific render window. - * - * If two different input colors are used, a gradient background is generated. - * - * @param upper The color of the gradient background. - * @param lower The color of the gradient background. - * @param widgetID The widget identifier. - */ - void SetBackgroundColorGradient(const mitk::Color& upper, const mitk::Color& lower, const QString& widgetID); - /** - * @brief Set a background color gradient for all available render windows. - * - * If two different input colors are used, a gradient background is generated. - * - * @param upper The color of the gradient background. - * @param lower The color of the gradient background. - */ - // #TODO: 'backgroundgradientcolor' - void SetAllBackgroundColorGradients(const mitk::Color& upper, const mitk::Color& lower); - void FillAllBackgroundColorGradientsWithBlack(); - void ShowBackgroundColorGradient(const QString& widgetID, bool show); - void ShowAllBackgroundColorGradients(bool show); - /** - * @rief Return a render window (widget) specific background color gradient - * - * @param widgetID The widget identifier. - * - * @return A color gradient as a pair of colors. - * First entry: upper color value - * Second entry: lower color value - */ - std::pair GetBackgroundColorGradient(const QString& widgetID) const; - bool GetBackgroundColorGradientFlag(const QString& widgetID) const; - - void SetDepartmentLogoPath(const char* path); - void ShowDepartmentLogo(const QString& widgetID, bool show); - void ShowAllDepartmentLogos(bool show); - - void SetDecorationColor(const QString& widgetID, const mitk::Color& color); - mitk::Color GetDecorationColor(const QString& widgetID) const; - - void ShowColoredRectangle(const QString& widgetID, bool show); - void ShowAllColoredRectangles(bool show); - bool IsColoredRectangleVisible(const QString& widgetID) const; - - void ShowCornerAnnotation(const QString& widgetID, bool show); - void ShowAllCornerAnnotations(bool show); - bool IsCornerAnnotationVisible(const QString& widgetID) const; - void SetCornerAnnotationText(const QString& widgetID, const std::string& cornerAnnotation); - std::string GetCornerAnnotationText(const QString& widgetID) const; /** * @brief Listener to the CrosshairPositionEvent * * Ensures the CrosshairPositionEvent is handled only once and at the end of the Qt-Event loop */ void HandleCrosshairPositionEvent(); /** * @brief Receives the signal from HandleCrosshairPositionEvent, executes the StatusBar update * */ void HandleCrosshairPositionEventDelayed(); - void Fit(); - - void EnsureDisplayContainsPoint(mitk::BaseRenderer *renderer, const mitk::Point3D &p); - void MoveCrossToPosition(const QString& widgetID, const mitk::Point3D& newPosition); void ResetCrosshair(); // mouse events void wheelEvent(QWheelEvent* e) override; void mousePressEvent(QMouseEvent* e) override; void moveEvent(QMoveEvent* e) override; signals: void WheelMoved(QWheelEvent *); void Moved(); public: enum { AXIAL, SAGITTAL, CORONAL, THREE_D }; private: void InitializeGUI(); void InitializeWidget(); void InitializeDisplayActionEventHandling(); - void AddRenderWindowWidget(int column, int row, const std::string& cornerAnnotation = ""); // #TODO: see T24173 mitk::DataNode::Pointer GetTopLayerNode(mitk::DataStorage::SetOfObjects::ConstPointer nodes); QGridLayout* m_CustomMultiWidgetLayout; RenderWindowWidgetMap m_RenderWindowWidgets; QmitkRenderWindowWidget* m_ActiveRenderWindowWidget; int m_PlaneMode; mitk::RenderingManager* m_RenderingManager; mitk::BaseRenderer::RenderingMode::Type m_RenderingMode; QString m_MultiWidgetName; mitk::MouseModeSwitcher::Pointer m_MouseModeSwitcher; - mitk::SliceNavigationController* m_TimeNavigationController; + mitk::DisplayActionEventBroadcast::Pointer m_DisplayActionEventBroadcast; std::unique_ptr m_StdDisplayActionEventHandler; mitk::DataStorage::Pointer m_DataStorage; bool m_PendingCrosshairPositionEvent; bool m_CrosshairNavigationEnabled; }; #endif // QMITKCUSTOMMULTIWIDGET_H diff --git a/Modules/QtWidgets/include/QmitkRenderWindowWidget.h b/Modules/QtWidgets/include/QmitkRenderWindowWidget.h index baa7bd5975..0e26f67cc5 100644 --- a/Modules/QtWidgets/include/QmitkRenderWindowWidget.h +++ b/Modules/QtWidgets/include/QmitkRenderWindowWidget.h @@ -1,117 +1,116 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical Image Computing. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef QMITKRENDERWINDOWWIDGET_H #define QMITKRENDERWINDOWWIDGET_H // qt widgets module #include "MitkQtWidgetsExports.h" #include #include // mitk core #include #include -//#include #include #include -// annotations module -#include - // qt #include #include /** * @brief * * */ class MITKQTWIDGETS_EXPORT QmitkRenderWindowWidget : public QWidget { Q_OBJECT public: - QmitkRenderWindowWidget(QWidget* parent = nullptr, const QString& UID = "", mitk::DataStorage* dataStorage = nullptr); + QmitkRenderWindowWidget( + QWidget* parent = nullptr, + const QString& UID = "", + mitk::DataStorage* dataStorage = nullptr, + mitk::BaseRenderer::RenderingMode::Type renderingMode = mitk::BaseRenderer::RenderingMode::Standard + ); + ~QmitkRenderWindowWidget() override; void SetDataStorage(mitk::DataStorage* dataStorage); + const QString& GetUID() const { return m_UID; }; QmitkRenderWindow* GetRenderWindow() const { return m_RenderWindow; }; QmitkLevelWindowWidget* GetlevelWindowWidget() const { return m_LevelWindowWidget; }; mitk::SliceNavigationController* GetSliceNavigationController() const; void RequestUpdate(); void ForceImmediateUpdate(); - // #TODO: 'backroundgradientcolor' - void SetBackgroundColorGradient(const mitk::Color& upper, const mitk::Color& lower); - void ShowBackgroundColorGradient(bool enable); - std::pair GetRendererBackgroundColorGradient() const { return m_BackgroundColorGradient; }; - bool GetBackgroundColorGradientFlag() const { return m_BackgroundColorGradientFlag; }; + void SetGradientBackgroundColors(const mitk::Color& upper, const mitk::Color& lower); + void ShowGradientBackground(bool enable); + std::pair GetGradientBackgroundColors() const { return m_GradientBackgroundColors; }; + bool IsGradientBackgroundOn() const; void ShowLevelWindowWidget(bool enable); - void ShowDepartmentLogo(bool show); void SetDecorationColor(const mitk::Color& color); mitk::Color GetDecorationColor() const { return m_DecorationColor; }; void ShowColoredRectangle(bool show); bool IsColoredRectangleVisible() const; void ShowCornerAnnotation(bool show); bool IsCornerAnnotationVisible() const; void SetCornerAnnotationText(const std::string& cornerAnnotation); std::string GetCornerAnnotationText() const; /** * @brief Create a corner annotation and a colored rectangle for this widget. * * @par text The text of the corner annotation. * @par color The color of the text and the rectangle. */ void SetDecorationProperties(std::string text, mitk::Color color); bool IsRenderWindowMenuActivated() const; private: void InitializeGUI(); void InitializeDecorations(); QString m_UID; QHBoxLayout* m_Layout; mitk::DataStorage* m_DataStorage; QmitkRenderWindow* m_RenderWindow; QmitkLevelWindowWidget* m_LevelWindowWidget; mitk::RenderingManager::Pointer m_RenderingManager; mitk::BaseRenderer::RenderingMode::Type m_RenderingMode; mitk::SliceNavigationController *m_TimeNavigationController; - std::pair m_BackgroundColorGradient; - bool m_BackgroundColorGradientFlag; - mitk::LogoAnnotation::Pointer m_LogoAnnotation; + std::pair m_GradientBackgroundColors; mitk::Color m_DecorationColor; vtkSmartPointer m_RectangleProp; vtkSmartPointer m_CornerAnnotation; }; #endif // QMITKRENDERWINDOWWIDGET_H diff --git a/Modules/QtWidgets/src/QmitkCustomMultiWidget.cpp b/Modules/QtWidgets/src/QmitkCustomMultiWidget.cpp index 984ebf7400..4f644922ac 100644 --- a/Modules/QtWidgets/src/QmitkCustomMultiWidget.cpp +++ b/Modules/QtWidgets/src/QmitkCustomMultiWidget.cpp @@ -1,750 +1,454 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical Image Computing. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmitkCustomMultiWidget.h" #include #include #include #include // mitk core -#include #include - -#include "mitkImagePixelReadAccessor.h" -#include "mitkPixelTypeMultiplex.h" -#include +#include +#include #include #include #include #include #include #include #include #include #include -#include -#include #include #include #include #include -#include #include // qt #include QmitkCustomMultiWidget::QmitkCustomMultiWidget(QWidget* parent, Qt::WindowFlags f/* = 0*/, mitk::RenderingManager* renderingManager/* = nullptr*/, mitk::BaseRenderer::RenderingMode::Type renderingMode/* = mitk::BaseRenderer::RenderingMode::Standard*/, const QString& multiWidgetName/* = "custommulti"*/) : QWidget(parent, f) , m_CustomMultiWidgetLayout(nullptr) , m_RenderingManager(renderingManager) , m_RenderingMode(renderingMode) , m_MultiWidgetName(multiWidgetName) , m_PendingCrosshairPositionEvent(false) , m_CrosshairNavigationEnabled(false) , m_DisplayActionEventBroadcast(nullptr) , m_StdDisplayActionEventHandler(nullptr) + , m_DataStorage(nullptr) { // create widget manually // create and set layout InitializeGUI(); - - resize(QSize(364, 477).expandedTo(minimumSizeHint())); - InitializeWidget(); InitializeDisplayActionEventHandling(); + resize(QSize(364, 477).expandedTo(minimumSizeHint())); } QmitkCustomMultiWidget::~QmitkCustomMultiWidget() { // nothing here } void QmitkCustomMultiWidget::SetDataStorage(mitk::DataStorage* dataStorage) { if (dataStorage == m_DataStorage) { return; } m_DataStorage = dataStorage; + // set new data storage for the render window widgets for (const auto& renderWindowWidget : m_RenderWindowWidgets) { renderWindowWidget.second->SetDataStorage(m_DataStorage); } } -void QmitkCustomMultiWidget::InitRenderWindowWidgets() +void QmitkCustomMultiWidget::InitializeRenderWindowWidgets() { - // create three render window (widgets) initially + // create render window (widgets) initially AddRenderWindowWidget(0, 0, "2015-01-14 - CT"); - AddRenderWindowWidget(0, 1, "2015-01-14 - MR"); - AddRenderWindowWidget(1, 0, "2015-08-19 - CT"); + /* + AddRenderWindowWidget(0, 1, "2015-08-19 - CT"); + AddRenderWindowWidget(0, 2, "2016-06-29 - CT"); + AddRenderWindowWidget(1, 0, "2015-01-14 - MR"); AddRenderWindowWidget(1, 1, "2015-08-19 - MR"); - AddRenderWindowWidget(2, 0, "2016-06-29 - CT"); - AddRenderWindowWidget(2, 1, "2016-06-29 - MR"); + AddRenderWindowWidget(1, 2, "2016-06-29 - MR"); + */ } QmitkCustomMultiWidget::RenderWindowWidgetMap QmitkCustomMultiWidget::GetRenderWindowWidgets() const { return m_RenderWindowWidgets; } QmitkRenderWindowWidget* QmitkCustomMultiWidget::GetRenderWindowWidget(const QString& widgetID) const { RenderWindowWidgetMap::const_iterator it = m_RenderWindowWidgets.find(widgetID); if (it == m_RenderWindowWidgets.end()) { return nullptr; } return it->second; } +void QmitkCustomMultiWidget::AddRenderWindowWidget(int row, int column, const std::string& cornerAnnotation/* = ""*/) +{ + // create the render window widget and connect signals / slots + mitk::UIDGenerator generator; + std::string renderWindowUID = generator.GetUID(); + QString UID = m_MultiWidgetName + "_" + QString::fromStdString(renderWindowUID); + QmitkRenderWindowWidget* renderWindowWidget = new QmitkRenderWindowWidget(this, UID, m_DataStorage); + renderWindowWidget->SetCornerAnnotationText(cornerAnnotation); + + // create connections + connect(renderWindowWidget, SIGNAL(ResetView()), this, SLOT(ResetCrosshair())); + connect(renderWindowWidget, SIGNAL(ChangeCrosshairRotationMode(int)), this, SLOT(SetWidgetPlaneMode(int))); + + // store the newly created render window widget with the UID + m_RenderWindowWidgets.insert(std::pair(UID, renderWindowWidget)); + + // add the newly created render window widget to this multi widget + m_CustomMultiWidgetLayout->addWidget(renderWindowWidget, row, column); +} + QmitkRenderWindow* QmitkCustomMultiWidget::GetRenderWindow(const QString& widgetID) const { QmitkRenderWindowWidget* renderWindowWidget = GetRenderWindowWidget(widgetID); if (nullptr != renderWindowWidget) { return renderWindowWidget->GetRenderWindow(); } return nullptr; } QmitkRenderWindowWidget* QmitkCustomMultiWidget::GetActiveRenderWindowWidget() const { //return m_ActiveRenderWindowWidget; return m_RenderWindowWidgets.begin()->second; } QmitkRenderWindowWidget* QmitkCustomMultiWidget::GetFirstRenderWindowWidget() const { - return m_RenderWindowWidgets.begin()->second; + if (!m_RenderWindowWidgets.empty()) + { + return m_RenderWindowWidgets.begin()->second; + } + else + { + return nullptr; + } } QmitkRenderWindowWidget* QmitkCustomMultiWidget::GetLastRenderWindowWidget() const { - return m_RenderWindowWidgets.rbegin()->second; + if (!m_RenderWindowWidgets.empty()) + { + return m_RenderWindowWidgets.rbegin()->second; + } + else + { + return nullptr; + } } unsigned int QmitkCustomMultiWidget::GetNumberOfRenderWindowWidgets() const { return m_RenderWindowWidgets.size(); } void QmitkCustomMultiWidget::RequestUpdate(const QString& widgetID) { QmitkRenderWindowWidget* renderWindowWidget = GetRenderWindowWidget(widgetID); if (nullptr != renderWindowWidget) { return renderWindowWidget->RequestUpdate(); } } void QmitkCustomMultiWidget::RequestUpdateAll() { - // #TODO: Update only render windows that show the same image? - // #TODO: Update only type specific render windows (2D / 3D)? for (const auto& renderWindowWidget : m_RenderWindowWidgets) { renderWindowWidget.second->RequestUpdate(); } } void QmitkCustomMultiWidget::ForceImmediateUpdate(const QString& widgetID) { QmitkRenderWindowWidget* renderWindowWidget = GetRenderWindowWidget(widgetID); if (nullptr != renderWindowWidget) { renderWindowWidget->ForceImmediateUpdate(); } } void QmitkCustomMultiWidget::ForceImmediateUpdateAll() { - // #TODO: Update only render windows that show the same image? - // #TODO: Update only type specific render windows (2D / 3D)? for (const auto& renderWindowWidget : m_RenderWindowWidgets) { renderWindowWidget.second->ForceImmediateUpdate(); } } mitk::MouseModeSwitcher* QmitkCustomMultiWidget::GetMouseModeSwitcher() { return m_MouseModeSwitcher; } const mitk::Point3D QmitkCustomMultiWidget::GetCrossPosition(const QString& widgetID) const { /* const mitk::PlaneGeometry *plane1 = mitkWidget1->GetSliceNavigationController()->GetCurrentPlaneGeometry(); const mitk::PlaneGeometry *plane2 = mitkWidget2->GetSliceNavigationController()->GetCurrentPlaneGeometry(); const mitk::PlaneGeometry *plane3 = mitkWidget3->GetSliceNavigationController()->GetCurrentPlaneGeometry(); mitk::Line3D line; if ((plane1 != NULL) && (plane2 != NULL) && (plane1->IntersectionLine(plane2, line))) { mitk::Point3D point; if ((plane3 != NULL) && (plane3->IntersectionPoint(line, point))) { return point; } } // TODO BUG POSITIONTRACKER; mitk::Point3D p; return p; // return m_LastLeftClickPositionSupplier->GetCurrentPoint(); */ return mitk::Point3D(); } ////////////////////////////////////////////////////////////////////////// // PUBLIC SLOTS ////////////////////////////////////////////////////////////////////////// void QmitkCustomMultiWidget::ShowLevelWindowWidget(const QString& widgetID, bool show) { QmitkRenderWindowWidget* renderWindowWidget = GetRenderWindowWidget(widgetID); if (nullptr != renderWindowWidget) { renderWindowWidget->ShowLevelWindowWidget(show); return; } MITK_ERROR << "Level window widget can not be shown for an unknown widget."; } void QmitkCustomMultiWidget::ShowAllLevelWindowWidgets(bool show) { for (const auto& renderWindowWidget : m_RenderWindowWidgets) { renderWindowWidget.second->ShowLevelWindowWidget(show); } } -void QmitkCustomMultiWidget::SetBackgroundColorGradient(const mitk::Color& upper, const mitk::Color& lower, const QString& widgetID) -{ - QmitkRenderWindowWidget* renderWindowWidget = GetRenderWindowWidget(widgetID); - if (nullptr != renderWindowWidget) - { - renderWindowWidget->SetBackgroundColorGradient(upper, lower); - return; - } - - MITK_ERROR << "Background color gradient can not be set for an unknown widget."; -} - -void QmitkCustomMultiWidget::SetAllBackgroundColorGradients(const mitk::Color& upper, const mitk::Color& lower) -{ - for (const auto& renderWindowWidget : m_RenderWindowWidgets) - { - renderWindowWidget.second->SetBackgroundColorGradient(upper, lower); - } -} - -void QmitkCustomMultiWidget::FillAllBackgroundColorGradientsWithBlack() -{ - float black[3] = { 0.0f, 0.0f, 0.0f }; - SetAllBackgroundColorGradients(black, black); -} - -void QmitkCustomMultiWidget::ShowBackgroundColorGradient(const QString& widgetID, bool show) -{ - QmitkRenderWindowWidget* renderWindowWidget = GetRenderWindowWidget(widgetID); - if (nullptr != renderWindowWidget) - { - renderWindowWidget->ShowBackgroundColorGradient(show); - return; - } - - MITK_ERROR << "Background color gradient can not be shown for an unknown widget."; -} - -void QmitkCustomMultiWidget::ShowAllBackgroundColorGradients(bool show) -{ - for (const auto& renderWindowWidget : m_RenderWindowWidgets) - { - renderWindowWidget.second->ShowBackgroundColorGradient(show); - } -} - -std::pair QmitkCustomMultiWidget::GetBackgroundColorGradient(const QString& widgetID) const -{ - QmitkRenderWindowWidget* renderWindowWidget = GetRenderWindowWidget(widgetID); - if (nullptr != renderWindowWidget) - { - return renderWindowWidget->GetRendererBackgroundColorGradient(); - } - - MITK_ERROR << "Background color gradient can not be retrieved for an unknown widget. Returning black color pair."; - float black[3] = { 0.0f, 0.0f, 0.0f }; - return std::make_pair(mitk::Color(black), mitk::Color(black)); -} - -bool QmitkCustomMultiWidget::GetBackgroundColorGradientFlag(const QString& widgetID) const -{ - QmitkRenderWindowWidget* renderWindowWidget = GetRenderWindowWidget(widgetID); - if (nullptr != renderWindowWidget) - { - return renderWindowWidget->GetBackgroundColorGradientFlag(); - } - - MITK_ERROR << "Background color gradient flag can not be retrieved for an unknown widget. Returning 'false'."; - return false; -} - -void QmitkCustomMultiWidget::SetDepartmentLogoPath(const char* path) -{ - /* old - m_LogoRendering->SetLogoImagePath(path); - mitk::BaseRenderer *renderer = mitk::BaseRenderer::GetInstance(mitkWidget4->GetRenderWindow()); - m_LogoRendering->Update(renderer); - RequestUpdate(); - */ - /* new - QImage* qimage = new QImage(path); - vtkSmartPointer qImageToVtk; - qImageToVtk = vtkSmartPointer::New(); - - qImageToVtk->SetQImage(qimage); - qImageToVtk->Update(); - - m_LogoRendering->SetLogoImage(qImageToVtk->GetOutput()); - mitk::BaseRenderer *renderer = mitk::BaseRenderer::GetInstance(mitkWidget4->GetRenderWindow()); - m_LogoRendering->Update(renderer); - RequestUpdate(); - */ -} - -void QmitkCustomMultiWidget::ShowDepartmentLogo(const QString& widgetID, bool show) -{ - QmitkRenderWindowWidget* renderWindowWidget = GetRenderWindowWidget(widgetID); - if (nullptr != renderWindowWidget) - { - GetRenderWindowWidget(widgetID)->ShowDepartmentLogo(show); - RequestUpdate(widgetID); - } - - MITK_ERROR << "Department logo can not be shown for an unknown widget."; - return; -} - -void QmitkCustomMultiWidget::ShowAllDepartmentLogos(bool show) -{ - for (const auto& renderWindowWidget : m_RenderWindowWidgets) - { - renderWindowWidget.second->ShowDepartmentLogo(show); - } -} - -void QmitkCustomMultiWidget::SetDecorationColor(const QString& widgetID, const mitk::Color& color) -{ - QmitkRenderWindowWidget* renderWindowWidget = GetRenderWindowWidget(widgetID); - if (nullptr != renderWindowWidget) - { - renderWindowWidget->SetDecorationColor(color); - } - - MITK_ERROR << "Decoration color can not be set for an unknown widget."; -} - -mitk::Color QmitkCustomMultiWidget::GetDecorationColor(const QString& widgetID) const -{ - QmitkRenderWindowWidget* renderWindowWidget = GetRenderWindowWidget(widgetID); - if (nullptr != renderWindowWidget) - { - renderWindowWidget->GetDecorationColor(); - } - - MITK_ERROR << "Decoration color can not be retrieved for an unknown widget. Returning black color!"; - float black[3] = { 0.0f, 0.0f, 0.0f }; - return mitk::Color(black); -} - -void QmitkCustomMultiWidget::ShowColoredRectangle(const QString& widgetID, bool show) -{ - QmitkRenderWindowWidget* renderWindowWidget = GetRenderWindowWidget(widgetID); - if (nullptr != renderWindowWidget) - { - renderWindowWidget->ShowColoredRectangle(show); - } - - MITK_ERROR << "Colored rectangle can not be set for an unknown widget."; -} - -void QmitkCustomMultiWidget::ShowAllColoredRectangles(bool show) -{ - for (const auto& renderWindowWidget : m_RenderWindowWidgets) - { - renderWindowWidget.second->ShowColoredRectangle(show); - } -} - -bool QmitkCustomMultiWidget::IsColoredRectangleVisible(const QString& widgetID) const -{ - QmitkRenderWindowWidget* renderWindowWidget = GetRenderWindowWidget(widgetID); - if (nullptr != renderWindowWidget) - { - renderWindowWidget->IsColoredRectangleVisible(); - } - - MITK_ERROR << "Colored rectangle visibility can not be retrieved for an unknown widget. Returning 'false'."; - return false; -} - -void QmitkCustomMultiWidget::SetCornerAnnotationText(const QString& widgetID, const std::string& cornerAnnotation) -{ - QmitkRenderWindowWidget* renderWindowWidget = GetRenderWindowWidget(widgetID); - if (nullptr != renderWindowWidget) - { - renderWindowWidget->SetCornerAnnotationText(cornerAnnotation); - } - - MITK_ERROR << "Corner annotation text can not be retrieved for an unknown widget."; -} - -std::string QmitkCustomMultiWidget::GetCornerAnnotationText(const QString& widgetID) const -{ - QmitkRenderWindowWidget* renderWindowWidget = GetRenderWindowWidget(widgetID); - if (nullptr != renderWindowWidget) - { - renderWindowWidget->GetCornerAnnotationText(); - } - - MITK_ERROR << "Corner annotation text can not be retrieved for an unknown widget."; - return ""; -} - -void QmitkCustomMultiWidget::ShowCornerAnnotation(const QString& widgetID, bool show) -{ - QmitkRenderWindowWidget* renderWindowWidget = GetRenderWindowWidget(widgetID); - if (nullptr != renderWindowWidget) - { - renderWindowWidget->ShowCornerAnnotation(show); - } - - MITK_ERROR << "Corner annotation can not be set for an unknown widget."; -} - -void QmitkCustomMultiWidget::ShowAllCornerAnnotations(bool show) -{ - for (const auto& renderWindowWidget : m_RenderWindowWidgets) - { - renderWindowWidget.second->ShowCornerAnnotation(show); - } -} - -bool QmitkCustomMultiWidget::IsCornerAnnotationVisible(const QString& widgetID) const -{ - QmitkRenderWindowWidget* renderWindowWidget = GetRenderWindowWidget(widgetID); - if (nullptr != renderWindowWidget) - { - renderWindowWidget->IsCornerAnnotationVisible(); - } - - MITK_ERROR << "Corner annotation visibility can not be retrieved for an unknown widget. Returning 'false'."; - return false; -} - void QmitkCustomMultiWidget::HandleCrosshairPositionEvent() { /* if (!m_PendingCrosshairPositionEvent) { m_PendingCrosshairPositionEvent = true; QTimer::singleShot(0, this, SLOT(HandleCrosshairPositionEventDelayed())); } */ } void QmitkCustomMultiWidget::HandleCrosshairPositionEventDelayed() { /* m_PendingCrosshairPositionEvent = false; // find image with highest layer mitk::TNodePredicateDataType::Pointer isImageData = mitk::TNodePredicateDataType::New(); mitk::DataStorage::SetOfObjects::ConstPointer nodes = this->m_DataStorage->GetSubset(isImageData).GetPointer(); mitk::DataNode::Pointer node; mitk::DataNode::Pointer topSourceNode; mitk::Image::Pointer image; bool isBinary = false; node = this->GetTopLayerNode(nodes); int component = 0; if (node.IsNotNull()) { node->GetBoolProperty("binary", isBinary); if (isBinary) { mitk::DataStorage::SetOfObjects::ConstPointer sourcenodes = m_DataStorage->GetSources(node, NULL, true); if (!sourcenodes->empty()) { topSourceNode = this->GetTopLayerNode(sourcenodes); } if (topSourceNode.IsNotNull()) { image = dynamic_cast(topSourceNode->GetData()); topSourceNode->GetIntProperty("Image.Displayed Component", component); } else { image = dynamic_cast(node->GetData()); node->GetIntProperty("Image.Displayed Component", component); } } else { image = dynamic_cast(node->GetData()); node->GetIntProperty("Image.Displayed Component", component); } } mitk::Point3D crosshairPos = this->GetCrossPosition(); std::string statusText; std::stringstream stream; itk::Index<3> p; mitk::BaseRenderer *baseRenderer = GetRenderWindow()->GetSliceNavigationController()->GetRenderer(); unsigned int timestep = baseRenderer->GetTimeStep(); if (image.IsNotNull() && (image->GetTimeSteps() > timestep)) { image->GetGeometry()->WorldToIndex(crosshairPos, p); stream.precision(2); stream << "Position: <" << std::fixed << crosshairPos[0] << ", " << std::fixed << crosshairPos[1] << ", " << std::fixed << crosshairPos[2] << "> mm"; stream << "; Index: <" << p[0] << ", " << p[1] << ", " << p[2] << "> "; mitk::ScalarType pixelValue; mitkPixelTypeMultiplex5(mitk::FastSinglePixelAccess, image->GetChannelDescriptor().GetPixelType(), image, image->GetVolumeData(baseRenderer->GetTimeStep()), p, pixelValue, component); if (fabs(pixelValue) > 1000000 || fabs(pixelValue) < 0.01) { stream << "; Time: " << baseRenderer->GetTime() << " ms; Pixelvalue: " << std::scientific << pixelValue << " "; } else { stream << "; Time: " << baseRenderer->GetTime() << " ms; Pixelvalue: " << pixelValue << " "; } } else { stream << "No image information at this position!"; } statusText = stream.str(); mitk::StatusBar::GetInstance()->DisplayGreyValueText(statusText.c_str()); */ } -void QmitkCustomMultiWidget::Fit() -{ - // #TODO: what is this function's purpose? - - /* - vtkSmartPointer vtkrenderer; - size_t numberOfRenderWindowWidgets = m_RenderWindowWidgets.size(); - for (size_t i = 0; i < numberOfRenderWindowWidgets; ++i) - { - vtkRenderer* renderer = GetRenderWindow(widgetID)->GetRenderer()->GetVtkRenderer(); - mitk::BaseRenderer* baseRenderer = mitk::BaseRenderer::GetInstance(GetRenderWindow(i)->GetRenderWindow()); - vtkrenderer = baseRenderer->GetVtkRenderer(); - if (nullptr != vtkrenderer) - { - vtkrenderer->ResetCamera(); - } - - baseRenderer->GetCameraController()->Fit(); - } - - int w = vtkObject::GetGlobalWarningDisplay(); - vtkObject::GlobalWarningDisplayOff(); - vtkObject::SetGlobalWarningDisplay(w); - */ -} - -void QmitkCustomMultiWidget::EnsureDisplayContainsPoint(mitk::BaseRenderer *renderer, const mitk::Point3D &p) -{ - // #TODO: what is this function's purpose? - - /* - mitk::Point2D pointOnDisplay; - renderer->WorldToDisplay(p, pointOnDisplay); - - if (pointOnDisplay[0] < renderer->GetVtkRenderer()->GetOrigin()[0] || - pointOnDisplay[1] < renderer->GetVtkRenderer()->GetOrigin()[1] || - pointOnDisplay[0] > renderer->GetVtkRenderer()->GetOrigin()[0] + renderer->GetViewportSize()[0] || - pointOnDisplay[1] > renderer->GetVtkRenderer()->GetOrigin()[1] + renderer->GetViewportSize()[1]) - { - mitk::Point2D pointOnPlane; - renderer->GetCurrentWorldPlaneGeometry()->Map(p, pointOnPlane); - renderer->GetCameraController()->MoveCameraToPoint(pointOnPlane); - } - */ -} - void QmitkCustomMultiWidget::MoveCrossToPosition(const QString& widgetID, const mitk::Point3D& newPosition) { QmitkRenderWindowWidget* renderWindowWidget = GetRenderWindowWidget(widgetID); if (nullptr != renderWindowWidget) { - GetRenderWindowWidget(widgetID)->GetSliceNavigationController()->SelectSliceByPoint(newPosition); - GetRenderWindowWidget(widgetID)->RequestUpdate(); + renderWindowWidget->GetSliceNavigationController()->SelectSliceByPoint(newPosition); + renderWindowWidget->RequestUpdate(); + return; } MITK_ERROR << "Geometry plane can not be shown for an unknown widget."; } void QmitkCustomMultiWidget::ResetCrosshair() { // #TODO: new concept: we do not want to initialize all views; // we do not want to rely on the geometry planes /* if (m_DataStorage.IsNotNull()) { m_RenderingManager->InitializeViewsByBoundingObjects(m_DataStorage); // m_RenderingManager->InitializeViews( m_DataStorage->ComputeVisibleBoundingGeometry3D() ); // reset interactor to normal slicing SetWidgetPlaneMode(PLANE_MODE_SLICING); } */ } ////////////////////////////////////////////////////////////////////////// // MOUSE EVENTS ////////////////////////////////////////////////////////////////////////// void QmitkCustomMultiWidget::wheelEvent(QWheelEvent* e) { emit WheelMoved(e); } void QmitkCustomMultiWidget::mousePressEvent(QMouseEvent* e) { } void QmitkCustomMultiWidget::moveEvent(QMoveEvent* e) { QWidget::moveEvent(e); - // it is necessary to readjust the position of the overlays as the StdMultiWidget has moved + // it is necessary to readjust the position of the overlays as the MultiWidget has moved // unfortunately it's not done by QmitkRenderWindow::moveEvent -> must be done here emit Moved(); } - ////////////////////////////////////////////////////////////////////////// // PRIVATE ////////////////////////////////////////////////////////////////////////// void QmitkCustomMultiWidget::InitializeGUI() { m_CustomMultiWidgetLayout = new QGridLayout(this); m_CustomMultiWidgetLayout->setContentsMargins(0, 0, 0, 0); setLayout(m_CustomMultiWidgetLayout); } void QmitkCustomMultiWidget::InitializeWidget() { // #TODO: some things have to be handled globally (hold for all render window (widgets) // analyse those things and design a controlling mechanism // necessary here? mouse mode is valid for all render windows (and also used in editor) //m_MouseModeSwitcher = mitk::MouseModeSwitcher::New(); //m_MouseModeSwitcher->SetInteractionScheme(mitk::MouseModeSwitcher::InteractionScheme::MITK); - - // setup the department logo rendering - /* - m_LogoRendering = mitk::LogoOverlay::New(); - mitk::BaseRenderer::Pointer renderer4 = mitk::BaseRenderer::GetInstance(mitkWidget4->GetRenderWindow()); - m_LogoRendering->SetOpacity(0.5); - mitk::Point2D offset; - offset.Fill(0.03); - m_LogoRendering->SetOffsetVector(offset); - m_LogoRendering->SetRelativeSize(0.15); - m_LogoRendering->SetCornerPosition(1); - m_LogoRendering->SetLogoImagePath("DefaultLogo"); - renderer4->GetOverlayManager()->AddOverlay(m_LogoRendering.GetPointer(), renderer4); - */ } void QmitkCustomMultiWidget::InitializeDisplayActionEventHandling() { m_DisplayActionEventBroadcast = mitk::DisplayActionEventBroadcast::New(); m_DisplayActionEventBroadcast->LoadStateMachine("DisplayInteraction.xml"); m_DisplayActionEventBroadcast->SetEventConfig("DisplayConfigPACS.xml"); m_StdDisplayActionEventHandler = std::make_unique(); m_StdDisplayActionEventHandler->SetObservableBroadcast(m_DisplayActionEventBroadcast); m_StdDisplayActionEventHandler->InitStdActions(); } -void QmitkCustomMultiWidget::AddRenderWindowWidget(int column, int row, const std::string& cornerAnnotation/* = ""*/) -{ - // #TODO: add QSplitter? - // #TODO: include technique, to set the image to level-slide on using the render window manager - - // create the render window widget and connect signals / slots - mitk::UIDGenerator generator; - std::string renderWindowUID = generator.GetUID(); - QString UID = m_MultiWidgetName + "_" + QString::fromStdString(renderWindowUID); - QmitkRenderWindowWidget* renderWindowWidget = new QmitkRenderWindowWidget(this, UID, m_DataStorage); - renderWindowWidget->SetCornerAnnotationText(cornerAnnotation); - - // create connections - connect(renderWindowWidget, SIGNAL(ResetView()), this, SLOT(ResetCrosshair())); - connect(renderWindowWidget, SIGNAL(ChangeCrosshairRotationMode(int)), this, SLOT(SetWidgetPlaneMode(int))); - - // store the newly created render window widget with the UID - m_RenderWindowWidgets.insert(std::pair(UID, renderWindowWidget)); - - // #TODO: define the grid cell to add the new render window widget - // add the newly created render window widget to this multi widget - m_CustomMultiWidgetLayout->addWidget(renderWindowWidget, row, column); - - /* - auto callback = [](const itk::EventObject& displayInteractorEvent) - { - if (mitk::DisplayZoomEvent().CheckEvent(&displayInteractorEvent)) - { - std::cout << "Success: CheckEvent" << std::endl; - } - - std::cout << "lambda called" << std::endl; - }; - - m_CustomDisplayActionEventHandler->ConnectDisplayActionEvent(mitk::DisplayZoomEvent(nullptr, 0, mitk::Point2D()), std::move(callback)); - */ -} - mitk::DataNode::Pointer QmitkCustomMultiWidget::GetTopLayerNode(mitk::DataStorage::SetOfObjects::ConstPointer nodes) { // #TODO: see T24173 return nodes->front(); } diff --git a/Modules/QtWidgets/src/QmitkRenderWindowWidget.cpp b/Modules/QtWidgets/src/QmitkRenderWindowWidget.cpp index 87a6766adf..a7e99d6c1e 100644 --- a/Modules/QtWidgets/src/QmitkRenderWindowWidget.cpp +++ b/Modules/QtWidgets/src/QmitkRenderWindowWidget.cpp @@ -1,235 +1,229 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical Image Computing. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmitkRenderWindowWidget.h" // vtk #include // qt widgets module #include -QmitkRenderWindowWidget::QmitkRenderWindowWidget(QWidget* parent/* = nullptr*/, const QString& UID/* = ""*/, mitk::DataStorage* dataStorage/* = nullptr*/) +QmitkRenderWindowWidget::QmitkRenderWindowWidget(QWidget* parent/* = nullptr*/, + const QString& UID/* = ""*/, + mitk::DataStorage* dataStorage/* = nullptr*/, + mitk::BaseRenderer::RenderingMode::Type renderingMode/* = mitk::BaseRenderer::RenderingMode::Standard*/) : QWidget(parent) , m_UID(UID) , m_DataStorage(dataStorage) + , m_RenderingMode(renderingMode) , m_RenderWindow(nullptr) , m_LevelWindowWidget(nullptr) { InitializeGUI(); // TODO: signals / slots } QmitkRenderWindowWidget::~QmitkRenderWindowWidget() { // nothing here } void QmitkRenderWindowWidget::SetDataStorage(mitk::DataStorage* dataStorage) { if (dataStorage == m_DataStorage) { return; } m_DataStorage = dataStorage; if (nullptr != m_RenderWindow) { mitk::BaseRenderer::GetInstance(m_RenderWindow->GetRenderWindow())->SetDataStorage(dataStorage); } } mitk::SliceNavigationController* QmitkRenderWindowWidget::GetSliceNavigationController() const { if (nullptr == m_RenderWindow) { return nullptr; } return m_RenderWindow->GetSliceNavigationController(); } void QmitkRenderWindowWidget::RequestUpdate() { m_RenderingManager->RequestUpdate(m_RenderWindow->GetRenderWindow()); } void QmitkRenderWindowWidget::ForceImmediateUpdate() { m_RenderingManager->ForceImmediateUpdate(m_RenderWindow->GetRenderWindow()); } -void QmitkRenderWindowWidget::SetBackgroundColorGradient(const mitk::Color& upper, const mitk::Color& lower) +void QmitkRenderWindowWidget::SetGradientBackgroundColors(const mitk::Color& upper, const mitk::Color& lower) { vtkRenderer* vtkRenderer = m_RenderWindow->GetRenderer()->GetVtkRenderer(); if (nullptr == vtkRenderer) { return; } - m_BackgroundColorGradient.first = upper; - m_BackgroundColorGradient.second = lower; + m_GradientBackgroundColors.first = upper; + m_GradientBackgroundColors.second = lower; vtkRenderer->SetBackground(lower[0], lower[1], lower[2]); vtkRenderer->SetBackground2(upper[0], upper[1], upper[2]); - ShowBackgroundColorGradient(true); + ShowGradientBackground(true); } -void QmitkRenderWindowWidget::ShowBackgroundColorGradient(bool show) +void QmitkRenderWindowWidget::ShowGradientBackground(bool show) { - if (show) - { - m_RenderWindow->GetRenderer()->GetVtkRenderer()->GradientBackgroundOn(); - } - else - { - m_RenderWindow->GetRenderer()->GetVtkRenderer()->GradientBackgroundOff(); + m_RenderWindow->GetRenderer()->GetVtkRenderer()->SetGradientBackground(show); +} - } - m_BackgroundColorGradientFlag = show; +bool QmitkRenderWindowWidget::IsGradientBackgroundOn() const +{ + return m_RenderWindow->GetRenderer()->GetVtkRenderer()->GetGradientBackground(); } void QmitkRenderWindowWidget::ShowLevelWindowWidget(bool show) { m_LevelWindowWidget->disconnect(this); if (show) { m_LevelWindowWidget->SetDataStorage(m_DataStorage); m_LevelWindowWidget->show(); } else { m_LevelWindowWidget->disconnect(this); m_LevelWindowWidget->hide(); } } -void QmitkRenderWindowWidget::ShowDepartmentLogo(bool show) -{ - m_LogoAnnotation->SetVisibility(show); -} - void QmitkRenderWindowWidget::SetDecorationColor(const mitk::Color& color) { m_DecorationColor = color; m_RectangleProp->SetColor(m_DecorationColor[0], m_DecorationColor[1], m_DecorationColor[2]); m_CornerAnnotation->GetTextProperty()->SetColor(color[0], color[1], color[2]); } void QmitkRenderWindowWidget::ShowColoredRectangle(bool show) { m_RectangleProp->SetVisibility(show); } bool QmitkRenderWindowWidget::IsColoredRectangleVisible() const { return m_RectangleProp->GetVisibility() > 0; } void QmitkRenderWindowWidget::ShowCornerAnnotation(bool show) { m_CornerAnnotation->SetVisibility(show); } bool QmitkRenderWindowWidget::IsCornerAnnotationVisible() const { return m_CornerAnnotation->GetVisibility() > 0; } void QmitkRenderWindowWidget::SetCornerAnnotationText(const std::string& cornerAnnotation) { m_CornerAnnotation->SetText(0, cornerAnnotation.c_str()); } std::string QmitkRenderWindowWidget::GetCornerAnnotationText() const { return std::string(m_CornerAnnotation->GetText(0)); } bool QmitkRenderWindowWidget::IsRenderWindowMenuActivated() const { return m_RenderWindow->GetActivateMenuWidgetFlag(); } void QmitkRenderWindowWidget::InitializeGUI() { m_Layout = new QHBoxLayout(this); m_Layout->setMargin(0); setLayout(m_Layout); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); // create render window for this render window widget m_RenderingManager = mitk::RenderingManager::GetInstance(); //m_RenderingManager = mitk::RenderingManager::New(); m_RenderingManager->SetDataStorage(m_DataStorage); - m_RenderingMode = mitk::BaseRenderer::RenderingMode::Standard; // TODO: do not always use the standard rendering mode m_RenderWindow = new QmitkRenderWindow(this, m_UID, nullptr, m_RenderingManager, m_RenderingMode); m_RenderWindow->SetLayoutIndex(QmitkCustomMultiWidget::SAGITTAL); // TODO: allow to change layout type later m_RenderWindow->GetSliceNavigationController()->SetDefaultViewDirection(mitk::SliceNavigationController::Sagittal); m_RenderWindow->GetSliceNavigationController()->SetRenderingManager(m_RenderingManager); mitk::TimeGeometry::Pointer timeGeometry = m_DataStorage->ComputeBoundingGeometry3D(m_DataStorage->GetAll()); m_RenderingManager->InitializeViews(timeGeometry); // create level window widget for this render window widget m_LevelWindowWidget = new QmitkLevelWindowWidget(this); //m_LevelWindowWidget->setObjectName(QString::fromUtf8("levelWindowWidget")); QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); sizePolicy.setHorizontalStretch(0); sizePolicy.setVerticalStretch(0); sizePolicy.setHeightForWidth(m_LevelWindowWidget->sizePolicy().hasHeightForWidth()); m_LevelWindowWidget->setSizePolicy(sizePolicy); m_LevelWindowWidget->setMaximumWidth(50); m_Layout->addWidget(m_RenderWindow); m_Layout->addWidget(m_LevelWindowWidget); - // set colors, add logo etc. + // set colors and corner annotation InitializeDecorations(); } void QmitkRenderWindowWidget::InitializeDecorations() { vtkRenderer* vtkRenderer = m_RenderWindow->GetRenderer()->GetVtkRenderer(); if (nullptr == vtkRenderer) { return; } // initialize background color gradients float black[3] = { 0.0f, 0.0f, 0.0f }; - SetBackgroundColorGradient(black, black); + SetGradientBackgroundColors(black, black); // initialize decoration color, rectangle and annotation text float white[3] = { 1.0f, 1.0f, 1.0f }; m_DecorationColor = white; m_RectangleProp = vtkSmartPointer::New(); m_RectangleProp->SetColor(m_DecorationColor[0], m_DecorationColor[1], m_DecorationColor[2]); if (0 == vtkRenderer->HasViewProp(m_RectangleProp)) { vtkRenderer->AddViewProp(m_RectangleProp); } m_CornerAnnotation = vtkSmartPointer::New(); m_CornerAnnotation->SetText(0, "Sagittal"); m_CornerAnnotation->SetMaximumFontSize(12); m_CornerAnnotation->GetTextProperty()->SetColor(m_DecorationColor[0], m_DecorationColor[1], m_DecorationColor[2]); if (0 == vtkRenderer->HasViewProp(m_CornerAnnotation)) { vtkRenderer->AddViewProp(m_CornerAnnotation); } } \ No newline at end of file diff --git a/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/files.cmake b/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/files.cmake index c90583e4b3..79481c4266 100644 --- a/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/files.cmake +++ b/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/files.cmake @@ -1,35 +1,36 @@ set(SRC_CPP_FILES QmitkCustomMultiWidgetEditor.cpp + QmitkMultiWidgetDecorationManager.cpp ) set(INTERNAL_CPP_FILES mitkPluginActivator.cpp QmitkCustomMultiWidgetEditorPreferencePage.cpp ) set(UI_FILES src/internal/QmitkCustomMultiWidgetEditorPreferencePage.ui ) set(MOC_H_FILES src/QmitkCustomMultiWidgetEditor.h src/internal/mitkPluginActivator.h src/internal/QmitkCustomMultiWidgetEditorPreferencePage.h ) set(CACHED_RESOURCE_FILES resources/CustomMultiWidgetEditor.svg plugin.xml ) set(QRC_FILES ) foreach(file ${SRC_CPP_FILES}) set(CPP_FILES ${CPP_FILES} src/${file}) endforeach(file ${SRC_CPP_FILES}) foreach(file ${INTERNAL_CPP_FILES}) set(CPP_FILES ${CPP_FILES} src/internal/${file}) endforeach(file ${INTERNAL_CPP_FILES}) diff --git a/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/resources/QmitkCustomMultiWidgetEditor.qrc b/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/resources/QmitkCustomMultiWidgetEditor.qrc new file mode 100644 index 0000000000..64a1a29379 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/resources/QmitkCustomMultiWidgetEditor.qrc @@ -0,0 +1,5 @@ + + + defaultWatermark.png + + diff --git a/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/resources/defaultWatermark.png b/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/resources/defaultWatermark.png new file mode 100644 index 0000000000..927adce68d Binary files /dev/null and b/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/resources/defaultWatermark.png differ diff --git a/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/src/QmitkCustomMultiWidgetEditor.cpp b/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/src/QmitkCustomMultiWidgetEditor.cpp index cf88bf34e7..d4a89a0331 100644 --- a/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/src/QmitkCustomMultiWidgetEditor.cpp +++ b/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/src/QmitkCustomMultiWidgetEditor.cpp @@ -1,449 +1,206 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical Image Computing. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmitkCustomMultiWidgetEditor.h" #include #include #include #include #include -#include +// mitk core #include #include -#include -#include - -#include - - const QString QmitkCustomMultiWidgetEditor::EDITOR_ID = "org.mitk.editors.custommultiwidget"; QmitkCustomMultiWidgetEditor::QmitkCustomMultiWidgetEditor() : m_CustomMultiWidget(nullptr) , m_MouseModeSwitcher(nullptr) { // nothing here } QmitkCustomMultiWidgetEditor::~QmitkCustomMultiWidgetEditor() { // nothing here } void QmitkCustomMultiWidgetEditor::Activated() { // nothing here } void QmitkCustomMultiWidgetEditor::Deactivated() { // nothing here } void QmitkCustomMultiWidgetEditor::Visible() { // nothing here } void QmitkCustomMultiWidgetEditor::Hidden() { // nothing here } QmitkRenderWindow* QmitkCustomMultiWidgetEditor::GetActiveQmitkRenderWindow() const { if (nullptr != m_CustomMultiWidget) { return m_CustomMultiWidget->GetActiveRenderWindowWidget()->GetRenderWindow(); } return nullptr; } QHash QmitkCustomMultiWidgetEditor::GetQmitkRenderWindows() const { QHash result; if (nullptr == m_CustomMultiWidget) { return result; } // create QHash on demand QmitkCustomMultiWidget::RenderWindowWidgetMap renderWindowWidgets = m_CustomMultiWidget->GetRenderWindowWidgets(); for (const auto& renderWindowWidget : renderWindowWidgets) { result.insert(renderWindowWidget.first, renderWindowWidget.second->GetRenderWindow()); } return result; } QmitkRenderWindow* QmitkCustomMultiWidgetEditor::GetQmitkRenderWindow(const QString& id) const { if (nullptr == m_CustomMultiWidget) { return nullptr; } return m_CustomMultiWidget->GetRenderWindow(id); } mitk::Point3D QmitkCustomMultiWidgetEditor::GetSelectedPosition(const QString& id) const { if (nullptr == m_CustomMultiWidget) { return mitk::Point3D(); } return m_CustomMultiWidget->GetCrossPosition(id); } void QmitkCustomMultiWidgetEditor::SetSelectedPosition(const mitk::Point3D& pos, const QString& id) { if (nullptr != m_CustomMultiWidget) { m_CustomMultiWidget->MoveCrossToPosition(id, pos); } } -void QmitkCustomMultiWidgetEditor::EnableDecorations(bool enable, const QStringList &decorations) +void QmitkCustomMultiWidgetEditor::EnableDecorations(bool enable, const QStringList& decorations) { - // #TODO: define: - for all render windows - // - for the one, active render window - // MOVE TO DECORATION MANAGER - - if (decorations.isEmpty() || decorations.contains(DECORATION_BORDER)) - { - m_CustomMultiWidget->ShowAllColoredRectangles(enable); - } - if (decorations.isEmpty() || decorations.contains(DECORATION_LOGO)) - { - m_CustomMultiWidget->ShowAllDepartmentLogos(enable); - } - if (decorations.isEmpty() || decorations.contains(DECORATION_MENU)) - { - //m_Impl->m_CustomMultiWidget->ActivateAllRenderWindowMenus(enable); - } - if (decorations.isEmpty() || decorations.contains(DECORATION_BACKGROUND)) - { - m_CustomMultiWidget->ShowAllBackgroundColorGradients(enable); - } - if (decorations.isEmpty() || decorations.contains(DECORATION_CORNER_ANNOTATION)) - { - m_CustomMultiWidget->ShowAllCornerAnnotations(enable); - } + m_MultiWidgetDecorationManager->ShowDecorations(enable, decorations); } -bool QmitkCustomMultiWidgetEditor::IsDecorationEnabled(const QString &decoration) const +bool QmitkCustomMultiWidgetEditor::IsDecorationEnabled(const QString& decoration) const { - // #TODO: define: - for all render windows - // - for the one, active render window - // MOVE TO DECORATION MANAGER - /* - if (decoration == DECORATION_BORDER) - { - return m_Impl->m_CustomMultiWidget->IsColoredRectanglesEnabled(); - } - else if (decoration == DECORATION_LOGO) - { - return m_Impl->m_CustomMultiWidget->IsColoredRectanglesEnabled(); - } - else if (decoration == DECORATION_MENU) - { - return m_Impl->m_CustomMultiWidget->IsRenderWindowWidgetMenuEnabled(); - } - else if (decoration == DECORATION_BACKGROUND) - { - return m_Impl->m_CustomMultiWidget->GetGradientBackgroundFlag(); - } - else if (decoration == DECORATION_CORNER_ANNOTATION) - { - return m_Impl->m_CustomMultiWidget->IsCornerAnnotationVisible(); - } - */ - return false; + return m_MultiWidgetDecorationManager->IsDecorationVisible(decoration); } QStringList QmitkCustomMultiWidgetEditor::GetDecorations() const { - // MOVE TO DECORATION MANAGER - - QStringList decorations; - decorations << DECORATION_BORDER << DECORATION_LOGO << DECORATION_MENU << DECORATION_BACKGROUND << DECORATION_CORNER_ANNOTATION; - return decorations; + return m_MultiWidgetDecorationManager->GetDecorations(); } void QmitkCustomMultiWidgetEditor::EnableSlicingPlanes(bool enable) { // #TODO: nothing here } bool QmitkCustomMultiWidgetEditor::IsSlicingPlanesEnabled() const { // #TODO: nothing here return false; } QmitkCustomMultiWidget* QmitkCustomMultiWidgetEditor::GetCustomMultiWidget() { return m_CustomMultiWidget; } void QmitkCustomMultiWidgetEditor::SetFocus() { if (nullptr != m_CustomMultiWidget) { m_CustomMultiWidget->setFocus(); } } -void QmitkCustomMultiWidgetEditor::OnPreferencesChanged(const berry::IBerryPreferences* preferences) -{ - // MOVE TO DECORATION MANAGER - - // Enable change of logo. If no DepartmentLogo was set explicitly, MBILogo is used. - // Set new department logo by prefs->Set("DepartmentLogo", "PathToImage"); - - // If no logo was set for this plug-in specifically, walk the parent preference nodes - // and lookup a logo value there. - /* - const berry::IPreferences* currentNode = preferences; - - while(currentNode) - { - bool logoFound = false; - foreach (const QString& key, currentNode->Keys()) - { - if( key == "DepartmentLogo") - { - QString departmentLogoLocation = currentNode->Get("DepartmentLogo", ""); - - if (departmentLogoLocation.isEmpty()) - { - m_Impl->m_CustomMultiWidget->ShowDepartmentLogo(false); - } - else - { - // we need to disable the logo first, otherwise setting a new logo will have - // no effect due to how mitkManufacturerLogo works... - m_Impl->m_CustomMultiWidget->DisableDepartmentLogo(); - m_Impl->m_CustomMultiWidget->SetDepartmentLogoPath(qPrintable(departmentLogoLocation)); - m_Impl->m_CustomMultiWidget->EnableDepartmentLogo(); - } - logoFound = true; - break; - } - } - - if (logoFound) - { - break; - } - currentNode = currentNode->Parent().GetPointer(); - } - */ - - // Update internal members - FillMembersWithCurrentDecorations(); - GetPreferenceDecorations(preferences); - - // MOVE TO DECORATION MANAGER - /* - // preferences for renderWindows - for(unsigned int i = 0; i < 4; ++i) - { - // set background color gradient - mitk::Color upper = HexColorToMitkColor(m_Impl->m_WidgetBackgroundColor1[i]); - mitk::Color lower = HexColorToMitkColor(m_Impl->m_WidgetBackgroundColor2[i]); - m_Impl->m_CustomMultiWidget->SetBackgroundColorGradient(upper, lower, i); - m_Impl->m_CustomMultiWidget->ShowBackgroundColorGradient(i, true); - - // set decoration color and corner annotation text - mitk::Color colorDecorationWidget = HexColorToMitkColor(m_Impl->m_WidgetDecorationColor[i]); - m_Impl->m_CustomMultiWidget->SetDecorationColor(i, colorDecorationWidget); - m_Impl->m_CustomMultiWidget->SetCornerAnnotationText(i, m_Impl->m_WidgetAnnotation[i].toStdString()); - - // enable colored rectangle - m_Impl->m_CustomMultiWidget->ShowColoredRectangle(i, true); - } - */ - - // Set preferences respecting zooming and panning - bool constrainedZooming = preferences->GetBool("Use constrained zooming and panning", true); - - mitk::RenderingManager::GetInstance()->SetConstrainedPanningZooming(constrainedZooming); - - mitk::RenderingManager::GetInstance()->InitializeViewsByBoundingObjects(this->GetDataStorage()); - - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); - - // level window setting - bool showLevelWindowWidget = preferences->GetBool("Show level-window widget", true); - if (showLevelWindowWidget) - { - m_CustomMultiWidget->ShowAllLevelWindowWidgets(true); - } - else - { - m_CustomMultiWidget->ShowAllLevelWindowWidgets(false); - } -} - void QmitkCustomMultiWidgetEditor::CreateQtPartControl(QWidget* parent) { if (nullptr == m_CustomMultiWidget) { QHBoxLayout* layout = new QHBoxLayout(parent); layout->setContentsMargins(0, 0, 0, 0); - berry::IPreferences::Pointer prefs = GetPreferences(); - mitk::BaseRenderer::RenderingMode::Type renderingMode = static_cast(prefs->GetInt("Rendering Mode", 0)); + berry::IBerryPreferences* preferences = dynamic_cast(GetPreferences().GetPointer()); + mitk::BaseRenderer::RenderingMode::Type renderingMode = static_cast(preferences->GetInt("Rendering Mode", 0)); + + m_CustomMultiWidget = new QmitkCustomMultiWidget(parent, 0, 0, renderingMode); + // create left toolbar: mouse mode toolbar to switch how the render window navigation behaves if (nullptr == m_MouseModeSwitcher) { m_MouseModeSwitcher = new QmitkMouseModeSwitcher(parent); layout->addWidget(m_MouseModeSwitcher); } + m_MouseModeSwitcher->setMouseModeSwitcher(m_CustomMultiWidget->GetMouseModeSwitcher()); - m_CustomMultiWidget = new QmitkCustomMultiWidget(parent, 0, 0, renderingMode); + // add center widget: the custom multi widget layout->addWidget(m_CustomMultiWidget); - m_MouseModeSwitcher->setMouseModeSwitcher(m_CustomMultiWidget->GetMouseModeSwitcher()); - m_CustomMultiWidget->SetDataStorage(GetDataStorage()); - m_CustomMultiWidget->InitRenderWindowWidgets(); - - m_CustomMultiWidget->ShowAllLevelWindowWidgets(true); - - // Store the initial visibility status of the menu widget. - //m_Impl->m_MenuWidgetsEnabled = m_Impl->m_CustomMultiWidget->IsRenderWindowMenuActivated(0); - - berry::IBerryPreferences* berryprefs = dynamic_cast(prefs.GetPointer()); - InitializePreferences(berryprefs); - OnPreferencesChanged(berryprefs); + m_CustomMultiWidget->InitializeRenderWindowWidgets(); - RequestUpdate(); - } -} -void QmitkCustomMultiWidgetEditor::InitializePreferences(berry::IBerryPreferences* preferences) -{ - /* - FillMembersWithCurrentDecorations(); // fill members - GetPreferenceDecorations(preferences); // overwrite if preferences are defined - - //create new preferences - preferences->Put("widget1 corner annotation", m_Impl->m_WidgetAnnotation[0]); - preferences->Put("widget2 corner annotation", m_Impl->m_WidgetAnnotation[1]); - preferences->Put("widget3 corner annotation", m_Impl->m_WidgetAnnotation[2]); - preferences->Put("widget4 corner annotation", m_Impl->m_WidgetAnnotation[3]); - - preferences->Put("widget1 decoration color", m_Impl->m_WidgetDecorationColor[0]); - preferences->Put("widget2 decoration color", m_Impl->m_WidgetDecorationColor[1]); - preferences->Put("widget3 decoration color", m_Impl->m_WidgetDecorationColor[2]); - preferences->Put("widget4 decoration color", m_Impl->m_WidgetDecorationColor[3]); - - preferences->Put("widget1 first background color", m_Impl->m_WidgetBackgroundColor1[0]); - preferences->Put("widget2 first background color", m_Impl->m_WidgetBackgroundColor1[1]); - preferences->Put("widget3 first background color", m_Impl->m_WidgetBackgroundColor1[2]); - preferences->Put("widget4 first background color", m_Impl->m_WidgetBackgroundColor1[3]); - preferences->Put("widget1 second background color", m_Impl->m_WidgetBackgroundColor2[0]); - preferences->Put("widget2 second background color", m_Impl->m_WidgetBackgroundColor2[1]); - preferences->Put("widget3 second background color", m_Impl->m_WidgetBackgroundColor2[2]); - preferences->Put("widget4 second background color", m_Impl->m_WidgetBackgroundColor2[3]); - */ -} + m_MultiWidgetDecorationManager = std::make_unique(m_CustomMultiWidget); -void QmitkCustomMultiWidgetEditor::FillMembersWithCurrentDecorations() -{ - /* - //fill members with current values (or default values) from the std multi widget - for(unsigned int i = 0; i < 4; ++i) - { - m_Impl->m_WidgetDecorationColor[i] = MitkColorToHexColor(m_Impl->m_CustomMultiWidget->GetDecorationColor(i)); - m_Impl->m_WidgetBackgroundColor1[i] = MitkColorToHexColor(m_Impl->m_CustomMultiWidget->GetBackgroundColorGradient(i).first); - m_Impl->m_WidgetBackgroundColor2[i] = MitkColorToHexColor(m_Impl->m_CustomMultiWidget->GetBackgroundColorGradient(i).second); - m_Impl->m_WidgetAnnotation[i] = QString::fromStdString(m_Impl->m_CustomMultiWidget->GetCornerAnnotationText(i)); + OnPreferencesChanged(preferences); } - */ } -void QmitkCustomMultiWidgetEditor::GetPreferenceDecorations(const berry::IBerryPreferences * preferences) -{ - /* - // MOVE TO DECORATION MANAGER - - //overwrite members with values from the preferences, if they the preference is defined - m_Impl->m_WidgetBackgroundColor1[0] = preferences->Get("widget1 first background color", m_Impl->m_WidgetBackgroundColor1[0]); - m_Impl->m_WidgetBackgroundColor2[0] = preferences->Get("widget1 second background color", m_Impl->m_WidgetBackgroundColor2[0]); - m_Impl->m_WidgetBackgroundColor1[1] = preferences->Get("widget2 first background color", m_Impl->m_WidgetBackgroundColor1[1]); - m_Impl->m_WidgetBackgroundColor2[1] = preferences->Get("widget2 second background color", m_Impl->m_WidgetBackgroundColor2[1]); - m_Impl->m_WidgetBackgroundColor1[2] = preferences->Get("widget3 first background color", m_Impl->m_WidgetBackgroundColor1[2]); - m_Impl->m_WidgetBackgroundColor2[2] = preferences->Get("widget3 second background color", m_Impl->m_WidgetBackgroundColor2[2]); - m_Impl->m_WidgetBackgroundColor1[3] = preferences->Get("widget4 first background color", m_Impl->m_WidgetBackgroundColor1[3]); - m_Impl->m_WidgetBackgroundColor2[3] = preferences->Get("widget4 second background color", m_Impl->m_WidgetBackgroundColor2[3]); - - m_Impl->m_WidgetDecorationColor[0] = preferences->Get("widget1 decoration color", m_Impl->m_WidgetDecorationColor[0]); - m_Impl->m_WidgetDecorationColor[1] = preferences->Get("widget2 decoration color", m_Impl->m_WidgetDecorationColor[1]); - m_Impl->m_WidgetDecorationColor[2] = preferences->Get("widget3 decoration color", m_Impl->m_WidgetDecorationColor[2]); - m_Impl->m_WidgetDecorationColor[3] = preferences->Get("widget4 decoration color", m_Impl->m_WidgetDecorationColor[3]); - - m_Impl->m_WidgetAnnotation[0] = preferences->Get("widget1 corner annotation", m_Impl->m_WidgetAnnotation[0]); - m_Impl->m_WidgetAnnotation[1] = preferences->Get("widget2 corner annotation", m_Impl->m_WidgetAnnotation[1]); - m_Impl->m_WidgetAnnotation[2] = preferences->Get("widget3 corner annotation", m_Impl->m_WidgetAnnotation[2]); - m_Impl->m_WidgetAnnotation[3] = preferences->Get("widget4 corner annotation", m_Impl->m_WidgetAnnotation[3]); - */ -} - -mitk::Color QmitkCustomMultiWidgetEditor::HexColorToMitkColor(const QString& hexColor) +void QmitkCustomMultiWidgetEditor::OnPreferencesChanged(const berry::IBerryPreferences* preferences) { - // MOVE TO DECORATION MANAGER - - QColor qColor(hexColor); - mitk::Color returnColor; - float colorMax = 255.0f; - if (hexColor.isEmpty()) // default value - { - returnColor[0] = 1.0; - returnColor[1] = 1.0; - returnColor[2] = 1.0; - MITK_ERROR << "Using default color for unknown hex string " << qPrintable(hexColor); - } - else - { - returnColor[0] = qColor.red() / colorMax; - returnColor[1] = qColor.green() / colorMax; - returnColor[2] = qColor.blue() / colorMax; - } - - return returnColor; -} + // update decoration preferences + m_MultiWidgetDecorationManager->DecorationPreferencesChanged(preferences); -QString QmitkCustomMultiWidgetEditor::MitkColorToHexColor(const mitk::Color& mitkColor) -{ - // MOVE TO DECORATION MANAGER + // zooming and panning preferences + bool constrainedZooming = preferences->GetBool("Use constrained zooming and panning", true); + mitk::RenderingManager::GetInstance()->SetConstrainedPanningZooming(constrainedZooming); - QColor returnColor; - float colorMax = 255.0f; - returnColor.setRed(static_cast(mitkColor[0] * colorMax + 0.5)); - returnColor.setGreen(static_cast(mitkColor[1] * colorMax + 0.5)); - returnColor.setBlue(static_cast(mitkColor[2] * colorMax + 0.5)); + // level window preferences + bool showLevelWindowWidget = preferences->GetBool("Show level-window widget", true); + m_CustomMultiWidget->ShowAllLevelWindowWidgets(showLevelWindowWidget); - return returnColor.name(); + mitk::RenderingManager::GetInstance()->InitializeViewsByBoundingObjects(GetDataStorage()); + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } diff --git a/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/src/QmitkCustomMultiWidgetEditor.h b/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/src/QmitkCustomMultiWidgetEditor.h index 9f680aff21..43f0376588 100644 --- a/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/src/QmitkCustomMultiWidgetEditor.h +++ b/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/src/QmitkCustomMultiWidgetEditor.h @@ -1,167 +1,135 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical Image Computing. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef QMITKCUSTOMMULTIWIDGETEDITOR_H #define QMITKCUSTOMMULTIWIDGETEDITOR_H #include #include #include // custom multi widget editor #include +#include "QmitkMultiWidgetDecorationManager.h" + // qt widgets module #include +#include #include -class QmitkCustomMultiWidget; class QmitkMouseModeSwitcher; class CUSTOMMULTIWIDGETEDITOR_EXPORT QmitkCustomMultiWidgetEditor final : public QmitkAbstractRenderEditor, public mitk::ILifecycleAwarePart, public mitk::ILinkedRenderWindowPart { Q_OBJECT public: berryObjectMacro(QmitkCustomMultiWidgetEditor) static const QString EDITOR_ID; QmitkCustomMultiWidgetEditor(); ~QmitkCustomMultiWidgetEditor(); /** * @brief Overridden from mitk::ILifecycleAwarePart */ virtual void Activated() override; /** * @brief Overridden from mitk::ILifecycleAwarePart */ virtual void Deactivated() override; /** * @brief Overridden from mitk::ILifecycleAwarePart */ virtual void Visible() override; /** * @brief Overridden from mitk::ILifecycleAwarePart */ virtual void Hidden() override; /** * @brief Overridden from mitk::ILinkedRenderWindowPart : IRenderWindowPart */ virtual QmitkRenderWindow* GetActiveQmitkRenderWindow() const override; /** * @brief Overridden from mitk::ILinkedRenderWindowPart : IRenderWindowPart */ virtual QHash GetQmitkRenderWindows() const override; /** * @brief Overridden from mitk::ILinkedRenderWindowPart : IRenderWindowPart */ virtual QmitkRenderWindow* GetQmitkRenderWindow(const QString& id) const override; /** * @brief Overridden from mitk::ILinkedRenderWindowPart : IRenderWindowPart */ virtual mitk::Point3D GetSelectedPosition(const QString& id = QString()) const override; /** * @brief Overridden from mitk::ILinkedRenderWindowPart : IRenderWindowPart */ virtual void SetSelectedPosition(const mitk::Point3D& pos, const QString& id = QString()) override; /** * @brief Overridden from mitk::ILinkedRenderWindowPart : IRenderWindowPart */ virtual void EnableDecorations(bool enable, const QStringList& decorations = QStringList()) override; /** * @brief Overridden from mitk::ILinkedRenderWindowPart : IRenderWindowPart */ virtual bool IsDecorationEnabled(const QString& decoration) const override; /** * @brief Overridden from mitk::ILinkedRenderWindowPart : IRenderWindowPart */ virtual QStringList GetDecorations() const override; /** * @brief Overridden from mitk::ILinkedRenderWindowPart */ virtual void EnableSlicingPlanes(bool enable) override; /** * @brief Overridden from mitk::ILinkedRenderWindowPart */ virtual bool IsSlicingPlanesEnabled() const override; QmitkCustomMultiWidget* GetCustomMultiWidget(); private: /** * @brief Overridden from QmitkAbstractRenderEditor */ virtual void SetFocus() override; /** * @brief Overridden from QmitkAbstractRenderEditor */ - virtual void OnPreferencesChanged(const berry::IBerryPreferences* preferences) override; + virtual void CreateQtPartControl(QWidget* parent) override; /** * @brief Overridden from QmitkAbstractRenderEditor */ - virtual void CreateQtPartControl(QWidget* parent) override; - + virtual void OnPreferencesChanged(const berry::IBerryPreferences* preferences) override; /** * @brief * * */ void RequestActivateMenuWidget(bool on); - /** - * @brief Set the default preferences. This method is used to show the current preferences - * in the first call of the preference page (the GUI). - * - * @param preferences The berry preferences. - */ - void InitializePreferences(berry::IBerryPreferences* preferences); - /** - * @brief FillMembersWithCurrentDecorations Helper method to fill internal members with - * current values of the std multi widget. - */ - void FillMembersWithCurrentDecorations(); - /** - * @brief GetPreferenceDecorations Getter to fill internal members with values of preferences. - * @param preferences The berry preferences. - * - * If a preference is set, the value will overwrite the current value. If it does not exist, - * the value will not change. - */ - void GetPreferenceDecorations(const berry::IBerryPreferences* preferences); - /** - * @brief Convert a hex color string to mitk::Color. - * - * @param widgetColorInHex The color in hex format (#RRGGBB) where each digit is in the form (0-F). - * @return The color in mitk format. - */ - mitk::Color HexColorToMitkColor(const QString& hexColor); - /** - * @brief Convert an mitk::Color to a hex color string. - * - * @param color The color in mitk format. - * @return The color as string in hex (#RRGGBB). - */ - QString MitkColorToHexColor(const mitk::Color& mitkColor); QmitkCustomMultiWidget* m_CustomMultiWidget; QmitkMouseModeSwitcher* m_MouseModeSwitcher; + std::unique_ptr m_MultiWidgetDecorationManager; }; #endif // QMITKCUSTOMMULTIWIDGETEDITOR_H diff --git a/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/src/QmitkMultiWidgetDecorationManager.cpp b/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/src/QmitkMultiWidgetDecorationManager.cpp new file mode 100644 index 0000000000..79e277d186 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/src/QmitkMultiWidgetDecorationManager.cpp @@ -0,0 +1,458 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical Image Computing. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#include "QmitkMultiWidgetDecorationManager.h" + +// org_mitk_gui_common +#include + +// mitk annotation +#include + +// vtk +#include + +// qt +#include + +QmitkMultiWidgetDecorationManager::QmitkMultiWidgetDecorationManager(QmitkCustomMultiWidget* customMultiWidget) + : m_CustomMultiWidget(customMultiWidget) + , m_LogoAnnotation(mitk::LogoAnnotation::New()) +{ + // nothing here +} + +void QmitkMultiWidgetDecorationManager::DecorationPreferencesChanged(const berry::IBerryPreferences* preferences) +{ + // Enable change of logo. If no DepartmentLogo was set explicitly, MBILogo is used. + // Set new department logo by prefs->Set("DepartmentLogo", "PathToImage"); + + // If no logo was set for this plug-in specifically, walk the parent preference nodes + // and lookup a logo value there. + + // Disable the logo first, otherwise setting a new logo will have no effect due to how mitkManufacturerLogo works + ShowLogo(false); + SetupLogo(qPrintable(":/org.mitk.gui.qt.stdmultiwidgeteditor/defaultWatermark.png")); + ShowLogo(true); + + const berry::IPreferences* currentNode = preferences; + while (currentNode) + { + bool logoFound = false; + foreach(const QString& key, currentNode->Keys()) + { + if (key == "DepartmentLogo") + { + ShowLogo(false); + QString departmentLogoLocation = currentNode->Get("DepartmentLogo", ""); + if (!departmentLogoLocation.isEmpty()) + { + SetupLogo(qPrintable(departmentLogoLocation)); + ShowLogo(true); + } + logoFound = true; + break; + } + } + + if (logoFound) + { + break; + } + currentNode = currentNode->Parent().GetPointer(); + } + + QmitkMultiWidgetDecorationManager::Colormap colormap = static_cast(preferences->GetInt("Render window widget colormap", 0)); + SetColormap(colormap); + + // show colored rectangle + ShowAllColoredRectangles(true); + + // show corner annotations + ShowAllCornerAnnotations(true); +} + +void QmitkMultiWidgetDecorationManager::ShowDecorations(bool show, const QStringList& decorations) +{ + if (nullptr != m_CustomMultiWidget) + { + return; + } + + if (decorations.isEmpty() || decorations.contains(mitk::IRenderWindowPart::DECORATION_BORDER)) + { + ShowAllColoredRectangles(show); + } + if (decorations.isEmpty() || decorations.contains(mitk::IRenderWindowPart::DECORATION_LOGO)) + { + ShowLogo(show); + } + if (decorations.isEmpty() || decorations.contains(mitk::IRenderWindowPart::DECORATION_MENU)) + { + //m_CustomMultiWidget->ActivateAllRenderWindowMenus(show); + } + if (decorations.isEmpty() || decorations.contains(mitk::IRenderWindowPart::DECORATION_BACKGROUND)) + { + ShowAllGradientBackgrounds(show); + } + if (decorations.isEmpty() || decorations.contains(mitk::IRenderWindowPart::DECORATION_CORNER_ANNOTATION)) + { + ShowAllCornerAnnotations(show); + } +} + +bool QmitkMultiWidgetDecorationManager::IsDecorationVisible(const QString& decoration) const +{ + if (mitk::IRenderWindowPart::DECORATION_BORDER == decoration) + { + return AreAllColoredRectanglesVisible(); + } + else if (mitk::IRenderWindowPart::DECORATION_LOGO == decoration) + { + return IsLogoVisible(); + } + else if (mitk::IRenderWindowPart::DECORATION_MENU == decoration) + { + //return IsMenuWidgetEnabled(); + } + else if (mitk::IRenderWindowPart::DECORATION_BACKGROUND == decoration) + { + return AreAllGradientBackgroundsOn(); + } + else if (mitk::IRenderWindowPart::DECORATION_CORNER_ANNOTATION == decoration) + { + return AreAllCornerAnnotationsVisible(); + } + + return false; +} + +QStringList QmitkMultiWidgetDecorationManager::GetDecorations() const +{ + QStringList decorations; + decorations << mitk::IRenderWindowPart::DECORATION_BORDER << mitk::IRenderWindowPart::DECORATION_LOGO << mitk::IRenderWindowPart::DECORATION_MENU + << mitk::IRenderWindowPart::DECORATION_BACKGROUND << mitk::IRenderWindowPart::DECORATION_CORNER_ANNOTATION; + return decorations; +} + +////////////////////////////////////////////////////////////////////////// +// PRIVATE +////////////////////////////////////////////////////////////////////////// +void QmitkMultiWidgetDecorationManager::SetupLogo(const char* path) +{ + m_LogoAnnotation->SetOpacity(0.5); + mitk::Point2D offset; + offset.Fill(0.03); + m_LogoAnnotation->SetOffsetVector(offset); + m_LogoAnnotation->SetRelativeSize(0.25); + m_LogoAnnotation->SetCornerPosition(1); + vtkSmartPointer vtkLogo = GetVtkLogo(path); + + SetLogo(vtkLogo); +} + +vtkSmartPointer QmitkMultiWidgetDecorationManager::GetVtkLogo(const char* path) +{ + QImage* qimage = new QImage(path); + vtkSmartPointer qImageToVtk; + qImageToVtk = vtkSmartPointer::New(); + + qImageToVtk->SetQImage(qimage); + qImageToVtk->Update(); + vtkSmartPointer vtkLogo = qImageToVtk->GetOutput(); + return vtkLogo; +} + +void QmitkMultiWidgetDecorationManager::SetLogo(vtkSmartPointer vtkLogo) +{ + QmitkRenderWindowWidget* renderWindowWidget = m_CustomMultiWidget->GetLastRenderWindowWidget(); + if (nullptr != renderWindowWidget && m_LogoAnnotation.IsNotNull()) + { + mitk::ManualPlacementAnnotationRenderer::AddAnnotation(m_LogoAnnotation.GetPointer(), renderWindowWidget->GetRenderWindow()->GetRenderer()); + m_LogoAnnotation->SetLogoImage(vtkLogo); + mitk::BaseRenderer *renderer = mitk::BaseRenderer::GetInstance(renderWindowWidget->GetRenderWindow()->GetVtkRenderWindow()); + m_LogoAnnotation->Update(renderer); + renderWindowWidget->RequestUpdate(); + return; + } + + MITK_ERROR << "Logo can not be set for an unknown widget."; +} + +void QmitkMultiWidgetDecorationManager::ShowLogo(bool show) +{ + QmitkRenderWindowWidget* renderWindowWidget = m_CustomMultiWidget->GetLastRenderWindowWidget(); + if (nullptr != renderWindowWidget) + { + m_LogoAnnotation->SetVisibility(show); + renderWindowWidget->RequestUpdate(); + return; + } + + MITK_ERROR << "Department logo can not be shown for an unknown widget."; +} + +bool QmitkMultiWidgetDecorationManager::IsLogoVisible() const +{ + return m_LogoAnnotation->IsVisible(); +} + +void QmitkMultiWidgetDecorationManager::SetColormap(QmitkMultiWidgetDecorationManager::Colormap colormap) +{ + switch (colormap) + { + case Colormap::BlackAndWhite: + { + FillAllGradientBackgroundColorsWithBlack(); + float white[3] = { 1.0f, 1.0f, 1.0f }; + SetAllDecorationColors(white); + break; + } + } +} + +void QmitkMultiWidgetDecorationManager::SetDecorationColor(const QString& widgetID, const mitk::Color& color) +{ + QmitkRenderWindowWidget* renderWindowWidget = m_CustomMultiWidget->GetRenderWindowWidget(widgetID); + if (nullptr != renderWindowWidget) + { + renderWindowWidget->SetDecorationColor(color); + return; + } + + MITK_ERROR << "Decoration color can not be set for an unknown widget."; +} + +void QmitkMultiWidgetDecorationManager::SetAllDecorationColors(const mitk::Color& color) +{ + QmitkCustomMultiWidget::RenderWindowWidgetMap renderWindowWidgets = m_CustomMultiWidget->GetRenderWindowWidgets(); + for (const auto& renderWindowWidget : renderWindowWidgets) + { + renderWindowWidget.second->SetDecorationColor(color); + } +} + +mitk::Color QmitkMultiWidgetDecorationManager::GetDecorationColor(const QString& widgetID) const +{ + QmitkRenderWindowWidget* renderWindowWidget = m_CustomMultiWidget->GetRenderWindowWidget(widgetID); + if (nullptr != renderWindowWidget) + { + return renderWindowWidget->GetDecorationColor(); + } + + MITK_ERROR << "Decoration color can not be retrieved for an unknown widget. Returning black color!"; + float black[3] = { 0.0f, 0.0f, 0.0f }; + return mitk::Color(black); +} + +void QmitkMultiWidgetDecorationManager::ShowColoredRectangle(const QString& widgetID, bool show) +{ + QmitkRenderWindowWidget* renderWindowWidget = m_CustomMultiWidget->GetRenderWindowWidget(widgetID); + if (nullptr != renderWindowWidget) + { + renderWindowWidget->ShowColoredRectangle(show); + return; + } + + MITK_ERROR << "Colored rectangle can not be set for an unknown widget."; +} + +void QmitkMultiWidgetDecorationManager::ShowAllColoredRectangles(bool show) +{ + QmitkCustomMultiWidget::RenderWindowWidgetMap renderWindowWidgets = m_CustomMultiWidget->GetRenderWindowWidgets(); + for (const auto& renderWindowWidget : renderWindowWidgets) + { + renderWindowWidget.second->ShowColoredRectangle(show); + } +} + +bool QmitkMultiWidgetDecorationManager::IsColoredRectangleVisible(const QString& widgetID) const +{ + QmitkRenderWindowWidget* renderWindowWidget = m_CustomMultiWidget->GetRenderWindowWidget(widgetID); + if (nullptr != renderWindowWidget) + { + return renderWindowWidget->IsColoredRectangleVisible(); + } + + MITK_ERROR << "Colored rectangle visibility can not be retrieved for an unknown widget. Returning 'false'."; + return false; +} + +bool QmitkMultiWidgetDecorationManager::AreAllColoredRectanglesVisible() const +{ + QmitkCustomMultiWidget::RenderWindowWidgetMap renderWindowWidgets = m_CustomMultiWidget->GetRenderWindowWidgets(); + bool allTrue = true; + for (const auto& renderWindowWidget : renderWindowWidgets) + { + allTrue = allTrue && renderWindowWidget.second->IsColoredRectangleVisible(); + } + + return allTrue; +} + +void QmitkMultiWidgetDecorationManager::SetGradientBackgroundColors(const mitk::Color& upper, const mitk::Color& lower, const QString& widgetID) +{ + QmitkRenderWindowWidget* renderWindowWidget = m_CustomMultiWidget->GetRenderWindowWidget(widgetID); + if (nullptr != renderWindowWidget) + { + renderWindowWidget->SetGradientBackgroundColors(upper, lower); + return; + } + + MITK_ERROR << "Background color gradient can not be set for an unknown widget."; +} + +void QmitkMultiWidgetDecorationManager::SetAllGradientBackgroundColors(const mitk::Color& upper, const mitk::Color& lower) +{ + QmitkCustomMultiWidget::RenderWindowWidgetMap renderWindowWidgets = m_CustomMultiWidget->GetRenderWindowWidgets(); + for (const auto& renderWindowWidget : renderWindowWidgets) + { + renderWindowWidget.second->SetGradientBackgroundColors(upper, lower); + } +} + +void QmitkMultiWidgetDecorationManager::FillAllGradientBackgroundColorsWithBlack() +{ + float black[3] = { 0.0f, 0.0f, 0.0f }; + SetAllGradientBackgroundColors(black, black); +} + +void QmitkMultiWidgetDecorationManager::ShowGradientBackground(const QString& widgetID, bool show) +{ + QmitkRenderWindowWidget* renderWindowWidget = m_CustomMultiWidget->GetRenderWindowWidget(widgetID); + if (nullptr != renderWindowWidget) + { + renderWindowWidget->ShowGradientBackground(show); + return; + } + + MITK_ERROR << "Background color gradient can not be shown for an unknown widget."; +} + +void QmitkMultiWidgetDecorationManager::ShowAllGradientBackgrounds(bool show) +{ + QmitkCustomMultiWidget::RenderWindowWidgetMap renderWindowWidgets = m_CustomMultiWidget->GetRenderWindowWidgets(); + for (const auto& renderWindowWidget : renderWindowWidgets) + { + renderWindowWidget.second->ShowGradientBackground(show); + } +} + +std::pair QmitkMultiWidgetDecorationManager::GetGradientBackgroundColors(const QString& widgetID) const +{ + QmitkRenderWindowWidget* renderWindowWidget = m_CustomMultiWidget->GetRenderWindowWidget(widgetID); + if (nullptr != renderWindowWidget) + { + return renderWindowWidget->GetGradientBackgroundColors(); + } + + MITK_ERROR << "Background color gradient can not be retrieved for an unknown widget. Returning black color pair."; + float black[3] = { 0.0f, 0.0f, 0.0f }; + return std::make_pair(mitk::Color(black), mitk::Color(black)); +} + +bool QmitkMultiWidgetDecorationManager::IsGradientBackgroundOn(const QString& widgetID) const +{ + QmitkRenderWindowWidget* renderWindowWidget = m_CustomMultiWidget->GetRenderWindowWidget(widgetID); + if (nullptr != renderWindowWidget) + { + return renderWindowWidget->IsGradientBackgroundOn(); + } + + MITK_ERROR << "Background color gradient flag can not be retrieved for an unknown widget. Returning 'false'."; + return false; +} + +bool QmitkMultiWidgetDecorationManager::AreAllGradientBackgroundsOn() const +{ + QmitkCustomMultiWidget::RenderWindowWidgetMap renderWindowWidgets = m_CustomMultiWidget->GetRenderWindowWidgets(); + bool allTrue = true; + for (const auto& renderWindowWidget : renderWindowWidgets) + { + allTrue = allTrue && renderWindowWidget.second->IsGradientBackgroundOn(); + } + + return allTrue; +} + +void QmitkMultiWidgetDecorationManager::SetCornerAnnotationText(const QString& widgetID, const std::string& cornerAnnotation) +{ + QmitkRenderWindowWidget* renderWindowWidget = m_CustomMultiWidget->GetRenderWindowWidget(widgetID); + if (nullptr != renderWindowWidget) + { + renderWindowWidget->SetCornerAnnotationText(cornerAnnotation); + return; + } + + MITK_ERROR << "Corner annotation text can not be retrieved for an unknown widget."; +} + +std::string QmitkMultiWidgetDecorationManager::GetCornerAnnotationText(const QString& widgetID) const +{ + QmitkRenderWindowWidget* renderWindowWidget = m_CustomMultiWidget->GetRenderWindowWidget(widgetID); + if (nullptr != renderWindowWidget) + { + return renderWindowWidget->GetCornerAnnotationText(); + } + + MITK_ERROR << "Corner annotation text can not be retrieved for an unknown widget."; + return ""; +} + +void QmitkMultiWidgetDecorationManager::ShowCornerAnnotation(const QString& widgetID, bool show) +{ + QmitkRenderWindowWidget* renderWindowWidget = m_CustomMultiWidget->GetRenderWindowWidget(widgetID); + if (nullptr != renderWindowWidget) + { + renderWindowWidget->ShowCornerAnnotation(show); + return; + } + + MITK_ERROR << "Corner annotation can not be set for an unknown widget."; +} + +void QmitkMultiWidgetDecorationManager::ShowAllCornerAnnotations(bool show) +{ + QmitkCustomMultiWidget::RenderWindowWidgetMap renderWindowWidgets = m_CustomMultiWidget->GetRenderWindowWidgets(); + for (const auto& renderWindowWidget : renderWindowWidgets) + { + renderWindowWidget.second->ShowCornerAnnotation(show); + } +} + +bool QmitkMultiWidgetDecorationManager::IsCornerAnnotationVisible(const QString& widgetID) const +{ + QmitkRenderWindowWidget* renderWindowWidget = m_CustomMultiWidget->GetRenderWindowWidget(widgetID); + if (nullptr != renderWindowWidget) + { + return renderWindowWidget->IsCornerAnnotationVisible(); + } + + MITK_ERROR << "Corner annotation visibility can not be retrieved for an unknown widget. Returning 'false'."; + return false; +} + +bool QmitkMultiWidgetDecorationManager::AreAllCornerAnnotationsVisible() const +{ + QmitkCustomMultiWidget::RenderWindowWidgetMap renderWindowWidgets = m_CustomMultiWidget->GetRenderWindowWidgets(); + bool allTrue = true; + for (const auto& renderWindowWidget : renderWindowWidgets) + { + allTrue = allTrue && renderWindowWidget.second->IsCornerAnnotationVisible(); + } + + return allTrue; +} diff --git a/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/src/QmitkMultiWidgetDecorationManager.h b/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/src/QmitkMultiWidgetDecorationManager.h new file mode 100644 index 0000000000..6b0637d29a --- /dev/null +++ b/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/src/QmitkMultiWidgetDecorationManager.h @@ -0,0 +1,144 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical Image Computing. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#ifndef QMITKMULTIWIDGETDECORATIONMANAGER_H +#define QMITKMULTIWIDGETDECORATIONMANAGER_H + +// custom multi widget editor +#include + +// mitk core +#include + +// mitk annotation +#include + +// mitk qtwidgets +#include + +// berry +#include + +// vtk +#include +#include + +// qt +#include +#include + +/** +* @brief +* +* +*/ +class CUSTOMMULTIWIDGETEDITOR_EXPORT QmitkMultiWidgetDecorationManager +{ + +public: + + QmitkMultiWidgetDecorationManager(QmitkCustomMultiWidget* customMultiWidget); + + enum class Colormap + { + BlackAndWhite = 0 // black background, white decoration + }; + + void DecorationPreferencesChanged(const berry::IBerryPreferences* preferences); + + /** + * @brief Show or hide decorations like like colored borders or background, logos, menu widgets, logos and + * text annotations. + * + * \@par Show the decorations specified in decorations if true. Hide them, if not. + * \@par A list of decoration names. If empty, all supported decorations are affected. + */ + void ShowDecorations(bool show, const QStringList& decorations); + /** + * @brief Return if a specific decoration is visible. + * + * \return True, if the specified decoration is shown, false if not. + */ + bool IsDecorationVisible(const QString &decoration) const; + QStringList GetDecorations() const; + +private: + + void SetupLogo(const char* path); + vtkSmartPointer GetVtkLogo(const char* path); + void SetLogo(vtkSmartPointer vtkLogo); + void ShowLogo(bool show); + bool IsLogoVisible() const; + + void SetColormap(Colormap colormap); + + void SetDecorationColor(const QString& widgetID, const mitk::Color& color); + void SetAllDecorationColors(const mitk::Color& color); + mitk::Color GetDecorationColor(const QString& widgetID) const; + + void ShowColoredRectangle(const QString& widgetID, bool show); + void ShowAllColoredRectangles(bool show); + bool IsColoredRectangleVisible(const QString& widgetID) const; + bool AreAllColoredRectanglesVisible() const; + + /** + * @brief Set a background color gradient for a specific render window. + * + * If two different input colors are used, a gradient background is generated. + * + * @param upper The color of the gradient background. + * @param lower The color of the gradient background. + * @param widgetID The widget identifier. + */ + void SetGradientBackgroundColors(const mitk::Color& upper, const mitk::Color& lower, const QString& widgetID); + /** + * @brief Set a background color gradient for all available render windows. + * + * If two different input colors are used, a gradient background is generated. + * + * @param upper The color of the gradient background. + * @param lower The color of the gradient background. + */ + void SetAllGradientBackgroundColors(const mitk::Color& upper, const mitk::Color& lower); + void FillAllGradientBackgroundColorsWithBlack(); + void ShowGradientBackground(const QString& widgetID, bool show); + void ShowAllGradientBackgrounds(bool show); + /** + * @rief Return a render window (widget) specific background color gradient + * + * @param widgetID The widget identifier. + * + * @return A color gradient as a pair of colors. + * First entry: upper color value + * Second entry: lower color value + */ + std::pair GetGradientBackgroundColors(const QString& widgetID) const; + bool IsGradientBackgroundOn(const QString& widgetID) const; + bool AreAllGradientBackgroundsOn() const; + + void SetCornerAnnotationText(const QString& widgetID, const std::string& cornerAnnotation); + std::string GetCornerAnnotationText(const QString& widgetID) const; + void ShowCornerAnnotation(const QString& widgetID, bool show); + void ShowAllCornerAnnotations(bool show); + bool IsCornerAnnotationVisible(const QString& widgetID) const; + bool AreAllCornerAnnotationsVisible() const; + + QmitkCustomMultiWidget* m_CustomMultiWidget; + mitk::LogoAnnotation::Pointer m_LogoAnnotation; + +}; + +#endif // QMITKMULTIWIDGETDECORATIONMANAGER_H diff --git a/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/src/internal/QmitkCustomMultiWidgetEditorPreferencePage.cpp b/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/src/internal/QmitkCustomMultiWidgetEditorPreferencePage.cpp index c7b5b11cd5..de3c064e12 100644 --- a/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/src/internal/QmitkCustomMultiWidgetEditorPreferencePage.cpp +++ b/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/src/internal/QmitkCustomMultiWidgetEditorPreferencePage.cpp @@ -1,256 +1,128 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ -#include #include "QmitkCustomMultiWidgetEditorPreferencePage.h" #include +// berry framework #include #include -#include - QmitkCustomMultiWidgetEditorPreferencePage::QmitkCustomMultiWidgetEditorPreferencePage() : m_Preferences(nullptr) { // nothing here } QmitkCustomMultiWidgetEditorPreferencePage::~QmitkCustomMultiWidgetEditorPreferencePage() { //nothing here } +void QmitkCustomMultiWidgetEditorPreferencePage::Init(berry::IWorkbench::Pointer) +{ + // nothing here +} + void QmitkCustomMultiWidgetEditorPreferencePage::CreateQtControl(QWidget* parent) { m_MainControl = new QWidget(parent); m_Ui.setupUi(m_MainControl); - berry::IPreferencesService* prefService = berry::Platform::GetPreferencesService(); - Q_ASSERT(prefService); - - m_Preferences = prefService->GetSystemPreferences()->Node(QmitkCustomMultiWidgetEditor::EDITOR_ID); + berry::IPreferencesService* preferenceService = berry::Platform::GetPreferencesService(); + Q_ASSERT(preferenceService); + m_Preferences = preferenceService->GetSystemPreferences()->Node(QmitkCustomMultiWidgetEditor::EDITOR_ID); - connect(m_Ui.m_ColorButton1, SIGNAL(clicked()), SLOT(ColorChooserButtonClicked())); - connect(m_Ui.m_ColorButton2, SIGNAL(clicked()), SLOT(ColorChooserButtonClicked())); + connect(m_Ui.m_RenderingModeComboBox, SIGNAL(activated(int)), SLOT(ChangeRenderingMode(int))); + connect(m_Ui.m_ColormapComboBox, SIGNAL(activated(int)), SLOT(ChangeColormap(int))); connect(m_Ui.m_ResetButton, SIGNAL(clicked()), SLOT(ResetPreferencesAndGUI())); - connect(m_Ui.m_RenderingMode, SIGNAL(activated(int)), SLOT(ChangeRenderingMode(int))); - connect(m_Ui.m_RenderWindowDecorationColor, SIGNAL(clicked()), SLOT(ColorChooserButtonClicked())); - connect(m_Ui.m_RenderWindowChooser, SIGNAL(activated(int)), SLOT(OnWidgetComboBoxChanged(int))); - connect(m_Ui.m_RenderWindowDecorationText, SIGNAL(textChanged(QString)), SLOT(AnnotationTextChanged(QString))); Update(); } QWidget* QmitkCustomMultiWidgetEditorPreferencePage::GetQtControl() const { return m_MainControl; } -void QmitkCustomMultiWidgetEditorPreferencePage::Init(berry::IWorkbench::Pointer) -{ -} - -void QmitkCustomMultiWidgetEditorPreferencePage::PerformCancel() -{ -} - bool QmitkCustomMultiWidgetEditorPreferencePage::PerformOk() { - m_Preferences->Put("widget1 corner annotation", m_WidgetAnnotation[0]); - m_Preferences->Put("widget2 corner annotation", m_WidgetAnnotation[1]); - m_Preferences->Put("widget3 corner annotation", m_WidgetAnnotation[2]); - m_Preferences->Put("widget4 corner annotation", m_WidgetAnnotation[3]); - - m_Preferences->Put("widget1 decoration color", m_WidgetDecorationColor[0]); - m_Preferences->Put("widget2 decoration color", m_WidgetDecorationColor[1]); - m_Preferences->Put("widget3 decoration color", m_WidgetDecorationColor[2]); - m_Preferences->Put("widget4 decoration color", m_WidgetDecorationColor[3]); - - m_Preferences->Put("widget1 first background color", m_WidgetBackgroundColor1[0]); - m_Preferences->Put("widget2 first background color", m_WidgetBackgroundColor1[1]); - m_Preferences->Put("widget3 first background color", m_WidgetBackgroundColor1[2]); - m_Preferences->Put("widget4 first background color", m_WidgetBackgroundColor1[3]); - m_Preferences->Put("widget1 second background color", m_WidgetBackgroundColor2[0]); - m_Preferences->Put("widget2 second background color", m_WidgetBackgroundColor2[1]); - m_Preferences->Put("widget3 second background color", m_WidgetBackgroundColor2[2]); - m_Preferences->Put("widget4 second background color", m_WidgetBackgroundColor2[3]); - m_Preferences->PutInt("crosshair gap size", m_Ui.m_CrosshairGapSize->value()); - m_Preferences->PutBool("Use constrained zooming and panning", m_Ui.m_EnableFlexibleZooming->isChecked()); m_Preferences->PutBool("Show level/window widget", m_Ui.m_ShowLevelWindowWidget->isChecked()); m_Preferences->PutBool("PACS like mouse interaction", m_Ui.m_PACSLikeMouseMode->isChecked()); - m_Preferences->PutInt("Rendering Mode", m_Ui.m_RenderingMode->currentIndex()); - return true; -} + m_Preferences->PutInt("Rendering Mode", m_Ui.m_RenderingModeComboBox->currentIndex()); -void QmitkCustomMultiWidgetEditorPreferencePage::Update() -{ - //Note: there should be default preferences already defined in the - //QmitkCustomMultiWidgetEditor::InitializePreferences(). Therefore, - //all default values here are not relevant. - //gradient background colors - m_WidgetBackgroundColor1[0] = m_Preferences->Get("widget1 first background color", "#000000"); - m_WidgetBackgroundColor2[0] = m_Preferences->Get("widget1 second background color", "#000000"); - m_WidgetBackgroundColor1[1] = m_Preferences->Get("widget2 first background color", "#000000"); - m_WidgetBackgroundColor2[1] = m_Preferences->Get("widget2 second background color", "#000000"); - m_WidgetBackgroundColor1[2] = m_Preferences->Get("widget3 first background color", "#000000"); - m_WidgetBackgroundColor2[2] = m_Preferences->Get("widget3 second background color", "#000000"); - m_WidgetBackgroundColor1[3] = m_Preferences->Get("widget4 first background color", "#191919"); - m_WidgetBackgroundColor2[3] = m_Preferences->Get("widget4 second background color", "#7F7F7F"); + m_Preferences->PutInt("Render window widget colormap", m_Ui.m_ColormapComboBox->currentIndex()); + m_Preferences->PutBool("Render window individual decorations", m_Ui.m_IndividualDecorations->isChecked()); - //decoration colors - m_WidgetDecorationColor[0] = m_Preferences->Get("widget1 decoration color", "#FF0000"); - m_WidgetDecorationColor[1] = m_Preferences->Get("widget2 decoration color", "#00FF00"); - m_WidgetDecorationColor[2] = m_Preferences->Get("widget3 decoration color", "#0000FF"); - m_WidgetDecorationColor[3] = m_Preferences->Get("widget4 decoration color", "#FFFF00"); - - //annotation text - m_WidgetAnnotation[0] = m_Preferences->Get("widget1 corner annotation", "Axial"); - m_WidgetAnnotation[1] = m_Preferences->Get("widget2 corner annotation", "Sagittal"); - m_WidgetAnnotation[2] = m_Preferences->Get("widget3 corner annotation", "Coronal"); - m_WidgetAnnotation[3] = m_Preferences->Get("widget4 corner annotation", "3D"); - - - //Ui stuff - int index = m_Ui.m_RenderWindowChooser->currentIndex(); - QColor firstBackgroundColor(m_WidgetBackgroundColor1[index]); - QColor secondBackgroundColor(m_WidgetBackgroundColor2[index]); - QColor widgetColor(m_WidgetDecorationColor[index]); + m_Preferences->PutInt("crosshair gap size", m_Ui.m_CrosshairGapSize->value()); - this->SetStyleSheetToColorChooserButton(firstBackgroundColor, m_Ui.m_ColorButton1); - this->SetStyleSheetToColorChooserButton(secondBackgroundColor, m_Ui.m_ColorButton2); - this->SetStyleSheetToColorChooserButton(widgetColor, m_Ui.m_RenderWindowDecorationColor); + return true; +} - m_Ui.m_RenderWindowDecorationText->setText(m_WidgetAnnotation[index]); +void QmitkCustomMultiWidgetEditorPreferencePage::PerformCancel() +{ + // nothing here +} +void QmitkCustomMultiWidgetEditorPreferencePage::Update() +{ m_Ui.m_EnableFlexibleZooming->setChecked(m_Preferences->GetBool("Use constrained zooming and panning", true)); m_Ui.m_ShowLevelWindowWidget->setChecked(m_Preferences->GetBool("Show level/window widget", true)); m_Ui.m_PACSLikeMouseMode->setChecked(m_Preferences->GetBool("PACS like mouse interaction", false)); - int mode= m_Preferences->GetInt("Rendering Mode",0); - m_Ui.m_RenderingMode->setCurrentIndex(mode); - m_Ui.m_CrosshairGapSize->setValue(m_Preferences->GetInt("crosshair gap size", 32)); -} -void QmitkCustomMultiWidgetEditorPreferencePage::ColorChooserButtonClicked() -{ - unsigned int widgetIndex = m_Ui.m_RenderWindowChooser->currentIndex(); - if(widgetIndex > 3) - { - MITK_ERROR << "Selected index for unknown."; - return; - } - QObject *senderObj = sender(); // This will give Sender button - //find out last used color and set it - QColor initialColor; - if( senderObj->objectName() == m_Ui.m_ColorButton1->objectName()) - { - initialColor = QColor(m_WidgetBackgroundColor1[widgetIndex]); - }else if( senderObj->objectName() == m_Ui.m_ColorButton2->objectName()) - { - initialColor = QColor(m_WidgetBackgroundColor2[widgetIndex]); - }else if( senderObj->objectName() == m_Ui.m_RenderWindowDecorationColor->objectName()) - { - initialColor = QColor(m_WidgetDecorationColor[widgetIndex]); - } + int renderingMode = m_Preferences->GetInt("Rendering Mode", 0); + m_Ui.m_RenderingModeComboBox->setCurrentIndex(renderingMode); - //get the new color - QColor newcolor = QColorDialog::getColor(initialColor); - if(!newcolor.isValid()) - { - newcolor = initialColor; - } - this->SetStyleSheetToColorChooserButton(newcolor, static_cast(senderObj)); + int colormap = m_Preferences->GetInt("Render window widget colormap", 0); + m_Ui.m_ColormapComboBox->setCurrentIndex(colormap); - //convert it to std string and apply it - if( senderObj->objectName() == m_Ui.m_ColorButton1->objectName()) - { - m_WidgetBackgroundColor1[widgetIndex] = newcolor.name(); - } - else if( senderObj->objectName() == m_Ui.m_ColorButton2->objectName()) - { - m_WidgetBackgroundColor2[widgetIndex] = newcolor.name(); - } - else if( senderObj->objectName() == m_Ui.m_RenderWindowDecorationColor->objectName()) - { - m_WidgetDecorationColor[widgetIndex] = newcolor.name(); - } -} + m_Ui.m_IndividualDecorations->setChecked(m_Preferences->GetBool("Render window individual decorations", false)); -void QmitkCustomMultiWidgetEditorPreferencePage::SetStyleSheetToColorChooserButton(QColor backgroundcolor, QPushButton* button) -{ - button->setAutoFillBackground(true); - QString styleSheet = "background-color:rgb("; - - styleSheet.append(QString::number(backgroundcolor.red())); - styleSheet.append(","); - styleSheet.append(QString::number(backgroundcolor.green())); - styleSheet.append(","); - styleSheet.append(QString::number(backgroundcolor.blue())); - styleSheet.append(")"); - button->setStyleSheet(styleSheet); -} - -void QmitkCustomMultiWidgetEditorPreferencePage::AnnotationTextChanged(QString text) -{ - unsigned int widgetIndex = m_Ui.m_RenderWindowChooser->currentIndex(); - if( widgetIndex > 3) - { - MITK_INFO << "Selected index for unknown widget."; - return; - } - m_WidgetAnnotation[widgetIndex] = text; + m_Ui.m_CrosshairGapSize->setValue(m_Preferences->GetInt("crosshair gap size", 32)); } void QmitkCustomMultiWidgetEditorPreferencePage::ResetPreferencesAndGUI() { m_Preferences->Clear(); - this->Update(); -} - -void QmitkCustomMultiWidgetEditorPreferencePage::OnWidgetComboBoxChanged(int i) -{ - if( i > 3) - { - MITK_ERROR << "Selected unknown widget."; - return; - } - QColor widgetColor(m_WidgetDecorationColor[i]); - QColor gradientBackground1(m_WidgetBackgroundColor1[i]); - QColor gradientBackground2(m_WidgetBackgroundColor2[i]); - SetStyleSheetToColorChooserButton(widgetColor, m_Ui.m_RenderWindowDecorationColor); - SetStyleSheetToColorChooserButton(gradientBackground1, m_Ui.m_ColorButton1); - SetStyleSheetToColorChooserButton(gradientBackground2, m_Ui.m_ColorButton2); - m_Ui.m_RenderWindowDecorationText->setText(m_WidgetAnnotation[i]); + Update(); } void QmitkCustomMultiWidgetEditorPreferencePage::ChangeRenderingMode(int i) { - if( i == 0 ) + if (0 == i) { m_CurrentRenderingMode = "Standard"; } - else if( i == 1 ) + else if (1 == i) { m_CurrentRenderingMode = "Multisampling"; } - else if( i == 2 ) + else if (2 == i) { m_CurrentRenderingMode = "DepthPeeling"; } } + +void QmitkCustomMultiWidgetEditorPreferencePage::ChangeColormap(int i) +{ + if (0 == i) + { + m_CurrentColormap = "Black and white"; + } +} \ No newline at end of file diff --git a/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/src/internal/QmitkCustomMultiWidgetEditorPreferencePage.h b/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/src/internal/QmitkCustomMultiWidgetEditorPreferencePage.h index 181d5b3635..06ed1df152 100644 --- a/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/src/internal/QmitkCustomMultiWidgetEditorPreferencePage.h +++ b/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/src/internal/QmitkCustomMultiWidgetEditorPreferencePage.h @@ -1,121 +1,80 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef QMITKCUSTOMMULTIWIDGETEDITORPREFERENCEPAGE_H #define QMITKCUSTOMMULTIWIDGETEDITORPREFERENCEPAGE_H // custom multi widget editor #include "ui_QmitkCustomMultiWidgetEditorPreferencePage.h" #include #include #include #include #include class QmitkCustomMultiWidgetEditorPreferencePage : public QObject, public berry::IQtPreferencePage { Q_OBJECT Q_INTERFACES(berry::IPreferencePage) public: QmitkCustomMultiWidgetEditorPreferencePage(); ~QmitkCustomMultiWidgetEditorPreferencePage(); + void Init(berry::IWorkbench::Pointer) override; void CreateQtControl(QWidget* parent) override; QWidget* GetQtControl() const override; - void Init(berry::IWorkbench::Pointer) override; - void PerformCancel() override; + bool PerformOk() override; + void PerformCancel() override; void Update() override; public slots: /** * @brief ResetColors set default colors and refresh the GUI. */ void ResetPreferencesAndGUI(); /** * @brief ChangeRenderingMode slot to chose the rendering mode via QComboBox. * @param i index of the box. */ void ChangeRenderingMode(int i); - /** - * @brief OnWidgetComboBoxChanged slot called when the QComboBox to chose the widget was modified. - * @param i index of the combobox to select the widget (1-4). - */ - void OnWidgetComboBoxChanged(int i); - - /** - * @brief AnnotationTextChanged called when QLineEdit for the annotation was changed. - * @param text The new text. - */ - void AnnotationTextChanged(QString text); + void ChangeColormap(int i); protected: /** * @brief m_CurrentRenderingMode String for the rendering mode. */ std::string m_CurrentRenderingMode; - /** - * @brief m_WidgetBackgroundColor1 the background colors. - * - * If two different colors are chosen, a gradient background appears. - */ - QString m_WidgetBackgroundColor1[4]; - QString m_WidgetBackgroundColor2[4]; - - /** - * @brief m_WidgetDecorationColor the decoration color. - * - * The rectangle prop, the crosshair, the 3D planes and the corner annotation use this. - */ - QString m_WidgetDecorationColor[4]; - - /** - * @brief m_Widget1Annotation the text of the corner annotation. - */ - QString m_WidgetAnnotation[4]; + std::string m_CurrentColormap; /** * @brief m_Preferences the berry preferences. */ berry::IPreferences::Pointer m_Preferences; - /** - * @brief SetStyleSheetToColorChooserButton colorize a button. - * @param backgroundcolor color for the button. - * @param button the button. - */ - void SetStyleSheetToColorChooserButton(QColor backgroundcolor, QPushButton* button); - -protected slots: - - /** - * @brief ColorChooserButtonClicked slot called when a button to choose color was clicked. - */ - void ColorChooserButtonClicked(); - private: Ui::QmitkCustomMultiWidgetEditorPreferencePage m_Ui; QWidget* m_MainControl; }; #endif // QMITKCUSTOMMULTIWIDGETEDITORPREFERENCEPAGE_H diff --git a/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/src/internal/QmitkCustomMultiWidgetEditorPreferencePage.ui b/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/src/internal/QmitkCustomMultiWidgetEditorPreferencePage.ui index 71878f5ea0..f360b20922 100644 --- a/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/src/internal/QmitkCustomMultiWidgetEditorPreferencePage.ui +++ b/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/src/internal/QmitkCustomMultiWidgetEditorPreferencePage.ui @@ -1,225 +1,163 @@ QmitkCustomMultiWidgetEditorPreferencePage 0 0 - 518 - 431 + 520 + 320 External Programs - - - - - stdmulti.widget1 - - - - - stdmulti.widget2 - - - - - stdmulti.widget3 - - - - - stdmulti.widget4 - - + + + + <html><head/><body><p>If activated, zooming and panning is limited to a certain space arround each image.</p></body></html> + + + Qt::LeftToRight + + + Use constraint zooming and panning + + + true + - - - - <html><head/><body><p>If two colors are set, a gradient background is generated.</p></body></html> + + + + Qt::LeftToRight + + + Show level/window widget + + + true + + + + + + + Qt::LeftToRight - Background color + Use PACS like mouse interaction (select left mouse button action) - - + + + + Qt::Horizontal + + + + + - Reset preferences + Rendering Mode* - - + + Standard Rendering Enable Multisampling (Antialiasing) Enable Depth Peeling - - + + * Changes require restart of MITK. Depth Peeling is only supported by Windows. For other OS, use Standard Rendering and enable the property 'Depth Sorting' in the property list of the surface data node. - - - - 32 - - - - - + + Qt::Horizontal - - - - The small text on the button left of each renderwindow. - + + - Corner annotation + Colormap - - - - <html><head/><body><p>The gap in the middle of the crosshair in pixels.</p></body></html> - - - Crosshair gap size - + + + + + Black and white + + - - - - <html><head/><body><p>The color is used for the following decorations (of each renderwindow):</p><p>Rectangle border</p><p>Corner annotation</p><p>Crosshair</p><p>Plane geometry helper objects (3D Planes)</p><p>Image navigator borders</p><p><br/></p></body></html> + + + + + 0 + 0 + - Decoration color + Allow render window individual decorations - - - - - - - - - + + - <html><head/><body><p>Choose the renderwindow from the multi widget.</p></body></html> - - - Render windows - - - - - - - Qt::LeftToRight - - - Show level/window widget - - - true - - - - - - - Qt::LeftToRight - - - Use PACS like mouse interaction (select left mouse button action) - - - false - - - - - - - - - - - - - - Qt::Horizontal + <html><head/><body><p>The gap in the middle of the crosshair in pixels.</p></body></html> - - - - - Rendering Mode* + Crosshair gap size - - - - - - - + + + + 32 - - - - <html><head/><body><p>If activated, zooming and panning is limited to a certain space arround each image.</p></body></html> - - - Qt::LeftToRight - + + - Use constraint zooming and panning - - - true + Reset preferences