Warning handling
authorfortefr <fortefr@localhost>
Thu, 21 Jan 2010 15:39:43 +0000 (15:39 +0000)
committerfortefr <fortefr@localhost>
Thu, 21 Jan 2010 15:39:43 +0000 (15:39 +0000)
src/gui/mainwindow.cpp
src/gui/mainwindow.h
src/mvc/delegate.cpp
src/mvc/delegate.h
src/mvc/treeview.cpp
src/mvc/treeview.h

index 7f2da94..97f1716 100644 (file)
 #include <conference.h>
 
 #include <QDialog>
+#include <QMessageBox>
 #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.") );
+}
index dd9e24e..3ee01f8 100644 (file)
@@ -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;
index a566e59..4edde0e 100644 (file)
@@ -135,9 +135,15 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
         // Time conflict
         //if(static_cast<Event*>(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<Event*>(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<QTreeView*>(parent())->visualRect(aIndex)).contains(aPoint))
+        if((mControls[id]->drawRect(static_cast<QTreeView*>(parent())->visualRect(aIndex)).contains(aPoint))
+            && (id != WarningControlOn) && (id != WarningControlOff))
+        {
+            return id;
+        }
+        else
+        {
+            if ((mControls[id]->drawRect(static_cast<QTreeView*>(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);
index 98bef42..d8cc1a4 100644 (file)
@@ -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;
index ac1e5d7..4a7a986 100644 (file)
@@ -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<QString>(aIndex.data());
             // TODO: implement
+            emit(requestForWarning(aIndex));
             handled = true;
         }
         break;
index cf21e06..e608ff1 100644 (file)
@@ -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 */