23 #include <QMouseEvent> 28 #include <itkCommand.h> 38 itk::ReceptorMemberCommand<QmitkSliderLevelWindowWidget>::Pointer command =
39 itk::ReceptorMemberCommand<QmitkSliderLevelWindowWidget>::New();
40 command->SetCallbackFunction(
this, &QmitkSliderLevelWindowWidget::OnPropertyModified);
44 setMouseTracking(
true);
79 itk::ReceptorMemberCommand<QmitkSliderLevelWindowWidget>::Pointer command =
80 itk::ReceptorMemberCommand<QmitkSliderLevelWindowWidget>::New();
81 command->SetCallbackFunction(
this, &QmitkSliderLevelWindowWidget::OnPropertyModified);
87 void QmitkSliderLevelWindowWidget::OnPropertyModified(
const itk::EventObject &)
109 QPixmap pm(width(), height());
110 pm.fill(this->palette().color(this->backgroundRole()));
111 QPainter painter(&pm);
114 painter.setPen(this->palette().color(this->foregroundRole()));
116 QColor c(51, 153, 204);
117 QColor cl = c.light();
118 QColor cd = c.dark();
124 float smallestLevelableValue = 1e-9;
130 if (!std::isfinite(mr))
137 if (mr < smallestLevelableValue)
138 mr = smallestLevelableValue;
152 if (!std::isfinite(minRange))
160 if (!std::isfinite(maxRange))
167 if (minRange < 0 && maxRange > 0)
169 painter.drawLine(5, yValue, 15, yValue);
170 painter.drawText(21, yValue + 3, s);
175 bool enoughSpace =
false;
176 bool enoughSpace2 =
false;
178 double dStepSize = pow(10, floor(log10(mr / 100)) + 1);
183 if (-count * dStepSize < minRange)
188 yValue = m_MoveHeight + (int)((minRange + count * dStepSize) * fact);
190 s = QString::number(-count * dStepSize);
191 if (count % k && ((dStepSize * fact) > 2.5))
193 painter.drawLine(8, yValue, 12, yValue);
196 else if (!(count % k))
198 if ((k * dStepSize * fact) > 7)
200 painter.drawLine(5, yValue, 15, yValue);
201 painter.drawText(21, yValue + 3, s);
214 else if (enoughSpace2)
229 enoughSpace2 =
false;
230 for (
int i = m_MoveHeight + (
int)(minRange * fact); i >= 0;)
232 if (count * dStepSize > maxRange)
236 yValue = m_MoveHeight + (int)((minRange - count * dStepSize) * fact);
237 s = QString::number(count * dStepSize);
238 if (count % k && ((dStepSize * fact) > 2.5))
240 if (!(minRange > 0 && (count * dStepSize) < minRange))
241 painter.drawLine(8, yValue, 12, yValue);
244 else if (!(count % k))
246 if ((k * dStepSize * fact) > 7)
248 if (!(minRange > 0 && (count * dStepSize) < minRange))
250 painter.drawLine(5, yValue, 15, yValue);
251 painter.drawText(21, yValue + 3, s);
265 else if (enoughSpace2)
280 painter.drawLine(
m_Rect.topLeft(),
m_Rect.bottomLeft());
283 painter.drawLine(
m_Rect.topRight(),
m_Rect.bottomRight());
284 painter.drawLine(
m_Rect.bottomRight(),
m_Rect.bottomLeft());
288 p.drawPixmap(0, 0, pm);
299 if (mouseEvent->pos().y() >= 0 && mouseEvent->pos().y() <= (
m_Rect.topLeft().y() + 3))
301 setCursor(Qt::SizeVerCursor);
303 this->setToolTip(
"Ctrl + left click to change only upper bound");
306 else if (mouseEvent->pos().y() >= (
m_Rect.bottomLeft().y() - 3))
308 setCursor(Qt::SizeVerCursor);
310 this->setToolTip(
"Ctrl + left click to change only lower bound");
316 setCursor(Qt::ArrowCursor);
317 this->setToolTip(
"Left click and mouse move to adjust the slider");
331 double diff = (mouseEvent->pos().y()) / fact;
352 double diff = (mouseEvent->pos().y()) / fact;
369 newLevel = oldLevel + (value - oldWindow) / 2;
375 double diff = (mouseEvent->pos().y()) / fact;
392 newLevel = oldLevel - (value - oldWindow) / 2;
401 const float level = (
m_MoveHeight - mouseEvent->pos().y()) / fact + minv;
403 double diff = (mouseEvent->pos().x()) / fact;
426 QPoint p = QCursor::pos();
427 p = this->mapFromGlobal(p);
428 QMouseEvent ev(QEvent::MouseMove, p, Qt::NoButton, Qt::NoButton, Qt::NoModifier);
439 if (mouseEvent->button() == Qt::LeftButton)
441 if (mouseEvent->modifiers() == Qt::ControlModifier || mouseEvent->modifiers() == Qt::ShiftModifier)
476 setMinimumSize(QSize(50, 50));
477 setMaximumSize(QSize(50, 2000));
478 setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding));
483 setMinimumSize(QSize(40, 50));
484 setMaximumSize(QSize(50, 2000));
485 setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding));
513 void QmitkSliderLevelWindowWidget::contextMenuEvent(QContextMenuEvent *)
516 auto contextMenu =
new QMenu(
this);
517 Q_CHECK_PTR(contextMenu);
519 contextMenu->addAction(tr(
"Hide Scale"),
this, SLOT(
HideScale()));
521 contextMenu->addAction(tr(
"Show Scale"),
this, SLOT(
ShowScale()));
522 contextMenu->addSeparator();
ScalarType GetLevel() const
method that returns the level value, i.e. the center of the current grey value interval ...
Data management class that handles 'was created by' relations.
ScalarType GetUpperWindowBound() const
static RenderingManager * GetInstance()
ScalarType GetRange() const
returns the size of the grey value range
ScalarType GetRangeMax() const
ScalarType GetWindow() const
returns the current window size, i.e the range size of the current grey value interval ...
ScalarType GetRangeMin() const
void SetLevelWindow(ScalarType level, ScalarType window, bool expandRangesIfNecessary=true)
Provides access to the LevelWindowProperty object and LevelWindow of the "current" image...
ScalarType GetLowerWindowBound() const
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)