eliot-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Eliot-dev] eliot qt/main_window.cpp qt/main_window.h qt/ui...


From: eliot-dev
Subject: [Eliot-dev] eliot qt/main_window.cpp qt/main_window.h qt/ui...
Date: Sat, 26 Jan 2008 10:10:51 +0000

CVSROOT:        /cvsroot/eliot
Module name:    eliot
Changes by:     Olivier Teulière <ipkiss>      08/01/26 10:10:51

Modified files:
        qt             : main_window.cpp main_window.h 
        qt/ui          : main_window.ui 
        game           : game.cpp pldrack.cpp 

Log message:
         - Fixed a bug due to the reject sign '-' preventing to load a saved 
training game
         - Qt interface: Loading and saving a game is now supported (it only 
works in
           training mode, due to limitations in the core)

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/main_window.cpp?cvsroot=eliot&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/main_window.h?cvsroot=eliot&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/ui/main_window.ui?cvsroot=eliot&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/eliot/game/game.cpp?cvsroot=eliot&r1=1.36&r2=1.37
http://cvs.savannah.gnu.org/viewcvs/eliot/game/pldrack.cpp?cvsroot=eliot&r1=1.10&r2=1.11

Patches:
Index: qt/main_window.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/main_window.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- qt/main_window.cpp  25 Jan 2008 18:42:59 -0000      1.4
+++ qt/main_window.cpp  26 Jan 2008 10:10:50 -0000      1.5
@@ -20,6 +20,8 @@
 
 #include "config.h"
 
+#include <iostream>
+#include <fstream>
 #include <QtGui/QMessageBox>
 #include <QtGui/QFileDialog>
 #include <QtGui/QDockWidget>
@@ -28,6 +30,7 @@
 #include "dic.h"
 #include "encoding.h"
 #include "header.h"
+#include "game_factory.h"
 #include "game.h"
 #include "freegame.h"
 #include "player.h"
@@ -119,67 +122,6 @@
 }
 
 
-void MainWindow::on_action_About_triggered()
-{
-    QString msg;
-    msg.sprintf("Eliot %s\n\n", VERSION);
-    msg += _q( \
-        "Copyright (C) 1999-2008 - Antoine Fraboulet & Olivier Teuliere\n\n" \
-        "This program is free software; you can redistribute it and/or " \
-        "modify it under the terms of the GNU General Public License as " \
-        "published by the Free Software Foundation; either version 2 of " \
-        "the License, or (at your option) any later version.");
-    // QMessageBox::about() doesn't add the nice information icon, so we create
-    // the box manually (not much work...)
-    QMessageBox *aboutBox = new QMessageBox(QMessageBox::Information,
-                                            _q("About Eliot"), msg, 
QMessageBox::Ok, this);
-    aboutBox->exec();
-}
-
-
-void MainWindow::on_action_Bag_triggered()
-{
-    if (m_bagWindow == NULL)
-    {
-        // Create the bag window
-        BagWidget *bagWidget = new BagWidget(NULL);
-        bagWidget->setGame(m_game);
-        m_bagWindow = new AuxWindow(*bagWidget, m_ui.action_Bag);
-        QObject::connect(this, SIGNAL(gameChanged(const Game*)),
-                         bagWidget, SLOT(setGame(const Game*)));
-        QObject::connect(this, SIGNAL(gameUpdated()),
-                         bagWidget, SLOT(refresh()));
-        // XXX
-        m_bagWindow->move(20, 20);
-    }
-    if (m_bagWindow->isVisible())
-        m_bagWindow->hide();
-    else
-        m_bagWindow->show();
-}
-
-
-void MainWindow::on_action_ChooseDic_triggered()
-{
-    QString fileName =
-        QFileDialog::getOpenFileName(this, _q("Choose a dictionary"), "", 
"*.dawg");
-    if (!fileName.isEmpty())
-    {
-        try
-        {
-            Dictionary *dic = new Dictionary(qtl(fileName));
-            delete m_dic;
-            m_dic = dic;
-            emit dicChanged(fileName, qfw(m_dic->getHeader().getName()));
-        }
-        catch (std::exception &e)
-        {
-            displayErrorMsg(e.what());
-        }
-    }
-}
-
-
 void MainWindow::destroyCurrentGame()
 {
     if (m_game == NULL)
@@ -197,7 +139,16 @@
 }
 
 
