Commit efa78f2a authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

Commit patch by Guillaume Denry

****
This patch displays the balls preview zone into the game zone and removes
the background grid of the three balls.
Johann Ollivier Lapeyre knows about it
****

CCMAIL: guillaume.denry@gmail.com>

svn path=/trunk/KDE/kdegames/klines/; revision=663657
parent da3d782c
......@@ -133,7 +133,6 @@ void KLinesMainWindow::startGame()
{
updateScore(0);
mwidget->scene()->startNewGame();
mwidget->updateNextColors();
}
void KLinesMainWindow::showNextToggled(bool show)
......
......@@ -35,47 +35,17 @@ MainWidget::MainWidget( QWidget* parent )
KLinesView* klview = new KLinesView( m_scene, this );
klview->setCacheMode( QGraphicsView::CacheBackground );
mainLay->addWidget( klview );
QBoxLayout *right = new QVBoxLayout;
mainLay->addLayout(right);
right->setMargin(2);
m_next_label = new QLabel(i18n("Next:"), this);
m_next_label->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
m_next_label->setAlignment( Qt::AlignHCenter );
m_preview = new BallsPreview(this);
updateNextColors();
right->addStretch( 1 );
right->addWidget( m_next_label );
right->addWidget( m_preview );
right->addStretch( 1 );
mainLay->addSpacing( mainLay->spacing() );
connect(m_scene, SIGNAL(nextColorsChanged()), SLOT(updateNextColors()) );
}
MainWidget::~MainWidget()
{
}
void MainWidget::resizeEvent( QResizeEvent* )
{
m_preview->updateGeometry();
}
void MainWidget::updateNextColors()
{
m_preview->setColors( m_scene->nextColors() );
}
void MainWidget::setShowNextColors(bool visible)
{
m_preview->setVisible( visible );
m_next_label->setVisible( visible );
// add bonus score points if playing w/o preview
m_scene->setBonusScorePoints( visible ? 0 : 1 );
m_scene->setPreviewZoneVisible( visible );
}
#include "mwidget.moc"
......@@ -35,12 +35,9 @@ public:
KLinesScene* scene() { return m_scene; }
public slots:
void updateNextColors();
void setShowNextColors(bool);
private:
virtual void resizeEvent( QResizeEvent* );
KLinesScene* m_scene;
BallsPreview* m_preview;
QLabel *m_next_label;
};
......
......@@ -49,7 +49,7 @@ void KLinesView::resizeEvent( QResizeEvent* ev )
KLinesScene::KLinesScene( QObject* parent )
: QGraphicsScene(parent),
m_playFieldOrigin(0, 0 ), m_numFreeCells(FIELD_SIZE*FIELD_SIZE),
m_score(0), m_bonusScore(0), m_cellSize(32)
m_score(0), m_bonusScore(0), m_cellSize(32), m_previewZoneVisible(true)
{
m_animator = new KLinesAnimator(this);
connect( m_animator, SIGNAL(moveFinished()), SLOT(moveAnimFinished() ) );
......@@ -116,7 +116,16 @@ void KLinesScene::resizeScene(int width,int height)
int minDim = qMin( width, height );
m_cellSize = minDim/FIELD_SIZE;
m_playFieldOrigin = QPoint( width/2 - minDim/2, height/2 - minDim/2 );
int boardSize = m_cellSize * FIELD_SIZE;
if (m_previewZoneVisible && boardSize + m_cellSize > width) // No space enough for balls preview
{
minDim = width;
m_cellSize = (minDim - m_cellSize)/FIELD_SIZE;
boardSize = m_cellSize * FIELD_SIZE;
}
m_playFieldOrigin = QPoint( (width - (m_previewZoneVisible ? m_cellSize : 0))/2 - boardSize/2, height/2 - boardSize/2 );
setSceneRect( 0, 0, width, height );
......@@ -169,11 +178,21 @@ void KLinesScene::nextThreeBalls()
m_nextColors[i] = c;
}
emit nextColorsChanged();
invalidate(sceneRect(), BackgroundLayer); // Refresh next colors preview zone
m_animator->animateBorn( newItems );
}
void KLinesScene::setPreviewZoneVisible( bool visible )
{
if (visible == m_previewZoneVisible)
return;
m_previewZoneVisible = visible;
resizeScene((int) width(), (int) height());
invalidate(sceneRect());
}
BallItem* KLinesScene::randomlyPlaceBall(BallColor c)
{
m_numFreeCells--;
......@@ -576,8 +595,8 @@ void KLinesScene::undo()
m_selPos = FieldPos();
emit scoreChanged(m_score);
emit nextColorsChanged();
emit scoreChanged(m_score);
invalidate(sceneRect(), BackgroundLayer); // Refresh next colors preview zone
emit enableUndo(false);
}
......@@ -587,6 +606,18 @@ void KLinesScene::drawBackground(QPainter *p, const QRectF&)
for(int x=m_playFieldOrigin.x(); x<m_playFieldOrigin.x()+m_cellSize*FIELD_SIZE;x+=m_cellSize)
for(int y=m_playFieldOrigin.y(); y<m_playFieldOrigin.y()+m_cellSize*FIELD_SIZE;y+=m_cellSize)
p->drawPixmap( x, y, KLinesRenderer::self()->backgroundTilePixmap() );
// Preview zone
if (m_previewZoneVisible)
{
QPixmap pix = KLinesRenderer::self()->backgroundTilePixmap();
int ballHeight = pix.size().height();
int previewOriginY = (int) height() / 2 - (3 * m_cellSize) / 2;
for(int i=0; i < 3; i++)
if( !m_nextColors.isEmpty() )
p->drawPixmap( (int) width() - m_cellSize + 2, previewOriginY + i*ballHeight, KLinesRenderer::self()->ballPixmap( m_nextColors.at(i) ) );
}
}
#include "scene.moc"
......@@ -52,6 +52,10 @@ public:
* Brings in next three balls to scene
*/
void nextThreeBalls();
/**
* Show/Hide the preview zone
*/
void setPreviewZoneVisible( bool visible );
/**
* This score points will be added as an additional bonus to
* every score resulted from ball erasing event.
......@@ -125,7 +129,6 @@ public slots:
signals:
void scoreChanged(int);
void enableUndo(bool);
void nextColorsChanged();
void gameOver(int);
private slots:
void moveAnimFinished();
......@@ -198,6 +201,10 @@ private:
* Cell size in pixels
*/
int m_cellSize;
/**
* Is true if preview zone is visible
*/
bool m_previewZoneVisible;
/**
* Varable which is needed for little trick (tm).
* Read more about it in removeAnimFinished() slot
......@@ -215,7 +222,6 @@ private:
* Keyboard-playing focus indication
*/
QGraphicsRectItem *m_focusItem;
/**
* Struct for holding game state - used on undos
*/
......
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