Commit 628222fa authored by Matt Williams's avatar Matt Williams
Browse files

Enable dynamic zooming of gameboard for usability

svn path=/trunk/playground/games/ksquares/; revision=616237
parent 697f7a0b
......@@ -14,7 +14,7 @@ set(ksquares_SRCS
kde4_automoc(${ksquares_SRCS})
kde4_add_ui_files(ksquares_SRCS newgamedialog.ui scoresdialog.ui prefs_base.ui prefs_ai.ui)
kde4_add_ui_files(ksquares_SRCS newgamedialog.ui scoresdialog.ui prefs_base.ui prefs_ai.ui prefs_display.ui)
kde4_add_kcfg_files(ksquares_SRCS GENERATE_MOC settings.kcfgc) #GENERATE_MOC is not needed but it doesn't work without it for some reason :S
......
......@@ -28,7 +28,7 @@ GameBoardScene::GameBoardScene(int newWidth, int newHeight, QWidget *parent) : Q
{
int x = iWidth*spacing;
int y = iHeight*spacing;
addEllipse(QRectF(-1,-1,2,2))->setPos(x,y);
addEllipse(QRectF(-1,-1,2,2), QPen(Qt::SolidLine), QBrush(Qt::SolidPattern))->setPos(x,y);
}
}
QPen feintPen(Qt::DotLine);
......@@ -183,7 +183,6 @@ void GameBoardScene::checkForNewSquares()
void GameBoardScene::setSquareOwner(int squareIndex, int owner)
{
//kdDebug() << "Square " << squareIndex << " owned by player " << owner << "." << endl;
squareOwnerTable[squareIndex] = owner;
drawSquare(squareIndex);
}
......
......@@ -11,6 +11,7 @@
using std::cout;
using std::endl;
#include "settings.h"
#include "gameboardview.h"
GameBoardView::GameBoardView(QWidget *parent) : QGraphicsView(parent)
......@@ -29,13 +30,32 @@ void GameBoardView::createBoard(int height, int width)
return;
gameScene = new GameBoardScene(height, width, this);
setScene(gameScene);
//emit gameStarted();
setBoardSize();
}
void GameBoardView::mouseMoveEvent(QMouseEvent* e)
void GameBoardView::mouseMoveEvent(QMouseEvent* event)
{
//cout << "GameBoardView::mouseMoveEvent" << endl;
QGraphicsView::mouseMoveEvent(e);
QGraphicsView::mouseMoveEvent(event);
}
void GameBoardView::resizeEvent(QResizeEvent* event)
{
QGraphicsView::resizeEvent(event);
setBoardSize();
}
void GameBoardView::setBoardSize()
{
if(Settings::resizeBoard() == true)
{
if (scene() != 0)
fitInView(scene()->sceneRect(), Qt::KeepAspectRatio);
}
else
{
resetMatrix();
}
}
#include "gameboardview.moc"
......@@ -24,8 +24,10 @@ class GameBoardView : public QGraphicsView
QSize sizeHint() {return scene()->sizeHint();}
public slots:
void createBoard(int height, int width);
void setBoardSize();
protected:
void mouseMoveEvent(QMouseEvent* e);
void mouseMoveEvent(QMouseEvent* event);
void resizeEvent(QResizeEvent* event);
GameBoardScene* gameScene;
signals:
//void gameStarted();
......
......@@ -158,12 +158,18 @@ void KSquares::gameOver(QVector<KSquaresPlayer> playerList)
void KSquares::optionsPreferences()
{
KConfigDialog *dialog = new KConfigDialog(this, "settings", Settings::self());
QWidget *displaySettingsDlg = new QWidget;
ui_prefs_display.setupUi(displaySettingsDlg);
dialog->addPage(displaySettingsDlg, i18n("Display"), "ksquares_display");
QWidget *aiSettingsDlg = new QWidget;
ui_prefs_ai.setupUi(aiSettingsDlg);
dialog->addPage(aiSettingsDlg, i18n("AI"), "ksquares_ai");
//connect(dialog, SIGNAL(settingsChanged(const QString &)), m_view, SLOT(settingsChanged()));
connect(dialog, SIGNAL(settingsChanged(const QString &)), m_view, SLOT(setBoardSize()));
dialog->show();
}
void KSquares::playerChanged(int playerNumber)
......
......@@ -19,8 +19,9 @@
#include "gameboardview.h"
#include "ksquaresgame.h"
#include "ui_prefs_base.h"
//#include "ui_prefs_base.h"
#include "ui_prefs_ai.h"
#include "ui_prefs_display.h"
class KToggleAction;
......@@ -41,8 +42,9 @@ class KSquares : public KMainWindow
private:
void setupAccel();
void setupActions();
Ui::prefs_base ui_prefs_base;
//Ui::prefs_base ui_prefs_base;
Ui::prefs_ai ui_prefs_ai;
Ui::prefs_display ui_prefs_display;
GameBoardView *m_view;
KSquaresGame* sGame;
......
......@@ -34,4 +34,11 @@ http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<default>0</default>
</entry>
</group>
<group name="Display">
<entry name="ResizeBoard" type="Bool">
<label>Fit board to view</label>
<whatsthis>Maximise the board so it fills the whole screen</whatsthis>
<default>0</default>
</entry>
</group>
</kcfg>
<ui version="4.0" >
<class>prefs_display</class>
<widget class="QWidget" name="prefs_display" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle" >
<string>Display Settings</string>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="0" >
<widget class="QCheckBox" name="kcfg_ResizeBoard" >
<property name="text" >
<string>Fit board to view</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
......@@ -2,4 +2,4 @@
File=ksquares.kcfg
ClassName=Settings
Singleton=true
Mutators=PlayerNames,BoardWidth,BoardHeight,NumOfPlayers, Difficulty, HumanList
Mutators=PlayerNames,BoardWidth,BoardHeight,NumOfPlayers, Difficulty, HumanList, ResizeBoard
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