- Timestamp:
- 01/18/10 19:21:48 (13 years ago)
- Branches:
- master, qt5
- Children:
- 18681b3
- Parents:
- a35aa83
- Location:
- src/mvc
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mvc/delegate.cpp
ra35aa83 r4be95b8 6 6 7 7 const int RADIUS = 10; 8 const int SPACER = RADIUS;8 const int SPACER = 15; 9 9 10 10 Delegate::Delegate(QTreeView *aParent) … … 136 136 font.setBold(true); 137 137 painter->setFont(font); 138 139 // draw icons 140 QPoint drawPoint = 141 option.rect.topRight() 142 - QPoint( 143 SPACER + mControls[FavouriteControlOn]->image()->width(), 144 - option.rect.height()/2 + mControls[FavouriteControlOn]->image()->height()/2); 145 painter->drawImage(drawPoint,*mControls[FavouriteControlOn]->image()); 146 painter->drawText(drawPoint+QPoint(mControls[FavouriteControlOn]->image()->width()+2, option.rect.height()/2), 147 QString::number(numberOfFavourities(index))); 148 drawPoint.setX(drawPoint.x() - SPACER - mControls[FavouriteControlOn]->image()->width()); 149 painter->drawImage(drawPoint,*mControls[AlarmControlOn]->image()); 150 painter->drawText(drawPoint+QPoint(mControls[FavouriteControlOn]->image()->width()+2, option.rect.height()/2), 151 QString::number(numberOfAlarms(index))); 152 // draw texts 153 drawPoint.setX(drawPoint.x() - SPACER -mControls[AlarmControlOn]->image()->width() - 20); 154 drawPoint.setY(drawPoint.y() + option.rect.height()/2); 155 painter->drawText(drawPoint,QString("Events: ") + QString::number(index.model()->rowCount(index))); 138 156 } 139 157 … … 218 236 // on 219 237 control = new Control(FavouriteControlOn,QString(":icons/favourite-on.png")); 220 p = QPoint(0, 0);238 p = QPoint(0,SPACER); 221 239 p.setX(p.x()-control->image()->width()-SPACER); 222 240 control->setDrawPoint(p); … … 224 242 // off 225 243 control = new Control(FavouriteControlOff,QString(":icons/favourite-off.png")); 226 p = QPoint(0, 0);244 p = QPoint(0,SPACER); 227 245 p.setX(p.x()-control->image()->width()-SPACER); 228 246 control->setDrawPoint(p); … … 259 277 } 260 278 279 int Delegate::numberOfFavourities(const QModelIndex &index) const 280 { 281 if(index.parent().isValid()) // it's event, not time-group 282 return 0; 283 284 int nrofFavs = 0; 285 for(int i=0; i<index.model()->rowCount(index); i++) 286 if(static_cast<Event*>(index.child(i,0).internalPointer())->isFavourite()) 287 nrofFavs++; 288 289 return nrofFavs; 290 } 291 292 int Delegate::numberOfAlarms(const QModelIndex &index) const 293 { 294 if(index.parent().isValid()) // it's event, not time-group 295 return 0; 296 297 int nrofAlarms = 0; 298 for(int i=0; i<index.model()->rowCount(index); i++) 299 if(static_cast<Event*>(index.child(i,0).internalPointer())->hasAlarm()) 300 nrofAlarms++; 301 302 return nrofAlarms; 303 } 304 -
src/mvc/delegate.h
ra35aa83 r4be95b8 63 63 bool isExpanded( const QModelIndex &index ) const; 64 64 void defineControls(); 65 // TODO: the better place for these methods would be 'eventmodel' 66 // they are used in 'paint' method and so it's better to obtain number of 67 // favourities/alarms once when the data has changed and not to call 68 // these methods which iterate over all Events in corresponding group 69 // every time it requires them 70 int numberOfFavourities(const QModelIndex &index) const; 71 int numberOfAlarms(const QModelIndex &index) const; 65 72 66 73 private:
Note: See TracChangeset
for help on using the changeset viewer.