Esempio n. 1
0
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();
}
Esempio n. 2
0
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;
}
Esempio n. 3
0
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);
		}
	}
}
Esempio n. 4
0
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 );
        }
    }
Esempio n. 5
0
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;
}
Esempio n. 6
0
//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 );
}
Esempio n. 7
0
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()));
    }
}
Esempio n. 8
0
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;
}
Esempio n. 9
0
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;
}
Esempio n. 10
0
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;
}
Esempio n. 11
0
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());
}
Esempio n. 12
0
void KPrTimeLineView::mousePressEvent(QMouseEvent *event)
{
    int row = rowAt(event->y());
    int column = columnAt(event->x());

    m_mainView->setSelectedRow(row);
    m_mainView->setSelectedColumn(column);
    // Request context menu
    if (event->button()== Qt::RightButton) {
        emit customContextMenuRequested(event->pos());
    }
    // Check if user wants to move the time bars
    if (event->button() == Qt::LeftButton) {
        if (column == KPrShapeAnimations::StartTime) {
            m_resize = false;
            m_move = false;

            QRectF lineRect = getRowRect(row, column);
            QRectF endLineRect = QRectF(lineRect.right() - RESIZE_RADIUS, lineRect.top(),
                                        RESIZE_RADIUS * 2, lineRect.height());

            // If the user clicks near the end of the line they could resize otherwise they move the bar.
            if (endLineRect.contains(event->x(), event->y())) {
                m_resize = true;
                m_resizedRow = row;
                setCursor(Qt::SizeHorCursor);
            } else {
                m_resize = false;
                m_move = false;
                if (lineRect.contains(event->x(), event->y())) {
                    startDragPos = event->x() - lineRect.x();
                    m_move = true;
                    m_resizedRow = row;
                    setCursor(
#if QT_VERSION >= 0x040700
                              Qt::DragMoveCursor
#else
                              Qt::ClosedHandCursor
#endif
                              );
                }
            }
        }
    }
    emit clicked(m_mainView->model()->index(row, column));


}
Esempio n. 13
0
    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;
    }
