QGraphicsItemGroup* SDefaultBrush::renderPath(QPainterPath path){
    QGraphicsItemGroup* pGroup = new QGraphicsItemGroup();

    QPen pen;
    QColor c1 = mColor;
    QColor c2 = mColor;
    int alpha1 = 3*mColor.alpha()/4;
    c1.setAlpha(alpha1);
    int alpha2 = alpha1*mHardness/100;
    c2.setAlpha(alpha2);
    pen.setColor(QColor(Qt::transparent));
    QRadialGradient gradient(500, 500, 500, 500, 500);
    gradient.setColorAt(0, c1);
    gradient.setColorAt(1, c2);
    QBrush brush(gradient);


    for(int i=0; i<path.length(); i+=(mWidth/2)*mSpacing){
        QGraphicsEllipseItem* pEllipse = new QGraphicsEllipseItem();
        pEllipse->setPen(pen);
        pEllipse->setBrush(brush);
        QPointF pt = path.pointAtPercent(path.percentAtLength(i));
        pEllipse->setRect(pt.x()-mWidth/2, pt.y()-mWidth/2, mWidth, mWidth);
        pGroup->addToGroup(pEllipse);
    }

    return pGroup;
}
示例#2
0
QGraphicsItemGroup *ProfileGraphicsView::plot_text(text_render_options_t *tro,const QPointF& pos, const QString& text, QGraphicsItem *parent)
{
    QFont fnt(font());
    QFontMetrics fm(fnt);

    if (printMode)
        fnt.setPixelSize(tro->size);

    QPointF point(SCALEGC(pos.x(), pos.y())); // This is neded because of the SCALE macro.
    double dx = tro->hpos * (fm.width(text));
    double dy = tro->vpos * (fm.height());

    QGraphicsItemGroup *group = new QGraphicsItemGroup(parent);
    QPainterPath textPath;
    /* addText() uses bottom-left text baseline and the -3 offset is probably slightly off
     * for different font sizes. */
    textPath.addText(0, fm.height() - 3, fnt, text);
    QPainterPathStroker stroker;
    stroker.setWidth(3);
    QGraphicsPathItem *strokedItem = new QGraphicsPathItem(stroker.createStroke(textPath), group);
    strokedItem->setBrush(QBrush(getColor(TEXT_BACKGROUND)));
    strokedItem->setPen(Qt::NoPen);

    QGraphicsPathItem *textItem = new QGraphicsPathItem(textPath, group);
    textItem->setBrush(QBrush(getColor(tro->color)));
    textItem->setPen(Qt::NoPen);

    group->setPos(point.x() + dx, point.y() + dy);
    if (!printMode)
        group->setFlag(QGraphicsItem::ItemIgnoresTransformations);

    if (!parent)
        scene()->addItem(group);
    return group;
}
示例#3
0
文件: slideshow.cpp 项目: callaa/Piqs
Slideshow::Slideshow(Gallery *gallery, ThumbnailModel *model, QVector<int> selection, QWidget *parent) :
	QGraphicsView(parent), m_gallery(gallery), m_model(model), m_selection(selection), m_picture(0)
{
	setWindowTitle(tr("Slideshow"));
	setAttribute(Qt::WA_DeleteOnClose, true);
	setWindowFlags(windowFlags() | Qt::Window);
	setFrameShape(QFrame::NoFrame);
	setFocusPolicy(Qt::StrongFocus);

	m_scene = new QGraphicsScene();
	m_scene->setBackgroundBrush(Qt::black);

	setScene(m_scene);
	setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	setInteractive(false);
	setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);

	m_slidetimer = new QTimer(this);
	connect(m_slidetimer, SIGNAL(timeout()), this, SLOT(nextSlide()));

	// Construct the pause glyph
	QGraphicsLineItem *p1 = new QGraphicsLineItem(QLineF(20, 20, 20, 70));
	QGraphicsLineItem *p2 = new QGraphicsLineItem(QLineF(60, 20, 60, 70));
	QPen pen;
	pen.setWidth(15);
	pen.setCapStyle(Qt::RoundCap);
	pen.setColor(Qt::white);
	p1->setPen(pen);
	p2->setPen(pen);

	QGraphicsItemGroup *pauseglyph = new QGraphicsItemGroup();
	pauseglyph->setZValue(100);
	pauseglyph->addToGroup(p1);
	pauseglyph->addToGroup(p2);
	addShadowEffect(pauseglyph);

	pauseglyph->hide();
	m_pauseglyph = pauseglyph;
	m_scene->addItem(m_pauseglyph);

	// Construct timer text item
	m_timertext = new QGraphicsTextItem();
	m_timertext->setZValue(100);
	QFont font;
	font.setPixelSize(20);
	m_timertext->setFont(font);
	m_timertext->setDefaultTextColor(Qt::white);
	setTimerText();
	addShadowEffect(m_timertext);

	m_timertext->hide();
	m_scene->addItem(m_timertext);

	m_scalefill = gallery->database()->getSetting("slideshow.scale").toString() == "fill";
	m_upscale = gallery->database()->getSetting("slideshow.upscale").toBool();
}
示例#4
0
void ULLineEditor::slotEditGroup ( QGraphicsItem * git )
{
	if ( editing )
		validateLine();
	editing = true;
	reedit = true;
// 	qDebug() << git->data ( 1 ).toString() << ":" << git->data ( 2 ).toUInt() ;
	QGraphicsItemGroup * gr = static_cast<QGraphicsItemGroup*> ( git );
	QList<QGraphicsItem*> lgr =  gr->children();
	double realwidth = 0;
	reeditPos = gr->scenePos();
	reedit_id = gr->data ( 2 ).toUInt();
	
	slotChangeBaseLine ( gr->data ( 3 ).toDouble() );
	slotChangeWidth ( gr->data ( 4 ).toDouble() );
	slotMoveCursor ( gr->data ( 5 ).toDouble() );
	slotLTR(gr->data( 6 ).toInt() == 1 ? Qt::Checked : Qt::Unchecked);
	
	gr->setPos ( 0.0, 0.0 );
	addItem ( gr );
	destroyItemGroup ( gr );
	
	for ( uint i = 0; i < lgr.count(); ++i )
	{
// 		lgr[i]->clearFocus();
		lgr[i]->setSelected ( false );
	}


// 	adjust();
	glyphs.clear();
	glyphs = PageBuffer::getInstance()->take ( reedit_id, false );
}
void TextFormulaNode::RenderCaret(const int pos, const int anchor)
{
	QRectF r = GetDocumentPosBounds(pos);
	
	QGraphicsItemGroup* g = wnd->caret->caretShape;
	
	qDeleteAll(g->childItems());
	g->childItems().clear();
	
	QGraphicsLineItem* i = new QGraphicsLineItem(r.left(), r.top(), r.left(), r.bottom(), g);
	i->setPen(QPen("red"));
	g->addToGroup(i);
}
示例#6
0
void MapScene::fixSymbol(float timeValue, QColor color, QVariant trackId)
{
    //FIXME !!
    TrackItem* targetTrack(NULL);
    int idTrack(-1);

    qDebug() << "fixSymbol :" << this->_tracks.count() << this->_tracks;

    for (int i(0); idTrack == -1 && i < this->_tracks.count(); i++)
    {
        TrackItem* tr = this->_tracks[i];

        if (tr->id() == trackId)
        {
            idTrack = i;
            targetTrack = tr;
        }
    }

    if (idTrack != -1)
    {
        qDebug() << "track found";

        CoordinateItem* nearestCoord = targetTrack->nearestCoord(timeValue);

        if (nearestCoord != NULL)
        {
            qDebug() << "nearest coord found";

            TickItem* tick = new TickItem(false);
            tick->setPos(nearestCoord->pos());
            tick->setZValue(10);
            tick->setColor(color);

            QGraphicsItemGroup* symbolGroup;

            if (!this->_symbols.contains(idTrack))
            {
                symbolGroup = new QGraphicsItemGroup;
                this->addItem(symbolGroup);
                this->_symbols[idTrack] = symbolGroup;
            }
            else
            {
                symbolGroup = this->_symbols[idTrack];
            }

            symbolGroup->addToGroup(tick);
        }
    }
}
示例#7
0
/// Adds a caption for a graph beneath the actual diagram.
void DiagramScene::addCaption(const QString &name, QPen &pen)
{
	QGraphicsItemGroup* caption = new QGraphicsItemGroup(NULL);
	QGraphicsLineItem* l = addLine(0,0,100,0,pen);
	QGraphicsTextItem* t = addText(name);
	l->setPos(0,0);
	t->setPos(110, -(t->boundingRect()).height() / 2);
	caption->addToGroup(l);
	caption->addToGroup(t);
	caption->setFlag(QGraphicsItem::ItemIgnoresTransformations, true);

	_graphCaptions.push_back(caption);
	addItem(_graphCaptions[_graphCaptions.size() - 1]);
}
示例#8
0
void QGVPage::removeQViewFromScene(QGIView *view)
{
    QGraphicsItemGroup* grp = view->group();
    if (grp) {
        grp->removeFromGroup(view);
    }

    if (view->parentItem()) {    //not top level
        view->setParentItem(0);
    }

    if (view->scene()) {
        view->scene()->removeItem(view);
    }
}
示例#9
0
QGraphicsItemGroup* Document::grid()
{
  QGraphicsItemGroup *group = new QGraphicsItemGroup();
  group->setZValue(-1.0);

  QPen gridPen(QBrush(QColor("#DDDDDD")), 0.0);
  QPen gridPenDec(QBrush(QColor("#AAAAAA")), 0.0);
  QPen *activePen;
  double margin;

  for (int i = 0; i < size_.height() + 1; ++i) {
    if (i % 10 == 0) {
      margin = 10.0;
      activePen = &gridPenDec;
    } else {
      margin = 5.0;
      activePen = &gridPen;
    }

    QGraphicsLineItem *line = new QGraphicsLineItem(-margin,
                                                    10.0 * i,
                                                    10.0 * size_.width() + margin,
                                                    10.0 * i,
                                                    group);
    line->setPen(*activePen);
  }

  for (int i = 0; i < size_.width() + 1; ++i) {
    if (i % 10 == 0) {
      margin = 10.0;
      activePen = &gridPenDec;
    } else {
      margin = 5.0;
      activePen = &gridPen;
    }

    QGraphicsLineItem *line = new QGraphicsLineItem(10.0 * i,
                                                    -margin,
                                                    10.0 * i,
                                                    10.0 * size_.height() + margin,
                                                    group);
    line->setPen(*activePen);
  }

  return group;
}
示例#10
0
QGraphicsItemGroup* MainWindow::createVisualNodo(string* names, int cant){
    QGraphicsItemGroup* grupo = new QGraphicsItemGroup();
    int posx = 0;
    int dim = 50;

    for(int x = 0; x < cant; x++){
        QGraphicsRectItem* cuadro = new QGraphicsRectItem(posx,0,50,50);
        cuadro->setBrush(QBrush(Qt::gray));
        QGraphicsTextItem* texto = new QGraphicsTextItem();
        texto->setPos(posx, dim/3);
        texto->setPlainText(QString::fromStdString(names[x]));
        grupo->addToGroup(cuadro);
        grupo->addToGroup(texto);
        posx+=dim;
    }
    return grupo;
}
示例#11
0
QList< QGraphicsItem * > UMLScene::getGroupingList()
{
	QList< QGraphicsItem * > selectedList( this->selectedItems() );
	QSet< QGraphicsItem * > roots;

	QListIterator < QGraphicsItem * > iter( selectedList );
	while( iter.hasNext() ) {
		QGraphicsItem * item = iter.next();
		QGraphicsItemGroup * itemGroup = item->group();
		while( itemGroup && itemGroup->group() ) {
			itemGroup = itemGroup->group();
		}
		
		roots.insert( itemGroup ? itemGroup : item );
	}

	return roots.toList();
}
示例#12
0
/**
 * @brief cwScreenCaptureManager::capturedImage
 * @param image
 */
