eliot-dev
[Top][All Lists]
Advanced

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

[Eliot-dev] eliot/qt Makefile.am dic_tools_widget.cpp dic_w...


From: Olivier Teulière
Subject: [Eliot-dev] eliot/qt Makefile.am dic_tools_widget.cpp dic_w...
Date: Sat, 15 May 2010 12:20:44 +0000

CVSROOT:        /cvsroot/eliot
Module name:    eliot
Changes by:     Olivier Teulière <ipkiss>       10/05/15 12:20:44

Modified files:
        qt             : Makefile.am dic_tools_widget.cpp dic_wizard.cpp 
                         dic_wizard.h main_window.cpp main_window.h 
        qt/ui          : dic_tools_widget.ui 
                         dic_wizard_letters_def_page.ui 
Added files:
        qt/ui          : dic_wizard_conclusion_page.ui 

Log message:
        Generate the dictionary from the wizard, and (optinally) load it.
        The wizard is now fully usable.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/Makefile.am?cvsroot=eliot&r1=1.17&r2=1.18
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/dic_tools_widget.cpp?cvsroot=eliot&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/dic_wizard.cpp?cvsroot=eliot&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/dic_wizard.h?cvsroot=eliot&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/main_window.cpp?cvsroot=eliot&r1=1.36&r2=1.37
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/main_window.h?cvsroot=eliot&r1=1.17&r2=1.18
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/ui/dic_tools_widget.ui?cvsroot=eliot&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/ui/dic_wizard_letters_def_page.ui?cvsroot=eliot&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/ui/dic_wizard_conclusion_page.ui?cvsroot=eliot&rev=1.1

Patches:
Index: Makefile.am
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/Makefile.am,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- Makefile.am 15 May 2010 12:13:35 -0000      1.17
+++ Makefile.am 15 May 2010 12:20:19 -0000      1.18
@@ -43,6 +43,7 @@
     ui/dic_tools_widget.ui \
     ui/dic_wizard_info_page.ui \
     ui/dic_wizard_letters_def_page.ui \
+    ui/dic_wizard_conclusion_page.ui \
     ui/main_window.ui \
     ui/new_game.ui \
     ui/player_widget.ui \
@@ -79,6 +80,7 @@
     ui/dic_tools_widget.ui.h \
     ui/dic_wizard_info_page.ui.h \
     ui/dic_wizard_letters_def_page.ui.h \
+    ui/dic_wizard_conclusion_page.ui.h \
     coord_model.moc.cpp \
     new_game.moc.cpp \
     dic_tools_widget.moc.cpp \

Index: dic_tools_widget.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/dic_tools_widget.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- dic_tools_widget.cpp        21 Sep 2009 20:10:34 -0000      1.13
+++ dic_tools_widget.cpp        15 May 2010 12:20:20 -0000      1.14
@@ -328,6 +328,12 @@
                 tmp += inputVect[i] + L"  ";
             }
             model->setData(model->index(rowNum, 5), qfw(tmp));
+            // Center the text in the column
+            for (int col = 0; col < 5; ++col)
+            {
+                model->item(rowNum, col)->setTextAlignment(Qt::AlignCenter);
+            }
+
             ++rowNum;
         }
         treeViewDicLetters->resizeColumnToContents(0);

Index: dic_wizard.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/dic_wizard.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- dic_wizard.cpp      15 May 2010 12:13:36 -0000      1.1
+++ dic_wizard.cpp      15 May 2010 12:20:20 -0000      1.2
@@ -21,6 +21,7 @@
 #include <iostream>
 
 #include <QtGui/QLabel>
+#include <QtGui/QSpinBox>
 #include <QtGui/QVBoxLayout>
 #include <QtGui/QFileDialog>
 #include <QtGui/QStandardItemModel>
@@ -32,6 +33,8 @@
 
 #include "dic_wizard.h"
 #include "qtcommon.h"
+#include "compdic.h"
+#include "dic_exception.h"
 
 using namespace std;
 
@@ -170,7 +173,7 @@
     setupUi(this);
 
     setTitle(_q("Letters characteristics"));
