23 #include <tqwhatsthis.h>
26 #include <kiconloader.h>
30 #include "eventlistviewbase.moc"
33 class EventListWhatsThisBase :
public TQWhatsThis
36 EventListWhatsThisBase(EventListViewBase* lv) : TQWhatsThis(lv), mListView(lv) { }
37 virtual TQString text(
const TQPoint&);
39 EventListViewBase* mListView;
48 EventListViewBase::EventListViewBase(TQWidget* parent,
const char* name)
49 : TDEListView(parent, name),
52 mLastColumnHeaderWidth(0)
54 setAllColumnsShowFocus(
true);
55 setShowSortIndicator(
true);
57 new EventListWhatsThisBase(
this);
60 void EventListViewBase::addLastColumn(
const TQString& title)
63 mLastColumn = columns() - 1;
64 mLastColumnHeaderWidth = columnWidth(mLastColumn);
65 setColumnWidthMode(mLastColumn, TQListView::Maximum);
71 void EventListViewBase::refresh()
75 currentID = currentItem()->event().id();
79 EventListViewItemBase* current = getEntry(currentID);
82 setCurrentItem(current);
83 ensureItemVisible(current);
90 EventListViewItemBase* EventListViewBase::getEntry(
const TQString& eventID)
const
92 if (!eventID.isEmpty())
94 for (EventListViewItemBase* item = firstChild(); item; item = item->nextSibling())
95 if (item->event().id() == eventID)
106 void EventListViewBase::addEvent(
const KAEvent& event,
const InstanceList& instanceList, EventListViewBase* selectionView)
108 for (InstanceListConstIterator it = instanceList.begin(); it != instanceList.end(); ++it)
109 (*it)->addEntry(event,
true, (*it == selectionView));
117 void EventListViewBase::modifyEvent(
const TQString& oldEventID,
const KAEvent& newEvent,
118 const InstanceList& instanceList, EventListViewBase* selectionView)
120 for (InstanceListConstIterator it = instanceList.begin(); it != instanceList.end(); ++it)
122 EventListViewBase* v = *it;
123 EventListViewItemBase* item = v->getEntry(oldEventID);
125 v->deleteEntry(item,
false);
126 v->addEntry(newEvent,
true, (v == selectionView));
133 void EventListViewBase::deleteEvent(
const TQString& eventID,
const InstanceList& instanceList)
135 for (InstanceListConstIterator it = instanceList.begin(); it != instanceList.end(); ++it)
137 EventListViewBase* v = *it;
138 EventListViewItemBase* item = v->getEntry(eventID);
140 v->deleteEntry(item,
true);
150 EventListViewItemBase* EventListViewBase::addEntry(
const KAEvent& event,
bool setSize,
bool reselect)
152 if (!shouldShowEvent(event))
154 return addEntry(createItem(event), setSize, reselect);
157 EventListViewItemBase* EventListViewBase::addEntry(EventListViewItemBase* item,
bool setSize,
bool reselect)
164 setSelected(item,
true);
173 EventListViewItemBase* EventListViewBase::updateEntry(EventListViewItemBase* item,
const KAEvent& newEvent,
bool setSize,
bool reselect)
176 return addEntry(newEvent, setSize, reselect);
182 void EventListViewBase::deleteEntry(EventListViewItemBase* item,
bool setSize)
197 void EventListViewBase::slotFind()
201 mFind =
new Find(
this);
202 connect(mFind, TQ_SIGNAL(active(
bool)), TQ_SIGNAL(findActive(
bool)));
210 void EventListViewBase::findNext(
bool forward)
213 mFind->findNext(forward);
220 void EventListViewBase::slotSelectAll()
222 if (selectionMode() == TQListView::Multi || selectionMode() == TQListView::Extended)
230 void EventListViewBase::slotDeselect()
238 bool EventListViewBase::anySelected()
const
240 for (TQListViewItem* item = TDEListView::firstChild(); item; item = item->nextSibling())
241 if (isSelected(item))
251 const KAEvent* EventListViewBase::selectedEvent()
const
253 EventListViewItemBase* sel = selectedItem();
254 return sel ? &sel->event() : 0;
263 EventListViewItemBase* EventListViewBase::selectedItem()
const
265 if (selectionMode() == TQListView::Single)
266 return (EventListViewItemBase*)TDEListView::selectedItem();
268 TQListViewItem* item = 0;
269 for (TQListViewItem* it = firstChild(); it; it = it->nextSibling())
278 return (EventListViewItemBase*)item;
284 TQValueList<EventListViewItemBase*> EventListViewBase::selectedItems()
const
286 TQValueList<EventListViewItemBase*> items;
287 for (TQListViewItem* item = firstChild(); item; item = item->nextSibling())
289 if (isSelected(item))
290 items.append((EventListViewItemBase*)item);
298 int EventListViewBase::selectedCount()
const
301 for (TQListViewItem* item = firstChild(); item; item = item->nextSibling())
303 if (isSelected(item))
313 void EventListViewBase::resizeLastColumn()
315 int lastColumnWidth = mLastColumnHeaderWidth;
316 for (EventListViewItemBase* item = firstChild(); item; item = item->nextSibling())
318 int mw = item->lastColumnWidth();
319 if (mw > lastColumnWidth)
320 lastColumnWidth = mw;
322 TQHeader* head = header();
323 int x = head->sectionPos(mLastColumn);
324 int availableWidth = visibleWidth() - x;
325 int rightColWidth = 0;
326 int index = head->mapToIndex(mLastColumn);
327 if (index < mLastColumn)
331 for (
int i = index + 1; i <= mLastColumn; ++i)
332 rightColWidth += columnWidth(head->mapToSection(i));
333 availableWidth -= rightColWidth;
335 if (availableWidth < lastColumnWidth)
336 availableWidth = lastColumnWidth;
337 setColumnWidth(mLastColumn, availableWidth);
338 if (contentsWidth() > x + availableWidth + rightColWidth)
339 resizeContents(x + availableWidth + rightColWidth, contentsHeight());
347 void EventListViewBase::resizeEvent(TQResizeEvent* re)
349 TDEListView::resizeEvent(re);
358 void EventListViewBase::showEvent(TQShowEvent* se)
360 TDEListView::showEvent(se);
367 int EventListViewBase::itemHeight()
369 EventListViewItemBase* item = firstChild();
373 TQListViewItem* item =
new TQListViewItem(
this, TQString());
374 int height = item->height();
379 return item->height();
388 TQPixmap* EventListViewItemBase::mTextIcon;
389 TQPixmap* EventListViewItemBase::mFileIcon;
390 TQPixmap* EventListViewItemBase::mCommandIcon;
391 TQPixmap* EventListViewItemBase::mEmailIcon;
392 int EventListViewItemBase::mIconWidth = 0;
395 EventListViewItemBase::EventListViewItemBase(EventListViewBase* parent,
const KAEvent& event)
396 : TQListViewItem(parent),
405 void EventListViewItemBase::setLastColumnText()
407 EventListViewBase* parent = (EventListViewBase*)listView();
408 setText(parent->lastColumn(), lastColumnText());
409 mLastColumnWidth = width(parent->fontMetrics(), parent, parent->lastColumn());
415 int EventListViewItemBase::iconWidth()
419 mTextIcon =
new TQPixmap(SmallIcon(
"message"));
420 mFileIcon =
new TQPixmap(SmallIcon(
"file"));
421 mCommandIcon =
new TQPixmap(SmallIcon(
"application-x-executable"));
422 mEmailIcon =
new TQPixmap(SmallIcon(
"mail_generic"));
424 mIconWidth = mTextIcon->width();
425 if (mFileIcon && mFileIcon->width() > mIconWidth)
426 mIconWidth = mFileIcon->width();
427 if (mCommandIcon && mCommandIcon->width() > mIconWidth)
428 mIconWidth = mCommandIcon->width();
429 if (mEmailIcon && mEmailIcon->width() > mIconWidth)
430 mIconWidth = mEmailIcon->width();
438 TQPixmap* EventListViewItemBase::eventIcon()
const
440 switch (mEvent.action())
442 case KAAlarm::FILE:
return mFileIcon;
443 case KAAlarm::COMMAND:
return mCommandIcon;
444 case KAAlarm::EMAIL:
return mEmailIcon;
445 case KAAlarm::MESSAGE:
446 default:
return mTextIcon;
456 TQString EventListWhatsThisBase::text(
const TQPoint& pt)
459 TQPoint viewportPt = mListView->viewport()->mapFrom(mListView, pt);
460 TQRect frame = mListView->header()->frameGeometry();
461 if (frame.contains(pt)
462 || (mListView->itemAt(TQPoint(mListView->itemMargin(), viewportPt.y())) && frame.contains(TQPoint(pt.x(), frame.y()))))
463 column = mListView->header()->sectionAt(pt.x());
464 return mListView->whatsThisText(column);
KAEvent corresponds to a KCal::Event instance.