File indexing completed on 2024-04-21 04:02:13
0001 /* 0002 SPDX-FileCopyrightText: 2008-2009 Stefan Majewsky <majewsky@gmx.net> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "infobar.h" 0008 #include "settings.h" 0009 0010 #include <KLocalizedString> 0011 #include <QStatusBar> 0012 #include <QLabel> 0013 0014 KDiamond::InfoBar::InfoBar(QStatusBar *bar) 0015 : m_untimed(Settings::untimed()) 0016 , m_bar(bar) 0017 { 0018 mMovement = new QLabel(i18n("Possible moves: %1", 0)); 0019 mPoints = new QLabel(i18n("Points: %1", 0)); 0020 mTime = new QLabel; 0021 if (m_untimed) { 0022 mTime->setText(i18n("Untimed game")); 0023 } else { 0024 mTime->setText(i18n("Time left: %1", QLatin1String("0:00"))); 0025 } 0026 m_bar->addPermanentWidget(mPoints); 0027 m_bar->addPermanentWidget(mTime); 0028 m_bar->addPermanentWidget(mMovement); 0029 m_bar->show(); 0030 } 0031 0032 void KDiamond::InfoBar::setUntimed(bool untimed) 0033 { 0034 if (untimed) { 0035 mTime->setText(i18n("Untimed game")); 0036 } 0037 m_untimed = untimed; 0038 } 0039 0040 void KDiamond::InfoBar::updatePoints(int points) 0041 { 0042 mPoints->setText(i18n("Points: %1", points)); 0043 } 0044 0045 void KDiamond::InfoBar::updateMoves(int moves) 0046 { 0047 if (moves == -1) { 0048 mMovement->setText(i18nc("Shown when the board is in motion.", "Possible moves: ...")); 0049 } else { 0050 mMovement->setText(i18n("Possible moves: %1", moves)); 0051 } 0052 } 0053 0054 void KDiamond::InfoBar::updateRemainingTime(int remainingSeconds) 0055 { 0056 if (m_untimed) { 0057 return; 0058 } 0059 //split time in seconds and minutes 0060 const int seconds = remainingSeconds % 60; 0061 const int minutes = remainingSeconds / 60; 0062 //compose new string 0063 QString secondString = QString::number(seconds); 0064 const QString minuteString = QString::number(minutes); 0065 if (seconds < 10) { 0066 secondString.prepend(QLatin1Char('0')); 0067 } 0068 mTime->setText(i18n("Time left: %1", QStringLiteral("%1:%2").arg(minuteString).arg(secondString))); 0069 //special treatment if game is finished 0070 if (remainingSeconds == 0) { 0071 updateMoves(0); 0072 } 0073 } 0074 0075 #include "moc_infobar.cpp"