From 7e37cde0c027353a1d413724bd0e6b1db7835bea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Teuli=C3=A8re?= Date: Thu, 5 Apr 2012 22:46:03 +0200 Subject: [PATCH] Arbitration: after the end of turn, give the focus to the rack and select all the letters --- qt/arbit_assignments.cpp | 2 +- qt/arbit_assignments.h | 1 + qt/arbitration_widget.cpp | 25 +++++++++++++++++++++++++ qt/arbitration_widget.h | 1 + 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/qt/arbit_assignments.cpp b/qt/arbit_assignments.cpp index 3915ee0..4669894 100644 --- a/qt/arbit_assignments.cpp +++ b/qt/arbit_assignments.cpp @@ -630,6 +630,6 @@ void ArbitAssignments::endTurn() // FIXME: shouldn't be done here setEnabled(!m_game->isFinished()); - emit gameUpdated(); + emit endOfTurn(); } diff --git a/qt/arbit_assignments.h b/qt/arbit_assignments.h index db9f443..af4a1d1 100644 --- a/qt/arbit_assignments.h +++ b/qt/arbit_assignments.h @@ -59,6 +59,7 @@ signals: void gameUpdated(); void notifyProblem(QString iMsg); void notifyInfo(QString iMsg); + void endOfTurn(); public slots: void refresh(); diff --git a/qt/arbitration_widget.cpp b/qt/arbitration_widget.cpp index 5d7a32c..90ec101 100644 --- a/qt/arbitration_widget.cpp +++ b/qt/arbitration_widget.cpp @@ -66,6 +66,8 @@ ArbitrationWidget::ArbitrationWidget(QWidget *parent, this, SIGNAL(notifyProblem(QString))); QObject::connect(m_assignmentsWidget, SIGNAL(notifyInfo(QString)), this, SIGNAL(notifyInfo(QString))); + QObject::connect(m_assignmentsWidget, SIGNAL(endOfTurn()), + this, SLOT(endOfTurnRefresh())); m_keyAccum = new KeyAccumulator(this, 400); @@ -204,6 +206,11 @@ ArbitrationWidget::ArbitrationWidget(QWidget *parent, this, SIGNAL(requestDefinition(QString))); refresh(); + + // Give focus to the rack + // FIXME: for some reason, the focus gets lost later... + lineEditRack->setFocus(); + lineEditRack->selectAll(); } @@ -213,9 +220,16 @@ void ArbitrationWidget::refresh() // Update the rack only if needed, to avoid losing cursor position QString qrack = qfw(pldRack.toString(PlayedRack::RACK_SIMPLE)); if (qrack != lineEditRack->text()) { + // Save the selection status + bool isAllselected = lineEditRack->text() == lineEditRack->selectedText(); + // Must be done before updateResultsModel(), because it will // indirectly call the clearResults() slot lineEditRack->setText(qrack); + + // Restore the selection + if (isAllselected) + lineEditRack->selectAll(); } updateResultsModel(); @@ -592,6 +606,17 @@ void ArbitrationWidget::selectTableNumber(int key) } +void ArbitrationWidget::endOfTurnRefresh() +{ + // Refresh everything + emit gameUpdated(); + + // Give focus to the rack + lineEditRack->setFocus(); + lineEditRack->selectAll(); +} + + void ArbitrationWidget::updateSelectedMove() { bool hasSelection = treeViewResults->selectionModel()->hasSelection(); diff --git a/qt/arbitration_widget.h b/qt/arbitration_widget.h index 3f68254..3d3347a 100644 --- a/qt/arbitration_widget.h +++ b/qt/arbitration_widget.h @@ -72,6 +72,7 @@ private slots: void updateCoordModel(const QString&); void populateResultsMenu(QMenu &iMenu, const QPoint &iPoint); void selectTableNumber(int key); + void endOfTurnRefresh(); private: /// Encapsulated game, can be NULL