예제 #1
0
void QgsLayoutView::ungroupSelectedItems()
{
  if ( !currentLayout() )
  {
    return;
  }

  QList< QgsLayoutItem * > ungroupedItems;
  //hunt through selection for any groups, and ungroup them
  const QList<QgsLayoutItem *> selectionList = currentLayout()->selectedLayoutItems();
  for ( QgsLayoutItem *item : selectionList )
  {
    if ( item->type() == QgsLayoutItemRegistry::LayoutGroup )
    {
      QgsLayoutItemGroup *itemGroup = static_cast<QgsLayoutItemGroup *>( item );
      ungroupedItems.append( currentLayout()->ungroupItems( itemGroup ) );
    }
  }

  if ( !ungroupedItems.empty() )
  {
    for ( QgsLayoutItem *item : qgis::as_const( ungroupedItems ) )
    {
      item->setSelected( true );
    }
    emit itemFocused( ungroupedItems.at( 0 ) );
  }
}
예제 #2
0
void QgsLayoutView::invertSelection()
{
  if ( !currentLayout() )
  {
    return;
  }

  QgsLayoutItem *focusedItem = nullptr;
  //check all items in layout
  const QList<QGraphicsItem *> itemList = currentLayout()->items();
  for ( QGraphicsItem *graphicsItem : itemList )
  {
    QgsLayoutItem *item = dynamic_cast<QgsLayoutItem *>( graphicsItem );
    QgsLayoutItemPage *paperItem = dynamic_cast<QgsLayoutItemPage *>( graphicsItem );
    if ( item && !paperItem )
    {
      //flip selected state for items (and deselect any locked items)
      if ( item->isSelected() || item->isLocked() )
      {
        item->setSelected( false );
      }
      else
      {
        item->setSelected( true );
        if ( !focusedItem )
          focusedItem = item;
      }
    }
  }
  if ( focusedItem )
    emit itemFocused( focusedItem );
}
예제 #3
0
void QgsLayoutView::selectAll()
{
  if ( !currentLayout() )
  {
    return;
  }

  //select all items in layout
  QgsLayoutItem *focusedItem = nullptr;
  const QList<QGraphicsItem *> itemList = currentLayout()->items();
  for ( QGraphicsItem *graphicsItem : itemList )
  {
    QgsLayoutItem *item = dynamic_cast<QgsLayoutItem *>( graphicsItem );
    QgsLayoutItemPage *paperItem = dynamic_cast<QgsLayoutItemPage *>( graphicsItem );
    if ( item && !paperItem )
    {
      if ( !item->isLocked() )
      {
        item->setSelected( true );
        if ( !focusedItem )
          focusedItem = item;
      }
      else
      {
        //deselect all locked items
        item->setSelected( false );
      }
    }
  }
  emit itemFocused( focusedItem );
}
예제 #4
0
void QgsLayoutView::viewChanged()
{
  if ( mHorizontalRuler )
  {
    mHorizontalRuler->setSceneTransform( viewportTransform() );
  }
  if ( mVerticalRuler )
  {
    mVerticalRuler->setSceneTransform( viewportTransform() );
  }

  // determine page at center of view
  QRect viewportRect( 0, 0, viewport()->width(), viewport()->height() );
  QRectF visibleRect = mapToScene( viewportRect ).boundingRect();
  QPointF centerVisible = visibleRect.center();

  if ( currentLayout() && currentLayout()->pageCollection() )
  {
    int newPage = currentLayout()->pageCollection()->pageNumberForPoint( centerVisible );
    if ( newPage != mCurrentPage )
    {
      mCurrentPage = newPage;
      emit pageChanged( mCurrentPage );
    }
  }
}
예제 #5
0
void QgsLayoutView::unlockAllItems()
{
  //unlock all items in layout
  currentLayout()->undoStack()->beginMacro( tr( "Unlock Items" ) );

  //first, clear the selection
  currentLayout()->deselectAll();

  QgsLayoutItem *focusItem = nullptr;

  const QList<QGraphicsItem *> itemList = currentLayout()->items();
  for ( QGraphicsItem *graphicItem : itemList )
  {
    QgsLayoutItem *item = dynamic_cast<QgsLayoutItem *>( graphicItem );
    if ( item && item->isLocked() )
    {
      focusItem = item;
      item->setLocked( false );
      //select unlocked items, same behavior as illustrator
      item->setSelected( true );
    }
  }
  currentLayout()->undoStack()->endMacro();

  emit itemFocused( focusItem );
}
예제 #6
0
void QgsLayoutView::deselectAll()
{
  if ( !currentLayout() )
  {
    return;
  }

  currentLayout()->deselectAll();
}
예제 #7
0
void QgsLayoutView::lockSelectedItems()
{
  currentLayout()->undoStack()->beginMacro( tr( "Lock Items" ) );
  const QList<QgsLayoutItem *> selectionList = currentLayout()->selectedLayoutItems();
  for ( QgsLayoutItem *item : selectionList )
  {
    item->setLocked( true );
  }

  currentLayout()->deselectAll();
  currentLayout()->undoStack()->endMacro();
}
예제 #8
0
void QgsLayoutView::mousePressEvent( QMouseEvent *event )
{
  mSnapMarker->setVisible( false );

  if ( mTool )
  {
    std::unique_ptr<QgsLayoutViewMouseEvent> me( new QgsLayoutViewMouseEvent( this, event, mTool->flags() & QgsLayoutViewTool::FlagSnaps ) );
    mTool->layoutPressEvent( me.get() );
    event->setAccepted( me->isAccepted() );
  }

  if ( !mTool || !event->isAccepted() )
  {
    if ( event->button() == Qt::MidButton )
    {
      // Pan layout with middle mouse button
      setTool( mMidMouseButtonPanTool );
      event->accept();
    }
    else if ( event->button() == Qt::RightButton && mMenuProvider )
    {
      QMenu *menu = mMenuProvider->createContextMenu( this, currentLayout(), mapToScene( event->pos() ) );
      if ( menu )
      {
        menu->exec( event->globalPos() );
        delete menu;
      }
    }
    else
    {
      QGraphicsView::mousePressEvent( event );
    }
  }
}
예제 #9
0
void LiveViewWindow::savedLayoutChanged(int index)
{
    if (m_isLayoutChanging)
        return;

    m_isLayoutChanging = true;

    if (static_cast<SavedLayoutsModel*>(m_savedLayouts->model())->isNewLayoutItem(index))
    {
        if (!createNewLayout())
            m_savedLayouts->setCurrentIndex(m_lastLayoutIndex);

        m_isLayoutChanging = false;
        return;
    }

    QByteArray data = m_savedLayouts->itemData(index, SavedLayoutsModel::LayoutDataRole).toByteArray();
    if (!data.isEmpty() && !m_liveView->layout()->loadLayout(data))
        qDebug() << "Failed to load camera layout" << m_savedLayouts->itemText(index);

    m_lastLayoutIndex = index;
    emit layoutChanged(currentLayout());

    aRenameLayout->setEnabled(index >= 0);
    aDelLayout->setEnabled(index >= 0);

    m_isLayoutChanging = false;
}
예제 #10
0
QList<int> QgsLayoutView::visiblePageNumbers() const
{
  //get current visible part of scene
  QRect viewportRect( 0, 0, viewport()->width(), viewport()->height() );
  QRectF visibleRect = mapToScene( viewportRect ).boundingRect();
  return currentLayout()->pageCollection()->visiblePageNumbers( visibleRect );
}
예제 #11
0
void QgsLayoutView::moveSelectedItemsToBottom()
{
  const QList<QgsLayoutItem *> selectedItems = currentLayout()->selectedLayoutItems();
  bool itemsLowered = false;
  for ( QgsLayoutItem *item : selectedItems )
  {
    itemsLowered = itemsLowered | currentLayout()->moveItemToBottom( item, true );
  }

  if ( !itemsLowered )
  {
    //no change
    return;
  }

  //update all positions
  currentLayout()->updateZValues();
  currentLayout()->update();
}
예제 #12
0
QDomElement KWDWriter::setLayout(QDomElement paragraph, QDomElement layout) {
	QDomElement theLayout;
	if (layout.isNull())
		theLayout=_doc->createElement("LAYOUT");
	else
		theLayout=layout.cloneNode().toElement();
	QDomElement oldLayout=currentLayout(paragraph);
	paragraph.removeChild(oldLayout);
	paragraph.appendChild(theLayout);
	return theLayout;
}
예제 #13
0
void QgsLayoutComboBox::rowsChanged()
{
  if ( count() == 1 )
  {
    //currently selected item has changed
    emit layoutChanged( currentLayout() );
  }
  else if ( count() == 0 )
  {
    emit layoutChanged( nullptr );
  }
}
예제 #14
0
void QgsLayoutView::setZoomLevel( double level )
{
  if ( currentLayout()->units() == QgsUnitTypes::LayoutPixels )
  {
    setTransform( QTransform::fromScale( level, level ) );
  }
  else
  {
    double dpi = QgsApplication::desktop()->logicalDpiX();
    //monitor dpi is not always correct - so make sure the value is sane
    if ( ( dpi < 60 ) || ( dpi > 1200 ) )
      dpi = 72;

    //desired pixel width for 1mm on screen
    level = qBound( MIN_VIEW_SCALE, level, MAX_VIEW_SCALE );
    double mmLevel = currentLayout()->convertFromLayoutUnits( level, QgsUnitTypes::LayoutMillimeters ).length() * dpi / 25.4;
    setTransform( QTransform::fromScale( mmLevel, mmLevel ) );
  }
  emit zoomLevelChanged();
  updateRulers();
}
예제 #15
0
void QgsLayoutView::setVerticalRuler( QgsLayoutRuler *ruler )
{
  mVerticalRuler = ruler;
  ruler->setLayoutView( this );
  if ( QgsLayout *layout = currentLayout() )
  {
    connect( &layout->guides(), &QAbstractItemModel::dataChanged, ruler, [ = ] { mVerticalRuler->update(); } );
    connect( &layout->guides(), &QAbstractItemModel::rowsInserted, ruler, [ = ] { mVerticalRuler->update(); } );
    connect( &layout->guides(), &QAbstractItemModel::rowsRemoved, ruler, [ = ] { mVerticalRuler->update(); } );
    connect( &layout->guides(), &QAbstractItemModel::modelReset, ruler, [ = ] { mVerticalRuler->update(); } );
  }
  viewChanged();
}
예제 #16
0
void QgsLayoutView::groupSelectedItems()
{
  if ( !currentLayout() )
  {
    return;
  }

  //group selected items
  const QList<QgsLayoutItem *> selectionList = currentLayout()->selectedLayoutItems();
  QgsLayoutItemGroup *itemGroup = currentLayout()->groupItems( selectionList );

  if ( !itemGroup )
  {
    //group could not be created
    return;
  }

  for ( QgsLayoutItem *item : selectionList )
  {
    item->setSelected( false );
  }

  currentLayout()->setSelectedItem( itemGroup );
}
예제 #17
0
void QgsLayoutView::deleteSelectedItems()
{
  if ( !currentLayout() )
  {
    return;
  }

#if 0 //TODO
  if ( mCurrentTool == QgsComposerView::EditNodesItem )
  {
    if ( mNodesItemIndex != -1 )
    {
      composition()->beginCommand( mNodesItem, tr( "Remove item node" ) );
      if ( mNodesItem->removeNode( mNodesItemIndex ) )
      {
        composition()->endCommand();
        if ( mNodesItem->nodesSize() > 0 )
        {
          mNodesItemIndex = mNodesItem->selectedNode();
          // setSelectedNode( mNodesItem, mNodesItemIndex );
        }
        else
        {
          mNodesItemIndex = -1;
          mNodesItem = nullptr;
        }
        scene()->update();
      }
      else
      {
        composition()->cancelCommand();
      }
    }
  }
  else
  {
#endif
    const QList<QgsLayoutItem *> selectedItems = currentLayout()->selectedLayoutItems();

    currentLayout()->undoStack()->beginMacro( tr( "Delete Items" ) );
    //delete selected items
    for ( QgsLayoutItem *item : selectedItems )
    {
      currentLayout()->removeLayoutItem( item );
    }
    currentLayout()->undoStack()->endMacro();
    currentLayout()->project()->setDirty( true );

#if 0
  }
#endif
}
예제 #18
0
void LiveViewWindow::setFullScreen(bool on)
{
    if (on == isFullScreen())
        return;

    if (on)
    {
        if (!isWindow())
        {
            LiveViewWindow *wnd = LiveViewWindow::openWindow(m_serverRepository, this, true);
            wnd->setLayout(currentLayout());
            wnd->showFullScreen();
            m_fsSetWindow = wnd;
            connect(wnd, SIGNAL(layoutChanged(QString)), SLOT(setLayout(QString)));
            connect(wnd, SIGNAL(destroyed()), SLOT(show()));
            setVisible(false);
        }
        else
            showFullScreen();
    }
    else
    {
        if (m_fsSetWindow)
        {
            setVisible(true);
            m_fsSetWindow.data()->close();
            m_fsSetWindow.clear();
        }
        else
            showNormal();
    }

    QSettings settings;
    if (settings.value(QLatin1String("ui/disableScreensaver/onFullscreen")).toBool())
        bcApp->setScreensaverInhibited(on);
}
예제 #19
0
void QgsLayoutComboBox::indexChanged( int i )
{
  Q_UNUSED( i );
  emit layoutChanged( currentLayout() );
}
예제 #20
0
void QgsLayoutView::alignSelectedItems( QgsLayoutAligner::Alignment alignment )
{
  const QList<QgsLayoutItem *> selectedItems = currentLayout()->selectedLayoutItems();
  QgsLayoutAligner::alignItems( currentLayout(), selectedItems, alignment );
}
예제 #21
0
void QgsLayoutView::distributeSelectedItems( QgsLayoutAligner::Distribution distribution )
{
  const QList<QgsLayoutItem *> selectedItems = currentLayout()->selectedLayoutItems();
  QgsLayoutAligner::distributeItems( currentLayout(), selectedItems, distribution );
}
예제 #22
0
void QgsLayoutView::resizeSelectedItems( QgsLayoutAligner::Resize resize )
{
  const QList<QgsLayoutItem *> selectedItems = currentLayout()->selectedLayoutItems();
  QgsLayoutAligner::resizeItems( currentLayout(), selectedItems, resize );
}
예제 #23
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();
  }
}
예제 #24
0
void QgsLayoutView::selectNextItemAbove()
{
  selectNextByZOrder( currentLayout(), true );
}
예제 #25
0
void QgsLayoutView::selectNextItemBelow()
{
  selectNextByZOrder( currentLayout(), false );
}