Exemplo n.º 1
0
void RangeHistogram::mouseMoveEvent(QMouseEvent *e)
{
  QPoint pos = e->pos();
  if(ValidRange() && (e->buttons() & Qt::LeftButton) && pos != m_MousePrev)
  {
    if(m_DragMode == DraggingMode::White)
    {
      float newWhite = (float)(pos.x() - totalSpace()) / (float)regionWidth();

      setWhiteDelta(qBound(blackDelta() + m_MinRangeSize, newWhite, 1.0f));
    }
    else if(m_DragMode == DraggingMode::Black)
    {
      float newBlack = (float)(pos.x() - totalSpace()) / (float)regionWidth();

      setBlackDelta(qBound(0.0f, newBlack, whiteDelta() - m_MinRangeSize));
    }

    emit rangeUpdated();

    if(m_DragMode != DraggingMode::None)
      update();

    m_MousePrev = pos;
  }
}
Exemplo n.º 2
0
void RangeHistogram::mousePressEvent(QMouseEvent *e)
{
  if(e->button() != Qt::LeftButton || !ValidRange())
    return;

  QRect r = rect();

  r.marginsRemoved(QMargins(totalSpace(), totalSpace(), totalSpace(), totalSpace()));

  int whiteX = (int)(whiteDelta() * r.width());
  int blackX = (int)(blackDelta() * r.width());

  QPointF whiteVec(whiteX - e->pos().x(), rect().height() - e->pos().y());
  QPointF blackVec(blackX - e->pos().x(), e->pos().y());

  float whitedist = (float)sqrt(whiteVec.x() * whiteVec.x() + whiteVec.y() * whiteVec.y());
  float blackdist = (float)sqrt(blackVec.x() * blackVec.x() + blackVec.y() * blackVec.y());

  if(whitedist < blackdist && whitedist < 18.0f)
    m_DragMode = DraggingMode::White;
  else if(blackdist < whitedist && blackdist < 18.0f)
    m_DragMode = DraggingMode::Black;
  else if(e->pos().x() > whiteX)
    m_DragMode = DraggingMode::White;
  else if(e->pos().x() < blackX)
    m_DragMode = DraggingMode::Black;

  if(m_DragMode == DraggingMode::White)
  {
    float newWhite = (float)(e->pos().x() - totalSpace()) / (float)regionWidth();

    setWhiteDelta(qBound(blackDelta() + m_MinRangeSize, newWhite, 1.0f));
  }
  else if(m_DragMode == DraggingMode::Black)
  {
    float newBlack = (float)(e->pos().x() - totalSpace()) / (float)regionWidth();

    setBlackDelta(qBound(0.0f, newBlack, whiteDelta() - m_MinRangeSize));
  }

  emit rangeUpdated();

  if(m_DragMode != DraggingMode::None)
    update();

  m_MousePrev = e->pos();
}
Exemplo n.º 3
0
void
iil4mitkImage::display (iil4mitkWidget* widget)
{
  GLdouble planeX [] = {-1, 0, 0, regionWidth ()};
  GLdouble planeY [] = {0, -1, 0, regionHeight ()};

  if (!visible () 
    || (constraint () && (widget != constraint ())))
  {
    return;
  }

  if (_pixels)
  {
    assert (_rx + _rw <= _width);
    assert (_ry + _rh <= _height);

    GLboolean texturing = glIsEnabled (GL_TEXTURE_2D);
    GLboolean blending = glIsEnabled (GL_BLEND);

    glClipPlane (GL_CLIP_PLANE4, planeX);
    glEnable (GL_CLIP_PLANE4);
    glClipPlane (GL_CLIP_PLANE5, planeY);
    glEnable (GL_CLIP_PLANE5);

    if ((_model == INTENSITY_ALPHA) || (_model == COLOR_ALPHA) || (_model == RGB) || (_model == RGBA))
    {
      glEnable (GL_BLEND);
      glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    }

    glEnable (GL_TEXTURE_2D);
    glMatrixMode (GL_MODELVIEW);
    glPushMatrix ();
    glColor4f (red (), green (), blue (), alpha ());
    glTranslatef (x (), y (), 0.0);
    drawTextures (widget);
    glPopMatrix ();

    glDisable (GL_CLIP_PLANE4);
    glDisable (GL_CLIP_PLANE5);

    if (texturing == GL_FALSE) glDisable (GL_TEXTURE_2D);
    if (blending  == GL_FALSE) glDisable (GL_BLEND);
  }
}