void QUnifiedToolbarSurface::insertToolbar(QWidget *toolbar, const QPoint &offset)
{
    setGeometry(QRect(QPoint(0, 0), QSize(offset.x() + toolbar->width(), 100))); // FIXME
    recursiveRedirect(toolbar, toolbar, offset);
}
Esempio n. 2
0
void ApplicationOverlay::renderControllerPointers() {
    Application* application = Application::getInstance();
    GLCanvas* glWidget = application->getGLWidget();
    MyAvatar* myAvatar = application->getAvatar();

    //Static variables used for storing controller state
    static quint64 pressedTime[NUMBER_OF_RETICLES] = { 0ULL, 0ULL, 0ULL };
    static bool isPressed[NUMBER_OF_RETICLES] = { false, false, false };
    static bool stateWhenPressed[NUMBER_OF_RETICLES] = { false, false, false };

    const HandData* handData = Application::getInstance()->getAvatar()->getHandData();

    for (unsigned int palmIndex = 2; palmIndex < 4; palmIndex++) {
        const int index = palmIndex - 1;

        const PalmData* palmData = NULL;

        if (palmIndex >= handData->getPalms().size()) {
            return;
        }

        if (handData->getPalms()[palmIndex].isActive()) {
            palmData = &handData->getPalms()[palmIndex];
        } else {
            continue;
        }

        int controllerButtons = palmData->getControllerButtons();

        //Check for if we should toggle or drag the magnification window
        if (controllerButtons & BUTTON_3) {
            if (isPressed[index] == false) {
                //We are now dragging the window
                isPressed[index] = true;
                //set the pressed time in us
                pressedTime[index] = usecTimestampNow();
                stateWhenPressed[index] = _magActive[index];
            }
        } else if (isPressed[index]) {
            isPressed[index] = false;
            //If the button was only pressed for < 250 ms
            //then disable it.

            const int MAX_BUTTON_PRESS_TIME = 250 * MSECS_TO_USECS;
            if (usecTimestampNow() < pressedTime[index] + MAX_BUTTON_PRESS_TIME) {
                _magActive[index] = !stateWhenPressed[index];
            }
        }

        //if we have the oculus, we should make the cursor smaller since it will be
        //magnified
        if (OculusManager::isConnected()) {

            QPoint point = getPalmClickLocation(palmData);

            _reticlePosition[index] = point;

            //When button 2 is pressed we drag the mag window
            if (isPressed[index]) {
                _magActive[index] = true;
            }

            // If oculus is enabled, we draw the crosshairs later
            continue;
        }

        int mouseX, mouseY;
        if (Menu::getInstance()->isOptionChecked(MenuOption::SixenseLasers)) {
            QPoint res = getPalmClickLocation(palmData);
            mouseX = res.x();
            mouseY = res.y();
        } else {
            // Get directon relative to avatar orientation
            glm::vec3 direction = glm::inverse(myAvatar->getOrientation()) * palmData->getFingerDirection();

            // Get the angles, scaled between (-0.5,0.5)
            float xAngle = (atan2(direction.z, direction.x) + M_PI_2);
            float yAngle = 0.5f - ((atan2(direction.z, direction.y) + M_PI_2));

            // Get the pixel range over which the xAngle and yAngle are scaled
            float cursorRange = glWidget->width() * SixenseManager::getInstance().getCursorPixelRangeMult();

            mouseX = (glWidget->width() / 2.0f + cursorRange * xAngle);
            mouseY = (glWidget->height() / 2.0f + cursorRange * yAngle);
        }

        //If the cursor is out of the screen then don't render it
        if (mouseX < 0 || mouseX >= glWidget->width() || mouseY < 0 || mouseY >= glWidget->height()) {
            _reticleActive[index] = false;
            continue;
        }
        _reticleActive[index] = true;


        const float reticleSize = 40.0f;

        mouseX -= reticleSize / 2.0f;
        mouseY += reticleSize / 2.0f;

        glBegin(GL_QUADS);

        glColor3f(RETICLE_COLOR[0], RETICLE_COLOR[1], RETICLE_COLOR[2]);

        glTexCoord2d(0.0f, 0.0f); glVertex2i(mouseX, mouseY);
        glTexCoord2d(1.0f, 0.0f); glVertex2i(mouseX + reticleSize, mouseY);
        glTexCoord2d(1.0f, 1.0f); glVertex2i(mouseX + reticleSize, mouseY - reticleSize);
        glTexCoord2d(0.0f, 1.0f); glVertex2i(mouseX, mouseY - reticleSize);

        glEnd();
    }
}
Esempio n. 3
0
static QPoint cutPoint(QPoint p11, QPoint p12, QPoint p21, QPoint p22)
{
    double dx1 = p12.x() - p11.x();
    double dy1 = p12.y() - p11.y();
    double dx2 = p22.x() - p21.x();
    double dy2 = p22.y() - p21.y();

    if ( dx1 == 0.0 && dx2 == 0.0 )
        return QPoint();

    if ( dx1 == 0.0 )
    {
        const double m = dy2 / dx2;
        const double t = p21.y() - m * p21.x();
        return QPoint(p11.x(), qwtInt(m * p11.x() + t));
    }

    if ( dx2 == 0 )
    {
        const double m = dy1 / dx1;
        const double t = p11.y() - m * p11.x();
        return QPoint(p21.x(), qwtInt(m * p21.x() + t));
    }

    const double m1 = dy1 / dx1;
    const double t1 = p11.y() - m1 * p11.x();

    const double m2 = dy2 / dx2;
    const double t2 = p21.y() - m2 * p21.x();

    if ( m1 == m2 )
        return QPoint();

    const double x = ( t2 - t1 ) / ( m1 - m2 );
    const double y = t1 + m1 * x;

    return QPoint(qwtInt(x), qwtInt(y));
}
Esempio n. 4
0
	void mouseMoveEvent(QMouseEvent *e) {
		QPoint diff = e->pos() - mousePos;
		mousePos = e->pos();
		verticalScrollBar()->setValue(verticalScrollBar()->value() + diff.y());
		horizontalScrollBar()->setValue(horizontalScrollBar()->value() + diff.x());
	}
