/* Function to check if the event positon was in 'close' section of the label. @detail This fuction checks the event position against the detection area for the close part of the label. @param QPointF position is the event position @return bool indicates if the event was in a relevant position */ bool GraphicsScene::InCloseRegion(QPointF& position) { if( (position.rx() >= selected_point->getCenter().rx()+LABEL_WIDTH/2-2*METRICS.width("X") && position.rx() <= selected_point->getCenter().rx()+LABEL_WIDTH/2) && (position.ry() >= selected_point->getCenter().ry()-LABEL_HEIGHT-LABEL_HEIGHT_MARGIN && position.ry() <= selected_point->getCenter().ry()-LABEL_HEIGHT_MARGIN)) return true; return false; }
ParkingLots::ParkingLots(const qreal &leftCorner, const qreal &bottomCorner) { QPointF tempPoint; QPointF leftBottomCorner(leftCorner, bottomCorner); OccupancyCell emptyCell; QPointF leftBottomUtm(871831, 6077369); qDebug() << "num of rows"<<_numOfRows; qDebug() << "num of cols"<<_numOfCols; for (int colNum = 0; colNum < _numOfCols; ++colNum) { for (int rowNum = 0; rowNum < _numOfRows; ++rowNum) { tempPoint.ry() = leftBottomCorner.y() * _metersInPx + leftBottomUtm.y() + rowNum * _height * _metersInPx + (_height / 2) * _metersInPx; tempPoint.rx() = leftBottomCorner.x() * _metersInPx + leftBottomUtm.x() + colNum * _width * _metersInPx + (_width / 2) * _metersInPx; // the rows are as follows: // 01___23___45___67___ ... // so we need to account for the gap tempPoint.rx() = tempPoint.x() + (colNum / _gap_every) * (_gap) * _metersInPx; _centers.append(tempPoint); _occupancy.append(emptyCell); _currentOccupancy.append(emptyCell); } } }
void HueSaturationDisc::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { QPen pen(Qt::black, 2, Qt::SolidLine); pen.setCosmetic ( true ); QBrush brush( Qt::SolidPattern ); brush.setColor(QColor::fromHsv( m_currentColor.hue(), m_currentColor.saturation(), 255)); painter->setBrush(brush); painter->setPen(pen); // compute position from current color int hue, sat, val; m_currentColor.getHsv(&hue, &sat, &val); // hue point { float r = (sat/255.0f)*m_radius; float angle = (1.0f - hue/359.0f)*2.0f*MATH_PIf; QPointF p = getPoint( angle, r ); float t = p.x(); p.rx() = -p.y(); p.ry() = t; float width = 5.0f; painter->drawEllipse( p, width, width ); } }
//计算t时,输出点的位置:有Bug //当控制点的横坐标位于两个端点之外时,出现bug == 找到,由于插入控制点的错误造成 QPointF QBezier::cal(float t) { QPointF result; QPointF pStart,pEnd; knowPoints.insert(knowPoints.begin(),startPoint); knowPoints.append(endPoint); if(knowPoints.count() <= 1){ return QPointF(0.0,0.0); } pStart.rx() = (1-t)*knowPoints.first().x() + t*knowPoints.at(1).x(); pStart.ry() = (1-t)*knowPoints.first().y() + t*knowPoints.at(1).y(); int cnt = knowPoints.count(); for(int i = 1; i < cnt - 1; i++) { pEnd.rx() = (1-t)*knowPoints.at(i).x() + t*knowPoints.at(i+1).x(); pEnd.ry() = (1-t)*knowPoints.at(i).y() + t*knowPoints.at(i+1).y(); result.rx() = (1-t)*pStart.x() + t*pEnd.x(); result.ry() = (1-t)*pStart.y() + t*pEnd.y(); pStart = result; } knowPoints.removeFirst(); knowPoints.removeLast(); return result; }
void QtViewportInteractionEngine::wheelEvent(QWheelEvent* ev) { if (scrollAnimationActive() || scaleAnimationActive() || pinchGestureActive()) return; // Ignore. int delta = ev->delta(); // A delta that is not mod 120 indicates a device that is sending // fine-resolution scroll events, so use the delta as number of wheel ticks // and number of pixels to scroll. See also webkit.org/b/29601 bool fullTick = !(delta % 120); static const int cDefaultQtScrollStep = 20; static const int wheelScrollLines = 3; int scrollLines = (fullTick) ? wheelScrollLines * cDefaultQtScrollStep : 1; delta = (fullTick) ? delta / 120.0f : delta; delta *= scrollLines; QPointF newPosition = m_viewport->contentPos(); if (ev->orientation() == Qt::Horizontal) newPosition.rx() += delta; else newPosition.ry() += delta; QRectF endPosRange = computePosRangeForItemAtScale(m_content->contentsScale()); QPointF currentPosition = m_viewport->contentPos(); newPosition = boundPosition(endPosRange.topLeft(), newPosition, endPosRange.bottomRight()); m_viewport->setContentPos(newPosition); emit contentViewportChanged(currentPosition - newPosition); }
/********************************************************************** * Function: get handle point * Parameters: handle id, bound rect * Return: none **********************************************************************/ QPointF QArcItem::getHandle(int iHandle, QRectF &qrcBondingRect) const { QPointF qpPoint; if (iHandle > 8) { QList<QPolygonF> polygonfs = m_ArcPath.toSubpathPolygons(); int iSize = polygonfs.size(); if (iSize <= 0 || iSize > 1) { return qpPoint; } QPolygonF polygonf = polygonfs.at(0); int j = polygonf.size(); if (j <= 1) { return qpPoint;; } /*Get the key points*/ QPointF qpDimCenter; qpDimCenter = polygonf.at(0); switch (iHandle) { case 9: qpPoint = polygonf.at(1); qpPoint.rx() = (qpPoint.x() + qpDimCenter.x()) / 2; qpPoint.ry() = (qpPoint.y() + qpDimCenter.y()) / 2; break; case 10: qpPoint = polygonf.at(j - 1); qpPoint.rx() = (qpPoint.x() + qpDimCenter.x()) / 2; qpPoint.ry() = (qpPoint.y() + qpDimCenter.y()) / 2; break; default: break; } qpPoint = this->mapToScene(qpPoint); qpPoint.rx() = qpPoint.x(); return qpPoint; } else { return SamDrawItemBase::getHandle(iHandle, qrcBondingRect); } }
void ShapeResizeStrategy::handleMouseMove(const QPointF &point, Qt::KeyboardModifiers modifiers) { tool()->canvas()->updateCanvas(tool()->canvas()->snapGuide()->boundingRect()); QPointF newPos = tool()->canvas()->snapGuide()->snap( point, modifiers ); tool()->canvas()->updateCanvas(tool()->canvas()->snapGuide()->boundingRect()); bool keepAspect = modifiers & Qt::ShiftModifier; foreach(KoShape *shape, m_selectedShapes) keepAspect = keepAspect || shape->keepAspectRatio(); qreal startWidth = m_initialSize.width(); if (startWidth < std::numeric_limits<qreal>::epsilon()) startWidth = std::numeric_limits<qreal>::epsilon(); qreal startHeight = m_initialSize.height(); if (startHeight < std::numeric_limits<qreal>::epsilon()) startHeight = std::numeric_limits<qreal>::epsilon(); QPointF distance = m_unwindMatrix.map(newPos) - m_unwindMatrix.map( m_start ); // guard against resizing zero width shapes, which would result in huge zoom factors if (m_initialSize.width() < std::numeric_limits<qreal>::epsilon()) { distance.rx() = 0.0; } // guard against resizing zero height shapes, which would result in huge zoom factors if (m_initialSize.height() < std::numeric_limits<qreal>::epsilon()) { distance.ry() = 0.0; } const bool scaleFromCenter = modifiers & Qt::ControlModifier; if (scaleFromCenter) { distance *= 2.0; } qreal zoomX=1, zoomY=1; if (m_left) zoomX = (startWidth - distance.x()) / startWidth; else if (m_right) zoomX = (startWidth + distance.x()) / startWidth; if (m_top) zoomY = (startHeight - distance.y()) / startHeight; else if (m_bottom) zoomY = (startHeight + distance.y()) / startHeight; if (keepAspect) { const bool cornerUsed = ((m_bottom?1:0) + (m_top?1:0) + (m_left?1:0) + (m_right?1:0)) == 2; if ((cornerUsed && startWidth < startHeight) || m_left || m_right) zoomY = zoomX; else zoomX = zoomY; } QPointF move; if (scaleFromCenter) move = QPointF(startWidth / 2.0, startHeight / 2.0); else move = QPointF(m_left?startWidth:0, m_top?startHeight:0); resizeBy( move, zoomX, zoomY ); }
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; } }
void PreviewWidget::drawShadow(QPainter &painter, QRectF rect) { // Shadow width int width = qBound(4, int(qMax(rect.height(), rect.width())) / 100, 7); painter.save(); painter.setClipRect(rect.adjusted(0, 0, width, width)); QColor lightColor = this->palette().color(QPalette::Background); QColor darkColor = lightColor.darker(160); QRectF shadowRect = rect.adjusted(0, 0, width, width); QLinearGradient lg; lg.setColorAt(0.0, darkColor); lg.setColorAt(1.0, lightColor); QRadialGradient rg; rg.setColorAt(0, darkColor); rg.setColorAt(1, lightColor); rg.setRadius(width); // Right lg.setStart(QPointF(rect.right(), rect.center().y())); lg.setFinalStop(QPointF(shadowRect.right(), rect.center().y())); painter.fillRect(rect.right(), rect.top() + width, width, rect.height() - width, lg); // Bottom lg.setStart(rect.center().x(), rect.bottom()); lg.setFinalStop(rect.center().x(), rect.bottom() + width); painter.fillRect(rect.left() + width, rect.bottom(), rect.width() - width, width, lg); //TopRight QPointF p; p = rect.bottomRight(); rg.setCenter(p); rg.setFocalPoint(p); painter.fillRect(rect.right(), rect.bottom(), width, width, rg); // BottomRight p = rect.topRight(); p.ry() += width; rg.setCenter(p); rg.setFocalPoint(p); painter.fillRect(rect.right(), rect.top(), width, width, rg); //BottomLeft p = rect.bottomLeft(); p.rx() += width; rg.setCenter(p); rg.setFocalPoint(p); painter.fillRect(rect.left(), rect.bottom(), width, width, rg); painter.restore(); }
void Cocos2dxView::mouseMoveInChoiceEdit(QMouseEvent *event) { QPointF pos = event->localPos(); //组装windows消息 UINT message = WM_MOUSEMOVE; WPARAM wparam = MK_LBUTTON; LPARAM lparam = MAKELPARAM(pos.rx(), pos.ry()); CCEGLView::sharedOpenGLView()->WindowProc(message, wparam, lparam); }
/* * Translates the items in the main * layer by (x, y). Note: the input * parameters are in the main layers * coordinate system. */ void View::Translate(qreal x, qreal y) { QPointF pos = m_pMainLayer->pos(); pos.rx() += (x * m_pMainLayer->scale()); pos.ry() += (y * m_pMainLayer->scale()); m_pMainLayer->setPos(pos); }
void KoPathShapeLoaderPrivate::svgLineToVertical(qreal y, bool abs) { if (abs) lastPoint.setY(y); else lastPoint.ry() += y; path->lineTo(lastPoint); }
QPointF ViewerNode::getWipeCenter() const { KnobDoublePtr wipeCenter = _imp->wipeCenter.lock(); QPointF r; r.rx() = wipeCenter->getValue(); r.ry() = wipeCenter->getValue(DimIdx(1)); return r; }
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; }
/*********************************************************************** *Funtion : Hit test for the object *Return : integer handle id. *Parameter: QPoint local mouse point, scene bonding rect, bool selected flag. **********************************************************************/ int SamDrawItemBase::hitTest(QPointF qpPoint, QRectF &qrcBondingRect, bool bSelected) { if (this->getResizable() == false) { return 0; } /*Object is selected*/ if (bSelected) { /*Check the handle, if the mouse point in it's area*/ int iHandleCount = getHandleCount(); for (int iHandle = 1; iHandle <= iHandleCount; iHandle++) { // GetHandleRect returns in logical coords QRectF qrcRect = getHandleRect(iHandle, qrcBondingRect); if ( (qpPoint.rx() >= qrcRect.left()) && (qpPoint.rx() <= qrcRect.right()) && (qpPoint.ry() >= qrcRect.top()) && (qpPoint.ry() <= qrcRect.bottom()) ) { return iHandle; } } } /*Object is not selected*/ else { /*if ( qpPoint.rx() >= this->sceneBoundingRect().left() && qpPoint.rx() < this->sceneBoundingRect().right() && qpPoint.ry() <= this->sceneBoundingRect().top() && qpPoint.ry() > this->sceneBoundingRect().bottom() )*/ if ( qpPoint.rx() >= qrcBondingRect.left() && qpPoint.rx() < qrcBondingRect.right() && qpPoint.ry() <= qrcBondingRect.top() && qpPoint.ry() > qrcBondingRect.bottom() ) { return 1; } } return 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; }
QRectF KItemListViewLayouter::groupHeaderRect(int index) const { const_cast<KItemListViewLayouter*>(this)->doLayout(); const QRectF firstItemRect = itemRect(index); QPointF pos = firstItemRect.topLeft(); if (pos.isNull()) { return QRectF(); } QSizeF size; if (m_scrollOrientation == Qt::Vertical) { pos.rx() = 0; pos.ry() -= m_groupHeaderHeight; size = QSizeF(m_size.width(), m_groupHeaderHeight); } else { pos.rx() -= m_itemMargin.width(); pos.ry() = 0; // Determine the maximum width used in the // current column. As the scroll-direction is // Qt::Horizontal and m_itemRects is accessed directly, // the logical height represents the visual width. qreal width = minimumGroupHeaderWidth(); const qreal y = m_itemInfos[index].rect.y(); const int maxIndex = m_itemInfos.count() - 1; while (index <= maxIndex) { QRectF bounds = m_itemInfos[index].rect; if (bounds.y() != y) { break; } if (bounds.height() > width) { width = bounds.height(); } ++index; } size = QSizeF(width, m_size.height()); } return QRectF(pos, size); }
QRectF TrajectoryFinder::getForcedRect(const QPointF& p, double radius) const { Q_ASSERT(radius > 0); QPointF br = p; br.rx() -= radius; br.ry() -= radius; return QRectF(br, QSizeF(radius*2, radius*2)); }
// -------------------------------------------------------------------------------------------------------------------------------------- QRectF getCircle(const qreal & lengthC, const qreal & angleC, const qreal & radius) { QPointF center = polarToDecard(lengthC, angleC); return QRectF ( center.rx() - radius, center.ry() - radius, radius*2, radius*2 ); }
const unsigned char* QgsSymbolV2::_getLineString( QPolygonF& pts, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent ) { QgsConstWkbPtr wkbPtr( wkb + 1 ); unsigned int wkbType, nPoints; wkbPtr >> wkbType >> nPoints; bool hasZValue = QgsWKBTypes::hasZ( static_cast< QgsWKBTypes::Type >( wkbType ) ); bool hasMValue = QgsWKBTypes::hasM( static_cast< QgsWKBTypes::Type >( wkbType ) ); double x = 0.0; double y = 0.0; const QgsCoordinateTransform* ct = context.coordinateTransform(); const QgsMapToPixel& mtp = context.mapToPixel(); //apply clipping for large lines to achieve a better rendering performance if ( clipToExtent && nPoints > 1 ) { const QgsRectangle& e = context.extent(); double cw = e.width() / 10; double ch = e.height() / 10; QgsRectangle clipRect( e.xMinimum() - cw, e.yMinimum() - ch, e.xMaximum() + cw, e.yMaximum() + ch ); wkbPtr = QgsConstWkbPtr( QgsClipper::clippedLineWKB( wkb, clipRect, pts ) ); } else { pts.resize( nPoints ); QPointF* ptr = pts.data(); for ( unsigned int i = 0; i < nPoints; ++i, ++ptr ) { wkbPtr >> x >> y; if ( hasZValue ) wkbPtr += sizeof( double ); if ( hasMValue ) wkbPtr += sizeof( double ); *ptr = QPointF( x, y ); } } //transform the QPolygonF to screen coordinates if ( ct ) { ct->transformPolygon( pts ); } QPointF* ptr = pts.data(); for ( int i = 0; i < pts.size(); ++i, ++ptr ) { mtp.transformInPlace( ptr->rx(), ptr->ry() ); } return wkbPtr; }
void OverviewDockWidget::circleItem(QString shortname) { for(int i = 0;i<gitems.size();i++){ if(gitems[i]->toolTip()==shortname){ QPointF p = oriabspos[i]; this->hoverCircle->setPos(p.rx()-6,p.ry()-6); this->hoverCircle->setVisible(true); break; } } }
void ChordLine::read(XmlReader& e) { path = QPainterPath(); while (e.readNextStartElement()) { const QStringRef& tag(e.name()); if (tag == "Path") { path = QPainterPath(); QPointF curveTo; QPointF p1; int state = 0; while (e.readNextStartElement()) { const QStringRef& tag(e.name()); if (tag == "Element") { int type = e.intAttribute("type"); qreal x = e.doubleAttribute("x"); qreal y = e.doubleAttribute("y"); switch(QPainterPath::ElementType(type)) { case QPainterPath::MoveToElement: path.moveTo(x, y); break; case QPainterPath::LineToElement: path.lineTo(x, y); break; case QPainterPath::CurveToElement: curveTo.rx() = x; curveTo.ry() = y; state = 1; break; case QPainterPath::CurveToDataElement: if (state == 1) { p1.rx() = x; p1.ry() = y; state = 2; } else if (state == 2) { path.cubicTo(curveTo, p1, QPointF(x, y)); state = 0; } break; } e.skipCurrentElement(); //needed to go to next Element in Path } else e.unknown(); } modified = true; } else if (tag == "subtype") setChordLineType(ChordLineType(e.readInt())); else if (!Element::readProperties(e)) e.unknown(); } }
void ChordLine::read(const QDomElement& de) { path = QPainterPath(); for (QDomElement e = de.firstChildElement(); !e.isNull(); e = e.nextSiblingElement()) { QString tag(e.tagName()); if (tag == "Path") { path = QPainterPath(); QPointF curveTo; QPointF p1; int state = 0; for (QDomElement ee = e.firstChildElement(); !ee.isNull(); ee = ee.nextSiblingElement()) { QString tag(ee.tagName()); if (tag == "Element") { int type = ee.attribute("type").toInt(); qreal x = ee.attribute("x").toDouble(); qreal y = ee.attribute("y").toDouble(); switch(QPainterPath::ElementType(type)) { case QPainterPath::MoveToElement: path.moveTo(x, y); break; case QPainterPath::LineToElement: path.lineTo(x, y); break; case QPainterPath::CurveToElement: curveTo.rx() = x; curveTo.ry() = y; state = 1; break; case QPainterPath::CurveToDataElement: if (state == 1) { p1.rx() = x; p1.ry() = y; state = 2; } else if (state == 2) { path.cubicTo(curveTo, p1, QPointF(x, y)); state = 0; } break; } } else domError(ee); } modified = true; setSubtype(ChordLineType(0)); } else if (tag == "subtype") setSubtype(ChordLineType(e.text().toInt())); else if (!Element::readProperties(e)) domError(e); } }
/*********************************************************************** *Funtion : Get the handle rect *Return : QRectF handle rect. *Parameter: handle id. **********************************************************************/ QRectF SamDrawItemBase::getHandleRect(int iHandleID, QRectF &qrcBondingRect) { QRectF qrRect; // get the center of the handle in logical coords QPointF qpPoint = getHandle(iHandleID, qrcBondingRect); /*Set the rect and normalize it*/ qrRect.setRect(qpPoint.rx()-SAMDRAW_TRACKER_POS_OFT, qpPoint.ry()-SAMDRAW_TRACKER_POS_OFT, SAMDRAW_TRACKER_SIZE, SAMDRAW_TRACKER_SIZE); qrRect = qrRect.normalized(); return qrRect; }
void QArcItem::refreshArc() { QPointF qpMid; qpMid.rx() = (m_qrcEllipseBndRect.topLeft().x() + m_qrcEllipseBndRect.bottomRight().x()) / 2; qpMid.ry() = (m_qrcEllipseBndRect.topLeft().y() + m_qrcEllipseBndRect.bottomRight().y()) / 2; QPainterPath path; path.moveTo(qpMid); path.arcTo(m_qrcEllipseBndRect, m_dStartAngle, m_dSpanAngle); path.lineTo(qpMid); m_ArcPath = path; setPath(m_ArcPath); SetPattern(nPatternType); }
void ChordLine::read(XmlReader*) { #if 0 path = QPainterPath(); while (r->readElement()) { if (r->tag() == "Path") { path = QPainterPath(); QPointF curveTo; QPointF p1; int state; while (r->readElement()) { QString tag(ee.tagName()); if (tag == "Element") { int type = ee.attribute("type").toInt(); qreal x = ee.attribute("x").toDouble(); qreal y = ee.attribute("y").toDouble(); switch(QPainterPath::ElementType(type)) { case QPainterPath::MoveToElement: path.moveTo(x, y); break; case QPainterPath::LineToElement: path.lineTo(x, y); break; case QPainterPath::CurveToElement: curveTo.rx() = x; curveTo.ry() = y; state = 1; break; case QPainterPath::CurveToDataElement: if (state == 1) { p1.rx() = x; p1.ry() = y; state = 2; } else if (state == 2) { path.cubicTo(curveTo, p1, QPointF(x, y)); } break; } } else AL::domError(ee); } modified = true; setSubtype(0); } else if (!Element::readProperties(r)) r->unknown(); } #endif }
void QgsGCPCanvasItem::drawResidualArrow( QPainter* p, const QgsRenderContext& context ) { if ( !mDataPoint || !mIsGCPSource || !mMapCanvas ) { return; } QPointF residual = mDataPoint->residual(); double rf = residualToScreenFactor(); p->setPen( mResidualPen ); p->drawLine( QPointF( 0, 0 ), QPointF( residual.rx() * rf, residual.ry() * rf ) ); }
QPointF SymbolDataEditor::fromViewBox(const QPointF &point) const { QPointF result = point; QDomElement svgElement = doc.elementsByTagName("svg").item(0).toElement(); QStringList viewBoxValues = svgElement.attribute("viewBox").split(" "); QRectF viewBox = QRectF(viewBoxValues.at(0).toDouble(), viewBoxValues.at(1).toDouble(), viewBoxValues.at(2).toDouble(), viewBoxValues.at(3).toDouble()); result -= viewBox.topLeft(); result.rx() /= viewBox.width(); result.ry() /= viewBox.height(); return result; }
void Legend::paint(QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &paintContext) { //painter.save(); // First of all, scale the painter's coordinate system to fit the current zoom level applyConversion(painter, converter); // Calculate the clipping rect QRectF paintRect = QRectF(QPointF(0, 0), size()); //clipRect.intersect(paintRect); painter.setClipRect(paintRect, Qt::IntersectClip); // Get the current zoom level QPointF zoomLevel; converter.zoom(&zoomLevel.rx(), &zoomLevel.ry()); // Only repaint the pixmap if it is scheduled, the zoom level changed or the shape was resized /*if ( d->pixmapRepaintRequested || d->lastZoomLevel != zoomLevel || d->lastSize != size()) { // TODO: What if two zoom levels are constantly being requested? // At the moment, this *is* the case, due to the fact // that the shape is also rendered in the page overview // in Stage // Every time the window is hidden and shown again, a repaint is // requested --> laggy performance, especially when quickly // switching through windows d->pixmapRepaintRequested = false; d->lastZoomLevel = zoomLevel; d->lastSize = size(); paintPixmap(painter, converter); }*/ // Paint the background if (background()) { QPainterPath p; p.addRect(paintRect); background()->paint(painter, converter, paintContext, p); } // KChart thinks in pixels, Calligra in pt ScreenConversions::scaleFromPtToPx(painter); d->kdLegend->paint(&painter); //painter.restore(); // Paint the cached pixmap //painter.drawImage(0, 0, d->image); }
void DisplayItem::returnLookAtToBounds() { QPointF p = lookAt(); qreal fwidth = m_frame->size().width(); qreal fheight = m_frame->size().height(); qreal width = size().width(); qreal height = size().height(); p.rx() = std::max(p.x(), fwidth / (2 * factor())); p.rx() = std::min(p.x(), width - fwidth / (2 * factor())); p.ry() = std::max(p.y(), fheight / (2 * factor())); p.ry() = std::min(p.y(), height - fheight / (2 * factor())); setEffectiveLookAt(p); }