Event favourite is now tristate in the code now and the corresponding buttons are...
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Fri, 20 Jan 2017 20:46:55 +0000 (21:46 +0100)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Fri, 20 Jan 2017 20:46:55 +0000 (21:46 +0100)
src/gui/eventdialog.cpp
src/gui/eventdialog.h
src/icons.qrc
src/icons/favourite-weak.png [new file with mode: 0644]
src/mvc/delegate.cpp
src/mvc/delegate.h
src/mvc/event.cpp
src/mvc/event.h
src/mvc/treeview.cpp

index 67f01d5..dce05bf 100644 (file)
@@ -88,10 +88,7 @@ EventDialog::EventDialog(int conferenceId, int eventId, QWidget *parent): QDialo
     connect(favouriteButton, SIGNAL(clicked()), SLOT(favouriteClicked()));
     connect(alarmButton, SIGNAL(clicked()), SLOT(alarmClicked()));
 
-    if(event.isFavourite())
-    {
-        favouriteButton->setIcon(QIcon(":/icons/favourite-on.png"));
-    }
+    updateFavouriteButton(event);
 
     if(event.hasAlarm())
     {
@@ -102,25 +99,12 @@ EventDialog::EventDialog(int conferenceId, int eventId, QWidget *parent): QDialo
 void EventDialog::favouriteClicked()
 {
     Event event = Event::getById(mEventId, mConferenceId);
-
-    QList<Event> conflicts = Event::conflictEvents(event.id(), mConferenceId);
-    if(event.isFavourite())
-    {
-        event.setFavourite(false);
-        favouriteButton->setIcon(QIcon(":/icons/favourite-off.png"));
-    }
-    else
-    {
-        event.setFavourite(true);
-        favouriteButton->setIcon(QIcon(":/icons/favourite-on.png"));
-    }
+    event.cycleFavourite();
     event.update("favourite");
+    updateFavouriteButton(event);
 
-    if(event.isFavourite())
-    {
-        // event has became 'favourite' and so 'conflicts' list may have changed
-        conflicts = Event::conflictEvents(event.id(), mConferenceId);
-    }
+    // 'conflicts' list may have changed
+    QList<Event> conflicts = Event::conflictEvents(event.id(), mConferenceId);
 
     // have to emit 'eventChanged' signal on all events in conflict
     for(int i=0; i<conflicts.count(); i++)
@@ -162,3 +146,12 @@ void EventDialog::alarmClicked()
     emit eventChanged(event.id(), false);
 }
 
+
+void EventDialog::updateFavouriteButton(const Event& event) {
+    switch (event.favourite()) {
+        case Favourite_no: favouriteButton->setIcon(QIcon(":/icons/favourite-off.png")); break;
+        case Favourite_weak: favouriteButton->setIcon(QIcon(":/icons/favourite-weak.png")); break;
+        case Favourite_strong: favouriteButton->setIcon(QIcon(":/icons/favourite-on.png")); break;
+    }
+}
+
index 6a0f0b4..9d31ed8 100644 (file)
@@ -38,6 +38,7 @@ signals:
 private:
     int mConferenceId;
     int mEventId;
+    void updateFavouriteButton(const Event& event);
 };
 
 #endif /* EVENTDIALOG_H */
index 60b5634..563300e 100644 (file)
@@ -9,6 +9,7 @@
         <file>icons/search.png</file>
         <file>icons/today.png</file>
         <file>icons/favourite-off.png</file>
+        <file>icons/favourite-weak.png</file>
         <file>icons/favourite-on.png</file>
         <file>icons/alarm-on.png</file>
         <file>icons/alarm-off.png</file>
diff --git a/src/icons/favourite-weak.png b/src/icons/favourite-weak.png
new file mode 100644 (file)
index 0000000..79ec011
Binary files /dev/null and b/src/icons/favourite-weak.png differ
index ef7dc7a..065d21d 100644 (file)
@@ -64,7 +64,7 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
         // * spacer (aka y position of image)
         // * image
         // * rest is text, which is 1 line of title with big letters and 2 lines of Presenter and Track
-        int aux = option.rect.height() - SPACER - mControls[FavouriteControlOn]->image()->height();
+        int aux = option.rect.height() - SPACER - mControls[FavouriteControlStrong]->image()->height();
         Event *event = static_cast<Event*>(index.internalPointer());
 
         // font SMALL