-    labelTableDesc->setText(_q("The table below lists all the letters found in 
the word list (plus the joker). "
+    labelDesc->setText(_q("The table below lists all the letters found in the 
word list (plus the joker). "
             "For each letter, you need to define:\n"
             " - its number of points;\n"
             " - its frequency (number of occurrences in the game);\n"
@@ -187,19 +190,12 @@
     m_model->setHeaderData(2, Qt::Horizontal, _q("Frequency"), 
Qt::DisplayRole);
     m_model->setHeaderData(3, Qt::Horizontal, _q("Vowel?"), Qt::DisplayRole);
     m_model->setHeaderData(4, Qt::Horizontal, _q("Consonant?"), 
Qt::DisplayRole);
-    tableLetters->setModel(m_model);
     treeLetters->setModel(m_model);
     treeLetters->header()->setDefaultAlignment(Qt::AlignCenter);
+    treeLetters->setItemDelegate(new LettersDelegate);
 
     connect(buttonLoadLetters, SIGNAL(clicked(bool)),
             this, SLOT(loadLettersFromWordList()));
-    connect(buttonRemoveLetter, SIGNAL(clicked(bool)),
-            this, SLOT(removeLetter()));
-    // Enable the Remove button only when there is a selection in the tree
-    connect(treeLetters->selectionModel(),
-            SIGNAL(selectionChanged(const QItemSelection&, const 
QItemSelection&)),
-            this,
-            SLOT(enableRemoveButton(const QItemSelection&)));
 }
 
 
@@ -233,8 +229,8 @@
         if (!res)
             return;
         m_model->setData(m_model->index(rowNum, 0), ch);
-        m_model->setData(m_model->index(rowNum, 1), 0);
-        m_model->setData(m_model->index(rowNum, 2), 0);
+        m_model->setData(m_model->index(rowNum, 1), 1);
+        m_model->setData(m_model->index(rowNum, 2), 1);
         m_model->setData(m_model->index(rowNum, 3),
                          (bool)QString("AEIOUY").contains(ch));
         m_model->setData(m_model->index(rowNum, 4),
@@ -246,7 +242,7 @@
     bool res = m_model->insertRow(rowNum);
     if (!res)
         return;
-    m_model->setData(m_model->index(rowNum, 0), QString(_q("? (joker)")));
+    m_model->setData(m_model->index(rowNum, 0), QChar('?'));
     m_model->setData(m_model->index(rowNum, 1), 0);
     m_model->setData(m_model->index(rowNum, 2), 2);
     m_model->setData(m_model->index(rowNum, 3), true);
@@ -264,46 +260,29 @@
 }
 
 
-void WizardLettersDefPage::enableRemoveButton(const QItemSelection &iSelected)
-{
-    // Enable the "Remove" button iff at least one line in the tree view
-    // is selected
-    buttonRemoveLetter->setEnabled(!iSelected.indexes().empty());
-}
+// ---------- WizardConclusionPage ----------
 
-
-void WizardLettersDefPage::removeLetter()
+WizardConclusionPage::WizardConclusionPage(QWidget *parent) : 
QWizardPage(parent)
 {
-    QModelIndexList indexList = 
treeLetters->selectionModel()->selectedIndexes();
-    if (indexList.empty())
-        return;
-
-    // Warn the user of the consequences
-    QString msg = _q("If you remove this letter, the only way to play words "
-                     "containing this letter will be to use the joker tile(s). 
"
-                     "This might be wanted in some rare cases, but it is "
-                     "usually better to remove the words containing the "
-                     "unwanted letter from the word list.");
-    QMessageBox confoBox(QMessageBox::Warning, _q("Eliot"), msg,
-                         QMessageBox::Yes | QMessageBox::No, this);
-    confoBox.setInformativeText(_q("Do you really want to continue?"));
-    confoBox.setDefaultButton(QMessageBox::Yes);
-    confoBox.setEscapeButton(QMessageBox::No);
-    int ret = confoBox.exec();
-    if (ret != QMessageBox::Yes)
-        return;
-
-    m_model->removeRow(indexList.front().row());
+    setupUi(this);
 }
 
 
-bool WizardLettersDefPage::isComplete() const
+void WizardConclusionPage::initializePage()
 {
-    if (!QWizardPage::isComplete())
-        return false;
+    setTitle(_q("Conclusion"));
 
-    // TODO
-    return true;
+    // This code must not be in the constructor, because the call to wizard()
+    // supposes that the page is already associated with the wizard
+    // (and thus already constructed)
+    QString finishText = wizard()->buttonText(QWizard::FinishButton);
+    finishText.remove('&');
+    labelDesc->setText(_q("Click %1 to generate the 
dictionary.\n\n").arg(finishText) +
+            QString("You may now load it in Eliot using the checkbox below.\n"
+                    "You can also load it later manually, using the "
+                    "'Settings -> Change dictionary...' menu option."));
+
+    registerField("loadDic", checkBoxLoadDic);
 }
 
 
@@ -314,7 +293,73 @@
 {
     setOption(QWizard::IndependentPages);
     addPage(new WizardInfoPage);
-    addPage(new WizardLettersDefPage());
-    // TODO
+    m_lettersPageId = addPage(new WizardLettersDefPage());
+    addPage(new WizardConclusionPage());
+
+    setWindowTitle(_q("Dictionary creation"));
+}
+
+
+void DicWizard::accept()
+{
+    CompDic builder;
+    try {
+        // Retrieve the letters model
+        const QStandardItemModel *model =
+            
static_cast<WizardLettersDefPage*>(page(m_lettersPageId))->getModel();
+
+        // Define the letters
+        for (int i = 0; i < model->rowCount(); ++i)
+        {
+            QString letter = model->data(model->index(i, 0)).toString();
+            int points = model->data(model->index(i, 1)).toInt();
+            int frequency = model->data(model->index(i, 2)).toInt();
+            bool isVowel = model->data(model->index(i, 3)).toBool();
+            bool isConsonant = model->data(model->index(i, 4)).toBool();
+
+            wstring wstr = qtw(letter);
+            if (wstr.size() != 1)
+                throw DicException("Invalid letter '" + qtl(letter) + "'");
+            builder.addLetter(wstr[0], points, frequency,
+                              isVowel, isConsonant, vector<wstring>());
+        }
+
+        // Build the dictionary
+        builder.generateDawg(qtl(field("wordList").toString()),
+                             qtl(field("genDic").toString()),
+                             qtl(field("dicName").toString()));
+    }
+    catch (std::exception &e)
+    {
+        QMessageBox::warning(this, _q("Eliot - Error"), e.what());
+        return;
+    }
+
+    emit infoMsg(_q("Dictionary successfully created"));
+
+    bool shouldLoad = field("loadDic").toBool();
+    if (shouldLoad)
+    {
+        emit loadDictionary(field("genDic").toString());
+    }
+
+    QDialog::accept();
+}
+
+
+// ---------- LettersDelegate ----------
+
+QWidget * LettersDelegate::createEditor(QWidget *parent,
+                                        const QStyleOptionViewItem &option,
+                                        const QModelIndex &index) const
+{
+    // For integer columns, bound the values in the [0, 20] range
+    QWidget * editor = QStyledItemDelegate::createEditor(parent, option, 
index);
+    if (editor->inherits("QSpinBox"))
+    {
+        static_cast<QSpinBox*>(editor)->setMinimum(0);
+        static_cast<QSpinBox*>(editor)->setMaximum(20);
+    }
+    return editor;
 }
 

Index: dic_wizard.h
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/dic_wizard.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- dic_wizard.h        15 May 2010 12:13:36 -0000      1.1
+++ dic_wizard.h        15 May 2010 12:20:20 -0000      1.2
@@ -23,12 +23,16 @@
 
 #include <QtGui/QWizard>
 #include <QtGui/QWizardPage>
+#include <QtGui/QStyledItemDelegate>
 
 #include "ui/dic_wizard_info_page.ui.h"
 #include "ui/dic_wizard_letters_def_page.ui.h"
+#include "ui/dic_wizard_conclusion_page.ui.h"
 
 class QStandardItemModel;
 class QItemSelection;
+class QStyleOptionViewItem;
+class QModelIndex;
 
 class DicWizard: public QWizard
 {
@@ -36,9 +40,14 @@
 
 public:
     DicWizard(QWidget *parent);
+    virtual void accept();
 
 private:
-    QWizardPage *createLettersDefPage() const;
+    int m_lettersPageId;
+
+signals:
+    void loadDictionary(QString dawgFile);
+    void infoMsg(QString message);
 };
 
 
@@ -61,17 +70,37 @@
     Q_OBJECT
 public:
     explicit WizardLettersDefPage(QWidget *parent = 0);
-    virtual bool isComplete() const;
+    const QStandardItemModel * getModel() const { return m_model; }
 
 private:
     QStandardItemModel *m_model;
 
 private slots:
     void loadLettersFromWordList();
-    void enableRemoveButton(const QItemSelection &);
-    void removeLetter();
 };
 
 
+class WizardConclusionPage: public QWizardPage, private 
Ui::WizardConclusionPage
+{
+    Q_OBJECT
+public:
+    explicit WizardConclusionPage(QWidget *parent = 0);
+    virtual void initializePage();
+};
+
+
+class LettersDelegate: public QStyledItemDelegate
+{
+    Q_OBJECT;
+
+public:
+    explicit LettersDelegate(QWidget *parent = 0)
+        : QStyledItemDelegate(parent) {}
+
+    virtual QWidget *createEditor(QWidget *parent,
+                                  const QStyleOptionViewItem &option,
+                                  const QModelIndex &index) const;
+};
+
 #endif
 

Index: main_window.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/main_window.cpp,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -b -r1.36 -r1.37
--- main_window.cpp     15 May 2010 12:13:36 -0000      1.36
+++ main_window.cpp     15 May 2010 12:20:23 -0000      1.37
@@ -170,6 +170,7 @@
         {
             displayErrorMsg(_q("Cannot load dictionary '%1' indicated in the "
                                "preferences.\nReason: 
%2").arg(dicPath).arg(e.what()));
+            return;
         }
     }
     emit dicChanged(m_dic);
@@ -352,6 +353,45 @@
 }
 
 
+void MainWindow::changeDictionary(QString iFileName)
+{
+    if (!iFileName.isEmpty())
+    {
+        if (m_game)
+        {
+            QString msg = _q("Loading a dictionary will stop the current 
game.");
+            QMessageBox confirmationBox(QMessageBox::Question, _q("Eliot"), 
msg,
+                                        QMessageBox::Yes | QMessageBox::No, 
this);
+            confirmationBox.setInformativeText(_q("Do you want to continue?"));
+            confirmationBox.setDefaultButton(QMessageBox::Yes);
+            confirmationBox.setEscapeButton(QMessageBox::No);
+            int res = confirmationBox.exec();
+            if (res == QMessageBox::No)
+                return;
+        }
+
+        destroyCurrentGame();
+
+        try
+        {
+            Dictionary *dic = new Dictionary(qtl(iFileName));
+            delete m_dic;
+            m_dic = dic;
+            emit dicChanged(m_dic);
+            displayInfoMsg(_q("Loaded dictionary '%1'").arg(iFileName));
+
+            // Save the location of the dictionary in the preferences
+            QSettings qs(ORGANIZATION, PACKAGE_NAME);
+            qs.setValue(PrefsDialog::kINTF_DIC_PATH, iFileName);
+        }
+        catch (std::exception &e)
+        {
+            displayErrorMsg(e.what());
+        }
+    }
+}
+
+
 QAction * MainWindow::addMenuAction(QMenu *menu, QString iText,
                                     const QKeySequence &iShortcut,
                                     QString iStatusTip, const char *iMember,
@@ -705,42 +745,9 @@
 
 void MainWindow::onSettingsChooseDic()
 {
-    if (m_game)
-    {
-        QString msg = _q("Loading a dictionary will stop the current game.");
-        QMessageBox confirmationBox(QMessageBox::Question, _q("Eliot"), msg,
-                                    QMessageBox::Yes | QMessageBox::No, this);
-        confirmationBox.setInformativeText(_q("Do you want to continue?"));
-        confirmationBox.setDefaultButton(QMessageBox::Yes);
-        confirmationBox.setEscapeButton(QMessageBox::No);
-        int res = confirmationBox.exec();
-        if (res == QMessageBox::No)
-            return;
-    }
-
     QString fileName =
         QFileDialog::getOpenFileName(this, _q("Choose a dictionary"), "", 
"*.dawg");
-    if (!fileName.isEmpty())
-    {
-        destroyCurrentGame();
-
-        try
-        {
-            Dictionary *dic = new Dictionary(qtl(fileName));
-            delete m_dic;
-            m_dic = dic;
-            emit dicChanged(m_dic);
-            displayInfoMsg(_q("Loaded dictionary '%1'").arg(fileName));
-
-            // Save the location of the dictionary in the preferences
-            QSettings qs(ORGANIZATION, PACKAGE_NAME);
-            qs.setValue(PrefsDialog::kINTF_DIC_PATH, fileName);
-        }
-        catch (std::exception &e)
-        {
-            displayErrorMsg(e.what());
-        }
-    }
+    changeDictionary(fileName);
 }
 
 
@@ -749,6 +756,10 @@
     DicWizard *wizard = new DicWizard(this);
     wizard->setWindowTitle(_("Dictionary creation wizard"));
     wizard->setModal(true);
+    connect(wizard, SIGNAL(infoMsg(QString)),
+            this, SLOT(displayInfoMsg(QString)));
+    connect(wizard, SIGNAL(loadDictionary(QString)),
+            this, SLOT(changeDictionary(QString)));
     wizard->show();
 }
 

Index: main_window.h
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/main_window.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- main_window.h       15 May 2010 12:13:37 -0000      1.17
+++ main_window.h       15 May 2010 12:20:27 -0000      1.18
@@ -83,6 +83,9 @@
     void onHistoryLastTurn();
     void onHistoryReplayTurn();
 
+    /** Load a new dictionary */
+    void changeDictionary(QString);
+
     /** Perform some updates when the game is updated */
     void refresh();
 

Index: ui/dic_tools_widget.ui
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/ui/dic_tools_widget.ui,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- ui/dic_tools_widget.ui      28 Jun 2009 11:47:50 -0000      1.5
+++ ui/dic_tools_widget.ui      15 May 2010 12:20:32 -0000      1.6
@@ -207,6 +207,9 @@
          <property name="editTriggers">
           <set>QAbstractItemView::NoEditTriggers</set>
          </property>
+         <property name="alternatingRowColors">
+          <bool>true</bool>
+         </property>
          <property name="rootIsDecorated">
           <bool>false</bool>
          </property>

Index: ui/dic_wizard_letters_def_page.ui
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/ui/dic_wizard_letters_def_page.ui,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- ui/dic_wizard_letters_def_page.ui   15 May 2010 12:13:37 -0000      1.1
+++ ui/dic_wizard_letters_def_page.ui   15 May 2010 12:20:44 -0000      1.2
@@ -15,7 +15,7 @@
   </property>
   <layout class="QVBoxLayout" name="verticalLayout">
    <item>
-    <widget class="QLabel" name="labelTableDesc">
+    <widget class="QLabel" name="labelDesc">
      <property name="text">
       <string>Description</string>
      </property>
@@ -46,16 +46,6 @@
        </property>
       </spacer>
      </item>
-     <item>
-      <widget class="QPushButton" name="buttonRemoveLetter">
-       <property name="enabled">
-        <bool>false</bool>
-       </property>
-       <property name="text">
-        <string>_(&quot;Remove Letter&quot;)</string>
-       </property>
-      </widget>
-     </item>
     </layout>
    </item>
    <item>
@@ -71,22 +61,6 @@
      </property>
     </widget>
    </item>
-   <item>
-    <widget class="QTableView" name="tableLetters">
-     <property name="editTriggers">
-      
<set>QAbstractItemView::AnyKeyPressed|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked</set>
-     </property>
-     <property name="alternatingRowColors">
-      <bool>true</bool>
-     </property>
-     <property name="selectionMode">
-      <enum>QAbstractItemView::SingleSelection</enum>
-     </property>
-     <property name="selectionBehavior">
-      <enum>QAbstractItemView::SelectRows</enum>
-     </property>
-    </widget>
-   </item>
   </layout>
  </widget>
  <resources/>

Index: ui/dic_wizard_conclusion_page.ui
===================================================================
RCS file: ui/dic_wizard_conclusion_page.ui
diff -N ui/dic_wizard_conclusion_page.ui
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ ui/dic_wizard_conclusion_page.ui    15 May 2010 12:20:39 -0000      1.1
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>WizardConclusionPage</class>
+ <widget class="QWizardPage" name="WizardConclusionPage">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>WizardPage</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <widget class="QLabel" name="labelDesc">
+     <property name="text">
+      <string>Description</string>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QCheckBox" name="checkBoxLoadDic">
+     <property name="text">
+      <string>_(&quot;Load this dictionary in Eliot&quot;)</string>
+     </property>
+     <property name="checked">
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <spacer name="verticalSpacer">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>20</width>
+       <height>231</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>



reply via email to

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