void MainWindow::finishmanualmatch()
{
    scanSN = dm->scanSN;//这里不能放在finishMatch后面
    ui->scanSNLabel->setText(QString::number(scanSN+1));//表示已经进行了的扫描次数(实际是查找点次数)
    dm->finishMatch();
    paintPoints();
}
예제 #2
0
void NMGChartSeries::paint(QPainter* painter,
                           const QStyleOptionGraphicsItem* option, 
                           QWidget* widget)
{
  if(!vertexList.isEmpty())
  { 
    if(spaceAvailableIntoSceneChanged || rebuildScaleFactors)
    {
      calculateScaleFactors();
      if(spaceAvailableIntoSceneChanged) spaceAvailableIntoSceneChanged = FALSE;
      if(rebuildScaleFactors) rebuildScaleFactors = FALSE;
    }
    
    QPen pen;
    pen.setColor(baseColor);
    pen.setWidth(1);
    painter->setPen(pen);
  
    if(isClipped)
    {
      painter->setClipRect(0, 0, currentWidthIntoScene + pen.width(), currentHeightIntoScene);
    }
    painter->save();
    painter->translate(0,currentHeightIntoScene);
        
    if(representation == LINE_TYPE) paintLine(painter, option, widget);
    else if(representation == AREA_TYPE) paintArea(painter, option, widget);
    else if(representation == POINTS_TYPE) paintPoints(painter, option, widget);
    else if(representation == BARS_TYPE) paintBars(painter, option, widget);
    
    painter->restore();
  }
}
void MainWindow::findPoint()
{
    if (dm->dotForMark.size() != 0)
    {
        dm->dotForMark.clear();
    }
    cv::Mat mat_1 = cv::Mat(cameraHeight, cameraWidth, CV_8UC1, DHC->m_pRawBuffer_1);//直接从内存缓冲区获得图像数据是可行的
    cv::Mat mat_2 = cv::Mat(cameraHeight, cameraWidth, CV_8UC1, DHC->m_pRawBuffer_2);
    //imshow("d",mat_1);
    //cvWaitKey(10);
    bool success = dm->matchDot(mat_1,mat_2);//在这一步生成了mm
    if (success){
        ///保证运行activeManual时mm已经生成
        if (dm->scanSN != 0){
            if (ui->matchAssistant->isChecked()){
                dm->activeManual();
                ui->manualWindow->setEnabled(true);
                connect(ui->manualWindow,SIGNAL(clicked()),this,SLOT(showhidemanual()));
            }
        }
        else{
            paintPoints();
            if (QMessageBox::information(NULL,tr("Finished"), tr("Is the result right for reconstruction?"),
                QMessageBox::Yes,QMessageBox::No)== QMessageBox::Yes)
                finishmanualmatch();
         }
    }
}
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;
}
예제 #5
0
bool HoverPoints::eventFilter( QObject* object, QEvent* hoverEvent )
{
    // If the selected object is the transfer object and the widget is enabled.
    if( object != _colorMapWidget || !_enabled || !_editable )
        return false;

    auto& controlPoints = _colorMap.getControlPoints( _channel );
    if( controlPoints.empty( ))
        return false;

    const float w = _colorMapWidget->width();
    const float h = _colorMapWidget->height();

    // Detect the event type.
    switch ( hoverEvent->type())
    {
    case QEvent::MouseButtonPress:
    {
        QMouseEvent* mouseEvent = (QMouseEvent*)hoverEvent;
        QPointF clickPosition = mouseEvent->pos();
        QPointF selectedPoint = emptyPoint;
        for( size_t i = 0; i < controlPoints.size(); ++i )
        {
            // Select the shape of the bounding rectangle of the volume
            // whether it is circle of rectangle.
            QPainterPath touchSurface;
            const auto& cp = controlPoints[ i ];
            const QPointF point( cp.getX() / 256.0f * w,
                                 ( 1.0f - cp.getY( )) * h );
            touchSurface.addEllipse( point, controlPointSize, controlPointSize );

            // If the mouse event was applied in this boundary of the point,
            // set the index to that of the selected point.
            if( touchSurface.contains( clickPosition ))
            {
                selectedPoint = { cp.getX(), cp.getY() };
                break;
            }
        }

        // If the Qt::LeftButton is clicked where there are no points,
        // insert a new point, and if the Qt::LeftButton is clicked where
        // a point already exists, then move the HoverPoint.
        if( mouseEvent->button() == Qt::LeftButton )
        {
            // If there is no point where the mouse is clicked, then create
            // a new point.
            if( selectedPoint == emptyPoint )
            {
                lexis::render::ControlPoint cp(
                            (float)clickPosition.x() / w * 256.0f,
                            1.0f - (float)clickPosition.y() / h );

                // Insert a new point at this position.
                _colorMap.addControlPoint( cp,  _channel );
                _selectedPoint = QPointF( cp.getX(), cp.getY( ));
                // Select the point

                // Update the system.
                emit pointsChanged();
            }
            else // If there is a specific point that is clicked, get it.
                _selectedPoint = selectedPoint;

            // We have created or selected a point.
            return true;

        }
        // If the Qt::RightButton is selcted where there is a point, then
        // delete this point and update the system.
        else if( mouseEvent->button() == Qt::RightButton )
        {
            // If there is a specified point that is selected based on
            // the index and the widget is editible.
            if( selectedPoint != emptyPoint )
            {
                const float selectedX = selectedPoint.x();

                // If it is the last point or the first point, do not remove
                if(  selectedX == controlPoints[ 0 ].getX() ||
                     selectedX == controlPoints[ controlPoints.size() - 1 ].getX( ))
                {
                    return true;
                }

                _colorMap.removeControlPoint( selectedX, _channel );

                // Update the system.
                emit pointsChanged();

                // We have deleted a point.
                return true;
            }
        }
    }   break;

    case QEvent::MouseButtonRelease:
    {
        _selectedPoint = emptyPoint;
    }   break;

    case QEvent::MouseMove:
    {
        // If there is a point selected with a specific index, move it.
        if( _selectedPoint == emptyPoint )
            return false;

        const auto& pos = ((QMouseEvent*)hoverEvent )->pos();
        const float y = std::max( std::min( 1.0f, 1.0f - pos.y() / h ), 0.0f );
        const float selectedX = _selectedPoint.x();

        // If it is the last point or the first point
        if(  selectedX == controlPoints[ 0 ].getX() ||
             selectedX == controlPoints[ controlPoints.size() - 1 ].getX( ))
        {
            // Update the control point only on y direction
            _colorMap.addControlPoint( { selectedX, y }, _channel );
            emit pointsChanged();
            return true;
        }

        const float x = pos.x() / w * 256.0f;

        // If position reaches or passes the boundaries
        if( x <= controlPoints[ 0 ].getX( )
            || x >= controlPoints[ controlPoints.size() - 1 ].getX( ))
        {
            return true;
        }

        // If there is previously a control point in the position
        for( size_t i = 0; i < controlPoints.size(); ++i )
        {
            if( controlPoints[ i ].getX() == x && _selectedPoint.x() != x )
                return true;
        }

        _colorMap.removeControlPoint( selectedX, _channel );
        _colorMap.addControlPoint( { x, y }, _channel );
        _selectedPoint = { x, y };

        // Update the system.
        emit pointsChanged();
        return true;

    }   break;

    case QEvent::Resize: // Resize the points.
    {
        // Update the system.
        emit pointsChanged();
        break;
    }

    case QEvent::Paint: // Render the points on the widget.
    {
        QWidget* tfWidget = _colorMapWidget;
        _colorMapWidget = 0;

        QApplication::sendEvent( object, hoverEvent );
        _colorMapWidget = tfWidget;

        // Paing all the points on the widget.
        paintPoints();
        return true;
    }
    default: break;
    }

    // No event is selected.
    return false;
}
예제 #6
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;
        }
