Now the conflict severity is drawn.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Fri, 20 Jan 2017 22:04:17 +0000 (23:04 +0100)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Fri, 20 Jan 2017 22:04:17 +0000 (23:04 +0100)
src/mvc/delegate.cpp
src/mvc/event.cpp
src/mvc/event.h

index 065d21d..c2dd111 100644 (file)
@@ -60,12 +60,28 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
 
     if(hasParent(index))
     {
+        Event *event = static_cast<Event*>(index.internalPointer());
+
+        // determine severity of conflict
+        Favourite eventTimeConflict = event->timeConflict(); // cache value as event->timeConflict is expensive
+        enum ConflictSeverity {csNone, csWeak, csStrong} conflictSeverity;
+        switch (event->favourite()) {
+            case Favourite_strong:
+                conflictSeverity = (eventTimeConflict == Favourite_strong) ? csStrong : csNone;
+                break;
+            case Favourite_weak:
+                conflictSeverity = (eventTimeConflict == Favourite_no) ? csNone : csWeak;
+                break;
+            case Favourite_no:
+                conflictSeverity = csNone;
+                break;
+        }
+
         // entry horizontal layout:
         // * spacer (aka y position of image)
         // * image
         // * rest is text, which is 1 line of title with big letters and 2 lines of Presenter and Track
         int aux = option.rect.height() - SPACER - mControls[FavouriteControlStrong]->image()->height();
-        Event *event = static_cast<Event*>(index.internalPointer());
 
         // font SMALL
         QFont fontSmall = option.font;
@@ -88,8 +104,8 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
         QFontMetrics fmBigB(fontBigB);
 
         // background (in case of time conflicts)
-        if(event->hasTimeConflict()) {
-            painter->setBrush(Qt::yellow);
+        if (conflictSeverity != csNone) {
+            painter->setBrush(conflictSeverity == csStrong ? Qt::yellow : QColor("lightyellow"));
             painter->setPen(Qt::NoPen);
             painter->drawRect(option.rect);
         }
@@ -122,14 +138,14 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
         else
             mControls[AlarmControlOff]->paint(painter, option.rect);
 
-        if(event->hasTimeConflict())
+        if(eventTimeConflict != Favourite_no)
             mControls[WarningControl]->paint(painter, option.rect);
 
         // draw texts
         // it starts just below the image
         // ("position of text" is lower-left angle of the first letter,
         //  so the first line is actually at the same height as the image)
-        painter->setPen(QPen(event->hasTimeConflict() ? Qt::black : textColor));
+        painter->setPen(QPen(conflictSeverity != csNone ? Qt::black : textColor));
         QPointF titlePointF(option.rect.x() + SPACER,
                             option.rect.y() + SPACER + mControls[FavouriteControlStrong]->image()->height());
         QTime start = event->start().time();
index 47a7494..35fb3c7 100644 (file)
@@ -192,12 +192,23 @@ QMap<QString,QString> Event::links()
     return mLinksList;
 }
 
-bool Event::hasTimeConflict() const
-{
-    if(favourite() == Favourite_no) // if it's not favourite, it can't have time-conflict
-        return false;
+Favourite Event::timeConflict() const {
+    if (favourite() == Favourite_no) // if it's not favourite, it can't have time-conflict
+        return Favourite_no;
+
+    QList<Event> events = conflictEvents(id(),conferenceId());
+
+    // find "strongest" conflict
+    Favourite f = Favourite_no;
+    for (int i = 0; i != events.size(); ++i) {
+        switch (events[i].favourite()) {
+        case Favourite_strong: f = Favourite_strong; break;
+        case Favourite_weak: if (f == Favourite_no) f = Favourite_weak; break;
+        case Favourite_no: break;
+        }
+    }
+    return f;
 
-    return conflictEvents(id(),conferenceId()).count() > 0;
 }
 
 void Event::cycleFavourite() {
index bb0cc34..5451989 100644 (file)
@@ -65,7 +65,7 @@ public:
     QString language() const { return value("language").toString(); }
     Favourite favourite() const { return static_cast<Favourite>(value("favourite").toInt()); }
     bool hasAlarm() const { return value("alarm").toBool(); }
-    bool hasTimeConflict() const;
+    Favourite timeConflict() const;
     QString tag() const { return value("tag").toString(); }
     QString title() const { return value("title").toString(); }
     QString subtitle() const { return value("subtitle").toString(); }