Source Code (Use browser search to find items of interest.)

Class Index

kabalone'AbTop (./kdegames/kabalone/AbTop.h:29)

class AbTop: public KTMainWindow
{
  Q_OBJECT

public:
  AbTop();
  ~AbTop();

  /* timer states */
  enum { noGame, gameOver, notStarted, moveShown,
	 showMove = 100, showSugg=200
  };

  void netPort(int p) { myPort = p; }
  void netHost(char* h) { hosts.append(h); }
	
protected:
  virtual void closeEvent (QCloseEvent *);

  virtual void saveProperties( KConfig * );
  virtual void readProperties( KConfig * );


public slots:  
  void timerDone();
  void newGame();
  void copy();
  void paste();
  void pastePosition(const char*);
  void stopGame();
  void continueGame();
  void back();
  void forward();
  void suggestion();
  void easy();
  void stopSearch();
  void normal();
  void hard();
  void challange();
  void help();
  void quit();
  void searchBreak();
  void moveChoosen(Move&);
  void play_red();
  void play_yellow();
  void play_both();
  void play_none();
  void savePosition();
  void restorePosition();
  void setSpy(int);
  void updateSpy(QString);
  void edited(int);
  void updateBestMove(Move&,int);
  void readConfig();
  void writeConfig();
  void mousePress(int);

  void gameNetwork(bool);
  void editModify(bool);
  void optionMoveSlow(bool);
  void optionRenderBalls(bool);
  void optionShowSpy(bool);
  void showToolbar(bool);
  void configureToolbars();
  void levelEasy(bool);
  void levelNormal(bool);
  void levelHard(bool);
  void levelChallange(bool);
  void iplayRed(bool);
  void iplayYellow(bool);
  void iplayBoth(bool);
  void iplayNone(bool);

private:
  void setupActions();
  void updateStatus();
  void userMove();
  void playGame();
  void loadPixmaps();
  void setupMenu();
  void setupToolBar();
  void setupStatusBar();
  void updateToolBar();
  void setLevel(int);
  void setIplay(int);
  bool iPlayNow();
  Move haveHint();
  void readOptions(KConfig *);
  void writeOptions(KConfig *);

  Move actMove;
  Board* board;
  int actValue;
  BoardWidget *boardWidget;
  QTimer *timer;
  KStatusBar *status;
  KToolBar *toolbar;
  int timerState;
  int depth, moveNo;
  bool showMoveLong, stop, showSpy;
  bool editMode, renderBalls;
  int validState, spyLevel;
  bool pastePossible, validShown;

  int iplay;
  enum { none, cYellow, cRed, cBoth, cNone };

  QPopupMenu *_file, *_edit, *_options, *_level, *_iplay;
  int stop_id, back_id, hint_id;
  int easy_id, normal_id, hard_id, challange_id, slow_id, level_id;
  int render_id;
  int yellow_id, red_id, both_id, none_id, iplay_id;
  int spy_id, paste_id, edit_id, forward_id, net_id;

  QLabel *validLabel, *ballLabel, *moveLabel, *statusLabel;
  QPixmap warningPix, okPix, redBall, yellowBall, noBall, netPix;
  QPixmap spy0, spy1, spy2, spy3;

  QPixmap newPix, openPix, savePix, editPix, copyPix, pastePix, stopPix;
  QPixmap forwardPix, backPix, hintPix;

  Network *net;
  int myPort;
  QStrList hosts;

#ifdef SPION	
  Spy* spy;
#endif

};

kabalone'AbTop::AbTop() (./kdegames/kabalone/AbTop.cpp:31)

AbTop::AbTop()
{
  timerState = noGame;

  myPort = Network::defaultPort;
  net = 0;

  moveNo = 0;
  actValue = 0;
  stop = false;
  editMode = false;
  spyLevel = 0;
  pastePossible = true;

  //  loadPixmaps();
  setupActions();

  // this creates the GUI (menu+toolbar) from the XML definition
  createGUI();
  //  setupMenu();
  //  setupToolBar();

  setupStatusBar();

  timer = new QTimer;
  connect( timer, SIGNAL(timeout()), this, SLOT(timerDone()) );

  board = new Board();
  validState = board->validState();

  connect( board, SIGNAL(searchBreak()), this, SLOT(searchBreak()) );

  CHECK_PTR(board);
  boardWidget = new BoardWidget(*board,this);  

#ifdef SPION
  spy = new Spy(*board);
#endif

  connect( boardWidget, SIGNAL(updateSpy(QString)),
	   this, SLOT(updateSpy(QString)) );

  /* Copy/Pase with Mousebuttons in board area (outside)
   * To easy to get rid of your board -> disable (for now?) 
   connect( boardWidget, SIGNAL(mousePressed(int)),
	   this, SLOT(mousePress(int)) );
  */

  connect( boardWidget, SIGNAL(edited(int)),
	   this, SLOT(edited(int)) );

  connect( board, SIGNAL(updateBestMove(Move&,int)),
	   this, SLOT(updateBestMove(Move&,int)) );

  connect( boardWidget, SIGNAL(moveChoosen(Move&)), 
	   this, SLOT(moveChoosen(Move&)) );

  /* default */
  easy();
  play_red();
  showMoveLong = true;
  showSpy = false;
  renderBalls = true;
  
  setView(boardWidget);
  boardWidget->show();

  setMinimumSize(150,200);

  updateStatus();
  updateToolBar();
}


kabalone'AbTop::~AbTop() (./kdegames/kabalone/AbTop.cpp:104)

AbTop::~AbTop()
{
  /* Unregister from other abalone processes */
  if (net)
    delete net;

#ifdef SPION
  delete spy;
#endif
	
  delete toolbar;
}


/**
 * Create all the actions...
 *
 * The GUI will be built in createGUI using a XML file
 *
 */


