当前位置: 首页>>代码示例>>C++>>正文


C++ QRectF::contains方法代码示例

本文整理汇总了C++中QRectF::contains方法的典型用法代码示例。如果您正苦于以下问题:C++ QRectF::contains方法的具体用法?C++ QRectF::contains怎么用?C++ QRectF::contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QRectF的用法示例。


在下文中一共展示了QRectF::contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: mouseMoveEvent

void DualColorButton::mouseMoveEvent(QMouseEvent *event)
{
	if(dragSource_ != NODRAG && (event->buttons() & Qt::LeftButton) &&
			(event->pos() - dragStart_).manhattanLength()
		> QApplication::startDragDistance())
	{
		QDrag *drag = new QDrag(this);

		QMimeData *mimedata = new QMimeData;
		const QColor color = (dragSource_ == FOREGROUND)?foreground_:background_;
		mimedata->setColorData(color);

		drag->setMimeData(mimedata);
		drag->start(Qt::CopyAction);
	}
	// Higlight clickable areas
	QRectF fgr = foregroundRect();
	QRectF bgr = backgroundRect();
	if(fgr.contains(event->pos()))
		hilite_ = 1;
	else if(bgr.contains(event->pos()))
		hilite_ = 2;
	else if(event->pos().x() > fgr.right() && event->pos().y() < bgr.top())
		hilite_ = 3;
	else if(event->pos().x() < bgr.left() && event->pos().y() > fgr.bottom())
		hilite_ = 4;
	else
		hilite_ = 0;
	update();
}
开发者ID:GreenReaper,项目名称:Drawpile,代码行数:30,代码来源:dualcolorbutton.cpp

示例2: setBaseCard

bool GameManager::setBaseCard(const QPointF& point, CardSvgItem* card)
{
	qint32 indexPileEnd = -1, indexPileStart = -1, i;
	QRectF rc;
	
	for(i = 0; i < NUM_PILES_BASE; i++)
	{
		rc = basePiles.at(i).getZone();
		if(rc.contains(point))
		{
			indexPileEnd = i;
		}
		if(rc.contains(card->getLastPos()))
		{
			indexPileStart = i;
		}
	}
	if(indexPileEnd == -1)
	{
		return false;
	}
	
	if(indexPileEnd == indexPileStart)
		return true;
	
	if(basePiles[indexPileEnd].addCard(card))
	{
		for(i = 0; i < NUM_PILES_FAULT; i++)
		{
			rc = faultPiles.at(i).getZone();
			if(rc.contains(card->getLastPos()))
			{
				faultPiles[i].removeCard(faultPiles[i].getCardIndex(card));
				return true;
			}
		}
		
		rc = reserve->getZone();
		if(rc.contains(card->getLastPos()))
		{
			reserve->removeCard(reserve->getCardIndex(card));
			return true;
		}
		
		rc = activeReserve->getZone();
		if(rc.contains(card->getLastPos()))
		{
			activeReserve->removeCard(activeReserve->getCardIndex(card));
			if(pack->count() > 0)
			{
				activeReserve->addCard(pack->lastCard());
				pack->removeCard(pack->count() - 1);
			}
			return true;
		}
	}
	card->setPos(card->getLastPos());
	card->setZValue(card->getOldZ());
	return true;
}
开发者ID:Horsmir,项目名称:frog,代码行数:60,代码来源:gamemanager.cpp

示例3: mousePressEvent

void KColorTable::mousePressEvent( QGraphicsSceneMouseEvent *event )
{
	Q_D(KColorTable);
	QPointF pt = event->pos();
	QRectF hitRt = hueLightRect();
	if(hitRt.contains(pt))
	{
		d->hue = pt.x() / hitRt.width() * 360.0;
		d->light = pt.y() / hitRt.height() * 100.0;
		update(hitRt);

		QRgb clr;
		KHSL::Hsl2Rgb(d->hue, d->sat, d->light, 0, &clr);
		KHSL::UpdateColorBar(d->satuation, d->hue, d->light);
		emit colorChanged(clr);
	}
	else
	{
		hitRt = satuationRect();
		if(hitRt.contains(pt))
		{
			d->sat = pt.x() / hitRt.width() * 100.0;
			update(hitRt);

			QRgb clr;
			KHSL::Hsl2Rgb(d->hue, d->sat, d->light, 0, &clr);
			KHSL::UpdateColorTable(d->huelight, d->sat);
			emit colorChanged(clr);
		}
	}
}
开发者ID:kxtry,项目名称:kxfw,代码行数:31,代码来源:kcolortable.cpp

示例4: itemsBoundingRect

