Esempio n. 1
0
void WindowController::_constrainPosition(QRectF& window) const
{
    const auto& group = _group.getCoordinates();

    if (_targetIsFullscreen())
    {
        const auto overlapX = group.width() - window.width();
        const auto overlapY = group.height() - window.height();

        const auto minX = overlapX < 0.0 ? overlapX : 0.5 * overlapX;
        const auto minY = overlapY < 0.0 ? overlapY : 0.5 * overlapY;

        const auto maxX = 0.0;
        const auto maxY = 0.0;

        window.moveTopLeft({std::max(minX, std::min(window.x(), maxX)),
                            std::max(minY, std::min(window.y(), maxY))});
        return;
    }

    const auto minX = ui::getMinWindowSize() - window.width();
    const auto minY = ui::getMinWindowSize() - window.height();

    const auto maxX = group.width() - ui::getMinWindowSize();
    const auto maxY = group.height() - ui::getMinWindowSize();

    window.moveTopLeft({std::max(minX, std::min(window.x(), maxX)),
                        std::max(minY, std::min(window.y(), maxY))});
}
Esempio n. 2
0
void OnMonitorRectItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
    Q_UNUSED(widget)
    Q_UNUSED(option)

    painter->setPen(pen());
    //painter->setClipRect(option->rect);
    const QRectF r = rect();
    painter->drawRect(r);
    QRectF handle = painter->worldTransform().inverted().mapRect(QRectF(0, 0, 6, 6));
    if (isEnabled()) {
        handle.moveTopLeft(r.topLeft());
        painter->fillRect(handle, QColor(Qt::yellow));
        handle.moveTopRight(r.topRight());
        painter->fillRect(handle, QColor(Qt::yellow));
        handle.moveBottomLeft(r.bottomLeft());
        painter->fillRect(handle, QColor(Qt::yellow));
        handle.moveBottomRight(r.bottomRight());
        painter->fillRect(handle, QColor(Qt::yellow));
    }
    
    // Draw cross at center
    QPointF center = r.center();
    painter->drawLine(center + QPointF(-handle.width(), 0), center + QPointF(handle.width(), 0));
    painter->drawLine(center + QPointF(0, handle.height()), center + QPointF(0, -handle.height()));
}
Esempio n. 3
0
void QgsComposerScaleBar::setSceneRect( const QRectF& rectangle )
{
  QRectF box = mStyle->calculateBoxSize();
  if ( rectangle.height() > box.height() )
  {
    //keep user specified item height if higher than minimum scale bar height
    box.setHeight( rectangle.height() );
  }
  box.moveTopLeft( rectangle.topLeft() );

  //update rect for data defined size and position
  QRectF newRect = evalItemRect( rectangle );

  //scale bars have a minimum size, respect that regardless of data defined settings
  if ( newRect.width() < box.width() )
  {
    newRect.setWidth( box.width() );
  }
  if ( newRect.height() < box.height() )
  {
    newRect.setHeight( box.height() );
  }

  QgsComposerItem::setSceneRect( newRect );
}
Esempio n. 4
0
QRectF
FormCheckBox::rectangle() const
{
	QRectF r = boundingRect();
	r.moveTopLeft( position() );

	return r;
}
Esempio n. 5
0
QPointF SymbolDataEditor::fromStored(const QPointF &point) const
{
    QPointF result;
    QRectF symbolRect = scene->items(Qt::AscendingOrder).at(Item::SymbolItem)->boundingRect();
    symbolRect.moveTopLeft(scene->items(Qt::AscendingOrder).at(Item::SymbolItem)->pos());
    result.rx() = point.x() * symbolRect.width();
    result.ry() = point.y() * symbolRect.height();
    result += symbolRect.topLeft();
    return result;
}
Esempio n. 6
0
QPointF SymbolDataEditor::toStored(const QPointF &point) const
{
    QRectF symbolRect = scene->items(Qt::AscendingOrder).at(Item::SymbolItem)->boundingRect();
    symbolRect.moveTopLeft(scene->items(Qt::AscendingOrder).at(Item::SymbolItem)->pos());
    QPointF result = point - symbolRect.topLeft();
    result.rx() = point.x() / symbolRect.width();
    result.ry() = point.y() / symbolRect.height();
    result -= QPointF(2.0,2.0); //WARNING: I don't know why this works, but it depends on SvgView::scaleViewBox()
    return result;
}
void LabelItemDialog::saveDimensions(ViewItem *viewitem) {
  Q_ASSERT(viewitem);

  LabelItem *item = qobject_cast<LabelItem*>(viewitem);
  Q_ASSERT(item);

  QPointF xy(_labelDimensionsTab->x(),_labelDimensionsTab->y());
  qreal theta = _labelDimensionsTab->rotation();
  bool fix_left = _labelDimensionsTab->fixLeft();

  if (_labelDimensionsTab->lockPosToData() && item->dataPosLockable()) {
    QRectF dr = item->dataRelativeRect();
    if (fix_left) {
      dr.moveTopLeft(xy);
      item->setFixLeft(true);
    } else {
      dr.moveBottomRight(xy);
      item->setFixLeft(false);
    }
    item->setDataRelativeRect(dr);

    bool lockPosToData = _labelDimensionsTab->lockPosToDataDirty() ? _labelDimensionsTab->lockPosToData() : item->lockPosToData();
    item->setLockPosToData(lockPosToData);

    item->applyDataLockedDimensions();

  } else {
    QRectF parentRect = item->parentRect();
    qreal parentWidth = parentRect.width();
    qreal parentHeight = parentRect.height();
    qreal parentX = parentRect.x();
    qreal parentY = parentRect.y();
    bool lockPosToData = _labelDimensionsTab->lockPosToDataDirty() ? _labelDimensionsTab->lockPosToData() : item->lockPosToData();
    item->setLockPosToData(lockPosToData);
    qreal width = item->rect().width();
    qreal height = item->rect().height();

    item->setPos(parentX + xy.x()*parentWidth, parentY + xy.y()*parentHeight);
    if (fix_left) {
      item->setViewRect(0,-height, width, height);
      item->setFixLeft(true);
    } else {
      item->setViewRect(-width,-height, width, height);
      item->setFixLeft(false);
    }
  }
  QTransform transform;
  transform.rotate(theta);
  item->setTransform(transform);
  item->updateRelativeSize(true);

  if (_saveAsDefault->isChecked()) {
    _dialogDefaults->setValue(item->staticDefaultsGroupName()+"/fixLeft",_labelDimensionsTab->fixLeft());
  }
}
Esempio n. 8
0
void ItemBackground::setTargetItem(QGraphicsItem *target)
{
    if (d->target && d->target != target) {
        QObject *obj = 0;
        if (d->target->isWidget()) {
            obj = static_cast<QGraphicsWidget*>(d->target);
            obj->removeEventFilter(this);
        } else {
            d->target->removeSceneEventFilter(this);
            obj = dynamic_cast<QObject *>(d->target);
        }

        if (obj) {
            disconnect(obj, 0, this, 0);
        }
    }

    if (!target) {
        hide();
    }

    bool newTarget = (d->target != target);
    d->target = target;
    if (target) {
        setZValue(target->zValue() - 1);
        if (parentItem() != target->parentItem()) {
            QTransform t = transform();
            setTransform(QTransform());
            QRectF geom = mapToScene(geometry()).boundingRect();
            setGeometry(mapFromScene(geom).boundingRect());
            setTransform(t);
        }

        QRectF rect = target->boundingRect();
        rect.moveTopLeft(mapToParent(mapFromScene(target->mapToScene(QPointF(0, 0)))));

        setTarget(rect);


        if (newTarget) {
            QObject *obj = 0;
            if (target->isWidget()) {
                obj = static_cast<QGraphicsWidget*>(target);
                obj->installEventFilter(this);
            } else {
                d->target->installSceneEventFilter(this);
                obj = dynamic_cast<QObject *>(target);
            }

            if (obj) {
                connect(obj, SIGNAL(destroyed(QObject*)), this, SLOT(targetDestroyed(QObject*)));
            }
        }
    }
}
Esempio n. 9
0
void
FormComboBoxPrivate::setRect( const QRectF & rect )
{
	m_rect = rect;

	q->setPos( m_rect.topLeft() );

	m_proxy->setRect( m_rect );

	m_rect.moveTopLeft( QPointF( 0.0, 0.0 ) );
}
Esempio n. 10
0
void
FormCheckBox::setPosition( const QPointF & pos, bool pushUndoCommand )
{
	if( pushUndoCommand )
		form()->undoStack()->push( new UndoMove< FormCheckBox > ( form(),
			objectId(), pos - position() ) );

	QRectF r = boundingRect();
	r.moveTopLeft( pos );

	d->setRect( r );
}
Esempio n. 11
0
QRectF
FormResizableProxy::boundingRect() const
{
	if( !d.isNull() )
	{
		QRectF r = d->m_rect;
		r.moveTopLeft( QPointF( 0.0, 0.0 ) );

		return r.adjusted( -12.0, -12.0, 12.0, 12.0 );
	}
	else
		return QRectF();
}
Esempio n. 12
0
void PlotController::mouseMoveSignal(QMouseEvent *event) {
    if (dragging_legend) {
        QRectF rect = roi_plot->axisRect()->insetLayout()->insetRect(0);

        QPointF mousePoint((event->pos().x() - roi_plot->axisRect()->left()) /
                           (double) roi_plot->axisRect()->width(),
                           (event->pos().y() - roi_plot->axisRect()->top()) /
                           (double) roi_plot->axisRect()->height());
        rect.moveTopLeft(mousePoint - drag_legend_origin);
        roi_plot->axisRect()->insetLayout()->setInsetRect(0, rect);
        roi_plot->replot();
    }
}
Esempio n. 13
0
void
Context::Applet::drawRoundedRectAroundText( QPainter* p, QGraphicsSimpleTextItem* t )
{

   p->setRenderHint( QPainter::Antialiasing );
   QColor col = PaletteHandler::highlightColor().lighter( 150 );
   p->save();
   QRectF rect = t->boundingRect();
   rect.moveTopLeft( t->pos() );
   QPainterPath path;
   path.addRoundedRect( rect.adjusted( -5, -2, 5, 2 ), 3, 3 );

   p->fillPath( path, col );
   p->restore();
   // draw outline around textbox
   p->save();
   col = PaletteHandler::highlightColor( 0.3, .5 );
   p->setPen( col );
   rect = t->boundingRect();
   rect.moveTopLeft( t->pos() );
   p->drawRoundedRect( rect.adjusted( -5, -2, 5, 2 ), 3, 3 );
   p->restore(); 
}
void QQuickTextNodeEngine::addImage(const QRectF &rect, const QImage &image, qreal ascent,
                                    SelectionState selectionState,
                                    QTextFrameFormat::Position layoutPosition)
{
    QRectF searchRect = rect;
    if (layoutPosition == QTextFrameFormat::InFlow) {
        if (m_currentLineTree.isEmpty()) {
            searchRect.moveTopLeft(m_position + m_currentLine.position() + QPointF(0,1));
        } else {
            const BinaryTreeNode *lastNode = m_currentLineTree.data() + m_currentLineTree.size() - 1;
            if (lastNode->glyphRun.isRightToLeft()) {
                QPointF lastPos = lastNode->boundingRect.topLeft();
                searchRect.moveTopRight(lastPos - QPointF(0, ascent - lastNode->ascent));
            } else {
                QPointF lastPos = lastNode->boundingRect.topRight();
                searchRect.moveTopLeft(lastPos - QPointF(0, ascent - lastNode->ascent));
            }
        }
    }

    BinaryTreeNode::insert(&m_currentLineTree, searchRect, image, ascent, selectionState);
    m_hasContents = true;
}
void ContentWindowController::_constrainPosition( QRectF& window ) const
{
    const QRectF& group = _displayGroup->getCoordinates();

    const qreal minX = MIN_VISIBLE_AREA_PX - window.width();
    const qreal minY = MIN_VISIBLE_AREA_PX - window.height();

    const qreal maxX = group.width() - MIN_VISIBLE_AREA_PX;
    const qreal maxY = group.height() - MIN_VISIBLE_AREA_PX;

    const QPointF position( std::max( minX, std::min( window.x(), maxX )),
                            std::max( minY, std::min( window.y(), maxY )));

    window.moveTopLeft( position );
}
Esempio n. 16
0
void Layout2D::mouseMoveSignal(QMouseEvent *event) {
  // dragging legend
  if (draggingLegend) {
    QRectF rect = currentAxisRect_->insetLayout()->insetRect(0);
    // since insetRect is in axisRect coordinates (0..1), we transform the mouse
    // position:
    QPointF mousePoint((event->pos().x() - currentAxisRect_->left()) /
                           static_cast<double>(currentAxisRect_->width()),
                       (event->pos().y() - currentAxisRect_->top()) /
                           static_cast<double>(currentAxisRect_->height()));
    rect.moveTopLeft(mousePoint - dragLegendOrigin);
    currentAxisRect_->insetLayout()->setInsetRect(0, rect);
    plot2dCanvas_->replot();
  }
}
Esempio n. 17
0
void
FormCheckBoxPrivate::setRect( const QRectF & rect )
{
	const QRectF r = rect;

	m_rect = QRectF( 0.0, 0.0, r.height(), r.height() );

	m_width = r.width();

	q->setPos( r.topLeft() );

	QRectF hr = q->boundingRect();
	hr.moveTopLeft( r.topLeft() );

	m_handles->setRect( hr );
}
Esempio n. 18
0
QImage minigis::svgGenerator(QSvgRenderer &render, const QPointF &p, const qreal &ang, const QString &cls,
                             const qreal &svgSize, const quint8 &anchorX, const quint8 &anchorY, QPointF *start)
{
    QRectF rgn = svgRect(render, cls, p, svgSize);

    QPointF mid(rgn.left(), rgn.top());
    if (anchorX != 0 || anchorY != 0) {
        QPointF anchor(rgn.width() * anchorX * 0.01, rgn.height() * anchorY * 0.01);
        rgn.moveTopLeft(rgn.topLeft() - anchor);
        mid = QPointF(rgn.left() + anchor.x(), rgn.top() + anchor.y());
    }
    QTransform tr;
    tr.translate(mid.x(), mid.y()).rotate(ang).translate(-mid.x(), -mid.y());

    return svgGenerator(render, cls, rgn, tr, tr.inverted(), start);
}
QRectF k9CanvasSprite::boundingRect() const {

    QRectF r;
    if (m_pixmap){
        r=m_pixmap->boundingRect();
        r.moveTopLeft(m_pixmap->pos());
    }
    if (m_text) {
        QRectF r2=m_text->boundingRect();
        r2.moveTopLeft(m_text->pos());
        r=r.unite(r2);
    }
    r.adjust(-m_selsize,-m_selsize,m_selsize,m_selsize);

    return r;

}
Esempio n. 20
0
void SymbolDataEditor::setSymbolData(const QPointF _inPoint, const QPointF _outPoint, const QRectF _limits)
{
    if (scene->items().isEmpty())
        return;

    QRectF symbolRect = scene->items(Qt::AscendingOrder).at(Item::SymbolItem)->boundingRect();
    symbolRect.moveTopLeft(scene->items(Qt::AscendingOrder).at(Item::SymbolItem)->pos());
    symbolRect.adjust(symbolRect.width() / 4, symbolRect.height() / 4,
                      -symbolRect.width() / 4, -symbolRect.height() / 4);

    //try to set data automatically if they're not set
    if (_inPoint.isNull())
    {
        if (setupPoints)
            inPoint = getBeginPoint();
        else
        {
            inPoint = symbolRect.topLeft();
            inPoint.ry() += symbolRect.height() / 2;
        }
    }
    else
        inPoint = fromStored(_inPoint);

    if (_outPoint.isNull())
    {
        if (setupPoints)
            outPoint = getEndPoint();
        else
        {
            outPoint = symbolRect.topRight();
            outPoint.ry() += symbolRect.height() / 2;
        }
    }
    else
        outPoint = fromStored(_outPoint);

    if (_limits.isNull())
        limits = symbolRect;
    else
        limits = QRectF(fromStored(_limits.topLeft()),
                        fromStored(_limits.bottomRight()));

    correctLimits();
    addDataItems();
}
Esempio n. 21
0
void PrintTool::updateDragging(MapCoordF mouse_pos_map)
{
	QPointF delta = QPointF(mouse_pos_map - click_pos_map);
	QRectF area = map_printer->getPrintArea();
	switch (region)
	{
		case Inside:
			area.moveTopLeft(area.topLeft() + delta);
			break;
		case LeftBorder:
			area.setLeft(area.left() + delta.rx());
			break;
		case TopLeftCorner:
			area.setTopLeft(area.topLeft() + delta);
			break;
		case TopBorder:
			area.setTop(area.top() + delta.ry());
			break;
		case TopRightCorner:
			area.setTopRight(area.topRight() + delta);
			break;
		case RightBorder:
			area.setRight(area.right() + delta.rx());
			break;
		case BottomRightCorner:
			area.setBottomRight(area.bottomRight() + delta);
			break;
		case BottomBorder:
			area.setBottom(area.bottom() + delta.ry());
			break;
		case BottomLeftCorner:
			area.setBottomLeft(area.bottomLeft() + delta);
			break;
		case Outside:
			Q_ASSERT(false); // Handled outside.
		case Unknown:
			; // Nothing
	}
	
	if (area.left() < area.right() && area.top() < area.bottom())
	{
		map_printer->setPrintArea(area);
		click_pos_map = mouse_pos_map;
	}
}
Esempio n. 22
0
/*!
    \internal
    \overload
    Overloaded paint event to draw the QtSvgDialGauge components
*/
void QtSvgDialGauge::paintEvent(QPaintEvent * event)
{
    Q_UNUSED(event);
    QPainter painter(this);

    QRectF targetRect;

    qreal angleSpan = m_endAngle - m_startAngle;
    qreal valueSpan = m_maximum - m_minimum;
    qreal rotate = (m_value - m_minimum) / valueSpan * angleSpan + m_startAngle;

    // draw background
    targetRect = availableRect(m_backgroundRenderer);
    painter.translate((width() - targetRect.width()) / 2.0, (height() - targetRect.height()) / 2.0);
    painter.save();

    m_backgroundRenderer->render(&painter, targetRect);

    targetRect = availableRect(m_needleRenderer);
    targetRect.moveTopLeft(QPoint(-targetRect.width() * m_originX,
                                  -targetRect.height() * m_originY));

    // move origin to center of widget and rotate for the needle
    painter.translate(targetRect.width() * m_originX,
                      targetRect.height() * m_originY);

    // draw needle shadow with offset x=2, y=4
    painter.save();
    painter.translate(2, 4);
    painter.rotate(rotate);
    m_needleShadowRenderer->render(&painter, targetRect);

    // draw needle
    painter.restore();
    painter.rotate(rotate);
    m_needleRenderer->render(&painter, targetRect);

    painter.restore();
    if (m_showOverlay) {
        // draw overlay
        targetRect = availableRect(m_overlayRenderer);
        m_overlayRenderer->render(&painter, targetRect);
    }
}
Esempio n. 23
0
void Note::mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
	if (m_spaceBarWasPressed) {
		event->ignore();
		return;
	}

	if (m_inResize) {
		double minWidth = emptyMinWidth;
		double minHeight = emptyMinHeight;
		QSizeF gripSize = m_resizeGrip->boundingRect().size();
		QSizeF minSize = m_graphicsTextItem->document()->size() + gripSize + gripSize;
		if (minSize.height() > minHeight) minHeight = minSize.height();

		QRectF rect = boundingRect();
		rect.moveTopLeft(this->pos());

		double oldX1 = rect.x();
		double oldY1 = rect.y();
		double newX = event->scenePos().x() + m_inResize->resizeOffset().x();
		double newY = event->scenePos().y() + m_inResize->resizeOffset().y();
		QRectF newR;

		if (newX - oldX1 < minWidth) {
			newX = oldX1 + minWidth;
		}
		if (newY - oldY1 < minHeight) {
			newY = oldY1 + minHeight;
		}	
		newR.setRect(0, 0, newX - oldX1, newY - oldY1);

		prepareGeometryChange();
		m_rect = newR;
		positionGrip();
		event->accept();
		
		return;
	}

	ItemBase::mouseMoveEvent(event);
}
Esempio n. 24
0
void KWCanvasBase::clipToDocument(const KoShape *shape, QPointF &move) const
{
    Q_ASSERT(shape);
    const QPointF absPos = shape->absolutePosition();
    const QPointF destination = absPos + move;
    qreal bottomOfPage = 0.0;
    KWPage page;
    foreach (const KWPage &p, m_document->pageManager()->pages()) {
        bottomOfPage += p.height();
        if (bottomOfPage >= absPos.y())
            page = p;
        if (bottomOfPage >= destination.y()) {
            page = p;
            break;
        }
    }
    if (!page.isValid()) { // shape was not in any page to begin with, can't propose anything sane...
        move.setX(0);
        move.setY(0);
        return;
    }
    QRectF pageRect(page.rect().adjusted(5, 5, -5, -5));
    QPainterPath path(shape->absoluteTransformation(0).map(shape->outline()));
    QRectF shapeBounds = path.boundingRect();
    shapeBounds.moveTopLeft(shapeBounds.topLeft() + move);
    if (!shapeBounds.intersects(pageRect)) {
        if (shapeBounds.left() > pageRect.right()) // need to move to the left some
            move.setX(move.x() + (pageRect.right() - shapeBounds.left()));
        else if (shapeBounds.right() < pageRect.left()) // need to move to the right some
            move.setX(move.x() + pageRect.left() - shapeBounds.right());

        if (shapeBounds.top() > pageRect.bottom()) // need to move up some
            move.setY(move.y() + (pageRect.bottom() - shapeBounds.top()));
        else if (shapeBounds.bottom() < pageRect.top()) // need to move down some
            move.setY(move.y() + pageRect.top() - shapeBounds.bottom());
    }

    // Also make sure any anchoring restrictions are adhered to
    KWFrameLayout::proposeShapeMove(shape, move, page);
}
Esempio n. 25
0
void
FormCheckBox::resize( const QRectF & rect )
{
	setPos( rect.topLeft() );

	QSizeF s = d->m_rect.size().scaled( rect.width(), rect.height(),
		( d->m_handles->isKeepAspectRatio() ? Qt::KeepAspectRatio :
			Qt::IgnoreAspectRatio ) );

	d->m_rect = QRectF( 0.0, 0.0, s.width(), s.height() );

	d->m_width = rect.width();

	QRectF r = boundingRect();
	r.moveTopLeft( rect.topLeft() );

	d->m_handles->setRect( r );

	update();

	form()->update();
}
    foreach(QReportWidgetBase  *widget, _selectedWidgets) {
        QRectF widgetRect = _widgetRects[widget];
        QSizeF sizeby(
            rc.width()  / selectionRect.width(),
            rc.height() / selectionRect.height());

        widgetRect.moveTop(widgetRect.top()  - selectionRect.top());
        widgetRect.moveLeft(widgetRect.left() - selectionRect.left());

        widgetRect.setTop(widgetRect.top()     *sizeby.height());
        widgetRect.setBottom(widgetRect.bottom()  *sizeby.height());
        widgetRect.setLeft(widgetRect.left()    *sizeby.width());
        widgetRect.setRight(widgetRect.right()   *sizeby.width());

        widgetRect.moveTop(widgetRect.top()  + rc.top());
        widgetRect.moveLeft(widgetRect.left() + rc.left());

        widgetRect.moveTopLeft(widget->parentItem()->mapFromScene(widgetRect.topLeft()));

        widget->setPos(widgetRect.topLeft());
        widget->setSize(widgetRect.width(), widgetRect.height());

    }