kabalone'AbTop::setupActions() (./kdegames/kabalone/AbTop.cpp:125)

void AbTop::setupActions()
{
  (void) new KAction( i18n("&New"), "new", 
		      KStdAccel::key(KStdAccel::New), this,
		      SLOT(newGame()), actionCollection(), "game_new");

  (void) new KAction( i18n("&Stop Search"), "stop", Key_S, this,
		      SLOT(stopSearch()), actionCollection(), "game_stop");

  (void) new KAction( i18n("Take &Back"), "back",
		      KStdAccel::key(KStdAccel::Prior), this,
		      SLOT(back()), actionCollection(), "game_back");

  (void) new KAction( i18n("&Forward"), "forward",
		      KStdAccel::key(KStdAccel::Next), this,
		      SLOT(forward()), actionCollection(), "game_forward");

  (void) new KAction( i18n("&Hint"), "hint", Key_H, this,
		      SLOT(suggestion()), actionCollection(), "game_hint");

  (void) new KAction( i18n("&Quit"), "exit",
		      KStdAccel::key(KStdAccel::Quit), this,
		      SLOT(quit()), actionCollection(), "game_quit");

  KStdAction::copy( this, SLOT(copy()), actionCollection());
  KStdAction::paste( this, SLOT(paste()), actionCollection());

  (void) new KAction( i18n("&Restore Position"),
		      KStdAccel::key(KStdAccel::Open), 
		      this, SLOT(restorePosition()), 
		      actionCollection(), "edit_restore" );

  (void) new KAction( i18n("&Save Position"),
		      KStdAccel::key(KStdAccel::Save), 
		      this, SLOT(savePosition()), 
		      actionCollection(), "edit_save" );

  KToggleAction *ta;

  ta = new KToggleAction( i18n("&Network Play"), "net", Key_N,
			  actionCollection(), "game_net");
  connect(ta, SIGNAL(toggled(bool)), this, SLOT(gameNetwork(bool)));

  ta = new KToggleAction( i18n("&Modify"), "edit",
			  KStdAccel::key(KStdAccel::Insert), 
			  actionCollection(), "edit_modify");
  connect(ta, SIGNAL(toggled(bool)), this, SLOT( editModify(bool)));   

  ta = KStdAction::showToolbar( this, SLOT(dummySlot()), actionCollection());
  connect(ta, SIGNAL(toggled(bool)), this, SLOT(showToolbar(bool)));

  ta =  new KToggleAction( i18n("&Move Slow"), 0,
			   actionCollection(), "option_moveSlow");
  connect(ta, SIGNAL(toggled(bool)), this, SLOT(optionMoveSlow(bool)));

  ta =  new KToggleAction( i18n("&Render Balls"), 0,
			   actionCollection(), "option_renderBalls");
  connect(ta, SIGNAL(toggled(bool)), this, SLOT(optionRenderBalls(bool)));

  ta =  new KToggleAction( i18n("&Spy"), 0,
			   actionCollection(), "option_showSpy");
  connect(ta, SIGNAL(toggled(bool)), this, SLOT(optionShowSpy(bool)));

  KStdAction::configureToolbars(this,SLOT(configureToolbars()),
				actionCollection());

  KStdAction::saveOptions( this, SLOT(writeConfig()), actionCollection());

  KRadioAction *ra;

  ra =  new KRadioAction( i18n("&Easy"), 0,
			  actionCollection(), "level_easy");
  ra->setExclusiveGroup( "Level" );
  ra->setChecked( false );
  connect(ra, SIGNAL(toggled(bool)), this, SLOT(levelEasy(bool)));

  ra =  new KRadioAction( i18n("&Normal"), 0,
			  actionCollection(), "level_normal");
  ra->setExclusiveGroup( "Level" );
  ra->setChecked( true );
  connect(ra, SIGNAL(toggled(bool)), this, SLOT(levelNormal(bool)));

  ra =  new KRadioAction( i18n("&Hard"), 0,
			  actionCollection(), "level_hard");
  ra->setExclusiveGroup( "Level" );
  ra->setChecked( false );
  connect(ra, SIGNAL(toggled(bool)), this, SLOT(levelNormal(bool)));

  ra =  new KRadioAction( i18n("&Challange"), 0,
			  actionCollection(), "level_challange");
  ra->setExclusiveGroup( "Level" );
  ra->setChecked( false );
  connect(ra, SIGNAL(toggled(bool)), this, SLOT(levelChallange(bool)));

  ra =  new KRadioAction( i18n("&Red"), 0,
			  actionCollection(), "iplay_red");
  ra->setExclusiveGroup( "IPlay" );
  ra->setChecked( true );
  connect(ra, SIGNAL(toggled(bool)), this, SLOT(iplayRed(bool)));

  ra =  new KRadioAction( i18n("&Yellow"), 0,
			  actionCollection(), "iplay_yellow");
  ra->setExclusiveGroup( "IPlay" );
  ra->setChecked( false );
  connect(ra, SIGNAL(toggled(bool)), this, SLOT(iplayYellow(bool)));

  ra =  new KRadioAction( i18n("&Both"), 0,
			  actionCollection(), "iplay_both");
  ra->setExclusiveGroup( "IPlay" );
  ra->setChecked( false );
  connect(ra, SIGNAL(toggled(bool)), this, SLOT(iplayBoth(bool)));

  ra =  new KRadioAction( i18n("&None"), 0,
			  actionCollection(), "iplay_none");
  ra->setExclusiveGroup( "IPlay" );
  ra->setChecked( false );
  connect(ra, SIGNAL(toggled(bool)), this, SLOT(iplayNone(bool)));
}



kabalone'AbTop::showToolbar() (./kdegames/kabalone/AbTop.cpp:245)