QRectF Scene::itemsBoundingRect() const
{
    QRectF boundingRect ( QPointF ( -50, -50 ), QSizeF ( 100, 100 ) );

    // iterate over all elements
    // → agents
    foreach ( Agent* agent, agents )
    {
        if ( !boundingRect.contains ( agent->getVisiblePosition() ) )
        {
            // resize rectangle to include point
            boundingRect |= QRectF ( agent->getVisiblePosition() - QPointF ( 0.5, 0.5 ), QSizeF ( 1, 1 ) );
        }
    }
    // → obstacles
    foreach ( Obstacle* obstacle, obstacles )
    {
        QPointF startPoint = obstacle->getVisiblePosition();
        QPointF endPoint ( obstacle->getbx(), obstacle->getby() );

        if ( !boundingRect.contains ( startPoint )
                || !boundingRect.contains ( endPoint ) )
        {
            // resize rectangle to include point
            boundingRect |= QRectF ( startPoint, endPoint );
        }
    }
开发者ID:lengmm,项目名称:pedsim_ros,代码行数:27,代码来源:scene.cpp

示例5: rectContainsWall

bool AStarAlgorithm::rectContainsWall(const LineSegment *wall, const QRectF &rect)
{
    if (rect.contains(wall->x1(), wall->y1()) || rect.contains(wall->x2(), wall->y2()))
        return true;
    if(numberOfIntersectingSegmentsWithAGivenRectangleBuiltByExpandingAPoint(wall, rect) > 0)
        return true;
    return false;
}
开发者ID:gaf90,项目名称:Tesi,代码行数:8,代码来源:astaralgorithm.cpp

示例6: SetCenter

//Set the current centerpoint in the
void GraphicView::SetCenter ( const QPointF& centerPoint )
{
    //Get the rectangle of the visible area in scene coords
    QRectF visibleArea = mapToScene ( rect() ).boundingRect();

    //Get the scene area
    QRectF sceneBounds = sceneRect();

    double boundX = visibleArea.width() / 2.0;
    double boundY = visibleArea.height() / 2.0;
    double boundWidth = sceneBounds.width() - 2.0 * boundX;
    double boundHeight = sceneBounds.height() - 2.0 * boundY;

    //The max boundary that the centerPoint can be to
    QRectF bounds ( boundX, boundY, boundWidth, boundHeight );

    if ( bounds.contains ( centerPoint ) )
    {
        //We are within the bounds
        CurrentCenterPoint = centerPoint;
    } else
    {
        //We need to clamp or use the center of the screen
        if ( visibleArea.contains ( sceneBounds ) )
        {
            //Use the center of scene ie. we can see the whole scene
            CurrentCenterPoint = sceneBounds.center();
        }
        else
        {

            CurrentCenterPoint = centerPoint;

            //We need to clamp the center. The centerPoint is too large
            if ( centerPoint.x() > bounds.x() + bounds.width() )
            {
                CurrentCenterPoint.setX ( bounds.x() + bounds.width() );
            }
            else if ( centerPoint.x() < bounds.x() )
            {
                CurrentCenterPoint.setX ( bounds.x() );
            }

            if ( centerPoint.y() > bounds.y() + bounds.height() )
            {
                CurrentCenterPoint.setY ( bounds.y() + bounds.height() );
            }
            else if ( centerPoint.y() < bounds.y() )
            {
                CurrentCenterPoint.setY ( bounds.y() );
            }

        }
    }

    //Update the scrollbars
    centerOn ( CurrentCenterPoint );
}
开发者ID:jfnavarro,项目名称:PrimeTV2,代码行数:59,代码来源:GraphicView.cpp

示例7: paint_label

void Trace::paint_label(QPainter &p, int right, const QPoint pt)
{
    compute_text_size(p);
    const int y = get_y();

    const QRectF color_rect = get_rect("color", y, right);
    const QRectF name_rect  = get_rect("name",  y, right);
    const QRectF label_rect = get_rect("label", get_zeroPos(), right);

    p.setRenderHint(QPainter::Antialiasing);
    // Paint the ColorButton
    p.setPen(Qt::transparent);
    p.setBrush(enabled() ? _colour : dsDisable);
    p.drawRect(color_rect);

    // Paint the signal name
    p.setPen(enabled() ? Qt::black : dsDisable);
    p.drawText(name_rect, Qt::AlignLeft | Qt::AlignVCenter, _name);

    // Paint the trigButton
    paint_type_options(p, right, pt);

    // Paint the label
    if (enabled()) {
        const QPointF points[] = {
            label_rect.topLeft(),
            label_rect.topRight(),
            QPointF(right, get_zeroPos()),
            label_rect.bottomRight(),
            label_rect.bottomLeft()
        };

        p.setPen(Qt::transparent);
        if (_type == SR_CHANNEL_DSO)
            p.setBrush((label_rect.contains(pt) || selected()) ? _colour.darker() : _colour);
        else
            p.setBrush((label_rect.contains(pt) || selected()) ? dsYellow : dsBlue);
        p.drawPolygon(points, countof(points));

        p.setPen(QPen(Qt::blue, 1, Qt::DotLine));
        p.setBrush(Qt::transparent);
        p.drawLine(label_rect.right(), label_rect.top() + 3,
                    label_rect.right(), label_rect.bottom() - 3);

        // Paint the text
        p.setPen(Qt::white);
        if (_type == SR_CHANNEL_GROUP)
            p.drawText(label_rect, Qt::AlignCenter | Qt::AlignVCenter, "G");
        else if (_type == SR_CHANNEL_ANALOG)
            p.drawText(label_rect, Qt::AlignCenter | Qt::AlignVCenter, "A");
        else if (_type == SR_CHANNEL_DECODER)
            p.drawText(label_rect, Qt::AlignCenter | Qt::AlignVCenter, "D");
        else
            p.drawText(label_rect, Qt::AlignCenter | Qt::AlignVCenter, QString::number(_index_list.front()));
    }
}
开发者ID:DoctorCannibal,项目名称:DSView,代码行数:56,代码来源:trace.cpp

示例8: xml

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;
}
开发者ID:0TheFox0,项目名称:MayaReports,代码行数:50,代码来源:reportline.cpp

