void CTimeline::mouseDoubleClickEvent(QMouseEvent* event) { const QPoint mousePos(event->x(), event->y()); if (m_frameCount == 0 || mousePos.x() <= m_leftWidth) return; int frame = (mousePos.x() - m_leftWidth) + m_viewPos.x() - 2; if (frame <= 0) frame = 0; else frame /= m_frameWidth; if (m_frameCount != -1 && frame >= m_frameCount) return; int row = event->y() + m_viewPos.y(); row -= m_rowHeight; if (row <= 0) return; row /= m_rowHeight; if (row >= m_rows.size()) return; if (m_rows[row].keys.contains(frame)) { int i = 0; for (auto it = m_rows[row].keys.begin(); it != m_rows[row].keys.end();) { if ((*it) == frame) { it = m_rows[row].keys.erase(it); emit KeyModified(row, frame, true); if (m_selection.y() == row && m_selection.x() == i) { m_selection.setX(-1); _emitSelectionChanged(); } break; } else it++; i++; } } else { m_rows[row].keys.push_back(frame); emit KeyModified(row, frame, false); m_selection = QPoint(m_rows[row].keys.size() - 1, row); _emitSelectionChanged(); } update(); event->accept(); }
void FloatTrackEditor::mouseMoveEvent(QMouseEvent *event) { event->accept(); if(mIsEditingKey) { int yValue = qBound(event->pos().y(), rect().y(), rect().y() + rect().height()); mLastMousePosition = QPoint(mLastMousePosition.x(), yValue); QCursor::setPos(mapToGlobal(mLastMousePosition)); // Cut the position down into increments of tenths of a second double keyPosition = (mLastMousePosition.x() / (UIConstants::SecondSizeInPixels / 10)) / 10.0f; float dataValue = (1.0f - ((float)(mLastMousePosition.y() - rect().y()) / (float)rect().height())) * 100.0f; FloatTrack* floatTrack = static_cast<FloatTrack*>(mTrack); unsigned int keyIndex = 0; if(floatTrack->GetKeyIndex(keyPosition, &keyIndex)) { floatTrack->GetKey(keyIndex).SetData(dataValue); emit KeyModified(floatTrack, keyPosition, dataValue); } } else { mLastMousePosition = event->pos(); } update(); }
void FloatTrackEditor::mousePressEvent(QMouseEvent *event) { mLastMousePosition = event->pos(); event->accept(); // Cut the position down into increments of tenths of a second double keyPosition = (mLastMousePosition.x() / (UIConstants::SecondSizeInPixels / 10)) / 10.0f; float dataValue = (1.0f - ((float)(mLastMousePosition.y() - rect().y()) / (float)rect().height())) * 100.0f; FloatTrack* floatTrack = static_cast<FloatTrack*>(mTrack); unsigned int keyIndex = 0; if(floatTrack->GetKeyIndex(keyPosition, &keyIndex)) { if(event->button() == Qt::RightButton) { floatTrack->RemoveKey(keyIndex); emit KeyRemoved(floatTrack, keyPosition); } else { floatTrack->GetKey(keyIndex).SetData(dataValue); emit KeyModified(floatTrack, keyPosition, dataValue); mIsEditingKey = true; } } else { if(event->button() == Qt::LeftButton) { floatTrack->AddKey(keyPosition, dataValue); emit KeyAdded(floatTrack, keyPosition, dataValue); mIsEditingKey = true; } } update(); }