void AbTop::showToolbar(bool on)
{
  toolBar()->enable( on ? KToolBar::Show : KToolBar::Hide );
}          


kabalone'AbTop::configureToolbars() (./kdegames/kabalone/AbTop.cpp:250)

void AbTop::configureToolbars()
{
  KEditToolbar dlg(actionCollection());
  if (dlg.exec())
    createGUI();
}
  


/* Mouse button pressed in Board area,
 *  but outside of any board position
 */

kabalone'AbTop::mousePress() (./kdegames/kabalone/AbTop.cpp:262)

void AbTop::mousePress(int b)
{
  if (b==QWidget::MidButton) 
    paste();
  else
    copy();
}

/* Read config options
 *
 * menu must already be created!
 */

kabalone'AbTop::readConfig() (./kdegames/kabalone/AbTop.cpp:274)

void AbTop::readConfig()
{
  KConfig* config = kapp->config();
  config->setGroup("Options");
	
  readOptions(config);

  config->setGroup("Appearance");
  int x=215, y=280;
  QString entry;
  if (!(entry = config->readEntry("Geometry")).isNull())
	  sscanf(entry.ascii(),"%dx%d",&x,&y);
  resize(x,y);
  config->setGroup("Rating");
  board->readRating(config);
}


kabalone'AbTop::readOptions() (./kdegames/kabalone/AbTop.cpp:291)

void AbTop::readOptions(KConfig* config)
{	
  QString entry;
  if (!(entry = config->readEntry("Level")).isNull()) {
    if (entry == "Easy")  easy();
    else if (entry == "Normal") normal();
    else if (entry == "Hard") hard();
    else if (entry == "Challange") challange();
  }

  if (!(entry = config->readEntry("Computer")).isNull()) {
    if (entry == "Red") play_red();
    else if (entry == "Yellow") play_yellow();
    else if (entry == "Both") play_both();
    else if (entry == "None") play_none();
  }

  showMoveLong = false; // default
  if (!(entry = config->readEntry("MoveSlow")).isNull()) 
    showMoveLong = (entry == "Yes");
  ((KToggleAction*) actionCollection()->action("option_moveSlow"))
    ->setChecked( showMoveLong );

  renderBalls = true; // default  
  if (!(entry = config->readEntry("RenderBalls")).isNull()) 
    renderBalls = (entry == "Yes");
  boardWidget->renderBalls(renderBalls);
  ((KToggleAction*) actionCollection()->action("option_renderBalls"))
    ->setChecked( renderBalls );

  showSpy = true; // default
  if (!(entry = config->readEntry("ShowSpy")).isNull()) 
    showSpy = (entry == "Yes");
  board->updateSpy(showSpy);
  ((KToggleAction*) actionCollection()->action("option_showSpy"))
    ->setChecked( showSpy );
}


kabalone'AbTop::readProperties() (./kdegames/kabalone/AbTop.cpp:329)

void AbTop::readProperties(KConfig *config)
{
  QString entry;
	
  readOptions(config);
  board->readRating(config);
	
  if (!(entry = config->readEntry("TimerState")).isNull())
    timerState = entry.toInt();
  if (timerState == noGame) return;

  if (!(entry = config->readEntry("GameStopped")).isNull())  
    stop = (entry == "Yes");

  moveNo = 0;
  if (!(entry = config->readEntry("Position")).isNull()) {
    moveNo = board->setState(entry);
    boardWidget->copyPosition();
    boardWidget->draw();
  }
  updateStatus();
  updateToolBar();
  show();
  playGame();
}


kabalone'AbTop::writeConfig() (./kdegames/kabalone/AbTop.cpp:355)

void AbTop::writeConfig()
{
  KConfig* config = kapp->config();
  config->setGroup("Options");

  writeOptions(config);

  QString entry;
  config->setGroup("Appearance");
  config->writeEntry("Geometry", entry.sprintf("%dx%d",width(),height()) );
  config->setGroup("Rating");
  board->saveRating(config);
  config->sync();
}



kabalone'AbTop::writeOptions() (./kdegames/kabalone/AbTop.cpp:371)

void AbTop::writeOptions(KConfig *config)
{
  QString entry;

  if (((KRadioAction*) actionCollection()->action("level_easy"))
      ->isChecked()) {
    entry = "Easy";
  }
  else if (((KRadioAction*) actionCollection()->action("level_normal"))
	   ->isChecked()) {
    entry = "Normal";
  }
  else if (((KRadioAction*) actionCollection()->action("level_hard"))
	   ->isChecked()) {
    entry = "Hard";
  }
  else
    entry = "Challange";

  config->writeEntry("Level",entry);

  if (((KRadioAction*) actionCollection()->action("iplay_red"))
      ->isChecked()) {
    entry = "Red";
  }
  else if (((KRadioAction*) actionCollection()->action("iplay_yellow"))
	   ->isChecked()) {
    entry = "Yellow";
  }
  else if (((KRadioAction*) actionCollection()->action("iplay_both"))
	   ->isChecked()) {
    entry = "Both";
  }
  else
    entry = "None";

  config->writeEntry("Computer",entry);

  entry = showMoveLong ? "Yes" : "No";
  config->writeEntry("MoveSlow",entry);

  entry = renderBalls ? "Yes" : "No";
  config->writeEntry("RenderBalls",entry);
	
  entry = showSpy ? "Yes" : "No";
  config->writeEntry("ShowSpy",entry);
}


kabalone'AbTop::saveProperties() (./kdegames/kabalone/AbTop.cpp:419)

void AbTop::saveProperties(KConfig *config)
{
  QString entry;
  
  writeOptions(config);
  board->saveRating(config);
	
  config->writeEntry("TimerState",entry.setNum(timerState));

  if (timerState == noGame) return;

  config->writeEntry("GameStopped", stop ? "Yes":"No");
  config->writeEntry("Position", board->getState(moveNo));
}


