void QgsLayoutItemPropertiesDialog::setItemPosition( QgsLayoutPoint position )
{
  // page number
  QPointF layoutPoint = mLayout->convertToLayoutUnits( position );
  int page = mLayout->pageCollection()->pageNumberForPoint( layoutPoint );

  // convert position to relative for current page
  position = mLayout->convertFromLayoutUnits( mLayout->pageCollection()->positionOnPage( layoutPoint ), position.units() );

  mPageSpin->setValue( page + 1 );
  whileBlocking( mPosUnitsComboBox )->setUnit( position.units() );
  mXPosSpin->setValue( position.x() );
  mYPosSpin->setValue( position.y() );
}
Ejemplo n.º 2
0
void QgsLayoutItemPropertiesWidget::setValuesForGuiPositionElements()
{
  if ( !mItem )
  {
    return;
  }

  auto block = [ = ]( bool blocked )
  {
    mXPosSpin->blockSignals( blocked );
    mYPosSpin->blockSignals( blocked );
    mPosUnitsComboBox->blockSignals( blocked );
    mWidthSpin->blockSignals( blocked );
    mHeightSpin->blockSignals( blocked );
    mSizeUnitsComboBox->blockSignals( blocked );
    mUpperLeftRadioButton->blockSignals( blocked );
    mUpperMiddleRadioButton->blockSignals( blocked );
    mUpperRightRadioButton->blockSignals( blocked );
    mMiddleLeftRadioButton->blockSignals( blocked );
    mMiddleRadioButton->blockSignals( blocked );
    mMiddleRightRadioButton->blockSignals( blocked );
    mLowerLeftRadioButton->blockSignals( blocked );
    mLowerMiddleRadioButton->blockSignals( blocked );
    mLowerRightRadioButton->blockSignals( blocked );
    mPageSpinBox->blockSignals( blocked );
  };
  block( true );

  QgsLayoutPoint point = mItem->pagePositionWithUnits();

  if ( !mFreezeXPosSpin )
    mXPosSpin->setValue( point.x() );
  if ( !mFreezeYPosSpin )
    mYPosSpin->setValue( point.y() );
  mPosUnitsComboBox->setUnit( point.units() );

  switch ( mItem->referencePoint() )
  {
    case QgsLayoutItem::UpperLeft:
    {
      mUpperLeftRadioButton->setChecked( true );
      break;
    }

    case QgsLayoutItem::UpperMiddle:
    {
      mUpperMiddleRadioButton->setChecked( true );
      break;
    }

    case QgsLayoutItem::UpperRight:
    {
      mUpperRightRadioButton->setChecked( true );
      break;
    }

    case QgsLayoutItem::MiddleLeft:
    {
      mMiddleLeftRadioButton->setChecked( true );
      break;
    }

    case QgsLayoutItem::Middle:
    {
      mMiddleRadioButton->setChecked( true );
      break;
    }

    case QgsLayoutItem::MiddleRight:
    {
      mMiddleRightRadioButton->setChecked( true );
      break;
    }

    case QgsLayoutItem::LowerLeft:
    {
      mLowerLeftRadioButton->setChecked( true );
      break;
    }

    case QgsLayoutItem::LowerMiddle:
    {
      mLowerMiddleRadioButton->setChecked( true );
      break;
    }

    case QgsLayoutItem::LowerRight:
    {
      mLowerRightRadioButton->setChecked( true );
      break;
    }
  }

  QgsLayoutSize size = mItem->sizeWithUnits();
  if ( !mFreezeWidthSpin )
    mWidthSpin->setValue( size.width() );
  if ( !mFreezeHeightSpin )
    mHeightSpin->setValue( size.height() );

  mSizeUnitsComboBox->setUnit( size.units() );

  mSizeLockAspectRatio->resetRatio();
  mPosLockAspectRatio->resetRatio();

  if ( !mFreezePageSpin )
    mPageSpinBox->setValue( mItem->page() + 1 );

  block( false );
}
Ejemplo n.º 3
0
void QgsLayoutView::keyPressEvent( QKeyEvent *event )
{
  if ( mTool )
  {
    mTool->keyPressEvent( event );
  }

  if ( mTool && event->isAccepted() )
    return;

  if ( event->key() == Qt::Key_Space && ! event->isAutoRepeat() )
  {
    if ( !( event->modifiers() & Qt::ControlModifier ) )
    {
      // Pan layout with space bar
      setTool( mSpacePanTool );
    }
    else
    {
      //ctrl+space pressed, so switch to temporary keyboard based zoom tool
      setTool( mSpaceZoomTool );
    }
    event->accept();
  }
  else if ( event->key() == Qt::Key_Left
            || event->key() == Qt::Key_Right
            || event->key() == Qt::Key_Up
            || event->key() == Qt::Key_Down )
  {
    QgsLayout *l = currentLayout();
    const QList<QgsLayoutItem *> layoutItemList = l->selectedLayoutItems();

    // increment used for cursor key item movement
    double increment = 1.0;
    if ( event->modifiers() & Qt::ShiftModifier )
    {
      //holding shift while pressing cursor keys results in a big step
      increment = 10.0;
    }
    else if ( event->modifiers() & Qt::AltModifier )
    {
      //holding alt while pressing cursor keys results in a 1 pixel step
      double viewScale = transform().m11();
      if ( viewScale > 0 )
      {
        increment = 1 / viewScale;
      }
    }

    double deltaX = 0;
    double deltaY = 0;
    switch ( event->key() )
    {
      case Qt::Key_Left:
        deltaX = -increment;
        break;
      case Qt::Key_Right:
        deltaX = increment;
        break;
      case Qt::Key_Up:
        deltaY = -increment;
        break;
      case Qt::Key_Down:
        deltaY = increment;
        break;
      default:
        break;
    }

    auto moveItem = [ l, deltaX, deltaY ]( QgsLayoutItem * item )
    {
      QgsLayoutPoint itemPos = item->positionWithUnits();
      QgsLayoutPoint deltaPos = l->convertFromLayoutUnits( QPointF( deltaX, deltaY ), itemPos.units() );
      itemPos.setX( itemPos.x() + deltaPos.x() );
      itemPos.setY( itemPos.y() + deltaPos.y() );
      item->attemptMove( itemPos );
    };

    l->undoStack()->beginMacro( tr( "Move Item" ) );
    for ( QgsLayoutItem *item : layoutItemList )
    {
      l->undoStack()->beginCommand( item, tr( "Move Item" ), QgsLayoutItem::UndoIncrementalMove );
      moveItem( item );
      l->undoStack()->endCommand();
    }
    l->undoStack()->endMacro();
    event->accept();
  }
}