Beispiel #1
0
void TutorialDlg::createSceneAndView ()
{
  LOG4CPP_INFO_S ((*mainCat)) << "TutorialDlg::createSceneAndView";

  m_scene = new QGraphicsScene (this);

  m_view = new QGraphicsView (m_scene, this);
  m_view->setMouseTracking (true);
  layout ()->addWidget(m_view);

  // Spacer is used to ensure view is the desired size. Directly setting the size of the view
  // is ineffective since the view then get resized to the smallest rectangle fitting the added items
  QGraphicsRectItem *spacer = new QGraphicsRectItem (0,
                                                     0,
                                                     backgroundSize().width (),
                                                     backgroundSize().height ());
  spacer->setBrush (QBrush (Qt::NoBrush));
  spacer->setPen (QPen (Qt::NoPen));
  spacer->setZValue(-1); // Put behind everything else at the default z of zero
  m_scene->addItem (spacer);
}
Beispiel #2
0
void KBounceGameWidget::generateOverlay()
{
	if ( size().isEmpty() )
		return;
	
    int itemWidth = qRound( 0.8 * size().width() );
    int itemHeight = qRound( 0.6 * size().height() );

	QSize backgroundSize( itemWidth,itemHeight );

	QPixmap px( backgroundSize );
	px.fill( Qt::transparent );

	QPainter p( &px );
	
	p.setPen( Qt::transparent );
	p.setRenderHint(QPainter::Antialiasing );
	
	if ( m_renderer.spriteExists("overlayBackground") )
	{
		QPixmap themeBackgound = m_renderer.spritePixmap("overlayBackground",backgroundSize);
		p.setCompositionMode( QPainter::CompositionMode_Source );
		p.drawPixmap( p.viewport(), themeBackgound );
		p.setCompositionMode( QPainter::CompositionMode_DestinationIn );
		p.fillRect(px.rect(), QColor( 0, 0, 0, 160 ));
		p.setCompositionMode( QPainter::CompositionMode_SourceOver );
	}
	else
	{
		p.setBrush( QBrush( QColor( 188, 202, 222, 155 ) ) );
		p.drawRoundRect( 0, 0, itemWidth, itemHeight, 25 );
	}
	
	QString text;
	switch( m_state )
	{
	case BeforeFirstGame:
	    text = i18n( "Welcome to KBounce.\n Click to start a game" );
	    break;
	case Paused:
	    text = i18n( "Paused" );
	    break;
	case BetweenLevels:
	    text = i18n( "You have successfully cleared more than %1% of the board\n", MIN_FILL_PERCENT ) +
		i18n( "%1 points: %2 points per remaining life\n", m_lives * POINTS_FOR_LIFE, POINTS_FOR_LIFE ) +
		i18n( "%1 points: Bonus\n", m_bonus ) +
		i18n( "%1 points: Total score for this level\n", m_bonus + m_lives * POINTS_FOR_LIFE ) +
		i18n( "On to level %1. Remember you get %2 lives this time!", m_level, m_level + 1 );
	    break;
	case GameOver:
	    text = i18n( "Game over.\n Click to start a game" );
	    break;
	default:
	    text = QString();
    }

    QFont font;
    font.setPointSize( 28 );
    p.setFont( font );
    int textWidth = p.boundingRect( p.viewport(), Qt::AlignCenter | Qt::AlignVCenter, text ).width();
    int fontSize = 28;
    while ( ( textWidth > itemWidth * 0.95 ) && fontSize > 1 )
    {
        fontSize--;
        font.setPointSize( fontSize );
        p.setFont( font );
        textWidth = p.boundingRect( p.viewport(), Qt::AlignCenter | Qt::AlignVCenter, text ).width();
    }
    KColorScheme kcs = KColorScheme( QPalette::Normal, KColorScheme::Window );
    p.setPen( kcs.foreground(KColorScheme::NormalText).color()); 
    p.drawText( p.viewport(), Qt::AlignCenter | Qt::AlignVCenter, text );
    p.end();

    m_overlay->setPixmap( px );
    m_overlay->moveTo( ( size().width() - itemWidth ) / 2, ( size().height() - itemHeight ) / 2 );
}