Exemple #1
0
void MainWindow::drawnewconnect(int xxend, int yyend)
{
    QGraphicsScene *scene = new QGraphicsScene(ui->graphicsView);
    scene->setSceneRect(0,0,725,575);//розмір сцені
    ui->graphicsView->setAlignment(Qt::AlignLeft|Qt::AlignTop );
    connects u;
    parsanddrow d;
    QDebug qd= qDebug();
    qApp->applicationDirPath() +"C:/Users/Igro/build-vns_kma-Desktop_Qt_5_1_1_MinGW_32bit-Debug/24.jpeg";
    QPixmap pcc;
    QPixmap modem;
    QPixmap sw;
    QPainterPath path;
    QFont font;
    font.setPixelSize(50);
    //pcc.load("C:/Users/Igro/build-vns_kma-Desktop_Qt_5_1_1_MinGW_32bit-Debug/pc.png");
    pcc.load("pc.png");
    modem.load("modem.png");
    sw.load("sw.png");
    QString l; //назва приладу
    int xbeg;
    int ybeg;
    int xend;
    int yend;
    xend=xxend;
    yend=yyend;
    int dd; //кілкість приладів
    if(d.count(openfil())!=0)
    {
    dd=d.count(openfil());//кілкість рядків на 4 властивості отримаємо кілкість приладів
    d.cord(openfil());//заповнення масивік кординатами та іменами (and mac)

    for(int i=0;i<dd;i++)
    {
        if(d.getmac(i)==u.getbegin())
        {
            xbeg=d.getx(i);
            ybeg=d.gety(i);
        }
    }
    for(int h=0; h<dd; h++) //малювання
    {
        l=d.getdev(h);
                if(l=="sw")
                {
                    QGraphicsPixmapItem * a=scene->addPixmap(sw);
                    a->moveBy(d.getx(h),d.gety(h));
                    QFont font;
                    QPainterPath path;
                    a->setZValue(1);
                    font.setPixelSize(20);
                    font.setBold(false);
                    font.setFamily("Calibri");
                    path.addText(d.getx(h)-2,d.gety(h)+63,font,d.getname(h));
                    scene->addPath(path, QPen(QBrush(Qt::black), 1), QBrush(Qt::black));
                }
                if(l=="pc")
                {
                    QGraphicsPixmapItem * b=scene->addPixmap(pcc);
                    b->moveBy(d.getx(h),d.gety(h));
                    b->setZValue(1);
                    QFont font;
                    QPainterPath path;
                    font.setPixelSize(20);
                    font.setBold(false);
                    font.setFamily("Calibri");
                    path.addText(d.getx(h)-2,d.gety(h)+63,font,d.getname(h));
                    scene->addPath(path, QPen(QBrush(Qt::black), 1), QBrush(Qt::black));
                }
                if(l=="modem")
                {
                  QGraphicsPixmapItem * bc=scene->addPixmap(modem);
                  bc->moveBy(d.getx(h),d.gety(h));
                  bc->setZValue(1);
                  QFont font;
                  QPainterPath path;
                  font.setPixelSize(20);
                  font.setBold(false);
                  font.setFamily("Calibri");
                  path.addText(d.getx(h)-2,d.gety(h)+63,font,d.getname(h));
                  scene->addPath(path, QPen(QBrush(Qt::black), 1), QBrush(Qt::black));
                }
                if(l=="con")
                {   int xpoch[dd];
                    int ypoch[dd];
                    int xend[dd];
                    int yend[dd];
                    for(int i=0; dd>i;i++)
                    {
                        if(d.gatmacconnect1(h)==d.getmac(i))
                        {
                            xpoch[h]=d.getx(i);
                            ypoch[h]=d.gety(i);

                        }
                        else
                        if(d.gatmacconnect2(h)==d.getmac(i))
                        {
                            xend[h]=d.getx(i);
                            yend[h]=d.gety(i);

                        }
                    }
                    scene->addLine(QLineF(xpoch[h]+15, ypoch[h]+15, xend[h]+15, yend[h]+15), QPen(Qt::blue, 2));
                }
    scene->addLine(QLineF(xbeg+15, ybeg+15, xend, yend), QPen(Qt::blue, 2));
    }
    }
    ui->graphicsView->setScene(scene);
    ui->graphicsView->show();
    ui->graphicsView->scene()->installEventFilter(this);
    d.deletemas();
}
Exemple #2
0
void GraphicsWorker::run()
{
    qDebug() << "Starting graphics worker...";



    //Create scene with new keyword from heap so it does not disappear from the stack
    QGraphicsScene *scene = new QGraphicsScene();


    //If scene ref exists, delete old, else set a scene ref.
    if(!this->sceneRef)
    {
        this->sceneRef = scene;
    }
    else
    {
        delete this->sceneRef;
        this->sceneRef = scene;
    }


    QPainterPath *path = new QPainterPath(QPointF(0, 0));
    QPainter *painter = new QPainter();

    QPen pen = QPen(Qt::DashLine);


    //Draw axis
    scene->addLine(-100, 0, 100, 0, pen);
    scene->addLine(0, -100, 0, 100, pen);

    //


    //Access wavFile data
    if(wavFile.hexFormatChunkIdText != "fmt ")
    {
        //qDebug() << "error";
        //qDebug() << wavFile.hexFormatChunkIdText;
        exit(-1);
    }

    if (wavFile.formatAudioFormat != 1)
    {
        //qDebug() << "error, unsupported audio format.";
        exit(-1);
    }

    //continue
    //qDebug() << "good";
    int i;


    for(i=0;i<wavFile.hexDataChunk.size();i+= wavFile.formatBlockAlign*2)
    {
        // read signal


        if(wavFile.formatNumChannels == 1 && wavFile.formatBitsPerSample == 8)
        {
            bool ok;
            QByteArray sample = wavFile.hexDataChunk.mid(i, 2);
            int sampleValue = sample.toInt(&ok, 16);

            path->lineTo(i, sampleValue);
        }
        else if(wavFile.formatNumChannels == 1 && wavFile.formatBitsPerSample == 16)
        {
            QByteArray sample = wavFile.hexDataChunk.mid(i, 4);
            bool ok;
            int sampleValue = sample.toInt(&ok, 16);

            //2's complement
            if(sampleValue > 32767)
            {
                sampleValue = (sampleValue - 65535);
            }

            path->lineTo(i, sampleValue);

        }
        else if(wavFile.formatNumChannels == 2 && wavFile.formatBitsPerSample == 8)
        {
            QByteArray leftSample = wavFile.hexDataChunk.mid(i, 2);
            QByteArray rightSample = wavFile.hexDataChunk.mid(i+2, 2);
        }
        else if(wavFile.formatNumChannels == 2 && wavFile.formatBitsPerSample == 16)
        {
            QByteArray leftSample = wavFile.hexDataChunk.mid(i, 4);
            QByteArray rightSample = wavFile.hexDataChunk.mid(i+4, 4);
        }
    }

    painter->fillPath(*path, Qt::blue);

    scene->addPath(*path);



    //Change scene owner to mainThread
    scene->moveToThread(QApplication::instance()->thread());


    emit sceneReady(scene);

    delete path;
    delete painter;
}
Exemple #3
0
void MainWindow::drawinwindow()
{

    parsanddrow d;
    QGraphicsScene *scene = new QGraphicsScene(ui->graphicsView);
    scene->setSceneRect(0,0,725,575);//розмір сцені
    ui->graphicsView->setAlignment(Qt::AlignLeft|Qt::AlignTop );
    if(d.count(openfil())!=0)
    {
    QPixmap pcc;
    QPixmap modem;
    QPixmap sw;
    QPainterPath path;
    QFont font;
    font.setPixelSize(50);
    //pcc.load("C:/Users/Igro/build-vns_kma-Desktop_Qt_5_1_1_MinGW_32bit-Debug/pc.png");
    pcc.load("pc.png");
    modem.load("modem.png");
    sw.load("sw.png");
    QString l; //назва приладу
    QDebug qd= qDebug();
    int dd; //кілкість приладів
    dd=d.count(openfil());//кілкість рядків на 4 властивості отримаємо кілкість приладів
    d.cord(openfil());//заповнення масивік кординатами та іменами (and mac)
    if(dd)
    for(int h=0; h<dd; h++) //малювання
    {
        l=d.getdev(h);
                if(l=="sw")
                {
                    QGraphicsPixmapItem * a=scene->addPixmap(sw);
                    a->moveBy(d.getx(h),d.gety(h));
                    QFont font;
                    QPainterPath path;
                    a->setZValue(1);
                    font.setPixelSize(20);
                    font.setBold(false);
                    font.setFamily("Calibri");
                    path.addText(d.getx(h)-2,d.gety(h)+63,font,d.getname(h));
                    scene->addPath(path, QPen(QBrush(Qt::black), 1), QBrush(Qt::black));
                }
                if(l=="pc")
                {
                    QGraphicsPixmapItem * b=scene->addPixmap(pcc);
                    b->moveBy(d.getx(h),d.gety(h));
                    b->setZValue(1);
                    QFont font;
                    QPainterPath path;
                    font.setPixelSize(20);
                    font.setBold(false);
                    font.setFamily("Calibri");
                    path.addText(d.getx(h)-2,d.gety(h)+63,font,d.getname(h));
                    scene->addPath(path, QPen(QBrush(Qt::black), 1), QBrush(Qt::black));
                }
                if(l=="modem")
                {
                  QGraphicsPixmapItem * bc=scene->addPixmap(modem);
                  bc->moveBy(d.getx(h),d.gety(h));
                  bc->setZValue(1);
                  QFont font;
                  QPainterPath path;
                  font.setPixelSize(20);
                  font.setBold(false);
                  font.setFamily("Calibri");
                  path.addText(d.getx(h)-2,d.gety(h)+63,font,d.getname(h));
                  scene->addPath(path, QPen(QBrush(Qt::black), 1), QBrush(Qt::black));
                }
                if(l=="con")
                {   int xpoch[dd];
                    int ypoch[dd];
                    int xend[dd];
                    int yend[dd];
                    bool fir=false;
                    bool sec=false;
                    for(int i=0; dd>i;i++)
                    {
                        if(d.gatmacconnect1(h)==d.getmac(i))
                        {
                            xpoch[h]=d.getx(i);
                            ypoch[h]=d.gety(i);
                            fir=true;
                        }
                        else
                        if(d.gatmacconnect2(h)==d.getmac(i))
                        {
                            xend[h]=d.getx(i);
                            yend[h]=d.gety(i);
                            sec=true;
                        }

                    }
                    if(fir==false || sec==false)
                        {
                            d.delate(openfil(),h);
                        }

                    if(fir!=false && sec!=false)
                    scene->addLine(QLineF(xpoch[h]+15, ypoch[h]+15, xend[h]+15, yend[h]+15), QPen(Qt::blue, 2));
                }
                if((l!="modem")|(l!="sw")|(l!="pc"))
                {
                   qd<<l;
                }

     }
   // d.deletemas();
    }
    else
    {
        scene->clear();
    }

    ui->graphicsView->setScene(scene);
    ui->graphicsView->show();
    ui->graphicsView->scene()->installEventFilter(this);
}
const QImage loadThumb(const QString& fileName)
{
    QFile file(fileName);
    if(!file.open(QFile::ReadOnly | QFile::Text))
    {
        //Error opening file
        return QImage();
    }

    //Read
    EmbPattern* p = embPattern_create();
    if(!p) { return QImage(); }
    int readSuccessful = 0;
    QString readError;
    EmbReaderWriter* reader = embReaderWriter_getByFileName(qPrintable(fileName));
    if(!reader)
    {
        readSuccessful = 0;
    }
    else
    {
        readSuccessful = reader->reader(p, qPrintable(fileName));
    }
    free(reader);

    if(readSuccessful)
    {
        QGraphicsScene gscene;
        QPainterPath path;

        if(p->stitchList)
        {
            int previousColor = p->stitchList->stitch.color;

            EmbStitchList* curStitchItem = p->stitchList;
            while(curStitchItem)
            {
                EmbStitch tempStitch = curStitchItem->stitch;
                curStitchItem = curStitchItem->next;
                if((tempStitch.flags & STOP) || (tempStitch.flags & END))
                {
                    if(!path.isEmpty())
                    {
                        EmbColor thisColor = embThread_getAt(p->threadList, previousColor).color;
                        QPen loadPen(qRgb(thisColor.r, thisColor.g, thisColor.b));
                        loadPen.setWidthF(0.35);
                        loadPen.setCapStyle(Qt::RoundCap);
                        loadPen.setJoinStyle(Qt::RoundJoin);
                        gscene.addPath(path, loadPen);
                        previousColor = tempStitch.color;
                        path = QPainterPath();
                    }
                    path.moveTo(tempStitch.xx, -tempStitch.yy);
                }
                else if((tempStitch.flags & JUMP) || (tempStitch.flags & TRIM))
                {
                    path.moveTo(tempStitch.xx, -tempStitch.yy);
                }
                else
                {
                    path.lineTo(tempStitch.xx, -tempStitch.yy);
                }
            }
        }

        QImage sceneImg(gscene.width(), gscene.height(), QImage::Format_ARGB32);
        sceneImg.fill(QColor(0,0,0,0));

        QPainter painter(&sceneImg);
        gscene.render(&painter);
        return sceneImg;
    }
    embPattern_free(p);

    return QImage();
}