korganizer

multiagendaview.cpp

00001 /*
00002     Copyright (c) 2007 Volker Krause <vkrause@kde.org>
00003 
00004     This program is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or
00007     (at your option) any later version.
00008 
00009     This program is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with this program; if not, write to the Free Software
00016     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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     // fallback to single-agenda
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(toggleAlarmSignal(Incidence*)),
00116              SIGNAL(toggleAlarmSignal(Incidence*)) );
00117     connect( agenda, SIGNAL(dissociateOccurrenceSignal(Incidence*, const QDate&)),
00118              SIGNAL(dissociateOccurrenceSignal(Incidence*, const QDate&)) );
00119     connect( agenda, SIGNAL(dissociateFutureOccurrenceSignal(Incidence*, const QDate&)),
00120              SIGNAL(dissociateFutureOccurrenceSignal(Incidence*, const QDate&)) );
00121 
00122     connect( agenda, SIGNAL(newEventSignal(const QDate&)),
00123              SIGNAL(newEventSignal(const QDate&)) );
00124     connect( agenda, SIGNAL(newEventSignal(const QDateTime&)),
00125              SIGNAL(newEventSignal(const QDateTime&)) );
00126     connect( agenda, SIGNAL(newEventSignal(const QDateTime&, const QDateTime&)),
00127              SIGNAL(newEventSignal(const QDateTime&, const QDateTime&)) );
00128     connect( agenda, SIGNAL(newTodoSignal(const QDate&)),
00129              SIGNAL(newTodoSignal(const QDate&)) );
00130 
00131     connect( agenda, SIGNAL(incidenceSelected(Incidence*)),
00132              SLOT(slotSelectionChanged()) );
00133 
00134     connect( agenda, SIGNAL(timeSpanSelectionChanged()),
00135              SLOT(slotClearTimeSpanSelection()) );
00136 
00137   }
00138 
00139   FOREACH_VIEW( agenda ) {
00140     agenda->readSettings();
00141   }
00142 }
00143 
00144 MultiAgendaView::~ MultiAgendaView()
00145 {
00146 }
00147 
00148 Incidence::List MultiAgendaView::selectedIncidences()
00149 {
00150   Incidence::List list;
00151   FOREACH_VIEW(agendaView) {
00152     list += agendaView->selectedIncidences();
00153   }
00154   return list;
00155 }
00156 
00157 DateList MultiAgendaView::selectedDates()
00158 {
00159   DateList list;
00160   FOREACH_VIEW(agendaView) {
00161     list += agendaView->selectedDates();
00162   }
00163   return list;
00164 }
00165 
00166 int MultiAgendaView::currentDateCount()
00167 {
00168   FOREACH_VIEW( agendaView )
00169     return agendaView->currentDateCount();
00170   return 0;
00171 }
00172 
00173 void MultiAgendaView::showDates(const QDate & start, const QDate & end)
00174 {
00175   kdDebug() << k_funcinfo << endl;
00176   recreateViews();
00177   FOREACH_VIEW( agendaView )
00178     agendaView->showDates( start, end );
00179 }
00180 
00181 void MultiAgendaView::showIncidences(const Incidence::List & incidenceList)
00182 {
00183   FOREACH_VIEW( agendaView )
00184     agendaView->showIncidences( incidenceList );
00185 }
00186 
00187 void MultiAgendaView::updateView()
00188 {
00189   kdDebug() << k_funcinfo << endl;
00190   recreateViews();
00191   FOREACH_VIEW( agendaView )
00192     agendaView->updateView();
00193 }
00194 
00195 void MultiAgendaView::changeIncidenceDisplay(Incidence * incidence, int mode)
00196 {
00197   FOREACH_VIEW( agendaView )
00198     agendaView->changeIncidenceDisplay( incidence, mode );
00199 }
00200 
00201 int MultiAgendaView::maxDatesHint()
00202 {
00203   FOREACH_VIEW( agendaView )
00204     return agendaView->maxDatesHint();
00205   return 0;
00206 }
00207 
00208 void MultiAgendaView::slotSelectionChanged()
00209 {
00210   FOREACH_VIEW( agenda ) {
00211     if ( agenda != sender() )
00212       agenda->clearSelection();
00213   }
00214 }
00215 
00216 bool MultiAgendaView::eventDurationHint(QDateTime & startDt, QDateTime & endDt, bool & allDay)
00217 {
00218   FOREACH_VIEW( agenda ) {
00219     bool valid = agenda->eventDurationHint( startDt, endDt, allDay );
00220     if ( valid )
00221       return true;
00222   }
00223   return false;
00224 }
00225 
00226 void MultiAgendaView::slotClearTimeSpanSelection()
00227 {
00228   FOREACH_VIEW( agenda ) {
00229     if ( agenda != sender() )
00230       agenda->clearTimeSpanSelection();
00231   }
00232 }
00233 
00234 void MultiAgendaView::setTypeAheadReceiver(QObject * o)
00235 {
00236   FOREACH_VIEW( agenda )
00237     agenda->setTypeAheadReceiver( o );
00238 }
00239 
00240 void MultiAgendaView::finishTypeAhead()
00241 {
00242   FOREACH_VIEW( agenda )
00243     agenda->finishTypeAhead();
00244 }
00245 
00246 void MultiAgendaView::addView( const QString &label, KCal::ResourceCalendar * res, const QString & subRes )
00247 {
00248   QVBox *box = new QVBox( mTopBox );
00249   QLabel *l = new QLabel( label, box );
00250   l->setAlignment( AlignVCenter | AlignHCenter );
00251   KOAgendaView* av = new KOAgendaView( calendar(), box );
00252   av->setResource( res, subRes );
00253   av->setIncidenceChanger( mChanger );
00254   mAgendaViews.append( av );
00255   mAgendaWidgets.append( box );
00256   box->show();
00257 }
00258 
00259 void MultiAgendaView::resizeEvent(QResizeEvent * ev)
00260 {
00261   resizeScrollView( ev->size() );
00262   AgendaView::resizeEvent( ev );
00263 }
00264 
00265 void MultiAgendaView::resizeScrollView(const QSize & size)
00266 {
00267   int width = QMAX( mTopBox->sizeHint().width(), size.width() );
00268   int height = size.height();
00269   if ( width > size.width() )
00270     height -= mScrollView->horizontalScrollBar()->height();
00271   mScrollView->resizeContents( width, height );
00272   mTopBox->resize( width, height );
00273 }
00274 
00275 void MultiAgendaView::setIncidenceChanger(IncidenceChangerBase * changer)
00276 {
00277   AgendaView::setIncidenceChanger( changer );
00278   FOREACH_VIEW( agenda )
00279     agenda->setIncidenceChanger( changer );
00280 }
00281 
00282 #include "multiagendaview.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys