00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <kprinter.h>
00022 #include <kmessagebox.h>
00023
00024 #include <KoMainWindow.h>
00025 #include <KoToolManager.h>
00026
00027 #include <QApplication>
00028 #include <QDockWidget>
00029 #include <QIcon>
00030 #include <QLayout>
00031 #include <QColor>
00032 #include <QLabel>
00033 #include <QString>
00034 #include <QStringList>
00035 #include <qsize.h>
00036 #include <QStackedWidget>
00037 #include <QHeaderView>
00038 #include <QVBoxLayout>
00039 #include <QTreeWidget>
00040 #include <QTreeWidgetItem>
00041 #include <QItemDelegate>
00042 #include <QStyle>
00043 #include <QVariant>
00044
00045 #include <kicon.h>
00046 #include <kaction.h>
00047 #include <kactionmenu.h>
00048 #include <kstdaction.h>
00049 #include <klocale.h>
00050 #include <kdebug.h>
00051 #include <ktoolbar.h>
00052 #include <kstdaccel.h>
00053 #include <kaccelgen.h>
00054 #include <kdeversion.h>
00055 #include <kstatusbar.h>
00056 #include <kxmlguifactory.h>
00057 #include <kstandarddirs.h>
00058 #include <kdesktopfile.h>
00059 #include <kcommand.h>
00060 #include <kfiledialog.h>
00061
00062 #include "kptview.h"
00063 #include "kptaccountsview.h"
00064 #include "kptfactory.h"
00065 #include "kptmilestoneprogressdialog.h"
00066 #include "kptnode.h"
00067 #include "kptpart.h"
00068 #include "kptproject.h"
00069 #include "kptmainprojectdialog.h"
00070 #include "kpttask.h"
00071 #include "kptsummarytaskdialog.h"
00072 #include "kpttaskdialog.h"
00073 #include "kpttaskprogressdialog.h"
00074 #include "kptganttview.h"
00075
00076 #include "kpttaskeditor.h"
00077 #include "kptdatetime.h"
00078 #include "kptcommand.h"
00079 #include "kptrelation.h"
00080 #include "kptrelationdialog.h"
00081 #include "kptresourceview.h"
00082 #include "kptresourcedialog.h"
00083 #include "kptresource.h"
00084 #include "kptresourcesdialog.h"
00085 #include "kptcalendarlistdialog.h"
00086 #include "kptstandardworktimedialog.h"
00087 #include "kptcanvasitem.h"
00088 #include "kptconfigdialog.h"
00089 #include "kptwbsdefinitiondialog.h"
00090 #include "kptaccountsdialog.h"
00091
00092 #include "KDGanttView.h"
00093 #include "KDGanttViewTaskItem.h"
00094 #include "KPtViewAdaptor.h"
00095
00096 namespace KPlato
00097 {
00098
00099
00100 class ViewCategoryDelegate : public QItemDelegate
00101 {
00102 public:
00103 ViewCategoryDelegate( QObject *parent, QTreeView *view )
00104 : QItemDelegate( parent ),
00105 m_view( view )
00106 {}
00107
00108 virtual void paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
00109
00110 private:
00111 QTreeView *m_view;
00112 };
00113
00114 void ViewCategoryDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
00115 {
00116 const QAbstractItemModel * model = index.model();
00117 Q_ASSERT( model );
00118
00119 if ( !model->parent( index ).isValid() ) {
00120
00121 QStyleOptionButton buttonOption;
00122 buttonOption.state = option.state;
00123 buttonOption.state &= ~QStyle::State_HasFocus;
00124
00125 buttonOption.rect = option.rect;
00126 buttonOption.palette = option.palette;
00127 buttonOption.features = QStyleOptionButton::None;
00128 m_view->style() ->drawControl( QStyle::CE_PushButton, &buttonOption, painter, m_view );
00129
00130 QStyleOption branchOption;
00131 static const int i = 9;
00132 QRect r = option.rect;
00133 branchOption.rect = QRect( r.left() + i / 2, r.top() + ( r.height() - i ) / 2, i, i );
00134 branchOption.palette = option.palette;
00135 branchOption.state = QStyle::State_Children;
00136
00137 if ( m_view->isExpanded( index ) )
00138 branchOption.state |= QStyle::State_Open;
00139
00140 m_view->style() ->drawPrimitive( QStyle::PE_IndicatorBranch, &branchOption, painter, m_view );
00141
00142
00143 QRect textrect = QRect( r.left() + i * 2, r.top(), r.width() - ( ( 5 * i ) / 2 ), r.height() );
00144 QString text = elidedText( option.fontMetrics, textrect.width(), Qt::ElideMiddle,
00145 model->data( index, Qt::DisplayRole ).toString() );
00146 m_view->style() ->drawItemText( painter, textrect, Qt::AlignCenter,
00147 option.palette, m_view->isEnabled(), text );
00148
00149 } else {
00150 QItemDelegate::paint( painter, option, index );
00151 }
00152
00153 }
00154
00155 ViewListTreeWidget::ViewListTreeWidget( QWidget *parent )
00156 : QTreeWidget( parent )
00157 {
00158 header() ->hide();
00159 setRootIsDecorated( false );
00160 setItemDelegate( new ViewCategoryDelegate( this, this ) );
00161 setItemsExpandable( true );
00162
00163 connect( this, SIGNAL( itemPressed( QTreeWidgetItem*, int ) ), SLOT( handleMousePress( QTreeWidgetItem* ) ) );
00164 }
00165
00166 void ViewListTreeWidget::drawRow( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const
00167 {
00168 QTreeWidget::drawRow( painter, option, index );
00169 }
00170
00171 void ViewListTreeWidget::handleMousePress( QTreeWidgetItem *item )
00172 {
00173 if ( item == 0 )
00174 return ;
00175
00176 if ( item->parent() == 0 ) {
00177 setItemExpanded( item, !isItemExpanded( item ) );
00178 return ;
00179 } else {
00180 emit activated( item );
00181 }
00182 }
00183
00184 QTreeWidgetItem *ViewListTreeWidget::findCategory( const QString cat )
00185 {
00186 QTreeWidgetItem * item;
00187 int cnt = topLevelItemCount();
00188 for ( int i = 0; i < cnt; ++i ) {
00189 item = topLevelItem( i );
00190 if ( item->text( 0 ) == cat )
00191 return item;
00192 }
00193 return 0;
00194 }
00195
00196 ViewListDockWidget::ViewListDockWidget( QString name, KMainWindow *parent )
00197 : QDockWidget( name, parent )
00198 {
00199 setObjectName("ViewSelectorDockWidget");
00200 setFeatures( features() & ~QDockWidget::DockWidgetClosable );
00201 m_viewList = new ViewListTreeWidget( this );
00202 setWidget( m_viewList );
00203 parent->addDockWidget( Qt::LeftDockWidgetArea, this );
00204 connect( m_viewList, SIGNAL( activated( QTreeWidgetItem* ) ), SLOT( slotActivated( QTreeWidgetItem* ) ) );
00205 }
00206
00207 void ViewListDockWidget::slotActivated( QTreeWidgetItem *item )
00208 {
00209 if ( item == 0 ) {
00210 kDebug() << k_funcinfo << "item=0" << endl;
00211 return ;
00212 }
00213 QWidget *wgt = qvariant_cast<QWidget*>( item->data( 0, Qt::UserRole ) );
00214 if ( wgt ) {
00215
00216 emit activated( wgt );
00217 } else {
00218 kDebug() << k_funcinfo << "something else" << endl;
00219
00220 }
00221 }
00222
00223 QTreeWidgetItem *ViewListDockWidget::addCategory( QString name )
00224 {
00225
00226 QTreeWidgetItem *item = m_viewList->findCategory( name );
00227 if ( item == 0 ) {
00228 item = new QTreeWidgetItem( m_viewList, QStringList( name ) );
00229 item->setExpanded( true );
00230 }
00231 return item;
00232 }
00233
00234 void ViewListDockWidget::addView( QTreeWidgetItem *category, QString name, QWidget *view, QString icon )
00235 {
00236 QTreeWidgetItem * item = new QTreeWidgetItem( category, QStringList( name ) );
00237 item->setData( 0, Qt::UserRole, qVariantFromValue( view ) );
00238 if ( !icon.isEmpty() )
00239 item->setData( 0, Qt::DecorationRole, KIcon( icon ) );
00240
00241 }
00242
00243
00244
00245 ViewBase::ViewBase(View *mainview, QWidget *parent)
00246 : QWidget(parent),
00247 m_mainview(mainview)
00248 {
00249 }
00250
00251 ViewBase::ViewBase(QWidget *parent)
00252 : QWidget(parent),
00253 m_mainview(0)
00254 {
00255 }
00256
00257 View *ViewBase::mainView() const
00258 {
00259 return m_mainview;
00260 }
00261
00262 void ViewBase::setViewActive( bool active, KXMLGUIFactory*)
00263 {
00264 if ( mainView() )
00265 mainView()->setTaskActionsEnabled( this, active );
00266 }
00267
00268 void ViewBase::addActions( KXMLGUIFactory *factory )
00269 {
00270
00271 if (factory ) {
00272 factory->addClient( this );
00273 }
00274 }
00275
00276 void ViewBase::removeActions()
00277 {
00278
00279 if ( factory() ) {
00280 factory()->removeClient( this );
00281 }
00282 }
00283
00284
00285 View::View( Part* part, QWidget* parent )
00286 : KoView( part, parent ),
00287 m_currentview(0),
00288 m_ganttview( 0 ),
00289
00290 m_currentEstimateType( Effort::Use_Expected )
00291 {
00292
00293 getProject().setCurrentSchedule( Schedule::Expected );
00294
00295 setInstance( Factory::global() );
00296 if ( !part->isReadWrite() )
00297 setXMLFile( "kplato_readonly.rc" );
00298 else
00299 setXMLFile( "kplato.rc" );
00300
00301 m_dbus = new ViewAdaptor( this );
00302 QDBusConnection::sessionBus().registerObject( "/" + objectName(), this );
00303
00304 m_tab = new QStackedWidget( this );
00305 QVBoxLayout *layout = new QVBoxLayout( this );
00306 layout->setMargin(0);
00307 layout->addWidget( m_tab );
00308
00309 m_ganttview = new GanttView( m_tab, part->isReadWrite() );
00310 m_currentview = m_ganttview;
00311 m_tab->addWidget( m_ganttview );
00312 m_updateGanttview = false;
00313 m_ganttview->draw( getProject() );
00314
00315 m_resourceview = new ResourceView( this, m_tab );
00316 m_updateResourceview = true;
00317 m_tab->addWidget( m_resourceview );
00318
00319 m_accountsview = new AccountsView( getProject(), this, m_tab );
00320 m_updateAccountsview = true;
00321 m_tab->addWidget( m_accountsview );
00322
00323 m_taskeditor = new TaskEditor( this, m_tab );
00324 m_tab->addWidget( m_taskeditor );
00325 m_taskeditor->draw( getProject() );
00326 connect( m_taskeditor, SIGNAL( addTask() ), SLOT( slotAddTask() ) );
00327 connect( m_taskeditor, SIGNAL( addMilestone() ), SLOT( slotAddMilestone() ) );
00328 connect( m_taskeditor, SIGNAL( addSubtask() ), SLOT( slotAddSubTask() ) );
00329 connect( m_taskeditor, SIGNAL( deleteTaskList( QList<Node*> ) ), SLOT( slotDeleteTask( QList<Node*> ) ) );
00330 connect( m_taskeditor, SIGNAL( moveTaskUp() ), SLOT( slotMoveTaskUp() ) );
00331 connect( m_taskeditor, SIGNAL( moveTaskDown() ), SLOT( slotMoveTaskDown() ) );
00332 connect( m_taskeditor, SIGNAL( indentTask() ), SLOT( slotIndentTask() ) );
00333 connect( m_taskeditor, SIGNAL( unindentTask() ), SLOT( slotUnindentTask() ) );
00334
00335
00336
00337
00338 createViewSelector();
00339
00340 connect( m_tab, SIGNAL( currentChanged( int ) ), this, SLOT( slotCurrentChanged( int ) ) );
00341
00342 connect( m_ganttview, SIGNAL( enableActions( bool ) ), SLOT( setTaskActionsEnabled( bool ) ) );
00343 connect( m_ganttview, SIGNAL( addRelation( Node*, Node*, int ) ), SLOT( slotAddRelation( Node*, Node*, int ) ) );
00344 connect( m_ganttview, SIGNAL( modifyRelation( Relation*, int ) ), SLOT( slotModifyRelation( Relation*, int ) ) );
00345 connect( m_ganttview, SIGNAL( modifyRelation( Relation* ) ), SLOT( slotModifyRelation( Relation* ) ) );
00346 connect( m_ganttview, SIGNAL( itemDoubleClicked() ), SLOT( slotOpenNode() ) );
00347 connect( m_ganttview, SIGNAL( itemRenamed( Node*, const QString& ) ), this, SLOT( slotRenameNode( Node*, const QString& ) ) );
00348 connect( m_ganttview, SIGNAL( requestPopupMenu( const QString&, const QPoint & ) ), this, SLOT( slotPopupMenu( const QString&, const QPoint& ) ) );
00349 connect( m_resourceview, SIGNAL( itemDoubleClicked() ), SLOT( slotEditResource() ) );
00350
00351
00352
00353 actionCut = KStdAction::cut( this, SLOT( slotEditCut() ), actionCollection(), "edit_cut" );
00354 actionCopy = KStdAction::copy( this, SLOT( slotEditCopy() ), actionCollection(), "edit_copy" );
00355 actionPaste = KStdAction::paste( this, SLOT( slotEditPaste() ), actionCollection(), "edit_paste" );
00356
00357 actionIndentTask = new KAction( KIcon( "indent_task" ), i18n( "Indent Task" ), actionCollection(), "indent_task" );
00358 connect( actionIndentTask, SIGNAL( triggered( bool ) ), SLOT( slotIndentTask() ) );
00359 actionUnindentTask = new KAction( KIcon( "unindent_task" ), i18n( "Unindent Task" ), actionCollection(), "unindent_task" );
00360 connect( actionUnindentTask, SIGNAL( triggered( bool ) ), SLOT( slotUnindentTask() ) );
00361 actionMoveTaskUp = new KAction( KIcon( "move_task_up" ), i18n( "Move Up" ), actionCollection(), "move_task_up" );
00362 connect( actionMoveTaskUp, SIGNAL( triggered( bool ) ), SLOT( slotMoveTaskUp() ) );
00363 actionMoveTaskDown = new KAction( KIcon( "move_task_down" ), i18n( "Move Down" ), actionCollection(), "move_task_down" );
00364 connect( actionMoveTaskDown, SIGNAL( triggered( bool ) ), SLOT( slotMoveTaskDown() ) );
00365
00366
00367 actionViewGantt = new KAction( KIcon( "gantt_chart" ), i18n( "Gantt" ), actionCollection(), "view_gantt" );
00368 connect( actionViewGantt, SIGNAL( triggered( bool ) ), SLOT( slotViewGantt() ) );
00369
00370 actionViewSelector = new KToggleAction( i18n( "Show Selector" ), actionCollection(), "view_show_selector" );
00371 connect( actionViewSelector, SIGNAL( triggered( bool ) ), SLOT( slotViewSelector( bool ) ) );
00372
00373 actionViewExpected = new KToggleAction( i18n( "Expected" ), actionCollection(), "view_expected" );
00374 connect( actionViewExpected, SIGNAL( triggered( bool ) ), SLOT( slotViewExpected() ) );
00375 actionViewOptimistic = new KToggleAction( i18n( "Optimistic" ), actionCollection(), "view_optimistic" );
00376 connect( actionViewOptimistic, SIGNAL( triggered( bool ) ), SLOT( slotViewOptimistic() ) );
00377 actionViewPessimistic = new KToggleAction( i18n( "Pessimistic" ), actionCollection(), "view_pessimistic" );
00378 connect( actionViewPessimistic, SIGNAL( triggered( bool ) ), SLOT( slotViewPessimistic() ) );
00379
00380 QActionGroup *estimationType = new QActionGroup( this );
00381 estimationType->setExclusive( true );
00382 estimationType->addAction( actionViewExpected );
00383 estimationType->addAction( actionViewOptimistic );
00384 estimationType->addAction( actionViewPessimistic );
00385
00386 actionViewGanttResources = new KToggleAction( i18n( "Resources" ), actionCollection(), "view_gantt_showResources" );
00387 connect( actionViewGanttResources, SIGNAL( triggered( bool ) ), SLOT( slotViewGanttResources() ) );
00388 actionViewGanttTaskName = new KToggleAction( i18n( "Task Name" ), actionCollection(), "view_gantt_showTaskName" );
00389 connect( actionViewGanttTaskName, SIGNAL( triggered( bool ) ), SLOT( slotViewGanttTaskName() ) );
00390 actionViewGanttTaskLinks = new KToggleAction( i18n( "Task Links" ), actionCollection(), "view_gantt_showTaskLinks" );
00391 connect( actionViewGanttTaskLinks, SIGNAL( triggered( bool ) ), SLOT( slotViewGanttTaskLinks() ) );
00392 actionViewGanttProgress = new KToggleAction( i18n( "Progress" ), actionCollection(), "view_gantt_showProgress" );
00393 connect( actionViewGanttProgress, SIGNAL( triggered( bool ) ), SLOT( slotViewGanttProgress() ) );
00394 actionViewGanttFloat = new KToggleAction( i18n( "Float" ), actionCollection(), "view_gantt_showFloat" );
00395 connect( actionViewGanttFloat, SIGNAL( triggered( bool ) ), SLOT( slotViewGanttFloat() ) );
00396 actionViewGanttCriticalTasks = new KToggleAction( i18n( "Critical Tasks" ), actionCollection(), "view_gantt_showCriticalTasks" );
00397 connect( actionViewGanttCriticalTasks, SIGNAL( triggered( bool ) ), SLOT( slotViewGanttCriticalTasks() ) );
00398 actionViewGanttCriticalPath = new KToggleAction( i18n( "Critical Path" ), actionCollection(), "view_gantt_showCriticalPath" );
00399 connect( actionViewGanttCriticalPath, SIGNAL( triggered( bool ) ), SLOT( slotViewGanttCriticalPath() ) );
00400
00401
00402
00403 actionViewTaskAppointments = new KToggleAction( i18n( "Show allocations" ), actionCollection(), "view_task_appointments" );
00404 connect( actionViewTaskAppointments, SIGNAL( triggered( bool ) ), SLOT( slotViewTaskAppointments() ) );
00405
00406 actionViewResources = new KAction( KIcon( "resources" ), i18n( "Resources" ), actionCollection(), "view_resources" );
00407 connect( actionViewResources, SIGNAL( triggered( bool ) ), SLOT( slotViewResources() ) );
00408
00409 actionViewResourceAppointments = new KToggleAction( i18n( "Show allocations" ), actionCollection(), "view_resource_appointments" );
00410 connect( actionViewResourceAppointments, SIGNAL( triggered( bool ) ), SLOT( slotViewResourceAppointments() ) );
00411
00412 actionViewAccounts = new KAction( KIcon( "accounts" ), i18n( "Accounts" ), actionCollection(), "view_accounts" );
00413 connect( actionViewAccounts, SIGNAL( triggered( bool ) ), SLOT( slotViewAccounts() ) );
00414
00415
00416
00417
00418 actionAddTask = new KAction( KIcon( "add_task" ), i18n( "Task..." ), actionCollection(), "add_task" );
00419 connect( actionAddTask, SIGNAL( triggered( bool ) ), SLOT( slotAddTask() ) );
00420 actionAddSubtask = new KAction( KIcon( "add_sub_task" ), i18n( "Sub-Task..." ), actionCollection(), "add_sub_task" );
00421 connect( actionAddSubtask, SIGNAL( triggered( bool ) ), SLOT( slotAddSubTask() ) );
00422 actionAddMilestone = new KAction( KIcon( "add_milestone" ), i18n( "Milestone..." ), actionCollection(), "add_milestone" );
00423 connect( actionAddMilestone, SIGNAL( triggered( bool ) ), SLOT( slotAddMilestone() ) );
00424
00425
00426 actionEditMainProject = new KAction( KIcon( "edit" ), i18n( "Edit Main Project..." ), actionCollection(), "project_edit" );
00427 connect( actionEditMainProject, SIGNAL( triggered( bool ) ), SLOT( slotProjectEdit() ) );
00428 actionEditStandardWorktime = new KAction( KIcon( "edit" ), i18n( "Edit Standard Worktime..." ), actionCollection(), "project_worktime" );
00429 connect( actionEditStandardWorktime, SIGNAL( triggered( bool ) ), SLOT( slotProjectWorktime() ) );
00430 actionEditCalendar = new KAction( KIcon( "edit" ), i18n( "Edit Calendar..." ), actionCollection(), "project_calendar" );
00431 connect( actionEditCalendar, SIGNAL( triggered( bool ) ), SLOT( slotProjectCalendar() ) );
00432 actionEditAccounts = new KAction( KIcon( "edit" ), i18n( "Edit Accounts..." ), actionCollection(), "project_accounts" );
00433 connect( actionEditAccounts, SIGNAL( triggered( bool ) ), SLOT( slotProjectAccounts() ) );
00434 actionEditResources = new KAction( KIcon( "edit" ), i18n( "Edit Resources..." ), actionCollection(), "project_resources" );
00435 connect( actionEditResources, SIGNAL( triggered( bool ) ), SLOT( slotProjectResources() ) );
00436
00437 actionCalculate = new KActionMenu( KIcon( "project_calculate" ), i18n( "Calculate" ), actionCollection(), "project_calculate" );
00438 connect( actionCalculate, SIGNAL( activated() ), SLOT( slotProjectCalculate() ) );
00439
00440 actionCalculateExpected = new KAction( i18n( "Expected" ), actionCollection(), "project_calculate_expected" );
00441 connect( actionCalculateExpected, SIGNAL( triggered( bool ) ), SLOT( slotProjectCalculateExpected() ) );
00442 actionCalculate->addAction( actionCalculateExpected );
00443
00444 actionCalculateOptimistic = new KAction( i18n( "Optimistic" ), actionCollection(), "project_calculate_optimistic" );
00445 connect( actionCalculateOptimistic, SIGNAL( triggered( bool ) ), SLOT( slotProjectCalculateOptimistic() ) );
00446 actionCalculate->addAction( actionCalculateOptimistic );
00447
00448 actionCalculatePessimistic = new KAction( i18n( "Pessimistic" ), actionCollection(), "project_calculate_pessimistic" );
00449 connect( actionCalculatePessimistic, SIGNAL( triggered( bool ) ), SLOT( slotProjectCalculatePessimistic() ) );
00450 actionCalculate->addAction( actionCalculatePessimistic );
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462 mainWindow() ->toolBar( "report" ) ->hide();
00463
00464
00465
00466
00467
00468
00469 actionDefineWBS = new KAction( KIcon( "tools_define_wbs" ), i18n( "Define WBS Pattern..." ), actionCollection(), "tools_generate_wbs" );
00470 connect( actionDefineWBS, SIGNAL( triggered( bool ) ), SLOT( slotDefineWBS() ) );
00471
00472 actionGenerateWBS = new KAction( KIcon( "tools_generate_wbs" ), i18n( "Generate WBS Code" ), actionCollection(), "tools_define_wbs" );
00473 connect( actionGenerateWBS, SIGNAL( triggered( bool ) ), SLOT( slotGenerateWBS() ) );
00474
00475
00476
00477
00478
00479
00480 actionConfigure = new KAction( KIcon( "configure" ), i18n( "Configure KPlato..." ), actionCollection(), "configure" );
00481 connect( actionConfigure, SIGNAL( triggered( bool ) ), SLOT( slotConfigure() ) );
00482
00483
00484 actionOpenNode = new KAction( KIcon( "edit" ), i18n( "Edit..." ), actionCollection(), "node_properties" );
00485 connect( actionOpenNode, SIGNAL( triggered( bool ) ), SLOT( slotOpenNode() ) );
00486 actionTaskProgress = new KAction( KIcon( "edit" ), i18n( "Progress..." ), actionCollection(), "task_progress" );
00487 connect( actionTaskProgress, SIGNAL( triggered( bool ) ), SLOT( slotTaskProgress() ) );
00488 actionDeleteTask = new KAction( KIcon( "editdelete" ), i18n( "Delete Task" ), actionCollection(), "delete_task" );
00489 connect( actionDeleteTask, SIGNAL( triggered( bool ) ), SLOT( slotDeleteTask() ) );
00490
00491 actionEditResource = new KAction( KIcon( "edit" ), i18n( "Edit Resource..." ), actionCollection(), "edit_resource" );
00492 connect( actionEditResource, SIGNAL( triggered( bool ) ), SLOT( slotEditResource() ) );
00493
00494
00495
00496 actNoInformation = new KAction( "Toggle no information", actionCollection(), "show_noinformation" );
00497 connect( actNoInformation, SIGNAL( triggered( bool ) ), SLOT( slotViewGanttNoInformation() ) );
00498 actNoInformation->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_T );
00499
00500 #ifndef NDEBUG
00501
00502 KAction *action = new KAction( "Print Debug", actionCollection(), "print_debug" );
00503 connect( action, SIGNAL( triggered( bool ) ), SLOT( slotPrintSelectedDebug() ) );
00504 action->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_P );
00505 action = new KAction( "Print Calendar Debug", actionCollection(), "print_calendar_debug" );
00506 connect( action, SIGNAL( triggered( bool ) ), SLOT( slotPrintCalendarDebug() ) );
00507 action->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_C );
00508
00509
00510 KAction *actExportGantt = new KAction( i18n( "Export Gantt" ), actionCollection(), "export_gantt" );
00511 connect( actExportGantt, SIGNAL( triggered( bool ) ), SLOT( slotExportGantt() ) );
00512 actExportGantt->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_G );
00513
00514 #endif
00515
00516 #ifndef NDEBUG
00517
00518
00519 Q_UNUSED( actExportGantt );
00520 #endif
00521
00522 m_estlabel = new KStatusBarLabel( "", 0 );
00523 addStatusBarItem( m_estlabel, 0, true );
00524 actionViewExpected->setChecked( true );
00525 setScheduleActionsEnabled();
00526 slotViewExpected();
00527
00528 setTaskActionsEnabled( false );
00529 }
00530
00531 View::~View()
00532 {
00533 removeStatusBarItem( m_estlabel );
00534 delete m_estlabel;
00535 }
00536
00537 ViewAdaptor* View::dbusObject()
00538 {
00539 return m_dbus;
00540 }
00541
00542 void View::createViewSelector()
00543 {
00544
00545 m_viewlist = new ViewListDockWidget( i18n( "Select" ), mainWindow() );
00546 QTreeWidgetItem *cat;
00547 cat = m_viewlist->addCategory(i18n("Editors"));
00548 m_viewlist->addView( cat, i18n( "Tasks" ), m_taskeditor, "task_editor" );
00549
00550 cat = m_viewlist->addCategory( i18n( "Views" ) );
00551 m_viewlist->addView( cat, i18n( "Gantt" ), m_ganttview, "gantt_chart" );
00552 m_viewlist->addView( cat, i18n( "Resources" ), m_resourceview, "resources" );
00553 m_viewlist->addView( cat, i18n( "Accounts" ), m_accountsview, "accounts" );
00554
00555
00556
00557 connect( m_viewlist, SIGNAL( activated( QWidget* ) ), SLOT( slotViewActivated( QWidget* ) ) );
00558 }
00559
00560
00561 void View::slotViewActivated( QWidget *view )
00562 {
00563
00564 if ( view ) {
00565 m_tab->setCurrentWidget( view );
00566 }
00567 }
00568
00569 Project& View::getProject() const
00570 {
00571 return getPart() ->getProject();
00572 }
00573
00574 void View::setZoom( double zoom )
00575 {
00576 m_ganttview->setZoom( zoom );
00577 }
00578
00579 void View::setupPrinter( KPrinter & )
00580 {
00581
00582 }
00583
00584 void View::print( KPrinter &printer )
00585 {
00586
00587 if ( printer.previewOnly() ) {
00588
00589 if ( !printer.setup() ) {
00590 return ;
00591 }
00592 }
00593 if ( m_tab->currentWidget() == m_ganttview ) {
00594 m_ganttview->print( printer );
00595 } else if ( m_tab->currentWidget() == m_resourceview ) {
00596 m_resourceview->print( printer );
00597 } else if ( m_tab->currentWidget() == m_accountsview ) {
00598 m_accountsview->print( printer );
00599 }
00600
00601
00602
00603
00604
00605 }
00606
00607 void View::slotEditCut()
00608 {
00609
00610 }
00611
00612 void View::slotEditCopy()
00613 {
00614
00615 }
00616
00617 void View::slotEditPaste()
00618 {
00619
00620 }
00621
00622 void View::slotViewExpected()
00623 {
00624
00625 m_currentEstimateType = Effort::Use_Expected;
00626 getProject().setCurrentSchedulePtr( getProject().findSchedule( Schedule::Expected ) );
00627 slotUpdate( false );
00628 }
00629
00630 void View::slotViewOptimistic()
00631 {
00632
00633 m_currentEstimateType = Effort::Use_Optimistic;
00634 getProject().setCurrentSchedulePtr( getProject().findSchedule( Schedule::Optimistic ) );
00635 slotUpdate( false );
00636 }
00637
00638 void View::slotViewPessimistic()
00639 {
00640
00641 m_currentEstimateType = Effort::Use_Pessimistic;
00642 getProject().setCurrentSchedulePtr( getProject().findSchedule( Schedule::Pessimistic ) );
00643 slotUpdate( false );
00644 }
00645
00646 void View::slotViewGanttResources()
00647 {
00648
00649 m_ganttview->setShowResources( actionViewGanttResources->isChecked() );
00650 if ( m_tab->currentWidget() == m_ganttview )
00651 slotUpdate( false );
00652 }
00653
00654 void View::slotViewGanttTaskName()
00655 {
00656
00657 m_ganttview->setShowTaskName( actionViewGanttTaskName->isChecked() );
00658 if ( m_tab->currentWidget() == m_ganttview )
00659 slotUpdate( false );
00660 }
00661
00662 void View::slotViewGanttTaskLinks()
00663 {
00664
00665 m_ganttview->setShowTaskLinks( actionViewGanttTaskLinks->isChecked() );
00666 if ( m_tab->currentWidget() == m_ganttview )
00667 slotUpdate( false );
00668 }
00669
00670 void View::slotViewGanttProgress()
00671 {
00672
00673 m_ganttview->setShowProgress( actionViewGanttProgress->isChecked() );
00674 if ( m_tab->currentWidget() == m_ganttview )
00675 slotUpdate( false );
00676 }
00677
00678 void View::slotViewGanttFloat()
00679 {
00680
00681 m_ganttview->setShowPositiveFloat( actionViewGanttFloat->isChecked() );
00682 if ( m_tab->currentWidget() == m_ganttview )
00683 slotUpdate( false );
00684 }
00685
00686 void View::slotViewGanttCriticalTasks()
00687 {
00688
00689 m_ganttview->setShowCriticalTasks( actionViewGanttCriticalTasks->isChecked() );
00690 if ( m_tab->currentWidget() == m_ganttview )
00691 slotUpdate( false );
00692 }
00693
00694 void View::slotViewGanttCriticalPath()
00695 {
00696
00697 m_ganttview->setShowCriticalPath( actionViewGanttCriticalPath->isChecked() );
00698 if ( m_tab->currentWidget() == m_ganttview )
00699 slotUpdate( false );
00700 }
00701
00702 void View::slotViewGanttNoInformation()
00703 {
00704 kDebug() << k_funcinfo << m_ganttview->showNoInformation() << endl;
00705 m_ganttview->setShowNoInformation( !m_ganttview->showNoInformation() );
00706 if ( m_tab->currentWidget() == m_ganttview )
00707 slotUpdate( false );
00708 }
00709
00710 void View::slotViewTaskAppointments()
00711 {
00712
00713 m_ganttview->setShowAppointments( actionViewTaskAppointments->isChecked() );
00714 m_updateGanttview = true;
00715 if ( m_tab->currentWidget() == m_ganttview )
00716 slotUpdate( false );
00717 }
00718
00719 void View::slotViewSelector( bool show )
00720 {
00721
00722 m_viewlist->setVisible( show );
00723 }
00724
00725 void View::slotViewGantt()
00726 {
00727
00728 m_tab->setCurrentWidget( m_ganttview );
00729 }
00730
00731 void View::slotViewResources()
00732 {
00733
00734 m_tab->setCurrentWidget( m_resourceview );
00735 }
00736
00737 void View::slotViewResourceAppointments()
00738 {
00739
00740 m_resourceview->setShowAppointments( actionViewResourceAppointments->isChecked() );
00741 m_updateResourceview = true;
00742 if ( m_tab->currentWidget() == m_resourceview )
00743 slotUpdate( false );
00744 }
00745
00746 void View::slotViewAccounts()
00747 {
00748
00749 m_tab->setCurrentWidget( m_accountsview );
00750 }
00751
00752 void View::slotProjectEdit()
00753 {
00754 MainProjectDialog * dia = new MainProjectDialog( getProject() );
00755 if ( dia->exec() == QDialog::Accepted) {
00756 KCommand * cmd = dia->buildCommand( getPart() );
00757 if ( cmd ) {
00758 getPart() ->addCommand( cmd );
00759 }
00760 }
00761 delete dia;
00762 }
00763
00764 void View::slotProjectCalendar()
00765 {
00766 CalendarListDialog * dia = new CalendarListDialog( getProject() );
00767 if ( dia->exec() == QDialog::Accepted) {
00768 KCommand * cmd = dia->buildCommand( getPart() );
00769 if ( cmd ) {
00770
00771 getPart() ->addCommand( cmd );
00772 }
00773 }
00774 delete dia;
00775 }
00776
00777 void View::slotProjectAccounts()
00778 {
00779 AccountsDialog * dia = new AccountsDialog( getProject().accounts() );
00780 if ( dia->exec() == QDialog::Accepted) {
00781 KCommand * cmd = dia->buildCommand( getPart() );
00782 if ( cmd ) {
00783
00784 getPart() ->addCommand( cmd );
00785 }
00786 }
00787 delete dia;
00788 }
00789
00790 void View::slotProjectWorktime()
00791 {
00792 StandardWorktimeDialog * dia = new StandardWorktimeDialog( getProject() );
00793 if ( dia->exec() == QDialog::Accepted) {
00794 KCommand * cmd = dia->buildCommand( getPart() );
00795 if ( cmd ) {
00796
00797 getPart() ->addCommand( cmd );
00798 }
00799 }
00800 delete dia;
00801 }
00802
00803 void View::slotProjectResources()
00804 {
00805 ResourcesDialog * dia = new ResourcesDialog( getProject() );
00806 if ( dia->exec() == QDialog::Accepted) {
00807 KCommand * cmd = dia->buildCommand( getPart() );
00808 if ( cmd ) {
00809
00810 getPart() ->addCommand( cmd );
00811 }
00812 }
00813 delete dia;
00814 }
00815
00816 void View::slotProjectCalculate()
00817 {
00818
00819 slotUpdate( true );
00820 }
00821
00822 void View::slotProjectCalculateExpected()
00823 {
00824 m_currentEstimateType = Effort::Use_Expected;
00825 m_updateGanttview = true;
00826 m_updateResourceview = true;
00827 m_updateAccountsview = true;
00828 slotUpdate( true );
00829 }
00830
00831 void View::slotProjectCalculateOptimistic()
00832 {
00833 m_currentEstimateType = Effort::Use_Optimistic;
00834 m_updateGanttview = true;
00835 m_updateResourceview = true;
00836 m_updateAccountsview = true;
00837 slotUpdate( true );
00838 }
00839
00840 void View::slotProjectCalculatePessimistic()
00841 {
00842 m_currentEstimateType = Effort::Use_Pessimistic;
00843 m_updateGanttview = true;
00844 m_updateResourceview = true;
00845 m_updateAccountsview = true;
00846 slotUpdate( true );
00847 }
00848
00849 void View::projectCalculate()
00850 {
00851 if ( false ) {
00852
00853 if ( KMessageBox::warningContinueCancel( this, i18n( "Progress information will be deleted if the project is recalculated." ), i18n( "Calculate" ), KGuiItem( i18n( "Calculate" ) ) ) == KMessageBox::Cancel ) {
00854 return ;
00855 }
00856 }
00857 QApplication::setOverrideCursor( Qt::WaitCursor );
00858 Schedule *ns = getProject().findSchedule( ( Schedule::Type ) m_currentEstimateType );
00859 KCommand *cmd;
00860 if ( ns ) {
00861 cmd = new RecalculateProjectCmd( getPart(), getProject(), *ns, i18n( "Calculate" ) );
00862 } else {
00863 cmd = new CalculateProjectCmd( getPart(), getProject(), i18n( "Standard" ), ( Effort::Use ) m_currentEstimateType, i18n( "Calculate" ) );
00864 }
00865 getPart() ->addCommand( cmd );
00866 QApplication::restoreOverrideCursor();
00867 }
00868
00869 void View::slotViewReportDesign()
00870 {
00871
00872 }
00873
00874 void View::slotViewReports()
00875 {
00876
00877
00878 }
00879
00880 void View::slotAddSubTask()
00881 {
00882
00883
00884
00885 Task * node = getProject().createTask( getPart() ->config().taskDefaults(), currentTask() );
00886 TaskDialog *dia = new TaskDialog( *node, getProject().accounts(), getProject().standardWorktime() );
00887 if ( dia->exec() == QDialog::Accepted) {
00888 Node * currNode = currentTask();
00889 if ( currNode ) {
00890 KCommand * m = dia->buildCommand( getPart() );
00891 m->execute();
00892 delete m;
00893 SubtaskAddCmd *cmd = new SubtaskAddCmd( getPart(), &( getProject() ), node, currNode, i18n( "Add Subtask" ) );
00894 getPart() ->addCommand( cmd );
00895 delete dia;
00896 return ;
00897 } else
00898 kDebug() << k_funcinfo << "Cannot insert new project. Hmm, no current node!?" << endl;
00899 }
00900 delete node;
00901 delete dia;
00902 }
00903
00904
00905 void View::slotAddTask()
00906 {
00907 Task * node = getProject().createTask( getPart() ->config().taskDefaults(), currentTask() );
00908 TaskDialog *dia = new TaskDialog( *node, getProject().accounts(), getProject().standardWorktime() );
00909 if ( dia->exec() == QDialog::Accepted) {
00910 Node * currNode = currentTask();
00911 if ( currNode ) {
00912 KCommand * m = dia->buildCommand( getPart() );
00913 m->execute();
00914 delete m;
00915 TaskAddCmd *cmd = new TaskAddCmd( getPart(), &( getProject() ), node, currNode, i18n( "Add Task" ) );
00916 getPart() ->addCommand( cmd );
00917 delete dia;
00918 return ;
00919 } else
00920 kDebug() << k_funcinfo << "Cannot insert new task. Hmm, no current node!?" << endl;
00921 }
00922 delete node;
00923 delete dia;
00924 }
00925
00926 void View::slotAddMilestone()
00927 {
00928 Task * node = getProject().createTask( currentTask() );
00929 node->effort() ->set
00930 ( Duration::zeroDuration );
00931
00932 TaskDialog *dia = new TaskDialog( *node, getProject().accounts(), getProject().standardWorktime() );
00933 if ( dia->exec() == QDialog::Accepted ) {
00934 Node * currNode = currentTask();
00935 if ( currNode ) {
00936 KCommand * m = dia->buildCommand( getPart() );
00937 m->execute();
00938 delete m;
00939 TaskAddCmd *cmd = new TaskAddCmd( getPart(), &( getProject() ), node, currNode, i18n( "Add Milestone" ) );
00940 getPart() ->addCommand( cmd );
00941 delete dia;
00942 return ;
00943 } else
00944 kDebug() << k_funcinfo << "Cannot insert new milestone. Hmm, no current node!?" << endl;
00945 }
00946 delete node;
00947 delete dia;
00948 }
00949
00950 void View::slotDefineWBS()
00951 {
00952
00953 WBSDefinitionDialog * dia = new WBSDefinitionDialog( getPart() ->wbsDefinition() );
00954 dia->exec();
00955
00956 delete dia;
00957 }
00958
00959 void View::slotGenerateWBS()
00960 {
00961
00962 getPart() ->generateWBS();
00963 slotUpdate( false );
00964 }
00965
00966 void View::slotConfigure()
00967 {
00968
00969 ConfigDialog * dia = new ConfigDialog( getPart() ->config(), getProject() );
00970 dia->exec();
00971 delete dia;
00972 }
00973
00974 Node *View::currentTask()
00975 {
00976 Node * task = 0;
00977 if ( m_tab->currentWidget() == m_ganttview ) {
00978 task = m_ganttview->currentNode();
00979 } else if ( m_tab->currentWidget() == m_resourceview ) {
00980 task = m_resourceview->currentNode();
00981 } else if ( m_tab->currentWidget() == m_taskeditor ) {
00982 task = m_taskeditor->selectedNode();
00983 }
00984 if ( 0 != task ) {
00985 return task;
00986 }
00987 return &( getProject() );
00988 }
00989
00990 void View::slotOpenNode()
00991 {
00992
00993 Node * node = currentTask();
00994 if ( !node )
00995 return ;
00996
00997 switch ( node->type() ) {
00998 case Node::Type_Project: {
00999 Project * project = dynamic_cast<Project *>( node );
01000 MainProjectDialog *dia = new MainProjectDialog( *project );
01001 if ( dia->exec() == QDialog::Accepted) {
01002 KCommand * m = dia->buildCommand( getPart() );
01003 if ( m ) {
01004 getPart() ->addCommand( m );
01005 }
01006 }
01007 delete dia;
01008 break;
01009 }
01010 case Node::Type_Subproject:
01011
01012 break;
01013 case Node::Type_Task: {
01014 Task *task = dynamic_cast<Task *>( node );
01015 Q_ASSERT( task );
01016 TaskDialog *dia = new TaskDialog( *task, getProject().accounts(), getProject().standardWorktime() );
01017 if ( dia->exec() == QDialog::Accepted) {
01018 KCommand * m = dia->buildCommand( getPart() );
01019 if ( m ) {
01020 getPart() ->addCommand( m );
01021 }
01022 }
01023 delete dia;
01024 break;
01025 }
01026 case Node::Type_Milestone: {
01027
01028
01029
01030
01031 Task *task = dynamic_cast<Task *>( node );
01032 Q_ASSERT( task );
01033 TaskDialog *dia = new TaskDialog( *task, getProject().accounts(), getProject().standardWorktime() );
01034 if ( dia->exec() == QDialog::Accepted) {
01035 KCommand * m = dia->buildCommand( getPart() );
01036 if ( m ) {
01037 getPart() ->addCommand( m );
01038 }
01039 }
01040 delete dia;
01041 break;
01042 }
01043 case Node::Type_Summarytask: {
01044 Task *task = dynamic_cast<Task *>( node );
01045 Q_ASSERT( task );
01046 SummaryTaskDialog *dia = new SummaryTaskDialog( *task );
01047 if ( dia->exec() == QDialog::Accepted) {
01048 KCommand * m = dia->buildCommand( getPart() );
01049 if ( m ) {
01050 getPart() ->addCommand( m );
01051 }
01052 }
01053 delete dia;
01054 break;
01055 }
01056 default:
01057 break;
01058 }
01059 }
01060
01061 void View::slotTaskProgress()
01062 {
01063
01064 Node * node = currentTask();
01065 if ( !node )
01066 return ;
01067
01068 switch ( node->type() ) {
01069 case Node::Type_Project: {
01070 break;
01071 }
01072 case Node::Type_Subproject:
01073
01074 break;
01075 case Node::Type_Task: {
01076 Task *task = dynamic_cast<Task *>( node );
01077 Q_ASSERT( task );
01078 TaskProgressDialog *dia = new TaskProgressDialog( *task, getProject().standardWorktime() );
01079 if ( dia->exec() == QDialog::Accepted) {
01080 KCommand * m = dia->buildCommand( getPart() );
01081 if ( m ) {
01082 getPart() ->addCommand( m );
01083 }
01084 }
01085 delete dia;
01086 break;
01087 }
01088 case Node::Type_Milestone: {
01089 Task *task = dynamic_cast<Task *>( node );
01090 MilestoneProgressDialog *dia = new MilestoneProgressDialog( *task );
01091 if ( dia->exec() == QDialog::Accepted) {
01092 KCommand * m = dia->buildCommand( getPart() );
01093 if ( m ) {
01094 getPart() ->addCommand( m );
01095 }
01096 }
01097 delete dia;
01098 break;
01099 }
01100 case Node::Type_Summarytask: {
01101
01102 break;
01103 }
01104 default:
01105 break;
01106 }
01107 }
01108
01109 void View::slotDeleteTask( QList<Node*> lst )
01110 {
01111
01112 if ( lst.count() == 1 ) {
01113 slotDeleteTask( lst.takeFirst() );
01114 return;
01115 }
01116 int num = 0;
01117 KMacroCommand *cmd = new KMacroCommand( i18n( "Delete Tasks" ) );
01118 while ( !lst.isEmpty() ) {
01119 Node *node = lst.takeFirst();
01120 if ( node == 0 || node->getParent() == 0 ) {
01121 kDebug() << k_funcinfo << ( node ? "Task is main project" : "No current task" ) << endl;
01122 continue;
01123 }
01124 bool del = true;
01125 foreach ( Node *n, lst ) {
01126 if ( node->isChildOf( n ) ) {
01127 del = false;
01128 break;
01129 }
01130 }
01131 if ( del ) {
01132
01133 cmd->addCommand( new NodeDeleteCmd( getPart(), node, i18n( "Delete Task" ) ) );
01134 num++;
01135 }
01136 }
01137 if ( num > 0 ) {
01138 getPart()->addCommand( cmd );
01139 } else {
01140 delete cmd;
01141 }
01142 }
01143
01144 void View::slotDeleteTask( Node *node )
01145 {
01146
01147 if ( node == 0 || node->getParent() == 0 ) {
01148 kDebug() << k_funcinfo << ( node ? "Task is main project" : "No current task" ) << endl;
01149 return ;
01150 }
01151 NodeDeleteCmd *cmd = new NodeDeleteCmd( getPart(), node, i18n( "Delete Task" ) );
01152 getPart() ->addCommand( cmd );
01153 }
01154
01155 void View::slotDeleteTask()
01156 {
01157
01158 return slotDeleteTask( currentTask() );
01159 }
01160
01161 void View::slotIndentTask()
01162 {
01163
01164 Node * node = currentTask();
01165 if ( node == 0 || node->getParent() == 0 ) {
01166 kDebug() << k_funcinfo << ( node ? "Task is main project" : "No current task" ) << endl;
01167 return ;
01168 }
01169 if ( getProject().canIndentTask( node ) ) {
01170 NodeIndentCmd * cmd = new NodeIndentCmd( getPart(), *node, i18n( "Indent Task" ) );
01171 getPart() ->addCommand( cmd );
01172 }
01173 }
01174
01175 void View::slotUnindentTask()
01176 {
01177
01178 Node * node = currentTask();
01179 if ( node == 0 || node->getParent() == 0 ) {
01180 kDebug() << k_funcinfo << ( node ? "Task is main project" : "No current task" ) << endl;
01181 return ;
01182 }
01183 if ( getProject().canUnindentTask( node ) ) {
01184 NodeUnindentCmd * cmd = new NodeUnindentCmd( getPart(), *node, i18n( "Unindent Task" ) );
01185 getPart() ->addCommand( cmd );
01186 }
01187 }
01188
01189 void View::slotMoveTaskUp()
01190 {
01191
01192
01193 Node * task = currentTask();
01194 if ( 0 == task ) {
01195
01196
01197 kError() << k_funcinfo << "No current task" << endl;
01198 return ;
01199 }
01200
01201 if ( Node::Type_Project == task->type() ) {
01202 kDebug() << k_funcinfo << "The root node cannot be moved up" << endl;
01203 return ;
01204 }
01205 if ( getProject().canMoveTaskUp( task ) ) {
01206 NodeMoveUpCmd * cmd = new NodeMoveUpCmd( getPart(), *task, i18n( "Move Task Up" ) );
01207 getPart() ->addCommand( cmd );
01208 }
01209 }
01210
01211 void View::slotMoveTaskDown()
01212 {
01213
01214
01215 Node * task = currentTask();
01216 if ( 0 == task ) {
01217
01218
01219 return ;
01220 }
01221
01222 if ( Node::Type_Project == task->type() ) {
01223 kDebug() << k_funcinfo << "The root node cannot be moved down" << endl;
01224 return ;
01225 }
01226 if ( getProject().canMoveTaskDown( task ) ) {
01227 NodeMoveDownCmd * cmd = new NodeMoveDownCmd( getPart(), *task, i18n( "Move Task Down" ) );
01228 getPart() ->addCommand( cmd );
01229 }
01230 }
01231
01232 void View::slotAddRelation( Node *par, Node *child )
01233 {
01234
01235 Relation * rel = new Relation( par, child );
01236 AddRelationDialog *dia = new AddRelationDialog( rel, this );
01237 if ( dia->exec() == QDialog::Accepted) {
01238 KCommand * cmd = dia->buildCommand( getPart() );
01239 if ( cmd )
01240 getPart() ->addCommand( cmd );
01241 } else {
01242 delete rel;
01243 }
01244 delete dia;
01245 }
01246
01247 void View::slotAddRelation( Node *par, Node *child, int linkType )
01248 {
01249
01250 if ( linkType == Relation::FinishStart ||
01251 linkType == Relation::StartStart ||
01252 linkType == Relation::FinishFinish ) {
01253 Relation * rel = new Relation( par, child, static_cast<Relation::Type>( linkType ) );
01254 getPart() ->addCommand( new AddRelationCmd( getPart(), rel, i18n( "Add Relation" ) ) );
01255 } else {
01256 slotAddRelation( par, child );
01257 }
01258 }
01259
01260 void View::slotModifyRelation( Relation *rel )
01261 {
01262
01263 ModifyRelationDialog * dia = new ModifyRelationDialog( rel, this );
01264 if ( dia->exec() == QDialog::Accepted) {
01265 if ( dia->relationIsDeleted() ) {
01266 getPart() ->addCommand( new DeleteRelationCmd( getPart(), rel, i18n( "Delete Relation" ) ) );
01267 } else {
01268 KCommand *cmd = dia->buildCommand( getPart() );
01269 if ( cmd ) {
01270 getPart() ->addCommand( cmd );
01271 }
01272 }
01273 }
01274 delete dia;
01275 }
01276
01277 void View::slotModifyRelation( Relation *rel, int linkType )
01278 {
01279
01280 if ( linkType == Relation::FinishStart ||
01281 linkType == Relation::StartStart ||
01282 linkType == Relation::FinishFinish ) {
01283 getPart() ->addCommand( new ModifyRelationTypeCmd( getPart(), rel, static_cast<Relation::Type>( linkType ) ) );
01284 } else {
01285 slotModifyRelation( rel );
01286 }
01287 }
01288
01289
01290 void View::slotExportGantt()
01291 {
01292
01293 if ( !m_ganttview ) {
01294 return ;
01295 }
01296 QString fn = KFileDialog::getSaveFileName( KUrl(),
01297 QString::null, this );
01298 if ( !fn.isEmpty() ) {
01299 QFile f( fn );
01300 m_ganttview->exportGantt( &f );
01301 }
01302 }
01303
01304 void View::slotEditResource()
01305 {
01306
01307 Resource * r = m_resourceview->currentResource();
01308 if ( !r )
01309 return ;
01310 ResourceDialog *dia = new ResourceDialog( getProject(), r );
01311 if ( dia->exec() == QDialog::Accepted) {
01312 KCommand * cmd = dia->buildCommand( getPart() );
01313 if ( cmd )
01314 getPart() ->addCommand( cmd );
01315 }
01316 delete dia;
01317 }
01318
01319 void View::updateReadWrite( bool )
01320 {}
01321
01322 Part *View::getPart() const
01323 {
01324 return ( Part * ) koDocument();
01325 }
01326
01327 void View::slotConnectNode()
01328 {
01329
01330
01331
01332
01333
01334 }
01335
01336 QMenu * View::popupMenu( const QString& name )
01337 {
01338
01339 Q_ASSERT( factory() );
01340 if ( factory() )
01341 return ( ( QMenu* ) factory() ->container( name, this ) );
01342 return 0L;
01343 }
01344
01345 void View::slotUpdate( bool calculate )
01346 {
01347
01348 if ( calculate )
01349 projectCalculate();
01350
01351 m_updateGanttview = true;
01352 m_updateResourceview = true;
01353 m_updateAccountsview = true;
01354
01355 updateView( m_tab->currentWidget() );
01356 }
01357
01358 void View::slotCurrentChanged( int index )
01359 {
01360
01361 if (m_currentview)
01362 m_currentview->setViewActive( false );
01363 m_currentview = static_cast<ViewBase*>( m_tab->currentWidget() );
01364 updateView( m_currentview );
01365 m_currentview->setViewActive( true, factory() );
01366 m_currentview->setFocus( Qt::ActiveWindowFocusReason );
01367
01368 }
01369
01370 void View::updateView( QWidget *widget )
01371 {
01372 QApplication::setOverrideCursor( Qt::WaitCursor );
01373 setScheduleActionsEnabled();
01374 setTaskActionsEnabled( false );
01375 mainWindow() ->toolBar( "report" ) ->hide();
01376 if ( widget == m_ganttview ) {
01377
01378 m_ganttview->setShowExpected( actionViewExpected->isChecked() );
01379 m_ganttview->setShowOptimistic( actionViewOptimistic->isChecked() );
01380 m_ganttview->setShowPessimistic( actionViewPessimistic->isChecked() );
01381 if ( m_updateGanttview )
01382 m_ganttview->drawChanges( getProject() );
01383 setTaskActionsEnabled( widget, true );
01384 m_updateGanttview = false;
01385 } else if ( widget == m_resourceview ) {
01386
01387 if ( m_updateResourceview )
01388 m_resourceview->draw( getPart() ->getProject() );
01389 m_updateResourceview = false;
01390 } else if ( widget == m_accountsview ) {
01391
01392 if ( m_updateAccountsview )
01393 m_accountsview->draw();
01394 m_updateAccountsview = false;
01395 } else if ( widget == m_taskeditor ) {
01396
01397 }
01398
01399
01400
01401
01402
01403 QApplication::restoreOverrideCursor();
01404 }
01405
01406 void View::slotRenameNode( Node *node, const QString& name )
01407 {
01408
01409 if ( node ) {
01410 NodeModifyNameCmd * cmd = new NodeModifyNameCmd( getPart(), *node, name, i18n( "Modify Name" ) );
01411 getPart() ->addCommand( cmd );
01412 }
01413 }
01414
01415 void View::slotPopupMenu( const QString& menuname, const QPoint & pos )
01416 {
01417 QMenu * menu = this->popupMenu( menuname );
01418 if ( menu )
01419 menu->exec( pos );
01420 }
01421
01422 bool View::setContext( Context &context )
01423 {
01424
01425 m_currentEstimateType = context.currentEstimateType;
01426 getProject().setCurrentSchedule( context.currentSchedule );
01427 actionViewExpected->setChecked( context.actionViewExpected );
01428 actionViewOptimistic->setChecked( context.actionViewOptimistic );
01429 actionViewPessimistic->setChecked( context.actionViewPessimistic );
01430
01431 m_ganttview->setContext( context.ganttview, getProject() );
01432
01433 actionViewGanttResources->setChecked( context.ganttview.showResources );
01434 actionViewGanttTaskName->setChecked( context.ganttview.showTaskName );
01435 actionViewGanttTaskLinks->setChecked( context.ganttview.showTaskLinks );
01436 actionViewGanttProgress->setChecked( context.ganttview.showProgress );
01437 actionViewGanttFloat->setChecked( context.ganttview.showPositiveFloat );
01438 actionViewGanttCriticalTasks->setChecked( context.ganttview.showCriticalTasks );
01439 actionViewGanttCriticalPath->setChecked( context.ganttview.showCriticalPath );
01440
01441 m_resourceview->setContext( context.resourceview );
01442 m_accountsview->setContext( context.accountsview );
01443
01444
01445 if ( context.currentView == "ganttview" ) {
01446 m_ganttview->setShowExpected( actionViewExpected->isChecked() );
01447 m_ganttview->setShowOptimistic( actionViewOptimistic->isChecked() );
01448 m_ganttview->setShowPessimistic( actionViewPessimistic->isChecked() );
01449 slotViewGantt();
01450 } else if ( context.currentView == "resourceview" ) {
01451 slotViewResources();
01452 } else if ( context.currentView == "accountsview" ) {
01453 slotViewAccounts();
01454 } else if ( context.currentView == "reportview" ) {
01455
01456 } else {
01457 slotViewGantt();
01458 }
01459 slotUpdate( false );
01460 return true;
01461 }
01462
01463 void View::getContext( Context &context ) const
01464 {
01465
01466 context.currentEstimateType = m_currentEstimateType;
01467 if ( getProject().currentSchedule() )
01468 context.currentSchedule = getProject().currentSchedule() ->id();
01469 context.actionViewExpected = actionViewExpected->isChecked();
01470 context.actionViewOptimistic = actionViewOptimistic->isChecked();
01471 context.actionViewPessimistic = actionViewPessimistic->isChecked();
01472
01473 if ( m_tab->currentWidget() == m_ganttview ) {
01474 context.currentView = "ganttview";
01475 } else if ( m_tab->currentWidget() == m_resourceview ) {
01476 context.currentView = "resourceview";
01477 } else if ( m_tab->currentWidget() == m_accountsview ) {
01478 context.currentView = "accountsview";
01479
01480
01481 }
01482 m_ganttview->getContext( context.ganttview );
01483 m_resourceview->getContext( context.resourceview );
01484 m_accountsview->getContext( context.accountsview );
01485
01486 }
01487
01488
01489 void View::setTaskActionsEnabled( QWidget *w, bool on )
01490 {
01491 Node * n = 0;
01492 if ( w == m_ganttview ) {
01493 n = m_ganttview->currentNode();
01494 } else {
01495 on = false;
01496 }
01497
01498 actionAddTask->setEnabled( on );
01499 actionAddMilestone->setEnabled( on );
01500
01501 bool o = ( on && n );
01502 actionAddSubtask->setEnabled( o );
01503 actionDeleteTask->setEnabled( o );
01504 actionMoveTaskUp->setEnabled( o && getProject().canMoveTaskUp( n ) );
01505 actionMoveTaskDown->setEnabled( o && getProject().canMoveTaskDown( n ) );
01506 actionIndentTask->setEnabled( o && getProject().canIndentTask( n ) );
01507 actionUnindentTask->setEnabled( o && getProject().canUnindentTask( n ) );
01508 }
01509
01510 void View::setTaskActionsEnabled( bool on )
01511 {
01512 setTaskActionsEnabled( m_ganttview, on );
01513 }
01514
01515 void View::setScheduleActionsEnabled()
01516 {
01517 actionViewExpected->setEnabled( getProject().findSchedule( Schedule::Expected ) );
01518 actionViewOptimistic->setEnabled( getProject().findSchedule( Schedule::Optimistic ) );
01519 actionViewPessimistic->setEnabled( getProject().findSchedule( Schedule::Pessimistic ) );
01520 if ( getProject().notScheduled() ) {
01521 m_estlabel->setText( i18n( "Not scheduled" ) );
01522 return ;
01523 }
01524 Schedule *ns = getProject().currentSchedule();
01525 if ( ns->type() == Schedule::Expected ) {
01526 actionViewExpected->setChecked( true );
01527 m_estlabel->setText( i18n( "Expected" ) );
01528 } else if ( ns->type() == Schedule::Optimistic ) {
01529 actionViewOptimistic->setChecked( true );
01530 m_estlabel->setText( i18n( "Optimistic" ) );
01531 } else if ( ns->type() == Schedule::Pessimistic ) {
01532 actionViewPessimistic->setChecked( true );
01533 m_estlabel->setText( i18n( "Pessimistic" ) );
01534 }
01535 }
01536
01537
01538 #ifndef NDEBUG
01539 void View::slotPrintDebug()
01540 {
01541 kDebug() << "-------- Debug printout: Node list" << endl;
01542
01543
01544
01545
01546 getPart() ->getProject().printDebug( true, "" );
01547 }
01548 void View::slotPrintSelectedDebug()
01549 {
01550 Node * curr = m_ganttview->currentNode();
01551 if ( curr ) {
01552 kDebug() << "-------- Debug printout: Selected node" << endl;
01553 curr->printDebug( true, "" );
01554 } else
01555 slotPrintDebug();
01556 }
01557 void View::slotPrintCalendarDebug()
01558 {
01559 kDebug() << "-------- Debug printout: Node list" << endl;
01560
01561
01562
01563
01564 getPart() ->getProject().printCalendarDebug( "" );
01565 }
01566 void View::slotPrintTestDebug()
01567 {
01568 const QStringList & lst = getPart() ->xmlLoader().log();
01569
01570 for ( QStringList::ConstIterator it = lst.constBegin(); it != lst.constEnd(); ++it ) {
01571 kDebug() << *it << endl;
01572 }
01573
01574
01575
01576
01577
01578
01579
01580
01581
01582
01583
01584
01585
01586
01587
01588
01589
01590
01591
01592
01593
01594
01595
01596
01597
01598
01599
01600
01601
01602
01603
01604
01605
01606
01607
01608
01609
01610
01611
01612
01613
01614
01615
01616
01617
01618
01619
01620
01621
01622
01623
01624
01625
01626
01627
01628
01629
01630
01631
01632
01633
01634
01635
01636
01637
01638
01639
01640
01641
01642
01643
01644
01645
01646
01647
01648
01649
01650
01651
01652
01653
01654
01655
01656
01657
01658
01659
01660
01661
01662
01663
01664
01665
01666
01667
01668
01669
01670
01671
01672
01673
01674
01675
01676
01677
01678
01679
01680
01681
01682
01683
01684
01685
01686
01687
01688
01689
01690
01691
01692
01693
01694
01695
01696
01697
01698
01699
01700
01701
01702
01703
01704
01705
01706
01707
01708
01709
01710
01711
01712
01713
01714
01715
01716
01717
01718
01719
01720
01721
01722
01723
01724
01725
01726
01727
01728
01729
01730
01731
01732
01733
01734
01735
01736
01737
01738
01739
01740
01741
01742
01743
01744
01745
01746
01747
01748
01749
01750
01751
01752
01753
01754
01755
01756
01757
01758
01759
01760
01761
01762
01763
01764
01765
01766
01767
01768
01769
01770
01771
01772
01773
01774
01775
01776
01777
01778
01779
01780
01781
01782
01783
01784
01785
01786
01787
01788
01789
01790
01791
01792
01793
01794
01795 }
01796 #endif
01797
01798 }
01799
01800 #include "kptview.moc"