00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "multiagendaview.h"
00020
00021 #include "koagendaview.h"
00022
00023 #include <libkcal/calendarresources.h>
00024
00025 #include <qlayout.h>
00026 #include <qvbox.h>
00027 #include <qobjectlist.h>
00028
00029 #define FOREACH_VIEW(av) \
00030 for(QValueList<KOAgendaView*>::ConstIterator it = mAgendaViews.constBegin(); \
00031 it != mAgendaViews.constEnd();) \
00032 for(KOAgendaView* av = (it != mAgendaViews.constEnd() ? (*it) : 0); \
00033 it != mAgendaViews.constEnd(); ++it, av = (*it) )
00034
00035 using namespace KOrg;
00036
00037 MultiAgendaView::MultiAgendaView(Calendar * cal, QWidget * parent, const char *name ) :
00038 AgendaView( cal, parent, name )
00039 {
00040 QBoxLayout *topLevelLayout = new QHBoxLayout( this );
00041 mScrollView = new QScrollView( this );
00042 mScrollView->setResizePolicy( QScrollView::Manual );
00043 mScrollView->setVScrollBarMode( QScrollView::AlwaysOff );
00044 mScrollView->setFrameShape( QFrame::NoFrame );
00045 topLevelLayout->addWidget( mScrollView );
00046 mTopBox = new QHBox( mScrollView->viewport() );
00047 mScrollView->addChild( mTopBox );
00048 recreateViews();
00049 }
00050
00051 void MultiAgendaView::recreateViews()
00052 {
00053 deleteViews();
00054
00055 CalendarResources *calres = dynamic_cast<CalendarResources*>( calendar() );
00056 if ( !calres ) {
00057
00058 KOAgendaView* av = new KOAgendaView( calendar(), mTopBox );
00059 mAgendaViews.append( av );
00060 mAgendaWidgets.append( av );
00061 av->show();
00062 } else {
00063 CalendarResourceManager *manager = calres->resourceManager();
00064 for ( CalendarResourceManager::ActiveIterator it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
00065 if ( (*it)->canHaveSubresources() ) {
00066 QStringList subResources = (*it)->subresources();
00067 for ( QStringList::ConstIterator subit = subResources.constBegin(); subit != subResources.constEnd(); ++subit ) {
00068 QString type = (*it)->subresourceType( *subit );
00069 if ( !(*it)->subresourceActive( *subit ) || (!type.isEmpty() && type != "event") )
00070 continue;
00071 addView( (*it)->labelForSubresource( *subit ), *it, *subit );
00072 }
00073 } else {
00074 addView( (*it)->resourceName(), *it );
00075 }
00076 }
00077 }
00078 setupViews();
00079 resizeScrollView( size() );
00080 }
00081
00082 void MultiAgendaView::deleteViews()
00083 {
00084 for ( QValueList<QWidget*>::ConstIterator it = mAgendaWidgets.constBegin();
00085 it != mAgendaWidgets.constEnd(); ++it ) {
00086 delete *it;
00087 }
00088 mAgendaViews.clear();
00089 mAgendaWidgets.clear();
00090 }
00091
00092 void MultiAgendaView::setupViews()
00093 {
00094 FOREACH_VIEW( agenda ) {
00095 connect( agenda, SIGNAL( newEventSignal() ),
00096 SIGNAL( newEventSignal() ) );
00097 connect( agenda, SIGNAL( editIncidenceSignal( Incidence * ) ),
00098 SIGNAL( editIncidenceSignal( Incidence * ) ) );
00099 connect( agenda, SIGNAL( showIncidenceSignal( Incidence * ) ),
00100 SIGNAL( showIncidenceSignal( Incidence * ) ) );
00101 connect( agenda, SIGNAL( deleteIncidenceSignal( Incidence * ) ),
00102 SIGNAL( deleteIncidenceSignal( Incidence * ) ) );
00103 connect( agenda, SIGNAL( startMultiModify( const QString & ) ),
00104 SIGNAL( startMultiModify( const QString & ) ) );
00105 connect( agenda, SIGNAL( endMultiModify() ),
00106 SIGNAL( endMultiModify() ) );
00107
00108 connect( agenda, SIGNAL( incidenceSelected( Incidence * ) ),
00109 SIGNAL( incidenceSelected( Incidence * ) ) );
00110
00111 connect( agenda, SIGNAL(cutIncidenceSignal(Incidence*)),
00112 SIGNAL(cutIncidenceSignal(Incidence*)) );
00113 connect( agenda, SIGNAL(copyIncidenceSignal(Incidence*)),
00114 SIGNAL(copyIncidenceSignal(Incidence*)) );
00115 connect( agenda, SIGNAL(pasteIncidenceSignal()),
00116 SIGNAL(pasteIncidenceSignal()) );
00117 connect( agenda, SIGNAL(toggleAlarmSignal(Incidence*)),
00118 SIGNAL(toggleAlarmSignal(Incidence*)) );
00119 connect( agenda, SIGNAL(dissociateOccurrenceSignal(Incidence*, const QDate&)),
00120 SIGNAL(dissociateOccurrenceSignal(Incidence*, const QDate&)) );
00121 connect( agenda, SIGNAL(dissociateFutureOccurrenceSignal(Incidence*, const QDate&)),
00122 SIGNAL(dissociateFutureOccurrenceSignal(Incidence*, const QDate&)) );
00123
00124 connect( agenda, SIGNAL(newEventSignal(const QDate&)),
00125 SIGNAL(newEventSignal(const QDate&)) );
00126 connect( agenda, SIGNAL(newEventSignal(const QDateTime&)),
00127 SIGNAL(newEventSignal(const QDateTime&)) );
00128 connect( agenda, SIGNAL(newEventSignal(const QDateTime&, const QDateTime&)),
00129 SIGNAL(newEventSignal(const QDateTime&, const QDateTime&)) );
00130 connect( agenda, SIGNAL(newTodoSignal(const QDate&)),
00131 SIGNAL(newTodoSignal(const QDate&)) );
00132
00133 connect( agenda, SIGNAL(incidenceSelected(Incidence*)),
00134 SLOT(slotSelectionChanged()) );
00135
00136 connect( agenda, SIGNAL(timeSpanSelectionChanged()),
00137 SLOT(slotClearTimeSpanSelection()) );
00138
00139 }
00140
00141 FOREACH_VIEW( agenda ) {
00142 agenda->readSettings();
00143 }
00144 }
00145
00146 MultiAgendaView::~ MultiAgendaView()
00147 {
00148 }
00149
00150 Incidence::List MultiAgendaView::selectedIncidences()
00151 {
00152 Incidence::List list;
00153 FOREACH_VIEW(agendaView) {
00154 list += agendaView->selectedIncidences();
00155 }
00156 return list;
00157 }
00158
00159 DateList MultiAgendaView::selectedDates()
00160 {
00161 DateList list;
00162 FOREACH_VIEW(agendaView) {
00163 list += agendaView->selectedDates();
00164 }
00165 return list;
00166 }
00167
00168 int MultiAgendaView::currentDateCount()
00169 {
00170 FOREACH_VIEW( agendaView )
00171 return agendaView->currentDateCount();
00172 return 0;
00173 }
00174
00175 void MultiAgendaView::showDates(const QDate & start, const QDate & end)
00176 {
00177 kdDebug() << k_funcinfo << endl;
00178 recreateViews();
00179 FOREACH_VIEW( agendaView )
00180 agendaView->showDates( start, end );
00181 }
00182
00183 void MultiAgendaView::showIncidences(const Incidence::List & incidenceList)
00184 {
00185 FOREACH_VIEW( agendaView )
00186 agendaView->showIncidences( incidenceList );
00187 }
00188
00189 void MultiAgendaView::updateView()
00190 {
00191 kdDebug() << k_funcinfo << endl;
00192 recreateViews();
00193 FOREACH_VIEW( agendaView )
00194 agendaView->updateView();
00195 }
00196
00197 void MultiAgendaView::changeIncidenceDisplay(Incidence * incidence, int mode)
00198 {
00199 FOREACH_VIEW( agendaView )
00200 agendaView->changeIncidenceDisplay( incidence, mode );
00201 }
00202
00203 int MultiAgendaView::maxDatesHint()
00204 {
00205 FOREACH_VIEW( agendaView )
00206 return agendaView->maxDatesHint();
00207 return 0;
00208 }
00209
00210 void MultiAgendaView::slotSelectionChanged()
00211 {
00212 FOREACH_VIEW( agenda ) {
00213 if ( agenda != sender() )
00214 agenda->clearSelection();
00215 }
00216 }
00217
00218 bool MultiAgendaView::eventDurationHint(QDateTime & startDt, QDateTime & endDt, bool & allDay)
00219 {
00220 FOREACH_VIEW( agenda ) {
00221 bool valid = agenda->eventDurationHint( startDt, endDt, allDay );
00222 if ( valid )
00223 return true;
00224 }
00225 return false;
00226 }
00227
00228 void MultiAgendaView::slotClearTimeSpanSelection()
00229 {
00230 FOREACH_VIEW( agenda ) {
00231 if ( agenda != sender() )
00232 agenda->clearTimeSpanSelection();
00233 }
00234 }
00235
00236 void MultiAgendaView::setTypeAheadReceiver(QObject * o)
00237 {
00238 FOREACH_VIEW( agenda )
00239 agenda->setTypeAheadReceiver( o );
00240 }
00241
00242 void MultiAgendaView::finishTypeAhead()
00243 {
00244 FOREACH_VIEW( agenda )
00245 agenda->finishTypeAhead();
00246 }
00247
00248 void MultiAgendaView::addView( const QString &label, KCal::ResourceCalendar * res, const QString & subRes )
00249 {
00250 QVBox *box = new QVBox( mTopBox );
00251 QLabel *l = new QLabel( label, box );
00252 l->setAlignment( AlignVCenter | AlignHCenter );
00253 KOAgendaView* av = new KOAgendaView( calendar(), box );
00254 av->setResource( res, subRes );
00255 av->setIncidenceChanger( mChanger );
00256 mAgendaViews.append( av );
00257 mAgendaWidgets.append( box );
00258 box->show();
00259 }
00260
00261 void MultiAgendaView::resizeEvent(QResizeEvent * ev)
00262 {
00263 resizeScrollView( ev->size() );
00264 AgendaView::resizeEvent( ev );
00265 }
00266
00267 void MultiAgendaView::resizeScrollView(const QSize & size)
00268 {
00269 int width = QMAX( mTopBox->sizeHint().width(), size.width() );
00270 int height = size.height();
00271 if ( width > size.width() )
00272 height -= mScrollView->horizontalScrollBar()->height();
00273 mScrollView->resizeContents( width, height );
00274 mTopBox->resize( width, height );
00275 }
00276
00277 void MultiAgendaView::setIncidenceChanger(IncidenceChangerBase * changer)
00278 {
00279 AgendaView::setIncidenceChanger( changer );
00280 FOREACH_VIEW( agenda )
00281 agenda->setIncidenceChanger( changer );
00282 }
00283
00284 #include "multiagendaview.moc"