Merge branch 'master' into qt5
[toast/confclerk.git] / src / mvc / delegate.cpp
index e6136598c41dfc9e46b3e297479d89cba7a84033..2d1f08524084873ea61ee03ad94879a50a826960 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2010 Ixonos Plc.
- * Copyright (C) 2011-2015 Philipp Spitzer, gregor herrmann, Stefan Stahl
+ * Copyright (C) 2011-2017 Philipp Spitzer, gregor herrmann, Stefan Stahl
  *
  * This file is part of ConfClerk.
  *
@@ -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 = csNone;
+        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[FavouriteControlOn]->image()->height();
-        Event *event = static_cast<Event*>(index.internalPointer());
+        int aux = option.rect.height() - SPACER - mControls[FavouriteControlStrong]->image()->height();
 
         // 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);
         }
@@ -105,26 +121,33 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
         foreach(Control* c, mControls.values()) {
             c->setEnabled(false);
         }
-        if(event->isFavourite())
-            mControls[FavouriteControlOn]->paint(painter, option.rect);
-        else
-            mControls[FavouriteControlOff]->paint(painter, option.rect);
+        switch (event->favourite()) {
+        case Favourite_strong:
+            mControls[FavouriteControlStrong]->paint(painter, option.rect);
+            break;
+        case Favourite_weak:
+            mControls[FavouriteControlWeak]->paint(painter, option.rect);
+            break;
+        case Favourite_no:
+            mControls[FavouriteControlNo]->paint(painter, option.rect);
+            break;
+        }
 
         if(event->hasAlarm())
             mControls[AlarmControlOn]->paint(painter, option.rect);
         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[FavouriteControlOn]->image()->height());
+                            option.rect.y() + SPACER + mControls[FavouriteControlStrong]->image()->height());
         QTime start = event->start().time();
         painter->setFont(fontBig);
         painter->drawText(titlePointF,start.toString("hh:mm") + "-" + start.addSecs(event->duration()).toString("hh:mm") + ", " + event->roomName());
@@ -188,7 +211,7 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
         // draw icons
         painter->setPen(QPen(textColor));
         painter->setFont(fontSmall);
-        QImage *image = mControls[numFav ? FavouriteControlOn : FavouriteControlOff]->image();
+        QImage *image = mControls[numFav ? FavouriteControlStrong : FavouriteControlNo]->image();
         QPoint drawPoint =
             option.rect.topRight()
             - QPoint(
@@ -306,18 +329,20 @@ void Delegate::Control::paint(QPainter* painter, const QRect rect)
 void Delegate::defineControls()
 {
     // FAVOURITE ICONs
-    // on
-    mControls.insert(FavouriteControlOn, new Control(FavouriteControlOn, QString(":icons/favourite-on.png"), NULL));
-    // off
-    mControls.insert(FavouriteControlOff, new Control(FavouriteControlOff, QString(":icons/favourite-off.png"), NULL));
+    // strong
+    mControls.insert(FavouriteControlStrong, new Control(FavouriteControlStrong, QString(":icons/favourite-strong.png"), NULL));
+    // weak
+    mControls.insert(FavouriteControlWeak, new Control(FavouriteControlWeak, QString(":icons/favourite-weak.png"), NULL));
+    // no
+    mControls.insert(FavouriteControlNo, new Control(FavouriteControlNo, QString(":icons/favourite-no.png"), NULL));
 
     // ALARM ICONs
     // on
     mControls.insert(AlarmControlOn,
-                    new Control(AlarmControlOn, QString(":icons/alarm-on.png"), mControls[FavouriteControlOn]));
+                    new Control(AlarmControlOn, QString(":icons/alarm-on.png"), mControls[FavouriteControlStrong]));
     // off
     mControls.insert(AlarmControlOff,
-                    new Control(AlarmControlOff, QString(":icons/alarm-off.png"), mControls[FavouriteControlOff]));
+                    new Control(AlarmControlOff, QString(":icons/alarm-off.png"), mControls[FavouriteControlNo]));
     // WARNING ICON
     mControls.insert(WarningControl,
                     new Control(WarningControl, QString(":icons/dialog-warning.png"), mControls[AlarmControlOff]));
@@ -338,7 +363,7 @@ int Delegate::numberOfFavourities(const QModelIndex &index) const
 
     int nrofFavs = 0;
     for(int i=0; i<index.model()->rowCount(index); i++)
-        if(static_cast<Event*>(index.child(i,0).internalPointer())->isFavourite())
+        if(static_cast<Event*>(index.child(i,0).internalPointer())->favourite() != Favourite_no)
             nrofFavs++;
 
     return nrofFavs;