Esempio n. 14
0
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;
}
Esempio n. 15
0
void AbstractSelectionStrategy::handleMouseMove(const QPointF& documentPos, Qt::KeyboardModifiers modifiers)
{
    Q_UNUSED(modifiers)
    const KoShape* shape = m_canvas->shapeManager()->selection()->firstSelectedShape();
    const QPointF position = documentPos - (shape ? shape->position() : QPointF(0.0, 0.0));
    // In which cell did the user click?
    double xpos;
    double ypos;
    int col = d->selection->activeSheet()->leftColumn(position.x(), xpos);
    int row = d->selection->activeSheet()->topRow(position.y(), ypos);
    // Check boundaries.
    if (col > KS_colMax || row > KS_rowMax)
    {
        kDebug(36005) << "col or row is out of range:" << "col:" << col << " row:" << row;
        return;
    }
    // Test whether mouse is over the Selection.handle
    const QRectF selectionHandle = d->selection->selectionHandleArea(m_canvas->viewConverter());
    if (selectionHandle.contains(position))
    {
        // If the cursor is over the handle, than it might be already on the next cell.
        // Recalculate the cell position!
        col = d->selection->activeSheet()->leftColumn(position.x() - m_canvas->viewConverter()->viewToDocumentX(2.0), xpos);
        row = d->selection->activeSheet()->topRow(position.y() - m_canvas->viewConverter()->viewToDocumentY(2.0), ypos);
    }
    // Update the selection.
    d->selection->update(QPoint(col, row));
    m_parent->repaintDecorations();
}
/*!
    \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();
}
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();
        }
    }
/*!
    \class HsAnchorPointInBottomRight
    \brief Diagonal widget positioning algorithm.
    
    Sets widget's lower right corner to follow content area's diagonal.
    Widgets are positioned to certain offset to each other.
*/
HsWidgetPositioningOnWidgetAdd::Result HsAnchorPointInBottomRight::convert(
    const QRectF &contentArea,
    const QList<QRectF> &existingRects,
    const QList<QRectF> &newRects,
    const QPointF &startPoint)
{
    Q_UNUSED(existingRects);

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

    //Offset for widgets' bottom right 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);
    
    QPointF anchorPoint;
   
    if(startPoint.isNull()){

        QLineF diagonal(contentArea.topLeft(), contentArea.bottomRight());
        QLineF widgetRightSide(contentArea.center().x()+ newRects.at(0).width()/2,
                           contentArea.top(),
                           contentArea.center().x()+ newRects.at(0).width()/2,
                           contentArea.bottom());

        // right side line intersection with diagonal will be bottom right position
        // for the first rect
        if(QLineF::BoundedIntersection != 
            diagonal.intersect(widgetRightSide, &anchorPoint)) {
            result.calculatedRects = newRects;
            return result; //Return original since undefined error.
                            //In this case widget's must be wider than the content area.
        }
    } else {
        anchorPoint = startPoint - offsetPoint;
    }

    QRectF widgetRect;
    for(int i=0;i<newRects.count();++i) {
        widgetRect = newRects.at(i);
        widgetRect.moveBottomRight(anchorPoint);
        //if widget rect doesn't fit, try to move it
        if(!contentArea.contains(widgetRect)) {
            /*! precondition is that
             widget's max height < content area height
             widget's max widht < content area width
            */
            widgetRect.moveBottomRight(contentArea.bottomRight());
            // anchorPoin is always previous bottom right
            anchorPoint = widgetRect.bottomRight();
        }
        toGeometries << widgetRect;
        anchorPoint -= offsetPoint;
        
    }
    result.calculatedRects = toGeometries;
    return result;
}
Esempio n. 19
0
/*!
  Repaint the knob
  \param event Paint event
*/
void QwtKnob::paintEvent( QPaintEvent *event )
{
    const QRectF knobRect = this->knobRect();

    QPainter painter( this );
    painter.setClipRegion( event->region() );

    QStyleOption opt;
    opt.init(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);

    painter.setRenderHint( QPainter::Antialiasing, true );

    if ( !knobRect.contains( event->region().boundingRect() ) )
    {
        scaleDraw()->setRadius( 0.5 * knobRect.width() + d_data->scaleDist );
        scaleDraw()->moveCenter( knobRect.center() );

        scaleDraw()->draw( &painter, palette() );
    }

    drawKnob( &painter, knobRect );

    drawMarker( &painter, knobRect,
        qwtNormalizeDegrees( scaleMap().transform( value() ) ) );

    painter.setRenderHint( QPainter::Antialiasing, false );

    if ( hasFocus() )
        drawFocusIndicator( &painter );
}
Esempio n. 20
0
bool
TracingItem::containsPoint(const QRectF &rect, int index)
{
    if (my.points.isEmpty())
	return false;
    return rect.contains(my.points.at(index));
}
Esempio n. 21
0
QVariant QBayesNode::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
{
    switch (change) {
    case QGraphicsItem::ItemSelectedChange:
        mIsSelected = value.toBool();
        if (mIsSelected)
            setFocus();
        break;
    case QGraphicsItem::ItemPositionChange:
    {
        if (scene()) {
            // value is the new position.
            QPointF newPos = value.toPointF();
            QRectF sceneRect = scene()->sceneRect();
            if (!sceneRect.contains(newPos)) {
                // Keep the item inside the scene rect.
                newPos.setX(qMin(sceneRect.right(), qMax(newPos.x(), sceneRect.left())));
                newPos.setY(qMin(sceneRect.bottom(), qMax(newPos.y(), sceneRect.top())));
            }
            emit positionChanged(newPos);
            update();
            return QGraphicsItem::itemChange(change, newPos);
        }
        break;
    }
    default:
        break;
    }
    return QGraphicsItem::itemChange(change, value);
}
void MContainerHeaderView::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    Q_UNUSED(event);
    style().setModeDefault();

    if (!expectMouseReleaseEvent) {
        return;
    }

    QPointF touch = event->scenePos();
    qreal distanceFromPressPoint = (touch - pressScenePos).manhattanLength();

    QRectF rect = controller->sceneBoundingRect();
    rect.adjust(-M_RELEASE_MISS_DELTA, -M_RELEASE_MISS_DELTA,
                M_RELEASE_MISS_DELTA, M_RELEASE_MISS_DELTA);

    if (distanceFromPressPoint > style()->maxDistanceForClick() || !rect.contains(touch)) {
        // Too far: cancel
        expectMouseReleaseEvent = false;
        QApplication::postEvent(controller, new MCancelEvent);
        return;
    }

    update();
}
void MButtonView::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    Q_D(MButtonView);
    if (!d->expectMouseReleaseEvent) {
        // The usual mouse-press -> mouse-move -> mouse-release cycle
        // has been interrupted by a cancel event.
        return;
    }

    QPointF touch = event->scenePos();
    QRectF rect = d->controller->sceneBoundingRect();
    rect.adjust(-M_RELEASE_MISS_DELTA, -M_RELEASE_MISS_DELTA,
                M_RELEASE_MISS_DELTA, M_RELEASE_MISS_DELTA);

    if (rect.contains(touch)) {
        if (!model()->down()) {
            model()->setDown(true);
        }
    } else {
        if (model()->down()) {
            d->eventCancelled = true;
            model()->setDown(false);
        }
    }

}
void ribi::braw::qtbrainweaverprintconceptmapdialog_test::default_construct()
{
  const auto files = FileFactory().GetTests();
  for (const auto file: files) {
    QtPrintConceptMapDialog d(file);
    d.show();
    QTest::qWait(1000);
    for (const ribi::cmap::QtNode * const qtnode:
      ribi::cmap::GetQtNodes(d.m_widget->GetScene())
    )
    {
      QVERIFY(qtnode != nullptr);
      QVERIFY(qtnode->isVisible());
      #ifdef REALLY_CARE_20161008
      //All QtNodes' their rectangles should be within all_items_rect
      const QRectF all_items_rect {
        //d.m_widget->scene()->itemsBoundingRect() //Does not work
        //d.m_widget->scene()->sceneRect() //Does not work
        d.m_widget->sceneRect()
      };
      QVERIFY(all_items_rect.contains(qtnode->boundingRect()));
      #endif
    }
  }
}
Esempio n. 25
0
/*!
  Draw the marker

  \param painter Painter
  \param xMap x Scale Map
  \param yMap y Scale Map
  \param canvasRect Contents rectangle of the canvas in painter coordinates
*/
void QwtPlotMarker::draw( QPainter *painter,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    const QRectF &canvasRect ) const
{
    const QPointF pos( xMap.transform( d_data->xValue ), 
        yMap.transform( d_data->yValue ) );

    // draw lines

    drawLines( painter, canvasRect, pos );

    // draw symbol
    if ( d_data->symbol &&
        ( d_data->symbol->style() != QwtSymbol::NoSymbol ) )
    {
        const QSizeF sz = d_data->symbol->size();

        const QRectF clipRect = canvasRect.adjusted( 
            -sz.width(), -sz.height(), sz.width(), sz.height() );

        if ( clipRect.contains( pos ) )
            d_data->symbol->drawSymbol( painter, pos );
    }

    drawLabel( painter, canvasRect, pos );
}
Esempio n. 26
0
QVariant SceneItem::itemChange(GraphicsItemChange change, const QVariant& value) {
    if (scene() && change == QGraphicsItem::ItemPositionChange) {
        QPointF newPos = value.toPointF();
        // rect is adjusted so that items cannot be placed one tile to the right/bottom
        int adjust = -TILE_SIZE;
        QRectF rect = scene()->sceneRect().adjusted(0, 0, adjust, adjust);

        if (!rect.contains(newPos)) {
            // don't allow the item to be moved outside the scene
            newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left())));
            newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top())));
        }
        newPos.setX(round(newPos.x() / TILE_SIZE) * TILE_SIZE);
        newPos.setY(round(newPos.y() / TILE_SIZE) * TILE_SIZE);

        return newPos;
    } else if (change == QGraphicsItem::ItemPositionHasChanged) {
        // update the position of the sprite/exit (or whatever) based on the new position

        // TODO: generate undo/redo actions for movement somehow
        this->updateObject();
        return value;
    }

    return QGraphicsItem::itemChange(change, value);
}
Esempio n. 27
0
void OutputGLCanvas::drawForeground(QPainter *painter , const QRectF &rect)
{
  if (getMainWindow()->displayTestSignal())
  {
    glPushMatrix();
    painter->save();
    _drawTestSignal(painter);
    painter->restore();
    glPopMatrix();
  }
  else
  {
    MapperGLCanvas::drawForeground(painter, rect);

    // Display crosshair cursor.
    if (_displayCrosshair)
    {
      QPointF cursorPosition = mapToScene(cursor().pos());// - rect.topLeft();//(QCursor::pos());///*this->mapFromGlobal(*/QCursor::pos()/*)*/;
      if (rect.contains(cursorPosition))
      {
        painter->setPen(MM::CONTROL_COLOR);
        painter->drawLine(cursorPosition.x(), rect.y(), cursorPosition.x(), rect.height());
        painter->drawLine(rect.x(), cursorPosition.y(), rect.width(), cursorPosition.y());
      }
    }
  }

}
bool ShaderNodeUI::containsSceneSpace(const QPointF& point) const
{
	QRectF localRect = boundingRect();
	localRect.moveTo(pos().x(), pos().y());

	return localRect.contains(point);
}
Esempio n. 29
0
//! Wrapper for QPainter::drawRect()
void QwtPainter::drawRect( QPainter *painter, const QRectF &rect )
{
    const QRectF r = rect;

    QRectF clipRect;
    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );

    if ( deviceClipping )
    {
        if ( !clipRect.intersects( r ) )
            return;

        if ( !clipRect.contains( r ) )
        {
            fillRect( painter, r & clipRect, painter->brush() );

            painter->save();
            painter->setBrush( Qt::NoBrush );
            drawPolyline( painter, QPolygonF( r ) );
            painter->restore();

            return;
        }
    }

    painter->drawRect( r );
}
Esempio n. 30
0
QVariant Component::itemChange(GraphicsItemChange change,
		const QVariant &value) {
	if (change == ItemPositionChange && scene()) {
		int i = 0;


//		QList<Connection *> connectionlist = scene->getConnections();
//		qDebug() << "connections are " + QString::number(m);

//		foreach (Connection *connection, connections)
//			{
//				connection->updatePosition();
//				qDebug() << i++;
//			}
	}

	  if (change == ItemPositionChange && scene()) {
	         // value is the new position.
	         QPointF newPos = value.toPointF();
	         QRectF rect = scene()->sceneRect();
	         if (!rect.contains(newPos)) {
	             // Keep the item inside the scene rect.
	             newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left())));
	             newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top())));
	             return newPos;
	         }
	     }

	     return QGraphicsItem::itemChange(change, value);
}