Пример #1
0
void HoverPoints::paintPoints()
{
    QPainter p(m_widget);

    p.setRenderHint(QPainter::Antialiasing);

    if (m_connectionPen.style() != Qt::NoPen && m_connectionType != NoConnection)
    {
        p.setPen(m_connectionPen);

        if (m_connectionType == CurveConnection)
        {
            QPainterPath path;
            path.moveTo(m_points.at(0));
            for (int i = 1; i < m_points.size(); ++i)
            {
                QPointF p1 = m_points.at(i-1);
                QPointF p2 = m_points.at(i);
                double distance = p2.x() - p1.x();

                path.cubicTo(p1.x() + distance / 2, p1.y(),
                             p1.x() + distance / 2, p2.y(),
                             p2.x(), p2.y());
            }
            p.drawPath(path);
        }
        else
        {
            p.drawPolyline(m_points);
        }
    }

    p.setPen(m_pointPen);
    p.setBrush(m_pointBrush);

    for (int i = 0; i < m_points.size(); ++i)
    {
        QRectF bounds = pointBoundingRect(i);
        if (m_shape == CircleShape)
        {
            p.drawEllipse(bounds);
        }
        else
        {
            if (m_shape == RectangleShape)
            {
                p.drawRect(bounds);
            }
        }
    }
}
Пример #2
0
void HoverPoints::paintPoints()
{
    QPainter p;
#ifdef QT_OPENGL_SUPPORT
    ArthurFrame *af = qobject_cast<ArthurFrame *>(m_widget);
    if (af && af->usesOpenGL())
        p.begin(af->glWidget());
    else
        p.begin(m_widget);
#else
    p.begin(m_widget);
#endif

    p.setRenderHint(QPainter::Antialiasing);

    if (m_connectionPen.style() != Qt::NoPen && m_connectionType != NoConnection) {
        p.setPen(m_connectionPen);

        if (m_connectionType == CurveConnection) {
            QPainterPath path;
            path.moveTo(m_points.at(0));
            for (int i=1; i<m_points.size(); ++i) {
                QPointF p1 = m_points.at(i-1);
                QPointF p2 = m_points.at(i);
                qreal distance = p2.x() - p1.x();

                path.cubicTo(p1.x() + distance / 2, p1.y(),
                             p1.x() + distance / 2, p2.y(),
                             p2.x(), p2.y());
            }
            p.drawPath(path);
        } else {
            p.drawPolyline(m_points);
        }
    }

    p.setPen(m_pointPen);
    p.setBrush(m_pointBrush);

    for (int i=0; i<m_points.size(); ++i) {
        QRectF bounds = pointBoundingRect(i);
        if (m_shape == CircleShape)
            p.drawEllipse(bounds);
        else
            p.drawRect(bounds);
    }
}
Пример #3
0
void MapEditorWidget::paintPoints()
{
  QPolygonF sPoints = transform.map(points);
  QPainter p;
  p.begin(this);
  
  p.setRenderHint(QPainter::Antialiasing);

  p.setPen(QColor("#000000"));
  p.setBrush(QBrush());
  //  p.drawRect(plotArea);
  
  p.setPen(connectionPen);
  if(sPoints.size()){
    QPainterPath path;
    path.moveTo(QPointF(plotArea.topLeft().x(),sPoints.at(0).y()));
    path.lineTo(QPointF(sPoints.at(0)));
      //    path.moveTo(sPoints.at(0));
    for (int i=1; i<sPoints.size(); ++i) {
      QPointF p1 = sPoints.at(i-1);
      QPointF p2 = sPoints.at(i);
      double distance = p2.x() - p1.x();
      
      path.cubicTo(p1.x() + distance / 2, p1.y(),
		   p1.x() + distance / 2, p2.y(),
		   p2.x(), p2.y());
    }
    path.lineTo(plotArea.bottomRight().x(),sPoints.last().y());
    p.drawPath(path);    
    path.lineTo(plotArea.bottomRight());
    path.lineTo(plotArea.topLeft().x(),plotArea.bottomRight().y());
    QLinearGradient grad = QLinearGradient(0,0,0,plotArea.height());
    grad.setColorAt(0,QColor("#B2DFEE"));
    grad.setColorAt(1,QColor("#26466D"));
    QBrush grad_brush(grad);      
    p.fillPath(path,grad_brush);
  }
  p.setPen(pointPen);
  p.setBrush(pointBrush);
  for (int i=0; i<sPoints.size(); ++i) {
    QRectF bounds = pointBoundingRect(i);
    p.drawEllipse(bounds);
  }



}
void HoverPoints::paintPoints()
{
    QPainter p;
    p.begin(m_widget);
    p.setRenderHint(QPainter::Antialiasing);
  
    p.setBrush(m_gradient);
    //p.setBrush(QColor(230,230,230));
    p.setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
    p.drawRoundedRect(QRect(1, 1, m_widget->width() - 2, m_widget->height() - 2), 4.0, 4.0);
   
    p.setBrush(QBrush());
   
    if (m_connectionPen.style() != Qt::NoPen && m_connectionType != NoConnection) {
        p.setPen(m_connectionPen);

        if (m_connectionType == CurveConnection) {
            QPainterPath path;
            path.moveTo(m_points.at(0));
            for (int i=1; i<m_points.size(); ++i) {
                QPointF p1 = m_points.at(i-1);
                QPointF p2 = m_points.at(i);
                qreal distance = p2.x() - p1.x();

                path.cubicTo(p1.x() + distance / 2, p1.y(),
                             p1.x() + distance / 2, p2.y(),
                             p2.x(), p2.y());
            }
            p.drawPath(path);
        } else {
            p.drawPolyline(m_points);
        }
    }

    p.setPen(m_pointPen);
    p.setBrush(m_pointBrush);

    for (int i=0; i<m_points.size(); ++i) {
        QRectF bounds = pointBoundingRect(i);
        if (m_shape == CircleShape)
            p.drawEllipse(bounds);
        else
            p.drawRect(bounds);
    }
}
Пример #5
0
void MapEditorWidget::mousePressEvent ( QMouseEvent * event ){
  if(popup){
    return;
  }
  QPointF clickPos = transform.inverted().map(QPointF(event->pos()));
  int index = -1;
  for (int i=0; i<points.size(); ++i) {
    QPainterPath path;
    path.addEllipse(pointBoundingRect(i));
    if (path.contains(event->pos())) {
      index = i;
      break;
    }
  }
  if(plotArea.contains(event->pos()) == false && index == -1){
    return;
  }


  if (event->button() == Qt::LeftButton) {
    if (index == -1) {
      int pos = 0;
      // Insert sort for x or y
      for (int i=0; i<points.size(); ++i){
	if (points.at(i).x() > clickPos.x()) {
	  pos = i;
	  break;
	}
      }
      points.insert(pos, clickPos);
      currentIndex = pos;
      firePointChange();
    } else {
      currentIndex = index;
    }
  } else if (event->button() == Qt::RightButton) {
    if (index >= 0) {
      if(points.size() > 1){
	points.remove(index);
	firePointChange();
      }
    }
  }
}
Пример #6
0
void MapEditorWidget::mouseDoubleClickEvent ( QMouseEvent * event ){
  //QPointF clickPos = transform.inverted().map(QPointF(event->pos()));
  int index = -1;
  if(popup){
    /* there is already a point being edited */
    return;
  }
  for (int i=0; i<points.size(); ++i) {
    QPainterPath path;
    path.addEllipse(pointBoundingRect(i));
    if (path.contains(event->pos())) {
      index = i;
      break;
    }
  }
  if(index != -1){
    popup = new MapEditorPopup(event->pos(),points[index],index,this);    
    popup->show();
    if(plotArea.contains(popup->geometry()) == false){
      QRectF united = plotArea.united(popup->geometry());
      QPoint move(0,0);
      if(united.bottomRight() != plotArea.bottomRight()){
	if(united.bottomRight().x()!=plotArea.bottomRight().x()){
	  move.rx() -= popup->width()+pointSize.width();
	}
	move.ry() -= united.bottomRight().y()-plotArea.bottomRight().y();
      } 
      if(united.topLeft() != plotArea.topLeft()){
	move.rx() -= united.topLeft().x()-plotArea.topLeft().x();
	move.ry() -= united.topLeft().y()-plotArea.topLeft().y();
      } 
      popup->move(popup->pos()+move);
    }
    connect(popup,SIGNAL(editingFinished()),this,SLOT(updatePointFromPopup()));
  }else{
    QWidget::mouseDoubleClickEvent(event);
  }
}
Пример #7
0
void HoverPoints::paintPoints()
{
    QPainter p;
    p.begin(m_widget);

    p.setRenderHint(QPainter::Antialiasing);

    if (m_connectionPen.style() != Qt::NoPen && m_connectionType != NoConnection)
      {
      p.setPen(m_connectionPen);
      p.drawPolyline(m_points);
      }

    if(m_shape != CircleShape)
      return;

    p.setPen(m_pointPen);
    p.setBrush(m_pointBrush);

    for (int i=0; i<m_points.size(); ++i) {
        QRectF bounds = pointBoundingRect(i);
        p.drawEllipse(bounds);
    }
}
bool HoverPoints::eventFilter(QObject *object, QEvent *event)
{
    if (object == m_widget && m_enabled) {
        switch (event->type()) {

        case QEvent::MouseButtonPress:
        {
            if (!m_fingerPointMapping.isEmpty())
                return true;
            QMouseEvent *me = (QMouseEvent *) event;

            QPointF clickPos = me->pos();
            int index = -1;
            for (int i=0; i<m_points.size(); ++i) {
                QPainterPath path;
                if (m_shape == CircleShape)
                    path.addEllipse(pointBoundingRect(i));
                else
                    path.addRect(pointBoundingRect(i));

                if (path.contains(clickPos)) {
                    index = i;
                    break;
                }
            }

            if (me->button() == Qt::LeftButton) {
                if (index == -1) {
                  	if (!m_editable)
				  	    return false;
				  	int pos = 0;
                    // Insert sort for x or y
                	if (m_sortType == XSort) {
                	    for (int i=0; i<m_points.size(); ++i)
                            if (m_points.at(i).x() > clickPos.x()) {
                	            pos = i;
                                break;
                            }
                    } else if (m_sortType == YSort) {
                	    for (int i=0; i<m_points.size(); ++i)
                            if (m_points.at(i).y() > clickPos.y()) {
                	            pos = i;
                                break;
                            }
                    }
					
                    m_points.insert(pos, clickPos);
					m_locks.insert(pos, 0);
					m_currentIndex = pos;
					firePointChange();
					
                } else {
					m_currentIndex = index;
                }	
                return true;

            } else if (me->button() == Qt::RightButton) {
                if (index >= 0 && m_editable) {
		  if ((m_points.size() - 1) < m_minCountPoints) 
			  return true;
		  if (m_locks[index] == 0) {
		                m_locks.remove(index);
		                m_points.remove(index);
		            }
		            firePointChange();
		            return true;
                }
            }

        }
        break;

        case QEvent::MouseButtonRelease:
            if (!m_fingerPointMapping.isEmpty())
                return true;
            m_currentIndex = -1;
            break;

        case QEvent::MouseMove:
            if (!m_fingerPointMapping.isEmpty())
                return true;
            if (m_currentIndex >= 0)
                movePoint(m_currentIndex, ((QMouseEvent *)event)->pos());
            break;
        case QEvent::TouchBegin:
        case QEvent::TouchUpdate:
            {
                const QTouchEvent *const touchEvent = static_cast<const QTouchEvent*>(event);
                const QList<QTouchEvent::TouchPoint> points = touchEvent->touchPoints();
                const qreal pointSize = qMax(m_pointSize.width(), m_pointSize.height());
                Q_FOREACH (const QTouchEvent::TouchPoint &touchPoint, points) {
                    const int id = touchPoint.id();
                    switch (touchPoint.state()) {
                    case Qt::TouchPointPressed:
                        {
                            // find the point, move it
                            QSet<int> activePoints = QSet<int>::fromList(m_fingerPointMapping.values());
                            int activePoint = -1;
                            qreal distance = -1;
                            const int pointsCount = m_points.size();
                            const int activePointCount = activePoints.size();
                            if (pointsCount == 2 && activePointCount == 1) { // only two points
                                activePoint = activePoints.contains(0) ? 1 : 0;
                            } else {
                                for (int i=0; i<pointsCount; ++i) {
                                    if (activePoints.contains(i))
                                        continue;

                                    qreal d = QLineF(touchPoint.pos(), m_points.at(i)).length();
                                    if ((distance < 0 && d < 12 * pointSize) || d < distance) {
                                        distance = d;
                                        activePoint = i;
                                    }

                                }
                            }
                            if (activePoint != -1) {
                                m_fingerPointMapping.insert(touchPoint.id(), activePoint);
                                movePoint(activePoint, touchPoint.pos());
                            }
                        }
                        break;
                    case Qt::TouchPointReleased:
                        {
                            // move the point and release
                            QHash<int,int>::iterator it = m_fingerPointMapping.find(id);
                            movePoint(it.value(), touchPoint.pos());
                            m_fingerPointMapping.erase(it);
                        }
                        break;
                    case Qt::TouchPointMoved:
                        {
                            // move the point
                            const int pointIdx = m_fingerPointMapping.value(id, -1);
                            if (pointIdx >= 0) // do we track this point?
                                movePoint(pointIdx, touchPoint.pos());
                        }
                        break;
                    default:
                        break;
                    }
                }
                if (m_fingerPointMapping.isEmpty()) {
                    event->ignore();
                    return false;
                } else {
                    return true;
                }
            }
            break;
        case QEvent::TouchEnd:
            if (m_fingerPointMapping.isEmpty()) {
                event->ignore();
                return false;
            }
            return true;
            break;

        case QEvent::Resize:
        {
            QResizeEvent *e = (QResizeEvent *) event;
            if (e->oldSize().width() == 0 || e->oldSize().height() == 0)
                break;
            qreal stretch_x = e->size().width() / qreal(e->oldSize().width());
            qreal stretch_y = e->size().height() / qreal(e->oldSize().height());
            for (int i=0; i<m_points.size(); ++i) {
                QPointF p = m_points[i];
                movePoint(i, QPointF(p.x() * stretch_x, p.y() * stretch_y), false);
            }

            firePointChange();
            break;
        }

        case QEvent::Paint:
        {
            QWidget *that_widget = m_widget;
            m_widget = 0;
            QApplication::sendEvent(object, event);
            m_widget = that_widget;
            paintPoints();
            return true;
        }
        default:
            break;
        }
    }

    return false;
}
Пример #9
0
        bool Breakpoints::eventFilter(QObject *object, QEvent *event)
        {
            if( object != m_widget )
            {
                return false;
            }

            switch (event->type()) 
            {
                case QEvent::MouseButtonPress:
                {
                    QMouseEvent *me = (QMouseEvent *) event;
                    QPointF clickPos = me->pos();

                    for(m_selectedBreakpoint = m_model->GetBreakpoints().begin(); m_selectedBreakpoint != m_model->GetBreakpoints().end(); ++m_selectedBreakpoint)
                    {
                        QPainterPath path;
                        path.addEllipse(pointBoundingRect(m_selectedBreakpoint));
                        if (path.contains(clickPos)) 
                        {
                            break;
                        }
                    }

                    if (me->button() == Qt::LeftButton) 
                    {
                        if (m_selectedBreakpoint == m_model->GetBreakpoints().end() ) 
                        {
                            double px, py;
                            CalculatePercent(clickPos.x(), clickPos.y(), px, py);
                            ElVis::Color c;
                            c.SetAlpha(py);
                            c.SetGreen(1.0);
                            c.SetRed(1.0);
                            c.SetBlue(1.0);
                            m_selectedBreakpoint = m_model->InsertBreakpoint(px, c);
                        } 
                    } 
                    else if (me->button() == Qt::RightButton) 
                    {
                        if( m_selectedBreakpoint != m_model->GetBreakpoints().end() )
                        {
                            m_model->RemoveBreakpoint(m_selectedBreakpoint);
                            m_selectedBreakpoint = m_model->GetBreakpoints().end();
                        }
                    }
                    OnSelectedPointChanged(m_selectedBreakpoint);
                    OnBreakpointsChanged();
                    return true;
                }
                break;

                case QEvent::MouseButtonRelease:
                    break;

                case QEvent::MouseMove:
                    if (m_selectedBreakpoint != m_model->GetBreakpoints().end() )
                    {
                        const QPointF& point = ((QMouseEvent *)event)->pos();
                        double px, py;
                        CalculatePercent(point.x(), point.y(), px, py);

                        ElVisFloat key = px;
                        while( m_model->GetBreakpoints().find(key) != m_model->GetBreakpoints().end())
                        {
                            key += .00001;
                        }

                        ElVis::Color c = (*m_selectedBreakpoint).second.Col;
                        c.SetAlpha(py);
                        m_model->RemoveBreakpoint(m_selectedBreakpoint);
                        m_selectedBreakpoint = m_model->InsertBreakpoint(key, c);
                        OnBreakpointsChanged();
                    }
                    break;

                case QEvent::Resize:
                {
                    //QResizeEvent *e = (QResizeEvent *) event;
                    //if (e->oldSize().width() == 0 || e->oldSize().height() == 0)
                    //    break;
                    //qreal stretch_x = e->size().width() / qreal(e->oldSize().width());
                    //qreal stretch_y = e->size().height() / qreal(e->oldSize().height());
                    //for (int i=0; i<m_points.size(); ++i) 
                    //{
                    //    QPointF p = m_points[i];
                    //    movePoint(i, QPointF(p.x() * stretch_x, p.y() * stretch_y), false);
                    //}

                    //update();
                    break;
                }

                case QEvent::Paint:
                {
                    ColorMapRect* that_widget = m_widget;
                    m_widget = 0;
                    QApplication::sendEvent(object, event);
                    m_widget = that_widget;
                    paintPoints();
                    return true;
                }
                default:
                    break;
            }

            return false;
        }