@@ -105,10 +105,17 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
         foreach(Control* c, mControls.values()) {
             c->setEnabled(false);
         }
-        if(event->isFavourite())
-            mControls[FavouriteControlOn]->paint(painter, option.rect);
-        else
-            mControls[FavouriteControlOff]->paint(painter, option.rect);
+        switch (event->favourite()) {
+        case Favourite_strong:
+            mControls[FavouriteControlStrong]->paint(painter, option.rect);
+            break;
+        case Favourite_weak:
+            mControls[FavouriteControlWeak]->paint(painter, option.rect);
+            break;
+        case Favourite_no:
+            mControls[FavouriteControlNo]->paint(painter, option.rect);
+            break;
+        }
 
         if(event->hasAlarm())
             mControls[AlarmControlOn]->paint(painter, option.rect);
@@ -124,7 +131,7 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
         //  so the first line is actually at the same height as the image)
         painter->setPen(QPen(event->hasTimeConflict() ? Qt::black : textColor));
         QPointF titlePointF(option.rect.x() + SPACER,
-                            option.rect.y() + SPACER + mControls[FavouriteControlOn]->image()->height());
+                            option.rect.y() + SPACER + mControls[FavouriteControlStrong]->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());
@@ -188,7 +195,7 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
         // draw icons
         painter->setPen(QPen(textColor));
         painter->setFont(fontSmall);
-        QImage *image = mControls[numFav ? FavouriteControlOn : FavouriteControlOff]->image();
+        QImage *image = mControls[numFav ? FavouriteControlStrong : FavouriteControlNo]->image();
         QPoint drawPoint =
             option.rect.topRight()
             - QPoint(
@@ -306,18 +313,20 @@ void Delegate::Control::paint(QPainter* painter, const QRect rect)
 void Delegate::defineControls()
 {
     // FAVOURITE ICONs
-    // on
-    mControls.insert(FavouriteControlOn, new Control(FavouriteControlOn, QString(":icons/favourite-on.png"), NULL));
-    // off
-    mControls.insert(FavouriteControlOff, new Control(FavouriteControlOff, QString(":icons/favourite-off.png"), NULL));
+    // strong
+    mControls.insert(FavouriteControlStrong, new Control(FavouriteControlStrong, QString(":icons/favourite-on.png"), NULL));
+    // weak
+    mControls.insert(FavouriteControlWeak, new Control(FavouriteControlWeak, QString(":icons/favourite-weak.png"), NULL));
+    // no
+    mControls.insert(FavouriteControlNo, new Control(FavouriteControlNo, QString(":icons/favourite-off.png"), NULL));
 
     // ALARM ICONs
     // on
     mControls.insert(AlarmControlOn,
-                    new Control(AlarmControlOn, QString(":icons/alarm-on.png"), mControls[FavouriteControlOn]));
+                    new Control(AlarmControlOn, QString(":icons/alarm-on.png"), mControls[FavouriteControlStrong]));
     // off
     mControls.insert(AlarmControlOff,
-                    new Control(AlarmControlOff, QString(":icons/alarm-off.png"), mControls[FavouriteControlOff]));
+                    new Control(AlarmControlOff, QString(":icons/alarm-off.png"), mControls[FavouriteControlNo]));
     // WARNING ICON
     mControls.insert(WarningControl,
                     new Control(WarningControl, QString(":icons/dialog-warning.png"), mControls[AlarmControlOff]));
@@ -338,7 +347,7 @@ int Delegate::numberOfFavourities(const QModelIndex &index) const
 
     int nrofFavs = 0;
     for(int i=0; i<index.model()->rowCount(index); i++)
-        if(static_cast<Event*>(index.child(i,0).internalPointer())->isFavourite())
+        if(static_cast<Event*>(index.child(i,0).internalPointer())->favourite() != Favourite_no)
             nrofFavs++;
 
     return nrofFavs;
