Changeset 1343ea4


Ignore:
Timestamp:
01/20/17 23:04:17 (5 years ago)
Author:
Philipp Spitzer <philipp@…>
Branches:
master, qt5
Children:
81d87d7
Parents:
ec7fa22
Message:

Now the conflict severity is drawn.

Location:
src/mvc
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/mvc/delegate.cpp

    rec7fa22 r1343ea4  
    6161    if(hasParent(index))
    6262    {
     63        Event *event = static_cast<Event*>(index.internalPointer());
     64
     65        // determine severity of conflict
     66        Favourite eventTimeConflict = event->timeConflict(); // cache value as event->timeConflict is expensive
     67        enum ConflictSeverity {csNone, csWeak, csStrong} conflictSeverity;
     68        switch (event->favourite()) {
     69            case Favourite_strong:
     70                conflictSeverity = (eventTimeConflict == Favourite_strong) ? csStrong : csNone;
     71                break;
     72            case Favourite_weak:
     73                conflictSeverity = (eventTimeConflict == Favourite_no) ? csNone : csWeak;
     74                break;
     75            case Favourite_no:
     76                conflictSeverity = csNone;
     77                break;
     78        }
     79
    6380        // entry horizontal layout:
    6481        // * spacer (aka y position of image)
     
    6683        // * rest is text, which is 1 line of title with big letters and 2 lines of Presenter and Track
    6784        int aux = option.rect.height() - SPACER - mControls[FavouriteControlStrong]->image()->height();
    68         Event *event = static_cast<Event*>(index.internalPointer());
    6985
    7086        // font SMALL
     
    89105
    90106        // background (in case of time conflicts)
    91         if(event->hasTimeConflict()) {
    92             painter->setBrush(Qt::yellow);
     107        if (conflictSeverity != csNone) {
     108            painter->setBrush(conflictSeverity == csStrong ? Qt::yellow : QColor("lightyellow"));
    93109            painter->setPen(Qt::NoPen);
    94110            painter->drawRect(option.rect);
     
    123139            mControls[AlarmControlOff]->paint(painter, option.rect);
    124140
    125         if(event->hasTimeConflict())
     141        if(eventTimeConflict != Favourite_no)
    126142            mControls[WarningControl]->paint(painter, option.rect);
    127143
     
    130146        // ("position of text" is lower-left angle of the first letter,
    131147        //  so the first line is actually at the same height as the image)
    132         painter->setPen(QPen(event->hasTimeConflict() ? Qt::black : textColor));
     148        painter->setPen(QPen(conflictSeverity != csNone ? Qt::black : textColor));
    133149        QPointF titlePointF(option.rect.x() + SPACER,
    134150                            option.rect.y() + SPACER + mControls[FavouriteControlStrong]->image()->height());
  • src/mvc/event.cpp

    rec7fa22 r1343ea4  
    193193}
    194194
    195 bool Event::hasTimeConflict() const
    196 {
    197     if(favourite() == Favourite_no) // if it's not favourite, it can't have time-conflict
    198         return false;
    199 
    200     return conflictEvents(id(),conferenceId()).count() > 0;
     195Favourite Event::timeConflict() const {
     196    if (favourite() == Favourite_no) // if it's not favourite, it can't have time-conflict
     197        return Favourite_no;
     198
     199    QList<Event> events = conflictEvents(id(),conferenceId());
     200
     201    // find "strongest" conflict
     202    Favourite f = Favourite_no;
     203    for (int i = 0; i != events.size(); ++i) {
     204        switch (events[i].favourite()) {
     205        case Favourite_strong: f = Favourite_strong; break;
     206        case Favourite_weak: if (f == Favourite_no) f = Favourite_weak; break;
     207        case Favourite_no: break;
     208        }
     209    }
     210    return f;
     211
    201212}
    202213
  • src/mvc/event.h

    rec7fa22 r1343ea4  
    6666    Favourite favourite() const { return static_cast<Favourite>(value("favourite").toInt()); }
    6767    bool hasAlarm() const { return value("alarm").toBool(); }
    68     bool hasTimeConflict() const;
     68    Favourite timeConflict() const;
    6969    QString tag() const { return value("tag").toString(); }
    7070    QString title() const { return value("title").toString(); }
Note: See TracChangeset for help on using the changeset viewer.