Esempio n. 5
0
bool TMOGUIToneSlider::InRect(const QPoint& p, int x1, int x2, int y1, int y2)
{
	return (p.x() >= x1)&&(p.x() <= x2)&&(p.y() >= y1)&&(p.y() <= y2);
}
Esempio n. 6
0
bool PluginItemDelegate::editorEvent( QEvent *event,
                                      QAbstractItemModel *model,
                                      const QStyleOptionViewItem &option,
                                      const QModelIndex &index )
{
    Q_ASSERT(event);
    Q_ASSERT(model);

    if ( ( event->type() == QEvent::MouseButtonRelease )
         || ( event->type() == QEvent::MouseButtonDblClick )
         || ( event->type() == QEvent::MouseButtonPress )
         || ( event->type() == QEvent::MouseMove ) )
    {
        QMouseEvent *me = static_cast<QMouseEvent*>(event);
        QPoint mousePosition = me->pos() - option.rect.topLeft();

        if ( ( event->type() == QEvent::MouseMove )
             && !( me->buttons() & Qt::LeftButton ) )
        {
            // If the mouse moves around and no left button is pressed, no pushbutton is pressed
            // and no other event will be successful.
            m_aboutPressedIndex = QModelIndex();
            m_configPressedIndex = QModelIndex();
            return true;
        }

        // Handle checkbox
        QRect checkRect = checkboxOption( option, index, 0, Qt::AlignLeft ).rect;
        if ( checkRect.contains( mousePosition )
             && ( ( event->type() == QEvent::MouseButtonDblClick )
                   || ( event->type() == QEvent::MouseButtonRelease ) ) )
        {
            // make sure that the item is checkable
            Qt::ItemFlags flags = model->flags(index);
            if ( !( flags & Qt::ItemIsUserCheckable ) || !( option.state & QStyle::State_Enabled )
                || !( flags & Qt::ItemIsEnabled ) )
                return false;

            // make sure that we have a check state
            QVariant checkValue = index.data( Qt::CheckStateRole );
            if ( !checkValue.isValid() )
                return false;

            // eat the double click events inside the check rect
            if ( event->type() == QEvent::MouseButtonDblClick )
                return true;

            Qt::CheckState state = ( static_cast<Qt::CheckState>( checkValue.toInt() ) == Qt::Checked
                                     ? Qt::Unchecked : Qt::Checked );
            return model->setData(index, state, Qt::CheckStateRole);
        }

        if ( ( event->type() == QEvent::MouseMove )
             && !( me->buttons() & Qt::LeftButton ) )
        {
            m_aboutPressedIndex = QModelIndex();
            m_configPressedIndex = QModelIndex();
            return true;
        }

        QPoint topRight = option.rect.topRight();

        // Handle aboutButton
        {
            QRect aboutRect = buttonOption( option,
                                            index,
                                            PluginItemDelegate::About,
                                            topRight.x(),
                                            Qt::AlignRight ).rect;
            if ( aboutRect.contains( mousePosition ) ) {
                if ( event->type() == QEvent::MouseButtonDblClick )
                    return true;
                if ( event->type() == QEvent::MouseButtonPress ) {
                    m_aboutPressedIndex = index;
                    m_configPressedIndex = QModelIndex();
                    return true;
                }
                if ( event->type() == QEvent::MouseButtonRelease ) {
                    m_aboutPressedIndex = QModelIndex();
                    m_configPressedIndex = QModelIndex();
                    emit aboutPluginClicked( index );
                    return true;
                }
                if ( event->type() == QEvent::MouseMove ) {
                    if ( me->buttons() & Qt::LeftButton ) {
                        m_aboutPressedIndex = index;
                        m_configPressedIndex = QModelIndex();
                        return true;
                    }
                    else {
                        m_aboutPressedIndex = QModelIndex();
                        m_configPressedIndex = QModelIndex();
                        return true;
                    }
                }
            }
            else {
                // If the mouse is on the item and the mouse isn't above the button.
                // no about button is pressed.
                m_aboutPressedIndex = QModelIndex();
            }
            topRight -= QPoint( aboutRect.width(), 0 );
        }

        // Handle configButton
        // make sure we have config button
        if ( index.data( RenderPluginModel::ConfigurationDialogAvailable ).toBool() ) {
            QRect configRect = buttonOption( option,
                                             index,
                                             PluginItemDelegate::Configure,
                                             topRight.x(),
                                             Qt::AlignRight ).rect;
            if( configRect.contains( mousePosition ) ) {
                if ( event->type() == QEvent::MouseButtonDblClick )
                    return true;

                if ( event->type() == QEvent::MouseButtonPress ) {
                    m_aboutPressedIndex = QModelIndex();
                    m_configPressedIndex = index;
                    return true;
                }
                if ( event->type() == QEvent::MouseButtonRelease ) {
                    m_aboutPressedIndex = QModelIndex();
                    m_configPressedIndex = QModelIndex();
                    emit configPluginClicked( index );
                    return true;
                }
                if ( event->type() == QEvent::MouseMove ) {
                    if ( me->buttons() & Qt::LeftButton ) {
                        m_aboutPressedIndex = QModelIndex();
                        m_configPressedIndex = index;
                        return true;
                    }
                    else {
                        m_aboutPressedIndex = QModelIndex();
                        m_configPressedIndex = QModelIndex();
                        return true;
                    }
                }
            }
            else {
                // If the mouse is on the item and the mouse isn't above the button.
                // no config button is pressed.
                m_configPressedIndex = QModelIndex();
            }

            topRight -= QPoint( configRect.width(), 0 );
        }
        else {
            // If we don't have an config dialog shown and the mouse is over this item,
            // no config button is pressed.
            m_configPressedIndex = QModelIndex();
        }
    }

    return false;
}
Esempio n. 7
0
void wxWindowQt::DoClientToScreen( int *x, int *y ) const
{
    QPoint screenPosition = GetHandle()->mapToGlobal( QPoint( *x, *y ));
    *x = screenPosition.x();
    *y = screenPosition.y();
}
Esempio n. 8
0
void note::mouseMoveEvent(QMouseEvent *event)//重写鼠标移动事件
{
    QPoint gloPoint = event->globalPos();
    QRect rect = this->rect();
    QPoint tl = mapToGlobal(rect.topLeft());
    QPoint rb = mapToGlobal(rect.bottomRight());

    if(!isLeftPressDown) {
        this->region(gloPoint);
    } else {

        if(dir != NONE) {
            QRect rMove(tl, rb);

            switch(dir) {
            case LEFT:
                if(rb.x() - gloPoint.x() <= this->minimumWidth())
                    rMove.setX(tl.x());
                else
                    rMove.setX(gloPoint.x());
                break;
            case RIGHT:
                rMove.setWidth(gloPoint.x() - tl.x());
                break;
            case UP:
                if(rb.y() - gloPoint.y() <= this->minimumHeight())
                    rMove.setY(tl.y());
                else
                    rMove.setY(gloPoint.y());
                break;
            case DOWN:
                rMove.setHeight(gloPoint.y() - tl.y());
                break;
            case LEFTTOP:
                if(rb.x() - gloPoint.x() <= this->minimumWidth())
                    rMove.setX(tl.x());
                else
                    rMove.setX(gloPoint.x());
                if(rb.y() - gloPoint.y() <= this->minimumHeight())
                    rMove.setY(tl.y());
                else
                    rMove.setY(gloPoint.y());
                break;
            case RIGHTTOP:
                rMove.setWidth(gloPoint.x() - tl.x());
                rMove.setY(gloPoint.y());
                break;
            case LEFTBOTTOM:
                rMove.setX(gloPoint.x());
                rMove.setHeight(gloPoint.y() - tl.y());
                break;
            case RIGHTBOTTOM:
                rMove.setWidth(gloPoint.x() - tl.x());
                rMove.setHeight(gloPoint.y() - tl.y());
                break;
            default:

                break;
            }
            this->setGeometry(rMove);
        } else {
            move(event->globalPos() - dragPosition);
            event->accept();
        }
    }
    QDialog::mouseMoveEvent(event);
}
Esempio n. 9
0
TileLayer::TileLayer(const QString &name, QPoint position, QSize size)
    : TileLayer(name, position.x(), position.y(), size.width(), size.height())
{
}
Esempio n. 10
0
void QWSMouseHandler::limitToScreen(QPoint &position)
{
    position.setX(qMin(d_ptr->screen->deviceWidth() - 1, qMax(0, position.x())));
    position.setY(qMin(d_ptr->screen->deviceHeight() - 1, qMax(0, position.y())));
}
Esempio n. 11
0
void note::region(const QPoint &cursorGlobalPoint)//改变大小时,位置计算
{
    QRect rect = this->rect();
    QPoint tl = mapToGlobal(rect.topLeft());
    QPoint rb = mapToGlobal(rect.bottomRight());
    int x = cursorGlobalPoint.x();
    int y = cursorGlobalPoint.y();

    if(tl.x() + PADDING >= x && tl.x() <= x && tl.y() + PADDING >= y && tl.y() <= y) {
        // 左上角
        dir = LEFTTOP;
        this->setCursor(QCursor(Qt::SizeFDiagCursor));
    } else if(x >= rb.x() - PADDING && x <= rb.x() && y >= rb.y() - PADDING && y <= rb.y()) {
        // 右下角
        dir = RIGHTBOTTOM;
        this->setCursor(QCursor(Qt::SizeFDiagCursor));
    } else if(x <= tl.x() + PADDING && x >= tl.x() && y >= rb.y() - PADDING && y <= rb.y()) {
        //左下角
        dir = LEFTBOTTOM;
        this->setCursor(QCursor(Qt::SizeBDiagCursor));
    } else if(x <= rb.x() && x >= rb.x() - PADDING && y >= tl.y() && y <= tl.y() + PADDING) {
        // 右上角
        dir = RIGHTTOP;
        this->setCursor(QCursor(Qt::SizeBDiagCursor));
    } else if(x <= tl.x() + PADDING && x >= tl.x()) {
        // 左边
        dir = LEFT;
        this->setCursor(QCursor(Qt::SizeHorCursor));
    } else if( x <= rb.x() && x >= rb.x() - PADDING) {
        // 右边
        dir = RIGHT;
        this->setCursor(QCursor(Qt::SizeHorCursor));
    }else if(y >= tl.y() && y <= tl.y() + PADDING){
        // 上边
        dir = UP;
        this->setCursor(QCursor(Qt::SizeVerCursor));
    } else if(y <= rb.y() && y >= rb.y() - PADDING) {
        // 下边
        dir = DOWN;
        this->setCursor(QCursor(Qt::SizeVerCursor));
    }else {
        // 默认
        dir = NONE;
        this->setCursor(QCursor(Qt::ArrowCursor));
    }
}
Esempio n. 12
0
void VIfStatementCF::updateGeometry(int availableWidth, int availableHeight)
{
	clearConnectors();
	breaks_.clear();
	continues_.clear();

	if (!showAsControlFlow())
	{
		Item::updateGeometry(vis_, availableWidth, availableHeight);
		return;
	}

	// First compute the size
	int halfCondition = conditionBackground->width()/2 + style()->pinLength();
	int leftHalf = halfCondition + thenBranch->entrance().x();
	int rightHalf = halfCondition + elseBranch->width() - elseBranch->entrance().x();

	int extraLeft = leftHalf - thenBranch->width() - style()->pinLength();
	if (extraLeft < 0)
	{
		leftHalf += -extraLeft;
		extraLeft = 0;
	}

	int extraRight = rightHalf - elseBranch->width() - style()->pinLength();
	if (extraRight < 0)
	{
		rightHalf += -extraRight;
		extraRight = 0;
	}

	int height = conditionBackground->height() + style()->pinLength();
	int branchesTop = height;
	height += ( thenBranch->height() > elseBranch->height() ) ? thenBranch->height() : elseBranch->height() ;
	height += 3*style()->pinLength();

	// Set the size
	if ( hasShape() ) getShape()->setInnerSize(leftHalf + rightHalf, height);
	else setSize(leftHalf + rightHalf, height);

	// Set the positions
	conditionBackground->setPos(leftHalf - conditionBackground->width()/2,style()->pinLength());
	thenBranch->setPos(0, branchesTop);
	elseBranch->setPos(leftHalf + extraRight + style()->pinLength(), branchesTop);
	entrance_ = QPoint(leftHalf, 0);

	// Put connectors
	addConnector(leftHalf, 0, leftHalf, style()->pinLength(), true);

	// Then
	addConnector(conditionBackground->pos().x(), style()->pinLength() + conditionBackground->height()/2,
			thenBranch->entrance().x(), style()->pinLength() + conditionBackground->height()/2, false);
	addToLastConnector(thenBranch->pos().toPoint() + thenBranch->entrance());

	// Else
	addConnector(conditionBackground->pos().x() + conditionBackground->width(), style()->pinLength() + conditionBackground->height()/2,
			elseBranch->pos().toPoint().x() + elseBranch->entrance().x(), style()->pinLength() + conditionBackground->height()/2, false);
	addToLastConnector(elseBranch->pos().toPoint() + elseBranch->entrance());

	// Process Connectors on the then branch
	int thenBranchInnerBegin = height; // Height indicates no connectors on the inner side
	for (int i = 0; i < thenBranch->breaks().size(); ++i)
	{
		QPoint p = thenBranch->breaks().at(i);
		if (p.x() == 0) breaks_.append(thenBranch->pos().toPoint() + p);
		else if (thenBranch->pos().y() + p.y() < thenBranchInnerBegin)
			thenBranchInnerBegin = thenBranch->pos().y() + p.y();
	}
	for (int i = 0; i < thenBranch->continues().size(); ++i)
	{
		QPoint p = thenBranch->continues().at(i);
		if (p.x() == 0) continues_.append(thenBranch->pos().toPoint() + p);
		else if (thenBranch->pos().y() + p.y() < thenBranchInnerBegin)
			thenBranchInnerBegin = thenBranch->pos().y() + p.y();
	}

	// Process Connectors on the else branch
	int elseBranchInnerBegin = height; // Height indicates no connectors on the inner side
	for (int i = 0; i < elseBranch->breaks().size(); ++i)
	{
		QPoint p = elseBranch->breaks().at(i);
		if (p.x() > 0) breaks_.append(QPoint(1, elseBranch->pos().y() + p.y()));
		else if (elseBranch->pos().y() + p.y() < elseBranchInnerBegin)
			elseBranchInnerBegin = elseBranch->pos().y() + p.y();
	}
	for (int i = 0; i < elseBranch->continues().size(); ++i)
	{
		QPoint p = elseBranch->continues().at(i);
		if (p.x() > 0) continues_.append(QPoint(1, elseBranch->pos().y() + p.y()));
		else if (elseBranch->pos().y() + p.y() < elseBranchInnerBegin)
			elseBranchInnerBegin = elseBranch->pos().y() + p.y();
	}

	// If there are any break or continue statements on the inside put the corresponding connectors
	if (thenBranchInnerBegin < height)
	{
		addConnector(thenBranch->width(), thenBranchInnerBegin, thenBranch->width() , height - 3*style()->pinLength(), false);
		addToLastConnector(width(), height - 3*style()->pinLength());

		QPoint c = QPoint(1, height - 3*style()->pinLength());
		if (preferredBreakExit_ == ControlFlowItem::EXIT_RIGHT) breaks_.append(c);
		else continues_.append(c);
	}

	if (elseBranchInnerBegin < height)
	{
		addConnector(elseBranch->pos().x(), elseBranchInnerBegin, elseBranch->pos().x() , height - 2*style()->pinLength(), false);
		addToLastConnector(0, height - 2*style()->pinLength());

		QPoint c = QPoint(0, height - 2*style()->pinLength());
		if (preferredBreakExit_ == ControlFlowItem::EXIT_LEFT) breaks_.append(c);
		else continues_.append(c);
	}

	// Handle the exit and its connectors
	if (thenBranch->exit().isNull() && elseBranch->exit().isNull()) exit_ = QPoint(0,0);
	else if (thenBranch->exit().isNull())
	{
		exit_ = QPoint(elseBranch->pos().x() + elseBranch->exit().x(), height);
		addConnector(elseBranch->pos().toPoint() + elseBranch->exit(), exit_, false);
	}
	else if (elseBranch->exit().isNull())
	{
		exit_ = QPoint(thenBranch->exit().x(), height);
		addConnector(thenBranch->pos().toPoint() + thenBranch->exit(), exit_, false);
	}
	else
	{
		exit_ = QPoint(entrance_.x(), height);
		int lineHeight = height - style()->pinLength();
		addConnector(exit_ - QPoint(0,style()->pinLength()), exit_, false);
		addConnector(thenBranch->pos().toPoint() + thenBranch->exit(), QPoint(thenBranch->pos().x() + thenBranch->exit().x(), lineHeight), false);
		addToLastConnector(elseBranch->pos().x() + elseBranch->exit().x(), lineHeight);
		addToLastConnector(elseBranch->pos().toPoint() + elseBranch->exit());
	}

}
Esempio n. 13
0
void graph::paintEvent( QPaintEvent * )
{
	QPainter p( this );

	p.setPen( QPen( m_graphColor, 1 ) );

	QVector<float> * samps = &(model()->m_samples);
	int length = model()->length();
	const float maxVal = model()->maxValue();

	float xscale = (float)( width()-4 ) / length;
	float yscale = (float)( height()-4 ) / ( model()->minValue() - maxVal );

	// Max index, more useful below
	length--;


	switch( m_graphStyle )
	{
		case graph::LinearStyle:
			p.setRenderHints( QPainter::Antialiasing, true );

			for( int i=0; i < length; i++ )
			{
				// Needs to be rewritten
				p.drawLine(2+static_cast<int>(i*xscale), 
					2+static_cast<int>( ( (*samps)[i] - maxVal ) * yscale ),
					2+static_cast<int>((i+1)*xscale), 
					2+static_cast<int>( ( (*samps)[i+1] - maxVal ) * yscale )
					);
			}

			// Draw last segment wrapped around
			p.drawLine(2+static_cast<int>(length*xscale), 
				2+static_cast<int>( ( (*samps)[length] - maxVal ) * yscale ),
				width()-2,
				2+static_cast<int>( ( (*samps)[0] - maxVal ) * yscale ) );

			p.setRenderHints( QPainter::Antialiasing, false );
			break;


		case graph::NearestStyle:
			for( int i=0; i < length; i++ )
			{
				p.drawLine(2+static_cast<int>(i*xscale), 
					2+static_cast<int>( ( (*samps)[i] - maxVal ) * yscale ),
					2+static_cast<int>((i+1)*xscale), 
					2+static_cast<int>( ( (*samps)[i] - maxVal ) * yscale )
					);
				p.drawLine(2+static_cast<int>((i+1)*xscale), 
					2+static_cast<int>( ( (*samps)[i] - maxVal ) * yscale ),
					2+static_cast<int>((i+1)*xscale), 
					2+static_cast<int>( ( (*samps)[i+1] - maxVal ) * yscale )
					);
			}

			p.drawLine(2+static_cast<int>(length*xscale), 
				2+static_cast<int>( ( (*samps)[length] - maxVal ) * yscale ),
				width()-2,
				2+static_cast<int>( ( (*samps)[length] - maxVal ) * yscale ) );
			break;

		default:
			break;
	}


	// draw Pointer
	if( m_mouseDown ) 
	{
		QPoint cursor = mapFromGlobal( QCursor::pos() );
		p.setPen( QColor( 0xAA, 0xFF, 0x00, 0x70 ) );
		p.drawLine( 2, cursor.y(), width()-2, cursor.y() );
		p.drawLine( cursor.x(), 2, cursor.x(), height()-2 );
	}
	p.drawPixmap( 0, 0, m_foreground );
}
Esempio n. 14
0
int StripChart::indexAtPoint(const QPoint& point) {
    return (width() - point.x()) * _history->size() / width();
}
Esempio n. 15
0
double MyMoveServer::dist(const QPoint& p1, const QPoint& p2)
{
    return qSqrt(qPow(p1.x()-p2.x(),2)+qPow(p1.y()-p2.y(),2));
}
Esempio n. 16
0
void TileLayer::rotateHexagonal(RotateDirection direction, Map *map)
{
    Map::StaggerIndex staggerIndex = map->staggerIndex();
    Map::StaggerAxis staggerAxis = map->staggerAxis();

    Hex bottomRight(mWidth, mHeight, staggerIndex, staggerAxis);
    Hex topRight(mWidth, 0, staggerIndex, staggerAxis);
    Hex center(mWidth / 2, mHeight / 2, staggerIndex, staggerAxis);

    bottomRight -= center;
    topRight -= center;

    bottomRight.rotate(RotateRight);
    topRight.rotate(RotateRight);

    int newWidth = topRight.toStaggered(staggerIndex, staggerAxis).x() * 2 + 2;
    int newHeight = bottomRight.toStaggered(staggerIndex, staggerAxis).y() * 2 + 2;
    QScopedPointer<TileLayer> newLayer(new TileLayer(QString(), 0, 0, newWidth, newHeight));

    Hex newCenter(newWidth / 2, newHeight / 2, staggerIndex, staggerAxis);

    /* https://github.com/bjorn/tiled/pull/1447

  0 or 15     0: None or (Rotated60 | Rotated120 | FlippedVertically | FlippedHorizontally)
     2       60: Rotated60
     1      120: Rotated120
 12 or 3    180: (FlippedHorizontally | FlippedVertically) or (Rotated60 | Rotated120)
    14      240: Rotated60 | FlippedHorizontally | FlippedVertically
    13      300: Rotated120 | FlippedHorizontally | FlippedVertically

  8 or 7      0: FlippedHorizontally or (Rotated60 | Rotated120 | FlippedVertically)
    10       60: Rotated60 | FlippedHorizontally
     9      120: Rotated120 | FlippedHorizontally
  4 or 11   180: (FlippedVertically) or (Rotated60 | Rotated120 | FlippedHorizontally)
     6      240: Rotated60 | FlippedVertically
     5      300: Rotated120 | FlippedVertically

    */

    static const char rotateRightMask[16] = { 2, 12, 1, 14, 6, 8, 5, 10, 10,  4, 9, 0, 14,  0, 13,  2 }; // [0,15]->2->1->[12,3]->14->13; [8,7]->10->9->[4,11]->6->5;
    static const char rotateLeftMask[16]  = { 13, 2, 0,  1, 9, 6, 4,  5,  5, 10, 8, 9,  1, 14, 12, 13 }; // [0,15]->13->14->[12,3]->1->2; [8,7]->5->6->[4,11]->9->10;

    const char (&rotateMask)[16] =
            (direction == RotateRight) ? rotateRightMask : rotateLeftMask;

    QHashIterator<QPoint, Chunk> it(mChunks);
    while (it.hasNext()) {
        it.next();
        for (int y = 0; y < CHUNK_SIZE; ++y) {
            for (int x = 0; x < CHUNK_SIZE; ++x) {
                int _x = it.key().x() * CHUNK_SIZE + x;
                int _y = it.key().y() * CHUNK_SIZE + y;

                Cell dest(it.value().cellAt(x, y));

                if (dest.isEmpty())
                    continue;

                unsigned char mask =
                        (static_cast<unsigned char>(dest.flippedHorizontally()) << 3) |
                        (static_cast<unsigned char>(dest.flippedVertically()) << 2) |
                        (static_cast<unsigned char>(dest.flippedAntiDiagonally()) << 1) |
                        (static_cast<unsigned char>(dest.rotatedHexagonal120()) << 0);

                mask = rotateMask[mask];

                dest.setFlippedHorizontally((mask & 8) != 0);
                dest.setFlippedVertically((mask & 4) != 0);
                dest.setFlippedAntiDiagonally((mask & 2) != 0);
                dest.setRotatedHexagonal120((mask & 1) != 0);

                Hex rotatedHex(_x, _y, staggerIndex, staggerAxis);
                rotatedHex -= center;
                rotatedHex.rotate(direction);
                rotatedHex += newCenter;

                QPoint rotatedPoint = rotatedHex.toStaggered(staggerIndex, staggerAxis);

                newLayer->setCell(rotatedPoint.x(), rotatedPoint.y(), dest);
            }
        }
    }

    mWidth = newWidth;
    mHeight = newHeight;
    mChunks = newLayer->mChunks;

    QRect filledRect = region().boundingRect();

    if (staggerAxis == Map::StaggerY) {
        if (filledRect.y() & 1)
            map->invertStaggerIndex();
    } else {
        if (filledRect.x() & 1)
            map->invertStaggerIndex();
    }

    resize(filledRect.size(), -filledRect.topLeft());
}
Esempio n. 17
0
QRegion TilePainter::computeFillRegion(const QPoint &fillOrigin) const {
    //create that region that will hold the fill
    QRegion fillRegion;

    //silently quit if parameters are unsatisfactory
    if (!isDrawable(fillOrigin.x(), fillOrigin.y()))
        return fillRegion;

    //cache cell that we will match other cells against
    const Cell matchCell = cellAt(fillOrigin.x(), fillOrigin.y());

    //grab map dimensions for later use.
    const int mapWidth = mMapEditor->map()->width();
    const int mapHeight = mMapEditor->map()->height();
    const int mapSize = mapWidth * mapHeight;

    //create a queue to hold cells that need filling
    QList<QPoint> fillPositions;
    fillPositions.append(fillOrigin);

    qDebug() << "fix " << fillPositions.at(0).x();
    qDebug() << "fiy " << fillPositions.at(0).y();

    //create an array that will store which cells have been processed
    //this is faster than checking if a given cell is in the region/list
    QVector<quint8> processedCellsVec(mapSize);
    quint8 *processedCells = processedCellsVec.data();

    //loop through queued positions and fill them, while at the same time
    //checking adjacent positions to see if they should be added
    while (!fillPositions.isEmpty()) {

        for (int i = 0; i < fillPositions.size(); ++i) {
            qDebug() << "fx " << fillPositions.at(i).x();
            qDebug() << "fy " << fillPositions.at(i).y();
        }

        const QPoint currentPoint = fillPositions.takeFirst();

        //qDebug() << "cpx" << currentPoint.x();
        //qDebug() << "cpy" << currentPoint.y();

        const int startOfLine = currentPoint.y() * mapWidth;

        //seek as far left as we can
        int left = currentPoint.x();
        while (cellAt(left - 1, currentPoint.y()) == matchCell &&
               isDrawable(left - 1, currentPoint.y()))
            --left;

        //seek as far right as we can
        int right = currentPoint.x();
        while (cellAt(right + 1, currentPoint.y()) == matchCell &&
               isDrawable(right + 1, currentPoint.y()))
            ++right;

        qDebug() << left;

        //add cells between left and right to the region
        fillRegion += QRegion(left, currentPoint.y(), right - left + 1, 1);

        //add cell strip to processed cells
        memset(&processedCells[startOfLine + left],
               1,
               right - left);

        //these variables cache whether the last cell was added to the queue
        //or not as an optimization, since adjacent cells on the x axis
        //do not need to be added to the queue.
        bool lastAboveCell = false;
        bool lastBelowCell = false;

        //loop between left and right and check if cells above or
        //below need to be added to the queue
        for (int x = left; x <= right; ++x) {
            const QPoint fillPoint(x, currentPoint.y());

            //check cell above
            if (fillPoint.y() > 0) {
                QPoint aboveCell(fillPoint.x(), fillPoint.y() - 1);
                if (!processedCells[aboveCell.y() * mapWidth + aboveCell.x()] &&
                    cellAt(aboveCell.x(), aboveCell.y()) == matchCell &&
                    isDrawable(aboveCell.x(), aboveCell.y()))
                {
                    //do not add the above cell to the queue if its
                    //x-adjacent cell was added.
                    if (!lastAboveCell)
                        fillPositions.append(aboveCell);

                    lastAboveCell = true;
                } else lastAboveCell = false;

                processedCells[aboveCell.y() * mapWidth + aboveCell.x()] = 1;
            }

            //check cell below
            if (fillPoint.y() + 1 < mapHeight) {
                QPoint belowCell(fillPoint.x(), fillPoint.y() + 1);
                if (!processedCells[belowCell.y()*mapWidth + belowCell.x()] &&
                    cellAt(belowCell.x(), belowCell.y()) == matchCell &&
                    isDrawable(belowCell.x(), belowCell.y()))
                {
                    //do not add the below cell to the queue if its
                    //x-adjacent cell was added.
                    if (!lastBelowCell)
                        fillPositions.append(belowCell);

                    lastBelowCell = true;
                } else lastBelowCell = false;

                processedCells[belowCell.y() * mapWidth + belowCell.x()] = 1;
            }
        }
    }

    return fillRegion;
}
Esempio n. 18
0
QgsPoint QgsMapToPixel::toMapCoordinates( QPoint p ) const
{
  QgsPoint mapPt = toMapPoint( p.x(), p.y() );
  return QgsPoint( mapPt );
}
Esempio n. 19
0
static QString positionToStr(const QPoint& p)
{
    if (p == invalidPoint)
        return QString();
    return QString::number(p.x()) + ',' + QString::number(p.y());
}
Esempio n. 20
0
QPoint MapTilesFrame::convertRelativeCoordinateToServerCoordinate(QPoint relativeCoordinate, int newScaleLevel, int oldScaleLevel)
{
    QPoint nowPos(relativeCoordinate.x() * getViewportWidth() / width() + getViewportCoordinate().x(),
                   getViewportCoordinate().y() - relativeCoordinate.y() * getViewportHeight() / height());
    return nowPos * newScaleLevel / oldScaleLevel;
}
Esempio n. 21
0
void wxWindowQt::DoScreenToClient( int *x, int *y ) const
{
    QPoint clientPosition = GetHandle()->mapFromGlobal( QPoint( *x, *y ));
    *x = clientPosition.x();
    *y = clientPosition.y();
}
Esempio n. 22
0
/*============================================================
 * 视口准备函数
 *(Qt 槽函数)
 * 功能说明 : 计算并加载客户端地图视口区域要显示的地图瓦片
 *           供 paintEvent 使用
 * 函数重要性: 重要
 *
 * 参数说明 : 新的视口坐标
 *           (视口坐标为视口的左上角点坐标,以服务器坐标系为基准)
 * 返回值  :  无
 * 作者    : 刘梓懿
 * -----------------------------------------------------------
 * 变更履历 :
 *
 ============================================================*/
