mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2024-12-25 21:59:30 +01:00
New dialog to display hints to the user. Not yet used.
This commit is contained in:
parent
3f19d6ae49
commit
0a7aa2ce8e
3 changed files with 240 additions and 0 deletions
|
@ -76,6 +76,7 @@ eliot_SOURCES = \
|
||||||
dic_tools_widget.cpp dic_tools_widget.h \
|
dic_tools_widget.cpp dic_tools_widget.h \
|
||||||
players_table_helper.cpp players_table_helper.h \
|
players_table_helper.cpp players_table_helper.h \
|
||||||
fav_players.cpp fav_players.h \
|
fav_players.cpp fav_players.h \
|
||||||
|
hints_dialog.cpp hints_dialog.h \
|
||||||
new_game.cpp new_game.h \
|
new_game.cpp new_game.h \
|
||||||
score_widget.cpp score_widget.h \
|
score_widget.cpp score_widget.h \
|
||||||
dic_wizard.cpp dic_wizard.h \
|
dic_wizard.cpp dic_wizard.h \
|
||||||
|
@ -117,6 +118,7 @@ nodist_eliot_SOURCES = \
|
||||||
custom_popup.moc.cpp \
|
custom_popup.moc.cpp \
|
||||||
players_table_helper.moc.cpp \
|
players_table_helper.moc.cpp \
|
||||||
fav_players.moc.cpp \
|
fav_players.moc.cpp \
|
||||||
|
hints_dialog.moc.cpp \
|
||||||
new_game.moc.cpp \
|
new_game.moc.cpp \
|
||||||
dic_tools_widget.moc.cpp \
|
dic_tools_widget.moc.cpp \
|
||||||
arbitration_widget.moc.cpp \
|
arbitration_widget.moc.cpp \
|
||||||
|
|
144
qt/hints_dialog.cpp
Normal file
144
qt/hints_dialog.cpp
Normal file
|
@ -0,0 +1,144 @@
|
||||||
|
/*****************************************************************************
|
||||||
|
* Eliot
|
||||||
|
* Copyright (C) 2013 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 <algorithm>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
#include <QtGui/QHBoxLayout>
|
||||||
|
#include <QtGui/QVBoxLayout>
|
||||||
|
#include <QtGui/QPushButton>
|
||||||
|
#include <QtGui/QLabel>
|
||||||
|
#include <QtGui/QDialogButtonBox>
|
||||||
|
#include <QtGui/QMessageBox>
|
||||||
|
|
||||||
|
#include "hints_dialog.h"
|
||||||
|
#include "qtcommon.h"
|
||||||
|
|
||||||
|
#include "hints.h"
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
INIT_LOGGER(qt, HintsDialog);
|
||||||
|
|
||||||
|
|
||||||
|
struct CostComparator : public binary_function<const AbstractHint*, const AbstractHint*, bool>
|
||||||
|
{
|
||||||
|
bool operator()(const AbstractHint *iHint1, const AbstractHint *iHint2) const
|
||||||
|
{
|
||||||
|
return iHint1->getCost() < iHint2->getCost();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
HintWidget::HintWidget(const AbstractHint &iHint, QWidget *parent)
|
||||||
|
: QWidget(parent), m_hint(iHint)
|
||||||
|
{
|
||||||
|
QHBoxLayout *layout = new QHBoxLayout(this);
|
||||||
|
|
||||||
|
QLabel *label = new QLabel(qfl(m_hint.getName()));
|
||||||
|
label->setToolTip(qfl(m_hint.getDescription()));
|
||||||
|
layout->addWidget(label);
|
||||||
|
|
||||||
|
layout->addStretch();
|
||||||
|
|
||||||
|
QPushButton *button = new QPushButton(_q("Show"));
|
||||||
|
button->setToolTip(qfl(m_hint.getDescription()));
|
||||||
|
QObject::connect(button, SIGNAL(clicked()),
|
||||||
|
this, SLOT(buttonClicked()));
|
||||||
|
layout->addWidget(button);
|
||||||
|
|
||||||
|
setContentsMargins(0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void HintWidget::buttonClicked()
|
||||||
|
{
|
||||||
|
emit hintRequested(m_hint);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
HintsDialog::HintsDialog(QWidget *parent)
|
||||||
|
: QDialog(parent), m_move(NULL)
|
||||||
|
{
|
||||||
|
initializeHints();
|
||||||
|
|
||||||
|
QVBoxLayout *vLayout = new QVBoxLayout(this);
|
||||||
|
Q_FOREACH(const AbstractHint *hint, m_allHints)
|
||||||
|
{
|
||||||
|
HintWidget *hintWidget = new HintWidget(*hint);
|
||||||
|
QObject::connect(hintWidget, SIGNAL(hintRequested(const AbstractHint&)),
|
||||||
|
this, SLOT(showHint(const AbstractHint&)));
|
||||||
|
vLayout->addWidget(hintWidget);
|
||||||
|
}
|
||||||
|
|
||||||
|
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel);
|
||||||
|
vLayout->addWidget(buttonBox);
|
||||||
|
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||||
|
|
||||||
|
setWindowTitle(_q("Hints"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
HintsDialog::~HintsDialog()
|
||||||
|
{
|
||||||
|
Q_FOREACH(const AbstractHint *hint, m_allHints)
|
||||||
|
{
|
||||||
|
delete hint;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void HintsDialog::initializeHints()
|
||||||
|
{
|
||||||
|
m_allHints.push_back(new ScoreHint);
|
||||||
|
m_allHints.push_back(new OrientationHint);
|
||||||
|
m_allHints.push_back(new PositionHint);
|
||||||
|
m_allHints.push_back(new LengthHint);
|
||||||
|
m_allHints.push_back(new BoardLettersHint);
|
||||||
|
m_allHints.push_back(new WordLettersHint);
|
||||||
|
m_allHints.push_back(new FirstLetterHint);
|
||||||
|
|
||||||
|
// Sort them by increasing cost
|
||||||
|
CostComparator costComp;
|
||||||
|
std::sort(m_allHints.begin(), m_allHints.end(), costComp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void HintsDialog::setMove(const Move &iMove)
|
||||||
|
{
|
||||||
|
m_move = &iMove;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void HintsDialog::showHint(const AbstractHint &iHint)
|
||||||
|
{
|
||||||
|
ASSERT(m_move != 0, "No move defined");
|
||||||
|
// Show the hint in a message box
|
||||||
|
const string & result = iHint.giveHint(*m_move);
|
||||||
|
QMessageBox::information(this, _q("Hint"), qfl(result));
|
||||||
|
|
||||||
|
// Notify of the hint usage (most likely to "pay" the cost of the hint)
|
||||||
|
emit hintUsed(iHint);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
94
qt/hints_dialog.h
Normal file
94
qt/hints_dialog.h
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
/*****************************************************************************
|
||||||
|
* Eliot
|
||||||
|
* Copyright (C) 2013 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 HINTS_DIALOG_H_
|
||||||
|
#define HINTS_DIALOG_H_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <QtGui/QDialog>
|
||||||
|
|
||||||
|
#include "logging.h"
|
||||||
|
|
||||||
|
|
||||||
|
using std::vector;
|
||||||
|
|
||||||
|
class AbstractHint;
|
||||||
|
class Move;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hint widget, used in the HintsDialog class
|
||||||
|
*/
|
||||||
|
class HintWidget: public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT;
|
||||||
|
DEFINE_LOGGER();
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit HintWidget(const AbstractHint &iHint, QWidget *parent = 0);
|
||||||
|
|
||||||
|
const AbstractHint & getHint() const { return m_hint; }
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void hintRequested(const AbstractHint &iHint);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void buttonClicked();
|
||||||
|
|
||||||
|
private:
|
||||||
|
const AbstractHint &m_hint;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hints dialog
|
||||||
|
*/
|
||||||
|
class HintsDialog: public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT;
|
||||||
|
DEFINE_LOGGER();
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit HintsDialog(QWidget *parent = 0);
|
||||||
|
~HintsDialog();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void setMove(const Move &iMove);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void hintUsed(const AbstractHint &iHint);
|
||||||
|
void notifyProblem(QString msg);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void showHint(const AbstractHint &iHint);
|
||||||
|
|
||||||
|
private:
|
||||||
|
const Move *m_move;
|
||||||
|
vector<const AbstractHint *> m_allHints;
|
||||||
|
|
||||||
|
/// Initialize the m_allHints vector
|
||||||
|
void initializeHints();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue