QRectF MapView::calculateViewBoundingBox(QRectF rect) const { auto top_left = mapToView(static_cast<MapCoordF>(rect.topLeft())); auto top_right = mapToView(static_cast<MapCoordF>(rect.topRight())); auto bottom_right = mapToView(static_cast<MapCoordF>(rect.bottomRight())); auto bottom_left = mapToView(static_cast<MapCoordF>(rect.bottomLeft())); rect = QRectF{ top_left, bottom_right }.normalized(); rectInclude(rect, top_right); rectInclude(rect, bottom_left); rect.adjust(-1.0, -1.0, +1.0, +1.0); return rect; }
/** * \overload */ RRefPoint RGraphicsView::getClosestReferencePoint(REntity::Id entityId, const RVector& screenPosition) { RRefPoint ret = RVector::invalid; double minDist = RMAXDOUBLE; if (scene == NULL) { return ret; } if (getDocument() == NULL) { return ret; } QSharedPointer<REntity> entity = getDocument()->queryEntity(entityId); if (entity.isNull()) { return ret; } QList<RRefPoint> referencePoints = entity->getReferencePoints(scene->getProjectionRenderingHint()); QList<RRefPoint>::iterator it; for (it=referencePoints.begin(); it!=referencePoints.end(); it++) { RVector rp = mapToView(*it); double dist = screenPosition.getDistanceTo(rp); if (dist<minDist) { minDist = dist; ret = (*it); } } return ret; }
/** * Maps the given \c box (e.g. a 3d bounding box) to a 2d box * in view coordinates (pixels). */ RBox RGraphicsView::mapToView(const RBox& box) const { QList<RVector> boxCorners = box.getCorners(); RVector minView(RMAXDOUBLE, RMAXDOUBLE, RMAXDOUBLE); RVector maxView(RMINDOUBLE, RMINDOUBLE, RMINDOUBLE); RVector corner; for (int i=0; i<8; i++) { corner = mapToView(boxCorners[i]); minView = RVector::getMinimum(corner, minView); maxView = RVector::getMaximum(corner, maxView); } return RBox(minView, maxView); }
/** * Finds the reference point that is the closest to the given screen * coordinate (in pixels). * * \param range Maximum distance in pixels. * * \return The closest referecene point in model coordinates. */ RRefPoint RGraphicsView::getClosestReferencePoint(const RVector& screenPosition, int range) { RRefPoint ret = RVector::invalid; if (scene == NULL) { return ret; } double minDist = (double) range; QMultiMap<REntity::Id, RRefPoint>& referencePoints = scene->getReferencePoints(); QMultiMap<REntity::Id, RRefPoint>::iterator it; for (it = referencePoints.begin(); it != referencePoints.end(); it++) { RVector rp = mapToView(*it); double dist = screenPosition.getDistanceTo(rp); if (dist < minDist) { minDist = dist; ret = *it; } } return ret; }
void MultilineTextEdit::drawWhitespaces() { // prepare a rectangle to store the width of the whitespace found QRect space; // get the painter for the text area QPainter pa(viewport()); // get a sane color QColor col=colorGroup().link(); // and a brush of the same color QBrush fillBrush(col); // use it for line drawing pa.setPen(col); // and for filling pa.setBrush(fillBrush); // prepare the carriage return coordinates array QPointArray cr(4); // and the tabulator arrow coordinate array QPointArray tab(7); // whitespace expression QRegExp regex("\\s"); // line buffer QString line; int x,y,pos,paragraph; // start looking in every paragraph for(paragraph=0;paragraph<paragraphs();paragraph++) { // get paragraph text line=text(paragraph); // start looking for whitespaces from the beginning pos=0; while((pos=line.find(regex,pos))!=-1) { // whitespace found is not the carriage return at the end of the line? if(pos<((int)line.length()-1)) { // get whitespace rectangle space=mapToView(paragraph,pos); // extract x/y coordinates x=space.width()/2-1+space.x(); y=space.height()/2-1+space.y(); // if it was a regular blank ... if(regex.cap(0)==" ") { // dras a simple small square pa.drawRect(x-1,y,2,2); } // if it was a tabulator else if(regex.cap(0)=="\t") { // calculate arrow points and draw them filled tab.putPoints(0,7, x-5,y-1, x,y-1, x,y-3, x+3,y, x,y+3, x,y+1, x-5,y+1); pa.drawPolygon(tab); } } // go to next position and resume looking for more whitespaces pos++; } // while // end of line, get carriage return position space=mapToView(paragraph,line.length()-1); // extract x/y positions x=space.width()/2-1+space.x(); y=space.height()/2-1+space.y(); // calculate carriage return triangle coordinates and draw them filled cr.putPoints(0,4, x,y, x,y+1, x+4, y+5, x+4, y-4); pa.drawPolygon(cr); } // for }