void Board::mousePressEvent(QMouseEvent *e) { // calculate position int pos_x = (e->pos().x() - XBORDER <0)?-1: (e->pos().x() - XBORDER) / pm_tile[0]->width(); int pos_y = (e->pos().y() - YBORDER <0)?-1: (e->pos().y() - YBORDER) / pm_tile[0]->height(); // Mark tile if(e->button() == LeftButton) { if(highlighted_tile != -1) { int oldmarkx = mark_x; int oldmarky = mark_y; mark_x=-1; mark_y=-1; for(int i = 0; i < x_tiles(); i++) for(int j = 0; j < y_tiles(); j++){ if( highlighted_tile == getField(i, j)) updateField(i, j); } mark_x = oldmarkx; mark_y = oldmarky; // no tile selected highlighted_tile = -1; } if(pos_x >= 0 && pos_x < x_tiles() && pos_y >= 0 && pos_y < y_tiles()) emit fieldClicked(pos_x, pos_y); } // Assist by lighting all tiles of same type if(e->button() == RightButton) { int field = getField(pos_x,pos_y); highlighted_tile = field; for(int i = 0; i < x_tiles(); i++) for(int j = 0; j < y_tiles(); j++){ if( field == getField(i, j)){ mark_x=i; mark_y=j; } else{ mark_x=-1; mark_y=-1; } updateField(i, j); } mark_x=-1; mark_y=-1; // no tile selected } }
void RecordContentWidget::onFieldClicked(types::rfield_id id) { emit fieldClicked(id); }