author | zautrix <zautrix> | 2005-04-02 12:16:34 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-04-02 12:16:34 (UTC) |
commit | 997e7660a81baa2b8aeb1b66a3cc3ebe54e00ebe (patch) (side-by-side diff) | |
tree | f788b37459574b5cea0d2ab874882c6a396c240d /korganizer/kotodoview.cpp | |
parent | e0d51120d2f0c178115746e0c1357af40f95bc77 (diff) | |
download | kdepimpi-997e7660a81baa2b8aeb1b66a3cc3ebe54e00ebe.zip kdepimpi-997e7660a81baa2b8aeb1b66a3cc3ebe54e00ebe.tar.gz kdepimpi-997e7660a81baa2b8aeb1b66a3cc3ebe54e00ebe.tar.bz2 |
more fixes
-rw-r--r-- | korganizer/kotodoview.cpp | 49 |
1 files changed, 34 insertions, 15 deletions
diff --git a/korganizer/kotodoview.cpp b/korganizer/kotodoview.cpp index ccc4b01..0a315cb 100644 --- a/korganizer/kotodoview.cpp +++ b/korganizer/kotodoview.cpp @@ -18,403 +18,414 @@ As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include <qlayout.h> #include <qheader.h> #include <qcursor.h> #include <qwhatsthis.h> #include <qvbox.h> #include <kdebug.h> #include "koprefs.h" #include <klocale.h> #include <kglobal.h> #include <kiconloader.h> #include <kmessagebox.h> #include <libkcal/icaldrag.h> #include <libkcal/vcaldrag.h> #include <libkcal/calfilter.h> #include <libkcal/dndfactory.h> #include <libkcal/calendarresources.h> #include <libkcal/resourcecalendar.h> #include <kresources/resourceselectdialog.h> #include <libkcal/kincidenceformatter.h> #ifndef DESKTOP_VERSION #include <qpe/qpeapplication.h> #else #include <qapplication.h> #endif #ifndef KORG_NOPRINTER #include "calprinter.h" #endif #include "docprefs.h" #include "kotodoview.h" using namespace KOrg; class KOTodoViewWhatsThis :public QWhatsThis { public: KOTodoViewWhatsThis( QWidget *wid, KOTodoView* view ) : QWhatsThis( wid ), _wid(wid),_view (view) { }; protected: virtual QString text( const QPoint& p) { return _view->getWhatsThisText(p) ; } private: QWidget* _wid; KOTodoView * _view; }; KOTodoListView::KOTodoListView(Calendar *calendar,QWidget *parent, const char *name) : KListView(parent,name) { mName = QString ( name ); mCalendar = calendar; #ifndef DESKTOP_VERSION QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold ); #endif mOldCurrent = 0; mMousePressed = false; setAcceptDrops(true); viewport()->setAcceptDrops(true); int size = 16; if (qApp->desktop()->width() < 300 ) size = 12; setTreeStepSize( size + 6 ); } void KOTodoListView::contentsDragEnterEvent(QDragEnterEvent *e) { #ifndef KORG_NODND // kdDebug() << "KOTodoListView::contentsDragEnterEvent" << endl; if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && !QTextDrag::canDecode( e ) ) { e->ignore(); return; } mOldCurrent = currentItem(); #endif } void KOTodoListView::contentsDragMoveEvent(QDragMoveEvent *e) { #ifndef KORG_NODND // kdDebug() << "KOTodoListView::contentsDragMoveEvent" << endl; if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && !QTextDrag::canDecode( e ) ) { e->ignore(); return; } e->accept(); #endif } void KOTodoListView::contentsDragLeaveEvent(QDragLeaveEvent *) { #ifndef KORG_NODND // kdDebug() << "KOTodoListView::contentsDragLeaveEvent" << endl; setCurrentItem(mOldCurrent); setSelected(mOldCurrent,true); #endif } void KOTodoListView::contentsDropEvent(QDropEvent *e) { #ifndef KORG_NODND // kdDebug() << "KOTodoListView::contentsDropEvent" << endl; if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && !QTextDrag::canDecode( e ) ) { e->ignore(); return; } DndFactory factory( mCalendar ); Todo *todo = factory.createDropTodo(e); if (todo) { e->acceptAction(); KOTodoViewItem *destination = (KOTodoViewItem *)itemAt(contentsToViewport(e->pos())); Todo *destinationEvent = 0; if (destination) destinationEvent = destination->todo(); Todo *existingTodo = mCalendar->todo(todo->uid()); if(existingTodo) { Incidence *to = destinationEvent; while(to) { if (to->uid() == todo->uid()) { KMessageBox::sorry(this, i18n("Cannot move To-Do to itself\nor a child of itself"), i18n("Drop To-Do")); delete todo; return; } to = to->relatedTo(); } internalDrop = true; if ( destinationEvent ) reparentTodoSignal( destinationEvent, existingTodo ); else unparentTodoSignal(existingTodo); delete todo; } else { mCalendar->addTodo(todo); emit todoDropped(todo, KOGlobals::EVENTADDED); if ( destinationEvent ) reparentTodoSignal( destinationEvent, todo ); } } else { QString text; if (QTextDrag::decode(e,text)) { //QListViewItem *qlvi = itemAt( contentsToViewport(e->pos()) ); KOTodoViewItem *todoi = static_cast<KOTodoViewItem *>(itemAt( contentsToViewport(e->pos()) )); qDebug("Dropped : " + text); QStringList emails = QStringList::split(",",text); for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) { int pos = (*it).find("<"); QString name = (*it).left(pos); QString email = (*it).mid(pos); if (!email.isEmpty() && todoi) { todoi->todo()->addAttendee(new Attendee(name,email)); } } } else { qDebug("KOTodoListView::contentsDropEvent(): Todo from drop not decodable "); e->ignore(); } } #endif } void KOTodoListView::contentsMousePressEvent(QMouseEvent* e) { + + QPoint p(contentsToViewport(e->pos())); + QListViewItem *i = itemAt(p); + bool rootClicked = true; + if (i) { + // if the user clicked into the root decoration of the item, don't + // try to start a drag! + int X = p.x(); + //qDebug("%d %d %d", X, header()->sectionPos(0), treeStepSize() ); + if (X > header()->sectionPos(0) + + treeStepSize() * (i->depth() + (rootIsDecorated() ? 1 : 0)) + + itemMargin() || + X < header()->sectionPos(0)) { + rootClicked = false; + } + } #ifndef KORG_NODND - QPoint p(contentsToViewport(e->pos())); - QListViewItem *i = itemAt(p); - mMousePressed = false; - if (i) { - // if the user clicked into the root decoration of the item, don't - // try to start a drag! - if (p.x() > header()->sectionPos(header()->mapToIndex(0)) + - treeStepSize() * (i->depth() + (rootIsDecorated() ? 1 : 0)) + - itemMargin() || - p.x() < header()->sectionPos(header()->mapToIndex(0))) { - if (e->button()==Qt::LeftButton) { + mMousePressed = false; + if (! rootClicked ) { mPressPos = e->pos(); mMousePressed = true; - } } - } #endif - QListView::contentsMousePressEvent(e); + //qDebug("KOTodoListView::contentsMousePressEvent %d", rootClicked); +#ifndef DESKTOP_VERSION + if (!( e->button() == RightButton && rootClicked) ) + QListView::contentsMousePressEvent(e); +#else + QListView::contentsMousePressEvent(e); +#endif } void KOTodoListView::paintEvent(QPaintEvent* e) { emit paintNeeded(); QListView::paintEvent( e); } void KOTodoListView::contentsMouseMoveEvent(QMouseEvent* e) { #ifndef KORG_NODND //QListView::contentsMouseMoveEvent(e); if (mMousePressed && (mPressPos - e->pos()).manhattanLength() > QApplication::startDragDistance()*3) { mMousePressed = false; QListViewItem *item = itemAt(contentsToViewport(mPressPos)); if (item) { DndFactory factory( mCalendar ); ICalDrag *vd = factory.createDrag( ((KOTodoViewItem *)item)->todo(),viewport()); internalDrop = false; // we cannot do any senseful here, because the DnD is still broken in Qt if (vd->drag()) { if ( !internalDrop ) { //emit deleteTodo( ((KOTodoViewItem *)item)->todo() ); qDebug("Dnd: External move: Delete drag source "); } else qDebug("Dnd: Internal move "); } else { if ( !internalDrop ) { qDebug("Dnd: External Copy"); } else qDebug("DnD: Internal copy: Copy pending"); } } } #endif } void KOTodoListView::keyReleaseEvent ( QKeyEvent *e ) { if ( !e->isAutoRepeat() ) { mFlagKeyPressed = false; } } void KOTodoListView::keyPressEvent ( QKeyEvent * e ) { qApp->processEvents(); if ( e->isAutoRepeat() && !mFlagKeyPressed ) { e->ignore(); // qDebug(" ignore %d",e->isAutoRepeat() ); return; } if (! e->isAutoRepeat() ) mFlagKeyPressed = true; QListViewItem* cn; if ( e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) { cn = currentItem(); if ( cn ) { KOTodoViewItem* ci = (KOTodoViewItem*)( cn ); if ( ci ){ if ( e->state() == ShiftButton ) ci->setOn( false ); else ci->setOn( true ); cn = cn->itemBelow(); if ( cn ) { setCurrentItem ( cn ); ensureItemVisible ( cn ); } } } return; } if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton || mName != "todolistsmall" ) { switch ( e->key() ) { case Qt::Key_Down: case Qt::Key_Up: QListView::keyPressEvent ( e ); break; case Qt::Key_Left: case Qt::Key_Right: QListView::keyPressEvent ( e ); e->accept(); return; break; default: e->ignore(); break; } return; } e->ignore(); } void KOTodoListView::contentsMouseReleaseEvent(QMouseEvent *e) { QListView::contentsMouseReleaseEvent(e); mMousePressed = false; } void KOTodoListView::contentsMouseDoubleClickEvent(QMouseEvent *e) { if (!e) return; QPoint vp = contentsToViewport(e->pos()); QListViewItem *item = itemAt(vp); emit double_Clicked(item); if (!item) return; emit doubleClicked(item,vp,0); } ///////////////////////////////////////////////////////////////////////////// KOQuickTodo::KOQuickTodo(QWidget *parent) : QLineEdit(parent) { setText(i18n("Click to add a new Todo")); } void KOQuickTodo::focusInEvent(QFocusEvent *ev) { if ( text()==i18n("Click to add a new Todo") ) setText(""); QLineEdit::focusInEvent(ev); } void KOQuickTodo::focusOutEvent(QFocusEvent *ev) { setText(i18n("Click to add a new Todo")); QLineEdit::focusOutEvent(ev); } ///////////////////////////////////////////////////////////////////////////// KOTodoView::KOTodoView(Calendar *calendar,QWidget* parent,const char* name) : KOrg::BaseView(calendar,parent,name) { mPendingUpdateBeforeRepaint = false; isFlatDisplay = false; mNavigator = 0; QBoxLayout *topLayout = new QVBoxLayout(this); mName = QString ( name ); mBlockUpdate = false; mQuickAdd = new KOQuickTodo(this); topLayout->addWidget(mQuickAdd); if ( !KOPrefs::instance()->mEnableQuickTodo ) mQuickAdd->hide(); mTodoListView = new KOTodoListView(calendar,this, name ); topLayout->addWidget(mTodoListView); //mTodoListView->header()->setMaximumHeight(30); mTodoListView->setRootIsDecorated(true); mTodoListView->setAllColumnsShowFocus(true); mTodoListView->setShowSortIndicator(true); mTodoListView->addColumn(i18n("Todo")); mTodoListView->addColumn(i18n("Prio")); mTodoListView->setColumnAlignment(1,AlignHCenter); mTodoListView->addColumn(i18n("Complete")); mTodoListView->setColumnAlignment(2,AlignCenter); mTodoListView->addColumn(i18n("Due Date")); mTodoListView->setColumnAlignment(3,AlignLeft); mTodoListView->addColumn(i18n("Due Time")); mTodoListView->setColumnAlignment(4,AlignHCenter); mTodoListView->addColumn(i18n("Start Date")); mTodoListView->setColumnAlignment(5,AlignLeft); mTodoListView->addColumn(i18n("Start Time")); mTodoListView->setColumnAlignment(6,AlignHCenter); mTodoListView->addColumn(i18n("Cancelled")); mTodoListView->addColumn(i18n("Categories")); #if 0 mTodoListView->addColumn(i18n("Sort Id")); mTodoListView->setColumnAlignment(4,AlignHCenter); #endif mTodoListView->setMinimumHeight( 60 ); mTodoListView->setItemsRenameable( true ); mTodoListView->setRenameable( 0 ); mTodoListView->setColumnWidth( 0, 120 ); mTodoListView->setColumnWidthMode(0, QListView::Manual); mTodoListView->setColumnWidthMode(1, QListView::Manual); @@ -874,396 +885,404 @@ void KOTodoView::printPreview(CalPrinter *calPrinter, const QDate &fd, const QDate &td) { #ifndef KORG_NOPRINTER calPrinter->preview(CalPrinter::Todolist, fd, td); #endif } void KOTodoView::editItem(QListViewItem *item ) { // qDebug("editItem(QListViewItem *item ) "); emit editTodoSignal(((KOTodoViewItem *)item)->todo()); } void KOTodoView::showItem(QListViewItem *item,const QPoint &,int) { emit showTodoSignal(((KOTodoViewItem *)item)->todo()); } void KOTodoView::popupMenu(QListViewItem *item,const QPoint &p,int column) { pendingSubtodo = 0; mActiveItem = (KOTodoViewItem *)item; if (item) { switch (column){ case 1: mPriorityPopupMenu->popup(QCursor::pos ()); break; case 2: mPercentageCompletedPopupMenu->popup(QCursor::pos ()); break; case 3: moveTodo(); break; case 8: getCategoryPopupMenu((KOTodoViewItem *)item)->popup(QCursor::pos ()); break; default: mItemPopupMenu->popup(QCursor::pos()); } } else mPopupMenu->popup(QCursor::pos()); } void KOTodoView::newTodo() { emit newTodoSignal(); } void KOTodoView::newSubTodo() { if (mActiveItem) { emit newSubTodoSignal(mActiveItem->todo()); } } void KOTodoView::unparentTodo() { if (mActiveItem) { emit unparentTodoSignal(mActiveItem->todo()); } } void KOTodoView::reparentTodo() { if (mActiveItem) { qDebug("KOTodoView::reparentTodo() "); topLevelWidget()->setCaption(i18n("Click on new parent item")); pendingSubtodo = mActiveItem; } } void KOTodoView::editTodo() { if (mActiveItem) { emit editTodoSignal(mActiveItem->todo()); } } void KOTodoView::cloneTodo() { if (mActiveItem) { emit cloneTodoSignal((Incidence*)mActiveItem->todo()); } } void KOTodoView::cancelTodo() { if (mActiveItem) { emit cancelTodoSignal((Incidence*)mActiveItem->todo()); } } void KOTodoView::moveTodo() { if (mActiveItem) { emit moveTodoSignal((Incidence*)mActiveItem->todo()); } } void KOTodoView::beamTodo() { if (mActiveItem) { emit beamTodoSignal((Incidence*)mActiveItem->todo()); } } void KOTodoView::showTodo() { if (mActiveItem) { emit showTodoSignal(mActiveItem->todo()); } } void KOTodoView::deleteTodo() { if (mActiveItem) { emit deleteTodoSignal(mActiveItem->todo()); } } void KOTodoView::setNewPriority(int index) { if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { mActiveItem->todo()->setPriority(mPriority[index]); mActiveItem->construct(); todoModified (mActiveItem->todo(), KOGlobals::PRIORITY_MODIFIED); mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); } } void KOTodoView::setNewPercentage(int index) { if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { if ( mPercentage[index] == 100 && !mActiveItem->isOn() ) { mActiveItem->setOn( true ); return; } else if ( mPercentage[index] != 100 && mActiveItem->isOn() ) { KOTodoViewItem* par = (static_cast<KOTodoViewItem*>(mActiveItem->parent())); if ( par && par->isOn() ) par->setOn( false ); } if (mPercentage[index] == 100) { mActiveItem->todo()->setCompleted(QDateTime::currentDateTime()); } else { mActiveItem->todo()->setCompleted(false); } mActiveItem->todo()->setPercentComplete(mPercentage[index]); mActiveItem->construct(); todoModified (mActiveItem->todo (), KOGlobals::COMPLETION_MODIFIED); mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); } } QPopupMenu * KOTodoView::getCategoryPopupMenu (KOTodoViewItem *todoItem) { QPopupMenu* tempMenu = new QPopupMenu (this); QStringList checkedCategories = todoItem->todo()->categories (); tempMenu->setCheckable (true); for (QStringList::Iterator it = KOPrefs::instance()->mCustomCategories.begin (); it != KOPrefs::instance()->mCustomCategories.end (); ++it) { int index = tempMenu->insertItem (*it); mCategory[index] = *it; if (checkedCategories.find (*it) != checkedCategories.end ()) tempMenu->setItemChecked (index, true); } connect (tempMenu, SIGNAL (activated (int)), SLOT (changedCategories (int))); return tempMenu; } void KOTodoView::changedCategories(int index) { if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { QStringList categories = mActiveItem->todo()->categories (); QString colcat = categories.first(); if (categories.find (mCategory[index]) != categories.end ()) categories.remove (mCategory[index]); else categories.insert (categories.end(), mCategory[index]); categories.sort (); if ( !colcat.isEmpty() ) { if ( categories.find ( colcat ) != categories.end () ) { categories.remove( colcat ); categories.prepend( colcat ); } } mActiveItem->todo()->setCategories (categories); mActiveItem->construct(); mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); todoModified (mActiveItem->todo (), KOGlobals::CATEGORY_MODIFIED); } } void KOTodoView::itemDoubleClicked(QListViewItem *item) { if ( pendingSubtodo != 0 ) { topLevelWidget()->setCaption(i18n("Reparenting aborted!")); } pendingSubtodo = 0; + int row = mTodoListView->header()->sectionAt ( mTodoListView->header()->mapFromGlobal( QCursor::pos()).x() ); + //qDebug("ROW %d ", row); if (!item) { newTodo(); return; + } else { + if ( row == 1 ) { + mActiveItem = (KOTodoViewItem *) item; + newSubTodo(); + return; + } } if ( KOPrefs::instance()->mEditOnDoubleClick ) editItem( item ); else showItem( item , QPoint(), 0 ); } void KOTodoView::itemClicked(QListViewItem *item) { - + //qDebug("KOTodoView::itemClicked %d", item); if (!item) { if ( pendingSubtodo != 0 ) { topLevelWidget()->setCaption(i18n("Reparenting aborted!")); } pendingSubtodo = 0; return; } KOTodoViewItem *todoItem = (KOTodoViewItem *)item; if ( pendingSubtodo != 0 ) { bool allowReparent = true; QListViewItem *par = item; while ( par ) { if ( par == pendingSubtodo ) { allowReparent = false; break; } par = par->parent(); } if ( !allowReparent ) { topLevelWidget()->setCaption(i18n("Recursive reparenting not possible!")); qDebug("Recursive reparenting not possible "); pendingSubtodo = 0; } else { Todo* newParent = todoItem->todo(); Todo* newSub = pendingSubtodo->todo(); pendingSubtodo = 0; emit reparentTodoSignal( newParent,newSub ); return; } } #if 0 // handled by the item itself bool completed = todoItem->todo()->isCompleted(); // Completed or not? qDebug("com %d ",completed ); qDebug("itemclicked "); if (todoItem->isOn()) { qDebug("on "); if (!completed) { qDebug("set true "); todoItem->todo()->setCompleted(QDateTime::currentDateTime()); } } else { qDebug("not on "); if (completed) { qDebug("set false "); todoItem->todo()->setCompleted(false); } } #endif } void KOTodoView::setDocumentId( const QString &id ) { kdDebug() << "KOTodoView::setDocumentId()" << endl; mDocPrefs->setDoc( id ); } void KOTodoView::itemStateChanged( QListViewItem *item ) { if (!item) return; KOTodoViewItem *todoItem = (KOTodoViewItem *)item; // kdDebug() << "KOTodoView::itemStateChanged(): " << todoItem->todo()->summary() << endl; if( mDocPrefs ) mDocPrefs->writeEntry( todoItem->todo()->uid(), todoItem->isOpen() ); } void KOTodoView::saveLayout(KConfig *config, const QString &group) const { mTodoListView->saveLayout(config,group); } void KOTodoView::restoreLayout(KConfig *config, const QString &group) { mTodoListView->restoreLayout(config,group); } void KOTodoView::processSelectionChange() { // kdDebug() << "KOTodoView::processSelectionChange()" << endl; KOTodoViewItem *item = static_cast<KOTodoViewItem *>( mTodoListView->selectedItem() ); if ( !item ) { emit incidenceSelected( 0 ); } else { emit incidenceSelected( item->todo() ); } } void KOTodoView::modified(bool b) { emit isModified(b); } void KOTodoView::setTodoModified( Todo* todo ) { todoModified( todo, KOGlobals::UNKNOWN_MODIFIED ); } void KOTodoView::clearSelection() { mTodoListView->selectAll( false ); } void KOTodoView::setAllOpen() { if ( isFlatDisplay ) { isFlatDisplay = false; mPopupMenu->setItemChecked( 8,false ); updateView(); } setOpen(mTodoListView->firstChild(), true); } void KOTodoView::setAllClose() { if ( isFlatDisplay ) { isFlatDisplay = false; mPopupMenu->setItemChecked( 8,false ); updateView(); } setOpen(mTodoListView->firstChild(), false); } void KOTodoView::setOpen( QListViewItem* item, bool setOpenI) { while ( item ) { setOpen( item->firstChild(), setOpenI ); item->setOpen( setOpenI ); item = item->nextSibling(); } } void KOTodoView::displayAllFlat() { pendingSubtodo = 0; if ( mBlockUpdate ) { return; } mPopupMenu->setItemChecked( 8,true ); isFlatDisplay = true; QPtrList<Todo> todoList = calendar()->todos(); mTodoMap.clear(); mTodoListView->clear(); Todo *todo; for(todo = todoList.first(); todo; todo = todoList.next()) { KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this); mTodoMap.insert(todo,todoItem); } mTodoListView->setFocus(); processSelectionChange(); } void KOTodoView::setAllFlat() { if ( isFlatDisplay ) { isFlatDisplay = false; mPopupMenu->setItemChecked( 8,false ); updateView(); return; } displayAllFlat(); } void KOTodoView::purgeCompleted() { emit purgeCompletedSignal(); } void KOTodoView::toggleQuickTodo() { if ( mQuickAdd->isVisible() ) { mQuickAdd->hide(); KOPrefs::instance()->mEnableQuickTodo = false; } else { mQuickAdd->show(); KOPrefs::instance()->mEnableQuickTodo = true; } mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo); mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo ); } void KOTodoView::toggleRunning() { KOPrefs::instance()->mHideNonStartedTodos = !KOPrefs::instance()->mHideNonStartedTodos; mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos); mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos ); updateView(); } void KOTodoView::toggleCompleted() { |