2011-03-25 09:25:17 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
|
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2011-03-25 09:25:17 +01:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-07-06 15:48:52 +00:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2011-03-25 09:25:17 +01:00
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-07-06 15:48:52 +00:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2011-03-25 09:25:17 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-07-06 15:48:52 +00:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2011-03-25 09:25:17 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2011-03-25 09:25:17 +01:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
2011-03-11 12:22:57 +01:00
|
|
|
#include "timelineview.h"
|
|
|
|
|
|
|
|
|
|
#include <qdeclarativecontext.h>
|
|
|
|
|
#include <qdeclarativeproperty.h>
|
2011-07-26 13:56:14 +02:00
|
|
|
#include <QtCore/QTimer>
|
2011-10-26 11:32:01 +02:00
|
|
|
#include <QtGui/QPixmap>
|
|
|
|
|
#include <QtGui/QPainter>
|
|
|
|
|
#include <QtGui/QGraphicsSceneMouseEvent>
|
|
|
|
|
|
|
|
|
|
#include <math.h>
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2011-03-25 09:21:00 +01:00
|
|
|
using namespace QmlProfiler::Internal;
|
|
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
const int DefaultRowHeight = 30;
|
2011-07-26 13:56:14 +02:00
|
|
|
|
2011-03-11 12:22:57 +01:00
|
|
|
TimelineView::TimelineView(QDeclarativeItem *parent) :
|
2011-10-26 11:32:01 +02:00
|
|
|
QDeclarativeItem(parent), m_startTime(0), m_endTime(0), m_spacing(0),
|
|
|
|
|
m_lastStartTime(0), m_lastEndTime(0), m_eventList(0)
|
2011-03-11 12:22:57 +01:00
|
|
|
{
|
2011-10-26 11:32:01 +02:00
|
|
|
clearData();
|
|
|
|
|
setFlag(QGraphicsItem::ItemHasNoContents, false);
|
|
|
|
|
setAcceptedMouseButtons(Qt::LeftButton);
|
|
|
|
|
setAcceptHoverEvents(true);
|
|
|
|
|
for (int i=0; i<QmlJsDebugClient::MaximumQmlEventType; i++)
|
|
|
|
|
m_rowsExpanded << false;
|
2011-03-11 12:22:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TimelineView::componentComplete()
|
|
|
|
|
{
|
2011-10-26 11:32:01 +02:00
|
|
|
const QMetaObject *metaObject = this->metaObject();
|
|
|
|
|
int propertyCount = metaObject->propertyCount();
|
|
|
|
|
int requestPaintMethod = metaObject->indexOfMethod("requestPaint()");
|
|
|
|
|
for (int ii = TimelineView::staticMetaObject.propertyCount(); ii < propertyCount; ++ii) {
|
|
|
|
|
QMetaProperty p = metaObject->property(ii);
|
|
|
|
|
if (p.hasNotifySignal())
|
|
|
|
|
QMetaObject::connect(this, p.notifySignalIndex(), this, requestPaintMethod, 0, 0);
|
|
|
|
|
}
|
2011-03-11 12:22:57 +01:00
|
|
|
QDeclarativeItem::componentComplete();
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
void TimelineView::requestPaint()
|
2011-03-11 12:22:57 +01:00
|
|
|
{
|
2011-10-26 11:32:01 +02:00
|
|
|
update();
|
2011-03-11 12:22:57 +01:00
|
|
|
}
|
|
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
void TimelineView::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
|
2011-03-11 12:22:57 +01:00
|
|
|
{
|
2011-10-26 11:32:01 +02:00
|
|
|
qint64 windowDuration = m_endTime - m_startTime;
|
|
|
|
|
if (windowDuration <= 0)
|
2011-03-11 12:22:57 +01:00
|
|
|
return;
|
|
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
m_spacing = qreal(width()) / windowDuration;
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
m_rowWidths.clear();
|
2011-11-16 16:08:05 +01:00
|
|
|
// The "1+" is because the reference screenshot features an empty row per type, in order to leave space for the title
|
2011-10-26 11:32:01 +02:00
|
|
|
for (int i=0; i<QmlJsDebugClient::MaximumQmlEventType; i++) {
|
2011-11-16 16:08:05 +01:00
|
|
|
m_rowWidths << 1 + (m_rowsExpanded[i] ? m_eventList->uniqueEventsOfType(i) : m_eventList->maxNestingForType(i));
|
2011-10-26 11:32:01 +02:00
|
|
|
}
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
// event rows
|
|
|
|
|
m_rowStarts.clear();
|
|
|
|
|
int pos = 0;
|
|
|
|
|
for (int i=0; i<QmlJsDebugClient::MaximumQmlEventType; i++) {
|
|
|
|
|
m_rowStarts << pos;
|
|
|
|
|
pos += DefaultRowHeight * m_rowWidths[i];
|
|
|
|
|
}
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
p->setPen(Qt::transparent);
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
// speedup: don't draw overlapping events, just skip them
|
|
|
|
|
m_rowLastX.clear();
|
|
|
|
|
for (int i=0; i<QmlJsDebugClient::MaximumQmlEventType; i++)
|
|
|
|
|
for (int j=0; j<m_rowWidths[i]; j++)
|
|
|
|
|
m_rowLastX << -m_startTime * m_spacing;
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
int firstIndex = m_eventList->findFirstIndex(m_startTime);
|
|
|
|
|
int lastIndex = m_eventList->findLastIndex(m_endTime);
|
|
|
|
|
drawItemsToPainter(p, firstIndex, lastIndex);
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
drawSelectionBoxes(p);
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
m_lastStartTime = m_startTime;
|
|
|
|
|
m_lastEndTime = m_endTime;
|
|
|
|
|
}
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
QColor TimelineView::colorForItem(int itemIndex)
|
|
|
|
|
{
|
2011-11-04 17:33:09 +01:00
|
|
|
int ndx = m_eventList->getEventId(itemIndex);
|
2011-10-26 11:32:01 +02:00
|
|
|
return QColor::fromHsl((ndx*25)%360, 76, 166);
|
|
|
|
|
}
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
void TimelineView::drawItemsToPainter(QPainter *p, int fromIndex, int toIndex)
|
|
|
|
|
{
|
|
|
|
|
int x,y,width,rowNumber, eventType;
|
|
|
|
|
for (int i = fromIndex; i <= toIndex; i++) {
|
|
|
|
|
x = (m_eventList->getStartTime(i) - m_startTime) * m_spacing;
|
|
|
|
|
eventType = m_eventList->getType(i);
|
|
|
|
|
if (m_rowsExpanded[eventType])
|
2011-11-16 16:08:05 +01:00
|
|
|
y = m_rowStarts[eventType] + DefaultRowHeight*(m_eventList->eventPosInType(i) + 1);
|
2011-07-26 13:56:14 +02:00
|
|
|
else
|
2011-11-16 16:08:05 +01:00
|
|
|
y = m_rowStarts[eventType] + DefaultRowHeight*m_eventList->getNestingLevel(i);
|
2011-10-26 11:32:01 +02:00
|
|
|
|
|
|
|
|
width = m_eventList->getDuration(i)*m_spacing;
|
|
|
|
|
if (width<1)
|
|
|
|
|
width = 1;
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
rowNumber = y/DefaultRowHeight;
|
|
|
|
|
if (m_rowLastX[rowNumber] > x+width)
|
|
|
|
|
continue;
|
|
|
|
|
m_rowLastX[rowNumber] = x+width;
|
2011-07-26 13:56:14 +02:00
|
|
|
|
2011-11-16 16:08:05 +01:00
|
|
|
p->setBrush(colorForItem(i));
|
2011-10-26 11:32:01 +02:00
|
|
|
p->drawRect(x,y,width,DefaultRowHeight);
|
|
|
|
|
}
|
2011-07-26 13:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
void TimelineView::drawSelectionBoxes(QPainter *p)
|
2011-07-26 13:56:14 +02:00
|
|
|
{
|
2011-10-26 11:32:01 +02:00
|
|
|
if (m_selectedItem == -1)
|
|
|
|
|
return;
|
2011-07-26 13:56:14 +02:00
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
int fromIndex = m_eventList->findFirstIndex(m_startTime);
|
|
|
|
|
int toIndex = m_eventList->findLastIndex(m_endTime);
|
2011-11-04 17:33:09 +01:00
|
|
|
int id = m_eventList->getEventId(m_selectedItem);
|
2011-07-26 13:56:14 +02:00
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
p->setBrush(Qt::transparent);
|
2011-11-16 16:08:05 +01:00
|
|
|
QColor selectionColor = Qt::blue;
|
|
|
|
|
if (m_selectionLocked)
|
|
|
|
|
selectionColor = QColor(96,0,255);
|
|
|
|
|
QPen strongPen(selectionColor, 3);
|
|
|
|
|
QPen lightPen(QBrush(selectionColor.lighter(130)), 2);
|
2011-10-26 11:32:01 +02:00
|
|
|
p->setPen(lightPen);
|
|
|
|
|
|
2011-11-08 11:05:07 +01:00
|
|
|
int x, y, width, eventType;
|
2011-11-23 16:17:33 +01:00
|
|
|
p->setPen(lightPen);
|
|
|
|
|
|
|
|
|
|
QRect selectedItemRect(0,0,0,0);
|
2011-10-26 11:32:01 +02:00
|
|
|
for (int i = fromIndex; i <= toIndex; i++) {
|
2011-11-04 17:33:09 +01:00
|
|
|
if (m_eventList->getEventId(i) != id)
|
2011-10-26 11:32:01 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
x = (m_eventList->getStartTime(i) - m_startTime) * m_spacing;
|
|
|
|
|
eventType = m_eventList->getType(i);
|
|
|
|
|
if (m_rowsExpanded[eventType])
|
2011-11-16 16:08:05 +01:00
|
|
|
y = m_rowStarts[eventType] + DefaultRowHeight*(m_eventList->eventPosInType(i) + 1);
|
2011-10-26 11:32:01 +02:00
|
|
|
else
|
2011-11-16 16:08:05 +01:00
|
|
|
y = m_rowStarts[eventType] + DefaultRowHeight*m_eventList->getNestingLevel(i);
|
2011-07-26 13:56:14 +02:00
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
width = m_eventList->getDuration(i)*m_spacing;
|
|
|
|
|
if (width<1)
|
|
|
|
|
width = 1;
|
2011-07-26 13:56:14 +02:00
|
|
|
|
2011-11-23 16:17:33 +01:00
|
|
|
if (i == m_selectedItem)
|
|
|
|
|
selectedItemRect = QRect(x,y,width,DefaultRowHeight);
|
|
|
|
|
else
|
|
|
|
|
p->drawRect(x,y,width,DefaultRowHeight);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// draw the selected item rectangle the last, so that it's overlayed
|
|
|
|
|
if (selectedItemRect.width() != 0) {
|
|
|
|
|
p->setPen(strongPen);
|
|
|
|
|
p->drawRect(selectedItemRect);
|
2011-10-26 11:32:01 +02:00
|
|
|
}
|
2011-07-26 13:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
void TimelineView::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
2011-07-26 13:56:14 +02:00
|
|
|
{
|
2011-10-26 11:32:01 +02:00
|
|
|
// special case: if there is a drag area below me, don't accept the
|
|
|
|
|
// events unless I'm actually clicking inside an item
|
|
|
|
|
if (m_currentSelection.eventIndex == -1 &&
|
|
|
|
|
event->pos().x()+x() >= m_startDragArea &&
|
|
|
|
|
event->pos().x()+x() <= m_endDragArea)
|
|
|
|
|
event->setAccepted(false);
|
|
|
|
|
|
2011-07-26 13:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
void TimelineView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
2011-07-26 13:56:14 +02:00
|
|
|
{
|
2011-10-26 11:32:01 +02:00
|
|
|
Q_UNUSED(event);
|
|
|
|
|
manageClicked();
|
2011-07-26 13:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
void TimelineView::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
2011-07-26 13:56:14 +02:00
|
|
|
{
|
2011-10-26 11:32:01 +02:00
|
|
|
event->setAccepted(false);
|
|
|
|
|
}
|
2011-07-26 13:56:14 +02:00
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
|
|
|
|
|
void TimelineView::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(event);
|
|
|
|
|
manageHovered(event->pos().x(), event->pos().y());
|
|
|
|
|
if (m_currentSelection.eventIndex == -1)
|
|
|
|
|
event->setAccepted(false);
|
2011-07-26 13:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
void TimelineView::manageClicked()
|
2011-07-26 13:56:14 +02:00
|
|
|
{
|
2011-10-26 11:32:01 +02:00
|
|
|
if (m_currentSelection.eventIndex != -1) {
|
|
|
|
|
if (m_currentSelection.eventIndex == m_selectedItem)
|
|
|
|
|
setSelectionLocked(!m_selectionLocked);
|
|
|
|
|
else
|
|
|
|
|
setSelectionLocked(true);
|
|
|
|
|
emit itemPressed(m_currentSelection.eventIndex);
|
|
|
|
|
} else {
|
|
|
|
|
// setSelectionLocked(false);
|
2011-07-26 13:56:14 +02:00
|
|
|
}
|
2011-10-26 11:32:01 +02:00
|
|
|
setSelectedItem(m_currentSelection.eventIndex);
|
|
|
|
|
}
|
2011-07-26 13:56:14 +02:00
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
void TimelineView::manageHovered(int x, int y)
|
|
|
|
|
{
|
2011-11-09 17:35:12 +01:00
|
|
|
if (m_endTime - m_startTime <=0 || m_lastEndTime - m_lastStartTime <= 0)
|
2011-10-26 11:32:01 +02:00
|
|
|
return;
|
2011-07-26 13:56:14 +02:00
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
qint64 time = x * (m_endTime - m_startTime) / width() + m_startTime;
|
|
|
|
|
int row = y / DefaultRowHeight;
|
2011-07-26 13:56:14 +02:00
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
// already covered? nothing to do
|
|
|
|
|
if (m_currentSelection.eventIndex != -1 && time >= m_currentSelection.startTime && time <= m_currentSelection.endTime && row == m_currentSelection.row) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-07-26 13:56:14 +02:00
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
// find if there's items in the time range
|
|
|
|
|
int eventFrom = m_eventList->findFirstIndex(time);
|
|
|
|
|
int eventTo = m_eventList->findLastIndex(time);
|
|
|
|
|
if (eventTo < eventFrom) {
|
|
|
|
|
m_currentSelection.eventIndex = -1;
|
2011-07-26 13:56:14 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
// find if we are in the right column
|
|
|
|
|
int itemRow, eventType;
|
|
|
|
|
for (int i=eventTo; i>=eventFrom; --i) {
|
|
|
|
|
if (ceil(m_eventList->getEndTime(i)*m_spacing) < floor(time*m_spacing))
|
|
|
|
|
continue;
|
2011-07-26 13:56:14 +02:00
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
eventType = m_eventList->getType(i);
|
|
|
|
|
if (m_rowsExpanded[eventType])
|
2011-11-16 16:08:05 +01:00
|
|
|
itemRow = m_rowStarts[eventType]/DefaultRowHeight + m_eventList->eventPosInType(i) + 1;
|
2011-10-26 11:32:01 +02:00
|
|
|
else
|
2011-11-16 16:08:05 +01:00
|
|
|
itemRow = m_rowStarts[eventType]/DefaultRowHeight + m_eventList->getNestingLevel(i);
|
2011-10-26 11:32:01 +02:00
|
|
|
if (itemRow == row) {
|
|
|
|
|
// match
|
|
|
|
|
m_currentSelection.eventIndex = i;
|
|
|
|
|
m_currentSelection.startTime = m_eventList->getStartTime(i);
|
|
|
|
|
m_currentSelection.endTime = m_eventList->getEndTime(i);
|
|
|
|
|
m_currentSelection.row = row;
|
|
|
|
|
if (!m_selectionLocked)
|
|
|
|
|
setSelectedItem(i);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-07-26 13:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
m_currentSelection.eventIndex = -1;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TimelineView::clearData()
|
|
|
|
|
{
|
|
|
|
|
m_startTime = 0;
|
|
|
|
|
m_endTime = 0;
|
|
|
|
|
m_lastStartTime = 0;
|
|
|
|
|
m_lastEndTime = 0;
|
|
|
|
|
m_currentSelection.startTime = -1;
|
|
|
|
|
m_currentSelection.endTime = -1;
|
|
|
|
|
m_currentSelection.row = -1;
|
|
|
|
|
m_currentSelection.eventIndex = -1;
|
|
|
|
|
m_selectedItem = -1;
|
|
|
|
|
m_selectionLocked = true;
|
2011-07-26 13:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qint64 TimelineView::getDuration(int index) const
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(m_eventList);
|
|
|
|
|
return m_eventList->getEndTime(index) - m_eventList->getStartTime(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString TimelineView::getFilename(int index) const
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(m_eventList);
|
|
|
|
|
return m_eventList->getFilename(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TimelineView::getLine(int index) const
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(m_eventList);
|
|
|
|
|
return m_eventList->getLine(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString TimelineView::getDetails(int index) const
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(m_eventList);
|
|
|
|
|
return m_eventList->getDetails(index);
|
2011-03-11 12:22:57 +01:00
|
|
|
}
|
2011-10-26 11:32:01 +02:00
|
|
|
|
2011-11-23 16:17:33 +01:00
|
|
|
void TimelineView::setRowExpanded(int rowIndex, bool expanded)
|
|
|
|
|
{
|
|
|
|
|
m_rowsExpanded[rowIndex] = expanded;
|
|
|
|
|
update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TimelineView::selectNext()
|
|
|
|
|
{
|
|
|
|
|
if (m_eventList->count() == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// select next in view or after
|
|
|
|
|
int newIndex = m_selectedItem+1;
|
|
|
|
|
if (newIndex >= m_eventList->count())
|
|
|
|
|
newIndex = 0;
|
|
|
|
|
if (m_eventList->getEndTime(newIndex) < m_startTime)
|
|
|
|
|
newIndex = m_eventList->findFirstIndexNoParents(m_startTime);
|
|
|
|
|
setSelectedItem(newIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TimelineView::selectPrev()
|
|
|
|
|
{
|
|
|
|
|
if (m_eventList->count() == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// select last in view or before
|
|
|
|
|
int newIndex = m_selectedItem-1;
|
|
|
|
|
if (newIndex < 0)
|
|
|
|
|
newIndex = m_eventList->count()-1;
|
|
|
|
|
if (m_eventList->getStartTime(newIndex) > m_endTime)
|
|
|
|
|
newIndex = m_eventList->findLastIndex(m_endTime);
|
|
|
|
|
setSelectedItem(newIndex);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-09 12:57:41 +01:00
|
|
|
int TimelineView::nextItemFromId(int eventId) const
|
|
|
|
|
{
|
|
|
|
|
int ndx = -1;
|
|
|
|
|
if (m_selectedItem == -1)
|
|
|
|
|
ndx = m_eventList->findFirstIndexNoParents(m_startTime);
|
|
|
|
|
else
|
|
|
|
|
ndx = m_selectedItem + 1;
|
|
|
|
|
if (ndx >= m_eventList->count())
|
|
|
|
|
ndx = 0;
|
|
|
|
|
int startIndex = ndx;
|
|
|
|
|
do {
|
|
|
|
|
if (m_eventList->getEventId(ndx) == eventId)
|
|
|
|
|
return ndx;
|
2011-11-16 16:08:05 +01:00
|
|
|
ndx = (ndx + 1) % m_eventList->count();
|
2011-11-09 12:57:41 +01:00
|
|
|
} while (ndx != startIndex);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-23 16:17:33 +01:00
|
|
|
int TimelineView::prevItemFromId(int eventId) const
|
2011-10-26 11:32:01 +02:00
|
|
|
{
|
2011-11-23 16:17:33 +01:00
|
|
|
int ndx = -1;
|
|
|
|
|
if (m_selectedItem == -1)
|
|
|
|
|
ndx = m_eventList->findFirstIndexNoParents(m_startTime);
|
|
|
|
|
else
|
|
|
|
|
ndx = m_selectedItem - 1;
|
|
|
|
|
if (ndx < 0)
|
|
|
|
|
ndx = m_eventList->count() - 1;
|
|
|
|
|
int startIndex = ndx;
|
|
|
|
|
do {
|
|
|
|
|
if (m_eventList->getEventId(ndx) == eventId)
|
|
|
|
|
return ndx;
|
|
|
|
|
if (--ndx < 0)
|
|
|
|
|
ndx = m_eventList->count()-1;
|
|
|
|
|
} while (ndx != startIndex);
|
|
|
|
|
return -1;
|
2011-10-26 11:32:01 +02:00
|
|
|
}
|
|
|
|
|
|
2011-11-23 16:17:33 +01:00
|
|
|
void TimelineView::selectNextFromId(int eventId)
|
2011-10-26 11:32:01 +02:00
|
|
|
{
|
2011-11-23 16:17:33 +01:00
|
|
|
int eventIndex = nextItemFromId(eventId);
|
|
|
|
|
if (eventIndex != -1)
|
|
|
|
|
setSelectedItem(eventIndex);
|
2011-10-26 11:32:01 +02:00
|
|
|
}
|
|
|
|
|
|
2011-11-23 16:17:33 +01:00
|
|
|
void TimelineView::selectPrevFromId(int eventId)
|
2011-10-26 11:32:01 +02:00
|
|
|
{
|
2011-11-23 16:17:33 +01:00
|
|
|
int eventIndex = prevItemFromId(eventId);
|
|
|
|
|
if (eventIndex != -1)
|
|
|
|
|
setSelectedItem(eventIndex);
|
2011-10-26 11:32:01 +02:00
|
|
|
}
|