-void MainWindow::on_action_New_Game_triggered()
+void MainWindow::displayErrorMsg(QString iMsg, QString iContext)
+{
+    if (iContext == "")
+        iContext = PACKAGE_NAME;
+
+    QMessageBox::warning(this, iContext, iMsg);
+}
+
+
+void MainWindow::on_action_GameNew_triggered()
 {
     if (m_dic == NULL)
     {
@@ -229,7 +180,47 @@
 }
 
 
-void MainWindow::on_action_Preferences_triggered()
+void MainWindow::on_action_GameLoad_triggered()
+{
+    if (m_dic == NULL)
+    {
+        displayErrorMsg(_q("You have to select a dictionary first!"));
+        return;
+    }
+
+    QString fileName = QFileDialog::getOpenFileName(this, _q("Load a game"));
+    if (fileName != "")
+    {
+        destroyCurrentGame();
+        m_game = GameFactory::Instance()->load(qtl(fileName), *m_dic);
+        if (m_game == NULL)
+        {
+            displayErrorMsg(_q("Error while loading the game"));
+            return;
+        }
+        m_ui.groupBoxPlayers->show();
+        emit gameChangedNonConst(m_game);
+        emit gameChanged(m_game);
+        emit gameUpdated();
+    }
+}
+
+
+void MainWindow::on_action_GameSaveAs_triggered()
+{
+    if (m_game == NULL)
+        return;
+
+    QString fileName = QFileDialog::getSaveFileName(this, _q("Save a game"));
+    if (fileName != "")
+    {
+        ofstream fout(qtl(fileName));
+        m_game->save(fout);
+    }
+}
+
+
+void MainWindow::on_action_SettingsPreferences_triggered()
 {
     if (m_prefsDialog == NULL)
         m_prefsDialog = new PrefsDialog(this);
@@ -237,11 +228,63 @@
 }
 
 
-void MainWindow::displayErrorMsg(QString iMsg, QString iContext)
+void MainWindow::on_action_SettingsChooseDic_triggered()
 {
-    if (iContext == "")
-        iContext = PACKAGE_NAME;
+    QString fileName =
+        QFileDialog::getOpenFileName(this, _q("Choose a dictionary"), "", 
"*.dawg");
+    if (!fileName.isEmpty())
+    {
+        try
+        {
+            Dictionary *dic = new Dictionary(qtl(fileName));
+            delete m_dic;
+            m_dic = dic;
+            emit dicChanged(fileName, qfw(m_dic->getHeader().getName()));
+        }
+        catch (std::exception &e)
+        {
+            displayErrorMsg(e.what());
+        }
+    }
+}
 
-    QMessageBox::warning(this, iContext, iMsg);
+
+void MainWindow::on_action_WindowsBag_triggered()
+{
+    if (m_bagWindow == NULL)
+    {
+        // Create the bag window
+        BagWidget *bagWidget = new BagWidget(NULL);
+        bagWidget->setGame(m_game);
+        m_bagWindow = new AuxWindow(*bagWidget, m_ui.action_WindowsBag);
+        QObject::connect(this, SIGNAL(gameChanged(const Game*)),
+                         bagWidget, SLOT(setGame(const Game*)));
+        QObject::connect(this, SIGNAL(gameUpdated()),
+                         bagWidget, SLOT(refresh()));
+        // XXX
+        m_bagWindow->move(20, 20);
+    }
+    if (m_bagWindow->isVisible())
+        m_bagWindow->hide();
+    else
+        m_bagWindow->show();
+}
+
+
+void MainWindow::on_action_HelpAbout_triggered()
+{
+    QString msg;
+    msg.sprintf("Eliot %s\n\n", VERSION);
+    msg += _q( \
+        "Copyright (C) 1999-2008 - Antoine Fraboulet & Olivier Teuliere\n\n" \
+        "This program is free software; you can redistribute it and/or " \
+        "modify it under the terms of the GNU General Public License as " \
+        "published by the Free Software Foundation; either version 2 of " \
+        "the License, or (at your option) any later version.");
+    // QMessageBox::about() doesn't add the nice information icon, so we create
+    // the box manually (not much work...)
+    QMessageBox *aboutBox = new QMessageBox(QMessageBox::Information,
+                                            _q("About Eliot"), msg, 
QMessageBox::Ok, this);
+    aboutBox->exec();
 }
 

Index: qt/main_window.h
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/main_window.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- qt/main_window.h    25 Jan 2008 18:42:59 -0000      1.4
+++ qt/main_window.h    26 Jan 2008 10:10:50 -0000      1.5
@@ -54,11 +54,13 @@
     void displayErrorMsg(QString iMsg, QString iContext = "");
 
 private slots:
-    void on_action_About_triggered();
-    void on_action_Bag_triggered();
-    void on_action_ChooseDic_triggered();
-    void on_action_New_Game_triggered();
-    void on_action_Preferences_triggered();
+    void on_action_GameNew_triggered();
+    void on_action_GameLoad_triggered();
+    void on_action_GameSaveAs_triggered();
+    void on_action_SettingsChooseDic_triggered();
+    void on_action_SettingsPreferences_triggered();
+    void on_action_WindowsBag_triggered();
+    void on_action_HelpAbout_triggered();
 
 private:
     /// Current dictionary

Index: qt/ui/main_window.ui
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/ui/main_window.ui,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- qt/ui/main_window.ui        25 Jan 2008 18:43:00 -0000      1.4
+++ qt/ui/main_window.ui        26 Jan 2008 10:10:51 -0000      1.5
@@ -70,29 +70,32 @@
     <property name="title" >
      <string>_("&amp;Game")</string>
     </property>
-    <addaction name="action_New_Game" />
+    <addaction name="action_GameNew" />
+    <addaction name="action_GameLoad" />
     <addaction name="separator" />
-    <addaction name="action_Quit" />
+    <addaction name="action_GameSaveAs" />
+    <addaction name="separator" />
+    <addaction name="action_GameQuit" />
    </widget>
    <widget class="QMenu" name="menuHelp" >
     <property name="title" >
      <string>&amp;Settings</string>
     </property>
-    <addaction name="action_ChooseDic" />
-    <addaction name="action_Preferences" />
+    <addaction name="action_SettingsChooseDic" />
+    <addaction name="action_SettingsPreferences" />
    </widget>
    <widget class="QMenu" name="menu_Help" >
     <property name="title" >
      <string>_("&amp;Help")</string>
     </property>
-    <addaction name="action_About" />
+    <addaction name="action_HelpAbout" />
     <addaction name="separator" />
    </widget>
    <widget class="QMenu" name="menu_Windows" >
     <property name="title" >
      <string>_("&amp;Windows")</string>
     </property>
-    <addaction name="action_Bag" />
+    <addaction name="action_WindowsBag" />
    </widget>
    <addaction name="menuFile" />
    <addaction name="menuHelp" />
@@ -111,12 +114,12 @@
     <bool>false</bool>
    </attribute>
   </widget>
-  <action name="action_ChooseDic" >
+  <action name="action_SettingsChooseDic" >
    <property name="text" >
     <string>_("Choose dictionary...")</string>
    </property>
   </action>
-  <action name="action_About" >
+  <action name="action_HelpAbout" >
    <property name="text" >
     <string>_("&amp;About...")</string>
    </property>
@@ -124,37 +127,67 @@
     <string>About Eliot</string>
    </property>
   </action>
-  <action name="action_Quit" >
+  <action name="action_GameQuit" >
    <property name="text" >
     <string>_("&amp;Quit")</string>
    </property>
   </action>
-  <action name="action_New_Game" >
+  <action name="action_GameNew" >
    <property name="text" >
-    <string>_("&amp;New game...")</string>
+    <string>_("New...")</string>
    </property>
    <property name="shortcut" >
     <string>Ctrl+N</string>
    </property>
   </action>
-  <action name="action_Bag" >
+  <action name="action_WindowsBag" >
    <property name="checkable" >
     <bool>true</bool>
    </property>
    <property name="text" >
     <string>_("&amp;Bag")</string>
    </property>
+   <property name="shortcut" >
+    <string>Ctrl+B</string>
+   </property>
   </action>
-  <action name="action_Preferences" >
+  <action name="action_SettingsPreferences" >
    <property name="text" >
     <string>_("Preferences...")</string>
    </property>
+   <property name="shortcut" >
+    <string>Ctrl+P</string>
+   </property>
+  </action>
+  <action name="action_GameSave" >
+   <property name="text" >
+    <string>_("Save")</string>
+   </property>
+   <property name="shortcut" >
+    <string>Ctrl+S</string>
+   </property>
+  </action>
+  <action name="action_GameLoad" >
+   <property name="text" >
+    <string>_("Load...")</string>
+   </property>
+   <property name="shortcut" >
+    <string>Ctrl+O</string>
+   </property>
+  </action>
+  <action name="action_GameSaveAs" >
+   <property name="text" >
+    <string>_("Save as...")</string>
+   </property>
+   <property name="shortcut" >
+    <string>Ctrl+S</string>
+   </property>
   </action>
  </widget>
  <resources/>
  <connections>
   <connection>
-   <sender>action_Quit</sender>
+   <sender>action_GameQuit</sender>
    <signal>triggered()</signal>
    <receiver>MainWindow</receiver>
    <slot>close()</slot>

Index: game/game.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/game.cpp,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -b -r1.36 -r1.37
--- game/game.cpp       15 Jan 2008 14:56:38 -0000      1.36
+++ game/game.cpp       26 Jan 2008 10:10:51 -0000      1.37
@@ -477,7 +477,7 @@
 {
     ASSERT(p < getNPlayers(), "Wrong player number");
 
-    if (!m_dic.validateLetters(iLetters, L"+"))
+    if (!m_dic.validateLetters(iLetters, L"+-"))
         return 3;
 
     PlayedRack pld;

Index: game/pldrack.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/pldrack.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- game/pldrack.cpp    8 Jan 2008 13:52:39 -0000       1.10
+++ game/pldrack.cpp    26 Jan 2008 10:10:51 -0000      1.11
@@ -140,8 +140,18 @@
     if (iLetters.empty())
         return;
 
+    // Handle the reject sign
+    unsigned int begin;
+    if (iLetters[0] == L'-')
+    {
+        setReject();
+        begin = 1;
+    }
+    else
+        begin = 0;
+
     unsigned int i;
-    for (i = 0; i < iLetters.size() && iLetters[i] != L'+'; i++)
+    for (i = begin; i < iLetters.size() && iLetters[i] != L'+'; i++)
     {
         addOld(Tile(iLetters[i]));
     }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]