From 699d5b8b1b53e8b3866150d59799d8cd96a53d63 Mon Sep 17 00:00:00 2001 From: fortefr Date: Thu, 21 Jan 2010 13:38:39 +0000 Subject: [PATCH] Time conflict warning --- src/mvc/delegate.cpp | 37 +++++++++++++++++++++++++++++++++++-- src/mvc/delegate.h | 1 + 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/mvc/delegate.cpp b/src/mvc/delegate.cpp index 54808b8..6f620b2 100644 --- a/src/mvc/delegate.cpp +++ b/src/mvc/delegate.cpp @@ -34,8 +34,8 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons return; painter->save(); - QColor bkgrColor = Qt::cyan; + QPen borderPen(bkgrColor.darker()); //QColor bkgrColor = QColor(0,0,113); //QPen borderPen(Qt::cyan); @@ -64,6 +64,13 @@ 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())->isFavourite()) + && (hasTimeConflict(index, index.parent()))) + { + bkgrColor = Qt::yellow; + } + if(isLast(index)) { QLinearGradient lastGradient(option.rect.topLeft(), option.rect.bottomLeft()); @@ -126,7 +133,8 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons // map painter->drawImage(mControls[MapControl]->drawPoint(option.rect),*mControls[MapControl]->image()); // Time conflict - if(static_cast(index.internalPointer())->hasTimeConflict()) + //if(static_cast(index.internalPointer())->hasTimeConflict()) + if(bkgrColor == Qt::yellow) painter->drawImage(mControls[WarningControlOn]->drawPoint(option.rect),*mControls[WarningControlOn]->image()); else painter->drawImage(mControls[WarningControlOff]->drawPoint(option.rect),*mControls[WarningControlOff]->image()); @@ -405,3 +413,28 @@ int Delegate::numberOfAlarms(const QModelIndex &index) const return nrofAlarms; } +bool Delegate::hasTimeConflict(const QModelIndex &index, const QModelIndex &parent) const +{ + Event *event = static_cast(index.internalPointer()); + QTime start = event->start().time(); + QTime end = start.addSecs(event->duration()); + for(int i=0; irowCount(parent); i++) + { + if((event->id()!=static_cast(parent.child(i,0).internalPointer())->id()) + && + (static_cast(parent.child(i,0).internalPointer())->isFavourite())) + { + if (((start >= static_cast(parent.child(i,0).internalPointer())->start().time()) + && + (start <= static_cast(parent.child(i,0).internalPointer())->start().time().addSecs(static_cast(parent.child(i,0).internalPointer())->duration()))) + || + ((end >= static_cast(parent.child(i,0).internalPointer())->start().time()) + && + (end <= static_cast(parent.child(i,0).internalPointer())->start().time().addSecs(static_cast(parent.child(i,0).internalPointer())->duration())))) + { + return true; + } + } + } + return false; +} diff --git a/src/mvc/delegate.h b/src/mvc/delegate.h index 269e35e..98bef42 100644 --- a/src/mvc/delegate.h +++ b/src/mvc/delegate.h @@ -71,6 +71,7 @@ class Delegate : public QItemDelegate // every time it requires them int numberOfFavourities(const QModelIndex &index) const; int numberOfAlarms(const QModelIndex &index) const; + bool hasTimeConflict(const QModelIndex &index, const QModelIndex &parent) const; private: QPointer mViewPtr; -- 2.39.5