示例9: xml

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;
}
开发者ID:0TheFox0,项目名称:MayaReports,代码行数:50,代码来源:roundedrect.cpp

示例10: pt_in_rect

int Trace::pt_in_rect(int y, int right, const QPoint &point)
{
    const QRectF color = get_rect("color", y, right);
    const QRectF name  = get_rect("name", y, right);
    const QRectF label = get_rect("label", get_zeroPos(), right);

    if (color.contains(point) && enabled())
        return COLOR;
    else if (name.contains(point) && enabled())
        return NAME;
    else if (label.contains(point) && enabled())
        return LABEL;
    else
        return 0;
}
开发者ID:DoctorCannibal,项目名称:DSView,代码行数:15,代码来源:trace.cpp

示例11: doMousePress

void KTreeWidgetPrivate::doMousePress( QGraphicsSceneMouseEvent *event )
{
	Q_Q(KTreeWidget);
	QPointF pt = event->pos();
	bool bdepth = m_styleTree & KTreeWidget::HasBranch;
	for(QHash<qint64,QPointer<KTreeItem>>::iterator iter = m_widgetItems.begin(); iter != m_widgetItems.end(); iter++)
	{
		KTreeItem *pli = iter.value();
		QRectF geom = pli->geometry();
		if(geom.contains(pt))
		{
			qint64 nid = pli->nodeId();
			if(bdepth)
			{
				QMargins m = pli->margins();
				QRectF plusRt = QRectF(geom.left() + m.left() - m_depthIndentation, geom.top(), m_depthIndentation, geom.height());
				if(plusRt.contains(pt))
				{
					if(m_itemsExpanded.contains(nid))
					{
						doItemCollapsed(nid);
					}
					else
					{
						doItemExpanded(nid);
					}
					return;
				}
			}
			if(nid == m_nodeIdSelect)
			{
				emit q->itemClicked(nid, event->button());
				return;
			}
			KTreeItem *pliOld = m_widgetItems.value(m_nodeIdSelect);
			if(pliOld)
			{
				pliOld->setUnselected(m_variantUnselect);
			}
			m_nodeIdSelect = pli->nodeId();
			pli->setSelected(m_variantSelected);
			emit q->indexChanged(m_nodeIdSelect);
			emit q->itemClicked(nid, event->button());
			return;
		}
	}
	emit q->clicked(event->button());
}
开发者ID:kxtry,项目名称:kxfw,代码行数:48,代码来源:ktreewidget.cpp

示例12: intersect_rect

    static bool intersect_rect(const QGraphicsItem *item, const QRectF &exposeRect, Qt::ItemSelectionMode mode,
                               const QTransform &deviceTransform, const void *intersectData)
    {
        const QRectF sceneRect = *static_cast<const QRectF *>(intersectData);

        QRectF brect = item->boundingRect();
        _q_adjustRect(&brect);

        // ### Add test for this (without making things slower?)
        Q_UNUSED(exposeRect);

        bool keep = true;
        const QGraphicsItemPrivate *itemd = QGraphicsItemPrivate::get(item);
        if (itemd->itemIsUntransformable()) {
            // Untransformable items; map the scene rect to item coordinates.
            const QTransform transform = item->deviceTransform(deviceTransform);
            QRectF itemRect = (deviceTransform * transform.inverted()).mapRect(sceneRect);
            if (mode == Qt::ContainsItemShape || mode == Qt::ContainsItemBoundingRect)
                keep = itemRect.contains(brect) && itemRect != brect;
            else
                keep = itemRect.intersects(brect);
            if (keep && (mode == Qt::ContainsItemShape || mode == Qt::IntersectsItemShape)) {
                QPainterPath itemPath;
                itemPath.addRect(itemRect);
                keep = QGraphicsSceneIndexPrivate::itemCollidesWithPath(item, itemPath, mode);
            }
        } else {
            Q_ASSERT(!itemd->dirtySceneTransform);
            const QRectF itemSceneBoundingRect = itemd->sceneTransformTranslateOnly
                                               ? brect.translated(itemd->sceneTransform.dx(),
                                                                  itemd->sceneTransform.dy())
                                               : itemd->sceneTransform.mapRect(brect);
            if (mode == Qt::ContainsItemShape || mode == Qt::ContainsItemBoundingRect)
                keep = sceneRect != brect && sceneRect.contains(itemSceneBoundingRect);
            else
                keep = sceneRect.intersects(itemSceneBoundingRect);
            if (keep && (mode == Qt::ContainsItemShape || mode == Qt::IntersectsItemShape)) {
                QPainterPath rectPath;
                rectPath.addRect(sceneRect);
                if (itemd->sceneTransformTranslateOnly)
                    rectPath.translate(-itemd->sceneTransform.dx(), -itemd->sceneTransform.dy());
                else
                    rectPath = itemd->sceneTransform.inverted().map(rectPath);
                keep = QGraphicsSceneIndexPrivate::itemCollidesWithPath(item, rectPath, mode);
            }
        }
        return keep;
    }
开发者ID:3163504123,项目名称:phantomjs,代码行数:48,代码来源:qgraphicssceneindex.cpp

示例13: pointsInRect

auto pointsInRect(QXYSeries *series, const QRectF &rect) {
   QVector<QPointF> result;
   auto const points = series->pointsVector();
   std::copy_if(points.begin(), points.end(), std::back_inserter(result),
                [rect](auto &p) { return rect.contains(p); });
   return result;
}
开发者ID:KubaO,项目名称:stackoverflown,代码行数:7,代码来源:main.cpp

示例14: anchorAt

/*!
    \fn QString QAbstractTextDocumentLayout::anchorAt(const QPointF &position) const

    Returns the reference of the anchor the given \a position, or an empty
    string if no anchor exists at that point.
*/
QString QAbstractTextDocumentLayout::anchorAt(const QPointF& pos) const
{
    int cursorPos = hitTest(pos, Qt::ExactHit);
    if (cursorPos == -1)
        return QString();

    // compensate for preedit in the hit text block
    QTextBlock block = document()->firstBlock();
    while (block.isValid()) {
        QRectF blockBr = blockBoundingRect(block);
        if (blockBr.contains(pos)) {
            QTextLayout *layout = block.layout();
            int relativeCursorPos = cursorPos - block.position();
            const int preeditLength = layout ? layout->preeditAreaText().length() : 0;
            if (preeditLength > 0 && relativeCursorPos > layout->preeditAreaPosition())
                cursorPos -= qMin(cursorPos - layout->preeditAreaPosition(), preeditLength);
            break;
        }
        block = block.next();
    }

    QTextDocumentPrivate *pieceTable = qobject_cast<const QTextDocument *>(parent())->docHandle();
    QTextDocumentPrivate::FragmentIterator it = pieceTable->find(cursorPos);
    QTextCharFormat fmt = pieceTable->formatCollection()->charFormat(it->format);
    return fmt.anchorHref();
}
开发者ID:KDE,项目名称:android-qt5-qtbase,代码行数:32,代码来源:qabstracttextdocumentlayout.cpp

示例15: convert

HsWidgetPositioningOnWidgetAdd::Result HsAnchorPointInCenter::convert(
    const QRectF &contentArea,
    const QList<QRectF> &existingRects,
    const QList<QRectF> &newRects,
    const QPointF &startPoint )
{
    Q_UNUSED(existingRects);
    Q_UNUSED(startPoint)

    HsWidgetPositioningOnWidgetAdd::Result result;
    QList<QRectF> toGeometries;

    //Offset for widgets' centers position to each other
    qreal k = contentArea.height()/contentArea.width(); //slope of the diagonal
    qreal offset_x = offset/(sqrt(k + 1));
    qreal offset_y = k*offset_x;
    QPointF offsetPoint(offset_x, offset_y);

    //First widget to the center of the content area
    QPointF anchorPoint = contentArea.center();
    foreach (QRectF g, newRects) {
        g.moveCenter(anchorPoint);
        toGeometries << g;
        anchorPoint -= offsetPoint;
        if(!contentArea.contains(anchorPoint)) {
            anchorPoint = contentArea.bottomRight();
        }
    }
开发者ID:cdaffara,项目名称:symbiandump-ossapps,代码行数:28,代码来源:hswidgetpositioningonwidgetadd.cpp


注:本文中的QRectF::contains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。