void cwCaptureViewport::capturedImage(QImage image, int id)
{
    Q_UNUSED(id)

    Q_ASSERT(CapturingImages);

    QPointF origin = IdToOrigin.value(id);

    QGraphicsItemGroup* parent = previewCapture() ? PreviewItem : Item;

    cwGraphicsImageItem* graphicsImage = new cwGraphicsImageItem(parent);
    graphicsImage->setImage(image);
    graphicsImage->setPos(origin);
    parent->addToGroup(graphicsImage);

    //For debugging tiles
//    QRectF tileRect = QRectF(origin, image.size());
//    QGraphicsRectItem* rectItem = new QGraphicsRectItem(parent);
//    rectItem->setPen(QPen(Qt::red));
//    rectItem->setRect(tileRect);
//    QGraphicsSimpleTextItem* textItem = new QGraphicsSimpleTextItem(parent);
//    textItem->setText(QString("Id:%1").arg(id));
//    textItem->setPen(QPen(Qt::red));
//    textItem->setPos(tileRect.center());

    NumberOfImagesProcessed++;

    if(NumberOfImagesProcessed == Rows * Columns) {
        //Finished capturing images
        NumberOfImagesProcessed = 0;
        Rows = 0;
        Columns = 0;
        CapturingImages = false;

        if(previewCapture()) {
            updateBoundingBox();
        }

        emit finishedCapture();
    }
}
示例#13
0
文件: Buoy.cpp 项目: emoratac/devel
void Buoy::render(QGraphicsItemGroup *layer) {

	QPointF origo(0,0);

	QGraphicsPixmapItem *buoyItem = new QGraphicsPixmapItem(buoy);
	buoyItem->setPos(origo);

        QRectF bb = buoyItem->boundingRect();
        //buoyItem->rotate(90.0f);
        //buoyItem->translate(-bb.width()/2.0f, -bb.height());
        buoyItem->setOffset(-bb.width()/2, -bb.height()*0.8);
        QGraphicsPixmapItem *coneItem = new QGraphicsPixmapItem(lightCone);
        coneItem->setPos(origo);
        coneItem->rotate(180 + lightConeRotation);
        //coneItem->rotate(lightConeRotation);

        bb = coneItem->boundingRect();
        //coneItem->translate(-bb.width()/2.0f, -bb.height());
        coneItem->setOffset(-bb.width()/2, -bb.height()*0.8);
        QGraphicsItemGroup* group = new QGraphicsItemGroup();

        group->addToGroup(buoyItem);
        group->addToGroup(coneItem);
        //group->scale(0.000025, 0.000025);
        group->scale(0.25, 0.25);
	group->setZValue(6.5);
	group->setPos(position);
	group->setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
	//TODO: check if i should give and offset to the pixmaps

	layer->addToGroup(group);
}
示例#14
0
void Canvas::setSceneRect(qreal x, qreal y, qreal w, qreal h)
{
    currentScene->setSceneRect(x, y, w, h);

    qreal borderWidth = 0.5;
    QPen borderPen(QBrush(Qt::black), borderWidth);
    borderPen.setCapStyle(Qt::SquareCap);
    borderPen.setJoinStyle(Qt::MiterJoin);

    qreal shadowWidth = 5;
    QPen shadowPen(QBrush(Qt::lightGray), shadowWidth);
    shadowPen.setCapStyle(Qt::SquareCap);
    shadowPen.setJoinStyle(Qt::MiterJoin);

    QGraphicsItemGroup * group = new QGraphicsItemGroup;

    QGraphicsLineItem * shadowRight =
            new QGraphicsLineItem(x + w + (shadowWidth - borderWidth) / 2,
                                  y + shadowWidth,
                                  x + w + (shadowWidth - borderWidth) / 2,
                                  y + h + shadowWidth / 2);
    shadowRight->setPen(shadowPen);

    QGraphicsLineItem * shadowBottom =
            new QGraphicsLineItem(x + shadowWidth,
                                  y + h + (shadowWidth - borderWidth) / 2,
                                  x + w + shadowWidth / 2,
                                  y + h + (shadowWidth - borderWidth) / 2);
    shadowBottom->setPen(shadowPen);

    QGraphicsRectItem * rect = new QGraphicsRectItem(x, y, w, h);
    rect->setPen(borderPen);

    group->addToGroup(shadowRight);
    group->addToGroup(shadowBottom);
    group->addToGroup(rect);

    currentScene->addItem(group);
}
示例#15
0
void FrameView::addShape( const QVector<QPoint>& Shape )
{
  for(qint16 pointIndex(0); pointIndex < Shape.size(); pointIndex++)
  {
    Qt::GlobalColor color(getPointColorByIndex(pointIndex+1));
    QPen Pen(color);
    QList<QGraphicsItem*> pointGroupList;
    QGraphicsLineItem* line1(new QGraphicsLineItem(-POINT_SIZE, 0, POINT_SIZE, 0));
    line1->setPen(Pen);
    pointGroupList.push_back(line1);
    QGraphicsLineItem* line2(new QGraphicsLineItem(0, -POINT_SIZE, 0, POINT_SIZE));
    line2->setPen(Pen);
    pointGroupList.push_back(line2);
    QGraphicsTextItem* label(new QGraphicsTextItem(QString::number(pointIndex)));
    label->setDefaultTextColor(color);
    label->setFont(POINT_TEXT_FONT);
    label->setPos(-2*POINT_SIZE, -2.5f*POINT_SIZE);
    pointGroupList.push_back(label);

    QGraphicsItemGroup* pointGroup = Scene->createItemGroup(pointGroupList);
    pointGroup->setPos(QPointF(Shape[pointIndex]) * Scale);
  }
}
示例#16
0
文件: GIFactory.cpp 项目: fer-rum/q2d
QGraphicsItem*
GIFactory::createComponentGI(
    ComponentDescriptor* type) {

    qDebug() << "Generating Graphics item for" << type->text();

    // collect all the information
    QString componentName = type->text();

    QGraphicsItemGroup* parent = new QGraphicsItemGroup();

    // create all the partial items and calculate sizes

    unsigned int inSection_minWidth = 0;
    unsigned int outSection_minWidth = 0;
    unsigned int portSection_lineHeight = 0;

    QList<PortEntry> inPorts = QList<PortEntry>();
    QList<PortEntry> outPorts = QList<PortEntry>();
    for (PortDescriptor * port : type->ports()) {


        PortEntry portEntry = PortEntry(port, parent);
        unsigned int width = portEntry.textGraphics()->boundingRect().width() + 2 * TEXT_PADDING;
        unsigned int height = portEntry.textGraphics()->boundingRect().height() + 2 * TEXT_PADDING;

        // adjust the line height, if needed
        if (height > portSection_lineHeight) {
            portSection_lineHeight = height;
        }

        switch (port->direction()) {
        case model::enums::PortDirection::IN : {
            inPorts.append(portEntry);
            if (width > inSection_minWidth) {
                inSection_minWidth = width;
            }
        }
        break;

        case model::enums::PortDirection::OUT : {
            outPorts.append(portEntry);
            if (width > outSection_minWidth) {
                outSection_minWidth = width;
            }
        }
        break;
        default:
            continue; // do not handle other types.
        }

    }

    std::sort(inPorts.begin(), inPorts.end());
    std::sort(outPorts.begin(), outPorts.end());


    unsigned int portSection_height =
        inPorts.count() > outPorts.count() ?
        inPorts.count() * portSection_lineHeight :
        outPorts.count() * portSection_lineHeight;

    QGraphicsTextItem* text_compName = new QGraphicsTextItem(componentName, parent);
    parent->addToGroup(text_compName);

    unsigned int nameSection_minWidth = text_compName->boundingRect().width() + 2 * TEXT_PADDING;
    unsigned int nameSection_height = text_compName->boundingRect().height() + 2 * TEXT_PADDING;

    // adjust the total width
    unsigned int totalWidth  = 0;
    if (nameSection_minWidth > (inSection_minWidth + outSection_minWidth)) {
        totalWidth = nameSection_minWidth;
        if (inSection_minWidth > totalWidth / 2) { // extend outSection_minWidth
            outSection_minWidth = totalWidth - inSection_minWidth;
        } else if (outSection_minWidth > totalWidth / 2) { // extend inSection_minWidth
            inSection_minWidth = totalWidth - outSection_minWidth;
        } else { // stretch both to totalWidth / 2
            inSection_minWidth = totalWidth / 2;
            outSection_minWidth = totalWidth / 2;
        }
    } else { // adjust nameSection_minWidth
        totalWidth = inSection_minWidth + outSection_minWidth;
    }

    // now actually place all the stuff
    QBrush nameSectionBrush = QBrush(Qt::lightGray, Qt::SolidPattern);
    QBrush portSectionBrush = QBrush(Qt::white, Qt::SolidPattern);
    QPen pen = QPen(Qt::black, Qt::SolidLine);
    QPoint currentPos = QPoint(0, 0);

    // draw the rectangles
    QGraphicsRectItem* nameSection = new QGraphicsRectItem(
        currentPos.x(), currentPos.y(),
        totalWidth, nameSection_height, parent);
    nameSection->setBrush(nameSectionBrush);
    nameSection->setPen(pen);
    nameSection->setZValue(-1);
    parent->addToGroup(nameSection);

    currentPos.ry() += nameSection_height;
    QGraphicsRectItem* inSection = new QGraphicsRectItem(
        currentPos.x(), currentPos.y(),
        inSection_minWidth, portSection_height, parent);
    inSection->setBrush(portSectionBrush);
    inSection->setPen(pen);
    inSection->setZValue(-1);
    parent->addToGroup(inSection);

    currentPos.rx() += inSection_minWidth;
    QGraphicsRectItem* outSection = new QGraphicsRectItem(
        currentPos.x(), currentPos.y(),
        outSection_minWidth, portSection_height, parent);
    outSection->setBrush(portSectionBrush);
    outSection->setPen(pen);
    outSection->setZValue(-1);
    parent->addToGroup(outSection);

    // place the texts and set the port positions in the port descriptor
    text_compName->setPos((totalWidth - text_compName->boundingRect().width()) / 2,
                          /*0 + */ TEXT_PADDING);

    currentPos.setX(0);
    currentPos.setY(nameSection_height);
    for(PortEntry inIter : inPorts){
        inIter.textGraphics()->setPos(currentPos.x() + TEXT_PADDING, currentPos.y() + TEXT_PADDING);
        currentPos.ry() += portSection_lineHeight / 2;
        QPoint portPos = QPoint(currentPos.x() - PORT_DIAMETER, currentPos.y());
        inIter.descriptor()->setPosition(portPos);

        QGraphicsLineItem* lineToPort = new QGraphicsLineItem(QLineF(portPos, currentPos), parent);
        parent->addToGroup(lineToPort);
        currentPos.ry() += portSection_lineHeight / 2;
    }

    currentPos.setX(totalWidth);
    currentPos.setY(nameSection_height);
   for(PortEntry outIter : outPorts){
        outIter.textGraphics()->setPos(
            currentPos.x() - TEXT_PADDING - outIter.textGraphics()->boundingRect().width(),
            currentPos.y() + TEXT_PADDING);
        currentPos.ry() += portSection_lineHeight / 2;
        QPoint portPos = QPoint(currentPos.x() + PORT_DIAMETER, currentPos.y());
        outIter.descriptor()->setPosition(portPos);

        QGraphicsLineItem* lineToPort = new QGraphicsLineItem(QLineF(currentPos, portPos), parent);
        parent->addToGroup(lineToPort);
        currentPos.ry() += portSection_lineHeight / 2;
    }

    parent->setVisible(true);
    return parent;
}
示例#17
0
/*!
    \fn ULLineEditor::validateLine()
 */
