00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "commentsviewitem.h"
00021
00022 #include <models/commentsmodel.h>
00023
00024 #include <KIcon>
00025 #include <Plasma/IconWidget>
00026 #include <Plasma/Label>
00027
00028 #include <QGraphicsGridLayout>
00029
00030 CommentsViewItem::CommentsViewItem( QGraphicsItem* parent, Qt::WindowFlags wFlags )
00031 : QGraphicsWidget( parent, wFlags )
00032 , m_author( 0 )
00033 , m_title( 0 )
00034 , m_body( 0 )
00035 , m_dateTime( 0 )
00036 , m_rating( 0 )
00037 , m_replyButton( 0 )
00038 , m_layout( 0 )
00039 , m_depth( 0 )
00040 , m_replyEnabled( false )
00041 {
00042
00043 }
00044
00045 CommentsViewItem::~CommentsViewItem()
00046 {
00047 }
00048
00049 void CommentsViewItem::setModelIndex( const QModelIndex& index )
00050 {
00051 m_index = index;
00052 layoutWidgets();
00053 setToolTips();
00054 }
00055
00056 QModelIndex CommentsViewItem::modelIndex() const
00057 {
00058
00059 return m_index.sibling( m_index.row(), m_index.column() );
00060 }
00061
00062 int CommentsViewItem::depth()
00063 {
00064 return m_depth;
00065 }
00066
00067 void CommentsViewItem::setDepth( int newDepth )
00068 {
00069 m_depth = newDepth;
00070 setContentsMargins( m_depth * 20, 0, 0, 0 );
00071 }
00072
00073 int CommentsViewItem::rowInLayout()
00074 {
00075 return m_rowInLayout;
00076 }
00077
00078 void CommentsViewItem::setRowInLayout( int row )
00079 {
00080 m_rowInLayout = row;
00081 }
00082
00083 bool CommentsViewItem::replyEnabled()
00084 {
00085 return m_replyEnabled;
00086 }
00087
00088 void CommentsViewItem::setReplyEnabled( bool enabled )
00089 {
00090 m_replyEnabled = enabled;
00091 }
00092
00093 void CommentsViewItem::hoverEnterEvent( QGraphicsSceneHoverEvent* event )
00094 {
00095 if( m_replyButton && m_replyEnabled )
00096 {
00097 m_replyButton->setVisible( true );
00098 }
00099 QGraphicsItem::hoverEnterEvent( event );
00100 }
00101
00102 void CommentsViewItem::hoverLeaveEvent( QGraphicsSceneHoverEvent* event )
00103 {
00104 if( m_replyButton && m_replyEnabled )
00105 {
00106 m_replyButton->setVisible( false );
00107 }
00108 QGraphicsWidget::hoverLeaveEvent( event );
00109 }
00110
00111
00112 void CommentsViewItem::layoutWidgets()
00113 {
00114 m_layout = new QGraphicsGridLayout();
00115
00116 m_author = new Plasma::IconWidget( this );
00117 m_author->setText( m_index.sibling( m_index.row(), GluonPlayer::CommentsModel::AuthorColumn ).data().toString() );
00118
00119 m_title = new Plasma::Label( this );
00120 m_title->setText( m_index.sibling( m_index.row(), GluonPlayer::CommentsModel::TitleColumn ).data().toString() );
00121 m_title->setAlignment( Qt::AlignRight );
00122
00123 m_body = new Plasma::Label( this );
00124 m_body->setText( m_index.sibling( m_index.row(), GluonPlayer::CommentsModel::BodyColumn ).data().toString() );
00125
00126 m_dateTime = new Plasma::Label( this );
00127 m_dateTime->setText( m_index.sibling( m_index.row(), GluonPlayer::CommentsModel::DateTimeColumn ).data().toString() );
00128
00129 m_rating = new Plasma::Label( this );
00130 m_rating->setText( m_index.sibling( m_index.row(), GluonPlayer::CommentsModel::RatingColumn ).data().toString() );
00131
00132 m_replyButton = new Plasma::IconWidget( this );
00133 m_replyButton->setVisible( false );
00134 m_replyButton->setIcon( KIcon( "edit-undo" ) );
00135 connect( m_replyButton, SIGNAL( activated() ), SIGNAL( replyClicked() ) );
00136
00137 m_layout->addItem( m_title, 0, 0 );
00138 m_layout->addItem( m_author, 0, 1 );
00139 m_layout->addItem( m_body, 1, 0, 1, 2 );
00140 m_layout->addItem( m_dateTime, 2, 0 );
00141 m_layout->addItem( m_rating, 2, 1 );
00142 m_layout->addItem( m_replyButton, 2, 2 );
00143
00144 setLayout( m_layout );
00145 }
00146
00147 void CommentsViewItem::setToolTips()
00148 {
00149 }
00150