Changeset 525448c for src


Ignore:
Timestamp:
05/05/10 15:58:56 (12 years ago)
Author:
kirilma <kirilma@…>
Branches:
master, qt5
Children:
a6a9e0b
Parents:
508de33
Message:

refactor: more compact drawing of controls

Location:
src/mvc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/mvc/delegate.cpp

    r508de33 r525448c  
    6262    if(hasParent(index))
    6363    {
    64         int aux = option.rect.height() - mControls[FavouriteControlOn]->drawPoint().y() - mControls[FavouriteControlOn]->image()->height();
     64        // entry horisontal layout:
     65        // * spacer (aka y position of image)
     66        // * image
     67        // * rest is text, which is 1 line of title with big letters and 2 lines of Presenter and Track
     68        int aux = option.rect.height() - SPACER - mControls[FavouriteControlOn]->image()->height();
    6569        Event *event = static_cast<Event*>(index.internalPointer());
    6670        // font SMALL
     
    132136
    133137        // draw Controls
    134         // favourite
    135138        if(event->isFavourite())
    136             painter->drawImage(mControls[FavouriteControlOn]->drawPoint(option.rect),*mControls[FavouriteControlOn]->image());
     139            mControls[FavouriteControlOn]->paint(painter, option.rect);
    137140        else
    138             painter->drawImage(mControls[FavouriteControlOff]->drawPoint(option.rect),*mControls[FavouriteControlOff]->image());
     141            mControls[FavouriteControlOff]->paint(painter, option.rect);
    139142#ifdef MAEMO
    140         // alarm
    141143        if(event->hasAlarm())
    142             painter->drawImage(mControls[AlarmControlOn]->drawPoint(option.rect),*mControls[AlarmControlOn]->image());
     144            mControls[AlarmControlOn]->paint(painter, option.rect);
    143145        else
    144             painter->drawImage(mControls[AlarmControlOff]->drawPoint(option.rect),*mControls[AlarmControlOff]->image());
     146            mControls[AlarmControlOff]->paint(painter, option.rect);
    145147#endif
    146         // map
    147         if (event->room()->hasMap()) {
    148             painter->drawImage(mControls[MapControl]->drawPoint(option.rect),*mControls[MapControl]->image());
    149         }
    150         // Time conflict
     148        if (event->room()->hasMap())
     149            mControls[MapControl]->paint(painter, option.rect);
    151150        if(event->hasTimeConflict())
    152             painter->drawImage(mControls[WarningControl]->drawPoint(option.rect),*mControls[WarningControl]->image());
     151            mControls[WarningControl]->paint(painter, option.rect);
    153152
    154153        // draw texts
    155         QPointF titlePointF(mControls[FavouriteControlOn]->drawPoint(option.rect));
    156         titlePointF.setX(option.rect.x()+SPACER);
    157         titlePointF.setY(titlePointF.y()+mControls[FavouriteControlOn]->image()->height());
     154        // it starts just below the image
     155        // ("position of text" is lower-left angle of the first letter,
     156        //  so the first line is actually at the same height as the image)
     157        QPointF titlePointF(option.rect.x() + SPACER,
     158                            option.rect.y() + SPACER + mControls[FavouriteControlOn]->image()->height());
    158159        QTime start = event->start().time();
    159160        painter->setFont(fontBig);
     
    337338}
    338339
     340Delegate::Control::Control(ControlId aControlId, const QString &aImageName, const Control* prev_control)
     341    : mId(aControlId)
     342    , mImage(new QImage(aImageName))
     343    , mDrawPoint(QPoint(0,0))
     344{
     345    QPoint p;
     346    if (prev_control == NULL) {
     347        p = QPoint(0, SPACER);
     348    } else {
     349        p = prev_control->drawPoint();
     350    }
     351    p.setX(p.x()-image()->width()-SPACER);
     352    setDrawPoint(p);
     353}
     354
     355void Delegate::Control::paint(QPainter* painter, const QRect rect)
     356{
     357    painter->drawImage(drawPoint(rect),*image());
     358}
     359
    339360void Delegate::defineControls()
    340361{
    341     Control *control;
    342     QPoint p(0,0);
    343362    // FAVOURITE ICONs
    344363    // on
    345     control = new Control(FavouriteControlOn,QString(":icons/favourite-onBig.png"));
    346     p = QPoint(0,SPACER);
    347     p.setX(p.x()-control->image()->width()-SPACER);
    348     control->setDrawPoint(p);
    349     mControls.insert(FavouriteControlOn,control);
     364    mControls.insert(FavouriteControlOn, new Control(FavouriteControlOn, QString(":icons/favourite-onBig.png"), NULL));
    350365    // off
    351     control = new Control(FavouriteControlOff,QString(":icons/favourite-offBig.png"));
    352     p = QPoint(0,SPACER);
    353     p.setX(p.x()-control->image()->width()-SPACER);
    354     control->setDrawPoint(p);
    355     mControls.insert(FavouriteControlOff,control);
     366    mControls.insert(FavouriteControlOff, new Control(FavouriteControlOff, QString(":icons/favourite-offBig.png"), NULL));
    356367
    357368#ifdef MAEMO
    358369    // ALARM ICONs
    359370    // on
    360     control = new Control(AlarmControlOn,QString(":icons/alarm-onBig.png"));
    361     p = mControls[FavouriteControlOn]->drawPoint();
    362     p.setX(p.x()-control->image()->width()-SPACER);
    363     control->setDrawPoint(p);
    364     mControls.insert(AlarmControlOn,control);
     371    mControls.insert(AlarmControlOn,
     372                    new Control(AlarmControlOn, QString(":icons/alarm-onBig.png"), mControls[FavouriteControlOn]));
    365373    // off
    366     control = new Control(AlarmControlOff,QString(":icons/alarm-offBig.png"));
    367     p = mControls[FavouriteControlOff]->drawPoint();
    368     p.setX(p.x()-control->image()->width()-SPACER);
    369     control->setDrawPoint(p);
    370     mControls.insert(AlarmControlOff,control);
     374    mControls.insert(AlarmControlOff,
     375                    new Control(AlarmControlOff, QString(":icons/alarm-offBig.png"), mControls[FavouriteControlOff]));
    371376
    372377    // MAP ICON
    373     control = new Control(MapControl,QString(":icons/compassBig.png"));
    374     p = mControls[AlarmControlOn]->drawPoint();
    375     p.setX(p.x()-control->image()->width()-SPACER);
    376     control->setDrawPoint(p);
    377     mControls.insert(MapControl,control);
     378    mControls.insert(MapControl,
     379                    new Control(MapControl, QString(":icons/compassBig.png"), mControls[AlarmControlOn]));
    378380#else
    379381    // MAP ICON
    380     control = new Control(MapControl,QString(":icons/compassBig.png"));
    381     p = mControls[FavouriteControlOn]->drawPoint();
    382     p.setX(p.x()-control->image()->width()-SPACER);
    383     control->setDrawPoint(p);
    384     mControls.insert(MapControl,control);
     382    mControls.insert(MapControl,
     383                    new Control(MapControl, QString(":icons/compassBig.png"), mControls[FavouriteControlOn]));
    385384#endif
    386385
    387386    // WARNING ICON
    388     control = new Control(WarningControl,QString(":icons/exclamation.png"));
    389     p = mControls[MapControl]->drawPoint();
    390     p.setX(p.x()-control->image()->width()-SPACER);
    391     control->setDrawPoint(p);
    392     mControls.insert(WarningControl,control);
     387    mControls.insert(WarningControl,
     388                    new Control(WarningControl, QString(":icons/exclamation.png"), mControls[MapControl]));
    393389}
    394390
  • src/mvc/delegate.h

    r508de33 r525448c  
    4444        {
    4545            public:
    46                 Control(ControlId aControlId, const QString &aImageName)
    47                     : mId(aControlId)
    48                     , mImage(new QImage(aImageName))
    49                     , mDrawPoint(QPoint(0,0))
    50                 { }
     46                Control(ControlId aControlId, const QString &aImageName, const Control* prev_control);
     47
    5148                inline QImage *image() const { return mImage; }
    5249                inline void setDrawPoint(const QPoint &aPoint) { mDrawPoint = aPoint; }
     50                inline QRect drawRect(const QRect &aRect) const // helper for determining if Control was clicked
     51                {
     52                    return QRect(drawPoint(aRect), drawPoint(aRect)+QPoint(mImage->size().width(),mImage->size().height()));
     53                }
     54                void paint(QPainter* painter, const QRect rect);
     55
     56            private:
    5357                inline QPoint drawPoint(const QRect &aRect = QRect()) const // for painter to draw Control
    5458                {
     
    5862                        return QPoint(aRect.x()+aRect.width(),aRect.y()) + mDrawPoint; // returns absolute drawing point
    5963                }
    60                 inline QRect drawRect(const QRect &aRect) const // helper for determining if Control was clicked
    61                 {
    62                     return QRect(drawPoint(aRect), drawPoint(aRect)+QPoint(mImage->size().width(),mImage->size().height()));
    63                 }
    64             private:
     64
    6565                ControlId mId;
    6666                QImage *mImage;
Note: See TracChangeset for help on using the changeset viewer.