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

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002   Copyright (C) 1998, 1999, 2000 Torben Weis <weis@kde.org>
00003   Copyright (C) 2002 - 2006 Dag Andersen <danders@get2net.dk>
00004 
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Library General Public
00007   License as published by the Free Software Foundation; either
00008   version 2 of the License, or (at your option) any later version.
00009 
00010   This library is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013   Library General Public License for more details.
00014 
00015   You should have received a copy of the GNU Library General Public License
00016   along with this library; see the file COPYING.LIB.  If not, write to
00017   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018 * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include <kprinter.h>
00022 #include <kmessagebox.h>
00023 
00024 #include <KoMainWindow.h>
00025 #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 //#include "kptreportview.h"
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 // <Code mostly nicked from qt designer ;)>
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         // this is a top-level item.
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; // ### hardcoded in qcommonstyle.cpp
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         // draw text
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         //kDebug() << k_funcinfo << "widget: " << wgt << endl;
00216         emit activated( wgt );
00217     } else {
00218         kDebug() << k_funcinfo << "something else" << endl;
00219         //emit activated(item);
00220     }
00221 }
00222 
00223 QTreeWidgetItem *ViewListDockWidget::addCategory( QString name )
00224 {
00225     //kDebug() << k_funcinfo << endl;
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     //kDebug() << k_funcinfo << "added: " << item << endl;
00241 }
00242 // </Code mostly nicked from qt designer ;)>
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*) // slot
00263 {
00264     if ( mainView() )
00265         mainView()->setTaskActionsEnabled( this, active );
00266 }
00267 
00268 void ViewBase::addActions( KXMLGUIFactory *factory )
00269 {
00270     //kDebug()<<k_funcinfo<<this<<endl;
00271     if (factory ) {
00272         factory->addClient( this );
00273     }
00274 }
00275 
00276 void ViewBase::removeActions()
00277 {
00278     //kDebug()<<k_funcinfo<<this<<endl;
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         //    m_reportview(0),
00290         m_currentEstimateType( Effort::Use_Expected )
00291 {
00292     //kDebug()<<k_funcinfo<<endl;
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     //m_reportview = new ReportView(this, m_tab);
00336     //m_tab->addWidget(m_reportview);
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     // The menu items
00352     // ------ Edit
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     // ------ View
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     //    actionViewGanttNotScheduled = new KToggleAction(i18n("Not Scheduled"), 0, 0, this, SLOT(slotViewGanttNotScheduled()), actionCollection(), "view_gantt_showNotScheduled");
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     //actionViewReports = new KAction(i18n("Reports"), "reports", 0, this, SLOT(slotViewReports()), actionCollection(), "view_reports");
00416 
00417     // ------ Insert
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     // ------ Project
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     /*    // ------ Reports
00453         actionFirstpage = KStdAction::firstPage(m_reportview,SLOT(slotPrevPage()),actionCollection(),"go_firstpage");
00454         connect(m_reportview, SIGNAL(setFirstPageActionEnabled(bool)), actionFirstpage, SLOT(setEnabled(bool)));
00455         actionPriorpage = KStdAction::prior(m_reportview,SLOT(slotPrevPage()),actionCollection(),"go_prevpage");
00456         connect(m_reportview, SIGNAL(setPriorPageActionEnabled(bool)), actionPriorpage, SLOT(setEnabled(bool)));
00457         actionNextpage = KStdAction::next(m_reportview,SLOT(slotNextPage()),actionCollection(), "go_nextpage");
00458         connect(m_reportview, SIGNAL(setNextPageActionEnabled(bool)), actionNextpage, SLOT(setEnabled(bool)));
00459         actionLastpage = KStdAction::lastPage(m_reportview,SLOT(slotLastPage()),actionCollection(), "go_lastpage");
00460         connect(m_reportview, SIGNAL(setLastPageActionEnabled(bool)), actionLastpage, SLOT(setEnabled(bool)));
00461         m_reportview->enableNavigationBtn();*/
00462     mainWindow() ->toolBar( "report" ) ->hide();
00463 
00464     //     new KAction(i18n("Design..."), "report_design", 0, this,
00465     //         SLOT(slotReportDesign()), actionCollection(), "report_design");
00466 
00467 
00468     // ------ Tools
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     // ------ Export (testing)
00476     //actionExportGantt = new KAction(i18n("Export Ganttview"), "export_gantt", 0, this,
00477     //    SLOT(slotExportGantt()), actionCollection(), "export_gantt");
00478 
00479     // ------ Settings
00480     actionConfigure = new KAction( KIcon( "configure" ), i18n( "Configure KPlato..." ), actionCollection(), "configure" );
00481     connect( actionConfigure, SIGNAL( triggered( bool ) ), SLOT( slotConfigure() ) );
00482 
00483     // ------ Popup
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     // ------------------- Actions with a key binding and no GUI item
00495     // Temporary, till we get a menu entry
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     //new KAction("Print Debug", CTRL+Qt::SHIFT+Qt::Key_P, this, SLOT( slotPrintDebug()), actionCollection(), "print_debug");
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     //     new KAction("Print Test Debug", CTRL+Qt::SHIFT+Qt::Key_T, this, SLOT(slotPrintTestDebug()), actionCollection(), "print_test_debug");
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     // Stupid compilers ;)
00516 #ifndef NDEBUG 
00517     /*  Q_UNUSED( actPrintSelectedDebug );
00518         Q_UNUSED( actPrintCalendarDebug );*/
00519     Q_UNUSED( actExportGantt );
00520 #endif
00521 
00522     m_estlabel = new KStatusBarLabel( "", 0 );
00523     addStatusBarItem( m_estlabel, 0, true );
00524     actionViewExpected->setChecked( true ); //TODO: context
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     //kDebug() << k_funcinfo << endl;
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     //    cat = m_viewlist->addCategory(i18n("Reports"));
00556 
00557     connect( m_viewlist, SIGNAL( activated( QWidget* ) ), SLOT( slotViewActivated( QWidget* ) ) );
00558 }
00559 
00560 
00561 void View::slotViewActivated( QWidget *view )
00562 {
00563     //kDebug() << k_funcinfo << "view=" << view << endl;
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 & /*printer*/ )
00580 {
00581     //kDebug()<<k_funcinfo<<endl;
00582 }
00583 
00584 void View::print( KPrinter &printer )
00585 {
00586     //kDebug()<<k_funcinfo<<endl;
00587     if ( printer.previewOnly() ) {
00588         //HACK: KoMainWindow shows setup on print, but not on print preview!
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     //  else if (m_tab->currentWidget() == m_reportview)
00601     //  {
00602     //         m_reportview->print(printer);
00603     //  }
00604 
00605 }
00606 
00607 void View::slotEditCut()
00608 {
00609     //kDebug()<<k_funcinfo<<endl;
00610 }
00611 
00612 void View::slotEditCopy()
00613 {
00614     //kDebug()<<k_funcinfo<<endl;
00615 }
00616 
00617 void View::slotEditPaste()
00618 {
00619     //kDebug()<<k_funcinfo<<endl;
00620 }
00621 
00622 void View::slotViewExpected()
00623 {
00624     //kDebug()<<k_funcinfo<<endl;
00625     m_currentEstimateType = Effort::Use_Expected;
00626     getProject().setCurrentSchedulePtr( getProject().findSchedule( Schedule::Expected ) );
00627     slotUpdate( false );
00628 }
00629 
00630 void View::slotViewOptimistic()
00631 {
00632     //kDebug()<<k_funcinfo<<endl;
00633     m_currentEstimateType = Effort::Use_Optimistic;
00634     getProject().setCurrentSchedulePtr( getProject().findSchedule( Schedule::Optimistic ) );
00635     slotUpdate( false );
00636 }
00637 
00638 void View::slotViewPessimistic()
00639 {
00640     //kDebug()<<k_funcinfo<<endl;
00641     m_currentEstimateType = Effort::Use_Pessimistic;
00642     getProject().setCurrentSchedulePtr( getProject().findSchedule( Schedule::Pessimistic ) );
00643     slotUpdate( false );
00644 }
00645 
00646 void View::slotViewGanttResources()
00647 {
00648     //kDebug()<<k_funcinfo<<endl;
00649     m_ganttview->setShowResources( actionViewGanttResources->isChecked() );
00650     if ( m_tab->currentWidget() == m_ganttview )
00651         slotUpdate( false );
00652 }
00653 
00654 void View::slotViewGanttTaskName()
00655 {
00656     //kDebug()<<k_funcinfo<<endl;
00657     m_ganttview->setShowTaskName( actionViewGanttTaskName->isChecked() );
00658     if ( m_tab->currentWidget() == m_ganttview )
00659         slotUpdate( false );
00660 }
00661 
00662 void View::slotViewGanttTaskLinks()
00663 {
00664     //kDebug()<<k_funcinfo<<endl;
00665     m_ganttview->setShowTaskLinks( actionViewGanttTaskLinks->isChecked() );
00666     if ( m_tab->currentWidget() == m_ganttview )
00667         slotUpdate( false );
00668 }
00669 
00670 void View::slotViewGanttProgress()
00671 {
00672     //kDebug()<<k_funcinfo<<endl;
00673     m_ganttview->setShowProgress( actionViewGanttProgress->isChecked() );
00674     if ( m_tab->currentWidget() == m_ganttview )
00675         slotUpdate( false );
00676 }
00677 
00678 void View::slotViewGanttFloat()
00679 {
00680     //kDebug()<<k_funcinfo<<endl;
00681     m_ganttview->setShowPositiveFloat( actionViewGanttFloat->isChecked() );
00682     if ( m_tab->currentWidget() == m_ganttview )
00683         slotUpdate( false );
00684 }
00685 
00686 void View::slotViewGanttCriticalTasks()
00687 {
00688     //kDebug()<<k_funcinfo<<endl;
00689     m_ganttview->setShowCriticalTasks( actionViewGanttCriticalTasks->isChecked() );
00690     if ( m_tab->currentWidget() == m_ganttview )
00691         slotUpdate( false );
00692 }
00693 
00694 void View::slotViewGanttCriticalPath()
00695 {
00696     //kDebug()<<k_funcinfo<<endl;
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() ); //Toggle
00706     if ( m_tab->currentWidget() == m_ganttview )
00707         slotUpdate( false );
00708 }
00709 
00710 void View::slotViewTaskAppointments()
00711 {
00712     //kDebug()<<k_funcinfo<<endl;
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     //kDebug()<<k_funcinfo<<endl;
00722     m_viewlist->setVisible( show );
00723 }
00724 
00725 void View::slotViewGantt()
00726 {
00727     //kDebug()<<k_funcinfo<<endl;
00728     m_tab->setCurrentWidget( m_ganttview );
00729 }
00730 
00731 void View::slotViewResources()
00732 {
00733     //kDebug()<<k_funcinfo<<endl;
00734     m_tab->setCurrentWidget( m_resourceview );
00735 }
00736 
00737 void View::slotViewResourceAppointments()
00738 {
00739     //kDebug()<<k_funcinfo<<endl;
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     //kDebug()<<k_funcinfo<<endl;
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             //kDebug()<<k_funcinfo<<"Modifying calendar(s)"<<endl;
00771             getPart() ->addCommand( cmd ); //also executes
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             //kDebug()<<k_funcinfo<<"Modifying account(s)"<<endl;
00784             getPart() ->addCommand( cmd ); //also executes
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             //kDebug()<<k_funcinfo<<"Modifying calendar(s)"<<endl;
00797             getPart() ->addCommand( cmd ); //also executes
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             //kDebug()<<k_funcinfo<<"Modifying resources"<<endl;
00810             getPart() ->addCommand( cmd ); //also executes
00811         }
00812     }
00813     delete dia;
00814 }
00815 
00816 void View::slotProjectCalculate()
00817 {
00818     //kDebug()<<k_funcinfo<<endl;
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 /*getProject().actualEffort() > 0*/ ) {
00852         // NOTE: This can be removed when proper baselining etc is implemented
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     //kDebug()<<k_funcinfo<<endl;
00872 }
00873 
00874 void View::slotViewReports()
00875 {
00876     //kDebug()<<k_funcinfo<<endl;
00877     //m_tab->setCurrentWidget(m_reportview);
00878 }
00879 
00880 void View::slotAddSubTask()
00881 {
00882     // If we are positionend on the root project, then what we really want to
00883     // do is to add a first project. We will silently accept the challenge
00884     // and will not complain.
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(); // do changes to task
00892             delete m;
00893             SubtaskAddCmd *cmd = new SubtaskAddCmd( getPart(), &( getProject() ), node, currNode, i18n( "Add Subtask" ) );
00894             getPart() ->addCommand( cmd ); // add task to project
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(); // do changes to task
00914             delete m;
00915             TaskAddCmd *cmd = new TaskAddCmd( getPart(), &( getProject() ), node, currNode, i18n( "Add Task" ) );
00916             getPart() ->addCommand( cmd ); // add task to project
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(); // do changes to task
00938             delete m;
00939             TaskAddCmd *cmd = new TaskAddCmd( getPart(), &( getProject() ), node, currNode, i18n( "Add Milestone" ) );
00940             getPart() ->addCommand( cmd ); // add task to project
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     //kDebug()<<k_funcinfo<<endl;
00953     WBSDefinitionDialog * dia = new WBSDefinitionDialog( getPart() ->wbsDefinition() );
00954     dia->exec();
00955 
00956     delete dia;
00957 }
00958 
00959 void View::slotGenerateWBS()
00960 {
00961     //kDebug()<<k_funcinfo<<endl;
00962     getPart() ->generateWBS();
00963     slotUpdate( false );
00964 }
00965 
00966 void View::slotConfigure()
00967 {
00968     //kDebug()<<k_funcinfo<<endl;
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     //kDebug()<<k_funcinfo<<endl;
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             //TODO
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                 // Use the normal task dialog for now.
01028                 // Maybe milestone should have it's own dialog, but we need to be able to
01029                 // enter a duration in case we accidentally set a tasks duration to zero
01030                 // and hence, create a milestone
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; // avoid warnings
01058     }
01059 }
01060 
01061 void View::slotTaskProgress()
01062 {
01063     //kDebug()<<k_funcinfo<<endl;
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             //TODO
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                 // TODO
01102                 break;
01103             }
01104         default:
01105             break; // avoid warnings
01106     }
01107 }
01108 
01109 void View::slotDeleteTask( QList<Node*> lst )
01110 {
01111     //kDebug()<<k_funcinfo<<endl;
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; // node is going to be deleted when we delete n
01128                 break;
01129             }
01130         }
01131         if ( del ) {
01132             //kDebug()<<k_funcinfo<<num<<": delete: "<<node->name()<<endl;
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     //kDebug()<<k_funcinfo<<endl;
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     //kDebug()<<k_funcinfo<<endl;
01158     return slotDeleteTask( currentTask() );
01159 }
01160 
01161 void View::slotIndentTask()
01162 {
01163     //kDebug()<<k_funcinfo<<endl;
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     //kDebug()<<k_funcinfo<<endl;
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     //kDebug()<<k_funcinfo<<endl;
01192 
01193     Node * task = currentTask();
01194     if ( 0 == task ) {
01195         // is always != 0. At least we would get the Project, but you never know who might change that
01196         // so better be careful
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     //kDebug()<<k_funcinfo<<endl;
01214 
01215     Node * task = currentTask();
01216     if ( 0 == task ) {
01217         // is always != 0. At least we would get the Project, but you never know who might change that
01218         // so better be careful
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     //kDebug()<<k_funcinfo<<endl;
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     //kDebug()<<k_funcinfo<<endl;
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     //kDebug()<<k_funcinfo<<endl;
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     //kDebug()<<k_funcinfo<<endl;
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 // testing
01290 void View::slotExportGantt()
01291 {
01292     //kDebug()<<k_funcinfo<<endl;
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     //kDebug()<<k_funcinfo<<endl;
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 /*readwrite*/ )
01320 {}
01321 
01322 Part *View::getPart() const
01323 {
01324     return ( Part * ) koDocument();
01325 }
01326 
01327 void View::slotConnectNode()
01328 {
01329     //kDebug()<<k_funcinfo<<endl;
01330     /*    NodeItem *curr = m_ganttview->currentItem();
01331         if (curr) {
01332             kDebug()<<k_funcinfo<<"node="<<curr->getNode().name()<<endl;
01333         }*/
01334 }
01335 
01336 QMenu * View::popupMenu( const QString& name )
01337 {
01338     //kDebug()<<k_funcinfo<<endl;
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     //kDebug()<<k_funcinfo<<"calculate="<<calculate<<endl;
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     //kDebug()<<k_funcinfo<<m_currentview<<endl;
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     //kDebug()<<k_funcinfo<<m_currentview<<endl;
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         //kDebug()<<k_funcinfo<<"draw gantt"<<endl;
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         //kDebug()<<k_funcinfo<<"draw resourceview"<<endl;
01387         if ( m_updateResourceview )
01388             m_resourceview->draw( getPart() ->getProject() );
01389         m_updateResourceview = false;
01390     } else if ( widget == m_accountsview ) {
01391         //kDebug()<<k_funcinfo<<"draw accountsview"<<endl;
01392         if ( m_updateAccountsview )
01393             m_accountsview->draw();
01394         m_updateAccountsview = false;
01395     } else if ( widget == m_taskeditor ) {
01396         //kDebug()<<k_funcinfo<<"draw taskeditor"<<endl;
01397     }
01398     /*    else if (widget == m_reportview)
01399         {
01400             mainWindow()->toolBar("report")->show();
01401             m_reportview->enableNavigationBtn();
01402         }*/
01403     QApplication::restoreOverrideCursor();
01404 }
01405 
01406 void View::slotRenameNode( Node *node, const QString& name )
01407 {
01408     //kDebug()<<k_funcinfo<<name<<endl;
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     //kDebug()<<k_funcinfo<<endl;
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     // hmmm, can't decide if these should be here or actions moved to ganttview
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     //    m_reportview->setContext(context.reportview);
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         //slotViewReport();
01456     } else {
01457         slotViewGantt();
01458     }
01459     slotUpdate( false );
01460     return true;
01461 }
01462 
01463 void View::getContext( Context &context ) const
01464 {
01465     //kDebug()<<k_funcinfo<<endl;
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         /*    } else if (m_tab->currentWidget() == m_reportview) {
01480                 context.currentView = "reportview";*/
01481     }
01482     m_ganttview->getContext( context.ganttview );
01483     m_resourceview->getContext( context.resourceview );
01484     m_accountsview->getContext( context.accountsview );
01485     //    m_reportview->getContext(context.reportview);
01486 }
01487 
01488 // called when widget w is about to be shown
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     // only enabled when we have a task selected
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 ); //FIXME if more than ganttview can do this
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     /*    Node *curr = m_ganttview->currentNode();
01543         if (curr) {
01544             curr->printDebug(true,"");
01545         } else*/
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     /*    Node *curr = m_ganttview->currentNode();
01561         if (curr) {
01562             curr->printDebug(true,"");
01563         } else*/
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     //     kDebug()<<"------------Test 1---------------------"<<endl;
01574     //     {
01575     //     DateTime d1(QDate(2006,1,2), QTime(8,0,0));
01576     //     DateTime d2 = d1.addSecs(3600);
01577     //     Duration d = d2 - d1;
01578     //     bool b = d==Duration(0,0,0,3600);
01579     //     kDebug()<<"1: Success="<<b<<"    "<<d2.toString()<<"-"<<d1.toString()<<"="<<d.toString()<<endl;
01580     //     d = d1 - d2;
01581     //     b = d==Duration(0,0,0,3600);
01582     //     kDebug()<<"2: Success="<<b<<"    "<<d1.toString()<<"-"<<d2.toString()<<"="<<d.toString()<<endl;
01583     //     d2 = d2.addDays(-2);
01584     //     d = d1 - d2;
01585     //     b = d==Duration(2,0,0)-Duration(0,0,0,3600);
01586     //     kDebug()<<"3: Success="<<b<<"    "<<d1.toString()<<"-"<<d2.toString()<<"="<<d.toString()<<endl;
01587     //     d = d2 - d1;
01588     //     b = d==Duration(2,0,0)-Duration(0,0,0,3600);
01589     //     kDebug()<<"4: Success="<<b<<"     "<<d2.toString()<<"-"<<d1.toString()<<"="<<d.toString()<<endl;
01590     //     kDebug()<<endl;
01591     //     b = (d2 + d)==d1;
01592     //     kDebug()<<"5: Success="<<b<<"   "<<d2<<"+"<<d.toString()<<"="<<d1<<endl;
01593     //     b = (d1 - d)==d2;
01594     //     kDebug()<<"6: Success="<<b<<"   "<<d1<<"-"<<d.toString()<<"="<<d2<<endl;
01595     //     } // end test 1
01596     //     kDebug()<<endl;
01597     //     kDebug()<<"------------Test 2 Single calendar-----------------"<<endl;
01598     //     {
01599     //     Calendar *t = new Calendar("Test 2");
01600     //     QDate wdate(2006,1,2);
01601     //     DateTime before = DateTime(wdate.addDays(-1));
01602     //     DateTime after = DateTime(wdate.addDays(1));
01603     //     QTime t1(8,0,0);
01604     //     QTime t2(10,0,0);
01605     //     DateTime wdt1(wdate, t1);
01606     //     DateTime wdt2(wdate, t2);
01607     //     CalendarDay *day = new CalendarDay(QDate(2006,1,2), Map::Working);
01608     //     day->addInterval(TimeInterval(t1, t2));
01609     //     if (!t->addDay(day)) {
01610     //         kDebug()<<"Failed to add day"<<endl;
01611     //         delete day;
01612     //         delete t;
01613     //         return;
01614     //     }
01615     //     kDebug()<<"Added     date="<<day->date().toString()<<" "<<day->startOfDay().toString()<<" - "<<day->endOfDay()<<endl;
01616     //     kDebug()<<"Found     date="<<day->date().toString()<<" "<<day->startOfDay().toString()<<" - "<<day->endOfDay()<<endl;
01617     //
01618     //     CalendarDay *d = t->findDay(wdate);
01619     //     bool b = (day == d);
01620     //     kDebug()<<"1: Success="<<b<<"      Find same day"<<endl;
01621     //
01622     //     DateTime dt = t->firstAvailableAfter(after, after.addDays(10));
01623     //     b = !dt.isValid();
01624     //     kDebug()<<"2: Success="<<b<<"      firstAvailableAfter("<<after<<"): ="<<dt<<endl;
01625     //
01626     //     dt = t->firstAvailableBefore(before, before.addDays(-10));
01627     //     b = !dt.isValid();
01628     //     kDebug()<<"3: Success="<<b<<"       firstAvailableBefore("<<before.toString()<<"): ="<<dt<<endl;
01629     //
01630     //     dt = t->firstAvailableAfter(before, after);
01631     //     b = dt == wdt1;
01632     //     kDebug()<<"4: Success="<<b<<"      firstAvailableAfter("<<before<<"): ="<<dt<<endl;
01633     //
01634     //     dt = t->firstAvailableBefore(after, before);
01635     //     b = dt == wdt2;
01636     //     kDebug()<<"5: Success="<<b<<"      firstAvailableBefore("<<after<<"): ="<<dt<<endl;
01637     //
01638     //     b = t->hasInterval(before, after);
01639     //     kDebug()<<"6: Success="<<b<<"      hasInterval("<<before<<", "<<after<<")"<<endl;
01640     //
01641     //     b = !t->hasInterval(after, after.addDays(1));
01642     //     kDebug()<<"7: Success="<<b<<"      !hasInterval("<<after<<", "<<after.addDays(1)<<")"<<endl;
01643     //
01644     //     b = !t->hasInterval(before, before.addDays(-1));
01645     //     kDebug()<<"8: Success="<<b<<"      !hasInterval("<<before<<", "<<before.addDays(-1)<<")"<<endl;
01646     //
01647     //     Duration e1(0, 2, 0); // 2 hours
01648     //     Duration e2 = t->effort(before, after);
01649     //     b = e1==e2;
01650     //     kDebug()<<"9: Success="<<b<<"      effort"<<e1.toString()<<" = "<<e2.toString()<<endl;
01651     //
01652     //     delete t;
01653     //     }// end test 2
01654     //
01655     //     kDebug()<<endl;
01656     //     kDebug()<<"------------Test 3 Parent calendar-----------------"<<endl;
01657     //     {
01658     //     Calendar *t = new Calendar("Test 3");
01659     //     Calendar *p = new Calendar("Test 3 parent");
01660     //     t->setParent(p);
01661     //     QDate wdate(2006,1,2);
01662     //     DateTime before = DateTime(wdate.addDays(-1));
01663     //     DateTime after = DateTime(wdate.addDays(1));
01664     //     QTime t1(8,0,0);
01665     //     QTime t2(10,0,0);
01666     //     DateTime wdt1(wdate, t1);
01667     //     DateTime wdt2(wdate, t2);
01668     //     CalendarDay *day = new CalendarDay(QDate(2006,1,2), Map::Working);
01669     //     day->addInterval(TimeInterval(t1, t2));
01670     //     if (!p->addDay(day)) {
01671     //         kDebug()<<"Failed to add day"<<endl;
01672     //         delete day;
01673     //         delete t;
01674     //         return;
01675     //     }
01676     //     kDebug()<<"Added     date="<<day->date().toString()<<" "<<day->startOfDay().toString()<<" - "<<day->endOfDay().toString()<<endl;
01677     //     kDebug()<<"Found     date="<<day->date().toString()<<" "<<day->startOfDay().toString()<<" - "<<day->endOfDay().toString()<<endl;
01678     //
01679     //     CalendarDay *d = p->findDay(wdate);
01680     //     bool b = (day == d);
01681     //     kDebug()<<"1: Success="<<b<<"      Find same day"<<endl;
01682     //
01683     //     DateTime dt = t->firstAvailableAfter(after, after.addDays(10));
01684     //     b = !dt.isValid();
01685     //     kDebug()<<"2: Success="<<b<<"      firstAvailableAfter("<<after.toString()<<"): ="<<!b<<endl;
01686     //
01687     //     dt = t->firstAvailableBefore(before, before.addDays(-10));
01688     //     b = !dt.isValid();
01689     //     kDebug()<<"3: Success="<<b<<"       firstAvailableBefore("<<before.toString()<<"): ="<<!b<<endl;
01690     //
01691     //     dt = t->firstAvailableAfter(before, after);
01692     //     b = dt == wdt1;
01693     //     kDebug()<<"4: Success="<<b<<"      firstAvailableAfter("<<before.toString()<<"): ="<<dt.toString()<<endl;
01694     //
01695     //     dt = t->firstAvailableBefore(after, before);
01696     //     b = dt == wdt2;
01697     //     kDebug()<<"5: Success="<<b<<"      firstAvailableBefore("<<after.toString()<<"): ="<<dt.toString()<<endl;
01698     //
01699     //     b = t->hasInterval(before, after);
01700     //     kDebug()<<"6: Success="<<b<<"      hasInterval("<<before.toString()<<", "<<after<<")"<<endl;
01701     //
01702     //     b = !t->hasInterval(after, after.addDays(1));
01703     //     kDebug()<<"7: Success="<<b<<"      !hasInterval("<<after.toString()<<", "<<after.addDays(1)<<")"<<endl;
01704     //
01705     //     b = !t->hasInterval(before, before.addDays(-1));
01706     //     kDebug()<<"8: Success="<<b<<"      !hasInterval("<<before.toString()<<", "<<before.addDays(-1)<<")"<<endl;
01707     //     Duration e1(0, 2, 0); // 2 hours
01708     //     Duration e2 = t->effort(before, after);
01709     //     b = e1==e2;
01710     //     kDebug()<<"9: Success="<<b<<"      effort "<<e1.toString()<<"=="<<e2.toString()<<endl;
01711     //
01712     //     delete t;
01713     //     delete p;
01714     //     }// end test 3
01715     //     kDebug()<<endl;
01716     //     kDebug()<<"------------Test 4 Parent calendar/weekdays-------------"<<endl;
01717     //     {
01718     //     QTime t1(8,0,0);
01719     //     QTime t2(10,0,0);
01720     //     Calendar *p = new Calendar("Test 4 parent");
01721     //     CalendarDay *wd1 = p->weekday(0); // monday
01722     //     if (wd1 == 0) {
01723     //         kDebug()<<"Failed to get weekday"<<endl;
01724     //     }
01725     //     wd1->setState(Map::NonWorking);
01726     //
01727     //     CalendarDay *wd2 = p->weekday(2); // wednesday
01728     //     if (wd2 == 0) {
01729     //         kDebug()<<"Failed to get weekday"<<endl;
01730     //     }
01731     //     wd2->addInterval(TimeInterval(t1, t2));
01732     //     wd2->setState(Map::Working);
01733     //
01734     //     Calendar *t = new Calendar("Test 4");
01735     //     t->setParent(p);
01736     //     QDate wdate(2006,1,2); // monday jan 2
01737     //     DateTime before = DateTime(wdate.addDays(-4)); //Thursday dec 29
01738     //     DateTime after = DateTime(wdate.addDays(4)); // Friday jan 6
01739     //     DateTime wdt1(wdate, t1);
01740     //     DateTime wdt2(QDate(2006, 1, 4), t2); // Wednesday
01741     //     CalendarDay *day = new CalendarDay(QDate(2006,1,2), Map::Working);
01742     //     day->addInterval(TimeInterval(t1, t2));
01743     //     if (!p->addDay(day)) {
01744     //         kDebug()<<"Failed to add day"<<endl;
01745     //         delete day;
01746     //         delete t;
01747     //         return;
01748     //     }
01749     //     kDebug()<<"Added     date="<<day->date().toString()<<" "<<day->startOfDay().toString()<<" - "<<day->endOfDay().toString()<<endl;
01750     //     kDebug()<<"Found     date="<<day->date().toString()<<" "<<day->startOfDay().toString()<<" - "<<day->endOfDay().toString()<<endl;
01751     //
01752     //     CalendarDay *d = p->findDay(wdate);
01753     //     bool b = (day == d);
01754     //     kDebug()<<"1: Success="<<b<<"      Find same day"<<endl;
01755     //
01756     //     DateTime dt = t->firstAvailableAfter(after, after.addDays(10));
01757     //     b = (dt.isValid() && dt == DateTime(QDate(2006,1,11), t1));
01758     //     kDebug()<<"2: Success="<<b<<"      firstAvailableAfter("<<after<<"): ="<<dt<<endl;
01759     //
01760     //     dt = t->firstAvailableBefore(before, before.addDays(-10));
01761     //     b = (dt.isValid() && dt == DateTime(QDate(2005, 12, 28), t2));
01762     //     kDebug()<<"3: Success="<<b<<"       firstAvailableBefore("<<before.toString()<<"): ="<<dt<<endl;
01763     //
01764     //     dt = t->firstAvailableAfter(before, after);
01765     //     b = dt == wdt1; // We find the day jan 2
01766     //     kDebug()<<"4: Success="<<b<<"      firstAvailableAfter("<<before.toString()<<"): ="<<dt.toString()<<endl;
01767     //
01768     //     dt = t->firstAvailableBefore(after, before);
01769     //     b = dt == wdt2; // We find the weekday (wednesday)
01770     //     kDebug()<<"5: Success="<<b<<"      firstAvailableBefore("<<after.toString()<<"): ="<<dt.toString()<<endl;
01771     //
01772     //     b = t->hasInterval(before, after);
01773     //     kDebug()<<"6: Success="<<b<<"      hasInterval("<<before.toString()<<", "<<after<<")"<<endl;
01774     //
01775     //     b = !t->hasInterval(after, after.addDays(1));
01776     //     kDebug()<<"7: Success="<<b<<"      !hasInterval("<<after.toString()<<", "<<after.addDays(1)<<")"<<endl;
01777     //
01778     //     b = !t->hasInterval(before, before.addDays(-1));
01779     //     kDebug()<<"8: Success="<<b<<"      !hasInterval("<<before.toString()<<", "<<before.addDays(-1)<<")"<<endl;
01780     //     Duration e1(0, 4, 0); // 2 hours
01781     //     Duration e2 = t->effort(before, after);
01782     //     b = e1==e2;
01783     //     kDebug()<<"9: Success="<<b<<"      effort "<<e1.toString()<<"="<<e2.toString()<<endl;
01784     //
01785     //     DateTimeInterval r = t->firstInterval(before, after);
01786     //     b = r.first == wdt1; // We find the monday jan 2
01787     //     kDebug()<<"10: Success="<<b<<"      firstInterval("<<before<<"): ="<<r.first<<", "<<r.second<<endl;
01788     //     r = t->firstInterval(r.second, after);
01789     //     b = r.first == DateTime(QDate(2006, 1, 4),t1); // We find the wednesday jan 4
01790     //     kDebug()<<"11: Success="<<b<<"      firstInterval("<<r.second<<"): ="<<r.first<<", "<<r.second<<endl;
01791     //
01792     //     delete t;
01793     //     delete p;
01794     //     }// end test 4
01795 }
01796 #endif
01797 
01798 }  //KPlato namespace
01799 
01800 #include "kptview.moc"

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