Commit d52e8e7b authored by Frederik Schwarzer's avatar Frederik Schwarzer

Use nullptr.

parent 9e7607db
......@@ -24,7 +24,7 @@ Block::Block(qreal p_x, qreal p_y, Arena* p_arena, const QString& p_imageId) : E
{
m_imageId = p_imageId;
m_type = Granatier::Element::BLOCK;
m_bonus = NULL;
m_bonus = nullptr;
}
Block::~Block()
......
......@@ -25,7 +25,7 @@
BlockItem::BlockItem(Block* p_model, KGameRenderer* renderer) : ElementItem (p_model, renderer)
{
setSpriteKey(p_model->getImageId());
m_destructionTimer = NULL;
m_destructionTimer = nullptr;
connect(p_model, SIGNAL(startDestructionAnimation()), this, SLOT(startDestructionAnimation()));
}
......@@ -54,7 +54,7 @@ void BlockItem::destructionAnimation()
{
m_destructionTimer->stop();
delete m_destructionTimer;
m_destructionTimer = 0;
m_destructionTimer = nullptr;
emit blockItemDestroyed(this);
}
}
......@@ -55,7 +55,7 @@ Bomb::Bomb(qreal fX, qreal fY, Arena* p_arena, int nBombID, int nDetonationCount
m_detonationCountdownTimer->start();
connect(m_detonationCountdownTimer, &QTimer::timeout, this, &Bomb::detonate);
m_mortarTimer = 0;
m_mortarTimer = nullptr;
m_mortarState = -1;
m_thrown = false;
m_stopOnCenter = false;
......@@ -474,7 +474,7 @@ void Bomb::detonate()
{
m_detonated = true;
delete m_detonationCountdownTimer;
m_detonationCountdownTimer = 0;
m_detonationCountdownTimer = nullptr;
emit bombDetonated(this);
emit releaseBombArmory();
}
......
......@@ -55,7 +55,7 @@ BombItem::BombItem(Bomb* p_model, KGameRenderer* renderer) : ElementItem (p_mode
m_pulseTimer->start();
connect(m_pulseTimer, &QTimer::timeout, this, &BombItem::pulse);
m_explosionTimer = NULL;
m_explosionTimer = nullptr;
m_listExplosionTiming.append(Settings::self()->blastTime1());
m_listExplosionTiming.append(Settings::self()->blastTime2());
m_listExplosionTiming.append(Settings::self()->blastTime3());
......@@ -127,7 +127,7 @@ void BombItem::startDetonation()
{
m_pulseTimer->stop();
delete m_pulseTimer;
m_pulseTimer = 0;
m_pulseTimer = nullptr;
}
m_animationCounter = 0;
QTransform transform;
......@@ -249,7 +249,7 @@ void BombItem::updateMortar(int nMortarState, int nMortarRampEnd, int nMortarPea
{
m_pulseTimer->stop();
delete m_pulseTimer;
m_pulseTimer = 0;
m_pulseTimer = nullptr;
}
if(nMortarState <= 0)
......
......@@ -26,7 +26,7 @@ BonusItem::BonusItem(Bonus* p_model, KGameRenderer* renderer) : ElementItem (p_m
{
setSpriteKey(p_model->getImageId());
m_undestroyableExplosionID = 0;
m_destructionTimer = NULL;
m_destructionTimer = nullptr;
m_destructionCounter = 0;
}
......@@ -65,7 +65,7 @@ void BonusItem::destructionAnimation()
{
m_destructionTimer->stop();
delete m_destructionTimer;
m_destructionTimer = 0;
m_destructionTimer = nullptr;
emit bonusItemDestroyed(this);
}
}
......@@ -39,8 +39,8 @@ bool Cell::isWalkable(Element* p_element) const
foreach(Element* element, m_elements)
{
if(element->getType() == Granatier::Element::BLOCK ||
(element->getType() == Granatier::Element::BOMB && (p_element == 0 || p_element != element)) ||
(element->getType() == Granatier::Element::PLAYER && (p_element == 0 || p_element->getType() != Granatier::Element::PLAYER)))
(element->getType() == Granatier::Element::BOMB && (p_element == nullptr || p_element != element)) ||
(element->getType() == Granatier::Element::PLAYER && (p_element == nullptr || p_element->getType() != Granatier::Element::PLAYER)))
{
return false;
}
......
This diff is collapsed.
......@@ -46,7 +46,7 @@
class PlayerSelectorDelegate : public QStyledItemDelegate
{
public:
PlayerSelectorDelegate(QObject* parent = 0);
PlayerSelectorDelegate(QObject* parent = nullptr);
virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
///@note The implementation is independent of @a option and @a index.
virtual QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
......@@ -64,7 +64,7 @@ struct PlayerSelector::Private
void fillList();
Private(PlayerSettings* playerSettings, Options options, PlayerSelector* q) : q(q), m_playerSettings(playerSettings), m_options(options), m_knsButton(0) {}
Private(PlayerSettings* playerSettings, Options options, PlayerSelector* q) : q(q), m_playerSettings(playerSettings), m_options(options), m_knsButton(nullptr) {}
void _k_showNewStuffDialog();
};
......@@ -105,35 +105,35 @@ PlayerSelector::~PlayerSelector()
void PlayerSelector::Private::fillList()
{
m_list->clear();
QModelIndex modelIndex;
PlayerSelectorItem* playerSelectorItem;
QSvgRenderer renderer;
QPixmap pixmap(QSize(64, 64));
pixmap.fill(QColor(0, 0, 0, 0));
QPainter pixPainter(&pixmap);
QStringList playerIDs = m_playerSettings->playerIDs();
for(int i = 0; i < playerIDs.count(); i++)
{
QListWidgetItem* item = new QListWidgetItem(playerIDs[i], m_list);
item->setFlags(item->flags() & ~Qt::ItemIsSelectable);
playerSelectorItem = new PlayerSelectorItem(playerIDs[i], m_playerSettings, m_list);
renderer.load(QStandardPaths::locate(QStandardPaths::DataLocation, QStringLiteral("players/%1").arg(m_playerSettings->playerGraphicsFile(playerIDs[i]))));
renderer.render(&pixPainter, QStringLiteral("player_0"));
playerSelectorItem->setPlayerPreviewPixmap(pixmap);
KConfig desktopFile(QStandardPaths::locate(QStandardPaths::DataLocation, QStringLiteral("players/%1").arg(playerIDs[i])), KConfig::SimpleConfig);
QString author = desktopFile.group("KGameTheme").readEntry<QString>("Author", QStringLiteral(""));
QString authorEmail = QStringLiteral("<a href=\"mailto:%1\">%1</a>").arg(desktopFile.group("KGameTheme").readEntry<QString>("AuthorEmail", QStringLiteral("")));
//TODO: QString description = desktopFile.group("KGameTheme").readEntry<QString>("Description", "");
playerSelectorItem->setPlayerAuthor(author, authorEmail);
modelIndex = m_list->model()->index(i, 0, m_list->rootIndex());
m_list->setIndexWidget(modelIndex, playerSelectorItem);
}
......@@ -167,7 +167,7 @@ PlayerSelectorDelegate::PlayerSelectorDelegate(QObject* parent)
void PlayerSelectorDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& /*index*/) const
{
//draw background
QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter, 0);
QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter, nullptr);
}
QSize PlayerSelectorDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
......
......@@ -51,9 +51,9 @@ Game::Game(PlayerSettings* playerSettings)
m_soundFalling = new KgSound(QStandardPaths::locate(QStandardPaths::DataLocation, QStringLiteral("sounds/deepfall.wav")));
m_soundDie = new KgSound(QStandardPaths::locate(QStandardPaths::DataLocation, QStringLiteral("sounds/die.wav")));
m_arena = 0;
m_arena = nullptr;
m_randomArenaModeArenaList.clear();
m_gameScene = 0;
m_gameScene = nullptr;
m_winPoints = Settings::self()->pointsToWin();
QStringList strPlayerIDs = m_playerSettings->playerIDs();
......@@ -236,13 +236,13 @@ void Game::cleanUp()
qDeleteAll(m_bombs);
m_bombs.clear();
delete m_arena;
m_arena = 0;
m_arena = nullptr;
delete m_timer;
m_timer = 0;
m_timer = nullptr;
delete m_roundTimer;
m_roundTimer = 0;
m_roundTimer = nullptr;
delete m_setRoundFinishedTimer;
m_setRoundFinishedTimer = 0;
m_setRoundFinishedTimer = nullptr;
}
void Game::setGameScene(GameScene* p_gameScene)
......@@ -582,7 +582,7 @@ void Game::decrementRemainingRoundTime()
nRow = m_arena->getNbRows() * (qrand()/1.0)/RAND_MAX;
nCol = m_arena->getNbColumns() * (qrand()/1.0)/RAND_MAX;
cellType = m_arena->getCell(nRow, nCol).getType();
if(cellType != Granatier::Cell::WALL && cellType != Granatier::Cell::HOLE && m_arena->getCell(nRow, nCol).isWalkable(0))
if(cellType != Granatier::Cell::WALL && cellType != Granatier::Cell::HOLE && m_arena->getCell(nRow, nCol).isWalkable(nullptr))
{
bFound = true;
}
......
......@@ -98,7 +98,7 @@ GameScene::GameScene(Game* p_game, KgThemeProvider* p_themeProvider) : m_game(p_
// setup the theme renderer
m_rendererSelectedTheme = new KGameRenderer(m_themeProvider);
m_rendererDefaultTheme = 0;
m_rendererDefaultTheme = nullptr;
setupThemeRenderer();
connect(m_themeProvider, &KgThemeProvider::currentThemeChanged, this, &GameScene::themeChanged);
......@@ -118,7 +118,7 @@ void GameScene::setupThemeRenderer()
{
// Load the default SVG file as fallback
selectedThemeIsDefault = false;
if(m_rendererDefaultTheme == 0)
if(m_rendererDefaultTheme == nullptr)
{
KgTheme* theme = new KgTheme(m_themeProvider->defaultTheme()->identifier());
theme->setGraphicsPath(m_themeProvider->defaultTheme()->graphicsPath());
......@@ -293,7 +293,7 @@ void GameScene::initItemsWithGraphicsFromTheme()
break;
case Granatier::Cell::HOLE:
delete arenaItem;
arenaItem = NULL;
arenaItem = nullptr;
break;
case Granatier::Cell::ICE:
arenaItem->setSpriteKey(QStringLiteral("arena_ice"));
......@@ -425,14 +425,14 @@ void GameScene::initItemsWithGraphicsFromTheme()
}
else
{
m_bonusItems[i][j] = NULL;
m_bonusItems[i][j] = nullptr;
}
}
}
else
{
m_blockItems[i][j] = NULL;
m_bonusItems[i][j] = NULL;
m_blockItems[i][j] = nullptr;
m_bonusItems[i][j] = nullptr;
}
}
}
......@@ -457,7 +457,7 @@ void GameScene::initItemsWithGraphicsFromTheme()
{
for (int j = 0; j < m_game->getArena()->getNbColumns(); ++j)
{
if(m_arenaItem[i][j] != NULL)
if(m_arenaItem[i][j] != nullptr)
{
addItem(m_arenaItem[i][j]);
}
......@@ -469,7 +469,7 @@ void GameScene::initItemsWithGraphicsFromTheme()
{
for (int j = 0; j < m_game->getArena()->getNbColumns(); ++j)
{
if (m_blockItems[i][j] != NULL)
if (m_blockItems[i][j] != nullptr)
{
if (!items().contains(m_blockItems[i][j]))
{
......@@ -543,7 +543,7 @@ void GameScene::cleanUpItemsWithGraphicsFromTheme()
{
for (int j = 0; j < m_game->getArena()->getNbColumns(); ++j)
{
if (m_arenaItem[i][j] != NULL)
if (m_arenaItem[i][j] != nullptr)
{
if (items().contains(m_arenaItem[i][j]))
{
......@@ -587,7 +587,7 @@ void GameScene::cleanUpItemsWithGraphicsFromTheme()
{
for (int j = 0; j < m_game->getArena()->getNbColumns(); ++j)
{
if (m_blockItems[i][j] != NULL)
if (m_blockItems[i][j] != nullptr)
{
if (items().contains(m_blockItems[i][j]))
{
......@@ -595,7 +595,7 @@ void GameScene::cleanUpItemsWithGraphicsFromTheme()
}
delete m_blockItems[i][j];
}
if (m_bonusItems[i][j] != NULL)
if (m_bonusItems[i][j] != nullptr)
{
if (items().contains(m_bonusItems[i][j]))
{
......@@ -651,7 +651,7 @@ KGameRenderer* GameScene::renderer(Granatier::Element::Type type, Player* player
case Granatier::Element::SCORE:
return m_rendererScoreItems;
default:
return NULL;
return nullptr;
}
}
......@@ -773,12 +773,12 @@ void GameScene::removeBlockItem(BlockItem* blockItem)
{
for (int j = 0; j < m_game->getArena()->getNbColumns(); ++j)
{
if (m_blockItems[i][j] != NULL && m_blockItems[i][j] == blockItem)
if (m_blockItems[i][j] != nullptr && m_blockItems[i][j] == blockItem)
{
if (items().contains(m_blockItems[i][j]))
{
removeItem(m_blockItems[i][j]);
m_blockItems[i][j] = NULL;
m_blockItems[i][j] = nullptr;
m_game->blockDestroyed(i, j, dynamic_cast <Block*> (blockItem->getModel()));
delete blockItem;
}
......@@ -794,12 +794,12 @@ void GameScene::removeBonusItem(BonusItem* bonusItem)
{
for (int j = 0; j < m_game->getArena()->getNbColumns(); ++j)
{
if (m_bonusItems[i][j] != NULL && m_bonusItems[i][j] == bonusItem)
if (m_bonusItems[i][j] != nullptr && m_bonusItems[i][j] == bonusItem)
{
if (items().contains(m_bonusItems[i][j]))
{
removeItem(m_bonusItems[i][j]);
m_bonusItems[i][j] = NULL;
m_bonusItems[i][j] = nullptr;
m_game->removeBonus(dynamic_cast <Bonus*> (bonusItem->getModel()));
delete bonusItem;
}
......@@ -833,7 +833,7 @@ void GameScene::createBombItem(Bomb* bomb)
// Corrects the position of the BombItem
bombItem->update(bomb->getX(), bomb->getY());
addItem(bombItem);
m_bombItems[bombItem].append(NULL);
m_bombItems[bombItem].append(nullptr);
bombItem->updateGraphics(m_SvgScaleFactor); //TODO: use a Renderer class and get the scale factor from a static function during initialization
......@@ -880,8 +880,8 @@ void GameScene::removeBombItem(BombItem* bombItem)
void GameScene::bombDetonated(Bomb* bomb)
{
BombItem* bombItem = NULL;
BombExplosionItem* bombExplosionItem = NULL;
BombItem* bombItem = nullptr;
BombExplosionItem* bombExplosionItem = nullptr;
QList<Element*> blockElements;
QList<Element*> bombElements;
int nBombPower = bomb->bombPower();
......@@ -934,10 +934,10 @@ void GameScene::bombDetonated(Bomb* bomb)
foreach(Element* element, blockElements)
{
dynamic_cast <Block*> (element)->startDestruction();
if (m_blockItems[nRow][nColumn] != NULL)
if (m_blockItems[nRow][nColumn] != nullptr)
{
//display bonus if available
if (m_bonusItems[nRow][nColumn] != NULL)
if (m_bonusItems[nRow][nColumn] != nullptr)
{
m_bonusItems[nRow][nColumn]->setUndestroyable(bomb->explosionID());
m_bonusItems[nRow][nColumn]->show();
......@@ -945,7 +945,7 @@ void GameScene::bombDetonated(Bomb* bomb)
}
}
}
else if(m_bonusItems[nRow][nColumn] != NULL)
else if(m_bonusItems[nRow][nColumn] != nullptr)
{
m_bonusItems[nRow][nColumn]->initDestruction(bomb->explosionID());
}
......@@ -1006,10 +1006,10 @@ void GameScene::bombDetonated(Bomb* bomb)
foreach(Element* element, blockElements)
{
dynamic_cast <Block*> (element)->startDestruction();
if (m_blockItems[nRow][nColumn] != NULL)
if (m_blockItems[nRow][nColumn] != nullptr)
{
//display bonus if available
if (m_bonusItems[nRow][nColumn] != NULL)
if (m_bonusItems[nRow][nColumn] != nullptr)
{
m_bonusItems[nRow][nColumn]->setUndestroyable(bomb->explosionID());
m_bonusItems[nRow][nColumn]->show();
......@@ -1017,7 +1017,7 @@ void GameScene::bombDetonated(Bomb* bomb)
}
}
}
else if(m_bonusItems[nRow][nColumn] != NULL)
else if(m_bonusItems[nRow][nColumn] != nullptr)
{
m_bonusItems[nRow][nColumn]->initDestruction(bomb->explosionID());
}
......
......@@ -79,16 +79,16 @@ InfoSidebar::InfoSidebar (Game* p_game, GameScene* p_scene) : QObject()
QBrush dimmRectBrush(QColor(0,0,0,200));
playerInfo = new PlayerInfo;
playerInfo->name = 0;
playerInfo->icon = 0;
playerInfo->bonusShield = 0;
playerInfo->bonusShieldDimm = 0;
playerInfo->bonusThrow = 0;
playerInfo->bonusThrowDimm = 0;
playerInfo->bonusKick = 0;
playerInfo->bonusKickDimm = 0;
playerInfo->badBonus = 0;
playerInfo->badBonusDimm = 0;
playerInfo->name = nullptr;
playerInfo->icon = nullptr;
playerInfo->bonusShield = nullptr;
playerInfo->bonusShieldDimm = nullptr;
playerInfo->bonusThrow = nullptr;
playerInfo->bonusThrowDimm = nullptr;
playerInfo->bonusKick = nullptr;
playerInfo->bonusKickDimm = nullptr;
playerInfo->badBonus = nullptr;
playerInfo->badBonusDimm = nullptr;
//create the player icons
renderer = m_gameScene->renderer(Granatier::Element::PLAYER, playerList[i]);
......@@ -258,8 +258,8 @@ InfoSidebar::~InfoSidebar()
}
delete m_background;
m_gameScene = 0;
m_game = 0;
m_gameScene = nullptr;
m_game = nullptr;
}
void InfoSidebar::reset()
......
......@@ -2,17 +2,17 @@
* Copyright 2008 Mathias Kraus <k.hias@gmx.de>
* Copyright 2007-2008 Thomas Gallinari <tg8187@yahoo.fr>
* Copyright 2007-2008 Pierre-Benoit Bessse <besse@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
* 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, see <http://www.gnu.org/licenses/>.
*/
......@@ -55,12 +55,12 @@ MainWindow::MainWindow()
{
// initialize random generator
qsrand(QDateTime::currentDateTime().toTime_t());
m_settingsDialog = NULL;
m_settingsDialog = nullptr;
// Initialize the game
m_game = NULL;
m_view = NULL;
m_scene = NULL;
m_game = nullptr;
m_view = nullptr;
m_scene = nullptr;
m_playerSettings = new PlayerSettings();
m_themeProvider = new KgThemeProvider(QByteArray("Theme"), this);
m_themeProvider->discoverThemes(QByteArray("appdata"), QStringLiteral("themes"), QStringLiteral("granatier"));
......@@ -94,21 +94,21 @@ void MainWindow::initGame()
//TODO: check why setting the focus only at the end doesn't work
this->setFocusProxy(m_view);
this->setFocus();
// If a GameView instance already exists
if (m_view)
{
// Delete the GameView instance
delete m_view;
}
// If a GameScene instance already exists
if (m_scene)
{
// Delete the GameScene instance
delete m_scene;
}
// If a Game instance already exists
if (m_game)
{
......@@ -118,15 +118,15 @@ void MainWindow::initGame()
// Create a new Game instance
m_game = new Game(m_playerSettings);
connect(m_game, &Game::gameOver, this, &MainWindow::newGame);
m_scene = new GameScene(m_game, m_themeProvider);
// Create a new GameView instance
m_view = new GameView(m_scene, m_game);
m_view->setBackgroundBrush(Qt::black);
setCentralWidget(m_view);
m_game->setGameScene(dynamic_cast <GameScene*> (m_view->scene()));
this->setFocusProxy(m_view);
this->setFocus();
}
......@@ -134,7 +134,7 @@ void MainWindow::initGame()
void MainWindow::newGame()
{
bool gameRunning; // True if the game is running (game timer is active), false otherwise
gameRunning = m_game->getTimer()->isActive();
// If the game is running
if (gameRunning)
......@@ -189,9 +189,9 @@ void MainWindow::showSettings()
settingsDialog->addPage(new ArenaSelector(settingsDialog, Settings::self(), &m_tempRandomArenaModeArenaList, ArenaSelector::DefaultBehavior), i18n("Arena"), QStringLiteral("games-config-board"));
// Player
settingsDialog->addPage(new PlayerSelector(m_playerSettings, PlayerSelector::DefaultBehavior, settingsDialog), i18n("Player"), QStringLiteral("games-config-custom"));
m_settingsDialog = settingsDialog;
connect(settingsDialog, &KConfigDialog::settingsChanged, this, &MainWindow::applyNewSettings);
connect(settingsDialog->button(QDialogButtonBox::Cancel), &QPushButton::clicked, this, &MainWindow::settingsDialogCanceled);
settingsDialog->show();
......@@ -229,7 +229,7 @@ void MainWindow::settingsDialogCanceled()
void MainWindow::close()
{
bool gameRunning; // True if the game is running (game timer is active), false otherwise
gameRunning = m_game->getTimer()->isActive();
// If the game is running
if (gameRunning)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment