Commit 2d6f98c5 authored by Julian Helfferich's avatar Julian Helfferich 💬
Browse files

Create SvgItemInterface

To be able to test the next step in the bugfix, I need to verify the
actions taken on a KBlocksSvgItem object. Thus, I want to replace it
with a mock object. To make this possible, I have created a
SvgItemInterface class and replaced all necessary KBlocksSvgItem
pointers with SvgItemInterface pointers.
parent 17b25472
/***************************************************************************
* KBlocks, a falling blocks game by KDE *
* Copyright (C) 2009 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) 2009-2021 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. *
******************************************************************************/
#include "KBlocksAnimDrop.h"
KBlocksAnimDrop::KBlocksAnimDrop(const QList<KBlocksSvgItem *> &items, int duration, QTimeLine::Direction direction)
#include "SvgItemInterface.h"
KBlocksAnimDrop::KBlocksAnimDrop(const QList<SvgItemInterface *> &items, int duration, QTimeLine::Direction direction)
{
mItemList = items;
......@@ -32,7 +35,7 @@ KBlocksAnimDrop::~KBlocksAnimDrop()
void KBlocksAnimDrop::valueChanged(qreal value)
{
Q_UNUSED(value);
for (KBlocksSvgItem *pItem : qAsConst(mItemList)) {
for (SvgItemInterface *pItem : qAsConst(mItemList)) {
pItem->execPosAnim(value);
}
}
......
/***************************************************************************
* KBlocks, a falling blocks game by KDE *
* Copyright (C) 2009 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) 2009-2021 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 KBLOCKSANIMDROP_H
#define KBLOCKSANIMDROP_H
#include <QTimeLine>
#include "KBlocksSvgItem.h"
class SvgItemInterface;
class KBlocksAnimDrop : public QObject
{
Q_OBJECT
public:
KBlocksAnimDrop(const QList<KBlocksSvgItem *> &items, int duration, QTimeLine::Direction direction);
KBlocksAnimDrop(const QList<SvgItemInterface *> &items, int duration, QTimeLine::Direction direction);
~KBlocksAnimDrop();
signals:
......@@ -32,7 +33,7 @@ private slots:
private:
QTimeLine *mpTimeLine;
QList<KBlocksSvgItem *> mItemList;
QList<SvgItemInterface *> mItemList;
};
#endif
/***************************************************************************
* KBlocks, a falling blocks game by KDE *
* Copyright (C) 2009 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) 2009-2021 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. *
******************************************************************************/
#include "KBlocksAnimFade.h"
KBlocksAnimFade::KBlocksAnimFade(const QList<KBlocksSvgItem *> &items, int duration, QTimeLine::Direction direction)
#include "SvgItemInterface.h"
KBlocksAnimFade::KBlocksAnimFade(const QList<SvgItemInterface *> &items, int duration, QTimeLine::Direction direction)
{
mItemList = items;
......@@ -31,7 +34,7 @@ KBlocksAnimFade::~KBlocksAnimFade()
void KBlocksAnimFade::valueChanged(qreal value)
{
for (KBlocksSvgItem *pItem : qAsConst(mItemList)) {
for (SvgItemInterface *pItem : qAsConst(mItemList)) {
pItem->setOpacity(value);
}
}
......
/***************************************************************************
* KBlocks, a falling blocks game by KDE *
* Copyright (C) 2009 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) 2009-2021 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 KBLOCKSANIMFADE_H
#define KBLOCKSANIMFADE_H
#include <QTimeLine>
#include "KBlocksSvgItem.h"
class SvgItemInterface;
class KBlocksAnimFade : public QObject
{
Q_OBJECT
public:
KBlocksAnimFade(const QList<KBlocksSvgItem *> &items, int duration, QTimeLine::Direction direction);
KBlocksAnimFade(const QList<SvgItemInterface *> &items, int duration, QTimeLine::Direction direction);
~KBlocksAnimFade();
signals:
......@@ -32,7 +33,7 @@ private slots:
private:
QTimeLine *mpTimeLine;
QList<KBlocksSvgItem *> mItemList;
QList<SvgItemInterface *> mItemList;
};
#endif
/***************************************************************************
* KBlocks, a falling blocks game by KDE *
* Copyright (C) 2009 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) 2009-2021 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. *
******************************************************************************/
#include "KBlocksAnimator.h"
#include "SvgItemInterface.h"
KBlocksAnimator::KBlocksAnimator()
{
}
......@@ -26,7 +29,7 @@ KBlocksAnimator::~KBlocksAnimator()
}
}
bool KBlocksAnimator::createFadeAnim(const QList<KBlocksSvgItem *> &items, int duration, QTimeLine::Direction direction)
bool KBlocksAnimator::createFadeAnim(const QList<SvgItemInterface *> &items, int duration, QTimeLine::Direction direction)
{
if (mpAnimFade) {
return false;
......@@ -58,7 +61,7 @@ KBlocksAnimFade *KBlocksAnimator::getFadeAnim()
return mpAnimFade;
}
bool KBlocksAnimator::createDropAnim(const QList<KBlocksSvgItem *> &items, int duration, QTimeLine::Direction direction)
bool KBlocksAnimator::createDropAnim(const QList<SvgItemInterface *> &items, int duration, QTimeLine::Direction direction)
{
if (mpAnimDrop) {
return false;
......
/***************************************************************************
* KBlocks, a falling blocks game by KDE *
* Copyright (C) 2009 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) 2009-2021 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 KBLOCKSANIMATOR_H
#define KBLOCKSANIMATOR_H
......@@ -16,7 +17,7 @@
#include "KBlocksAnimFade.h"
#include "KBlocksAnimDrop.h"
#include "KBlocksSvgItem.h"
class SvgItemInterface;
enum KBlocks_Animation_Type {
KBlocks_Animation_None = 0,
......@@ -34,11 +35,11 @@ public:
KBlocksAnimator();
~KBlocksAnimator();
bool createFadeAnim(const QList<KBlocksSvgItem *> &items, int duration, QTimeLine::Direction direction);
bool createFadeAnim(const QList<SvgItemInterface *> &items, int duration, QTimeLine::Direction direction);
bool deleteFadeAnim();
KBlocksAnimFade *getFadeAnim();
bool createDropAnim(const QList<KBlocksSvgItem *> &items, int duration, QTimeLine::Direction direction);
bool createDropAnim(const QList<SvgItemInterface *> &items, int duration, QTimeLine::Direction direction);
bool deleteDropAnim();
KBlocksAnimDrop *getDropAnim();
......
......@@ -13,6 +13,8 @@
#include "SoundInterface.h"
#include "KBlocksItemGroup.h"
#include "KBlocksSvgItem.h"
#include "SvgItemInterface.h"
KBlocksItemGroup::KBlocksItemGroup(int groupID, SingleGameInterface *p, GraphicsInterface *pG, SoundInterface *pS, bool snapshotMode)
{
......@@ -42,7 +44,7 @@ KBlocksItemGroup::KBlocksItemGroup(int groupID, SingleGameInterface *p, Graphics
}
mMaxFreezeCellNum = (mFieldWidth * mFieldHeight);
maFreezeCells = new KBlocksSvgItem*[mMaxFreezeCellNum];
maFreezeCells = new SvgItemInterface*[mMaxFreezeCellNum];
for (int i = 0; i < mMaxFreezeCellNum; i++) {
maFreezeCells[i] = new KBlocksSvgItem(mpGameLayout, KBlocksSvgItem_FieldArea,
i % mFieldWidth, i / mFieldWidth);
......@@ -310,11 +312,11 @@ void KBlocksItemGroup::fadeInNewPiece()
for (int i = 0; i < mMaxFreezeCellNum; i++) {
maFreezeCells[i]->updateSelf();
}
for (KBlocksSvgItem *tmpItem : qAsConst(mFadeOutItems)) {
for (SvgItemInterface *tmpItem : qAsConst(mFadeOutItems)) {
tmpItem->setOpacity(1);
tmpItem->stopOpAnim();
}
for (KBlocksSvgItem *tmpItem : qAsConst(mDropItems)) {
for (SvgItemInterface *tmpItem : qAsConst(mDropItems)) {
tmpItem->stopPosAnim();
}
......
/***************************************************************************
* 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-2021 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 KBLOCKSITEMGROUP_H
#define KBLOCKSITEMGROUP_H
......@@ -16,7 +17,6 @@
#include <QTimer>
#include <QList>
#include "KBlocksSvgItem.h"
#include "KBlocksAnimator.h"
#include "SingleGameInterface.h"
......@@ -24,7 +24,10 @@
#include "KBlocksDefine.h"
class GraphicsInterface;
class KBlocksLayout;
class KBlocksSvgItem;
class SoundInterface;
class SvgItemInterface;
class KBlocksItemGroup : public QObject, public QGraphicsItemGroup
{
......@@ -67,13 +70,15 @@ private:
void updateGraphicInfo();
protected:
int mMaxFreezeCellNum;
SvgItemInterface **maFreezeCells;
private:
int mGroupID;
KBlocksSvgItem *mpBackground;
int mMaxFreezeCellNum;
KBlocksSvgItem **maFreezeCells;
int mMaxPrepareCellNum;
KBlocksSvgItem **maPrepareCells;
......@@ -88,9 +93,9 @@ private:
bool mWaitForAllUpdate;
KBlocksAnimator *mpAnimator;
QList<KBlocksSvgItem *> mFadeInItems;
QList<KBlocksSvgItem *> mFadeOutItems;
QList<KBlocksSvgItem *> mDropItems;
QList<SvgItemInterface *> mFadeInItems;
QList<SvgItemInterface *> mFadeOutItems;
QList<SvgItemInterface *> mDropItems;
QList<int> mRemovedLine;
QList<int> mPunishLine;
......
/***************************************************************************
* 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-2021 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 KBLOCKSSVGITEM_H
#define KBLOCKSSVGITEM_H
#include <QGraphicsPixmapItem>
#include <QGraphicsSvgItem>
#include "KBlocksLayout.h"
#include "SvgItemInterface.h"
enum KBlocks_SvgItem_Type {
KBlocksSvgItem_None = -1,
......@@ -23,24 +24,24 @@ enum KBlocks_SvgItem_Type {
KBlocksSvgItem_Max_Count
};
class KBlocksSvgItem : public QGraphicsSvgItem
class KBlocksSvgItem : public SvgItemInterface
{
Q_OBJECT
public:
KBlocksSvgItem(KBlocksLayout *p, int type, int posX, int posY);
~KBlocksSvgItem();
virtual ~KBlocksSvgItem();
void setLayoutPos(int posX, int posY);
bool updateSelf();
bool updateSelf() override;
void startOpAnim();
void stopOpAnim();
void startOpAnim() override;
void stopOpAnim() override;
void startPosAnim(QPointF target);
void execPosAnim(qreal step);
void stopPosAnim();
void startPosAnim(QPointF target) override;
void execPosAnim(qreal step) override;
void stopPosAnim() override;
private:
KBlocksLayout *mpGameLayout;
......
/******************************************************************************
* 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 SVGITEMINTERFACE_H
#define SVGITEMINTERFACE_H
#include <QGraphicsSvgItem>
#include <QPointF>
class SvgItemInterface : public QGraphicsSvgItem
{
public:
SvgItemInterface() = default;
virtual ~SvgItemInterface() = default;
public:
virtual bool updateSelf() = 0;
virtual void startOpAnim() = 0;
virtual void stopOpAnim() = 0;
virtual void startPosAnim(QPointF target) = 0;
virtual void execPosAnim(qreal step) = 0;
virtual void stopPosAnim() = 0;
};
#endif // SVGITEMINTERFACE_H
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