m_renderer = new kMancalaRenderer(this);
setScene ( m_scene );
setSize(dim);
addItems();
}
void kMancalaBoard::positionItems() {
qDebug("positionItems(): Positioning items");
qreal height = sceneRect().height();
qreal width = sceneRect().width();
qreal middle = height/2;
int treasury_width = GAP_TREASURY_WIDTH+BORDER;
int gaps_space = width - 2*treasury_width;
int gap_offset = (gaps_space-(6*GAP_WIDTH))/7;
int left_offset = treasury_width + gap_offset;
treasury[0]->setPos(BORDER, middle-GAP_TREASURY_HEIGHT/2);
treasury[1]->setPos(width-BORDER-GAP_TREASURY_WIDTH, middle-GAP_TREASURY_HEIGHT/2);
for(int i = 0; i != 6; i++) {
hole[i]->setPos(left_offset+(i*(GAP_WIDTH+gap_offset)), height*0.3);
hole[i+6]->setPos(left_offset+(i*(GAP_WIDTH+gap_offset)), height*0.7-GAP_HEIGHT);
}
}
void kMancalaBoard::addItems() {
qDebug("addItems(): Adding items");
QPixmap bean
= m_renderer
->renderPixmap
("bean",
QSize(GAP_WIDTH, GAP_HEIGHT
));
for(int i = 0; i != 2; i++) {
treasury[i] = new kMancalaBoardGap(
m_renderer
->renderPixmap
("treasury",
QSize(GAP_TREASURY_WIDTH, GAP_TREASURY_HEIGHT
)),
bean
);
m_scene->addItem(treasury[i]);
}
for(int i =0; i != 12; i++) {
hole[i] = new kMancalaBoardGap(
m_renderer
->renderPixmap
("hole",
QSize(GAP_WIDTH, GAP_HEIGHT
)),
bean
);
m_scene->addItem(hole[i]);
}
}
kMancalaBoard::~kMancalaBoard() {
}
void kMancalaBoard
::drawBackground(QPainter *painter,
const QRectF &rect
) { qDebug("drawBackground(): Drawing background");
if ( m_renderer
->elementExists
( QString ( "board" ) ) ) { qDebug ("drawBackground(): -> Rendering" );
m_renderer
->render
(painter,
QString ( "background" ), rect
);
m_renderer
->render
(painter,
QString ( "board" ), rect
);
} else {
qDebug ("drawBackground(): -> No background found" );
}
}
qDebug("resizeEvent(): Resize event");
setSize(s);
positionItems();
qDebug("resizeEvent(): -> Scene size now %d x %d", s.width(), s.height());
}
void kMancalaBoard
::setSize(QSize s
) { qDebug("setSize(): Setting size");
qDebug("setSize(): -> Setting scene to %d x %d", s.width(), s.height());
m_scene
->setSceneRect
(QRectF(0,
0,s.
width()-10,s.
height()-10));
QRectF scene_rect
= m_scene
->sceneRect
();
qDebug("setSize(): -> Scene rectangle: x: %lf, y: %lf, width: %lf, height: %lf", scene_rect.x(), scene_rect.y(), scene_rect.width(), scene_rect.height());
}
kMancalaBoard::kMancalaBoard ( QSize dim = QSize(850, 475), QWidget *parent = 0 )
: QGraphicsView (parent) {
m_scene = new QGraphicsScene();
m_renderer = new kMancalaRenderer(this);
setScene ( m_scene );
setSize(dim);
addItems();
}
void kMancalaBoard::positionItems() {
qDebug("positionItems(): Positioning items");
qreal height = sceneRect().height();
qreal width = sceneRect().width();
qreal middle = height/2;
int treasury_width = GAP_TREASURY_WIDTH+BORDER;
int gaps_space = width - 2*treasury_width;
int gap_offset = (gaps_space-(6*GAP_WIDTH))/7;
int left_offset = treasury_width + gap_offset;
treasury[0]->setPos(BORDER, middle-GAP_TREASURY_HEIGHT/2);
treasury[1]->setPos(width-BORDER-GAP_TREASURY_WIDTH, middle-GAP_TREASURY_HEIGHT/2);
for(int i = 0; i != 6; i++) {
hole[i]->setPos(left_offset+(i*(GAP_WIDTH+gap_offset)), height*0.3);
hole[i+6]->setPos(left_offset+(i*(GAP_WIDTH+gap_offset)), height*0.7-GAP_HEIGHT);
}
}
void kMancalaBoard::addItems() {
qDebug("addItems(): Adding items");
QPixmap bean = m_renderer->renderPixmap("bean", QSize(GAP_WIDTH, GAP_HEIGHT));
for(int i = 0; i != 2; i++) {
treasury[i] = new kMancalaBoardGap(
m_renderer->renderPixmap("treasury", QSize(GAP_TREASURY_WIDTH, GAP_TREASURY_HEIGHT)),
bean
);
m_scene->addItem(treasury[i]);
}
for(int i =0; i != 12; i++) {
hole[i] = new kMancalaBoardGap(
m_renderer->renderPixmap("hole", QSize(GAP_WIDTH, GAP_HEIGHT)),
bean
);
m_scene->addItem(hole[i]);
}
}
kMancalaBoard::~kMancalaBoard() {
}
void kMancalaBoard::drawBackground(QPainter *painter, const QRectF &rect) {
qDebug("drawBackground(): Drawing background");
if ( m_renderer->elementExists ( QString ( "board" ) ) ) {
qDebug ("drawBackground(): -> Rendering" );
m_renderer->render(painter, QString ( "background" ), rect);
m_renderer->render(painter, QString ( "board" ), rect);
} else {
qDebug ("drawBackground(): -> No background found" );
}
QGraphicsView::drawBackground(painter, rect);
}
void kMancalaBoard::resizeEvent(QResizeEvent *event) {
qDebug("resizeEvent(): Resize event");
QSize s = size();
setSize(s);
positionItems();
qDebug("resizeEvent(): -> Scene size now %d x %d", s.width(), s.height());
}
void kMancalaBoard::setSize(QSize s) {
qDebug("setSize(): Setting size");
qDebug("setSize(): -> Setting scene to %d x %d", s.width(), s.height());
m_scene->setSceneRect(QRectF(0,0,s.width()-10,s.height()-10));
QRectF scene_rect = m_scene->sceneRect();
qDebug("setSize(): -> Scene rectangle: x: %lf, y: %lf, width: %lf, height: %lf", scene_rect.x(), scene_rect.y(), scene_rect.width(), scene_rect.height());
}
To copy to clipboard, switch view to plain text mode
pixmapBean = pBean;
pixmapGap = pGap;
beans = 0;
}
kMancalaBoardGap::~kMancalaBoardGap() {
}
QRectF kMancalaBoardGap
::boundingRect() const { return QRectF(0,
0, pixmapGap.
width(), pixmapGap.
height());
}
qDebug("kMancalaBoardGap::paint(): Painting gap");
//painter->fillRect(0,0,pixmapGap.width(), pixmapGap.height(), Qt::transparent);
painter->drawPixmap(0,0,pixmapGap);
}
kMancalaBoardGap::kMancalaBoardGap(QPixmap pGap, QPixmap pBean)
: QGraphicsItem() {
pixmapBean = pBean;
pixmapGap = pGap;
beans = 0;
}
kMancalaBoardGap::~kMancalaBoardGap() {
}
QRectF kMancalaBoardGap::boundingRect() const {
return QRectF(0, 0, pixmapGap.width(), pixmapGap.height());
}
void kMancalaBoardGap::paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
QWidget* widget) {
qDebug("kMancalaBoardGap::paint(): Painting gap");
//painter->fillRect(0,0,pixmapGap.width(), pixmapGap.height(), Qt::transparent);
painter->drawPixmap(0,0,pixmapGap);
}
To copy to clipboard, switch view to plain text mode
Bookmarks