kplato

kptview.cpp
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999, 2000 Torben Weis <weis@kde.org>
3 Copyright (C) 2002 - 2005 Dag Andersen <danders@get2net.dk>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include <kprinter.h>
22#include <tdemessagebox.h>
23
24#include <KoMainWindow.h>
25
26#include <tqapplication.h>
27#include <tqpainter.h>
28#include <tqiconset.h>
29#include <tqlayout.h>
30#include <tqsplitter.h>
31#include <tqcanvas.h>
32#include <tqscrollview.h>
33#include <tqcolor.h>
34#include <tqlabel.h>
35#include <tqstring.h>
36#include <tqstringlist.h>
37#include <tqvbox.h>
38#include <tqgrid.h>
39#include <tqsize.h>
40#include <tqheader.h>
41#include <tqtabwidget.h>
42#include <tqwidgetstack.h>
43#include <tqtimer.h>
44#include <tqpopupmenu.h>
45#include <tqpair.h>
46
47#include <kiconloader.h>
48#include <tdeaction.h>
49#include <kstdaction.h>
50#include <tdelocale.h>
51#include <kdebug.h>
52#include <tdelistview.h>
53#include <tdestdaccel.h>
54#include <tdeaccelgen.h>
55#include <tdeversion.h>
56#include <kstatusbar.h>
57#include <kxmlguifactory.h>
58
59#include <kstandarddirs.h>
60#include <kdesktopfile.h>
61#include <kcommand.h>
62#include <tdefiledialog.h>
63
64#include "kptview.h"
65#include "kptaccountsview.h"
66#include "kptfactory.h"
67#include "kptmilestoneprogressdialog.h"
68#include "kptnode.h"
69#include "kptpart.h"
70#include "kptproject.h"
71#include "kptmainprojectdialog.h"
72#include "kptprojectdialog.h"
73#include "kpttask.h"
74#include "kptsummarytaskdialog.h"
75#include "kpttaskdialog.h"
76#include "kpttaskprogressdialog.h"
77#include "kptganttview.h"
78#include "kptpertview.h"
79//#include "kptreportview.h"
80#include "kptdatetime.h"
81#include "kptcommand.h"
82#include "kptrelation.h"
83#include "kptrelationdialog.h"
84#include "kptresourceview.h"
85#include "kptresourcedialog.h"
86#include "kptresource.h"
87#include "kptresourcesdialog.h"
88#include "kptcalendarlistdialog.h"
89#include "kptstandardworktimedialog.h"
90#include "kptcanvasitem.h"
91#include "kptconfigdialog.h"
92#include "kptwbsdefinitiondialog.h"
93#include "kptaccountsdialog.h"
94
95#include "KDGanttView.h"
96#include "KDGanttViewTaskItem.h"
97#include "KPtViewIface.h"
98
99namespace KPlato
100{
101
102View::View(Part* part, TQWidget* parent, const char* /*name*/)
103 : KoView(part, parent, "Main View"),
104 m_ganttview(0),
105 m_ganttlayout(0),
106 m_pertview(0),
107 m_pertlayout(0),
108// m_reportview(0),
109 m_baselineMode(false),
110 m_currentEstimateType(Effort::Use_Expected)
111{
112 //kdDebug()<<k_funcinfo<<endl;
113 getProject().setCurrentSchedule(Schedule::Expected);
114
115 setInstance(Factory::global());
116 if ( !part->isReadWrite() )
117 setXMLFile("kplato_readonly.rc");
118 else
119 setXMLFile("kplato.rc");
120 m_dcop = 0L;
121 // build the DCOP object
122 dcopObject();
123
124 m_tab = new TQWidgetStack(this);
125 TQVBoxLayout *layout = new TQVBoxLayout(this);
126 layout->add(m_tab);
127
128 m_ganttview = new GanttView(m_tab, part->isReadWrite());
129 m_tab->addWidget(m_ganttview);
130 m_updateGanttview = false;
131 m_ganttview->draw(getPart()->getProject());
132
133 m_pertview = new PertView( this, m_tab, layout );
134 m_tab->addWidget(m_pertview);
135
136 m_resourceview = new ResourceView( this, m_tab );
137 m_updateResourceview = true;
138 m_tab->addWidget(m_resourceview);
139
140 m_accountsview = new AccountsView( getProject(), this, m_tab );
141 m_updateAccountsview = true;
142 m_tab->addWidget(m_accountsview);
143
144 //m_reportview = new ReportView(this, m_tab);
145 //m_tab->addWidget(m_reportview);
146
147 connect(m_tab, TQ_SIGNAL(aboutToShow(TQWidget *)), this, TQ_SLOT(slotAboutToShow(TQWidget *)));
148
149 connect(m_pertview, TQ_SIGNAL(addRelation(Node*, Node*)), TQ_SLOT(slotAddRelation(Node*, Node*)));
150 connect(m_pertview, TQ_SIGNAL(modifyRelation(Relation*)), TQ_SLOT(slotModifyRelation(Relation*)));
151
152 connect(m_ganttview, TQ_SIGNAL(enableActions(bool)), TQ_SLOT(setTaskActionsEnabled(bool)));
153 connect(m_ganttview, TQ_SIGNAL(addRelation(Node*, Node*, int)), TQ_SLOT(slotAddRelation(Node*, Node*, int)));
154 connect(m_ganttview, TQ_SIGNAL(modifyRelation(Relation*, int)), TQ_SLOT(slotModifyRelation(Relation*, int)));
155 connect(m_ganttview, TQ_SIGNAL(modifyRelation(Relation*)), TQ_SLOT(slotModifyRelation(Relation*)));
156 connect(m_ganttview, TQ_SIGNAL(itemDoubleClicked()), TQ_SLOT(slotOpenNode()));
157 connect(m_ganttview, TQ_SIGNAL(itemRenamed(Node*, const TQString&)),this, TQ_SLOT(slotRenameNode(Node*, const TQString&)));
158 connect(m_ganttview, TQ_SIGNAL(requestPopupMenu(const TQString&, const TQPoint &)),this, TQ_SLOT(slotPopupMenu(const TQString&, const TQPoint&)));
159 connect(m_resourceview, TQ_SIGNAL(itemDoubleClicked()), TQ_SLOT(slotEditResource()));
160
161 // The menu items
162 // ------ Edit
163 actionCut = KStdAction::cut( this, TQ_SLOT( slotEditCut() ), actionCollection(), "edit_cut" );
164 actionCopy = KStdAction::copy( this, TQ_SLOT( slotEditCopy() ), actionCollection(), "edit_copy" );
165 actionPaste = KStdAction::paste( this, TQ_SLOT( slotEditPaste() ), actionCollection(), "edit_paste" );
166
167 actionIndentTask = new TDEAction(i18n("Indent Task"), "indent_task", 0, this,
168 TQ_SLOT(slotIndentTask()), actionCollection(), "indent_task");
169 actionUnindentTask = new TDEAction(i18n("Unindent Task"), "unindent_task", 0, this,
170 TQ_SLOT(slotUnindentTask()), actionCollection(), "unindent_task");
171 actionMoveTaskUp = new TDEAction(i18n("Move Up"), "move_task_up", 0, this,
172 TQ_SLOT(slotMoveTaskUp()), actionCollection(), "move_task_up");
173 actionMoveTaskDown = new TDEAction(i18n("Move Down"), "move_task_down", 0, this,
174 TQ_SLOT(slotMoveTaskDown()), actionCollection(), "move_task_down");
175
176 // ------ View
177 actionViewGantt = new TDEAction(i18n("Gantt"), "gantt_chart", 0, this, TQ_SLOT(slotViewGantt()), actionCollection(), "view_gantt");
178
179 TQString group = "EstimationType";
180 actionViewExpected = new TDERadioAction(i18n("Expected"), 0, 0, this, TQ_SLOT(slotViewExpected()), actionCollection(), "view_expected");
181 actionViewExpected->setExclusiveGroup(group);
182 actionViewOptimistic = new TDERadioAction(i18n("Optimistic"), 0, 0, this, TQ_SLOT(slotViewOptimistic()), actionCollection(), "view_optimistic");
183 actionViewOptimistic->setExclusiveGroup(group);
184 actionViewPessimistic = new TDERadioAction(i18n("Pessimistic"), 0, 0, this, TQ_SLOT(slotViewPessimistic()), actionCollection(), "view_pessimistic");
185 actionViewPessimistic->setExclusiveGroup(group);
186
187 actionViewGanttResources = new TDEToggleAction(i18n("Resources"), 0, 0, this, TQ_SLOT(slotViewGanttResources()), actionCollection(), "view_gantt_showResources");
188 actionViewGanttTaskName = new TDEToggleAction(i18n("Task Name"), 0, 0, this, TQ_SLOT(slotViewGanttTaskName()), actionCollection(), "view_gantt_showTaskName");
189 actionViewGanttTaskLinks = new TDEToggleAction(i18n("Task Links"), 0, 0, this, TQ_SLOT(slotViewGanttTaskLinks()), actionCollection(), "view_gantt_showTaskLinks");
190 actionViewGanttProgress = new TDEToggleAction(i18n("Progress"), 0, 0, this, TQ_SLOT(slotViewGanttProgress()), actionCollection(), "view_gantt_showProgress");
191 actionViewGanttFloat = new TDEToggleAction(i18n("Float"), 0, 0, this, TQ_SLOT(slotViewGanttFloat()), actionCollection(), "view_gantt_showFloat");
192 actionViewGanttCriticalTasks = new TDEToggleAction(i18n("Critical Tasks"), 0, 0, this, TQ_SLOT(slotViewGanttCriticalTasks()), actionCollection(), "view_gantt_showCriticalTasks");
193 actionViewGanttCriticalPath = new TDEToggleAction(i18n("Critical Path"), 0, 0, this, TQ_SLOT(slotViewGanttCriticalPath()), actionCollection(), "view_gantt_showCriticalPath");
194
195// actionViewGanttNotScheduled = new TDEToggleAction(i18n("Not Scheduled"), 0, 0, this, TQ_SLOT(slotViewGanttNotScheduled()), actionCollection(), "view_gantt_showNotScheduled");
196
197 actionViewTaskAppointments = new TDEToggleAction(i18n("Show Allocations"), 0, 0, this, TQ_SLOT(slotViewTaskAppointments()), actionCollection(), "view_task_appointments");
198
199 actionViewPert = new TDEAction(i18n("Network"), "pert_chart", 0, this, TQ_SLOT(slotViewPert()), actionCollection(), "view_pert");
200
201 actionViewResources = new TDEAction(i18n("Resources"), "resources", 0, this, TQ_SLOT(slotViewResources()), actionCollection(), "view_resources");
202
203 actionViewResourceAppointments = new TDEToggleAction(i18n("Show Allocations"), 0, 0, this, TQ_SLOT(slotViewResourceAppointments()), actionCollection(), "view_resource_appointments");
204
205 actionViewAccounts = new TDEAction(i18n("Accounts"), "accounts", 0, this, TQ_SLOT(slotViewAccounts()), actionCollection(), "view_accounts");
206
207 //actionViewReports = new TDEAction(i18n("Reports"), "reports", 0, this, TQ_SLOT(slotViewReports()), actionCollection(), "view_reports");
208
209 // ------ Insert
210 actionAddTask = new TDEAction(i18n("Task..."), "add_task", 0, this,
211 TQ_SLOT(slotAddTask()), actionCollection(), "add_task");
212 actionAddSubtask = new TDEAction(i18n("Sub-Task..."), "add_sub_task", 0, this,
213 TQ_SLOT(slotAddSubTask()), actionCollection(), "add_sub_task");
214 actionAddMilestone = new TDEAction(i18n("Milestone..."), "add_milestone", 0, this,
215 TQ_SLOT(slotAddMilestone()), actionCollection(), "add_milestone");
216
217 // ------ Project
218 actionEditMainProject = new TDEAction(i18n("Edit Main Project..."), "edit", 0, this, TQ_SLOT(slotProjectEdit()), actionCollection(), "project_edit");
219 actionEditStandardWorktime = new TDEAction(i18n("Edit Standard Worktime..."), "edit", 0, this, TQ_SLOT(slotProjectWorktime()), actionCollection(), "project_worktime");
220 actionEditCalendar = new TDEAction(i18n("Edit Calendar..."), "edit", 0, this, TQ_SLOT(slotProjectCalendar()), actionCollection(), "project_calendar");
221 actionEditAccounts = new TDEAction(i18n("Edit Accounts..."), "edit", 0, this, TQ_SLOT(slotProjectAccounts()), actionCollection(), "project_accounts");
222 actionEditResources = new TDEAction(i18n("Edit Resources..."), "edit", 0, this, TQ_SLOT(slotProjectResources()), actionCollection(), "project_resources");
223
224 actionCalculate = new TDEActionMenu(i18n("Calculate"), "project_calculate", actionCollection(), "project_calculate");
225 connect(actionCalculate, TQ_SIGNAL(activated()), TQ_SLOT(slotProjectCalculate()));
226
227 actionCalculateExpected = new TDEAction(i18n("Expected"), 0, 0, this, TQ_SLOT(slotProjectCalculateExpected()), actionCollection(), "project_calculate_expected");
228 actionCalculate->insert(actionCalculateExpected);
229
230 actionCalculateOptimistic = new TDEAction(i18n("Optimistic"), 0, 0, this, TQ_SLOT(slotProjectCalculateOptimistic()), actionCollection(), "project_calculate_optimistic");
231 actionCalculate->insert(actionCalculateOptimistic);
232
233 actionCalculatePessimistic = new TDEAction(i18n("Pessimistic"), 0, 0, this, TQ_SLOT(slotProjectCalculatePessimistic()), actionCollection(), "project_calculate_pessimistic");
234 actionCalculate->insert(actionCalculatePessimistic);
235
236/* // ------ Reports
237 actionFirstpage = KStdAction::firstPage(m_reportview,TQ_SLOT(slotPrevPage()),actionCollection(),"go_firstpage");
238 connect(m_reportview, TQ_SIGNAL(setFirstPageActionEnabled(bool)), actionFirstpage, TQ_SLOT(setEnabled(bool)));
239 actionPriorpage = KStdAction::prior(m_reportview,TQ_SLOT(slotPrevPage()),actionCollection(),"go_prevpage");
240 connect(m_reportview, TQ_SIGNAL(setPriorPageActionEnabled(bool)), actionPriorpage, TQ_SLOT(setEnabled(bool)));
241 actionNextpage = KStdAction::next(m_reportview,TQ_SLOT(slotNextPage()),actionCollection(), "go_nextpage");
242 connect(m_reportview, TQ_SIGNAL(setNextPageActionEnabled(bool)), actionNextpage, TQ_SLOT(setEnabled(bool)));
243 actionLastpage = KStdAction::lastPage(m_reportview,TQ_SLOT(slotLastPage()),actionCollection(), "go_lastpage");
244 connect(m_reportview, TQ_SIGNAL(setLastPageActionEnabled(bool)), actionLastpage, TQ_SLOT(setEnabled(bool)));
245 m_reportview->enableNavigationBtn();*/
246 mainWindow()->toolBar("report")->hide();
247
248// new TDEAction(i18n("Design..."), "report_design", 0, this,
249// TQ_SLOT(slotReportDesign()), actionCollection(), "report_design");
250
251
252 // ------ Tools
253 actionDefineWBS =
254 new TDEAction(i18n("Define WBS Pattern..."), "tools_define_wbs", 0, this,
255 TQ_SLOT(slotDefineWBS()), actionCollection(), "tools_generate_wbs");
256 actionGenerateWBS =
257 new TDEAction(i18n("Generate WBS Code"), "tools_generate_wbs", 0, this,
258 TQ_SLOT(slotGenerateWBS()), actionCollection(), "tools_define_wbs");
259
260 // ------ Export (testing)
261 //actionExportGantt = new TDEAction(i18n("Export Ganttview"), "export_gantt", 0, this,
262 // TQ_SLOT(slotExportGantt()), actionCollection(), "export_gantt");
263
264 // ------ Settings
265 actionConfigure = new TDEAction(i18n("Configure KPlato..."), "configure", 0, this,
266 TQ_SLOT(slotConfigure()), actionCollection(), "configure");
267
268 // ------ Popup
269 actionOpenNode = new TDEAction(i18n("Edit..."), "edit", 0, this,
270 TQ_SLOT(slotOpenNode()), actionCollection(), "node_properties");
271 actionTaskProgress = new TDEAction(i18n("Progress..."), "edit", 0, this,
272 TQ_SLOT(slotTaskProgress()), actionCollection(), "task_progress");
273 actionDeleteTask = new TDEAction(i18n("Delete Task"), "edit-delete", 0, this,
274 TQ_SLOT(slotDeleteTask()), actionCollection(), "delete_task");
275
276 actionEditResource = new TDEAction(i18n("Edit Resource..."), "edit", 0, this,
277 TQ_SLOT(slotEditResource()), actionCollection(), "edit_resource");
278
279 // ------------------- Actions with a key binding and no GUI item
280 // Temporary, till we get a menu entry
281 actNoInformation = new TDEAction("Toggle no information", CTRL+SHIFT+Key_T, this, TQ_SLOT(slotViewGanttNoInformation()), actionCollection(), "show_noinformation");
282
283#ifndef NDEBUG
284 //new TDEAction("Print Debug", CTRL+SHIFT+Key_P, this, TQ_SLOT( slotPrintDebug()), actionCollection(), "print_debug");
285 new TDEAction("Print Debug", CTRL+SHIFT+Key_P, this, TQ_SLOT(slotPrintSelectedDebug()), actionCollection(), "print_debug");
286 new TDEAction("Print Calendar Debug", CTRL+SHIFT+Key_C, this, TQ_SLOT(slotPrintCalendarDebug()), actionCollection(), "print_calendar_debug");
287// new TDEAction("Print Test Debug", CTRL+SHIFT+Key_T, this, TQ_SLOT(slotPrintTestDebug()), actionCollection(), "print_test_debug");
288
289 TDEAction* actExportGantt = new TDEAction( i18n( "Export Gantt" ), CTRL+SHIFT+Key_G,
290 this, TQ_SLOT( slotExportGantt() ), actionCollection(), "export_gantt" );
291
292#endif
293 // Stupid compilers ;)
294#ifndef NDEBUG
295/* Q_UNUSED( actPrintSelectedDebug );
296 Q_UNUSED( actPrintCalendarDebug );*/
297 Q_UNUSED( actExportGantt );
298#endif
299
300 m_estlabel = new KStatusBarLabel("", 0);
301 addStatusBarItem(m_estlabel, 0, true);
302 actionViewExpected->setChecked(true); //TODO: context
303 setScheduleActionsEnabled();
304 slotViewExpected();
305
306 setTaskActionsEnabled(false);
307}
308
309View::~View()
310{
311 delete m_dcop;
312 removeStatusBarItem(m_estlabel);
313 delete m_estlabel;
314}
315
316DCOPObject * View::dcopObject()
317{
318 if ( !m_dcop )
319 m_dcop = new ViewIface( this );
320
321 return m_dcop;
322}
323
324
325Project& View::getProject() const
326{
327 return getPart()->getProject();
328}
329
330void View::setZoom(double zoom) {
331 m_ganttview->setZoom(zoom);
332 m_pertview->setZoom(zoom);
333}
334
335void View::setupPrinter(KPrinter &/*printer*/) {
336 //kdDebug()<<k_funcinfo<<endl;
337}
338
339void View::print(KPrinter &printer) {
340 //kdDebug()<<k_funcinfo<<endl;
341 if (printer.previewOnly()) {
342 //HACK: KoMainWindow shows setup on print, but not on print preview!
343 if (!printer.setup()) {
344 return;
345 }
346 }
347 if (m_tab->visibleWidget() == m_ganttview)
348 {
349 m_ganttview->print(printer);
350 }
351 else if (m_tab->visibleWidget() == m_pertview)
352 {
353 m_pertview->print(printer);
354 }
355 else if (m_tab->visibleWidget() == m_resourceview)
356 {
357 m_resourceview->print(printer);
358 }
359 else if (m_tab->visibleWidget() == m_accountsview)
360 {
361 m_accountsview->print(printer);
362 }
363// else if (m_tab->visibleWidget() == m_reportview)
364// {
365// m_reportview->print(printer);
366// }
367
368}
369
370void View::slotEditCut() {
371 //kdDebug()<<k_funcinfo<<endl;
372}
373
374void View::slotEditCopy() {
375 //kdDebug()<<k_funcinfo<<endl;
376}
377
378void View::slotEditPaste() {
379 //kdDebug()<<k_funcinfo<<endl;
380}
381
382void View::slotViewExpected() {
383 //kdDebug()<<k_funcinfo<<endl;
384 m_currentEstimateType = Effort::Use_Expected;
385 getProject().setCurrentSchedulePtr(getProject().findSchedule(Schedule::Expected));
386 slotUpdate(false);
387}
388
389void View::slotViewOptimistic() {
390 //kdDebug()<<k_funcinfo<<endl;
391 m_currentEstimateType = Effort::Use_Optimistic;
392 getProject().setCurrentSchedulePtr(getProject().findSchedule(Schedule::Optimistic));
393 slotUpdate(false);
394}
395
396void View::slotViewPessimistic() {
397 //kdDebug()<<k_funcinfo<<endl;
398 m_currentEstimateType = Effort::Use_Pessimistic;
399 getProject().setCurrentSchedulePtr(getProject().findSchedule(Schedule::Pessimistic));
400 slotUpdate(false);
401}
402
403void View::slotViewGanttResources() {
404 //kdDebug()<<k_funcinfo<<endl;
405 m_ganttview->setShowResources(actionViewGanttResources->isChecked());
406 if (m_tab->visibleWidget() == m_ganttview)
407 slotUpdate(false);
408}
409
410void View::slotViewGanttTaskName() {
411 //kdDebug()<<k_funcinfo<<endl;
412 m_ganttview->setShowTaskName(actionViewGanttTaskName->isChecked());
413 if (m_tab->visibleWidget() == m_ganttview)
414 slotUpdate(false);
415}
416
417void View::slotViewGanttTaskLinks() {
418 //kdDebug()<<k_funcinfo<<endl;
419 m_ganttview->setShowTaskLinks(actionViewGanttTaskLinks->isChecked());
420 if (m_tab->visibleWidget() == m_ganttview)
421 slotUpdate(false);
422}
423
424void View::slotViewGanttProgress() {
425 //kdDebug()<<k_funcinfo<<endl;
426 m_ganttview->setShowProgress(actionViewGanttProgress->isChecked());
427 if (m_tab->visibleWidget() == m_ganttview)
428 slotUpdate(false);
429}
430
431void View::slotViewGanttFloat() {
432 //kdDebug()<<k_funcinfo<<endl;
433 m_ganttview->setShowPositiveFloat(actionViewGanttFloat->isChecked());
434 if (m_tab->visibleWidget() == m_ganttview)
435 slotUpdate(false);
436}
437
438void View::slotViewGanttCriticalTasks() {
439 //kdDebug()<<k_funcinfo<<endl;
440 m_ganttview->setShowCriticalTasks(actionViewGanttCriticalTasks->isChecked());
441 if (m_tab->visibleWidget() == m_ganttview)
442 slotUpdate(false);
443}
444
445void View::slotViewGanttCriticalPath() {
446 //kdDebug()<<k_funcinfo<<endl;
447 m_ganttview->setShowCriticalPath(actionViewGanttCriticalPath->isChecked());
448 if (m_tab->visibleWidget() == m_ganttview)
449 slotUpdate(false);
450}
451
452void View::slotViewGanttNoInformation() {
453 kdDebug()<<k_funcinfo<<m_ganttview->showNoInformation()<<endl;
454 m_ganttview->setShowNoInformation(!m_ganttview->showNoInformation()); //Toggle
455 if (m_tab->visibleWidget() == m_ganttview)
456 slotUpdate(false);
457}
458
459void View::slotViewTaskAppointments() {
460 //kdDebug()<<k_funcinfo<<endl;
461 m_ganttview->setShowAppointments(actionViewTaskAppointments->isChecked());
462 m_updateGanttview = true;
463 if (m_tab->visibleWidget() == m_ganttview)
464 slotUpdate(false);
465}
466
467void View::slotViewGantt() {
468 //kdDebug()<<k_funcinfo<<endl;
469 m_tab->raiseWidget(m_ganttview);
470}
471
472void View::slotViewPert() {
473 //kdDebug()<<k_funcinfo<<endl;
474 m_tab->raiseWidget(m_pertview);
475}
476
477void View::slotViewResources() {
478 //kdDebug()<<k_funcinfo<<endl;
479 m_tab->raiseWidget(m_resourceview);
480}
481
482void View::slotViewResourceAppointments() {
483 //kdDebug()<<k_funcinfo<<endl;
484 m_resourceview->setShowAppointments(actionViewResourceAppointments->isChecked());
485 m_updateResourceview = true;
486 if (m_tab->visibleWidget() == m_resourceview)
487 slotUpdate(false);
488}
489
490void View::slotViewAccounts() {
491 //kdDebug()<<k_funcinfo<<endl;
492 m_tab->raiseWidget(m_accountsview);
493}
494
495void View::slotProjectEdit() {
496 MainProjectDialog *dia = new MainProjectDialog(getProject());
497 if (dia->exec()) {
498 KCommand *cmd = dia->buildCommand(getPart());
499 if (cmd) {
500 getPart()->addCommand(cmd);
501 }
502 }
503 delete dia;
504}
505
506void View::slotProjectCalendar() {
507 CalendarListDialog *dia = new CalendarListDialog(getProject());
508 if (dia->exec()) {
509 KCommand *cmd = dia->buildCommand(getPart());
510 if (cmd) {
511 //kdDebug()<<k_funcinfo<<"Modifying calendar(s)"<<endl;
512 getPart()->addCommand(cmd); //also executes
513 }
514 }
515 delete dia;
516}
517
518void View::slotProjectAccounts() {
519 AccountsDialog *dia = new AccountsDialog(getProject().accounts());
520 if (dia->exec()) {
521 KCommand *cmd = dia->buildCommand(getPart());
522 if (cmd) {
523 //kdDebug()<<k_funcinfo<<"Modifying account(s)"<<endl;
524 getPart()->addCommand(cmd); //also executes
525 }
526 }
527 delete dia;
528}
529
530void View::slotProjectWorktime() {
531 StandardWorktimeDialog *dia = new StandardWorktimeDialog(getProject());
532 if (dia->exec()) {
533 KCommand *cmd = dia->buildCommand(getPart());
534 if (cmd) {
535 //kdDebug()<<k_funcinfo<<"Modifying calendar(s)"<<endl;
536 getPart()->addCommand(cmd); //also executes
537 }
538 }
539 delete dia;
540}
541
542void View::slotProjectResources() {
543 ResourcesDialog *dia = new ResourcesDialog(getProject());
544 if (dia->exec()) {
545 KCommand *cmd = dia->buildCommand(getPart());
546 if (cmd) {
547 //kdDebug()<<k_funcinfo<<"Modifying resources"<<endl;
548 getPart()->addCommand(cmd); //also executes
549 }
550 }
551 delete dia;
552}
553
554void View::slotProjectCalculate() {
555 //kdDebug()<<k_funcinfo<<endl;
556 slotUpdate(true);
557}
558
559void View::slotProjectCalculateExpected() {
560 m_currentEstimateType = Effort::Use_Expected;
561 m_updateGanttview = true;
562 m_updateResourceview = true;
563 m_updateAccountsview = true;
564 slotUpdate(true);
565}
566
567void View::slotProjectCalculateOptimistic() {
568 m_currentEstimateType = Effort::Use_Optimistic;
569 m_updateGanttview = true;
570 m_updateResourceview = true;
571 m_updateAccountsview = true;
572 slotUpdate(true);
573}
574
575void View::slotProjectCalculatePessimistic() {
576 m_currentEstimateType = Effort::Use_Pessimistic;
577 m_updateGanttview = true;
578 m_updateResourceview = true;
579 m_updateAccountsview = true;
580 slotUpdate(true);
581}
582
583void View::projectCalculate() {
584 if (false /*getProject().actualEffort() > 0*/) {
585 // NOTE: This can be removed when proper baselining etc is implemented
586 if (KMessageBox::warningContinueCancel(this, i18n("Progress information will be deleted if the project is recalculated."), i18n("Calculate"), i18n("Calculate")) == KMessageBox::Cancel) {
587 return;
588 }
589 }
590 TQApplication::setOverrideCursor(TQt::waitCursor);
591 Schedule *ns = getProject().findSchedule((Schedule::Type)m_currentEstimateType);
592 KCommand *cmd;
593 if (ns) {
594 cmd = new RecalculateProjectCmd(getPart(), getProject(), *ns, i18n("Calculate"));
595 } else {
596 cmd = new CalculateProjectCmd(getPart(), getProject(), i18n("Standard"), (Effort::Use)m_currentEstimateType, i18n("Calculate"));
597 }
598 getPart()->addCommand(cmd);
599 TQApplication::restoreOverrideCursor();
600}
601
602void View::slotViewReportDesign() {
603 //kdDebug()<<k_funcinfo<<endl;
604}
605
606void View::slotViewReports() {
607 //kdDebug()<<k_funcinfo<<endl;
608 //m_tab->raiseWidget(m_reportview);
609}
610
611void View::slotAddSubTask() {
612 // If we are positionend on the root project, then what we really want to
613 // do is to add a first project. We will silently accept the challenge
614 // and will not complain.
615 Task* node = getProject().createTask(getPart()->config().taskDefaults(), currentTask());
616 TaskDialog *dia = new TaskDialog(*node, getProject().accounts(), getProject().standardWorktime(), getProject().isBaselined());
617 if (dia->exec()) {
618 Node *currNode = currentTask();
619 if (currNode)
620 {
621 KCommand *m = dia->buildCommand(getPart());
622 m->execute(); // do changes to task
623 delete m;
624 SubtaskAddCmd *cmd = new SubtaskAddCmd(getPart(), &(getProject()), node, currNode, i18n("Add Subtask"));
625 getPart()->addCommand(cmd); // add task to project
626 return;
627 }
628 else
629 kdDebug()<<k_funcinfo<<"Cannot insert new project. Hmm, no current node!?"<<endl;
630 }
631 delete node;
632 delete dia;
633}
634
635
636void View::slotAddTask() {
637 Task* node = getProject().createTask(getPart()->config().taskDefaults(), currentTask());
638 TaskDialog *dia = new TaskDialog(*node, getProject().accounts(), getProject().standardWorktime(), getProject().isBaselined());
639 if (dia->exec()) {
640 Node* currNode = currentTask();
641 if (currNode)
642 {
643 KCommand *m = dia->buildCommand(getPart());
644 m->execute(); // do changes to task
645 delete m;
646 TaskAddCmd *cmd = new TaskAddCmd(getPart(), &(getProject()), node, currNode, i18n("Add Task"));
647 getPart()->addCommand(cmd); // add task to project
648 return;
649 }
650 else
651 kdDebug()<<k_funcinfo<<"Cannot insert new task. Hmm, no current node!?"<<endl;
652 }
653 delete node;
654 delete dia;
655}
656
657void View::slotAddMilestone() {
658 Task* node = getProject().createTask(currentTask());
659 node->effort()->set(Duration::zeroDuration);
660
661 TaskDialog *dia = new TaskDialog(*node, getProject().accounts(), getProject().standardWorktime(), getProject().isBaselined());
662 if (dia->exec()) {
663 Node *currNode = currentTask();
664 if (currNode)
665 {
666 KCommand *m = dia->buildCommand(getPart());
667 m->execute(); // do changes to task
668 delete m;
669 TaskAddCmd *cmd = new TaskAddCmd(getPart(), &(getProject()), node, currNode, i18n("Add Milestone"));
670 getPart()->addCommand(cmd); // add task to project
671 return;
672 }
673 else
674 kdDebug()<<k_funcinfo<<"Cannot insert new milestone. Hmm, no current node!?"<<endl;
675 }
676 delete node;
677 delete dia;
678}
679
680void View::slotDefineWBS() {
681 //kdDebug()<<k_funcinfo<<endl;
682 WBSDefinitionDialog *dia = new WBSDefinitionDialog(getPart()->wbsDefinition());
683 dia->exec();
684
685 delete dia;
686}
687
688void View::slotGenerateWBS() {
689 //kdDebug()<<k_funcinfo<<endl;
690 getPart()->generateWBS();
691 slotUpdate(false);
692}
693
694void View::slotConfigure() {
695 //kdDebug()<<k_funcinfo<<endl;
696 ConfigDialog *dia = new ConfigDialog(getPart()->config(), getProject());
697 dia->exec();
698 delete dia;
699}
700
701Node *View::currentTask()
702{
703 Node* task = 0;
704 if (m_tab->visibleWidget() == m_ganttview) {
705 task = m_ganttview->currentNode();
706 }
707 else if (m_tab->visibleWidget() == m_pertview) {
708 task = m_pertview->currentNode();
709 }
710 else if (m_tab->visibleWidget() == m_resourceview) {
711 task = m_resourceview->currentNode();
712 }
713 if ( 0 != task ) {
714 return task;
715 }
716 return &(getProject());
717}
718
719void View::slotOpenNode() {
720 //kdDebug()<<k_funcinfo<<endl;
721 Node *node = currentTask();
722 if (!node)
723 return;
724
725 switch (node->type()) {
726 case Node::Type_Project: {
727 Project *project = dynamic_cast<Project *>(node);
728 MainProjectDialog *dia = new MainProjectDialog(*project);
729 if (dia->exec()){
730 KCommand *m = dia->buildCommand(getPart());
731 if (m) {
732 getPart()->addCommand(m);
733 }
734 }
735 delete dia;
736 break;
737 }
738 case Node::Type_Subproject:
739 //TODO
740 break;
741 case Node::Type_Task: {
742 Task *task = dynamic_cast<Task *>(node);
743 TaskDialog *dia = new TaskDialog(*task, getProject().accounts(), getProject().standardWorktime(), getProject().isBaselined());
744 if (dia->exec()) {
745 KCommand *m = dia->buildCommand(getPart());
746 if (m) {
747 getPart()->addCommand(m);
748 }
749 }
750 delete dia;
751 break;
752 }
753 case Node::Type_Milestone: {
754 // Use the normal task dialog for now.
755 // Maybe milestone should have it's own dialog, but we need to be able to
756 // enter a duration in case we accidentally set a tasks duration to zero
757 // and hence, create a milestone
758 Task *task = dynamic_cast<Task *>(node);
759 TaskDialog *dia = new TaskDialog(*task, getProject().accounts(), getProject().standardWorktime(), getProject().isBaselined());
760 if (dia->exec()) {
761 KCommand *m = dia->buildCommand(getPart());
762 if (m) {
763 getPart()->addCommand(m);
764 }
765 }
766 delete dia;
767 break;
768 }
769 case Node::Type_Summarytask: {
770 Task *task = dynamic_cast<Task *>(node);
771 SummaryTaskDialog *dia = new SummaryTaskDialog(*task);
772 if (dia->exec()) {
773 KCommand *m = dia->buildCommand(getPart());
774 if (m) {
775 getPart()->addCommand(m);
776 }
777 }
778 delete dia;
779 break;
780 }
781 default:
782 break; // avoid warnings
783 }
784}
785
786void View::slotTaskProgress() {
787 //kdDebug()<<k_funcinfo<<endl;
788 Node *node = currentTask();
789 if (!node)
790 return;
791
792 switch (node->type()) {
793 case Node::Type_Project: {
794 break;
795 }
796 case Node::Type_Subproject:
797 //TODO
798 break;
799 case Node::Type_Task: {
800 Task *task = dynamic_cast<Task *>(node);
801 TaskProgressDialog *dia = new TaskProgressDialog(*task, getProject().standardWorktime());
802 if (dia->exec()) {
803 KCommand *m = dia->buildCommand(getPart());
804 if (m) {
805 getPart()->addCommand(m);
806 }
807 }
808 delete dia;
809 break;
810 }
811 case Node::Type_Milestone: {
812 Task *task = dynamic_cast<Task *>(node);
813 MilestoneProgressDialog *dia = new MilestoneProgressDialog(*task);
814 if (dia->exec()) {
815 KCommand *m = dia->buildCommand(getPart());
816 if (m) {
817 getPart()->addCommand(m);
818 }
819 }
820 delete dia;
821 break;
822 }
823 case Node::Type_Summarytask: {
824 // TODO
825 break;
826 }
827 default:
828 break; // avoid warnings
829 }
830}
831
832void View::slotDeleteTask()
833{
834 //kdDebug()<<k_funcinfo<<endl;
835 Node *node = currentTask();
836 if (node == 0 || node->getParent() == 0) {
837 kdDebug()<<k_funcinfo<<(node ? "Task is main project" : "No current task")<<endl;
838 return;
839 }
840 KMacroCommand *cmd = new KMacroCommand(i18n("Delete Task"));
841 cmd->addCommand(new NodeDeleteCmd(getPart(), node));
842 TQPtrListIterator<Relation> it = node->dependChildNodes();
843 for (; it.current(); ++it) {
844 cmd->addCommand(new DeleteRelationCmd(getPart(), it.current()));
845 }
846 it = node->dependParentNodes();
847 for (; it.current(); ++it) {
848 cmd->addCommand(new DeleteRelationCmd(getPart(),it.current()));
849 }
850 getPart()->addCommand(cmd);
851}
852
853void View::slotIndentTask()
854{
855 //kdDebug()<<k_funcinfo<<endl;
856 Node *node = currentTask();
857 if (node == 0 || node->getParent() == 0) {
858 kdDebug()<<k_funcinfo<<(node ? "Task is main project" : "No current task")<<endl;
859 return;
860 }
861 if (getProject().canIndentTask(node)) {
862 NodeIndentCmd *cmd = new NodeIndentCmd(getPart(), *node, i18n("Indent Task"));
863 getPart()->addCommand(cmd);
864 }
865}
866
867void View::slotUnindentTask()
868{
869 //kdDebug()<<k_funcinfo<<endl;
870 Node *node = currentTask();
871 if (node == 0 || node->getParent() == 0) {
872 kdDebug()<<k_funcinfo<<(node ? "Task is main project" : "No current task")<<endl;
873 return;
874 }
875 if (getProject().canUnindentTask(node)) {
876 NodeUnindentCmd *cmd = new NodeUnindentCmd(getPart(), *node, i18n("Unindent Task"));
877 getPart()->addCommand(cmd);
878 }
879}
880
881void View::slotMoveTaskUp()
882{
883 //kdDebug()<<k_funcinfo<<endl;
884
885 Node* task = currentTask();
886 if ( 0 == task ) {
887 // is always != 0. At least we would get the Project, but you never know who might change that
888 // so better be careful
889 kdError()<<k_funcinfo<<"No current task"<<endl;
890 return;
891 }
892
893 if ( Node::Type_Project == task->type() ) {
894 kdDebug()<<k_funcinfo<<"The root node cannot be moved up"<<endl;
895 return;
896 }
897 if (getProject().canMoveTaskUp(task)) {
898 NodeMoveUpCmd *cmd = new NodeMoveUpCmd(getPart(), *task, i18n("Move Task Up"));
899 getPart()->addCommand(cmd);
900 }
901}
902
903void View::slotMoveTaskDown()
904{
905 //kdDebug()<<k_funcinfo<<endl;
906
907 Node* task = currentTask();
908 if ( 0 == task ) {
909 // is always != 0. At least we would get the Project, but you never know who might change that
910 // so better be careful
911 return;
912 }
913
914 if ( Node::Type_Project == task->type() ) {
915 kdDebug()<<k_funcinfo<<"The root node cannot be moved down"<<endl;
916 return;
917 }
918 if (getProject().canMoveTaskDown(task)) {
919 NodeMoveDownCmd *cmd = new NodeMoveDownCmd(getPart(), *task, i18n("Move Task Down"));
920 getPart()->addCommand(cmd);
921 }
922}
923
924void View::slotAddRelation(Node *par, Node *child) {
925 //kdDebug()<<k_funcinfo<<endl;
926 Relation *rel = new Relation(par, child);
927 AddRelationDialog *dia = new AddRelationDialog(rel, this);
928 if (dia->exec()) {
929 KCommand *cmd = dia->buildCommand(getPart());
930 if (cmd)
931 getPart()->addCommand(cmd);
932 } else {
933 delete rel;
934 }
935 delete dia;
936}
937
938void View::slotAddRelation(Node *par, Node *child, int linkType) {
939 //kdDebug()<<k_funcinfo<<endl;
940 if (linkType == Relation::FinishStart ||
941 linkType == Relation::StartStart ||
942 linkType == Relation::FinishFinish)
943 {
944 Relation *rel = new Relation(par, child, static_cast<Relation::Type>(linkType));
945 getPart()->addCommand(new AddRelationCmd(getPart(), rel, i18n("Add Relation")));
946 } else {
947 slotAddRelation(par, child);
948 }
949}
950
951void View::slotModifyRelation(Relation *rel) {
952 //kdDebug()<<k_funcinfo<<endl;
953 ModifyRelationDialog *dia = new ModifyRelationDialog(rel, this);
954 if (dia->exec()) {
955 if (dia->relationIsDeleted()) {
956 getPart()->addCommand(new DeleteRelationCmd(getPart(), rel, i18n("Delete Relation")));
957 } else {
958 KCommand *cmd = dia->buildCommand(getPart());
959 if (cmd) {
960 getPart()->addCommand(cmd);
961 }
962 }
963 }
964 delete dia;
965}
966
967void View::slotModifyRelation(Relation *rel, int linkType) {
968 //kdDebug()<<k_funcinfo<<endl;
969 if (linkType == Relation::FinishStart ||
970 linkType == Relation::StartStart ||
971 linkType == Relation::FinishFinish)
972 {
973 getPart()->addCommand(new ModifyRelationTypeCmd(getPart(), rel, static_cast<Relation::Type>(linkType)));
974 } else {
975 slotModifyRelation(rel);
976 }
977}
978
979// testing
980void View::slotExportGantt() {
981 //kdDebug()<<k_funcinfo<<endl;
982 if (!m_ganttview) {
983 return;
984 }
985 TQString fn = KFileDialog::getSaveFileName( TQString(), TQString(), this );
986 if (!fn.isEmpty()) {
987 TQFile f(fn);
988 m_ganttview->exportGantt(&f);
989 }
990}
991
992void View::slotEditResource() {
993 //kdDebug()<<k_funcinfo<<endl;
994 Resource *r = m_resourceview->currentResource();
995 if (!r)
996 return;
997 ResourceDialog *dia = new ResourceDialog(getProject(), r);
998 if (dia->exec()) {
999 KCommand *cmd = dia->buildCommand(getPart());
1000 if (cmd)
1001 getPart()->addCommand(cmd);
1002 }
1003 delete dia;
1004}
1005
1006void View::updateReadWrite(bool /*readwrite*/) {
1007}
1008
1009Part *View::getPart()const {
1010 return (Part *)koDocument();
1011}
1012
1013void View::slotConnectNode() {
1014 //kdDebug()<<k_funcinfo<<endl;
1015/* NodeItem *curr = m_ganttview->currentItem();
1016 if (curr) {
1017 kdDebug()<<k_funcinfo<<"node="<<curr->getNode().name()<<endl;
1018 }*/
1019}
1020
1021TQPopupMenu * View::popupMenu( const TQString& name )
1022{
1023 //kdDebug()<<k_funcinfo<<endl;
1024 Q_ASSERT(factory());
1025 if ( factory() )
1026 return ((TQPopupMenu*)factory()->container( name, this ));
1027 return 0L;
1028}
1029
1030void View::slotChanged(TQWidget *)
1031{
1032 //kdDebug()<<k_funcinfo<<endl;
1033 slotUpdate(false);
1034}
1035
1036void View::slotChanged()
1037{
1038 //kdDebug()<<k_funcinfo<<endl;
1039 slotUpdate(false);
1040}
1041
1042void View::slotUpdate(bool calculate)
1043{
1044 //kdDebug()<<k_funcinfo<<"calculate="<<calculate<<endl;
1045 if (calculate)
1046 projectCalculate();
1047
1048 m_updateGanttview = true;
1049 m_updateResourceview = true;
1050 m_updateAccountsview = true;
1051
1052 updateView(m_tab->visibleWidget());
1053}
1054
1055void View::slotAboutToShow(TQWidget *widget) {
1056 updateView(widget);
1057}
1058
1059void View::updateView(TQWidget *widget)
1060{
1061 TQApplication::setOverrideCursor(TQt::waitCursor);
1062 setScheduleActionsEnabled();
1063 setTaskActionsEnabled(false);
1064 mainWindow()->toolBar("report")->hide();
1065 if (widget == m_ganttview)
1066 {
1067 //kdDebug()<<k_funcinfo<<"draw gantt"<<endl;
1068 m_ganttview->setShowExpected(actionViewExpected->isChecked());
1069 m_ganttview->setShowOptimistic(actionViewOptimistic->isChecked());
1070 m_ganttview->setShowPessimistic(actionViewPessimistic->isChecked());
1071 if (m_updateGanttview)
1072 m_ganttview->drawChanges(getProject());
1073 setTaskActionsEnabled(widget, true);
1074 m_updateGanttview = false;
1075 }
1076 else if (widget == m_pertview)
1077 {
1078 //kdDebug()<<k_funcinfo<<"draw pertview"<<endl;
1079 m_pertview->draw();
1080 }
1081 else if (widget == m_resourceview)
1082 {
1083 //kdDebug()<<k_funcinfo<<"draw resourceview"<<endl;
1084 if (m_updateResourceview)
1085 m_resourceview->draw(getPart()->getProject());
1086 m_updateResourceview = false;
1087 }
1088 else if (widget == m_accountsview)
1089 {
1090 //kdDebug()<<k_funcinfo<<"draw accountsview"<<endl;
1091 if (m_updateAccountsview)
1092 m_accountsview->draw();
1093 m_updateAccountsview = false;
1094 }
1095/* else if (widget == m_reportview)
1096 {
1097 mainWindow()->toolBar("report")->show();
1098 m_reportview->enableNavigationBtn();
1099 }*/
1100 TQApplication::restoreOverrideCursor();
1101}
1102
1103void View::slotRenameNode(Node *node, const TQString& name) {
1104 //kdDebug()<<k_funcinfo<<name<<endl;
1105 if (node) {
1106 NodeModifyNameCmd *cmd = new NodeModifyNameCmd(getPart(), *node, name, i18n("Modify Name"));
1107 getPart()->addCommand(cmd);
1108 }
1109}
1110
1111void View::slotPopupMenu(const TQString& menuname, const TQPoint & pos)
1112{
1113 TQPopupMenu* menu = this->popupMenu(menuname);
1114 if (menu)
1115 menu->exec(pos);
1116}
1117
1118bool View::setContext(Context &context) {
1119 //kdDebug()<<k_funcinfo<<endl;
1120 m_currentEstimateType = context.currentEstimateType;
1121 getProject().setCurrentSchedule(context.currentSchedule);
1122 actionViewExpected->setChecked(context.actionViewExpected);
1123 actionViewOptimistic->setChecked(context.actionViewOptimistic);
1124 actionViewPessimistic->setChecked(context.actionViewPessimistic);
1125
1126 m_ganttview->setContext(context.ganttview, getProject());
1127 // hmmm, can't decide if these should be here or actions moved to ganttview
1128 actionViewGanttResources->setChecked(context.ganttview.showResources);
1129 actionViewGanttTaskName->setChecked(context.ganttview.showTaskName);
1130 actionViewGanttTaskLinks->setChecked(context.ganttview.showTaskLinks);
1131 actionViewGanttProgress->setChecked(context.ganttview.showProgress);
1132 actionViewGanttFloat->setChecked(context.ganttview.showPositiveFloat);
1133 actionViewGanttCriticalTasks->setChecked(context.ganttview.showCriticalTasks);
1134 actionViewGanttCriticalPath->setChecked(context.ganttview.showCriticalPath);
1135
1136 m_pertview->setContext(context.pertview);
1137 m_resourceview->setContext(context.resourceview);
1138 m_accountsview->setContext(context.accountsview);
1139// m_reportview->setContext(context.reportview);
1140
1141 if (context.currentView == "ganttview") {
1142 m_ganttview->setShowExpected(actionViewExpected->isChecked());
1143 m_ganttview->setShowOptimistic(actionViewOptimistic->isChecked());
1144 m_ganttview->setShowPessimistic(actionViewPessimistic->isChecked());
1145 slotViewGantt();
1146 } else if (context.currentView == "pertview") {
1147 slotViewPert();
1148 } else if (context.currentView == "resourceview") {
1149 slotViewResources();
1150 } else if (context.currentView == "accountsview") {
1151 slotViewAccounts();
1152 } else if (context.currentView == "reportview") {
1153 //slotViewReport();
1154 } else {
1155 slotViewGantt();
1156 }
1157 slotUpdate(false);
1158 return true;
1159}
1160
1161void View::getContext(Context &context) const {
1162 //kdDebug()<<k_funcinfo<<endl;
1163 context.currentEstimateType = m_currentEstimateType;
1164 if (getProject().currentSchedule())
1165 context.currentSchedule = getProject().currentSchedule()->id();
1166 context.actionViewExpected = actionViewExpected->isChecked();
1167 context.actionViewOptimistic = actionViewOptimistic->isChecked();
1168 context.actionViewPessimistic = actionViewPessimistic->isChecked();
1169
1170 if (m_tab->visibleWidget() == m_ganttview) {
1171 context.currentView = "ganttview";
1172 } else if (m_tab->visibleWidget() == m_pertview) {
1173 context.currentView = "pertview";
1174 } else if (m_tab->visibleWidget() == m_resourceview) {
1175 context.currentView = "resourceview";
1176 } else if (m_tab->visibleWidget() == m_accountsview) {
1177 context.currentView = "accountsview";
1178/* } else if (m_tab->visibleWidget() == m_reportview) {
1179 context.currentView = "reportview";*/
1180 }
1181 m_ganttview->getContext(context.ganttview);
1182 m_pertview->getContext(context.pertview);
1183 m_resourceview->getContext(context.resourceview);
1184 m_accountsview->getContext(context.accountsview);
1185// m_reportview->getContext(context.reportview);
1186}
1187
1188void View::setBaselineMode(bool /*on*/) {
1189 //kdDebug()<<k_funcinfo<<endl;
1190/* m_baselineMode = on;
1191
1192 m_ganttview->setReadWriteMode(!on);
1193
1194 actionCut->setEnabled(!on);
1195 actionCopy->setEnabled(!on);
1196 actionPaste->setEnabled(!on);
1197
1198 actionDeleteTask->setEnabled(!on);
1199 actionIndentTask->setEnabled(!on);
1200 actionUnindentTask->setEnabled(!on);
1201 actionMoveTaskUp->setEnabled(!on);
1202 actionMoveTaskDown->setEnabled(!on);
1203
1204 actionAddTask->setEnabled(!on);
1205 actionAddSubtask->setEnabled(!on);
1206 actionAddMilestone->setEnabled(!on);
1207
1208 actionEditStandardWorktime->setEnabled(!on);
1209 actionEditCalendar->setEnabled(!on);
1210 actionEditResources->setEnabled(!on);
1211 actionCalculate->setEnabled(!on);
1212
1213 actionEditResource->setEnabled(!on);*/
1214}
1215
1216// called when widget w is about to be shown
1217void View::setTaskActionsEnabled(TQWidget *w, bool on) {
1218 Node *n = 0;
1219 if (w == m_ganttview) {
1220 n = m_ganttview->currentNode();
1221 }// else pert, etc when implemented
1222
1223 actionAddTask->setEnabled(on);
1224 actionAddMilestone->setEnabled(on);
1225 // only enabled when we have a task selected
1226 bool o = (on && n);
1227 actionAddSubtask->setEnabled(o);
1228 actionDeleteTask->setEnabled(o);
1229 actionMoveTaskUp->setEnabled(o && getProject().canMoveTaskUp(n));
1230 actionMoveTaskDown->setEnabled(o && getProject().canMoveTaskDown(n));
1231 actionIndentTask->setEnabled(o && getProject().canIndentTask(n));
1232 actionUnindentTask->setEnabled(o && getProject().canUnindentTask(n));
1233}
1234
1235void View::setTaskActionsEnabled(bool on) {
1236 setTaskActionsEnabled(m_ganttview, on); //FIXME if more than ganttview can do this
1237}
1238
1239void View::setScheduleActionsEnabled() {
1240 actionViewExpected->setEnabled(getProject().findSchedule(Schedule::Expected));
1241 actionViewOptimistic->setEnabled(getProject().findSchedule(Schedule::Optimistic));
1242 actionViewPessimistic->setEnabled(getProject().findSchedule(Schedule::Pessimistic));
1243 if (getProject().notScheduled()) {
1244 m_estlabel->setText(i18n("Not scheduled"));
1245 return;
1246 }
1247 Schedule *ns = getProject().currentSchedule();
1248 if (ns->type() == Schedule::Expected) {
1249 actionViewExpected->setChecked(true);
1250 m_estlabel->setText(i18n("Expected"));
1251 } else if (ns->type() == Schedule::Optimistic) {
1252 actionViewOptimistic->setChecked(true);
1253 m_estlabel->setText(i18n("Optimistic"));
1254 } else if (ns->type() == Schedule::Pessimistic) {
1255 actionViewPessimistic->setChecked(true);
1256 m_estlabel->setText(i18n("Pessimistic"));
1257 }
1258}
1259
1260
1261#ifndef NDEBUG
1262void View::slotPrintDebug() {
1263 kdDebug()<<"-------- Debug printout: Node list" <<endl;
1264/* Node *curr = m_ganttview->currentNode();
1265 if (curr) {
1266 curr->printDebug(true,"");
1267 } else*/
1268 getPart()->getProject().printDebug(true, "");
1269}
1270void View::slotPrintSelectedDebug() {
1271 Node *curr = m_ganttview->currentNode();
1272 if (curr) {
1273 kdDebug()<<"-------- Debug printout: Selected node" <<endl;
1274 curr->printDebug(true,"");
1275 } else
1276 slotPrintDebug();
1277}
1278void View::slotPrintCalendarDebug() {
1279 kdDebug()<<"-------- Debug printout: Node list" <<endl;
1280/* Node *curr = m_ganttview->currentNode();
1281 if (curr) {
1282 curr->printDebug(true,"");
1283 } else*/
1284 getPart()->getProject().printCalendarDebug("");
1285}
1286void View::slotPrintTestDebug() {
1287 const TQStringList &lst = getPart()->xmlLoader().log();
1288
1289 for ( TQStringList::ConstIterator it = lst.constBegin(); it != lst.constEnd(); ++it ) {
1290 kdDebug()<<*it<<endl;
1291 }
1292// kdDebug()<<"------------Test 1---------------------"<<endl;
1293// {
1294// DateTime d1(TQDate(2006,1,2), TQTime(8,0,0));
1295// DateTime d2 = d1.addSecs(3600);
1296// Duration d = d2 - d1;
1297// bool b = d==Duration(0,0,0,3600);
1298// kdDebug()<<"1: Success="<<b<<" "<<d2.toString()<<"-"<<d1.toString()<<"="<<d.toString()<<endl;
1299// d = d1 - d2;
1300// b = d==Duration(0,0,0,3600);
1301// kdDebug()<<"2: Success="<<b<<" "<<d1.toString()<<"-"<<d2.toString()<<"="<<d.toString()<<endl;
1302// d2 = d2.addDays(-2);
1303// d = d1 - d2;
1304// b = d==Duration(2,0,0)-Duration(0,0,0,3600);
1305// kdDebug()<<"3: Success="<<b<<" "<<d1.toString()<<"-"<<d2.toString()<<"="<<d.toString()<<endl;
1306// d = d2 - d1;
1307// b = d==Duration(2,0,0)-Duration(0,0,0,3600);
1308// kdDebug()<<"4: Success="<<b<<" "<<d2.toString()<<"-"<<d1.toString()<<"="<<d.toString()<<endl;
1309// kdDebug()<<endl;
1310// b = (d2 + d)==d1;
1311// kdDebug()<<"5: Success="<<b<<" "<<d2<<"+"<<d.toString()<<"="<<d1<<endl;
1312// b = (d1 - d)==d2;
1313// kdDebug()<<"6: Success="<<b<<" "<<d1<<"-"<<d.toString()<<"="<<d2<<endl;
1314// } // end test 1
1315// kdDebug()<<endl;
1316// kdDebug()<<"------------Test 2 Single calendar-----------------"<<endl;
1317// {
1318// Calendar *t = new Calendar("Test 2");
1319// TQDate wdate(2006,1,2);
1320// DateTime before = DateTime(wdate.addDays(-1));
1321// DateTime after = DateTime(wdate.addDays(1));
1322// TQTime t1(8,0,0);
1323// TQTime t2(10,0,0);
1324// DateTime wdt1(wdate, t1);
1325// DateTime wdt2(wdate, t2);
1326// CalendarDay *day = new CalendarDay(TQDate(2006,1,2), Map::Working);
1327// day->addInterval(TQPair<TQTime, TQTime>(t1, t2));
1328// if (!t->addDay(day)) {
1329// kdDebug()<<"Failed to add day"<<endl;
1330// delete day;
1331// delete t;
1332// return;
1333// }
1334// kdDebug()<<"Added date="<<day->date().toString()<<" "<<day->startOfDay().toString()<<" - "<<day->endOfDay()<<endl;
1335// kdDebug()<<"Found date="<<day->date().toString()<<" "<<day->startOfDay().toString()<<" - "<<day->endOfDay()<<endl;
1336//
1337// CalendarDay *d = t->findDay(wdate);
1338// bool b = (day == d);
1339// kdDebug()<<"1: Success="<<b<<" Find same day"<<endl;
1340//
1341// DateTime dt = t->firstAvailableAfter(after, after.addDays(10));
1342// b = !dt.isValid();
1343// kdDebug()<<"2: Success="<<b<<" firstAvailableAfter("<<after<<"): ="<<dt<<endl;
1344//
1345// dt = t->firstAvailableBefore(before, before.addDays(-10));
1346// b = !dt.isValid();
1347// kdDebug()<<"3: Success="<<b<<" firstAvailableBefore("<<before.toString()<<"): ="<<dt<<endl;
1348//
1349// dt = t->firstAvailableAfter(before, after);
1350// b = dt == wdt1;
1351// kdDebug()<<"4: Success="<<b<<" firstAvailableAfter("<<before<<"): ="<<dt<<endl;
1352//
1353// dt = t->firstAvailableBefore(after, before);
1354// b = dt == wdt2;
1355// kdDebug()<<"5: Success="<<b<<" firstAvailableBefore("<<after<<"): ="<<dt<<endl;
1356//
1357// b = t->hasInterval(before, after);
1358// kdDebug()<<"6: Success="<<b<<" hasInterval("<<before<<", "<<after<<")"<<endl;
1359//
1360// b = !t->hasInterval(after, after.addDays(1));
1361// kdDebug()<<"7: Success="<<b<<" !hasInterval("<<after<<", "<<after.addDays(1)<<")"<<endl;
1362//
1363// b = !t->hasInterval(before, before.addDays(-1));
1364// kdDebug()<<"8: Success="<<b<<" !hasInterval("<<before<<", "<<before.addDays(-1)<<")"<<endl;
1365//
1366// Duration e1(0, 2, 0); // 2 hours
1367// Duration e2 = t->effort(before, after);
1368// b = e1==e2;
1369// kdDebug()<<"9: Success="<<b<<" effort"<<e1.toString()<<" = "<<e2.toString()<<endl;
1370//
1371// delete t;
1372// }// end test 2
1373//
1374// kdDebug()<<endl;
1375// kdDebug()<<"------------Test 3 Parent calendar-----------------"<<endl;
1376// {
1377// Calendar *t = new Calendar("Test 3");
1378// Calendar *p = new Calendar("Test 3 parent");
1379// t->setParent(p);
1380// TQDate wdate(2006,1,2);
1381// DateTime before = DateTime(wdate.addDays(-1));
1382// DateTime after = DateTime(wdate.addDays(1));
1383// TQTime t1(8,0,0);
1384// TQTime t2(10,0,0);
1385// DateTime wdt1(wdate, t1);
1386// DateTime wdt2(wdate, t2);
1387// CalendarDay *day = new CalendarDay(TQDate(2006,1,2), Map::Working);
1388// day->addInterval(TQPair<TQTime, TQTime>(t1, t2));
1389// if (!p->addDay(day)) {
1390// kdDebug()<<"Failed to add day"<<endl;
1391// delete day;
1392// delete t;
1393// return;
1394// }
1395// kdDebug()<<"Added date="<<day->date().toString()<<" "<<day->startOfDay().toString()<<" - "<<day->endOfDay().toString()<<endl;
1396// kdDebug()<<"Found date="<<day->date().toString()<<" "<<day->startOfDay().toString()<<" - "<<day->endOfDay().toString()<<endl;
1397//
1398// CalendarDay *d = p->findDay(wdate);
1399// bool b = (day == d);
1400// kdDebug()<<"1: Success="<<b<<" Find same day"<<endl;
1401//
1402// DateTime dt = t->firstAvailableAfter(after, after.addDays(10));
1403// b = !dt.isValid();
1404// kdDebug()<<"2: Success="<<b<<" firstAvailableAfter("<<after.toString()<<"): ="<<!b<<endl;
1405//
1406// dt = t->firstAvailableBefore(before, before.addDays(-10));
1407// b = !dt.isValid();
1408// kdDebug()<<"3: Success="<<b<<" firstAvailableBefore("<<before.toString()<<"): ="<<!b<<endl;
1409//
1410// dt = t->firstAvailableAfter(before, after);
1411// b = dt == wdt1;
1412// kdDebug()<<"4: Success="<<b<<" firstAvailableAfter("<<before.toString()<<"): ="<<dt.toString()<<endl;
1413//
1414// dt = t->firstAvailableBefore(after, before);
1415// b = dt == wdt2;
1416// kdDebug()<<"5: Success="<<b<<" firstAvailableBefore("<<after.toString()<<"): ="<<dt.toString()<<endl;
1417//
1418// b = t->hasInterval(before, after);
1419// kdDebug()<<"6: Success="<<b<<" hasInterval("<<before.toString()<<", "<<after<<")"<<endl;
1420//
1421// b = !t->hasInterval(after, after.addDays(1));
1422// kdDebug()<<"7: Success="<<b<<" !hasInterval("<<after.toString()<<", "<<after.addDays(1)<<")"<<endl;
1423//
1424// b = !t->hasInterval(before, before.addDays(-1));
1425// kdDebug()<<"8: Success="<<b<<" !hasInterval("<<before.toString()<<", "<<before.addDays(-1)<<")"<<endl;
1426// Duration e1(0, 2, 0); // 2 hours
1427// Duration e2 = t->effort(before, after);
1428// b = e1==e2;
1429// kdDebug()<<"9: Success="<<b<<" effort "<<e1.toString()<<"=="<<e2.toString()<<endl;
1430//
1431// delete t;
1432// delete p;
1433// }// end test 3
1434// kdDebug()<<endl;
1435// kdDebug()<<"------------Test 4 Parent calendar/weekdays-------------"<<endl;
1436// {
1437// TQTime t1(8,0,0);
1438// TQTime t2(10,0,0);
1439// Calendar *p = new Calendar("Test 4 parent");
1440// CalendarDay *wd1 = p->weekday(0); // monday
1441// if (wd1 == 0) {
1442// kdDebug()<<"Failed to get weekday"<<endl;
1443// }
1444// wd1->setState(Map::NonWorking);
1445//
1446// CalendarDay *wd2 = p->weekday(2); // wednesday
1447// if (wd2 == 0) {
1448// kdDebug()<<"Failed to get weekday"<<endl;
1449// }
1450// wd2->addInterval(TQPair<TQTime, TQTime>(t1, t2));
1451// wd2->setState(Map::Working);
1452//
1453// Calendar *t = new Calendar("Test 4");
1454// t->setParent(p);
1455// TQDate wdate(2006,1,2); // monday jan 2
1456// DateTime before = DateTime(wdate.addDays(-4)); //Thursday dec 29
1457// DateTime after = DateTime(wdate.addDays(4)); // Friday jan 6
1458// DateTime wdt1(wdate, t1);
1459// DateTime wdt2(TQDate(2006, 1, 4), t2); // Wednesday
1460// CalendarDay *day = new CalendarDay(TQDate(2006,1,2), Map::Working);
1461// day->addInterval(TQPair<TQTime, TQTime>(t1, t2));
1462// if (!p->addDay(day)) {
1463// kdDebug()<<"Failed to add day"<<endl;
1464// delete day;
1465// delete t;
1466// return;
1467// }
1468// kdDebug()<<"Added date="<<day->date().toString()<<" "<<day->startOfDay().toString()<<" - "<<day->endOfDay().toString()<<endl;
1469// kdDebug()<<"Found date="<<day->date().toString()<<" "<<day->startOfDay().toString()<<" - "<<day->endOfDay().toString()<<endl;
1470//
1471// CalendarDay *d = p->findDay(wdate);
1472// bool b = (day == d);
1473// kdDebug()<<"1: Success="<<b<<" Find same day"<<endl;
1474//
1475// DateTime dt = t->firstAvailableAfter(after, after.addDays(10));
1476// b = (dt.isValid() && dt == DateTime(TQDate(2006,1,11), t1));
1477// kdDebug()<<"2: Success="<<b<<" firstAvailableAfter("<<after<<"): ="<<dt<<endl;
1478//
1479// dt = t->firstAvailableBefore(before, before.addDays(-10));
1480// b = (dt.isValid() && dt == DateTime(TQDate(2005, 12, 28), t2));
1481// kdDebug()<<"3: Success="<<b<<" firstAvailableBefore("<<before.toString()<<"): ="<<dt<<endl;
1482//
1483// dt = t->firstAvailableAfter(before, after);
1484// b = dt == wdt1; // We find the day jan 2
1485// kdDebug()<<"4: Success="<<b<<" firstAvailableAfter("<<before.toString()<<"): ="<<dt.toString()<<endl;
1486//
1487// dt = t->firstAvailableBefore(after, before);
1488// b = dt == wdt2; // We find the weekday (wednesday)
1489// kdDebug()<<"5: Success="<<b<<" firstAvailableBefore("<<after.toString()<<"): ="<<dt.toString()<<endl;
1490//
1491// b = t->hasInterval(before, after);
1492// kdDebug()<<"6: Success="<<b<<" hasInterval("<<before.toString()<<", "<<after<<")"<<endl;
1493//
1494// b = !t->hasInterval(after, after.addDays(1));
1495// kdDebug()<<"7: Success="<<b<<" !hasInterval("<<after.toString()<<", "<<after.addDays(1)<<")"<<endl;
1496//
1497// b = !t->hasInterval(before, before.addDays(-1));
1498// kdDebug()<<"8: Success="<<b<<" !hasInterval("<<before.toString()<<", "<<before.addDays(-1)<<")"<<endl;
1499// Duration e1(0, 4, 0); // 2 hours
1500// Duration e2 = t->effort(before, after);
1501// b = e1==e2;
1502// kdDebug()<<"9: Success="<<b<<" effort "<<e1.toString()<<"="<<e2.toString()<<endl;
1503//
1504// TQPair<DateTime, DateTime> r = t->firstInterval(before, after);
1505// b = r.first == wdt1; // We find the monday jan 2
1506// kdDebug()<<"10: Success="<<b<<" firstInterval("<<before<<"): ="<<r.first<<", "<<r.second<<endl;
1507// r = t->firstInterval(r.second, after);
1508// b = r.first == DateTime(TQDate(2006, 1, 4),t1); // We find the wednesday jan 4
1509// kdDebug()<<"11: Success="<<b<<" firstInterval("<<r.second<<"): ="<<r.first<<", "<<r.second<<endl;
1510//
1511// delete t;
1512// delete p;
1513// }// end test 4
1514}
1515#endif
1516
1517} //KPlato namespace
1518
1519#include "kptview.moc"