Пример #10
0
        void Breakpoints::paintPoints()
        {
            const std::map<ElVisFloat, ColorMapBreakpoint>& breakpoints = m_model->GetBreakpoints();
            if( breakpoints.size() == 0) return;

            QPainter p;
            p.begin(m_widget);
            p.setRenderHint(QPainter::Antialiasing);

            p.setPen(m_connectionPen);
            QPainterPath path;

            typedef std::map<ElVisFloat, ColorMapBreakpoint>::const_iterator IterType;
            IterType iter = breakpoints.begin();
            double px = (*iter).first;
            double py = (*iter).second.Col.Alpha();

            double x,y;
            CalculatePosition(px, py, x, y);
            path.moveTo( x, y );

            for( ; iter != breakpoints.end(); ++iter)
            {
                px = (*iter).first;
                py = (*iter).second.Col.Alpha();
                CalculatePosition(px, py, x, y);

                path.lineTo(x, y);
            }
            p.drawPath(path);


            p.setPen(m_pointPen);
            p.setBrush(m_pointBrush);

            for(iter = breakpoints.begin() ; iter != breakpoints.end(); ++iter)
            {
                if( iter == m_selectedBreakpoint )
                {
                    p.setPen(m_selectedPointPen);
                }
                else
                {
                    p.setPen(m_pointPen);
                }

                QRectF bounds = pointBoundingRect(iter);
                p.drawEllipse(bounds);
            }

            //if (m_connectionPen.style() != Qt::NoPen && m_connectionType != NoConnection) 
            //{
            //    p.setPen(m_connectionPen);

            //    QPainterPath path;
            //    path.moveTo(m_points.at(0));
            //    for (int i=1; i<m_points.size(); ++i) {
            //        path.lineTo(m_points.at(i));
            //    }
            //    p.drawPath(path);
            //}

            //p.setPen(m_pointPen);
            //p.setBrush(m_pointBrush);

            //for (int i=0; i<m_points.size(); ++i) 
            //{
            //    if( i == m_currentIndex ) continue;
            //    QRectF bounds = pointBoundingRect(i);
            //    p.drawEllipse(bounds);
            //}

            //if( m_currentIndex >= 0 && m_currentIndex < m_points.size() )
            //{
            //    p.setPen(m_selectedPointPen);
            //    QRectF bounds = pointBoundingRect(m_currentIndex);
            //    p.drawEllipse(bounds);
            //}
        }
