korganizer Library API Documentation

kolistview.cpp

00001 /* 00002 This file is part of KOrganizer. 00003 Copyright (c) 1999 Preston Brown 00004 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00019 00020 As a special exception, permission is given to link this program 00021 with any edition of Qt, and distribute the resulting executable, 00022 without including the source code for Qt in the source distribution. 00023 */ 00024 00025 #include <qlistview.h> 00026 #include <qlayout.h> 00027 #include <qpopupmenu.h> 00028 00029 #include <klocale.h> 00030 #include <kdebug.h> 00031 #include <kiconloader.h> 00032 #include <kglobal.h> 00033 00034 #include <libkcal/calendar.h> 00035 00036 #ifndef KORG_NOPRINTER 00037 #include "calprinter.h" 00038 #endif 00039 #include "koglobals.h" 00040 #include "koincidencetooltip.h" 00041 00042 #include "kolistview.h" 00043 #include "kolistview.moc" 00044 00045 00046 KOListViewToolTip::KOListViewToolTip( QWidget* parent, 00047 KListView* lv ) 00048 :QToolTip(parent) 00049 { 00050 eventlist=lv; 00051 } 00052 00053 void KOListViewToolTip::maybeTip( const QPoint & pos) 00054 { 00055 QRect r; 00056 QListViewItem *it = eventlist->itemAt(pos); 00057 KOListViewItem *i = static_cast<KOListViewItem*>(it); 00058 00059 if( i && KOPrefs::instance()->mEnableToolTips ) { 00060 /* Calculate the rectangle. */ 00061 r=eventlist->itemRect( it ); 00062 /* Show the tip */ 00063 QString tipText; 00064 ToolTipVisitor v; 00065 if (v.act(i->data(), &tipText, true)) { 00066 tip(r, tipText); 00067 } 00068 } 00069 00070 } 00071 00072 ListItemVisitor::ListItemVisitor(KOListViewItem *item) 00073 { 00074 mItem = item; 00075 } 00076 00077 ListItemVisitor::~ListItemVisitor() 00078 { 00079 } 00080 00081 bool ListItemVisitor::visit(Event *e) 00082 { 00083 mItem->setText(0,e->summary()); 00084 mItem->setText(1,e->dtStartDateStr()); 00085 mItem->setText(2,e->dtStartTimeStr()); 00086 mItem->setText(3,e->dtEndDateStr()); 00087 mItem->setText(4,e->dtEndTimeStr()); 00088 mItem->setText(5,e->isAlarmEnabled() ? i18n("Yes") : i18n("No")); 00089 mItem->setText(6,e->doesRecur() ? i18n("Yes") : i18n("No")); 00090 mItem->setText(7,"---"); 00091 mItem->setText(8,"---"); 00092 mItem->setText(9,e->categoriesStr()); 00093 00094 QString key; 00095 QDate d = e->dtStart().date(); 00096 QTime t = e->doesFloat() ? QTime(0,0) : e->dtStart().time(); 00097 key.sprintf("%04d%02d%02d%02d%02d",d.year(),d.month(),d.day(),t.hour(),t.minute()); 00098 mItem->setSortKey(1,key); 00099 00100 d = e->dtEnd().date(); 00101 t = e->doesFloat() ? QTime(0,0) : e->dtEnd().time(); 00102 key.sprintf("%04d%02d%02d%02d%02d",d.year(),d.month(),d.day(),t.hour(),t.minute()); 00103 mItem->setSortKey(3,key); 00104 00105 return true; 00106 } 00107 00108 bool ListItemVisitor::visit(Todo *t) 00109 { 00110 mItem->setText(0,i18n("To-Do: %1").arg(t->summary())); 00111 mItem->setText(1,"---"); 00112 mItem->setText(2,"---"); 00113 mItem->setText(3,"---"); 00114 mItem->setText(4,"---"); 00115 mItem->setText(5,"---"); 00116 mItem->setText(6,"---"); 00117 if (t->hasDueDate()) { 00118 mItem->setText(7,t->dtDueDateStr()); 00119 if (t->doesFloat()) { 00120 mItem->setText(8,"---"); 00121 } else { 00122 mItem->setText(8,t->dtDueTimeStr()); 00123 } 00124 } else { 00125 mItem->setText(7,"---"); 00126 mItem->setText(8,"---"); 00127 } 00128 mItem->setText(9,t->categoriesStr()); 00129 00130 QString key; 00131 QDate d = t->dtDue().date(); 00132 QTime tm = t->doesFloat() ? QTime(0,0) : t->dtDue().time(); 00133 key.sprintf("%04d%02d%02d%02d%02d",d.year(),d.month(),d.day(),tm.hour(),tm.minute()); 00134 mItem->setSortKey(7,key); 00135 00136 return true; 00137 } 00138 00139 bool ListItemVisitor::visit(Journal *t) 00140 { 00141 // TODO: When the string freeze is over, use i18n("Journal: %1").arg(t->summary()) 00142 // mItem->setText( 0, i18n("Journal: %1").arg(t->description()) ); 00143 mItem->setText( 0, t->description() ); 00144 mItem->setText( 1, t->dtStartDateStr() ); 00145 00146 return true; 00147 } 00148 00149 KOListView::KOListView( Calendar *calendar, QWidget *parent, 00150 const char *name) 00151 : KOEventView(calendar, parent, name) 00152 { 00153 mActiveItem = 0; 00154 00155 mListView = new KListView(this); 00156 mListView->addColumn(i18n("Summary")); 00157 mListView->addColumn(i18n("Start Date")); 00158 mListView->setColumnAlignment(1,AlignHCenter); 00159 mListView->addColumn(i18n("Start Time")); 00160 mListView->setColumnAlignment(2,AlignHCenter); 00161 mListView->addColumn(i18n("End Date")); 00162 mListView->setColumnAlignment(3,AlignHCenter); 00163 mListView->addColumn(i18n("End Time")); 00164 mListView->setColumnAlignment(4,AlignHCenter); 00165 mListView->addColumn(i18n("Alarm")); // alarm set? 00166 mListView->addColumn(i18n("Recurs")); // recurs? 00167 mListView->addColumn(i18n("Due Date")); 00168 mListView->setColumnAlignment(7,AlignHCenter); 00169 mListView->addColumn(i18n("Due Time")); 00170 mListView->setColumnAlignment(8,AlignHCenter); 00171 mListView->addColumn(i18n("Categories")); 00172 mListView->setColumnAlignment(9,AlignHCenter); 00173 00174 QBoxLayout *layoutTop = new QVBoxLayout(this); 00175 layoutTop->addWidget(mListView); 00176 00177 mPopupMenu = eventPopup(); 00178 /* 00179 mPopupMenu = new QPopupMenu; 00180 mPopupMenu->insertItem(i18n("Edit Event"), this, 00181 SLOT (editEvent())); 00182 mPopupMenu->insertItem(KOGlobals::self()->smallIcon("delete"), i18n("Delete Event"), this, 00183 SLOT (deleteEvent())); 00184 mPopupMenu->insertSeparator(); 00185 mPopupMenu->insertItem(i18n("Show Dates"), this, 00186 SLOT(showDates())); 00187 mPopupMenu->insertItem(i18n("Hide Dates"), this, 00188 SLOT(hideDates())); 00189 */ 00190 00191 QObject::connect( mListView, SIGNAL( doubleClicked( QListViewItem * ) ), 00192 SLOT( defaultItemAction( QListViewItem * ) ) ); 00193 QObject::connect( mListView, SIGNAL( returnPressed( QListViewItem * ) ), 00194 SLOT( defaultItemAction( QListViewItem * ) ) ); 00195 QObject::connect( mListView, SIGNAL( rightButtonClicked ( QListViewItem *, 00196 const QPoint &, 00197 int ) ), 00198 SLOT( popupMenu( QListViewItem *, const QPoint &, int ) ) ); 00199 QObject::connect( mListView, SIGNAL( selectionChanged() ), 00200 SLOT( processSelectionChange() ) ); 00201 00202 // setMinimumSize(100,100); 00203 mListView->restoreLayout(KOGlobals::self()->config(),"KOListView Layout"); 00204 00205 new KOListViewToolTip( mListView->viewport(), mListView ); 00206 } 00207 00208 KOListView::~KOListView() 00209 { 00210 delete mPopupMenu; 00211 } 00212 00213 int KOListView::maxDatesHint() 00214 { 00215 return 0; 00216 } 00217 00218 int KOListView::currentDateCount() 00219 { 00220 return 0; 00221 } 00222 00223 Incidence::List KOListView::selectedIncidences() 00224 { 00225 Incidence::List eventList; 00226 00227 QListViewItem *item = mListView->selectedItem(); 00228 if (item) eventList.append(((KOListViewItem *)item)->data()); 00229 00230 return eventList; 00231 } 00232 00233 DateList KOListView::selectedDates() 00234 { 00235 DateList eventList; 00236 return eventList; 00237 } 00238 00239 void KOListView::showDates(bool show) 00240 { 00241 // Shouldn't we set it to a value greater 0? When showDates is called with 00242 // show == true at first, then the columnwidths are set to zero. 00243 static int oldColWidth1 = 0; 00244 static int oldColWidth3 = 0; 00245 00246 if (!show) { 00247 oldColWidth1 = mListView->columnWidth(1); 00248 oldColWidth3 = mListView->columnWidth(3); 00249 mListView->setColumnWidth(1, 0); 00250 mListView->setColumnWidth(3, 0); 00251 } else { 00252 mListView->setColumnWidth(1, oldColWidth1); 00253 mListView->setColumnWidth(3, oldColWidth3); 00254 } 00255 mListView->repaint(); 00256 } 00257 00258 void KOListView::printPreview(CalPrinter *calPrinter, const QDate &fd, 00259 const QDate &td) 00260 { 00261 #ifndef KORG_NOPRINTER 00262 calPrinter->preview(CalPrinter::Day, fd, td); 00263 #endif 00264 } 00265 00266 void KOListView::showDates() 00267 { 00268 showDates(true); 00269 } 00270 00271 void KOListView::hideDates() 00272 { 00273 showDates(false); 00274 } 00275 00276 void KOListView::updateView() 00277 { 00278 kdDebug(5850) << "KOListView::updateView() does nothing" << endl; 00279 } 00280 00281 void KOListView::showDates(const QDate &start, const QDate &end) 00282 { 00283 clear(); 00284 00285 QDate date = start; 00286 while( date <= end ) { 00287 addEvents(calendar()->events(date)); 00288 addTodos(calendar()->todos(date)); 00289 date = date.addDays( 1 ); 00290 } 00291 00292 emit incidenceSelected( 0 ); 00293 } 00294 00295 void KOListView::addEvents( const Event::List &eventList ) 00296 { 00297 Event::List::ConstIterator it; 00298 for( it = eventList.begin(); it != eventList.end(); ++it ) { 00299 addIncidence( *it ); 00300 } 00301 } 00302 00303 void KOListView::addTodos( const Todo::List &eventList ) 00304 { 00305 Todo::List::ConstIterator it; 00306 for( it = eventList.begin(); it != eventList.end(); ++it ) { 00307 addIncidence( *it ); 00308 } 00309 } 00310 00311 void KOListView::addIncidences( const Incidence::List &incidenceList ) 00312 { 00313 Incidence::List::ConstIterator it; 00314 for( it = incidenceList.begin(); it != incidenceList.end(); ++it ) { 00315 addIncidence( *it ); 00316 } 00317 } 00318 00319 void KOListView::addIncidence(Incidence *incidence) 00320 { 00321 if ( mUidDict.find( incidence->uid() ) ) return; 00322 00323 mUidDict.insert( incidence->uid(), incidence ); 00324 00325 KOListViewItem *item = new KOListViewItem( incidence, mListView ); 00326 ListItemVisitor v(item); 00327 if (incidence->accept(v)) return; 00328 else delete item; 00329 } 00330 00331 void KOListView::showEvents( const Event::List &eventList ) 00332 { 00333 clear(); 00334 00335 addEvents( eventList ); 00336 00337 // After new creation of list view no events are selected. 00338 emit incidenceSelected( 0 ); 00339 } 00340 00341 void KOListView::showIncidences( const Incidence::List &eventList ) 00342 { 00343 clear(); 00344 00345 addIncidences( eventList ); 00346 00347 // After new creation of list view no events are selected. 00348 emit incidenceSelected( 0 ); 00349 } 00350 00351 void KOListView::changeEventDisplay(Event *event, int action) 00352 { 00353 KOListViewItem *item; 00354 00355 switch(action) { 00356 case KOGlobals::EVENTADDED: 00357 addIncidence( event ); 00358 break; 00359 case KOGlobals::EVENTEDITED: 00360 item = getItemForEvent(event); 00361 if (item) { 00362 delete item; 00363 mUidDict.remove( event->uid() ); 00364 addIncidence( event ); 00365 } 00366 break; 00367 case KOGlobals::EVENTDELETED: 00368 item = getItemForEvent(event); 00369 if (item) { 00370 delete item; 00371 } 00372 break; 00373 default: 00374 kdDebug(5850) << "KOListView::changeEventDisplay(): Illegal action " << action << endl; 00375 } 00376 } 00377 00378 KOListViewItem *KOListView::getItemForEvent(Event *event) 00379 { 00380 KOListViewItem *item = (KOListViewItem *)mListView->firstChild(); 00381 while (item) { 00382 // kdDebug(5850) << "Item " << item->text(0) << " found" << endl; 00383 if (item->data() == event) return item; 00384 item = (KOListViewItem *)item->nextSibling(); 00385 } 00386 return 0; 00387 } 00388 00389 void KOListView::defaultItemAction(QListViewItem *i) 00390 { 00391 KOListViewItem *item = static_cast<KOListViewItem *>( i ); 00392 if ( item ) defaultAction( item->data() ); 00393 } 00394 00395 void KOListView::popupMenu(QListViewItem *item,const QPoint &,int) 00396 { 00397 mActiveItem = (KOListViewItem *)item; 00398 if (mActiveItem) { 00399 Incidence *incidence = mActiveItem->data(); 00400 mPopupMenu->showIncidencePopup(incidence); 00401 00402 /* 00403 if ( incidence && incidence->type() == "Event" ) { 00404 Event *event = static_cast<Event *>( incidence ); 00405 mPopupMenu->showEventPopup(event); 00406 } 00407 */ 00408 } 00409 } 00410 00411 void KOListView::readSettings(KConfig *config) 00412 { 00413 mListView->restoreLayout(config,"KOListView Layout"); 00414 } 00415 00416 void KOListView::writeSettings(KConfig *config) 00417 { 00418 mListView->saveLayout(config,"KOListView Layout"); 00419 } 00420 00421 void KOListView::processSelectionChange() 00422 { 00423 kdDebug(5850) << "KOListView::processSelectionChange()" << endl; 00424 00425 KOListViewItem *item = 00426 static_cast<KOListViewItem *>( mListView->selectedItem() ); 00427 00428 if ( !item ) { 00429 emit incidenceSelected( 0 ); 00430 } else { 00431 emit incidenceSelected( item->data() ); 00432 } 00433 } 00434 00435 void KOListView::clearSelection() 00436 { 00437 mListView->selectAll( false ); 00438 } 00439 00440 void KOListView::clear() 00441 { 00442 mListView->clear(); 00443 mUidDict.clear(); 00444 }
KDE Logo
This file is part of the documentation for korganizer Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:58:13 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003