]> ToastFreeware Gitweb - toast/confclerk.git/blobdiff - src/mvc/delegate.cpp
do not draw showmap button for event is there is no map for its room
[toast/confclerk.git] / src / mvc / delegate.cpp
index 80dcb7b55ac4cdc95579bad3ee51be3bf3fcad6e..dac1bdfa2da2140f0b8f39de691e6887937e4939 100644 (file)
@@ -1,10 +1,30 @@
+/*
+ * Copyright (C) 2010 Ixonos Plc.
+ *
+ * This file is part of fosdem-schedule.
+ *
+ * fosdem-schedule is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation, either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * fosdem-schedule is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * fosdem-schedule.  If not, see <http://www.gnu.org/licenses/>.
+ */
 #include "delegate.h"
 #include "eventmodel.h"
-#include <activity.h>
+#include <track.h>
 
 #include <QDebug>
 #include <QPainter>
 
+#include "room.h"
+
 const int RADIUS = 10;
 const int SPACER = 10;
 
@@ -34,14 +54,15 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
         return;
 
     painter->save();
-
     QColor bkgrColor = Qt::cyan;
+    //QColor bkgrColor = QColor(0xAA,0xAA,0xAA);
+    QColor conflictColor = Qt::yellow;
+
     QPen borderPen(bkgrColor.darker());
