Changeset 4be95b8 for src/mvc


Ignore:
Timestamp:
01/18/10 19:21:48 (12 years ago)
Author:
pavelpa <pavelpa@…>
Branches:
master, qt5
Children:
18681b3
Parents:
a35aa83
Message:

implemented drawing icons + number of favs/alarms
in the corresponding group

Location:
src/mvc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/mvc/delegate.cpp

    ra35aa83 r4be95b8  
    66
    77const int RADIUS = 10;
    8 const int SPACER = RADIUS;
     8const int SPACER = 15;
    99
    1010Delegate::Delegate(QTreeView *aParent)
     
    136136        font.setBold(true);
    137137        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)));
    138156    }
    139157
     
    218236    // on
    219237    control = new Control(FavouriteControlOn,QString(":icons/favourite-on.png"));
    220     p = QPoint(0,0);
     238    p = QPoint(0,SPACER);
    221239    p.setX(p.x()-control->image()->width()-SPACER);
    222240    control->setDrawPoint(p);
     
    224242    // off
    225243    control = new Control(FavouriteControlOff,QString(":icons/favourite-off.png"));
    226     p = QPoint(0,0);
     244    p = QPoint(0,SPACER);
    227245    p.setX(p.x()-control->image()->width()-SPACER);
    228246    control->setDrawPoint(p);
     
    259277}
    260278
     279int 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
     292int 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  
    6363        bool isExpanded( const QModelIndex &index ) const;
    6464        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;
    6572
    6673    private:
Note: See TracChangeset for help on using the changeset viewer.