예제 #7
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;
}
예제 #8
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;
}
예제 #9
0
파일: HoverPoints.cpp 프로젝트: VMML/Livre
bool HoverPoints::eventFilter( QObject* object, QEvent* hoverEvent )
{
    // If the selected object is the transfer object and the widget is enabled.
    if( object == _tfWidget && _enabled )
    {
        // Detect the event type.
        switch ( hoverEvent->type())
        {
        case QEvent::MouseButtonPress:
        {
            if( !_fingerPointMapping.isEmpty())
                return true;

            QMouseEvent* mouseEvent = (QMouseEvent*)hoverEvent;
            QPointF clickPosition = mouseEvent->pos();
            int index = -1;
            for( int32_t i = 0; i < _tfPoints.size(); ++i )
            {
                // Select the shape of the bounding rectangle of the volume
                // whether it is circle of rectangle.
                QPainterPath touchSurface;
                if( _pointShape == CIRCLE_POINT )
                    touchSurface.addEllipse( _pointBoundingRectangle( i ));
                else
                    touchSurface.addRect( _pointBoundingRectangle( i ));

                // If the mouse event was applied in this boundary of the point,
                // set the index to that of the selected point.
                if (touchSurface.contains( clickPosition ))
                {
                    index = i;
                    break;
                }
            }

            // If the Qt::LeftButton is clicked where there are no points,
            // insert a new point, and if the Qt::LeftButton is clicked where
            // a point already exists, then move the HoverPoint.
            if( mouseEvent->button() == Qt::LeftButton )
            {
                // If there is no point where the mouse is clicked, then create
                // a new point.
                if( index == -1 )
                {
                    // If the widget (point) is not editible, return.
                    if ( !_editable ) return false;

                    // TODO: Insert sort for x or y
                    int position = 0;
                    if( _sortType == X_SORT )
                    {
                        for( int32_t i = 0; i < _tfPoints.size(); ++i )
                        {
                            if( _tfPoints.at(i).x() > clickPosition.x())
                            {
                                position = i;
                                break;
                            }
                        }
                    }
                    else if( _sortType == Y_SORT )
                    {
                        for ( int32_t i = 0; i < _tfPoints.size(); ++i )
                        {
                            if( _tfPoints.at(i).y() > clickPosition.y())
                            {
                                position = i;
                                break;
                            }
                        }
                    }

                    // Insert a new point at this position.
                    _tfPoints.insert( position, clickPosition );
                    _locks.insert( position, 0 );
                    _currentPointIndex = position;

                    // Update the system.
                    firePointChange();
                }
                else // If there is a specific point that is clicked, get it.
                {
                    _currentPointIndex = index;
                }

                // We have created or selected a point.
                return true;

            }
            // If the Qt::RightButton is selcted where there is a point, then
            // delete this point and update the system.
            else if( mouseEvent->button() == Qt::RightButton )
            {
                // If there is a specified point that is selected based on
                // the index and the widget is editible.
                if( index >= 0 && _editable )
                {
                    if( _locks[index] == 0 )
                    {
                        // Remove the point from the list.
                        _locks.remove( index );
                        _tfPoints.remove( index );
                    }

                    // Update the system.
                    firePointChange();

                    // We have deleted a point.
                    return true;
                }
            }
        }   break;

        case QEvent::MouseButtonRelease:
        {
            if( !_fingerPointMapping.isEmpty())
                return true;
            _currentPointIndex = -1;
        }   break;

        case QEvent::MouseMove:
        {
            // If there is no point selected, do nothing.
            if( !_fingerPointMapping.isEmpty())
                return true;

            // If there is a point selected with a specific index, move it.
            if( _currentPointIndex >= 0 )
                _movePoint( _currentPointIndex, ((QMouseEvent*)hoverEvent )->pos());
        }   break;


        case QEvent::TouchBegin:  /// Events for the rendeirng widget.
        case QEvent::TouchUpdate: /// Events for the rendeirng widget.
        {
            const QTouchEvent* const touchEvent =
                    static_cast<const QTouchEvent*>( hoverEvent );
            const QList<QTouchEvent::TouchPoint> touchPoints =
                    touchEvent->touchPoints();
            const qreal pointSize =
                    qMax( _pointSize.width(), _pointSize.height() );

            foreach ( const QTouchEvent::TouchPoint &touchPoint, touchPoints )
            {
                const int touchId = touchPoint.id();
                switch ( touchPoint.state())
                {
                case Qt::TouchPointPressed:
                {
                    // Find the point and then move it
                    QSet<int> activePoints =
                            QSet<int>::fromList( _fingerPointMapping.values());

                    int activePoint = -1;
                    qreal distance = -1;
                    const int pointsCount = _tfPoints.size();
                    const int activePointCount = activePoints.size();

                    // You are allowed to only have two points on the rendering
                    // widget.
                    if( pointsCount == 2 && activePointCount == 1 )
                        activePoint = activePoints.contains(0) ? 1 : 0;
                    else
                    {
                        for( int32_t i = 0; i < pointsCount; ++i )
                        {
                            if( activePoints.contains( i ))
                                continue;

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

                    if( activePoint != -1 )
                    {
                        _fingerPointMapping.insert( touchPoint.id(), activePoint );
                        _movePoint( activePoint, touchPoint.pos());
                    }
                }
                break;

                case Qt::TouchPointReleased: /// Events for the rendeirng widget.
                {
                    // Move the point and release
                    QHash<int,int>::iterator it = _fingerPointMapping.find( touchId );
                    _movePoint( it.value(), touchPoint.pos());
                    _fingerPointMapping.erase( it );
                }
                break;

                case Qt::TouchPointMoved: /// Events for the rendeirng widget.
                {
                    // Move the point
                    const int pointIdx = _fingerPointMapping.value( touchId, -1 );
                    if( pointIdx >= 0 )
                        _movePoint(pointIdx, touchPoint.pos());
                }
                break;

                default:
                    break;
                }
            }
            if( _fingerPointMapping.isEmpty())
            {
                hoverEvent->ignore();
                return false;
            }
            else
            {
                return true;
            }
        }
            break;
        case QEvent::TouchEnd:
            if( _fingerPointMapping.isEmpty())
            {
                hoverEvent->ignore();
                return false;
            }
            return true;
            break;

        case QEvent::Resize: // Resize the points.
        {
            QResizeEvent* resizeEvent = (QResizeEvent *) hoverEvent;
            const int oldPointWidth = resizeEvent->oldSize().width();
            const int oldPointHeight = resizeEvent->oldSize().height();
            if( oldPointWidth == 0 || oldPointHeight == 0 )
                break;

            const int newPointWidth = resizeEvent->size().width();
            const int newPointHeight = resizeEvent->size().height();
            const qreal scaleX = newPointWidth / qreal( oldPointWidth );
            const qreal scaleY = newPointHeight / qreal( oldPointHeight );

            // Update the size of all the points in the transfer function widget.
            for( int32_t i = 0; i < _tfPoints.size(); ++i )
            {
                QPointF p = _tfPoints[i];
                _movePoint( i, QPointF(p.x() * scaleX, p.y() * scaleY), false );
            }

            // Update the system.
            firePointChange();
            break;
        }

        case QEvent::Paint: // Render the points on the widget.
        {
            QWidget* tfWidget = _tfWidget;
            _tfWidget = 0;

            QApplication::sendEvent( object, hoverEvent );
            _tfWidget = tfWidget;

            // Paing all the points on the widget.
            paintPoints();
            return true;
        }
        default: break;
        }
    }

    // No event is selected.
    return false;
}
예제 #10
0
void MapEditorWidget::paintEvent(QPaintEvent * ){
  paintAxis();
  paintPoints();
}