void ULLineEditor::validateLine()
{
// 	clearPreview();
	editing = false;
//	QPainterPath  sel;
//	sel.addRect ( sceneRect() );
//	setSelectionArea ( sel );
	QList<QGraphicsItem*> l;
	foreach(QGraphicsItem* gi, glyphs)
	{
		l << gi;
	}

	QGraphicsItemGroup * g = createItemGroup (l);
//	g->setSelected(false);
//	foreach(QGraphicsItem* i, g->childItems())
//	{
//		i->setSelected(false);
//	}

	m_mainScene->addItem ( g );
	g->setFlags ( QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable);
	g->setData ( 1,"group" );
	qDebug() << "set data 3 to "<<m_baseLine;
	g->setData ( 3,QVariant ( m_baseLine ) );
	g->setData ( 4,m_marginRight );
	g->setData ( 5,m_curPpos );
	g->setData( 6, (ltr ? 1 : 0) );
	g->setZValue ( 10.0 );
	g->setHandlesChildEvents ( true );
	if ( reedit )
	{
		g->setPos ( reeditPos );
// 		g->moveBy(0.0,-(g->boundingRect().height()));
		g->setData ( 2, QVariant ( reedit_id ) );
		PageBuffer::getInstance()->insert ( reedit_id,glyphs );
		reedit = false;
	}
	else
	{
		g->setData ( 2, QVariant ( PageBuffer::getInstance()->put ( glyphs ) ) );
		g->setPos ( m_mainScene->cur_pos );
		g->moveBy ( 0.0,-m_baseLine );
		m_mainScene->setCur ( m_mainScene->cur_pos.x(), m_mainScene->cur_pos.y() + m_baseLine );
	}
	m_mainScene->views() [0]->centerOn ( g );
	m_curPpos = 0.0;
	adjust();
	glyphs.clear();
	keyLast.clear();
	emit isValidate();

}
示例#18
0
void EnhancedGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent)
{
    static int cnt = 0;
    QPointF mousePosition = mouseEvent->scenePos();
    QGraphicsItem* pItem = itemAt(mousePosition.x(), mousePosition.y(), QTransform());

    if (pItem == 0)
    {
        if(!rot && !selectedItems().isEmpty())
        {
            QGraphicsScene::mouseMoveEvent(mouseEvent);
            return;
        }
    }
    else if (pItem->isSelected() == false && !rot && !selectedItems().isEmpty())
    {
        QGraphicsScene::mouseMoveEvent(mouseEvent);
        return;
    }

    // We want to move the items only if the mouse is clicked and not in rubberband
    if((rubberBandOn == false) && clicked)
    {
        if(rot)
        {
            QLog_Info(LOG_ID_INFO, "entering rotation code");
            // we must find the most east point of all selected object as well
            // as the most west point. With this, we determine if we turn around
            // one or the other
            QList<QGraphicsItem*> selectionList = selectedItems();
            QGraphicsItemGroup *group = createItemGroup(selectionList);

            // Get the bounding rect of the group to determine the rotation
            if(firstRot)
            {
                // Calculate X coordinate of the center of the top segment, we need to separate cases if there is only
                // one selected object, and to use this object's bounding rect. Otherwise, the bounding rect of the group
                // won't fit the object
                qreal center = 0;
                if(selectionList.size() == 1)
                {
                    center = (selectionList.first()->mapToScene(0,0).x() + selectionList.first()->mapToScene(selectionList.first()->boundingRect().topRight()).x()) / 2;
                }
                else
                    center = group->boundingRect().center().x();

                if(mouseEvent->scenePos().x() < center)
                {
                    originPoint = findRotationPivot(selectionList, false);
                    previousRot = 0;
                }
                else
                {
                    originPoint = findRotationPivot(selectionList, true);
                    previousRot = 0;
                }

                // Check the rotation offset of the position of the mouse
                qreal a1 = mouseEvent->scenePos().x() - originPoint.x();
                qreal a2 = mouseEvent->scenePos().y() - originPoint.y();
                previousAngle = qAtan2(a2, a1);

                firstRot = false;
            }

            qreal a1 = mouseEvent->scenePos().x() - originPoint.x();
            qreal a2 = mouseEvent->scenePos().y() - originPoint.y();
            qreal angle = qAtan2(a2, a1);

            QTransform trans;
            trans.translate(originPoint.x(), originPoint.y())
                    .rotate(-previousRot)
                    .rotate(( (angle - previousAngle) * 180 / 3.14))
                    .translate(-originPoint.x(), -originPoint.y());

            previousRot = ((angle - previousAngle) * 180 / 3.14);

            group->setTransform(trans, true);

            // group must be destroyed so that we can interact with the items
            destroyItemGroup(group);
        }

        if(cnt++ % 6 == 0)
        {
            cnt = 0;
            refreshItemPositionsOnNetwork();
        }
        // In case of a rotation, we don't want the graphics items
        // to get the mouse move event, so we return without
        // calling mouse move event of qgraphicsscene
        if(rot) return;
    }

    QGraphicsScene::mouseMoveEvent(mouseEvent);
}
示例#19
-4
BoardScene::BoardScene(const SLFormat::Board* inBoard, QWidget* inParent)
    :QGraphicsScene(inParent), mBoard(inBoard)
{
    this->setSceneRect(0, 0, mBoard->size().x, mBoard->size().y);

    // background
    const unsigned activeLayer = mBoard->activeLayer();
    QBrush brush(gSettings().backgroundColor());
    QPen pen(brush.color());
    mBackground = this->addRect(this->sceneRect(), pen, brush);

    // ground planes (initially invisible)
    for (unsigned i = 0; i < SLFormat::Board::cNumberLayers; i++)
    {
        unsigned layer = gSettings().layerFromOrderNumber(i);
        if (mBoard->isGroundPlaneSupported(layer))
        {
            QGraphicsItemGroup* plane = new QGraphicsItemGroup;
            mGroundPlanes[layer] = plane;

            addItem(plane);
            plane->setVisible(false);

            auto rect = new QGraphicsRectItem(this->sceneRect());
            const QColor color = gSettings().groundPlaneLayerColor(layer);
            rect->setBrush(QBrush(color));
            rect->setPen(QPen(color));
            plane->addToGroup(rect);
        }
        else
        {
            mGroundPlanes[layer] = nullptr;
        }
    }

    // grid
    mGrid = new BoardGrid(mBoard);
    addItem(mGrid);

    // layers
    for (unsigned i = 0; i < SLFormat::Board::cNumberLayers; i++)
    {
        unsigned layer = gSettings().layerFromOrderNumber(i);
        mLayerGroups[layer] = new QGraphicsItemGroup;
        addItem(mLayerGroups[layer]);
    }

    mDrillHoles = new QGraphicsItemGroup;
    addItem(mDrillHoles);

    // components on layers
    for (auto comp : mBoard->components())
    {
        ComponentItem* item = ComponentFactory::createItem(comp);
        if (item)
        {
            unsigned layer = comp->layer();
            mLayerGroups[layer]->addToGroup(item->mainItem());
            if (mBoard->isGroundPlaneSupported(layer))
            {
                mGroundPlanes[layer]->addToGroup(item->groundPlaneItem());
            }
            mDrillHoles->addToGroup(item->drillItem());
        }
    }

    // show ground plane for active layer
    if (mBoard->isGroundPlaneEnabled(activeLayer))
    {
        assert(mGroundPlanes[activeLayer]);
        mGroundPlanes[activeLayer]->setVisible(true);
    }
}