summaryrefslogtreecommitdiff
path: root/noncore
Side-by-side diff
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/backgammon/backgammon.cpp131
-rw-r--r--noncore/games/backgammon/backgammon.h32
-rw-r--r--noncore/games/backgammon/backgammonview.cpp14
-rw-r--r--noncore/games/backgammon/backgammonview.h10
-rw-r--r--noncore/games/backgammon/definition.cpp1
-rw-r--r--noncore/games/backgammon/displaydialog.cpp89
-rw-r--r--noncore/games/backgammon/displaydialog.h30
-rw-r--r--noncore/games/backgammon/moveengine.cpp2
-rw-r--r--noncore/games/backgammon/moveengine.h2
-rw-r--r--noncore/games/backgammon/rulesdialog.h1
10 files changed, 56 insertions, 256 deletions
diff --git a/noncore/games/backgammon/backgammon.cpp b/noncore/games/backgammon/backgammon.cpp
index 38ccb49..c40f462 100644
--- a/noncore/games/backgammon/backgammon.cpp
+++ b/noncore/games/backgammon/backgammon.cpp
@@ -1,53 +1,33 @@
#include "backgammon.h"
#include "aidialog.h"
-#include "displaydialog.h"
#include "filedialog.h"
#include "playerdialog.h"
#include "rulesdialog.h"
#include "themedialog.h"
#include <qdatetime.h>
#include <qfile.h>
+#include <qlayout.h>
#include <qmessagebox.h>
#include <qstring.h>
#include <qtimer.h>
+#include <qmainwindow.h>
#include <qpe/qpeapplication.h>
#include <qpe/config.h>
#include <qpe/qpemenubar.h>
#include <qpe/resource.h>
#include <stdlib.h>
-BackGammonView::BackGammonView(QCanvas* canvas,QWidget* parent)
- :QCanvasView(canvas,parent)
-{
- //do nothing
-}
-
-
-
-BackGammonView::~BackGammonView()
-{
- //do nothing
-}
-
-
-
-void BackGammonView::contentsMousePressEvent(QMouseEvent* e)
-{
- int x=e->x();
- int y=e->y();
- emit mouse(x,y);
-}
BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl)
- : QWidget(parent, name, fl)
+ : QMainWindow(parent, name, fl)
{
if (!name) setName("BackGammon");
setCaption("Backgammon");
setIcon( Resource::loadPixmap( "backgammon" ) );
//general counter varaible
int a=0;
//the game engine
move=new MoveEngine();
@@ -91,31 +71,16 @@ BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl)
ai.rescue=conf.readNumEntry("rescue",6);
ai.eliminate=conf.readNumEntry("eliminate",4);
ai.expose=conf.readNumEntry("expose",1);
ai.protect=conf.readNumEntry("protect",5);
ai.safe=conf.readNumEntry("safe",3);
ai.empty=conf.readNumEntry("empty",2);
move->setAISettings(ai);
- //non qte styles are smaller
- conf.setGroup("display");
- display.small=conf.readBoolEntry("small",false);
- display.warning=conf.readBoolEntry("warning",true);
- non_qte=display.small;
- if(display.warning)
- {
- Config test("qpe");
- test.setGroup("Appearance");
- if(test.readEntry("Style")!="QPE")
- {
- displaySettings();
- }
- }
- offset=(non_qte) ? 5 : 0;
//get the theme component names
Config theme(theme_file,Config::File);
if(!theme.isValid())
{
qDebug("theme file does not exist");
theme.setGroup("theme");
theme.writeEntry("board","casino_board_1");
@@ -158,36 +123,31 @@ BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl)
thememenu->insertItem("Delete",this,SLOT(deletetheme()));
menuBar->insertItem("Theme",thememenu);
QPopupMenu* optionmenu=new QPopupMenu(this);
optionmenu->insertItem("Player",this,SLOT(playerselect()));
optionmenu->insertSeparator();
optionmenu->insertItem("AI",this,SLOT(modify_AI()));
optionmenu->insertItem("Rules",this,SLOT(setrules()));
- optionmenu->insertItem("Display",this,SLOT(displaySettings()));
menuBar->insertItem("Options",optionmenu);
- //status bar
- message=new QLabel("<b>Backgammon</b>",this);
- message->setGeometry(0,260,237,20);
- message->setAlignment(AlignHCenter);
-
+ QWidget* mainarea=new QWidget(this);
+ setCentralWidget(mainarea);
//the main area
- area=new QCanvas(235-2*offset,235-2*offset);
- boardview=new BackGammonView(area,this);
+ QBoxLayout* layout=new QBoxLayout(mainarea,QBoxLayout::TopToBottom);
+ area=new QCanvas(235,235);
+ boardview=new BackGammonView(area,mainarea);
+ boardview->setMaximumHeight(240);
+ layout->addWidget(boardview);
connect(boardview,SIGNAL(mouse(int,int)),this,SLOT(mouse(int,int)));
- if(non_qte)
- {
- boardview->setGeometry(5,20,229,229);
- }
- else
- {
- boardview->setGeometry(1,20,237,237);
- }
+ //status bar
+ message=new QLabel("<b>Backgammon</b>",mainarea);
+ message->setAlignment(AlignHCenter);
+ layout->addWidget(message);
//the marker
marker_current=new QCanvasRectangle(area);
marker_current->setBrush(QColor(0,0,255));
marker_current->setSize(15,5);
marker_current->setZ(1);
for(a=0;a<4;a++)
@@ -243,77 +203,69 @@ BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl)
QImage oddsbg_all=(Resource::loadImage("backgammon/odds/"+odds_name));
//oddsDice=new CanvasImageItem*[6];
for(a=0;a<7;a++)
{
QImage dicebgA=dicebgA_all.copy(a*25,0,25,25);
diceA1[a]=new CanvasImageItem(dicebgA,area);
- diceA1[a]->setX(5-offset);
- diceA1[a]->setY(205-2*offset);
+ diceA1[a]->setX(5);
+ diceA1[a]->setY(205-2);
diceA1[a]->setZ(1);
diceA1[a]->setSize(25,25);
diceA2[a]=new CanvasImageItem(dicebgA,area);
- diceA2[a]->setX(35-offset);
- diceA2[a]->setY(205-2*offset);
+ diceA2[a]->setX(35);
+ diceA2[a]->setY(205-2);
diceA2[a]->setZ(1);
diceA2[a]->setSize(25,25);
QImage dicebgB=dicebgB_all.copy(a*25,0,25,25);
diceB1[a]=new CanvasImageItem(dicebgB,area);
- diceB1[a]->setX(175-offset);
- diceB1[a]->setY(205-2*offset);
+ diceB1[a]->setX(175);
+ diceB1[a]->setY(205-2);
diceB1[a]->setZ(1);
diceB1[a]->setSize(25,25);
diceB2[a]=new CanvasImageItem(dicebgB,area);
- diceB2[a]->setX(205-offset);
- diceB2[a]->setY(205-2*offset);
+ diceB2[a]->setX(205);
+ diceB2[a]->setY(205-2);
diceB2[a]->setZ(1);
diceB2[a]->setSize(25,25);
/*
if(a<6)
{
QImage oddsbg=oddsbg_all.copy(a*15,0,15,15);
oddsDice[a]=new CanvasImageItem(oddsbg,area);
- oddsDice[a]->setX(110-offset);
- oddsDice[a]->setY(210-2*offset);
+ oddsDice[a]->setX(110);
+ oddsDice[a]->setY(210-2);
oddsDice[a]->setZ(1);
oddsDice[a]->setSize(15,15);
oddsDice[a]->hide();
}
*/
}
//oddsDice[0]->show();
//set the board
QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name));
- if(non_qte)
- {
- boardbg=boardbg.copy(offset,offset,235-2*offset,200-2*offset);
- }
board=new CanvasImageItem(boardbg,area);
board->setX(0);
board->setY(0);
board->setZ(0);
- board->setSize(235-2*offset,200-2*offset);
+ board->setSize(235-2,200-2);
board->show();
//the table
QImage tablebg(Resource::loadImage("backgammon/table/"+table_name));
- if(non_qte)
- {
- tablebg=tablebg.copy(offset,0,235-offset,200);
- }
table=new CanvasImageItem(tablebg,area);
table->setX(0);
- table->setY(200-2*offset);
+ table->setY(200-2);
table->setZ(0);
- table->setSize(235-2*offset,20);
+ table->setSize(235-2,20);
table->show();
//the no move marker
QImage nomovebg(Resource::loadImage("backgammon/no_move"));
nomove_marker=new CanvasImageItem(nomovebg,area);
nomove_marker->setX(0);
nomove_marker->setY(200);
nomove_marker->setZ(2);
@@ -594,34 +546,21 @@ void BackGammon::setrules()
rules=rulesdialog->getRules();
Config conf("backgammon");
conf.setGroup("rules");
conf.writeEntry("move_with_pieces_out",rules.move_with_pieces_out);
conf.writeEntry("nice_dice",rules.generous_dice);
move->setRules(rules);
}
-void BackGammon::displaySettings()
-{
- DisplayDialog* displaydialog=new DisplayDialog(this);
- displaydialog->setDisplaySettings(display);
- if(!displaydialog->exec())
- return;
- display=displaydialog->getDisplaySettings();
- Config conf("backgammon");
- conf.setGroup("display");
- conf.writeEntry("small",display.small);
- conf.writeEntry("warning",display.warning);
- QMessageBox::warning(this,"Backgammon","changed display settings will\nonly take place after game has\nbeen restarted","OK");
-}
void BackGammon::draw()
{
Pieces pieces;
- move->position(pieces,non_qte);
+ move->position(pieces);
for(int a=0;a<15;a++)
{
if(!pieces.player1[a].side)
{
p1[a]->setX(pieces.player1[a].x);
p1[a]->setY(pieces.player1[a].y);
p1[a]->setZ(pieces.player1[a].z);
p1[a]->show();
@@ -664,33 +603,33 @@ void BackGammon::mouse(int x,int y)
}
if(y<=200) //move pieces
{
if((player==1 && player1_auto) || (player==2 && player2_auto))
return;
Marker marker;
- move->boardpressed(x,y,marker,non_qte);
+ move->boardpressed(x,y,marker);
if(marker.visible_current)
{
- marker_current->setX(marker.x_current-offset);
+ marker_current->setX(marker.x_current);
marker_current->setY(marker.y_current);
marker_current->show();
}
else
{
marker_current->hide();
}
for(int a=0;a<4;a++)
{
if(marker.visible_next[a])
{
- marker_next[a]->setX(marker.x_next[a]-offset);
+ marker_next[a]->setX(marker.x_next[a]);
marker_next[a]->setY(marker.y_next[a]);
marker_next[a]->show();
}
else
{
marker_next[a]->hide();
}
}
@@ -980,27 +919,19 @@ void BackGammon::autoroll_dice1()
void BackGammon::autoroll_dice2()
{
mouse(170,210);
}
void BackGammon::applytheme()
{
QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name));
- if(non_qte)
- {
- boardbg=boardbg.copy(offset,offset,235-2*offset,200-2*offset);
- }
board->setImage(boardbg);
QImage tablebg(Resource::loadImage("backgammon/table/"+table_name));
- if(non_qte)
- {
- tablebg=tablebg.copy(offset,0,235-offset,200);
- }
table->setImage(tablebg);
QImage piece_1_all(Resource::loadImage("backgammon/pieces/"+piecesA_name));
QImage piece_1_front=piece_1_all.copy(0,0,15,15);
QImage piece_1_side=piece_1_all.copy(0,15,15,5);
QImage piece_2_all(Resource::loadImage("backgammon/pieces/"+piecesB_name));
QImage piece_2_front=piece_2_all.copy(0,0,15,15);
diff --git a/noncore/games/backgammon/backgammon.h b/noncore/games/backgammon/backgammon.h
index 40dbaba..e3276f1 100644
--- a/noncore/games/backgammon/backgammon.h
+++ b/noncore/games/backgammon/backgammon.h
@@ -1,64 +1,51 @@
#ifndef BACKGAMMON_H
#define BACKGAMMON_H
+#include "backgammonview.h"
#include "canvasimageitem.h"
-#include "definition.h"
//#include "rulesdialog.h"
#include "moveengine.h"
-#include <qcanvas.h>
+
#include <qlabel.h>
-#include <qlineedit.h>
-#include <qwidget.h>
+#include <qmainwindow.h>
+//#include <qwidget.h>
-class BackGammonView : public QCanvasView
-{
- Q_OBJECT
-public:
- BackGammonView(QCanvas* canvas,QWidget* parent);
- ~BackGammonView();
-signals:
- void mouse(int,int);
-private:
- void contentsMousePressEvent(QMouseEvent* e);
-};
-class BackGammon : public QWidget
+
+class BackGammon : public QMainWindow
{
Q_OBJECT
private:
//GUI
- //is the style not qte ?
- bool non_qte;
- int offset;
//the "status" bar
- QLineEdit* inputfield;
+ QLabel* message;
//the main drawing area
QCanvas* area;
BackGammonView* boardview;
CanvasImageItem* board;
CanvasImageItem* table;
CanvasImageItem** p1;
CanvasImageItem** p2;
CanvasImageItem** p1_side;
CanvasImageItem** p2_side;
CanvasImageItem** diceA1;
CanvasImageItem** diceA2;
CanvasImageItem** diceB1;
CanvasImageItem** diceB2;
//CanvasImageItem** oddsDice;
CanvasImageItem* nomove_marker;
-
+
QCanvasRectangle* marker_current;
QCanvasRectangle* marker_next[4];
- QLabel* message;
+
//ENGINE
MoveEngine* move;
//the dice values
int diceA1_value;
int diceA2_value;
int diceA3_value;
int diceA4_value;
int diceB1_value;
@@ -108,17 +95,16 @@ private slots:
void deletegame();
void newtheme();
void loadtheme();
void savetheme();
void themedefault();
void deletetheme();
void modify_AI();
void setrules();
- void displaySettings();
void mouse(int x,int y);
void done_dice1();
void done_dice2();
void done_dice3();
void done_dice4();
void nomove();
void nomove2();
void finished(int theplayer);
diff --git a/noncore/games/backgammon/backgammonview.cpp b/noncore/games/backgammon/backgammonview.cpp
index ecbc12b..6ee8f10 100644
--- a/noncore/games/backgammon/backgammonview.cpp
+++ b/noncore/games/backgammon/backgammonview.cpp
@@ -1,17 +1,23 @@
#include "backgammonview.h"
BackGammonView::BackGammonView(QCanvas* canvas,QWidget* parent)
- :QCanvasView(canvas,parent)
+ :QCanvasView(canvas,parent)
{
+ //do nothing
}
+
+
BackGammonView::~BackGammonView()
{
+ //do nothing
}
+
+
void BackGammonView::contentsMousePressEvent(QMouseEvent* e)
{
int x=e->x();
- int y=e->y();
- //emit mousepressed(x,y);
-} \ No newline at end of file
+ int y=e->y();
+ emit mouse(x,y);
+}
diff --git a/noncore/games/backgammon/backgammonview.h b/noncore/games/backgammon/backgammonview.h
index e50f2b0..52508e2 100644
--- a/noncore/games/backgammon/backgammonview.h
+++ b/noncore/games/backgammon/backgammonview.h
@@ -1,18 +1,18 @@
-#ifndef BACKGAMMONVIEW_H
-#define BACKGAMMONVIEW_H
+#ifndef BACKGAMMON_VIEW_H
+#define BACKGAMMON_VIEW_H
#include <qcanvas.h>
class BackGammonView : public QCanvasView
{
Q_OBJECT
public:
BackGammonView(QCanvas* canvas,QWidget* parent);
- ~BackGammonView();
+ ~BackGammonView();
signals:
- //void mousepressed(int,int);
+ void mouse(int,int);
private:
void contentsMousePressEvent(QMouseEvent* e);
};
-#endif //BACKGAMMONVIEW_H \ No newline at end of file
+#endif //BACKGAMMON_VIEW_H \ No newline at end of file
diff --git a/noncore/games/backgammon/definition.cpp b/noncore/games/backgammon/definition.cpp
index 9e0029d..c036319 100644
--- a/noncore/games/backgammon/definition.cpp
+++ b/noncore/games/backgammon/definition.cpp
@@ -1,3 +1,2 @@
#include "definition.h"
-static bool debug=false;
diff --git a/noncore/games/backgammon/displaydialog.cpp b/noncore/games/backgammon/displaydialog.cpp
deleted file mode 100644
index 8b97545..0000000
--- a/noncore/games/backgammon/displaydialog.cpp
+++ b/dev/null
@@ -1,89 +0,0 @@
-#include "displaydialog.h"
-
-#include <qgroupbox.h>
-#include <qlabel.h>
-
-DisplayDialog::DisplayDialog(QWidget* parent,const char* name,bool modal,WFlags f)
- : QDialog(parent,name,modal,f)
-{
- setCaption("Display Configuration");
- QLabel* header=new QLabel("<b>Change the display settings</b>",this);
- header->setGeometry(10,10,200,20);
-
- //
- QGroupBox* settings_frame=new QGroupBox("Settings",this);
- settings_frame->setGeometry(10,10,220,120);
-
- small_box=new QRadioButton("Big display, e.g. for QPE Style",settings_frame);
- small_box->setGeometry(10,20,200,20);
- connect(small_box,SIGNAL(clicked()),this,SLOT(small_clicked()));
-
- big_box=new QRadioButton("Small display, e.g. for Windows Style",settings_frame);
- big_box->setGeometry(10,50,200,20);
- connect(big_box,SIGNAL(clicked()),this,SLOT(big_clicked()));
-
- //
- QGroupBox* warning_frame=new QGroupBox("Warning",this);
- warning_frame->setGeometry(10,140,220,120);
-
- warning_box=new QCheckBox("show style warning",warning_frame);
- warning_box->setGeometry(10,20,200,20);
- connect(warning_box,SIGNAL(clicked()),this,SLOT(warning_clicked()));
-
- QLabel* warning_help=new QLabel("show style warning at statup if the system style is not QPE\nif not set to small you may have\nscrollbars on the palying area",warning_frame);
- warning_help->setGeometry(10,50,200,60);
-
- showMaximized();
-}
-
-
-DisplayDialog::~DisplayDialog()
-{
-}
-
-void DisplayDialog::big_clicked()
-{
- big_box->setChecked(true);
- small_box->setChecked(false);
-}
-
-void DisplayDialog::small_clicked()
-{
- big_box->setChecked(false);
- small_box->setChecked(true);
-}
-
-void DisplayDialog::warning_clicked()
-{
-}
-
-void DisplayDialog::setDisplaySettings(const Display& display)
-{
- if(!display.small)
- {
- big_box->setChecked(false);
- small_box->setChecked(true);
- }
- else
- {
- big_box->setChecked(true);
- small_box->setChecked(false);
- }
- if(display.warning)
- warning_box->setChecked(true);
- else
- warning_box->setChecked(false);
-
-}
-
-Display DisplayDialog::getDisplaySettings()
-{
- Display display;
- display.small=!small_box->isChecked();
- display.warning=warning_box->isChecked();
- return display;
-}
-
-
-
-
diff --git a/noncore/games/backgammon/displaydialog.h b/noncore/games/backgammon/displaydialog.h
deleted file mode 100644
index 26b77f0..0000000
--- a/noncore/games/backgammon/displaydialog.h
+++ b/dev/null
@@ -1,30 +0,0 @@
-#ifndef DISPLAYDLAOG_H
-#define DISPLAYDLAOG_H
-
-#include <qcheckbox.h>
-#include <qdialog.h>
-#include <qradiobutton.h>
-
-#include "definition.h"
-
-
-class DisplayDialog : public QDialog
-{
- Q_OBJECT
-private:
- QRadioButton* small_box;
- QRadioButton* big_box;
- QCheckBox* warning_box;
-public:
- DisplayDialog(QWidget* parent=0,const char* name=0,bool modal=TRUE,WFlags f=0);
- ~DisplayDialog();
-private slots:
- void big_clicked();
- void small_clicked();
- void warning_clicked();
-public:
- void setDisplaySettings(const Display& display);
- Display getDisplaySettings();
-};
-
-#endif //DISPLAYDLAOG_H
diff --git a/noncore/games/backgammon/moveengine.cpp b/noncore/games/backgammon/moveengine.cpp
index 8106b3f..009c449 100644
--- a/noncore/games/backgammon/moveengine.cpp
+++ b/noncore/games/backgammon/moveengine.cpp
@@ -1,16 +1,14 @@
#include "moveengine.h"
#include <qmessagebox.h>
#include <qtimer.h>
-#include <stdlib.h>
-
MoveEngine::MoveEngine()
: QObject()
{
int offset=7;
int a=0; //counter variable
int xfill[]={210,185,170,155,140,125,110,85,70,55,40,25,10,10,25,40,55,70,85,110,125,140,155,170,185,210};
for(a=0;a<26;a++)
{
diff --git a/noncore/games/backgammon/moveengine.h b/noncore/games/backgammon/moveengine.h
index a2d4a52..4c39a04 100644
--- a/noncore/games/backgammon/moveengine.h
+++ b/noncore/games/backgammon/moveengine.h
@@ -1,13 +1,13 @@
#ifndef MOVEENGINE_H
#define MOVEENGINE_H
-#include <qobject.h>
#include "definition.h"
+#include <qobject.h>
class MoveEngine : public QObject
{
Q_OBJECT
private:
//normal pieses
int x_coord[26]; //26 posssible x-positions or piece is not on the board
int yup_coord[15]; // the 15 posssible y-positions on the upper half of the board
diff --git a/noncore/games/backgammon/rulesdialog.h b/noncore/games/backgammon/rulesdialog.h
index 9269a0e..f11a28c 100644
--- a/noncore/games/backgammon/rulesdialog.h
+++ b/noncore/games/backgammon/rulesdialog.h
@@ -1,16 +1,15 @@
#ifndef RULESDIALOG_H_
#define RULESDIALOG_H_
#include <qcheckbox.h>
#include <qdialog.h>
#include "definition.h"
-
class RulesDialog : public QDialog
{
Q_OBJECT
private:
QCheckBox* pieces_out;
QCheckBox* nice_dice;
Rules rules;
public: