예제 #1
0
bool SelectTool::startCustomDragging(const QPoint &pos, bool selectedOnly )
{
  KivioCanvas* canvas = view()->canvasWidget();
  KivioPage *pPage = canvas->activePage();
  KivioStencil *pStencil;
  int colType;

  KoPoint pagePoint = canvas->mapFromScreen( pos );
  
  // Figure out how big 4 pixels is in terms of points
  double threshold =  view()->zoomHandler()->unzoomItY(4);

  pStencil = pPage->checkForStencil( &pagePoint, &colType, threshold, selectedOnly );

  if( !pStencil || colType < kctCustom ) {
    return false;
  }


  if(pStencil->isSelected()) {
    // If we are clicking an already selected stencil, and the control
    // key down, then unselect this stencil
    if(m_controlKey) {
      pPage->unselectStencil(pStencil);
    }
  } else {
    // Clicking a new stencil, and the control key is not down
    if(!m_controlKey) {
      pPage->unselectAllStencils();
    }

    pPage->selectStencil( pStencil );
  }

  m_pCustomDraggingStencil = pStencil;

  // Set the mode
  m_mode = stmCustomDragging;

  m_customDragID = colType;
  m_customDragOrigPoint = pStencil->customIDPoint(m_customDragID);

  view()->canvasWidget()->setShowConnectorTargets(true);
  view()->canvasWidget()->repaint();

  // Create a new painter object
  canvas->beginUnclippedSpawnerPainter();
  m_firstTime = true;

  return true;
}
예제 #2
0
/**
 * Tests if we should start rubber banding (always returns true).
 */
bool SMLConnector::startRubberBanding( QMouseEvent *e )
{
  KivioDoc* doc = view()->doc();
  KivioPage* pPage = view()->activePage();
  KivioCanvas* canvas = view()->canvasWidget();

  startPoint = canvas->snapToGrid(canvas->mapFromScreen( e->pos() ));

  // Create the stencil
    KivioStencilSpawner* ss = doc->findInternalStencilSpawner("SML Connector");

  if (!ss) {
    kdDebug(43000) << "SMLTool: Failed to find StencilSpawner!" << endl;
    return false;
  }

  startPoint = canvas->snapToGrid(canvas->mapFromScreen( e->pos() ));

  // Create the stencil
  m_pStencil = (KivioSMLConnector*)ss->newStencil("basic_line");
  m_pStencil->setTextFont(doc->defaultFont());

  // Unselect everything, add the stencil to the page, and select it
  pPage->unselectAllStencils();
  pPage->addStencil(m_pStencil);
  pPage->selectStencil(m_pStencil);

  // Get drag info ready
  m_pDragData = new KivioCustomDragData();
  m_pDragData->page = pPage;
  m_pDragData->x = startPoint.x();
  m_pDragData->y = startPoint.y();
  m_pDragData->id = kctCustom + 2;

  m_pStencil->setStartPoint(startPoint.x() + 10.0f, startPoint.y() + 10.0f);
  m_pStencil->setEndPoint(startPoint.x(), startPoint.y());
  m_pStencil->customDrag(m_pDragData);


  canvas->repaint();
  canvas->setCursor(*m_pConnectorCursor2);
  return true;
}
예제 #3
0
void SMLConnector::connector(QRect)
{
    if (!m_pStencil)
      return;

    delete m_pDragData;
    m_pDragData = 0;

    KivioDoc* doc = view()->doc();
    KivioPage* page = view()->activePage();

    if (m_pStencil->w() < 3.0 && m_pStencil->h() < 3.0) {
        page->unselectAllStencils();
        page->selectStencil(m_pStencil);
        page->deleteSelectedStencils();
        m_pStencil = 0;
        doc->updateView(page);
        return;
    }

    m_pStencil->searchForConnections(page, view()->zoomHandler()->unzoomItY(4));
    doc->updateView(page);
}
예제 #4
0
/**
 * Tests if we should start rubber banding (always returns true).
 */
