+/*
+ * 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 <track.h>
#include <QDebug>
#include <QPainter>
+#include "room.h"
+
const int RADIUS = 10;
-const int SPACER = RADIUS;
+const int SPACER = 10;
+
+const double scaleFactor1 = 0.4;
+const double scaleFactor2 = 0.8;
Delegate::Delegate(QTreeView *aParent)
: QItemDelegate(aParent)
return;
painter->save();
-
QColor bkgrColor = Qt::cyan;
+ //QColor bkgrColor = QColor(0xAA,0xAA,0xAA);
+ QColor conflictColor = Qt::yellow;
+
QPen borderPen(bkgrColor.darker());
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);
+ fontSmall.setPixelSize(aux*0.2);
+ QFontMetrics fmSmall(fontSmall);
+ // font SMALL bold
+ QFont fontSmallB = fontSmall;
+ fontSmallB.setBold(true);
+ QFontMetrics fmSmallB(fontSmallB);
+
+ // font BIG
+ QFont fontBig = option.font;
+ fontBig.setBold(false);
+ fontBig.setPixelSize(aux*0.33);
+ QFontMetrics fmBig(fontBig);
+ // font BIG bold
+ QFont fontBigB = fontBig;
+ fontBigB.setBold(true);
+ QFontMetrics fmBigB(fontBigB);
+
+ //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));
endPath.lineTo(option.rect.topRight());
//painter->setBrush( bkgrColor );
- painter->setBrush(lastGradient);
+ painter->setBrush(itemGradient);
painter->setPen(borderPen);
painter->drawPath(endPath);
}
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(itemGradient);
painter->setPen(Qt::NoPen);
painter->drawRect(option.rect);
}
// draw Controls
- if(static_cast<Event*>(index.internalPointer())->isFavourite())
+ // favourite
+ if(event->isFavourite())
painter->drawImage(mControls[FavouriteControlOn]->drawPoint(option.rect),*mControls[FavouriteControlOn]->image());
else
painter->drawImage(mControls[FavouriteControlOff]->drawPoint(option.rect),*mControls[FavouriteControlOff]->image());
- painter->drawImage(mControls[AlarmControlOn]->drawPoint(option.rect),*mControls[AlarmControlOn]->image());
- painter->drawImage(mControls[MapControl]->drawPoint(option.rect),*mControls[MapControl]->image());
+#ifdef MAEMO
+ // alarm
+ 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
+ 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
+ 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->roomName());
+ // title
+ titlePointF.setY(titlePointF.y()+fmBig.height()-fmBig.descent());
+ painter->setFont(fontBigB);
+ QString title = event->title();
+ if(fmBigB.boundingRect(title).width() > (option.rect.width()-2*SPACER)) // the title won't fit the screen
+ {
+ // chop words from the end
+ while( (fmBigB.boundingRect(title + "...").width() > (option.rect.width()-2*SPACER)) && !title.isEmpty())
+ {
+ title.chop(1);
+ // chop characters one-by-one from the end
+ while( (!title.at(title.length()-1).isSpace()) && !title.isEmpty())
+ {
+ title.chop(1);
+ }
+ }
+ title += "...";
+ }
+ painter->drawText(titlePointF,title);
+ // persons
+ titlePointF.setY(titlePointF.y()+fmSmall.height()-fmSmall.descent());
+ painter->setFont(fontSmall);
+ painter->drawText(titlePointF,"Presenter(s): " + event->persons().join(" and "));
+ // track
+ titlePointF.setY(titlePointF.y()+fmSmall.height()-fmSmall.descent());
+ painter->drawText(titlePointF,"Track: " + Track::retrieveTrackName(event->trackId()));
}
else // doesn't have parent - time-groups' elements (top items)
{
+ QFont fontSmall = option.font;
+ fontSmall.setBold(true);
+ fontSmall.setPixelSize(option.rect.height()*scaleFactor1);
+ QFontMetrics fmSmall(fontSmall);
+
+ QFont fontBig = option.font;
+ fontBig.setBold(true);
+ fontBig.setPixelSize(option.rect.height()*scaleFactor2);
+ QFontMetrics fmBig(fontBig);
+
+ int spacer = (fmSmall.boundingRect("999").width() < SPACER) ? SPACER : fmSmall.boundingRect("999").width();
+
QLinearGradient titleGradient(option.rect.topLeft(), option.rect.topRight());
//titleGradient.setColorAt(0.0, Qt::white);
titleGradient.setColorAt(0.0, bkgrColor);
painter->setPen(borderPen);
painter->drawPath(titlePath);
- QFont font = option.font;
- font.setBold(true);
- painter->setFont(font);
+ // draw icons
+ painter->setFont(fontSmall);
+ QImage *image = mControls[FavouriteControlOn]->image();
+ QPoint drawPoint =
+ option.rect.topRight()
+ - QPoint(
+ 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)));
+#ifdef MAEMO
+ drawPoint.setX(drawPoint.x() - spacer - image->width());
+ painter->drawImage(drawPoint,*mControls[AlarmControlOn]->image());
+ 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()+image->height() - 2);
+ painter->drawText(drawPoint,numEvents);
+
+ QPointF titlePointF = QPoint(
+ option.rect.x()+SPACER,
+ option.rect.y()+option.rect.height()-fmBig.descent());
+ painter->setFont(fontBig);
+
+ painter->drawText(titlePointF,qVariantValue<QString>(index.data()));
}
//// HIGHLIGHTING SELECTED ITEM
//if (option.state & QStyle::State_Selected)
//painter->fillRect(option.rect, option.palette.highlight());
- // draw title
- QPointF titlePointF(option.rect.x()+SPACER,option.rect.y()+option.rect.height()-10);
- QString text;
- if(index.parent().isValid()) // event
- text = qVariantValue<QString>(index.data()) + ": " + static_cast<Event*>(index.internalPointer())->title();
- else // group
- text = qVariantValue<QString>(index.data());
- painter->drawText(titlePointF,text);
-
painter->restore();
}
if (index.internalId() == 0) // time group
{
- return QSize(30,30);
+ return QSize(40,40);
}
else // event
{
{
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;
QPoint p(0,0);
// FAVOURITE ICONs
// on
- control = new Control(FavouriteControlOn,QString(":icons/favourite-on.png"));
- p = QPoint(0,0);
+ control = new Control(FavouriteControlOn,QString(":icons/favourite-onBig.png"));
+ 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);
+ control = new Control(FavouriteControlOff,QString(":icons/favourite-offBig.png"));
+ p = QPoint(0,SPACER);
p.setX(p.x()-control->image()->width()-SPACER);
control->setDrawPoint(p);
mControls.insert(FavouriteControlOff,control);
+#ifdef MAEMO
// ALARM ICONs
// on
- control = new Control(AlarmControlOn,QString(":icons/alarm-off.png"));
+ control = new Control(AlarmControlOn,QString(":icons/alarm-onBig.png"));
p = mControls[FavouriteControlOn]->drawPoint();
p.setX(p.x()-control->image()->width()-SPACER);
control->setDrawPoint(p);
mControls.insert(AlarmControlOn,control);
// off
- control = new Control(AlarmControlOff,QString(":icons/alarm-off.png"));
+ control = new Control(AlarmControlOff,QString(":icons/alarm-offBig.png"));
p = mControls[FavouriteControlOff]->drawPoint();
p.setX(p.x()-control->image()->width()-SPACER);
control->setDrawPoint(p);
mControls.insert(AlarmControlOff,control);
// MAP ICON
- control = new Control(MapControl,QString(":icons/compass.png"));
+ control = new Control(MapControl,QString(":icons/compassBig.png"));
p = mControls[AlarmControlOn]->drawPoint();
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
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;
+}
+