void StarRating::paint(QPainter *painter, const QRect &rect, const QPalette &palette, EditMode mode) const { painter->save(); painter->setRenderHint(QPainter::Antialiasing, true); painter->setPen(Qt::NoPen); QBrush yellowBrush(QColor::fromCmyk(0,128,255,0)); if (mode == Editable) { painter->setBrush(palette.highlight()); } else { painter->setBrush(yellowBrush); } int yOffset = (rect.height() - PaintingScaleFactor) / 2; painter->translate(rect.x(), rect.y() + yOffset); painter->scale(PaintingScaleFactor, PaintingScaleFactor); for (int i = 0; i < m_maxStars; ++i) { if (i < m_stars) { painter->drawPolygon(m_starPolygon, Qt::WindingFill); } else if (mode == Editable) { painter->drawPolygon(m_diamondPolygon, Qt::WindingFill); } painter->translate(1.0, 0.0); } painter->restore(); }
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 ); }
/** 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); }
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); } } } }
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); }
/** * 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 } }
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(); }
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; }