QDomElement RoundedRect::xml(QDomDocument doc, QPointF relPos, QList<Section *> sectionPool) { QDomElement mainNode = doc.createElement("Element"); mainNode.setAttribute("id","RoundRect"); Container::apendXML(mainNode , doc, relPos); QString endSec; QString sPoint; Section* start; Section* end; QPointF top = mapRectToScene(this->rect()).topLeft(); QPointF bt = mapRectToScene(this->rect()).bottomLeft(); for(int i = 0; i< sectionPool.size();i++) { QRectF seCrec = QRectF(sectionPool.at(i)->pos(),sectionPool.at(i)->rect().size()); if(seCrec.contains(top)) start = sectionPool.at(i); if(seCrec.contains(bt)) { endSec = sectionPool.at(i)->SectionName(); if(endSec!= "Pie de pagina" && endSec != "Pie de report") { end = start; break; } QPointF endPoint = bt - seCrec.topRight(); sPoint = QString("%1").arg(endPoint.y()); end = sectionPool.at(i); break; } } if(start == end) endSec = "Self"; mainNode.setAttribute("endPointName",endSec); mainNode.setAttribute("endPointPoint",sPoint); mainNode.setAttribute("PenWidth",m_penWidth); mainNode.setAttribute("PenColor",ColorString(m_penColor)); mainNode.setAttribute("Color1",ColorString(m_color1)); mainNode.setAttribute("Color2",ColorString(m_color2)); mainNode.setAttribute("GradientUsed",m_useGradient); mainNode.setAttribute("GradientDirection",m_GradientDirection == Vertical ? "V" : "H"); mainNode.setAttribute("RadiousX",m_RadiousX); mainNode.setAttribute("RadiousY",m_RadiousY); return mainNode; }
QDomElement ReportLine::xml(QDomDocument doc, QPointF relPos,QList<Section*> sectionPool) { QDomElement node = doc.createElement("Element"); node.setAttribute("id","Line"); Container::apendXML(node,doc, relPos); QString endSec; QString sPoint; Section* start; Section* end; if(m_Orientacion == Vertical) { QPointF top = mapRectToScene(this->rect()).topLeft(); QPointF bt = mapRectToScene(this->rect()).bottomLeft(); for(int i = 0; i< sectionPool.size();i++) { QRectF seCrec = QRectF(sectionPool.at(i)->pos(),sectionPool.at(i)->rect().size()); if(seCrec.contains(top)) start = sectionPool.at(i); if(seCrec.contains(bt)) { endSec = sectionPool.at(i)->SectionName(); if(endSec!= "Pie de pagina" && endSec != "Pie de report") { end = start; break; } QPointF endPoint = bt - seCrec.topRight(); sPoint = QString("%1").arg(endPoint.y()); end = sectionPool.at(i); break; } } } else endSec = "Self"; if(start == end) endSec = "Self"; node.setAttribute("penWidth",m_penWidth); node.setAttribute("endPointName",endSec); node.setAttribute("endPointPoint",sPoint); node.setAttribute("penColor",ColorString(m_penColor)); node.setAttribute("penStyle",m_penStyle); node.setAttribute("Orientacion",m_Orientacion == Vertical ? "V" : "H"); return node; }
//virtual void DemoGoggles::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget) { //map myself into the scene QRectF sceneRect = mapRectToScene(boundingRect()); QRectF sourceRect = sceneRect.intersected(m_sceneBgViewrect).translated(-m_sceneBgViewrect.topLeft()); m_qp_backgroundPmo->paint(painter,boundingRect().toRect(),sourceRect.toRect()); }
void QgsLayoutItemGroup::updateBoundingRect( QgsLayoutItem *item ) { //update extent if ( mBoundingRectangle.isEmpty() ) //we add the first item { mBoundingRectangle = QRectF( 0, 0, item->rect().width(), item->rect().height() ); setSceneRect( QRectF( item->pos().x(), item->pos().y(), item->rect().width(), item->rect().height() ) ); if ( !qgsDoubleNear( item->rotation(), 0.0 ) ) { setItemRotation( item->rotation() ); } } else { if ( !qgsDoubleNear( item->rotation(), rotation() ) ) { //items have mixed rotation, so reset rotation of group mBoundingRectangle = mapRectToScene( mBoundingRectangle ); setItemRotation( 0 ); mBoundingRectangle = mBoundingRectangle.united( item->mapRectToScene( item->rect() ) ); setSceneRect( mBoundingRectangle ); } else { //items have same rotation, so keep rotation of group mBoundingRectangle = mBoundingRectangle.united( mapRectFromItem( item, item->rect() ) ); QPointF newPos = mapToScene( mBoundingRectangle.topLeft().x(), mBoundingRectangle.topLeft().y() ); mBoundingRectangle = QRectF( 0, 0, mBoundingRectangle.width(), mBoundingRectangle.height() ); setSceneRect( QRectF( newPos.x(), newPos.y(), mBoundingRectangle.width(), mBoundingRectangle.height() ) ); } } }
void ActiveRegion::updateGeometry() { QRect rect = mapRectToScene(QRectF(x(), y(), width(), height())).toRect(); if (rect != m_geometry) { m_geometry = rect; active_region_set_geometry(m_activeRegion, rect.x(), rect.y(), rect.width(), rect.height()); } }
void BubbleChatBox::setText(const QString &text) { chatLabel->setHtml(text); QString plainText = chatLabel->toPlainText(); if (plainText.isEmpty()) { return; } QFontMetrics fontMetrics(chatLabel->font()); int imageCount = text.count("</img>"); int width = qAbs(fontMetrics.width(plainText)) + imageCount * ChatFaceWidth; int lineCount = 1; if (width > PixelsPerLine) { lineCount = width / PixelsPerLine; if (lineCount >= MaxLineCount) { lineCount = MaxLineCount; } else if (width % PixelsPerLine != 0) { ++lineCount; } width = PixelsPerLine; } int boxWidth = width + fontMetrics.maxWidth(); if (boxWidth <= BoxMinWidth) { boxWidth = BoxMinWidth; chatLabel->setAlignment(Qt::AlignHCenter); } else { chatLabel->setAlignment(Qt::AlignLeft); } chatLabel->setTextWidth(boxWidth); QRectF oldRect = rect; int height = fontMetrics.lineSpacing() + fontMetrics.xHeight(); rect.setSize(QSize(boxWidth + BoxRightFrameWidth, height * lineCount + BoxFrameHeight)); chatLabel->setPos(QPointF(BoxLeftFrameWidth, rect.center().y() - (height * lineCount) + (lineCount - 1) * (height / 2) - (imageCount > 0 ? 1 : 0))); chatLabel->setBoundingRect(QRectF(0, 0, boxWidth, height * lineCount + (MaxLineCount - lineCount) * 1)); updatePos(); if (opacity() != 1) { appearAndDisappear->setDirection(QAbstractAnimation::Forward); appearAndDisappear->start(); } if (oldRect.width() > rect.width()) { QRectF sceneRect = mapRectToScene(oldRect); scene()->update(sceneRect); } else { update(); } timer.start(Config.BubbleChatBoxKeepSeconds * 1000 - AnimationDuration); }
void DesktopSelectionRectangle::updateCoordinates() { QRectF sceneRect = mapRectToScene(rect()); x_ = (int)sceneRect.x() + PEN_WIDTH/2; y_ = (int)sceneRect.y() + PEN_WIDTH/2; width_ = (int)sceneRect.width() - PEN_WIDTH; height_ = (int)sceneRect.height() - PEN_WIDTH; }
bool QSGPinchArea::sendMouseEvent(QGraphicsSceneMouseEvent *event) { Q_D(QSGPinchArea); QGraphicsSceneMouseEvent mouseEvent(event->type()); QRectF myRect = mapRectToScene(QRectF(0, 0, width(), height())); QSGCanvas *c = canvas(); QSGItem *grabber = c ? c->mouseGrabberItem() : 0; bool stealThisEvent = d->stealMouse; if ((stealThisEvent || myRect.contains(event->scenePos().toPoint())) && (!grabber || !grabber->keepMouseGrab())) { mouseEvent.setAccepted(false); for (int i = 0x1; i <= 0x10; i <<= 1) { if (event->buttons() & i) { Qt::MouseButton button = Qt::MouseButton(i); mouseEvent.setButtonDownPos(button, mapFromScene(event->buttonDownPos(button))); } } mouseEvent.setScenePos(event->scenePos()); mouseEvent.setLastScenePos(event->lastScenePos()); mouseEvent.setPos(mapFromScene(event->scenePos())); mouseEvent.setLastPos(mapFromScene(event->lastScenePos())); switch(mouseEvent.type()) { case QEvent::GraphicsSceneMouseMove: mouseMoveEvent(&mouseEvent); break; case QEvent::GraphicsSceneMousePress: mousePressEvent(&mouseEvent); break; case QEvent::GraphicsSceneMouseRelease: mouseReleaseEvent(&mouseEvent); break; default: break; } grabber = c->mouseGrabberItem(); if (grabber && stealThisEvent && !grabber->keepMouseGrab() && grabber != this) grabMouse(); return stealThisEvent; } if (mouseEvent.type() == QEvent::GraphicsSceneMouseRelease) { d->stealMouse = false; if (c && c->mouseGrabberItem() == this) ungrabMouse(); setKeepMouseGrab(false); } return false; }
void ActiveRegion::init() { if (m_activeRegion) { active_region_destroy(m_activeRegion); m_activeRegion = nullptr; disconnect(m_updateConnection); } if (window()) { QRect rect = mapRectToScene(QRectF(x(), y(), width(), height())).toRect(); m_activeRegion = Client::client()->createActiveRegion(window(), rect); m_geometry = rect; m_updateConnection = connect(window(), &QQuickWindow::beforeRendering, this, &ActiveRegion::updateGeometry); } }
void ContentWindowGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) { // handle mouse movements differently depending on selected mode of item if(!selected()) { if(event->buttons().testFlag(Qt::LeftButton)) { if(resizing_) { QRectF r = boundingRect(); QPointF eventPos = event->pos(); r.setBottomRight(eventPos); QRectF sceneRect = mapRectToScene(r); double w = sceneRect.width(); double h = sceneRect.height(); setSize(w, h); } else { QPointF delta = event->pos() - event->lastPos(); double new_x = coordinates_.x() + delta.x(); double new_y = coordinates_.y() + delta.y(); setPosition(new_x, new_y); } } } else { ContentWindowManagerPtr contentWindow = getContentWindowManager(); if(contentWindow) { // Zoom or forward event depending on type contentWindow->getInteractionDelegate().mouseMoveEvent(event); // force a redraw to update window info label update(); } } }
/*! reimplementation. */ void HbComboBox::gestureEvent(QGestureEvent *event) { Q_D( HbComboBox ); if (!isEnabled()) { return; } if(event->gesture(Qt::TapGesture)) { HbTapGesture *tap = static_cast<HbTapGesture *>(event->gesture(Qt::TapGesture)); switch(tap->state()) { case Qt::GestureStarted: { scene()->setProperty(HbPrivate::OverridingGesture.latin1(),Qt::TapGesture); if (!tap->property(HbPrivate::ThresholdRect.latin1()).toRect().isValid()) { tap->setProperty(HbPrivate::ThresholdRect.latin1(), mapRectToScene(boundingRect()).toRect()); } d->touchAreaPressEvent(); break; } case Qt::GestureCanceled: { scene()->setProperty(HbPrivate::OverridingGesture.latin1(),QVariant()); d->mIsDown = false; updatePrimitives(); setProperty( "state", "normal" ); break; } case Qt::GestureFinished: { scene()->setProperty(HbPrivate::OverridingGesture.latin1(),QVariant()); d->touchAreaReleaseEvent(); break; //TODO :: move else part here } default: break; } } }
QDomElement DetailSection::xml(QDomDocument doc, QList<Container *> &usedItems, QMap<QString, bool> &querys, QList<Section*> sectionPool) { QDomElement node = doc.createElement("Section"); node.setAttribute("id",sectionType()); node.setAttribute("size",(int)rect().height()); node.setAttribute("name",m_SectionName); node.setAttribute("SqlGlobal",m_SqlGlobal); node.setAttribute("SqlInterno",m_SqlInterno); node.setAttribute("ClausulaInterna",m_ClausulaInterna); node.setAttribute("haveSqlInterno",m_header || m_foot); node.setAttribute("colored",m_colorear); node.setAttribute("color1",ColorString(m_color1)); node.setAttribute("alternative",m_use2Colors); node.setAttribute("color2",ColorString(m_color2)); QPointF br(rect().bottomRight().x(),rect().bottomRight().y()); QPointF tl(rect().topLeft().x(),rect().topLeft().y()); if(m_header) { QDomElement headerNode = doc.createElement("Header"); headerNode.setAttribute("size",m_headerSize); QRectF aux(tl,QPointF(br.x(),tl.y()+m_headerSize)); QRectF headerRect(mapRectToScene(aux)); QList<QGraphicsItem*>items =this->scene()->items(headerRect); QListIterator<QGraphicsItem*> it(items); while (it.hasNext()) { QGraphicsItem* c = it.next(); Container* cont = qgraphicsitem_cast<Container*>(c); if(cont) { if(!usedItems.contains(cont)) { headerNode.appendChild(cont->xml(doc,marginPoint(),sectionPool)); usedItems.append(cont); } } } node.appendChild(headerNode); } QDomElement bodyNode = doc.createElement("Body"); bodyNode.setAttribute("size",this->rect().height() - m_headerSize - m_footSize); QRectF bodyRect(mapToScene(QPointF(tl.x(),tl.y()+m_headerSize)),mapToScene(QPointF(br.x(),br.y()-m_footSize))); QList<QGraphicsItem*>items =this->scene()->items(bodyRect); QListIterator<QGraphicsItem*> it(items); while (it.hasNext()) { QGraphicsItem* c = it.next(); Container* cont = qgraphicsitem_cast<Container*>(c); if(cont) { if(!usedItems.contains(cont)) { bodyNode.appendChild(cont->xml(doc,mapToScene(QPointF(tl.x(),tl.y()+m_headerSize)),sectionPool)); usedItems.append(cont); } } } node.appendChild(bodyNode); if(m_foot) { QDomElement footNode = doc.createElement("Foot"); footNode.setAttribute("size",m_footSize); QRectF footRect(mapToScene(QPointF(tl.x(),br.y()-m_footSize+1)),mapToScene(QPointF(br))); QList<QGraphicsItem*>items =this->scene()->items(footRect); QListIterator<QGraphicsItem*> it(items); while (it.hasNext()) { QGraphicsItem* c = it.next(); Container* cont = qgraphicsitem_cast<Container*>(c); if(cont) { if(!usedItems.contains(cont)) { footNode.appendChild(cont->xml(doc,mapToScene(QPointF(tl.x(),br.y()-m_footSize)),sectionPool)); usedItems.append(cont); } } } node.appendChild(footNode); } return node; }
void ContentWindowGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) { // handle mouse movements differently depending on selected mode of item if(windowState_ == UNSELECTED) { if(event->buttons().testFlag(Qt::LeftButton) == true) { if(resizing_ == true) { QRectF r = rect(); QPointF eventPos = event->pos(); r.setBottomRight(eventPos); QRectF sceneRect = mapRectToScene(r); double w = sceneRect.width(); double h = sceneRect.height(); setSize(w, h); } else { QPointF delta = event->pos() - event->lastPos(); double x = x_ + delta.x(); double y = y_ + delta.y(); setPosition(x, y); } } } else if(windowState_ == SELECTED) { // handle zooms / pans QPointF delta = event->scenePos() - event->lastScenePos(); if(event->buttons().testFlag(Qt::RightButton) == true) { // increment zoom // if this is a touch event, use cross-product for determining change in zoom (counterclockwise rotation == zoom in, etc.) // otherwise, use y as the change in zoom double zoomDelta; if(event->modifiers().testFlag(Qt::AltModifier) == true) { zoomDelta = (event->scenePos().x()-0.5) * delta.y() - (event->scenePos().y()-0.5) * delta.x(); zoomDelta *= 2.; } else { zoomDelta = delta.y(); } double zoom = zoom_ * (1. - zoomDelta); setZoom(zoom); } else if(event->buttons().testFlag(Qt::LeftButton) == true) { // pan (move center coordinates) double centerX = centerX_ + 2.*delta.x() / zoom_; double centerY = centerY_ + 2.*delta.y() / zoom_; setCenter(centerX, centerY); } // force a redraw to update window info label update(); } else if(windowState_ == INTERACTION) { QRectF r = rect(); QPointF eventPos = event->pos(); InteractionState interactionState = interactionState_; interactionState.mouseX_ = (eventPos.x() - r.x()) / r.width(); interactionState.mouseY_ = (eventPos.y() - r.y()) / r.height(); if(event->buttons().testFlag(Qt::LeftButton) == true) interactionState.mouseLeft_ = true; else interactionState.mouseLeft_ = false; if(event->buttons().testFlag(Qt::MiddleButton) == true) interactionState.mouseMiddle_ = true; else interactionState.mouseMiddle_ = false; if(event->buttons().testFlag(Qt::RightButton) == true) interactionState.mouseRight_ = true; else interactionState.mouseRight_ = false; setInteractionState(interactionState); // force a redraw to update window info label update(); } }
void QDecViewportItem::paint(QPainter *qPainter, const QStyleOptionGraphicsItem *qStyle, QWidget *qWidget) { Q_UNUSED(qStyle); Q_UNUSED(qWidget); if(!m_initViewport) { if(!m_initFailed) { // create the fbo m_frameBufferObj = new QGLFramebufferObject(width(),height(), QGLFramebufferObject::CombinedDepthStencil, // play with this value? GL_TEXTURE_2D, GL_RGBA); // run the implemented init method this->initViewport(); if(m_initFailed) { return; } // connect the timer connect(&m_updateTimer,SIGNAL(timeout()), this, SLOT(updateViewport())); // start the timer if refreshRate is valid if(m_refreshRate > 0) { m_updateTimer.setInterval(m_refreshRate); m_updateTimer.start(); } emit refreshRateChanged(); m_initViewport = true; } else { return; } } QRectF localBounds = boundingRect(); QRectF sceneBounds = mapRectToScene(localBounds); // notes: // for some reason, this doesn't work unless // we draw the texture to the fbo first, and // *then* paint the fbo itself; so we're behind by // a frame (but this isn't a big deal) // if we do it the other way around, the context's // paint engine gets disabled/null even if // qPainter->paintEngine()->isActive() returns // true, and QGL::Context will give us an error // also, keep in mind that using an fbo like this // every frame is pretty expensive, especially for // a mobile target, so we may get slow downs if(qPainter->paintEngine()->type() == QPaintEngine::OpenGL2 && qPainter->paintEngine()->isActive()) { m_frameBufferObj->drawTexture(localBounds, m_frameBufferObj->texture()); } // beginNativePainting // flushes the painting pipeline and prepares for the // user issuing commands directly to the underlying // graphics context: // * blending is disabled // * depth, stencil and scissor tests are disabled // * active texture unit is reset to 0 // * depth mask, depth function and the clear depth // are reset to their default values // * stencil mask, stencil operation and stencil // function are reset to their default values // * current color is reset to solid white // draw scene contents to the fbo qPainter->beginNativePainting(); m_frameBufferObj->bind(); this->drawViewport(); m_frameBufferObj->release(); qPainter->endNativePainting(); }