index e285795..ec67731 100644 (file)
@@ -31,8 +31,9 @@ class Delegate : public QItemDelegate
         enum ControlId
         {
             ControlNone = 0,
-            FavouriteControlOn,
-            FavouriteControlOff,
+            FavouriteControlStrong,
+            FavouriteControlWeak,
+            FavouriteControlNo,
             AlarmControlOn,
             AlarmControlOff,
             WarningControl
index 4ac2f68..47a7494 100644 (file)
@@ -90,7 +90,7 @@ QList<Event> Event::conflictEvents(int aEventId, int conferenceId) {
     query.prepare(selectQuery() + "WHERE xid_conference = :conf AND ( \
            ( start >= :s1 AND ( start + duration ) < :e1 ) \
         OR ( ( start + duration ) > :s2 AND start < :e2 ) ) \
-        AND favourite = 1 AND NOT id = :id ORDER BY start, duration");
+        AND favourite >= 1 AND NOT id = :id ORDER BY start, duration");
     query.bindValue(":conf", event.conferenceId());
     query.bindValue(":s1", convertToDb(event.start(), QVariant::DateTime));
     query.bindValue(":e1", convertToDb(event.start().toTime_t()+event.duration(), QVariant::DateTime));
@@ -116,7 +116,7 @@ QList<Event> Event::getFavByDate(const QDate& date, int conferenceId) {
     Conference conference = Conference::getById(conferenceId);
     QDateTime dayStart(date, conference.dayChangeTime(), Qt::UTC);
     QSqlQuery query;
-    query.prepare(selectQuery() + QString("WHERE xid_conference = :conf AND start >= :start AND start < :end AND favourite = 1 ORDER BY start, duration"));
+    query.prepare(selectQuery() + QString("WHERE xid_conference = :conf AND start >= :start AND start < :end AND favourite >= 1 ORDER BY start, duration"));
     query.bindValue(":conf", conferenceId);
     query.bindValue(":start", dayStart.toTime_t());
     query.bindValue(":end", dayStart.addDays(1).toTime_t());
@@ -194,10 +194,18 @@ QMap<QString,QString> Event::links()
 
 bool Event::hasTimeConflict() const
 {
-    if(!isFavourite()) // if it's not favourite, it can't have time-conflict
+    if(favourite() == Favourite_no) // if it's not favourite, it can't have time-conflict
         return false;
 
-    return conflictEvents(id(),conferenceId()).count() > 0 ? true : false;
+    return conflictEvents(id(),conferenceId()).count() > 0;
+}
+
+void Event::cycleFavourite() {
+    switch (favourite()) {
+        case Favourite_no: setFavourite(Favourite_strong); break;
+        case Favourite_strong: setFavourite(Favourite_weak); break;
+        case Favourite_weak: setFavourite(Favourite_no); break;
+    }
 }
 
 void Event::setRoom(const QString &room)
index 481db52..6322d04 100644 (file)
@@ -88,6 +88,7 @@ public:
     void setLanguage(const QString & language) { setValue("language", language); }
     void setFavourite(Favourite favourite) { setValue("favourite", (int) favourite); }
     void setFavourite(bool favourite) { setFavourite(favourite ? Favourite_strong : Favourite_no); } // deprecated
+    void cycleFavourite();
     void setHasAlarm(bool alarm) { setValue("alarm", (int)((alarm))); }
     void setTag(const QString& tag) { setValue("tag", tag); }
     void setTitle(const QString& title) { setValue("title", title); }
index a3c081a..b4510ce 100644 (file)
@@ -64,21 +64,19 @@ bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aP
     Delegate *delegate = static_cast<Delegate*>(itemDelegate(aIndex));
     switch(delegate->whichControlClicked(aIndex,aPoint))
     {
-        case Delegate::FavouriteControlOn:
-        case Delegate::FavouriteControlOff:
+        case Delegate::FavouriteControlStrong:
+        case Delegate::FavouriteControlWeak:
+        case Delegate::FavouriteControlNo:
             {
                 // handle Favourite Control clicked
                 Event event = Event::getById(aIndex.data().toInt(),confId);
 
                 QList<Event> conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
-                event.setFavourite(!event.isFavourite());
+                event.cycleFavourite();
                 event.update("favourite");
 
-                if(event.isFavourite())
-                {
-                    // event has became 'favourite' and so 'conflicts' list may have changed
-                    conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
-                }
+                // event has became 'favourite' and so 'conflicts' list may have changed
+                conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
 
                 // have to emit 'eventChanged' signal on all events in conflict
                 for(int i=0; i<conflicts.count(); i++)