Files
qt6-migration-pipeline/Lts/Common/LtsTimeline/timeline_view_track_handler.cpp
T

108 lines
2.6 KiB
C++
Executable File

#include "timeline_view_resize_handler.h"
#include "timeline_view.h"
#include "timeline_header_view.h"
#include "item.h"
#include "track.h"
#include <LtsWidgets/lts_message_dialog.h>
#include <QApplication>
#include <QMouseEvent>
#include <QDebug>
namespace LtsTimeline
{
TimelineViewTrackHandler::TimelineViewTrackHandler(TimelineView *view)
: m_view(view)
{
}
TimelineViewTrackHandler::~TimelineViewTrackHandler()
{
m_view = nullptr;
}
void TimelineViewTrackHandler::mouseDoubleClickEvent(QMouseEvent *e)
{
if (e->button() != Qt::LeftButton)
return;
const QModelIndex index = m_view->indexAt(e->pos());
if (!index.isValid() || index.column() != Section::eActuator)
return;
emit m_view->trackActivated(index.data().toInt());
}
void TimelineViewTrackHandler::mousePressEvent(QMouseEvent *e)
{
if (e->button() != Qt::LeftButton)
{
if (e->button() == Qt::RightButton)
emit m_view->customContextMenuRequested(e->pos());
return;
}
const QModelIndex index = m_view->indexAt(e->pos());
if (!index.isValid() || index.column() != Section::eActuator)
return;
try
{
if(!m_view->timelineModel()->isEditable())
return;
const Track &track = m_view->timelineModel()->track(index.data(Qt::UserRole).toInt());
QRect visRect = m_view->visualRect(index);
int buttonLength = visRect.height() / 2;
if (track.hasInsertButton())
{
QRect rect = QRect(visRect.right() - buttonLength, visRect.top(), buttonLength, buttonLength);
if (rect.contains(e->pos()))
{
m_pressedInsertButtonIndex = index;
m_view->timelineModel()->onInsertTrack(index);
return;
}
}
if (track.hasRemoveButton())
{
QRect rect = QRect(visRect.right() - buttonLength, visRect.center().y(), buttonLength, buttonLength);
if (rect.contains(e->pos()))
{
m_pressedRemoveButtonIndex = index;
auto msg = new LtsWidgets::LtsMessageDialogNew(m_view, {}, QApplication::translate("LtsTimeline", "Do you really want to remove this filter track and all of its contents?"),
LtsWidgets::Behaviour::Modal, LtsWidgets::Button::Yes | LtsWidgets::Button::Cancel);
QObject::connect(msg, &LtsWidgets::LtsMessageDialogNew::yes,
m_view, [this, index]()
{
m_view->timelineModel()->onRemoveTrack(index);
});
return;
}
}
}
catch (...) {}
}
void TimelineViewTrackHandler::mouseReleaseEvent(QMouseEvent *e)
{
Q_UNUSED(e);
m_pressedInsertButtonIndex = {};
m_pressedRemoveButtonIndex = {};
}
}