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;
}
Beispiel #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);
}
Beispiel #3
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;
}
Beispiel #4
0
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();
}
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);
}
Beispiel #6
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);
}
Beispiel #7
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);
        }
    }
}
Beispiel #8
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]);
}
/**
 * @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();
    }
}
Beispiel #10
0
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;
}
Beispiel #11
-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);
    }
}