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 (calculate)
01046         projectCalculate();
01047         
01048     m_updateGanttview = true;
01049     m_updateResourceview = true;
01050     m_updateAccountsview = true;
01051     
01052     updateView(m_tab->visibleWidget());
01053 }
01054 
01055 void View::slotAboutToShow(QWidget *widget) {
01056     updateView(widget);
01057 }
01058 
01059 void View::updateView(QWidget *widget)
01060 {
01061     QApplication::setOverrideCursor(Qt::waitCursor);
01062     setScheduleActionsEnabled();
01063     setTaskActionsEnabled(false);
01064     mainWindow()->toolBar("report")->hide();
01065     if (widget == m_ganttview)
01066     {
01067         //kdDebug()<<k_funcinfo<<"draw gantt"<<endl;
01068         m_ganttview->setShowExpected(actionViewExpected->isChecked());
01069         m_ganttview->setShowOptimistic(actionViewOptimistic->isChecked());
01070         m_ganttview->setShowPessimistic(actionViewPessimistic->isChecked());
01071         if (m_updateGanttview)
01072             m_ganttview->drawChanges(getProject());
01073         setTaskActionsEnabled(widget, true);
01074         m_updateGanttview = false;
01075     }
01076     else if (widget == m_pertview)
01077     {
01078         //kdDebug()<<k_funcinfo<<"draw pertview"<<endl;
01079         m_pertview->draw();
01080     }
01081     else if (widget == m_resourceview)
01082     {
01083         //kdDebug()<<k_funcinfo<<"draw resourceview"<<endl;
01084         if (m_updateResourceview)
01085             m_resourceview->draw(getPart()->getProject());
01086         m_updateResourceview = false;
01087     }
01088     else if (widget == m_accountsview)
01089     {
01090         //kdDebug()<<k_funcinfo<<"draw accountsview"<<endl;
01091         if (m_updateAccountsview)
01092             m_accountsview->draw();
01093         m_updateAccountsview = false;
01094     }
01095 /*    else if (widget == m_reportview)
01096     {
01097         mainWindow()->toolBar("report")->show();
01098         m_reportview->enableNavigationBtn();
01099     }*/
01100     QApplication::restoreOverrideCursor();
01101 }
01102 
01103 void View::slotRenameNode(Node *node, const QString& name) {
01104     //kdDebug()<<k_funcinfo<<name<<endl;
01105     if (node) {
01106         NodeModifyNameCmd *cmd = new NodeModifyNameCmd(getPart(), *node, name, i18n("Modify Name"));
01107         getPart()->addCommand(cmd);
01108     }
01109 }
01110 
01111 void View::slotPopupMenu(const QString& menuname, const QPoint & pos)
01112 {
01113     QPopupMenu* menu = this->popupMenu(menuname);
01114     if (menu)
01115       menu->exec(pos);
01116 }
01117 
01118 bool View::setContext(Context &context) {
01119     //kdDebug()<<k_funcinfo<<endl;
01120     m_currentEstimateType = context.currentEstimateType;
01121     getProject().setCurrentSchedule(context.currentSchedule);
01122     actionViewExpected->setChecked(context.actionViewExpected);
01123     actionViewOptimistic->setChecked(context.actionViewOptimistic);
01124     actionViewPessimistic->setChecked(context.actionViewPessimistic);
01125     
01126     m_ganttview->setContext(context.ganttview, getProject());
01127     // hmmm, can't decide if these should be here or actions moved to ganttview
01128     actionViewGanttResources->setChecked(context.ganttview.showResources);
01129     actionViewGanttTaskName->setChecked(context.ganttview.showTaskName);
01130     actionViewGanttTaskLinks->setChecked(context.ganttview.showTaskLinks);
01131     actionViewGanttProgress->setChecked(context.ganttview.showProgress);
01132     actionViewGanttFloat->setChecked(context.ganttview.showPositiveFloat);
01133     actionViewGanttCriticalTasks->setChecked(context.ganttview.showCriticalTasks);
01134     actionViewGanttCriticalPath->setChecked(context.ganttview.showCriticalPath);
01135 
01136     m_pertview->setContext(context.pertview);
01137     m_resourceview->setContext(context.resourceview);
01138     m_accountsview->setContext(context.accountsview);
01139 //    m_reportview->setContext(context.reportview);
01140     
01141     if (context.currentView == "ganttview") {
01142         m_ganttview->setShowExpected(actionViewExpected->isChecked());
01143         m_ganttview->setShowOptimistic(actionViewOptimistic->isChecked());
01144         m_ganttview->setShowPessimistic(actionViewPessimistic->isChecked());
01145         slotViewGantt();
01146     } else if (context.currentView == "pertview") {
01147         slotViewPert();
01148     } else if (context.currentView == "resourceview") {
01149         slotViewResources();
01150     } else if (context.currentView == "accountsview") {
01151         slotViewAccounts();
01152     } else if (context.currentView == "reportview") {
01153         //slotViewReport();
01154     } else {
01155         slotViewGantt();
01156     }
01157     slotUpdate(false);
01158     return true;
01159 }
01160 
01161 void View::getContext(Context &context) const {
01162     //kdDebug()<<k_funcinfo<<endl;
01163     context.currentEstimateType = m_currentEstimateType;
01164     if (getProject().currentSchedule())
01165         context.currentSchedule = getProject().currentSchedule()->id();
01166     context.actionViewExpected = actionViewExpected->isChecked();
01167     context.actionViewOptimistic = actionViewOptimistic->isChecked();
01168     context.actionViewPessimistic = actionViewPessimistic->isChecked();
01169     
01170     if (m_tab->visibleWidget() == m_ganttview) {
01171         context.currentView = "ganttview";
01172     } else if (m_tab->visibleWidget() == m_pertview) {
01173         context.currentView = "pertview";
01174     } else if (m_tab->visibleWidget() == m_resourceview) {
01175         context.currentView = "resourceview";
01176     } else if (m_tab->visibleWidget() == m_accountsview) {
01177         context.currentView = "accountsview";
01178 /*    } else if (m_tab->visibleWidget() == m_reportview) {
01179         context.currentView = "reportview";*/
01180     }
01181     m_ganttview->getContext(context.ganttview);
01182     m_pertview->getContext(context.pertview);
01183     m_resourceview->getContext(context.resourceview);
01184     m_accountsview->getContext(context.accountsview);
01185 //    m_reportview->getContext(context.reportview);
01186 }
01187 
01188 void View::setBaselineMode(bool /*on*/) {
01189     //kdDebug()<<k_funcinfo<<endl;
01190 /*    m_baselineMode = on;
01191     
01192     m_ganttview->setReadWriteMode(!on);
01193     
01194     actionCut->setEnabled(!on);
01195     actionCopy->setEnabled(!on);
01196     actionPaste->setEnabled(!on);
01197 
01198     actionDeleteTask->setEnabled(!on);
01199     actionIndentTask->setEnabled(!on);
01200     actionUnindentTask->setEnabled(!on);
01201     actionMoveTaskUp->setEnabled(!on);
01202     actionMoveTaskDown->setEnabled(!on);
01203 
01204     actionAddTask->setEnabled(!on);
01205     actionAddSubtask->setEnabled(!on);
01206     actionAddMilestone->setEnabled(!on);
01207 
01208     actionEditStandardWorktime->setEnabled(!on);
01209     actionEditCalendar->setEnabled(!on);
01210     actionEditResources->setEnabled(!on);
01211     actionCalculate->setEnabled(!on);
01212 
01213     actionEditResource->setEnabled(!on);*/
01214 }
01215 
01216 // called when widget w is about to be shown
01217 void View::setTaskActionsEnabled(QWidget *w, bool on) {
01218     Node *n = 0;
01219     if (w == m_ganttview) {
01220         n = m_ganttview->currentNode();
01221     }// else pert, etc when implemented
01222      
01223     actionAddTask->setEnabled(on);
01224     actionAddMilestone->setEnabled(on);
01225     // only enabled when we have a task selected
01226     bool o = (on && n);
01227     actionAddSubtask->setEnabled(o);
01228     actionDeleteTask->setEnabled(o);
01229     actionMoveTaskUp->setEnabled(o && getProject().canMoveTaskUp(n));
01230     actionMoveTaskDown->setEnabled(o && getProject().canMoveTaskDown(n));
01231     actionIndentTask->setEnabled(o && getProject().canIndentTask(n));
01232     actionUnindentTask->setEnabled(o && getProject().canUnindentTask(n));
01233 }
01234 
01235 void View::setTaskActionsEnabled(bool on) {
01236     setTaskActionsEnabled(m_ganttview, on); //FIXME if more than ganttview can do this
01237 }
01238 
01239 void View::setScheduleActionsEnabled() {
01240     actionViewExpected->setEnabled(getProject().findSchedule(Schedule::Expected));
01241     actionViewOptimistic->setEnabled(getProject().findSchedule(Schedule::Optimistic));
01242     actionViewPessimistic->setEnabled(getProject().findSchedule(Schedule::Pessimistic));
01243     if (getProject().notScheduled()) {
01244         m_estlabel->setText(i18n("Not scheduled"));
01245         return;
01246     }
01247     Schedule *ns = getProject().currentSchedule();
01248     if (ns->type() == Schedule::Expected) {
01249         actionViewExpected->setChecked(true);
01250         m_estlabel->setText(i18n("Expected"));
01251     } else if (ns->type() == Schedule::Optimistic) {
01252         actionViewOptimistic->setChecked(true);
01253         m_estlabel->setText(i18n("Optimistic"));
01254     } else if (ns->type() == Schedule::Pessimistic) {
01255         actionViewPessimistic->setChecked(true);
01256         m_estlabel->setText(i18n("Pessimistic"));
01257     }
01258 }
01259 
01260 
01261 #ifndef NDEBUG
01262 void View::slotPrintDebug() {
01263     kdDebug()<<"-------- Debug printout: Node list" <<endl;
01264 /*    Node *curr = m_ganttview->currentNode();
01265     if (curr) {
01266         curr->printDebug(true,"");
01267     } else*/
01268         getPart()->getProject().printDebug(true, "");
01269 }
01270 void View::slotPrintSelectedDebug() {
01271     Node *curr = m_ganttview->currentNode();
01272     if (curr) {
01273         kdDebug()<<"-------- Debug printout: Selected node" <<endl;
01274         curr->printDebug(true,"");
01275     } else
01276         slotPrintDebug();
01277 }
01278 void View::slotPrintCalendarDebug() {
01279     kdDebug()<<"-------- Debug printout: Node list" <<endl;
01280 /*    Node *curr = m_ganttview->currentNode();
01281     if (curr) {
01282         curr->printDebug(true,"");
01283     } else*/
01284         getPart()->getProject().printCalendarDebug("");
01285 }
01286 void View::slotPrintTestDebug() {
01287     const QStringList &lst = getPart()->xmlLoader().log();
01288     
01289     for ( QStringList::ConstIterator it = lst.constBegin(); it != lst.constEnd(); ++it ) {
01290         kdDebug()<<*it<<endl;
01291     }
01292 //     kdDebug()<<"------------Test 1---------------------"<<endl;
01293 //     {
01294 //     DateTime d1(QDate(2006,1,2), QTime(8,0,0));
01295 //     DateTime d2 = d1.addSecs(3600);
01296 //     Duration d = d2 - d1;
01297 //     bool b = d==Duration(0,0,0,3600);
01298 //     kdDebug()<<"1: Success="<<b<<"    "<<d2.toString()<<"-"<<d1.toString()<<"="<<d.toString()<<endl;
01299 //     d = d1 - d2;
01300 //     b = d==Duration(0,0,0,3600);
01301 //     kdDebug()<<"2: Success="<<b<<"    "<<d1.toString()<<"-"<<d2.toString()<<"="<<d.toString()<<endl;
01302 //     d2 = d2.addDays(-2);
01303 //     d = d1 - d2;
01304 //     b = d==Duration(2,0,0)-Duration(0,0,0,3600);
01305 //     kdDebug()<<"3: Success="<<b<<"    "<<d1.toString()<<"-"<<d2.toString()<<"="<<d.toString()<<endl;
01306 //     d = d2 - d1;
01307 //     b = d==Duration(2,0,0)-Duration(0,0,0,3600);
01308 //     kdDebug()<<"4: Success="<<b<<"     "<<d2.toString()<<"-"<<d1.toString()<<"="<<d.toString()<<endl;
01309 //     kdDebug()<<endl;
01310 //     b = (d2 + d)==d1;
01311 //     kdDebug()<<"5: Success="<<b<<"   "<<d2<<"+"<<d.toString()<<"="<<d1<<endl;
01312 //     b = (d1 - d)==d2;
01313 //     kdDebug()<<"6: Success="<<b<<"   "<<d1<<"-"<<d.toString()<<"="<<d2<<endl;
01314 //     } // end test 1
01315 //     kdDebug()<<endl;
01316 //     kdDebug()<<"------------Test 2 Single calendar-----------------"<<endl;
01317 //     {
01318 //     Calendar *t = new Calendar("Test 2");
01319 //     QDate wdate(2006,1,2);
01320 //     DateTime before = DateTime(wdate.addDays(-1));
01321 //     DateTime after = DateTime(wdate.addDays(1));
01322 //     QTime t1(8,0,0);
01323 //     QTime t2(10,0,0);
01324 //     DateTime wdt1(wdate, t1);
01325 //     DateTime wdt2(wdate, t2);
01326 //     CalendarDay *day = new CalendarDay(QDate(2006,1,2), Map::Working);
01327 //     day->addInterval(QPair<QTime, QTime>(t1, t2));
01328 //     if (!t->addDay(day)) {
01329 //         kdDebug()<<"Failed to add day"<<endl;
01330 //         delete day;
01331 //         delete t;
01332 //         return;
01333 //     }
01334 //     kdDebug()<<"Added     date="<<day->date().toString()<<" "<<day->startOfDay().toString()<<" - "<<day->endOfDay()<<endl;
01335 //     kdDebug()<<"Found     date="<<day->date().toString()<<" "<<day->startOfDay().toString()<<" - "<<day->endOfDay()<<endl;
01336 //     
01337 //     CalendarDay *d = t->findDay(wdate);
01338 //     bool b = (day == d);
01339 //     kdDebug()<<"1: Success="<<b<<"      Find same day"<<endl;
01340 //     
01341 //     DateTime dt = t->firstAvailableAfter(after, after.addDays(10));
01342 //     b = !dt.isValid();
01343 //     kdDebug()<<"2: Success="<<b<<"      firstAvailableAfter("<<after<<"): ="<<dt<<endl;
01344 //     
01345 //     dt = t->firstAvailableBefore(before, before.addDays(-10));
01346 //     b = !dt.isValid();
01347 //     kdDebug()<<"3: Success="<<b<<"       firstAvailableBefore("<<before.toString()<<"): ="<<dt<<endl;
01348 //     
01349 //     dt = t->firstAvailableAfter(before, after);
01350 //     b = dt == wdt1;
01351 //     kdDebug()<<"4: Success="<<b<<"      firstAvailableAfter("<<before<<"): ="<<dt<<endl;
01352 //     
01353 //     dt = t->firstAvailableBefore(after, before);
01354 //     b = dt == wdt2;
01355 //     kdDebug()<<"5: Success="<<b<<"      firstAvailableBefore("<<after<<"): ="<<dt<<endl;
01356 //     
01357 //     b = t->hasInterval(before, after);
01358 //     kdDebug()<<"6: Success="<<b<<"      hasInterval("<<before<<", "<<after<<")"<<endl;
01359 //     
01360 //     b = !t->hasInterval(after, after.addDays(1));
01361 //     kdDebug()<<"7: Success="<<b<<"      !hasInterval("<<after<<", "<<after.addDays(1)<<")"<<endl;
01362 //     
01363 //     b = !t->hasInterval(before, before.addDays(-1));
01364 //     kdDebug()<<"8: Success="<<b<<"      !hasInterval("<<before<<", "<<before.addDays(-1)<<")"<<endl;
01365 //     
01366 //     Duration e1(0, 2, 0); // 2 hours
01367 //     Duration e2 = t->effort(before, after);
01368 //     b = e1==e2;
01369 //     kdDebug()<<"9: Success="<<b<<"      effort"<<e1.toString()<<" = "<<e2.toString()<<endl;
01370 //     
01371 //     delete t;
01372 //     }// end test 2
01373 //     
01374 //     kdDebug()<<endl;
01375 //     kdDebug()<<"------------Test 3 Parent calendar-----------------"<<endl;
01376 //     {
01377 //     Calendar *t = new Calendar("Test 3");
01378 //     Calendar *p = new Calendar("Test 3 parent");
01379 //     t->setParent(p);
01380 //     QDate wdate(2006,1,2);
01381 //     DateTime before = DateTime(wdate.addDays(-1));
01382 //     DateTime after = DateTime(wdate.addDays(1));
01383 //     QTime t1(8,0,0);
01384 //     QTime t2(10,0,0);
01385 //     DateTime wdt1(wdate, t1);
01386 //     DateTime wdt2(wdate, t2);
01387 //     CalendarDay *day = new CalendarDay(QDate(2006,1,2), Map::Working);
01388 //     day->addInterval(QPair<QTime, QTime>(t1, t2));
01389 //     if (!p->addDay(day)) {
01390 //         kdDebug()<<"Failed to add day"<<endl;
01391 //         delete day;
01392 //         delete t;
01393 //         return;
01394 //     }
01395 //     kdDebug()<<"Added     date="<<day->date().toString()<<" "<<day->startOfDay().toString()<<" - "<<day->endOfDay().toString()<<endl;
01396 //     kdDebug()<<"Found     date="<<day->date().toString()<<" "<<day->startOfDay().toString()<<" - "<<day->endOfDay().toString()<<endl;
01397 //     
01398 //     CalendarDay *d = p->findDay(wdate);
01399 //     bool b = (day == d);
01400 //     kdDebug()<<"1: Success="<<b<<"      Find same day"<<endl;
01401 //     
01402 //     DateTime dt = t->firstAvailableAfter(after, after.addDays(10));
01403 //     b = !dt.isValid();
01404 //     kdDebug()<<"2: Success="<<b<<"      firstAvailableAfter("<<after.toString()<<"): ="<<!b<<endl;
01405 //     
01406 //     dt = t->firstAvailableBefore(before, before.addDays(-10));
01407 //     b = !dt.isValid();
01408 //     kdDebug()<<"3: Success="<<b<<"       firstAvailableBefore("<<before.toString()<<"): ="<<!b<<endl;
01409 //     
01410 //     dt = t->firstAvailableAfter(before, after);
01411 //     b = dt == wdt1;
01412 //     kdDebug()<<"4: Success="<<b<<"      firstAvailableAfter("<<before.toString()<<"): ="<<dt.toString()<<endl;
01413 //     
01414 //     dt = t->firstAvailableBefore(after, before);
01415 //     b = dt == wdt2;
01416 //     kdDebug()<<"5: Success="<<b<<"      firstAvailableBefore("<<after.toString()<<"): ="<<dt.toString()<<endl;
01417 //     
01418 //     b = t->hasInterval(before, after);
01419 //     kdDebug()<<"6: Success="<<b<<"      hasInterval("<<before.toString()<<", "<<after<<")"<<endl;
01420 //     
01421 //     b = !t->hasInterval(after, after.addDays(1));
01422 //     kdDebug()<<"7: Success="<<b<<"      !hasInterval("<<after.toString()<<", "<<after.addDays(1)<<")"<<endl;
01423 //     
01424 //     b = !t->hasInterval(before, before.addDays(-1));
01425 //     kdDebug()<<"8: Success="<<b<<"      !hasInterval("<<before.toString()<<", "<<before.addDays(-1)<<")"<<endl;
01426 //     Duration e1(0, 2, 0); // 2 hours
01427 //     Duration e2 = t->effort(before, after);
01428 //     b = e1==e2;
01429 //     kdDebug()<<"9: Success="<<b<<"      effort "<<e1.toString()<<"=="<<e2.toString()<<endl;
01430 //     
01431 //     delete t;
01432 //     delete p;
01433 //     }// end test 3
01434 //     kdDebug()<<endl;
01435 //     kdDebug()<<"------------Test 4 Parent calendar/weekdays-------------"<<endl;
01436 //     {
01437 //     QTime t1(8,0,0);
01438 //     QTime t2(10,0,0);
01439 //     Calendar *p = new Calendar("Test 4 parent");
01440 //     CalendarDay *wd1 = p->weekday(0); // monday
01441 //     if (wd1 == 0) {
01442 //         kdDebug()<<"Failed to get weekday"<<endl;
01443 //     }
01444 //     wd1->setState(Map::NonWorking);
01445 //     
01446 //     CalendarDay *wd2 = p->weekday(2); // wednesday
01447 //     if (wd2 == 0) {
01448 //         kdDebug()<<"Failed to get weekday"<<endl;
01449 //     }
01450 //     wd2->addInterval(QPair<QTime, QTime>(t1, t2));
01451 //     wd2->setState(Map::Working);
01452 //      
01453 //     Calendar *t = new Calendar("Test 4");
01454 //     t->setParent(p);
01455 //     QDate wdate(2006,1,2); // monday jan 2
01456 //     DateTime before = DateTime(wdate.addDays(-4)); //Thursday dec 29
01457 //     DateTime after = DateTime(wdate.addDays(4)); // Friday jan 6
01458 //     DateTime wdt1(wdate, t1);
01459 //     DateTime wdt2(QDate(2006, 1, 4), t2); // Wednesday
01460 //     CalendarDay *day = new CalendarDay(QDate(2006,1,2), Map::Working);
01461 //     day->addInterval(QPair<QTime, QTime>(t1, t2));
01462 //     if (!p->addDay(day)) {
01463 //         kdDebug()<<"Failed to add day"<<endl;
01464 //         delete day;
01465 //         delete t;
01466 //         return;
01467 //     }
01468 //     kdDebug()<<"Added     date="<<day->date().toString()<<" "<<day->startOfDay().toString()<<" - "<<day->endOfDay().toString()<<endl;
01469 //     kdDebug()<<"Found     date="<<day->date().toString()<<" "<<day->startOfDay().toString()<<" - "<<day->endOfDay().toString()<<endl;
01470 //     
01471 //     CalendarDay *d = p->findDay(wdate);
01472 //     bool b = (day == d);
01473 //     kdDebug()<<"1: Success="<<b<<"      Find same day"<<endl;
01474 //     
01475 //     DateTime dt = t->firstAvailableAfter(after, after.addDays(10));
01476 //     b = (dt.isValid() && dt == DateTime(QDate(2006,1,11), t1));
01477 //     kdDebug()<<"2: Success="<<b<<"      firstAvailableAfter("<<after<<"): ="<<dt<<endl;
01478 //     
01479 //     dt = t->firstAvailableBefore(before, before.addDays(-10));
01480 //     b = (dt.isValid() && dt == DateTime(QDate(2005, 12, 28), t2));
01481 //     kdDebug()<<"3: Success="<<b<<"       firstAvailableBefore("<<before.toString()<<"): ="<<dt<<endl;
01482 //     
01483 //     dt = t->firstAvailableAfter(before, after);
01484 //     b = dt == wdt1; // We find the day jan 2
01485 //     kdDebug()<<"4: Success="<<b<<"      firstAvailableAfter("<<before.toString()<<"): ="<<dt.toString()<<endl;
01486 //     
01487 //     dt = t->firstAvailableBefore(after, before);
01488 //     b = dt == wdt2; // We find the weekday (wednesday)
01489 //     kdDebug()<<"5: Success="<<b<<"      firstAvailableBefore("<<after.toString()<<"): ="<<dt.toString()<<endl;
01490 //     
01491 //     b = t->hasInterval(before, after);
01492 //     kdDebug()<<"6: Success="<<b<<"      hasInterval("<<before.toString()<<", "<<after<<")"<<endl;
01493 //     
01494 //     b = !t->hasInterval(after, after.addDays(1));
01495 //     kdDebug()<<"7: Success="<<b<<"      !hasInterval("<<after.toString()<<", "<<after.addDays(1)<<")"<<endl;
01496 //     
01497 //     b = !t->hasInterval(before, before.addDays(-1));
01498 //     kdDebug()<<"8: Success="<<b<<"      !hasInterval("<<before.toString()<<", "<<before.addDays(-1)<<")"<<endl;
01499 //     Duration e1(0, 4, 0); // 2 hours
01500 //     Duration e2 = t->effort(before, after);
01501 //     b = e1==e2;
01502 //     kdDebug()<<"9: Success="<<b<<"      effort "<<e1.toString()<<"="<<e2.toString()<<endl;
01503 //     
01504 //     QPair<DateTime, DateTime> r = t->firstInterval(before, after);
01505 //     b = r.first == wdt1; // We find the monday jan 2
01506 //     kdDebug()<<"10: Success="<<b<<"      firstInterval("<<before<<"): ="<<r.first<<", "<<r.second<<endl;
01507 //     r = t->firstInterval(r.second, after);
01508 //     b = r.first == DateTime(QDate(2006, 1, 4),t1); // We find the wednesday jan 4
01509 //     kdDebug()<<"11: Success="<<b<<"      firstInterval("<<r.second<<"): ="<<r.first<<", "<<r.second<<endl;
01510 //     
01511 //     delete t;
01512 //     delete p;
01513 //     }// end test 4
01514 }
01515 #endif
01516 
01517 }  //KPlato namespace
01518 
01519 #include "kptview.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys