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 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); }
/** 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); }
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 //} }
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; }
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 } }