22 #include <QMouseEvent>
25 #include <itkCommand.h>
34 : QQuickPaintedItem(parent)
37 m_Manager->SetDataStorage(QmlMitkSliderLevelWindowItem::storage);
40 command->SetCallbackFunction(
this, &QmlMitkSliderLevelWindowItem::OnPropertyModified);
41 m_ObserverTag = m_Manager->AddObserver(itk::ModifiedEvent(), command);
44 setAcceptedMouseButtons(Qt::AllButtons);
45 setAcceptHoverEvents(
true);
46 setAntialiasing(
true);
75 m_Manager = levelWindowManager;
76 if ( m_Manager.IsNotNull() )
79 command->SetCallbackFunction(
this, &QmlMitkSliderLevelWindowItem::OnPropertyModified);
80 m_ObserverTag = m_Manager->AddObserver(itk::ModifiedEvent(), command);
85 void QmlMitkSliderLevelWindowItem::OnPropertyModified(
const itk::EventObject& )
89 m_LevelWindow = m_Manager->GetLevelWindow();
91 this->m_Level = (int)m_LevelWindow.
GetLevel();
92 this->m_Window = (int)m_LevelWindow.
GetWindow();
103 QQuickPaintedItem::update();
108 return this->m_Enabled;
113 this->m_Enabled = enable;
125 this->m_Font.setPointSize(fontSize);
130 return this->m_FontColor;
135 this->m_FontColor =
color;
140 return this->m_Color;
145 this->m_Color =
color;
150 return this->m_BorderColor;
155 this->m_BorderColor =
color;
161 if(level != m_LevelWindow.
GetLevel())
164 m_Manager->SetLevelWindow(m_LevelWindow);
169 this->m_Level =
level;
174 return this->m_Level;
183 m_Manager->SetLevelWindow(m_LevelWindow);
192 return this->m_Window;
202 painter->setFont( m_Font );
203 painter->setPen(this->m_BorderColor);
205 painter->setBrush(this->m_Color);
206 painter->drawRoundedRect(
m_Rect, 3, 3);
208 painter->setPen(this->m_FontColor);
210 float mr = m_LevelWindow.
GetRange();
224 if (minRange <= 0 && maxRange >= 0)
226 painter->drawLine( 5, yValue , 15, yValue);
227 painter->drawText( 21, yValue + 3, s );
232 bool enoughSpace =
false;
233 bool enoughSpace2 =
false;
235 double dStepSize = pow(10,floor(log10(mr/100))+1);
239 if (-count*dStepSize < minRange)
241 yValue = m_MoveHeight + (int)((minRange + count*dStepSize)*fact);
243 s = QString::number(-count*dStepSize);
244 if (count % k && ((dStepSize*fact) > 2.5))
246 painter->drawLine( 8, yValue, 12, yValue);
249 else if (!(count % k))
251 if ((k*dStepSize*fact) > 7)
253 painter->drawLine( 5, yValue, 15, yValue);
254 painter->drawText( 21, yValue + 3, s );
267 else if (enoughSpace2)
281 enoughSpace2 =
false;
283 for(
int i = m_MoveHeight + (
int)(minRange*fact); i >= 0;)
285 if (count*dStepSize > maxRange)
287 yValue = m_MoveHeight + (int)((minRange - count*dStepSize)*fact);
289 s = QString::number(count*dStepSize);
290 if(count % k && ((dStepSize*fact) > 2.5))
292 if (!(minRange > 0 && (count*dStepSize) < minRange))
293 painter->drawLine( 8, yValue, 12, yValue);
296 else if (!(count % k))
298 if ((k*dStepSize*fact) > 7)
300 if (!(minRange > 0 && (count*dStepSize) < minRange))
302 painter->drawLine( 5, yValue, 15, yValue);
303 painter->drawText( 21, yValue + 3, s );
317 else if (enoughSpace2)
334 QQuickPaintedItem::geometryChanged(newGeometry, oldGeometry);
339 if ( mouseEvent->pos().y() >= 0
340 && mouseEvent->pos().y() <= (
m_Rect.topLeft().y() + 3) )
342 setCursor(Qt::SizeVerCursor);
347 else if ( mouseEvent->pos().y() >= (
m_Rect.bottomLeft().y() - 3) )
349 setCursor(Qt::SizeVerCursor);
357 setCursor(Qt::ArrowCursor);
380 double diff = (mouseEvent->pos().y()) / fact;
384 if (diff == 0)
return;
387 value = m_LevelWindow.
GetWindow() + ( ( 2 * diff ) );
389 value = m_LevelWindow.
GetWindow() - ( ( 2 * diff ) );
400 double diff = (mouseEvent->pos().y()) / fact;
404 if (diff == 0)
return;
407 value = m_LevelWindow.
GetWindow() - ( ( diff ) );
415 oldLevel = m_LevelWindow.
GetLevel();
416 newLevel = oldLevel + (value - oldWindow)/2;
417 if (!((newLevel + value/2) > m_LevelWindow.
GetRangeMax()))
422 double diff = (mouseEvent->pos().y()) / fact;
426 if (diff == 0)
return;
429 value = m_LevelWindow.
GetWindow() + ( ( diff ) );
437 oldLevel = m_LevelWindow.
GetLevel();
438 newLevel = oldLevel - (value - oldWindow)/2;
439 if (!((newLevel - value/2) < m_LevelWindow.
GetRangeMin()))
449 double diff = (mouseEvent->pos().x()) / fact;
455 window = m_LevelWindow.
GetWindow() + ( ( 2 * diff ) );
457 window = m_LevelWindow.
GetWindow() - ( ( 2 * diff ) );
464 m_Manager->SetLevelWindow(m_LevelWindow);
479 if ( mouseEvent->button() == Qt::LeftButton )
481 if (mouseEvent->modifiers() == Qt::ControlModifier || mouseEvent->modifiers() == Qt::ShiftModifier)
523 float mr = m_LevelWindow.
GetRange();
530 float rectHeight = m_LevelWindow.
GetWindow() * fact;
532 if ( rectHeight < 15 )
540 QQuickPaintedItem::update();
558 m_Manager->SetDataStorage(ds);
563 return m_Manager.GetPointer();
568 qmlRegisterType<QmlMitkSliderLevelWindowItem>(
"Mitk.Views", 1, 0,
"LevelWindow");
570 QmlMitkSliderLevelWindowItem::storage = storage;
unsigned long m_ObserverTag
Data management class that handles 'was created by' relations.
itk::SmartPointer< Self > Pointer
void setDataStorage(mitk::DataStorage *ds)
ScalarType GetLowerWindowBound() const
static QmlMitkSliderLevelWindowItem * instance
QColor borderColor() const
~QmlMitkSliderLevelWindowItem()
void setLevelWindowManager(mitk::LevelWindowManager *levelWindowManager)
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override
void setWindow(int window)
void mouseMoveEvent(QMouseEvent *mouseEvent) override
QmlMitkSliderLevelWindowItem(QQuickPaintedItem *parent=nullptr)
static RenderingManager * GetInstance()
static void create(QQmlEngine &engine, mitk::DataStorage::Pointer storage)
void setFontSize(const int &fontSize)
void setColor(const QColor &color)
ScalarType GetRangeMax() const
void setEnabled(bool enable)
void setFontColor(const QColor &color)
void mousePressEvent(QMouseEvent *mouseEvent) override
mitk::LevelWindowManager * GetManager()
void paint(QPainter *painter) override
ScalarType GetRangeMin() const
ScalarType GetUpperWindowBound() const
void mouseReleaseEvent(QMouseEvent *mouseEvent) override
void SetLevelWindow(ScalarType level, ScalarType window, bool expandRangesIfNecessary=true)
Provides access to the LevelWindowProperty object and LevelWindow of the "current" image...
ScalarType GetWindow() const
returns the current window size, i.e the range size of the current grey value interval ...
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)
ScalarType GetRange() const
returns the size of the grey value range
void setBorderColor(const QColor &color)
ScalarType GetLevel() const
method that returns the level value, i.e. the center of the current grey value interval ...
void hoverMoveEvent(QHoverEvent *event) override
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.