-    //QColor bkgrColor = QColor(0,0,113);
-    //QPen borderPen(Qt::cyan);
     if(hasParent(index))
     {
         int aux = option.rect.height() - mControls[FavouriteControlOn]->drawPoint().y() - mControls[FavouriteControlOn]->image()->height();
+        Event *event = static_cast<Event*>(index.internalPointer());
         // font SMALL
         QFont fontSmall = option.font;
         fontSmall.setBold(false);
@@ -62,15 +83,21 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
         fontBigB.setBold(true);
         QFontMetrics fmBigB(fontBigB);
 
-        int spacer = (fmSmall.boundingRect("999").width() < SPACER) ? SPACER : fmSmall.boundingRect("999").width();
+        //int spacer = (fmSmall.boundingRect("999").width() < SPACER) ? SPACER : fmSmall.boundingRect("999").width();
+
+        //Time conflicts are colored differently
+        if(event->hasTimeConflict())
+            bkgrColor = conflictColor;
+
+        QLinearGradient itemGradient(option.rect.topLeft(), option.rect.bottomLeft());
+        itemGradient.setColorAt(0.0, Qt::white);
+        itemGradient.setColorAt(0.25, bkgrColor);
+        itemGradient.setColorAt(0.5, bkgrColor);
+        itemGradient.setColorAt(0.75, bkgrColor);
+        itemGradient.setColorAt(1.0, Qt::white);
 
         if(isLast(index))
         {
-            QLinearGradient lastGradient(option.rect.topLeft(), option.rect.bottomLeft());
-            lastGradient.setColorAt(0.0, Qt::white);
-            lastGradient.setColorAt(0.5, bkgrColor);
-            lastGradient.setColorAt(1.0, Qt::white);
-
             QPainterPath endPath;
             endPath.moveTo(option.rect.topLeft());
             endPath.lineTo(option.rect.bottomLeft()-QPoint(0, RADIUS));
@@ -79,8 +106,8 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
             endPath.arcTo(option.rect.right()-2*RADIUS, option.rect.bottom()-2*RADIUS, 2*RADIUS, 2*RADIUS, 270, 90);
             endPath.lineTo(option.rect.topRight());
 
-            painter->setBrush( bkgrColor );
-            //painter->setBrush(lastGradient);
+            //painter->setBrush( bkgrColor );
+            painter->setBrush(itemGradient);
             painter->setPen(borderPen);
             painter->drawPath(endPath);
 
@@ -88,15 +115,8 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
         }
         else // middle elements
         {
-            QLinearGradient middleGradient(option.rect.topLeft(), option.rect.bottomLeft());
-            middleGradient.setColorAt(0.0, Qt::white);
-            middleGradient.setColorAt(0.25, bkgrColor);
-            middleGradient.setColorAt(0.5, Qt::white);
-            middleGradient.setColorAt(0.75, bkgrColor);
-            middleGradient.setColorAt(1.0, Qt::white);
-
-            painter->setBrush( bkgrColor );
-            //painter->setBrush(middleGradient);
+            //painter->setBrush( bkgrColor );
+            painter->setBrush(itemGradient);
             painter->setPen(Qt::NoPen);
             painter->drawRect(option.rect);
 
@@ -112,26 +132,32 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
 
         // draw Controls
         // favourite
-        if(static_cast<Event*>(index.internalPointer())->isFavourite())
+        if(event->isFavourite())
             painter->drawImage(mControls[FavouriteControlOn]->drawPoint(option.rect),*mControls[FavouriteControlOn]->image());
         else
             painter->drawImage(mControls[FavouriteControlOff]->drawPoint(option.rect),*mControls[FavouriteControlOff]->image());
+#ifdef MAEMO
         // alarm
-        if(static_cast<Event*>(index.internalPointer())->hasAlarm())
+        if(event->hasAlarm())
             painter->drawImage(mControls[AlarmControlOn]->drawPoint(option.rect),*mControls[AlarmControlOn]->image());
         else
             painter->drawImage(mControls[AlarmControlOff]->drawPoint(option.rect),*mControls[AlarmControlOff]->image());
+#endif
         // map
-        painter->drawImage(mControls[MapControl]->drawPoint(option.rect),*mControls[MapControl]->image());
+        if (event->room()->hasMap()) {
+            painter->drawImage(mControls[MapControl]->drawPoint(option.rect),*mControls[MapControl]->image());
+        }
+        // Time conflict
+        if(event->hasTimeConflict())
+            painter->drawImage(mControls[WarningControl]->drawPoint(option.rect),*mControls[WarningControl]->image());
 
         // draw texts
-        Event *event = static_cast<Event*>(index.internalPointer());
         QPointF titlePointF(mControls[FavouriteControlOn]->drawPoint(option.rect));
         titlePointF.setX(option.rect.x()+SPACER);
         titlePointF.setY(titlePointF.y()+mControls[FavouriteControlOn]->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->room());
+        painter->drawText(titlePointF,start.toString("hh:mm") + "-" + start.addSecs(event->duration()).toString("hh:mm") + ", " + event->roomName());
         // title
         titlePointF.setY(titlePointF.y()+fmBig.height()-fmBig.descent());
         painter->setFont(fontBigB);
@@ -157,7 +183,7 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
         painter->drawText(titlePointF,"Presenter(s): " + event->persons().join(" and "));
         // track
         titlePointF.setY(titlePointF.y()+fmSmall.height()-fmSmall.descent());
-        painter->drawText(titlePointF,"Activity(s): " + Activity::getActivityName(event->activityId()));
+        painter->drawText(titlePointF,"Track: " + Track::retrieveTrackName(event->trackId()));
     }
     else // doesn't have parent - time-groups' elements (top items)
     {
@@ -209,22 +235,25 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
 
         // draw icons 
         painter->setFont(fontSmall);
+        QImage *image = mControls[FavouriteControlOn]->image();
         QPoint drawPoint =
             option.rect.topRight()
             - QPoint(
-                    spacer + mControls[FavouriteControlOn]->image()->width(),
-                    - option.rect.height()/2 + mControls[FavouriteControlOn]->image()->height()/2);
-        painter->drawImage(drawPoint,*mControls[FavouriteControlOn]->image());
-        painter->drawText(drawPoint+QPoint(mControls[FavouriteControlOn]->image()->width()+2, option.rect.height()/2),
+                    spacer + image->width(),
+                    - option.rect.height()/2 + image->height()/2);
+        painter->drawImage(drawPoint,*image);
+        painter->drawText(drawPoint+QPoint(image->width()+2, image->height() - 2),
                 QString::number(numberOfFavourities(index)));
-        drawPoint.setX(drawPoint.x() - spacer - mControls[FavouriteControlOn]->image()->width());
+#ifdef MAEMO
+        drawPoint.setX(drawPoint.x() - spacer - image->width());
         painter->drawImage(drawPoint,*mControls[AlarmControlOn]->image());
-        painter->drawText(drawPoint+QPoint(mControls[FavouriteControlOn]->image()->width()+2, option.rect.height()/2),
+        painter->drawText(drawPoint+QPoint(image->width()+2, image->height() - 2),
                 QString::number(numberOfAlarms(index)));
+#endif
         // draw texts
         QString numEvents = QString::number(index.model()->rowCount(index)).append("/");
         drawPoint.setX(drawPoint.x() - spacer - fmSmall.boundingRect(numEvents).width());
-        drawPoint.setY(drawPoint.y() + option.rect.height()/2);
+        drawPoint.setY(drawPoint.y()+image->height() - 2);
         painter->drawText(drawPoint,numEvents);
 
         QPointF titlePointF = QPoint(
@@ -293,7 +322,15 @@ Delegate::ControlId Delegate::whichControlClicked(const QModelIndex &aIndex, con
     {
         ControlId id = i.next();
         if(mControls[id]->drawRect(static_cast<QTreeView*>(parent())->visualRect(aIndex)).contains(aPoint))
-            return id;
+        {
+            if(id == WarningControl)
+            {
+                if(static_cast<Event*>(aIndex.internalPointer())->hasTimeConflict())
+                    return id;
+            }
+            else
+                return id;
+        }
     }
 
     return ControlNone;
@@ -317,6 +354,7 @@ void Delegate::defineControls()
     control->setDrawPoint(p);
     mControls.insert(FavouriteControlOff,control);
 
+#ifdef MAEMO
     // ALARM ICONs
     // on
     control = new Control(AlarmControlOn,QString(":icons/alarm-onBig.png"));
@@ -337,6 +375,21 @@ void Delegate::defineControls()
     p.setX(p.x()-control->image()->width()-SPACER);
     control->setDrawPoint(p);
     mControls.insert(MapControl,control);
+#else
+    // MAP ICON
+    control = new Control(MapControl,QString(":icons/compassBig.png"));
+    p = mControls[FavouriteControlOn]->drawPoint();
+    p.setX(p.x()-control->image()->width()-SPACER);
+    control->setDrawPoint(p);
+    mControls.insert(MapControl,control);
+#endif
+
+    // WARNING ICON
+    control = new Control(WarningControl,QString(":icons/exclamation.png"));
+    p = mControls[MapControl]->drawPoint();
+    p.setX(p.x()-control->image()->width()-SPACER);
+    control->setDrawPoint(p);
+    mControls.insert(WarningControl,control);
 }
 
 bool Delegate::isPointFromRect(const QPoint &aPoint, const QRect &aRect) const