kabalone'AbTop::closeEvent() (./kdegames/kabalone/AbTop.cpp:434)

void AbTop::closeEvent(QCloseEvent *)
{
  quit();
}


kabalone'AbTop::savePosition() (./kdegames/kabalone/AbTop.cpp:439)

void AbTop::savePosition()
{
  KConfig* config = kapp->config();
  config->setGroup("SavedPosition");
  config->writeEntry("Position", board->getState(moveNo));
}


kabalone'AbTop::restorePosition() (./kdegames/kabalone/AbTop.cpp:446)

void AbTop::restorePosition()
{
  KConfig* config = kapp->config();
  config->setGroup("SavedPosition");
  QString  entry = config->readEntry("Position");
  
  timerState = notStarted;
  timer->stop();	
  board->begin(Board::color1);
  stop = false;
  moveNo = board->setState(entry);

  if (net)
    net->broadcast( board->getASCIIState( moveNo ) );

  boardWidget->copyPosition();
  boardWidget->draw();
  updateStatus();
  updateToolBar();  
  playGame();
}


kabalone'AbTop::setupStatusBar() (./kdegames/kabalone/AbTop.cpp:468)

void AbTop::setupStatusBar()
{
  QString tmp;
  status = new KStatusBar(this);

  // validPixmap, only visible in Modify mode: is position valid ?
  warningPix = BarIcon( "warning" );
  okPix = BarIcon( "ok" );
  validLabel = new QLabel( "", status );
  validLabel->setFixedSize( 18,18 );
  validLabel->setAlignment( AlignCenter );
  validLabel->hide();
  validShown = false;

  QString t = i18n("Press %1 for a new game")
    .arg( KAccel::keyToString(KStdAccel::key(KStdAccel::New)) );
  statusLabel = new QLabel( t, status );
  status->addWidget(statusLabel,1);

  // PERMANENT: Moving side + move No.
  redBall = BarIcon( "redball" );
  yellowBall = BarIcon( "yellowball" );
  noBall = BarIcon( "noball" );  
  ballLabel = new QLabel( "", status );
  ballLabel->setPixmap(noBall);
  ballLabel->setFixedSize( 18,18 );
  ballLabel->setAlignment( AlignCenter );
  status->addWidget(ballLabel, 0, true);

  moveLabel = new QLabel( i18n("Move %1").arg("--"), status );
  status->addWidget(moveLabel, 0, true);

  setStatusBar(status);
}


#if 0
void AbTop::setupToolBar()
{
  toolbar = new KToolBar(this);
  
  toolbar->insertButton(newPix, 0, SIGNAL( clicked() ),
			this, SLOT( newGame() ),
			TRUE, i18n("New Game"));
  
  toolbar->insertSeparator();
  
  toolbar->insertButton(editPix, 12, SIGNAL( toggled(int) ),
			this, SLOT( editToggled(int) ),
			TRUE, i18n("Modify"));
  toolbar->setToggle(12);
  
  toolbar->insertButton(copyPix, 10, SIGNAL( clicked() ),
			this, SLOT( copy() ),
			TRUE, i18n("Copy"));
  
  toolbar->insertButton(pastePix, 11, SIGNAL( clicked() ),
			this, SLOT( paste() ),
			TRUE, i18n("Paste"));
  
  toolbar->insertSeparator();
  
  toolbar->insertButton(stopPix, 20, SIGNAL( clicked() ),
			this, SLOT( stopSearch() ),
			TRUE, i18n("Stop Search"));
  
  toolbar->insertButton(backPix, 21, SIGNAL( clicked() ),
			this, SLOT( back() ),
			TRUE, i18n("Back"));
  
  toolbar->insertButton(forwardPix, 22, SIGNAL( clicked() ),
			this, SLOT( forward() ),
			TRUE, i18n("Forward"));
  
  toolbar->insertButton(hintPix, 23, SIGNAL( clicked() ),
			this, SLOT( suggestion() ),
			TRUE, i18n("Hint"));

  toolbar->insertSeparator();
  
  toolbar->insertButton(netPix, 24, SIGNAL( toggled(int) ),
			this, SLOT( netToggled(int) ),
			TRUE, i18n("Network Play"));
  toolbar->setToggle(24);
  
#ifdef MYTRACE	
  QPopupMenu* spyPopup = new QPopupMenu;
  spy0 = BarIcon( "spy0" );
  spy1 = BarIcon( "spy1" );
  spy2 = BarIcon( "spy2" );
  spy3 = BarIcon( "spy3" );
  spyPopup->insertItem(spy0, 0);
  spyPopup->insertItem(spy1, 1);
  spyPopup->insertItem(spy2, 2);
  spyPopup->insertItem(spy3, 3);	
  connect( spyPopup, SIGNAL(activated(int)), 
	   this, SLOT(setSpy(int)) );
  toolbar->insertButton(spy0, 30, spyPopup,
			TRUE, i18n("Spy"));
#endif
  toolbar->show();	
  addToolBar(toolbar);	
}


