1 /*
2     SPDX-FileCopyrightText: 2008-2009 Stefan Majewsky <majewsky@gmx.net>
3 
4     SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "infobar.h"
8 #include "settings.h"
9 
10 #include <KLocalizedString>
11 #include <QStatusBar>
12 #include <QLabel>
13 
InfoBar(QStatusBar * bar)14 KDiamond::InfoBar::InfoBar(QStatusBar *bar)
15     : m_untimed(Settings::untimed())
16     , m_bar(bar)
17 {
18     mMovement = new QLabel(i18n("Possible moves: %1", 0));
19     mPoints = new QLabel(i18n("Points: %1", 0));
20     mTime = new QLabel;
21     if (m_untimed) {
22         mTime->setText(i18n("Untimed game"));
23     } else {
24         mTime->setText(i18n("Time left: %1", QLatin1String("0:00")));
25     }
26     m_bar->addPermanentWidget(mPoints);
27     m_bar->addPermanentWidget(mTime);
28     m_bar->addPermanentWidget(mMovement);
29     m_bar->show();
30 }
31 
setUntimed(bool untimed)32 void KDiamond::InfoBar::setUntimed(bool untimed)
33 {
34     if (untimed) {
35         mTime->setText(i18n("Untimed game"));
36     }
37     m_untimed = untimed;
38 }
39 
updatePoints(int points)40 void KDiamond::InfoBar::updatePoints(int points)
41 {
42     mPoints->setText(i18n("Points: %1", points));
43 }
44 
updateMoves(int moves)45 void KDiamond::InfoBar::updateMoves(int moves)
46 {
47     if (moves == -1) {
48         mMovement->setText(i18nc("Shown when the board is in motion.", "Possible moves: ..."));
49     } else {
50         mMovement->setText(i18n("Possible moves: %1", moves));
51     }
52 }
53 
updateRemainingTime(int remainingSeconds)54 void KDiamond::InfoBar::updateRemainingTime(int remainingSeconds)
55 {
56     if (m_untimed) {
57         return;
58     }
59     //split time in seconds and minutes
60     const int seconds = remainingSeconds % 60;
61     const int minutes = remainingSeconds / 60;
62     //compose new string
63     QString secondString = QString::number(seconds);
64     const QString minuteString = QString::number(minutes);
65     if (seconds < 10) {
66         secondString.prepend(QLatin1Char('0'));
67     }
68     mTime->setText(i18n("Time left: %1", QStringLiteral("%1:%2").arg(minuteString).arg(secondString)));
69     //special treatment if game is finished
70     if (remainingSeconds == 0) {
71         updateMoves(0);
72     }
73 }
74 
75