F:/KPlato/koffice/kplato/kptcanvasitem.cc

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2003 - 2004 Dag Andersen <danders@get2net.dk>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation;
00007    version 2 of the License.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "kpttask.h"
00021 #include "kptcanvasitem.h"
00022 #include "kptrelation.h"
00023 #include "kptganttview.h"
00024 
00025 #include <klocale.h>
00026 #include <qpainter.h>
00027 #include <q3pointarray.h>
00028 #include <q3ptrlist.h>
00029 #include <QPoint>
00030 
00031 #include <kdebug.h>
00032 
00033 namespace KPlato
00034 {
00035 
00036 
00038 KDGanttViewTaskLink::LinkType ItemBase::kdLinkType(int relationType) {
00039     switch (relationType) {
00040         case Relation::FinishStart:
00041             return KDGanttViewTaskLink::FinishStart;
00042             break;
00043         case Relation::FinishFinish:
00044             return KDGanttViewTaskLink::FinishFinish;
00045             break;
00046         case Relation::StartStart:
00047             return KDGanttViewTaskLink::StartStart;
00048             break;
00049         default:
00050             break;
00051     }
00052     return KDGanttViewTaskLink::None;
00053 }
00054 
00056 
00057 
00058 GanttViewSummaryItem::GanttViewSummaryItem(KDGanttView *parent, Node *node)
00059     : KDGanttViewSummaryItem(parent, node->name()),
00060       m_node(node),
00061       m_view(parent)
00062 {
00063     setExpandable(true);
00064     setOpen(true);
00065 }
00066 
00067 GanttViewSummaryItem::GanttViewSummaryItem(KDGanttViewItem *parent, Node *node)
00068     : KDGanttViewSummaryItem(parent, node->name()),
00069       m_node(node),
00070       m_view(0)
00071 {
00072     m_drawn = false;
00073     GanttViewSummaryItem *p = dynamic_cast<GanttViewSummaryItem*>(parent);
00074     if (p)
00075         m_view = p->ganttView();
00076     setExpandable(true);
00077     setOpen(true);
00078 }
00079 
00080 void GanttViewSummaryItem::insertRelations(GanttView *view)
00081 {
00082     //kDebug()<<k_funcinfo<<endl;
00083 
00084     foreach (Relation *r, m_node->dependChildNodes())
00085     {
00086         KDGanttViewItem *child = find(m_view->firstChild(), r->child());
00087         if (child)
00088         {
00089             KDGanttViewTaskLink *link = new KDGanttViewTaskLink(this, child, kdLinkType(r->type()));
00090             //TODO i18n
00091             QString t = i18n("From: %1", this->listViewText(0));
00092             t += "\n" + i18n("To: %1", child->listViewText(0));
00093             if (r->lag() > Duration::zeroDuration) {
00094                 t += "\n" + i18n("Lag:  %1", r->lag().toString(Duration::Format_i18nDayTime));
00095             }
00096             link->setTooltipText(t);
00097             view->addTaskLink(link);
00098         }
00099     }
00100 }
00101 
00102 KDGanttViewItem *GanttViewSummaryItem::find(Node *node)
00103 {
00104     //kDebug()<<k_funcinfo<<endl;
00105     if (m_node == node)
00106         return this;
00107 
00108     KDGanttViewItem *item = find(firstChild(), node);
00109     if (item)
00110         return item;
00111 
00112     return find(nextSibling(), node);
00113 }
00114 
00115 
00116 KDGanttViewItem *GanttViewSummaryItem::find(KDGanttViewItem *item, Node *node)
00117 {
00118     if (!item)
00119         return 0;
00120 
00121     if (item->type() == Event)
00122     {
00123         GanttViewEventItem *i = static_cast<GanttViewEventItem *>(item);
00124         return i->find(node);
00125     }
00126     else if (item->type() == Task)
00127     {
00128         GanttViewTaskItem *i = static_cast<GanttViewTaskItem *>(item);
00129         return i->find(node);
00130     }
00131     else if (item->type() == Summary)
00132     {
00133         GanttViewSummaryItem *i = static_cast<GanttViewSummaryItem *>(item);
00134         return i->find(node);
00135     }
00136     return 0;
00137 }
00138 
00140 
00141 
00142 GanttViewTaskItem::GanttViewTaskItem(KDGanttView *parent, KPlato::Task *task)
00143     : KDGanttViewTaskItem(parent, task->name()),
00144       m_task(task),
00145       m_view(parent)
00146 {
00147 }
00148 
00149 GanttViewTaskItem::GanttViewTaskItem(KDGanttViewItem *parent, KPlato::Task *task)
00150     : KDGanttViewTaskItem(parent, task->name()),
00151       m_task(task),
00152       m_view()
00153 {
00154     m_drawn = false;
00155     GanttViewSummaryItem *p = dynamic_cast<GanttViewSummaryItem*>(parent);
00156     if (p)
00157         m_view = p->ganttView();
00158 }
00159 
00160 void GanttViewTaskItem::insertRelations(GanttView *view)
00161 {
00162     //kDebug()<<k_funcinfo<<endl;
00163 
00164     foreach (Relation *r, m_task->dependChildNodes())
00165     {
00166         KDGanttViewItem *child = find(m_view->firstChild(), r->child());
00167         if (child)
00168         {
00169             KDGanttViewTaskLink *link = new KDGanttViewTaskLink(this, child,  kdLinkType(r->type()));
00170             QString t = i18n("From: %1", this->listViewText(0));
00171             t += "\n" + i18n("To: %1", child->listViewText(0));
00172             if (r->lag() > Duration::zeroDuration) {
00173                 t += "\n" + i18n("Lag:  %1", r->lag().toString(Duration::Format_i18nDayTime));
00174             }
00175             link->setTooltipText(t);
00176             view->addTaskLink(link);
00177         }
00178     }
00179 }
00180 
00181 KDGanttViewItem *GanttViewTaskItem::find(Node *node)
00182 {
00183     //kDebug()<<k_funcinfo<<endl;
00184     if (m_task == node)
00185         return this;
00186 
00187     KDGanttViewItem *item = find(firstChild(), node);
00188     if (item)
00189         return item;
00190 
00191     return find(nextSibling(), node);
00192 }
00193 
00194 
00195 KDGanttViewItem *GanttViewTaskItem::find(KDGanttViewItem *item, Node *node)
00196 {
00197     if (!item)
00198         return 0;
00199 
00200     if (item->type() == Event)
00201     {
00202         GanttViewEventItem *i = static_cast<GanttViewEventItem *>(item);
00203         return i->find(node);
00204     }
00205     else if (item->type() == Task)
00206     {
00207         GanttViewTaskItem *i= static_cast<GanttViewTaskItem *>(item);
00208         return i->find(node);
00209     }
00210     else if (item->type() == Summary)
00211     {
00212         GanttViewSummaryItem *i = static_cast<GanttViewSummaryItem *>(item);
00213         return i->find(node);
00214     }
00215     return 0; // avoid warning
00216 }
00217 
00219 
00220 
00221 GanttViewEventItem::GanttViewEventItem(KDGanttView *parent, KPlato::Task *task)
00222     : KDGanttViewEventItem(parent, task->name()),
00223       m_task(task),
00224       m_view(parent)
00225 {
00226 }
00227 
00228 GanttViewEventItem::GanttViewEventItem(KDGanttViewItem *parent, KPlato::Task *task)
00229     : KDGanttViewEventItem(parent, task->name()),
00230       m_task(task),
00231       m_view()
00232 {
00233     m_drawn = false;
00234     GanttViewSummaryItem *p = dynamic_cast<GanttViewSummaryItem*>(parent);
00235     if (p)
00236         m_view = p->ganttView();
00237 }
00238 
00239 
00240 void GanttViewEventItem::insertRelations(GanttView *view)
00241 {
00242     //kDebug()<<k_funcinfo<<endl;
00243 
00244     foreach (Relation *r, m_task->dependChildNodes())
00245     {
00246         KDGanttViewItem *child = find(m_view->firstChild(), r->child());
00247         if (child)
00248         {
00249             KDGanttViewTaskLink *link = new KDGanttViewTaskLink(this, child, kdLinkType(r->type()));
00250 
00251             QString t = i18n("From: %1",this->listViewText(0));
00252             t += "\n" + i18n("To: %1",child->listViewText(0));
00253             if (r->lag() > Duration::zeroDuration) {
00254                 t += "\n" + i18n("Lag:  %1",r->lag().toString(Duration::Format_i18nDayTime));
00255             }
00256             link->setTooltipText(t);
00257             view->addTaskLink(link);
00258         }
00259     }
00260 }
00261 
00262 KDGanttViewItem *GanttViewEventItem::find(Node *node)
00263 {
00264     //kDebug()<<k_funcinfo<<endl;
00265     if (m_task == node)
00266         return this;
00267 
00268     KDGanttViewItem *item = find(firstChild(), node);
00269     if (item)
00270         return item;
00271 
00272     return find(nextSibling(), node);
00273 }
00274 
00275 
00276 KDGanttViewItem *GanttViewEventItem::find(KDGanttViewItem *item, Node *node)
00277 {
00278     if (!item)
00279         return 0;
00280 
00281     if (item->type() == Event)
00282     {
00283         GanttViewEventItem *i = static_cast<GanttViewEventItem *>(item);
00284         return i->find(node);
00285     }
00286     else if (item->type() == Task)
00287     {
00288         GanttViewTaskItem *i = static_cast<GanttViewTaskItem *>(item);
00289         return i->find(node);
00290     }
00291     else if (item->type() == Summary)
00292     {
00293         GanttViewSummaryItem *i = static_cast<GanttViewSummaryItem *>(item);
00294         return i->find(node);
00295     }
00296     return 0;
00297 }
00298 
00299 }  //KPlato namespace

Généré le Wed Nov 22 23:40:55 2006 pour KPlato par  doxygen 1.5.1-p1