00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "gamesviewitem.h"
00021 #include "models/gamesmodel.h"
00022
00023 #include <KIcon>
00024 #include <Plasma/IconWidget>
00025 #include <Plasma/Label>
00026 #include <Plasma/ToolTipManager>
00027 #include <Plasma/ToolTipContent>
00028
00029 GamesViewItem::GamesViewItem( QGraphicsItem* parent, Qt::WindowFlags wFlags )
00030 : QGraphicsWidget( parent, wFlags )
00031 , m_preview( 0 )
00032 , m_gameName( 0 )
00033 , m_gameDescription( 0 )
00034 , m_playButton( 0 )
00035 , m_layout( 0 )
00036 {
00037 }
00038
00039 void GamesViewItem::setModelIndex( const QModelIndex& index )
00040 {
00041 m_index = index;
00042 layoutWidgets();
00043 setToolTips();
00044 }
00045
00046 void GamesViewItem::layoutWidgets()
00047 {
00048 m_layout = new QGraphicsGridLayout();
00049
00050 m_preview = new Plasma::IconWidget( this );
00051 m_preview->setIcon( KIcon( "gluon_creator" ) );
00052 m_preview->setAcceptHoverEvents( false );
00053 m_preview->setContentsMargins( 0, 0, 0, 0 );
00054 m_preview->setAcceptedMouseButtons( Qt::NoButton );
00055 m_preview->setFocusPolicy( Qt::NoFocus );
00056 m_preview->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::MinimumExpanding );
00057
00058 m_gameName = new Plasma::Label( this );
00059 m_gameName->setText( m_index.sibling( m_index.row(), GluonPlayer::GamesModel::NameColumn ).data().toString() );
00060
00061 m_gameDescription = new Plasma::Label( this );
00062 m_gameDescription->setText( m_index.sibling( m_index.row(), GluonPlayer::GamesModel::DescriptionColumn ).data().toString() );
00063
00064 m_playButton = new Plasma::IconWidget( this );
00065 m_playButton->setIcon( KIcon( "media-playback-start" ) );
00066 m_playButton->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::MinimumExpanding );
00067 connect( m_playButton, SIGNAL( activated() ), SLOT( playGameActivated() ) );
00068
00069 m_layout->addItem( m_preview, 0, 0, 2, 1 );
00070 m_layout->addItem( m_gameName, 0, 1 );
00071 m_layout->addItem( m_gameDescription, 1, 1 );
00072 m_layout->addItem( m_playButton, 0, 2, 2, 1 );
00073 setLayout( m_layout );
00074 }
00075
00076 void GamesViewItem::setToolTips()
00077 {
00078 Plasma::ToolTipContent data;
00079 data.setImage( m_preview->icon() );
00080 data.setMainText( m_gameName->text() );
00081 data.setSubText( i18n( "Click here to Start the game" ) );
00082 Plasma::ToolTipManager::self()->setContent( m_playButton, data );
00083 }
00084
00085 QModelIndex GamesViewItem::modelIndex() const
00086 {
00087 return m_index;
00088 }
00089
00090 void GamesViewItem::playGameActivated()
00091 {
00092 emit gameToPlaySelected( m_index );
00093 }
00094
00095 void GamesViewItem::mousePressEvent( QGraphicsSceneMouseEvent* event )
00096 {
00097 Q_UNUSED( event );
00098 emit gameSelected( m_index );
00099 }
00100
00101 #include "gamesviewitem.moc"