19 #include "multiagendaview.h"
21 #include "koagendaview.h"
24 #include "timelabels.h"
28 #include <tdeglobalsettings.h>
32 #include <tqobjectlist.h>
35 #define FOREACH_VIEW(av) \
36 for(TQValueList<KOAgendaView*>::ConstIterator it = mAgendaViews.constBegin(); \
37 it != mAgendaViews.constEnd();) \
38 for(KOAgendaView* av = (it != mAgendaViews.constEnd() ? (*it) : 0); \
39 it != mAgendaViews.constEnd(); ++it, av = (*it) )
44 TQWidget * parent,
const char *name ) :
46 mSelectedAgendaView( 0 ),
47 mLastMovedSplitter( 0 ),
48 mUpdateOnShow( false ),
49 mPendingChanges( true ),
50 mCalendarView( calendarView )
52 TQBoxLayout *topLevelLayout =
new TQHBoxLayout(
this );
54 TQFontMetrics fm( font() );
55 int topLabelHeight = 2 * fm.height() + fm.lineSpacing();
57 TQVBox *topSideBox =
new TQVBox(
this );
58 mLeftTopSpacer =
new TQWidget( topSideBox );
59 mLeftTopSpacer->setFixedHeight( topLabelHeight );
60 mLeftSplitter =
new TQSplitter( TQt::Vertical, topSideBox );
61 mLeftSplitter->setOpaqueResize( TDEGlobalSettings::opaqueResize() );
62 TQLabel *label =
new TQLabel( i18n(
"All Day"), mLeftSplitter );
63 label->setAlignment( TQt::AlignRight | TQt::AlignVCenter | TQt::WordBreak );
64 TQVBox *sideBox =
new TQVBox( mLeftSplitter );
65 EventIndicator *eiSpacer =
new EventIndicator( EventIndicator::Top, sideBox );
66 eiSpacer->changeColumns( 0 );
67 mTimeLabels =
new TimeLabels( 24, sideBox );
68 eiSpacer =
new EventIndicator( EventIndicator::Bottom, sideBox );
69 eiSpacer->changeColumns( 0 );
70 mLeftBottomSpacer =
new TQWidget( topSideBox );
71 topLevelLayout->addWidget( topSideBox );
73 mScrollView =
new TQScrollView(
this );
74 mScrollView->setResizePolicy( TQScrollView::Manual );
75 mScrollView->setVScrollBarMode( TQScrollView::AlwaysOff );
76 mScrollView->setFrameShape( TQFrame::NoFrame );
77 topLevelLayout->addWidget( mScrollView, 100 );
78 mTopBox =
new TQHBox( mScrollView->viewport() );
79 mScrollView->addChild( mTopBox );
81 topSideBox =
new TQVBox(
this );
82 mRightTopSpacer =
new TQWidget( topSideBox );
83 mRightTopSpacer->setFixedHeight( topLabelHeight );
84 mRightSplitter =
new TQSplitter( TQt::Vertical, topSideBox );
85 mRightSplitter->setOpaqueResize( TDEGlobalSettings::opaqueResize() );
86 new TQWidget( mRightSplitter );
87 sideBox =
new TQVBox( mRightSplitter );
88 eiSpacer =
new EventIndicator( EventIndicator::Top, sideBox );
89 eiSpacer->setFixedHeight( eiSpacer->minimumHeight() );
90 eiSpacer->changeColumns( 0 );
91 mScrollBar =
new TQScrollBar( TQt::Vertical, sideBox );
92 eiSpacer =
new EventIndicator( EventIndicator::Bottom, sideBox );
93 eiSpacer->setFixedHeight( eiSpacer->minimumHeight() );
94 eiSpacer->changeColumns( 0 );
95 mRightBottomSpacer =
new TQWidget( topSideBox );
96 topLevelLayout->addWidget( topSideBox );
101 void MultiAgendaView::recreateViews()
103 if ( !mPendingChanges ) {
107 mPendingChanges =
false;
115 mAgendaViews.append( av );
116 mAgendaWidgets.append( av );
117 mSelectedAgendaView = av;
121 for ( CalendarResourceManager::ActiveIterator it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
122 if ( (*it)->canHaveSubresources() ) {
123 TQStringList subResources = (*it)->subresources();
124 for ( TQStringList::ConstIterator subit = subResources.constBegin(); subit != subResources.constEnd(); ++subit ) {
125 TQString type = (*it)->subresourceType( *subit );
127 if ( !(*it)->subresourceActive( *subit ) || (!type.isEmpty() && type !=
"event") ) {
131 addView( (*it)->labelForSubresource( *subit ), *it, *subit );
134 addView( (*it)->resourceName(), *it );
140 if ( mAgendaViews.isEmpty() ) {
145 TQTimer::singleShot( 0,
this, TQ_SLOT(slotResizeScrollView()) );
146 mTimeLabels->updateConfig();
148 connect( mTimeLabels->verticalScrollBar(), TQ_SIGNAL(valueChanged(
int)),
149 mScrollBar, TQ_SLOT(setValue(
int)) );
150 connect( mScrollBar, TQ_SIGNAL(valueChanged(
int)),
151 mTimeLabels, TQ_SLOT(positionChanged(
int)) );
153 installSplitterEventFilter( mLeftSplitter );
154 installSplitterEventFilter( mRightSplitter );
156 TQValueList<int> sizes = KOGlobals::self()->config()->readIntListEntry(
"Separator AgendaView" );
157 if ( sizes.count() != 2 ) {
158 sizes = mLeftSplitter->sizes();
160 FOREACH_VIEW( agenda ) {
161 agenda->splitter()->setSizes( sizes );
163 mLeftSplitter->setSizes( sizes );
164 mRightSplitter->setSizes( sizes );
166 TQTimer::singleShot( 0,
this, TQ_SLOT(setupScrollBar()) );
168 mTimeLabels->positionChanged();
171 void MultiAgendaView::deleteViews()
173 for ( TQValueList<TQWidget*>::ConstIterator it = mAgendaWidgets.constBegin();
174 it != mAgendaWidgets.constEnd(); ++it ) {
177 mAgendaViews.clear();
178 mAgendaWidgets.clear();
179 mLastMovedSplitter = 0;
180 mSelectedAgendaView = 0;
183 void MultiAgendaView::setupViews()
185 FOREACH_VIEW( agenda ) {
186 if ( !agenda->readOnly() ) {
201 TQ_SIGNAL(newTodoSignal(
ResourceCalendar *,
const TQString &,
const TQDate &)),
202 TQ_SIGNAL(newTodoSignal(
ResourceCalendar *,
const TQString &,
const TQDate &)) );
211 TQ_SIGNAL(startMultiModify(
const TQString &)),
212 TQ_SIGNAL(startMultiModify(
const TQString &)) );
214 TQ_SIGNAL(endMultiModify()),
215 TQ_SIGNAL(endMultiModify()) );
241 TQ_SIGNAL(incidenceSelected(
Incidence *,
const TQDate &)),
242 TQ_SIGNAL(incidenceSelected(
Incidence *,
const TQDate &)) );
244 TQ_SIGNAL(incidenceSelected(
Incidence*,
const TQDate &)),
245 TQ_SLOT(slotSelectionChanged()) );
248 TQ_SIGNAL(timeSpanSelectionChanged()),
249 TQ_SLOT(slotClearTimeSpanSelection()) );
251 disconnect( agenda->agenda(),
252 TQ_SIGNAL(zoomView(
const int,
const TQPoint&,
const TQt::Orientation)),
254 connect( agenda->agenda(),
255 TQ_SIGNAL(zoomView(
const int,
const TQPoint&,
const TQt::Orientation)),
256 TQ_SLOT(zoomView(
const int,
const TQPoint&,
const TQt::Orientation)) );
259 KOAgenda *anAgenda = mAgendaViews.first()->agenda();
260 connect( anAgenda, TQ_SIGNAL(lowerYChanged(
int) ), TQ_SLOT(resizeSpacers(
int)) );
262 FOREACH_VIEW( agenda ) {
263 agenda->readSettings();
267 for ( TQValueList<TQWidget*>::ConstIterator it = mAgendaWidgets.constBegin(); it != mAgendaWidgets.constEnd(); ++it )
268 minWidth = TQMAX( minWidth, (*it)->minimumSizeHint().width() );
269 for ( TQValueList<TQWidget*>::ConstIterator it = mAgendaWidgets.constBegin(); it != mAgendaWidgets.constEnd(); ++it )
270 (*it)->setMinimumWidth( minWidth );
273 MultiAgendaView::~ MultiAgendaView()
279 Incidence::List list;
280 FOREACH_VIEW(agendaView) {
281 list += agendaView->selectedIncidences();
289 FOREACH_VIEW(agendaView) {
290 list += agendaView->selectedIncidenceDates();
297 FOREACH_VIEW( agendaView )
298 return agendaView->currentDateCount();
302 void MultiAgendaView::showDates(
const TQDate & start,
const TQDate & end)
307 FOREACH_VIEW( agendaView )
308 agendaView->showDates( start, end );
311 void MultiAgendaView::showIncidences(
const Incidence::List & incidenceList,
const TQDate &date)
313 FOREACH_VIEW( agendaView )
314 agendaView->showIncidences( incidenceList, date );
317 void MultiAgendaView::updateView()
320 FOREACH_VIEW( agendaView )
321 agendaView->updateView();
324 void MultiAgendaView::changeIncidenceDisplay(
Incidence * incidence,
int mode)
326 FOREACH_VIEW( agendaView )
327 agendaView->changeIncidenceDisplay( incidence, mode );
332 FOREACH_VIEW( agendaView )
333 return agendaView->maxDatesHint();
337 void MultiAgendaView::slotSelectionChanged()
339 FOREACH_VIEW( agenda ) {
340 if ( agenda != sender() )
341 agenda->clearSelection();
347 FOREACH_VIEW( agenda ) {
348 bool valid = agenda->eventDurationHint( startDt, endDt, allDay );
355 void MultiAgendaView::slotClearTimeSpanSelection()
357 FOREACH_VIEW( agenda ) {
358 if ( agenda != sender() )
359 agenda->clearTimeSpanSelection();
363 void MultiAgendaView::setTypeAheadReceiver(TQObject * o)
365 FOREACH_VIEW( agenda )
366 agenda->setTypeAheadReceiver( o );
369 void MultiAgendaView::finishTypeAhead()
371 FOREACH_VIEW( agenda )
372 agenda->finishTypeAhead();
375 void MultiAgendaView::addView(
const TQString &label,
ResourceCalendar *res,
const TQString &subRes )
377 bool readOnlyView =
false;
379 TQVBox *box =
new TQVBox( mTopBox );
382 TQHeader *title =
new TQHeader( 1, box );
383 title->setClickEnabled(
false );
384 title->setStretchEnabled(
true );
387 title->setLabel( 0, TQIconSet( KOGlobals::self()->smallIcon(
"readonlyevent" ) ), label );
390 if ( subRes.isEmpty() ) {
391 resColor = *KOPrefs::instance()->resourceColor( res->identifier() );
393 resColor = *KOPrefs::instance()->resourceColor( subRes );
395 TQFontMetrics fm = fontMetrics();
396 TQPixmap px( fm.height(), fm.height() );
398 title->setLabel( 0, TQIconSet( px, TQIconSet::Small ), label );
404 av->setResource( res, subRes );
405 av->setIncidenceChanger( mChanger );
406 av->agenda()->setVScrollBarMode( TQScrollView::AlwaysOff );
407 mAgendaViews.append( av );
408 mAgendaWidgets.append( box );
410 mTimeLabels->setAgenda( av->agenda() );
412 connect( av->agenda()->verticalScrollBar(), TQ_SIGNAL(valueChanged(
int)),
413 mTimeLabels, TQ_SLOT(positionChanged(
int)) );
414 connect( mTimeLabels->verticalScrollBar(), TQ_SIGNAL(valueChanged(
int)),
415 av, TQ_SLOT(setContentsPos(
int)) );
417 av->installEventFilter(
this );
418 installSplitterEventFilter( av->splitter() );
421 void MultiAgendaView::resizeEvent(TQResizeEvent * ev)
423 resizeScrollView( ev->size() );
424 AgendaView::resizeEvent( ev );
427 void MultiAgendaView::resizeScrollView(
const TQSize & size)
429 const int widgetWidth = size.width() - mTimeLabels->width() - mScrollBar->width();
430 int width = TQMAX( mTopBox->sizeHint().width(), widgetWidth );
431 int height = size.height();
432 if ( width > widgetWidth ) {
433 const int sbHeight = mScrollView->horizontalScrollBar()->height();
435 mLeftBottomSpacer->setFixedHeight( sbHeight );
436 mRightBottomSpacer->setFixedHeight( sbHeight );
438 mLeftBottomSpacer->setFixedHeight( 0 );
439 mRightBottomSpacer->setFixedHeight( 0 );
441 mScrollView->resizeContents( width, height );
442 mTopBox->resize( width, height );
445 void MultiAgendaView::setIncidenceChanger(IncidenceChangerBase * changer)
448 FOREACH_VIEW( agenda )
449 agenda->setIncidenceChanger( changer );
452 void MultiAgendaView::updateConfig()
455 mTimeLabels->updateConfig();
456 FOREACH_VIEW( agenda )
457 agenda->updateConfig();
460 bool MultiAgendaView::eventFilter(TQObject * obj, TQEvent * event)
462 if ( obj->className() == TQCString(
"TQSplitterHandle") ) {
464 if ( (event->type() == TQEvent::MouseMove && TDEGlobalSettings::opaqueResize())
465 || event->type() == TQEvent::MouseButtonRelease ) {
466 FOREACH_VIEW( agenda ) {
467 if ( agenda->splitter() == obj->parent() )
468 mLastMovedSplitter = agenda->splitter();
470 if ( mLeftSplitter == obj->parent() )
471 mLastMovedSplitter = mLeftSplitter;
472 else if ( mRightSplitter == obj->parent() )
473 mLastMovedSplitter = mRightSplitter;
474 TQTimer::singleShot( 0,
this, TQ_SLOT(resizeSplitters()) );
478 if ( obj->className() == TQCString(
"KOAgendaView" ) ) {
479 if ( event->type() == TQEvent::MouseButtonRelease ||
480 event->type() == TQEvent::MouseButtonPress ) {
485 return AgendaView::eventFilter( obj, event );
490 return mSelectedAgendaView;
493 void MultiAgendaView::resizeSplitters()
495 if ( !mLastMovedSplitter )
496 mLastMovedSplitter = mAgendaViews.first()->splitter();
497 FOREACH_VIEW( agenda ) {
498 if ( agenda->splitter() == mLastMovedSplitter )
500 agenda->splitter()->setSizes( mLastMovedSplitter->sizes() );
502 if ( mLastMovedSplitter != mLeftSplitter )
503 mLeftSplitter->setSizes( mLastMovedSplitter->sizes() );
504 if ( mLastMovedSplitter != mRightSplitter )
505 mRightSplitter->setSizes( mLastMovedSplitter->sizes() );
508 void MultiAgendaView::resizeSpacers(
int newY )
516 TQFontMetrics fm( font() );
517 int topLabelHeight = mAgendaViews.first()->dayLabels()->height() +
518 fm.height() + mLeftSplitter->handleWidth();
519 mLeftTopSpacer->setFixedHeight( topLabelHeight );
520 mRightTopSpacer->setFixedHeight( topLabelHeight );
523 void MultiAgendaView::zoomView(
const int delta,
const TQPoint & pos,
const TQt::Orientation ori )
525 if ( ori == TQt::Vertical ) {
527 if ( KOPrefs::instance()->mHourSize > 4 )
528 KOPrefs::instance()->mHourSize--;
530 KOPrefs::instance()->mHourSize++;
534 FOREACH_VIEW( agenda )
535 agenda->zoomView( delta, pos, ori );
537 mTimeLabels->updateConfig();
538 mTimeLabels->positionChanged();
539 mTimeLabels->repaint();
543 void MultiAgendaView::installSplitterEventFilter(TQSplitter * splitter)
545 TQObjectList *objlist = splitter->queryList(
"TQSplitterHandle" );
548 if ( objlist->count() == 0 && !isVisible() )
549 mUpdateOnShow =
true;
550 TQObjectListIt it( *objlist );
552 while ( (obj = it.current()) != 0 ) {
553 obj->removeEventFilter(
this );
554 obj->installEventFilter(
this );
560 void MultiAgendaView::slotResizeScrollView()
562 resizeScrollView( size() );
565 void MultiAgendaView::show()
568 if ( mUpdateOnShow ) {
569 mUpdateOnShow =
false;
570 mPendingChanges =
true;
571 showDates( mStartDate, mEndDate );
575 void MultiAgendaView::resourcesChanged()
577 mPendingChanges =
true;
579 kdDebug() <<
"mAgendaViews.size is " << mAgendaViews.size()
580 <<
"; mAgendaWidgets.size is " << mAgendaWidgets.size()
581 <<
"; mSelectedAgendaView is " << mSelectedAgendaView
584 if ( mSelectedAgendaView ) {
591 mSelectedAgendaView = 0;
594 if ( res->readOnly() || !res->isActive() ) {
595 mSelectedAgendaView = 0;
599 mSelectedAgendaView = 0;
603 FOREACH_VIEW( agenda )
604 agenda->resourcesChanged();
607 void MultiAgendaView::setupScrollBar()
609 if ( !mAgendaViews.isEmpty() && mAgendaViews.first()->agenda() ) {
610 TQScrollBar *scrollBar = mAgendaViews.first()->agenda()->verticalScrollBar();
611 mScrollBar->setMinValue( scrollBar->minValue() );
612 mScrollBar->setMaxValue( scrollBar->maxValue() );
613 mScrollBar->setLineStep( scrollBar->lineStep() );
614 mScrollBar->setPageStep( scrollBar->pageStep() );
615 mScrollBar->setValue( scrollBar->value() );
619 #include "multiagendaview.moc"
This is the main calendar widget.
CalendarResourceManager * resourceManager() const
virtual bool subresourceWritable(const TQString &) const
virtual bool subresourceActive(const TQString &) const
virtual bool canHaveSubresources() const
KOAgendaView is the agenda-like view used to display events in a single one or multi-day view.
Base class for single/multi agenda views.
void copyIncidenceSignal(Incidence *)
instructs the receiver to copy the incidence
void dissociateOccurrenceSignal(Incidence *, const TQDate &)
Dissociate from a recurring incidence the occurrence on the given date to a new incidence.
void toggleAlarmSignal(Incidence *)
instructs the receiver to toggle the alarms of the Incidence.
void editIncidenceSignal(Incidence *, const TQDate &)
instructs the receiver to begin editing the incidence specified in some manner.
void dissociateFutureOccurrenceSignal(Incidence *, const TQDate &)
Dissociate from a recurring incidence all occurrences after the given date to a new incidence.
ResourceCalendar * resourceCalendar()
Return resourceCalendar of this view.
void cutIncidenceSignal(Incidence *)
instructs the receiver to cut the Incidence
virtual void setIncidenceChanger(IncidenceChangerBase *changer)
Assign a new incidence change helper object.
void deleteIncidenceSignal(Incidence *)
instructs the receiver to delete the Incidence in some manner; some possibilities include automatical...
void newEventSignal(ResourceCalendar *res, const TQString &subResource)
instructs the receiver to create a new event.
void setReadOnly(bool readonly)
Flag indicating if the view is read-only.
void pasteIncidenceSignal()
instructs the receiver to paste the incidence
virtual void updateConfig()
Re-reads the KOrganizer configuration and picks up relevant changes which are applicable to the view.
TQString subResourceCalendar() const
Return subResourceCalendar of this view.
void showIncidenceSignal(Incidence *, const TQDate &)
instructs the receiver to show the incidence in read-only mode.
virtual Calendar * calendar()
Return calendar object of this view.
Incidence::List selectedIncidences()
int currentDateCount()
Return number of currently shown dates.
DateList selectedIncidenceDates()
int maxDatesHint()
provides a hint back to the caller on the maximum number of dates that the view supports.
bool eventDurationHint(TQDateTime &startDt, TQDateTime &endDt, bool &allDay)
Set the default start/end date/time for new events.