Пример #11
0
bool HoverPoints::eventFilter(QObject *object, QEvent *event)
{
    if (object == m_widget && m_enabled)
    {
        switch (event->type())
        {
            case QEvent::MouseButtonPress:
            {
                QMouseEvent *me = (QMouseEvent *) event;

                QPointF clickPos = me->pos();
                int index = -1;
                for (int i = 0; i < m_points.size(); ++i)
                {
                    QPainterPath path;
                    if (m_shape == CircleShape)
                    {
                        path.addEllipse(pointBoundingRect(i));
                    }
                    else
                    {
                        if (m_shape == RectangleShape)
                        {
                            path.addRect(pointBoundingRect(i));
                        }
                    }

                    if (path.contains(clickPos))
                    {
                        index = i;
                        break;
                    }
                }

                if (me->button() == Qt::LeftButton)
                {
                    if (index == -1)
                    {
                        if (!m_editable)
                        {
                            return false;
                        }
                        int pos = 0;
                        // Insert sort for x or y
                        if (m_sortType == XSort)
                        {
                            for (int i = 0; i < m_points.size(); ++i)
                            {
                                if (m_points.at(i).x() > clickPos.x())
                                {
                                    pos = i;
                                    break;
                                }
                            }
                        }
                        else if (m_sortType == YSort)
                        {
                            for (int i = 0; i < m_points.size(); ++i)
                            {
                                if (m_points.at(i).y() > clickPos.y())
                                {
                                    pos = i;
                                    break;
                                }
                            }
                        }

                        m_points.insert(pos, clickPos);
                        m_locks.insert(pos, 0);
                        m_currentIndex = pos;
                        firePointChange();
                    }
                    else
                    {
                        m_currentIndex = index;
                    }
                    return true;

                }
                else if (me->button() == Qt::RightButton)
                {
                    if (index >= 0 && m_editable)
                    {
                        if (m_locks[index] == 0)
                        {
                            m_locks.remove(index);
                            m_points.remove(index);
                        }
                        firePointChange();
                        return true;
                    }
                }

            }
                break;

            case QEvent::MouseButtonRelease:
                m_currentIndex = -1;
                break;

            case QEvent::MouseMove:
                if (m_currentIndex >= 0)
                {
                    movePoint(m_currentIndex, ((QMouseEvent *)event)->pos());
                }
                break;

            case QEvent::Resize:
            {
                if (m_widget->isVisible())
                {
                    QResizeEvent *e = (QResizeEvent *) event;
                    double stretch_x = e->size().width() / double(e->oldSize().width());
                    double stretch_y = e->size().height() / double(e->oldSize().height());
                    for (int i = 0; i < m_points.size(); ++i)
                    {
                        QPointF p = m_points[i];
                        movePoint(i, QPointF(p.x() * stretch_x, p.y() * stretch_y), false);
                    }

                    firePointChange();

                    m_width = e->size().width();
                    m_height = e->size().height();
                }
                break;
            }

            case QEvent::Show:
            {
                if (m_width != m_widget->width() || m_height != m_widget->height())
                {
                    if (m_width == -1 && m_height == -1)
                    {
                        m_width = m_widget->width();
                        m_height = m_widget->height();
                    }
                    double stretch_x = m_widget->width() / double(m_width);
                    double stretch_y = m_widget->height() / double(m_height);
                    for (int i = 0; i < m_points.size(); ++i)
                    {
                        QPointF p = m_points[i];
                        movePoint(i, QPointF(p.x() * stretch_x, p.y() * stretch_y), false);
                    }

                    firePointChange();

                    m_width = m_widget->width();
                    m_height = m_widget->height();
                }
                break;
            }

            case QEvent::Paint:
            {
                QWidget *that_widget = m_widget;
                m_widget = 0;
                QApplication::sendEvent(object, event);
                m_widget = that_widget;
                paintPoints();
                return true;
            }
            default:
                break;
        }
    }

    return false;
}
Пример #12
0
bool HoverPoints::eventFilter(QObject *object, QEvent *event)
{
    if (object == m_widget && m_enabled) {
        switch (event->type()) {

        case QEvent::MouseButtonPress:
        {
            QMouseEvent *me = (QMouseEvent *) event;

            QPointF clickPos = me->pos();
            int index = -1;
            for (int i=0; i<m_points.size(); ++i) {
                QPainterPath path;
                if (m_shape == CircleShape)
                    path.addEllipse(pointBoundingRect(i));
                else
                    path.addRect(pointBoundingRect(i));

                if (path.contains(clickPos)) {
                    index = i;
                    break;
                }
            }

            if (me->button() == Qt::LeftButton) {
                if (index == -1) {
                    if (!m_editable)
                        return false;
                    int pos = 0;
                    // Insert sort for x or y
                    if (m_sortType == XSort) {
                        for (int i=0; i<m_points.size(); ++i)
                            if (m_points.at(i).x() > clickPos.x()) {
                                pos = i;
                                break;
                            }
                    } else if (m_sortType == YSort) {
                        for (int i=0; i<m_points.size(); ++i)
                            if (m_points.at(i).y() > clickPos.y()) {
                                pos = i;
                                break;
                            }
                    }

                    m_points.insert(pos, clickPos);
                    m_locks.insert(pos, 0);
                    m_currentIndex = pos;
                    firePointChange();
                } else {
                    m_currentIndex = index;
                }
                return true;

            } else if (me->button() == Qt::RightButton) {
                if (index >= 0 && m_editable) {
                    if (m_locks[index] == 0) {
                        m_locks.remove(index);
                        m_points.remove(index);
                    }
                    firePointChange();
                    return true;
                }
            }

        }
        break;

        case QEvent::MouseButtonRelease:
            m_currentIndex = -1;
            break;

        case QEvent::MouseMove:
            if (m_currentIndex >= 0)
                movePoint(m_currentIndex, ((QMouseEvent *)event)->pos());
            break;

        case QEvent::Resize:
        {
            QResizeEvent *e = (QResizeEvent *) event;
            if (e->oldSize().width() == 0 || e->oldSize().height() == 0)
                break;
            qreal stretch_x = e->size().width() / qreal(e->oldSize().width());
            qreal stretch_y = e->size().height() / qreal(e->oldSize().height());
            for (int i=0; i<m_points.size(); ++i) {
                QPointF p = m_points[i];
                movePoint(i, QPointF(p.x() * stretch_x, p.y() * stretch_y), false);
            }

            firePointChange();
            break;
        }

        case QEvent::Paint:
        {
            QWidget *that_widget = m_widget;
            m_widget = 0;
            QApplication::sendEvent(object, event);
            m_widget = that_widget;
            paintPoints();
#ifdef QT_OPENGL_SUPPORT
            ArthurFrame *af = qobject_cast<ArthurFrame *>(that_widget);
            if (af && af->usesOpenGL())
                af->glWidget()->swapBuffers();
#endif
            return true;
        }
        default:
            break;
        }
    }

    return false;
}