Commit 849aa2f1 authored by Julian Helfferich's avatar Julian Helfferich 💬
Browse files

Extract interface of KBlocksGraphics

I want to bring KBlocksItemGroup under test. To do this, it is
inconvenient to instantiate it with a KBlocksGraphics object. Instead,
I have extracted the interface and will create a MockGraphics class
which will fake the Graphics object.
parent 5dded49d
/******************************************************************************
* KBlocks, a falling blocks game by KDE *
* Copyright (C) 2010-2021 Julian Helfferich <julian.helfferich@mailbox.org> *
* *
* 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 the License, or *
* (at your option) any later version. *
******************************************************************************/
#ifndef GRAPHICSINTERFACE_H
#define GRAPHICSINTERFACE_H
class QSize;
class QString;
class QSvgRenderer;
class KGameTheme;
class GraphicsInterface
{
public:
GraphicsInterface() = default;
virtual ~GraphicsInterface() = default;
public:
virtual bool loadTheme(const QString &) = 0;
virtual void readThemeValues() = 0;
virtual void adjustForSize(const QSize &) = 0;
virtual KGameTheme *theme() const = 0;
virtual QSvgRenderer *renderer() const = 0;
int m_Block_Size;
int m_View_Size_Width;
int m_View_Size_Height;
int m_PlayArea_OffsetPoint_X;
int m_PlayArea_OffsetPoint_Y;
int m_PlayArea_NumberOfBlocks_X;
int m_PlayArea_NumberOfBlocks_Y;
int m_PreviewArea_CenterPoint_X;
int m_PreviewArea_CenterPoint_Y;
};
#endif // GRAPHICSINTERFACE_H
/***************************************************************************
* KBlocks, a falling blocks game by KDE *
* Copyright (C) 2010 Mauricio Piacentini <mauricio@tabuleiro.com> *
* Zhongjie Cai <squall.leonhart.cai@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 the License, or *
* (at your option) any later version. *
***************************************************************************/
/******************************************************************************
* KBlocks, a falling blocks game by KDE *
* Copyright (C) 2010-2020 Mauricio Piacentini <mauricio@tabuleiro.com> *
* Zhongjie Cai <squall.leonhart.cai@gmail.com> *
* Julian Helfferich <julian.helfferich@mailbox.org> *
* *
* 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 the License, or *
* (at your option) any later version. *
******************************************************************************/
#ifndef KBLOCKSGRAPHICS_H
#define KBLOCKSGRAPHICS_H
......@@ -18,35 +19,26 @@
#define USE_UNSTABLE_LIBKDEGAMESPRIVATE_API
#include <libkdegamesprivate/kgametheme.h>
class KBlocksGraphics
#include "GraphicsInterface.h"
class KBlocksGraphics : public GraphicsInterface
{
public:
explicit KBlocksGraphics(const QString &themeFile);
virtual ~KBlocksGraphics();
public:
bool loadTheme(const QString &themeFile);
void readThemeValues();
void adjustForSize(const QSize &newsize);
KGameTheme *theme() const
bool loadTheme(const QString &themeFile) override;
void readThemeValues() override;
void adjustForSize(const QSize &newsize) override;
KGameTheme *theme() const override
{
return m_theme;
}
QSvgRenderer *renderer() const
QSvgRenderer *renderer() const override
{
return m_renderer;
}
//QPixmap elementPixmap(int width, int height, const QString & elementid);
int m_Block_Size;
int m_View_Size_Width;
int m_View_Size_Height;
int m_PlayArea_OffsetPoint_X;
int m_PlayArea_OffsetPoint_Y;
int m_PlayArea_NumberOfBlocks_X;
int m_PlayArea_NumberOfBlocks_Y;
int m_PreviewArea_CenterPoint_X;
int m_PreviewArea_CenterPoint_Y;
private:
KGameTheme *m_theme = nullptr;
......
......@@ -8,9 +8,11 @@
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "GraphicsInterface.h"
#include "KBlocksItemGroup.h"
KBlocksItemGroup::KBlocksItemGroup(int groupID, SingleGameInterface *p, KBlocksGraphics *pG, KBlocksSound *pS, bool snapshotMode)
KBlocksItemGroup::KBlocksItemGroup(int groupID, SingleGameInterface *p, GraphicsInterface *pG, KBlocksSound *pS, bool snapshotMode)
{
mGroupID = groupID;
mpSingleGame = p;
......
......@@ -16,7 +16,6 @@
#include <QTimer>
#include <QList>
#include "KBlocksGraphics.h"
#include "KBlocksSound.h"
#include "KBlocksSvgItem.h"
#include "KBlocksAnimator.h"
......@@ -25,12 +24,14 @@
#include "KBlocksDefine.h"
class GraphicsInterface;
class KBlocksItemGroup : public QObject, public QGraphicsItemGroup
{
Q_OBJECT
public:
KBlocksItemGroup(int groupID, SingleGameInterface *p, KBlocksGraphics *pG, KBlocksSound *pS, bool snapshotMode = false);
KBlocksItemGroup(int groupID, SingleGameInterface *p, GraphicsInterface *pG, KBlocksSound *pS, bool snapshotMode = false);
~KBlocksItemGroup();
public:
......@@ -76,7 +77,7 @@ private:
SingleGameInterface *mpSingleGame;
KBlocksLayout *mpGameLayout = nullptr;
KBlocksGraphics *mpGrafx = nullptr;
GraphicsInterface *mpGrafx = nullptr;
KBlocksSound *mpSnd = nullptr;
QTimer mUpdateTimer;
......
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