From 3f3e22d1e14247c2a6b71cf13f85b377c548154e Mon Sep 17 00:00:00 2001 From: fortefr Date: Thu, 21 Jan 2010 15:39:43 +0000 Subject: [PATCH] Warning handling --- src/gui/mainwindow.cpp | 14 ++++++++++++++ src/gui/mainwindow.h | 1 + src/mvc/delegate.cpp | 21 ++++++++++++++++++++- src/mvc/delegate.h | 1 + src/mvc/treeview.cpp | 5 ++++- src/mvc/treeview.h | 1 + 6 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 7f2da94..97f1716 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -12,12 +12,14 @@ #include #include +#include #include "ui_about.h" #include "eventdialog.h" #include "daynavigatorwidget.h" #include "importscheduledialog.h" #include "mapwindow.h" + const int confId = 1; MainWindow::MainWindow(int aEventId, QWidget *aParent) @@ -85,6 +87,11 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent) connect(favTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &))); connect(trackTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &))); connect(searchTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &))); + // request for warning to be displayed + connect(dayTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &))); + connect(favTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &))); + connect(trackTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &))); + connect(searchTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &))); // event search button clicked connect(searchButton, SIGNAL(clicked()), SLOT(searchClicked())); @@ -273,3 +280,10 @@ void MainWindow::searchClicked() updateSearchView( Conference::getById(confId).start() ); } +void MainWindow::displayWarning(const QModelIndex &aIndex) +{ + QMessageBox::warning( + this, + tr("Time Conflict Warning"), + tr("This event happens at the same time than another one of your favourites.") ); +} diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index dd9e24e..3ee01f8 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -25,6 +25,7 @@ private slots: void updateSearchView(const QDate &aDate); void itemClicked(const QModelIndex &aIndex); void displayMap(const QModelIndex &aIndex); + void displayWarning(const QModelIndex &aIndex); void searchClicked(); private: SqlEngine *mSqlEngine; diff --git a/src/mvc/delegate.cpp b/src/mvc/delegate.cpp index a566e59..4edde0e 100644 --- a/src/mvc/delegate.cpp +++ b/src/mvc/delegate.cpp @@ -135,9 +135,15 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons // Time conflict //if(static_cast(index.internalPointer())->hasTimeConflict()) if(bkgrColor == Qt::yellow) + { painter->drawImage(mControls[WarningControlOn]->drawPoint(option.rect),*mControls[WarningControlOn]->image()); + mControls[WarningControlOn]->hasConflict=true; + } else + { painter->drawImage(mControls[WarningControlOff]->drawPoint(option.rect),*mControls[WarningControlOff]->image()); + mControls[WarningControlOn]->hasConflict=false; + } // draw texts Event *event = static_cast(index.internalPointer()); @@ -309,8 +315,19 @@ Delegate::ControlId Delegate::whichControlClicked(const QModelIndex &aIndex, con while (i.hasNext()) { ControlId id = i.next(); - if(mControls[id]->drawRect(static_cast(parent())->visualRect(aIndex)).contains(aPoint)) + if((mControls[id]->drawRect(static_cast(parent())->visualRect(aIndex)).contains(aPoint)) + && (id != WarningControlOn) && (id != WarningControlOff)) + { + return id; + } + else + { + if ((mControls[id]->drawRect(static_cast(parent())->visualRect(aIndex)).contains(aPoint)) + && (mControls[id]->hasConflict)) + { return id; + } + } } return ControlNone; @@ -368,12 +385,14 @@ void Delegate::defineControls() // on control = new Control(WarningControlOn,QString(":icons/exclamation-iconOn.png")); p = mControls[MapControl]->drawPoint(); + control->hasConflict = false; p.setX(p.x()-control->image()->width()-SPACER); control->setDrawPoint(p); mControls.insert(WarningControlOn,control); // off control = new Control(WarningControlOff,QString(":icons/exclamation-iconOff.png")); p = mControls[MapControl]->drawPoint(); + control->hasConflict = false; p.setX(p.x()-control->image()->width()-SPACER); control->setDrawPoint(p); mControls.insert(WarningControlOff,control); diff --git a/src/mvc/delegate.h b/src/mvc/delegate.h index 98bef42..d8cc1a4 100644 --- a/src/mvc/delegate.h +++ b/src/mvc/delegate.h @@ -44,6 +44,7 @@ class Delegate : public QItemDelegate { return QRect(drawPoint(aRect), drawPoint(aRect)+QPoint(mImage->size().width(),mImage->size().height())); } + bool hasConflict; private: ControlId mId; QImage *mImage; diff --git a/src/mvc/treeview.cpp b/src/mvc/treeview.cpp index ac1e5d7..4a7a986 100644 --- a/src/mvc/treeview.cpp +++ b/src/mvc/treeview.cpp @@ -106,10 +106,13 @@ bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aP handled = true; } break; - case Delegate::WarningControlOn: case Delegate::WarningControlOff: + case Delegate::WarningControlOn: { + + qDebug() << "WARNING CLICKED: " << qVariantValue(aIndex.data()); // TODO: implement + emit(requestForWarning(aIndex)); handled = true; } break; diff --git a/src/mvc/treeview.h b/src/mvc/treeview.h index cf21e06..e608ff1 100644 --- a/src/mvc/treeview.h +++ b/src/mvc/treeview.h @@ -16,6 +16,7 @@ private slots: void handleItemClicked(const QModelIndex &index); signals: void requestForMap(const QModelIndex &aIndex); + void requestForWarning(const QModelIndex &aIndex); }; #endif /* TREEVIEW_H */ -- 2.39.5