//Draw pawns on checkerboard (color cells of TableWidget)
void szachownica::draw_pawns(QTableWidget *parent, std::vector<std::vector<pawn> > board)
{
    for(int row=0;row<size;row++)
    {
        for(int col=0;col<size;col++)
        {
            parent->setItem(row,col,new QTableWidgetItem);
            if(board[row][col].type == pawn::PAWN && board[row][col].isSelected()) setCellColor(parent,row,col,Qt::green);
            else if(board[row][col].type == pawn::PAWN && board[row][col].side == pawn::RED) setCellColor(parent,row,col,Qt::red);
            else if(board[row][col].type == pawn::PAWN && board[row][col].side == pawn::BLUE) setCellColor(parent,row,col,Qt::blue);
            else if(board[row][col].type == pawn::EMPTY_FIELD) setCellColor(parent,row,col,Qt::black);
            else if(board[row][col].type == pawn::FORBIDDEN) setCellColor(parent,row,col,Qt::gray);
            else;

            if(board[row][col].isDamka() && board[row][col].side == pawn::RED)
            {
                QColor orange;
                orange.setRgb(255,128,0,255);
                setCellColor(parent,row,col,orange);
            }
            else if(board[row][col].isDamka() && board[row][col].side == pawn::BLUE)
            {
                QColor cyan;
                cyan.setRgb(0,230,255,255);
                setCellColor(parent,row,col,cyan);
            }
        }

    }

}
//Draw checkerboard (a TableWidget)
void szachownica::draw(QTableWidget* checkboard)
{
    checkboard->setColumnCount(size);
    checkboard->setRowCount(size);

    for(int i=0;i<checkboard->columnCount();i++)
    {
     checkboard->setRowHeight(i,50);
     checkboard->setColumnWidth(i,50);
    }
    checkboard->horizontalHeader()->hide();
    checkboard->verticalHeader()->hide();
    checkboard->verticalHeader()->hide();

    int row,col;
    row=0;
    col=1;
    for(row;row<size;row++)
    {
        for(col;col<size;col=col+2)
        {
            checkboard->setItem(row,col,new QTableWidgetItem);
            setCellColor(checkboard,row,col,Qt::black);
        }
        if(row%2==0) col = 0;
        else col = 1;
    }
    checkboard->setMaximumWidth(size*checkboard->columnWidth(0)+2);
    checkboard->setMaximumHeight(size*checkboard->rowHeight(1)+2);
    checkboard->setMinimumWidth(size*checkboard->columnWidth(0)+2);
    checkboard->setMinimumHeight(size*checkboard->rowHeight(1)+2);

}
示例#3
0
MainWindow::MainWindow(QWidget *parent) :
    QWidget(parent)
{
    QHBoxLayout* layoutH=new QHBoxLayout;
    QVBoxLayout* layoutV=new QVBoxLayout;

    MyField* field = new MyField;
    field->setMinimumSize(500,500);
    layoutH->addWidget(field);

    layoutH->addLayout(layoutV);

    dl = new QColorDialog();

    QLabel* lbl1=new QLabel("Set universe size");
    lbl1->setFixedHeight(10);
    layoutV->addWidget(lbl1);

    spinBox1 = new QSpinBox;
    spinBox1->setFixedSize(90,30);
    spinBox1->setValue(50);
    spinBox1->setMaximum(50);
    spinBox1->setMinimum(5);
    layoutV->addWidget(spinBox1);
    QObject::connect(spinBox1,SIGNAL(valueChanged(int)),field,SLOT(changeUniverseSize(int)));

    QLabel* lbl2=new QLabel("Set interval size");
    lbl2->setFixedHeight(10);
    layoutV->addWidget(lbl2);

    spinBox2 = new QSpinBox;
    spinBox2->setFixedSize(90,30);
    spinBox2->setValue(50);
    spinBox2->setMaximum(1000);
    spinBox2->setMinimum(10);
    layoutV->addWidget(spinBox2);
    QObject::connect(spinBox2,SIGNAL(valueChanged(int)),field,SLOT(changeInterval(int)));

    btnStart = new QPushButton("Start");
    btnStart->setFixedSize(90,30);
    QObject::connect(btnStart,SIGNAL(clicked()),field,SLOT(startGame()));
    layoutV->addWidget(btnStart);

    btnStop = new QPushButton("Stop");
    btnStop->setFixedSize(90,30);
    QObject::connect(btnStop,SIGNAL(clicked()),field,SLOT(stopGame()));
    layoutV->addWidget(btnStop);

    btnClear = new QPushButton("Clear");
    btnClear->setFixedSize(90,30);
    QObject::connect(btnClear,SIGNAL(clicked()),field,SLOT(clearUniverse()));
    layoutV->addWidget(btnClear);

    setColor = new QPushButton("Set color");
    setColor->setFixedSize(90,30);
    QObject::connect( setColor,SIGNAL(clicked()),this,SLOT(setCellColor()));
    QObject::connect(dl,SIGNAL(colorSelected(QColor)),field,SLOT(changeColor(QColor)));
    layoutV->addWidget( setColor);

    btnNewRules=new QPushButton("New Rules");
    btnNewRules->setFixedSize(90,30);
    QObject::connect(btnNewRules,SIGNAL(clicked()),field,SLOT(newRules()));
    layoutV->addWidget(btnNewRules);

    ResetRules=new QPushButton("Reset Rules");
    ResetRules->setFixedSize(90,30);
    QObject::connect(ResetRules,SIGNAL(clicked()),field,SLOT(resetRules()));
    layoutV->addWidget(ResetRules);


    this->setLayout(layoutH);
}
示例#4
0
void cell::drawCell() {
    setCellColor();
    ofRect(pos_x + 1, pos_y + 1, width - 2, width - 2);
}
//Highlight cell at position (row,col) in TableWidget
void szachownica::highlight_selected(QTableWidget *parent, int row, int col)
{
    setCellColor(parent, row, col, Qt::green);
}