Esempio n. 27
0
void ePageView::drawForeground(QPainter *painter, const QRectF &rect)
{
    QGraphicsView::drawForeground(painter, rect);

    if (!m_moving || !scene())
    {
        return;
    }

    for (eInt i=0; i<scene()->selectedItems().size(); i++)
    {
        const eGuiOperator *guiOp = (eGuiOperator *)scene()->selectedItems()[i];
        eASSERT(guiOp != eNULL);

        const QPoint newPos = m_mouseMoveDist;
        const eF32 x = (eF32)((newPos.x()/eGuiOperator::WIDTH+guiOp->getOperator()->getPosition().x)*eGuiOperator::WIDTH);
        const eF32 y = (eF32)((newPos.y()/eGuiOperator::HEIGHT+guiOp->getOperator()->getPosition().y)*eGuiOperator::HEIGHT);

        QRectF r = guiOp->boundingRect();
        r.moveTopLeft(QPointF(x, y));

        painter->drawRect(r);
    }
}
void TransformableGraphicsGuide::update()
{
	if (isVisible())
	{
		FigureEditor::EditMode mode = editor->mode();

		bool scaleMode( mode == FigureEditor::Scale );
		topRightRect.setVisible(scaleMode);
		topLeftRect.setVisible(scaleMode);
		bottomRightRect.setVisible(scaleMode);
		bottomLeftRect.setVisible(scaleMode);

		if (scaleMode)
		{
			QPointF cen;
			QPolygonF poly;

			if (editor->hasSelection())
			{
				QGraphicsPolygonItem* item = editor->selection();
				if (item == 0)
					return;
				cen  = mapFromScene(editor->selectionTransformPos());
				poly = mapFromScene(item->polygon());
			}
			else
			{
				QGraphicsPolygonItem* item = dynamic_cast<QGraphicsPolygonItem*>(parentItem());
				cen  = editor->triangleTransformPos();
				poly = item->polygon();
			}
			QRectF f( poly.boundingRect() );
			qreal xmax = qMax(qAbs(f.left() - cen.x()), qAbs(f.right()  - cen.x()));
			qreal ymax = qMax(qAbs(f.top()  - cen.y()), qAbs(f.bottom() - cen.y()));
			QPointF pmax(xmax, ymax);
			QRectF r(pmax, -pmax);

			r.moveCenter(cen);
			outerRect = r;
			QRectF l = parentItem()->mapRectFromScene(QRectF(QPointF(0.0, 0.0), QSizeF(10, 10)));
			QPen pen( editor->guideColor() );

			l.moveBottomLeft(r.topRight());
			topRightRect.setPen(pen);
			topRightRect.setRect(l);

			l.moveBottomRight(r.topLeft());
			topLeftRect.setPen(pen);
			topLeftRect.setRect(l);

			l.moveTopLeft(r.bottomRight());
			bottomRightRect.setPen(pen);
			bottomRightRect.setRect(l);

			l.moveTopRight(r.bottomLeft());
			bottomLeftRect.setPen(pen);
			bottomLeftRect.setRect(l);
		}
		else if (mode == FigureEditor::Rotate)
		{
			QGraphicsPolygonItem* item;
			QPointF cen;
			QPolygonF poly;
			if (editor->hasSelection())
			{
				item = editor->selection();
				if (item == 0)
					return;
				cen  = mapFromScene(editor->selectionTransformPos());
				poly = mapFromScene(item->polygon());
			}
			else
			{
				item = dynamic_cast<QGraphicsPolygonItem*>(parentItem());
				poly = item->polygon();
				cen = editor->triangleTransformPos();
			}
			qreal rmax = 0.0;
			foreach (QPointF p, poly)
			{
				QLineF l(p, cen);
				qreal len(l.length());
				if (len > rmax)
					rmax = len;
			}
			qreal height = rmax * 2.0;
			outerRect = QRectF(cen.x() - rmax, cen.y() - rmax, height, height);
		}
Esempio n. 29
0
QList<KWViewMode::ViewMap> KWViewModeNormal::mapExposedRects(const QRectF &viewRect, KoViewConverter *viewConverter) const
{
    QList<ViewMap> answer;
    if (!viewConverter) return answer;

#if 1
    if (m_pageTops.isEmpty())
        return answer;
    KWPage page  = m_pageManager->begin();
    const int pageOffset = page.pageNumber();

    // Perform a binary search for page-index using our m_pageTops cache.
    int begin = 0;
    int end = m_pageTops.count() - 1;
    int index = 0;
    const qreal value = viewConverter->viewToDocument(viewRect.topLeft()).y();
    if (m_pageTops.value(end) <= value) { // check extremes. Only end is needed since begin is zero.
        begin = end;
        index = end;
    }
    while (end - begin > 1) {
        index = begin + (end - begin) / 2;
        qreal diff = m_pageTops.value(index) - value;
        if (diff < 0)
            begin = index;
        else if (diff > 0)
            end = index;
        else
            break;
    }
    // index is now the number of the first possible page that can
    // contain the viewRect.  The next step is to find the
    // corresponding Page.  Since we have no way to get to the Nth
    // page directly we have to enumerate them from the beginning.
    //
    // We use 1 since we might hit a pagespread in the binary search,
    // so start one page early.
    while (index > 1) { 
        page = page.next();
        --index;
    }

    // From here we loop through some more pages after the found one
    // and see if they intersect with the page in question.  When we
    // have two pages in row that don't intersect we break the loop.
    qreal offsetX = 0.0;
    int emptyPages = 0;
    for(; page.isValid(); page = page.next()) {
        Q_ASSERT_X(page.pageNumber()-pageOffset < m_pageTops.count(), __FUNCTION__,
                   QString("Pagemanager has more pages than viewmode (%1>%2 with pageOffset=%3 and pageNumber=%4 and pageCount=%5). Make sure you add pages via the document!")
                   .arg(page.pageNumber()-pageOffset).arg(m_pageTops.count())
                   .arg(pageOffset).arg(page.pageNumber()).arg(m_pageManager->pageCount()).toLocal8Bit());


        // Some invariants
        const QRectF pageRect = page.rect();
        const qreal offsetY = m_pageTops[page.pageNumber() - pageOffset] - pageRect.top();

        bool pageIntersects = false;

        // 1. First handle the page itself.
        const QRectF zoomedPage = viewConverter->documentToView(pageRect);
        ViewMap vm;
        vm.page = page;
        //kDebug(32003) <<"page" << page.pageNumber();
        vm.distance = viewConverter->documentToView(QPointF(offsetX, offsetY));

        const QRectF targetPage(zoomedPage.x() + vm.distance.x(), zoomedPage.y() + vm.distance.y(),
                                zoomedPage.width(), zoomedPage.height());
        QRectF intersection = targetPage.intersect(viewRect);
        if (! intersection.isEmpty()) {
            intersection.moveTopLeft(intersection.topLeft() - vm.distance);
            vm.clipRect = intersection.toRect();
            answer.append(vm);
            pageIntersects = true;
        }

        // 2. Then handle the annotation area if annotations are active.
        //
        //    The reason we don't do them together with the page
        //    itself is because the pages have a gap between them, but
        //    the annotation area should be unbroken.
        //
        // NOTE: 'annotation' below means the annotation area.
        //
        // FIXME: We should only do this if the annotation area is
        //        actually shown. How can we inside the KWViewMode
        //        know if annotations are active?
        if (1 /* annotations are shown */) {
            const QRectF annotationRect = pageRect.adjusted(page.width(), 0,
                                                            KWCanvasBase::AnnotationAreaWidth, GAP);
            const QRectF zoomedAnnotation = viewConverter->documentToView(annotationRect);
            ViewMap vm2;
            vm2.page = page;
            vm2.distance = viewConverter->documentToView(QPointF(offsetX, offsetY));

            const QRectF targetAnnotation(zoomedAnnotation.x() + vm2.distance.x(),
                                          zoomedAnnotation.y() + vm2.distance.y(),
                                          zoomedAnnotation.width(), zoomedAnnotation.height());
            intersection = targetAnnotation.intersect(viewRect);
            if (! intersection.isEmpty()) {
                intersection.moveTopLeft(intersection.topLeft() - vm2.distance);
                vm2.clipRect = intersection.toRect();
                answer.append(vm2);
                pageIntersects = true;
            }
        }

        // Record whether this page had an intersection with the view rect.
        if (pageIntersects) {
            emptyPages = 0;
        } else {
            ++emptyPages;
        }
        if (emptyPages > 2) // Since we show at max 2 pages side by side this is an easy rule
            break;

        if (m_pageSpreadMode) {
            if (page.pageSide() == KWPage::Left)
                offsetX = page.width() + GAP;
            else
                offsetX = 0.0;
        }
    }
#else
    KWPage page  = m_pageManager->begin();
    Q_ASSERT(page.isValid());
    qreal offsetX = 0.0;
    const int pageOffset = page.pageNumber();
    for(; page.isValid(); page = page.next()) {
        const QRectF pageRect = page.rect();
        const QRectF zoomedPage = viewConverter->documentToView(pageRect);
        ViewMap vm;
        vm.page = page;

        const qreal offsetY = m_pageTops[page.pageNumber() - pageOffset] - pageRect.top();
        vm.distance = viewConverter->documentToView(QPointF(offsetX, offsetY));
#if 0
        const QRectF targetPage(zoomedPage.x() + vm.distance.x(), zoomedPage.y() + vm.distance.y(), zoomedPage.width() , zoomedPage.height());
        QRectF intersection = targetPage.intersect(viewRect);
        if (! intersection.isEmpty()) {
            intersection.moveTopLeft(intersection.topLeft() - vm.distance);
            vm.clipRect = intersection.toRect();
            answer.append(vm);
        }
#else
        const QRectF targetPage(zoomedPage.x() + vm.distance.x(), zoomedPage.y() + vm.distance.y(), zoomedPage.width() , zoomedPage.height());
        vm.clipRect = targetPage.toRect();
        answer.append(vm);
#endif
    }
#endif
    return answer;
}
Esempio n. 30
0
QList<KWViewMode::ViewMap> KWViewModeNormal::mapExposedRects(const QRectF &viewRect, KoViewConverter *viewConverter) const
{
    QList<ViewMap> answer;
    if (!viewConverter) return answer;

#if 1
    if (m_pageTops.isEmpty())
        return answer;
    KWPage page  = m_pageManager->begin();
    qreal offsetX = 0.0;
    const int pageOffset = page.pageNumber();

    int begin = 0;
    int end = m_pageTops.count() - 1;
    int index = 0;
    const qreal value = viewConverter->viewToDocument(viewRect.topLeft()).y();
    if (m_pageTops.value(end) <= value) { // check extremes. Only end is needed since begin is zero.
        begin = end;
        index = end;
    }
    while (end - begin > 1) { // binary search for page-index using our m_pageTops cache.
        index = begin + (end - begin) / 2;
        qreal diff = m_pageTops.value(index) - value;
        if (diff < 0)
            begin = index;
        else if (diff > 0)
            end = index;
        else
            break;
    }
    while (index > 1) { // 1 since we might hit a pagespread in the binary search, so start one page early
        page = page.next();
        --index;
    }

    int emptyPages = 0;
    for(; page.isValid(); page = page.next()) {
        Q_ASSERT_X(page.pageNumber()-pageOffset < m_pageTops.count(), __FUNCTION__,
                   QString("Pagemanager has more pages than viewmode (%1>%2 with pageOffset=%3 and pageNumber=%4 and pageCount=%5). Make sure you add pages via the document!")
                   .arg(page.pageNumber()-pageOffset).arg(m_pageTops.count()).arg(pageOffset).arg(page.pageNumber()).arg(m_pageManager->pageCount()).toLocal8Bit());

        const QRectF pageRect = page.rect();
        const QRectF zoomedPage = viewConverter->documentToView(pageRect);
        ViewMap vm;
        vm.page = page;
        //kDebug(32003) <<"page" << page.pageNumber();
        const qreal offsetY = m_pageTops[page.pageNumber() - pageOffset] - pageRect.top();
        vm.distance = viewConverter->documentToView(QPointF(offsetX, offsetY));

        const QRectF targetPage(zoomedPage.x() + vm.distance.x(), zoomedPage.y() + vm.distance.y(),
                zoomedPage.width() , zoomedPage.height());
        QRectF intersection = targetPage.intersect(viewRect);
        if (! intersection.isEmpty()) {
            intersection.moveTopLeft(intersection.topLeft() - vm.distance);
            vm.clipRect = intersection.toRect();
            answer.append(vm);
            emptyPages = 0;
        } else {
            emptyPages++;
        }
        if (emptyPages > 2) // Since we show at max 2 pages side by side this is an easy rule
            break;
        if (m_pageSpreadMode) {
            if (page.pageSide() == KWPage::Left)
                offsetX = page.width() + GAP;
            else
                offsetX = 0.0;
        }
    }
#else
    KWPage page  = m_pageManager->begin();
    Q_ASSERT(page.isValid());
    qreal offsetX = 0.0;
    const int pageOffset = page.pageNumber();
    for(; page.isValid(); page = page.next()) {
        const QRectF pageRect = page.rect();
        const QRectF zoomedPage = viewConverter->documentToView(pageRect);
        ViewMap vm;
        vm.page = page;

        const qreal offsetY = m_pageTops[page.pageNumber() - pageOffset] - pageRect.top();
        vm.distance = viewConverter->documentToView(QPointF(offsetX, offsetY));
#if 0
        const QRectF targetPage(zoomedPage.x() + vm.distance.x(), zoomedPage.y() + vm.distance.y(), zoomedPage.width() , zoomedPage.height());
        QRectF intersection = targetPage.intersect(viewRect);
        if (! intersection.isEmpty()) {
            intersection.moveTopLeft(intersection.topLeft() - vm.distance);
            vm.clipRect = intersection.toRect();
            answer.append(vm);
        }
#else
        const QRectF targetPage(zoomedPage.x() + vm.distance.x(), zoomedPage.y() + vm.distance.y(), zoomedPage.width() , zoomedPage.height());
        vm.clipRect = targetPage.toRect();
        answer.append(vm);
#endif
    }
#endif
    return answer;
}