[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Eliot-dev] eliot/qt Makefile.am dic_tools_widget.cpp dic_t...
From: |
Olivier Teulière |
Subject: |
[Eliot-dev] eliot/qt Makefile.am dic_tools_widget.cpp dic_t... |
Date: |
Thu, 28 Jul 2011 20:55:50 +0000 |
CVSROOT: /cvsroot/eliot
Module name: eliot
Changes by: Olivier Teulière <ipkiss> 11/07/28 20:55:49
Modified files:
qt : Makefile.am dic_tools_widget.cpp
dic_tools_widget.h history_widget.cpp
history_widget.h main_window.cpp main_window.h
player_widget.cpp player_widget.h
prefs_dialog.cpp prefs_dialog.h
training_widget.cpp training_widget.h
qt/ui : prefs_dialog.ui
Added files:
qt : custom_popup.cpp custom_popup.h
Log message:
Added support for definitions, using an external website
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/Makefile.am?cvsroot=eliot&r1=1.24&r2=1.25
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/dic_tools_widget.cpp?cvsroot=eliot&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/dic_tools_widget.h?cvsroot=eliot&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/history_widget.cpp?cvsroot=eliot&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/history_widget.h?cvsroot=eliot&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/main_window.cpp?cvsroot=eliot&r1=1.41&r2=1.42
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/main_window.h?cvsroot=eliot&r1=1.20&r2=1.21
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/player_widget.cpp?cvsroot=eliot&r1=1.22&r2=1.23
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/player_widget.h?cvsroot=eliot&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/prefs_dialog.cpp?cvsroot=eliot&r1=1.12&r2=1.13
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/prefs_dialog.h?cvsroot=eliot&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/training_widget.cpp?cvsroot=eliot&r1=1.22&r2=1.23
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/training_widget.h?cvsroot=eliot&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/custom_popup.cpp?cvsroot=eliot&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/custom_popup.h?cvsroot=eliot&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/ui/prefs_dialog.ui?cvsroot=eliot&r1=1.11&r2=1.12
Patches:
Index: Makefile.am
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/Makefile.am,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -b -r1.24 -r1.25
--- Makefile.am 16 Jan 2011 21:30:31 -0000 1.24
+++ Makefile.am 28 Jul 2011 20:55:48 -0000 1.25
@@ -59,6 +59,7 @@
coord_model.h coord_model.cpp \
tile_widget.cpp tile_widget.h \
tile_layout.cpp tile_layout.h \
+ custom_popup.cpp custom_popup.h \
bag_widget.cpp bag_widget.h \
bag_widget2.cpp bag_widget2.h \
dic_tools_widget.cpp dic_tools_widget.h \
@@ -89,6 +90,7 @@
coord_model.moc.cpp \
tile_widget.moc.cpp \
tile_layout.moc.cpp \
+ custom_popup.moc.cpp \
new_game.moc.cpp \
dic_tools_widget.moc.cpp \
bag_widget.moc.cpp \
Index: dic_tools_widget.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/dic_tools_widget.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- dic_tools_widget.cpp 18 Sep 2010 13:07:39 -0000 1.15
+++ dic_tools_widget.cpp 28 Jul 2011 20:55:49 -0000 1.16
@@ -34,6 +34,7 @@
#include <QtCore/QString>
#include "dic_tools_widget.h"
+#include "custom_popup.h"
#include "qtcommon.h"
#include "dic.h"
#include "header.h"
@@ -91,6 +92,19 @@
QObject::connect(lineEditRegexp, SIGNAL(returnPressed()), this,
SLOT(refreshRegexp()));
QObject::connect(buttonSaveWords, SIGNAL(clicked()), this,
SLOT(exportWordsList()));
+ // Add context menus for the results
+ m_customPopupPlus1 = new CustomPopup(treeViewPlus1);
+ QObject::connect(m_customPopupPlus1, SIGNAL(popupCreated(QMenu&, const
QPoint&)),
+ this, SLOT(populateMenuPlus1(QMenu&, const QPoint&)));
+ QObject::connect(m_customPopupPlus1, SIGNAL(requestDefinition(QString)),
+ this, SIGNAL(requestDefinition(QString)));
+
+ m_customPopupRegexp = new CustomPopup(treeViewRegexp);
+ QObject::connect(m_customPopupRegexp, SIGNAL(popupCreated(QMenu&, const
QPoint&)),
+ this, SLOT(populateMenuRegexp(QMenu&, const QPoint&)));
+ QObject::connect(m_customPopupRegexp, SIGNAL(requestDefinition(QString)),
+ this, SIGNAL(requestDefinition(QString)));
+
// Create models
m_plus1Model = new QStandardItemModel(this);
treeViewPlus1->setModel(m_plus1Model);
@@ -373,6 +387,34 @@
}
+void DicToolsWidget::populateMenuPlus1(QMenu &iMenu, const QPoint &iPoint)
+{
+ const QModelIndex &index = treeViewPlus1->indexAt(iPoint);
+ if (!index.isValid() || !index.parent().isValid())
+ return;
+
+ // Find the selected word
+ const QModelIndex &wordIndex = m_plus1Model->index(index.row(), 0,
index.parent());
+ QString selectedWord = m_plus1Model->data(wordIndex).toString();
+
+ m_customPopupPlus1->addShowDefinitionEntry(iMenu, selectedWord);
+}
+
+
+void DicToolsWidget::populateMenuRegexp(QMenu &iMenu, const QPoint &iPoint)
+{
+ const QModelIndex &index = treeViewRegexp->indexAt(iPoint);
+ if (!index.isValid())
+ return;
+
+ // Find the selected word
+ const QModelIndex &wordIndex = m_regexpModel->index(index.row(), 0);
+ QString selectedWord = m_regexpModel->data(wordIndex).toString();
+
+ m_customPopupRegexp->addShowDefinitionEntry(iMenu, selectedWord);
+}
+
+
DicRackValidator::DicRackValidator(QObject *parent,
const Dictionary *iDic,
Index: dic_tools_widget.h
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/dic_tools_widget.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- dic_tools_widget.h 18 Sep 2010 13:07:39 -0000 1.5
+++ dic_tools_widget.h 28 Jul 2011 20:55:49 -0000 1.6
@@ -29,6 +29,7 @@
class QStandardItemModel;
class QString;
class Dictionary;
+class CustomPopup;
class DicToolsWidget: public QWidget, private Ui::DicToolsWidget
{
@@ -41,6 +42,9 @@
void setDic(const Dictionary *iDic);
void setPlus1Rack(const QString &iRack);
+signals:
+ void requestDefinition(QString iWord);
+
private:
/// Dictionary in which the searches are done
const Dictionary *m_dic;
@@ -59,6 +63,12 @@
/// Palette to write text in green
QPalette greenPalette;
+ /// Popup menu for words definition
+ CustomPopup *m_customPopupPlus1;
+
+ /// Popup menu for words definition
+ CustomPopup *m_customPopupRegexp;
+
private slots:
/// Force synchronizing the model with the "check" results
void refreshCheck();
@@ -70,6 +80,9 @@
void refreshDicInfo();
/// Save the words of the dictionary to a file
void exportWordsList();
+ /// Build the popup menu
+ void populateMenuPlus1(QMenu &iMenu, const QPoint &iPoint);
+ void populateMenuRegexp(QMenu &iMenu, const QPoint &iPoint);
};
#endif
Index: history_widget.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/history_widget.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- history_widget.cpp 30 Nov 2008 20:53:45 -0000 1.7
+++ history_widget.cpp 28 Jul 2011 20:55:49 -0000 1.8
@@ -26,6 +26,7 @@
#include <QtCore/QSettings>
#include "history_widget.h"
+#include "custom_popup.h"
#include "prefs_dialog.h"
#include "qtcommon.h"
#include "public_game.h"
@@ -44,6 +45,13 @@
setEditTriggers(QAbstractItemView::NoEditTriggers);
setRootIsDecorated(false);
+ // Add a context menu for the results
+ m_customPopup = new CustomPopup(this);
+ QObject::connect(m_customPopup, SIGNAL(popupCreated(QMenu&, const
QPoint&)),
+ this, SLOT(populateMenu(QMenu&, const QPoint&)));
+ QObject::connect(m_customPopup, SIGNAL(requestDefinition(QString)),
+ this, SIGNAL(requestDefinition(QString)));
+
// Associate the model to the view
m_model = new QStandardItemModel(this);
setModel(m_model);
@@ -74,6 +82,21 @@
}
+void HistoryWidget::populateMenu(QMenu &iMenu, const QPoint &iPoint)
+{
+ const QModelIndex &index = indexAt(iPoint);
+ if (!index.isValid())
+ return;
+
+ // Find the selected word
+ const QModelIndex &wordIndex = m_model->index(index.row(), 2);
+ QString selectedWord = m_model->data(wordIndex).toString();
+
+ if (selectedWord != "")
+ m_customPopup->addShowDefinitionEntry(iMenu, selectedWord);
+}
+
+
void HistoryWidget::updateModel()
{
m_model->removeRows(0, m_model->rowCount());
@@ -208,6 +231,8 @@
m_gameHistoryWidget->setHistory(&m_game->getHistory(), m_game);
QObject::connect(this, SIGNAL(refreshSignal()),
m_gameHistoryWidget, SLOT(refresh()));
+ QObject::connect(m_gameHistoryWidget,
SIGNAL(requestDefinition(QString)),
+ this, SIGNAL(requestDefinition(QString)));
// In training mode, the players history is completely useless
if (m_game->getMode() == PublicGame::kTRAINING)
@@ -220,6 +245,8 @@
HistoryWidget *h = new HistoryWidget(NULL);
h->setHistory(&player.getHistory(), m_game, true);
QObject::connect(this, SIGNAL(refreshSignal()), h,
SLOT(refresh()));
+ QObject::connect(h, SIGNAL(requestDefinition(QString)),
+ this, SIGNAL(requestDefinition(QString)));
addTab(h, qfw(player.getName()));
}
}
Index: history_widget.h
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/history_widget.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- history_widget.h 30 Nov 2008 20:53:45 -0000 1.4
+++ history_widget.h 28 Jul 2011 20:55:49 -0000 1.5
@@ -29,6 +29,7 @@
class PublicGame;
class QStandardItemModel;
class QTabWidget;
+class CustomPopup;
class HistoryWidget: public QTreeView
{
@@ -44,6 +45,12 @@
public slots:
void refresh();
+signals:
+ void requestDefinition(QString iWord);
+
+private slots:
+ void populateMenu(QMenu &iMenu, const QPoint &iPoint);
+
private:
/// Encapsulated history, can be NULL
const History *m_history;
@@ -60,6 +67,9 @@
/// Model of the history
QStandardItemModel *m_model;
+ /// Popup menu for words definition
+ CustomPopup *m_customPopup;
+
/// Force synchronizing the model with the contents of the history
void updateModel();
};
@@ -78,6 +88,7 @@
signals:
void refreshSignal();
+ void requestDefinition(QString iWord);
protected:
virtual QSize sizeHint() const;
Index: main_window.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/main_window.cpp,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -b -r1.41 -r1.42
--- main_window.cpp 30 Jan 2011 00:23:46 -0000 1.41
+++ main_window.cpp 28 Jul 2011 20:55:49 -0000 1.42
@@ -20,7 +20,7 @@
#include "config.h"
-#include <iostream>
+//#include <iostream>
#include <QtGui/QLabel>
#include <QtGui/QMessageBox>
#include <QtGui/QFileDialog>
@@ -29,7 +29,9 @@
#include <QtGui/QPrintDialog>
#include <QtGui/QPrinter>
#include <QtGui/QPainter>
+#include <QtGui/QDesktopServices>
#include <QtCore/QSettings>
+#include <QtCore/QUrl>
#include "main_window.h"
#include "dic.h"
@@ -127,6 +129,8 @@
historyTab, SLOT(setGame(const PublicGame*)));
QObject::connect(this, SIGNAL(gameUpdated()),
historyTab, SLOT(refresh()));
+ QObject::connect(historyTab, SIGNAL(requestDefinition(QString)),
+ this, SLOT(showDefinition(QString)));
QHBoxLayout *hlayout2 = new QHBoxLayout;
hlayout2->addWidget(historyTab);
m_ui.groupBoxHistory->setLayout(hlayout2);
@@ -145,8 +149,8 @@
QObject::connect(m_playersWidget, SIGNAL(gameUpdated()), this,
SIGNAL(gameUpdated()));
QObject::connect(m_playersWidget, SIGNAL(notifyProblem(QString)),
this, SLOT(displayErrorMsg(QString)));
- QObject::connect(m_playersWidget, SIGNAL(notifyInfo(QString)),
- this, SLOT(displayInfoMsg(QString)));
+ QObject::connect(m_playersWidget, SIGNAL(requestDefinition(QString)),
+ this, SLOT(showDefinition(QString)));
// Players score
ScoreWidget *scores = new ScoreWidget;
@@ -319,6 +323,28 @@
}
+void MainWindow::showDefinition(QString iWord)
+{
+ QSettings qs(ORGANIZATION, PACKAGE_NAME);
+ QString url = qs.value(PrefsDialog::kINTF_DEFINITIONS_SITE_URL,
+ PrefsDialog::kDEFAULT_DEF_SITE).toString();
+ if (url == "")
+ {
+ displayErrorMsg(_q("No definitions site defined.\n"
+ "Please define one in the preferences."));
+ return;
+ }
+
+ url = url.replace("%w", iWord.toLower());
+ url = url.replace("%W", iWord.toUpper());
+ bool res = QDesktopServices::openUrl(QUrl(url));
+ if (!res)
+ {
+ LOG_ERROR("Could not open URL: " << qtl(url));
+ }
+}
+
+
void MainWindow::closeEvent(QCloseEvent *event)
{
// Make sure auxiliary windows don't survive after the main one
@@ -878,6 +904,8 @@
m_actionWindowsDicTools);
QObject::connect(this, SIGNAL(dicChanged(const Dictionary*)),
dicTools, SLOT(setDic(const Dictionary*)));
+ QObject::connect(dicTools, SIGNAL(requestDefinition(QString)),
+ this, SLOT(showDefinition(QString)));
// Link the training rack with the "Plus 1" one
QSettings qs(ORGANIZATION, PACKAGE_NAME);
if (qs.value(PrefsDialog::kINTF_LINK_TRAINING_7P1, false).toBool())
@@ -899,7 +927,7 @@
QString msg;
msg.sprintf("Eliot %s\n\n", VERSION);
msg += _q( \
- "Copyright (C) 1999-2010 - Antoine Fraboulet & Olivier Teuliere\n\n" \
+ "Copyright (C) 1999-2011 - 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 " \
Index: main_window.h
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/main_window.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- main_window.h 29 Jan 2011 23:47:21 -0000 1.20
+++ main_window.h 28 Jul 2011 20:55:49 -0000 1.21
@@ -104,6 +104,9 @@
/// Update the status bar contents
void updateStatusBar(const Dictionary *iDic);
+ /** Show the definition of the given word */
+ void showDefinition(QString iWord);
+
private:
/// Current dictionary
const Dictionary *m_dic;
Index: player_widget.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/player_widget.cpp,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- player_widget.cpp 16 Jul 2011 23:31:18 -0000 1.22
+++ player_widget.cpp 28 Jul 2011 20:55:49 -0000 1.23
@@ -281,6 +281,8 @@
this, SIGNAL(gameUpdated()));
QObject::connect(trWidget, SIGNAL(rackUpdated(const QString&)),
this, SIGNAL(trainingRackUpdated(const
QString&)));
+ QObject::connect(trWidget, SIGNAL(requestDefinition(QString)),
+ this, SIGNAL(requestDefinition(QString)));
addTab(trWidget, qfw(player.getName()));
}
else
Index: player_widget.h
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/player_widget.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- player_widget.h 15 Jan 2011 16:33:02 -0000 1.11
+++ player_widget.h 28 Jul 2011 20:55:49 -0000 1.12
@@ -92,6 +92,7 @@
void notifyProblem(QString iMsg);
void notifyInfo(QString iMsg);
void trainingRackUpdated(const QString &iRack);
+ void requestDefinition(QString iWord);
private slots:
void changeCurrentPlayer(int);
Index: prefs_dialog.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/prefs_dialog.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- prefs_dialog.cpp 19 Feb 2009 21:56:41 -0000 1.12
+++ prefs_dialog.cpp 28 Jul 2011 20:55:49 -0000 1.13
@@ -23,6 +23,7 @@
#include <QtCore/QSettings>
#include <QtGui/QFileDialog>
#include <QtGui/QMessageBox>
+#include <QtCore/QStringList>
#include "prefs_dialog.h"
#include "game_exception.h"
@@ -31,22 +32,31 @@
const QString PrefsDialog::kINTF_ALIGN_HISTORY = "Interface/AlignHistory";
const QString PrefsDialog::kINTF_DIC_PATH = "Interface/DicPath";
+const QString PrefsDialog::kINTF_DEFINITIONS_SITE_URL =
"Interface/DefinitionsSiteUrl";
const QString PrefsDialog::kINTF_SHOW_TILES_POINTS =
"Interface/ShowTilesPoints";
const QString PrefsDialog::kINTF_WARN_REPLAY_TURN = "Interface/WarnReplayTurn";
const QString PrefsDialog::kINTF_SHOW_TOOLBAR = "Interface/ShowToolBar";
const QString PrefsDialog::kINTF_LINK_TRAINING_7P1 =
"Interface/LinkTrainingRackWith7P1";
+const QString PrefsDialog::kDEFAULT_DEF_SITE =
"http://fr.wiktionary.org/wiki/%w";
PrefsDialog::PrefsDialog(QWidget *iParent)
: QDialog(iParent)
{
setupUi(this);
+ lineEditDefSite->setToolTip(_("URL of the site used to display word
definitions.\n"
+ "In the URL, %w will be replaced with the
word in lower case. Examples:\n"
+ "\thttp://fr.wiktionary.org/wiki/%w\n"
+ "\thttp://en.wiktionary.org/wiki/%w\n"
+ "\thttp://images.google.com/images?q=%w"));
try
{
// Interface settings
QSettings qs(ORGANIZATION, PACKAGE_NAME);
lineEditIntfDicPath->setText(qs.value(kINTF_DIC_PATH, "").toString());
+ lineEditDefSite->setText(qs.value(kINTF_DEFINITIONS_SITE_URL,
+ kDEFAULT_DEF_SITE).toString());
checkBoxIntfAlignHistory->setChecked(qs.value(kINTF_ALIGN_HISTORY).toBool());
bool showPoints = qs.value(kINTF_SHOW_TILES_POINTS, true).toBool();
checkBoxIntfShowPoints->setChecked(showPoints);
@@ -99,6 +109,7 @@
// Interface settings
QSettings qs(ORGANIZATION, PACKAGE_NAME);
qs.setValue(kINTF_DIC_PATH, lineEditIntfDicPath->text());
+ qs.setValue(kINTF_DEFINITIONS_SITE_URL, lineEditDefSite->text());
if (qs.value(kINTF_ALIGN_HISTORY, true).toBool() !=
checkBoxIntfAlignHistory->isChecked())
{
// We need to redraw the history widget
Index: prefs_dialog.h
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/prefs_dialog.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- prefs_dialog.h 24 Jan 2009 17:44:57 -0000 1.7
+++ prefs_dialog.h 28 Jul 2011 20:55:49 -0000 1.8
@@ -26,6 +26,8 @@
#include <ui/prefs_dialog.ui.h>
+class QStringList;
+
class PrefsDialog: public QDialog, private Ui::PrefsDialog
{
@@ -36,11 +38,14 @@
static const QString kINTF_ALIGN_HISTORY;
static const QString kINTF_DIC_PATH;
+ static const QString kINTF_DEFINITIONS_SITE_URL;
static const QString kINTF_SHOW_TILES_POINTS;
static const QString kINTF_WARN_REPLAY_TURN;
static const QString kINTF_SHOW_TOOLBAR;
static const QString kINTF_LINK_TRAINING_7P1;
+ static const QString kDEFAULT_DEF_SITE;
+
public slots:
/// Update the settings when the user selects "OK"
virtual void accept();
Index: training_widget.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/training_widget.cpp,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- training_widget.cpp 17 Jul 2011 09:16:52 -0000 1.22
+++ training_widget.cpp 28 Jul 2011 20:55:49 -0000 1.23
@@ -1,6 +1,6 @@
/*****************************************************************************
* Eliot
- * Copyright (C) 2010 Olivier Teulière
+ * Copyright (C) 2010-2011 Olivier Teulière
* Authors: Olivier Teulière <ipkiss @@ gmail.com>
*
* This program is free software; you can redistribute it and/or modify
@@ -24,6 +24,7 @@
#include "training_widget.h"
#include "qtcommon.h"
#include "play_word_mediator.h"
+#include "custom_popup.h"
#include "dic.h"
#include "bag.h"
@@ -92,6 +93,13 @@
QObject::connect(lockSizesAction, SIGNAL(toggled(bool)),
this, SLOT(lockSizesChanged(bool)));
+ // Add another context menu for the results
+ m_customPopup = new CustomPopup(treeViewResults);
+ QObject::connect(m_customPopup, SIGNAL(popupCreated(QMenu&, const
QPoint&)),
+ this, SLOT(populateMenu(QMenu&, const QPoint&)));
+ QObject::connect(m_customPopup, SIGNAL(requestDefinition(QString)),
+ this, SIGNAL(requestDefinition(QString)));
+
// Allow very thin columns
treeViewResults->header()->setMinimumSectionSize(1);
@@ -243,6 +251,20 @@
}
+void TrainingWidget::populateMenu(QMenu &iMenu, const QPoint &iPoint)
+{
+ const QModelIndex &index = treeViewResults->indexAt(iPoint);
+ if (!index.isValid())
+ return;
+
+ // Find the selected word
+ const QModelIndex &wordIndex = m_model->index(index.row(), 0);
+ QString selectedWord = m_model->data(wordIndex).toString();
+
+ m_customPopup->addShowDefinitionEntry(iMenu, selectedWord);
+}
+
+
void TrainingWidget::lockSizesChanged(bool checked)
{
m_autoResizeColumns = !checked;
Index: training_widget.h
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/training_widget.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- training_widget.h 17 Jul 2011 09:09:47 -0000 1.8
+++ training_widget.h 28 Jul 2011 20:55:49 -0000 1.9
@@ -1,6 +1,6 @@
/*****************************************************************************
* Eliot
- * Copyright (C) 2008 Olivier Teulière
+ * Copyright (C) 2008-2011 Olivier Teulière
* Authors: Olivier Teulière <ipkiss @@ gmail.com>
*
* This program is free software; you can redistribute it and/or modify
@@ -27,7 +27,9 @@
class QStandardItemModel;
class QString;
+class QPoint;
class CoordModel;
+class CustomPopup;
class PlayWordMediator;
class PublicGame;
@@ -46,6 +48,7 @@
void notifyProblem(QString iMsg);
void notifyInfo(QString iMsg);
void rackUpdated(const QString &iRack);
+ void requestDefinition(QString iWord);
protected:
/// Define a default size
@@ -56,6 +59,7 @@
void showPreview(const QItemSelection &, const QItemSelection &);
void lockSizesChanged(bool checked);
+ void populateMenu(QMenu &iMenu, const QPoint &iPoint);
// These slots are automatically connected
void on_lineEditRack_textEdited(const QString &iText);
@@ -84,6 +88,9 @@
/// Palette to write text in black
QPalette blackPalette;
+ /// Popup menu for words definition
+ CustomPopup *m_customPopup;
+
/// Force synchronizing the model with the contents of the search results
void updateModel();
};
Index: ui/prefs_dialog.ui
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/ui/prefs_dialog.ui,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- ui/prefs_dialog.ui 22 Jan 2009 21:41:27 -0000 1.11
+++ ui/prefs_dialog.ui 28 Jul 2011 20:55:49 -0000 1.12
@@ -1,93 +1,108 @@
-<ui version="4.0" >
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
<class>PrefsDialog</class>
- <widget class="QDialog" name="PrefsDialog" >
- <property name="geometry" >
+ <widget class="QDialog" name="PrefsDialog">
+ <property name="geometry">
<rect>
<x>0</x>
<y>0</y>
- <width>414</width>
- <height>526</height>
+ <width>491</width>
+ <height>528</height>
</rect>
</property>
- <property name="windowTitle" >
- <string>_("Preferences")</string>
+ <property name="windowTitle">
+ <string>_("Preferences")</string>
</property>
- <layout class="QVBoxLayout" >
+ <layout class="QVBoxLayout">
<item>
- <widget class="QGroupBox" name="groupBoxInterface" >
- <property name="title" >
- <string>_("Interface")</string>
+ <widget class="QGroupBox" name="groupBoxInterface">
+ <property name="title">
+ <string>_("Interface")</string>
</property>
- <layout class="QVBoxLayout" name="verticalLayout_2" >
+ <layout class="QVBoxLayout" name="verticalLayout_2">
<item>
- <layout class="QHBoxLayout" >
+ <layout class="QHBoxLayout">
<item>
- <widget class="QLabel" name="label_4" >
- <property name="text" >
- <string>_("Dictionary path:")</string>
+ <widget class="QLabel" name="label_4">
+ <property name="text">
+ <string>_("Dictionary path:")</string>
</property>
</widget>
</item>
<item>
- <widget class="QLineEdit" name="lineEditIntfDicPath" >
- <property name="minimumSize" >
+ <widget class="QLineEdit" name="lineEditIntfDicPath">
+ <property name="minimumSize">
<size>
<width>140</width>
<height>0</height>
</size>
</property>
- <property name="toolTip" >
- <string>_("Enter the dictionary path (mandatory to start a
game)")</string>
+ <property name="toolTip">
+ <string>_("Enter the dictionary path (mandatory to start a
game)")</string>
</property>
</widget>
</item>
<item>
- <widget class="QPushButton" name="pushButtonIntfDicBrowse" >
- <property name="toolTip" >
- <string>_("Open a browser window to choose the dictionary")</string>
+ <widget class="QPushButton" name="pushButtonIntfDicBrowse">
+ <property name="toolTip">
+ <string>_("Open a browser window to choose the
dictionary")</string>
</property>
- <property name="text" >
- <string>_("Browse...")</string>
+ <property name="text">
+ <string>_("Browse...")</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
- <widget class="QCheckBox" name="checkBoxIntfShowPoints" >
- <property name="toolTip" >
- <string>_("Show/hide the tiles points on the board.")</string>
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <widget class="QLabel" name="label_5">
+ <property name="text">
+ <string>_("Definitions site:")</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="lineEditDefSite"/>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="checkBoxIntfShowPoints">
+ <property name="toolTip">
+ <string>_("Show/hide the tiles points on the
board.")</string>
</property>
- <property name="text" >
- <string>_("Display tiles points")</string>
+ <property name="text">
+ <string>_("Display tiles points")</string>
</property>
- <property name="checked" >
+ <property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
- <widget class="QCheckBox" name="checkBoxIntfAlignHistory" >
- <property name="toolTip" >
- <string>_("If checked, the game and player histories will display the
rack and the corresponding solution on the same line")</string>
+ <widget class="QCheckBox" name="checkBoxIntfAlignHistory">
+ <property name="toolTip">
+ <string>_("If checked, the game and player histories will
display the rack and the corresponding solution on the same line")</string>
</property>
- <property name="text" >
- <string>_("Align the rack and the solution in history")</string>
+ <property name="text">
+ <string>_("Align the rack and the solution in
history")</string>
</property>
- <property name="checked" >
+ <property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
- <widget class="QCheckBox" name="checkBoxIntfWarnReplayTurn" >
- <property name="toolTip" >
- <string>_("If checked, a confirmation will be requested before
replaying the game from a given turn. If unchecked, the action is performed
without confirmation.")</string>
+ <widget class="QCheckBox" name="checkBoxIntfWarnReplayTurn">
+ <property name="toolTip">
+ <string>_("If checked, a confirmation will be requested before
replaying the game from a given turn. If unchecked, the action is performed
without confirmation.")</string>
</property>
- <property name="text" >
- <string>_("Warn before replaying a turn")</string>
+ <property name="text">
+ <string>_("Warn before replaying a turn")</string>
</property>
- <property name="checked" >
+ <property name="checked">
<bool>true</bool>
</property>
</widget>
@@ -96,51 +111,51 @@
</widget>
</item>
<item>
- <widget class="QGroupBox" name="groupBoxDuplicate" >
- <property name="title" >
- <string>_("Duplicate mode")</string>
+ <widget class="QGroupBox" name="groupBoxDuplicate">
+ <property name="title">
+ <string>_("Duplicate mode")</string>
</property>
- <layout class="QGridLayout" name="gridLayout" >
- <item row="0" column="0" colspan="2" >
- <widget class="QCheckBox" name="checkBoxDuplRefuseInvalid" >
- <property name="toolTip" >
- <string>_("If checked, playing an invalid or misplaced word will not
be possible. If unchecked, you will get 0 point and lose your turn")</string>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0" colspan="2">
+ <widget class="QCheckBox" name="checkBoxDuplRefuseInvalid">
+ <property name="toolTip">
+ <string>_("If checked, playing an invalid or misplaced word will
not be possible. If unchecked, you will get 0 point and lose your
turn")</string>
</property>
- <property name="text" >
- <string>_("Refuse to play invalid moves")</string>
+ <property name="text">
+ <string>_("Refuse to play invalid moves")</string>
</property>
</widget>
</item>
- <item row="2" column="0" >
- <widget class="QLabel" name="label_2" >
- <property name="text" >
- <string>_("Min. players for a solo:")</string>
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>_("Min. players for a solo:")</string>
</property>
</widget>
</item>
- <item row="3" column="0" >
- <widget class="QLabel" name="label_3" >
- <property name="text" >
- <string>_("Solo value:")</string>
+ <item row="3" column="0">
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>_("Solo value:")</string>
</property>
</widget>
</item>
- <item row="3" column="1" >
- <widget class="QSpinBox" name="spinBoxDuplSoloValue" >
- <property name="toolTip" >
- <string>_("Value of the solo bonus. Set it to 0 if you don't want
solo bonus")</string>
+ <item row="3" column="1">
+ <widget class="QSpinBox" name="spinBoxDuplSoloValue">
+ <property name="toolTip">
+ <string>_("Value of the solo bonus. Set it to 0 if you don't
want solo bonus")</string>
</property>
- <property name="value" >
+ <property name="value">
<number>10</number>
</property>
</widget>
</item>
- <item row="2" column="2" >
- <spacer name="horizontalSpacer" >
- <property name="orientation" >
+ <item row="2" column="2">
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
- <property name="sizeHint" stdset="0" >
+ <property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
@@ -148,12 +163,12 @@
</property>
</spacer>
</item>
- <item row="2" column="1" >
- <widget class="QSpinBox" name="spinBoxDuplSoloPlayers" >
- <property name="toolTip" >
- <string>_("Minimum number of players needed to take into account the
solo bonus")</string>
+ <item row="2" column="1">
+ <widget class="QSpinBox" name="spinBoxDuplSoloPlayers">
+ <property name="toolTip">
+ <string>_("Minimum number of players needed to take into account
the solo bonus")</string>
</property>
- <property name="value" >
+ <property name="value">
<number>16</number>
</property>
</widget>
@@ -168,18 +183,18 @@
</widget>
</item>
<item>
- <widget class="QGroupBox" name="groupBoxFreeGame" >
- <property name="title" >
- <string>_("Free game mode")</string>
- </property>
- <layout class="QVBoxLayout" >
- <item>
- <widget class="QCheckBox" name="checkBoxFreeRefuseInvalid" >
- <property name="toolTip" >
- <string>_("If checked, playing an invalid or misplaced word will not
be possible. If unchecked, you will get 0 point and lose your turn")</string>
+ <widget class="QGroupBox" name="groupBoxFreeGame">
+ <property name="title">
+ <string>_("Free game mode")</string>
+ </property>
+ <layout class="QVBoxLayout">
+ <item>
+ <widget class="QCheckBox" name="checkBoxFreeRefuseInvalid">
+ <property name="toolTip">
+ <string>_("If checked, playing an invalid or misplaced word will
not be possible. If unchecked, you will get 0 point and lose your
turn")</string>
</property>
- <property name="text" >
- <string>_("Refuse to play invalid moves")</string>
+ <property name="text">
+ <string>_("Refuse to play invalid moves")</string>
</property>
</widget>
</item>
@@ -187,49 +202,49 @@
</widget>
</item>
<item>
- <widget class="QGroupBox" name="groupBoxTraining" >
- <property name="title" >
- <string>_("Training mode")</string>
+ <widget class="QGroupBox" name="groupBoxTraining">
+ <property name="title">
+ <string>_("Training mode")</string>
</property>
- <layout class="QVBoxLayout" name="verticalLayout" >
+ <layout class="QVBoxLayout" name="verticalLayout">
<item>
- <widget class="QCheckBox" name="checkBoxIntfLinkTraining7P1" >
- <property name="toolTip" >
- <string>_("If checked, any change to the player rack in training mode
will update the 'Plus 1' tab of the 'Dictionary tools' window")</string>
+ <widget class="QCheckBox" name="checkBoxIntfLinkTraining7P1">
+ <property name="toolTip">
+ <string>_("If checked, any change to the player rack in training
mode will update the 'Plus 1' tab of the 'Dictionary tools'
window")</string>
</property>
- <property name="text" >
- <string>_("Copy rack to the 'Plus 1' dictionary tool")</string>
+ <property name="text">
+ <string>_("Copy rack to the 'Plus 1' dictionary
tool")</string>
</property>
</widget>
</item>
<item>
- <layout class="QHBoxLayout" name="horizontalLayout" >
+ <layout class="QHBoxLayout" name="horizontalLayout">
<item>
- <widget class="QLabel" name="label" >
- <property name="text" >
- <string>_("Search results limit:")</string>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>_("Search results limit:")</string>
</property>
</widget>
</item>
<item>
- <widget class="QSpinBox" name="spinBoxTrainSearchLimit" >
- <property name="toolTip" >
- <string>_("Maximum number of results returned by a search. The
returned results will always be the best ones. Use 0 to disable the limit
(warning: searches yielding many results can be extremely slow in this
case!).")</string>
+ <widget class="QSpinBox" name="spinBoxTrainSearchLimit">
+ <property name="toolTip">
+ <string>_("Maximum number of results returned by a search. The
returned results will always be the best ones. Use 0 to disable the limit
(warning: searches yielding many results can be extremely slow in this
case!).")</string>
</property>
- <property name="maximum" >
+ <property name="maximum">
<number>100000</number>
</property>
- <property name="value" >
+ <property name="value">
<number>100</number>
</property>
</widget>
</item>
<item>
- <spacer name="horizontalSpacer_2" >
- <property name="orientation" >
+ <spacer name="horizontalSpacer_2">
+ <property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
- <property name="sizeHint" stdset="0" >
+ <property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
@@ -243,11 +258,11 @@
</widget>
</item>
<item>
- <widget class="QDialogButtonBox" name="buttonBox" >
- <property name="orientation" >
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
- <property name="standardButtons" >
+ <property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
@@ -257,6 +272,7 @@
<tabstops>
<tabstop>lineEditIntfDicPath</tabstop>
<tabstop>pushButtonIntfDicBrowse</tabstop>
+ <tabstop>lineEditDefSite</tabstop>
<tabstop>checkBoxIntfShowPoints</tabstop>
<tabstop>checkBoxIntfAlignHistory</tabstop>
<tabstop>checkBoxIntfWarnReplayTurn</tabstop>
@@ -265,6 +281,7 @@
<tabstop>spinBoxDuplSoloValue</tabstop>
<tabstop>checkBoxFreeRefuseInvalid</tabstop>
<tabstop>checkBoxIntfLinkTraining7P1</tabstop>
+ <tabstop>spinBoxTrainSearchLimit</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
@@ -275,11 +292,11 @@
<receiver>PrefsDialog</receiver>
<slot>accept()</slot>
<hints>
- <hint type="sourcelabel" >
+ <hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
- <hint type="destinationlabel" >
+ <hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
@@ -291,11 +308,11 @@
<receiver>PrefsDialog</receiver>
<slot>reject()</slot>
<hints>
- <hint type="sourcelabel" >
+ <hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
- <hint type="destinationlabel" >
+ <hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
Index: custom_popup.cpp
===================================================================
RCS file: custom_popup.cpp
diff -N custom_popup.cpp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ custom_popup.cpp 28 Jul 2011 20:55:48 -0000 1.1
@@ -0,0 +1,60 @@
+/*****************************************************************************
+ * Eliot
+ * Copyright (C) 2011 Olivier Teulière
+ * Authors: Olivier Teulière <ipkiss @@ gmail.com>
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *****************************************************************************/
+
+#include <QtGui/QMenu>
+
+#include "custom_popup.h"
+#include "qtcommon.h"
+
+
+CustomPopup::CustomPopup(QWidget *iWidget)
+ : QObject(iWidget), m_widget(iWidget)
+{
+ iWidget->setContextMenuPolicy(Qt::CustomContextMenu);
+ QObject::connect(iWidget, SIGNAL(customContextMenuRequested(const
QPoint&)),
+ this, SLOT(showPopup(const QPoint&)));
+}
+
+void CustomPopup::showPopup(const QPoint &iPoint)
+{
+ QMenu menu(m_widget);
+ emit popupCreated(menu, iPoint);
+ if (!menu.isEmpty())
+ menu.exec(m_widget->mapToGlobal(iPoint));
+}
+
+
+void CustomPopup::addShowDefinitionEntry(QMenu &iPopup, QString iWord)
+{
+ m_word = iWord;
+
+ QAction *definitionAction = new QAction(_q("Show definition"), this);
+ definitionAction->setStatusTip(_q("Show definition of the selected word in
an external browser"));
+ QObject::connect(definitionAction, SIGNAL(triggered()),
+ this, SLOT(definitionRequested()));
+
+ iPopup.addAction(definitionAction);
+}
+
+
+void CustomPopup::definitionRequested()
+{
+ emit requestDefinition(m_word);
+}
Index: custom_popup.h
===================================================================
RCS file: custom_popup.h
diff -N custom_popup.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ custom_popup.h 28 Jul 2011 20:55:49 -0000 1.1
@@ -0,0 +1,57 @@
+/*****************************************************************************
+ * Eliot
+ * Copyright (C) 2011 Olivier Teulière
+ * Authors: Olivier Teulière <ipkiss @@ gmail.com>
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *****************************************************************************/
+
+#ifndef CUSTOM_POPUP_H_
+#define CUSTOM_POPUP_H_
+
+#include <QtCore/QObject>
+#include <QtCore/QString>
+
+class QWidget;
+class QPoint;
+class QMenu;
+
+
+class CustomPopup: public QObject
+{
+ Q_OBJECT;
+
+public:
+ CustomPopup(QWidget *iWidget);
+ void addShowDefinitionEntry(QMenu &iPopup, QString iWord);
+
+signals:
+ void requestDefinition(QString iWord);
+ void popupCreated(QMenu &iPopup, const QPoint &iPoint);
+
+private slots:
+ void showPopup(const QPoint &iPoint);
+ void definitionRequested();
+
+private:
+ /// Widget triggering the custom popup menu
+ QWidget *m_widget;
+
+ /// Word to define
+ QString m_word;
+};
+
+#endif
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Eliot-dev] eliot/qt Makefile.am dic_tools_widget.cpp dic_t...,
Olivier Teulière <=