javauis/eswt_qt/org.eclipse.swt/Eclipse_SWT_PI/qt/library/listdatamodel.cpp
changeset 80 d6dafc5d983f
parent 35 85266cc22c7f
equal deleted inserted replaced
78:71ad690e91f5 80:d6dafc5d983f
    42 
    42 
    43 /**
    43 /**
    44  *  ListItem
    44  *  ListItem
    45  */
    45  */
    46 ListItem::ListItem(const QString& aText)
    46 ListItem::ListItem(const QString& aText)
    47 	: txt( aText )
    47     : txt( aText )
    48 	{
    48     {
    49 	SWT_LOG_FUNC_CALL();
    49     SWT_LOG_FUNC_CALL();
    50 	}
    50     }
    51 
    51 
    52 ListItem::~ListItem()
    52 ListItem::~ListItem()
    53 	{
    53     {
    54 	SWT_LOG_FUNC_CALL();
    54     SWT_LOG_FUNC_CALL();
    55 	} 
    55     } 
    56 
    56 
    57 
    57 
    58 const QString& ListItem::text() const
    58 const QString& ListItem::text() const
    59 	{
    59     {
    60 	return txt;
    60     return txt;
    61 	}
    61     }
    62 
    62 
    63 const QPixmap* ListItem::image() const
    63 const QPixmap* ListItem::image() const
    64 	{
    64     {
    65 	return NULL;
    65     return NULL;
    66 	}
    66     }
    67 
    67 
    68 void ListItem::setText( const QString& string )
    68 void ListItem::setText( const QString& string )
    69 	{
    69     {
    70 	txt = string;
    70     txt = string;
    71 	}
    71     }
    72 
    72 
    73 
    73 
    74 Qt::CheckState ListItem::checkState() const
    74 Qt::CheckState ListItem::checkState() const
    75 	{
    75     {
    76 	SWT_LOG_FUNC_CALL();
    76     SWT_LOG_FUNC_CALL();
    77 	return state;
    77     return state;
    78 	}
    78     }
    79 
    79 
    80 
    80 
    81 void ListItem::setCheckState( Qt::CheckState state )
    81 void ListItem::setCheckState( Qt::CheckState state )
    82 	{
    82     {
    83 	SWT_LOG_FUNC_CALL();
    83     SWT_LOG_FUNC_CALL();
    84 	this->state = state;
    84     this->state = state;
    85 	}
    85     }
    86 	
    86     
    87 /**
    87 /**
    88  *  ListBoxItem
    88  *  ListBoxItem
    89  */
    89  */
    90 
    90 
    91 ListBoxItem::ListBoxItem( const QString& aDetailText, const QPixmap** aDetailImages, const int aDetailImageCount,  
    91 ListBoxItem::ListBoxItem( const QString& aDetailText, const QPixmap* aDetailImages, const int aDetailImageCount,  
    92 	const QString& aHeadingText, const QPixmap** aHeadingImages, const int aHeadingImageCount ) 
    92     const QString& aHeadingText, const QPixmap* aHeadingImages, const int aHeadingImageCount ) 
    93 	: ListItem(aDetailText), headingTxt(aHeadingText)
    93     : ListItem(aDetailText), headingTxt(aHeadingText)
    94 	{
    94     {
    95 	SWT_LOG_FUNC_CALL();
    95     SWT_LOG_FUNC_CALL();
    96 	for (int i = 0; i < aDetailImageCount; i++) 
    96     for (int i = 0; i < aDetailImageCount; i++) 
    97 	    {
    97         {
    98 	    detailImgs.push_back(*aDetailImages[i]);
    98         detailImgs.push_back(aDetailImages[i]);
    99 	    }
    99         }
   100     for (int i = 0; i < aHeadingImageCount; i++) 
   100     for (int i = 0; i < aHeadingImageCount; i++) 
   101         {
   101         {
   102         headingImgs.push_back(*aHeadingImages[i]);
   102         headingImgs.push_back(aHeadingImages[i]);
   103         }
   103         }
   104 	}
   104     }
   105 
   105 
   106 
   106 
   107 ListBoxItem::~ListBoxItem()
   107 ListBoxItem::~ListBoxItem()
   108 	{
   108     {
   109 	SWT_LOG_FUNC_CALL();
   109     SWT_LOG_FUNC_CALL();
   110 	}
   110     }
   111 	
   111     
   112 const QString& ListBoxItem::headingText() const
   112 const QString& ListBoxItem::headingText() const
   113 	{
   113     {
   114 	SWT_LOG_FUNC_CALL();
   114     SWT_LOG_FUNC_CALL();
   115 	return headingTxt;
   115     return headingTxt;
   116 	}
   116     }
   117 	
   117     
   118 const QList<QPixmap>& ListBoxItem::detailImages() const
   118 const QList<QPixmap>& ListBoxItem::detailImages() const
   119 	{
   119     {
   120 	SWT_LOG_FUNC_CALL();
   120     SWT_LOG_FUNC_CALL();
   121 	return detailImgs;
   121     return detailImgs;
   122 	}
   122     }
   123 	
   123     
   124 const QList<QPixmap>& ListBoxItem::headingImages() const
   124 const QList<QPixmap>& ListBoxItem::headingImages() const
   125 	{
   125     {
   126 	SWT_LOG_FUNC_CALL();
   126     SWT_LOG_FUNC_CALL();
   127 	return headingImgs;
   127     return headingImgs;
   128 	}
   128     }
   129 	
   129     
   130 int ListBoxItem::detailImageCount() const
   130 int ListBoxItem::detailImageCount() const
   131 	{
   131     {
   132 	SWT_LOG_FUNC_CALL();
   132     SWT_LOG_FUNC_CALL();
   133 	return detailImgs.count();
   133     return detailImgs.count();
   134 	}
   134     }
   135 	
   135     
   136 int ListBoxItem::headingImageCount() const
   136 int ListBoxItem::headingImageCount() const
   137 	{
   137     {
   138 	SWT_LOG_FUNC_CALL();
   138     SWT_LOG_FUNC_CALL();
   139 	return headingImgs.count();
   139     return headingImgs.count();
   140 	}
   140     }
   141 
   141 
   142 void ListBoxItem::setContentsToNull()
   142 void ListBoxItem::setContentsToNull()
   143     {
   143     {
   144     SWT_LOG_FUNC_CALL();
   144     SWT_LOG_FUNC_CALL();
   145     setText( QString() );
   145     setText( QString() );
   151     for (int i = 0; i < headingImgs.count(); i++) 
   151     for (int i = 0; i < headingImgs.count(); i++) 
   152         {
   152         {
   153         headingImgs.pop_back();
   153         headingImgs.pop_back();
   154         }
   154         }
   155     }
   155     }
   156 	
   156     
   157 /**
   157 /**
   158  *  ListModel
   158  *  ListModel
   159  */
   159  */
   160 
   160 
   161 ListModel::ListModel( int type, int style, QListView *parent )
   161 ListModel::ListModel( int type, int style, QListView *parent )
   162 	: QAbstractListModel( parent ),
   162     : QAbstractListModel( parent ),
   163 	listType( type ),
   163     listType( type ),
   164 	layoutStyle( style )
   164     layoutStyle( style )
   165 	{
   165     {
   166 	SWT_LOG_FUNC_CALL();
   166     SWT_LOG_FUNC_CALL();
   167 	SWT_LOG_DATA_3("listType=%d layoutStyle=%x parent=%x ", style, type, reinterpret_cast<int>(parent) );
   167     SWT_LOG_DATA_3("listType=%d layoutStyle=%x parent=%x ", style, type, reinterpret_cast<int>(parent) );
   168 	}
   168     }
   169 	
   169     
   170 ListModel::~ListModel()
   170 ListModel::~ListModel()
   171 	{
   171     {
   172 	SWT_LOG_FUNC_CALL();
   172     SWT_LOG_FUNC_CALL();
   173 	clearList();
   173     clearList();
   174 	}
   174     }
   175 
   175 
   176 ListModel* ListModel::createDataModel( int type, int style, QListView *parent )
   176 ListModel* ListModel::createDataModel( int type, int style, QListView *parent )
   177 	{
   177     {
   178 	if( ( type & LISTTYPE_LISTBOX ) != 0 )
   178     if( ( type & LISTTYPE_LISTBOX ) != 0 )
   179 		{
   179         {
   180 		return new ListBoxModel( type, style, parent );
   180         return new ListBoxModel( type, style, parent );
   181 		}
   181         }
   182 	else
   182     else
   183 		{
   183         {
   184 		return new ListModel( type, style, parent );
   184         return new ListModel( type, style, parent );
   185 		}	
   185         }   
   186 	}
   186     }
   187 
   187 
   188 
   188 
   189 void ListModel::beginInsertRows( const QModelIndex& parent, int first, int last )
   189 void ListModel::beginInsertRows( const QModelIndex& parent, int first, int last )
   190 	{
   190     {
   191 	Q_ASSERT( first >= 0 && first <= list.size() );
   191     Q_ASSERT( first >= 0 && first <= list.size() );
   192 	Q_ASSERT( last >= first );
   192     Q_ASSERT( last >= first );
   193 	SWT_LOG_FUNC_CALL();
   193     SWT_LOG_FUNC_CALL();
   194 	QAbstractItemModel::beginInsertRows( parent, first, last );		
   194     QAbstractItemModel::beginInsertRows( parent, first, last );     
   195 	}
   195     }
   196 	
   196     
   197 	
   197     
   198 void ListModel::endInsertRows()
   198 void ListModel::endInsertRows()
   199 	{
   199     {
   200 	SWT_LOG_FUNC_CALL();
   200     SWT_LOG_FUNC_CALL();
   201 	QAbstractItemModel::endInsertRows();
   201     QAbstractItemModel::endInsertRows();
   202 	}
   202     }
   203 
   203 
   204 void ListModel::beginRemoveRows( const QModelIndex& parent, int first, int last )
   204 void ListModel::beginRemoveRows( const QModelIndex& parent, int first, int last )
   205 	{
   205     {
   206 	Q_ASSERT( first > -1 && first < list.size() );
   206     Q_ASSERT( first > -1 && first < list.size() );
   207 	Q_ASSERT( last >= first && last < list.size() );
   207     Q_ASSERT( last >= first && last < list.size() );
   208 	SWT_LOG_FUNC_CALL();
   208     SWT_LOG_FUNC_CALL();
   209 	QAbstractItemModel::beginRemoveRows( parent, first, last );		
   209     QAbstractItemModel::beginRemoveRows( parent, first, last );     
   210 	}
   210     }
   211 	
   211     
   212 void ListModel::endRemoveRows()
   212 void ListModel::endRemoveRows()
   213 	{
   213     {
   214 	SWT_LOG_FUNC_CALL();
   214     SWT_LOG_FUNC_CALL();
   215 	QAbstractItemModel::endRemoveRows();
   215     QAbstractItemModel::endRemoveRows();
   216 	}
   216     }
   217 	
   217     
   218 
   218 
   219 void ListModel::emitLayoutAboutToBeChanged()
   219 void ListModel::emitLayoutAboutToBeChanged()
   220 	{
   220     {
   221 	SWT_LOG_FUNC_CALL();
   221     SWT_LOG_FUNC_CALL();
   222 	emit layoutAboutToBeChanged();
   222     emit layoutAboutToBeChanged();
   223 	}
   223     }
   224 
   224 
   225 void ListModel::emitLayoutChanged()
   225 void ListModel::emitLayoutChanged()
   226 	{
   226     {
   227 	SWT_LOG_FUNC_CALL();
   227     SWT_LOG_FUNC_CALL();
   228 	emit layoutChanged();
   228     emit layoutChanged();
   229 	}
   229     }
   230 	
   230     
   231 Qt::ItemFlags ListModel::flags( const QModelIndex& index ) const
   231 Qt::ItemFlags ListModel::flags( const QModelIndex& index ) const
   232 	{
   232     {
   233 	SWT_LOG_FUNC_CALL();
   233     SWT_LOG_FUNC_CALL();
   234 	Qt::ItemFlags  flags = ( QAbstractItemModel::flags(index) | Qt::ItemIsEnabled | Qt::ItemIsSelectable ) & ~Qt::ItemIsUserCheckable;
   234     Qt::ItemFlags  flags = ( QAbstractItemModel::flags(index) | Qt::ItemIsEnabled | Qt::ItemIsSelectable ) & ~Qt::ItemIsUserCheckable;
   235 	if( ( layoutStyle & LISTBASE_SHOW_CHECKBOX ) != 0 )
   235     if( ( layoutStyle & LISTBASE_SHOW_CHECKBOX ) != 0 )
   236 		{
   236         {
   237 		flags |= Qt::ItemIsUserCheckable;
   237         flags |= Qt::ItemIsUserCheckable;
   238 		}
   238         }
   239 	return flags;
   239     return flags;
   240 	}
   240     }
   241 	
   241     
   242 int ListModel::rowCount(const QModelIndex& /*parent*/ ) const
   242 int ListModel::rowCount(const QModelIndex& /*parent*/ ) const
   243 	{
   243     {
   244 	SWT_LOG_FUNC_CALL();
   244     SWT_LOG_FUNC_CALL();
   245 	return list.count();
   245     return list.count();
   246 	}
   246     }
   247 	
   247     
   248 QVariant ListModel::data(const QModelIndex &index, int role) const
   248 QVariant ListModel::data(const QModelIndex &index, int role) const
   249 	{
   249     {
   250 	SWT_LOG_FUNC_CALL();
   250     SWT_LOG_FUNC_CALL();
   251 	if(!index.isValid()) 
   251     if(!index.isValid()) 
   252 		{
   252         {
   253 		SWT_LOG_DATA_1("invalid index %d", -1);
   253         SWT_LOG_DATA_1("invalid index %d", -1);
   254 		return QVariant();
   254         return QVariant();
   255 		}
   255         }
   256 	Q_ASSERT( index.row() > -1  && index.row() < list.size() );
   256     Q_ASSERT( index.row() > -1  && index.row() < list.size() );
   257 	
   257     
   258 	if ( role == Qt::DisplayRole )
   258     if ( role == Qt::DisplayRole )
   259 		{ 
   259         { 
   260 		SWT_LOG_DATA_2("Request data on DisplayRole: row=%d col=%d", index.row(), index.column());
   260         SWT_LOG_DATA_2("Request data on DisplayRole: row=%d col=%d", index.row(), index.column());
   261 		return	list[index.row()]->text();
   261         return  list[index.row()]->text();
   262 		}
   262         }
   263 	else if ( role == Qt::DecorationRole )
   263     else if ( role == Qt::DecorationRole )
   264 		{ 
   264         { 
   265 		SWT_LOG_DATA_2("Request data on DecorationRole: row=%d col=%d", index.row(), index.column());
   265         SWT_LOG_DATA_2("Request data on DecorationRole: row=%d col=%d", index.row(), index.column());
   266 		const QPixmap* img = list[index.row()]->image();
   266         const QPixmap* img = list[index.row()]->image();
   267 		if( img )
   267         if( img )
   268 			{
   268             {
   269 			return *img;
   269             return *img;
   270 			}
   270             }
   271 		}
   271         }
   272 	else if( role == Qt::CheckStateRole && index.column()==0 ) 
   272     else if( role == Qt::CheckStateRole && index.column()==0 ) 
   273 		{
   273         {
   274 		SWT_LOG_DATA_2("Request checkState: row=%d col=%d", index.row(), index.column());
   274         SWT_LOG_DATA_2("Request checkState: row=%d col=%d", index.row(), index.column());
   275 		return list[index.row()]->checkState();
   275         return list[index.row()]->checkState();
   276 		}
   276         }
   277 		
   277         
   278 	SWT_LOG_DATA_2("Request something else: row=%d col=%d", index.row(), index.column());
   278     SWT_LOG_DATA_2("Request something else: row=%d col=%d", index.row(), index.column());
   279 	return QVariant();
   279     return QVariant();
   280 	}
   280     }
   281 
   281 
   282 void ListModel::setCheckState( const QItemSelection& selection, Qt::CheckState state )
   282 void ListModel::setCheckState( const QItemSelection& selection, Qt::CheckState state )
   283 	{
   283     {
   284 	SWT_LOG_FUNC_CALL();
   284     SWT_LOG_FUNC_CALL();
   285 	const QModelIndexList indexes = selection.indexes ();
   285     const QModelIndexList indexes = selection.indexes ();
   286 	for( int i=0; i< indexes.size(); i++)
   286     for( int i=0; i< indexes.size(); i++)
   287 		{
   287         {
   288 		list.at(indexes.at(i).row())->setCheckState( state );
   288         list.at(indexes.at(i).row())->setCheckState( state );
   289 		}
   289         }
   290 	}
   290     }
   291 
   291 
   292 const QString& ListModel::itemString( const int row ) const
   292 const QString& ListModel::itemString( const int row ) const
   293 	{
   293     {
   294 	SWT_LOG_FUNC_CALL();
   294     SWT_LOG_FUNC_CALL();
   295 	Q_ASSERT(row > -1 && row < list.size());
   295     Q_ASSERT(row > -1 && row < list.size());
   296 	return list.at(row)->text();	
   296     return list.at(row)->text();    
   297 	}
   297     }
   298 
   298 
   299 
   299 
   300 jobjectArray ListModel::itemStrings( JNIEnv* aJniEnv )
   300 jobjectArray ListModel::itemStrings( JNIEnv* aJniEnv )
   301 	{
   301     {
   302 	SWT_LOG_FUNC_CALL();
   302     SWT_LOG_FUNC_CALL();
   303 	
   303     
   304 	const int count = list.size();
   304     const int count = list.size();
   305    	jclass stringClass = aJniEnv->FindClass( "java/lang/String" );
   305     jclass stringClass = aJniEnv->FindClass( "java/lang/String" );
   306     jobjectArray result = aJniEnv->NewObjectArray(count, stringClass, NULL);
   306     jobjectArray result = aJniEnv->NewObjectArray(count, stringClass, NULL);
   307     if( !result )
   307     if( !result )
   308         {
   308         {
   309         throw std::bad_alloc();
   309         throw std::bad_alloc();
   310         }
   310         }
   311     
   311     
   312  	jstring javaString;
   312     jstring javaString;
   313     for ( int i=0; i<count; ++i ) 
   313     for ( int i=0; i<count; ++i ) 
   314 	    {
   314         {
   315 		javaString = swtApp->jniUtils().QStringToJavaString(aJniEnv, list.at(i)->text() );
   315         javaString = swtApp->jniUtils().QStringToJavaString(aJniEnv, list.at(i)->text() );
   316 	    aJniEnv->SetObjectArrayElement( result, i, javaString ); 
   316         aJniEnv->SetObjectArrayElement( result, i, javaString ); 
   317 	    aJniEnv->DeleteLocalRef( javaString );
   317         aJniEnv->DeleteLocalRef( javaString );
   318 	    }
   318         }
   319 	aJniEnv->DeleteLocalRef( stringClass );
   319     aJniEnv->DeleteLocalRef( stringClass );
   320         
   320         
   321     return result;
   321     return result;
   322 	}
   322     }
   323 
   323 
   324 int ListModel::indexOf(const QString& string, const int start ) const
   324 int ListModel::indexOf(const QString& string, const int start ) const
   325 	{
   325     {
   326 	SWT_LOG_FUNC_CALL();
   326     SWT_LOG_FUNC_CALL();
   327  	Q_ASSERT(start > -1 && start < list.size());
   327     Q_ASSERT(start > -1 && start < list.size());
   328     QStringMatcher matcher(string, Qt::CaseSensitive);
   328     QStringMatcher matcher(string, Qt::CaseSensitive);
   329     for (int i = start; i < list.size(); ++i) 
   329     for (int i = start; i < list.size(); ++i) 
   330     	{
   330         {
   331         const QString & str = list.at(i)->text();
   331         const QString & str = list.at(i)->text();
   332         if (string.length() == str.length() && matcher.indexIn(str) == 0)
   332         if (string.length() == str.length() && matcher.indexIn(str) == 0)
   333             return i;
   333             return i;
   334     	}
   334         }
   335     return -1;
   335     return -1;
   336 	}
   336     }
   337 
   337 
   338 int ListModel::itemHeight()
   338 int ListModel::itemHeight()
   339 	{
   339     {
   340 	SWT_LOG_FUNC_CALL();
   340     SWT_LOG_FUNC_CALL();
   341 	const QListView* listView = static_cast<const QListView*>( static_cast<QObject*>(this)->parent() );
   341     const QListView* listView = static_cast<const QListView*>( static_cast<QObject*>(this)->parent() );
   342 
   342 
   343 	if(list.size() > 0 ) 
   343     if(list.size() > 0 ) 
   344 		{
   344         {
   345 		return listView->sizeHintForRow(0);
   345         return listView->sizeHintForRow(0);
   346 		}
   346         }
   347 		
   347         
   348 	return listView->fontMetrics().height();
   348     return listView->fontMetrics().height();
   349 	}
   349     }
   350 
   350 
   351 int ListModel::insertPosition(const QString& string, bool ascent )
   351 int ListModel::insertPosition(const QString& string, bool ascent )
   352 	{
   352     {
   353 	SWT_LOG_FUNC_CALL();
   353     SWT_LOG_FUNC_CALL();
   354 	if( listType != LISTTYPE_SORTEDLIST )
   354     if( listType != LISTTYPE_SORTEDLIST )
   355 		{
   355         {
   356 		throw std::bad_exception();
   356         throw std::bad_exception();
   357 		}
   357         }
   358 		
   358         
   359 	int pos = 0;	
   359     int pos = 0;    
   360 	for(int i = list.size() -1; i > -1; i--)
   360     for(int i = list.size() -1; i > -1; i--)
   361 		{
   361         {
   362 		if( ascent )
   362         if( ascent )
   363 			{
   363             {
   364 			if( string < list.at(i)->text() )
   364             if( string < list.at(i)->text() )
   365 			continue;
   365             continue;
   366 			}
   366             }
   367 		else
   367         else
   368 			{
   368             {
   369 			if( string > list.at(i)->text() )
   369             if( string > list.at(i)->text() )
   370 			continue;
   370             continue;
   371 			}	
   371             }   
   372 		pos = i + 1;
   372         pos = i + 1;
   373 		break;
   373         break;
   374 		}
   374         }
   375 	return pos;
   375     return pos;
   376 	}
   376     }
   377 
   377 
   378 
   378 
   379 void ListModel::remove( const int row )
   379 void ListModel::remove( const int row )
   380 	{
   380     {
   381 	SWT_LOG_FUNC_CALL();
   381     SWT_LOG_FUNC_CALL();
   382 	Q_ASSERT(row > -1 && row < list.size());
   382     Q_ASSERT(row > -1 && row < list.size());
   383 	ListItem* item = list.takeAt(row);
   383     ListItem* item = list.takeAt(row);
   384 	delete item;
   384     delete item;
   385 	}
   385     }
   386 
   386 
   387 
   387 
   388 void ListModel::clearList()
   388 void ListModel::clearList()
   389 	{
   389     {
   390 	SWT_LOG_FUNC_CALL();
   390     SWT_LOG_FUNC_CALL();
   391 	qDeleteAll(list.begin(), list.end());
   391     qDeleteAll(list.begin(), list.end());
   392 	list.clear();
   392     list.clear();
   393 	}
   393     }
   394 
   394 
   395 
   395 
   396 void ListModel::appendItem( const QString& string )
   396 void ListModel::appendItem( const QString& string )
   397 	{
   397     {
   398 	SWT_LOG_FUNC_CALL();
   398     SWT_LOG_FUNC_CALL();
   399 	ListItem* item = createItem( string );
   399     ListItem* item = createItem( string );
   400 	list.append(item);
   400     list.append(item);
   401 	}
   401     }
   402 	
   402     
   403 void ListModel::appendItem(const QString& string, const QPixmap* pixmap )
   403 void ListModel::appendItem(const QString& string, const QPixmap* pixmap )
   404 	{
   404     {
   405 	SWT_LOG_FUNC_CALL();
   405     SWT_LOG_FUNC_CALL();
   406 	ListItem* item = createItem( string, pixmap );
   406     ListItem* item = createItem( string, pixmap );
   407 	list.append(item);
   407     list.append(item);
   408 	}
   408     }
   409 
   409 
   410 	
   410     
   411 void ListModel::appendItem(const QString& /*aDetailText*/, const QPixmap** /*aDetailImages*/, const int /*aDetailImageCount*/,  
   411 void ListModel::appendItem(const QString& /*aDetailText*/, const QPixmap* /*aDetailImages*/, const int /*aDetailImageCount*/,  
   412 	const QString& /*aHeadingText*/, const QPixmap** /*aHeadingImages*/, const int /*aHeadingImageCount*/ )
   412     const QString& /*aHeadingText*/, const QPixmap* /*aHeadingImages*/, const int /*aHeadingImageCount*/ )
   413 	{
   413     {
   414 	Q_ASSERT( false );	
   414     Q_ASSERT( false );  
   415 	}
   415     }
   416 
   416 
   417 void ListModel::insertItem( const int row, const QString& string )
   417 void ListModel::insertItem( const int row, const QString& string )
   418 	{
   418     {
   419 	SWT_LOG_FUNC_CALL();
   419     SWT_LOG_FUNC_CALL();
   420 	Q_ASSERT(row > -1 && row <= list.size());
   420     Q_ASSERT(row > -1 && row <= list.size());
   421 	ListItem* item = createItem( string );
   421     ListItem* item = createItem( string );
   422 	if( row == list.size() )
   422     if( row == list.size() )
   423 		{
   423         {
   424 		list.append(item);
   424         list.append(item);
   425 		}
   425         }
   426 	else
   426     else
   427 		{
   427         {
   428 		list.insert( row, item );
   428         list.insert( row, item );
   429 		}
   429         }
   430 	} 
   430     } 
   431 
   431 
   432 void ListModel::insertItem( const int row, const QString& string, const QPixmap* pixmap )
   432 void ListModel::insertItem( const int row, const QString& string, const QPixmap* pixmap )
   433 	{
   433     {
   434 	SWT_LOG_FUNC_CALL();
   434     SWT_LOG_FUNC_CALL();
   435 	Q_ASSERT(row > -1 && row <= list.size());
   435     Q_ASSERT(row > -1 && row <= list.size());
   436 	ListItem* item = createItem( string, pixmap );
   436     ListItem* item = createItem( string, pixmap );
   437 	if( row == list.size() )
   437     if( row == list.size() )
   438 		{
   438         {
   439 		list.append(item);
   439         list.append(item);
   440 		}
   440         }
   441 	else
   441     else
   442 		{
   442         {
   443 		list.insert( row, item );
   443         list.insert( row, item );
   444 		}
   444         }
   445 	} 
   445     } 
   446 
   446 
   447 
   447 
   448 int ListModel::style() const
   448 int ListModel::style() const
   449 	{
   449     {
   450 	SWT_LOG_FUNC_CALL();
   450     SWT_LOG_FUNC_CALL();
   451 	return layoutStyle;
   451     return layoutStyle;
   452 	}
   452     }
   453 	
   453     
   454 
   454 
   455 	
   455     
   456 ListItem* ListModel::createItem( const QString& string )
   456 ListItem* ListModel::createItem( const QString& string )
   457 	{
   457     {
   458 	SWT_LOG_FUNC_CALL();
   458     SWT_LOG_FUNC_CALL();
   459 	ListItem* item =  new ListItem(string);
   459     ListItem* item =  new ListItem(string);
   460 	if( !item )
   460     if( !item )
   461 		{	
   461         {   
   462        	throw std::bad_alloc();
   462         throw std::bad_alloc();
   463 		}
   463         }
   464 	return item;	
   464     return item;    
   465 	}
   465     }
   466 
   466 
   467 
   467 
   468 ListItem* ListModel::createItem( const QString& /*string*/, const QPixmap* /*pixmap*/ )
   468 ListItem* ListModel::createItem( const QString& /*string*/, const QPixmap* /*pixmap*/ )
   469 	{
   469     {
   470 	SWT_LOG_FUNC_CALL();
   470     SWT_LOG_FUNC_CALL();
   471 	Q_ASSERT( false );	
   471     Q_ASSERT( false );  
   472 	return NULL;
   472     return NULL;
   473 	}
   473     }
   474 	
   474     
   475 ListItem* ListModel::createItem(const QString& /*aDetailText*/, const QPixmap** /*aDetailImages*/, const int /*aDetailImageCount*/,  
   475 ListItem* ListModel::createItem(const QString& /*aDetailText*/, const QPixmap* /*aDetailImages*/, const int /*aDetailImageCount*/,  
   476 	const QString& /*aHeadingText*/, const QPixmap** /*aHeadingImages*/, const int /*aHeadingImageCount*/ )
   476     const QString& /*aHeadingText*/, const QPixmap* /*aHeadingImages*/, const int /*aHeadingImageCount*/ )
   477 	{
   477     {
   478 	SWT_LOG_FUNC_CALL();
   478     SWT_LOG_FUNC_CALL();
   479 	Q_ASSERT( false );	
   479     Q_ASSERT( false );  
   480 	return NULL;
   480     return NULL;
   481 	}
   481     }
   482 
   482 
   483 void ListModel::setItemContentsToNull( const int /*row*/ )
   483 void ListModel::setItemContentsToNull( const int /*row*/ )
   484     {
   484     {
   485     SWT_LOG_FUNC_CALL();
   485     SWT_LOG_FUNC_CALL();
   486     Q_ASSERT( false );
   486     Q_ASSERT( false );
   487     }   
   487     }   
   488 
   488 
   489 // ListBoxModel
   489 // ListBoxModel
   490 
   490 
   491 ListBoxModel::ListBoxModel( int type, int style, QListView *parent )
   491 ListBoxModel::ListBoxModel( int type, int style, QListView *parent )
   492 	: ListModel(type, style, parent ),
   492     : ListModel(type, style, parent ),
   493 	detailTxtIndex(-1),
   493     detailTxtIndex(-1),
   494 	headingTxtIndex(-1),
   494     headingTxtIndex(-1),
   495 	detailTxtSize(QPoint(0, 0)),
   495     detailTxtSize(QPoint(0, 0)),
   496 	headingTxtSize(QPoint(0, 0)),
   496     headingTxtSize(QPoint(0, 0)),
   497 	detailImgCount(0),
   497     detailImgCount(0),
   498 	headingImgCount(0),
   498     headingImgCount(0),
   499 	imgHeight(0),
   499     imgHeight(0),
   500 	detailImgWidths(NULL),
   500     detailImgWidths(NULL),
   501 	headingImgWidths(NULL),
   501     headingImgWidths(NULL),
   502 	rowHeights(NULL),
   502     rowHeights(NULL),
   503 	detailImgWidth(0),
   503     detailImgWidth(0),
   504 	headingImgWidth(0)
   504     headingImgWidth(0)
   505 	{
   505     {
   506 	SWT_LOG_FUNC_CALL();
   506     SWT_LOG_FUNC_CALL();
   507 	}
   507     }
   508 	
   508     
   509 ListBoxModel::~ListBoxModel()
   509 ListBoxModel::~ListBoxModel()
   510 	{
   510     {
   511 	SWT_LOG_FUNC_CALL();
   511     SWT_LOG_FUNC_CALL();
   512 
   512 
   513 	delete detailImgWidths;
   513     delete detailImgWidths;
   514 	delete headingImgWidths;
   514     delete headingImgWidths;
   515 	delete rowHeights;
   515     delete rowHeights;
   516 	}
   516     }
   517 
   517 
   518 	
   518     
   519 void ListBoxModel::clearList()
   519 void ListBoxModel::clearList()
   520 	{
   520     {
   521 	SWT_LOG_FUNC_CALL();
   521     SWT_LOG_FUNC_CALL();
   522 	ListModel::clearList();
   522     ListModel::clearList();
   523 	detailTxtIndex = -1;
   523     detailTxtIndex = -1;
   524 	headingTxtIndex = -1;
   524     headingTxtIndex = -1;
   525 	detailTxtSize = QPoint(0, 0);
   525     detailTxtSize = QPoint(0, 0);
   526 	headingTxtSize = QPoint(0, 0);
   526     headingTxtSize = QPoint(0, 0);
   527 	detailImgCount = 0;
   527     detailImgCount = 0;
   528 	headingImgCount = 0;
   528     headingImgCount = 0;
   529 	imgHeight = 0;
   529     imgHeight = 0;
   530 	delete detailImgWidths;
   530     delete detailImgWidths;
   531 	detailImgWidths = NULL;
   531     detailImgWidths = NULL;
   532 	delete headingImgWidths;
   532     delete headingImgWidths;
   533 	headingImgWidths = NULL;
   533     headingImgWidths = NULL;
   534 	delete rowHeights;
   534     delete rowHeights;
   535 	rowHeights = NULL;
   535     rowHeights = NULL;
   536 	detailImgWidth = 0;
   536     detailImgWidth = 0;
   537 	headingImgWidth = 0;
   537     headingImgWidth = 0;
   538 	}
   538     }
   539 
   539 
   540 void ListBoxModel::appendItem(const QString& aDetailText, const QPixmap** aDetailImages, const int aDetailImageCount,  
   540 void ListBoxModel::appendItem(const QString& aDetailText, const QPixmap* aDetailImages, const int aDetailImageCount,  
   541 	const QString& aHeadingText, const QPixmap** aHeadingImages, const int aHeadingImageCount )
   541     const QString& aHeadingText, const QPixmap* aHeadingImages, const int aHeadingImageCount )
   542 	{
   542     {
   543 	SWT_LOG_FUNC_CALL();
   543     SWT_LOG_FUNC_CALL();
   544 	ListItem* item = createItem( aDetailText, aDetailImages,  aDetailImageCount,  
   544     ListItem* item = createItem( aDetailText, aDetailImages,  aDetailImageCount,  
   545 		aHeadingText, aHeadingImages, aHeadingImageCount );
   545         aHeadingText, aHeadingImages, aHeadingImageCount );
   546 	list.append(item);
   546     list.append(item);
   547 
   547 
   548 	// remember the index of the item, which has the longest detail text
   548     // remember the index of the item, which has the longest detail text
   549 	const QListView* listView = static_cast<const QListView*>( static_cast<QObject*>(this)->parent() );
   549     const QListView* listView = static_cast<const QListView*>( static_cast<QObject*>(this)->parent() );
   550 	if(!aDetailText.isNull())
   550     if(!aDetailText.isNull())
   551 		{
   551         {
   552 		int textWidth = listView->fontMetrics().boundingRect(aDetailText).width();	
   552         int textWidth = listView->fontMetrics().boundingRect(aDetailText).width();  
   553 		if( detailTxtSize.x() < textWidth )
   553         if( detailTxtSize.x() < textWidth )
   554 			{
   554             {
   555 			detailTxtSize.rx() = textWidth;
   555             detailTxtSize.rx() = textWidth;
   556 			detailTxtIndex = list.size() - 1;
   556             detailTxtIndex = list.size() - 1;
   557 			}
   557             }
   558 		}
   558         }
   559 	
   559     
   560 	// remember the index of the item, which has the longest heading text
   560     // remember the index of the item, which has the longest heading text
   561 	if( (layoutStyle | LB_STYLE_1LINE_ITEM) != 0 || (layoutStyle | LB_STYLE_2LINE_ITEM) != 0 )
   561     if( (layoutStyle | LB_STYLE_1LINE_ITEM) != 0 || (layoutStyle | LB_STYLE_2LINE_ITEM) != 0 )
   562 		{
   562         {
   563 		if(!aHeadingText.isNull())
   563         if(!aHeadingText.isNull())
   564 			{
   564             {
   565 			int textWidth = listView->fontMetrics().boundingRect(aHeadingText).width();	
   565             int textWidth = listView->fontMetrics().boundingRect(aHeadingText).width(); 
   566 			if( headingTxtSize.x() < textWidth )
   566             if( headingTxtSize.x() < textWidth )
   567 				{
   567                 {
   568 				headingTxtSize.rx() = textWidth;
   568                 headingTxtSize.rx() = textWidth;
   569 				headingTxtIndex = list.size() - 1;
   569                 headingTxtIndex = list.size() - 1;
   570 				}
   570                 }
   571 			}
   571             }
   572 		}
   572         }
   573 	
   573     
   574 	// remember the maximum detail image count
   574     // remember the maximum detail image count
   575 	// and remember the maximum widths for every columns of detail images
   575     // and remember the maximum widths for every columns of detail images
   576 	if( (layoutStyle | LB_MOD_SHOW_DETAIL_ICONS) != 0 )	
   576     if( (layoutStyle | LB_MOD_SHOW_DETAIL_ICONS) != 0 ) 
   577 		{
   577         {
   578 		if( detailImgCount < aDetailImageCount )
   578         if( detailImgCount < aDetailImageCount )
   579 			{
   579             {
   580 			int* alloc =  new int[aDetailImageCount];
   580             int* alloc =  new int[aDetailImageCount];
   581 			memset(alloc, '\0', sizeof(int)*aDetailImageCount);
   581             memset(alloc, '\0', sizeof(int)*aDetailImageCount);
   582 			if( !alloc )
   582             if( !alloc )
   583 				{	
   583                 {   
   584 		       	throw std::bad_alloc();
   584                 throw std::bad_alloc();
   585 				}
   585                 }
   586 			for(int i = 0; i < detailImgCount; i++)
   586             for(int i = 0; i < detailImgCount; i++)
   587 				{
   587                 {
   588 				alloc[i] =  detailImgWidths[i];
   588                 alloc[i] =  detailImgWidths[i];
   589 				}
   589                 }
   590 			delete 	detailImgWidths;
   590             delete  detailImgWidths;
   591 			detailImgWidths = alloc;
   591             detailImgWidths = alloc;
   592 			detailImgCount = aDetailImageCount;
   592             detailImgCount = aDetailImageCount;
   593 			}	
   593             }   
   594 		for(int i = 0; i < aDetailImageCount; i++)
   594         for(int i = 0; i < aDetailImageCount; i++)
   595 			{
   595             {
   596 			if( aDetailImages[i] )
   596             if( !aDetailImages[i].isNull() )
   597 				{
   597                 {
   598 				QSize size = aDetailImages[i]->size();
   598                 QSize size = aDetailImages[i].size();
   599 				if(detailImgWidths[i] < size.width())
   599                 if(detailImgWidths[i] < size.width())
   600 					{
   600                     {
   601 					detailImgWidths[i] = size.width();
   601                     detailImgWidths[i] = size.width();
   602 					}
   602                     }
   603 				if(imgHeight < size.height())
   603                 if(imgHeight < size.height())
   604 					{
   604                     {
   605 					imgHeight = size.height();
   605                     imgHeight = size.height();
   606 					}
   606                     }
   607 				}	
   607                 }   
   608 			}	
   608             }   
   609 		}
   609         }
   610 		
   610         
   611 	// remember the maximum detail image count
   611     // remember the maximum detail image count
   612 	// and remember the maximum widths for every columns of heading images
   612     // and remember the maximum widths for every columns of heading images
   613 	if( (layoutStyle | LB_MOD_SHOW_HEADING_ICONS) != 0 )	
   613     if( (layoutStyle | LB_MOD_SHOW_HEADING_ICONS) != 0 )    
   614 		{
   614         {
   615 		if( headingImgCount < aHeadingImageCount )
   615         if( headingImgCount < aHeadingImageCount )
   616 			{
   616             {
   617 			int* alloc =  new int[aHeadingImageCount ];
   617             int* alloc =  new int[aHeadingImageCount ];
   618 			memset(alloc, '\0', sizeof(int)*aHeadingImageCount);
   618             memset(alloc, '\0', sizeof(int)*aHeadingImageCount);
   619 			if( !alloc )
   619             if( !alloc )
   620 				{	
   620                 {   
   621 		       	throw std::bad_alloc();
   621                 throw std::bad_alloc();
   622 				}
   622                 }
   623 			for(int i = 0; i < headingImgCount; i++)
   623             for(int i = 0; i < headingImgCount; i++)
   624 				{
   624                 {
   625 				alloc[i] =  headingImgWidths[i];
   625                 alloc[i] =  headingImgWidths[i];
   626 				}
   626                 }
   627 			delete 	headingImgWidths;
   627             delete  headingImgWidths;
   628 			headingImgWidths = alloc;
   628             headingImgWidths = alloc;
   629 			headingImgCount = aHeadingImageCount;
   629             headingImgCount = aHeadingImageCount;
   630 			}	
   630             }   
   631 		for(int i = 0; i < aHeadingImageCount; i++)
   631         for(int i = 0; i < aHeadingImageCount; i++)
   632 			{
   632             {
   633 			if( aHeadingImages[i] )
   633             if( !aHeadingImages[i].isNull() )
   634 				{
   634                 {
   635 				QSize size = aHeadingImages[i]->size();
   635                 QSize size = aHeadingImages[i].size();
   636 				if(headingImgWidths[i] < size.width())
   636                 if(headingImgWidths[i] < size.width())
   637 					{
   637                     {
   638 					headingImgWidths[i] = size.width();
   638                     headingImgWidths[i] = size.width();
   639 					}
   639                     }
   640 				if(imgHeight < size.height())
   640                 if(imgHeight < size.height())
   641 					{
   641                     {
   642 					imgHeight = size.height();
   642                     imgHeight = size.height();
   643 					}
   643                     }
   644 				}	
   644                 }   
   645 			}	
   645             }   
   646 		}
   646         }
   647 	}
   647     }
   648 	
   648     
   649 	
   649     
   650 void ListBoxModel::updateLayoutData( const int row, const int rowHeight, const QPoint detailTxtSize, 
   650 void ListBoxModel::updateLayoutData( const int row, const int rowHeight, const QPoint detailTxtSize, 
   651 		const QPoint headingTxtSize, const int detailImgWidth, const int headingImgWidth ) const
   651         const QPoint headingTxtSize, const int detailImgWidth, const int headingImgWidth ) const
   652 	{
   652     {
   653 	SWT_LOG_FUNC_CALL();
   653     SWT_LOG_FUNC_CALL();
   654 	Q_ASSERT(row > -1 && row < list.size());
   654     Q_ASSERT(row > -1 && row < list.size());
   655 	
   655     
   656 	if(!rowHeights)
   656     if(!rowHeights)
   657 		{
   657         {
   658 		int count = list.size();
   658         int count = list.size();
   659 		rowHeights =  new int[count];
   659         rowHeights =  new int[count];
   660 		if( !rowHeights )
   660         if( !rowHeights )
   661 			{	
   661             {   
   662 	       	throw std::bad_alloc();
   662             throw std::bad_alloc();
   663 			}
   663             }
   664 		memset(rowHeights, '\0', sizeof(int)*count);
   664         memset(rowHeights, '\0', sizeof(int)*count);
   665 		}
   665         }
   666 		
   666         
   667 	rowHeights[row] = rowHeight;
   667     rowHeights[row] = rowHeight;
   668     this->detailTxtSize = detailTxtSize;
   668     this->detailTxtSize = detailTxtSize;
   669     this->headingTxtSize = headingTxtSize;
   669     this->headingTxtSize = headingTxtSize;
   670     this->detailImgWidth = detailImgWidth;
   670     this->detailImgWidth = detailImgWidth;
   671     this->headingImgWidth = headingImgWidth;
   671     this->headingImgWidth = headingImgWidth;
   672 	}	
   672     }   
   673 
   673 
   674 const QString& ListBoxModel::headingText( const int row ) const
   674 const QString& ListBoxModel::headingText( const int row ) const
   675 	{
   675     {
   676 	SWT_LOG_FUNC_CALL();
   676     SWT_LOG_FUNC_CALL();
   677 	Q_ASSERT(row > -1 && row < list.size());
   677     Q_ASSERT(row > -1 && row < list.size());
   678 	return static_cast<ListBoxItem*>(list.at(row))->headingText();
   678     return static_cast<ListBoxItem*>(list.at(row))->headingText();
   679 	}
   679     }
   680 	
   680     
   681 	
   681     
   682 int ListBoxModel::detailImageCount() const
   682 int ListBoxModel::detailImageCount() const
   683 	{
   683     {
   684 	SWT_LOG_FUNC_CALL();
   684     SWT_LOG_FUNC_CALL();
   685 	return detailImgCount;
   685     return detailImgCount;
   686 	}
   686     }
   687 	
   687     
   688 int ListBoxModel::headingImageCount() const
   688 int ListBoxModel::headingImageCount() const
   689 	{
   689     {
   690 	SWT_LOG_FUNC_CALL();
   690     SWT_LOG_FUNC_CALL();
   691 	return headingImgCount;
   691     return headingImgCount;
   692 	}
   692     }
   693 
   693 
   694 const int& ListBoxModel::detailImageWidth(const int index) const
   694 const int& ListBoxModel::detailImageWidth(const int index) const
   695 	{
   695     {
   696 	SWT_LOG_FUNC_CALL();
   696     SWT_LOG_FUNC_CALL();
   697 	Q_ASSERT(index > -1 && index < detailImgCount);
   697     Q_ASSERT(index > -1 && index < detailImgCount);
   698 	return detailImgWidths[index];
   698     return detailImgWidths[index];
   699 	}
   699     }
   700 	
   700     
   701 const int& ListBoxModel::headingImageWidth(const int index) const
   701 const int& ListBoxModel::headingImageWidth(const int index) const
   702 	{
   702     {
   703 	SWT_LOG_FUNC_CALL();
   703     SWT_LOG_FUNC_CALL();
   704 	Q_ASSERT(index > -1 && index < headingImgCount);
   704     Q_ASSERT(index > -1 && index < headingImgCount);
   705 	return headingImgWidths[index];
   705     return headingImgWidths[index];
   706 	}
   706     }
   707 
   707 
   708 	
   708     
   709 int ListBoxModel::detailImageCount( const int row ) const
   709 int ListBoxModel::detailImageCount( const int row ) const
   710 	{
   710     {
   711 	SWT_LOG_FUNC_CALL();
   711     SWT_LOG_FUNC_CALL();
   712 	Q_ASSERT(row > -1 && row < list.size());
   712     Q_ASSERT(row > -1 && row < list.size());
   713 	return static_cast<ListBoxItem*>(list.at(row))->detailImageCount();
   713     return static_cast<ListBoxItem*>(list.at(row))->detailImageCount();
   714 	}
   714     }
   715 	
   715     
   716 int ListBoxModel::headingImageCount( const int row ) const
   716 int ListBoxModel::headingImageCount( const int row ) const
   717 	{
   717     {
   718 	SWT_LOG_FUNC_CALL();
   718     SWT_LOG_FUNC_CALL();
   719 	Q_ASSERT(row > -1 && row < list.size());
   719     Q_ASSERT(row > -1 && row < list.size());
   720 	return static_cast<ListBoxItem*>(list.at(row))->headingImageCount();
   720     return static_cast<ListBoxItem*>(list.at(row))->headingImageCount();
   721 	}
   721     }
   722 	
   722     
   723 const QList<QPixmap>& ListBoxModel::detailImages(const int row ) const
   723 const QList<QPixmap>& ListBoxModel::detailImages(const int row ) const
   724 	{
   724     {
   725 	SWT_LOG_FUNC_CALL();
   725     SWT_LOG_FUNC_CALL();
   726 	Q_ASSERT(row > -1 && row < list.size());
   726     Q_ASSERT(row > -1 && row < list.size());
   727 	return static_cast<ListBoxItem*>(list.at(row))->detailImages();
   727     return static_cast<ListBoxItem*>(list.at(row))->detailImages();
   728 	}
   728     }
   729 	
   729     
   730 const QList<QPixmap>& ListBoxModel::headingImages( const int row ) const
   730 const QList<QPixmap>& ListBoxModel::headingImages( const int row ) const
   731 	{
   731     {
   732 	SWT_LOG_FUNC_CALL();
   732     SWT_LOG_FUNC_CALL();
   733 	Q_ASSERT(row > -1 && row < list.size());
   733     Q_ASSERT(row > -1 && row < list.size());
   734 	return static_cast<ListBoxItem*>(list.at(row))->headingImages();
   734     return static_cast<ListBoxItem*>(list.at(row))->headingImages();
   735 	}
   735     }
   736 	
   736     
   737 QPoint ListBoxModel::detailTextSize() const
   737 QPoint ListBoxModel::detailTextSize() const
   738 	{
   738     {
   739 	SWT_LOG_FUNC_CALL();
   739     SWT_LOG_FUNC_CALL();
   740 	return detailTxtSize;
   740     return detailTxtSize;
   741 	}
   741     }
   742 	
   742     
   743 QPoint ListBoxModel::headingTextSize() const
   743 QPoint ListBoxModel::headingTextSize() const
   744 	{
   744     {
   745 	SWT_LOG_FUNC_CALL();
   745     SWT_LOG_FUNC_CALL();
   746 	return headingTxtSize;
   746     return headingTxtSize;
   747 	}
   747     }
   748 	
   748     
   749 QPoint ListBoxModel::detailImageSize(const int row) const
   749 QPoint ListBoxModel::detailImageSize(const int row) const
   750 	{
   750     {
   751 	SWT_LOG_FUNC_CALL();
   751     SWT_LOG_FUNC_CALL();
   752 	Q_ASSERT(row > -1 && row < list.size());
   752     Q_ASSERT(row > -1 && row < list.size());
   753 	return QPoint(detailImgWidth, rowHeights[row]);
   753     return QPoint(detailImgWidth, rowHeights[row]);
   754 	}
   754     }
   755 	
   755     
   756 QPoint ListBoxModel::headingImageSize(const int row) const
   756 QPoint ListBoxModel::headingImageSize(const int row) const
   757 	{
   757     {
   758 	SWT_LOG_FUNC_CALL();
   758     SWT_LOG_FUNC_CALL();
   759 	Q_ASSERT(row > -1 && row < list.size());
   759     Q_ASSERT(row > -1 && row < list.size());
   760 	return QPoint(headingImgWidth, rowHeights[row]);
   760     return QPoint(headingImgWidth, rowHeights[row]);
   761 	}
   761     }
   762 	
   762     
   763 int ListBoxModel::rowWithMaxDetailTextSize() const
   763 int ListBoxModel::rowWithMaxDetailTextSize() const
   764 	{
   764     {
   765 	SWT_LOG_FUNC_CALL();
   765     SWT_LOG_FUNC_CALL();
   766 	return detailTxtIndex;
   766     return detailTxtIndex;
   767 	}
   767     }
   768 	
   768     
   769 int ListBoxModel::rowWithMaxHeadingTextSize() const
   769 int ListBoxModel::rowWithMaxHeadingTextSize() const
   770 	{
   770     {
   771 	SWT_LOG_FUNC_CALL();
   771     SWT_LOG_FUNC_CALL();
   772 	return headingTxtIndex;
   772     return headingTxtIndex;
   773 	}
   773     }
   774 
   774 
   775 void ListBoxModel::setItemContentsToNull( const int row )
   775 void ListBoxModel::setItemContentsToNull( const int row )
   776     {
   776     {
   777     SWT_LOG_FUNC_CALL();
   777     SWT_LOG_FUNC_CALL();
   778     Q_ASSERT(row > -1 && row < list.size());
   778     Q_ASSERT(row > -1 && row < list.size());
   779     static_cast<ListBoxItem*>(list.at(row))->setContentsToNull( );
   779     static_cast<ListBoxItem*>(list.at(row))->setContentsToNull( );
   780     }	
   780     }   
   781 	
   781     
   782 ListItem* ListBoxModel::createItem(const QString& aDetailText, const QPixmap** aDetailImages, const int aDetailImageCount,  
   782 ListItem* ListBoxModel::createItem(const QString& aDetailText, const QPixmap* aDetailImages, const int aDetailImageCount,  
   783 	const QString& aHeadingText, const QPixmap** aHeadingImages, const int aHeadingImageCount )
   783     const QString& aHeadingText, const QPixmap* aHeadingImages, const int aHeadingImageCount )
   784 	{
   784     {
   785 	SWT_LOG_FUNC_CALL();
   785     SWT_LOG_FUNC_CALL();
   786 	
   786     
   787 	ListItem* item =  new ListBoxItem( aDetailText, aDetailImages, aDetailImageCount, aHeadingText, aHeadingImages, aHeadingImageCount );
   787     ListItem* item =  new ListBoxItem( aDetailText, aDetailImages, aDetailImageCount, aHeadingText, aHeadingImages, aHeadingImageCount );
   788 	if( !item )
   788     if( !item )
   789 		{	
   789         {   
   790        	throw std::bad_alloc();
   790         throw std::bad_alloc();
   791 		}
   791         }
   792 		
   792         
   793 	return item;	
   793     return item;    
   794 	}
   794     }
   795 
   795 
   796 
   796 
   797 
   797 
   798 	
   798     
   799 /**
   799 /**
   800  *  ListItemDelegate
   800  *  ListItemDelegate
   801  */	
   801  */ 
   802 
   802 
   803 ListBoxItemDelegate::ListBoxItemDelegate( QObject * parent ) 
   803 ListBoxItemDelegate::ListBoxItemDelegate( QObject * parent ) 
   804 	: QItemDelegate( parent ),
   804     : QItemDelegate( parent ),
   805 	headingFont( NULL )
   805     headingFont( NULL )
   806 	{
   806     {
   807 	SWT_LOG_FUNC_CALL();
   807     SWT_LOG_FUNC_CALL();
   808 	QListView* listView = static_cast< QListView* >( parent );
   808     QListView* listView = static_cast< QListView* >( parent );
   809 	dataModel = static_cast < ListBoxModel* > ( listView->model() );
   809     dataModel = static_cast < ListBoxModel* > ( listView->model() );
   810 	}
   810     }
   811 	
   811     
   812 void ListBoxItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
   812 void ListBoxItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
   813 	{
   813     {
   814 	SWT_LOG_FUNC_CALL();
   814     SWT_LOG_FUNC_CALL();
   815 
   815 
   816     Q_ASSERT(index.isValid());
   816     Q_ASSERT(index.isValid());
   817 
   817 
   818 	// setup option
   818     // setup option
   819     QStyleOptionViewItemV3 opt = setOptions(index, option);
   819     QStyleOptionViewItemV3 opt = setOptions(index, option);
   820     const QStyleOptionViewItemV2* v2 = qstyleoption_cast<const QStyleOptionViewItemV2 *>(&option);
   820     const QStyleOptionViewItemV2* v2 = qstyleoption_cast<const QStyleOptionViewItemV2 *>(&option);
   821     opt.features = v2 ? v2->features : QStyleOptionViewItemV2::ViewItemFeatures(QStyleOptionViewItemV2::None);
   821     opt.features = v2 ? v2->features : QStyleOptionViewItemV2::ViewItemFeatures(QStyleOptionViewItemV2::None);
   822     const QStyleOptionViewItemV3 *v3 = qstyleoption_cast<const QStyleOptionViewItemV3 *>(&option);
   822     const QStyleOptionViewItemV3 *v3 = qstyleoption_cast<const QStyleOptionViewItemV3 *>(&option);
   823     opt.locale = v3 ? v3->locale : QLocale();
   823     opt.locale = v3 ? v3->locale : QLocale();
   827     painter->setClipRect(opt.rect);
   827     painter->setClipRect(opt.rect);
   828  
   828  
   829     
   829     
   830     // retrieve cached layout data from data model
   830     // retrieve cached layout data from data model
   831     const int row = index.row();
   831     const int row = index.row();
   832 	QRect headingImageRect(QPoint(0, 0), dataModel->headingImageSize(row));
   832     QRect headingImageRect(QPoint(0, 0), dataModel->headingImageSize(row));
   833 	QRect detailImageRect(QPoint(0, 0),  dataModel->detailImageSize(row));
   833     QRect detailImageRect(QPoint(0, 0),  dataModel->detailImageSize(row));
   834 	QRect headingTextRect(QPoint(0, 0),  dataModel->headingTextSize());
   834     QRect headingTextRect(QPoint(0, 0),  dataModel->headingTextSize());
   835 	QRect detailTextRect(QPoint(0, 0),  dataModel->detailTextSize());
   835     QRect detailTextRect(QPoint(0, 0),  dataModel->detailTextSize());
   836 	
   836     
   837 	// get check rectangle
   837     // get check rectangle
   838 	Qt::CheckState checkState = static_cast<Qt::CheckState>(dataModel->data(index, Qt::CheckStateRole).toInt());
   838     Qt::CheckState checkState = static_cast<Qt::CheckState>(dataModel->data(index, Qt::CheckStateRole).toInt());
   839 	QRect checkRect = (dataModel->flags(index) & Qt::ItemIsUserCheckable) != 0  ? check( opt, opt.rect, checkState ) : QRect();
   839     QRect checkRect = (dataModel->flags(index) & Qt::ItemIsUserCheckable) != 0  ? check( opt, opt.rect, checkState ) : QRect();
   840 	if(checkRect.isValid())
   840     if(checkRect.isValid())
   841 		{
   841         {
   842 		checkRect.setRight(checkRect.right() + 2 * margin(opt));	
   842         checkRect.setRight(checkRect.right() + 2 * margin(opt));    
   843 		}
   843         }
   844 		
   844         
   845 	doLayout( option, &checkRect, &headingImageRect, &detailImageRect, & headingTextRect, &detailTextRect );
   845     doLayout( option, &checkRect, &headingImageRect, &detailImageRect, & headingTextRect, &detailTextRect );
   846 
   846 
   847 	const int layoutStyle = dataModel->style();
   847     const int layoutStyle = dataModel->style();
   848 	
   848     
   849     drawBackground(painter, opt, index);
   849     drawBackground(painter, opt, index);
   850     
   850     
   851     if(checkRect.isValid())
   851     if(checkRect.isValid())
   852 	    {
   852         {
   853 	    drawCheck( painter, opt, checkRect, checkState );
   853         drawCheck( painter, opt, checkRect, checkState );
   854 	    }
   854         }
   855     
   855     
   856     // draw heading images
   856     // draw heading images
   857 	if ( ( layoutStyle & LB_MOD_SHOW_HEADING_ICONS ) != 0 && dataModel->headingImageCount(row) > 0 )
   857     if ( ( layoutStyle & LB_MOD_SHOW_HEADING_ICONS ) != 0 && dataModel->headingImageCount(row) > 0 )
   858 		{
   858         {
   859 		drawImages( painter, opt, headingImageRect, dataModel->headingImages(row), &(dataModel->headingImageWidth(0)), dataModel->headingImageCount(row) );
   859         drawImages( painter, opt, headingImageRect, dataModel->headingImages(row), &(dataModel->headingImageWidth(0)), dataModel->headingImageCount(row) );
   860 		}
   860         }
   861 		
   861         
   862 	// draw detail images	
   862     // draw detail images   
   863 	if ( ( layoutStyle & LB_MOD_SHOW_DETAIL_ICONS ) != 0 && dataModel->detailImageCount(row) > 0 )
   863     if ( ( layoutStyle & LB_MOD_SHOW_DETAIL_ICONS ) != 0 && dataModel->detailImageCount(row) > 0 )
   864 		{
   864         {
   865 		drawImages( painter, opt, detailImageRect, dataModel->detailImages(row), &(dataModel->detailImageWidth(0)), dataModel->detailImageCount(row) );
   865         drawImages( painter, opt, detailImageRect, dataModel->detailImages(row), &(dataModel->detailImageWidth(0)), dataModel->detailImageCount(row) );
   866 		}
   866         }
   867 		
   867         
   868 	// draw detail text	
   868     // draw detail text 
   869 	if(detailTextRect.isValid())
   869     if(detailTextRect.isValid())
   870 		{
   870         {
   871 		SWT_LOG_DATA_4("Draw detail text; size=(%d, %d); topleft=(%d, %d)", detailTextRect.width(), detailTextRect.height(), detailTextRect.left(), detailTextRect.top() );   
   871         SWT_LOG_DATA_4("Draw detail text; size=(%d, %d); topleft=(%d, %d)", detailTextRect.width(), detailTextRect.height(), detailTextRect.left(), detailTextRect.top() );   
   872 	    drawDisplay( painter, opt, detailTextRect, dataModel->data(index, Qt::DisplayRole).toString() );
   872         drawDisplay( painter, opt, detailTextRect, dataModel->data(index, Qt::DisplayRole).toString() );
   873 	    drawFocus( painter, opt, detailTextRect);
   873         drawFocus( painter, opt, detailTextRect);
   874 		}
   874         }
   875     
   875     
   876 	// draw heading text
   876     // draw heading text
   877 	if ( headingTextRect.isValid() && ( ( layoutStyle & LB_STYLE_1LINE_ITEM ) != 0 ||  ( layoutStyle & LB_STYLE_2LINE_ITEM ) != 0  ))
   877     if ( headingTextRect.isValid() && ( ( layoutStyle & LB_STYLE_1LINE_ITEM ) != 0 ||  ( layoutStyle & LB_STYLE_2LINE_ITEM ) != 0  ))
   878 		{
   878         {
   879 	    if ( headingFont != NULL)
   879         if ( headingFont != NULL)
   880 	    	{
   880             {
   881 	        opt.font = *headingFont;
   881             opt.font = *headingFont;
   882 	        opt.fontMetrics = QFontMetrics( *headingFont );
   882             opt.fontMetrics = QFontMetrics( *headingFont );
   883 	    	}
   883             }
   884 			
   884             
   885 		SWT_LOG_DATA_4("Draw heading text; size=(%d, %d); topleft=(%d, %d)", headingTextRect.width(), headingTextRect.height(), headingTextRect.right(), headingTextRect.top() );   
   885         SWT_LOG_DATA_4("Draw heading text; size=(%d, %d); topleft=(%d, %d)", headingTextRect.width(), headingTextRect.height(), headingTextRect.right(), headingTextRect.top() );   
   886 		drawDisplay(painter, opt, headingTextRect, dataModel->headingText(row) );
   886         drawDisplay(painter, opt, headingTextRect, dataModel->headingText(row) );
   887     	drawFocus(painter, opt, headingTextRect);
   887         drawFocus(painter, opt, headingTextRect);
   888 		}
   888         }
   889 		
   889         
   890     painter->restore();
   890     painter->restore();
   891     
   891     
   892 	}
   892     }
   893 
   893 
   894 void ListBoxItemDelegate::computeSizes( const QModelIndex& index, const QStyleOptionViewItem& option, QSize* checkSize, 
   894 void ListBoxItemDelegate::computeSizes( const QModelIndex& index, const QStyleOptionViewItem& option, QSize* checkSize, 
   895 	QSize *headingImageSize, QSize* detailImageSize, QSize* headingTextSize, QSize* detailTextSize ) const
   895     QSize *headingImageSize, QSize* detailImageSize, QSize* headingTextSize, QSize* detailTextSize ) const
   896  	{
   896     {
   897  	SWT_LOG_FUNC_CALL();
   897     SWT_LOG_FUNC_CALL();
   898 	const int layoutStyle = dataModel->style();
   898     const int layoutStyle = dataModel->style();
   899 	
   899     
   900 	 int imageMargin = margin(option);
   900      int imageMargin = margin(option);
   901 	 // go through every columns of heading images to get width of entire heading image area
   901      // go through every columns of heading images to get width of entire heading image area
   902 	 // go through every heading images in the row to get the height of entire heading image area
   902      // go through every heading images in the row to get the height of entire heading image area
   903      if ( ( layoutStyle & LB_MOD_SHOW_HEADING_ICONS ) != 0 && dataModel->headingImageCount() > 0 ) 
   903      if ( ( layoutStyle & LB_MOD_SHOW_HEADING_ICONS ) != 0 && dataModel->headingImageCount() > 0 ) 
   904 		{
   904         {
   905 		int width = 0;	
   905         int width = 0;  
   906 		int height = 0;
   906         int height = 0;
   907 		int headingImageCount = dataModel->headingImageCount();
   907         int headingImageCount = dataModel->headingImageCount();
   908 		int itemHeadingImageCount = dataModel->headingImageCount(index.row());
   908         int itemHeadingImageCount = dataModel->headingImageCount(index.row());
   909 		const QPixmap* pixmap;
   909         const QPixmap* pixmap;
   910 		for( int i = 0; i < headingImageCount; i++)   
   910         for( int i = 0; i < headingImageCount; i++)   
   911 			{
   911             {
   912 			width += dataModel->headingImageWidth(i);
   912             width += dataModel->headingImageWidth(i);
   913 			pixmap = &(dataModel->headingImages(index.row())[i]);
   913             pixmap = &(dataModel->headingImages(index.row())[i]);
   914 			if(i <  itemHeadingImageCount && pixmap)
   914             if(i <  itemHeadingImageCount && pixmap)
   915 				{
   915                 {
   916 				if( pixmap->size().height() > height )
   916                 if( pixmap->size().height() > height )
   917 					{
   917                     {
   918 					height = pixmap->size().height();
   918                     height = pixmap->size().height();
   919 					}
   919                     }
   920 				}
   920                 }
   921 			}
   921             }
   922 		width += (headingImageCount - 1) * imageMargin;	
   922         width += (headingImageCount - 1) * imageMargin; 
   923 		*headingImageSize = QSize( width, height );
   923         *headingImageSize = QSize( width, height );
   924  		SWT_LOG_DATA_3("heading image rect row=%d; size=(%d, %d);", index.row(), headingImageSize->width(), headingImageSize->height() );   
   924         SWT_LOG_DATA_3("heading image rect row=%d; size=(%d, %d);", index.row(), headingImageSize->width(), headingImageSize->height() );   
   925 		} 
   925         } 
   926      else
   926      else
   927 		{
   927         {
   928 		*headingImageSize = QSize();
   928         *headingImageSize = QSize();
   929 		}	
   929         }   
   930 
   930 
   931 	 // go through every columns of detail images to get width of entire detail image area
   931      // go through every columns of detail images to get width of entire detail image area
   932 	 // go through every detail images in the row to get height of entire detial image area
   932      // go through every detail images in the row to get height of entire detial image area
   933      if ( ( layoutStyle & LB_MOD_SHOW_DETAIL_ICONS ) != 0 && dataModel->detailImageCount() > 0 ) 
   933      if ( ( layoutStyle & LB_MOD_SHOW_DETAIL_ICONS ) != 0 && dataModel->detailImageCount() > 0 ) 
   934     	{
   934         {
   935 		int width = 0;	
   935         int width = 0;  
   936 		int height = 0;
   936         int height = 0;
   937 		int detailImageCount = dataModel->detailImageCount();
   937         int detailImageCount = dataModel->detailImageCount();
   938 		int itemDetailImageCount = dataModel->detailImageCount(index.row());
   938         int itemDetailImageCount = dataModel->detailImageCount(index.row());
   939 		const QPixmap* pixmap;
   939         const QPixmap* pixmap;
   940 		for( int i = 0; i < detailImageCount; i++)   
   940         for( int i = 0; i < detailImageCount; i++)   
   941 			{
   941             {
   942 			width += dataModel->detailImageWidth(i);
   942             width += dataModel->detailImageWidth(i);
   943 			pixmap = &(dataModel->detailImages(index.row())[i]);
   943             pixmap = &(dataModel->detailImages(index.row())[i]);
   944 			if(i <  itemDetailImageCount && pixmap)
   944             if(i <  itemDetailImageCount && pixmap)
   945 				{
   945                 {
   946 				if( pixmap->size().height() > height )
   946                 if( pixmap->size().height() > height )
   947 					{
   947                     {
   948 					height = pixmap->size().height();
   948                     height = pixmap->size().height();
   949 					}
   949                     }
   950 				}
   950                 }
   951 			}
   951             }
   952 		width += (detailImageCount - 1) * imageMargin;	
   952         width += (detailImageCount - 1) * imageMargin;  
   953 		*detailImageSize = QSize( width, height );
   953         *detailImageSize = QSize( width, height );
   954  		SWT_LOG_DATA_3("detail image rect row=%d; size=(%d, %d);", index.row(), detailImageSize->width(), detailImageSize->height() );   
   954         SWT_LOG_DATA_3("detail image rect row=%d; size=(%d, %d);", index.row(), detailImageSize->width(), detailImageSize->height() );   
   955     	}
   955         }
   956     else	 
   956     else     
   957     	{
   957         {
   958     	*detailImageSize = QSize();
   958         *detailImageSize = QSize();
   959     	}
   959         }
   960 
   960 
   961 	const QStyleOptionViewItemV2* v2 = qstyleoption_cast< const QStyleOptionViewItemV2* >(&option);
   961     const QStyleOptionViewItemV2* v2 = qstyleoption_cast< const QStyleOptionViewItemV2* >(&option);
   962     const bool wrapText = v2->features & QStyleOptionViewItemV2::WrapText;
   962     const bool wrapText = v2->features & QStyleOptionViewItemV2::WrapText;
   963     const int width = wrapText && option.rect.isValid() ? option.rect.width() : 0xffff;
   963     const int width = wrapText && option.rect.isValid() ? option.rect.width() : 0xffff;
   964 	
   964     
   965 	// compute width of heading text upon the item which has the longest heading text
   965     // compute width of heading text upon the item which has the longest heading text
   966 	int row;
   966     int row;
   967 	if ( ( layoutStyle & LB_STYLE_1LINE_ITEM ) != 0  || ( layoutStyle & LB_STYLE_2LINE_ITEM ) != 0 ) 
   967     if ( ( layoutStyle & LB_STYLE_1LINE_ITEM ) != 0  || ( layoutStyle & LB_STYLE_2LINE_ITEM ) != 0 ) 
   968 		{
   968         {
   969 		row = dataModel->rowWithMaxHeadingTextSize();
   969         row = dataModel->rowWithMaxHeadingTextSize();
   970 		if( row > -1)
   970         if( row > -1)
   971 			{
   971             {
   972 			const QString& text = dataModel->headingText( row );
   972             const QString& text = dataModel->headingText( row );
   973 			if( !text.isNull() )
   973             if( !text.isNull() )
   974 				{
   974                 {
   975 				const QFont& font = headingFont ? *headingFont : option.font;
   975                 const QFont& font = headingFont ? *headingFont : option.font;
   976 				*headingTextSize = textRectangle( width, font, text ).size();
   976                 *headingTextSize = textRectangle( width, font, text ).size();
   977 				}
   977                 }
   978 			}
   978             }
   979 		}
   979         }
   980 	else
   980     else
   981 		{
   981         {
   982 		*headingTextSize = QSize();
   982         *headingTextSize = QSize();
   983 		}
   983         }
   984 	    
   984         
   985 	// compute width of detail text upon the item which has the longest detail text
   985     // compute width of detail text upon the item which has the longest detail text
   986 	row = dataModel->rowWithMaxDetailTextSize();
   986     row = dataModel->rowWithMaxDetailTextSize();
   987 	if( row > -1)
   987     if( row > -1)
   988 		{
   988         {
   989 		const QString& text = dataModel->data( index, Qt::DisplayRole).toString();
   989         const QString& text = dataModel->data( index, Qt::DisplayRole).toString();
   990 		if( !text.isNull() )
   990         if( !text.isNull() )
   991 			{
   991             {
   992 			*detailTextSize = textRectangle( width, option.font, text ).size();
   992             *detailTextSize = textRectangle( width, option.font, text ).size();
   993 			}
   993             }
   994 		}
   994         }
   995 	else
   995     else
   996 		{
   996         {
   997 		*detailTextSize = QSize();
   997         *detailTextSize = QSize();
   998 		}
   998         }
   999 		
   999         
  1000 
  1000 
  1001     *checkSize = check( option, option.rect, Qt::Unchecked ).size();
  1001     *checkSize = check( option, option.rect, Qt::Unchecked ).size();
  1002   }
  1002   }
  1003 
  1003 
  1004 void ListBoxItemDelegate::addMargins( const QStyleOptionViewItem &option, QSize* checkSize, 
  1004 void ListBoxItemDelegate::addMargins( const QStyleOptionViewItem &option, QSize* checkSize, 
  1005 	QSize* headingImageSize, QSize* detailImageSize, QSize* headingTextSize, QSize* detailTextSize ) const
  1005     QSize* headingImageSize, QSize* detailImageSize, QSize* headingTextSize, QSize* detailTextSize ) const
  1006 	{
  1006     {
  1007  	SWT_LOG_FUNC_CALL();
  1007     SWT_LOG_FUNC_CALL();
  1008  	
  1008     
  1009     const bool hasCheck = checkSize->isValid();
  1009     const bool hasCheck = checkSize->isValid();
  1010     const bool hasHeadingImage = headingImageSize->isValid();
  1010     const bool hasHeadingImage = headingImageSize->isValid();
  1011     const bool hasDetailImage = detailImageSize->isValid();
  1011     const bool hasDetailImage = detailImageSize->isValid();
  1012  
  1012  
  1013     const int pixmapMargin = margin(option);
  1013     const int pixmapMargin = margin(option);
  1015     
  1015     
  1016     // don't need to add margin to text since text size includes margin
  1016     // don't need to add margin to text since text size includes margin
  1017     
  1017     
  1018     // set height for text if text height is 0 and there is no image
  1018     // set height for text if text height is 0 and there is no image
  1019     if ( detailTextSize->height() == 0 && !hasHeadingImage && !hasDetailImage  )
  1019     if ( detailTextSize->height() == 0 && !hasHeadingImage && !hasDetailImage  )
  1020     	{
  1020         {
  1021         detailTextSize->setHeight( option.fontMetrics.height() );
  1021         detailTextSize->setHeight( option.fontMetrics.height() );
  1022      	}
  1022         }
  1023  	if ( headingTextSize->height() == 0 && !hasHeadingImage && !hasDetailImage )
  1023     if ( headingTextSize->height() == 0 && !hasHeadingImage && !hasDetailImage )
  1024     	{
  1024         {
  1025 	    if ( headingFont )
  1025         if ( headingFont )
  1026 		    {
  1026             {
  1027 	        headingTextSize->setHeight( QFontMetrics( *headingFont ).height() );
  1027             headingTextSize->setHeight( QFontMetrics( *headingFont ).height() );
  1028 		    }
  1028             }
  1029 		else
  1029         else
  1030 			{
  1030             {
  1031 			headingTextSize->setHeight( detailTextSize->height() );	
  1031             headingTextSize->setHeight( detailTextSize->height() ); 
  1032 			}	    
  1032             }       
  1033 	    }
  1033         }
  1034 
  1034 
  1035 
  1035 
  1036     if ( hasHeadingImage ) 
  1036     if ( hasHeadingImage ) 
  1037     	{
  1037         {
  1038   	    headingImageSize->rwidth() += pixmapMargin * 2;
  1038         headingImageSize->rwidth() += pixmapMargin * 2;
  1039     	}
  1039         }
  1040     
  1040     
  1041     if ( hasDetailImage ) 
  1041     if ( hasDetailImage ) 
  1042     	{
  1042         {
  1043   	    detailImageSize->rwidth() += pixmapMargin * 2;
  1043         detailImageSize->rwidth() += pixmapMargin * 2;
  1044      	}
  1044         }
  1045     	
  1045         
  1046     if ( hasCheck ) 
  1046     if ( hasCheck ) 
  1047     	{
  1047         {
  1048   	    checkSize->rwidth() += checkMargin * 2;
  1048         checkSize->rwidth() += checkMargin * 2;
  1049     	}
  1049         }
  1050 	}
  1050     }
  1051 
  1051 
  1052 QSize ListBoxItemDelegate::computeSize(  const QStyleOptionViewItem &option, const QSize& check, const QSize& headingImage, 
  1052 QSize ListBoxItemDelegate::computeSize(  const QStyleOptionViewItem &option, const QSize& check, const QSize& headingImage, 
  1053 	const QSize& detailImage, const QSize& headingText, const QSize& detailText ) const
  1053     const QSize& detailImage, const QSize& headingText, const QSize& detailText ) const
  1054 	{
  1054     {
  1055 	SWT_LOG_FUNC_CALL();
  1055     SWT_LOG_FUNC_CALL();
  1056  	const int layoutStyle = dataModel->style();
  1056     const int layoutStyle = dataModel->style();
  1057  	int h, w;
  1057     int h, w;
  1058     if ( ( layoutStyle &  LB_STYLE_2LINE_ITEM ) != 0 ) 
  1058     if ( ( layoutStyle &  LB_STYLE_2LINE_ITEM ) != 0 ) 
  1059         {
  1059         {
  1060 		const int textWidth = qMax( headingText.width(),  detailText.width() );	
  1060         const int textWidth = qMax( headingText.width(),  detailText.width() ); 
  1061     	const int textMargin = margin(option);
  1061         const int textMargin = margin(option);
  1062         h = qMax( check.height(), qMax( headingText.height() + detailText.height() + textMargin,
  1062         h = qMax( check.height(), qMax( headingText.height() + detailText.height() + textMargin,
  1063         	qMax( headingImage.height(), detailImage.height() ) ) );
  1063             qMax( headingImage.height(), detailImage.height() ) ) );
  1064         w = check.width() + textWidth + headingImage.width() + detailImage.width();
  1064         w = check.width() + textWidth + headingImage.width() + detailImage.width();
  1065         }
  1065         }
  1066     else 
  1066     else 
  1067     	{
  1067         {
  1068         h = qMax( check.height(), qMax( qMax( headingText.height(), detailText.height() ),
  1068         h = qMax( check.height(), qMax( qMax( headingText.height(), detailText.height() ),
  1069         	qMax( headingImage.height(), detailImage.height() ) ) );
  1069             qMax( headingImage.height(), detailImage.height() ) ) );
  1070         w = check.width() + headingText.width() + detailText.width() + headingImage.width() + detailImage.width();
  1070         w = check.width() + headingText.width() + detailText.width() + headingImage.width() + detailImage.width();
  1071     	}
  1071         }
  1072     	
  1072         
  1073     return QSize( w, h );	
  1073     return QSize( w, h );   
  1074 	}
  1074     }
  1075 
  1075 
  1076 
  1076 
  1077 void ListBoxItemDelegate::layoutRects( const QStyleOptionViewItem &option, QRect* check, QRect *headingImage, 
  1077 void ListBoxItemDelegate::layoutRects( const QStyleOptionViewItem &option, QRect* check, QRect *headingImage, 
  1078 	QRect* detailImage, QRect* headingText, QRect* detailText, bool hint ) const
  1078     QRect* detailImage, QRect* headingText, QRect* detailText, bool hint ) const
  1079 	{
  1079     {
  1080 	SWT_LOG_FUNC_CALL();
  1080     SWT_LOG_FUNC_CALL();
  1081 	
  1081     
  1082 	const int layoutStyle = dataModel->style();
  1082     const int layoutStyle = dataModel->style();
  1083  	int h, w; 
  1083     int h, w; 
  1084  	int textWidth;
  1084     int textWidth;
  1085  	if( ( layoutStyle & LB_STYLE_2LINE_ITEM ) != 0 )
  1085     if( ( layoutStyle & LB_STYLE_2LINE_ITEM ) != 0 )
  1086 	 	{
  1086         {
  1087  		textWidth = qMax( headingText->width(),  detailText->width() );
  1087         textWidth = qMax( headingText->width(),  detailText->width() );
  1088 	 	}
  1088         }
  1089  	else
  1089     else
  1090 	 	{
  1090         {
  1091  		textWidth = headingText->width() + detailText->width();
  1091         textWidth = headingText->width() + detailText->width();
  1092 	 	}
  1092         }
  1093  	
  1093     
  1094     if ( hint )
  1094     if ( hint )
  1095 	    {
  1095         {
  1096 		QSize size = computeSize( option, check->size(), headingImage->size(), detailImage->size(), headingText->size(), detailText->size() );
  1096         QSize size = computeSize( option, check->size(), headingImage->size(), detailImage->size(), headingText->size(), detailText->size() );
  1097 		h = size.height();
  1097         h = size.height();
  1098 		w = size.width();
  1098         w = size.width();
  1099 	    }
  1099         }
  1100 	else
  1100     else
  1101 		{
  1101         {
  1102         w = option.rect.width();
  1102         w = option.rect.width();
  1103         h = option.rect.height();
  1103         h = option.rect.height();
  1104 		} 
  1104         } 
  1105 	const int x = option.rect.left(), y = option.rect.top();   
  1105     const int x = option.rect.left(), y = option.rect.top();   
  1106 	SWT_LOG_DATA_4("space for layout: size=(%d, %d); topleft=(%d, %d)", w, h, x, y );   
  1106     SWT_LOG_DATA_4("space for layout: size=(%d, %d); topleft=(%d, %d)", w, h, x, y );   
  1107 	
  1107     
  1108     int leftX = x, rightX = x + w;	
  1108     int leftX = x, rightX = x + w;  
  1109 	if ( option.direction == Qt::RightToLeft ) 
  1109     if ( option.direction == Qt::RightToLeft ) 
  1110      	{
  1110         {
  1111      	if ( check->isValid() )	
  1111         if ( check->isValid() ) 
  1112          	{
  1112             {
  1113             check->setRect( qMax( rightX - check->width(), leftX ) , y, qMin( check->width(), rightX - leftX ), h );
  1113             check->setRect( qMax( rightX - check->width(), leftX ) , y, qMin( check->width(), rightX - leftX ), h );
  1114             rightX = check->left();
  1114             rightX = check->left();
  1115          	}
  1115             }
  1116          	
  1116             
  1117         if ( headingImage->isValid() )
  1117         if ( headingImage->isValid() )
  1118         	{
  1118             {
  1119         	if ( rightX > leftX )
  1119             if ( rightX > leftX )
  1120             	{	
  1120                 {   
  1121             	headingImage->setRect( qMax( rightX - headingImage->width(), leftX ), y, qMin( headingImage->width(), rightX - leftX  ) , h );
  1121                 headingImage->setRect( qMax( rightX - headingImage->width(), leftX ), y, qMin( headingImage->width(), rightX - leftX  ) , h );
  1122             	rightX = headingImage->left();
  1122                 rightX = headingImage->left();
  1123             	}
  1123                 }
  1124         	else
  1124             else
  1125             	{
  1125                 {
  1126             	*headingImage = QRect();
  1126                 *headingImage = QRect();
  1127             	}
  1127                 }
  1128         	} 
  1128             } 
  1129         	
  1129             
  1130         if ( detailImage->isValid() )
  1130         if ( detailImage->isValid() )
  1131         	{
  1131             {
  1132         	if (  rightX > leftX  )
  1132             if (  rightX > leftX  )
  1133             	{
  1133                 {
  1134             	int detailImageX = leftX;
  1134                 int detailImageX = leftX;
  1135             	int detailImageWidth = detailImage->width();
  1135                 int detailImageWidth = detailImage->width();
  1136             	if( (rightX -leftX) >= (textWidth + detailImageWidth) )
  1136                 if( (rightX -leftX) >= (textWidth + detailImageWidth) )
  1137 	            	{
  1137                     {
  1138 	            	detailImageX = rightX - textWidth - detailImageWidth;
  1138                     detailImageX = rightX - textWidth - detailImageWidth;
  1139 	            	}
  1139                     }
  1140             	else
  1140                 else
  1141 	            	{
  1141                     {
  1142 	            	detailImageX = qMin( rightX, leftX + detailImageWidth );
  1142                     detailImageX = qMin( rightX, leftX + detailImageWidth );
  1143 	             	}
  1143                     }
  1144            		detailImage->setRect( detailImageX, y, qMin( detailImageWidth, rightX - detailImageX ), h );
  1144                 detailImage->setRect( detailImageX, y, qMin( detailImageWidth, rightX - detailImageX ), h );
  1145             	leftX = detailImage->right();
  1145                 leftX = detailImage->right();
  1146             	}
  1146                 }
  1147         	else
  1147             else
  1148             	{
  1148                 {
  1149             	*detailImage = QRect();
  1149                 *detailImage = QRect();
  1150             	}
  1150                 }
  1151         	}
  1151             }
  1152         	
  1152             
  1153         if (  ( layoutStyle & LB_STYLE_2LINE_ITEM ) != 0 )
  1153         if (  ( layoutStyle & LB_STYLE_2LINE_ITEM ) != 0 )
  1154             {
  1154             {
  1155             if ( rightX > leftX )	
  1155             if ( rightX > leftX )   
  1156 	            {
  1156                 {
  1157 		    	const int textMargin = margin(option);
  1157                 const int textMargin = margin(option);
  1158     			headingText->setRect( qMax( leftX, rightX - textWidth ), y, qMin( textWidth, rightX - leftX ), headingText->height() );
  1158                 headingText->setRect( qMax( leftX, rightX - textWidth ), y, qMin( textWidth, rightX - leftX ), headingText->height() );
  1159     			detailText->setRect( headingText->left(), headingText->bottom() + textMargin, headingText->width(), detailText->height() );
  1159                 detailText->setRect( headingText->left(), headingText->bottom() + textMargin, headingText->width(), detailText->height() );
  1160 	            }
  1160                 }
  1161 	        else
  1161             else
  1162 		        {
  1162                 {
  1163 		        *headingText = QRect();	
  1163                 *headingText = QRect(); 
  1164 		        *detailText = QRect();	
  1164                 *detailText = QRect();  
  1165 		        }    
  1165                 }    
  1166             }
  1166             }
  1167         else
  1167         else
  1168 	        {
  1168             {
  1169             if ( headingText->isValid() )	
  1169             if ( headingText->isValid() )   
  1170 	            {
  1170                 {
  1171 	            if ( rightX > leftX )
  1171                 if ( rightX > leftX )
  1172 		            {
  1172                     {
  1173 	            	headingText->setRect( qMax( rightX - headingText->width(), leftX ), y, qMin( headingText->width(), rightX - leftX  ) , h );
  1173                     headingText->setRect( qMax( rightX - headingText->width(), leftX ), y, qMin( headingText->width(), rightX - leftX  ) , h );
  1174 	            	rightX = headingText->left();
  1174                     rightX = headingText->left();
  1175 		            }
  1175                     }
  1176 		        else 
  1176                 else 
  1177 		        	{
  1177                     {
  1178 			        *headingText = QRect();	
  1178                     *headingText = QRect(); 
  1179 		        	}
  1179                     }
  1180 	            }  
  1180                 }  
  1181 	              
  1181                   
  1182             if ( detailText->isValid() )	
  1182             if ( detailText->isValid() )    
  1183 	            {
  1183                 {
  1184 	            if ( rightX > leftX )
  1184                 if ( rightX > leftX )
  1185 		            {
  1185                     {
  1186 	            	detailText->setRect( qMax( rightX - detailText->width(), leftX ), y, qMin( detailText->width(), rightX - leftX  ) , h );
  1186                     detailText->setRect( qMax( rightX - detailText->width(), leftX ), y, qMin( detailText->width(), rightX - leftX  ) , h );
  1187 		            }
  1187                     }
  1188 		        else 
  1188                 else 
  1189 		        	{
  1189                     {
  1190 			        *detailText = QRect();	
  1190                     *detailText = QRect();  
  1191 		        	}
  1191                     }
  1192 	            }    
  1192                 }    
  1193 	        }  
  1193             }  
  1194      	}
  1194         }
  1195  	else // left to right
  1195     else // left to right
  1196      	{
  1196         {
  1197      	if (check->isValid() )	
  1197         if (check->isValid() )  
  1198          	{
  1198             {
  1199             check->setRect( leftX, y, qMin( check->width(), rightX - leftX ), h );
  1199             check->setRect( leftX, y, qMin( check->width(), rightX - leftX ), h );
  1200             leftX = check->right();
  1200             leftX = check->right();
  1201          	}
  1201             }
  1202          	
  1202             
  1203         if ( headingImage->isValid() )
  1203         if ( headingImage->isValid() )
  1204         	{
  1204             {
  1205         	if ( rightX > leftX )
  1205             if ( rightX > leftX )
  1206             	{	
  1206                 {   
  1207             	headingImage->setRect( leftX, y, qMin( headingImage->width(), rightX - leftX  ) , h );
  1207                 headingImage->setRect( leftX, y, qMin( headingImage->width(), rightX - leftX  ) , h );
  1208             	leftX = headingImage->right();
  1208                 leftX = headingImage->right();
  1209             	}
  1209                 }
  1210         	else
  1210             else
  1211             	{
  1211                 {
  1212             	*headingImage = QRect();
  1212                 *headingImage = QRect();
  1213             	}
  1213                 }
  1214         	} 
  1214             } 
  1215         	
  1215             
  1216         if ( detailImage->isValid() )
  1216         if ( detailImage->isValid() )
  1217         	{
  1217             {
  1218         	if (  rightX > leftX  )
  1218             if (  rightX > leftX  )
  1219             	{
  1219                 {
  1220             	int detailImageX = leftX;
  1220                 int detailImageX = leftX;
  1221             	int detailImageWidth = detailImage->width();
  1221                 int detailImageWidth = detailImage->width();
  1222             	if( (rightX -leftX) >= (textWidth + detailImageWidth) )
  1222                 if( (rightX -leftX) >= (textWidth + detailImageWidth) )
  1223 	            	{
  1223                     {
  1224 	            	detailImageX = leftX + textWidth;
  1224                     detailImageX = leftX + textWidth;
  1225 	            	}
  1225                     }
  1226             	else
  1226                 else
  1227 	            	{
  1227                     {
  1228 	            	detailImageX = qMax( leftX, rightX - detailImageWidth );
  1228                     detailImageX = qMax( leftX, rightX - detailImageWidth );
  1229 	             	}
  1229                     }
  1230            		detailImage->setRect( detailImageX, y, qMin( detailImageWidth, rightX - detailImageX ), h );
  1230                 detailImage->setRect( detailImageX, y, qMin( detailImageWidth, rightX - detailImageX ), h );
  1231             	rightX = detailImage->left();
  1231                 rightX = detailImage->left();
  1232             	}
  1232                 }
  1233         	else
  1233             else
  1234             	{
  1234                 {
  1235             	*detailImage = QRect();
  1235                 *detailImage = QRect();
  1236             	}
  1236                 }
  1237         	}
  1237             }
  1238         	
  1238             
  1239         if (  ( layoutStyle & LB_STYLE_2LINE_ITEM ) != 0 )
  1239         if (  ( layoutStyle & LB_STYLE_2LINE_ITEM ) != 0 )
  1240             {
  1240             {
  1241             if ( rightX > leftX )	
  1241             if ( rightX > leftX )   
  1242 	            {
  1242                 {
  1243 				const QStyleOptionViewItemV3 *v3 = qstyleoption_cast<const QStyleOptionViewItemV3 *>(&option);
  1243                 const QStyleOptionViewItemV3 *v3 = qstyleoption_cast<const QStyleOptionViewItemV3 *>(&option);
  1244 				const QWidget* widget = v3 ? v3->widget : NULL;
  1244                 const QWidget* widget = v3 ? v3->widget : NULL;
  1245 			    QStyle* style = widget ? widget->style() : QApplication::style();
  1245                 QStyle* style = widget ? widget->style() : QApplication::style();
  1246 		    	const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, widget) + 1;
  1246                 const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, widget) + 1;
  1247     			headingText->setRect( leftX , y,  qMin( textWidth, rightX - leftX ), headingText->height() );
  1247                 headingText->setRect( leftX , y,  qMin( textWidth, rightX - leftX ), headingText->height() );
  1248     			detailText->setRect( headingText->left(), headingText->bottom() + textMargin, headingText->width(), detailText->height() );
  1248                 detailText->setRect( headingText->left(), headingText->bottom() + textMargin, headingText->width(), detailText->height() );
  1249 	            }
  1249                 }
  1250 	        else
  1250             else
  1251 		        {
  1251                 {
  1252 		        *headingText = QRect();	
  1252                 *headingText = QRect(); 
  1253 		        *detailText = QRect();	
  1253                 *detailText = QRect();  
  1254 		        }    
  1254                 }    
  1255             }
  1255             }
  1256         else
  1256         else
  1257 	        {
  1257             {
  1258             if ( headingText->isValid() )	
  1258             if ( headingText->isValid() )   
  1259 	            {
  1259                 {
  1260 	            if ( rightX > leftX )
  1260                 if ( rightX > leftX )
  1261 		            {
  1261                     {
  1262 	            	headingText->setRect( leftX, y, qMin( headingText->width(), rightX - leftX  ) , h );
  1262                     headingText->setRect( leftX, y, qMin( headingText->width(), rightX - leftX  ) , h );
  1263 	            	leftX = headingText->right();
  1263                     leftX = headingText->right();
  1264 		            }
  1264                     }
  1265 		        else 
  1265                 else 
  1266 		        	{
  1266                     {
  1267 			        *headingText = QRect();	
  1267                     *headingText = QRect(); 
  1268 		        	}
  1268                     }
  1269 	            }  
  1269                 }  
  1270 	              
  1270                   
  1271             if ( detailText->isValid() )	
  1271             if ( detailText->isValid() )    
  1272 	            {
  1272                 {
  1273 	            if ( rightX > leftX )
  1273                 if ( rightX > leftX )
  1274 		            {
  1274                     {
  1275 	            	detailText->setRect( leftX, y, qMin( detailText->width(), rightX - leftX  ) , h );
  1275                     detailText->setRect( leftX, y, qMin( detailText->width(), rightX - leftX  ) , h );
  1276 		            }
  1276                     }
  1277 		        else 
  1277                 else 
  1278 		        	{
  1278                     {
  1279 			        *detailText = QRect();	
  1279                     *detailText = QRect();  
  1280 		        	}
  1280                     }
  1281 	            }    
  1281                 }    
  1282 	        }  
  1282             }  
  1283     	} 
  1283         } 
  1284 	SWT_LOG_DATA_4("check rect: size=(%d, %d); topleft=(%d, %d)", check->width(), check->height(), check->left(), check->top() );   
  1284     SWT_LOG_DATA_4("check rect: size=(%d, %d); topleft=(%d, %d)", check->width(), check->height(), check->left(), check->top() );   
  1285 	SWT_LOG_DATA_4("heading image rect: size=(%d, %d); topleft=(%d, %d)", headingImage->width(), headingImage->height(), headingImage->left(), headingImage->top() );   
  1285     SWT_LOG_DATA_4("heading image rect: size=(%d, %d); topleft=(%d, %d)", headingImage->width(), headingImage->height(), headingImage->left(), headingImage->top() );   
  1286 	SWT_LOG_DATA_4("detail image rect: size=(%d, %d); topleft=(%d, %d)", detailImage->width(), detailImage->height(), detailImage->left(), detailImage->top() );   
  1286     SWT_LOG_DATA_4("detail image rect: size=(%d, %d); topleft=(%d, %d)", detailImage->width(), detailImage->height(), detailImage->left(), detailImage->top() );   
  1287 	SWT_LOG_DATA_4("heading text rect: size=(%d, %d); topleft=(%d, %d)", headingText->width(), headingText->height(), headingText->left(), headingText->top() );   
  1287     SWT_LOG_DATA_4("heading text rect: size=(%d, %d); topleft=(%d, %d)", headingText->width(), headingText->height(), headingText->left(), headingText->top() );   
  1288 	SWT_LOG_DATA_4("detail text rect: size=(%d, %d); topleft=(%d, %d)", detailText->width(), detailText->height(), detailText->left(), detailText->top() );   
  1288     SWT_LOG_DATA_4("detail text rect: size=(%d, %d); topleft=(%d, %d)", detailText->width(), detailText->height(), detailText->left(), detailText->top() );   
  1289     	 
  1289          
  1290  	}
  1290     }
  1291 
  1291 
  1292 
  1292 
  1293 void ListBoxItemDelegate::doLayout( const QStyleOptionViewItem &option, QRect* checkRect, QRect* headingImageRect,
  1293 void ListBoxItemDelegate::doLayout( const QStyleOptionViewItem &option, QRect* checkRect, QRect* headingImageRect,
  1294 	QRect* detailImageRect, QRect* headingTextRect, QRect* detailTextRect ) const
  1294     QRect* detailImageRect, QRect* headingTextRect, QRect* detailTextRect ) const
  1295 	{
  1295     {
  1296     Q_ASSERT( checkRect && headingImageRect && detailImageRect && headingTextRect && detailTextRect );
  1296     Q_ASSERT( checkRect && headingImageRect && detailImageRect && headingTextRect && detailTextRect );
  1297     
  1297     
  1298     // duplicate rects
  1298     // duplicate rects
  1299  	QRect check = *checkRect;
  1299     QRect check = *checkRect;
  1300  	QRect headingImage = *headingImageRect;
  1300     QRect headingImage = *headingImageRect;
  1301  	QRect detailImage = *detailImageRect;
  1301     QRect detailImage = *detailImageRect;
  1302  	QRect headingText = *headingTextRect;
  1302     QRect headingText = *headingTextRect;
  1303  	QRect detailText = *detailTextRect;
  1303     QRect detailText = *detailTextRect;
  1304  	
  1304     
  1305     // layout duplicated rects	
  1305     // layout duplicated rects  
  1306 	layoutRects( option, &check, &headingImage, &detailImage, &headingText, &detailText, false );
  1306     layoutRects( option, &check, &headingImage, &detailImage, &headingText, &detailText, false );
  1307 	
  1307     
  1308 
  1308 
  1309 	// remove margins
  1309     // remove margins
  1310 	const int mg = margin(option);
  1310     const int mg = margin(option);
  1311 	if( checkRect->isValid() )
  1311     if( checkRect->isValid() )
  1312 		{
  1312         {
  1313 	 	checkRect->setRight( checkRect->right() - 2 * mg );
  1313         checkRect->setRight( checkRect->right() - 2 * mg );
  1314 		}
  1314         }
  1315 	if( headingImageRect->isValid() )
  1315     if( headingImageRect->isValid() )
  1316 		{
  1316         {
  1317 	 	headingImageRect->setRight( headingImageRect->right() - 2 * mg );
  1317         headingImageRect->setRight( headingImageRect->right() - 2 * mg );
  1318 		}
  1318         }
  1319 	if( detailImageRect->isValid() )
  1319     if( detailImageRect->isValid() )
  1320 		{
  1320         {
  1321 	 	detailImageRect->setRight( detailImageRect->right() - 2 * mg );
  1321         detailImageRect->setRight( detailImageRect->right() - 2 * mg );
  1322 		}
  1322         }
  1323 	
  1323     
  1324 	// adust rectangles	
  1324     // adust rectangles 
  1325     *checkRect = QStyle::alignedRect( option.direction, Qt::AlignCenter, checkRect->size(), check );
  1325     *checkRect = QStyle::alignedRect( option.direction, Qt::AlignCenter, checkRect->size(), check );
  1326     *headingImageRect = QStyle::alignedRect( option.direction, option.decorationAlignment, headingImageRect->size(), headingImage );
  1326     *headingImageRect = QStyle::alignedRect( option.direction, option.decorationAlignment, headingImageRect->size(), headingImage );
  1327     *detailImageRect = QStyle::alignedRect( option.direction, option.decorationAlignment, detailImageRect->size().boundedTo(detailImage.size()), detailImage );
  1327     *detailImageRect = QStyle::alignedRect( option.direction, option.decorationAlignment, detailImageRect->size().boundedTo(detailImage.size()), detailImage );
  1328      if (option.showDecorationSelected)
  1328      if (option.showDecorationSelected)
  1329     	{
  1329         {
  1330     	// take up entire space	
  1330         // take up entire space 
  1331         *headingTextRect = headingText;
  1331         *headingTextRect = headingText;
  1332         *detailTextRect = detailText;
  1332         *detailTextRect = detailText;
  1333     	}
  1333         }
  1334     else
  1334     else
  1335     	{
  1335         {
  1336     	// aligne to the space
  1336         // aligne to the space
  1337         *headingTextRect = QStyle::alignedRect( option.direction, option.displayAlignment, 
  1337         *headingTextRect = QStyle::alignedRect( option.direction, option.displayAlignment, 
  1338         	headingTextRect->size().boundedTo(headingText.size()), headingText );
  1338             headingTextRect->size().boundedTo(headingText.size()), headingText );
  1339         *detailTextRect = QStyle::alignedRect( option.direction, option.displayAlignment, 
  1339         *detailTextRect = QStyle::alignedRect( option.direction, option.displayAlignment, 
  1340         	detailTextRect->size().boundedTo(detailText.size()), detailText );
  1340             detailTextRect->size().boundedTo(detailText.size()), detailText );
  1341     	}
  1341         }
  1342 	}
  1342     }
  1343 
  1343 
  1344 QSize ListBoxItemDelegate::sizeHint(const QStyleOptionViewItem &option,
  1344 QSize ListBoxItemDelegate::sizeHint(const QStyleOptionViewItem &option,
  1345 	const QModelIndex &index) const
  1345     const QModelIndex &index) const
  1346 	{
  1346     {
  1347  	SWT_LOG_FUNC_CALL();
  1347     SWT_LOG_FUNC_CALL();
  1348    	
  1348     
  1349  	QSize checkSize;
  1349     QSize checkSize;
  1350  	QSize headingImageSize;
  1350     QSize headingImageSize;
  1351  	QSize detailImageSize;
  1351     QSize detailImageSize;
  1352  	QSize headingTextSize;
  1352     QSize headingTextSize;
  1353  	QSize detailTextSize;
  1353     QSize detailTextSize;
  1354 
  1354 
  1355 	computeSizes( index, option, &checkSize, &headingImageSize, &detailImageSize, &headingTextSize, &detailTextSize ); 
  1355     computeSizes( index, option, &checkSize, &headingImageSize, &detailImageSize, &headingTextSize, &detailTextSize ); 
  1356 	addMargins( option, &checkSize, &headingImageSize, &detailImageSize, &headingTextSize, &detailTextSize ); 
  1356     addMargins( option, &checkSize, &headingImageSize, &detailImageSize, &headingTextSize, &detailTextSize ); 
  1357 	SWT_LOG_DATA_2("check size=(%d, %d) ", checkSize.width(), checkSize.height() );   
  1357     SWT_LOG_DATA_2("check size=(%d, %d) ", checkSize.width(), checkSize.height() );   
  1358 	SWT_LOG_DATA_2("heading image size=(%d, %d) ", headingImageSize.width(), headingImageSize.height() );   
  1358     SWT_LOG_DATA_2("heading image size=(%d, %d) ", headingImageSize.width(), headingImageSize.height() );   
  1359 	SWT_LOG_DATA_2("detail imageSize size=(%d, %d) ", detailImageSize.width(), detailImageSize.height() );   
  1359     SWT_LOG_DATA_2("detail imageSize size=(%d, %d) ", detailImageSize.width(), detailImageSize.height() );   
  1360 	SWT_LOG_DATA_2("headingText size=(%d, %d) ", headingTextSize.width(), headingTextSize.height() );   
  1360     SWT_LOG_DATA_2("headingText size=(%d, %d) ", headingTextSize.width(), headingTextSize.height() );   
  1361 	SWT_LOG_DATA_2("detail text size=(%d, %d) ", detailTextSize.width(), detailTextSize.height() );   
  1361     SWT_LOG_DATA_2("detail text size=(%d, %d) ", detailTextSize.width(), detailTextSize.height() );   
  1362 	QSize size = computeSize( option, checkSize, headingImageSize, detailImageSize, headingTextSize, detailTextSize );
  1362     QSize size = computeSize( option, checkSize, headingImageSize, detailImageSize, headingTextSize, detailTextSize );
  1363 	SWT_LOG_DATA_2("hint size=(%d, %d) ", size.width(), size.height() ); 
  1363     SWT_LOG_DATA_2("hint size=(%d, %d) ", size.width(), size.height() ); 
  1364 	dataModel->updateLayoutData( index.row(), size.height(), 
  1364     dataModel->updateLayoutData( index.row(), size.height(), 
  1365 		QPoint( detailTextSize.width(), detailTextSize.height() ), 
  1365         QPoint( detailTextSize.width(), detailTextSize.height() ), 
  1366 		QPoint( headingTextSize.width(), headingTextSize.height() ), 
  1366         QPoint( headingTextSize.width(), headingTextSize.height() ), 
  1367 		detailImageSize.width(), headingImageSize.width() );
  1367         detailImageSize.width(), headingImageSize.width() );
  1368     return size;
  1368     return size;
  1369 	}
  1369     }
  1370 	
  1370     
  1371 void ListBoxItemDelegate::setHeadingFont( QFont* font )
  1371 void ListBoxItemDelegate::setHeadingFont( QFont* font )
  1372 	{
  1372     {
  1373  	SWT_LOG_FUNC_CALL();
  1373     SWT_LOG_FUNC_CALL();
  1374 	headingFont = font;
  1374     headingFont = font;
  1375 	}
  1375     }
  1376 	
  1376     
  1377 
  1377 
  1378 QStyleOptionViewItem ListBoxItemDelegate::setOptions(const QModelIndex &index,
  1378 QStyleOptionViewItem ListBoxItemDelegate::setOptions(const QModelIndex &index,
  1379 	const QStyleOptionViewItem &option) const
  1379     const QStyleOptionViewItem &option) const
  1380 	{
  1380     {
  1381 	SWT_LOG_FUNC_CALL();
  1381     SWT_LOG_FUNC_CALL();
  1382     QStyleOptionViewItem opt = option;
  1382     QStyleOptionViewItem opt = option;
  1383     
  1383     
  1384 	// ask data modle for font, alignment and brush, then set them
  1384     // ask data modle for font, alignment and brush, then set them
  1385 	
  1385     
  1386    // set font
  1386    // set font
  1387     QVariant value = index.data(Qt::FontRole);
  1387     QVariant value = index.data(Qt::FontRole);
  1388     if (value.isValid()){
  1388     if (value.isValid()){
  1389         opt.font = qvariant_cast<QFont>(value).resolve(opt.font);
  1389         opt.font = qvariant_cast<QFont>(value).resolve(opt.font);
  1390         opt.fontMetrics = QFontMetrics(opt.font);
  1390         opt.fontMetrics = QFontMetrics(opt.font);
  1399     value = index.data(Qt::ForegroundRole);
  1399     value = index.data(Qt::ForegroundRole);
  1400     if (qVariantCanConvert<QBrush>(value))
  1400     if (qVariantCanConvert<QBrush>(value))
  1401         opt.palette.setBrush(QPalette::Text, qvariant_cast<QBrush>(value));
  1401         opt.palette.setBrush(QPalette::Text, qvariant_cast<QBrush>(value));
  1402         
  1402         
  1403     return opt;
  1403     return opt;
  1404 	}
  1404     }
  1405 
  1405 
  1406 QRect ListBoxItemDelegate::textRectangle( const int width, const QFont &font, const QString &text) const
  1406 QRect ListBoxItemDelegate::textRectangle( const int width, const QFont &font, const QString &text) const
  1407 	{
  1407     {
  1408  	SWT_LOG_FUNC_CALL();
  1408     SWT_LOG_FUNC_CALL();
  1409     QTextOption textOption;
  1409     QTextOption textOption;
  1410     textOption.setWrapMode(QTextOption::WordWrap);
  1410     textOption.setWrapMode(QTextOption::WordWrap);
  1411     textLayout.setTextOption( textOption );
  1411     textLayout.setTextOption( textOption );
  1412     textLayout.setFont( font );
  1412     textLayout.setFont( font );
  1413     
  1413     
  1414     // replace new line char with QChar::LineSeparator
  1414     // replace new line char with QChar::LineSeparator
  1415     QString replaceText = text;
  1415     QString replaceText = text;
  1416     const QChar nl = QLatin1Char('\n');
  1416     const QChar nl = QLatin1Char('\n');
  1417     for (int i = 0; i < text.count(); ++i)
  1417     for (int i = 0; i < text.count(); ++i)
  1418     	{
  1418         {
  1419         if (replaceText.at(i) == nl)
  1419         if (replaceText.at(i) == nl)
  1420             replaceText[i] = QChar::LineSeparator;
  1420             replaceText[i] = QChar::LineSeparator;
  1421     	}
  1421         }
  1422     textLayout.setText( replaceText );
  1422     textLayout.setText( replaceText );
  1423     
  1423     
  1424     qreal height = 0;
  1424     qreal height = 0;
  1425     qreal widthUsed = 0;
  1425     qreal widthUsed = 0;
  1426     textLayout.beginLayout();
  1426     textLayout.beginLayout();
  1427     while (true) 
  1427     while (true) 
  1428     	{
  1428         {
  1429         QTextLine line = textLayout.createLine();
  1429         QTextLine line = textLayout.createLine();
  1430         if  ( !line.isValid() )
  1430         if  ( !line.isValid() )
  1431         	{
  1431             {
  1432             break;
  1432             break;
  1433         	}
  1433             }
  1434         line.setLineWidth( width );
  1434         line.setLineWidth( width );
  1435         line.setPosition( QPointF( 0, height ) );
  1435         line.setPosition( QPointF( 0, height ) );
  1436         height += line.height();
  1436         height += line.height();
  1437         widthUsed = qMax( widthUsed, line.naturalTextWidth() );
  1437         widthUsed = qMax( widthUsed, line.naturalTextWidth() );
  1438     	}
  1438         }
  1439     textLayout.endLayout();
  1439     textLayout.endLayout();
  1440     QSize size =  QSizeF(widthUsed, height).toSize();
  1440     QSize size =  QSizeF(widthUsed, height).toSize();
  1441     
  1441     
  1442     const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
  1442     const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
  1443     return QRect(0, 0, size.width() + 2 * textMargin, size.height());
  1443     return QRect(0, 0, size.width() + 2 * textMargin, size.height());
  1444 	}
  1444     }
  1445 
  1445 
  1446 int ListBoxItemDelegate::margin( const QStyleOptionViewItem &option ) const
  1446 int ListBoxItemDelegate::margin( const QStyleOptionViewItem &option ) const
  1447 	{
  1447     {
  1448 	const QStyleOptionViewItemV3 *v3 = qstyleoption_cast<const QStyleOptionViewItemV3 *>(&option);
  1448     const QStyleOptionViewItemV3 *v3 = qstyleoption_cast<const QStyleOptionViewItemV3 *>(&option);
  1449 	const QWidget* widget = v3 ? v3->widget : NULL;
  1449     const QWidget* widget = v3 ? v3->widget : NULL;
  1450     QStyle* style = widget ? widget->style() : QApplication::style();
  1450     QStyle* style = widget ? widget->style() : QApplication::style();
  1451 	return style->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, widget) + 1;
  1451     return style->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, widget) + 1;
  1452 	}
  1452     }
  1453 
  1453 
  1454 void ListBoxItemDelegate::drawImages( QPainter* painter, const QStyleOptionViewItem &option, 
  1454 void ListBoxItemDelegate::drawImages( QPainter* painter, const QStyleOptionViewItem &option, 
  1455 	const QRect imageRect, const QList<QPixmap>& images, const int* imageWidths, const int imageCount ) const
  1455     const QRect imageRect, const QList<QPixmap>& images, const int* imageWidths, const int imageCount ) const
  1456 	{
  1456     {
  1457 	SWT_LOG_FUNC_CALL();
  1457     SWT_LOG_FUNC_CALL();
  1458 	SWT_LOG_DATA_4( "Heading image rect, row=%d: size=(%d, %d); topleft=(%d, %d)", imageRect.width(), imageRect.height(), imageRect.left(), imageRect.top() );
  1458     SWT_LOG_DATA_4( "Heading image rect, row=%d: size=(%d, %d); topleft=(%d, %d)", imageRect.width(), imageRect.height(), imageRect.left(), imageRect.top() );
  1459 	const int imageMargin = margin(option);
  1459     const int imageMargin = margin(option);
  1460 	const int top = imageRect.top();
  1460     const int top = imageRect.top();
  1461 	const int height = imageRect.height();
  1461     const int height = imageRect.height();
  1462 	int left = imageRect.left();
  1462     int left = imageRect.left();
  1463 	int right = left;
  1463     int right = left;
  1464 	QRect rect;
  1464     QRect rect;
  1465 	if( option.direction == Qt::RightToLeft )
  1465     if( option.direction == Qt::RightToLeft )
  1466 		{
  1466         {
  1467 		right = imageRect.right();
  1467         right = imageRect.right();
  1468 		left=right;
  1468         left=right;
  1469 		for( int i = 0; i < imageCount; i++)   
  1469         for( int i = 0; i < imageCount; i++)   
  1470 			{
  1470             {
  1471 			left -= imageWidths[i];
  1471             left -= imageWidths[i];
  1472 			rect = QRect( left, top, right - left, height );
  1472             rect = QRect( left, top, right - left, height );
  1473 			if( !rect.isValid() )break;
  1473             if( !rect.isValid() )break;
  1474 	   		rect = QStyle::alignedRect( option.direction, option.decorationAlignment, images[i].size(), rect );
  1474             rect = QStyle::alignedRect( option.direction, option.decorationAlignment, images[i].size(), rect );
  1475 		    drawDecoration( painter, option, rect, images[i] );
  1475             drawDecoration( painter, option, rect, images[i] );
  1476 			SWT_LOG_DATA_5("Image No.%d, size=(%d, %d); topleft=(%d, %d)", i, right - left, height, left, top );
  1476             SWT_LOG_DATA_5("Image No.%d, size=(%d, %d); topleft=(%d, %d)", i, right - left, height, left, top );
  1477 			right = left - imageMargin;
  1477             right = left - imageMargin;
  1478 			left = right;
  1478             left = right;
  1479 			}
  1479             }
  1480 		}
  1480         }
  1481 	else
  1481     else
  1482 		{
  1482         {
  1483 		for( int i = 0; i < imageCount; i++)   
  1483         for( int i = 0; i < imageCount; i++)   
  1484 			{
  1484             {
  1485 			right += imageWidths[i];
  1485             right += imageWidths[i];
  1486 			rect = QRect( left, top, right - left, height );
  1486             rect = QRect( left, top, right - left, height );
  1487 			if( !rect.isValid() )break;
  1487             if( !rect.isValid() )break;
  1488 	   		rect = QStyle::alignedRect( option.direction, option.decorationAlignment, images[i].size(), rect );
  1488             rect = QStyle::alignedRect( option.direction, option.decorationAlignment, images[i].size(), rect );
  1489 		    drawDecoration( painter, option, rect, images[i] );
  1489             drawDecoration( painter, option, rect, images[i] );
  1490 			SWT_LOG_DATA_5("Image No.%d, size=(%d, %d); topleft=(%d, %d)", i, right - left, height, left, top );
  1490             SWT_LOG_DATA_5("Image No.%d, size=(%d, %d); topleft=(%d, %d)", i, right - left, height, left, top );
  1491 			left = right + imageMargin;
  1491             left = right + imageMargin;
  1492 			right = left;
  1492             right = left;
  1493 			}
  1493             }
  1494 		}	
  1494         }   
  1495 	}
  1495     }
  1496 
  1496 
  1497 
  1497