void AbTop::setupMenu()
{
  KMenuBar* menu;

  _file = new QPopupMenu;
  CHECK_PTR( _file );
  _file->insertItem( newPix, i18n("New Game"), 
		   this, SLOT(newGame()), Key_F2 );
  _file->insertSeparator();

  stop_id = _file->insertItem( stopPix, i18n("Stop Search"),
			     this, SLOT(stopSearch()), Key_S );
  //  file->insertItem( "Stop", this, SLOT(stopGame()) );
  //  file->insertItem( "Continue", this, SLOT(continueGame()) );
  back_id = _file->insertItem( backPix, i18n("Take back"),
				 this, SLOT(back()), KStdAccel::key(KStdAccel::Prior) );
  forward_id = _file->insertItem( forwardPix, i18n("Forward"),
				 this, SLOT(forward()), KStdAccel::key(KStdAccel::Next) );

  hint_id = _file->insertItem( hintPix, i18n("Hint"),
			     this, SLOT(suggestion()), Key_H );

  _file->insertSeparator();

  net_id = _file->insertItem( netPix, i18n("Network"),
		         this, SLOT(toggleNet()), Key_N );
  _file->setCheckable( TRUE );
  
  _file->insertSeparator();
  _file->insertItem( i18n("&Quit"), 
				 this, SLOT(quit()), KStdAccel::key(KStdAccel::Quit) );


  _edit = new QPopupMenu;
  CHECK_PTR( _edit );

  edit_id = _edit->insertItem( editPix, i18n("Modify"), 
				  this, SLOT(toggleEdit()), KStdAccel::key(KStdAccel::Insert) );
  _edit->setCheckable( TRUE );

  _edit->insertItem( copyPix, i18n("Copy"), 
				this, SLOT(copy()), KStdAccel::key(KStdAccel::Copy) );
  paste_id = _edit->insertItem( pastePix, i18n("Paste"), 
			    this, SLOT(paste()), KStdAccel::key(KStdAccel::Paste) );

  _edit->insertSeparator();

  _edit->insertItem( i18n("Restore Position"), 
			this, SLOT(restorePosition()), KStdAccel::key(KStdAccel::Open) );
  _edit->insertItem( i18n("Save Position"), 
			this, SLOT(savePosition()), KStdAccel::key(KStdAccel::Save) );


  _level = new QPopupMenu;
  CHECK_PTR( _level );
  easy_id = _level->insertItem( i18n("Easy"),
			       this, SLOT(easy()) );
  normal_id = _level->insertItem( i18n("Normal"),
				 this, SLOT(normal()) );
  hard_id = _level->insertItem( i18n("Hard"),
			       this, SLOT(hard()) );
  challange_id = _level->insertItem( i18n("Challange"),
				    this, SLOT(challange()) );
  _level->setCheckable( TRUE );

  _iplay = new QPopupMenu;
  CHECK_PTR( _iplay );
  red_id = _iplay->insertItem( i18n("Red"),
			      this, SLOT(play_red()) );
  yellow_id = _iplay->insertItem( i18n("Yellow"),
				 this, SLOT(play_yellow()) );
  both_id = _iplay->insertItem( i18n("Both"), 
			       this, SLOT(play_both()) );
  none_id = _iplay->insertItem( i18n("None"), 
			       this, SLOT(play_none()) );
  _iplay->setCheckable( TRUE );

  _options = new QPopupMenu;
  CHECK_PTR( _options );
  _options->insertItem( i18n("Level"), _level );
  _options->insertItem( i18n("Computer plays"), _iplay );
  _options->insertSeparator();
  slow_id = _options->insertItem( i18n("Move slow"),
				  this, SLOT(changeShowMove()) );
  render_id = _options->insertItem( i18n("Render balls"),
				  this, SLOT(toggleRender()) );
  spy_id = _options->insertItem( i18n("Spy"),
				  this, SLOT(toggleSpy()) );
  _options->insertSeparator();
  _options->insertItem( i18n("Save"),
				  this, SLOT(writeConfig()) );	
  _options->setCheckable( TRUE );

  QPopupMenu *help = helpMenu(QString(i18n("Abalone"))
                                    + " " + KABALONE_VERSION
                                    + i18n("\n\nby Josef Weidendorfer")
                                    + " (Josef.Weidendorfer@in.tum.de)"); 

  menu  = new KMenuBar(this);
  CHECK_PTR( menu );
  menu->insertItem( i18n("&File"), _file);
  menu->insertItem( i18n("&Edit"), _edit);
  menu->insertItem( i18n("&Options"), _options);
  menu->insertSeparator();
  menu->insertItem( i18n("&Help"), help);
  menu->show();

  setMenu(menu);
}

kabalone'AbTop::updateSpy() (./kdegames/kabalone/AbTop.cpp:685)

void AbTop::updateSpy(QString s)
{
  if (showSpy) {
    if (s.isEmpty()) {      
      updateStatus();
      //      status->clear();
    }
    else
      statusLabel->setText(s);
  }
}


kabalone'AbTop::updateBestMove() (./kdegames/kabalone/AbTop.cpp:697)

void AbTop::updateBestMove(Move& m, int value)
{
  if (showSpy) {
    board->showMove(m,3);
    boardWidget->copyPosition();
    boardWidget->draw();
    board->showMove(m,0);

    QString tmp;
    tmp.sprintf("%s : %+d", (const char*) m.name(), value-actValue);
    updateSpy(tmp);
    kapp->processEvents();
  }
}



kabalone'AbTop::updateStatus() (./kdegames/kabalone/AbTop.cpp:713)

