21#include "kptganttview.h"
23#include "kptappointment.h"
26#include "kptcanvasitem.h"
29#include "kptproject.h"
31#include "kptresource.h"
32#include "kptdatetime.h"
33#include "kpttaskappointmentsview.h"
34#include "kptrelation.h"
35#include "kptcontext.h"
36#include "kptschedule.h"
38#include "KDGanttView.h"
39#include "KDGanttViewItem.h"
40#include "KDGanttViewTaskItem.h"
41#include "KDGanttViewSummaryItem.h"
42#include "KDGanttViewEventItem.h"
46#include <tqsplitter.h>
49#include <tqlistview.h>
51#include <tqpopupmenu.h>
52#include <tqtabwidget.h>
54#include <tqlineedit.h>
58#include <tqstringlist.h>
59#include <tqvaluelist.h>
61#include <tqpaintdevicemetrics.h>
66#include <tdemessagebox.h>
71class MyKDGanttView :
public KDGanttView {
73 MyKDGanttView(TQWidget *parent,
const char *name)
74 : KDGanttView(parent, name) {
76 virtual TQSize sizeHint()
const {
77 return minimumSizeHint();
81GanttView::GanttView(TQWidget *parent,
bool readWrite,
const char* name)
82 : TQSplitter(parent, name),
83 m_readWrite(readWrite),
89 kdDebug() <<
" ---------------- KPlato: Creating GanttView ----------------" << endl;
90 setOrientation(TQt::Vertical);
92 m_gantt =
new MyKDGanttView(
this,
"Gantt view");
94 m_showExpected =
true;
95 m_showOptimistic =
false;
96 m_showPessimistic =
false;
97 m_showResources =
false;
98 m_showTaskName =
false;
99 m_showTaskLinks =
false;
100 m_showProgress =
false;
101 m_showPositiveFloat =
false;
102 m_showCriticalTasks =
false;
103 m_showCriticalPath =
false;
104 m_showNoInformation =
false;
105 m_showAppointments =
false;
107 m_gantt->setHeaderVisible(
true);
108 m_gantt->addColumn(i18n(
"Work Breakdown Structure",
"WBS"));
110 KDGanttViewTaskItem *item =
new KDGanttViewTaskItem(m_gantt);
111 TQListView *lv = item->listView();
112 lv->header()->moveSection(1, 0);
114 m_gantt->setScale(KDGanttView::Day);
115 m_gantt->setShowLegendButton(
false);
116 m_gantt->setShowHeaderPopupMenu();
117 m_taskView =
new TaskAppointmentsView(
this);
119 TQValueList<int> list = sizes();
125 setReadWriteMode(readWrite);
127 connect(m_gantt, TQ_SIGNAL(lvContextMenuRequested ( KDGanttViewItem *,
const TQPoint &,
int )),
128 this, TQ_SLOT (popupMenuRequested(KDGanttViewItem *,
const TQPoint &,
int)));
130 connect(m_gantt, TQ_SIGNAL(lvCurrentChanged(KDGanttViewItem*)),
this, TQ_SLOT (currentItemChanged(KDGanttViewItem*)));
133 connect(lv, TQ_SIGNAL(doubleClicked(TQListViewItem*,
const TQPoint&,
int)),
this, TQ_SLOT (slotItemDoubleClicked(TQListViewItem*)));
135 m_taskLinks.setAutoDelete(
true);
137 if (m_gantt->firstChild()) {
138 m_gantt->firstChild()->listView()->setCurrentItem(m_gantt->firstChild());
139 m_gantt->firstChild()->listView()->setFocus();
143void GanttView::setZoom(
double zoom)
145 kdDebug() <<
"setting gantt zoom: " << zoom << endl;
146 m_gantt->setZoomFactor(zoom,
true);
147 m_taskView->zoom( zoom );
150void GanttView::clear()
156void GanttView::draw(Project &project)
158 m_project = &project;
160 Schedule::Type type = Schedule::Expected;
161 if (m_showOptimistic) {
162 type = Schedule::Optimistic;
163 }
else if (m_showPessimistic) {
164 type = Schedule::Pessimistic;
166 Schedule *sch = project.findSchedule(type);
168 project.setCurrentSchedule(sch->id());
171 m_gantt->setUpdateEnabled(
false);
174 drawChildren(NULL, project);
178 m_gantt->centerTimelineAfterShow(project.startTime().addDays(-1));
181 m_gantt->setUpdateEnabled(
true);
182 currentItemChanged(m_currentItem);
185void GanttView::drawChanges(Project &project)
187 m_project = &project;
189 Schedule::Type type = Schedule::Expected;
190 if (m_showOptimistic) {
191 type = Schedule::Optimistic;
192 }
else if (m_showPessimistic) {
193 type = Schedule::Pessimistic;
195 Schedule *sch = project.findSchedule(type);
197 project.setCurrentSchedule(sch->id());
200 m_gantt->setUpdateEnabled(
false);
201 resetDrawn(m_gantt->firstChild());
202 updateChildren(&project);
203 removeNotDrawn(m_gantt->firstChild());
208 m_gantt->setUpdateEnabled(
true);
209 if (m_currentItem == 0 && m_gantt->firstChild()) {
210 m_gantt->firstChild()->listView()->setCurrentItem(m_gantt->firstChild());
211 currentItemChanged(m_gantt->firstChild());
213 currentItemChanged(m_currentItem);
216void GanttView::drawOnPainter(TQPainter* painter,
const TQRect rect)
221 TQSize s = m_gantt->drawContents(0,
false,
true);
222 while (s.width() < rect.width()) {
223 m_gantt->addTicksRight();
224 m_gantt->setTimelineToEnd();
225 s = m_gantt->drawContents(0,
false,
true);
227 kdDebug()<<k_funcinfo<<rect<<
" : "<<s<<endl;
250 m_gantt->drawContents(painter,
false,
true);
258KDGanttViewItem *GanttView::findItem(Node *node)
260 return findItem(node, m_gantt->firstChild());
263KDGanttViewItem *GanttView::findItem(Node *node, KDGanttViewItem *item)
265 for (; item; item = item->nextSibling()) {
266 if (node == getNode(item)) {
269 KDGanttViewItem *i = findItem(node, item->firstChild());
276Node *GanttView::getNode(KDGanttViewItem *item)
const {
278 if (item->type() == KDGanttViewItem::Event){
279 return static_cast<GanttViewEventItem *
>(item)->getTask();
280 }
else if (item->type() == KDGanttViewItem::Task) {
281 return static_cast<GanttViewTaskItem *
>(item)->getTask();
282 }
else if (item->type() == KDGanttViewItem::Summary) {
283 return static_cast<GanttViewSummaryItem *
>(item)->getNode();
289bool GanttView::isDrawn(KDGanttViewItem *item) {
291 if (item->type() == KDGanttViewItem::Event){
292 return static_cast<GanttViewEventItem *
>(item)->isDrawn();
293 }
else if (item->type() == KDGanttViewItem::Task) {
294 return static_cast<GanttViewTaskItem *
>(item)->isDrawn();
295 }
else if (item->type() == KDGanttViewItem::Summary) {
296 return static_cast<GanttViewSummaryItem *
>(item)->isDrawn();
298 kdWarning()<<k_funcinfo<<
"Unknown item type: "<<item->type()<<endl;
304void GanttView::setDrawn(KDGanttViewItem *item,
bool state) {
306 if (item->type() == KDGanttViewItem::Event){
307 static_cast<GanttViewEventItem *
>(item)->setDrawn(state);
308 }
else if (item->type() == KDGanttViewItem::Task) {
309 static_cast<GanttViewTaskItem *
>(item)->setDrawn(state);
310 }
else if (item->type() == KDGanttViewItem::Summary) {
311 static_cast<GanttViewSummaryItem *
>(item)->setDrawn(state);
313 kdWarning()<<k_funcinfo<<
"Unknown item type: "<<item->type()<<endl;
319void GanttView::resetDrawn(KDGanttViewItem *_item)
321 KDGanttViewItem *nextItem, *item=_item;
322 for (; item; item = nextItem) {
323 nextItem = item->nextSibling();
324 setDrawn(item,
false);
325 resetDrawn(item->firstChild());
329void GanttView::removeNotDrawn(KDGanttViewItem *_item)
331 KDGanttViewItem *nextItem, *item=_item;
332 for (; item; item = nextItem) {
333 nextItem = item->nextSibling();
334 if (!isDrawn(item)) {
335 if (item == m_currentItem)
339 removeNotDrawn(item->firstChild());
344void GanttView::deleteItem(KDGanttViewItem *item)
348 item->parent()->takeItem(item);
350 item->listView()->takeItem(item);
354KDGanttViewItem *GanttView::correctType(KDGanttViewItem *item, Node *node)
357 switch (node->type()) {
358 case Node::Type_Project:
361 case Node::Type_Summarytask:
362 case Node::Type_Subproject:
363 if (item->type() == KDGanttViewItem::Summary)
366 case Node::Type_Task:
367 if (item->type() == KDGanttViewItem::Task)
370 case Node::Type_Milestone:
371 if (item->type() == KDGanttViewItem::Event)
378 KDGanttViewItem *newItem = addNode(item->parent(), node, item);
379 newItem->setOpen(item->isOpen());
384void GanttView::correctPosition(KDGanttViewItem *item, Node *node)
386 KDGanttViewItem *after = findItem(node->siblingBefore());
388 item->moveItem(after);
392KDGanttViewItem *GanttView::correctParent(KDGanttViewItem *item, Node *node)
394 KDGanttViewItem *p = findItem(node->getParent());
395 if (p == item->parent()) {
398 KDGanttViewItem *newItem = addNode(p, node);
399 newItem->setOpen(item->isOpen());
404void GanttView::updateChildren(Node *parentNode)
407 TQPtrListIterator<Node> nit(parentNode->childNodeIterator());
408 for (; nit.current(); ++nit )
410 updateNode(nit.current());
414void GanttView::updateNode(Node *node)
417 KDGanttViewItem *item = findItem(node);
419 item = addNode(findItem(node->getParent()), node, findItem(node->siblingBefore()));
420 if (item && node->type() == Node::Type_Summarytask)
421 updateChildren(node);
424 item = correctType(item, node);
425 item = correctParent(item, node);
426 correctPosition(item, node);
430 if (node->type() == Node::Type_Summarytask)
431 updateChildren(node);
434void GanttView::modifyChildren(Node *node)
437 TQPtrListIterator<Node> nit(node->childNodeIterator());
438 for ( nit.toLast(); nit.current(); --nit ) {
439 modifyNode(nit.current());
440 modifyChildren(nit.current());
444void GanttView::modifyNode(Node *node)
447 KDGanttViewItem *item = findItem(node);
449 kdDebug()<<k_funcinfo<<
" Item not found"<<endl;
452 if (node->type() == Node::Type_Project) {
453 return modifyProject(item, node);
455 if (node->type() == Node::Type_Subproject) {
456 return modifyProject(item, node);
458 if (node->type() == Node::Type_Summarytask) {
459 return modifySummaryTask(item,
static_cast<Task *
>(node));
461 if (node->type() == Node::Type_Task) {
462 return modifyTask(item,
static_cast<Task *
>(node));
464 if (node->type() == Node::Type_Milestone) {
465 return modifyMilestone(item,
static_cast<Task *
>(node));
470void GanttView::modifyProject(KDGanttViewItem *item, Node *node)
473 item->setListViewText(node->name());
474 item->setListViewText(1, node->wbs());
475 item->setStartTime(node->startTime());
476 item->setEndTime(node->endTime());
478 setDrawn(item,
true);
482void GanttView::modifySummaryTask(KDGanttViewItem *item, Task *task)
485 TDELocale *locale = TDEGlobal::locale();
487 if (task->currentSchedule() == 0) {
488 item->setShowNoInformation(m_showNoInformation);
489 item->setStartTime(task->projectNode()->startTime());
490 item->setEndTime(item->startTime().addDays(1));
492 bool noinf = m_showNoInformation && (task->notScheduled() || (m_project ? m_project->notScheduled() :
false ));
493 item->setShowNoInformation(noinf);
494 item->setStartTime(task->startTime());
495 item->setEndTime(task->endTime());
497 item->setListViewText(task->name());
498 item->setListViewText(1, task->wbs());
500 if (m_showTaskName) {
501 item->setText(task->name());
503 item->setText(TQString());
505 TQString w = i18n(
"Name: %1").arg(task->name());
506 if (!task->notScheduled()) {
507 w +=
"\n" + i18n(
"Start: %1").arg(locale->formatDateTime(task->startTime()));
508 w +=
"\n" + i18n(
"End: %1").arg(locale->formatDateTime(task->endTime()));
511 if (task->notScheduled()) {
512 w +=
"\n" + i18n(
"Not scheduled");
515 if (!m_showNoInformation && m_project && m_project->notScheduled()) {
521 item->setColors(c,c,c);
524 item->setColors(c,c,c);
526 item->setTooltipText(w);
527 setDrawn(item,
true);
530void GanttView::modifyTask(KDGanttViewItem *item, Task *task)
533 TDELocale *locale = TDEGlobal::locale();
535 item->setListViewText(task->name());
536 item->setListViewText(1, task->wbs());
537 if (task->currentSchedule() == 0) {
538 item->setShowNoInformation(m_showNoInformation);
539 item->setStartTime(task->projectNode()->startTime());
540 item->setEndTime(item->startTime().addDays(1));
542 bool noinf = m_showNoInformation && (task->notScheduled() || (m_project ? m_project->notScheduled() :
false ));
543 item->setShowNoInformation(noinf);
544 item->setStartTime(task->startTime());
545 item->setEndTime(task->endTime());
549 if (m_showTaskName) {
552 if (m_showResources && !task->notScheduled()) {
553 TQPtrList<Appointment> lst = task->appointments();
554 if (lst.count() > 0) {
558 TQPtrListIterator<Appointment> it = lst;
559 for (
bool first=
true; it.current(); ++it) {
562 text += it.current()->resource()->resource()->name();
569 if (m_showProgress) {
570 item->setProgress(task->progress().percentFinished);
572 item->setProgress(0);
574 if (m_showPositiveFloat) {
575 TQDateTime t = task->endTime() + task->positiveFloat();
576 if (t.isValid() && t > task->endTime()) {
577 item->setFloatEndTime(t);
579 item->setFloatEndTime(TQDateTime());
582 item->setFloatStartTime(TQDateTime());
583 item->setFloatEndTime(TQDateTime());
585 TQString w = i18n(
"Name: %1").arg(task->name());
586 if (!task->notScheduled()) {
587 w +=
"\n"; w += i18n(
"Start: %1").arg(locale->formatDateTime(task->startTime()));
588 w +=
"\n"; w += i18n(
"End: %1").arg(locale->formatDateTime(task->endTime()));
589 if (m_showProgress) {
590 w +=
"\n"; w += i18n(
"Completion: %1%").arg(task->progress().percentFinished);
592 if (task->positiveFloat() > Duration::zeroDuration) {
593 w +=
"\n" + i18n(
"Float: %1").arg(task->positiveFloat().toString(Duration::Format_i18nDayTime));
595 if (task->inCriticalPath()) {
596 w +=
"\n" + i18n(
"Critical path");
597 }
else if (task->isCritical()) {
598 w +=
"\n" + i18n(
"Critical");
603 if (task->notScheduled()) {
604 sts +=
"\n" + i18n(
"Not scheduled");
607 if (task->resourceError()) {
608 sts +=
"\n" + i18n(
"No resource assigned");
611 if (task->resourceNotAvailable()) {
612 sts +=
"\n" + i18n(
"Resource not available");
615 if (task->schedulingError()) {
616 sts +=
"\n" + i18n(
"Scheduling conflict");
619 if (task->effortMetError()) {
620 sts +=
"\n" + i18n(
"Requested effort could not be met");
623 if (task->resourceOverbooked()) {
625 TQStringList rl = task->overbookedResources();
626 sts +=
"\n" + i18n(
"arg: list of resources",
"Resource overbooked: %1").arg(rl.join(
","));
629 if (!m_showNoInformation && m_project && m_project->notScheduled()) {
635 item->setColors(c,c,c);
639 item->setColors(c,c,c);
641 item->setHighlight(
false);
642 if (m_showCriticalTasks) {
643 item->setHighlight(task->isCritical());
644 }
else if (m_showCriticalPath) {
645 item->setHighlight(task->inCriticalPath());
648 item->setTooltipText(w);
649 setDrawn(item,
true);
652void GanttView::modifyMilestone(KDGanttViewItem *item, Task *task)
655 TDELocale *locale = TDEGlobal::locale();
657 if (task->currentSchedule() == 0) {
658 item->setShowNoInformation(m_showNoInformation);
659 item->setStartTime(task->projectNode()->startTime());
661 bool noinf = m_showNoInformation && (task->notScheduled() || (m_project ? m_project->notScheduled() :
false ));
662 item->setShowNoInformation(noinf);
663 item->setStartTime(task->startTime());
665 item->setListViewText(task->name());
666 item->setListViewText(1, task->wbs());
668 if (m_showTaskName) {
669 item->setText(task->name());
671 item->setText(TQString());
673 if (m_showPositiveFloat) {
674 DateTime t = task->startTime() + task->positiveFloat();
676 if (t.isValid() && t > task->startTime()) {
677 item->setFloatEndTime(t);
679 item->setFloatEndTime(TQDateTime());
682 item->setFloatStartTime(TQDateTime());
683 item->setFloatEndTime(TQDateTime());
687 TQString w = i18n(
"Name: %1").arg(task->name());
688 if (!task->notScheduled()) {
689 w +=
"\n" + i18n(
"Time: %1").arg(locale->formatDateTime(task->startTime()));
691 if (task->positiveFloat() > Duration::zeroDuration) {
692 w +=
"\n" + i18n(
"Float: %1").arg(task->positiveFloat().toString(Duration::Format_i18nDayTime));
694 if (task->inCriticalPath()) {
695 w +=
"\n" + i18n(
"Critical path");
696 }
else if (task->isCritical()) {
697 w +=
"\n" + i18n(
"Critical");
701 if (task->notScheduled()) {
702 w +=
"\n" + i18n(
"Not scheduled");
705 if (task->schedulingError()) {
706 w +=
"\n" + i18n(
"Scheduling conflict");
709 if (!m_showNoInformation && m_project && m_project->notScheduled()) {
715 item->setColors(c,c,c);
718 item->setColors(c,c,c);
720 item->setHighlight(
false);
721 if (m_showCriticalTasks) {
722 item->setHighlight(task->isCritical());
723 }
else if (m_showCriticalPath) {
724 item->setHighlight(task->inCriticalPath());
727 item->setTooltipText(w);
728 setDrawn(item,
true);
731KDGanttViewItem *GanttView::addNode( KDGanttViewItem *parentItem, Node *node, KDGanttViewItem *after)
734 if (node->type() == Node::Type_Project) {
735 return addProject(parentItem, node, after);
737 if (node->type() == Node::Type_Subproject) {
738 return addSubProject(parentItem, node, after);
740 if (node->type() == Node::Type_Summarytask) {
741 return addSummaryTask(parentItem,
static_cast<Task *
>(node), after);
743 if (node->type() == Node::Type_Task) {
744 return addTask(parentItem,
static_cast<Task *
>(node), after);
746 if (node->type() == Node::Type_Milestone) {
747 return addMilestone(parentItem,
static_cast<Task *
>(node), after);
752KDGanttViewItem *GanttView::addProject(KDGanttViewItem *parentItem, Node *node, KDGanttViewItem *after)
755 GanttViewSummaryItem *item;
757 item =
new GanttViewSummaryItem(parentItem, node);
760 item =
new GanttViewSummaryItem(m_gantt, node);
763 item->moveItem(after);
764 modifyProject(item, node);
768KDGanttViewItem *GanttView::addSubProject(KDGanttViewItem *parentItem, Node *node, KDGanttViewItem *after)
771 return addProject(parentItem, node, after);
774KDGanttViewItem *GanttView::addSummaryTask(KDGanttViewItem *parentItem, Task *task, KDGanttViewItem *after)
778 GanttViewSummaryItem *item;
780 item =
new GanttViewSummaryItem(parentItem, task);
783 item =
new GanttViewSummaryItem(m_gantt, task);
786 item->moveItem(after);
787 modifySummaryTask(item, task);
791KDGanttViewItem *GanttView::addTask(KDGanttViewItem *parentItem, Task *task, KDGanttViewItem *after)
795 GanttViewTaskItem *item;
797 item =
new GanttViewTaskItem(parentItem, task);
801 item =
new GanttViewTaskItem(m_gantt, task);
804 item->moveItem(after);
805 modifyTask(item, task);
809KDGanttViewItem *GanttView::addMilestone(KDGanttViewItem *parentItem, Task *task, KDGanttViewItem *after)
812 GanttViewEventItem *item;
814 item =
new GanttViewEventItem(parentItem, task);
817 item =
new GanttViewEventItem(m_gantt, task);
820 item->moveItem(after);
821 modifyMilestone(item, task);
825void GanttView::drawChildren(KDGanttViewItem *parentItem, Node &parentNode)
828 TQPtrListIterator<Node> nit(parentNode.childNodeIterator());
829 for ( nit.toLast(); nit.current(); --nit )
831 Node *n = nit.current();
832 if (n->type() == Node::Type_Project)
833 drawProject(parentItem, n);
834 else if (n->type() == Node::Type_Subproject)
835 drawSubProject(parentItem, n);
836 else if (n->type() == Node::Type_Summarytask) {
837 Task *t =
dynamic_cast<Task *
>(n);
838 drawSummaryTask(parentItem, t);
839 }
else if (n->type() == Node::Type_Task) {
840 Task *t =
dynamic_cast<Task *
>(n);
841 drawTask(parentItem, t);
842 }
else if (n->type() == Node::Type_Milestone) {
843 Task *t =
dynamic_cast<Task *
>(n);
844 drawMilestone(parentItem, t);
847 kdDebug()<<k_funcinfo<<
"Node type "<<n->type()<<
" not implemented yet"<<endl;
853void GanttView::drawProject(KDGanttViewItem *parentItem, Node *node)
856 GanttViewSummaryItem *item =
dynamic_cast<GanttViewSummaryItem*
>(addProject(parentItem, node));
857 drawChildren(item, *node);
860void GanttView::drawSubProject(KDGanttViewItem *parentItem, Node *node)
863 GanttViewSummaryItem *item =
dynamic_cast<GanttViewSummaryItem*
>(addSubProject(parentItem, node));
864 drawChildren(item, *node);
867void GanttView::drawSummaryTask(KDGanttViewItem *parentItem, Task *task)
870 GanttViewSummaryItem *item =
dynamic_cast<GanttViewSummaryItem*
>(addSummaryTask(parentItem, task));
871 drawChildren(item, *task);
874void GanttView::drawTask(KDGanttViewItem *parentItem, Task *task)
877 addTask(parentItem, task);
880void GanttView::drawMilestone(KDGanttViewItem *parentItem, Task *task)
883 addMilestone(parentItem, task);
886void GanttView::addTaskLink(KDGanttViewTaskLink *link) {
888 m_taskLinks.append(link);
891void GanttView::drawRelations()
893 if (!m_showTaskLinks)
895 KDGanttViewItem *item = m_gantt->firstChild();
897 for (; item; item = item->nextSibling())
900 drawChildRelations(item->firstChild());
904void GanttView::drawChildRelations(KDGanttViewItem *item)
907 for (; item; item = item->nextSibling())
910 drawChildRelations(item->firstChild());
914void GanttView::drawRelations(KDGanttViewItem *item)
919 GanttViewSummaryItem *summaryItem =
dynamic_cast<GanttViewSummaryItem *
>(item);
923 summaryItem->insertRelations(
this);
926 GanttViewTaskItem *taskItem =
dynamic_cast<GanttViewTaskItem *
>(item);
930 taskItem->insertRelations(
this);
933 GanttViewEventItem *milestoneItem =
dynamic_cast<GanttViewEventItem *
>(item);
937 milestoneItem->insertRelations(
this);
940 kdDebug()<<k_funcinfo<<
"Unknown item type: "<<item->listViewText()<<endl;
943void GanttView::currentItemChanged(KDGanttViewItem* item)
947 m_gantt->setSelected(m_currentItem,
false);
948 m_currentItem = item;
950 m_gantt->setSelected(item,
true);
951 if (m_showAppointments) {
953 GanttViewTaskItem *taskItem =
dynamic_cast<GanttViewTaskItem *
>(item);
955 m_taskView->draw(taskItem->getTask());
957 GanttViewEventItem *msItem =
dynamic_cast<GanttViewEventItem *
>(item);
959 m_taskView->draw(msItem->getTask());
965 emit enableActions(
true);
968Node *GanttView::currentNode()
const
970 return getNode(m_currentItem);
973void GanttView::popupMenuRequested(KDGanttViewItem * item,
const TQPoint & pos,
int)
977 kdDebug()<<
"No item selected"<<endl;
980 Node *n = getNode(item);
982 kdDebug()<<
"No node selected"<<endl;
985 Task *t =
dynamic_cast<Task*
>(n);
986 if (t && (t->type() == Node::Type_Task || t->type() == Node::Type_Milestone)) {
987 emit requestPopupMenu(
"task_popup",pos);
996 if (t && t->type() == Node::Type_Summarytask) {
997 emit requestPopupMenu(
"summarytask_popup",pos);
1009void GanttView::slotItemDoubleClicked(TQListViewItem* item) {
1011 if (item == 0 || item->childCount() > 0) {
1015 emit itemDoubleClicked();
1020void GanttView::print(KPrinter &prt) {
1023 KDGanttViewItem *selItem = m_gantt->selectedItem();
1025 selItem->setSelected(
false);
1032 TQPaintDeviceMetrics metrics( &prt );
1033 uint top, left, bottom, right;
1034 prt.margins(&top, &left, &bottom, &right);
1040 TQSize size = m_gantt->drawContents(0);
1044 p.setViewport(left, top, metrics.width()-left-right, metrics.height()-top-bottom);
1045 p.setClipRect(left, top, metrics.width()-left-right, metrics.height()-top-bottom);
1048 p.drawRect(0,0,metrics.width(),metrics.height());
1051 text = TDEGlobal::locale()->formatDateTime(TQDateTime::currentDateTime());
1052 TQRect r = p.boundingRect(metrics.width()-1,0,0,0, TQt::AlignRight, text );
1053 p.drawText( r, TQt::AlignRight, text );
1058 TQRect re = p.boundingRect(1,0,0,0, TQt::AlignLeft, text );
1059 re.setWidth(metrics.width()-r.width()-5);
1060 p.drawText( re, TQt::AlignLeft, m_project->name() );
1063 hei = TQMAX(hei, re.height());
1067 p.drawLine(0,hei,metrics.width(),hei);
1070 float dx = (float) (metrics.width()-2) / (float)size.width();
1071 float dy = (float)(metrics.height()-hei) / (float)size.height();
1080 p.scale( scale, scale );
1081 m_gantt->drawContents(&p);
1090 selItem->setSelected(
true);
1093void GanttView::slotItemRenamed(KDGanttViewItem* item,
int col,
const TQString& str) {
1096 emit itemRenamed(getNode(item), str);
1100 void GanttView::slotGvItemClicked(KDGanttViewItem *) {
1104bool GanttView::exportGantt(TQIODevice* device) {
1105 kdDebug()<<k_funcinfo<<endl;
1106 return m_gantt->saveProject(device);
1109void GanttView::slotLinkItems(KDGanttViewItem* from, KDGanttViewItem* to,
int linkType) {
1111 Node *par = getNode(from);
1112 Node *child = getNode(to);
1113 if (!par || !child || !(par->legalToLink(child))) {
1114 KMessageBox::sorry(
this, i18n(
"Cannot link these nodes"));
1117 Relation *rel = child->findRelation(par);
1119 emit modifyRelation(rel, linkTypeToRelation(linkType));
1121 emit addRelation(par, child, linkTypeToRelation(linkType));
1126int GanttView::linkTypeToRelation(
int linkType) {
1128 case KDGanttViewTaskLink::FinishStart:
1129 return Relation::FinishStart;
1131 case KDGanttViewTaskLink::StartStart:
1132 return Relation::StartStart;
1134 case KDGanttViewTaskLink::FinishFinish:
1135 return Relation::FinishFinish;
1137 case KDGanttViewTaskLink::StartFinish:
1144void GanttView::slotModifyLink(KDGanttViewTaskLink* link) {
1147 Node *par = getNode(link->from().first());
1148 Relation *rel = par->findRelation(getNode(link->to().first()));
1150 emit modifyRelation(rel);
1153bool GanttView::setContext(Context::Ganttview &context, Project& ) {
1156 TQValueList<int> list = sizes();
1157 list[0] = context.ganttviewsize;
1158 list[1] = context.taskviewsize;
1164 m_showResources = context.showResources ;
1165 m_showTaskName = context.showTaskName;
1166 m_showTaskLinks = context.showTaskLinks;
1167 m_showProgress = context.showProgress;
1168 m_showPositiveFloat = context.showPositiveFloat;
1169 m_showCriticalTasks = context.showCriticalTasks;
1170 m_showCriticalPath = context.showCriticalPath;
1171 m_showNoInformation = context.showNoInformation;
1184void GanttView::getContext(Context::Ganttview &context)
const {
1186 context.ganttviewsize = sizes()[0];
1187 context.taskviewsize = sizes()[1];
1189 if (currentNode()) {
1190 context.currentNode = currentNode()->id();
1192 context.showResources = m_showResources;
1193 context.showTaskName = m_showTaskName;
1194 context.showTaskLinks = m_showTaskLinks;
1195 context.showProgress = m_showProgress;
1196 context.showPositiveFloat = m_showPositiveFloat;
1197 context.showCriticalTasks = m_showCriticalTasks;
1198 context.showCriticalPath = m_showCriticalPath;
1199 context.showNoInformation = m_showNoInformation;
1200 getContextClosedNodes(context, m_gantt->firstChild());
1203void GanttView::getContextClosedNodes(Context::Ganttview &context, KDGanttViewItem *item)
const {
1206 for (KDGanttViewItem *i = item; i; i = i->nextSibling()) {
1208 context.closedNodes.append(getNode(i)->
id());
1211 getContextClosedNodes(context, i->firstChild());
1215void GanttView::setReadWriteMode(
bool on) {
1217 disconnect(m_gantt, TQ_SIGNAL(linkItems(KDGanttViewItem*, KDGanttViewItem*,
int)),
this, TQ_SLOT(slotLinkItems(KDGanttViewItem*, KDGanttViewItem*,
int)));
1218 disconnect(m_gantt, TQ_SIGNAL(taskLinkDoubleClicked(KDGanttViewTaskLink*)),
this, TQ_SLOT(slotModifyLink(KDGanttViewTaskLink*)));
1219 m_gantt->setLinkItemsEnabled(on);
1222 connect(m_gantt, TQ_SIGNAL(linkItems(KDGanttViewItem*, KDGanttViewItem*,
int)), TQ_SLOT(slotLinkItems(KDGanttViewItem*, KDGanttViewItem*,
int)));
1224 connect(m_gantt, TQ_SIGNAL(taskLinkDoubleClicked(KDGanttViewTaskLink*)), TQ_SLOT(slotModifyLink(KDGanttViewTaskLink*)));
1226 setRenameEnabled(m_gantt->firstChild(), on);
1229void GanttView::setRenameEnabled(TQListViewItem *item,
bool on) {
1232 for (TQListViewItem *i = item; i; i = i->nextSibling()) {
1233 i->setRenameEnabled(0, on);
1234 setRenameEnabled(i->firstChild(), on);
1240#include "kptganttview.moc"