Commit ddc2ff07 authored by Dmitry Suzdalev's avatar Dmitry Suzdalev
Browse files

Some more work on klines' QGVization (nice word ;))

By looking at the current code state I guess that the result
will be more like rewrite rather than adaptation... :-)

Btw, I failed to reach anyone of listed authors by email,
so I guess I'll take mainainership of this cute little game :-).

svn path=/trunk/KDE/kdegames/klines/; revision=615165
parent 726252e0
......@@ -12,7 +12,10 @@ set(klines_SRCS
cell.cpp
ballpainter.cpp
klines.cpp
main.cpp )
main.cpp
scene.cpp
renderer.cpp
ballitem.cpp)
kde4_automoc(${klines_SRCS})
......
/*******************************************************************
*
* Copyright 2006 Dmitry Suzdalev <dimsuz@gmail.com>
*
* This file is part of the KDE project "KLines"
*
* KLines 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, or (at your option)
* any later version.
*
* KLines 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 KAtomic; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
********************************************************************/
#include "ballitem.h"
#include "renderer.h"
void BallItem::setColor( BallColor c )
{
m_color = c;
setPixmap( m_renderer->ballPixmap(c) );
}
......@@ -24,6 +24,7 @@
#define BALL_ITEM_H
#include <QGraphicsPixmapItem>
#include "commondefs.h"
class QTimeLine;
class KLinesRenderer;
......@@ -31,18 +32,15 @@ class KLinesRenderer;
class BallItem : public QObject, public QGraphicsPixmapItem
{
public:
enum AnimType { SelectedAnimation, BornAnimation, BurnAnimation };
enum Color { Red, Green, Blue, Yellow, Violet, Cyan, Brown };
BallItem( QGraphicsScene* parent, KLinesRenderer* r );
void setColor( Color c ) { m_color = c; setPixmap( m_renderer->ballPixmap(c) ); };
Color color() const { return m_color; }
void setColor( BallColor c );
BallColor color() const { return m_color; }
/**
* Starts animation
* @param type type of animation sequence to play
*/
void startAnimation( AnimType type );
void startAnimation( BallAnimationType type );
void stopAnimation();
private slots:
void animFrameChanged(int);
......@@ -58,7 +56,7 @@ private:
/**
* Color of the ball
*/
Color m_color;
BallColor m_color;
};
#endif
/*******************************************************************
*
* Copyright 2006 Dmitry Suzdalev <dimsuz@gmail.com>
*
* This file is part of the KDE project "KLines"
*
* KLines 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, or (at your option)
* any later version.
*
* KLines 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 KAtomic; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
********************************************************************/
#ifndef COMMON_DEFINES_H
#define COMMON_DEFINES_H
enum BallAnimationType { SelectedAnimation, BornAnimation, BurnAnimation };
enum BallColor { Red, Green, Blue, Yellow, Violet, Cyan, Brown };
#endif
......@@ -24,6 +24,8 @@
#include "linesboard.h"
#include "prompt.h"
#include "scene.h"
MainWidget::MainWidget( QWidget* parent )
: QFrame( parent )
{
......@@ -32,7 +34,9 @@ MainWidget::MainWidget( QWidget* parent )
bPainter = new BallPainter();
lsb = new LinesBoard(bPainter, this);
grid->addWidget( lsb );
// grid->addWidget( lsb );
lsb->hide();
grid->addWidget( new KLinesView( new KLinesScene(this), this ) );
QBoxLayout *right = new QVBoxLayout;
grid->addLayout(right);
......@@ -44,9 +48,6 @@ MainWidget::MainWidget( QWidget* parent )
right->addWidget( label, 0, Qt::AlignBottom | Qt::AlignHCenter );
right->addWidget( lPrompt, 0, Qt::AlignTop | Qt::AlignHCenter );
grid->activate();
grid->setSizeConstraint( QLayout::SetFixedSize );
// warning("width: %i height: %i", width(), height() );
// warning("wh: %i hh: %i", sizeHint().width(), sizeHint().height() );
......
/*******************************************************************
*
* Copyright 2006 Dmitry Suzdalev <dimsuz@gmail.com>
*
* This file is part of the KDE project "KLines"
*
* KLines 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, or (at your option)
* any later version.
*
* KLines 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 KAtomic; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
********************************************************************/
#include <KStandardDirs>
#include "renderer.h"
KLinesRenderer::KLinesRenderer()
{
m_fieldPix = QPixmap( KStandardDirs::locate( "appdata", "field.jpg" ));
}
QPixmap KLinesRenderer::ballPixmap(BallColor) const
{
return QPixmap();
}
QPixmap KLinesRenderer::backgroundTilePixmap() const
{
return m_fieldPix;
}
......@@ -23,13 +23,20 @@
#ifndef KL_RENDERER_H
#define KL_RENDERER_H
#include <QPixmap>
#include "commondefs.h"
class KLinesRenderer
{
public:
KLinesRenderer();
~KLinesRenderer();
QPixmap ballPixmap( BallItem::Color c ) const;
QPixmap animationFrame( BallItem::Color c, BallItem::AnimType t, int frameNo ) const;
QPixmap ballPixmap( BallColor c ) const;
QPixmap animationFrame( BallColor c, BallAnimationType t, int frameNo ) const;
QPixmap backgroundTilePixmap() const;
private:
QPixmap m_ballsPix; // to be removed when SVG comes to us
QPixmap m_fieldPix; // to be removed when SVG comes to us
};
#endif
/*******************************************************************
*
* Copyright 2006 Dmitry Suzdalev <dimsuz@gmail.com>
*
* This file is part of the KDE project "KLines"
*
* KLines 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, or (at your option)
* any later version.
*
* KLines 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 KAtomic; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
********************************************************************/
#include <QResizeEvent>
#include <kdebug.h>
#include "scene.h"
#include "renderer.h"
KLinesView::KLinesView( KLinesScene* scene, QWidget* parent )
: QGraphicsView(scene, parent)
{
//setMinimumSize( defaultFieldSize, defaultFieldSize );
}
void KLinesView::resizeEvent( QResizeEvent* ev )
{
static_cast<KLinesScene*>(scene())->resizeScene( ev->size().width(), ev->size().height() );
}
// =============== KLinesScene =======================
KLinesScene::KLinesScene( QObject* parent )
: QGraphicsScene(parent)
{
m_renderer = new KLinesRenderer;
}
KLinesScene::~KLinesScene()
{
delete m_renderer;
}
void KLinesScene::resizeScene(int width,int height)
{
kDebug() << "resize:" << width << "," << height << endl;
setSceneRect( 0, 0, width, height );
}
void KLinesScene::drawBackground(QPainter *p, const QRectF&)
{
kDebug() << k_funcinfo << endl;
// FIXME dimsuz: temp
for(int x=0; x<32*FIELD_SIZE;x+=32)
for(int y=0; y<32*FIELD_SIZE;y+=32)
p->drawPixmap( x, y, m_renderer->backgroundTilePixmap() );
}
/*******************************************************************
*
* Copyright 2006 Dmitry Suzdalev <dimsuz@gmail.com>
*
* This file is part of the KDE project "KLines"
*
* KLines 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, or (at your option)
* any later version.
*
* KLines 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 KAtomic; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
********************************************************************/
#ifndef KL_SCENE_H
#define KL_SCENE_H
#include <QGraphicsScene>
#include <QGraphicsView>
#include "commondefs.h"
static const int FIELD_SIZE=9;
class KLinesRenderer;
class KLinesScene : public QGraphicsScene
{
public:
KLinesScene( QObject *parent );
~KLinesScene();
void resizeScene( int width, int height );
private:
virtual void drawBackground( QPainter*, const QRectF& );
BallColor m_field[FIELD_SIZE][FIELD_SIZE];
KLinesRenderer* m_renderer;
};
class KLinesView : public QGraphicsView
{
public:
KLinesView( KLinesScene* scene, QWidget *parent );
private:
void resizeEvent(QResizeEvent *);
};
#endif
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