void AbTop::updateStatus()
{
  QString tmp;
  bool showValid = false;

  if (!editMode && timerState == noGame) {
    tmp = i18n("Move %1").arg("--");
    ballLabel->setPixmap(noBall);
  }
  else {
    tmp = i18n("Move %1").arg(moveNo/2 + 1);
    ballLabel->setPixmap( ((moveNo%2)==0) ? redBall : yellowBall);
  }
  moveLabel->setText(tmp);

  if (editMode) {
    tmp = QString("%1: %2 %3 - %4 %5")
      .arg( i18n("Edit") )
      .arg( i18n("Red") ).arg(boardWidget->getColor1Count())
      .arg( i18n("Yellow") ).arg(boardWidget->getColor2Count());
    validLabel->setPixmap( (validState == Board::invalid) ? warningPix:okPix );
    showValid = true;
  }
  else if (timerState == noGame) {
    tmp = i18n("Press %1 for a new game")
      .arg( KAccel::keyToString(KStdAccel::key(KStdAccel::New)) );
  }
  else {
    if (timerState == gameOver) {
      tmp = QString("%1 %2 !")
	.arg( (board->actColor() == Board::color2) ? 
	      i18n("Red"):i18n("Yellow"))
	.arg( i18n("won") );
      validLabel->setPixmap( warningPix );
      showValid = true;
    }
    else {
      tmp = QString("%1 - %2")
	.arg( (board->actColor() == Board::color1) ? 
	      i18n("Red"):i18n("Yellow") )
	.arg( iPlayNow() ?
	      i18n("I am thinking...") : i18n("It's your turn !") );
    }
  }
  statusLabel->setText(tmp);
  if (validShown != showValid) {
    if (showValid) {
      status->addWidget(validLabel);
      validLabel->show();
    }
    else {
      status->removeWidget(validLabel);
      validLabel->hide();
    }
    validShown = showValid;
  }
  status->clear();
  status->repaint();
}


kabalone'AbTop::edited() (./kdegames/kabalone/AbTop.cpp:773)

void AbTop::edited(int vState)
{
  validState = vState;
  if (validState == Board::empty)
    timerState = noGame;

  updateStatus();
}

/* only <stop search>, <hint>, <take back> have to be updated */

kabalone'AbTop::updateToolBar() (./kdegames/kabalone/AbTop.cpp:783)

void AbTop::updateToolBar()
{
  bool iPlay = iPlayNow();

  /* New && Copy always on */

  /* Paste */
  pastePossible = !iPlay;
  ((KAction*)actionCollection()->action("edit_paste"))->setEnabled(!iPlay);
  
  /* Edit */
  ((KAction*)actionCollection()->action("edit_modify"))->setEnabled(!iPlay);

  /* Stop search */
  ((KAction*)actionCollection()->action("game_stop"))->setEnabled(iPlay);

  /* Back */
  bool bBack = (editMode && moveNo>0) || 
    (board->movesStored() >=2 && !iPlay);
  ((KAction*)actionCollection()->action("game_back"))->setEnabled(bBack);
	
  /* Forward */
  bool bForward = editMode && moveNo<999;
  ((KAction*)actionCollection()->action("game_forward"))->setEnabled(bForward);

  /* Hint */
  bool bHint = !editMode && !iPlay && (haveHint().type != Move::none);
  ((KAction*)actionCollection()->action("game_hint"))->setEnabled(bHint);
}

/* let the program be responsive even in a long search... */

kabalone'AbTop::searchBreak() (./kdegames/kabalone/AbTop.cpp:814)

void AbTop::searchBreak()
{
  kapp->processEvents();
}



kabalone'AbTop::setSpy() (./kdegames/kabalone/AbTop.cpp:820)

void AbTop::setSpy(int id)
{
  toolbar->setButtonPixmap(30, (id==0)?spy0:(id==1)?spy1:(id==2)?spy2:spy3 );
  spyLevel = id;
  board->setSpyLevel(spyLevel);
}


kabalone'AbTop::timerDone() (./kdegames/kabalone/AbTop.cpp:827)

void AbTop::timerDone()
{
  int interval = 400;

  switch(timerState) {
  case noGame:
  case notStarted:
    return;
  case showMove:
  case showMove+2:
  case showSugg:
  case showSugg+2:
  case showSugg+4:
    board->showMove(actMove, 2);
    interval = 200;
    break;
  case showMove+1:
  case showMove+3:
  case showSugg+1:
  case showSugg+3:
    board->showMove(actMove, 3);
    break;
  case showSugg+5:
    interval = 800;
  case showMove+4:
    board->showMove(actMove, 4);
    break;
  case showMove+5:
    board->showMove(actMove, 0);
    timerState = moveShown;
    playGame();
    return;
  case showSugg+6:
    board->showMove(actMove, 0);
    timerState = notStarted;
    boardWidget->copyPosition();
    boardWidget->draw();
    return;
  }
  boardWidget->copyPosition();
  boardWidget->draw();
  timerState++;
  timer->start(interval,TRUE);
}


kabalone'AbTop::userMove() (./kdegames/kabalone/AbTop.cpp:872)

void AbTop::userMove()
{
    /* User has to move */
    static MoveList list;
    
    list.clear();
    board->generateMoves(list);
    boardWidget->choseMove(&list);
}


kabalone'AbTop::iPlayNow() (./kdegames/kabalone/AbTop.cpp:882)

bool AbTop::iPlayNow()
{
  if (editMode ||
      validState != Board::valid ||
      timerState == gameOver)
    return false;

  int c = board->actColor();
    
  /* color1 is red */
  return ((iplay == cBoth) || 
	  ((c == Board::color1) && (iplay == cRed) ) ||
	  ((c == Board::color2) && (iplay == cYellow) ));
}


kabalone'AbTop::playGame() (./kdegames/kabalone/AbTop.cpp:897)

void AbTop::playGame()
{
  if (timerState == moveShown) {
    if (actMove.type != Move::none) {
      board->playMove(actMove);
      moveNo++;

      if (net)
	net->broadcast( board->getASCIIState( moveNo ) );
    }
    actValue = - board->calcValue();
    boardWidget->copyPosition();
    boardWidget->draw();
    timerState = notStarted;
  }
  if (!board->isValid()) { 
    stop = true;
    timerState = gameOver;
  }

  updateStatus();
  updateToolBar();
  if (stop) return;


  if (!iPlayNow()) {
    userMove();
    return;
  }
	
  kapp->processEvents();

  if (moveNo <4) {
    /* Chose a random move making the position better for actual color */

    /* If comparing ratings among color1/2 on move, we have to negate one */
    int v = -board->calcValue(), vv;
    do {
      actMove = board->randomMove();
      board->playMove(actMove);
      vv = board->calcValue();
      board->takeBack();
    } while( (board->actColor() == Board::color1) ? (vv<v) : (vv>v) );
  }
  else
    actMove = (board->bestMove());

  timerState = showMoveLong ? showMove : showMove+3;
  timerDone();
}


