22 #include "eventlistview.moc"
30 #include <kglobalsettings.h>
34 #include <QHeaderView>
35 #include <QMouseEvent>
37 #include <QApplication>
43 mEditOnSingleClick(false)
45 setRootIsDecorated(
false);
46 setSortingEnabled(
true);
47 setAllColumnsShowFocus(
true);
48 setSelectionMode(ExtendedSelection);
49 setSelectionBehavior(SelectRows);
50 setTextElideMode(Qt::ElideRight);
52 setWhatsThis(i18nc(
"@info:whatsthis",
"List of scheduled alarms"));
61 return itemModel()->event(index);
66 return itemModel()->event(itemModel()->index(row, 0));
86 select(itemModel()->eventIndex(eventId));
97 selectionModel()->select(index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
104 selectionModel()->clearSelection();
113 QModelIndexList list = selectionModel()->selectedRows();
114 if (list.count() != 1)
115 return QModelIndex();
126 QModelIndexList list = selectionModel()->selectedRows();
127 if (list.count() != 1)
129 kDebug(0)<<
"SelectedEvent() count="<<list.count();
131 return model->
event(list[0]);
136 QModelIndexList list = selectionModel()->selectedRows();
137 if (list.count() != 1)
139 kDebug(0)<<
"SelectedEvent() count="<<list.count();
140 const QAbstractProxyModel* proxy =
static_cast<const QAbstractProxyModel*
>(list[0].model());
141 QModelIndex source = proxy->mapToSource(list[0]);
142 return static_cast<KAEvent*
>(source.internalPointer());
156 QVector<KAEvent> elist;
160 QModelIndexList ixlist = selectionModel()->selectedRows();
161 int count = ixlist.count();
166 for (
int i = 0; i < count; ++i)
167 elist += model->
event(ixlist[i]);
169 const QAbstractProxyModel* proxy =
static_cast<const QAbstractProxyModel*
>(ixlist[0].model());
170 for (
int i = 0; i < count; ++i)
172 QModelIndex source = proxy->mapToSource(ixlist[i]);
173 elist +=
static_cast<KAEvent*
>(source.internalPointer());
188 mFind =
new Find(
this);
189 connect(mFind, SIGNAL(active(
bool)), SIGNAL(
findActive(
bool)));
197 void EventListView::findNext(
bool forward)
208 if (e->type() == QEvent::ToolTip && isActiveWindow())
210 QHelpEvent* he =
static_cast<QHelpEvent*
>(e);
211 QModelIndex index = indexAt(he->pos());
212 QVariant value = model()->data(index, Qt::ToolTipRole);
213 if (qVariantCanConvert<QString>(value))
215 QString toolTip = value.toString();
216 int i = toolTip.indexOf(QLatin1Char(
'\n'));
221 if (!m || m->
event(index).commandError() == KAEvent::CMD_NO_ERROR)
224 if (!m || m->
event(index)->commandError() == KAEvent::CMD_NO_ERROR)
229 value = model()->data(index, Qt::FontRole);
230 QFontMetrics fm(qvariant_cast<QFont>(value).resolve(viewOptions().font));
231 int textWidth = fm.boundingRect(toolTip).width() + 1;
232 const int margin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
233 int left = columnViewportPosition(index.column()) + margin;
234 int right = left + textWidth;
235 if (left >= 0 && right <= width() - 2*frameWidth())
239 QToolTip::showText(he->globalPos(), toolTip,
this);
243 return QTreeView::viewportEvent(e);
262 case QEvent::MouseButtonPress:
263 case QEvent::MouseMove:
265 case QEvent::MouseButtonDblClick:
267 case QEvent::MouseButtonRelease:
269 if (!static_cast<EventListView*>(parent())->editOnSingleClick()
270 || !KGlobalSettings::singleClick())
272 QMouseEvent* me =
static_cast<QMouseEvent*
>(e);
273 if (me->button() != Qt::LeftButton || me->buttons()
274 || me->modifiers() != Qt::NoModifier)
287 kError() <<
"Invalid cast to ItemListModel*";
290 KAEvent
event = itemModel->
event(index);
291 edit(&event, static_cast<EventListView*>(parent()));
295 QModelIndex source =
static_cast<QAbstractProxyModel*
>(model)->mapToSource(index);
296 KAEvent*
event =
static_cast<KAEvent*
>(source.internalPointer());
297 edit(event, static_cast<EventListView*>(parent()));
KAEvent * selectedEvent() const
virtual bool editorEvent(QEvent *, QAbstractItemModel *, const QStyleOptionViewItem &, const QModelIndex &)
EventListView(QWidget *parent=0)
KAEvent event(int row) const
KAEvent::List selectedEvents() const
void contextMenuRequested(const QPoint &globalPos)
KAEvent * event(int row) const
void select(const QString &eventId, bool scrollToEvent=false)
virtual void edit(KAEvent *, EventListView *)=0
QModelIndex selectedIndex() const
EventListFilterModel * eventFilterModel() const
virtual void contextMenuEvent(QContextMenuEvent *)
KAEvent * event(int row) const
virtual bool viewportEvent(QEvent *)
void findNext(bool forward)