HintsDialog: display the cost of each hint (optional)

This commit is contained in:
Olivier Teulière 2013-01-10 15:06:07 +01:00
parent 4f817bfa24
commit b6715c6c05
3 changed files with 21 additions and 8 deletions

View file

@ -49,12 +49,16 @@ struct CostComparator : public binary_function<const AbstractHint*, const Abstra
}; };
HintWidget::HintWidget(const AbstractHint &iHint, QWidget *parent) HintWidget::HintWidget(const AbstractHint &iHint,
bool iShowCosts, QWidget *parent)
: QWidget(parent), m_hint(iHint) : QWidget(parent), m_hint(iHint)
{ {
QHBoxLayout *layout = new QHBoxLayout(this); QHBoxLayout *layout = new QHBoxLayout(this);
QLabel *label = new QLabel(qfl(m_hint.getName())); QString labelText = qfl(m_hint.getName());
if (iShowCosts)
labelText += " (" + _q("cost: %1").arg(m_hint.getCost()) + ")";
QLabel *label = new QLabel(labelText);
label->setToolTip(qfl(m_hint.getDescription())); label->setToolTip(qfl(m_hint.getDescription()));
layout->addWidget(label); layout->addWidget(label);
@ -77,15 +81,21 @@ void HintWidget::buttonClicked()
HintsDialog::HintsDialog(QWidget *parent) HintsDialog::HintsDialog(QWidget *parent, bool iShowCosts)
: QDialog(parent), m_move(NULL) : QDialog(parent), m_move(NULL), m_showCosts(iShowCosts)
{ {
initializeHints(); initializeHints();
QVBoxLayout *vLayout = new QVBoxLayout(this); QVBoxLayout *vLayout = new QVBoxLayout(this);
if (m_showCosts)
{
QLabel *label = new QLabel(_q("Each hint has a corresponding cost, seen as a time penalty."));
label->setWordWrap(true);
vLayout->addWidget(label);
}
Q_FOREACH(const AbstractHint *hint, m_allHints) Q_FOREACH(const AbstractHint *hint, m_allHints)
{ {
HintWidget *hintWidget = new HintWidget(*hint); HintWidget *hintWidget = new HintWidget(*hint, m_showCosts);
QObject::connect(hintWidget, SIGNAL(hintRequested(const AbstractHint&)), QObject::connect(hintWidget, SIGNAL(hintRequested(const AbstractHint&)),
this, SLOT(showHint(const AbstractHint&))); this, SLOT(showHint(const AbstractHint&)));
vLayout->addWidget(hintWidget); vLayout->addWidget(hintWidget);

View file

@ -43,7 +43,9 @@ class HintWidget: public QWidget
DEFINE_LOGGER(); DEFINE_LOGGER();
public: public:
explicit HintWidget(const AbstractHint &iHint, QWidget *parent = 0); explicit HintWidget(const AbstractHint &iHint,
bool iShowCosts,
QWidget *parent = 0);
const AbstractHint & getHint() const { return m_hint; } const AbstractHint & getHint() const { return m_hint; }
@ -68,7 +70,7 @@ class HintsDialog: public QDialog
DEFINE_LOGGER(); DEFINE_LOGGER();
public: public:
explicit HintsDialog(QWidget *parent = 0); explicit HintsDialog(QWidget *parent = 0, bool iShowCosts = false);
~HintsDialog(); ~HintsDialog();
public slots: public slots:
@ -84,6 +86,7 @@ private slots:
private: private:
const Move *m_move; const Move *m_move;
vector<const AbstractHint *> m_allHints; vector<const AbstractHint *> m_allHints;
bool m_showCosts;
/// Initialize the m_allHints vector /// Initialize the m_allHints vector
void initializeHints(); void initializeHints();

View file

@ -48,7 +48,7 @@ ToppingWidget::ToppingWidget(QWidget *parent, PlayModel &iPlayModel, PublicGame
{ {
setupUi(this); setupUi(this);
m_hintsDialog = new HintsDialog(this); m_hintsDialog = new HintsDialog(this, true);
QObject::connect(m_hintsDialog, SIGNAL(hintUsed(const AbstractHint&)), QObject::connect(m_hintsDialog, SIGNAL(hintUsed(const AbstractHint&)),
this, SLOT(hintUsed(const AbstractHint&))); this, SLOT(hintUsed(const AbstractHint&)));