170 lines
6.0 KiB
C++
170 lines
6.0 KiB
C++
#include "track_select_handler.h"
|
|
|
|
#include "tools.h"
|
|
#include "track_content_widget.h"
|
|
#include "track_entry.h"
|
|
|
|
#include <QtCore/QCoreApplication>
|
|
#include <QtCore/QDebug>
|
|
#include <QtGui/QGuiApplication>
|
|
#include <QtWidgets/QInputDialog>
|
|
#include <QtGui/QKeyEvent>
|
|
#include <QtWidgets/QMenu>
|
|
#include <QtGui/QMouseEvent>
|
|
|
|
namespace LtsScriptTimeline
|
|
{
|
|
|
|
void SelectHandler::slotSetDescription()
|
|
{
|
|
if (m_pressedEntry == nullptr)
|
|
return;
|
|
|
|
bool ok;
|
|
QString iniDescription = m_pressedEntry->m_description;
|
|
QString text =
|
|
QInputDialog::getText(tcw, tr("Operator Application"), tr("Topic Description:"), QLineEdit::Normal,
|
|
iniDescription, &ok, Qt::Popup | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
|
|
if (ok)
|
|
{
|
|
m_pressedEntry->m_description = text;
|
|
emit tcw->signalChangesMade();
|
|
}
|
|
}
|
|
|
|
void SelectHandler::mouseDoubleClick(QMouseEvent* event)
|
|
{
|
|
if (m_pressedEntry != nullptr && tcw->m_selected.count() == 1 && !tcw->m_isMultiLineMultiSelectionMode &&
|
|
event->buttons() == Qt::LeftButton)
|
|
emit tcw->signalEditEntry(m_pressedEntry->m_topicId);
|
|
}
|
|
|
|
void SelectHandler::mousePressEvent(QMouseEvent* event)
|
|
{
|
|
if (event->buttons() == Qt::LeftButton)
|
|
{
|
|
m_pressedEntry = nullptr;
|
|
|
|
QPoint clickedPos = tcw->mapFromGlobal(event->globalPosition().toPoint());
|
|
int clickedPosY = clickedPos.y();
|
|
int clickedPosX = clickedPos.x();
|
|
|
|
if (clickedPosY < 0 || clickedPosY > tcw->height())
|
|
return;
|
|
|
|
int clickedTime = tcw->m_tools->getTime(clickedPosX, tcw->m_isFilter);
|
|
m_pressedEntry = tcw->getTrackEntryAt(clickedTime);
|
|
}
|
|
else if (event->buttons() == Qt::RightButton)
|
|
{
|
|
QMenu* contextMenu = new QMenu(tcw);
|
|
contextMenu->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
contextMenu->addSection(tr("All tracks"));
|
|
{
|
|
QAction* action = new QAction(tr("Set topic description"), tcw);
|
|
action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_D));
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
|
|
action->setShortcutVisibleInContextMenu(true);
|
|
#endif
|
|
action->setIcon(QIcon(QStringLiteral("icon:document-edit.svg")));
|
|
action->setEnabled(m_pressedEntry);
|
|
if (!m_pressedEntry)
|
|
action->setToolTip(tr("Right click directly on a single Topic to edit its description."));
|
|
connect(action, &QAction::triggered, this, &SelectHandler::slotSetDescription);
|
|
contextMenu->addAction(action);
|
|
}
|
|
|
|
{
|
|
QAction* action = new QAction(tr("Remove selected Topic(s)"), tcw);
|
|
action->setShortcut(QKeySequence(Qt::Key_Delete));
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
|
|
action->setShortcutVisibleInContextMenu(true);
|
|
#endif
|
|
action->setIcon(QIcon(QStringLiteral("icon:delete.svg")));
|
|
connect(action, &QAction::triggered, tcw, &TrackContentWidget::signalDeleteSelectedTopics);
|
|
contextMenu->addAction(action);
|
|
}
|
|
|
|
contextMenu->addSection(tr("Main track only"));
|
|
|
|
{
|
|
QAction* action = new QAction(tr("Select all topics"), tcw);
|
|
action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_A));
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
|
|
action->setShortcutVisibleInContextMenu(true);
|
|
#endif
|
|
action->setIcon(QIcon(QStringLiteral("icon:selection_rec.svg")));
|
|
connect(action, &QAction::triggered, tcw, &TrackContentWidget::signalSelectAllGlobal);
|
|
contextMenu->addAction(action);
|
|
}
|
|
|
|
{
|
|
|
|
QAction* action = new QAction(tr("Cut selected topic(s)"), tcw);
|
|
action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_X));
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
|
|
action->setShortcutVisibleInContextMenu(true);
|
|
#endif
|
|
action->setIcon(QIcon(QStringLiteral("icon:edit-cut.svg")));
|
|
connect(action, &QAction::triggered, tcw, &TrackContentWidget::signalCutTopics);
|
|
contextMenu->addAction(action);
|
|
}
|
|
|
|
{
|
|
QAction* action = new QAction(tr("Copy selected topic(s)"), tcw);
|
|
action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_C));
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
|
|
action->setShortcutVisibleInContextMenu(true);
|
|
#endif
|
|
action->setIcon(QIcon(QStringLiteral("icon:edit-copy.svg")));
|
|
connect(action, &QAction::triggered, tcw, &TrackContentWidget::signalCopyTopics);
|
|
contextMenu->addAction(action);
|
|
}
|
|
|
|
{
|
|
QAction* action = new QAction(tr("Paste topic(s) at indicator position"), tcw);
|
|
action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_V));
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
|
|
action->setShortcutVisibleInContextMenu(true);
|
|
#endif
|
|
action->setIcon(QIcon(QStringLiteral("icon:edit-paste.svg")));
|
|
connect(action, &QAction::triggered, tcw, &TrackContentWidget::signalPasteTopics);
|
|
contextMenu->addAction(action);
|
|
}
|
|
|
|
contextMenu->popup(event->globalPosition().toPoint());
|
|
}
|
|
}
|
|
|
|
void SelectHandler::mouseReleaseEvent(QMouseEvent* event)
|
|
{
|
|
QPoint clickedPos = tcw->mapFromGlobal(event->globalPosition().toPoint());
|
|
int clickedPosX = clickedPos.x();
|
|
int clickedTime = tcw->m_tools->getTime(clickedPosX, tcw->m_isFilter);
|
|
|
|
TrackEntry* releasedEntry = tcw->getTrackEntryAt(clickedTime);
|
|
|
|
if (!QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier) && (!m_pressedEntry || !releasedEntry))
|
|
{
|
|
emit tcw->signalUnselectAll();
|
|
emit tcw->signalTrackEntrySelectionChanged(nullptr);
|
|
}
|
|
else
|
|
{
|
|
if (m_pressedEntry == releasedEntry)
|
|
tcw->selectEntry(releasedEntry);
|
|
}
|
|
}
|
|
|
|
void SelectHandler::keyPressEvent(QKeyEvent* event)
|
|
{
|
|
if (event->key() == Qt::Key_Escape)
|
|
{
|
|
m_pressedEntry = nullptr;
|
|
emit tcw->signalUnselectAll();
|
|
emit tcw->signalTrackEntrySelectionChanged(nullptr);
|
|
}
|
|
}
|
|
} // namespace LtsScriptTimeline
|