/*
* Copyright (C) 2010 Ixonos Plc.
+ * Copyright (C) 2011-2017 Philipp Spitzer, gregor herrmann, Stefan Stahl
*
- * This file is part of fosdem-schedule.
+ * This file is part of ConfClerk.
*
- * fosdem-schedule is free software: you can redistribute it and/or modify it
+ * ConfClerk 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
+ * ConfClerk 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 <http://www.gnu.org/licenses/>.
+ * ConfClerk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "delegate.h"
#include "eventmodel.h"
-#include <track.h>
+#include "track.h"
#include <QDebug>
#include <QPainter>
#include "room.h"
-const int RADIUS = 10;
const int SPACER = 10;
const double scaleFactor1 = 0.4;
void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
- if(!mViewPtr)
+ if (!mViewPtr)
return;
painter->save();
- QColor bkgrColor = Qt::cyan;
- //QColor bkgrColor = QColor(0xAA,0xAA,0xAA);
- QColor conflictColor = Qt::yellow;
- QPen borderPen(bkgrColor.darker());
+ QColor textColor = option.palette.color(QPalette::Text);
+
if(hasParent(index))
{
- // entry horisontal layout:
+ Event *event = static_cast<Event*>(index.internalPointer());
+
+ // determine severity of conflict
+ Favourite eventTimeConflict = event->timeConflict(); // cache value as event->timeConflict is expensive
+ enum ConflictSeverity {csNone, csWeak, csStrong} conflictSeverity = csNone;
+ switch (event->favourite()) {
+ case Favourite_strong:
+ conflictSeverity = (eventTimeConflict == Favourite_strong) ? csStrong : csNone;
+ break;
+ case Favourite_weak:
+ conflictSeverity = (eventTimeConflict == Favourite_no) ? csNone : csWeak;
+ break;
+ case Favourite_no:
+ conflictSeverity = csNone;
+ break;
+ }
+
+ // entry horizontal layout:
// * 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();
- Event *event = static_cast<Event*>(index.internalPointer());
+ int aux = option.rect.height() - SPACER - mControls[FavouriteControlStrong]->image()->height();
+
// font SMALL
QFont fontSmall = option.font;
fontSmall.setBold(false);
// font SMALL bold
QFont fontSmallB = fontSmall;
fontSmallB.setBold(true);
- QFontMetrics fmSmallB(fontSmallB);
// font BIG
QFont fontBig = option.font;
fontBig.setBold(false);
fontBig.setPixelSize(aux*0.33);
QFontMetrics fmBig(fontBig);
+
// font BIG bold
QFont fontBigB = fontBig;
fontBigB.setBold(true);
QFontMetrics fmBigB(fontBigB);
- //int spacer = (fmSmall.boundingRect("999").width() < SPACER) ? SPACER : fmSmall.boundingRect("999").width();
-
- //Time conflicts are colored differently
- 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))
- {
- QPainterPath endPath;
- endPath.moveTo(option.rect.topLeft());
- endPath.lineTo(option.rect.bottomLeft()-QPoint(0, RADIUS));
- endPath.arcTo(option.rect.left(), option.rect.bottom()-2*RADIUS, 2*RADIUS, 2*RADIUS, 180, 90);
- endPath.lineTo(option.rect.bottomRight()-QPoint(RADIUS, 0));
- 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(itemGradient);
- painter->setPen(borderPen);
- painter->drawPath(endPath);
-
- painter->setFont(option.font);
- }
- else // middle elements
- {
- //painter->setBrush( bkgrColor );
- painter->setBrush(itemGradient);
+ // background (in case of time conflicts)
+ if (conflictSeverity != csNone) {
+ painter->setBrush(conflictSeverity == csStrong ? Qt::yellow : QColor("lightyellow"));
painter->setPen(Qt::NoPen);
painter->drawRect(option.rect);
+ }
- painter->setPen(borderPen);
- // vertical lines
- painter->drawLine(option.rect.topLeft(), option.rect.bottomLeft());
- painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
- // horizontal lines
- painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
-
- painter->setFont(option.font);
+ // background (without time conflicts)
+ else {
+ QStyleOption styleOption;
+ styleOption.rect = option.rect;
+ qApp->style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &styleOption, painter, mViewPtr);
}
// draw Controls
- if(event->isFavourite())
- mControls[FavouriteControlOn]->paint(painter, option.rect);
- else
- mControls[FavouriteControlOff]->paint(painter, option.rect);
-#ifdef MAEMO
+ foreach(Control* c, mControls.values()) {
+ c->setEnabled(false);
+ }
+ 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);
else
mControls[AlarmControlOff]->paint(painter, option.rect);
-#endif
- if (event->room()->hasMap())
- mControls[MapControl]->paint(painter, option.rect);
- if(event->hasTimeConflict())
+
+ if(eventTimeConflict != Favourite_no)
mControls[WarningControl]->paint(painter, option.rect);
// draw texts
// it starts just below the image
// ("position of text" is lower-left angle of the first letter,
// so the first line is actually at the same height as the image)
+ painter->setPen(QPen(conflictSeverity != csNone ? 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());
+
// title
titlePointF.setY(titlePointF.y()+fmBig.height()-fmBig.descent());
painter->setFont(fontBigB);
title += "...";
}
painter->drawText(titlePointF,title);
+
// persons
titlePointF.setY(titlePointF.y()+fmSmall.height()-fmSmall.descent());
painter->setFont(fontSmall);
- painter->drawText(titlePointF,"Presenter(s): " + event->persons().join(" and "));
+ QString presenterPrefix = event->persons().count() < 2 ? "Presenter" : "Presenters";
+ painter->drawText(titlePointF,presenterPrefix + ": " + event->persons().join(" and "));
+
// track
titlePointF.setY(titlePointF.y()+fmSmall.height()-fmSmall.descent());
painter->drawText(titlePointF,"Track: " + Track::retrieveTrackName(event->trackId()));
}
+
else // doesn't have parent - time-groups' elements (top items)
{
+ int numFav = numberOfFavourities(index);
+ int numAlarm = numberOfAlarms(index);
+
+ QStyleOptionButton styleOptionButton;
+ styleOptionButton.rect = option.rect;
+ if (isExpanded(index)) styleOptionButton.state = QStyle::State_Sunken;
+ // styleOptionButton.text = qVariantValue<QString>(index.data());
+ qApp->style()->drawPrimitive(QStyle::PE_PanelButtonCommand, &styleOptionButton, painter, mViewPtr);
+ // qApp->style()->drawControl(QStyle::CE_PushButtonLabel, &styleOptionButton, painter, mViewPtr);
+ // qApp->style()->drawPrimitive(QStyle::PE_IndicatorArrowDown, &styleOptionButton, painter, mViewPtr);
+
QFont fontSmall = option.font;
fontSmall.setBold(true);
fontSmall.setPixelSize(option.rect.height()*scaleFactor1);
int spacer = (fmSmall.boundingRect("999").width() < SPACER) ? SPACER : fmSmall.boundingRect("999").width();
- QLinearGradient titleGradient(option.rect.topLeft(), option.rect.topRight());
- //titleGradient.setColorAt(0.0, Qt::white);
- titleGradient.setColorAt(0.0, bkgrColor);
- titleGradient.setColorAt(0.5, Qt::white);
- titleGradient.setColorAt(1.0, bkgrColor);
-
- QPainterPath titlePath;
- if(isExpanded(index))
- {
- titlePath.moveTo(option.rect.bottomLeft());
- titlePath.lineTo(option.rect.topLeft()+QPoint(0, RADIUS));
- titlePath.arcTo(option.rect.left(), option.rect.top(), 2*RADIUS, 2*RADIUS, 180, -90);
- titlePath.lineTo(option.rect.topRight()-QPoint(RADIUS, 0));
- titlePath.arcTo(option.rect.right()-2*RADIUS, option.rect.top(), 2*RADIUS, 2*RADIUS, 90, -90);
- titlePath.lineTo(option.rect.bottomRight());
- titlePath.closeSubpath();
- }
- else
- {
- titlePath.lineTo(option.rect.topLeft()+QPoint(0, RADIUS));
- titlePath.arcTo(option.rect.left(), option.rect.top(), 2*RADIUS, 2*RADIUS, 180, -90);
- titlePath.lineTo(option.rect.topRight()-QPoint(RADIUS, 0));
- titlePath.arcTo(option.rect.right()-2*RADIUS, option.rect.top(), 2*RADIUS, 2*RADIUS, 90, -90);
- titlePath.lineTo(option.rect.bottomRight()-QPoint(0, RADIUS));
- titlePath.arcTo(option.rect.right()-2*RADIUS, option.rect.bottom()-2*RADIUS, 2*RADIUS, 2*RADIUS, 0, -90);
- titlePath.lineTo(option.rect.bottomLeft()+QPoint(RADIUS, 0));
- titlePath.arcTo(option.rect.left(), option.rect.bottom()-2*RADIUS, 2*RADIUS, 2*RADIUS, 270, -90);
- titlePath.closeSubpath();
- }
-
- painter->setBrush(titleGradient);
- painter->setPen(borderPen);
- painter->drawPath(titlePath);
-
- // draw icons
+ // draw icons
+ painter->setPen(QPen(textColor));
painter->setFont(fontSmall);
- QImage *image = mControls[FavouriteControlOn]->image();
+ QImage *image = mControls[numFav ? FavouriteControlStrong : FavouriteControlNo]->image();
QPoint drawPoint =
option.rect.topRight()
- QPoint(
- option.rect.height()/2 + image->height()/2);
painter->drawImage(drawPoint,*image);
painter->drawText(drawPoint+QPoint(image->width()+2, image->height() - 2),
- QString::number(numberOfFavourities(index)));
-#ifdef MAEMO
+ QString::number(numFav));
+
drawPoint.setX(drawPoint.x() - spacer - image->width());
- painter->drawImage(drawPoint,*mControls[AlarmControlOn]->image());
+ image = mControls[numAlarm ? AlarmControlOn : AlarmControlOff]->image();
+ painter->drawImage(drawPoint,*image);
painter->drawText(drawPoint+QPoint(image->width()+2, image->height() - 2),
- QString::number(numberOfAlarms(index)));
-#endif
+ QString::number(numAlarm));
+
// draw texts
QString numEvents = QString::number(index.model()->rowCount(index)).append("/");
drawPoint.setX(drawPoint.x() - spacer - fmSmall.boundingRect(numEvents).width());
option.rect.x()+SPACER,
option.rect.y()+option.rect.height()-fmBig.descent());
painter->setFont(fontBig);
-
- painter->drawText(titlePointF,qVariantValue<QString>(index.data()));
+ painter->drawText(titlePointF,index.data().value<QString>());
}
- //// HIGHLIGHTING SELECTED ITEM
- //if (option.state & QStyle::State_Selected)
- //painter->fillRect(option.rect, option.palette.highlight());
-
painter->restore();
}
while (i.hasNext())
{
ControlId id = i.next();
- if(mControls[id]->drawRect(static_cast<QTreeView*>(parent())->visualRect(aIndex)).contains(aPoint))
+ Control *control = mControls[id];
+ if (control->enabled()
+ and control->drawRect(static_cast<QTreeView*>(parent())->visualRect(aIndex)).contains(aPoint))
{
- if(id == WarningControl)
- {
- if(static_cast<Event*>(aIndex.internalPointer())->hasTimeConflict())
- return id;
- }
- else
- return id;
+ return id;
}
}
: mId(aControlId)
, mImage(new QImage(aImageName))
, mDrawPoint(QPoint(0,0))
+ , mEnabled(false)
{
QPoint p;
if (prev_control == NULL) {
void Delegate::Control::paint(QPainter* painter, const QRect rect)
{
painter->drawImage(drawPoint(rect),*image());
+ setEnabled(true);
}
void Delegate::defineControls()
{
// FAVOURITE ICONs
- // on
- mControls.insert(FavouriteControlOn, new Control(FavouriteControlOn, QString(":icons/favourite-onBig.png"), NULL));
- // off
- mControls.insert(FavouriteControlOff, new Control(FavouriteControlOff, QString(":icons/favourite-offBig.png"), NULL));
+ // strong
+ mControls.insert(FavouriteControlStrong, new Control(FavouriteControlStrong, QString(":icons/favourite-strong.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-no.png"), NULL));
-#ifdef MAEMO
// ALARM ICONs
// on
mControls.insert(AlarmControlOn,
- new Control(AlarmControlOn, QString(":icons/alarm-onBig.png"), mControls[FavouriteControlOn]));
+ new Control(AlarmControlOn, QString(":icons/alarm-on.png"), mControls[FavouriteControlStrong]));
// off
mControls.insert(AlarmControlOff,
- new Control(AlarmControlOff, QString(":icons/alarm-offBig.png"), mControls[FavouriteControlOff]));
-
- // MAP ICON
- mControls.insert(MapControl,
- new Control(MapControl, QString(":icons/compassBig.png"), mControls[AlarmControlOn]));
-#else
- // MAP ICON
- mControls.insert(MapControl,
- new Control(MapControl, QString(":icons/compassBig.png"), mControls[FavouriteControlOn]));
-#endif
-
+ new Control(AlarmControlOff, QString(":icons/alarm-off.png"), mControls[FavouriteControlNo]));
// WARNING ICON
mControls.insert(WarningControl,
- new Control(WarningControl, QString(":icons/exclamation.png"), mControls[MapControl]));
-}
+ new Control(WarningControl, QString(":icons/dialog-warning.png"), mControls[AlarmControlOff]));
+ }
bool Delegate::isPointFromRect(const QPoint &aPoint, const QRect &aRect) 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.model()->index(i, 0, index).internalPointer())->favourite() != Favourite_no)
nrofFavs++;
return nrofFavs;
int nrofAlarms = 0;
for(int i=0; i<index.model()->rowCount(index); i++)
- if(static_cast<Event*>(index.child(i,0).internalPointer())->hasAlarm())
+ if(static_cast<Event*>(index.model()->index(i, 0, index).internalPointer())->hasAlarm())
nrofAlarms++;
return nrofAlarms;