Esempio n. 1
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();

}
Esempio n. 2
0
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);
}
Esempio n. 3
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 );
}
Esempio n. 4
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;
}
Esempio n. 5
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);
  }
}