bool MapTilesFrame::prepareViewport(QPoint newPos)
{
    //本函数需要完成的具体任务是,计算并准备好biggerMapRect和clippedMapRect,供 paintEvent 使用

    qDebug() << "newPos: " << newPos;

    static QString tilePath("/s%1/s%2_%3-%4_%5-%6");
    //static QImage tile(tileWidth, tileHeight, QImage::Format_RGB16);
    static QImage noDataImage(":/images/notile.bmp");    //显示“暂无数据”的图片占位符,正好一个瓦片大小的

    int scaleLevel = getScaleLevel();     //当前缩放级别

    int w = width();
    int h = height();

    int mapWidth = scaleMaps[scaleLevel].width;
    int mapHeight = scaleMaps[scaleLevel].height;

     //判断用户显示视口大小是否大于当前缩放级别的整张地图大小
    if(w > mapWidth || h > mapHeight)
    {
        qDebug() << "viewport is bigger that whole map!";
        qDebug() << "viewportSize: " << size() << ", mapWidth: " << mapWidth << ", mapHeight: " << mapHeight;
        isViewportBiggerThanWholeMap = true;

        w = mapWidth;
        h = mapHeight;
    }
    else
    {
        isViewportBiggerThanWholeMap = false;
    }

    //新视口坐标的X和Y是否在地图网格线上(即X/Y坐标值是否能被被瓦片宽度/高度整除)
    //此判断在后面代码中会用到
    bool isSpecialX = false;
    bool isSpecialY = false;
    if(newPos.x() % tileWidth == 0)
    {
        isSpecialX = true;
        //qDebug() << "Special X!!!";
    }
    if(newPos.y() % tileHeight == 0)
    {
        isSpecialY = true;
        //qDebug() << "Special Y!!!";
    }

    //此为视口坐标点所在瓦片的左下角点,以下几行代码可以成功实现获取该点坐标
    QPoint tileBottomLeftCorner;
    tileBottomLeftCorner.rx() = newPos.x() - newPos.x() % tileWidth;
    tileBottomLeftCorner.ry() = newPos.y() - newPos.y() % tileHeight;
    if(isSpecialY)
    {
        tileBottomLeftCorner.ry() -= tileHeight;
    }

    //计算biggerMapRect占了几行、几列瓦片
    //numRows表示所占行数,numColumns表示所占列数
    //TODO: 算法有待优化
    int numRows;
    int numColumns;
    if(isViewportBiggerThanWholeMap)
    {
        numRows = mapHeight / tileHeight;
        numColumns = mapWidth / tileWidth;
    }
    else
    {
        int ceiling = newPos.y() / tileHeight * tileHeight + (newPos.y() % tileHeight == 0 ? 0 : tileHeight);
        int bottom = (newPos.y() - h) / tileHeight * tileHeight;
        numRows = (ceiling - bottom) / tileHeight;

        int rightX = newPos.x() + width();
        int rightOffset = ((rightX % tileWidth == 0) ? 0 : tileWidth);
        int leftBorder = newPos.x() - newPos.x() % tileWidth;
        int rightBorder = rightX / tileWidth * tileWidth + rightOffset;
        numColumns = (rightBorder - leftBorder) / tileWidth;
    }


    //biggerMapRect需要的大小
    //如果biggerMapRect不够大,则重新创建足够大的biggerMapRect
    QSize biggerMapRectSize(numColumns * tileWidth, numRows * tileHeight);
    if(biggerMapRect->width() < biggerMapRectSize.width()
            || biggerMapRect->height() < biggerMapRectSize.height())
    {
        delete biggerMapRect;
        biggerMapRect = new QImage(biggerMapRectSize, QImage::Format_RGB16);
    }


    QPainter painter(biggerMapRect);  //painter不能设为static!
    QString finalPath;     //最终的瓦片文件地址

    //biggerMapRect要加载的每个瓦片的左下角坐标和右上角坐标
    QPoint tempBL;
    QPoint tempTR;

//    qDebug() << "tileBottomLeftCorner:" << tileBottomLeftCorner;
//    qDebug() << "viewportCoordinate:" << newPos;
//    qDebug() << "viewportSize:" << size();
//    qDebug() << "numRows: " << numRows << ", numColumns: " << numColumns;

    QImage *tile = NULL;
    for(int m = 0; m < numRows; m++)
    {
        for(int n = 0; n < numColumns; n++)
        {
            tempBL.rx() = tileBottomLeftCorner.x() + n * tileWidth;
            tempBL.ry() = tileBottomLeftCorner.y() - m * tileHeight;
            tempTR.rx() = tempBL.x() + tileWidth;
            tempTR.ry() = tempBL.y() + tileHeight;

            //qDebug() << "tempBL" << tempBL;
            //qDebug() << "tempTR" << tempTR;

            finalPath = tilePath.arg(scaleLevel)
                    .arg(scaleLevel)
                    .arg(tempBL.x())
                    .arg(tempBL.y())
                    .arg(tempTR.x())
                    .arg(tempTR.y());
            //qDebug() << "loading tile(" << m << "," << n << "): " << finalPath;

            tile = tileProvider.getTile(finalPath);
            if(!tile)
            {
                qDebug() << "No tile data: " << finalPath;
                tile = &noDataImage;
                painter.drawImage(n * tileWidth, m * tileHeight, *tile);
            }
            else
            {
                painter.drawImage(n * tileWidth, m * tileHeight, *tile);
                delete tile;
                tile = NULL;
            }

        }
    }

    //此为视口在biggerMapRect中的相对坐标(坐标系为Qt坐标系,非服务器坐标系)
    QPoint viewportRelativeCoodinate(newPos.x() % tileWidth,
                                     isSpecialY ? 0 : (tileHeight - newPos.y() % tileHeight));

    //此为从biggerMapRect裁剪出来的,最终要呈现在屏幕上的显示矩形
    clippedMapRect = QRect(viewportRelativeCoodinate,
                           isViewportBiggerThanWholeMap ? QSize(mapWidth, mapHeight): size());

    qDebug() << "biggerMapRect" << biggerMapRect->size();
    qDebug() << "clippedMapRect: " << clippedMapRect;

    return isViewportBiggerThanWholeMap;
}
Esempio n. 23
0
 RotateEvent DrawWidget::GetRotateEvent(QPoint const & pt) const
 {
   QPoint const center = rect().center();
   return RotateEvent(L2D(center.x()), L2D(center.y()),
                      L2D(pt.x()), L2D(pt.y()));
 }
