bool block::inside(block & drop)
{
  bool ret=0;
  if(type==BLK_BRACKET){
    int inLine=y+ttlSize.y/2;
    //int bottomSpace=orig.height-(interior.y+interior.height);
    int inH=h-((inLine-y)+bottomBar/2);
    if(drop.inBounds(x+interior.x, inLine, fullWidth()-interior.x, inH))
      ret=true;
  }
  return ret;
}
Exemple #2
0
CString ArbI18N::toFullWidth(char const * s)
{   
  /* we want to ensure the use of full-width numbers and latin text. */
  BufferCharSource utf8Source(s);
  InternalEncodingConverter fromUTF8(utf8Source, ExternalEncoding::Unicode20UTF8(), InternalEncoding::Unicode20());
  ToFullwidthTransform fullWidth(fromUTF8);
  StringCharSink backToUTF8;
  InternalEncodingConverterSink sinkToUTF8(InternalEncoding::Unicode20(), ExternalEncoding::Unicode20UTF8(), backToUTF8);
  sinkToUTF8.Put(fullWidth);
  CString r = backToUTF8.c_str();
  return r;
}
bool block::beneath(block & chk,signed int blw)
{
  if(blw<ttlSize.y/2-5){
    blw=ttlSize.y;
  }
  else blw+=ttlSize.y;
  int midLine=y+h-ttlSize.y/2;
  
  if(type==BLK_BRACKET){
    midLine=y+(interior.y+interior.height+bottomBar/2);
    blw=blw+(y+h)-midLine;
  }
  
  return (chk.inBounds(x, midLine, fullWidth(), blw));
}
bool block::inOrOn(int _x, int _y)
{
  return (_x>x&&_x<x+fullWidth()&&_y>y&&_y<y+h+newHeightOn());
}
void InternalToolBox::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    if (!m_movable || (!m_dragging && boundingRect().contains(event->pos()))) {
        return;
    }

    m_dragging = true;
    m_userMoved = true;
    const QPoint newPos = mapToParent(event->pos()).toPoint();
    const QPoint curPos = pos().toPoint();

    const QSize cSize = cornerSize();
    const QSize fHeight = fullHeight();
    const QSize fWidth = fullWidth();
    const int h = fHeight.height();
    const int w = fWidth.width();

    const int areaWidth = parentWidget()->size().width();
    const int areaHeight = parentWidget()->size().height();

    int x = curPos.x();
    int y = curPos.y();

    // jump to the nearest desktop border
    int distanceToLeft = newPos.x() - m_dragStartRelative.x();
    int distanceToRight = areaWidth - w - distanceToLeft;
    int distanceToTop = newPos.y() - m_dragStartRelative.y();
    int distanceToBottom = areaHeight - h - distanceToTop;

    int distancetoHorizontalMiddle = qAbs((newPos.x() + boundingRect().size().width()/2) - areaWidth/2 - m_dragStartRelative.x());
    int distancetoVerticalMiddle = qAbs((newPos.y() + boundingRect().size().height()/2) - areaHeight/2 - m_dragStartRelative.y());

    if (distancetoHorizontalMiddle < 10) {
        x = areaWidth/2 - boundingRect().size().width()/2;
    } else if (distancetoVerticalMiddle < 10) {
        y = areaHeight/2 - boundingRect().size().height()/2;
    } else {
        // decide which border is the nearest
        if (distanceToLeft < distanceToTop && distanceToLeft < distanceToRight &&
            distanceToLeft < distanceToBottom ) {
            x = 0;
            y = (newPos.y() - m_dragStartRelative.y());
        } else if (distanceToRight < distanceToTop && distanceToRight < distanceToLeft &&
                distanceToRight < distanceToBottom) {
            x = areaWidth - w;
            y = (newPos.y() - m_dragStartRelative.y());
        } else if (distanceToTop < distanceToLeft && distanceToTop < distanceToRight &&
                distanceToTop < distanceToBottom ) {
            y = 0;
            x = (newPos.x() - m_dragStartRelative.x());
        } else if (distanceToBottom < distanceToLeft && distanceToBottom < distanceToRight &&
                distanceToBottom < distanceToTop) {
            y = areaHeight - h;
            x = (newPos.x() - m_dragStartRelative.x());
        }
    }


    x = qBound(0, x, areaWidth - w);
    y = qBound(0, y, areaHeight - h);

    Corner newCorner = corner();
    if (x == 0) {
        if (y == 0) {
            newCorner = TopLeft;
        } else if (areaHeight - cSize.height() < newPos.y()) {
            y = areaHeight - cSize.height();
            newCorner = BottomLeft;
        } else {
            newCorner = Left;
        }
    } else if (y == 0) {
        if (areaWidth - cSize.width() < newPos.x()) {
            x = areaWidth - cSize.width();
            newCorner = TopRight;
        } else {
            newCorner = Top;
        }
    } else if (x + w >= areaWidth) {
        if (areaHeight - cSize.height() < newPos.y()) {
            y = areaHeight - cSize.height();
            x = areaWidth - cSize.width();
            newCorner = BottomRight;
        } else {
            x = areaWidth - fHeight.width();
            newCorner = Right;
        }
    } else {
        y = areaHeight - fWidth.height();
        newCorner = Bottom;
    }

    if (newCorner != corner()) {
        prepareGeometryChange();
        setCorner(newCorner);
    }

    setPos(x, y);
}