utilityapps/loadgen/ui/hb/src/loadgenlistitem.cpp
changeset 55 2d9cac8919d3
equal deleted inserted replaced
53:819e59dfc032 55:2d9cac8919d3
       
     1 /*
       
     2  * LoadGenListItem.cpp
       
     3  *
       
     4  *  Created on: Jul 29, 2010
       
     5  *      Author: sopirbo
       
     6  */
       
     7 
       
     8 #include "loadgenlistitem.h"
       
     9 
       
    10 
       
    11 #include <hblabel.h>
       
    12 #include <hbpushbutton.h>
       
    13 #include <hbabstractitemview.h>
       
    14 
       
    15 #include <QGraphicsLinearLayout>
       
    16 #include <QRectF>
       
    17 #include <QPainter>
       
    18 
       
    19 
       
    20 LoadGenListItem::LoadGenListItem( EngineWrapper& engWrapp, QGraphicsItem *parent ) : HbListViewItem( parent ),
       
    21 		mEngineWrapper(engWrapp),
       
    22 		hLayout(0),
       
    23 		vLayout(0),
       
    24 		hButtonLayout(0),
       
    25 	    mItemText(0),
       
    26 		mEditButton(0),
       
    27 		mSuspendButton(0),
       
    28 		mStopButton(0),
       
    29 		mIcon(0),
       
    30 		mExpanded(false)
       
    31 	{
       
    32 
       
    33 		
       
    34 	// TODO Auto-generated constructor stub
       
    35 	
       
    36 	}
       
    37 
       
    38 
       
    39 LoadGenListItem::~LoadGenListItem()
       
    40 	{
       
    41 	// TODO Auto-generated destructor stub
       
    42 	}
       
    43 
       
    44 HbAbstractViewItem *LoadGenListItem::createItem()
       
    45 {
       
    46     return new LoadGenListItem(*this);
       
    47 }
       
    48 
       
    49 QHash<QString, QVariant> LoadGenListItem::transientState() const
       
    50 		{
       
    51 
       
    52 		QHash<QString,QVariant> state;
       
    53 	
       
    54 /*		if ( mExpanded )
       
    55 			{
       
    56 			state.insert( "myexpanded", mExpanded );
       
    57 			}
       
    58 		else
       
    59 			{
       
    60 			state.insert( "myexpanded", false );
       
    61 			}*/
       
    62 		return state;
       
    63 		
       
    64 		}
       
    65 
       
    66 void LoadGenListItem::setTransientState(const QHash<QString, QVariant> &state)
       
    67 	{
       
    68 /*
       
    69 	mExpanded = state.value("myexpanded").toBool();*/
       
    70 	HbAbstractViewItem::setTransientState( state ); 
       
    71 	}
       
    72 
       
    73 
       
    74 void LoadGenListItem::EditButtonClicked()
       
    75 	{
       
    76 	mEngineWrapper.loadEdit(modelIndex().row());
       
    77 	
       
    78 	}
       
    79 
       
    80 void LoadGenListItem::StopButtonClicked()
       
    81 	{
       
    82 
       
    83 
       
    84 	mEngineWrapper.asyncStopLoad();
       
    85 	}
       
    86 
       
    87 void LoadGenListItem::SuspendButtonClicked()
       
    88 	{
       
    89 	mEngineWrapper.asyncSuspendOrResumeSelectedOrHighlightedItems();
       
    90 
       
    91 
       
    92 
       
    93 	}
       
    94 
       
    95 void LoadGenListItem::ChangeExpandedState()
       
    96 	{
       
    97 	/*
       
    98 	if( mExpanded ) 
       
    99 		{
       
   100 		mExpanded = false;
       
   101 		}
       
   102 	else
       
   103 		{
       
   104 		mExpanded=true;
       
   105 		}*/
       
   106 	}
       
   107 
       
   108 
       
   109 
       
   110 void LoadGenListItem::updateChildItems( )
       
   111 {
       
   112 	if(!hLayout)
       
   113 		{
       
   114 		init();
       
   115 		}
       
   116 
       
   117 	int userRole = Qt::UserRole + 1;
       
   118 	int userRole2 = Qt::UserRole + 2;
       
   119     mExpanded = qvariant_cast<bool>( modelIndex().data( userRole ) );
       
   120     
       
   121     QVariant variant = modelIndex().data(Qt::DisplayRole);
       
   122     
       
   123     QString itemText = qvariant_cast<QString>( variant );
       
   124     if(variant.isValid())
       
   125     	{
       
   126 		itemText = qvariant_cast<QString>( variant );
       
   127     	}
       
   128     else
       
   129     	{
       
   130 		itemText = "Text tTest";
       
   131     	}
       
   132     
       
   133     QVariant decorationRole = modelIndex().data(Qt::DecorationRole);
       
   134 	if (decorationRole.isValid()) 
       
   135 	   	{
       
   136 	    QIcon icon = qvariant_cast<QIcon>(decorationRole);
       
   137 	    mIcon->setIcon( HbIcon(icon) );
       
   138 	   	}
       
   139 
       
   140 	bool suspended = qvariant_cast<bool>( modelIndex().data( userRole2 ) );
       
   141     if( suspended )
       
   142     	{
       
   143 		mSuspendButton->setText("Resume");
       
   144     	}
       
   145     else
       
   146     	{
       
   147 		mSuspendButton->setText("Suspend");
       
   148     	}
       
   149     
       
   150     if( !mExpanded )
       
   151     	{
       
   152 		mItemText->setTextWrapping(Hb::TextNoWrap);
       
   153 		mItemText->setPlainText(itemText);
       
   154 		vLayout->removeItem(hButtonLayout);
       
   155     	}
       
   156     else
       
   157     	{
       
   158 		mItemText->setTextWrapping(Hb::TextWordWrap);
       
   159 		mItemText->setPlainText(itemText);
       
   160 		//mItemText->setHtml( itemText );
       
   161 		vLayout->addItem(hButtonLayout);
       
   162     	}
       
   163     
       
   164     
       
   165 }
       
   166 
       
   167 void LoadGenListItem::initButtonLayout()
       
   168 	{
       
   169 	    
       
   170 	    hButtonLayout = new QGraphicsLinearLayout();
       
   171 	    hButtonLayout->setOrientation( Qt::Horizontal );
       
   172 
       
   173 	    //edit button 
       
   174 	    mEditButton = new HbPushButton();
       
   175 	    mEditButton->setText("Edit");
       
   176 	    hButtonLayout->addItem( mEditButton );
       
   177 	    hButtonLayout->setAlignment( mEditButton, Qt::AlignLeft );
       
   178 
       
   179 	    //pause button 
       
   180 	    mSuspendButton = new HbPushButton();
       
   181 	    mSuspendButton->setText("SuspRes");
       
   182 	    hButtonLayout->addItem( mSuspendButton );
       
   183 	    hButtonLayout->setAlignment( mSuspendButton , Qt::AlignLeft );
       
   184 	    
       
   185 	    //pause button 
       
   186 	    mStopButton = new HbPushButton();
       
   187 	    mStopButton->setText("Stop");
       
   188 	    hButtonLayout->addItem( mStopButton );
       
   189 	    hButtonLayout->setAlignment( mStopButton , Qt::AlignLeft );
       
   190 	    
       
   191 	 
       
   192 	    connect( mEditButton, SIGNAL( clicked() ), this , SLOT( EditButtonClicked() ) );
       
   193 	    connect( mStopButton, SIGNAL( clicked() ), this , SLOT( StopButtonClicked() ) );
       
   194 	    connect( mSuspendButton, SIGNAL( clicked() ), this , SLOT( SuspendButtonClicked() ) );
       
   195 	}
       
   196 
       
   197 
       
   198 void LoadGenListItem::init()
       
   199 {
       
   200 	hLayout = new QGraphicsLinearLayout();
       
   201 	hLayout->setContentsMargins(0, 0, 0, 0);
       
   202 
       
   203 	hLayout->setOrientation( Qt::Horizontal );
       
   204 	//hLayout->addItem( layout() );
       
   205 
       
   206 	vLayout = new QGraphicsLinearLayout();
       
   207 	vLayout->setOrientation( Qt::Vertical );
       
   208 
       
   209 	//icon
       
   210 	mIcon = new HbLabel();
       
   211 	hLayout->addItem( mIcon );
       
   212 	hLayout->setAlignment( mIcon, Qt::AlignLeft );
       
   213 	//hLayout->setStretchFactor( mIcon, 1 );
       
   214 	
       
   215     //text
       
   216     mItemText = new HbLabel();
       
   217     HbFontSpec fontSpecPrimary( HbFontSpec::Primary );
       
   218     mItemText->setFontSpec( fontSpecPrimary );
       
   219     vLayout->addItem( mItemText );
       
   220     vLayout->setAlignment( mItemText, Qt::AlignLeft );
       
   221 
       
   222     
       
   223     initButtonLayout();
       
   224     
       
   225 
       
   226 	hLayout->addItem( vLayout );
       
   227 
       
   228 	hLayout->setStretchFactor( vLayout, 2 );
       
   229 	
       
   230 	setLayout(hLayout);
       
   231 	
       
   232 }