-rw-r--r-- | korganizer/calendarview.cpp | 133 | ||||
-rw-r--r-- | korganizer/kotodoview.cpp | 14 |
2 files changed, 99 insertions, 48 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index e766b8f..65750af 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp @@ -595,177 +595,234 @@ void CalendarView::init() connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) ); connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) ); connect(QApplication::clipboard(),SIGNAL(dataChanged()), SLOT(checkClipboard())); connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ), SLOT( processTodoListSelection( Incidence * ) ) ); connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool))); // kdDebug() << "CalendarView::CalendarView() done" << endl; mDateFrame = new QVBox(0,0,WType_Popup); //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); mDateFrame->setLineWidth(3); mDateFrame->hide(); mDateFrame->setCaption( i18n( "Pick a date to display")); mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); mEventEditor = mDialogManager->getEventEditor(); mTodoEditor = mDialogManager->getTodoEditor(); mFlagEditDescription = false; mSuspendTimer = new QTimer( this ); mAlarmTimer = new QTimer( this ); mRecheckAlarmTimer = new QTimer( this ); connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); mAlarmDialog = new AlarmDialog( this ); connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); mAlarmDialog->setServerNotification( false ); mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); #ifndef DESKTOP_VERSION //US listen for arriving address resultsets connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)), this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&))); #endif mDateNavigator->setCalendar( mCalendar ); } CalendarView::~CalendarView() { // kdDebug() << "~CalendarView()" << endl; //qDebug("CalendarView::~CalendarView() "); delete mDialogManager; delete mViewManager; delete mStorage; delete mDateFrame ; delete mEventViewerDialog; //kdDebug() << "~CalendarView() done" << endl; } void CalendarView::nextConflict( bool all, bool allday ) { - QDate start = mNavigator->selectedDates().first().addDays(1); + + QPtrList<Event> testlist = mCalendar->events(); + Event * test = testlist.first(); + while ( test ) { + test->setTagged( false ); + } + QDateTime startDT = QDateTime (mNavigator->selectedDates().first().addDays(1), QTime ( 0,0,0)); + QDateTime conflict; + QDateTime retVal; + bool found = false; + Event * cE = 0; + QPtrList<Event> testlist2 = testlist; + while ( test ) { + Event * test2 = testlist2.first(); + while ( test2 ) { + if ( !test2->isTagged() ) { + if ( test->isOverlapping ( test2, &retVal, true ) ) { + if ( ! found ) { + if ( retVal >= startDT ) { + conflict = retVal; + cE = test; + found = true; + } + } else { + if ( retVal >= startDT && retVal < conflict ) { + conflict = retVal; + cE = test; + } + } + } + } + test2 = testlist2.next(); + } + test->setTagged( true ); + test = testlist.next(); + } + if ( found ) { + if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 ) + mViewManager->showDayView(); + mNavigator->slotDaySelect( conflict.date() ); + int hour = conflict.time().hour(); + mViewManager->agendaView()->setStartHour( hour ); + topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( mConflictingEvent->summary().left( 20 ) ).arg( cE->summary().left( 20 ) ) ); + return; + } + + topLevelWidget()->setCaption( i18n("No conflict found within the next two years") ); + qDebug("No conflict found "); + return; + + + + + +#if 0 + + QDate end = start.addDays( 365*2); while ( start < end ) { QPtrList<Event> eventList = calendar()->events( start ); Event * ev = eventList.first(); QPtrList<Event> test = eventList; while ( ev ) { //qDebug("found %d on %s ", eventList.count(), start.toString().latin1()); Event * t_ev = test.first(); QDateTime es = ev->dtStart(); QDateTime ee = ev->dtEnd(); if ( ev->doesFloat() ) ee = ee.addDays( 1 ); if ( ! all ) { if ( ev->doesFloat() != allday ) t_ev = 0; } while ( t_ev ) { bool skip = false; if ( ! all ) { if ( t_ev->doesFloat() != allday ) skip = true; } if ( !skip && ev != t_ev ) { QDateTime ets = t_ev->dtStart(); QDateTime ete = t_ev->dtEnd(); if ( t_ev->doesFloat() ) ete = ete.addDays( 1 ); //qDebug("test %s -- %s -------- %s -- %s ", es.toString().latin1() , ee.toString().latin1(), ets.toString().latin1() , ete.toString().latin1() ); if ( es < ete && ets < ee ) { if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 ) mViewManager->showDayView(); mNavigator->slotDaySelect( start ); int hour = es.time().hour(); if ( ets > es ) hour = ets.time().hour(); mViewManager->agendaView()->setStartHour( hour ); topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( ev->summary().left( 20 ) ).arg( t_ev->summary().left( 20 ) ) ); return; } } t_ev = test.next(); } ev = eventList.next(); } start = start.addDays( 1 ); } topLevelWidget()->setCaption( i18n("No conflict found within the next two years") ); qDebug("No conflict found "); +#endif } void CalendarView::conflictAll() { nextConflict ( true, true ); } void CalendarView::conflictAllday() { nextConflict ( false, true ); } void CalendarView::conflictNotAll() { nextConflict ( false, false ); } void CalendarView::setCalReadOnly( int id, bool readO ) { if ( readO ) { emit save(); } mCalendar->setReadOnly( id, readO ); } void CalendarView::setScrollBarStep(int val ) { #ifdef DESKTOP_VERSION mDateScrollBar->setLineStep ( val ); #endif } void CalendarView::scrollBarValue(int val ) { #ifdef DESKTOP_VERSION if ( QApplication::desktop()->width() < 800 ) return; static bool block = false; if ( block ) return; block = true; int count = mNavigator->selectedDates().count(); int day = mNavigator->selectedDates().first().dayOfYear(); int stepdays = val; if ( mDateScrollBar->lineStep () <= count ) { //val = val/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep(); //qDebug("VAL %d ",val ); stepdays = (val-day)/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep(); stepdays = day+stepdays; if ( stepdays < 0 ) stepdays = 0; } if ( stepdays == day ) { block = false; return; } int year = mNavigator->selectedDates().first().year(); QDate d ( year,1,1 ); mNavigator->selectDates( d.addDays( stepdays-1) , count ); block = false; #endif } void CalendarView::updateView(const QDate &start, const QDate &end) { #ifdef DESKTOP_VERSION if ( ! mDateScrollBar->draggingSlider () ) { int dof = start.dayOfYear(); //qDebug("dof %d day %d val %d ", dof, start.dayOfYear(),mDateScrollBar->value() ); if ( dof != mDateScrollBar->value() ) { mDateScrollBar->blockSignals( true ); @@ -2634,225 +2691,205 @@ void CalendarView::updateConfig() { if ( KOPrefs::instance()->mUseAppColors ) QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); emit configChanged(); mTodoList->updateConfig(); // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); // To make the "fill window" configurations work //mViewManager->raiseCurrentView(); } void CalendarView::eventChanged(Event *event) { changeEventDisplay(event,KOGlobals::EVENTEDITED); //updateUnmanagedViews(); } void CalendarView::eventAdded(Event *event) { changeEventDisplay(event,KOGlobals::EVENTADDED); } void CalendarView::eventToBeDeleted(Event *) { kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; } void CalendarView::eventDeleted() { changeEventDisplay(0,KOGlobals::EVENTDELETED); } void CalendarView::changeTodoDisplay(Todo *which, int action) { changeIncidenceDisplay((Incidence *)which, action); mDateNavigator->updateView(); //LR //mDialogManager->updateSearchDialog(); if (which) { mViewManager->updateWNview(); //mTodoList->updateView(); } } void CalendarView::changeIncidenceDisplay(Incidence *which, int action) { updateUnmanagedViews(); //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); if ( action == KOGlobals::EVENTDELETED ) { //delete mCalendar->checkAlarmForIncidence( 0, true ); if ( mEventViewerDialog ) mEventViewerDialog->hide(); } else mCalendar->checkAlarmForIncidence( which , false ); } // most of the changeEventDisplays() right now just call the view's // total update mode, but they SHOULD be recoded to be more refresh-efficient. void CalendarView::changeEventDisplay(Event *which, int action) { // kdDebug() << "CalendarView::changeEventDisplay" << endl; changeIncidenceDisplay((Incidence *)which, action); - - static bool clearallviews = false; if ( KOPrefs::instance()->mGlobalUpdateDisabled ) { if ( clearallviews ) { clearAllViews(); clearallviews = false; } return; } clearallviews = true; - - - mDateNavigator->updateView(); //mDialogManager->updateSearchDialog(); - if (which) { // If there is an event view visible update the display mViewManager->currentView()->changeEventDisplay(which,action); // TODO: check, if update needed // if (which->getTodoStatus()) { mTodoList->updateView(); if ( action != KOGlobals::EVENTDELETED ) { mConflictingEvent = which ; QTimer::singleShot( 1000, this, SLOT ( checkConflictForEvent() ) ); } // } } else { mViewManager->currentView()->updateView(); } } void CalendarView::checkConflictForEvent() { if (!KOPrefs::instance()->mConfirm) return; if ( ! mConflictingEvent ) return; if ( mConflictingEvent->doesFloat() ) { mConflictingEvent = 0; return; } - bool all = false; - bool allday = false; - Event * ev = mConflictingEvent; - mConflictingEvent = 0; - QDate start = ev->dtStart().date(); - QDate end = ev->dtEnd().date().addDays(1); - while ( start < end ) { - QPtrList<Event> test = calendar()->events( start ); - //qDebug("found %d on %s ", eventList.count(), start.toString().latin1()); - Event * t_ev = test.first(); - QDateTime es = ev->dtStart(); - QDateTime ee = ev->dtEnd(); - if ( ev->doesFloat() ) - ee = ee.addDays( 1 ); - if ( ! all ) { - if ( ev->doesFloat() != allday ) - t_ev = 0; + QPtrList<Event> testlist = mCalendar->events(); + Event * test = testlist.first(); + QDateTime conflict; + QDateTime retVal; + bool found = false; + Event * cE = 0; + while ( test ) { + if ( !test->doesFloat() ) { + if ( mConflictingEvent->isOverlapping ( test, &retVal, true ) ) { + if ( ! found ) { + conflict = retVal; + cE = test; + } else { + if ( retVal < conflict ) { + conflict = retVal; + cE = test; } - while ( t_ev ) { - bool skip = false; - if ( ! all ) { - if ( t_ev->doesFloat() != allday ) - skip = true; } - if ( !skip && ev != t_ev ) { - QDateTime ets = t_ev->dtStart(); - QDateTime ete = t_ev->dtEnd(); - if ( t_ev->doesFloat() ) - ete = ete.addDays( 1 ); - //qDebug("test %s -- %s -------- %s -- %s ", es.toString().latin1() , ee.toString().latin1(), ets.toString().latin1() , ete.toString().latin1() ); - if ( es < ete && ets < ee ) { - QString mess = i18n("The event\n%1\nconflicts with event\n%2\nat date\n%3.\n").arg(KGlobal::formatMessage ( ev->summary(),0 ) ).arg( KGlobal::formatMessage ( t_ev->summary(),0 )).arg(KGlobal::locale()->formatDate(start) ) ; + found = true; + } + } + test = testlist.next(); + } + if ( found ) { + QString mess = i18n("The event\n%1\nconflicts with event\n%2\nat date\n%3.\n").arg(KGlobal::formatMessage ( mConflictingEvent->summary(),0 ) ).arg( KGlobal::formatMessage ( cE->summary(),0 )).arg(KGlobal::locale()->formatDate(conflict.date()) ) ; qApp->processEvents(); int km = KMessageBox::warningContinueCancel(this,mess, i18n("KO/Pi Conflict delected"),i18n("Show date"),i18n("No problem!")); if ( km != KMessageBox::Continue ) return; if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 ) mViewManager->showDayView(); - mNavigator->slotDaySelect( start ); - int hour = es.time().hour(); - if ( ets > es ) - hour = ets.time().hour(); + mNavigator->slotDaySelect( conflict.date() ); + int hour = conflict.time().hour(); mViewManager->agendaView()->setStartHour( hour ); - topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( ev->summary().left( 20 ) ).arg( t_ev->summary().left( 20 ) ) ); + topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( mConflictingEvent->summary().left( 20 ) ).arg( cE->summary().left( 20 ) ) ); return; } - } - t_ev = test.next(); - } - start = start.addDays( 1 ); - } - qDebug("No conflict found "); + return; } void CalendarView::updateTodoViews() { mTodoList->updateView(); mViewManager->currentView()->updateView(); } void CalendarView::clearAllViews() { mTodoList->clearList(); mViewManager->clearAllViews(); SearchDialog * sd = mDialogManager->getSearchDialog(); if ( sd ) { KOListView* kol = sd->listview(); if ( kol ) kol->clearList(); } } void CalendarView::updateView() { static bool clearallviews = false; if ( KOPrefs::instance()->mGlobalUpdateDisabled ) { if ( clearallviews ) { clearAllViews(); clearallviews = false; } return; } clearallviews = true; DateList tmpList = mNavigator->selectedDates(); if ( KOPrefs::instance()->mHideNonStartedTodos ) mTodoList->updateView(); // We assume that the navigator only selects consecutive days. updateView( tmpList.first(), tmpList.last() ); } void CalendarView::updateUnmanagedViews() { mDateNavigator->updateDayMatrix(); } int CalendarView::msgItemDelete(const QString name) { return KMessageBox::warningContinueCancel(this,name +"\n\n"+ i18n("This item will be\npermanently deleted."), i18n("KO/Pi Confirmation"),i18n("Delete")); } void CalendarView::edit_cut() { Event *anEvent=0; Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); if (mViewManager->currentView()->isEventView()) { if ( incidence && incidence->typeID() == eventID ) { anEvent = static_cast<Event *>(incidence); diff --git a/korganizer/kotodoview.cpp b/korganizer/kotodoview.cpp index 2c017e1..c2ad886 100644 --- a/korganizer/kotodoview.cpp +++ b/korganizer/kotodoview.cpp @@ -341,128 +341,132 @@ void KOTodoListView::contentsMousePressEvent(QMouseEvent* e) mMousePressed = false; if (! rootClicked && !( e->button() == RightButton) ) { mPressPos = e->pos(); mMousePressed = true; } else { mMousePressed = false; } #endif //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 ( !isVisible() ) { + e->ignore(); + return; + } 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); @@ -1539,135 +1543,145 @@ void KOTodoView::toggleQuickTodo() } void KOTodoView::toggleRunning() { KOPrefs::instance()->mHideNonStartedTodos = !KOPrefs::instance()->mHideNonStartedTodos; mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos); mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos ); updateView(); if ( KOPrefs::instance()->mHideNonStartedTodos ) topLevelWidget()->setCaption(i18n("Hide not Running")); else topLevelWidget()->setCaption(i18n("Show not Running")); } void KOTodoView::toggleCompleted() { KOPrefs::instance()->mShowCompletedTodo = !KOPrefs::instance()->mShowCompletedTodo; mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo ); mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo ); updateView(); if ( KOPrefs::instance()->mShowCompletedTodo ) topLevelWidget()->setCaption(i18n("Show Completed")); else topLevelWidget()->setCaption(i18n("Hide Completed")); } void KOTodoView::addQuickTodo() { addQuickTodoPar( 0 ); } void KOTodoView::addQuickTodoPar( Todo * parentTodo) { Todo *todo = new Todo(); todo->setSummary(mQuickAdd->text()); todo->setOrganizer(KOPrefs::instance()->email()); if ( parentTodo ) { todo->setRelatedTo(parentTodo); todo->setCategories (parentTodo->categoriesStr ()); todo->setSecrecy (parentTodo->secrecy ()); if ( parentTodo->priority() < 3 ) todo->setPriority( parentTodo->priority() ); todo->setCalID( parentTodo->calID() ); } else { CalFilter * cf = mCalendar->filter(); if ( cf ) { if ( cf->isEnabled()&& cf->showCategories()) { todo->setCategories(cf->categoryList()); } if ( cf->isEnabled() ) todo->setSecrecy( cf->getSecrecy()); } } mCalendar->addTodo(todo); mQuickAdd->setText(""); todoModified (todo, KOGlobals::EVENTADDED ); updateView(); } void KOTodoView::keyPressEvent ( QKeyEvent * e ) { // e->ignore(); //return; //qDebug("KOTodoView::keyPressEvent "); + if ( !isVisible() ) { + e->ignore(); + return; + } switch ( e->key() ) { case Qt::Key_Down: case Qt::Key_Up: QWidget::keyPressEvent ( e ); break; case Qt::Key_Q: + + + if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton ) { + e->ignore(); + break; + } toggleQuickTodo(); break; case Qt::Key_U: if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) { mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); unparentTodo(); e->accept(); } else e->ignore(); break; case Qt::Key_S: if ( e->state() == Qt::ControlButton ) { e->ignore(); break; } if ( e->state() == Qt::ShiftButton ) { mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); reparentTodo(); e->accept(); } else e->ignore(); break; case Qt::Key_P: if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) { mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); if ( pendingSubtodo ) itemClicked(mActiveItem); e->accept(); } else e->ignore(); break; case Qt::Key_Escape: if ( pendingSubtodo ) { itemClicked(0); e->accept(); } else e->ignore(); break; default: e->ignore(); } if ( true ) { if ( e->key() == Qt::Key_I ) { KOTodoViewItem*cn = (KOTodoViewItem*)mTodoListView->currentItem(); if ( cn ) { mActiveItem = cn; KOTodoViewItem* ci = (KOTodoViewItem*)( cn ); if ( ci ){ showTodo(); cn = (KOTodoViewItem*)cn->itemBelow(); if ( cn ) { mTodoListView->setCurrentItem ( cn ); mTodoListView->ensureItemVisible ( cn ); } } } e->accept(); } } |