summaryrefslogtreecommitdiffabout
path: root/korganizer/kotodoview.cpp
authorzautrix <zautrix>2005-08-06 09:54:42 (UTC)
committer zautrix <zautrix>2005-08-06 09:54:42 (UTC)
commitb841f4f2d54ac531c1f9ec88852d31307b9145f2 (patch) (unidiff)
treec334106e75e73bbc3fc33cd3c0d6480314a42774 /korganizer/kotodoview.cpp
parentcd215c243d0636cabbc73006652b9b6783319de1 (diff)
downloadkdepimpi-b841f4f2d54ac531c1f9ec88852d31307b9145f2.zip
kdepimpi-b841f4f2d54ac531c1f9ec88852d31307b9145f2.tar.gz
kdepimpi-b841f4f2d54ac531c1f9ec88852d31307b9145f2.tar.bz2
fixes
Diffstat (limited to 'korganizer/kotodoview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kotodoview.cpp46
1 files changed, 30 insertions, 16 deletions
diff --git a/korganizer/kotodoview.cpp b/korganizer/kotodoview.cpp
index 00c2d97..27d755e 100644
--- a/korganizer/kotodoview.cpp
+++ b/korganizer/kotodoview.cpp
@@ -493,25 +493,26 @@ void KOQuickTodo::focusInEvent(QFocusEvent *ev)
493} 493}
494 494
495void KOQuickTodo::focusOutEvent(QFocusEvent *ev) 495void KOQuickTodo::focusOutEvent(QFocusEvent *ev)
496{ 496{
497 setText(i18n("Click to add new Todo")); 497 setText(i18n("Click to add new Todo"));
498 QLineEdit::focusOutEvent(ev); 498 QLineEdit::focusOutEvent(ev);
499} 499}
500 500
501///////////////////////////////////////////////////////////////////////////// 501/////////////////////////////////////////////////////////////////////////////
502 502
503KOTodoView::KOTodoView(Calendar *calendar,QWidget* parent,const char* name) : 503KOTodoView::KOTodoView(Calendar *calendar,QWidget* parent,const char* name) :
504 KOrg::BaseView(calendar,parent,name) 504 KOrg::BaseView(calendar,parent,name)
505{ 505{
506 mActiveItem = 0;
506 mCategoryPopupMenu = 0; 507 mCategoryPopupMenu = 0;
507 mPendingUpdateBeforeRepaint = false; 508 mPendingUpdateBeforeRepaint = false;
508 isFlatDisplay = false; 509 isFlatDisplay = false;
509 mNavigator = 0; 510 mNavigator = 0;
510 QBoxLayout *topLayout = new QVBoxLayout(this); 511 QBoxLayout *topLayout = new QVBoxLayout(this);
511 mName = QString ( name ); 512 mName = QString ( name );
512 mBlockUpdate = false; 513 mBlockUpdate = false;
513 mQuickBar = new QWidget( this ); 514 mQuickBar = new QWidget( this );
514 topLayout->addWidget(mQuickBar); 515 topLayout->addWidget(mQuickBar);
515 516
516 mQuickAdd = new KOQuickTodo(mQuickBar); 517 mQuickAdd = new KOQuickTodo(mQuickBar);
517 QBoxLayout *quickLayout = new QHBoxLayout(mQuickBar); 518 QBoxLayout *quickLayout = new QHBoxLayout(mQuickBar);
@@ -798,46 +799,56 @@ void KOTodoView::paintNeeded()
798 mPendingUpdateBeforeRepaint = false; 799 mPendingUpdateBeforeRepaint = false;
799 } 800 }
800} 801}
801void KOTodoView::paintEvent(QPaintEvent * pevent) 802void KOTodoView::paintEvent(QPaintEvent * pevent)
802{ 803{
803 if ( mPendingUpdateBeforeRepaint ) { 804 if ( mPendingUpdateBeforeRepaint ) {
804 updateView(); 805 updateView();
805 mPendingUpdateBeforeRepaint = false; 806 mPendingUpdateBeforeRepaint = false;
806 } 807 }
807 KOrg::BaseView::paintEvent( pevent); 808 KOrg::BaseView::paintEvent( pevent);
808} 809}
809 810
811void KOTodoView::clearList( bool saveCurrentItem ) // default true
812{
813 if ( mTodoListView->childCount() ) {
814 if ( saveCurrentItem )
815 storeCurrentItem();
816 mTodoListView->clear();
817 mTodoMap.clear();
818 }
819}
810void KOTodoView::updateView() 820void KOTodoView::updateView()
811{ 821{
822 mActiveItem = 0;
812 pendingSubtodo = 0; 823 pendingSubtodo = 0;
813 if ( mBlockUpdate ) { 824 if ( mBlockUpdate ) {
814 return; 825 return;
815 } 826 }
816 if ( !isVisible() ) { 827 if ( !isVisible() ) {
817 mPendingUpdateBeforeRepaint = true; 828 clearList ();
818 return; 829 mPendingUpdateBeforeRepaint = true;
830 return;
819 } 831 }
820 //qDebug("KOTodoView::updateView() %x", this); 832 //qDebug("KOTodoView::updateView() %x", this);
821 if ( isFlatDisplay ) { 833 if ( isFlatDisplay ) {
822 displayAllFlat(); 834 displayAllFlat();
823 return; 835 return;
824 } 836 }
825 storeCurrentItem();
826 //qDebug("update "); 837 //qDebug("update ");
827// kdDebug() << "KOTodoView::updateView()" << endl; 838// kdDebug() << "KOTodoView::updateView()" << endl;
828 QFont fo = KOPrefs::instance()->mTodoViewFont; 839 QFont fo = KOPrefs::instance()->mTodoViewFont;
829 840
830 841 clearList ();
831 mTodoListView->clear(); 842
832 if ( mName == "todolistsmall" ) { 843 if ( mName == "todolistsmall" ) {
833 if ( KOPrefs::instance()->mTodoViewUsesSmallFont ) { 844 if ( KOPrefs::instance()->mTodoViewUsesSmallFont ) {
834 int ps = fo.pointSize() -2; 845 int ps = fo.pointSize() -2;
835 if ( ps > 12 ) 846 if ( ps > 12 )
836 ps -= 2; 847 ps -= 2;
837 fo.setPointSize( ps ); 848 fo.setPointSize( ps );
838 } 849 }
839 } 850 }
840 851
841 mTodoListView->setFont( fo ); 852 mTodoListView->setFont( fo );
842 // QFontMetrics fm ( KOPrefs::instance()->mTodoViewFont ); 853 // QFontMetrics fm ( KOPrefs::instance()->mTodoViewFont );
843 //mTodoListView->header()->setMaximumHeight(fm.height()); 854 //mTodoListView->header()->setMaximumHeight(fm.height());
@@ -855,25 +866,24 @@ void KOTodoView::updateView()
855 866
856 QPtrList<Event> l = t->getRelations(); 867 QPtrList<Event> l = t->getRelations();
857 Event *c; 868 Event *c;
858 for(c=l.first();c;c=l.next()) { 869 for(c=l.first();c;c=l.next()) {
859 kdDebug() << " - relation: " << c->getSummary() << endl; 870 kdDebug() << " - relation: " << c->getSummary() << endl;
860 } 871 }
861 } 872 }
862*/ 873*/
863 874
864 // Put for each Event a KOTodoViewItem in the list view. Don't rely on a 875 // Put for each Event a KOTodoViewItem in the list view. Don't rely on a
865 // specific order of events. That means that we have to generate parent items 876 // specific order of events. That means that we have to generate parent items
866 // recursively for proper hierarchical display of Todos. 877 // recursively for proper hierarchical display of Todos.
867 mTodoMap.clear();
868 Todo *todo; 878 Todo *todo;
869 todo = todoList.first();// todo; todo = todoList.next()) { 879 todo = todoList.first();// todo; todo = todoList.next()) {
870 while ( todo ) { 880 while ( todo ) {
871 bool next = true; 881 bool next = true;
872 // qDebug("todo %s ", todo->summary().latin1()); 882 // qDebug("todo %s ", todo->summary().latin1());
873 Incidence *incidence = todo->relatedTo(); 883 Incidence *incidence = todo->relatedTo();
874 while ( incidence ) { 884 while ( incidence ) {
875 if ( incidence->typeID() == todoID ) { 885 if ( incidence->typeID() == todoID ) {
876 //qDebug("related %s ",incidence->summary().latin1() ); 886 //qDebug("related %s ",incidence->summary().latin1() );
877 if ( !(todoList.contains ( ((Todo* )incidence ) ) ) && incidence->calEnabled() ) { 887 if ( !(todoList.contains ( ((Todo* )incidence ) ) ) && incidence->calEnabled() ) {
878 //qDebug("related not found "); 888 //qDebug("related not found ");
879 todoList.remove( ); 889 todoList.remove( );
@@ -965,25 +975,26 @@ void KOTodoView::resetCurrentItem()
965 if ( foundItem ) { 975 if ( foundItem ) {
966 mTodoListView->setSelected ( foundItem, true ); 976 mTodoListView->setSelected ( foundItem, true );
967 mTodoListView->setCurrentItem( foundItem ); 977 mTodoListView->setCurrentItem( foundItem );
968 mTodoListView->ensureItemVisible( foundItem ); 978 mTodoListView->ensureItemVisible( foundItem );
969 } else { 979 } else {
970 if ( mTodoListView->firstChild () ) { 980 if ( mTodoListView->firstChild () ) {
971 mTodoListView->setSelected ( mTodoListView->firstChild (), true ); 981 mTodoListView->setSelected ( mTodoListView->firstChild (), true );
972 mTodoListView->setCurrentItem( mTodoListView->firstChild () ); 982 mTodoListView->setCurrentItem( mTodoListView->firstChild () );
973 } 983 }
974 } 984 }
975 } 985 }
976 processSelectionChange(); 986 processSelectionChange();
977 QTimer::singleShot( 100, this, SLOT ( resetFocusToList() )); 987 if ( mName != "todolistsmall" )
988 QTimer::singleShot( 100, this, SLOT ( resetFocusToList() ));
978} 989}
979void KOTodoView::resetFocusToList() 990void KOTodoView::resetFocusToList()
980{ 991{
981 topLevelWidget()->setActiveWindow(); 992 topLevelWidget()->setActiveWindow();
982 mTodoListView->setFocus(); 993 mTodoListView->setFocus();
983} 994}
984//Incidence * mCurItem, *mCurItemRootParent,*mCurItemAbove; 995//Incidence * mCurItem, *mCurItemRootParent,*mCurItemAbove;
985bool KOTodoView::checkTodo( Todo * todo ) 996bool KOTodoView::checkTodo( Todo * todo )
986{ 997{
987 998
988 if ( !KOPrefs::instance()->mShowCompletedTodo && todo->isCompleted() ) 999 if ( !KOPrefs::instance()->mShowCompletedTodo && todo->isCompleted() )
989 return false; 1000 return false;
@@ -1091,30 +1102,32 @@ void KOTodoView::showEvents(QPtrList<Event>)
1091} 1102}
1092 1103
1093void KOTodoView::printPreview(CalPrinter *calPrinter, const QDate &fd, 1104void KOTodoView::printPreview(CalPrinter *calPrinter, const QDate &fd,
1094 const QDate &td) 1105 const QDate &td)
1095{ 1106{
1096#ifndef KORG_NOPRINTER 1107#ifndef KORG_NOPRINTER
1097 calPrinter->preview(CalPrinter::Todolist, fd, td); 1108 calPrinter->preview(CalPrinter::Todolist, fd, td);
1098#endif 1109#endif
1099} 1110}
1100 1111
1101void KOTodoView::editItem(QListViewItem *item ) 1112void KOTodoView::editItem(QListViewItem *item )
1102{ 1113{
1103 emit editTodoSignal(((KOTodoViewItem *)item)->todo()); 1114 if ( item )
1115 emit editTodoSignal(((KOTodoViewItem *)item)->todo());
1104} 1116}
1105 1117
1106void KOTodoView::showItem(QListViewItem *item,const QPoint &,int) 1118void KOTodoView::showItem(QListViewItem *item,const QPoint &,int)
1107{ 1119{
1108 emit showTodoSignal(((KOTodoViewItem *)item)->todo()); 1120 if ( item )
1121 emit showTodoSignal(((KOTodoViewItem *)item)->todo());
1109} 1122}
1110 1123
1111void KOTodoView::popupMenu(QListViewItem *item,const QPoint &p,int column) 1124void KOTodoView::popupMenu(QListViewItem *item,const QPoint &p,int column)
1112{ 1125{
1113 pendingSubtodo = 0; 1126 pendingSubtodo = 0;
1114 mActiveItem = (KOTodoViewItem *)item; 1127 mActiveItem = (KOTodoViewItem *)item;
1115 if (item) { 1128 if (item) {
1116 switch (column){ 1129 switch (column){
1117 case 1: 1130 case 1:
1118 mPriorityPopupMenu->popup(QCursor::pos ()); break; 1131 mPriorityPopupMenu->popup(QCursor::pos ()); break;
1119 case 2: 1132 case 2:
1120 mPercentageCompletedPopupMenu->popup(QCursor::pos ()); break; 1133 mPercentageCompletedPopupMenu->popup(QCursor::pos ()); break;
@@ -1348,42 +1361,42 @@ void KOTodoView::toggleRunningItem()
1348 return; 1361 return;
1349 Todo * t = mActiveItem->todo(); 1362 Todo * t = mActiveItem->todo();
1350 if ( t->isRunning() ) { 1363 if ( t->isRunning() ) {
1351 KOStopTodoPrefs tp ( t, this ); 1364 KOStopTodoPrefs tp ( t, this );
1352 if (QApplication::desktop()->width() <= 800 ){ 1365 if (QApplication::desktop()->width() <= 800 ){
1353 int wid = tp.width(); 1366 int wid = tp.width();
1354 int hei = tp.height(); 1367 int hei = tp.height();
1355 int xx = (QApplication::desktop()->width()-wid)/2; 1368 int xx = (QApplication::desktop()->width()-wid)/2;
1356 int yy = (QApplication::desktop()->height()-hei)/2; 1369 int yy = (QApplication::desktop()->height()-hei)/2;
1357 tp.setGeometry( xx,yy,wid,hei ); 1370 tp.setGeometry( xx,yy,wid,hei );
1358 } 1371 }
1359 tp.exec(); 1372 tp.exec();
1360 updateTodo ( t, 0 ); 1373 updateTodo ( t, KOGlobals::EVENTEDITED );
1361 } else { 1374 } else {
1362 KOStartTodoPrefs tp ( t->summary(), this ); 1375 KOStartTodoPrefs tp ( t->summary(), this );
1363 if (QApplication::desktop()->width() <= 800 ){ 1376 if (QApplication::desktop()->width() <= 800 ){
1364 int wid = tp.width(); 1377 int wid = tp.width();
1365 int hei = tp.height(); 1378 int hei = tp.height();
1366 int xx = (QApplication::desktop()->width()-wid)/2; 1379 int xx = (QApplication::desktop()->width()-wid)/2;
1367 int yy = (QApplication::desktop()->height()-hei)/2; 1380 int yy = (QApplication::desktop()->height()-hei)/2;
1368 tp.setGeometry( xx,yy,wid,hei ); 1381 tp.setGeometry( xx,yy,wid,hei );
1369 } 1382 }
1370 if ( !tp.exec() ) return; 1383 if ( !tp.exec() ) return;
1371 if ( tp.stopAll() ) { 1384 if ( tp.stopAll() ) {
1372 mCalendar->stopAllTodos(); 1385 mCalendar->stopAllTodos();
1373 t->setRunning( true ); 1386 t->setRunning( true );
1374 updateView(); 1387 updateView();
1375 } else { 1388 } else {
1376 t->setRunning( true ); 1389 t->setRunning( true );
1377 updateTodo ( t, 0 ); 1390 updateTodo ( t, KOGlobals::EVENTEDITED );
1378 } 1391 }
1379 } 1392 }
1380} 1393}
1381 1394
1382void KOTodoView::itemClicked(QListViewItem *item) 1395void KOTodoView::itemClicked(QListViewItem *item)
1383{ 1396{
1384 //qDebug("KOTodoView::itemClicked %d", item); 1397 //qDebug("KOTodoView::itemClicked %d", item);
1385 if (!item) { 1398 if (!item) {
1386 if ( pendingSubtodo != 0 ) { 1399 if ( pendingSubtodo != 0 ) {
1387 topLevelWidget()->setCaption(i18n("Reparenting aborted!")); 1400 topLevelWidget()->setCaption(i18n("Reparenting aborted!"));
1388 } 1401 }
1389 pendingSubtodo = 0; 1402 pendingSubtodo = 0;
@@ -1496,34 +1509,34 @@ void KOTodoView::setAllClose()
1496void KOTodoView::setOpen( QListViewItem* item, bool setOpenI) 1509void KOTodoView::setOpen( QListViewItem* item, bool setOpenI)
1497{ 1510{
1498 1511
1499 while ( item ) { 1512 while ( item ) {
1500 setOpen( item->firstChild(), setOpenI ); 1513 setOpen( item->firstChild(), setOpenI );
1501 item->setOpen( setOpenI ); 1514 item->setOpen( setOpenI );
1502 item = item->nextSibling(); 1515 item = item->nextSibling();
1503 } 1516 }
1504} 1517}
1505 1518
1506void KOTodoView::displayAllFlat() 1519void KOTodoView::displayAllFlat()
1507{ 1520{
1508 storeCurrentItem(); 1521
1522 mActiveItem = 0;
1509 pendingSubtodo = 0; 1523 pendingSubtodo = 0;
1510 if ( mBlockUpdate ) { 1524 if ( mBlockUpdate ) {
1511 return; 1525 return;
1512 } 1526 }
1527 clearList ();
1513 mPopupMenu->setItemChecked( 8,true ); 1528 mPopupMenu->setItemChecked( 8,true );
1514 isFlatDisplay = true; 1529 isFlatDisplay = true;
1515 QPtrList<Todo> todoList = calendar()->todos(); 1530 QPtrList<Todo> todoList = calendar()->todos();
1516 mTodoMap.clear();
1517 mTodoListView->clear();
1518 Todo *todo; 1531 Todo *todo;
1519 for(todo = todoList.first(); todo; todo = todoList.next()) { 1532 for(todo = todoList.first(); todo; todo = todoList.next()) {
1520 if ( checkTodo( todo ) ) { 1533 if ( checkTodo( todo ) ) {
1521 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this); 1534 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this);
1522 mTodoMap.insert(todo,todoItem); 1535 mTodoMap.insert(todo,todoItem);
1523 } 1536 }
1524 } 1537 }
1525 resetCurrentItem(); 1538 resetCurrentItem();
1526} 1539}
1527 1540
1528void KOTodoView::setAllFlat() 1541void KOTodoView::setAllFlat()
1529{ 1542{
@@ -1687,27 +1700,28 @@ void KOTodoView::keyPressEvent ( QKeyEvent * e )
1687 cn = (KOTodoViewItem*)cn->itemBelow(); 1700 cn = (KOTodoViewItem*)cn->itemBelow();
1688 if ( cn ) { 1701 if ( cn ) {
1689 mTodoListView->setCurrentItem ( cn ); 1702 mTodoListView->setCurrentItem ( cn );
1690 mTodoListView->ensureItemVisible ( cn ); 1703 mTodoListView->ensureItemVisible ( cn );
1691 } 1704 }
1692 1705
1693 } 1706 }
1694 } 1707 }
1695 e->accept(); 1708 e->accept();
1696 } 1709 }
1697 } 1710 }
1698} 1711}
1712
1699void KOTodoView::updateTodo( Todo * t, int type ) 1713void KOTodoView::updateTodo( Todo * t, int type )
1700{ 1714{
1701 if ( mBlockUpdate) 1715 if ( mBlockUpdate )
1702 return; 1716 return;
1703 1717
1704 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator; 1718 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator;
1705 itemIterator = mTodoMap.find(t); 1719 itemIterator = mTodoMap.find(t);
1706 if (itemIterator != mTodoMap.end()) { 1720 if (itemIterator != mTodoMap.end()) {
1707 (*itemIterator)->construct(); 1721 (*itemIterator)->construct();
1708 } else { 1722 } else {
1709 if ( type == KOGlobals::EVENTADDED ) { 1723 if ( type == KOGlobals::EVENTADDED ) {
1710 insertTodoItem( t ); 1724 insertTodoItem( t );
1711 } 1725 }
1712 } 1726 }
1713 1727