X-Git-Url: https://git.toastfreeware.priv.at/toast/confclerk.git/blobdiff_plain/b0a3bc74ede1e747c8be13434380eed831b4617a..508de3335b33f912a20b1228016ae0b165fc48be:/src/mvc/delegate.cpp diff --git a/src/mvc/delegate.cpp b/src/mvc/delegate.cpp index 8f5fdb8..dac1bdf 100644 --- a/src/mvc/delegate.cpp +++ b/src/mvc/delegate.cpp @@ -1,3 +1,21 @@ +/* + * 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 . + */ #include "delegate.h" #include "eventmodel.h" #include @@ -5,6 +23,8 @@ #include #include +#include "room.h" + const int RADIUS = 10; const int SPACER = 10; @@ -35,13 +55,14 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons 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(index.internalPointer()); // font SMALL QFont fontSmall = option.font; fontSmall.setBold(false); @@ -65,16 +86,18 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons //int spacer = (fmSmall.boundingRect("999").width() < SPACER) ? SPACER : fmSmall.boundingRect("999").width(); //Time conflicts are colored differently - if(static_cast(index.internalPointer())->hasTimeConflict()) - bkgrColor = Qt::yellow; + 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)); @@ -83,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); @@ -92,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); @@ -116,31 +132,32 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons // draw Controls // favourite - if(static_cast(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(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(static_cast(index.internalPointer())->hasTimeConflict()) + if(event->hasTimeConflict()) painter->drawImage(mControls[WarningControl]->drawPoint(option.rect),*mControls[WarningControl]->image()); // draw texts - Event *event = static_cast(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);