Commit b7cff027 authored by Johannes Bergmeier's avatar Johannes Bergmeier
Browse files

- Some small fixes in the new view

- Added entering values with LMB-click

svn path=/trunk/KDE/kdegames/ksudoku/; revision=791892
parent 97552792
......@@ -32,6 +32,7 @@ public:
void setValues(QVector<ColoredValue> values);
protected:
void hoverEnterEvent(QGraphicsSceneHoverEvent* event);
void mousePressEvent(QGraphicsSceneMouseEvent* event);
private:
void updatePixmap();
private:
......@@ -70,6 +71,11 @@ void CellGraphicsItem::hoverEnterEvent(QGraphicsSceneHoverEvent* event) {
m_scene->hover(m_id);
}
void CellGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent* event) {
// TODO make action dependant on button
m_scene->press(m_id);
}
void CellGraphicsItem::setType(SpecialType type) {
if(type == m_type) return;
m_type = type;
......@@ -309,6 +315,8 @@ View2DScene::~View2DScene() {
}
void View2DScene::init(const Game& game) {
m_selectedValue = 1;
m_game = game;
m_background = new QGraphicsPixmapItem();
......@@ -337,6 +345,8 @@ void View2DScene::init(const Game& game) {
m_cells[i]->setType(SpecialCell);
if(game.value(i))
m_cells[i]->setValues(QVector<ColoredValue>() << ColoredValue(game.value(i),0));
else
m_cells[i]->setValues(QVector<ColoredValue>());
}
Graph2d* g2 = dynamic_cast<Graph2d*>(g);
......@@ -393,6 +403,10 @@ void View2DScene::hover(int cell) {
emit cellHovered(cell);
}
void View2DScene::press(int cell) {
m_game.setValue(cell, m_selectedValue);
}
void View2DScene::update(int cell) {
if(cell < 0) {
for(int i = 0; i < m_game.size(); ++i) {
......@@ -400,9 +414,11 @@ void View2DScene::update(int cell) {
if(m_game.given(i))
m_cells[i]->setType(SpecialCellPreset);
else
m_cells[cell]->setType(SpecialCell);
m_cells[i]->setType(SpecialCell);
if(m_game.value(i))
m_cells[i]->setValues(QVector<ColoredValue>() << ColoredValue(m_game.value(i),0));
else
m_cells[i]->setValues(QVector<ColoredValue>());
}
} else {
if(m_game.given(cell))
......@@ -411,9 +427,15 @@ void View2DScene::update(int cell) {
m_cells[cell]->setType(SpecialCell);
if(m_game.value(cell))
m_cells[cell]->setValues(QVector<ColoredValue>() << ColoredValue(m_game.value(cell),0));
else
m_cells[cell]->setValues(QVector<ColoredValue>());
}
}
void View2DScene::selectValue(int value) {
m_selectedValue = value;
}
View2D::View2D(QWidget *parent, const Game& game) : QGraphicsView(parent) {
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
......@@ -431,7 +453,6 @@ View2D::View2D(QWidget *parent, const Game& game) : QGraphicsView(parent) {
}
View2D::~View2D() {
qDebug() << m_scene;
delete m_scene;
}
......@@ -442,10 +463,15 @@ void View2D::resizeEvent(QResizeEvent* e) {
}
void View2D::update(int cell) {
qDebug() << "update";
if(!m_scene) return;
m_scene->update(cell);
}
void View2D::selectValue(int value) {
if(!m_scene) return;
m_scene->selectValue(value);
}
}
......@@ -25,7 +25,11 @@ public:
void setSceneSize(const QSize& size);
void hover(int cell);
void press(int cell);
void update(int cell = -1);
void selectValue(int val);
signals:
void cellHovered(int cell);
private:
......@@ -36,6 +40,8 @@ private:
QVector<CellGraphicsItem*> m_cells;
QGraphicsPixmapItem* m_cursor;
Game m_game;
int m_selectedValue;
};
class View2D : public QGraphicsView, public ViewInterface {
......@@ -48,7 +54,7 @@ public:
QWidget* widget() { return this; }
public slots:
void setCursor(int cell) { Q_UNUSED(cell) }
void selectValue(int value) { Q_UNUSED(value) }
void selectValue(int value);
void setSymbols(SymbolTable* table) { Q_UNUSED(table) }
void setFlags(ViewFlags flags) { Q_UNUSED(flags) }
void update(int cell = -1);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment