void MainWindow::addRectangle() { BouncingRectangle* newRectangle = new BouncingRectangle(rand()%250, rand()%250, 20.0, 20.0, rand()%6, rand()%6); QBrush redBrush(Qt::red); QBrush blueBrush(Qt::blue); QBrush greenBrush(Qt::green); QBrush yellowBrush(Qt::yellow); int color = rand()%5; switch(color) { case 0: newRectangle->setBrush( redBrush ); break; case 1: newRectangle->setBrush( blueBrush ); break; case 2: newRectangle->setBrush( greenBrush ); break; case 3: newRectangle->setBrush( yellowBrush ); break; } rectangles.push_back(newRectangle); scene->addItem( newRectangle ); }
void MainWindow::on_pushButton_clicked() { QGraphicsEllipseItem *ellipse2; QGraphicsTextItem *texto; QBrush redBrush(Qt::red); //QBrush blueBrush(Qt::blue); QPen blackPen(Qt::black); blackPen.setWidth(1); ellipse1 = scene->addEllipse(0, 10, 100, 100, blackPen, redBrush); ellipse2 = scene->addEllipse(500, 10, 100, 100, blackPen, redBrush); ellipse1->setAcceptDrops(true); ellipse2->setAcceptDrops(true); ellipse1->setFlag(QGraphicsItem::ItemIsMovable, true); texto = new QGraphicsTextItem(); texto->setPos(0,50); texto->setPlainText("Nodo X"); Nodo1->addToGroup(ellipse1); Nodo1->addToGroup(texto); Nodo1->setAcceptDrops(true); Nodo1->setFlag(QGraphicsItem::ItemIsMovable, true); scene->addItem(Nodo1); ui->painter->setAcceptDrops(true); ui->painter->setScene(scene); ui->painter->scale(currentScale,currentScale); }
static void addOneRecordToModel(const data::AccountReceivableRecord & record , QStandardItemModel * model , bool isChecked) { QList<QStandardItem *> row; row.append(new QStandardItem); row.append(new QStandardItem(record.date.toString("yyyy-MM-dd"))); row.append(new QStandardItem(record.product.category.name)); row.append(new QStandardItem(record.product.name)); row.append(new QStandardItem(QString("%1").arg(record.quantity))); if (0 == record.price) { QBrush redBrush(Qt::red); QStandardItem * item = new QStandardItem(QObject::tr("Please assign unzero price")); item->setForeground(redBrush); row.append(item); } else { row.append(new QStandardItem(QString("%1").arg(record.quantity * record.price))); } row.first()->setCheckable(true); row.first()->setCheckState(isChecked ? Qt::Checked : Qt::Unchecked); for (int i = 0; i < row.size(); ++i) row[i]->setEditable(false); model->appendRow(row); }
MainWindow::MainWindow() { //We need a scene and a view to do graphics in QT scene = new QGraphicsScene(); view = new QGraphicsView( scene ); //This adds a button to the window and connects it to the timer button = new QPushButton("Start/Stop", view); connect(button, SIGNAL(clicked()), this, SLOT(buttonPress())); //To fill a rectangle use a QBrush. To draw the border of a shape, use a QPen QBrush redBrush(Qt::red); //First 2 arguments are the x, y, of the upper left of the rectangle. //The second 2 arguments are the width and height //The last 2 arguments are the velocity in the x, and y, directions item = new BouncingRectangle( 11.0, 74.0, 20.0, 20.0, 2, 3 ); item->setBrush( redBrush ); scene->addItem( item ); //This sets the size of the window and gives it a title. view->setFixedSize( WINDOW_MAX_X*2, WINDOW_MAX_Y*2 ); view->setWindowTitle( "Bouncing Rectangles!"); //This is how we do animation. We use a timer with an interval of 5 milliseconds //We connect the signal from the timer - the timeout() function to a function //of our own - called handleTimer - which is in this same MainWindow class timer = new QTimer(this); timer->setInterval(5); connect(timer, SIGNAL(timeout()), this, SLOT(handleTimer())); timer2 = new QTimer(this); timer2->setInterval(250); connect(timer2, SIGNAL(timeout()), this, SLOT(addRectangle())); }
dialogSmithChart::dialogSmithChart(QWidget *parent) : QDialog(parent), ui(new Ui::dialogSmithChart) { ui->setupUi(this); resize(430,400); scene = new QGraphicsScene(this); ui->graphicsView->setScene(scene); QBrush redBrush(Qt::red); QBrush blueBrush(Qt::blue); QPen blackPen(Qt::black); //ell = scene->addEllipse(10,10,100,100,blackPen,redBrush); QPainterPath* path = new QPainterPath(); path->arcMoveTo(0,0,50,50,20); path->arcTo(0,0,50,50,20, 90); scene->addPath(*path); //ui->graphicsView->sc //h = 430; w = 400 // centerX = 195; // CenterY = 191; }
void Canvas::paint() { QBrush redBrush(Qt::red); QPen redPen(Qt::red); redPen.setWidth(2); this->addEllipse((int)links[2]->frontAxis->loc_x - PAINTER_DIAMETER/2,(int)links[2]->frontAxis->loc_y - PAINTER_DIAMETER/2, PAINTER_DIAMETER,PAINTER_DIAMETER,redPen,redBrush); //painter->addPoint((int)links[2]->frontAxis->loc_x, (int)links[2]->frontAxis->loc_y); //painter->update(); }
void TupColorPalette::setBaseColorsPanel() { #ifndef Q_OS_ANDROID QSize cellSize(50, 30); #else QSize cellSize(70, 50); #endif k->currentBaseColor = 0; QColor redColor(255, 0, 0); QBrush redBrush(redColor, k->brush.style()); TupColorWidget *red = new TupColorWidget(0, redBrush, cellSize, false); red->selected(); connect(red, SIGNAL(clicked(int)), this, SLOT(updateMatrix(int))); k->baseColors << red; QColor greenColor(0, 255, 0); QBrush greenBrush(greenColor, k->brush.style()); TupColorWidget *green = new TupColorWidget(1, greenBrush, cellSize, false); connect(green, SIGNAL(clicked(int)), this, SLOT(updateMatrix(int))); k->baseColors << green; QColor blueColor(0, 0, 255); QBrush blueBrush(blueColor, k->brush.style()); TupColorWidget *blue = new TupColorWidget(2, blueBrush, cellSize, false); connect(blue, SIGNAL(clicked(int)), this, SLOT(updateMatrix(int))); k->baseColors << blue; QColor whiteColor(255, 255, 255); QBrush whiteBrush(whiteColor, k->brush.style()); TupColorWidget *white = new TupColorWidget(3, whiteBrush, cellSize, false); connect(white, SIGNAL(clicked(int)), this, SLOT(updateMatrix(int))); k->baseColors << white; QBoxLayout *bottomLayout = new QHBoxLayout; bottomLayout->setAlignment(Qt::AlignHCenter); bottomLayout->setContentsMargins(3, 3, 3, 3); #ifndef Q_OS_ANDROID bottomLayout->setSpacing(10); #else bottomLayout->setSpacing(25); #endif bottomLayout->addWidget(red); bottomLayout->addWidget(green); bottomLayout->addWidget(blue); bottomLayout->addWidget(white); k->paletteGlobalLayout->addWidget(new TupSeparator(Qt::Horizontal)); k->paletteGlobalLayout->addLayout(bottomLayout); }
void CPage_Node_Lane::DrawCentroidRadicalLines(CPaintDC *pDC, CRect PlotRect,bool bOriginAngle/*=true*/) { CPen blackPen(PS_SOLID,0,RGB(0,0,0)); CPen greyPen(PS_SOLID,2,RGB(128,128,128)); CPen lanePen(PS_SOLID,1,RGB(0,0,0)); CPen laneSelectedPen(PS_SOLID,2,RGB(255,0,0)); CBrush greyBrush(RGB(128,128,128)); CBrush whiteBrush(RGB(255,255,255)); CBrush redBrush(RGB(255,0,0)); pDC->SetBkMode(TRANSPARENT); CPen *pOldPen = pDC->SelectObject(&blackPen); CBrush* pOldBrush = pDC->SelectObject(&whiteBrush); pDC->Rectangle(PlotRect); GDPoint cntPoint,lefttop,bottomright; CRect centerRect; cntPoint.x = 0.0; cntPoint.y = 0.0; int nRadius2 = m_Para.nCentroidRadius; lefttop.x = cntPoint.x - nRadius2; lefttop.y = cntPoint.y - nRadius2; bottomright.x = cntPoint.x + nRadius2; bottomright.y = cntPoint.y + nRadius2; pDC->SelectObject(&greyPen); pDC->SelectObject(&greyBrush); centerRect = CRect(NPtoSP(lefttop),NPtoSP(bottomright)); pDC->Ellipse(centerRect); for(int i=0;i<m_LinkData.size();i++) { LinkRecord *pRecord = m_LinkData[i]; pDC->SelectObject(&greyPen); DrawRadicalLine(pDC,pRecord,bOriginAngle); pDC->SelectObject(&lanePen); pDC->SelectObject(&greyBrush); DrawLanes(pDC,pRecord,bOriginAngle); pDC->SelectObject(&blackPen); if (pRecord->nLinkID == m_nSelectedLinkID) pDC->SelectObject(&redBrush); DrawLinkPinPoint(pDC,pRecord,bOriginAngle); } // draw selected link pin point pDC->SelectObject(pOldPen); pDC->SelectObject(pOldBrush); }
void subObservationVisualiserBase::constructStandardPoints(const observation& subObs) { assert(standardPointsItem); std::size_t nVertices = boost::num_vertices(contextObj.getGraph()); const std::vector<context::vertexPosition>& vertexPositions = contextObj.getVertexPositions(); const vertexState* state = subObs.getState(); QPen blackPen(QColor("black")); QBrush blackBrush(QColor("black")); QPen redPen(QColor("red")); QBrush redBrush(QColor("red")); QBrush noBrush; noBrush.setStyle(Qt::NoBrush); for(std::size_t vertexCounter = 0; vertexCounter < nVertices; vertexCounter++) { context::vertexPosition currentPosition = vertexPositions[vertexCounter]; float x = currentPosition.first; float y = currentPosition.second; QGraphicsEllipseItem* newItem = new QGraphicsEllipseItem(x - pointSize/2, y - pointSize/2, pointSize, pointSize, standardPointsItem); if(state[vertexCounter].state == FIXED_OFF) { newItem->setBrush(noBrush); newItem->setPen(blackPen); } else if(state[vertexCounter].state == FIXED_ON) { newItem->setBrush(blackBrush); newItem->setPen(blackPen); } else if(state[vertexCounter].state == UNFIXED_OFF) { newItem->setBrush(noBrush); newItem->setPen(redPen); } else if(state[vertexCounter].state == UNFIXED_ON) { newItem->setBrush(redBrush); newItem->setPen(redPen); } else { throw std::runtime_error("Internal error"); } } }
/** Default Constructor*/ GraphicsWindow::GraphicsWindow() { //We need a scene and a view to do graphics in QT scene = new QGraphicsScene(); setScene(scene); setWindowTitle( "Programming Assignment #4: Math Puzzles"); //view = new QGraphicsView( scene ); //To fill a rectangle use a QBrush. To draw the border of a shape, use a QPen QBrush redBrush(Qt::red); QPen blackPen(Qt::black); QBrush blueBrush(Qt::blue); QBrush yellowBrush(Qt::yellow); QBrush greenBrush(Qt::green); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); scene =new QGraphicsScene(this); ui->graphicsView->setScene(scene); QBrush redBrush(Qt::red); QBrush greenBrush(Qt::green); QPen bluePen(Qt::blue); bluePen.setWidth(6); ellipse=scene->addEllipse(10,10,100,100,bluePen,redBrush); rectangle=scene->addRect(-100,-100,50,50,bluePen,greenBrush); rectangle->setFlag(QGraphicsItem::ItemIsMovable); }
speckles::speckles(QWidget *parent) : QDialog(parent), ui(new Ui::speckles) { ui->setupUi(this); scene=new QGraphicsScene(this); ui->graphicsView->setScene(scene); QBrush redBrush(Qt::red); QBrush blueBrush(Qt::blue); QPen blackPen(Qt::black); blackPen.setWidth(6); ellipse=scene->addEllipse(10, 10, 100, 500, blackPen, redBrush); rectangle=scene->addRect(-10, -10, 100, 50, blackPen, blueBrush); qDebug()<<"The width of the scene is: "<<scene->width(); qDebug()<<"The height of the scene is: "<<scene->height(); }
/** * @brief Constructor. * @param[in] parent widget. */ BARSongAreaScene::BARSongAreaScene(QObject *parent) : QGraphicsScene(parent) { timeLineSize=100; /**< length of each rectangle composing the timeline. */ QBrush redBrush(Qt::white); /**< desired color for the background of the rectangles when empty. */ QPen blackPen(Qt::black); /**< desired color for the outline of the rectangle. */ blackPen.setWidth(1); /**< sets width of the outline of the rectangle. */ for(int i=0;i<50;i++) /**< this boucle creates the 50 rectangles of the timeline. */ { QGraphicsRectItem *rectangle=new QGraphicsRectItem(i*timeLineSize,0,timeLineSize,60); /**< create the new rectangle on the right of the last one. */ QGraphicsTextItem *label=new QGraphicsTextItem(QString::number(i)); /**< displays the number of the rectangle in the timeline. */ label->setPos(i*timeLineSize-timeLineSize/20,-25); /**< position the label in the top left corner of the rectangle. */ rectangle->setBrush(redBrush); /**< set the background color. */ rectangle->setPen(blackPen); /**< set the outline. */ addItem(rectangle); /**< the last three lines add the rectangle to the timeline. */ addItem(label); stock.push_back(rectangle); } }
void CSelectionPanel::OnShowHPLine(){ set<CSprite*>::iterator it; CDC *pDC = CDDraw::GetBackCDC(); // 取得 Back Plain 的 CDC CBrush *pb,redBrush(RGB(255,0,0)),greenBrush(RGB(0,255,0)); CPen *pp,blackPen(PS_SOLID,1,RGB(0,0,0)); pp = pDC->SelectObject(&blackPen); pb = pDC->SelectObject(&redBrush); for(it = selectedSprites.begin();it!=selectedSprites.end();it++){ CPoint screenPoint(CConvert::GetScreenPointByMapPoint((*it)->MapPoint())); CRect redRect(CPoint(screenPoint.x-25,screenPoint.y),CSize(50,5)); pDC->Rectangle(redRect); CRect greenRect(CPoint(screenPoint.x-25,screenPoint.y),CSize(50*(*it)->HP()/(*it)->MaxHP(),5)); pDC->SelectObject(&greenBrush); pDC->Rectangle(greenRect); pDC->SelectObject(&redBrush); } pDC->SelectObject(pb); // pDC->SelectObject(pp); CDDraw::ReleaseBackCDC(); // 放掉 Back Plain 的 CDC //if(isSelected){ // //畫圓圈 // CDC *pDC = CDDraw::GetBackCDC(); // 取得 Back Plain 的 CDC // CBrush *pb,redBrush(RGB(255,0,0)),greenBrush(RGB(0,255,0)); // CPen *pp,nullPen(PS_NULL,0,RGB(0,0,0)); // pb = pDC->SelectObject(&redBrush); // pp = pDC->SelectObject(&nullPen); // CPoint screenPoint(CConvert::GetScreenPointByMapPoint(mapPoint)); // CRect redRect(CPoint(screenPoint.x-25,screenPoint.y),CSize(50,5)); // CRect greenRect(CPoint(screenPoint.x-25,screenPoint.y),CSize(50*hp/maxHp,5)); // pDC->Rectangle(redRect); // pDC->SelectObject(&greenBrush); // pDC->Rectangle(greenRect); // pDC->SelectObject(pb); // // pDC->SelectObject(pp); // CDDraw::ReleaseBackCDC(); // 放掉 Back Plain 的 CDC //} }
wxBitmap BacklashGraph::CreateGraph(int bmpWidth, int bmpHeight) { wxMemoryDC dc; wxBitmap bmp(bmpWidth, bmpHeight, -1); wxPen axisPen("BLACK", 3, wxCROSS_HATCH); wxPen redPen("RED", 3, wxSOLID); wxPen bluePen("BLUE", 3, wxSOLID); wxBrush redBrush("RED", wxSOLID); wxBrush blueBrush("BLUE", wxSOLID); //double fakeNorthPoints[] = //{152.04, 164.77, 176.34, 188.5, 200.25, 212.36, 224.21, 236.89, 248.62, 260.25, 271.34, 283.54, 294.79, 307.56, 319.22, 330.87, 343.37, 355.75, 367.52, 379.7, 391.22, 403.89, 415.34, 427.09, 439.41, 450.36, 462.6}; //double fakeSouthPoints[] = //{474.84, 474.9, 464.01, 451.83, 438.08, 426, 414.68, 401.15, 390.39, 377.22, 366.17, 353.45, 340.75, 328.31, 316.93, 304.55, 292.42, 280.45, 269.03, 255.02, 243.76, 231.53, 219.43, 207.35, 195.22, 183.06, 169.47}; //std::vector <double> northSteps(fakeNorthPoints, fakeNorthPoints + 27); //std::vector <double> southSteps(fakeSouthPoints, fakeSouthPoints + 27); std::vector <double> northSteps = m_BLT->GetNorthSteps(); std::vector <double> southSteps = m_BLT->GetSouthSteps(); double xScaleFactor; double yScaleFactor; int xOrigin; int yOrigin; int ptRadius; int graphWindowWidth; int graphWindowHeight; int numNorth; double northInc; int numSouth; // Find the max excursion from the origin in order to scale the points to fit the bitmap double maxDec = -9999.0; double minDec = 9999.0; for (std::vector<double>::const_iterator it = northSteps.begin(); it != northSteps.end(); ++it) { maxDec = wxMax(maxDec, *it); minDec = wxMin(minDec, *it); } for (std::vector<double>::const_iterator it = southSteps.begin(); it != southSteps.end(); ++it) { maxDec = wxMax(maxDec, *it); minDec = wxMin(minDec, *it); } graphWindowWidth = bmpWidth; graphWindowHeight = 0.7 * bmpHeight; yScaleFactor = (graphWindowHeight) / (maxDec - minDec + 1); xScaleFactor = (graphWindowWidth) / (northSteps.size() + southSteps.size()); // Since we get mount coordinates, north steps will always be in ascending order numNorth = northSteps.size(); northInc = (northSteps.at(numNorth - 1) - northSteps.at(0)) / numNorth; numSouth = southSteps.size(); // Should be same as numNorth but be careful dc.SelectObject(bmp); dc.SetBackground(*wxLIGHT_GREY_BRUSH); dc.SetFont(wxFont(12, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL)); dc.Clear(); // Bottom and top labels dc.SetTextForeground("BLUE"); dc.DrawText(_("Ideal"), 0.7 * graphWindowWidth, bmpHeight - 25); dc.SetTextForeground("RED"); dc.DrawText(_("Measured"), 0.2 * graphWindowWidth, bmpHeight - 25); dc.DrawText(_("North"), 0.1 * graphWindowWidth, 10); dc.DrawText(_("South"), 0.8 * graphWindowWidth, 10); // Draw the axes dc.SetPen(axisPen); xOrigin = graphWindowWidth / 2; yOrigin = graphWindowHeight + 40; // Leave room at the top for labels and such dc.DrawLine(0, yOrigin, graphWindowWidth, yOrigin); // x dc.DrawLine(xOrigin, yOrigin, xOrigin, 0); // y // Draw the north steps dc.SetPen(redPen); dc.SetBrush(redBrush); ptRadius = 2; for (int i = 0; i < numNorth; i++) { wxPoint where = wxPoint(i * xScaleFactor, round(yOrigin - (northSteps.at(i) - minDec) * yScaleFactor)); dc.DrawCircle(wxPoint(i * xScaleFactor, round(yOrigin - (northSteps.at(i) - minDec) * yScaleFactor)), ptRadius); } // Draw the south steps for (int i = 0; i < numSouth; i++) { dc.DrawCircle(wxPoint((i + numNorth) * xScaleFactor, round(yOrigin - (southSteps.at(i) - minDec) * yScaleFactor)), ptRadius); } // Now show an ideal south recovery line dc.SetPen(bluePen); dc.SetBrush(blueBrush); double peakSouth = southSteps.at(0); for (int i = 1; i <= numNorth; i++) { wxPoint where = wxPoint((i + numNorth)* xScaleFactor, round(yOrigin - (peakSouth - i * northInc - minDec) * yScaleFactor)); dc.DrawCircle(where, ptRadius); } dc.SelectObject(wxNullBitmap); return bmp; }
void MainWindow::setupMainGraph(int M,int N) { this->_cleanTheList(); QBrush redBrush(Qt::red); QBrush blueBrush(Qt::blue); QBrush yellowBrush(Qt::yellow); QPen blackPen(Qt::black); blackPen.setWidth(0.5); QPen bluePen(Qt::blue); bluePen.setWidth(0.5); srand((int)time(NULL)); /* for(int i=0;i<5;i++){ elipse[i] = scene->addEllipse(-200+i*100+rand()%30,-110+rand()%30,-100,100,blackPen,redBrush); elipse[i]->setFlag(QGraphicsItem::ItemIsMovable); } for(int i=6;i<11;i++){ elipse[i] = scene->addEllipse(-200+(i-5)*100+rand()%30,100+rand()%30,-100,100,blackPen,yelloBrush); elipse[i]->setFlag(QGraphicsItem::ItemIsMovable); } for(int i=12;i<19;i++){ elipse[i] = scene->addEllipse(-200+(i-12)*100+rand()%30,300+rand()%30,-100,100,blackPen,blueBrush); elipse[i]->setFlag(QGraphicsItem::ItemIsMovable); } */ srand((int)time(NULL)); for(int j=-N;j<=N;j++){ for(int i=-M;i<=M;i++){ blue = new QGraphicsEllipseItem; blue = scene->addEllipse(2*sqrt(3)*R*i+RD,6*R*j+RD,2*R+EXTRA,2*R+EXTRA,blackPen,blueBrush); blue->setX(2*sqrt(3)*R*i+RD); blue ->setY(6*R*j+RD); blueElipse.append(blue); } } for(int j=-N;j<=N;j++){ for(int i=-M;i<=M;i++){ blue = new QGraphicsEllipseItem; blue = scene->addEllipse(-sqrt(3)*R+2*sqrt(3)*R*i+RD,-3*R+6*R*j+RD,2*R+EXTRA,2*R+EXTRA,blackPen,blueBrush); blue->setX(-sqrt(3)*R+2*sqrt(3)*R*i+RD); blue->setY(-3*R+6*R*j+RD); blueElipse.append(blue); } } for(int j=-N;j<=N;j++){ for(int i=-M;i<=M;i++){ red = new QGraphicsEllipseItem; red = scene->addEllipse(2*sqrt(3)*R*i+RD,2*R+6*R*j+RD,2*R+EXTRA,2*R+EXTRA,blackPen,redBrush); red->setX(2*sqrt(3)*R*i+RD); red->setY(2*R+6*R*j+RD); redElipse.append(red); } } for(int j=-N;j<=N;j++){ for(int i=-M;i<=M;i++){ red = new QGraphicsEllipseItem; red = scene->addEllipse(-sqrt(3)*R+2*sqrt(3)*R*i+RD,-R+6*R*j+RD,2*R+EXTRA,2*R+EXTRA,blackPen,redBrush); red->setX(-sqrt(3)*R+2*sqrt(3)*R*i+RD); red->setY(-R+6*R*j+RD); redElipse.append(red); } } for(int j=-N;j<=N;j++){ for(int i=-M;i<=M;i++){ yellow = new QGraphicsEllipseItem; yellow = scene->addEllipse(-sqrt(3)*R+2*sqrt(3)*R*i+RD,R+6*R*j+RD,2*R+EXTRA,2*R+EXTRA,blackPen,yellowBrush); yellow->setX(-sqrt(3)*R+2*sqrt(3)*R*i+RD); yellow->setY(R+6*R*j+RD); yellowElipse.append(yellow); } } for(int j=-N;j<=N;j++){ for(int i=-M;i<=M;i++){ yellow = new QGraphicsEllipseItem; yellow = scene->addEllipse(2*sqrt(3)*R*i+RD,-2*R+6*R*j+RD,2*R+EXTRA,2*R+EXTRA,blackPen,yellowBrush); yellow ->setX(2*sqrt(3)*R*i+RD); yellow ->setY(-2*R+6*R*j+RD); yellowElipse.append(yellow); } } qDebug()<<redElipse.size(); foreach(QGraphicsEllipseItem *red,redElipse){ red->setFlag(QGraphicsItem::ItemIsMovable); qDebug()<<red->x()<<" "<<red->y()<<endl; }
void MainWindow::on_pushButton_clicked() { this->scene->clear(); out="自配置\n"; this->ui->textEdit->setText(out); QBrush redBrush(Qt::red); QBrush blueBrush(Qt::blue); QBrush yellowBrush(Qt::yellow); QPen blackPen(Qt::black); blackPen.setWidth(0.5); QPen bluePen(Qt::blue); bluePen.setWidth(0.5); self_window = new self_set; qDebug()<<"hello"<<endl; self_window->exec(); QDateTime time = QDateTime::currentDateTime();//获取系统现在的时间 QString _time = time.toString("yyyy-MM-dd hh:mm:ss ddd"); //设置显示格式 out=out+_time+"\n"; this->ui->textEdit->setText(out); qDebug()<<this->self_window->_yes; setAlgo = new Set_algorithm; if(this->self_window->_yes==true){ this->ui->textEdit->setText(out); QString ch = (self_window->choice==1)? "平均SINR最高":"能效比最高"; out=out+"\n自配置参数预制如下:\n-----------------------\n"; out=out+"RESP0:"+QString::number(self_window->RESP0)+"\n"+ "优化标准:"+ch+"\n"+ "路损模型参数:\n"+"a="+QString::number(self_window->a)+" b="+QString::number(self_window->b)+"\n" +"覆盖率:"+QString::number(self_window->coverRate)+"%\n"+ "额定功率:"+QString::number(self_window->power)+"\n" +"临界信噪比:"+QString::number(self_window->SINR)+"\n"+ "-----------------------\n自配置开始......\n"; this->ui->textEdit->setText(out); setAlgo->RESP0=self_window->RESP0; setAlgo->choice=self_window->choice; setAlgo->coverRate=self_window->coverRate; setAlgo->power=self_window->power; setAlgo->SINR = self_window->SINR; setAlgo->a=self_window->a; setAlgo->b=self_window->b; qDebug()<<out; QString resultPower=QString::number(setAlgo->getResultPower())+"\n"; out=out+resultPower; this->ui->textEdit->setText(out); for(int i=0;i<setAlgo->apList.size();i++){ AP *temp = setAlgo->apList.at(i); qDebug()<<"x,y:"<<temp->x()<<" "<<temp->y()<<endl; if(temp->frequency==1) this->scene->addEllipse(temp->x(),temp->y(),(setAlgo->ratio)*EXR,(setAlgo->ratio)*EXR,blackPen,blueBrush); else if(temp->frequency==6) this->scene->addEllipse(temp->x(),temp->y(),(setAlgo->ratio)*EXR,(setAlgo->ratio)*EXR,blackPen,redBrush); else if(temp->frequency==11) this->scene->addEllipse(temp->x(),temp->y(),(setAlgo->ratio)*EXR,(setAlgo->ratio)*EXR,blackPen,yellowBrush); } } _addLineGraph(); }
/** * Draws the FLARM traffic icons onto the given canvas * @param canvas Canvas for drawing */ void MapWindow::DrawFLARMTraffic(Canvas &canvas) { // Return if FLARM icons on moving map are disabled if (!SettingsMap().EnableFLARMMap) return; // Return if FLARM data is not available if (!Basic().FLARM_Available) return; // Create pen for icon outlines Pen thinBlackPen(IBLSCALE(1), Color(0, 0, 0)); canvas.select(thinBlackPen); // Create point array that will form that arrow polygon POINT Arrow[5]; // double dX, dY; TextInBoxMode_t displaymode; displaymode.AsInt = 0; // Determine scale factor for use in Scaled mode double screenrange = GetScreenDistanceMeters(); double scalefact = screenrange/6000.0; // Create the brushes for filling the arrow (red/yellow/green) Brush redBrush(Color(0xFF,0x00,0x00)); Brush yellowBrush(Color(0xFF,0xFF,0x00)); Brush greenBrush(Color(0x00,0xFF,0x00)); // Saves the MacCready value const double MACCREADY = GlidePolar::GetMacCready(); // Circle through the FLARM targets for (int i = 0; i < FLARM_MAX_TRAFFIC; i++) { // if FLARM target i exists if (Basic().FLARM_Traffic[i].ID!=0) { // Save the location of the FLARM target GEOPOINT target_loc; target_loc = Basic().FLARM_Traffic[i].Location; // If Scaled mode is chosen, recalculate the // targets virtual position using the scale factor if ((SettingsMap().EnableFLARMMap == 2) && (scalefact > 1.0)) { double distance; double bearing; DistanceBearing(Basic().Location, target_loc, &distance, &bearing); FindLatitudeLongitude(Basic().Location, bearing, distance * scalefact, &target_loc); } // TODO feature: draw direction, rel height? // Points for the screen coordinates for the icon, name and average climb POINT sc, sc_name, sc_av; // If FLARM target not on the screen, move to the next one if (!LonLat2ScreenIfVisible(target_loc, &sc)) { continue; } // Draw the name 16 points below the icon sc_name = sc; sc_name.y -= IBLSCALE(16); // Draw the average climb value above the icon sc_av = sc; sc_av.y += IBLSCALE(16); #ifndef FLARM_AVERAGE if (Basic().FLARM_Traffic[i].Name) { TextInBox(hDC, Basic().FLARM_Traffic[i].Name, sc.x+IBLSCALE(3), sc.y, 0, displaymode, true); } #else TCHAR label_name[100]; TCHAR label_avg[100]; sc_av.x += IBLSCALE(3); if (Basic().FLARM_Traffic[i].Name) { sc_name.y -= IBLSCALE(8); _stprintf(label_name, TEXT("%s"), Basic().FLARM_Traffic[i].Name); } else { label_name[0]= _T('\0'); } if (Basic().FLARM_Traffic[i].Average30s >= 0.1) { _stprintf(label_avg, TEXT("%.1f"), LIFTMODIFY * Basic().FLARM_Traffic[i].Average30s); } else { label_avg[0]= _T('\0'); } #ifndef NDEBUG // for testing only! _stprintf(label_avg, TEXT("2.3")); _stprintf(label_name, TEXT("WUE")); #endif // JMW TODO enhancement: decluttering of FLARM altitudes (sort by max lift) int dx = (sc_av.x-Orig_Aircraft.x); int dy = (sc_av.y-Orig_Aircraft.y); // only draw labels if not close to aircraft if (dx*dx+dy*dy > IBLSCALE(30)*IBLSCALE(30)) { // Select the MapLabelFont and black color canvas.select(MapLabelFont); canvas.set_text_color(Color(0,0,0)); // If FLARM callsign/name available draw it to the canvas if (_tcslen(label_name) > 0) { canvas.text_opaque(sc_name.x, sc_name.y, label_name); } // If average climb data available draw it to the canvas if (_tcslen(label_avg)>0) { SIZE tsize; RECT brect; // Calculate the size of the average climb indicator tsize = canvas.text_size(label_avg); brect.left = sc_av.x-2; brect.right = brect.left+tsize.cx+6; brect.top = sc_av.y+((tsize.cy+4)>>3)-2; brect.bottom = brect.top+3+tsize.cy-((tsize.cy+4)>>3); // Determine the background color for the average climb indicator float vmax = (float)(1.5*min(5.0, max(MACCREADY,0.5))); float vmin = (float)(-1.5*min(5.0, max(MACCREADY,2.0))); float cv = Basic().FLARM_Traffic[i].Average30s; if (cv < 0) { cv /= (-vmin); // JMW fixed bug here } else { cv /= vmax; } int colourIndex = fSnailColour(cv); // Select the appropriate background color determined before canvas.select(MapGfx.hSnailPens[colourIndex]); Brush hVarioBrush(MapGfx.hSnailColours[colourIndex]); canvas.select(hVarioBrush); // Draw the rounded background rectangle canvas.round_rectangle(brect.left, brect.top, brect.right, brect.bottom, IBLSCALE(8), IBLSCALE(8)); #ifdef WINDOWSPC canvas.background_transparent(); canvas.text(sc_av.x, sc_av.y, label_avg); #else // Draw the average climb value on top canvas.text_opaque(sc_av.x, sc_av.y, label_avg); #endif } }
// Build the calibration "step" graph which will appear on the lefthand side of the panels wxBitmap CalReviewDialog::CreateGraph(bool AO) { wxMemoryDC memDC; wxBitmap bmp(CALREVIEW_BITMAP_SIZE, CALREVIEW_BITMAP_SIZE, -1); wxPen axisPen("BLACK", 3, wxCROSS_HATCH); wxPen redPen("RED", 3, wxSOLID); wxPen bluePen("BLUE", 3, wxSOLID); wxBrush redBrush("RED", wxSOLID); wxBrush blueBrush("BLUE", wxSOLID); CalibrationDetails calDetails; double scaleFactor; int ptRadius; if (!pSecondaryMount) { pMount->GetCalibrationDetails(&calDetails); // Normal case, no AO } else { if (AO) { pMount->GetCalibrationDetails(&calDetails); // AO tab, use AO details } else { pSecondaryMount->GetCalibrationDetails(&calDetails); // Mount tab, use mount details } } // Find the max excursion from the origin in order to scale the points to fit the bitmap double biggestVal = -100.0; for (std::vector<wxRealPoint>::const_iterator it = calDetails.raSteps.begin(); it != calDetails.raSteps.end(); ++it) { biggestVal = wxMax(biggestVal, fabs(it->x)); biggestVal = wxMax(biggestVal, fabs(it->y)); } for (std::vector<wxRealPoint>::const_iterator it = calDetails.decSteps.begin(); it != calDetails.decSteps.end(); ++it) { biggestVal = wxMax(biggestVal, fabs(it->x)); biggestVal = wxMax(biggestVal, fabs(it->y)); } if (biggestVal > 0.0) scaleFactor = ((CALREVIEW_BITMAP_SIZE - 5) / 2) / biggestVal; // Leave room for circular point else scaleFactor = 1.0; memDC.SelectObject(bmp); memDC.SetBackground(*wxLIGHT_GREY_BRUSH); memDC.Clear(); memDC.SetPen(axisPen); // Draw the axes memDC.SetDeviceOrigin(wxCoord(CALREVIEW_BITMAP_SIZE / 2), wxCoord(CALREVIEW_BITMAP_SIZE / 2)); memDC.DrawLine(-CALREVIEW_BITMAP_SIZE / 2, 0, CALREVIEW_BITMAP_SIZE / 2, 0); // x memDC.DrawLine(0, -CALREVIEW_BITMAP_SIZE / 2, 0, CALREVIEW_BITMAP_SIZE / 2); // y if (calDetails.raStepCount > 0) { // Draw the RA data memDC.SetPen(redPen); memDC.SetBrush(redBrush); ptRadius = 2; // Scale the points, then plot them individually for (int i = 0; i < (int) calDetails.raSteps.size(); i++) { if (i == calDetails.raStepCount + 2) // Valid even for "single-step" calibration { memDC.SetPen(wxPen("Red", 1)); // 1-pixel-thick red outline memDC.SetBrush(wxNullBrush); // Outline only for "return" data points ptRadius = 3; } memDC.DrawCircle(IntPoint(calDetails.raSteps.at(i), scaleFactor), ptRadius); } // Show the line PHD2 will use for the rate memDC.SetPen(redPen); if ((int)calDetails.raSteps.size() > calDetails.raStepCount) // New calib, includes return values memDC.DrawLine(IntPoint(calDetails.raSteps.at(0), scaleFactor), IntPoint(calDetails.raSteps.at(calDetails.raStepCount), scaleFactor)); else memDC.DrawLine(IntPoint(calDetails.raSteps.at(0), scaleFactor), IntPoint(calDetails.raSteps.at(calDetails.raStepCount - 1), scaleFactor)); } // Handle the Dec data memDC.SetPen(bluePen); memDC.SetBrush(blueBrush); ptRadius = 2; if (calDetails.decStepCount > 0) { for (int i = 0; i < (int) calDetails.decSteps.size(); i++) { if (i == calDetails.decStepCount + 2) { memDC.SetPen(wxPen("Blue", 1)); // 1-pixel-thick red outline memDC.SetBrush(wxNullBrush); // Outline only for "return" data points ptRadius = 3; } memDC.DrawCircle(IntPoint(calDetails.decSteps.at(i), scaleFactor), ptRadius); } // Show the line PHD2 will use for the rate memDC.SetPen(bluePen); if ((int)calDetails.decSteps.size() > calDetails.decStepCount) // New calib, includes return values memDC.DrawLine(IntPoint(calDetails.decSteps.at(0), scaleFactor), IntPoint(calDetails.decSteps.at(calDetails.decStepCount), scaleFactor)); else memDC.DrawLine(IntPoint(calDetails.decSteps.at(0), scaleFactor), IntPoint(calDetails.decSteps.at(calDetails.decStepCount - 1), scaleFactor)); } memDC.SelectObject(wxNullBitmap); return bmp; }
void ImageEditor::paintEvent(QPaintEvent *event) { if (!_image_loaded) return; QPainter painter(this); QPixmap pixmaptoshow; if(!_flag_mask) pixmaptoshow=QPixmap::fromImage(_image_layer.scaled(this->size(),Qt::KeepAspectRatio)); else pixmaptoshow=QPixmap::fromImage(_image_mask.scaled(this->size(),Qt::KeepAspectRatio)); painter.drawPixmap(0,0, pixmaptoshow); _real_size=pixmaptoshow.size(); //draw point if(_scissor) { QBrush blackBrush(qRgba(0, 0, 0, 255)); painter.setBrush(blackBrush); for (int i=0;i<_contourList.size();i++) for(int j=0;j<_contourList[i].size();j+=3) { QPoint ConP; ConP=QPoint(_contourList[i][j].x()*_real_size.width(),_contourList[i][j].y()*_real_size.height()); painter.drawEllipse(ConP,1,1); } for(int i=0;i<_segList.size();i+=3) { QPoint ConP; ConP=QPoint(_segList[i].x()*_real_size.width(),_segList[i].y()*_real_size.height()); painter.drawEllipse(ConP,1,1); } QBrush redBrush(qRgba(255, 0, 0, 255)); painter.setBrush(redBrush); for(int i=0;i<_fixedSeedList.size();i++) { QPoint ConP; ConP=QPoint(_fixedSeedList[i].x()*_real_size.width(),_fixedSeedList[i].y()*_real_size.height()); painter.drawEllipse(ConP,3,3); } } else { if(parameters) { for(int i=0;i<parameters->ui_points.size();i++) { if(i==parameters->ActIndex) { QBrush redBrush(qRgba(255, 0, 0, 255)); painter.setBrush(redBrush); } else { QBrush yellowBrush(qRgba(255, 255, 0, 255)); painter.setBrush(yellowBrush); } QPoint ConP; switch(_name) { case 'L': case 'l': ConP=QPoint(parameters->ui_points[i].lp.x*_real_size.width(),parameters->ui_points[i].lp.y*_real_size.height()); break; case 'R': case 'r': ConP=QPoint(parameters->ui_points[i].rp.x*_real_size.width(),parameters->ui_points[i].rp.y*_real_size.height()); } painter.drawEllipse(ConP,3,3); } } } }
void MainWin::createPages() { DIRRES *dir; QTreeWidgetItem *item, *topItem; m_firstItem = NULL; LockRes(); foreach_res(dir, R_DIRECTOR) { /* Create console tree stacked widget item */ m_currentConsole = new Console(stackedWidget); m_currentConsole->setDirRes(dir); m_currentConsole->readSettings(); /* The top tree item representing the director */ topItem = new QTreeWidgetItem(treeWidget); topItem->setText(0, dir->name()); topItem->setIcon(0, QIcon(":images/server.png")); /* Set background to grey for ease of identification of inactive Director */ QBrush greyBrush(Qt::lightGray); topItem->setBackground(0, greyBrush); m_currentConsole->setDirectorTreeItem(topItem); m_consoleHash.insert(topItem, m_currentConsole); /* Create Tree Widget Item */ item = new QTreeWidgetItem(topItem); item->setText(0, tr("Console")); if (!m_firstItem){ m_firstItem = item; } item->setIcon(0,QIcon(QString::fromUtf8(":images/utilities-terminal.png"))); /* insert the cosole and tree widget item into the hashes */ hashInsert(item, m_currentConsole); /* Set Color of treeWidgetItem for the console * It will be set to green in the console class if the connection is made. */ QBrush redBrush(Qt::red); item->setForeground(0, redBrush); m_currentConsole->dockPage(); /* * Create instances in alphabetic order of the rest * of the classes that will by default exist under each Director. */ // new bRestore(); new Clients(); new FileSet(); new Jobs(); createPageJobList("", "", "", "", NULL); #ifdef HAVE_QWT JobPlotPass pass; pass.use = false; if (m_openPlot) new JobPlot(NULL, pass); #endif new MediaList(); new Storage(); if (m_openBrowser) new restoreTree(); if (m_openDirStat) new DirStat(); treeWidget->expandItem(topItem); stackedWidget->setCurrentWidget(m_currentConsole); }
void CMidSubDrawHelper::drawHistoryBarData(CHistoryDataManager* pHistoryDataManager, QCustomPlot* pCustomPlot, QCPAxisRect* pRect) { QBrush redBrush(QColor(255, 0, 0, 255));//red QPen redPen(QColor(255, 0, 0, 255));//red QBrush greenBrush(QColor(0, 255, 0, 255));//green QPen greenPen(QColor(0, 255, 0, 255));//green QBrush* pBoxBrushRef = NULL; QPen* pBoxPenRef = NULL; QCPStatisticalBox *pStatisticalBoxRef = NULL; double fMinimum = 0; double fMaximum = 0; double fLowerQuartile = 0; double fUpperQuartile = 0; QMap<unsigned int, Bar>::iterator iterMap; int nIndex = 0; unsigned int nTimeFrom = 0; unsigned int nTimeTo = 0; double nLeftAxisRangeMin = 0; double nLeftAxisRangeMax = 0; int nBarWith = 0; nBarWith = pHistoryDataManager->getBarType();//FIVE_MINUTES nTimeFrom = pHistoryDataManager->getTimeFrom(); nTimeTo = pHistoryDataManager->getTimeTo(); // prepare axes: pRect->axis(QCPAxis::atLeft)->setLabel(QObject::tr("Y-value")); pRect->axis(QCPAxis::atBottom)->setLabel(QObject::tr("X-time")); pRect->axis(QCPAxis::atBottom)->setTickLabelType(QCPAxis::ltDateTime); pRect->axis(QCPAxis::atBottom)->setDateTimeFormat(DEF_STRING_FORMAT_TIME.c_str()); nIndex = 0; iterMap = pHistoryDataManager->m_pHistoryACK->m_MapBarData.begin(); while (iterMap != pHistoryDataManager->m_pHistoryACK->m_MapBarData.end()) { //iterMap->second; // create empty statistical box plottables: pStatisticalBoxRef = NULL; pStatisticalBoxRef = new QCPStatisticalBox(pRect->axis(QCPAxis::atBottom), pRect->axis(QCPAxis::atLeft)); pCustomPlot->addPlottable(pStatisticalBoxRef); fMinimum = iterMap->low; fMaximum= iterMap->high; if (iterMap->open > iterMap->close) { //high->low fLowerQuartile = iterMap->close; fUpperQuartile = iterMap->open; pBoxBrushRef = &redBrush; pBoxPenRef = &redPen; } else { fLowerQuartile = iterMap->open; fUpperQuartile = iterMap->close; pBoxBrushRef = &greenBrush; pBoxPenRef = &greenPen; } //boxBrush.setStyle(Qt::SolidPattern); // make it look oldschool Qt::SolidPattern Qt::Dense6Pattern pStatisticalBoxRef->setBrush(*pBoxBrushRef); pStatisticalBoxRef->setPen(*pBoxPenRef); pStatisticalBoxRef->setWhiskerPen(*pBoxPenRef); pStatisticalBoxRef->setWhiskerBarPen(*pBoxPenRef); pStatisticalBoxRef->setMedianPen(*pBoxPenRef); // set data: //pStatisticalBoxTmp->setKey(nIndex); pStatisticalBoxRef->setBoxType(QCPStatisticalBox::btBar); pStatisticalBoxRef->setKey(iterMap->timestamp); pStatisticalBoxRef->setMinimum(fMinimum); pStatisticalBoxRef->setLowerQuartile(fLowerQuartile); pStatisticalBoxRef->setMedian(fLowerQuartile); pStatisticalBoxRef->setUpperQuartile(fUpperQuartile); pStatisticalBoxRef->setMaximum(fMaximum); //pStatisticalBoxTmp->setWidth(1);//矩形宽度 pStatisticalBoxRef->setWidth(nBarWith);//矩形宽度 pStatisticalBoxRef->setWhiskerWidth(0);//上顶,下底 直线宽度 if (fMinimum < nLeftAxisRangeMin) { nLeftAxisRangeMin = fMinimum; } if (fMaximum > nLeftAxisRangeMax) { nLeftAxisRangeMax = fMaximum; } nIndex++; iterMap++; }//while // make key axis range scroll with the data (at a constant range size of 8): pRect->axis(QCPAxis::atBottom)->setRange(nTimeFrom, nTimeTo); pRect->axis(QCPAxis::atLeft)->setRange(nLeftAxisRangeMin, nLeftAxisRangeMax); // pCustomPlot->rescaleAxes(); // pCustomPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); pBoxBrushRef = NULL; pBoxPenRef = NULL; pStatisticalBoxRef = NULL; }
treeVisualiserFrame::treeVisualiserFrame(const observationTree& tree, float pointSize) :pointSize(pointSize), highlightItem(NULL) { graphicsScene = new QGraphicsScene(); graphicsScene->installEventFilter(this); graphicsScene->setItemIndexMethod(QGraphicsScene::NoIndex); graphicsView = new ZoomGraphicsView(graphicsScene); graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); graphicsView->installEventFilter(this); const observationTree::treeGraphType treeGraph = tree.getTreeGraph(); observationTree::treeGraphType::vertex_iterator currentVertex, endVertex; boost::tie(currentVertex, endVertex) = boost::vertices(treeGraph); QPen blackPen(QColor("black")); blackPen.setStyle(Qt::NoPen); QBrush blueBrush(QColor("blue")); QBrush redBrush(QColor("red")); for(; currentVertex != endVertex; currentVertex++) { float x = treeGraph[*currentVertex].x; float y = treeGraph[*currentVertex].y; treeVisualiserVertex* vertexItem = new treeVisualiserVertex(x - pointSize/2, y - pointSize/2, pointSize, pointSize); vertexItem->setVertexID((int)*currentVertex); if(treeGraph[*currentVertex].potentiallyDisconnected) { vertexItem->setPen(blackPen); vertexItem->setBrush(blueBrush); } else { vertexItem->setPen(blackPen); vertexItem->setBrush(redBrush); } vertexItem->setFlag(QGraphicsItem::ItemIsSelectable, true); graphicsScene->addItem(vertexItem); } blackPen.setStyle(Qt::SolidLine); blackPen.setWidthF(pointSize/8); observationTree::treeGraphType::edge_iterator currentEdge, endEdge; boost::tie(currentEdge, endEdge) = boost::edges(treeGraph); for(; currentEdge != endEdge; currentEdge++) { int sourceVertex = (int)boost::source(*currentEdge, treeGraph); int targetVertex = (int)boost::target(*currentEdge, treeGraph); float sourceX = treeGraph[sourceVertex].x; float sourceY = treeGraph[sourceVertex].y; float targetX = treeGraph[targetVertex].x; float targetY = treeGraph[targetVertex].y; QGraphicsLineItem* lineItem = graphicsScene->addLine(sourceX, sourceY, targetX, targetY, blackPen); lineItem->setFlag(QGraphicsItem::ItemIsSelectable, false); } layout = new QHBoxLayout; layout->addWidget(graphicsView, 1); layout->setContentsMargins(0,0,0,0); setLayout(layout); graphicsView->fitInView(graphicsView->sceneRect(), Qt::KeepAspectRatioByExpanding); }
twoChessBoard::twoChessBoard(QWidget *parent) : QDialog(parent), ui(new Ui::twoChessBoard) { // There are issues with this right now. Hardcoded integers are only used for testing on simulator, not actual phone. this->parent = parent; ui->setupUi(this); ui->widget->setGeometry(QRect(10,130,480,480)); graphicsView = new QGraphicsView(ui->widget); scene = new QGraphicsScene(QRect(-240,-180,480,480)); graphicsView->setGeometry(QRect(0,0,490,490)); graphicsView->setScene(scene); select = 0;//used to check whether a piece is selected or not turn = 1;//used to check which players turn it is //the following are to check how many different kind of pieces are left in the board blackPawnsLeft = 8; whitePawnsLeft = 8; blackRooksLeft = 2; whiteRooksLeft = 2; blackKnightsLeft = 2; whiteKnightsLeft = 2; blackBishopsLeft = 2; whiteBishopsLeft = 2; blackQueenLeft = 1; whiteQueenLeft = 1; blackKingLeft = 1; whiteKingLeft = 1; // colors for pieces QBrush blackBrush(Qt::black); QBrush whiteBrush(Qt::white); QBrush greenBrush(Qt::green); QBrush redBrush(Qt::red); QBrush yellowBrush(Qt::yellow); QBrush blueBrush(Qt::blue); QBrush magentaBrush(Qt::magenta); QBrush grayBrush(Qt::gray); QBrush darkGreenBrush(Qt::darkGreen); QBrush darkRedBrush(Qt::darkRed); QBrush darkYellowBrush(Qt::darkYellow); QBrush darkBlueBrush(Qt::darkBlue); QBrush darkMagentaBrush(Qt::darkMagenta); QBrush darkGrayBrush(Qt::darkGray); QPen pen(Qt::transparent); pen.setWidth(0); // This loop generates the chessboard. Code was written by TA. for(int i=0;i<CHESSBOARD_SIZE;i++){ chessboard[i].resize(CHESSBOARD_SIZE); for(int j = 0 ; j<CHESSBOARD_SIZE;j++){ chessboard[i][j] = new QGraphicsRectItem(CHESSBOARD_GRID_SIZE*(j-CHESSBOARD_SIZE/2) , CHESSBOARD_GRID_SIZE*( -i+CHESSBOARD_SIZE/2) , CHESSBOARD_GRID_SIZE ,CHESSBOARD_GRID_SIZE); scene->addItem(chessboard[i][j]); chessboard[i][j]->setPen(pen); chessboard[i][j]->setBrush(((i+j)%2==0)?blackBrush:whiteBrush); } } graphicsView->show(); qDebug("Initialized chessboard..."); for(int i =0; i<8;i++) { for(int j=0;j<8;j++) { boardvalues[i][j] = 0; } } //initialising the board values for(int i = 0;i<8;i++) { //pawns boardvalues[1][i] = 1; boardvalues[6][i] = 7; } //rooks boardvalues[0][0] = 2; boardvalues[0][7] = 2; boardvalues[7][0] = 8; boardvalues[7][7] = 8; //knights boardvalues[0][1] = 3; boardvalues[0][6] = 3; boardvalues[7][1] =9; boardvalues[7][6] =9; //bishops boardvalues[0][2] = 4; boardvalues[0][5] = 4; boardvalues[7][2] =10; boardvalues[7][5] =10; //queen boardvalues[0][3] = 6; boardvalues[7][3] =12; //king boardvalues[0][4] = 5; boardvalues[7][4] =11; // white pawns for (int i = 0; i < 8; i++) { whitePawns.resize(8); whitePawns[i] = new QGraphicsRectItem(-225+60*i, -105, 30, 30 ); whitePawns[i]->setBrush(greenBrush); scene->addItem(whitePawns[i]); } //black pawns for (int i = 0; i < 8; i++) { blackPawns.resize(8); blackPawns[i] = new QGraphicsRectItem(-225+60*i, 195, 30, 30 ); blackPawns[i]->setBrush(darkGreenBrush); scene->addItem(blackPawns[i]); } // white and black pieces for (int i = 0; i < 2; i++) { whiteRooks.resize(2); whiteRooks[i] = new QGraphicsRectItem(-225+420*i,-165,30,30); whiteRooks[i]->setBrush(redBrush); scene->addItem(whiteRooks[i]); blackRooks.resize(2); blackRooks[i] = new QGraphicsRectItem(-225+420*i,255,30,30); blackRooks[i]->setBrush(darkRedBrush); scene->addItem(blackRooks[i]); whiteKnights.resize(2); whiteKnights[i] = new QGraphicsRectItem(-165+300*i,-165,30,30); whiteKnights[i]->setBrush(yellowBrush); scene->addItem(whiteKnights[i]); blackKnights.resize(2); blackKnights[i] = new QGraphicsRectItem(-165+300*i,255,30,30); blackKnights[i]->setBrush(darkYellowBrush); scene->addItem(blackKnights[i]); whiteBishops.resize(2); whiteBishops[i] = new QGraphicsRectItem(-105+180*i,-165,30,30); whiteBishops[i]->setBrush(blueBrush); scene->addItem(whiteBishops[i]); blackBishops.resize(2); blackBishops[i] = new QGraphicsRectItem(-105+180*i,255,30,30); blackBishops[i]->setBrush(darkBlueBrush); scene->addItem(blackBishops[i]); } whiteQueen = new QGraphicsRectItem(-45,-165,30,30); whiteQueen->setBrush(magentaBrush); scene->addItem(whiteQueen); blackQueen = new QGraphicsRectItem(-45,255,30,30); blackQueen->setBrush(darkMagentaBrush); scene->addItem(blackQueen); whiteKing = new QGraphicsRectItem(15,-165,30,30); whiteKing->setBrush(grayBrush); scene->addItem(whiteKing); blackKing = new QGraphicsRectItem(15,255,30,30); blackKing->setBrush(darkGrayBrush); scene->addItem(blackKing); }