kabalone'AbTop::moveChoosen() (./kdegames/kabalone/AbTop.cpp:948)

void AbTop::moveChoosen(Move& m)
{
  actMove = m;
  timerState = moveShown;
  playGame();
}


kabalone'AbTop::newGame() (./kdegames/kabalone/AbTop.cpp:955)

void AbTop::newGame()
{
  /* stop a running animation */
  timerState = notStarted;
  timer->stop();	

  /* reset board */
  board->begin(Board::color1);
  boardWidget->copyPosition();
  boardWidget->draw();
  moveNo = 0;
  validState = board->validState();

  if (net)
    net->broadcast( board->getASCIIState( moveNo ) );

  updateStatus();
  updateToolBar();

  /* if not in EditMode, start Game immediately */
  if (!editMode) {
    stop = false;	
    playGame();
  }
}

/* Copy ASCII representation into Clipboard */

kabalone'AbTop::copy() (./kdegames/kabalone/AbTop.cpp:982)

void AbTop::copy()
{
  QClipboard *cb = QApplication::clipboard();
  cb->setText( board->getASCIIState( moveNo ) );
}


kabalone'AbTop::paste() (./kdegames/kabalone/AbTop.cpp:988)

void AbTop::paste()
{
  if (!pastePossible) return;

  QClipboard *cb = QApplication::clipboard();
  pastePosition( cb->text() );
  /* don't do this in pastePosition: RECURSION !! */

  if (net)
    net->broadcast( board->getASCIIState( moveNo ) );
}


kabalone'AbTop::pastePosition() (./kdegames/kabalone/AbTop.cpp:1000)

void AbTop::pastePosition(const char* text)
{
  if (!pastePossible) return;
  if ( text ) {
    timerState = notStarted;
    timer->stop();	
    board->begin(Board::color1);
    stop = false;

    int no = board->setASCIIState(text);
    moveNo = (no>=0) ? no : 0;
    board->setActColor( ((moveNo%2)==0) ? Board::color1 : Board::color2 );

    validState = board->validState();    
    boardWidget->copyPosition();
    validState = boardWidget->validState();    
    boardWidget->draw();

    if (validState==Board::invalid && !editMode) {
      toolbar->toggleButton(12);
      return;
    }
    updateStatus();
    updateToolBar();  
    playGame();
  }
}



kabalone'AbTop::gameNetwork() (./kdegames/kabalone/AbTop.cpp:1029)

void AbTop::gameNetwork(bool on)
{
  if (!on) {
    if (net != 0) {
      delete net;
      net = 0;
    }
    return;
  }

  if (myPort == 0) myPort = Network::defaultPort;
  net = new Network(myPort);
  char *h, h2[100];
  int p, i;
  for(h = hosts.first(); h!=0; h=hosts.next()) {
    for(i=0;h[i]!=0 && h[i]!=':';i++);
    if (h[i]==':')
      p = atoi(h+i+1);
    else
      p = 0;

    if (p == 0) p = Network::defaultPort;
    strncpy(h2,h,i);
    h2[i]=0;
    net->addListener(h2, p);
  }
  QObject::connect(net, SIGNAL(gotPosition(const char*)),
		   this, SLOT(pastePosition(const char*)) );
}
  


kabalone'AbTop::editModify() (./kdegames/kabalone/AbTop.cpp:1060)

void AbTop::editModify(bool on)
{
  editMode = boardWidget->setEditMode( on );
  validState = boardWidget->validState();

  if (validState != Board::valid)
    timerState = noGame;

  updateToolBar();
  updateStatus();
  if (!editMode && validState == Board::valid) {
    board->setActColor( ((moveNo%2)==0) ? Board::color1 : Board::color2 );
    actMove.type = Move::none;
    timerState = moveShown;
    playGame();
  }  
}


kabalone'AbTop::stopGame() (./kdegames/kabalone/AbTop.cpp:1078)

void AbTop::stopGame()
{
  stop = true;
  board->stopSearch();
}


kabalone'AbTop::stopSearch() (./kdegames/kabalone/AbTop.cpp:1084)

void AbTop::stopSearch()
{
  // When computer plays both, switch back to human for next color
  if (iplay == cBoth)
    iplay = (board->actColor() == Board::color1) ? cRed:cYellow;

  board->stopSearch();
}


kabalone'AbTop::quit() (./kdegames/kabalone/AbTop.cpp:1093)

void AbTop::quit()
{
  board->stopSearch();
  kapp->quit();
}


kabalone'AbTop::continueGame() (./kdegames/kabalone/AbTop.cpp:1099)

void AbTop::continueGame()
{
  if (timerState != noGame && timerState != gameOver) {
    stop = false;
    if (timerState == notStarted)
	    playGame();
  }
}


kabalone'AbTop::back() (./kdegames/kabalone/AbTop.cpp:1108)

void AbTop::back()
{
  if (editMode) {
    if (moveNo > 0) moveNo--;
    updateStatus();
    updateToolBar();
    return;
  }

  if (moveNo < 2) return;

  if (timerState == gameOver)
    timerState = notStarted;
  if (timerState != notStarted) return;

  board->takeBack();
  board->takeBack();
  boardWidget->copyPosition();
  boardWidget->draw();
  moveNo -=2;
  updateStatus();
  updateToolBar();
  userMove();
}

/* Only for edit Mode */

kabalone'AbTop::forward() (./kdegames/kabalone/AbTop.cpp:1134)

