implemented drawing icons + number of favs/alarms
authorpavelpa <pavelpa@localhost>
Mon, 18 Jan 2010 18:21:48 +0000 (18:21 +0000)
committerpavelpa <pavelpa@localhost>
Mon, 18 Jan 2010 18:21:48 +0000 (18:21 +0000)
in the corresponding group

src/mvc/delegate.cpp
src/mvc/delegate.h

index d085db9..306fc64 100644 (file)
@@ -5,7 +5,7 @@
 #include <QPainter>
 
 const int RADIUS = 10;
-const int SPACER = RADIUS;
+const int SPACER = 15;
 
 Delegate::Delegate(QTreeView *aParent)
     : QItemDelegate(aParent)
@@ -135,6 +135,24 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
         QFont font = option.font;
         font.setBold(true);
         painter->setFont(font);
+
+        // draw icons 
+        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),
+                QString::number(numberOfFavourities(index)));
+        drawPoint.setX(drawPoint.x() - SPACER - mControls[FavouriteControlOn]->image()->width());
+        painter->drawImage(drawPoint,*mControls[AlarmControlOn]->image());
+        painter->drawText(drawPoint+QPoint(mControls[FavouriteControlOn]->image()->width()+2, option.rect.height()/2),
+                QString::number(numberOfAlarms(index)));
+        // draw texts
+        drawPoint.setX(drawPoint.x() - SPACER -mControls[AlarmControlOn]->image()->width() - 20);
+        drawPoint.setY(drawPoint.y() + option.rect.height()/2);
+        painter->drawText(drawPoint,QString("Events: ") + QString::number(index.model()->rowCount(index)));
     }
 
     //// HIGHLIGHTING SELECTED ITEM
@@ -217,13 +235,13 @@ void Delegate::defineControls()
     // FAVOURITE ICONs
     // on
     control = new Control(FavouriteControlOn,QString(":icons/favourite-on.png"));
-    p = QPoint(0,0);
+    p = QPoint(0,SPACER);
     p.setX(p.x()-control->image()->width()-SPACER);
     control->setDrawPoint(p);
     mControls.insert(FavouriteControlOn,control);
     // off
     control = new Control(FavouriteControlOff,QString(":icons/favourite-off.png"));
-    p = QPoint(0,0);
+    p = QPoint(0,SPACER);
     p.setX(p.x()-control->image()->width()-SPACER);
     control->setDrawPoint(p);
     mControls.insert(FavouriteControlOff,control);
@@ -258,3 +276,29 @@ bool Delegate::isPointFromRect(const QPoint &aPoint, const QRect &aRect) const
     return false;
 }
 
+int Delegate::numberOfFavourities(const QModelIndex &index) const
+{
+    if(index.parent().isValid()) // it's event, not time-group
+        return 0;
+
+    int nrofFavs = 0;
+    for(int i=0; i<index.model()->rowCount(index); i++)
+        if(static_cast<Event*>(index.child(i,0).internalPointer())->isFavourite())
+            nrofFavs++;
+
+    return nrofFavs;
+}
+
+int Delegate::numberOfAlarms(const QModelIndex &index) const
+{
+    if(index.parent().isValid()) // it's event, not time-group
+        return 0;
+
+    int nrofAlarms = 0;
+    for(int i=0; i<index.model()->rowCount(index); i++)
+        if(static_cast<Event*>(index.child(i,0).internalPointer())->hasAlarm())
+            nrofAlarms++;
+
+    return nrofAlarms;
+}
+
index 5d7adac..64fc406 100644 (file)
@@ -62,6 +62,13 @@ class Delegate : public QItemDelegate
         bool isLast( const QModelIndex &index ) const;
         bool isExpanded( const QModelIndex &index ) const;
         void defineControls();
+        // TODO: the better place for these methods would be 'eventmodel'
+        // they are used in 'paint' method and so it's better to obtain number of
+        // favourities/alarms once when the data has changed and not to call
+        // these methods which iterate over all Events in corresponding group
+        // every time it requires them
+        int numberOfFavourities(const QModelIndex &index) const;
+        int numberOfAlarms(const QModelIndex &index) const;
 
     private:
         QPointer<QTreeView> mViewPtr;