20 #include <QMouseEvent>
25 #include <itkCommand.h>
39 command->SetCallbackFunction(
this, &QmitkSliderLevelWindowWidget::OnPropertyModified);
43 setMouseTracking(
true);
82 command->SetCallbackFunction(
this, &QmitkSliderLevelWindowWidget::OnPropertyModified);
88 void QmitkSliderLevelWindowWidget::OnPropertyModified(
const itk::EventObject &)
110 QPixmap pm(width(), height());
111 pm.fill(this->palette().color(this->backgroundRole()));
112 QPainter painter(&pm);
115 painter.setPen(this->palette().color(this->foregroundRole()));
117 QColor c(93, 144, 169);
118 QColor cl = c.light();
119 QColor cd = c.dark();
138 if (minRange <= 0 && maxRange >= 0)
140 painter.drawLine(5, yValue, 15, yValue);
141 painter.drawText(21, yValue + 3, s);
146 bool enoughSpace =
false;
147 bool enoughSpace2 =
false;
149 double dStepSize = pow(10, floor(log10(mr / 100)) + 1);
153 if (-count * dStepSize < minRange)
155 yValue = m_MoveHeight + (int)((minRange + count * dStepSize) * fact);
157 s = QString::number(-count * dStepSize);
158 if (count % k && ((dStepSize * fact) > 2.5))
160 painter.drawLine(8, yValue, 12, yValue);
163 else if (!(count % k))
165 if ((k * dStepSize * fact) > 7)
167 painter.drawLine(5, yValue, 15, yValue);
168 painter.drawText(21, yValue + 3, s);
181 else if (enoughSpace2)
195 enoughSpace2 =
false;
197 for (
int i = m_MoveHeight + (
int)(minRange * fact); i >= 0;)
199 if (count * dStepSize > maxRange)
201 yValue = m_MoveHeight + (int)((minRange - count * dStepSize) * fact);
203 s = QString::number(count * dStepSize);
204 if (count % k && ((dStepSize * fact) > 2.5))
206 if (!(minRange > 0 && (count * dStepSize) < minRange))
207 painter.drawLine(8, yValue, 12, yValue);
210 else if (!(count % k))
212 if ((k * dStepSize * fact) > 7)
214 if (!(minRange > 0 && (count * dStepSize) < minRange))
216 painter.drawLine(5, yValue, 15, yValue);
217 painter.drawText(21, yValue + 3, s);
231 else if (enoughSpace2)
246 painter.drawLine(
m_Rect.topLeft(),
m_Rect.bottomLeft());
249 painter.drawLine(
m_Rect.topRight(),
m_Rect.bottomRight());
250 painter.drawLine(
m_Rect.bottomRight(),
m_Rect.bottomLeft());
254 p.drawPixmap(0, 0, pm);
268 if (mouseEvent->pos().y() >= 0 && mouseEvent->pos().y() <= (
m_Rect.topLeft().y() + 3))
270 setCursor(Qt::SizeVerCursor);
272 this->setToolTip(
"Ctrl + left click to change only upper bound");
275 else if (mouseEvent->pos().y() >= (
m_Rect.bottomLeft().y() - 3))
277 setCursor(Qt::SizeVerCursor);
279 this->setToolTip(
"Ctrl + left click to change only lower bound");
285 setCursor(Qt::ArrowCursor);
286 this->setToolTip(
"Left click and mouse move to adjust the slider");
300 double diff = (mouseEvent->pos().y()) / fact;
321 double diff = (mouseEvent->pos().y()) / fact;
338 newLevel = oldLevel + (value - oldWindow) / 2;
344 double diff = (mouseEvent->pos().y()) / fact;
361 newLevel = oldLevel - (value - oldWindow) / 2;
370 const float level = (
m_MoveHeight - mouseEvent->pos().y()) / fact + minv;
372 double diff = (mouseEvent->pos().x()) / fact;
399 QPoint p = QCursor::pos();
400 p = this->mapFromGlobal(p);
401 QMouseEvent ev(QEvent::MouseMove, p, Qt::NoButton, Qt::NoButton, Qt::NoModifier);
415 if (mouseEvent->button() == Qt::LeftButton)
417 if (mouseEvent->modifiers() == Qt::ControlModifier || mouseEvent->modifiers() == Qt::ShiftModifier)
461 setMinimumSize(QSize(50, 50));
462 setMaximumSize(QSize(50, 2000));
463 setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding));
468 setMinimumSize(QSize(40, 50));
469 setMaximumSize(QSize(50, 2000));
470 setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding));
498 void QmitkSliderLevelWindowWidget::contextMenuEvent(QContextMenuEvent *)
501 auto contextMenu =
new QMenu(
this);
502 Q_CHECK_PTR(contextMenu);
504 contextMenu->addAction(tr(
"Hide Scale"),
this, SLOT(
hideScale()));
506 contextMenu->addAction(tr(
"Show Scale"),
this, SLOT(
showScale()));
507 contextMenu->addSeparator();
Data management class that handles 'was created by' relations.
itk::SmartPointer< Self > Pointer
ScalarType GetLowerWindowBound() const
static RenderingManager * GetInstance()
ScalarType GetRangeMax() const
ScalarType GetRangeMin() const
ScalarType GetUpperWindowBound() const
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
ScalarType GetLevel() const
method that returns the level value, i.e. the center of the current grey value interval ...
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.