~joerg-ehrichs/botrace/master

« back to all changes in this revision

Viewing changes to src/client/participantwidget.cpp

  • Committer: Jörg Ehrichs
  • Date: 2012-07-25 13:09:25 UTC
  • Revision ID: git-v1:08eb05e7719caeb1ff6bbc9d723f47f8dfb38a0c
better looking participant list and overall gamewindow

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2011 Jörg Ehrichs <joerg.ehichs@gmx.de>
3
 
 *
4
 
 * This program is free software; you can redistribute it and/or
5
 
 * modify it under the terms of the GNU General Public License as
6
 
 * published by the Free Software Foundation; either version 2 of
7
 
 * the License, or (at your option) any later version.
8
 
 *
9
 
 * This program is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
 * GNU General Public License for more details.
13
 
 *
14
 
 * You should have received a copy of the GNU General Public License
15
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 
 */
17
 
 
18
 
#include "participantwidget.h"
19
 
 
20
 
#include "participantlistitem.h"
21
 
 
22
 
#include "renderer/gametheme.h"
23
 
#include "renderer/uitheme.h"
24
 
#include "engine/participant.h"
25
 
#include "engine/abstractclient.h"
26
 
 
27
 
#include <QScrollArea>
28
 
#include <QVBoxLayout>
29
 
#include <QSpacerItem>
30
 
#include <QPainter>
31
 
 
32
 
using namespace BotRace;
33
 
using namespace Client;
34
 
 
35
 
ParticipantWidget::ParticipantWidget( Renderer::GameTheme *renderer, QWidget *parent ) :
36
 
    QWidget( parent ),
37
 
    m_renderer( renderer ),
38
 
    m_client( 0 )
39
 
{
40
 
    setAcceptDrops( false );
41
 
 
42
 
 
43
 
    m_layout = new QVBoxLayout;
44
 
 
45
 
    m_layout->addStretch();
46
 
    setLayout( m_layout );
47
 
}
48
 
 
49
 
void ParticipantWidget::setClient( Core::AbstractClient *client )
50
 
{
51
 
    m_listItems.clear();
52
 
    m_client = client;
53
 
 
54
 
    foreach( Core::Participant * p, m_client->getOpponents() ) {
55
 
        addParticipant( p );
56
 
    }
57
 
 
58
 
    addParticipant( m_client->getPlayer() );
59
 
 
60
 
    connect( m_client, SIGNAL( participantAdded( BotRace::Core::Participant * ) ),
61
 
             this, SLOT( addParticipant( BotRace::Core::Participant * ) ) );
62
 
}
63
 
 
64
 
void ParticipantWidget::resetWidget()
65
 
{
66
 
    qDeleteAll( m_listItems );
67
 
    m_listItems.clear();
68
 
    repaint();
69
 
}
70
 
 
71
 
void ParticipantWidget::paintEvent( QPaintEvent *event )
72
 
{
73
 
    Q_UNUSED( event );
74
 
 
75
 
    QPainter painter( this );
76
 
    painter.setRenderHint( QPainter::Antialiasing );
77
 
 
78
 
    painter.setBrush( Qt::black );
79
 
    painter.drawRect( rect() );
80
 
}
81
 
 
82
 
void ParticipantWidget::addParticipant( BotRace::Core::Participant *p )
83
 
{
84
 
    ParticipantListItem *pi = new ParticipantListItem( m_renderer );
85
 
    pi->setGameMode( m_client->getBoardManager()->getGameMode() );
86
 
    pi->setParticipant( p );
87
 
 
88
 
    m_listItems.append( pi );
89
 
    m_layout->insertWidget( m_layout->count() - 1, pi );
90
 
 
91
 
    m_layout->invalidate();
92
 
}