bool ConnectorTool::startRubberBanding( QMouseEvent *e )
{
  KivioCanvas* canvas = view()->canvasWidget();
  KivioDoc* doc = view()->doc();
  KivioPage* pPage = canvas->activePage();
  QString spawnerId;
  
  if(m_type == StraightConnector) {
    spawnerId = "Dave Marotti - Straight Connector";
  } else {
    spawnerId = "Internal - PolyLine Connector";
  }

  KivioStencilSpawner* ss = doc->findInternalStencilSpawner(spawnerId);
    
  if(!ss) {
    kdDebug(43000) << "ConnectorTool: Failed to find StencilSpawner!" << endl;
    return false;
  }
    
    // Create the stencil
  m_pStencil = static_cast<Kivio1DStencil*>(ss->newStencil());
  
  bool hit = false;
  startPoint = pPage->snapToTarget(canvas->mapFromScreen(e->pos()), 8.0, hit);

  if(!hit) {
    startPoint = canvas->snapToGrid(startPoint);
  }

  
  if(!m_pStencil) {
    return false;
  }
  
  m_pStencil->setTextFont(doc->defaultFont());

  // Unselect everything, add the stencil to the page, and select it
  pPage->unselectAllStencils();
  pPage->addStencil(m_pStencil);
  pPage->selectStencil(m_pStencil);
  // Get drag info ready
  m_pDragData = new KivioCustomDragData();
  m_pDragData->page = pPage;
  m_pDragData->x = startPoint.x();
  m_pDragData->y = startPoint.y();

  if(m_type == StraightConnector) {
    KivioStraightConnector* connector = static_cast<KivioStraightConnector*>(m_pStencil);
    m_pDragData->id = kctCustom + 2;
  
    connector->setStartPoint(startPoint.x(), startPoint.y());
    connector->setEndPoint(startPoint.x() + 10.0, startPoint.y() + 10.0);
  } else {
    Kivio::PolyLineConnector* connector = static_cast<Kivio::PolyLineConnector*>(m_pStencil);
    m_pDragData->id = kctCustom + 1;
    connector->addPoint(startPoint);
    connector->addPoint(startPoint);
  }

  m_pStencil->customDrag(m_pDragData);

  canvas->repaint();
  canvas->setCursor(*m_pConnectorCursor2);
  return true;
}
예제 #5
0
/**
 * Tests if we can start dragging a stencil.
 */
bool SelectTool::startDragging(const QPoint &pos, bool onlySelected)
{
  KivioCanvas* canvas = view()->canvasWidget();
  KivioPage *pPage = canvas->activePage();
  KivioStencil *pStencil;
  int colType;

  // Figure out how big 4 pixels is in terms of points
  double threshold =  view()->zoomHandler()->unzoomItY(4);

  KoPoint pagePoint = canvas->mapFromScreen( pos );

  pStencil = pPage->checkForStencil( &pagePoint, &colType, threshold, onlySelected );

  if( !pStencil )
    return false;

  canvas->setEnabled(false);

  if( pStencil->isSelected() )
  {
    // If we are clicking an already selected stencil, and the control
    // key down, then unselect this stencil
    if( m_controlKey==true ) {
      pPage->unselectStencil( pStencil );
    }

    // Otherwise, it means we are just moving
  }
  else
  {
    // Clicking a new stencil, and the control key is not down
    if( !m_controlKey )
      pPage->unselectAllStencils();

    pPage->selectStencil( pStencil );
    // Update the auto guidelines
    view()->canvasWidget()->updateAutoGuideLines();
  }

  // Create a new painter object
  canvas->beginUnclippedSpawnerPainter();

  // Build the list of old geometry
  KivioSelectDragData *pData;
  m_lstOldGeometry.clear();
  pStencil = canvas->activePage()->selectedStencils()->first();

  while( pStencil )
  {
    pData = new KivioSelectDragData;
    pData->rect = pStencil->rect();
    m_lstOldGeometry.append(pData);

    pStencil = canvas->activePage()->selectedStencils()->next();
  }

  m_selectedRect = view()->activePage()->getRectForAllSelectedStencils();
  changeMouseCursor(pos);
  // Set the mode
  m_mode = stmDragging;
  m_firstTime = true;
  canvas->setEnabled(true);
  return true;
}