void QGeoTiledMapCustomObjectInfo::offsetChanged(const QPoint &/*offset*/)
{
    QPoint offset = custom->offset();
    graphicsItem->translate(offset.x(), offset.y());
    updateItem();
}
Esempio n. 25
0
//Injecting mouse movements and clicks
void SixenseManager::emulateMouse(PalmData* palm, int index) {
    MyAvatar* avatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
    QPoint pos;

    Qt::MouseButton bumperButton;
    Qt::MouseButton triggerButton;

    unsigned int deviceID = index == 0 ? CONTROLLER_0_EVENT : CONTROLLER_1_EVENT;

    if (_invertButtons) {
        bumperButton = Qt::LeftButton;
        triggerButton = Qt::RightButton;
    } else {
        bumperButton = Qt::RightButton;
        triggerButton = Qt::LeftButton;
    }

    if (Menu::getInstance()->isOptionChecked(MenuOption::SixenseLasers)
        || Menu::getInstance()->isOptionChecked(MenuOption::EnableVRMode)) {
        pos = qApp->getApplicationCompositor().getPalmClickLocation(palm);
    } else {
        // Get directon relative to avatar orientation
        glm::vec3 direction = glm::inverse(avatar->getOrientation()) * palm->getFingerDirection();

        // Get the angles, scaled between (-0.5,0.5)
        float xAngle = (atan2(direction.z, direction.x) + PI_OVER_TWO);
        float yAngle = 0.5f - ((atan2f(direction.z, direction.y) + (float)PI_OVER_TWO));
        auto canvasSize = qApp->getCanvasSize();
        // Get the pixel range over which the xAngle and yAngle are scaled
        float cursorRange = canvasSize.x * getCursorPixelRangeMult();

        pos.setX(canvasSize.x / 2.0f + cursorRange * xAngle);
        pos.setY(canvasSize.y / 2.0f + cursorRange * yAngle);

    }

    //If we are off screen then we should stop processing, and if a trigger or bumper is pressed,
    //we should unpress them.
    if (pos.x() == INT_MAX) {
        if (_bumperPressed[index]) {
            QMouseEvent mouseEvent(QEvent::MouseButtonRelease, pos, bumperButton, bumperButton, 0);

            qApp->mouseReleaseEvent(&mouseEvent, deviceID);

            _bumperPressed[index] = false;
        }
        if (_triggerPressed[index]) {
            QMouseEvent mouseEvent(QEvent::MouseButtonRelease, pos, triggerButton, triggerButton, 0);

            qApp->mouseReleaseEvent(&mouseEvent, deviceID);

            _triggerPressed[index] = false;
        }
        return;
    }

    //If position has changed, emit a mouse move to the application
    if (pos.x() != _oldX[index] || pos.y() != _oldY[index]) {
        QMouseEvent mouseEvent(QEvent::MouseMove, pos, Qt::NoButton, Qt::NoButton, 0);

        //Only send the mouse event if the opposite left button isnt held down.
        if (triggerButton == Qt::LeftButton) {
            if (!_triggerPressed[(int)(!index)]) {
                qApp->mouseMoveEvent(&mouseEvent, deviceID);
            }
        } else {
            if (!_bumperPressed[(int)(!index)]) {
                qApp->mouseMoveEvent(&mouseEvent, deviceID);
            }
        }
    }
    _oldX[index] = pos.x();
    _oldY[index] = pos.y();


    //We need separate coordinates for clicks, since we need to check if
    //a magnification window was clicked on
    int clickX = pos.x();
    int clickY = pos.y();
    //Set pos to the new click location, which may be the same if no magnification window is open
    pos.setX(clickX);
    pos.setY(clickY);

    //Check for bumper press ( Right Click )
    if (palm->getControllerButtons() & BUTTON_FWD) {
        if (!_bumperPressed[index]) {
            _bumperPressed[index] = true;

            QMouseEvent mouseEvent(QEvent::MouseButtonPress, pos, bumperButton, bumperButton, 0);

            qApp->mousePressEvent(&mouseEvent, deviceID);
        }
    } else if (_bumperPressed[index]) {
        QMouseEvent mouseEvent(QEvent::MouseButtonRelease, pos, bumperButton, bumperButton, 0);

        qApp->mouseReleaseEvent(&mouseEvent, deviceID);

        _bumperPressed[index] = false;
    }

    //Check for trigger press ( Left Click )
    if (palm->getTrigger() == 1.0f) {
        if (!_triggerPressed[index]) {
            _triggerPressed[index] = true;

            QMouseEvent mouseEvent(QEvent::MouseButtonPress, pos, triggerButton, triggerButton, 0);

            qApp->mousePressEvent(&mouseEvent, deviceID);
        }
    } else if (_triggerPressed[index]) {
        QMouseEvent mouseEvent(QEvent::MouseButtonRelease, pos, triggerButton, triggerButton, 0);

        qApp->mouseReleaseEvent(&mouseEvent, deviceID);

        _triggerPressed[index] = false;
    }
}
Esempio n. 26
0
void Window::paintEvent(QPaintEvent *){
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing, true);
    int s = list.size();
    for (int i = 0; i < s; i++){
        if (list[i].selected){painter.setPen(QPen(Qt::red, list[i].width, Qt::SolidLine));}else{painter.setPen(QPen(Qt::black, list[i].width, Qt::SolidLine));}
        if (list[i].fill && list[i].shape != Curve){painter.setBrush(QBrush(Qt::white));}else{painter.setBrush(Qt::NoBrush);}
        if (list[i].shape == Line){
             painter.drawLine(list[i].ps[0],list[i].ps[1]);
        }else if (list[i].shape == Poly || list[i].shape == Diamond){
             painter.drawPolygon(list[i].ps.constData(), list[i].ps.size());
        }else if (list[i].shape == Circle){
            int r = qSqrt(qPow(list[i].ps[0].x()-list[i].ps[1].x(), 2)+qPow(list[i].ps[0].y()-list[i].ps[1].y(), 2));
            painter.drawEllipse(list[i].ps[0], r, r);
        }else if (list[i].shape == Curve){
            QPainterPath path;
            path.moveTo(list[i].ps[0]);
            path.cubicTo(list[i].ps[0], list[i].ps[2], list[i].ps[1]);
            painter.drawPath(path);
        }
    }
    if (hasMouseTracking()){
        QPoint qp = Window::mapFromGlobal(QCursor::pos());
        painter.setPen(QPen(Qt::gray, tool.width, Qt::DashLine));
        if (tool.fill && tool.shape != Curve){painter.setBrush(QBrush(Qt::white));}else{painter.setBrush(Qt::NoBrush);}
        if (tool.shape == Line){
            painter.drawLine(tool.ps.last(), qp);
        }else if (tool.shape == Poly){
            tool.ps.append(qp);
            painter.drawPolygon(tool.ps.constData(), tool.ps.size());
            tool.ps.removeLast();
        }else if (tool.shape == Diamond){
            tool.ps.append(qp);
            tool.ps.append(QPoint(2*qp.x()-tool.ps[0].x(), tool.ps[0].y()));
            tool.ps.append(QPoint(qp.x(), 2*tool.ps[0].y()-qp.y()));
            painter.drawPolygon(tool.ps.constData(), tool.ps.size());
            for (int i = 3; i > 0; i--){tool.ps.removeLast();}
        }else if (tool.shape == Circle){
           int r = qSqrt(qPow(tool.ps[0].x()-qp.x(), 2)+qPow(tool.ps[0].y()-qp.y(), 2));
           painter.drawEllipse(tool.ps[0], r, r);
        }else if (tool.shape == Curve){
           QPainterPath path;
           path.moveTo(tool.ps[0]);
           path.cubicTo(tool.ps[0], qp, tool.ps[1]);
           painter.drawPath(path);
        }else if (tool.shape == None && pressed){
            painter.setBrush(Qt::NoBrush);
            painter.setPen(QPen(Qt::gray, 1, Qt::SolidLine));
            for (int i = 0; i < s; i++){
               for (int j = list[i].ps.size() - 1; j >=0; j--){
                   painter.drawEllipse(list[i].ps[j], 3, 3);
               }
            }
            painter.setPen(QPen(Qt::gray, 1, Qt::DotLine));
            QPoint lt = QPoint(qMin(qp.x(), tool.ps.last().x()), qMin(qp.y(), tool.ps.last().y()));
            QPoint rb = QPoint(qMax(qp.x(), tool.ps.last().x()), qMax(qp.y(), tool.ps.last().y()));
            painter.drawRect(lt.x(), lt.y(), qAbs(lt.x()-rb.x()), qAbs(lt.y()-rb.y()));
        }
    }
    painter.end();
}
bool Connection::Inside(const QPoint &p)
{
    int x=(n1->x+n2->x)/2;
    int y=(n1->y+n2->y)/2;
    return pow(p.x()-x,2)+pow(p.y()-y,2)<pow(15,2);
}
QPoint QMeeGoOverlayWidget::convertPoint(const QPoint &p)
{
    int x = p.x() * scaleW;
    int y = p.y() * scaleH;
    return QPoint(x, y);
}
Esempio n. 29
0
void DiagramCanvas::paint_all( QRect& r )
{
    int i;
    QPainter p( &buffer );
    QPen pen;
    QBrush brush;
    QPointArray a;
    QColor color;
    QRegion mask, crossing_disk;
    set<double>::iterator dbl_it;

    for ( i=0; i<crossingList.size(); ++i )
    {
        Crossing *c = crossingList[i];

        c->under->underpasses.insert( c->under->underpasses.end(), c->position_on_understrand );
    }

    for ( i=0; i<edgeList.size(); ++i )
    {
        Edge *e = edgeList[i];

        pen.setWidth( e->thickness );
        pen.setColor( CANVAS );
        p.setPen( pen );

        QPoint v, v1, v2, p1, p2 ;

        p1 = e->vertex[begin]->position;
        p2 = e->vertex[end]->position;
        p.drawLine( p1, p2 );
/*
      if (e->edge_type==singular)
        {

                v = p1 - p2;
                v1.setX( v.x() - v.y() );
                v1.setY( v.x() + v.y() );
                v2.setX( v.x() + v.y() );
                v2.setY( -v.x() + v.y() );

                v1 = 5 * v1 / sqrt( double (v1.x() * v1.x() + v1.y() * v1.y()) );
                v2 = 5 * v2 / sqrt( double (v2.x() * v2.x() + v2.y() * v2.y()) );
                v  = v / 2;
                pen.setWidth( ARROW );
                p.setPen( pen );
                p.drawLine( p2+v, p2+v1+v );
                p.drawLine( p2+v, p2+v2+v );
        }
*/
    }

    for ( i=0; i<edgeList.size(); ++i )
    {
        Edge *e = edgeList[i];

        color = (e->edge_type == drilled) ? DRILLED : colorList[e->arc_id % 18 ];

        pen.setWidth( e->thickness );
        pen.setColor( color );
        p.setPen( pen );

        brush.setColor( color );
        brush.setStyle( SolidPattern );
        p.setBrush( brush );

        if ( e->underpasses.size() > 0 )
        {
            p.setClipping( TRUE );
            mask = QRegion( 0, 0, width(), height(), QRegion::Rectangle );

            for ( dbl_it=e->underpasses.begin(); dbl_it!=e->underpasses.end(); ++dbl_it )
            {
                QPoint center = time_to_point( e, *dbl_it );
                crossing_disk = QRegion( center.x()-7, center.y()-7, 14, 14 , QRegion::Ellipse );
                mask -= crossing_disk;
            }

            p.setClipRegion( mask );
            QPoint v, v1, v2, p1, p2 ;

            p1 = e->vertex[begin]->position;
            p2 = e->vertex[end]->position;
            p.drawLine( p1, p2 );
/*
            if (e->edge_type==singular)
            {
                v = p1 - p2;
                v1.setX( v.x() - v.y() );
                v1.setY( v.x() + v.y() );
                v2.setX( v.x() + v.y() );
                v2.setY( -v.x() + v.y() );

                v1 = 5 * v1 / sqrt( double (v1.x() * v1.x() + v1.y() * v1.y()) );
                v2 = 5 * v2 / sqrt( double (v2.x() * v2.x() + v2.y() * v2.y()) );
                v  = v / 2;
                pen.setWidth( ARROW );
                p.setPen( pen );
                p.drawLine( p2+v, p2+v1+v );
                p.drawLine( p2+v, p2+v2+v );
            }
*/
            p.setClipping( FALSE );
        }

        else
        {
            QPoint v, v1, v2, p1, p2 ;

            p1 = e->vertex[begin]->position;
            p2 = e->vertex[end]->position;
            p.drawLine( p1, p2 );
/*
            if (e->edge_type==singular)
            {
                v = p1 - p2;
                v1.setX( v.x() - v.y() );
                v1.setY( v.x() + v.y() );
                v2.setX( v.x() + v.y() );
                v2.setY( -v.x() + v.y() );

                v1 = 5 * v1 / sqrt( double (v1.x() * v1.x() + v1.y() * v1.y()) );
                v2 = 5 * v2 / sqrt( double (v2.x() * v2.x() + v2.y() * v2.y()) );
                v  = v / 2;
                pen.setWidth( ARROW );
                p.setPen( pen );
                p.drawLine( p2+v, p2+v1+v );
                p.drawLine( p2+v, p2+v2+v );
            }
*/
        }

        e->underpasses.clear();
    }

    p.end();

    bitBlt( this, r.x(), r.y(), &buffer, r.x(), r.y(), r.width(), r.height() );

}
Esempio n. 30
0
/*!
   Determine the value corresponding to a specified mouse location.
   \param pos Mouse position
*/
double QwtSlider::getValue( const QPoint &pos )
{
    return d_data->map.invTransform(
        orientation() == Qt::Horizontal ? pos.x() : pos.y() );
}