kplato

kptview.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 1998, 1999, 2000 Torben Weis <weis@kde.org>
00003    Copyright (C) 2002 - 2005 Dag Andersen <danders@get2net.dk>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include <kprinter.h>
00022 #include <kmessagebox.h>
00023 
00024 #include <KoMainWindow.h>
00025 
00026 #include <qapplication.h>
00027 #include <qpainter.h>
00028 #include <qiconset.h>
00029 #include <qlayout.h>
00030 #include <qsplitter.h>
00031 #include <qcanvas.h>
00032 #include <qscrollview.h>
00033 #include <qcolor.h>
00034 #include <qlabel.h>
00035 #include <qstring.h>
00036 #include <qstringlist.h>
00037 #include <qvbox.h>
00038 #include <qgrid.h>
00039 #include <qsize.h>
00040 #include <qheader.h>
00041 #include <qtabwidget.h>
00042 #include <qwidgetstack.h>
00043 #include <qtimer.h>
00044 #include <qpopupmenu.h>
00045 #include <qpair.h>
00046 
00047 #include <kiconloader.h>
00048 #include <kaction.h>
00049 #include <kstdaction.h>
00050 #include <klocale.h>
00051 #include <kdebug.h>
00052 #include <klistview.h>
00053 #include <kstdaccel.h>
00054 #include <kaccelgen.h>
00055 #include <kdeversion.h>
00056 #include <kstatusbar.h>
00057 #include <kxmlguifactory.h>
00058 
00059 #include <kstandarddirs.h>
00060 #include <kdesktopfile.h>
00061 #include <kcommand.h>
00062 #include <kfiledialog.h>
00063 
00064 #include "kptview.h"
00065 #include "kptaccountsview.h"
00066 #include "kptfactory.h"
00067 #include "kptmilestoneprogressdialog.h"
00068 #include "kptnode.h"
00069 #include "kptpart.h"
00070 #include "kptproject.h"
00071 #include "kptmainprojectdialog.h"
00072 #include "kptprojectdialog.h"
00073 #include "kpttask.h"
00074 #include "kptsummarytaskdialog.h"
00075 #include "kpttaskdialog.h"
00076 #include "kpttaskprogressdialog.h"
00077 #include "kptganttview.h"
00078 #include "kptpertview.h"
00079 //#include "kptreportview.h"
00080 #include "kptdatetime.h"
00081 #include "kptcommand.h"
00082 #include "kptrelation.h"
00083 #include "kptrelationdialog.h"
00084 #include "kptresourceview.h"
00085 #include "kptresourcedialog.h"
00086 #include "kptresource.h"
00087 #include "kptresourcesdialog.h"
00088 #include "kptcalendarlistdialog.h"
00089 #include "kptstandardworktimedialog.h"
00090 #include "kptcanvasitem.h"
00091 #include "kptconfigdialog.h"
00092 #include "kptwbsdefinitiondialog.h"
00093 #include "kptaccountsdialog.h"
00094 
00095 #include "KDGanttView.h"
00096 #include "KDGanttViewTaskItem.h"
00097 #include "KPtViewIface.h"
00098 
00099 namespace KPlato
00100 {
00101 
00102 View::View(Part* part, QWidget* parent, const char* /*name*/)
00103     : KoView(part, parent, "Main View"),
00104     m_ganttview(0),
00105     m_ganttlayout(0),
00106     m_pertview(0),
00107     m_pertlayout(0),
00108 //    m_reportview(0),
00109     m_baselineMode(false),
00110     m_currentEstimateType(Effort::Use_Expected)
00111 {
00112     //kdDebug()<<k_funcinfo<<endl;
00113     getProject().setCurrentSchedule(Schedule::Expected);
00114     
00115     setInstance(Factory::global());
00116     if ( !part->isReadWrite() )
00117         setXMLFile("kplato_readonly.rc");
00118     else
00119         setXMLFile("kplato.rc");
00120     m_dcop = 0L;
00121     // build the DCOP object
00122     dcopObject();
00123 
00124     m_tab = new QWidgetStack(this);
00125     QVBoxLayout *layout = new QVBoxLayout(this);
00126     layout->add(m_tab);
00127 
00128     m_ganttview = new GanttView(m_tab, part->isReadWrite());
00129     m_tab->addWidget(m_ganttview);
00130     m_updateGanttview = false;
00131     m_ganttview->draw(getPart()->getProject());
00132 
00133     m_pertview = new PertView( this, m_tab, layout );
00134     m_tab->addWidget(m_pertview);
00135 
00136     m_resourceview = new ResourceView( this, m_tab );
00137     m_updateResourceview = true;
00138     m_tab->addWidget(m_resourceview);
00139     
00140     m_accountsview = new AccountsView( getProject(), this, m_tab );
00141     m_updateAccountsview = true;
00142     m_tab->addWidget(m_accountsview);
00143     
00144     //m_reportview = new ReportView(this, m_tab);
00145     //m_tab->addWidget(m_reportview);
00146 
00147     connect(m_tab, SIGNAL(aboutToShow(QWidget *)), this, SLOT(slotAboutToShow(QWidget *)));
00148     
00149     connect(m_pertview, SIGNAL(addRelation(Node*, Node*)), SLOT(slotAddRelation(Node*, Node*)));
00150     connect(m_pertview, SIGNAL(modifyRelation(Relation*)), SLOT(slotModifyRelation(Relation*)));
00151 
00152     connect(m_ganttview, SIGNAL(enableActions(bool)), SLOT(setTaskActionsEnabled(bool)));
00153     connect(m_ganttview, SIGNAL(addRelation(Node*, Node*, int)), SLOT(slotAddRelation(Node*, Node*, int)));
00154     connect(m_ganttview, SIGNAL(modifyRelation(Relation*, int)), SLOT(slotModifyRelation(Relation*, int)));
00155     connect(m_ganttview, SIGNAL(modifyRelation(Relation*)), SLOT(slotModifyRelation(Relation*)));
00156     connect(m_ganttview, SIGNAL(itemDoubleClicked()), SLOT(slotOpenNode()));
00157     connect(m_ganttview, SIGNAL(itemRenamed(Node*, const QString&)),this,SLOT(slotRenameNode(Node*, const QString&)));
00158     connect(m_ganttview, SIGNAL(requestPopupMenu(const QString&, const QPoint &)),this,SLOT(slotPopupMenu(const QString&, const QPoint&)));
00159     connect(m_resourceview, SIGNAL(itemDoubleClicked()), SLOT(slotEditResource()));
00160 
00161     // The menu items
00162     // ------ Edit
00163     actionCut = KStdAction::cut( this, SLOT( slotEditCut() ), actionCollection(), "edit_cut" );
00164     actionCopy = KStdAction::copy( this, SLOT( slotEditCopy() ), actionCollection(), "edit_copy" );
00165     actionPaste = KStdAction::paste( this, SLOT( slotEditPaste() ), actionCollection(), "edit_paste" );
00166 
00167     actionIndentTask = new KAction(i18n("Indent Task"), "indent_task", 0, this,
00168         SLOT(slotIndentTask()), actionCollection(), "indent_task");
00169     actionUnindentTask = new KAction(i18n("Unindent Task"), "unindent_task", 0, this,
00170         SLOT(slotUnindentTask()), actionCollection(), "unindent_task");
00171     actionMoveTaskUp = new KAction(i18n("Move Up"), "move_task_up", 0, this,
00172         SLOT(slotMoveTaskUp()), actionCollection(), "move_task_up");
00173     actionMoveTaskDown = new KAction(i18n("Move Down"), "move_task_down", 0, this,
00174         SLOT(slotMoveTaskDown()), actionCollection(), "move_task_down");
00175 
00176     // ------ View
00177     actionViewGantt = new KAction(i18n("Gantt"), "gantt_chart", 0, this, SLOT(slotViewGantt()), actionCollection(), "view_gantt");
00178     
00179     QString group = "EstimationType";
00180     actionViewExpected = new KRadioAction(i18n("Expected"), 0, 0, this, SLOT(slotViewExpected()), actionCollection(), "view_expected");
00181     actionViewExpected->setExclusiveGroup(group);
00182     actionViewOptimistic = new KRadioAction(i18n("Optimistic"), 0, 0, this, SLOT(slotViewOptimistic()), actionCollection(), "view_optimistic");
00183     actionViewOptimistic->setExclusiveGroup(group);
00184     actionViewPessimistic = new KRadioAction(i18n("Pessimistic"), 0, 0, this, SLOT(slotViewPessimistic()), actionCollection(), "view_pessimistic");
00185     actionViewPessimistic->setExclusiveGroup(group);
00186 
00187     actionViewGanttResources = new KToggleAction(i18n("Resources"), 0, 0, this, SLOT(slotViewGanttResources()), actionCollection(), "view_gantt_showResources");
00188     actionViewGanttTaskName = new KToggleAction(i18n("Task Name"), 0, 0, this, SLOT(slotViewGanttTaskName()), actionCollection(), "view_gantt_showTaskName");
00189     actionViewGanttTaskLinks = new KToggleAction(i18n("Task Links"), 0, 0, this, SLOT(slotViewGanttTaskLinks()), actionCollection(), "view_gantt_showTaskLinks");
00190     actionViewGanttProgress = new KToggleAction(i18n("Progress"), 0, 0, this, SLOT(slotViewGanttProgress()), actionCollection(), "view_gantt_showProgress");
00191     actionViewGanttFloat = new KToggleAction(i18n("Float"), 0, 0, this, SLOT(slotViewGanttFloat()), actionCollection(), "view_gantt_showFloat");
00192     actionViewGanttCriticalTasks = new KToggleAction(i18n("Critical Tasks"), 0, 0, this, SLOT(slotViewGanttCriticalTasks()), actionCollection(), "view_gantt_showCriticalTasks");
00193     actionViewGanttCriticalPath = new KToggleAction(i18n("Critical Path"), 0, 0, this, SLOT(slotViewGanttCriticalPath()), actionCollection(), "view_gantt_showCriticalPath");
00194     
00195 //    actionViewGanttNotScheduled = new KToggleAction(i18n("Not Scheduled"), 0, 0, this, SLOT(slotViewGanttNotScheduled()), actionCollection(), "view_gantt_showNotScheduled");
00196     
00197     actionViewTaskAppointments = new KToggleAction(i18n("Show allocations"), 0, 0, this, SLOT(slotViewTaskAppointments()), actionCollection(), "view_task_appointments");
00198 
00199     actionViewPert = new KAction(i18n("Network"), "pert_chart", 0, this, SLOT(slotViewPert()), actionCollection(), "view_pert");
00200     
00201     actionViewResources = new KAction(i18n("Resources"), "resources", 0, this, SLOT(slotViewResources()), actionCollection(), "view_resources");
00202     
00203     actionViewResourceAppointments = new KToggleAction(i18n("Show allocations"), 0, 0, this, SLOT(slotViewResourceAppointments()), actionCollection(), "view_resource_appointments");
00204 
00205     actionViewAccounts = new KAction(i18n("Accounts"), "accounts", 0, this, SLOT(slotViewAccounts()), actionCollection(), "view_accounts");
00206 
00207     //actionViewReports = new KAction(i18n("Reports"), "reports", 0, this, SLOT(slotViewReports()), actionCollection(), "view_reports");
00208 
00209     // ------ Insert
00210     actionAddTask = new KAction(i18n("Task..."), "add_task", 0, this,
00211         SLOT(slotAddTask()), actionCollection(), "add_task");
00212     actionAddSubtask = new KAction(i18n("Sub-Task..."), "add_sub_task", 0, this,
00213         SLOT(slotAddSubTask()), actionCollection(), "add_sub_task");
00214     actionAddMilestone = new KAction(i18n("Milestone..."), "add_milestone", 0, this,
00215         SLOT(slotAddMilestone()), actionCollection(), "add_milestone");
00216 
00217     // ------ Project
00218     actionEditMainProject = new KAction(i18n("Edit Main Project..."), "edit", 0, this, SLOT(slotProjectEdit()), actionCollection(), "project_edit");
00219     actionEditStandardWorktime = new KAction(i18n("Edit Standard Worktime..."), "edit", 0, this, SLOT(slotProjectWorktime()), actionCollection(), "project_worktime");
00220     actionEditCalendar = new KAction(i18n("Edit Calendar..."), "edit", 0, this, SLOT(slotProjectCalendar()), actionCollection(), "project_calendar");
00221     actionEditAccounts = new KAction(i18n("Edit Accounts..."), "edit", 0, this, SLOT(slotProjectAccounts()), actionCollection(), "project_accounts");
00222     actionEditResources = new KAction(i18n("Edit Resources..."), "edit", 0, this, SLOT(slotProjectResources()), actionCollection(), "project_resources");
00223     
00224     actionCalculate = new KActionMenu(i18n("Calculate"), "project_calculate",  actionCollection(), "project_calculate");
00225     connect(actionCalculate, SIGNAL(activated()), SLOT(slotProjectCalculate()));
00226     
00227     actionCalculateExpected = new KAction(i18n("Expected"), 0, 0, this, SLOT(slotProjectCalculateExpected()), actionCollection(), "project_calculate_expected");
00228     actionCalculate->insert(actionCalculateExpected);
00229     
00230     actionCalculateOptimistic = new KAction(i18n("Optimistic"), 0, 0, this, SLOT(slotProjectCalculateOptimistic()), actionCollection(), "project_calculate_optimistic");
00231     actionCalculate->insert(actionCalculateOptimistic);
00232     
00233     actionCalculatePessimistic = new KAction(i18n("Pessimistic"), 0, 0, this, SLOT(slotProjectCalculatePessimistic()), actionCollection(), "project_calculate_pessimistic");
00234     actionCalculate->insert(actionCalculatePessimistic);
00235     
00236 /*    // ------ Reports
00237     actionFirstpage = KStdAction::firstPage(m_reportview,SLOT(slotPrevPage()),actionCollection(),"go_firstpage");
00238     connect(m_reportview, SIGNAL(setFirstPageActionEnabled(bool)), actionFirstpage, SLOT(setEnabled(bool)));
00239     actionPriorpage = KStdAction::prior(m_reportview,SLOT(slotPrevPage()),actionCollection(),"go_prevpage");
00240     connect(m_reportview, SIGNAL(setPriorPageActionEnabled(bool)), actionPriorpage, SLOT(setEnabled(bool)));
00241     actionNextpage = KStdAction::next(m_reportview,SLOT(slotNextPage()),actionCollection(), "go_nextpage");
00242     connect(m_reportview, SIGNAL(setNextPageActionEnabled(bool)), actionNextpage, SLOT(setEnabled(bool)));
00243     actionLastpage = KStdAction::lastPage(m_reportview,SLOT(slotLastPage()),actionCollection(), "go_lastpage");
00244     connect(m_reportview, SIGNAL(setLastPageActionEnabled(bool)), actionLastpage, SLOT(setEnabled(bool)));
00245     m_reportview->enableNavigationBtn();*/
00246     mainWindow()->toolBar("report")->hide();
00247     
00248 //     new KAction(i18n("Design..."), "report_design", 0, this,
00249 //         SLOT(slotReportDesign()), actionCollection(), "report_design");
00250 
00251 
00252     // ------ Tools
00253     actionDefineWBS = 
00254         new KAction(i18n("Define WBS Pattern..."), "tools_define_wbs", 0, this,
00255         SLOT(slotDefineWBS()), actionCollection(), "tools_generate_wbs");
00256     actionGenerateWBS = 
00257         new KAction(i18n("Generate WBS Code"), "tools_generate_wbs", 0, this,
00258         SLOT(slotGenerateWBS()), actionCollection(), "tools_define_wbs");
00259     
00260     // ------ Export (testing)
00261     //actionExportGantt = new KAction(i18n("Export Ganttview"), "export_gantt", 0, this,
00262     //    SLOT(slotExportGantt()), actionCollection(), "export_gantt");
00263     
00264     // ------ Settings
00265     actionConfigure = new KAction(i18n("Configure KPlato..."), "configure", 0, this,
00266         SLOT(slotConfigure()), actionCollection(), "configure");
00267     
00268     // ------ Popup
00269     actionOpenNode = new KAction(i18n("Edit..."), "edit", 0, this,
00270         SLOT(slotOpenNode()), actionCollection(), "node_properties");
00271     actionTaskProgress = new KAction(i18n("Progress..."), "edit", 0, this,
00272         SLOT(slotTaskProgress()), actionCollection(), "task_progress");
00273     actionDeleteTask = new KAction(i18n("Delete Task"), "editdelete", 0, this,
00274         SLOT(slotDeleteTask()), actionCollection(), "delete_task");
00275 
00276     actionEditResource = new KAction(i18n("Edit Resource..."), "edit", 0, this,
00277         SLOT(slotEditResource()), actionCollection(), "edit_resource");
00278 
00279     // ------------------- Actions with a key binding and no GUI item
00280     // Temporary, till we get a menu entry
00281     actNoInformation = new KAction("Toggle no information", CTRL+SHIFT+Key_T, this, SLOT(slotViewGanttNoInformation()), actionCollection(), "show_noinformation");
00282     
00283 #ifndef NDEBUG
00284     //new KAction("Print Debug", CTRL+SHIFT+Key_P, this, SLOT( slotPrintDebug()), actionCollection(), "print_debug");
00285     new KAction("Print Debug", CTRL+SHIFT+Key_P, this, SLOT(slotPrintSelectedDebug()), actionCollection(), "print_debug");
00286     new KAction("Print Calendar Debug", CTRL+SHIFT+Key_C, this, SLOT(slotPrintCalendarDebug()), actionCollection(), "print_calendar_debug");
00287 //     new KAction("Print Test Debug", CTRL+SHIFT+Key_T, this, SLOT(slotPrintTestDebug()), actionCollection(), "print_test_debug");
00288 
00289     KAction* actExportGantt = new KAction( i18n( "Export Gantt" ), CTRL+SHIFT+Key_G,
00290                         this, SLOT( slotExportGantt() ), actionCollection(), "export_gantt" );
00291 
00292 #endif
00293     // Stupid compilers ;)
00294 #ifndef NDEBUG
00295 /*  Q_UNUSED( actPrintSelectedDebug );
00296     Q_UNUSED( actPrintCalendarDebug );*/
00297     Q_UNUSED( actExportGantt );
00298 #endif
00299 
00300     m_estlabel = new KStatusBarLabel("", 0);
00301     addStatusBarItem(m_estlabel, 0, true);
00302     actionViewExpected->setChecked(true); //TODO: context
00303     setScheduleActionsEnabled();
00304     slotViewExpected();
00305     
00306     setTaskActionsEnabled(false);
00307 }
00308 
00309 View::~View()
00310 {
00311     delete m_dcop;
00312     removeStatusBarItem(m_estlabel);
00313     delete m_estlabel;
00314 }
00315 
00316 DCOPObject * View::dcopObject()
00317 {
00318   if ( !m_dcop )
00319     m_dcop = new ViewIface( this );
00320 
00321   return m_dcop;
00322 }
00323 
00324 
00325 Project& View::getProject() const
00326 {
00327     return getPart()->getProject();
00328 }
00329 
00330 void View::setZoom(double zoom) {
00331     m_ganttview->setZoom(zoom);
00332     m_pertview->setZoom(zoom);
00333 }
00334 
00335 void View::setupPrinter(KPrinter &/*printer*/) {
00336     //kdDebug()<<k_funcinfo<<endl;
00337 }
00338 
00339 void View::print(KPrinter &printer) {
00340     //kdDebug()<<k_funcinfo<<endl;
00341     if (printer.previewOnly()) {
00342         //HACK: KoMainWindow shows setup on print, but not on print preview!
00343         if (!printer.setup()) {
00344             return;
00345         }
00346     }
00347     if (m_tab->visibleWidget() == m_ganttview)
00348     {
00349         m_ganttview->print(printer);
00350     }
00351     else if (m_tab->visibleWidget() == m_pertview)
00352     {
00353         m_pertview->print(printer);
00354     }
00355     else if (m_tab->visibleWidget() == m_resourceview)
00356     {
00357         m_resourceview->print(printer);
00358     }
00359     else if (m_tab->visibleWidget() == m_accountsview)
00360     {
00361         m_accountsview->print(printer);
00362     }
00363 //  else if (m_tab->visibleWidget() == m_reportview)
00364 //  {
00365 //         m_reportview->print(printer);
00366 //  }
00367 
00368 }
00369 
00370 void View::slotEditCut() {
00371     //kdDebug()<<k_funcinfo<<endl;
00372 }
00373 
00374 void View::slotEditCopy() {
00375     //kdDebug()<<k_funcinfo<<endl;
00376 }
00377 
00378 void View::slotEditPaste() {
00379     //kdDebug()<<k_funcinfo<<endl;
00380 }
00381 
00382 void View::slotViewExpected() {
00383     //kdDebug()<<k_funcinfo<<endl;
00384     m_currentEstimateType = Effort::Use_Expected;
00385     getProject().setCurrentSchedulePtr(getProject().findSchedule(Schedule::Expected));
00386     slotUpdate(false);
00387 }
00388 
00389 void View::slotViewOptimistic() {
00390     //kdDebug()<<k_funcinfo<<endl;
00391     m_currentEstimateType = Effort::Use_Optimistic;
00392     getProject().setCurrentSchedulePtr(getProject().findSchedule(Schedule::Optimistic));
00393     slotUpdate(false);
00394 }
00395 
00396 void View::slotViewPessimistic() {
00397     //kdDebug()<<k_funcinfo<<endl;
00398     m_currentEstimateType = Effort::Use_Pessimistic;
00399     getProject().setCurrentSchedulePtr(getProject().findSchedule(Schedule::Pessimistic));
00400     slotUpdate(false);
00401 }
00402 
00403 void View::slotViewGanttResources() {
00404     //kdDebug()<<k_funcinfo<<endl;
00405     m_ganttview->setShowResources(actionViewGanttResources->isChecked());
00406     if (m_tab->visibleWidget() == m_ganttview)
00407         slotUpdate(false);
00408 }
00409 
00410 void View::slotViewGanttTaskName() {
00411     //kdDebug()<<k_funcinfo<<endl;
00412     m_ganttview->setShowTaskName(actionViewGanttTaskName->isChecked());
00413     if (m_tab->visibleWidget() == m_ganttview)
00414         slotUpdate(false);
00415 }
00416 
00417 void View::slotViewGanttTaskLinks() {
00418     //kdDebug()<<k_funcinfo<<endl;
00419     m_ganttview->setShowTaskLinks(actionViewGanttTaskLinks->isChecked());
00420     if (m_tab->visibleWidget() == m_ganttview)
00421         slotUpdate(false);
00422 }
00423 
00424 void View::slotViewGanttProgress() {
00425     //kdDebug()<<k_funcinfo<<endl;
00426     m_ganttview->setShowProgress(actionViewGanttProgress->isChecked());
00427     if (m_tab->visibleWidget() == m_ganttview)
00428         slotUpdate(false);
00429 }
00430 
00431 void View::slotViewGanttFloat() {
00432     //kdDebug()<<k_funcinfo<<endl;
00433     m_ganttview->setShowPositiveFloat(actionViewGanttFloat->isChecked());
00434     if (m_tab->visibleWidget() == m_ganttview)
00435         slotUpdate(false);
00436 }
00437 
00438 void View::slotViewGanttCriticalTasks() {
00439     //kdDebug()<<k_funcinfo<<endl;
00440     m_ganttview->setShowCriticalTasks(actionViewGanttCriticalTasks->isChecked());
00441     if (m_tab->visibleWidget() == m_ganttview)
00442         slotUpdate(false);
00443 }
00444 
00445 void View::slotViewGanttCriticalPath() {
00446     //kdDebug()<<k_funcinfo<<endl;
00447     m_ganttview->setShowCriticalPath(actionViewGanttCriticalPath->isChecked());
00448     if (m_tab->visibleWidget() == m_ganttview)
00449         slotUpdate(false);
00450 }
00451 
00452 void View::slotViewGanttNoInformation() {
00453     kdDebug()<<k_funcinfo<<m_ganttview->showNoInformation()<<endl;
00454     m_ganttview->setShowNoInformation(!m_ganttview->showNoInformation()); //Toggle
00455     if (m_tab->visibleWidget() == m_ganttview)
00456         slotUpdate(false);
00457 }
00458 
00459 void View::slotViewTaskAppointments() {
00460     //kdDebug()<<k_funcinfo<<endl;
00461     m_ganttview->setShowAppointments(actionViewTaskAppointments->isChecked());
00462     m_updateGanttview = true;
00463     if (m_tab->visibleWidget() == m_ganttview)
00464         slotUpdate(false);
00465 }
00466 
00467 void View::slotViewGantt() {
00468     //kdDebug()<<k_funcinfo<<endl;
00469     m_tab->raiseWidget(m_ganttview);
00470 }
00471 
00472 void View::slotViewPert() {
00473     //kdDebug()<<k_funcinfo<<endl;
00474     m_tab->raiseWidget(m_pertview);
00475 }
00476 
00477 void View::slotViewResources() {
00478     //kdDebug()<<k_funcinfo<<endl;
00479     m_tab->raiseWidget(m_resourceview);
00480 }
00481 
00482 void View::slotViewResourceAppointments() {
00483     //kdDebug()<<k_funcinfo<<endl;
00484     m_resourceview->setShowAppointments(actionViewResourceAppointments->isChecked());
00485     m_updateResourceview = true;
00486     if (m_tab->visibleWidget() == m_resourceview)
00487         slotUpdate(false);
00488 }
00489 
00490 void View::slotViewAccounts() {
00491     //kdDebug()<<k_funcinfo<<endl;
00492     m_tab->raiseWidget(m_accountsview);
00493 }
00494 
00495 void View::slotProjectEdit() {
00496     MainProjectDialog *dia = new MainProjectDialog(getProject());
00497     if (dia->exec()) {
00498         KCommand *cmd = dia->buildCommand(getPart());
00499         if (cmd) {
00500             getPart()->addCommand(cmd);
00501         }
00502     }
00503     delete dia;
00504 }
00505 
00506 void View::slotProjectCalendar() {
00507     CalendarListDialog *dia = new CalendarListDialog(getProject());
00508     if (dia->exec()) {
00509         KCommand *cmd = dia->buildCommand(getPart());
00510         if (cmd) {
00511             //kdDebug()<<k_funcinfo<<"Modifying calendar(s)"<<endl;
00512             getPart()->addCommand(cmd); //also executes
00513         }
00514     }
00515     delete dia;
00516 }
00517 
00518 void View::slotProjectAccounts() {
00519     AccountsDialog *dia = new AccountsDialog(getProject().accounts());
00520     if (dia->exec()) {
00521         KCommand *cmd = dia->buildCommand(getPart());
00522         if (cmd) {
00523             //kdDebug()<<k_funcinfo<<"Modifying account(s)"<<endl;
00524             getPart()->addCommand(cmd); //also executes
00525         }
00526     }
00527     delete dia;
00528 }
00529 
00530 void View::slotProjectWorktime() {
00531     StandardWorktimeDialog *dia = new StandardWorktimeDialog(getProject());
00532     if (dia->exec()) {
00533         KCommand *cmd = dia->buildCommand(getPart());
00534         if (cmd) {
00535             //kdDebug()<<k_funcinfo<<"Modifying calendar(s)"<<endl;
00536             getPart()->addCommand(cmd); //also executes
00537         }
00538     }
00539     delete dia;
00540 }
00541 
00542 void View::slotProjectResources() {
00543     ResourcesDialog *dia = new ResourcesDialog(getProject());
00544     if (dia->exec()) {
00545         KCommand *cmd = dia->buildCommand(getPart());
00546         if (cmd) {
00547             //kdDebug()<<k_funcinfo<<"Modifying resources"<<endl;
00548             getPart()->addCommand(cmd); //also executes
00549         }
00550     }
00551     delete dia;
00552 }
00553 
00554 void View::slotProjectCalculate() {
00555     //kdDebug()<<k_funcinfo<<endl;
00556     slotUpdate(true);
00557 }
00558 
00559 void View::slotProjectCalculateExpected() {
00560     m_currentEstimateType = Effort::Use_Expected;
00561     m_updateGanttview = true;
00562     m_updateResourceview = true;
00563     m_updateAccountsview = true;
00564     slotUpdate(true);
00565 }
00566 
00567 void View::slotProjectCalculateOptimistic() {
00568     m_currentEstimateType = Effort::Use_Optimistic;
00569     m_updateGanttview = true;
00570     m_updateResourceview = true;
00571     m_updateAccountsview = true;
00572     slotUpdate(true);
00573 }
00574 
00575 void View::slotProjectCalculatePessimistic() {
00576     m_currentEstimateType = Effort::Use_Pessimistic;
00577     m_updateGanttview = true;
00578     m_updateResourceview = true;
00579     m_updateAccountsview = true;
00580     slotUpdate(true);
00581 }
00582 
00583 void View::projectCalculate() {
00584     if (false /*getProject().actualEffort() > 0*/) {
00585         // NOTE: This can be removed when proper baselining etc is implemented
00586         if (KMessageBox::warningContinueCancel(this, i18n("Progress information will be deleted if the project is recalculated."), i18n("Calculate"), i18n("Calculate")) == KMessageBox::Cancel) {
00587             return;
00588         }
00589     }
00590     QApplication::setOverrideCursor(Qt::waitCursor);
00591     Schedule *ns = getProject().findSchedule((Schedule::Type)m_currentEstimateType);
00592     KCommand *cmd;
00593     if (ns) {
00594         cmd = new RecalculateProjectCmd(getPart(), getProject(), *ns, i18n("Calculate"));
00595     } else  {
00596         cmd = new CalculateProjectCmd(getPart(), getProject(), i18n("Standard"), (Effort::Use)m_currentEstimateType, i18n("Calculate"));
00597     }
00598     getPart()->addCommand(cmd);
00599     QApplication::restoreOverrideCursor();
00600 }
00601 
00602 void View::slotViewReportDesign() {
00603     //kdDebug()<<k_funcinfo<<endl;
00604 }
00605 
00606 void View::slotViewReports() {
00607     //kdDebug()<<k_funcinfo<<endl;
00608     //m_tab->raiseWidget(m_reportview);
00609 }
00610 
00611 void View::slotAddSubTask() {
00612     // If we are positionend on the root project, then what we really want to
00613     // do is to add a first project. We will silently accept the challenge
00614     // and will not complain.
00615     Task* node = getProject().createTask(getPart()->config().taskDefaults(), currentTask());
00616     TaskDialog *dia = new TaskDialog(*node, getProject().accounts(), getProject().standardWorktime(), getProject().isBaselined());
00617     if (dia->exec()) {
00618         Node *currNode = currentTask();
00619         if (currNode)
00620         {
00621             KCommand *m = dia->buildCommand(getPart());
00622             m->execute(); // do changes to task
00623             delete m;
00624             SubtaskAddCmd *cmd = new SubtaskAddCmd(getPart(), &(getProject()), node, currNode, i18n("Add Subtask"));
00625             getPart()->addCommand(cmd); // add task to project
00626             return;
00627         }
00628         else
00629             kdDebug()<<k_funcinfo<<"Cannot insert new project. Hmm, no current node!?"<<endl;
00630     }
00631     delete node;
00632     delete dia;
00633 }
00634 
00635 
00636 void View::slotAddTask() {
00637     Task* node = getProject().createTask(getPart()->config().taskDefaults(), currentTask());
00638     TaskDialog *dia = new TaskDialog(*node, getProject().accounts(), getProject().standardWorktime(), getProject().isBaselined());
00639     if (dia->exec()) {
00640         Node* currNode = currentTask();
00641         if (currNode)
00642         {
00643             KCommand *m = dia->buildCommand(getPart());
00644             m->execute(); // do changes to task
00645             delete m;
00646             TaskAddCmd *cmd = new TaskAddCmd(getPart(), &(getProject()), node, currNode, i18n("Add Task"));
00647             getPart()->addCommand(cmd); // add task to project
00648             return;
00649         }
00650         else
00651             kdDebug()<<k_funcinfo<<"Cannot insert new task. Hmm, no current node!?"<<endl;
00652     }
00653     delete node;
00654     delete dia;
00655 }
00656 
00657 void View::slotAddMilestone() {
00658     Task* node = getProject().createTask(currentTask());
00659     node->effort()->set(Duration::zeroDuration);
00660 
00661     TaskDialog *dia = new TaskDialog(*node, getProject().accounts(), getProject().standardWorktime(), getProject().isBaselined());
00662     if (dia->exec()) {
00663         Node *currNode = currentTask();
00664         if (currNode)
00665         {
00666             KCommand *m = dia->buildCommand(getPart());
00667             m->execute(); // do changes to task
00668             delete m;
00669             TaskAddCmd *cmd = new TaskAddCmd(getPart(), &(getProject()), node, currNode, i18n("Add Milestone"));
00670             getPart()->addCommand(cmd); // add task to project
00671             return;
00672         }
00673         else
00674             kdDebug()<<k_funcinfo<<"Cannot insert new milestone. Hmm, no current node!?"<<endl;
00675     }
00676     delete node;
00677     delete dia;
00678 }
00679 
00680 void View::slotDefineWBS() {
00681     //kdDebug()<<k_funcinfo<<endl;
00682     WBSDefinitionDialog *dia = new WBSDefinitionDialog(getPart()->wbsDefinition());
00683     dia->exec();
00684     
00685     delete dia;
00686 }
00687 
00688 void View::slotGenerateWBS() {
00689     //kdDebug()<<k_funcinfo<<endl;
00690     getPart()->generateWBS();
00691     slotUpdate(false);
00692 }
00693 
00694 void View::slotConfigure() {
00695     //kdDebug()<<k_funcinfo<<endl;
00696     ConfigDialog *dia = new ConfigDialog(getPart()->config(), getProject());
00697     dia->exec();
00698     delete dia;
00699 }
00700 
00701 Node *View::currentTask()
00702 {
00703     Node* task = 0;
00704     if (m_tab->visibleWidget() == m_ganttview) {
00705         task = m_ganttview->currentNode();
00706     }
00707     else if (m_tab->visibleWidget() == m_pertview) {
00708         task = m_pertview->currentNode();
00709     }
00710     else if (m_tab->visibleWidget() == m_resourceview) {
00711         task = m_resourceview->currentNode();
00712     }
00713     if ( 0 != task ) {
00714         return task;
00715     }
00716     return &(getProject());
00717 }
00718 
00719 void View::slotOpenNode() {
00720     //kdDebug()<<k_funcinfo<<endl;
00721     Node *node = currentTask();
00722     if (!node)
00723         return;
00724 
00725     switch (node->type()) {
00726         case Node::Type_Project: {
00727             Project *project = dynamic_cast<Project *>(node);
00728             MainProjectDialog *dia = new MainProjectDialog(*project);
00729             if (dia->exec()){
00730                 KCommand *m = dia->buildCommand(getPart());
00731                 if (m) {
00732                     getPart()->addCommand(m);
00733                 }
00734             }
00735             delete dia;
00736             break;
00737         }
00738         case Node::Type_Subproject:
00739             //TODO
00740             break;
00741         case Node::Type_Task: {
00742             Task *task = dynamic_cast<Task *>(node);
00743             TaskDialog *dia = new TaskDialog(*task, getProject().accounts(), getProject().standardWorktime(), getProject().isBaselined());
00744             if (dia->exec()) {
00745                 KCommand *m = dia->buildCommand(getPart());
00746                 if (m) {
00747                     getPart()->addCommand(m);
00748                 }
00749             }
00750             delete dia;
00751             break;
00752         }
00753         case Node::Type_Milestone: {
00754             // Use the normal task dialog for now.
00755             // Maybe milestone should have it's own dialog, but we need to be able to
00756             // enter a duration in case we accidentally set a tasks duration to zero
00757             // and hence, create a milestone
00758             Task *task = dynamic_cast<Task *>(node);
00759             TaskDialog *dia = new TaskDialog(*task, getProject().accounts(), getProject().standardWorktime(), getProject().isBaselined());
00760             if (dia->exec()) {
00761                 KCommand *m = dia->buildCommand(getPart());
00762                 if (m) {
00763                     getPart()->addCommand(m);
00764                 }
00765             }
00766             delete dia;
00767             break;
00768         }
00769         case Node::Type_Summarytask: {
00770             Task *task = dynamic_cast<Task *>(node);
00771             SummaryTaskDialog *dia = new SummaryTaskDialog(*task);
00772             if (dia->exec()) {
00773                 KCommand *m = dia->buildCommand(getPart());
00774                 if (m) {
00775                     getPart()->addCommand(m);
00776                 }
00777             }
00778             delete dia;
00779             break;
00780         }
00781         default:
00782             break; // avoid warnings
00783     }
00784 }
00785 
00786 void View::slotTaskProgress() {
00787     //kdDebug()<<k_funcinfo<<endl;
00788     Node *node = currentTask();
00789     if (!node)
00790         return;
00791 
00792     switch (node->type()) {
00793         case Node::Type_Project: {
00794             break;
00795         }
00796         case Node::Type_Subproject:
00797             //TODO
00798             break;
00799         case Node::Type_Task: {
00800             Task *task = dynamic_cast<Task *>(node);
00801             TaskProgressDialog *dia = new TaskProgressDialog(*task, getProject().standardWorktime());
00802             if (dia->exec()) {
00803                 KCommand *m = dia->buildCommand(getPart());
00804                 if (m) {
00805                     getPart()->addCommand(m);
00806                 }
00807             }
00808             delete dia;
00809             break;
00810         }
00811         case Node::Type_Milestone: {
00812             Task *task = dynamic_cast<Task *>(node);
00813             MilestoneProgressDialog *dia = new MilestoneProgressDialog(*task);
00814             if (dia->exec()) {
00815                 KCommand *m = dia->buildCommand(getPart());
00816                 if (m) {
00817                     getPart()->addCommand(m);
00818                 }
00819             }
00820             delete dia;
00821             break;
00822         }
00823         case Node::Type_Summarytask: {
00824             // TODO
00825             break;
00826         }
00827         default:
00828             break; // avoid warnings
00829     }
00830 }
00831 
00832 void View::slotDeleteTask()
00833 {
00834     //kdDebug()<<k_funcinfo<<endl;
00835     Node *node = currentTask();
00836     if (node == 0 || node->getParent() == 0) {
00837         kdDebug()<<k_funcinfo<<(node ? "Task is main project" : "No current task")<<endl;
00838         return;
00839     }
00840     KMacroCommand *cmd = new KMacroCommand(i18n("Delete Task"));
00841     cmd->addCommand(new NodeDeleteCmd(getPart(), node));
00842     QPtrListIterator<Relation> it = node->dependChildNodes();
00843     for (; it.current(); ++it) {
00844         cmd->addCommand(new DeleteRelationCmd(getPart(), it.current()));
00845     }
00846     it = node->dependParentNodes();
00847     for (; it.current(); ++it) {
00848         cmd->addCommand(new DeleteRelationCmd(getPart(),it.current()));
00849     }
00850     getPart()->addCommand(cmd);
00851 }
00852 
00853 void View::slotIndentTask()
00854 {
00855     //kdDebug()<<k_funcinfo<<endl;
00856     Node *node = currentTask();
00857     if (node == 0 || node->getParent() == 0) {
00858         kdDebug()<<k_funcinfo<<(node ? "Task is main project" : "No current task")<<endl;
00859         return;
00860     }
00861     if (getProject().canIndentTask(node)) {
00862         NodeIndentCmd *cmd = new NodeIndentCmd(getPart(), *node, i18n("Indent Task"));
00863         getPart()->addCommand(cmd);
00864     }
00865 }
00866 
00867 void View::slotUnindentTask()
00868 {
00869     //kdDebug()<<k_funcinfo<<endl;
00870     Node *node = currentTask();
00871     if (node == 0 || node->getParent() == 0) {
00872         kdDebug()<<k_funcinfo<<(node ? "Task is main project" : "No current task")<<endl;
00873         return;
00874     }
00875     if (getProject().canUnindentTask(node)) {
00876         NodeUnindentCmd *cmd = new NodeUnindentCmd(getPart(), *node, i18n("Unindent Task"));
00877         getPart()->addCommand(cmd);
00878     }
00879 }
00880 
00881 void View::slotMoveTaskUp()
00882 {
00883     //kdDebug()<<k_funcinfo<<endl;
00884 
00885     Node* task = currentTask();
00886     if ( 0 == task ) {
00887         // is always != 0. At least we would get the Project, but you never know who might change that
00888         // so better be careful
00889         kdError()<<k_funcinfo<<"No current task"<<endl;
00890         return;
00891     }
00892 
00893     if ( Node::Type_Project == task->type() ) {
00894         kdDebug()<<k_funcinfo<<"The root node cannot be moved up"<<endl;
00895         return;
00896     }
00897     if (getProject().canMoveTaskUp(task)) {
00898         NodeMoveUpCmd *cmd = new NodeMoveUpCmd(getPart(), *task, i18n("Move Task Up"));
00899         getPart()->addCommand(cmd);
00900     }
00901 }
00902 
00903 void View::slotMoveTaskDown()
00904 {
00905     //kdDebug()<<k_funcinfo<<endl;
00906 
00907     Node* task = currentTask();
00908     if ( 0 == task ) {
00909         // is always != 0. At least we would get the Project, but you never know who might change that
00910         // so better be careful
00911         return;
00912     }
00913 
00914     if ( Node::Type_Project == task->type() ) {
00915         kdDebug()<<k_funcinfo<<"The root node cannot be moved down"<<endl;
00916         return;
00917     }
00918     if (getProject().canMoveTaskDown(task)) {
00919         NodeMoveDownCmd *cmd = new NodeMoveDownCmd(getPart(), *task, i18n("Move Task Down"));
00920         getPart()->addCommand(cmd);
00921     }
00922 }
00923 
00924 void View::slotAddRelation(Node *par, Node *child) {
00925     //kdDebug()<<k_funcinfo<<endl;
00926     Relation *rel = new Relation(par, child);
00927     AddRelationDialog *dia = new AddRelationDialog(rel, this);
00928     if (dia->exec()) {
00929         KCommand *cmd = dia->buildCommand(getPart());
00930         if (cmd)
00931             getPart()->addCommand(cmd);
00932     } else {
00933         delete rel;
00934     }
00935     delete dia;
00936 }
00937 
00938 void View::slotAddRelation(Node *par, Node *child, int linkType) {
00939     //kdDebug()<<k_funcinfo<<endl;
00940     if (linkType == Relation::FinishStart ||
00941         linkType == Relation::StartStart ||
00942         linkType == Relation::FinishFinish) 
00943     {
00944         Relation *rel = new Relation(par, child,  static_cast<Relation::Type>(linkType));
00945         getPart()->addCommand(new AddRelationCmd(getPart(), rel, i18n("Add Relation")));
00946     } else {
00947         slotAddRelation(par, child);
00948     }
00949 }
00950 
00951 void View::slotModifyRelation(Relation *rel) {
00952     //kdDebug()<<k_funcinfo<<endl;
00953     ModifyRelationDialog *dia = new ModifyRelationDialog(rel, this);
00954     if (dia->exec()) {
00955         if (dia->relationIsDeleted()) {
00956             getPart()->addCommand(new DeleteRelationCmd(getPart(), rel, i18n("Delete Relation")));
00957         } else {
00958             KCommand *cmd = dia->buildCommand(getPart());
00959             if (cmd) {
00960                 getPart()->addCommand(cmd);
00961             }
00962         }
00963     }
00964     delete dia;
00965 }
00966 
00967 void View::slotModifyRelation(Relation *rel, int linkType) {
00968     //kdDebug()<<k_funcinfo<<endl;
00969     if (linkType == Relation::FinishStart ||
00970         linkType == Relation::StartStart ||
00971         linkType == Relation::FinishFinish) 
00972     {
00973         getPart()->addCommand(new ModifyRelationTypeCmd(getPart(), rel, static_cast<Relation::Type>(linkType)));
00974     } else {
00975         slotModifyRelation(rel);
00976     }
00977 }
00978 
00979 // testing
00980 void View::slotExportGantt() {
00981     //kdDebug()<<k_funcinfo<<endl;
00982     if (!m_ganttview) {
00983         return;
00984     }
00985     QString fn = KFileDialog::getSaveFileName( QString::null, QString::null, this );
00986     if (!fn.isEmpty()) {
00987         QFile f(fn);
00988         m_ganttview->exportGantt(&f);
00989     }
00990 }
00991 
00992 void View::slotEditResource() {
00993     //kdDebug()<<k_funcinfo<<endl;
00994     Resource *r = m_resourceview->currentResource();
00995     if (!r)
00996         return;
00997     ResourceDialog *dia = new ResourceDialog(getProject(), r);
00998     if (dia->exec()) {
00999         KCommand *cmd = dia->buildCommand(getPart());
01000         if (cmd)
01001             getPart()->addCommand(cmd);
01002     }
01003     delete dia;
01004 }
01005 
01006 void View::updateReadWrite(bool /*readwrite*/) {
01007 }
01008 
01009 Part *View::getPart()const {
01010     return (Part *)koDocument();
01011 }
01012 
01013 void View::slotConnectNode() {
01014     //kdDebug()<<k_funcinfo<<endl;
01015 /*    NodeItem *curr = m_ganttview->currentItem();
01016     if (curr) {
01017         kdDebug()<<k_funcinfo<<"node="<<curr->getNode().name()<<endl;
01018     }*/
01019 }
01020 
01021 QPopupMenu * View::popupMenu( const QString& name )
01022 {
01023     //kdDebug()<<k_funcinfo<<endl;
01024     Q_ASSERT(factory());
01025     if ( factory() )
01026         return ((QPopupMenu*)factory()->container( name, this ));
01027     return 0L;
01028 }
01029 
01030 void View::slotChanged(QWidget *)
01031 {
01032     //kdDebug()<<k_funcinfo<<endl;
01033     slotUpdate(false);
01034 }
01035 
01036 void View::slotChanged()
01037 {
01038     //kdDebug()<<k_funcinfo<<endl;
01039     slotUpdate(false);
01040 }
01041 
01042 void View::slotUpdate(bool calculate)
01043 {
01044     //kdDebug()<<k_funcinfo<<"calculate="<<calculate<<endl;
01045     if (m_currentEstimateType == Effort::Use_Expected) {
01046         m_estlabel->setText(i18n("Expected"));
01047     } else if (m_currentEstimateType == Effort::Use_Optimistic) {
01048         m_estlabel->setText(i18n("Optimistic"));
01049     } else if (m_currentEstimateType == Effort::Use_Pessimistic) {
01050         m_estlabel->setText(i18n("Pessimistic"));
01051     } else {
01052         m_estlabel->setText("");
01053     }
01054     if (calculate)
01055         projectCalculate();
01056         
01057     m_updateGanttview = true;
01058     m_updateResourceview = true;
01059     m_updateAccountsview = true;
01060     
01061     updateView(m_tab->visibleWidget());
01062 }
01063 
01064 void View::slotAboutToShow(QWidget *widget) {
01065     updateView(widget);
01066 }
01067 
01068 void View::updateView(QWidget *widget)
01069 {
01070     QApplication::setOverrideCursor(Qt::waitCursor);
01071     setScheduleActionsEnabled();
01072     setTaskActionsEnabled(false);
01073     mainWindow()->toolBar("report")->hide();
01074     if (widget == m_ganttview)
01075     {
01076         //kdDebug()<<k_funcinfo<<"draw gantt"<<endl;
01077         m_ganttview->setShowExpected(actionViewExpected->isChecked());
01078         m_ganttview->setShowOptimistic(actionViewOptimistic->isChecked());
01079         m_ganttview->setShowPessimistic(actionViewPessimistic->isChecked());
01080         if (m_updateGanttview)
01081             m_ganttview->drawChanges(getProject());
01082         setTaskActionsEnabled(widget, true);
01083         m_updateGanttview = false;
01084     }
01085     else if (widget == m_pertview)
01086     {
01087         //kdDebug()<<k_funcinfo<<"draw pertview"<<endl;
01088         m_pertview->draw();
01089     }
01090     else if (widget == m_resourceview)
01091     {
01092         //kdDebug()<<k_funcinfo<<"draw resourceview"<<endl;
01093         if (m_updateResourceview)
01094             m_resourceview->draw(getPart()->getProject());
01095         m_updateResourceview = false;
01096     }
01097     else if (widget == m_accountsview)
01098     {
01099         //kdDebug()<<k_funcinfo<<"draw accountsview"<<endl;
01100         if (m_updateAccountsview)
01101             m_accountsview->draw();
01102         m_updateAccountsview = false;
01103     }
01104 /*    else if (widget == m_reportview)
01105     {
01106         mainWindow()->toolBar("report")->show();
01107         m_reportview->enableNavigationBtn();
01108     }*/
01109     QApplication::restoreOverrideCursor();
01110 }
01111 
01112 void View::slotRenameNode(Node *node, const QString& name) {
01113     //kdDebug()<<k_funcinfo<<name<<endl;
01114     if (node) {
01115         NodeModifyNameCmd *cmd = new NodeModifyNameCmd(getPart(), *node, name, i18n("Modify Name"));
01116         getPart()->addCommand(cmd);
01117     }
01118 }
01119 
01120 void View::slotPopupMenu(const QString& menuname, const QPoint & pos)
01121 {
01122     QPopupMenu* menu = this->popupMenu(menuname);
01123     if (menu)
01124       menu->exec(pos);
01125 }
01126 
01127 bool View::setContext(Context &context) {
01128     //kdDebug()<<k_funcinfo<<endl;
01129     m_currentEstimateType = context.currentEstimateType;
01130     getProject().setCurrentSchedule(context.currentSchedule);
01131     actionViewExpected->setChecked(context.actionViewExpected);
01132     actionViewOptimistic->setChecked(context.actionViewOptimistic);
01133     actionViewPessimistic->setChecked(context.actionViewPessimistic);
01134     
01135     m_ganttview->setContext(context.ganttview, getProject());
01136     // hmmm, can't decide if these should be here or actions moved to ganttview
01137     actionViewGanttResources->setChecked(context.ganttview.showResources);
01138     actionViewGanttTaskName->setChecked(context.ganttview.showTaskName);
01139     actionViewGanttTaskLinks->setChecked(context.ganttview.showTaskLinks);
01140     actionViewGanttProgress->setChecked(context.ganttview.showProgress);
01141     actionViewGanttFloat->setChecked(context.ganttview.showPositiveFloat);
01142     actionViewGanttCriticalTasks->setChecked(context.ganttview.showCriticalTasks);
01143     actionViewGanttCriticalPath->setChecked(context.ganttview.showCriticalPath);
01144 
01145     m_pertview->setContext(context.pertview);
01146     m_resourceview->setContext(context.resourceview);
01147     m_accountsview->setContext(context.accountsview);
01148 //    m_reportview->setContext(context.reportview);
01149     
01150     if (context.currentView == "ganttview") {
01151         m_ganttview->setShowExpected(actionViewExpected->isChecked());
01152         m_ganttview->setShowOptimistic(actionViewOptimistic->isChecked());
01153         m_ganttview->setShowPessimistic(actionViewPessimistic->isChecked());
01154         slotViewGantt();
01155     } else if (context.currentView == "pertview") {
01156         slotViewPert();
01157     } else if (context.currentView == "resourceview") {
01158         slotViewResources();
01159     } else if (context.currentView == "accountsview") {
01160         slotViewAccounts();
01161     } else if (context.currentView == "reportview") {
01162         //slotViewReport();
01163     } else {
01164         slotViewGantt();
01165     }
01166     slotUpdate(false);
01167     return true;
01168 }
01169 
01170 void View::getContext(Context &context) const {
01171     //kdDebug()<<k_funcinfo<<endl;
01172     context.currentEstimateType = m_currentEstimateType;
01173     if (getProject().currentSchedule())
01174         context.currentSchedule = getProject().currentSchedule()->id();
01175     context.actionViewExpected = actionViewExpected->isChecked();
01176     context.actionViewOptimistic = actionViewOptimistic->isChecked();
01177     context.actionViewPessimistic = actionViewPessimistic->isChecked();
01178     
01179     if (m_tab->visibleWidget() == m_ganttview) {
01180         context.currentView = "ganttview";
01181     } else if (m_tab->visibleWidget() == m_pertview) {
01182         context.currentView = "pertview";
01183     } else if (m_tab->visibleWidget() == m_resourceview) {
01184         context.currentView = "resourceview";
01185     } else if (m_tab->visibleWidget() == m_accountsview) {
01186         context.currentView = "accountsview";
01187 /*    } else if (m_tab->visibleWidget() == m_reportview) {
01188         context.currentView = "reportview";*/
01189     }
01190     m_ganttview->getContext(context.ganttview);
01191     m_pertview->getContext(context.pertview);
01192     m_resourceview->getContext(context.resourceview);
01193     m_accountsview->getContext(context.accountsview);
01194 //    m_reportview->getContext(context.reportview);
01195 }
01196 
01197 void View::setBaselineMode(bool /*on*/) {
01198     //kdDebug()<<k_funcinfo<<endl;
01199 /*    m_baselineMode = on;
01200     
01201     m_ganttview->setReadWriteMode(!on);
01202     
01203     actionCut->setEnabled(!on);
01204     actionCopy->setEnabled(!on);
01205     actionPaste->setEnabled(!on);
01206 
01207     actionDeleteTask->setEnabled(!on);
01208     actionIndentTask->setEnabled(!on);
01209     actionUnindentTask->setEnabled(!on);
01210     actionMoveTaskUp->setEnabled(!on);
01211     actionMoveTaskDown->setEnabled(!on);
01212 
01213     actionAddTask->setEnabled(!on);
01214     actionAddSubtask->setEnabled(!on);
01215     actionAddMilestone->setEnabled(!on);
01216 
01217     actionEditStandardWorktime->setEnabled(!on);
01218     actionEditCalendar->setEnabled(!on);
01219     actionEditResources->setEnabled(!on);
01220     actionCalculate->setEnabled(!on);
01221 
01222     actionEditResource->setEnabled(!on);*/
01223 }
01224 
01225 // called when widget w is about to be shown
01226 void View::setTaskActionsEnabled(QWidget *w, bool on) {
01227     Node *n = 0;
01228     if (w == m_ganttview) {
01229         n = m_ganttview->currentNode();
01230     }// else pert, etc when implemented
01231      
01232     actionAddTask->setEnabled(on);
01233     actionAddMilestone->setEnabled(on);
01234     // only enabled when we have a task selected
01235     bool o = (on && n);
01236     actionAddSubtask->setEnabled(o);
01237     actionDeleteTask->setEnabled(o);
01238     actionMoveTaskUp->setEnabled(o && getProject().canMoveTaskUp(n));
01239     actionMoveTaskDown->setEnabled(o && getProject().canMoveTaskDown(n));
01240     actionIndentTask->setEnabled(o && getProject().canIndentTask(n));
01241     actionUnindentTask->setEnabled(o && getProject().canUnindentTask(n));
01242 }
01243 
01244 void View::setTaskActionsEnabled(bool on) {
01245     setTaskActionsEnabled(m_ganttview, on); //FIXME if more than ganttview can do this
01246 }
01247 
01248 void View::setScheduleActionsEnabled() {
01249     actionViewExpected->setEnabled(getProject().findSchedule(Schedule::Expected));
01250     actionViewOptimistic->setEnabled(getProject().findSchedule(Schedule::Optimistic));
01251     actionViewPessimistic->setEnabled(getProject().findSchedule(Schedule::Pessimistic));
01252     Schedule *ns = getProject().currentSchedule();
01253     if (ns == 0) {
01254         return;
01255     }
01256     if (ns->type() == Schedule::Expected)
01257         actionViewExpected->setChecked(true);
01258     else if (ns->type() == Schedule::Optimistic)
01259         actionViewOptimistic->setChecked(true);
01260     else if (ns->type() == Schedule::Pessimistic)
01261         actionViewPessimistic->setChecked(true);
01262 }
01263 
01264 
01265 #ifndef NDEBUG
01266 void View::slotPrintDebug() {
01267     kdDebug()<<"-------- Debug printout: Node list" <<endl;
01268 /*    Node *curr = m_ganttview->currentNode();
01269     if (curr) {
01270         curr->printDebug(true,"");
01271     } else*/
01272         getPart()->getProject().printDebug(true, "");
01273 }
01274 void View::slotPrintSelectedDebug() {
01275     Node *curr = m_ganttview->currentNode();
01276     if (curr) {
01277         kdDebug()<<"-------- Debug printout: Selected node" <<endl;
01278         curr->printDebug(true,"");
01279     } else
01280         slotPrintDebug();
01281 }
01282 void View::slotPrintCalendarDebug() {
01283     kdDebug()<<"-------- Debug printout: Node list" <<endl;
01284 /*    Node *curr = m_ganttview->currentNode();
01285     if (curr) {
01286         curr->printDebug(true,"");
01287     } else*/
01288         getPart()->getProject().printCalendarDebug("");
01289 }
01290 void View::slotPrintTestDebug() {
01291     const QStringList &lst = getPart()->xmlLoader().log();
01292     
01293     for ( QStringList::ConstIterator it = lst.constBegin(); it != lst.constEnd(); ++it ) {
01294         kdDebug()<<*it<<endl;
01295     }
01296 //     kdDebug()<<"------------Test 1---------------------"<<endl;
01297 //     {
01298 //     DateTime d1(QDate(2006,1,2), QTime(8,0,0));
01299 //     DateTime d2 = d1.addSecs(3600);
01300 //     Duration d = d2 - d1;
01301 //     bool b = d==Duration(0,0,0,3600);
01302 //     kdDebug()<<"1: Success="<<b<<"    "<<d2.toString()<<"-"<<d1.toString()<<"="<<d.toString()<<endl;
01303 //     d = d1 - d2;
01304 //     b = d==Duration(0,0,0,3600);
01305 //     kdDebug()<<"2: Success="<<b<<"    "<<d1.toString()<<"-"<<d2.toString()<<"="<<d.toString()<<endl;
01306 //     d2 = d2.addDays(-2);
01307 //     d = d1 - d2;
01308 //     b = d==Duration(2,0,0)-Duration(0,0,0,3600);
01309 //     kdDebug()<<"3: Success="<<b<<"    "<<d1.toString()<<"-"<<d2.toString()<<"="<<d.toString()<<endl;
01310 //     d = d2 - d1;
01311 //     b = d==Duration(2,0,0)-Duration(0,0,0,3600);
01312 //     kdDebug()<<"4: Success="<<b<<"     "<<d2.toString()<<"-"<<d1.toString()<<"="<<d.toString()<<endl;
01313 //     kdDebug()<<endl;
01314 //     b = (d2 + d)==d1;
01315 //     kdDebug()<<"5: Success="<<b<<"   "<<d2<<"+"<<d.toString()<<"="<<d1<<endl;
01316 //     b = (d1 - d)==d2;
01317 //     kdDebug()<<"6: Success="<<b<<"   "<<d1<<"-"<<d.toString()<<"="<<d2<<endl;
01318 //     } // end test 1
01319 //     kdDebug()<<endl;
01320 //     kdDebug()<<"------------Test 2 Single calendar-----------------"<<endl;
01321 //     {
01322 //     Calendar *t = new Calendar("Test 2");
01323 //     QDate wdate(2006,1,2);
01324 //     DateTime before = DateTime(wdate.addDays(-1));
01325 //     DateTime after = DateTime(wdate.addDays(1));
01326 //     QTime t1(8,0,0);
01327 //     QTime t2(10,0,0);
01328 //     DateTime wdt1(wdate, t1);
01329 //     DateTime wdt2(wdate, t2);
01330 //     CalendarDay *day = new CalendarDay(QDate(2006,1,2), Map::Working);
01331 //     day->addInterval(QPair<QTime, QTime>(t1, t2));
01332 //     if (!t->addDay(day)) {
01333 //         kdDebug()<<"Failed to add day"<<endl;
01334 //         delete day;
01335 //         delete t;
01336 //         return;
01337 //     }
01338 //     kdDebug()<<"Added     date="<<day->date().toString()<<" "<<day->startOfDay().toString()<<" - "<<day->endOfDay()<<endl;
01339 //     kdDebug()<<"Found     date="<<day->date().toString()<<" "<<day->startOfDay().toString()<<" - "<<day->endOfDay()<<endl;
01340 //     
01341 //     CalendarDay *d = t->findDay(wdate);
01342 //     bool b = (day == d);
01343 //     kdDebug()<<"1: Success="<<b<<"      Find same day"<<endl;
01344 //     
01345 //     DateTime dt = t->firstAvailableAfter(after, after.addDays(10));
01346 //     b = !dt.isValid();
01347 //     kdDebug()<<"2: Success="<<b<<"      firstAvailableAfter("<<after<<"): ="<<dt<<endl;
01348 //     
01349 //     dt = t->firstAvailableBefore(before, before.addDays(-10));
01350 //     b = !dt.isValid();
01351 //     kdDebug()<<"3: Success="<<b<<"       firstAvailableBefore("<<before.toString()<<"): ="<<dt<<endl;
01352 //     
01353 //     dt = t->firstAvailableAfter(before, after);
01354 //     b = dt == wdt1;
01355 //     kdDebug()<<"4: Success="<<b<<"      firstAvailableAfter("<<before<<"): ="<<dt<<endl;
01356 //     
01357 //     dt = t->firstAvailableBefore(after, before);
01358 //     b = dt == wdt2;
01359 //     kdDebug()<<"5: Success="<<b<<"      firstAvailableBefore("<<after<<"): ="<<dt<<endl;
01360 //     
01361 //     b = t->hasInterval(before, after);
01362 //     kdDebug()<<"6: Success="<<b<<"      hasInterval("<<before<<", "<<after<<")"<<endl;
01363 //     
01364 //     b = !t->hasInterval(after, after.addDays(1));
01365 //     kdDebug()<<"7: Success="<<b<<"      !hasInterval("<<after<<", "<<after.addDays(1)<<")"<<endl;
01366 //     
01367 //     b = !t->hasInterval(before, before.addDays(-1));
01368 //     kdDebug()<<"8: Success="<<b<<"      !hasInterval("<<before<<", "<<before.addDays(-1)<<")"<<endl;
01369 //     
01370 //     Duration e1(0, 2, 0); // 2 hours
01371 //     Duration e2 = t->effort(before, after);
01372 //     b = e1==e2;
01373 //     kdDebug()<<"9: Success="<<b<<"      effort"<<e1.toString()<<" = "<<e2.toString()<<endl;
01374 //     
01375 //     delete t;
01376 //     }// end test 2
01377 //     
01378 //     kdDebug()<<endl;
01379 //     kdDebug()<<"------------Test 3 Parent calendar-----------------"<<endl;
01380 //     {
01381 //     Calendar *t = new Calendar("Test 3");
01382 //     Calendar *p = new Calendar("Test 3 parent");
01383 //     t->setParent(p);
01384 //     QDate wdate(2006,1,2);
01385 //     DateTime before = DateTime(wdate.addDays(-1));
01386 //     DateTime after = DateTime(wdate.addDays(1));
01387 //     QTime t1(8,0,0);
01388 //     QTime t2(10,0,0);
01389 //     DateTime wdt1(wdate, t1);
01390 //     DateTime wdt2(wdate, t2);
01391 //     CalendarDay *day = new CalendarDay(QDate(2006,1,2), Map::Working);
01392 //     day->addInterval(QPair<QTime, QTime>(t1, t2));
01393 //     if (!p->addDay(day)) {
01394 //         kdDebug()<<"Failed to add day"<<endl;
01395 //         delete day;
01396 //         delete t;
01397 //         return;
01398 //     }
01399 //     kdDebug()<<"Added     date="<<day->date().toString()<<" "<<day->startOfDay().toString()<<" - "<<day->endOfDay().toString()<<endl;
01400 //     kdDebug()<<"Found     date="<<day->date().toString()<<" "<<day->startOfDay().toString()<<" - "<<day->endOfDay().toString()<<endl;
01401 //     
01402 //     CalendarDay *d = p->findDay(wdate);
01403 //     bool b = (day == d);
01404 //     kdDebug()<<"1: Success="<<b<<"      Find same day"<<endl;
01405 //     
01406 //     DateTime dt = t->firstAvailableAfter(after, after.addDays(10));
01407 //     b = !dt.isValid();
01408 //     kdDebug()<<"2: Success="<<b<<"      firstAvailableAfter("<<after.toString()<<"): ="<<!b<<endl;
01409 //     
01410 //     dt = t->firstAvailableBefore(before, before.addDays(-10));
01411 //     b = !dt.isValid();
01412 //     kdDebug()<<"3: Success="<<b<<"       firstAvailableBefore("<<before.toString()<<"): ="<<!b<<endl;
01413 //     
01414 //     dt = t->firstAvailableAfter(before, after);
01415 //     b = dt == wdt1;
01416 //     kdDebug()<<"4: Success="<<b<<"      firstAvailableAfter("<<before.toString()<<"): ="<<dt.toString()<<endl;
01417 //     
01418 //     dt = t->firstAvailableBefore(after, before);
01419 //     b = dt == wdt2;
01420 //     kdDebug()<<"5: Success="<<b<<"      firstAvailableBefore("<<after.toString()<<"): ="<<dt.toString()<<endl;
01421 //     
01422 //     b = t->hasInterval(before, after);
01423 //     kdDebug()<<"6: Success="<<b<<"      hasInterval("<<before.toString()<<", "<<after<<")"<<endl;
01424 //     
01425 //     b = !t->hasInterval(after, after.addDays(1));
01426 //     kdDebug()<<"7: Success="<<b<<"      !hasInterval("<<after.toString()<<", "<<after.addDays(1)<<")"<<endl;
01427 //     
01428 //     b = !t->hasInterval(before, before.addDays(-1));
01429 //     kdDebug()<<"8: Success="<<b<<"      !hasInterval("<<before.toString()<<", "<<before.addDays(-1)<<")"<<endl;
01430 //     Duration e1(0, 2, 0); // 2 hours
01431 //     Duration e2 = t->effort(before, after);
01432 //     b = e1==e2;
01433 //     kdDebug()<<"9: Success="<<b<<"      effort "<<e1.toString()<<"=="<<e2.toString()<<endl;
01434 //     
01435 //     delete t;
01436 //     delete p;
01437 //     }// end test 3
01438 //     kdDebug()<<endl;
01439 //     kdDebug()<<"------------Test 4 Parent calendar/weekdays-------------"<<endl;
01440 //     {
01441 //     QTime t1(8,0,0);
01442 //     QTime t2(10,0,0);
01443 //     Calendar *p = new Calendar("Test 4 parent");
01444 //     CalendarDay *wd1 = p->weekday(0); // monday
01445 //     if (wd1 == 0) {
01446 //         kdDebug()<<"Failed to get weekday"<<endl;
01447 //     }
01448 //     wd1->setState(Map::NonWorking);
01449 //     
01450 //     CalendarDay *wd2 = p->weekday(2); // wednesday
01451 //     if (wd2 == 0) {
01452 //         kdDebug()<<"Failed to get weekday"<<endl;
01453 //     }
01454 //     wd2->addInterval(QPair<QTime, QTime>(t1, t2));
01455 //     wd2->setState(Map::Working);
01456 //      
01457 //     Calendar *t = new Calendar("Test 4");
01458 //     t->setParent(p);
01459 //     QDate wdate(2006,1,2); // monday jan 2
01460 //     DateTime before = DateTime(wdate.addDays(-4)); //Thursday dec 29
01461 //     DateTime after = DateTime(wdate.addDays(4)); // Friday jan 6
01462 //     DateTime wdt1(wdate, t1);
01463 //     DateTime wdt2(QDate(2006, 1, 4), t2); // Wednesday
01464 //     CalendarDay *day = new CalendarDay(QDate(2006,1,2), Map::Working);
01465 //     day->addInterval(QPair<QTime, QTime>(t1, t2));
01466 //     if (!p->addDay(day)) {
01467 //         kdDebug()<<"Failed to add day"<<endl;
01468 //         delete day;
01469 //         delete t;
01470 //         return;
01471 //     }
01472 //     kdDebug()<<"Added     date="<<day->date().toString()<<" "<<day->startOfDay().toString()<<" - "<<day->endOfDay().toString()<<endl;
01473 //     kdDebug()<<"Found     date="<<day->date().toString()<<" "<<day->startOfDay().toString()<<" - "<<day->endOfDay().toString()<<endl;
01474 //     
01475 //     CalendarDay *d = p->findDay(wdate);
01476 //     bool b = (day == d);
01477 //     kdDebug()<<"1: Success="<<b<<"      Find same day"<<endl;
01478 //     
01479 //     DateTime dt = t->firstAvailableAfter(after, after.addDays(10));
01480 //     b = (dt.isValid() && dt == DateTime(QDate(2006,1,11), t1));
01481 //     kdDebug()<<"2: Success="<<b<<"      firstAvailableAfter("<<after<<"): ="<<dt<<endl;
01482 //     
01483 //     dt = t->firstAvailableBefore(before, before.addDays(-10));
01484 //     b = (dt.isValid() && dt == DateTime(QDate(2005, 12, 28), t2));
01485 //     kdDebug()<<"3: Success="<<b<<"       firstAvailableBefore("<<before.toString()<<"): ="<<dt<<endl;
01486 //     
01487 //     dt = t->firstAvailableAfter(before, after);
01488 //     b = dt == wdt1; // We find the day jan 2
01489 //     kdDebug()<<"4: Success="<<b<<"      firstAvailableAfter("<<before.toString()<<"): ="<<dt.toString()<<endl;
01490 //     
01491 //     dt = t->firstAvailableBefore(after, before);
01492 //     b = dt == wdt2; // We find the weekday (wednesday)
01493 //     kdDebug()<<"5: Success="<<b<<"      firstAvailableBefore("<<after.toString()<<"): ="<<dt.toString()<<endl;
01494 //     
01495 //     b = t->hasInterval(before, after);
01496 //     kdDebug()<<"6: Success="<<b<<"      hasInterval("<<before.toString()<<", "<<after<<")"<<endl;
01497 //     
01498 //     b = !t->hasInterval(after, after.addDays(1));
01499 //     kdDebug()<<"7: Success="<<b<<"      !hasInterval("<<after.toString()<<", "<<after.addDays(1)<<")"<<endl;
01500 //     
01501 //     b = !t->hasInterval(before, before.addDays(-1));
01502 //     kdDebug()<<"8: Success="<<b<<"      !hasInterval("<<before.toString()<<", "<<before.addDays(-1)<<")"<<endl;
01503 //     Duration e1(0, 4, 0); // 2 hours
01504 //     Duration e2 = t->effort(before, after);
01505 //     b = e1==e2;
01506 //     kdDebug()<<"9: Success="<<b<<"      effort "<<e1.toString()<<"="<<e2.toString()<<endl;
01507 //     
01508 //     QPair<DateTime, DateTime> r = t->firstInterval(before, after);
01509 //     b = r.first == wdt1; // We find the monday jan 2
01510 //     kdDebug()<<"10: Success="<<b<<"      firstInterval("<<before<<"): ="<<r.first<<", "<<r.second<<endl;
01511 //     r = t->firstInterval(r.second, after);
01512 //     b = r.first == DateTime(QDate(2006, 1, 4),t1); // We find the wednesday jan 4
01513 //     kdDebug()<<"11: Success="<<b<<"      firstInterval("<<r.second<<"): ="<<r.first<<", "<<r.second<<endl;
01514 //     
01515 //     delete t;
01516 //     delete p;
01517 //     }// end test 4
01518 }
01519 #endif
01520 
01521 }  //KPlato namespace
01522 
01523 #include "kptview.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys