[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/games/nonogram/src/gui
From:       Tom Vollerthun <vollerthun () gmx ! de>
Date:       2009-02-16 13:22:34
Message-ID: 1234790554.144773.12990.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 926952 by vollerthun:

- New feature: add keyboard controls for movement in grid and state toggle. There are \
not menu entries yet, so you must guess them :)

 M  +10 -0     a_grid.cpp  
 M  +49 -1     grid.cpp  
 M  +7 -1      grid.h  
 M  +31 -1     grid_center.cpp  
 M  +9 -3      grid_center.h  


--- trunk/playground/games/nonogram/src/gui/a_grid.cpp #926951:926952
@@ -80,6 +80,16 @@
 }
 
 void Abstract_Grid::selectCell(QPoint* newlySelectedCell) {
+
+    if ( newlySelectedCell->x() >= m_cols
+        || newlySelectedCell->y() >= m_rows
+        || newlySelectedCell->x() < 0
+        || newlySelectedCell->y() < 0) {
+
+        return;
+    }
+
+
     selectedCell = newlySelectedCell;
     update();
 }
--- trunk/playground/games/nonogram/src/gui/grid.cpp #926951:926952
@@ -30,8 +30,14 @@
 #include "colorselector.h"
 
 #include "ds/data.h"
+#include <kaction.h>
+#ifndef KXMLGUIWINDOW_H
+    #include <kxmlguiwindow.h>
+#endif
+#include <klocalizedstring.h>
+#include <KActionCollection>
 
-Grid::Grid(QWidget *parent) :
+Grid::Grid(KXmlGuiWindow *parent) :
     QWidget(parent)
 {
     setPalette(QPalette(QColor(200, 200, 200)));
@@ -69,8 +75,50 @@
 
     setLayout(gridLayout);
 
+    setupActions(parent);
+
 }
 
+void Grid::setupActions(KXmlGuiWindow *parent) {
+
+    KAction* upAction = new KAction(this);
+    upAction->setText(i18n("Up"));
+    upAction->setIcon(KIcon("up"));
+    upAction->setShortcut(Qt::Key_Up);
+    parent->actionCollection()->addAction("up", upAction);
+    connect(upAction, SIGNAL(triggered(bool)), central, SLOT(up()));
+
+    KAction* downAction = new KAction(this);
+    downAction->setText(i18n("Down"));
+    downAction->setIcon(KIcon("down"));
+    downAction->setShortcut(Qt::Key_Down);
+    parent->actionCollection()->addAction("down", downAction);
+    connect(downAction, SIGNAL(triggered(bool)), central, SLOT(down()));
+
+    KAction* leftAction = new KAction(this);
+    leftAction->setText(i18n("Left"));
+    leftAction->setIcon(KIcon("left"));
+    leftAction->setShortcut(Qt::Key_Left);
+    parent->actionCollection()->addAction("left", leftAction);
+    connect(leftAction, SIGNAL(triggered(bool)), central, SLOT(left()));
+
+    KAction* rightAction = new KAction(this);
+    rightAction->setText(i18n("Right"));
+    rightAction->setIcon(KIcon("right"));
+    rightAction->setShortcut(Qt::Key_Right);
+    parent->actionCollection()->addAction("right", rightAction);
+    connect(rightAction, SIGNAL(triggered(bool)), central, SLOT(right()));
+
+    KAction* toggleAction = new KAction(this);
+    toggleAction->setText(i18n("Toggle state"));
+    toggleAction->setIcon(KIcon("toggle"));
+    toggleAction->setShortcut(Qt::Key_Space);
+    parent->actionCollection()->addAction("toggle", toggleAction);
+    connect(toggleAction, SIGNAL(triggered(bool)), central, SLOT(toggleCurrent()));
+
+}
+
+
 void Grid::setData(Data * data)
 {
 
--- trunk/playground/games/nonogram/src/gui/grid.h #926951:926952
@@ -30,12 +30,16 @@
 
 #include "colorselector.h"
 #include "originalsize_picture.h"
+#ifndef KXMLGUIWINDOW_H
+    #include <kxmlguiwindow.h>
+#endif
+#include <KActionCollection>
 
 class Grid : public QWidget {
 Q_OBJECT
 
 public:
-	Grid(QWidget *parent);
+	Grid(KXmlGuiWindow *parent);
 	~Grid() {
 	}
 
@@ -59,6 +63,8 @@
 
     OriginalSizePicture * picturePreview;
 
+    void setupActions(KXmlGuiWindow *parent);
+
 };
 
 #endif
--- trunk/playground/games/nonogram/src/gui/grid_center.cpp #926951:926952
@@ -129,7 +129,7 @@
 
     if (event->button() == Qt::LeftButton) {
 
-        emit togglePosition(p->x(), p->y());
+        toggleCurrent();
     } else if (event->button() == Qt::MidButton) {
 
         emit toggle_UndefinedOn(p->x(), p->y());
@@ -148,6 +148,7 @@
 
 void GridCenter::mouseMoveEvent(QMouseEvent* event) {
     Abstract_Grid::mouseMoveEvent(event);
+
     if (lastPressedButton == Qt::LeftButton) {
 
         QPoint *p = getGridPositions(event);
@@ -173,6 +174,35 @@
         kDebug() << "Propagate change to: ["<<p->x()<<"/"<< p->y()<<"]";
 
         emit continueLastChange(p->x(), p->y());
+        emit cellSelected(p);
     }
 }
 
+void GridCenter::up() {
+    QPoint * newSelected = new QPoint(selectedCell->x(), selectedCell->y()-1);
+    emit cellSelected(newSelected);
+}
+
+void GridCenter::down() {
+    QPoint * newSelected = new QPoint(selectedCell->x(), selectedCell->y()+1);
+    emit cellSelected(newSelected);
+}
+
+void GridCenter::left() {
+    QPoint * newSelected = new QPoint(selectedCell->x()-1, selectedCell->y());
+    emit cellSelected(newSelected);
+}
+
+void GridCenter::right() {
+    QPoint * newSelected = new QPoint(selectedCell->x()+1, selectedCell->y());
+    emit cellSelected(newSelected);
+}
+
+void GridCenter::toggleCurrent() {
+    emit togglePosition(selectedCell->x(), selectedCell->y());
+}
+
+
+
+
+
--- trunk/playground/games/nonogram/src/gui/grid_center.h #926951:926952
@@ -39,18 +39,24 @@
 
     public:
         GridCenter(QWidget *parent);
-        ~GridCenter()
-        {
-        }
+        ~GridCenter() { }
+
     public slots:
         void setData(Data* newData);
+        void up();
+        void down();
+        void left();
+        void right();
+        void toggleCurrent();
 
     signals:
         void togglePosition(int x, int y);
         void toggle_UndefinedOn(int x, int y);
         void toggle_UndefinedOff(int x, int y);
+        void currentToggled();
         void continueLastChange(int x, int y);
 
+
     protected:
         bool doPaintHorizontal();
         bool doPaintVertical();


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic