Ejemplo n.º 1
0
// -----------------------------------------------------------------------
void GraphicText::paintScheme(QPainter *p)
{
  QWMatrix wm = p->worldMatrix();
  QWMatrix Mat (wm.m11(), 0.0, 0.0, wm.m22(),
		wm.dx() + double(cx) * wm.m11(),
		wm.dy() + double(cy) * wm.m22());
  p->setWorldMatrix(Mat);
  p->rotate(-Angle);
  p->drawRect(0, 0, x2, y2);

  p->setWorldMatrix(wm);
}
Ejemplo n.º 2
0
QWMatrix QPixmap::trueMatrix( const QWMatrix &matrix, int w, int h )
{
    const double dt = (double)0.;
    double x1,y1, x2,y2, x3,y3, x4,y4;		// get corners
    double xx = (double)w;
    double yy = (double)h;

    QWMatrix mat( matrix.m11(), matrix.m12(), matrix.m21(), matrix.m22(), 0., 0. );

    mat.map( dt, dt, &x1, &y1 );
    mat.map( xx, dt, &x2, &y2 );
    mat.map( xx, yy, &x3, &y3 );
    mat.map( dt, yy, &x4, &y4 );

    double ymin = y1;				// lowest y value
    if ( y2 < ymin ) ymin = y2;
    if ( y3 < ymin ) ymin = y3;
    if ( y4 < ymin ) ymin = y4;
    double xmin = x1;				// lowest x value
    if ( x2 < xmin ) xmin = x2;
    if ( x3 < xmin ) xmin = x3;
    if ( x4 < xmin ) xmin = x4;

    double ymax = y1;				// lowest y value
    if ( y2 > ymax ) ymax = y2;
    if ( y3 > ymax ) ymax = y3;
    if ( y4 > ymax ) ymax = y4;
    double xmax = x1;				// lowest x value
    if ( x2 > xmax ) xmax = x2;
    if ( x3 > xmax ) xmax = x3;
    if ( x4 > xmax ) xmax = x4;

    if ( xmax-xmin > 1.0 )
	xmin -= xmin/(xmax-xmin);
    if ( ymax-ymin > 1.0 )
	ymin -= ymin/(ymax-ymin);

    mat.setMatrix( matrix.m11(), matrix.m12(), matrix.m21(), matrix.m22(), -xmin, -ymin );
    return mat;
}
Ejemplo n.º 3
0
void CNavigationDiagramView::contentsMouseMoveEvent(QMouseEvent * e){
	QWMatrix matrix = inverseWorldMatrix();
	double x = matrix.m11() * e->x() + matrix.m12() * e->y();
	double y = matrix.m21() * e->x() + matrix.m22() * e->y();

	if (! canvas()->onCanvas(x, y)) return;

	if (m_pqActiveItem){
		

		double dxPosLokal = e->pos().x() - m_qLastPos.x();
		double dyPosLokal = e->pos().y() - m_qLastPos.y();

		double dxPos = matrix.m11() * dxPosLokal + matrix.m12() * dyPosLokal;
		double dyPos = matrix.m21() * dxPosLokal + matrix.m22() * dyPosLokal;

		//int newIntX = (int) (x() + dxPos);
		//int newIntY = (int) (y() + dyPos);
		//if (! canvas()->onCanvas(newIntX, newIntY)) return;

		m_pqActiveItem->moveBy(dxPos, dyPos);

		m_qLastPos = e->pos();
		canvas()->update();

		if (m_pqActiveItem->rtti() == CFromDiagramMarker::RTTI){
			CFromDiagramMarker *fromMarker = (CFromDiagramMarker*) m_pqActiveItem;
			float fXPos = (float) fromMarker->GetCenterX();
			float fYPos = (float) fromMarker->GetCenterY();
			CNavigationProjectController::Instance()->SetNewFromPosition(fXPos, fYPos);
		}else if (m_pqActiveItem->rtti() == CAtDiagramMarker::RTTI){
			CAtDiagramMarker *atMarker = (CAtDiagramMarker*) m_pqActiveItem;
			float fXPos = (float) atMarker->GetCenterX();
			float fYPos = (float) atMarker->GetCenterY();
			CNavigationProjectController::Instance()->SetNewAtPosition(fXPos, fYPos);
		}
	}
}
Ejemplo n.º 4
0
void CNavigationDiagramView::contentsMousePressEvent(QMouseEvent * e){
	QWMatrix matrix = inverseWorldMatrix();
	int xPos = matrix.m11() * e->pos().x() + matrix.m12() * e->pos().y();
	int yPos = matrix.m21() * e->pos().x() + matrix.m22() * e->pos().y();
	QPoint p(xPos, yPos);

	QCanvasItemList items = canvas()->collisions(p);
	if (items.empty()){
		setActiveItem(0);
	}else{
		setActiveItem(*items.begin());
	}
	m_qLastPos = e->pos();
}
Ejemplo n.º 5
0
/**
 * Tests if a point is over a stencils
 */
int SelectTool::isOverResizeHandle( KivioStencil *pStencil, const double x, const double y )
{
  double three_pixels = 4.0;

  int available;

  QWMatrix m;
  double w = pStencil->w();
  double h = pStencil->h();
  double w2 = pStencil->w() / 2.0;
  double h2 = pStencil->h() / 2.0;
  m.translate(pStencil->x(), pStencil->y());
  m.translate(w2, h2);
  m.rotate(pStencil->rotation());
  m.translate(-w2, -h2);

  // FIXME: this needs to be optimized!!!!
  KoPoint tl(0 * m.m11() + 0 * m.m21() + m.dx(), 0 * m.m12() + 0 * m.m22() + m.dy());
  KoPoint t(w2 * m.m11() + 0 * m.m21() + m.dx(), w2 * m.m12() + 0 * m.m22() + m.dy());
  KoPoint tr(w * m.m11() + 0 * m.m21() + m.dx(), w * m.m12() + 0 * m.m22() + m.dy());
  KoPoint r(w * m.m11() + h2 * m.m21() + m.dx(), w * m.m12() + h2 * m.m22() + m.dy());
  KoPoint br(w * m.m11() + h * m.m21() + m.dx(), w * m.m12() + h * m.m22() + m.dy());
  KoPoint b(w2 * m.m11() + h * m.m21() + m.dx(), w2 * m.m12() + h * m.m22() + m.dy());
  KoPoint bl(0 * m.m11() + h * m.m21() + m.dx(), 0 * m.m12() + h * m.m22() + m.dy());
  KoPoint l(0 * m.m11() + h2 * m.m21() + m.dx(), 0 * m.m12() + h2 * m.m22() + m.dy());

  available = pStencil->resizeHandlePositions();

  // Quick reject
  if( !available )
    return 0;


  // Top left
  if( available & krhpNW &&
    RESIZE_BOX_TEST( x, y, tl.x(), tl.y() ) )
    return 1;

  // Top
  if( available & krhpN &&
    RESIZE_BOX_TEST( x, y, t.x(), t.y() ) )
    return 2;

  // Top right
  if( available & krhpNE &&
    RESIZE_BOX_TEST( x, y, tr.x(), tr.y()  ) )
    return 3;

  // Right
  if( available & krhpE &&
    RESIZE_BOX_TEST( x, y, r.x(), r.y() ) )
    return 4;

  // Bottom right
  if( available & krhpSE &&
    RESIZE_BOX_TEST( x, y, br.x(), br.y() ) )
    return 5;

  // Bottom
  if( available & krhpS &&
    RESIZE_BOX_TEST( x, y, b.x(), b.y() ) )
    return 6;

  // Bottom left
  if( available & krhpSW &&
    RESIZE_BOX_TEST( x, y, bl.x(), bl.y() ) )
    return 7;

  // Left
  if( available & krhpW &&
    RESIZE_BOX_TEST( x, y, l.x(), l.y() ) )
    return 8;

  // Nothing found
  return 0;
}