void AbTop::forward()
{
  if (editMode) {
    if (moveNo < 999) moveNo++;
    updateStatus();
    updateToolBar();
    return;
  }
}


kabalone'AbTop::haveHint() (./kdegames/kabalone/AbTop.cpp:1144)

Move AbTop::haveHint()
{
  static Move m;
  static int oldMoveNo = 0;

  if (timerState != notStarted) {
    m.type = Move::none;
  }
  else if (moveNo != oldMoveNo) {
    MoveList list;
    
    oldMoveNo = moveNo;
    m = board->nextMove();
    board->generateMoves(list);
    if (!list.isElement(m,0))
      m.type = Move::none;
  }
  return m;
}



kabalone'AbTop::suggestion() (./kdegames/kabalone/AbTop.cpp:1165)

void AbTop::suggestion()
{
  if (timerState != notStarted) return;
  Move m = haveHint();
  if (m.type == Move::none) return;

  actMove = m;

  timerState = showSugg;
  timerDone();
}


kabalone'AbTop::setLevel() (./kdegames/kabalone/AbTop.cpp:1177)

void AbTop::setLevel(int d)
{
  depth = d;
  board->setDepth(depth);
  //  qDebug("Level set to %d",d);
}


kabalone'AbTop::levelEasy() (./kdegames/kabalone/AbTop.cpp:1184)

void AbTop::levelEasy(bool on)      { if (on) setLevel(2); }

kabalone'AbTop::levelNormal() (./kdegames/kabalone/AbTop.cpp:1185)

void AbTop::levelNormal(bool on)    { if (on) setLevel(3); }

kabalone'AbTop::levelHard() (./kdegames/kabalone/AbTop.cpp:1186)

void AbTop::levelHard(bool on)      { if (on) setLevel(4); }

kabalone'AbTop::levelChallange() (./kdegames/kabalone/AbTop.cpp:1187)

void AbTop::levelChallange(bool on) { if (on) setLevel(5); }


kabalone'AbTop::easy() (./kdegames/kabalone/AbTop.cpp:1189)

void AbTop::easy()
{  
  ((KRadioAction*) actionCollection()->action("level_easy"))
    ->setChecked( true );
}


kabalone'AbTop::normal() (./kdegames/kabalone/AbTop.cpp:1195)

void AbTop::normal()
{  
  ((KRadioAction*) actionCollection()->action("level_normal"))
    ->setChecked( true );
}


kabalone'AbTop::hard() (./kdegames/kabalone/AbTop.cpp:1201)

void AbTop::hard()
{  
  ((KRadioAction*) actionCollection()->action("level_hard"))
    ->setChecked( true );
}


kabalone'AbTop::challange() (./kdegames/kabalone/AbTop.cpp:1207)

void AbTop::challange()
{  
  ((KRadioAction*) actionCollection()->action("level_challange"))
    ->setChecked( true );
}


kabalone'AbTop::setIplay() (./kdegames/kabalone/AbTop.cpp:1213)

void AbTop::setIplay(int v)
{
  iplay = v;
  continueGame();
}


kabalone'AbTop::iplayRed() (./kdegames/kabalone/AbTop.cpp:1219)

void AbTop::iplayRed(bool on)    { if (on) setIplay(cRed); }

kabalone'AbTop::iplayYellow() (./kdegames/kabalone/AbTop.cpp:1220)

void AbTop::iplayYellow(bool on) { if (on) setIplay(cYellow); }

kabalone'AbTop::iplayBoth() (./kdegames/kabalone/AbTop.cpp:1221)

void AbTop::iplayBoth(bool on)   { if (on) setIplay(cBoth); }

kabalone'AbTop::iplayNone() (./kdegames/kabalone/AbTop.cpp:1222)

void AbTop::iplayNone(bool on)   { if (on) setIplay(cNone); }


kabalone'AbTop::play_red() (./kdegames/kabalone/AbTop.cpp:1224)

void AbTop::play_red()
{
  ((KRadioAction*) actionCollection()->action("iplay_red"))
    ->setChecked( true );
}


kabalone'AbTop::play_yellow() (./kdegames/kabalone/AbTop.cpp:1230)

void AbTop::play_yellow()
{
  ((KRadioAction*) actionCollection()->action("iplay_yellow"))
    ->setChecked( true );
}


kabalone'AbTop::play_both() (./kdegames/kabalone/AbTop.cpp:1236)

void AbTop::play_both()
{
  ((KRadioAction*) actionCollection()->action("iplay_both"))
    ->setChecked( true );
}


kabalone'AbTop::play_none() (./kdegames/kabalone/AbTop.cpp:1242)

void AbTop::play_none()
{
  ((KRadioAction*) actionCollection()->action("iplay_none"))
    ->setChecked( true );
}


kabalone'AbTop::optionMoveSlow() (./kdegames/kabalone/AbTop.cpp:1248)

void AbTop::optionMoveSlow(bool on)
{
  showMoveLong = on;
}


kabalone'AbTop::optionRenderBalls() (./kdegames/kabalone/AbTop.cpp:1253)

void AbTop::optionRenderBalls(bool on)
{
  renderBalls = on;
  boardWidget->renderBalls(renderBalls);
}


kabalone'AbTop::optionShowSpy() (./kdegames/kabalone/AbTop.cpp:1259)

void AbTop::optionShowSpy(bool on)
{
  showSpy = on;
  board->updateSpy(showSpy);

#ifdef SPION
  if (showSpy)
    spy->show();
  else {
    spy->nextStep();
    spy->hide();
  }
#endif

}



kabalone'AbTop::help() (./kdegames/kabalone/AbTop.cpp:1276)

void AbTop::help()
{
  kapp->invokeHTMLHelp("kabalone/index.html", "");
}