diff --git a/Modules/QmlItems/src/QmlMitkImageNavigator.cpp b/Modules/QmlItems/src/QmlMitkImageNavigator.cpp index 18b02735cc..595edb7d72 100644 --- a/Modules/QmlItems/src/QmlMitkImageNavigator.cpp +++ b/Modules/QmlItems/src/QmlMitkImageNavigator.cpp @@ -1,391 +1,379 @@ /*=================================================================== 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 "QmlMitkImageNavigator.h" #include #include QmlMitkImageNavigator* QmlMitkImageNavigator::instance = nullptr; QmlMitkImageNavigator::QmlMitkImageNavigator() : m_AxialStepper(0) , m_SagittalStepper(0) , m_FrontalStepper(0) , m_TimeStepper(0) { instance = this; } QmlMitkImageNavigator::~QmlMitkImageNavigator() { } void QmlMitkImageNavigator::setNavigatorAxial(QmlMitkSliderNavigatorItem *item) { this->m_NavigatorAxial = item; } void QmlMitkImageNavigator::setNavigatorSagittal(QmlMitkSliderNavigatorItem *item) { this->m_NavigatorSagittal = item; } void QmlMitkImageNavigator::setNavigatorCoronal(QmlMitkSliderNavigatorItem *item) { this->m_NavigatorCoronal = item; } void QmlMitkImageNavigator::setNavigatorTime(QmlMitkSliderNavigatorItem *item) { this->m_NavigatorTime = item; } QmlMitkSliderNavigatorItem* QmlMitkImageNavigator::getNavigatorAxial() { return this->m_NavigatorAxial; } QmlMitkSliderNavigatorItem* QmlMitkImageNavigator::getNavigatorSagittal() { return this->m_NavigatorSagittal; } QmlMitkSliderNavigatorItem* QmlMitkImageNavigator::getNavigatorCoronal() { return this->m_NavigatorCoronal; } QmlMitkSliderNavigatorItem* QmlMitkImageNavigator::getNavigatorTime() { return this->m_NavigatorTime; } void QmlMitkImageNavigator::setWorldCoordinateX(double coordinate) { this->m_WorldCoordinateX = coordinate; this->OnMillimetreCoordinateValueChanged(); } void QmlMitkImageNavigator::setWorldCoordinateY(double coordinate) { this->m_WorldCoordinateY = coordinate; this->OnMillimetreCoordinateValueChanged(); } void QmlMitkImageNavigator::setWorldCoordinateZ(double coordinate) { this->m_WorldCoordinateZ = coordinate; this->OnMillimetreCoordinateValueChanged(); } void QmlMitkImageNavigator::setWorldCoordinateXMin(double coordinate) { this->m_WorldCoordinateXMin = coordinate; } void QmlMitkImageNavigator::setWorldCoordinateYMin(double coordinate) { this->m_WorldCoordinateYMin = coordinate; } void QmlMitkImageNavigator::setWorldCoordinateZMin(double coordinate) { this->m_WorldCoordinateZMin = coordinate; } void QmlMitkImageNavigator::setWorldCoordinateXMax(double coordinate) { this->m_WorldCoordinateXMax = coordinate; } void QmlMitkImageNavigator::setWorldCoordinateYMax(double coordinate) { this->m_WorldCoordinateYMax = coordinate; } void QmlMitkImageNavigator::setWorldCoordinateZMax(double coordinate) { this->m_WorldCoordinateZMax = coordinate; } double QmlMitkImageNavigator::getWorldCoordinateX() { return this->m_WorldCoordinateX; } double QmlMitkImageNavigator::getWorldCoordinateY() { return this->m_WorldCoordinateY; } double QmlMitkImageNavigator::getWorldCoordinateZ() { return this->m_WorldCoordinateZ; } double QmlMitkImageNavigator::getWorldCoordinateXMin() { return this->m_WorldCoordinateXMin; } double QmlMitkImageNavigator::getWorldCoordinateYMin() { return this->m_WorldCoordinateYMin; } double QmlMitkImageNavigator::getWorldCoordinateZMin() { return this->m_WorldCoordinateZMin; } double QmlMitkImageNavigator::getWorldCoordinateXMax() { return this->m_WorldCoordinateXMax; } double QmlMitkImageNavigator::getWorldCoordinateYMax() { return this->m_WorldCoordinateYMax; } double QmlMitkImageNavigator::getWorldCoordinateZMax() { return this->m_WorldCoordinateZMax; } void QmlMitkImageNavigator::initialize() { if(!QmlMitkStdMultiItem::instance) return; QmlMitkRenderWindowItem* renderWindow = QmlMitkStdMultiItem::instance->getViewerAxial(); if (renderWindow) { if (m_AxialStepper) m_AxialStepper->deleteLater(); m_AxialStepper = new QmitkStepperAdapter(this->m_NavigatorAxial, renderWindow->GetSliceNavigationController()->GetSlice(), "sliceNavigatorAxialFromSimpleExample"); connect(m_AxialStepper, SIGNAL(Refetch()), this, SLOT(OnRefetch())); } else { this->m_NavigatorAxial->setEnabled(false); } renderWindow = QmlMitkStdMultiItem::instance->getViewerSagittal(); if (renderWindow) { if (m_SagittalStepper) m_SagittalStepper->deleteLater(); m_SagittalStepper = new QmitkStepperAdapter(this->m_NavigatorSagittal, renderWindow->GetSliceNavigationController()->GetSlice(), "sliceNavigatorSagittalFromSimpleExample"); connect(m_SagittalStepper, SIGNAL(Refetch()), this, SLOT(OnRefetch())); } else { this->m_NavigatorSagittal->setEnabled(false); } renderWindow = QmlMitkStdMultiItem::instance->getViewerCoronal(); if (renderWindow) { if (m_FrontalStepper) m_FrontalStepper->deleteLater(); m_FrontalStepper = new QmitkStepperAdapter(this->m_NavigatorCoronal, renderWindow->GetSliceNavigationController()->GetSlice(), "sliceNavigatorFrontalFromSimpleExample"); connect(m_FrontalStepper, SIGNAL(Refetch()), this, SLOT(OnRefetch())); } else { this->m_NavigatorCoronal->setEnabled(false); } mitk::SliceNavigationController* timeController = mitk::RenderingManager::GetInstance()->GetTimeNavigationController(); if (timeController) { if (m_TimeStepper) m_TimeStepper->deleteLater(); m_TimeStepper = new QmitkStepperAdapter(this->m_NavigatorTime, timeController->GetTime(), "sliceNavigatorTimeFromSimpleExample"); } else { this->m_NavigatorTime->setEnabled(false); } } int QmlMitkImageNavigator::GetClosestAxisIndex(mitk::Vector3D normal) { // cos(theta) = normal . axis // cos(theta) = (a, b, c) . (d, e, f) // cos(theta) = (a, b, c) . (1, 0, 0) = a // cos(theta) = (a, b, c) . (0, 1, 0) = b // cos(theta) = (a, b, c) . (0, 0, 1) = c double absCosThetaWithAxis[3]; for (int i = 0; i < 3; i++) { absCosThetaWithAxis[i] = fabs(normal[i]); } int largestIndex = 0; double largestValue = absCosThetaWithAxis[0]; for (int i = 1; i < 3; i++) { if (absCosThetaWithAxis[i] > largestValue) { largestValue = absCosThetaWithAxis[i]; largestIndex = i; } } return largestIndex; } void QmlMitkImageNavigator::SetStepSizes() { this->SetStepSize(0); this->SetStepSize(1); this->SetStepSize(2); } void QmlMitkImageNavigator::SetStepSize(int axis) { mitk::BaseGeometry::ConstPointer geometry = QmlMitkStdMultiItem::instance->getViewerAxial()->GetSliceNavigationController()->GetInputWorldGeometry3D(); if (geometry.IsNotNull()) { mitk::Point3D crossPositionInIndexCoordinates; mitk::Point3D crossPositionInIndexCoordinatesPlus1; mitk::Point3D crossPositionInMillimetresPlus1; mitk::Vector3D transformedAxisDirection; mitk::Point3D crossPositionInMillimetres = QmlMitkStdMultiItem::instance->getCrossPosition(); geometry->WorldToIndex(crossPositionInMillimetres, crossPositionInIndexCoordinates); crossPositionInIndexCoordinatesPlus1 = crossPositionInIndexCoordinates; crossPositionInIndexCoordinatesPlus1[axis] += 1; geometry->IndexToWorld(crossPositionInIndexCoordinatesPlus1, crossPositionInMillimetresPlus1); transformedAxisDirection = crossPositionInMillimetresPlus1 - crossPositionInMillimetres; int closestAxisInMillimetreSpace = this->GetClosestAxisIndex(transformedAxisDirection); double stepSize = transformedAxisDirection.GetNorm(); this->SetStepSize(closestAxisInMillimetreSpace, stepSize); } } -void QmlMitkImageNavigator::SetStepSize(int axis, double stepSize) +void QmlMitkImageNavigator::SetStepSize(int, double) { - if (axis == 0) - { - //m_Controls.m_XWorldCoordinateSpinBox->setSingleStep(stepSize); - } - else if (axis == 1) - { - //m_Controls.m_YWorldCoordinateSpinBox->setSingleStep(stepSize); - } - else if (axis == 2) - { - //m_Controls.m_ZWorldCoordinateSpinBox->setSingleStep(stepSize); - } } void QmlMitkImageNavigator::OnMillimetreCoordinateValueChanged() { mitk::TimeGeometry::ConstPointer geometry = QmlMitkStdMultiItem::instance->getViewerAxial()->GetSliceNavigationController()->GetInputWorldTimeGeometry(); if (geometry.IsNotNull()) { mitk::Point3D positionInWorldCoordinates; positionInWorldCoordinates[0] = this->m_WorldCoordinateX; positionInWorldCoordinates[1] = this->m_WorldCoordinateY; positionInWorldCoordinates[2] = this->m_WorldCoordinateZ; QmlMitkStdMultiItem::instance->moveCrossToPosition(positionInWorldCoordinates); } } void QmlMitkImageNavigator::OnRefetch() { mitk::BaseGeometry::ConstPointer geometry = QmlMitkStdMultiItem::instance->getViewerAxial()->GetSliceNavigationController()->GetInputWorldGeometry3D(); mitk::TimeGeometry::ConstPointer timeGeometry = QmlMitkStdMultiItem::instance->getViewerAxial()->GetSliceNavigationController()->GetInputWorldTimeGeometry(); if (geometry.IsNull() && timeGeometry.IsNotNull()) { mitk::TimeStepType timeStep = QmlMitkStdMultiItem::instance->getViewerAxial()->GetSliceNavigationController()->GetTime()->GetPos(); geometry = timeGeometry->GetGeometryForTimeStep(timeStep); } if (geometry.IsNotNull()) { mitk::BoundingBox::BoundsArrayType bounds = geometry->GetBounds(); mitk::Point3D cornerPoint1InIndexCoordinates; cornerPoint1InIndexCoordinates[0] = bounds[0]; cornerPoint1InIndexCoordinates[1] = bounds[2]; cornerPoint1InIndexCoordinates[2] = bounds[4]; mitk::Point3D cornerPoint2InIndexCoordinates; cornerPoint2InIndexCoordinates[0] = bounds[1]; cornerPoint2InIndexCoordinates[1] = bounds[3]; cornerPoint2InIndexCoordinates[2] = bounds[5]; if (!geometry->GetImageGeometry()) { cornerPoint1InIndexCoordinates[0] += 0.5; cornerPoint1InIndexCoordinates[1] += 0.5; cornerPoint1InIndexCoordinates[2] += 0.5; cornerPoint2InIndexCoordinates[0] -= 0.5; cornerPoint2InIndexCoordinates[1] -= 0.5; cornerPoint2InIndexCoordinates[2] -= 0.5; } mitk::Point3D crossPositionInWorldCoordinates = QmlMitkStdMultiItem::instance->getCrossPosition(); mitk::Point3D cornerPoint1InWorldCoordinates; mitk::Point3D cornerPoint2InWorldCoordinates; geometry->IndexToWorld(cornerPoint1InIndexCoordinates, cornerPoint1InWorldCoordinates); geometry->IndexToWorld(cornerPoint2InIndexCoordinates, cornerPoint2InWorldCoordinates); this->m_WorldCoordinateXMin = std::min(cornerPoint1InWorldCoordinates[0], cornerPoint2InWorldCoordinates[0]); this->m_WorldCoordinateYMin = std::min(cornerPoint1InWorldCoordinates[1], cornerPoint2InWorldCoordinates[1]); this->m_WorldCoordinateZMin = std::min(cornerPoint1InWorldCoordinates[2], cornerPoint2InWorldCoordinates[2]); this->m_WorldCoordinateXMax = std::max(cornerPoint1InWorldCoordinates[0], cornerPoint2InWorldCoordinates[0]); this->m_WorldCoordinateYMax = std::max(cornerPoint1InWorldCoordinates[1], cornerPoint2InWorldCoordinates[1]); this->m_WorldCoordinateZMax = std::max(cornerPoint1InWorldCoordinates[2], cornerPoint2InWorldCoordinates[2]); this->m_WorldCoordinateX = crossPositionInWorldCoordinates[0]; this->m_WorldCoordinateY = crossPositionInWorldCoordinates[1]; this->m_WorldCoordinateZ = crossPositionInWorldCoordinates[2]; emit this->sync(); } } void QmlMitkImageNavigator::create(QQmlEngine &engine) { QmlMitkSliderNavigatorItem::create(); qmlRegisterType("Mitk.Views", 1, 0, "ImageNavigator"); QQmlComponent component(&engine, QUrl("qrc:/MitkImageNavigator.qml")); } diff --git a/Modules/QmlItems/src/QmlMitkPiecewiseFunctionCanvas.cpp b/Modules/QmlItems/src/QmlMitkPiecewiseFunctionCanvas.cpp index 35df234279..8f9f4a1133 100644 --- a/Modules/QmlItems/src/QmlMitkPiecewiseFunctionCanvas.cpp +++ b/Modules/QmlItems/src/QmlMitkPiecewiseFunctionCanvas.cpp @@ -1,213 +1,180 @@ /*=================================================================== 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 "QmlMitkPiecewiseFunctionCanvas.h" #include QmlMitkPiecewiseFunctionCanvas* QmlMitkPiecewiseFunctionCanvas::instance = nullptr; QmlMitkPiecewiseFunctionCanvas::QmlMitkPiecewiseFunctionCanvas(QQuickPaintedItem* parent) : QmlMitkTransferFunctionCanvas(parent), m_PiecewiseFunction(nullptr) { instance = this; setAcceptedMouseButtons(Qt::AllButtons); } void QmlMitkPiecewiseFunctionCanvas::setGreyValue(double value) { this->m_GreyValue = value; this->SetX(value); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } double QmlMitkPiecewiseFunctionCanvas::getGreyValue() { return this->m_GreyValue; } void QmlMitkPiecewiseFunctionCanvas::setOpacity(double opacity) { this->m_Opacity = opacity; this->SetY(opacity); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } double QmlMitkPiecewiseFunctionCanvas::getOpacity() { return this->m_Opacity; } void QmlMitkPiecewiseFunctionCanvas::SetTitle(const QString& title) { m_Title=title; } void QmlMitkPiecewiseFunctionCanvas::paint(QPainter* painter) { PaintHistogram(painter); if (m_Title.size()>0) { painter->setPen(Qt::black); painter->drawText(QPoint(11,21),m_Title); painter->setPen(Qt::white); painter->drawText(QPoint(10,20),m_Title); } - { - - QString qs_min = QString::number( m_Min, 'g', 4 ); - QString qs_max = QString::number( m_Max, 'g', 4 ); - - QRect qr_min = painter->fontMetrics().boundingRect( qs_min ); - QRect qr_max = painter->fontMetrics().boundingRect( qs_max ); - - int y,x; - - y=this->boundingRect().height()-qr_min.height()+5; - //y = this->boundingRect().height()+5; - x=10; - - // Fill the tf presets in the generator widget - /* - painter->setPen(Qt::black); - painter->drawText(QPoint(x+1,y+1),qs_min); - painter->setPen(Qt::white); - painter->drawText(QPoint(x ,y ),qs_min); - - y=this->boundingRect().height()-qr_max.height()+5; - x=this->boundingRect().width()-qr_max.width()-6; - - painter->setPen(Qt::black); - painter->drawText(QPoint(x,y+1),qs_max); - painter->setPen(Qt::white); - painter->drawText(QPoint(x,y ),qs_max); - */ - } - painter->setPen(Qt::gray); - QRectF contentsRect = this->boundingRect(); - //painter->drawRect(0, 0, contentsRect.width()+1, contentsRect.height()+1); if (m_PiecewiseFunction && this->isEnabled()) { double* dp = m_PiecewiseFunction->GetDataPointer(); // Render lines painter->setPen(Qt::black); for (int i = -1; i < m_PiecewiseFunction->GetSize(); i++) { std::pair left; std::pair right; if(i < 0) left = this->FunctionToCanvas(std::make_pair(-32768, dp[0 * 2 + 1])); else left = this->FunctionToCanvas(std::make_pair(dp[i * 2], dp[i * 2 + 1])); if(i+1 >= m_PiecewiseFunction->GetSize()) right = this->FunctionToCanvas(std::make_pair(32768, dp[(i ) * 2 + 1])); else right = this->FunctionToCanvas(std::make_pair(dp[(i+1) * 2], dp[(i+1) * 2 + 1])); painter->drawLine(left.first, left.second, right.first, right.second); } // Render Points for (int i = 0; i < m_PiecewiseFunction->GetSize(); i++) { std::pair point = this->FunctionToCanvas(std::make_pair( dp[i * 2], dp[i * 2 + 1])); if (i == m_GrabbedHandle) { painter->setBrush(QBrush(Qt::red)); this->m_Opacity = QString::number(GetFunctionY(m_GrabbedHandle), 'g', 4).toFloat(); this->m_GreyValue = QString::number(GetFunctionX(m_GrabbedHandle), 'g', 4).toFloat(); emit this->sync(); } else { painter->setBrush(QBrush(Qt::green)); } painter->drawEllipse(point.first - 4, point.second - 4, 8, 8); } painter->setBrush(Qt::NoBrush); } } int QmlMitkPiecewiseFunctionCanvas::GetNearHandle(int x, int y, unsigned int maxSquaredDistance) { double* dp = m_PiecewiseFunction->GetDataPointer(); for (int i = 0; i < m_PiecewiseFunction->GetSize(); i++) { std::pair point = this->FunctionToCanvas(std::make_pair(dp[i * 2], dp[i * 2 + 1])); if ((unsigned int) ((point.first - x) * (point.first - x) + (point.second - y) * (point.second - y)) <= maxSquaredDistance) { return i; } } return -1; } void QmlMitkPiecewiseFunctionCanvas::MoveFunctionPoint(int index, std::pair pos) { RemoveFunctionPoint(GetFunctionX(index)); m_GrabbedHandle = AddFunctionPoint(pos.first, pos.second); } void QmlMitkPiecewiseFunctionCanvas::mousePressEvent( QMouseEvent* mouseEvent ) { QmlMitkTransferFunctionCanvas::mousePressEvent(mouseEvent); } void QmlMitkPiecewiseFunctionCanvas::mouseMoveEvent( QMouseEvent* mouseEvent ) { QmlMitkTransferFunctionCanvas::mouseMoveEvent(mouseEvent); } void QmlMitkPiecewiseFunctionCanvas::mouseReleaseEvent( QMouseEvent* mouseEvent ) { QmlMitkTransferFunctionCanvas::mouseReleaseEvent(mouseEvent); } void QmlMitkPiecewiseFunctionCanvas::mouseDoubleClickEvent( QMouseEvent* mouseEvent ) { QmlMitkTransferFunctionCanvas::mouseDoubleClickEvent(mouseEvent); } void QmlMitkPiecewiseFunctionCanvas::keyPressEvent(QKeyEvent *keyEvent) { QmlMitkTransferFunctionCanvas::keyPressEvent(keyEvent); } void QmlMitkPiecewiseFunctionCanvas::create() { qmlRegisterType("Mitk.Views", 1, 0, "PiecewiseItem"); } diff --git a/Modules/QmlItems/src/QmlMitkSliderLevelWindowItem.cpp b/Modules/QmlItems/src/QmlMitkSliderLevelWindowItem.cpp index d4a58ce026..35b715a169 100644 --- a/Modules/QmlItems/src/QmlMitkSliderLevelWindowItem.cpp +++ b/Modules/QmlItems/src/QmlMitkSliderLevelWindowItem.cpp @@ -1,571 +1,571 @@ /*=================================================================== 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 #include #include #include #include #include #include #include QmlMitkSliderLevelWindowItem* QmlMitkSliderLevelWindowItem::instance = nullptr; mitk::DataStorage::Pointer QmlMitkSliderLevelWindowItem::storage = nullptr; QmlMitkSliderLevelWindowItem::QmlMitkSliderLevelWindowItem( QQuickPaintedItem * parent ) : QQuickPaintedItem(parent) { m_Manager = mitk::LevelWindowManager::New(); m_Manager->SetDataStorage(QmlMitkSliderLevelWindowItem::storage); itk::ReceptorMemberCommand::Pointer command = itk::ReceptorMemberCommand::New(); command->SetCallbackFunction(this, &QmlMitkSliderLevelWindowItem::OnPropertyModified); m_ObserverTag = m_Manager->AddObserver(itk::ModifiedEvent(), command); m_IsObserverTagSet = true; setAcceptedMouseButtons(Qt::AllButtons); setAcceptHoverEvents(true); setAntialiasing(true); m_Resize = false; m_Bottom = false; m_CtrlPressed = false; m_MouseDown = false; m_ScaleVisible = true; this->setEnabled(false); update(); } QmlMitkSliderLevelWindowItem::~QmlMitkSliderLevelWindowItem() { if ( m_IsObserverTagSet) { m_Manager->RemoveObserver(m_ObserverTag); m_IsObserverTagSet = false; } } void QmlMitkSliderLevelWindowItem::setLevelWindowManager(mitk::LevelWindowManager* levelWindowManager) { if ( m_IsObserverTagSet) { m_Manager->RemoveObserver(m_ObserverTag); m_IsObserverTagSet = false; } m_Manager = levelWindowManager; if ( m_Manager.IsNotNull() ) { itk::ReceptorMemberCommand::Pointer command = itk::ReceptorMemberCommand::New(); command->SetCallbackFunction(this, &QmlMitkSliderLevelWindowItem::OnPropertyModified); m_ObserverTag = m_Manager->AddObserver(itk::ModifiedEvent(), command); m_IsObserverTagSet = true; } } void QmlMitkSliderLevelWindowItem::OnPropertyModified(const itk::EventObject& ) { try { m_LevelWindow = m_Manager->GetLevelWindow(); this->m_Level = (int)m_LevelWindow.GetLevel(); this->m_Window = (int)m_LevelWindow.GetWindow(); this->setEnabled(true); emit this->sync(); update(); } catch(...) { this->setEnabled(false); } QQuickPaintedItem::update(); } bool QmlMitkSliderLevelWindowItem::isEnabled() { return this->m_Enabled; } void QmlMitkSliderLevelWindowItem::setEnabled(bool enable) { this->m_Enabled = enable; emit this->enabledChanged(); } int QmlMitkSliderLevelWindowItem::fontSize() const { return this->m_FontSize; } void QmlMitkSliderLevelWindowItem::setFontSize(const int &fontSize) { this->m_FontSize = fontSize; this->m_Font.setPointSize(fontSize); } QColor QmlMitkSliderLevelWindowItem::fontColor() const { return this->m_FontColor; } void QmlMitkSliderLevelWindowItem::setFontColor(const QColor &color) { this->m_FontColor = color; } QColor QmlMitkSliderLevelWindowItem::color() const { return this->m_Color; } void QmlMitkSliderLevelWindowItem::setColor(const QColor &color) { this->m_Color = color; } QColor QmlMitkSliderLevelWindowItem::borderColor() const { return this->m_BorderColor; } void QmlMitkSliderLevelWindowItem::setBorderColor(const QColor &color) { this->m_BorderColor = color; } void QmlMitkSliderLevelWindowItem::setLevel(int level) { if(level != m_LevelWindow.GetLevel()) { m_LevelWindow.SetLevelWindow(level, m_LevelWindow.GetWindow()); m_Manager->SetLevelWindow(m_LevelWindow); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } this->m_Level = level; } int QmlMitkSliderLevelWindowItem::getLevel() { return this->m_Level; } void QmlMitkSliderLevelWindowItem::setWindow(int window) { if(window != m_LevelWindow.GetWindow()) { m_LevelWindow.SetLevelWindow(m_LevelWindow.GetLevel(), window); m_Manager->SetLevelWindow(m_LevelWindow); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } this->m_Window = window; } int QmlMitkSliderLevelWindowItem::getWindow() { return this->m_Window; } void QmlMitkSliderLevelWindowItem::paint( QPainter* painter ) { if(!this->m_Enabled) return; m_MoveHeight = boundingRect().height() - 55; painter->setFont( m_Font ); painter->setPen(this->m_BorderColor); painter->setBrush(this->m_Color); painter->drawRoundedRect(m_Rect, 3, 3); painter->setPen(this->m_FontColor); float mr = m_LevelWindow.GetRange(); if ( mr < 1 ) mr = 1; float fact = (float) m_MoveHeight / mr; //begin draw scale if (m_ScaleVisible) { int minRange = (int)m_LevelWindow.GetRangeMin(); int maxRange = (int)m_LevelWindow.GetRangeMax(); int yValue = m_MoveHeight + (int)(minRange*fact); QString s = " 0"; if (minRange <= 0 && maxRange >= 0) { painter->drawLine( 5, yValue , 15, yValue); painter->drawText( 21, yValue + 3, s ); } int count = 1; int k = 5; bool enoughSpace = false; bool enoughSpace2 = false; double dStepSize = pow(10,floor(log10(mr/100))+1); for(int i = m_MoveHeight + (int)(minRange*fact); i < m_MoveHeight;)//negative { if (-count*dStepSize < minRange) break; yValue = m_MoveHeight + (int)((minRange + count*dStepSize)*fact); s = QString::number(-count*dStepSize); if (count % k && ((dStepSize*fact) > 2.5)) { painter->drawLine( 8, yValue, 12, yValue); enoughSpace = true; } else if (!(count % k)) { if ((k*dStepSize*fact) > 7) { painter->drawLine( 5, yValue, 15, yValue); painter->drawText( 21, yValue + 3, s ); enoughSpace2 = true; } else { k += 5; } } if (enoughSpace) { i=yValue; count++; } else if (enoughSpace2) { i=yValue; count += k; } else { i=yValue; count = k; } } count = 1; k = 5; enoughSpace = false; enoughSpace2 = false; for(int i = m_MoveHeight + (int)(minRange*fact); i >= 0;) { if (count*dStepSize > maxRange) break; yValue = m_MoveHeight + (int)((minRange - count*dStepSize)*fact); s = QString::number(count*dStepSize); if(count % k && ((dStepSize*fact) > 2.5)) { if (!(minRange > 0 && (count*dStepSize) < minRange)) painter->drawLine( 8, yValue, 12, yValue); enoughSpace = true; } else if (!(count % k)) { if ((k*dStepSize*fact) > 7) { if (!(minRange > 0 && (count*dStepSize) < minRange)) { painter->drawLine( 5, yValue, 15, yValue); painter->drawText( 21, yValue + 3, s ); } enoughSpace2 = true; } else { k += 5; } } if (enoughSpace) { i=yValue; count++; } else if (enoughSpace2) { i=yValue; count += k; } else { i=yValue; count = k; } } } } void QmlMitkSliderLevelWindowItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { update(); QQuickPaintedItem::geometryChanged(newGeometry, oldGeometry); } void QmlMitkSliderLevelWindowItem::hoverMoveEvent(QHoverEvent *mouseEvent) { if ( mouseEvent->pos().y() >= 0 && mouseEvent->pos().y() <= (m_Rect.topLeft().y() + 3) ) { setCursor(Qt::SizeVerCursor); m_UpperBound.setRect(m_Rect.topLeft().x(), m_Rect.topLeft().y() - 3, 17, 7); //this->setToolTip("Ctrl + left click to change only upper bound"); m_Resize = true; } else if ( mouseEvent->pos().y() >= (m_Rect.bottomLeft().y() - 3) ) { setCursor(Qt::SizeVerCursor); m_LowerBound.setRect(m_Rect.bottomLeft().x(), m_Rect.bottomLeft().y() - 3, 17, 7); //this->setToolTip("Ctrl + left click to change only lower bound"); m_Resize = true; m_Bottom = true; } else { setCursor(Qt::ArrowCursor); //this->setToolTip("Left click and mouse move to adjust the slider"); m_Resize = false; m_Bottom = false; } } /** * */ void QmlMitkSliderLevelWindowItem::mouseMoveEvent( QMouseEvent* mouseEvent ) { if(!mouseEvent && !m_MouseDown) return; if ( m_LevelWindow.IsFixed() ) return; float fact = (float) m_MoveHeight / m_LevelWindow.GetRange(); if ( m_Leftbutton ) { if (m_Resize && !m_CtrlPressed) { double diff = (mouseEvent->pos().y()) / fact; diff -= (m_StartPos.y()) / fact; m_StartPos = mouseEvent->pos(); if (diff == 0) return; float value; if (m_Bottom) value = m_LevelWindow.GetWindow() + ( ( 2 * diff ) ); else value = m_LevelWindow.GetWindow() - ( ( 2 * diff ) ); if ( value < 0 ) value = 0; m_LevelWindow.SetLevelWindow( m_LevelWindow.GetLevel(), value ); } else if(m_Resize && m_CtrlPressed) { if (!m_Bottom) { double diff = (mouseEvent->pos().y()) / fact; diff -= (m_StartPos.y()) / fact; m_StartPos = mouseEvent->pos(); if (diff == 0) return; float value; value = m_LevelWindow.GetWindow() - ( ( diff ) ); if ( value < 0 ) value = 0; float oldWindow; float oldLevel; float newLevel; oldWindow = m_LevelWindow.GetWindow(); oldLevel = m_LevelWindow.GetLevel(); newLevel = oldLevel + (value - oldWindow)/2; if (!((newLevel + value/2) > m_LevelWindow.GetRangeMax())) m_LevelWindow.SetLevelWindow( newLevel, value ); } else { double diff = (mouseEvent->pos().y()) / fact; diff -= (m_StartPos.y()) / fact; m_StartPos = mouseEvent->pos(); if (diff == 0) return; float value; value = m_LevelWindow.GetWindow() + ( ( diff ) ); if ( value < 0 ) value = 0; float oldWindow; float oldLevel; float newLevel; oldWindow = m_LevelWindow.GetWindow(); oldLevel = m_LevelWindow.GetLevel(); newLevel = oldLevel - (value - oldWindow)/2; if (!((newLevel - value/2) < m_LevelWindow.GetRangeMin())) m_LevelWindow.SetLevelWindow( newLevel, value ); } } else { const float minv = m_LevelWindow.GetRangeMin(); const float level = (m_MoveHeight - mouseEvent->pos().y()) / fact + minv; double diff = (mouseEvent->pos().x()) / fact; diff -= (m_StartPos.x()) / fact; m_StartPos = mouseEvent->pos(); float window; if (m_Bottom) window = m_LevelWindow.GetWindow() + ( ( 2 * diff ) ); else window = m_LevelWindow.GetWindow() - ( ( 2 * diff ) ); if ( window < 0 ) window = 0; m_LevelWindow.SetLevelWindow( level, window ); } m_Manager->SetLevelWindow(m_LevelWindow); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } /** * */ void QmlMitkSliderLevelWindowItem::mousePressEvent( QMouseEvent* mouseEvent ) { if ( m_LevelWindow.IsFixed() ) return; m_MouseDown = true; m_StartPos = mouseEvent->pos(); if ( mouseEvent->button() == Qt::LeftButton ) { if (mouseEvent->modifiers() == Qt::ControlModifier || mouseEvent->modifiers() == Qt::ShiftModifier) { m_CtrlPressed = true; } else { m_CtrlPressed = false; } m_Leftbutton = true; } else m_Leftbutton = false; mouseMoveEvent( mouseEvent ); } /** * */ void QmlMitkSliderLevelWindowItem::mouseReleaseEvent( QMouseEvent* ) { if ( m_LevelWindow.IsFixed() ) return; m_MouseDown = false; } /** * */ void QmlMitkSliderLevelWindowItem::update() { int rectWidth; if(m_ScaleVisible) { rectWidth = 16; } else { rectWidth = 26; } float mr = m_LevelWindow.GetRange(); if ( mr < 1 ) mr = 1; float fact = (float) m_MoveHeight / mr; float rectHeight = m_LevelWindow.GetWindow() * fact; if ( rectHeight < 15 ) rectHeight = 15; if ( m_LevelWindow.GetLowerWindowBound() < 0 ) m_Rect.setRect( 2, (int) (m_MoveHeight - (m_LevelWindow.GetUpperWindowBound() - m_LevelWindow.GetRangeMin()) * fact) , rectWidth, (int) rectHeight ); else m_Rect.setRect( 2, (int) (m_MoveHeight - (m_LevelWindow.GetUpperWindowBound() - m_LevelWindow.GetRangeMin()) * fact), rectWidth, (int) rectHeight ); QQuickPaintedItem::update(); } void QmlMitkSliderLevelWindowItem::hideScale() { m_ScaleVisible = false; update(); } void QmlMitkSliderLevelWindowItem::showScale() { m_ScaleVisible = true; update(); } void QmlMitkSliderLevelWindowItem::setDataStorage(mitk::DataStorage* ds) { m_Manager->SetDataStorage(ds); } mitk::LevelWindowManager* QmlMitkSliderLevelWindowItem::GetManager() { return m_Manager.GetPointer(); } -void QmlMitkSliderLevelWindowItem::create(QQmlEngine &engine, mitk::DataStorage::Pointer storage) +void QmlMitkSliderLevelWindowItem::create(QQmlEngine &, mitk::DataStorage::Pointer storage) { qmlRegisterType("Mitk.Views", 1, 0, "LevelWindow"); QmlMitkSliderLevelWindowItem::storage = storage; }