summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-07-22 04:56:29 (GMT)
committerMontel Laurent <montel@kde.org>2016-07-22 04:56:29 (GMT)
commit3ae2cd1c9bf328030fd39a7dfbab9dce738d2b72 (patch)
treebc55d3184fb9ced723f73cfa0fad7eb40c28f9e1
parent95a0a8036612ca742062e200fcc82e1f93a1526c (diff)
Adapt code to support kdiagram
-rw-r--r--src/CMakeLists.txt3
-rw-r--r--src/timeline/timelineitem.cpp30
-rw-r--r--src/timeline/timelineview.cpp65
-rw-r--r--src/timeline/timelineview_p.cpp4
-rw-r--r--src/timeline/timelineview_p.h12
5 files changed, 105 insertions, 9 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index abe6f22..b7752ae 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -90,9 +90,6 @@ else()
set(grant_lib KF5::KDGantt2)
endif()
-
-set(grant_lib KF5::KDGantt2)
-
target_link_libraries(KF5EventViews
PUBLIC
KF5::AkonadiCore
diff --git a/src/timeline/timelineitem.cpp b/src/timeline/timelineitem.cpp
index 627022b..f5bfead 100644
--- a/src/timeline/timelineitem.cpp
+++ b/src/timeline/timelineitem.cpp
@@ -20,8 +20,11 @@
#include "timelineitem.h"
+#ifdef KDIAGRAM_SUPPORT
+#include <KGantt/KGanttGlobal>
+#else
#include <KDGantt2/KDGanttGlobal>
-
+#endif
#include <CalendarSupport/KCalPrefs>
#include <CalendarSupport/Utils>
@@ -39,8 +42,11 @@ TimelineItem::TimelineItem(const Akonadi::ETMCalendar::Ptr &calendar, uint index
{
mModel->removeRow(mIndex);
QStandardItem *dummyItem = new QStandardItem;
+#ifdef KDIAGRAM_SUPPORT
+ dummyItem->setData(KGantt::TypeTask, KGantt::ItemTypeRole);
+#else
dummyItem->setData(KDGantt::TypeTask, KDGantt::ItemTypeRole);
-
+#endif
mModel->insertRow(mIndex, dummyItem);
}
@@ -115,7 +121,11 @@ TimelineSubItem::TimelineSubItem(const Akonadi::ETMCalendar::Ptr &calendar,
: QStandardItem(), mCalendar(calendar), mIncidence(incidence),
mParent(parent), mToolTipNeedsUpdate(true)
{
+#ifdef KDIAGRAM_SUPPORT
+ setData(KGantt::TypeTask, KGantt::ItemTypeRole);
+#else
setData(KDGantt::TypeTask, KDGantt::ItemTypeRole);
+#endif
if (!CalendarSupport::incidence(incidence)->isReadOnly()) {
setFlags(Qt::ItemIsSelectable);
}
@@ -127,22 +137,38 @@ TimelineSubItem::~TimelineSubItem()
void TimelineSubItem::setStartTime(const QDateTime &dt)
{
+#ifdef KDIAGRAM_SUPPORT
+ setData(dt, KGantt::StartTimeRole);
+#else
setData(dt, KDGantt::StartTimeRole);
+#endif
}
QDateTime TimelineSubItem::startTime() const
{
+#ifdef KDIAGRAM_SUPPORT
+ return data(KGantt::StartTimeRole).toDateTime();
+#else
return data(KDGantt::StartTimeRole).toDateTime();
+#endif
}
void TimelineSubItem::setEndTime(const QDateTime &dt)
{
+#ifdef KDIAGRAM_SUPPORT
+ setData(dt, KGantt::EndTimeRole);
+#else
setData(dt, KDGantt::EndTimeRole);
+#endif
}
QDateTime TimelineSubItem::endTime() const
{
+#ifdef KDIAGRAM_SUPPORT
+ return data(KGantt::EndTimeRole).toDateTime();
+#else
return data(KDGantt::EndTimeRole).toDateTime();
+#endif
}
void TimelineSubItem::updateToolTip()
diff --git a/src/timeline/timelineview.cpp b/src/timeline/timelineview.cpp
index 739a9ec..1845df0 100644
--- a/src/timeline/timelineview.cpp
+++ b/src/timeline/timelineview.cpp
@@ -27,12 +27,21 @@
#include "timelineitem.h"
#include "helper.h"
+#ifdef KDIAGRAM_SUPPORT
+#include <KGantt/KGanttGraphicsItem>
+#include <KGantt/KGanttGraphicsView>
+#include <KGantt/KGanttAbstractRowController>
+#include <KGantt/KGanttDateTimeGrid>
+#include <KGantt/KGanttItemDelegate>
+#include <KGantt/KGanttStyleOptionGanttItem>
+#else
#include <KDGantt2/KDGanttGraphicsItem>
#include <KDGantt2/KDGanttGraphicsView>
#include <KDGantt2/KDGanttAbstractRowController>
#include <KDGantt2/KDGanttDateTimeGrid>
#include <KDGantt2/KDGanttItemDelegate>
#include <KDGantt2/KDGanttStyleOptionGanttItem>
+#endif
#include <Akonadi/Calendar/ETMCalendar>
#include <CalendarSupport/CollectionSelection>
@@ -58,8 +67,11 @@ using namespace EventViews;
namespace EventViews
{
-
+#ifdef KDIAGRAM_SUPPORT
+class RowController : public KGantt::AbstractRowController
+#else
class RowController : public KDGantt::AbstractRowController
+#endif
{
private:
static const int ROW_HEIGHT;
@@ -90,11 +102,17 @@ public:
{
return false;
}
-
+#ifdef KDIAGRAM_SUPPORT
+ KGantt::Span rowGeometry(const QModelIndex &idx) const Q_DECL_OVERRIDE
+ {
+ return KGantt::Span(idx.row() * mRowHeight, mRowHeight);
+ }
+#else
KDGantt::Span rowGeometry(const QModelIndex &idx) const Q_DECL_OVERRIDE
{
return KDGantt::Span(idx.row() * mRowHeight, mRowHeight);
}
+#endif
int maximumItemHeight() const Q_DECL_OVERRIDE
{
@@ -150,20 +168,33 @@ public:
return s;
}
};
-
+#ifdef KDIAGRAM_SUPPORT
+class GanttItemDelegate : public KGantt::ItemDelegate
+#else
class GanttItemDelegate : public KDGantt::ItemDelegate
+#endif
{
+#ifdef KDIAGRAM_SUPPORT
+ void paintGanttItem(QPainter *painter,
+ const KGantt::StyleOptionGanttItem &opt,
+ const QModelIndex &idx) Q_DECL_OVERRIDE {
+#else
void paintGanttItem(QPainter *painter,
const KDGantt::StyleOptionGanttItem &opt,
const QModelIndex &idx) Q_DECL_OVERRIDE {
+#endif
painter->setRenderHints(QPainter::Antialiasing);
if (!idx.isValid())
{
return;
}
-
+#ifdef KDIAGRAM_SUPPORT
+ KGantt::ItemType type = static_cast<KGantt::ItemType>(
+ idx.model()->data(idx, KGantt::ItemTypeRole).toInt());
+#else
KDGantt::ItemType type = static_cast<KDGantt::ItemType>(
idx.model()->data(idx, KDGantt::ItemTypeRole).toInt());
+#endif
QString txt = idx.model()->data(idx, Qt::DisplayRole).toString();
QRectF itemRect = opt.itemRect;
@@ -190,6 +221,31 @@ class GanttItemDelegate : public KDGantt::ItemDelegate
switch (type)
{
+#ifdef KDIAGRAM_SUPPORT
+ case KGantt::TypeTask:
+ if (itemRect.isValid()) {
+ QRectF r = itemRect;
+ painter->drawRect(r);
+
+ Qt::Alignment ta;
+ switch (opt.displayPosition) {
+ case KGantt::StyleOptionGanttItem::Left:
+ ta = Qt::AlignLeft;
+ break;
+ case KGantt::StyleOptionGanttItem::Right:
+ ta = Qt::AlignRight;
+ break;
+ case KGantt::StyleOptionGanttItem::Center:
+ ta = Qt::AlignCenter;
+ break;
+ }
+ painter->drawText(boundingRect, ta, txt);
+ }
+ break;
+ default:
+ KGantt::ItemDelegate::paintGanttItem(painter, opt, idx);
+ break;
+#else
case KDGantt::TypeTask:
if (itemRect.isValid()) {
QRectF r = itemRect;
@@ -213,6 +269,7 @@ class GanttItemDelegate : public KDGantt::ItemDelegate
default:
KDGantt::ItemDelegate::paintGanttItem(painter, opt, idx);
break;
+#endif
}
}
};
diff --git a/src/timeline/timelineview_p.cpp b/src/timeline/timelineview_p.cpp
index 8a7e323..8068383 100644
--- a/src/timeline/timelineview_p.cpp
+++ b/src/timeline/timelineview_p.cpp
@@ -25,7 +25,11 @@
#include "timelineview_p.h"
#include "timelineitem.h"
+#ifdef KDIAGRAM_SUPPORT
+#include <KGantt/KGanttGraphicsView>
+#else
#include <KDGantt2/KDGanttGraphicsView>
+#endif
#include <Akonadi/Calendar/ETMCalendar>
#include <CalendarSupport/CollectionSelection>
diff --git a/src/timeline/timelineview_p.h b/src/timeline/timelineview_p.h
index c444321..6d10abe 100644
--- a/src/timeline/timelineview_p.h
+++ b/src/timeline/timelineview_p.h
@@ -35,10 +35,18 @@
class QStandardItem;
class QTreeWidget;
+#ifdef KDIAGRAM_SUPPORT
+namespace KGantt
+{
+class GraphicsView;
+}
+#else
namespace KDGantt
{
class GraphicsView;
}
+#endif
+
namespace EventViews
{
@@ -69,7 +77,11 @@ public Q_SLOTS:
public:
Akonadi::Item::List mSelectedItemList;
+#ifdef KDIAGRAM_SUPPORT
+ KGantt::GraphicsView *mGantt;
+#else
KDGantt::GraphicsView *mGantt;
+#endif
QTreeWidget *mLeftView;
RowController *mRowController;
QMap<Akonadi::Collection::Id, TimelineItem *> mCalendarItemMap;