Apply clang-format to Lts/Common and DTC/enum headers
- Formatted all CodeGen module files (9 files) - Formatted LtsAppDescriptor module files - Formatted LtsAppManager/AppChooser files - Applied clang-format to all DTC and enum headers across modules - Removed coordTransTests from CommonUnitTestsPlaceholder (moved to tests/) Cosmetic changes only, no functional modifications. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
848 files changed
+89305
-100020
No files matched your search
Executable → Regular
+19
-28
@@ -1,16 +1,13 @@
|
||||
|
||||
|
||||
|
||||
#include "item.h"
|
||||
|
||||
#include <QBrush>
|
||||
#include <QPen>
|
||||
#include <QPainter>
|
||||
#include <QStyleOptionViewItem>
|
||||
#include <QModelIndex>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include <QModelIndex>
|
||||
#include <QPainter>
|
||||
#include <QPen>
|
||||
#include <QStyleOptionViewItem>
|
||||
|
||||
namespace LtsTimeline
|
||||
{
|
||||
@@ -19,27 +16,21 @@ QString Item::mimetype = QStringLiteral("application/rheinmetall.timeline.item")
|
||||
|
||||
QColor Item::s_highlightColor = QRgb(0x43b0e0);
|
||||
|
||||
|
||||
Item::Item(qint64 startTime, int duration, const QColor &color, bool isEditable)
|
||||
: m_color(color)
|
||||
, m_startTime(startTime)
|
||||
, m_duration(duration)
|
||||
, m_isEditable(isEditable)
|
||||
{}
|
||||
|
||||
|
||||
|
||||
|
||||
void Item::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &, bool highlight) const
|
||||
Item::Item(qint64 startTime, int duration, const QColor& color, bool isEditable)
|
||||
: m_color(color), m_startTime(startTime), m_duration(duration), m_isEditable(isEditable)
|
||||
{
|
||||
painter->save();
|
||||
if (highlight)
|
||||
painter->setPen(QPen(QBrush(s_highlightColor), 5));
|
||||
else
|
||||
painter->setPen(QPen(QBrush(Qt::black), 1));
|
||||
painter->setBrush(QBrush(m_color));
|
||||
painter->drawRect(option.rect);
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
}
|
||||
void Item::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex&, bool highlight) const
|
||||
{
|
||||
painter->save();
|
||||
if (highlight)
|
||||
painter->setPen(QPen(QBrush(s_highlightColor), 5));
|
||||
else
|
||||
painter->setPen(QPen(QBrush(Qt::black), 1));
|
||||
painter->setBrush(QBrush(m_color));
|
||||
painter->drawRect(option.rect);
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
} // namespace LtsTimeline
|
||||
Executable → Regular
+79
-41
@@ -1,15 +1,12 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ltstimeline_export.h"
|
||||
|
||||
#include <QColor>
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
|
||||
|
||||
class QPainter;
|
||||
class QStyleOptionViewItem;
|
||||
@@ -20,61 +17,102 @@ namespace PresentationManagement
|
||||
class ScriptModel;
|
||||
}
|
||||
|
||||
|
||||
namespace LtsTimeline
|
||||
{
|
||||
|
||||
class ItemDelegate;
|
||||
|
||||
|
||||
class LTSTIMELINE_EXPORT Item
|
||||
{
|
||||
friend class ItemDelegate;
|
||||
friend class ItemDelegate;
|
||||
|
||||
public:
|
||||
static QString mimetype;
|
||||
static QColor s_highlightColor;
|
||||
public:
|
||||
static QString mimetype;
|
||||
static QColor s_highlightColor;
|
||||
|
||||
Item() = default;
|
||||
Item(qint64 startTime, int duration, const QColor &color, bool isEditable = true);
|
||||
Item(const Item &) = delete;
|
||||
Item &operator=(const Item &) = delete;
|
||||
Item(Item &&) noexcept = default;
|
||||
virtual ~Item() = default;
|
||||
Item() = default;
|
||||
Item(qint64 startTime, int duration, const QColor& color, bool isEditable = true);
|
||||
Item(const Item&) = delete;
|
||||
Item& operator=(const Item&) = delete;
|
||||
Item(Item&&) noexcept = default;
|
||||
virtual ~Item() = default;
|
||||
|
||||
int id() const { return m_id; }
|
||||
int parentTrackId() const { return m_parentTrackId; }
|
||||
int id() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
QColor color() const { return m_color; }
|
||||
void setColor(const QColor &color) { m_color = color; }
|
||||
int parentTrackId() const
|
||||
{
|
||||
return m_parentTrackId;
|
||||
}
|
||||
|
||||
qint64 startTime() const { return m_startTime; }
|
||||
[[deprecated("use model's setItemStartTime instead, needed to notify the model that it has to re-sort items")]]
|
||||
void setStartTime(qint64 startTime) { m_startTime = startTime; }
|
||||
QColor color() const
|
||||
{
|
||||
return m_color;
|
||||
}
|
||||
|
||||
int duration() const { return m_duration; }
|
||||
void setDuration(int duration) { m_duration = duration; }
|
||||
void setColor(const QColor& color)
|
||||
{
|
||||
m_color = color;
|
||||
}
|
||||
|
||||
bool isEditable() const { return m_isEditable; }
|
||||
void setEditable(bool editable) { m_isEditable = editable; }
|
||||
qint64 startTime() const
|
||||
{
|
||||
return m_startTime;
|
||||
}
|
||||
|
||||
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index, bool highlight = false) const;
|
||||
[[deprecated("use model's setItemStartTime instead, needed to notify the model that it has to re-sort items")]] void
|
||||
setStartTime(qint64 startTime)
|
||||
{
|
||||
m_startTime = startTime;
|
||||
}
|
||||
|
||||
void _setStartTime(qint64 startTime) { m_startTime = startTime; }
|
||||
void _setDuration(int duration) { m_duration = duration; }
|
||||
int duration() const
|
||||
{
|
||||
return m_duration;
|
||||
}
|
||||
|
||||
protected:
|
||||
QColor m_color;
|
||||
qint64 m_startTime { -1 };
|
||||
int m_duration { -1 };
|
||||
bool m_isEditable { false };
|
||||
void setDuration(int duration)
|
||||
{
|
||||
m_duration = duration;
|
||||
}
|
||||
|
||||
private:
|
||||
friend class TimelineModel;
|
||||
friend class PresentationManagement::ScriptModel;
|
||||
bool isEditable() const
|
||||
{
|
||||
return m_isEditable;
|
||||
}
|
||||
|
||||
int m_id { -1 };
|
||||
int m_parentTrackId { -1 };
|
||||
void setEditable(bool editable)
|
||||
{
|
||||
m_isEditable = editable;
|
||||
}
|
||||
|
||||
virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index,
|
||||
bool highlight = false) const;
|
||||
|
||||
void _setStartTime(qint64 startTime)
|
||||
{
|
||||
m_startTime = startTime;
|
||||
}
|
||||
|
||||
void _setDuration(int duration)
|
||||
{
|
||||
m_duration = duration;
|
||||
}
|
||||
|
||||
protected:
|
||||
QColor m_color;
|
||||
qint64 m_startTime{-1};
|
||||
int m_duration{-1};
|
||||
bool m_isEditable{false};
|
||||
|
||||
private:
|
||||
friend class TimelineModel;
|
||||
friend class PresentationManagement::ScriptModel;
|
||||
|
||||
int m_id{-1};
|
||||
int m_parentTrackId{-1};
|
||||
};
|
||||
|
||||
typedef std::unique_ptr<Item> ItemPtr;
|
||||
@@ -84,4 +122,4 @@ typedef std::reference_wrapper<ItemPtr> ItemPtrNCVRef;
|
||||
typedef std::vector<ItemPtrNCVRef> ItemPtrNCVRefs;
|
||||
typedef std::vector<ItemPtrRef> ItemPtrRefs;
|
||||
|
||||
}
|
||||
} // namespace LtsTimeline
|
||||
Executable → Regular
+137
-151
@@ -1,185 +1,171 @@
|
||||
|
||||
|
||||
|
||||
#include "item_delegate.h"
|
||||
#include "item.h"
|
||||
#include "track.h"
|
||||
#include "timeline_view.h"
|
||||
|
||||
#include "item.h"
|
||||
#include "timeline_view.h"
|
||||
#include "track.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QGuiApplication>
|
||||
#include <QModelIndex>
|
||||
#include <QPainter>
|
||||
#include <QRect>
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
namespace LtsTimeline
|
||||
{
|
||||
|
||||
ItemDelegate::ItemDelegate(TimelineView *parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
, m_view(parent)
|
||||
, m_pushButton(new QPushButton)
|
||||
, m_pushButtonPressed(new QPushButton)
|
||||
ItemDelegate::ItemDelegate(TimelineView* parent)
|
||||
: QStyledItemDelegate(parent), m_view(parent), m_pushButton(new QPushButton), m_pushButtonPressed(new QPushButton)
|
||||
{
|
||||
m_pushButtonPressed->setDown(true);
|
||||
m_pushButtonPressed->setDown(true);
|
||||
}
|
||||
|
||||
ItemDelegate::~ItemDelegate()
|
||||
{
|
||||
m_pushButton->deleteLater();
|
||||
m_pushButton = nullptr;
|
||||
m_pushButtonPressed->deleteLater();
|
||||
m_pushButtonPressed = nullptr;
|
||||
m_pushButton->deleteLater();
|
||||
m_pushButton = nullptr;
|
||||
m_pushButtonPressed->deleteLater();
|
||||
m_pushButtonPressed = nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
QSize ItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
QSize ItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
Q_UNUSED(option);
|
||||
Q_UNUSED(index);
|
||||
return QSize(100, 50);
|
||||
Q_UNUSED(option);
|
||||
Q_UNUSED(index);
|
||||
return QSize(100, 50);
|
||||
}
|
||||
|
||||
void ItemDelegate::paintDragItems(QPainter *painter) const
|
||||
void ItemDelegate::paintDragItems(QPainter* painter) const
|
||||
{
|
||||
painter->save();
|
||||
|
||||
const QRect rightSectionRect = QRect(QPoint(m_view->m_header->sectionPosition(Section::eItems), 0),
|
||||
QPoint(m_view->geometry().right(), m_view->geometry().bottom()));
|
||||
painter->setClipRect(rightSectionRect);
|
||||
|
||||
int dx = m_view->m_dragHandler->deltaX();
|
||||
int dy = m_view->m_dragHandler->deltaY();
|
||||
try
|
||||
{
|
||||
for (const int &itemId : m_view->m_dragHandler->m_dragItemIds)
|
||||
{
|
||||
Item &item = m_view->timelineModel()->item(itemId);
|
||||
if (item.startTime() + item.duration() < m_view->currentTime())
|
||||
continue;
|
||||
|
||||
if (item.startTime() > m_view->endTime())
|
||||
break;
|
||||
|
||||
|
||||
|
||||
const QModelIndex rowIndex(m_view->timelineModel()->indexOfTrack(item.parentTrackId()));
|
||||
const QModelIndex columnIndex(m_view->timelineModel()->index(rowIndex.row(), 1, rowIndex.parent()));
|
||||
const QRect visualRect(m_view->visualRect(columnIndex));
|
||||
int left = m_view->toPixel(item.startTime()) + dx;
|
||||
int right = m_view->toPixel(item.startTime() + item.duration()) + dx;
|
||||
int top = visualRect.top() + dy;
|
||||
int bottom = visualRect.bottom() + dy;
|
||||
QStyleOptionViewItem option;
|
||||
option.rect = QRect(left, top, right - left - 1, bottom - top);
|
||||
item.paint(painter, option, columnIndex, m_view->selectedItemIds().contains(itemId));
|
||||
}
|
||||
}
|
||||
catch (...) {}
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
|
||||
void ItemDelegate::paintTrackButtons(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
const Track &track = m_view->timelineModel()->track(index.data(Qt::UserRole).toInt());
|
||||
|
||||
int buttonLength = option.rect.height() / 2;
|
||||
if (track.hasInsertButton())
|
||||
{
|
||||
QPushButton *button = m_view->m_trackHandler->isInsertButtonPressed(index) ? m_pushButtonPressed : m_pushButton;
|
||||
QRect rect = QRect(0, 0, buttonLength, buttonLength);
|
||||
button->setGeometry(rect);
|
||||
button->setText(QStringLiteral("+"));
|
||||
button->setEnabled(m_view->timelineModel()->isEditable());
|
||||
QPixmap map = button->grab();
|
||||
painter->drawPixmap(option.rect.right() - buttonLength, option.rect.top(), map);
|
||||
}
|
||||
if (track.hasRemoveButton())
|
||||
{
|
||||
QPushButton *button = m_view->m_trackHandler->isRemoveButtonPressed(index) ? m_pushButtonPressed : m_pushButton;
|
||||
QRect rect = QRect(0, 0, buttonLength, buttonLength);
|
||||
button->setGeometry(rect);
|
||||
button->setText(QStringLiteral("-"));
|
||||
button->setEnabled(m_view->timelineModel()->isEditable());
|
||||
QPixmap map = button->grab();
|
||||
painter->drawPixmap(option.rect.right() - buttonLength, option.rect.center().y(), map);
|
||||
}
|
||||
}
|
||||
catch (...) {}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
if (index.column() == Section::eActuator)
|
||||
{
|
||||
painter->save();
|
||||
QStyledItemDelegate::paint(painter, option, index);
|
||||
paintTrackButtons(painter, option, index);
|
||||
|
||||
const QRect rightSectionRect = QRect(QPoint(m_view->m_header->sectionPosition(Section::eItems), 0),
|
||||
QPoint(m_view->geometry().right(), m_view->geometry().bottom()));
|
||||
painter->setClipRect(rightSectionRect);
|
||||
|
||||
int dx = m_view->m_dragHandler->deltaX();
|
||||
int dy = m_view->m_dragHandler->deltaY();
|
||||
try
|
||||
{
|
||||
for (const int& itemId : m_view->m_dragHandler->m_dragItemIds)
|
||||
{
|
||||
Item& item = m_view->timelineModel()->item(itemId);
|
||||
if (item.startTime() + item.duration() < m_view->currentTime())
|
||||
continue;
|
||||
|
||||
if (item.startTime() > m_view->endTime())
|
||||
break;
|
||||
|
||||
const QModelIndex rowIndex(m_view->timelineModel()->indexOfTrack(item.parentTrackId()));
|
||||
const QModelIndex columnIndex(m_view->timelineModel()->index(rowIndex.row(), 1, rowIndex.parent()));
|
||||
const QRect visualRect(m_view->visualRect(columnIndex));
|
||||
int left = m_view->toPixel(item.startTime()) + dx;
|
||||
int right = m_view->toPixel(item.startTime() + item.duration()) + dx;
|
||||
int top = visualRect.top() + dy;
|
||||
int bottom = visualRect.bottom() + dy;
|
||||
QStyleOptionViewItem option;
|
||||
option.rect = QRect(left, top, right - left - 1, bottom - top);
|
||||
item.paint(painter, option, columnIndex, m_view->selectedItemIds().contains(itemId));
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
auto drawItem = [this, &option, &painter, &index](const Item &item)
|
||||
{
|
||||
void ItemDelegate::paintTrackButtons(QPainter* painter, const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index) const
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
const Track& track = m_view->timelineModel()->track(index.data(Qt::UserRole).toInt());
|
||||
|
||||
int buttonLength = option.rect.height() / 2;
|
||||
if (track.hasInsertButton())
|
||||
{
|
||||
QPushButton* button =
|
||||
m_view->m_trackHandler->isInsertButtonPressed(index) ? m_pushButtonPressed : m_pushButton;
|
||||
QRect rect = QRect(0, 0, buttonLength, buttonLength);
|
||||
button->setGeometry(rect);
|
||||
button->setText(QStringLiteral("+"));
|
||||
button->setEnabled(m_view->timelineModel()->isEditable());
|
||||
QPixmap map = button->grab();
|
||||
painter->drawPixmap(option.rect.right() - buttonLength, option.rect.top(), map);
|
||||
}
|
||||
if (track.hasRemoveButton())
|
||||
{
|
||||
QPushButton* button =
|
||||
m_view->m_trackHandler->isRemoveButtonPressed(index) ? m_pushButtonPressed : m_pushButton;
|
||||
QRect rect = QRect(0, 0, buttonLength, buttonLength);
|
||||
button->setGeometry(rect);
|
||||
button->setText(QStringLiteral("-"));
|
||||
button->setEnabled(m_view->timelineModel()->isEditable());
|
||||
QPixmap map = button->grab();
|
||||
painter->drawPixmap(option.rect.right() - buttonLength, option.rect.center().y(), map);
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (m_view->timelineModel()->isEditable())
|
||||
if (m_view->m_dragHandler->m_dragItemIds.contains(item.id()))
|
||||
void ItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
if (index.column() == Section::eActuator)
|
||||
{
|
||||
painter->save();
|
||||
QStyledItemDelegate::paint(painter, option, index);
|
||||
paintTrackButtons(painter, option, index);
|
||||
painter->restore();
|
||||
return;
|
||||
|
||||
QStyleOptionViewItem opt = option;
|
||||
opt.rect.setLeft(std::max(m_view->toPixel(item.startTime()), option.rect.left()));
|
||||
opt.rect.setRight(std::min(m_view->toPixel(item.startTime() + item.duration()), option.rect.right()) - 1);
|
||||
item.paint(painter, opt, index, m_view->selectedItemIds().contains(item.id()));
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
const Track &track = m_view->timelineModel()->track(index.data().toInt());
|
||||
painter->save();
|
||||
|
||||
|
||||
painter->setClipping(true);
|
||||
painter->setClipRect(option.rect);
|
||||
|
||||
const Items &items = track.items();
|
||||
for (const ItemPtr &item : items)
|
||||
drawItem(static_cast<Item &>(*item.get()));
|
||||
const QSet<int> copyItemIds = track.copyItemIds();
|
||||
for (const int &itemId : copyItemIds)
|
||||
{
|
||||
try
|
||||
{
|
||||
const Item &item = m_view->timelineModel()->item(itemId);
|
||||
drawItem(item);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
fprintf(stderr, "ItemDelegate::paint: cannot find item copy of %d\n", itemId);
|
||||
}
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << "ItemDelegate::paint -> CATCH";
|
||||
}
|
||||
auto drawItem = [this, &option, &painter, &index](const Item& item) {
|
||||
if (m_view->timelineModel()->isEditable())
|
||||
if (m_view->m_dragHandler->m_dragItemIds.contains(item.id()))
|
||||
return;
|
||||
|
||||
QStyleOptionViewItem opt = option;
|
||||
opt.rect.setLeft(std::max(m_view->toPixel(item.startTime()), option.rect.left()));
|
||||
opt.rect.setRight(std::min(m_view->toPixel(item.startTime() + item.duration()), option.rect.right()) - 1);
|
||||
item.paint(painter, opt, index, m_view->selectedItemIds().contains(item.id()));
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
const Track& track = m_view->timelineModel()->track(index.data().toInt());
|
||||
painter->save();
|
||||
|
||||
painter->setClipping(true);
|
||||
painter->setClipRect(option.rect);
|
||||
|
||||
const Items& items = track.items();
|
||||
for (const ItemPtr& item : items)
|
||||
drawItem(static_cast<Item&>(*item.get()));
|
||||
const QSet<int> copyItemIds = track.copyItemIds();
|
||||
for (const int& itemId : copyItemIds)
|
||||
{
|
||||
try
|
||||
{
|
||||
const Item& item = m_view->timelineModel()->item(itemId);
|
||||
drawItem(item);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
fprintf(stderr, "ItemDelegate::paint: cannot find item copy of %d\n", itemId);
|
||||
}
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << "ItemDelegate::paint -> CATCH";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsTimeline
|
||||
Executable → Regular
+17
-25
@@ -1,14 +1,11 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "ltstimeline_export.h"
|
||||
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QObject>
|
||||
#include <QPushButton>
|
||||
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
namespace LtsTimeline
|
||||
{
|
||||
@@ -16,33 +13,28 @@ namespace LtsTimeline
|
||||
class TimelineView;
|
||||
class TimelineModel;
|
||||
|
||||
|
||||
class LTSTIMELINE_EXPORT ItemDelegate : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ItemDelegate(TimelineView *parent = nullptr);
|
||||
~ItemDelegate();
|
||||
public:
|
||||
ItemDelegate(TimelineView* parent = nullptr);
|
||||
~ItemDelegate();
|
||||
|
||||
|
||||
QSize sizeHint(const QStyleOptionViewItem& option = {}, const QModelIndex& index = {}) const override;
|
||||
|
||||
QSize sizeHint(const QStyleOptionViewItem &option = {}, const QModelIndex &index = {}) const override;
|
||||
virtual void paintDragItems(QPainter* painter) const;
|
||||
virtual void paintTrackButtons(QPainter* painter, const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index) const;
|
||||
|
||||
|
||||
protected:
|
||||
virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
|
||||
|
||||
virtual void paintDragItems(QPainter *painter) const;
|
||||
virtual void paintTrackButtons(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
|
||||
protected:
|
||||
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||
|
||||
protected:
|
||||
TimelineView *m_view { nullptr };
|
||||
|
||||
QPushButton *m_pushButton { nullptr };
|
||||
QPushButton *m_pushButtonPressed { nullptr };
|
||||
protected:
|
||||
TimelineView* m_view{nullptr};
|
||||
|
||||
QPushButton* m_pushButton{nullptr};
|
||||
QPushButton* m_pushButtonPressed{nullptr};
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsTimeline
|
||||
Executable → Regular
+134
-205
@@ -1,289 +1,218 @@
|
||||
#include <timeline_widget.h>
|
||||
#include <timeline_model.h>
|
||||
#include <item.h>
|
||||
#include <track.h>
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
#include <nglapplication/nglapplication.h>
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include <item.h>
|
||||
#include <nglapplication/nglapplication.h>
|
||||
#include <timeline_model.h>
|
||||
#include <timeline_widget.h>
|
||||
#include <track.h>
|
||||
|
||||
using namespace LtsTimeline;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class AbstractStuff
|
||||
{
|
||||
public:
|
||||
virtual void thing() = 0;
|
||||
public:
|
||||
virtual void thing() = 0;
|
||||
};
|
||||
|
||||
|
||||
class TheStuff : public AbstractStuff
|
||||
{
|
||||
void thing() override { fprintf(stderr, "thing() !\n"); }
|
||||
void thing() override
|
||||
{
|
||||
fprintf(stderr, "thing() !\n");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
std::unique_ptr<AbstractStuff> get()
|
||||
{
|
||||
return std::make_unique<TheStuff>(std::move(TheStuff()));
|
||||
return std::make_unique<TheStuff>(std::move(TheStuff()));
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::unique_ptr<AbstractStuff>> test;
|
||||
|
||||
|
||||
void move(std::unique_ptr<AbstractStuff> &&stuff)
|
||||
void move(std::unique_ptr<AbstractStuff>&& stuff)
|
||||
{
|
||||
test.push_back(std::move(stuff));
|
||||
test.push_back(std::move(stuff));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void populateModel(LtsTimeline::TimelineModel *model)
|
||||
void populateModel(LtsTimeline::TimelineModel* model)
|
||||
{
|
||||
{
|
||||
std::unique_ptr<AbstractStuff> asp = get();
|
||||
move(std::move(asp));
|
||||
}
|
||||
|
||||
{
|
||||
AbstractStuff &as = *test.front();
|
||||
as.thing();
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
std::unique_ptr<AbstractStuff> asp = get();
|
||||
move(std::move(asp));
|
||||
}
|
||||
|
||||
{
|
||||
AbstractStuff& as = *test.front();
|
||||
as.thing();
|
||||
}
|
||||
|
||||
#define l() qCritical()
|
||||
qint64 rtlnau = QDateTime::currentMSecsSinceEpoch();
|
||||
qint64 rtlnau = QDateTime::currentMSecsSinceEpoch();
|
||||
|
||||
class TestItem : public Item
|
||||
{
|
||||
public:
|
||||
TestItem(qint64 startTime, int duration, const QColor &color, bool isEditable = true)
|
||||
: Item(startTime, duration, color, isEditable)
|
||||
, m_1234(1234)
|
||||
{}
|
||||
class TestItem : public Item
|
||||
{
|
||||
public:
|
||||
TestItem(qint64 startTime, int duration, const QColor& color, bool isEditable = true)
|
||||
: Item(startTime, duration, color, isEditable), m_1234(1234)
|
||||
{
|
||||
}
|
||||
|
||||
int get1234() const { return m_1234; }
|
||||
int get1234() const
|
||||
{
|
||||
return m_1234;
|
||||
}
|
||||
|
||||
private:
|
||||
int m_1234 { 9876 };
|
||||
};
|
||||
private:
|
||||
int m_1234{9876};
|
||||
};
|
||||
|
||||
int trackId;
|
||||
int itemId;
|
||||
|
||||
int trackId;
|
||||
int itemId;
|
||||
model->addTrack<Track>(0, Track(QStringLiteral("1st Track")));
|
||||
model->addItem<Item>(1, Item(rtlnau + 120'000, 30'000, Qt::green));
|
||||
|
||||
|
||||
int firstChildId = model->addTrack(1, Track(QStringLiteral("1st Track's 1st Child")));
|
||||
model->addItem<LtsTimeline::Item>(2, Item(rtlnau + 180'000, 30'000, Qt::magenta));
|
||||
l() << "firstChildId:" << firstChildId;
|
||||
|
||||
model->addTrack<Track>(0, Track(QStringLiteral("2nd Track")));
|
||||
model->addItem<Item>(3, Item(rtlnau + 120'000, 60'000, Qt::blue));
|
||||
model->addItem<Item>(3, Item(rtlnau + 60'000, 30'000, Qt::red));
|
||||
|
||||
|
||||
model->addTrack<Track>(0, Track(QStringLiteral("1st Track")));
|
||||
model->addItem<Item>(1, Item(rtlnau + 120'000, 30'000, Qt::green));
|
||||
model->addTrack<Track>(0, Track(QStringLiteral("3rd Track")));
|
||||
model->addItem<Item>(4, Item(rtlnau + 150'000, 60'000, Qt::yellow));
|
||||
model->addItem<TestItem>(4, TestItem(rtlnau + 90'000, 30'000, Qt::cyan));
|
||||
|
||||
int firstChildId =
|
||||
model->addTrack(1, Track(QStringLiteral("1st Track's 1st Child")));
|
||||
model->addItem<LtsTimeline::Item>(2, Item(rtlnau + 180'000, 30'000, Qt::magenta));
|
||||
l() << "firstChildId:" << firstChildId;
|
||||
model->print(true);
|
||||
|
||||
model->addTrack<Track>(0, Track(QStringLiteral("2nd Track")));
|
||||
model->addItem<Item>(3, Item(rtlnau + 120'000, 60'000, Qt::blue));
|
||||
model->addItem<Item>(3, Item(rtlnau + 60'000, 30'000, Qt::red));
|
||||
try
|
||||
{
|
||||
const TestItem& testItem = dynamic_cast<const TestItem&>(model->item(5));
|
||||
}
|
||||
catch (const std::exception& ex)
|
||||
{
|
||||
l() << "dynamic_cast back to TestItem failed!" << ex.what();
|
||||
}
|
||||
|
||||
model->addTrack<Track>(0, Track(QStringLiteral("3rd Track")));
|
||||
model->addItem<Item>(4, Item(rtlnau + 150'000, 60'000, Qt::yellow));
|
||||
model->addItem<TestItem>(4, TestItem(rtlnau + 90'000, 30'000, Qt::cyan));
|
||||
(void)itemId;
|
||||
(void)trackId;
|
||||
|
||||
qint64 now = rtlnau;
|
||||
|
||||
|
||||
model->print(true);
|
||||
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
const TestItem &testItem = dynamic_cast<const TestItem &>(model->item(5));
|
||||
|
||||
}
|
||||
catch(const std::exception &ex)
|
||||
{
|
||||
l() << "dynamic_cast back to TestItem failed!" << ex.what();
|
||||
}
|
||||
|
||||
|
||||
(void)itemId;
|
||||
(void)trackId;
|
||||
|
||||
|
||||
|
||||
qint64 now = rtlnau;
|
||||
|
||||
{
|
||||
{
|
||||
#define non_strict false
|
||||
#define strict true
|
||||
#define recursive true
|
||||
#define sorted true
|
||||
#define unsorted false
|
||||
QVector<int> x;
|
||||
bool y;
|
||||
QVector<int> x;
|
||||
bool y;
|
||||
|
||||
x = model->itemIdsBetween(now + 60'000 + 1, now + 150'000 - 1, non_strict, recursive);
|
||||
|
||||
|
||||
x = model->itemIdsBetween(now + 60'000 + 1, now + 150'000 - 1, non_strict, recursive);
|
||||
|
||||
x = model->itemIdsBetween(now + 60'000 + 1, now + 150'000 - 1, strict, recursive);
|
||||
|
||||
x = model->itemIdsBetween(now + 60'000 + 1, now + 150'000 - 1, strict, recursive);
|
||||
|
||||
y = model->isItemsBetween(now + 60'000 + 1, now + 150'000 - 1, -1, non_strict, recursive);
|
||||
|
||||
y = model->isItemsBetween(now + 60'000 + 1, now + 150'000 - 1, -1, strict, recursive);
|
||||
|
||||
y = model->isItemsBetween(now + 60'000 + 1, now + 150'000 - 1, -1, non_strict, recursive);
|
||||
|
||||
y = model->isItemsBetween(now + 60'000 + 1, now + 150'000 - 1, 5, non_strict, recursive);
|
||||
|
||||
y = model->isItemsBetween(now + 60'000 + 1, now + 150'000 - 1, -1, strict, recursive);
|
||||
|
||||
y = model->isItemsBetween(now + 60'000 + 1, now + 150'000 - 1, 5, strict, recursive);
|
||||
|
||||
x = model->itemIdsBetween(now + 60'000, now + 150'000, non_strict, recursive);
|
||||
|
||||
y = model->isItemsBetween(now + 60'000 + 1, now + 150'000 - 1, 5, non_strict, recursive);
|
||||
|
||||
x = model->itemIdsBetween(now + 60'000, now + 150'000, strict, recursive);
|
||||
|
||||
y = model->isItemsBetween(now + 60'000 + 1, now + 150'000 - 1, 5, strict, recursive);
|
||||
|
||||
y = model->isItemsBetween(now + 60'000, now + 150'000, -1, non_strict, recursive);
|
||||
|
||||
y = model->isItemsBetween(now + 60'000, now + 150'000, -1, strict, recursive);
|
||||
|
||||
y = model->isItemsBetween(now + 60'000, now + 150'000, 5, non_strict, recursive);
|
||||
|
||||
|
||||
x = model->itemIdsBetween(now + 60'000, now + 150'000, non_strict, recursive);
|
||||
|
||||
y = model->isItemsBetween(now + 60'000, now + 150'000, 5, strict, recursive);
|
||||
|
||||
x = model->itemIdsBetween(now + 60'000, now + 150'000, strict, recursive);
|
||||
|
||||
y = model->isItemsBetween(now + 60'000, now + 150'000, QVector<int>({0, 3, 5}), strict, recursive);
|
||||
|
||||
y = model->isItemsBetween(now + 60'000, now + 150'000, QVector<int>({0, 5}), strict, recursive);
|
||||
|
||||
y = model->isItemsBetween(now + 60'000, now + 150'000, -1, non_strict, recursive);
|
||||
|
||||
|
||||
y = model->isItemsBetween(now + 60'000, now + 150'000, -1, strict, recursive);
|
||||
|
||||
|
||||
|
||||
y = model->isItemsBetween(now + 60'000, now + 150'000, 5, non_strict, recursive);
|
||||
|
||||
|
||||
y = model->isItemsBetween(now + 60'000, now + 150'000, 5, strict, recursive);
|
||||
|
||||
|
||||
|
||||
y = model->isItemsBetween(now + 60'000, now + 150'000, QVector<int>({ 0, 3, 5 }), strict, recursive);
|
||||
|
||||
|
||||
y = model->isItemsBetween(now + 60'000, now + 150'000, QVector<int>({ 0, 5 }), strict, recursive);
|
||||
|
||||
|
||||
|
||||
|
||||
x = model->itemIdsBetween(0, now + 999'000, non_strict, recursive, sorted);
|
||||
// l() << "itemIdsBetween(0, now + 999'000, non_strict, recursive, sorted)" << x << "- okay?" << (x == QVector<int>({ 3, 5, 0, 2, 4, 1 }));
|
||||
x = model->itemIdsBetween(0, now + 999'000, non_strict, recursive, sorted);
|
||||
// l() << "itemIdsBetween(0, now + 999'000, non_strict, recursive, sorted)" << x << "- okay?" << (x ==
|
||||
// QVector<int>({ 3, 5, 0, 2, 4, 1 }));
|
||||
#undef non_strict
|
||||
#undef strict
|
||||
#undef recursive
|
||||
#undef unsorted
|
||||
#undef sorted
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// item 1 von track 2 auf track 3, zu startTime 210'000
|
||||
model->moveItemToTrack(1, 3, now + 210'000);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
fprintf(stderr, "That didn't work. %s:%d\n", __FUNCTION__, __LINE__);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// item 1 von track 2 auf track 3, zu startTime 210'000
|
||||
model->moveItemToTrack(1, 3, now + 210'000);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
fprintf(stderr, "That didn't work. %s:%d\n", __FUNCTION__, __LINE__);
|
||||
}
|
||||
model->print(true);
|
||||
|
||||
try
|
||||
{
|
||||
// item 3 von track 3 auf track 2, zu startTime 150'000
|
||||
model->moveItemToTrack(3, 2, now + 150'000);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
fprintf(stderr, "That didn't work. %s:%d\n", __FUNCTION__, __LINE__);
|
||||
}
|
||||
|
||||
model->print(true);
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
// item 3 von track 3 auf track 2, zu startTime 150'000
|
||||
model->moveItemToTrack(3, 2, now + 150'000);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
fprintf(stderr, "That didn't work. %s:%d\n", __FUNCTION__, __LINE__);
|
||||
}
|
||||
|
||||
|
||||
/* now
|
||||
/30 /60 /90 /120 /150 /180 /210 /240
|
||||
| ' ' ' | ' ' ' | ' ' ' | ' ' ' | ' ' ' | ' ' ' | ' ' ' |
|
||||
T1 000000000
|
||||
>T2 333333333
|
||||
T3 2222222222222222111111111
|
||||
T4 55555555 44444444444444444
|
||||
*/
|
||||
|
||||
|
||||
model->print(true);
|
||||
/* now
|
||||
/30 /60 /90 /120 /150 /180 /210 /240
|
||||
| ' ' ' | ' ' ' | ' ' ' | ' ' ' | ' ' ' | ' ' ' | ' ' ' |
|
||||
T1 000000000
|
||||
>T2 333333333
|
||||
T3 2222222222222222111111111
|
||||
T4 55555555 44444444444444444
|
||||
*/
|
||||
|
||||
model->print(true);
|
||||
|
||||
#undef l
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
// qputenv("TDS_DEVEL", "yes, of course");
|
||||
// qputenv("TDS_DEVEL", "yes, of course");
|
||||
|
||||
qWarning() << "LtsTimeline - Test";
|
||||
NGLApplication app(argc, argv);
|
||||
app.createLogger("Timeline", "log4cxx_timeline.props");
|
||||
qWarning() << "LtsTimeline - Test";
|
||||
NGLApplication app(argc, argv);
|
||||
app.createLogger("Timeline", "log4cxx_timeline.props");
|
||||
|
||||
STARTUP_LOG(app.baseLogger());
|
||||
STARTUP_LOG(app.baseLogger());
|
||||
|
||||
int ret = 0;
|
||||
int ret = 0;
|
||||
|
||||
LtsTimeline::TimelineWidget *timeline = new LtsTimeline::TimelineWidget();
|
||||
LtsTimeline::TimelineModel *model = new LtsTimeline::TimelineModel(timeline->view());
|
||||
model->setSnapEnabled(true);
|
||||
populateModel(model);
|
||||
timeline->setModel(model);
|
||||
timeline->showDebugWidget();
|
||||
timeline->setWindowState(Qt::WindowMaximized);
|
||||
timeline->show();
|
||||
LtsTimeline::TimelineWidget* timeline = new LtsTimeline::TimelineWidget();
|
||||
LtsTimeline::TimelineModel* model = new LtsTimeline::TimelineModel(timeline->view());
|
||||
model->setSnapEnabled(true);
|
||||
populateModel(model);
|
||||
timeline->setModel(model);
|
||||
timeline->showDebugWidget();
|
||||
timeline->setWindowState(Qt::WindowMaximized);
|
||||
timeline->show();
|
||||
|
||||
// timeline->setMaximumZoomFactor(LtsTimeline::ZoomFactor::ThirtyMinutes);
|
||||
timeline->setZoomFactor(LtsTimeline::ZoomFactor::SixtyMinutes);
|
||||
timeline->setStartTime(QDateTime::currentMSecsSinceEpoch());
|
||||
timeline->setDuration(12 * 60 * 60 * 1000);
|
||||
// timeline->setMaximumZoomFactor(LtsTimeline::ZoomFactor::ThirtyMinutes);
|
||||
timeline->setZoomFactor(LtsTimeline::ZoomFactor::SixtyMinutes);
|
||||
timeline->setStartTime(QDateTime::currentMSecsSinceEpoch());
|
||||
timeline->setDuration(12 * 60 * 60 * 1000);
|
||||
|
||||
ret = app.exec();
|
||||
ret = app.exec();
|
||||
|
||||
SHUTDOWN_LOG(app.baseLogger());
|
||||
SHUTDOWN_LOG(app.baseLogger());
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
Executable → Regular
+426
-470
File diff suppressed because it is too large.
Load diff
Executable → Regular
+249
-120
@@ -1,13 +1,10 @@
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "ltstimeline_export.h"
|
||||
#include "timeline_header_view_mouse_handler.h"
|
||||
#include "timeline_utils.h"
|
||||
|
||||
#include "ltstimeline_export.h"
|
||||
|
||||
#include <QHeaderView>
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QMouseEvent;
|
||||
class QPainter;
|
||||
@@ -15,159 +12,291 @@ class QRect;
|
||||
class QTimer;
|
||||
class QWheelEvent;
|
||||
|
||||
|
||||
namespace LtsTimeline
|
||||
{
|
||||
|
||||
class TimelineView;
|
||||
|
||||
|
||||
class LTSTIMELINE_EXPORT TimelineHeaderView : public QHeaderView
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
friend class TimelineHeaderViewMouseHandler;
|
||||
friend class TimelineViewMouseHandler;
|
||||
friend class TimelineHeaderViewMouseHandler;
|
||||
friend class TimelineViewMouseHandler;
|
||||
|
||||
public:
|
||||
static const QColor backgroundColor();
|
||||
static const QColor highlightColor();
|
||||
public:
|
||||
static const QColor backgroundColor();
|
||||
static const QColor highlightColor();
|
||||
|
||||
static const int s_limitHeight;
|
||||
static const int s_limitHeight;
|
||||
|
||||
enum Section { eActuator = 0, eItems = 1 };
|
||||
enum Section { eActuator = 0, eItems = 1 };
|
||||
|
||||
TimelineHeaderView(QWidget *parent = nullptr);
|
||||
~TimelineHeaderView();
|
||||
TimelineHeaderView(QWidget* parent = nullptr);
|
||||
~TimelineHeaderView();
|
||||
|
||||
void setParent(QWidget *);
|
||||
void setTrackLabel(const QString &trackLabel);
|
||||
void setParent(QWidget*);
|
||||
void setTrackLabel(const QString& trackLabel);
|
||||
|
||||
const Ticks &majorTicks() const { return m_majorTicks; }
|
||||
const Ticks &mediumTicks() const { return m_mediumTicks; }
|
||||
const Ticks &minorTicks() const { return m_minorTicks; }
|
||||
const Ticks& majorTicks() const
|
||||
{
|
||||
return m_majorTicks;
|
||||
}
|
||||
|
||||
DateTimeFormat dateTimeFormat() const { return m_dateTimeFormat; }
|
||||
void setDateTimeFormat(DateTimeFormat dateTimeFormat);
|
||||
void setDateTimeFormatChangable(bool changable) { m_isDateTimeFormatChangable = changable; }
|
||||
bool isDateTimeFormatChangable() const { return m_isDateTimeFormatChangable; }
|
||||
const Ticks& mediumTicks() const
|
||||
{
|
||||
return m_mediumTicks;
|
||||
}
|
||||
|
||||
double indicatorScalingFactor() const { return m_indicatorScalingFactor; }
|
||||
void setIndicatorScalingFactor(double factor);
|
||||
qint64 indicatorTime() const { return m_indicatorTime; }
|
||||
void setIndicatorTime(qint64 time);
|
||||
int indicatorPosition() const { return toPixel(m_indicatorTime); }
|
||||
void setIndicatorPosition(int position);
|
||||
bool isIndicatorVisible() const { return m_isIndicatorVisible; }
|
||||
void setIndicatorVisible(bool isIndicatorVisible);
|
||||
bool indicatorLocked() const { return m_isIndicatorLocked; }
|
||||
void setIndicatorLocked(bool locked) { m_isIndicatorLocked = locked; }
|
||||
void lockIndicator() { setIndicatorLocked(true); }
|
||||
void unlockIndicator() { setIndicatorLocked(false); }
|
||||
const Ticks& minorTicks() const
|
||||
{
|
||||
return m_minorTicks;
|
||||
}
|
||||
|
||||
double liveIndicatorScalingFactor() const { return m_liveIndicatorScalingFactor; }
|
||||
void setLiveIndicatorScalingFactor(double factor);
|
||||
QColor liveIndicatorColor() const { return m_liveIndicatorColor; }
|
||||
void setLiveIndicatorColor(const QColor &color);
|
||||
qint64 liveIndicatorTime() const { return m_liveIndicatorTime; }
|
||||
void setLiveIndicatorTime(qint64 time);
|
||||
int liveIndicatorPosition() const { return toPixel(m_liveIndicatorTime); }
|
||||
void setLiveIndicatorPosition(int position);
|
||||
bool isLiveIndicatorVisible() const { return m_isLiveIndicatorVisible; }
|
||||
void setLiveIndicatorVisible(bool isLiveIndicatorVisible);
|
||||
void startLiveTimer(qint64 startTime = -1, int interval = 1000);
|
||||
void stopLiveTimer();
|
||||
DateTimeFormat dateTimeFormat() const
|
||||
{
|
||||
return m_dateTimeFormat;
|
||||
}
|
||||
|
||||
qint64 hoverTime() const { return m_hoverTime; }
|
||||
void setHoverTime(qint64 time);
|
||||
int hoverPosition() const { return m_hoverPosition; }
|
||||
void setHoverPosition(int position);
|
||||
bool isHoverVisible() const { return m_isHoverVisible; }
|
||||
void setHoverVisible(bool visible);
|
||||
bool isHoverTimeVisible() const { return m_isHoverTimeVisible; }
|
||||
void setHoverTimeVisible(bool visible);
|
||||
DateTimeFormat hoverDateTimeFormat() const { return m_hoverDateTimeFormat; }
|
||||
void setHoverDateTimeFormat(DateTimeFormat format);
|
||||
void setDateTimeFormat(DateTimeFormat dateTimeFormat);
|
||||
|
||||
bool isLimitsVisible() const { return m_isLimitsVisible; }
|
||||
void setLimitsVisible(bool visible);
|
||||
DateTimeFormat limitsDateTimeFormat() const { return m_limitsDateTimeFormat; }
|
||||
void setLimitsDateTimeFormat(DateTimeFormat format);
|
||||
void setDateTimeFormatChangable(bool changable)
|
||||
{
|
||||
m_isDateTimeFormatChangable = changable;
|
||||
}
|
||||
|
||||
int toPixel(qint64 time) const;
|
||||
qint64 toTime(int pixel) const;
|
||||
bool isDateTimeFormatChangable() const
|
||||
{
|
||||
return m_isDateTimeFormatChangable;
|
||||
}
|
||||
|
||||
QFont &font() { return m_font; }
|
||||
double indicatorScalingFactor() const
|
||||
{
|
||||
return m_indicatorScalingFactor;
|
||||
}
|
||||
|
||||
TimelineHeaderViewMouseHandler *mouseHandler() { return m_mouseHandler; }
|
||||
void setIndicatorScalingFactor(double factor);
|
||||
|
||||
void wheelEvent(QWheelEvent *e) override { m_mouseHandler->wheelEvent(e); }
|
||||
qint64 indicatorTime() const
|
||||
{
|
||||
return m_indicatorTime;
|
||||
}
|
||||
|
||||
protected:
|
||||
void mouseMoveEvent(QMouseEvent *e) override { m_mouseHandler->mouseMoveEvent(e); }
|
||||
void mousePressEvent(QMouseEvent *e) override { m_mouseHandler->mousePressEvent(e); }
|
||||
void mouseReleaseEvent(QMouseEvent *e) override { m_mouseHandler->mouseReleaseEvent(e); }
|
||||
void setIndicatorTime(qint64 time);
|
||||
|
||||
void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const;
|
||||
int indicatorPosition() const
|
||||
{
|
||||
return toPixel(m_indicatorTime);
|
||||
}
|
||||
|
||||
private:
|
||||
void updateMajorTicks();
|
||||
void updateMediumTicks();
|
||||
void updateMinorTicks();
|
||||
void setIndicatorPosition(int position);
|
||||
|
||||
public slots:
|
||||
void onUpdateTicks();
|
||||
bool isIndicatorVisible() const
|
||||
{
|
||||
return m_isIndicatorVisible;
|
||||
}
|
||||
|
||||
private slots:
|
||||
void onLiveTimeout();
|
||||
void setIndicatorVisible(bool isIndicatorVisible);
|
||||
|
||||
signals:
|
||||
void ticksChanged(const Ticks &);
|
||||
void indicatorTimeChanged(qint64);
|
||||
void indicatorVisibilityChanged(bool);
|
||||
void liveIndicatorTimeChanged(qint64);
|
||||
void liveIndicatorVisibilityChanged(bool);
|
||||
void hoverPositionChanged(int);
|
||||
void hoverVisibilityChanged(bool);
|
||||
bool indicatorLocked() const
|
||||
{
|
||||
return m_isIndicatorLocked;
|
||||
}
|
||||
|
||||
private:
|
||||
TimelineHeaderViewMouseHandler *m_mouseHandler{nullptr};
|
||||
TimelineView *m_timelineView{nullptr};
|
||||
Ticks m_majorTicks;
|
||||
Ticks m_mediumTicks;
|
||||
Ticks m_minorTicks;
|
||||
DateTimeFormat m_dateTimeFormat{DateTimeFormat::DTG};
|
||||
bool m_isDateTimeFormatChangable{true};
|
||||
void setIndicatorLocked(bool locked)
|
||||
{
|
||||
m_isIndicatorLocked = locked;
|
||||
}
|
||||
|
||||
double m_indicatorScalingFactor{0.5};
|
||||
qint64 m_indicatorTime{-1};
|
||||
bool m_isIndicatorVisible{true};
|
||||
bool m_isIndicatorLocked{false};
|
||||
void lockIndicator()
|
||||
{
|
||||
setIndicatorLocked(true);
|
||||
}
|
||||
|
||||
double m_liveIndicatorScalingFactor{0.5};
|
||||
QColor m_liveIndicatorColor;
|
||||
qint64 m_liveIndicatorTime{-1};
|
||||
bool m_isLiveIndicatorVisible{false};
|
||||
QTimer *m_liveTimer{nullptr};
|
||||
int m_liveTimerInterval{1000};
|
||||
void unlockIndicator()
|
||||
{
|
||||
setIndicatorLocked(false);
|
||||
}
|
||||
|
||||
qint64 m_hoverTime{-1};
|
||||
int m_hoverPosition{-1};
|
||||
bool m_isHoverVisible{true};
|
||||
bool m_isHoverTimeVisible{true};
|
||||
DateTimeFormat m_hoverDateTimeFormat{DateTimeFormat::DTG};
|
||||
double liveIndicatorScalingFactor() const
|
||||
{
|
||||
return m_liveIndicatorScalingFactor;
|
||||
}
|
||||
|
||||
bool m_isLimitsVisible{false};
|
||||
DateTimeFormat m_limitsDateTimeFormat{DateTimeFormat::DTG};
|
||||
const QPixmap m_minLimitIndicator;
|
||||
const QPixmap m_maxLimitIndicator;
|
||||
void setLiveIndicatorScalingFactor(double factor);
|
||||
|
||||
QString m_trackLabel;
|
||||
QColor liveIndicatorColor() const
|
||||
{
|
||||
return m_liveIndicatorColor;
|
||||
}
|
||||
|
||||
QFont m_font;
|
||||
void setLiveIndicatorColor(const QColor& color);
|
||||
|
||||
qint64 liveIndicatorTime() const
|
||||
{
|
||||
return m_liveIndicatorTime;
|
||||
}
|
||||
|
||||
void setLiveIndicatorTime(qint64 time);
|
||||
|
||||
int liveIndicatorPosition() const
|
||||
{
|
||||
return toPixel(m_liveIndicatorTime);
|
||||
}
|
||||
|
||||
void setLiveIndicatorPosition(int position);
|
||||
|
||||
bool isLiveIndicatorVisible() const
|
||||
{
|
||||
return m_isLiveIndicatorVisible;
|
||||
}
|
||||
|
||||
void setLiveIndicatorVisible(bool isLiveIndicatorVisible);
|
||||
void startLiveTimer(qint64 startTime = -1, int interval = 1000);
|
||||
void stopLiveTimer();
|
||||
|
||||
qint64 hoverTime() const
|
||||
{
|
||||
return m_hoverTime;
|
||||
}
|
||||
|
||||
void setHoverTime(qint64 time);
|
||||
|
||||
int hoverPosition() const
|
||||
{
|
||||
return m_hoverPosition;
|
||||
}
|
||||
|
||||
void setHoverPosition(int position);
|
||||
|
||||
bool isHoverVisible() const
|
||||
{
|
||||
return m_isHoverVisible;
|
||||
}
|
||||
|
||||
void setHoverVisible(bool visible);
|
||||
|
||||
bool isHoverTimeVisible() const
|
||||
{
|
||||
return m_isHoverTimeVisible;
|
||||
}
|
||||
|
||||
void setHoverTimeVisible(bool visible);
|
||||
|
||||
DateTimeFormat hoverDateTimeFormat() const
|
||||
{
|
||||
return m_hoverDateTimeFormat;
|
||||
}
|
||||
|
||||
void setHoverDateTimeFormat(DateTimeFormat format);
|
||||
|
||||
bool isLimitsVisible() const
|
||||
{
|
||||
return m_isLimitsVisible;
|
||||
}
|
||||
|
||||
void setLimitsVisible(bool visible);
|
||||
|
||||
DateTimeFormat limitsDateTimeFormat() const
|
||||
{
|
||||
return m_limitsDateTimeFormat;
|
||||
}
|
||||
|
||||
void setLimitsDateTimeFormat(DateTimeFormat format);
|
||||
|
||||
int toPixel(qint64 time) const;
|
||||
qint64 toTime(int pixel) const;
|
||||
|
||||
QFont& font()
|
||||
{
|
||||
return m_font;
|
||||
}
|
||||
|
||||
TimelineHeaderViewMouseHandler* mouseHandler()
|
||||
{
|
||||
return m_mouseHandler;
|
||||
}
|
||||
|
||||
void wheelEvent(QWheelEvent* e) override
|
||||
{
|
||||
m_mouseHandler->wheelEvent(e);
|
||||
}
|
||||
|
||||
protected:
|
||||
void mouseMoveEvent(QMouseEvent* e) override
|
||||
{
|
||||
m_mouseHandler->mouseMoveEvent(e);
|
||||
}
|
||||
|
||||
void mousePressEvent(QMouseEvent* e) override
|
||||
{
|
||||
m_mouseHandler->mousePressEvent(e);
|
||||
}
|
||||
|
||||
void mouseReleaseEvent(QMouseEvent* e) override
|
||||
{
|
||||
m_mouseHandler->mouseReleaseEvent(e);
|
||||
}
|
||||
|
||||
void paintSection(QPainter* painter, const QRect& rect, int logicalIndex) const;
|
||||
|
||||
private:
|
||||
void updateMajorTicks();
|
||||
void updateMediumTicks();
|
||||
void updateMinorTicks();
|
||||
|
||||
public slots:
|
||||
void onUpdateTicks();
|
||||
|
||||
private slots:
|
||||
void onLiveTimeout();
|
||||
|
||||
signals:
|
||||
void ticksChanged(const Ticks&);
|
||||
void indicatorTimeChanged(qint64);
|
||||
void indicatorVisibilityChanged(bool);
|
||||
void liveIndicatorTimeChanged(qint64);
|
||||
void liveIndicatorVisibilityChanged(bool);
|
||||
void hoverPositionChanged(int);
|
||||
void hoverVisibilityChanged(bool);
|
||||
|
||||
private:
|
||||
TimelineHeaderViewMouseHandler* m_mouseHandler{nullptr};
|
||||
TimelineView* m_timelineView{nullptr};
|
||||
Ticks m_majorTicks;
|
||||
Ticks m_mediumTicks;
|
||||
Ticks m_minorTicks;
|
||||
DateTimeFormat m_dateTimeFormat{DateTimeFormat::DTG};
|
||||
bool m_isDateTimeFormatChangable{true};
|
||||
|
||||
double m_indicatorScalingFactor{0.5};
|
||||
qint64 m_indicatorTime{-1};
|
||||
bool m_isIndicatorVisible{true};
|
||||
bool m_isIndicatorLocked{false};
|
||||
|
||||
double m_liveIndicatorScalingFactor{0.5};
|
||||
QColor m_liveIndicatorColor;
|
||||
qint64 m_liveIndicatorTime{-1};
|
||||
bool m_isLiveIndicatorVisible{false};
|
||||
QTimer* m_liveTimer{nullptr};
|
||||
int m_liveTimerInterval{1000};
|
||||
|
||||
qint64 m_hoverTime{-1};
|
||||
int m_hoverPosition{-1};
|
||||
bool m_isHoverVisible{true};
|
||||
bool m_isHoverTimeVisible{true};
|
||||
DateTimeFormat m_hoverDateTimeFormat{DateTimeFormat::DTG};
|
||||
|
||||
bool m_isLimitsVisible{false};
|
||||
DateTimeFormat m_limitsDateTimeFormat{DateTimeFormat::DTG};
|
||||
const QPixmap m_minLimitIndicator;
|
||||
const QPixmap m_maxLimitIndicator;
|
||||
|
||||
QString m_trackLabel;
|
||||
|
||||
QFont m_font;
|
||||
};
|
||||
|
||||
typedef TimelineHeaderView::Section Section;
|
||||
|
||||
}
|
||||
} // namespace LtsTimeline
|
||||
Executable → Regular
+105
-118
@@ -1,160 +1,147 @@
|
||||
#include "timeline_header_view_mouse_handler.h"
|
||||
|
||||
#include "timeline_header_view.h"
|
||||
#include "timeline_view.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QMouseEvent>
|
||||
#include <QWheelEvent>
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
namespace LtsTimeline
|
||||
{
|
||||
|
||||
TimelineHeaderViewMouseHandler::TimelineHeaderViewMouseHandler(TimelineHeaderView *header)
|
||||
: m_header(header)
|
||||
{}
|
||||
TimelineHeaderViewMouseHandler::TimelineHeaderViewMouseHandler(TimelineHeaderView* header) : m_header(header) {}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void TimelineHeaderViewMouseHandler::mouseMoveEvent(QMouseEvent *e)
|
||||
void TimelineHeaderViewMouseHandler::mouseMoveEvent(QMouseEvent* e)
|
||||
{
|
||||
if (m_isLeftButtonPressed)
|
||||
m_hasMouseMovedLeft = true;
|
||||
if (m_isRightButtonPressed)
|
||||
m_hasMouseMovedRight = true;
|
||||
if (m_isLeftButtonPressed)
|
||||
m_hasMouseMovedLeft = true;
|
||||
if (m_isRightButtonPressed)
|
||||
m_hasMouseMovedRight = true;
|
||||
|
||||
if (!m_isResizingSection)
|
||||
{
|
||||
if (m_header->sectionPosition(Section::eItems) - 10 < e->pos().x() && e->pos().x() < m_header->sectionPosition(Section::eItems))
|
||||
m_header->m_timelineView->setCursor(QCursor(Qt::SizeHorCursor));
|
||||
else if (e->pos().y() <= m_header->geometry().bottom())
|
||||
m_header->m_timelineView->setCursor(QCursor(Qt::ArrowCursor));
|
||||
}
|
||||
else
|
||||
m_header->resizeSection(Section::eActuator, std::min(e->pos().x(), m_header->geometry().width() / 2));
|
||||
|
||||
const bool isWithinRangeX = isMouseWithinRangeX(e->pos().x());
|
||||
if (!isWithinRangeX && !m_isLeftButtonPressed)
|
||||
{
|
||||
m_header->setHoverPosition(-1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isWithinRangeX)
|
||||
m_header->setHoverPosition(e->pos().x());
|
||||
if (m_isLeftButtonPressed)
|
||||
{
|
||||
if (m_isIndicatorSelected && !m_header->m_isIndicatorLocked)
|
||||
if (!m_isResizingSection)
|
||||
{
|
||||
m_header->m_timelineView->setCursor(QCursor(Qt::ClosedHandCursor));
|
||||
if (isWithinRangeX)
|
||||
m_header->setIndicatorPosition(e->pos().x());
|
||||
if (m_header->sectionPosition(Section::eItems) - 10 < e->pos().x() &&
|
||||
e->pos().x() < m_header->sectionPosition(Section::eItems))
|
||||
m_header->m_timelineView->setCursor(QCursor(Qt::SizeHorCursor));
|
||||
else if (e->pos().y() <= m_header->geometry().bottom())
|
||||
m_header->m_timelineView->setCursor(QCursor(Qt::ArrowCursor));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isMouseOverIndicator(e->pos()) && m_header->m_isIndicatorVisible && !m_header->m_isIndicatorLocked)
|
||||
m_header->m_timelineView->setCursor(QCursor(Qt::OpenHandCursor));
|
||||
else if (e->pos().y() <= m_header->geometry().bottom())
|
||||
m_header->m_timelineView->setCursor(QCursor(Qt::ArrowCursor));
|
||||
}
|
||||
}
|
||||
else
|
||||
m_header->resizeSection(Section::eActuator, std::min(e->pos().x(), m_header->geometry().width() / 2));
|
||||
|
||||
void TimelineHeaderViewMouseHandler::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
if (e->button() == Qt::LeftButton)
|
||||
{
|
||||
m_lastPos = e->pos();
|
||||
m_isLeftButtonPressed = true;
|
||||
if (isMouseOverIndicator(e->pos()) && m_header->m_isIndicatorVisible && !m_header->m_isIndicatorLocked)
|
||||
const bool isWithinRangeX = isMouseWithinRangeX(e->pos().x());
|
||||
if (!isWithinRangeX && !m_isLeftButtonPressed)
|
||||
{
|
||||
m_header->m_timelineView->setCursor(QCursor(Qt::ClosedHandCursor));
|
||||
m_isIndicatorSelected = true;
|
||||
m_header->setHoverPosition(-1);
|
||||
return;
|
||||
}
|
||||
else if (m_header->m_timelineView->cursor().shape() == Qt::SizeHorCursor)
|
||||
|
||||
if (isWithinRangeX)
|
||||
m_header->setHoverPosition(e->pos().x());
|
||||
if (m_isLeftButtonPressed)
|
||||
{
|
||||
m_isResizingSection = true;
|
||||
if (m_isIndicatorSelected && !m_header->m_isIndicatorLocked)
|
||||
{
|
||||
m_header->m_timelineView->setCursor(QCursor(Qt::ClosedHandCursor));
|
||||
if (isWithinRangeX)
|
||||
m_header->setIndicatorPosition(e->pos().x());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isMouseOverIndicator(e->pos()) && m_header->m_isIndicatorVisible && !m_header->m_isIndicatorLocked)
|
||||
m_header->m_timelineView->setCursor(QCursor(Qt::OpenHandCursor));
|
||||
else if (e->pos().y() <= m_header->geometry().bottom())
|
||||
m_header->m_timelineView->setCursor(QCursor(Qt::ArrowCursor));
|
||||
}
|
||||
}
|
||||
if (e->button() == Qt::RightButton)
|
||||
m_isRightButtonPressed = true;
|
||||
}
|
||||
|
||||
void TimelineHeaderViewMouseHandler::mouseReleaseEvent(QMouseEvent *e)
|
||||
void TimelineHeaderViewMouseHandler::mousePressEvent(QMouseEvent* e)
|
||||
{
|
||||
if (e->button() == Qt::LeftButton)
|
||||
{
|
||||
if (!m_hasMouseMovedLeft && isMouseWithinRangeX(e->pos().x()) && !m_header->m_isIndicatorLocked)
|
||||
m_header->setIndicatorPosition(e->pos().x());
|
||||
if (isMouseOverIndicator(e->pos()))
|
||||
m_header->m_timelineView->setCursor(QCursor(Qt::OpenHandCursor));
|
||||
else
|
||||
m_header->m_timelineView->setCursor(QCursor(Qt::ArrowCursor));
|
||||
m_lastPos = {};
|
||||
m_isIndicatorSelected = false;
|
||||
m_isResizingSection = false;
|
||||
m_isLeftButtonPressed = false;
|
||||
m_hasMouseMovedLeft = false;
|
||||
}
|
||||
if (e->button() == Qt::RightButton)
|
||||
{
|
||||
m_header->setDateTimeFormat(static_cast<DateTimeFormat>((m_header->dateTimeFormat() + 1) % DateTime::numberOfDateTimeFormats()));
|
||||
m_isRightButtonPressed = false;
|
||||
m_hasMouseMovedRight = false;
|
||||
}
|
||||
if (e->button() == Qt::LeftButton)
|
||||
{
|
||||
m_lastPos = e->pos();
|
||||
m_isLeftButtonPressed = true;
|
||||
if (isMouseOverIndicator(e->pos()) && m_header->m_isIndicatorVisible && !m_header->m_isIndicatorLocked)
|
||||
{
|
||||
m_header->m_timelineView->setCursor(QCursor(Qt::ClosedHandCursor));
|
||||
m_isIndicatorSelected = true;
|
||||
}
|
||||
else if (m_header->m_timelineView->cursor().shape() == Qt::SizeHorCursor)
|
||||
{
|
||||
m_isResizingSection = true;
|
||||
}
|
||||
}
|
||||
if (e->button() == Qt::RightButton)
|
||||
m_isRightButtonPressed = true;
|
||||
}
|
||||
|
||||
void TimelineHeaderViewMouseHandler::wheelEvent(QWheelEvent *e)
|
||||
void TimelineHeaderViewMouseHandler::mouseReleaseEvent(QMouseEvent* e)
|
||||
{
|
||||
if (!m_header->m_timelineView)
|
||||
return;
|
||||
|
||||
if (QGuiApplication::queryKeyboardModifiers() == Qt::ControlModifier)
|
||||
{
|
||||
if (e->angleDelta().y() < 0)
|
||||
m_header->m_timelineView->setZoomFactor(Zoom::increment(m_header->m_timelineView->zoomFactor()));
|
||||
else
|
||||
m_header->m_timelineView->setZoomFactor(Zoom::decrement(m_header->m_timelineView->zoomFactor()));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (e->angleDelta().y() > 0)
|
||||
m_header->m_timelineView->setCurrentTime(
|
||||
m_header->m_timelineView->currentTime() - Zoom::majorInterval(m_header->m_timelineView->zoomFactor())
|
||||
);
|
||||
else
|
||||
m_header->m_timelineView->setCurrentTime(
|
||||
m_header->m_timelineView->currentTime() + Zoom::majorInterval(m_header->m_timelineView->zoomFactor())
|
||||
);
|
||||
}
|
||||
if (e->button() == Qt::LeftButton)
|
||||
{
|
||||
if (!m_hasMouseMovedLeft && isMouseWithinRangeX(e->pos().x()) && !m_header->m_isIndicatorLocked)
|
||||
m_header->setIndicatorPosition(e->pos().x());
|
||||
if (isMouseOverIndicator(e->pos()))
|
||||
m_header->m_timelineView->setCursor(QCursor(Qt::OpenHandCursor));
|
||||
else
|
||||
m_header->m_timelineView->setCursor(QCursor(Qt::ArrowCursor));
|
||||
m_lastPos = {};
|
||||
m_isIndicatorSelected = false;
|
||||
m_isResizingSection = false;
|
||||
m_isLeftButtonPressed = false;
|
||||
m_hasMouseMovedLeft = false;
|
||||
}
|
||||
if (e->button() == Qt::RightButton)
|
||||
{
|
||||
m_header->setDateTimeFormat(
|
||||
static_cast<DateTimeFormat>((m_header->dateTimeFormat() + 1) % DateTime::numberOfDateTimeFormats()));
|
||||
m_isRightButtonPressed = false;
|
||||
m_hasMouseMovedRight = false;
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineHeaderViewMouseHandler::wheelEvent(QWheelEvent* e)
|
||||
{
|
||||
if (!m_header->m_timelineView)
|
||||
return;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (QGuiApplication::queryKeyboardModifiers() == Qt::ControlModifier)
|
||||
{
|
||||
if (e->angleDelta().y() < 0)
|
||||
m_header->m_timelineView->setZoomFactor(Zoom::increment(m_header->m_timelineView->zoomFactor()));
|
||||
else
|
||||
m_header->m_timelineView->setZoomFactor(Zoom::decrement(m_header->m_timelineView->zoomFactor()));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (e->angleDelta().y() > 0)
|
||||
m_header->m_timelineView->setCurrentTime(m_header->m_timelineView->currentTime() -
|
||||
Zoom::majorInterval(m_header->m_timelineView->zoomFactor()));
|
||||
else
|
||||
m_header->m_timelineView->setCurrentTime(m_header->m_timelineView->currentTime() +
|
||||
Zoom::majorInterval(m_header->m_timelineView->zoomFactor()));
|
||||
}
|
||||
}
|
||||
|
||||
bool TimelineHeaderViewMouseHandler::isMouseWithinRangeX(int x) const
|
||||
{
|
||||
return m_header->sectionPosition(Section::eItems) < x && x < m_header->geometry().right();
|
||||
return m_header->sectionPosition(Section::eItems) < x && x < m_header->geometry().right();
|
||||
}
|
||||
|
||||
bool TimelineHeaderViewMouseHandler::isMouseWithinRangeY(int y) const
|
||||
{
|
||||
return m_header->geometry().top() < y && y < m_header->geometry().bottom();
|
||||
return m_header->geometry().top() < y && y < m_header->geometry().bottom();
|
||||
}
|
||||
|
||||
bool TimelineHeaderViewMouseHandler::isMouseOverIndicator(const QPoint &pos) const
|
||||
bool TimelineHeaderViewMouseHandler::isMouseOverIndicator(const QPoint& pos) const
|
||||
{
|
||||
const int height = m_header->height();
|
||||
return m_header->indicatorPosition() - height / 4 <= pos.x() && pos.x() <= m_header->indicatorPosition() + height / 4 &&
|
||||
m_header->geometry().center().y() <= pos.y() && pos.y() < m_header->geometry().bottom();
|
||||
const int height = m_header->height();
|
||||
return m_header->indicatorPosition() - height / 4 <= pos.x() &&
|
||||
pos.x() <= m_header->indicatorPosition() + height / 4 && m_header->geometry().center().y() <= pos.y() &&
|
||||
pos.y() < m_header->geometry().bottom();
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsTimeline
|
||||
Executable → Regular
+28
-25
@@ -4,46 +4,49 @@
|
||||
|
||||
#include <QPoint>
|
||||
|
||||
|
||||
class QMouseEvent;
|
||||
class QWheelEvent;
|
||||
|
||||
|
||||
namespace LtsTimeline
|
||||
{
|
||||
|
||||
class TimelineHeaderView;
|
||||
|
||||
|
||||
class LTSTIMELINE_EXPORT TimelineHeaderViewMouseHandler
|
||||
{
|
||||
|
||||
public:
|
||||
explicit TimelineHeaderViewMouseHandler(TimelineHeaderView *header);
|
||||
public:
|
||||
explicit TimelineHeaderViewMouseHandler(TimelineHeaderView* header);
|
||||
|
||||
void mouseMoveEvent(QMouseEvent *e);
|
||||
void mousePressEvent(QMouseEvent *e);
|
||||
void mouseReleaseEvent(QMouseEvent *e);
|
||||
void wheelEvent(QWheelEvent *e);
|
||||
void mouseMoveEvent(QMouseEvent* e);
|
||||
void mousePressEvent(QMouseEvent* e);
|
||||
void mouseReleaseEvent(QMouseEvent* e);
|
||||
void wheelEvent(QWheelEvent* e);
|
||||
|
||||
bool isBusy() const { return m_isIndicatorSelected || m_isResizingSection; }
|
||||
bool isIndicatorSelected() const { return m_isIndicatorSelected; }
|
||||
bool isBusy() const
|
||||
{
|
||||
return m_isIndicatorSelected || m_isResizingSection;
|
||||
}
|
||||
|
||||
private:
|
||||
bool isIndicatorSelected() const
|
||||
{
|
||||
return m_isIndicatorSelected;
|
||||
}
|
||||
|
||||
bool isMouseWithinRangeX(int x) const;
|
||||
bool isMouseWithinRangeY(int y) const;
|
||||
bool isMouseOverIndicator(const QPoint &pos) const;
|
||||
private:
|
||||
bool isMouseWithinRangeX(int x) const;
|
||||
bool isMouseWithinRangeY(int y) const;
|
||||
bool isMouseOverIndicator(const QPoint& pos) const;
|
||||
|
||||
private:
|
||||
TimelineHeaderView *m_header{nullptr};
|
||||
QPoint m_lastPos;
|
||||
bool m_isLeftButtonPressed{false};
|
||||
bool m_isRightButtonPressed{false};
|
||||
bool m_hasMouseMovedLeft{false};
|
||||
bool m_hasMouseMovedRight{false};
|
||||
bool m_isIndicatorSelected{false};
|
||||
bool m_isResizingSection{false};
|
||||
private:
|
||||
TimelineHeaderView* m_header{nullptr};
|
||||
QPoint m_lastPos;
|
||||
bool m_isLeftButtonPressed{false};
|
||||
bool m_isRightButtonPressed{false};
|
||||
bool m_hasMouseMovedLeft{false};
|
||||
bool m_hasMouseMovedRight{false};
|
||||
bool m_isIndicatorSelected{false};
|
||||
bool m_isResizingSection{false};
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsTimeline
|
||||
Executable → Regular
+465
-533
File diff suppressed because it is too large.
Load diff
Executable → Regular
+250
-197
@@ -1,248 +1,301 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "item.h"
|
||||
#include "ltstimeline_export.h"
|
||||
#include "track.h"
|
||||
|
||||
#include "ltstimeline_export.h"
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QObject>
|
||||
#include <type_traits>
|
||||
|
||||
|
||||
namespace LtsTimeline
|
||||
{
|
||||
|
||||
class TimelineView;
|
||||
|
||||
|
||||
class LTSTIMELINE_EXPORT TimelineModel : public QAbstractItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
friend class TimelineViewSelectHandler;
|
||||
friend class TimelineViewSelectHandler;
|
||||
|
||||
public:
|
||||
explicit TimelineModel(TimelineView *view, QObject *parent = nullptr);
|
||||
virtual ~TimelineModel() = default;
|
||||
public:
|
||||
explicit TimelineModel(TimelineView* view, QObject* parent = nullptr);
|
||||
virtual ~TimelineModel() = default;
|
||||
|
||||
void clear();
|
||||
Track &rootTrack() { return m_rootTrack; }
|
||||
Track &track(int id) noexcept(false);
|
||||
const Track &track(int id) const noexcept(false);
|
||||
const Item &item(int id) const noexcept(false);
|
||||
Item &item(int id) noexcept(false);
|
||||
const QVector<int> itemIds() const;
|
||||
const QVector<int> itemIdsBetween(qint64 start, qint64 end, bool strict = false, bool complete = false, bool recursive = false, bool sorted = false) const;
|
||||
const QVector<int> copyItemIdsBetween(qint64 start, qint64 end, bool strict, bool complete, bool sorted) const;
|
||||
|
||||
bool isItemsBetween(qint64 start, qint64 end, const QVector<int> &ignoreIds = {}, bool strict = false, bool complete = false, bool recursive = false) const;
|
||||
bool isItemsBetween(qint64 start, qint64 end, int ignoreId = -1 , bool strict = false, bool complete = false, bool recursive = false) const;
|
||||
const Track &parentOfTrackId(int id) const noexcept(false);
|
||||
void clear();
|
||||
|
||||
virtual void setItemStartTime(Track &t, Item &i, qint64 newStart);
|
||||
virtual void setItemStartTime(Item &i, qint64 newStart) noexcept(false);
|
||||
virtual void setItemStartTime(int itemId, qint64 newStart) noexcept(false);
|
||||
|
||||
virtual void setItemDuration(Track &t, Item &i, int duration);
|
||||
virtual void setItemDuration(Item &i, int duration) noexcept(false);
|
||||
virtual void setItemDuration(int itemId, int duration) noexcept(false);
|
||||
|
||||
|
||||
void print(bool withItems = false) const { m_rootTrack.printTrackIds(withItems); }
|
||||
|
||||
template <typename TrackClass, typename = typename std::enable_if<std::is_base_of<Track, TrackClass>::value, TrackClass>::type>
|
||||
int addTrack(int parentTrackId, TrackClass &&newTrack ) noexcept(false)
|
||||
{
|
||||
int id = nextFreeTrackId();
|
||||
|
||||
TrackClass _track(std::move(newTrack));
|
||||
_track.m_id = id;
|
||||
_track.m_parentId = parentTrackId;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
auto *ptr = track(parentTrackId).addTrack(std::move(_track));
|
||||
m_trackCache.insert(std::pair<int, Track *>(id, ptr));
|
||||
|
||||
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
template <typename ItemClass, typename = typename std::enable_if<std::is_base_of<Item, ItemClass>::value, ItemClass>::type>
|
||||
int addItem(int parentTrackId, ItemClass &&item) noexcept(false)
|
||||
{
|
||||
int id = nextFreeItemId();
|
||||
|
||||
ItemClass _item(std::move(item));
|
||||
_item.m_id = id;
|
||||
_item.m_parentTrackId = parentTrackId;
|
||||
|
||||
if (m_isSnapEnabled)
|
||||
Track& rootTrack()
|
||||
{
|
||||
_item.m_startTime = _item.m_startTime - (_item.m_startTime % 1000);
|
||||
_item.m_duration = _item.m_duration - (_item.m_duration % 1000);
|
||||
return m_rootTrack;
|
||||
}
|
||||
|
||||
Item *ptr = track(parentTrackId).addItem(std::move(_item));
|
||||
m_itemCache.insert(std::pair<int, Item *>(id, ptr));
|
||||
Track& track(int id) noexcept(false);
|
||||
const Track& track(int id) const noexcept(false);
|
||||
const Item& item(int id) const noexcept(false);
|
||||
Item& item(int id) noexcept(false);
|
||||
const QVector<int> itemIds() const;
|
||||
const QVector<int> itemIdsBetween(qint64 start, qint64 end, bool strict = false, bool complete = false,
|
||||
bool recursive = false, bool sorted = false) const;
|
||||
const QVector<int> copyItemIdsBetween(qint64 start, qint64 end, bool strict, bool complete, bool sorted) const;
|
||||
|
||||
QModelIndex idx = indexOfTrack(parentTrackId);
|
||||
emit dataChanged(idx, idx);
|
||||
bool isItemsBetween(qint64 start, qint64 end, const QVector<int>& ignoreIds = {}, bool strict = false,
|
||||
bool complete = false, bool recursive = false) const;
|
||||
bool isItemsBetween(qint64 start, qint64 end, int ignoreId = -1, bool strict = false, bool complete = false,
|
||||
bool recursive = false) const;
|
||||
const Track& parentOfTrackId(int id) const noexcept(false);
|
||||
|
||||
return id;
|
||||
}
|
||||
virtual void setItemStartTime(Track& t, Item& i, qint64 newStart);
|
||||
virtual void setItemStartTime(Item& i, qint64 newStart) noexcept(false);
|
||||
virtual void setItemStartTime(int itemId, qint64 newStart) noexcept(false);
|
||||
|
||||
bool isEditable() const { return m_isEditable; }
|
||||
void setEditable(bool editable) { m_isEditable = editable; }
|
||||
bool isSnapEnabled() const { return m_isSnapEnabled; }
|
||||
void setSnapEnabled(bool enabled) { m_isSnapEnabled = enabled; }
|
||||
int snapStep() const { return m_snapStep; }
|
||||
void setSnapStep(int step) { m_snapStep = step; }
|
||||
int snapTolerance() const { return m_snapTol; }
|
||||
void setSnapTolerance(int tolerance) { m_snapTol = tolerance; }
|
||||
qint64 snapTime(qint64 time) const { return m_isSnapEnabled ? time / m_snapStep * m_snapStep : time; }
|
||||
int minimumDuration() const { return m_minItemDuration; }
|
||||
void setMinimumDuration(int duration);
|
||||
virtual void setItemDuration(Track& t, Item& i, int duration);
|
||||
virtual void setItemDuration(Item& i, int duration) noexcept(false);
|
||||
virtual void setItemDuration(int itemId, int duration) noexcept(false);
|
||||
|
||||
QModelIndex indexOfTrack(int trackId) const;
|
||||
QModelIndex indexOfTrackSafe(int trackId) const noexcept(false);
|
||||
|
||||
virtual void moveItemToTrack(int itemId, int trackId, qint64 time) noexcept(false);
|
||||
virtual void removeItem(int itemId) noexcept(false);
|
||||
virtual void removeTrack(int trackId) noexcept(false);
|
||||
|
||||
virtual bool canDropItem(const Item &item, int trackId, qint64 start) const;
|
||||
virtual bool canMoveItem(const Item &item, qint64 start) const;
|
||||
virtual bool canResizeItem(const Item &item, qint64 start, int duration) const;
|
||||
|
||||
virtual bool isItemDragged(int _itemId) const;
|
||||
|
||||
virtual void copyToClipboard(const QVector<int> &ids) noexcept(false);
|
||||
virtual void cutToClipboard(const QVector<int> &ids) noexcept(false);
|
||||
virtual void pasteFromClipboard(qint64 time) noexcept(false);
|
||||
|
||||
bool isClipboardEmpty() const { return m_clipboard.empty(); }
|
||||
|
||||
|
||||
int rowCount(const QModelIndex &parent = {}) const override;
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
QModelIndex index(int row, int column, const QModelIndex &parent) const override;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
QModelIndex parent(const QModelIndex &index) const override;
|
||||
int columnCount(const QModelIndex &) const override { return 2; }
|
||||
|
||||
protected:
|
||||
NGL::INGLLogger &m_logger;
|
||||
ItemPtrNCVRef _itemNCV(Track &track, int id) noexcept(false)
|
||||
{
|
||||
return track._itemNCV(id);
|
||||
}
|
||||
|
||||
ItemPtrNCVRef _itemNCV(const TrackPtr &trackPtr, int id) noexcept(false)
|
||||
{
|
||||
return trackPtr->_itemNCV(id);
|
||||
}
|
||||
|
||||
const ItemPtrRefs _items(const TrackPtr &trackPtr, bool recursive) const
|
||||
{
|
||||
return trackPtr->_items(recursive);
|
||||
}
|
||||
|
||||
ItemPtrNCVRefs _itemsNCV(const TrackPtr &trackPtr, bool recursive)
|
||||
{
|
||||
return trackPtr->_itemsNCV(recursive);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int addItem(int parentTrackId, ItemPtr &&itemPtr, bool forceTheCompilerToUseMe = false) noexcept(false)
|
||||
{
|
||||
(void)forceTheCompilerToUseMe;
|
||||
|
||||
int id = nextFreeItemId();
|
||||
|
||||
ItemPtr _itemPtr(std::move(itemPtr));
|
||||
|
||||
_itemPtr->m_id = id;
|
||||
|
||||
_itemPtr->m_parentTrackId = parentTrackId;
|
||||
|
||||
if (m_isSnapEnabled)
|
||||
void print(bool withItems = false) const
|
||||
{
|
||||
_itemPtr->m_startTime = _itemPtr->m_startTime - (_itemPtr->m_startTime % 1000);
|
||||
_itemPtr->m_duration = _itemPtr->m_duration - (_itemPtr->m_duration % 1000);
|
||||
m_rootTrack.printTrackIds(withItems);
|
||||
}
|
||||
Item *ptr = track(parentTrackId).addItem(std::move(_itemPtr));
|
||||
|
||||
m_itemCache.insert(std::pair<int, Item *>(id, ptr));
|
||||
|
||||
QModelIndex idx = indexOfTrack(parentTrackId);
|
||||
emit dataChanged(idx, idx);
|
||||
template <typename TrackClass,
|
||||
typename = typename std::enable_if<std::is_base_of<Track, TrackClass>::value, TrackClass>::type>
|
||||
int addTrack(int parentTrackId, TrackClass&& newTrack) noexcept(false)
|
||||
{
|
||||
int id = nextFreeTrackId();
|
||||
|
||||
return id;
|
||||
}
|
||||
TrackClass _track(std::move(newTrack));
|
||||
_track.m_id = id;
|
||||
_track.m_parentId = parentTrackId;
|
||||
|
||||
auto* ptr = track(parentTrackId).addTrack(std::move(_track));
|
||||
m_trackCache.insert(std::pair<int, Track*>(id, ptr));
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
template <typename ItemClass,
|
||||
typename = typename std::enable_if<std::is_base_of<Item, ItemClass>::value, ItemClass>::type>
|
||||
int addItem(int parentTrackId, ItemClass&& item) noexcept(false)
|
||||
{
|
||||
int id = nextFreeItemId();
|
||||
|
||||
ItemClass _item(std::move(item));
|
||||
_item.m_id = id;
|
||||
_item.m_parentTrackId = parentTrackId;
|
||||
|
||||
if (m_isSnapEnabled)
|
||||
{
|
||||
_item.m_startTime = _item.m_startTime - (_item.m_startTime % 1000);
|
||||
_item.m_duration = _item.m_duration - (_item.m_duration % 1000);
|
||||
}
|
||||
|
||||
Item* ptr = track(parentTrackId).addItem(std::move(_item));
|
||||
m_itemCache.insert(std::pair<int, Item*>(id, ptr));
|
||||
|
||||
QModelIndex idx = indexOfTrack(parentTrackId);
|
||||
emit dataChanged(idx, idx);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
void clearItems();
|
||||
int rowOfTrackId(int id) const noexcept(false);
|
||||
bool isEditable() const
|
||||
{
|
||||
return m_isEditable;
|
||||
}
|
||||
|
||||
|
||||
void setEditable(bool editable)
|
||||
{
|
||||
m_isEditable = editable;
|
||||
}
|
||||
|
||||
const Track &trackOfIndex(const QModelIndex &index) const;
|
||||
int indexOf(int id) const;
|
||||
bool isSnapEnabled() const
|
||||
{
|
||||
return m_isSnapEnabled;
|
||||
}
|
||||
|
||||
const QVector<int> _itemIdsBetween(Track &t, qint64 start, qint64 end, bool strict, bool complete, bool recursive, bool sorted, qint64 minimumDuration) const;
|
||||
const QVector<int> _copyItemIdsBetween(Track &t, qint64 start, qint64 end, bool strict, bool complete, bool recursive, bool sorted, qint64 minimumDuration) const;
|
||||
bool _isItemsBetween(const Track &t, qint64 start, qint64 end, const QVector<int> &ignoreIds, bool strict, bool complete, bool recursive, qint64 minimumDuration) const;
|
||||
bool _isItemsBetween(const Track &t, qint64 start, qint64 end, int ignoreId, bool strict, bool complete, bool recursive, qint64 minimumDuration) const;
|
||||
void setSnapEnabled(bool enabled)
|
||||
{
|
||||
m_isSnapEnabled = enabled;
|
||||
}
|
||||
|
||||
private:
|
||||
int nextFreeTrackId() { return m_currentTrackId++; }
|
||||
int nextFreeItemId() { return m_currentItemId++; }
|
||||
int snapStep() const
|
||||
{
|
||||
return m_snapStep;
|
||||
}
|
||||
|
||||
QModelIndex indexOfTrackFromIndex(const QModelIndex &idx, int trackId) const;
|
||||
QModelIndex indexOfTrackFromIndexSafe(const QModelIndex &idx, int trackId) const noexcept(false);
|
||||
void setSnapStep(int step)
|
||||
{
|
||||
m_snapStep = step;
|
||||
}
|
||||
|
||||
public slots:
|
||||
virtual void onInsertTrack(const QModelIndex &index) { Q_UNUSED(index); }
|
||||
virtual void onRemoveTrack(const QModelIndex &index) { Q_UNUSED(index); }
|
||||
int snapTolerance() const
|
||||
{
|
||||
return m_snapTol;
|
||||
}
|
||||
|
||||
protected:
|
||||
NGL::INGLLogger &m_logger;
|
||||
TimelineView *m_view{nullptr};
|
||||
void setSnapTolerance(int tolerance)
|
||||
{
|
||||
m_snapTol = tolerance;
|
||||
}
|
||||
|
||||
Track m_rootTrack;
|
||||
int m_currentTrackId{0};
|
||||
int m_currentItemId{0};
|
||||
bool m_isEditable{true};
|
||||
bool m_isSnapEnabled{false};
|
||||
int m_snapStep{500};
|
||||
int m_snapTol{1000};
|
||||
int m_minItemDuration{0};
|
||||
qint64 snapTime(qint64 time) const
|
||||
{
|
||||
return m_isSnapEnabled ? time / m_snapStep * m_snapStep : time;
|
||||
}
|
||||
|
||||
|
||||
bool m_itemCaching{true};
|
||||
bool m_trackCaching{true};
|
||||
std::map<int , Track *> m_trackCache;
|
||||
|
||||
std::map<int , Item *> m_itemCache;
|
||||
Items m_clipboard;
|
||||
int minimumDuration() const
|
||||
{
|
||||
return m_minItemDuration;
|
||||
}
|
||||
|
||||
void setMinimumDuration(int duration);
|
||||
|
||||
QModelIndex indexOfTrack(int trackId) const;
|
||||
QModelIndex indexOfTrackSafe(int trackId) const noexcept(false);
|
||||
|
||||
virtual void moveItemToTrack(int itemId, int trackId, qint64 time) noexcept(false);
|
||||
virtual void removeItem(int itemId) noexcept(false);
|
||||
virtual void removeTrack(int trackId) noexcept(false);
|
||||
|
||||
virtual bool canDropItem(const Item& item, int trackId, qint64 start) const;
|
||||
virtual bool canMoveItem(const Item& item, qint64 start) const;
|
||||
virtual bool canResizeItem(const Item& item, qint64 start, int duration) const;
|
||||
|
||||
virtual bool isItemDragged(int _itemId) const;
|
||||
|
||||
virtual void copyToClipboard(const QVector<int>& ids) noexcept(false);
|
||||
virtual void cutToClipboard(const QVector<int>& ids) noexcept(false);
|
||||
virtual void pasteFromClipboard(qint64 time) noexcept(false);
|
||||
|
||||
bool isClipboardEmpty() const
|
||||
{
|
||||
return m_clipboard.empty();
|
||||
}
|
||||
|
||||
int rowCount(const QModelIndex& parent = {}) const override;
|
||||
QVariant data(const QModelIndex& index, int role) const override;
|
||||
QModelIndex index(int row, int column, const QModelIndex& parent) const override;
|
||||
Qt::ItemFlags flags(const QModelIndex& index) const override;
|
||||
QModelIndex parent(const QModelIndex& index) const override;
|
||||
|
||||
int columnCount(const QModelIndex&) const override
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
protected:
|
||||
NGL::INGLLogger& m_logger;
|
||||
|
||||
ItemPtrNCVRef _itemNCV(Track& track, int id) noexcept(false)
|
||||
{
|
||||
return track._itemNCV(id);
|
||||
}
|
||||
|
||||
ItemPtrNCVRef _itemNCV(const TrackPtr& trackPtr, int id) noexcept(false)
|
||||
{
|
||||
return trackPtr->_itemNCV(id);
|
||||
}
|
||||
|
||||
const ItemPtrRefs _items(const TrackPtr& trackPtr, bool recursive) const
|
||||
{
|
||||
return trackPtr->_items(recursive);
|
||||
}
|
||||
|
||||
ItemPtrNCVRefs _itemsNCV(const TrackPtr& trackPtr, bool recursive)
|
||||
{
|
||||
return trackPtr->_itemsNCV(recursive);
|
||||
}
|
||||
|
||||
int addItem(int parentTrackId, ItemPtr&& itemPtr, bool forceTheCompilerToUseMe = false) noexcept(false)
|
||||
{
|
||||
(void)forceTheCompilerToUseMe;
|
||||
|
||||
int id = nextFreeItemId();
|
||||
|
||||
ItemPtr _itemPtr(std::move(itemPtr));
|
||||
|
||||
_itemPtr->m_id = id;
|
||||
|
||||
_itemPtr->m_parentTrackId = parentTrackId;
|
||||
|
||||
if (m_isSnapEnabled)
|
||||
{
|
||||
_itemPtr->m_startTime = _itemPtr->m_startTime - (_itemPtr->m_startTime % 1000);
|
||||
_itemPtr->m_duration = _itemPtr->m_duration - (_itemPtr->m_duration % 1000);
|
||||
}
|
||||
Item* ptr = track(parentTrackId).addItem(std::move(_itemPtr));
|
||||
|
||||
m_itemCache.insert(std::pair<int, Item*>(id, ptr));
|
||||
|
||||
QModelIndex idx = indexOfTrack(parentTrackId);
|
||||
emit dataChanged(idx, idx);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
void clearItems();
|
||||
int rowOfTrackId(int id) const noexcept(false);
|
||||
|
||||
const Track& trackOfIndex(const QModelIndex& index) const;
|
||||
int indexOf(int id) const;
|
||||
|
||||
const QVector<int> _itemIdsBetween(Track& t, qint64 start, qint64 end, bool strict, bool complete, bool recursive,
|
||||
bool sorted, qint64 minimumDuration) const;
|
||||
const QVector<int> _copyItemIdsBetween(Track& t, qint64 start, qint64 end, bool strict, bool complete,
|
||||
bool recursive, bool sorted, qint64 minimumDuration) const;
|
||||
bool _isItemsBetween(const Track& t, qint64 start, qint64 end, const QVector<int>& ignoreIds, bool strict,
|
||||
bool complete, bool recursive, qint64 minimumDuration) const;
|
||||
bool _isItemsBetween(const Track& t, qint64 start, qint64 end, int ignoreId, bool strict, bool complete,
|
||||
bool recursive, qint64 minimumDuration) const;
|
||||
|
||||
private:
|
||||
int nextFreeTrackId()
|
||||
{
|
||||
return m_currentTrackId++;
|
||||
}
|
||||
|
||||
int nextFreeItemId()
|
||||
{
|
||||
return m_currentItemId++;
|
||||
}
|
||||
|
||||
QModelIndex indexOfTrackFromIndex(const QModelIndex& idx, int trackId) const;
|
||||
QModelIndex indexOfTrackFromIndexSafe(const QModelIndex& idx, int trackId) const noexcept(false);
|
||||
|
||||
public slots:
|
||||
|
||||
virtual void onInsertTrack(const QModelIndex& index)
|
||||
{
|
||||
Q_UNUSED(index);
|
||||
}
|
||||
|
||||
virtual void onRemoveTrack(const QModelIndex& index)
|
||||
{
|
||||
Q_UNUSED(index);
|
||||
}
|
||||
|
||||
protected:
|
||||
NGL::INGLLogger& m_logger;
|
||||
TimelineView* m_view{nullptr};
|
||||
|
||||
Track m_rootTrack;
|
||||
int m_currentTrackId{0};
|
||||
int m_currentItemId{0};
|
||||
bool m_isEditable{true};
|
||||
bool m_isSnapEnabled{false};
|
||||
int m_snapStep{500};
|
||||
int m_snapTol{1000};
|
||||
int m_minItemDuration{0};
|
||||
|
||||
bool m_itemCaching{true};
|
||||
bool m_trackCaching{true};
|
||||
std::map<int, Track*> m_trackCache;
|
||||
|
||||
std::map<int, Item*> m_itemCache;
|
||||
Items m_clipboard;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsTimeline
|
||||
Executable → Regular
+262
-271
@@ -1,11 +1,9 @@
|
||||
#include "timeline_utils.h"
|
||||
|
||||
#include <ngltools/ngltools_dtg.h>
|
||||
#include <ltstimeline_export.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDateTime>
|
||||
|
||||
#include <ltstimeline_export.h>
|
||||
#include <ngltools/ngltools_dtg.h>
|
||||
|
||||
namespace LtsTimeline
|
||||
{
|
||||
@@ -13,331 +11,324 @@ namespace LtsTimeline
|
||||
namespace DateTime
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
int numberOfDateTimeFormats()
|
||||
{
|
||||
return 6;
|
||||
return 6;
|
||||
}
|
||||
|
||||
QString toString(qint64 time, Format format)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case Format::DTG:
|
||||
return DTG::toStringMSec(time, DTG::DisplayFormat::Long);
|
||||
case Format::ISODate:
|
||||
return QDateTime::fromMSecsSinceEpoch(time).toString(Qt::ISODate);
|
||||
case Format::Standard:
|
||||
return QDateTime::fromMSecsSinceEpoch(time).toString(QStringLiteral("dd.MM.yyyy hh:mm:ss"));
|
||||
case Format::DTGShort:
|
||||
{
|
||||
QDateTime dateTime = QDateTime::fromMSecsSinceEpoch(time).toUTC().addSecs(DTG::timezone2Hours(DTG::timezone()) * 3600);
|
||||
return dateTime.toString(QStringLiteral("hhmmss ")) + QStringLiteral("%1").arg(DTG::timezone());
|
||||
}
|
||||
case Format::DTGVeryShort:
|
||||
{
|
||||
QDateTime dateTime = QDateTime::fromMSecsSinceEpoch(time).toUTC().addSecs(DTG::timezone2Hours(DTG::timezone()) * 3600);
|
||||
return dateTime.toString(QStringLiteral("hhmm"));
|
||||
}
|
||||
case Format::TimeOnly:
|
||||
return QTime::fromMSecsSinceStartOfDay(time).toString();
|
||||
}
|
||||
return {};
|
||||
switch (format)
|
||||
{
|
||||
case Format::DTG:
|
||||
return DTG::toStringMSec(time, DTG::DisplayFormat::Long);
|
||||
case Format::ISODate:
|
||||
return QDateTime::fromMSecsSinceEpoch(time).toString(Qt::ISODate);
|
||||
case Format::Standard:
|
||||
return QDateTime::fromMSecsSinceEpoch(time).toString(QStringLiteral("dd.MM.yyyy hh:mm:ss"));
|
||||
case Format::DTGShort: {
|
||||
QDateTime dateTime =
|
||||
QDateTime::fromMSecsSinceEpoch(time).toUTC().addSecs(DTG::timezone2Hours(DTG::timezone()) * 3600);
|
||||
return dateTime.toString(QStringLiteral("hhmmss ")) + QStringLiteral("%1").arg(DTG::timezone());
|
||||
}
|
||||
case Format::DTGVeryShort: {
|
||||
QDateTime dateTime =
|
||||
QDateTime::fromMSecsSinceEpoch(time).toUTC().addSecs(DTG::timezone2Hours(DTG::timezone()) * 3600);
|
||||
return dateTime.toString(QStringLiteral("hhmm"));
|
||||
}
|
||||
case Format::TimeOnly:
|
||||
return QTime::fromMSecsSinceStartOfDay(time).toString();
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace DateTime
|
||||
|
||||
namespace Zoom
|
||||
{
|
||||
|
||||
int numberOfZoomFactors()
|
||||
{
|
||||
return 15;
|
||||
return 15;
|
||||
}
|
||||
|
||||
Factor LTSTIMELINE_EXPORT increment(Factor factor)
|
||||
{
|
||||
switch (factor)
|
||||
{
|
||||
case ZoomFactor::FifteenSeconds:
|
||||
return ZoomFactor::ThirtySeconds;
|
||||
case ZoomFactor::ThirtySeconds:
|
||||
return ZoomFactor::SixtySeconds;
|
||||
case ZoomFactor::SixtySeconds:
|
||||
return ZoomFactor::TwoMinutes;
|
||||
case ZoomFactor::TwoMinutes:
|
||||
return ZoomFactor::ThreeMinutes;
|
||||
case ZoomFactor::ThreeMinutes:
|
||||
return ZoomFactor::FiveMinutes;
|
||||
case ZoomFactor::FiveMinutes:
|
||||
return ZoomFactor::TenMinutes;
|
||||
case ZoomFactor::TenMinutes:
|
||||
return ZoomFactor::FifteenMinutes;
|
||||
case ZoomFactor::FifteenMinutes:
|
||||
return ZoomFactor::ThirtyMinutes;
|
||||
case ZoomFactor::ThirtyMinutes:
|
||||
return ZoomFactor::SixtyMinutes;
|
||||
case ZoomFactor::SixtyMinutes:
|
||||
return ZoomFactor::TwoHours;
|
||||
case ZoomFactor::TwoHours:
|
||||
return ZoomFactor::FourHours;
|
||||
case ZoomFactor::FourHours:
|
||||
return ZoomFactor::EightHours;
|
||||
case ZoomFactor::EightHours:
|
||||
return ZoomFactor::TwelveHours;
|
||||
case ZoomFactor::TwelveHours:
|
||||
return ZoomFactor::OneDay;
|
||||
case ZoomFactor::OneDay:
|
||||
return ZoomFactor::OneDay;
|
||||
}
|
||||
return factor;
|
||||
switch (factor)
|
||||
{
|
||||
case ZoomFactor::FifteenSeconds:
|
||||
return ZoomFactor::ThirtySeconds;
|
||||
case ZoomFactor::ThirtySeconds:
|
||||
return ZoomFactor::SixtySeconds;
|
||||
case ZoomFactor::SixtySeconds:
|
||||
return ZoomFactor::TwoMinutes;
|
||||
case ZoomFactor::TwoMinutes:
|
||||
return ZoomFactor::ThreeMinutes;
|
||||
case ZoomFactor::ThreeMinutes:
|
||||
return ZoomFactor::FiveMinutes;
|
||||
case ZoomFactor::FiveMinutes:
|
||||
return ZoomFactor::TenMinutes;
|
||||
case ZoomFactor::TenMinutes:
|
||||
return ZoomFactor::FifteenMinutes;
|
||||
case ZoomFactor::FifteenMinutes:
|
||||
return ZoomFactor::ThirtyMinutes;
|
||||
case ZoomFactor::ThirtyMinutes:
|
||||
return ZoomFactor::SixtyMinutes;
|
||||
case ZoomFactor::SixtyMinutes:
|
||||
return ZoomFactor::TwoHours;
|
||||
case ZoomFactor::TwoHours:
|
||||
return ZoomFactor::FourHours;
|
||||
case ZoomFactor::FourHours:
|
||||
return ZoomFactor::EightHours;
|
||||
case ZoomFactor::EightHours:
|
||||
return ZoomFactor::TwelveHours;
|
||||
case ZoomFactor::TwelveHours:
|
||||
return ZoomFactor::OneDay;
|
||||
case ZoomFactor::OneDay:
|
||||
return ZoomFactor::OneDay;
|
||||
}
|
||||
return factor;
|
||||
}
|
||||
|
||||
Factor LTSTIMELINE_EXPORT decrement(Factor factor)
|
||||
{
|
||||
switch (factor)
|
||||
{
|
||||
case ZoomFactor::FifteenSeconds:
|
||||
return ZoomFactor::FifteenSeconds;
|
||||
case ZoomFactor::ThirtySeconds:
|
||||
return ZoomFactor::FifteenSeconds;
|
||||
case ZoomFactor::SixtySeconds:
|
||||
return ZoomFactor::ThirtySeconds;
|
||||
case ZoomFactor::TwoMinutes:
|
||||
return ZoomFactor::SixtySeconds;
|
||||
case ZoomFactor::ThreeMinutes:
|
||||
return ZoomFactor::TwoMinutes;
|
||||
case ZoomFactor::FiveMinutes:
|
||||
return ZoomFactor::ThreeMinutes;
|
||||
case ZoomFactor::TenMinutes:
|
||||
return ZoomFactor::FiveMinutes;
|
||||
case ZoomFactor::FifteenMinutes:
|
||||
return ZoomFactor::TenMinutes;
|
||||
case ZoomFactor::ThirtyMinutes:
|
||||
return ZoomFactor::FifteenMinutes;
|
||||
case ZoomFactor::SixtyMinutes:
|
||||
return ZoomFactor::ThirtyMinutes;
|
||||
case ZoomFactor::TwoHours:
|
||||
return ZoomFactor::SixtyMinutes;
|
||||
case ZoomFactor::FourHours:
|
||||
return ZoomFactor::TwoHours;
|
||||
case ZoomFactor::EightHours:
|
||||
return ZoomFactor::FourHours;
|
||||
case ZoomFactor::TwelveHours:
|
||||
return ZoomFactor::EightHours;
|
||||
case ZoomFactor::OneDay:
|
||||
return ZoomFactor::TwelveHours;
|
||||
}
|
||||
return factor;
|
||||
switch (factor)
|
||||
{
|
||||
case ZoomFactor::FifteenSeconds:
|
||||
return ZoomFactor::FifteenSeconds;
|
||||
case ZoomFactor::ThirtySeconds:
|
||||
return ZoomFactor::FifteenSeconds;
|
||||
case ZoomFactor::SixtySeconds:
|
||||
return ZoomFactor::ThirtySeconds;
|
||||
case ZoomFactor::TwoMinutes:
|
||||
return ZoomFactor::SixtySeconds;
|
||||
case ZoomFactor::ThreeMinutes:
|
||||
return ZoomFactor::TwoMinutes;
|
||||
case ZoomFactor::FiveMinutes:
|
||||
return ZoomFactor::ThreeMinutes;
|
||||
case ZoomFactor::TenMinutes:
|
||||
return ZoomFactor::FiveMinutes;
|
||||
case ZoomFactor::FifteenMinutes:
|
||||
return ZoomFactor::TenMinutes;
|
||||
case ZoomFactor::ThirtyMinutes:
|
||||
return ZoomFactor::FifteenMinutes;
|
||||
case ZoomFactor::SixtyMinutes:
|
||||
return ZoomFactor::ThirtyMinutes;
|
||||
case ZoomFactor::TwoHours:
|
||||
return ZoomFactor::SixtyMinutes;
|
||||
case ZoomFactor::FourHours:
|
||||
return ZoomFactor::TwoHours;
|
||||
case ZoomFactor::EightHours:
|
||||
return ZoomFactor::FourHours;
|
||||
case ZoomFactor::TwelveHours:
|
||||
return ZoomFactor::EightHours;
|
||||
case ZoomFactor::OneDay:
|
||||
return ZoomFactor::TwelveHours;
|
||||
}
|
||||
return factor;
|
||||
}
|
||||
|
||||
Factor ceil(int value)
|
||||
{
|
||||
if (value >= Factor::OneDay)
|
||||
return Factor::OneDay;
|
||||
if (value >= Factor::OneDay)
|
||||
return Factor::OneDay;
|
||||
|
||||
Factor ret = Factor::FifteenSeconds;
|
||||
while (static_cast<int>(ret) < value)
|
||||
{
|
||||
ret = increment(ret);
|
||||
}
|
||||
return ret;
|
||||
Factor ret = Factor::FifteenSeconds;
|
||||
while (static_cast<int>(ret) < value)
|
||||
{
|
||||
ret = increment(ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
Factor floor(int value)
|
||||
{
|
||||
if (value <= Factor::FifteenSeconds)
|
||||
return Factor::FifteenSeconds;
|
||||
if (value <= Factor::FifteenSeconds)
|
||||
return Factor::FifteenSeconds;
|
||||
|
||||
Factor ret = Factor::OneDay;
|
||||
while (static_cast<int>(ret) > value)
|
||||
{
|
||||
ret = decrement(ret);
|
||||
}
|
||||
return ret;
|
||||
Factor ret = Factor::OneDay;
|
||||
while (static_cast<int>(ret) > value)
|
||||
{
|
||||
ret = decrement(ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
QVector<Factor> availableZoomFactors(Factor min, Factor max)
|
||||
{
|
||||
if (min > max)
|
||||
return {};
|
||||
if (min > max)
|
||||
return {};
|
||||
|
||||
ZoomFactors ret;
|
||||
ret.reserve(numberOfZoomFactors());
|
||||
Factor factor = min;
|
||||
do
|
||||
{
|
||||
ret.append(factor);
|
||||
if (factor == max)
|
||||
break;
|
||||
factor = increment(factor);
|
||||
} while (increment(factor) > factor);
|
||||
return ret;
|
||||
ZoomFactors ret;
|
||||
ret.reserve(numberOfZoomFactors());
|
||||
Factor factor = min;
|
||||
do
|
||||
{
|
||||
ret.append(factor);
|
||||
if (factor == max)
|
||||
break;
|
||||
factor = increment(factor);
|
||||
} while (increment(factor) > factor);
|
||||
return ret;
|
||||
}
|
||||
|
||||
QString toString(ZoomFactor factor, bool useShort)
|
||||
{
|
||||
switch (factor)
|
||||
{
|
||||
case ZoomFactor::FifteenSeconds:
|
||||
return useShort ? QApplication::tr("15 sec") : QApplication::tr("15 Seconds");
|
||||
case ZoomFactor::ThirtySeconds:
|
||||
return useShort ? QApplication::tr("30 sec") : QApplication::tr("30 Seconds");
|
||||
case ZoomFactor::SixtySeconds:
|
||||
return useShort ? QApplication::tr("1 min") : QApplication::tr("1 Minute");
|
||||
case ZoomFactor::TwoMinutes:
|
||||
return useShort ? QApplication::tr("2 min") : QApplication::tr("2 Minutes");
|
||||
case ZoomFactor::ThreeMinutes:
|
||||
return useShort ? QApplication::tr("3 min") : QApplication::tr("3 Minutes");
|
||||
case ZoomFactor::FiveMinutes:
|
||||
return useShort ? QApplication::tr("5 min") : QApplication::tr("5 Minutes");
|
||||
case ZoomFactor::TenMinutes:
|
||||
return useShort ? QApplication::tr("10 min") : QApplication::tr("10 Minutes");
|
||||
case ZoomFactor::FifteenMinutes:
|
||||
return useShort ? QApplication::tr("15 min") : QApplication::tr("15 Minutes");
|
||||
case ZoomFactor::ThirtyMinutes:
|
||||
return useShort ? QApplication::tr("30 min") : QApplication::tr("30 Minutes");
|
||||
case ZoomFactor::SixtyMinutes:
|
||||
return useShort ? QApplication::tr("1 h") : QApplication::tr("1 Hour");
|
||||
case ZoomFactor::TwoHours:
|
||||
return useShort ? QApplication::tr("2 h") : QApplication::tr("2 Hours");
|
||||
case ZoomFactor::FourHours:
|
||||
return useShort ? QApplication::tr("4 h") : QApplication::tr("4 Hours");
|
||||
case ZoomFactor::EightHours:
|
||||
return useShort ? QApplication::tr("8 h") : QApplication::tr("8 Hours");
|
||||
case ZoomFactor::TwelveHours:
|
||||
return useShort ? QApplication::tr("12 h") : QApplication::tr("12 Hours");
|
||||
case ZoomFactor::OneDay:
|
||||
return useShort ? QApplication::tr("1 d") : QApplication::tr("1 Day");
|
||||
}
|
||||
return useShort ? QApplication::tr("N/A") : QApplication::tr("Unknown");
|
||||
switch (factor)
|
||||
{
|
||||
case ZoomFactor::FifteenSeconds:
|
||||
return useShort ? QApplication::tr("15 sec") : QApplication::tr("15 Seconds");
|
||||
case ZoomFactor::ThirtySeconds:
|
||||
return useShort ? QApplication::tr("30 sec") : QApplication::tr("30 Seconds");
|
||||
case ZoomFactor::SixtySeconds:
|
||||
return useShort ? QApplication::tr("1 min") : QApplication::tr("1 Minute");
|
||||
case ZoomFactor::TwoMinutes:
|
||||
return useShort ? QApplication::tr("2 min") : QApplication::tr("2 Minutes");
|
||||
case ZoomFactor::ThreeMinutes:
|
||||
return useShort ? QApplication::tr("3 min") : QApplication::tr("3 Minutes");
|
||||
case ZoomFactor::FiveMinutes:
|
||||
return useShort ? QApplication::tr("5 min") : QApplication::tr("5 Minutes");
|
||||
case ZoomFactor::TenMinutes:
|
||||
return useShort ? QApplication::tr("10 min") : QApplication::tr("10 Minutes");
|
||||
case ZoomFactor::FifteenMinutes:
|
||||
return useShort ? QApplication::tr("15 min") : QApplication::tr("15 Minutes");
|
||||
case ZoomFactor::ThirtyMinutes:
|
||||
return useShort ? QApplication::tr("30 min") : QApplication::tr("30 Minutes");
|
||||
case ZoomFactor::SixtyMinutes:
|
||||
return useShort ? QApplication::tr("1 h") : QApplication::tr("1 Hour");
|
||||
case ZoomFactor::TwoHours:
|
||||
return useShort ? QApplication::tr("2 h") : QApplication::tr("2 Hours");
|
||||
case ZoomFactor::FourHours:
|
||||
return useShort ? QApplication::tr("4 h") : QApplication::tr("4 Hours");
|
||||
case ZoomFactor::EightHours:
|
||||
return useShort ? QApplication::tr("8 h") : QApplication::tr("8 Hours");
|
||||
case ZoomFactor::TwelveHours:
|
||||
return useShort ? QApplication::tr("12 h") : QApplication::tr("12 Hours");
|
||||
case ZoomFactor::OneDay:
|
||||
return useShort ? QApplication::tr("1 d") : QApplication::tr("1 Day");
|
||||
}
|
||||
return useShort ? QApplication::tr("N/A") : QApplication::tr("Unknown");
|
||||
}
|
||||
|
||||
QString toShortString(Factor factor)
|
||||
{
|
||||
return toString(factor, true);
|
||||
return toString(factor, true);
|
||||
}
|
||||
|
||||
int majorInterval(ZoomFactor factor)
|
||||
{
|
||||
switch (factor)
|
||||
{
|
||||
case ZoomFactor::FifteenSeconds:
|
||||
return 3000;
|
||||
case ZoomFactor::ThirtySeconds:
|
||||
return 5000;
|
||||
case ZoomFactor::SixtySeconds:
|
||||
return 10000;
|
||||
case ZoomFactor::TwoMinutes:
|
||||
return 15000;
|
||||
case ZoomFactor::ThreeMinutes:
|
||||
return 30000;
|
||||
case ZoomFactor::FiveMinutes:
|
||||
return 60000;
|
||||
case ZoomFactor::TenMinutes:
|
||||
return 60000;
|
||||
case ZoomFactor::FifteenMinutes:
|
||||
return 180000;
|
||||
case ZoomFactor::ThirtyMinutes:
|
||||
return 300000;
|
||||
case ZoomFactor::SixtyMinutes:
|
||||
return 600000;
|
||||
case ZoomFactor::TwoHours:
|
||||
return 900000;
|
||||
case ZoomFactor::FourHours:
|
||||
return 1800000;
|
||||
case ZoomFactor::EightHours:
|
||||
return 3600000;
|
||||
case ZoomFactor::TwelveHours:
|
||||
return 5400000;
|
||||
case ZoomFactor::OneDay:
|
||||
return 7200000;
|
||||
}
|
||||
return -1;
|
||||
switch (factor)
|
||||
{
|
||||
case ZoomFactor::FifteenSeconds:
|
||||
return 3000;
|
||||
case ZoomFactor::ThirtySeconds:
|
||||
return 5000;
|
||||
case ZoomFactor::SixtySeconds:
|
||||
return 10000;
|
||||
case ZoomFactor::TwoMinutes:
|
||||
return 15000;
|
||||
case ZoomFactor::ThreeMinutes:
|
||||
return 30000;
|
||||
case ZoomFactor::FiveMinutes:
|
||||
return 60000;
|
||||
case ZoomFactor::TenMinutes:
|
||||
return 60000;
|
||||
case ZoomFactor::FifteenMinutes:
|
||||
return 180000;
|
||||
case ZoomFactor::ThirtyMinutes:
|
||||
return 300000;
|
||||
case ZoomFactor::SixtyMinutes:
|
||||
return 600000;
|
||||
case ZoomFactor::TwoHours:
|
||||
return 900000;
|
||||
case ZoomFactor::FourHours:
|
||||
return 1800000;
|
||||
case ZoomFactor::EightHours:
|
||||
return 3600000;
|
||||
case ZoomFactor::TwelveHours:
|
||||
return 5400000;
|
||||
case ZoomFactor::OneDay:
|
||||
return 7200000;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int mediumInterval(ZoomFactor factor)
|
||||
{
|
||||
switch (factor)
|
||||
{
|
||||
case ZoomFactor::FifteenSeconds:
|
||||
switch (factor)
|
||||
{
|
||||
case ZoomFactor::FifteenSeconds:
|
||||
return -1;
|
||||
case ZoomFactor::ThirtySeconds:
|
||||
return -1;
|
||||
case ZoomFactor::SixtySeconds:
|
||||
return 5000;
|
||||
case ZoomFactor::TwoMinutes:
|
||||
return 6000;
|
||||
case ZoomFactor::ThreeMinutes:
|
||||
return 10000;
|
||||
case ZoomFactor::FiveMinutes:
|
||||
return 15000;
|
||||
case ZoomFactor::TenMinutes:
|
||||
return 20000;
|
||||
case ZoomFactor::FifteenMinutes:
|
||||
return 60000;
|
||||
case ZoomFactor::ThirtyMinutes:
|
||||
return 100000;
|
||||
case ZoomFactor::SixtyMinutes:
|
||||
return 150000;
|
||||
case ZoomFactor::TwoHours:
|
||||
return 300000;
|
||||
case ZoomFactor::FourHours:
|
||||
return 600000;
|
||||
case ZoomFactor::EightHours:
|
||||
return 900000;
|
||||
case ZoomFactor::TwelveHours:
|
||||
return 1800000;
|
||||
case ZoomFactor::OneDay:
|
||||
return 2400000;
|
||||
}
|
||||
return -1;
|
||||
case ZoomFactor::ThirtySeconds:
|
||||
return -1;
|
||||
case ZoomFactor::SixtySeconds:
|
||||
return 5000;
|
||||
case ZoomFactor::TwoMinutes:
|
||||
return 6000;
|
||||
case ZoomFactor::ThreeMinutes:
|
||||
return 10000;
|
||||
case ZoomFactor::FiveMinutes:
|
||||
return 15000;
|
||||
case ZoomFactor::TenMinutes:
|
||||
return 20000;
|
||||
case ZoomFactor::FifteenMinutes:
|
||||
return 60000;
|
||||
case ZoomFactor::ThirtyMinutes:
|
||||
return 100000;
|
||||
case ZoomFactor::SixtyMinutes:
|
||||
return 150000;
|
||||
case ZoomFactor::TwoHours:
|
||||
return 300000;
|
||||
case ZoomFactor::FourHours:
|
||||
return 600000;
|
||||
case ZoomFactor::EightHours:
|
||||
return 900000;
|
||||
case ZoomFactor::TwelveHours:
|
||||
return 1800000;
|
||||
case ZoomFactor::OneDay:
|
||||
return 2400000;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int minorInterval(ZoomFactor factor)
|
||||
{
|
||||
switch (factor)
|
||||
{
|
||||
case ZoomFactor::FifteenSeconds:
|
||||
return 1000;
|
||||
case ZoomFactor::ThirtySeconds:
|
||||
return 1000;
|
||||
case ZoomFactor::SixtySeconds:
|
||||
return 1000;
|
||||
case ZoomFactor::TwoMinutes:
|
||||
return 3000;
|
||||
case ZoomFactor::ThreeMinutes:
|
||||
return 5000;
|
||||
case ZoomFactor::FiveMinutes:
|
||||
return 5000;
|
||||
case ZoomFactor::TenMinutes:
|
||||
return 10000;
|
||||
case ZoomFactor::FifteenMinutes:
|
||||
return 20000;
|
||||
case ZoomFactor::ThirtyMinutes:
|
||||
return 25000;
|
||||
case ZoomFactor::SixtyMinutes:
|
||||
return 50000;
|
||||
case ZoomFactor::TwoHours:
|
||||
return 60000;
|
||||
case ZoomFactor::FourHours:
|
||||
return 150000;
|
||||
case ZoomFactor::EightHours:
|
||||
return 300000;
|
||||
case ZoomFactor::TwelveHours:
|
||||
return 600000;
|
||||
case ZoomFactor::OneDay:
|
||||
return 800000;
|
||||
}
|
||||
return -1;
|
||||
switch (factor)
|
||||
{
|
||||
case ZoomFactor::FifteenSeconds:
|
||||
return 1000;
|
||||
case ZoomFactor::ThirtySeconds:
|
||||
return 1000;
|
||||
case ZoomFactor::SixtySeconds:
|
||||
return 1000;
|
||||
case ZoomFactor::TwoMinutes:
|
||||
return 3000;
|
||||
case ZoomFactor::ThreeMinutes:
|
||||
return 5000;
|
||||
case ZoomFactor::FiveMinutes:
|
||||
return 5000;
|
||||
case ZoomFactor::TenMinutes:
|
||||
return 10000;
|
||||
case ZoomFactor::FifteenMinutes:
|
||||
return 20000;
|
||||
case ZoomFactor::ThirtyMinutes:
|
||||
return 25000;
|
||||
case ZoomFactor::SixtyMinutes:
|
||||
return 50000;
|
||||
case ZoomFactor::TwoHours:
|
||||
return 60000;
|
||||
case ZoomFactor::FourHours:
|
||||
return 150000;
|
||||
case ZoomFactor::EightHours:
|
||||
return 300000;
|
||||
case ZoomFactor::TwelveHours:
|
||||
return 600000;
|
||||
case ZoomFactor::OneDay:
|
||||
return 800000;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Zoom
|
||||
|
||||
}
|
||||
} // namespace LtsTimeline
|
||||
Executable → Regular
+28
-25
@@ -4,26 +4,24 @@
|
||||
|
||||
#include <QString>
|
||||
|
||||
|
||||
namespace LtsTimeline
|
||||
{
|
||||
|
||||
struct LTSTIMELINE_EXPORT Tick
|
||||
{
|
||||
int pos{-1};
|
||||
qint64 time{0};
|
||||
QString label;
|
||||
Tick() {}
|
||||
explicit Tick(qint64 time) : time(time) {}
|
||||
explicit Tick(int pos, qint64 time, const QString &label) : pos(pos), time(time), label(label) {}
|
||||
int pos{-1};
|
||||
qint64 time{0};
|
||||
QString label;
|
||||
|
||||
Tick() {}
|
||||
|
||||
explicit Tick(qint64 time) : time(time) {}
|
||||
|
||||
explicit Tick(int pos, qint64 time, const QString& label) : pos(pos), time(time), label(label) {}
|
||||
};
|
||||
|
||||
typedef QVector<Tick> Ticks;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
namespace DateTime
|
||||
{
|
||||
|
||||
@@ -33,24 +31,29 @@ extern int numberOfDateTimeFormats();
|
||||
|
||||
extern LTSTIMELINE_EXPORT QString toString(qint64 time, Format format);
|
||||
|
||||
}
|
||||
} // namespace DateTime
|
||||
|
||||
typedef DateTime::Format DateTimeFormat;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
namespace Zoom
|
||||
{
|
||||
|
||||
enum Factor : int
|
||||
{
|
||||
FifteenSeconds = 15 * 1000, ThirtySeconds = 30 * 1000, SixtySeconds = 60 * 1000,
|
||||
TwoMinutes = 2 * 60 * 1000, ThreeMinutes = 3 * 60 * 1000, FiveMinutes = 5 * 60 * 1000,
|
||||
TenMinutes = 10 * 60 * 1000, FifteenMinutes = 15 * 60 * 1000, ThirtyMinutes = 30 * 60 * 1000, SixtyMinutes = 60 * 60 * 1000,
|
||||
TwoHours = 2 * 60 * 60 * 1000, FourHours = 4 * 60 * 60 * 1000, EightHours = 8 * 60 * 60 * 1000, TwelveHours = 12 * 60 * 60 * 1000,
|
||||
OneDay = 24 * 60 * 60 * 1000
|
||||
enum Factor : int {
|
||||
FifteenSeconds = 15 * 1000,
|
||||
ThirtySeconds = 30 * 1000,
|
||||
SixtySeconds = 60 * 1000,
|
||||
TwoMinutes = 2 * 60 * 1000,
|
||||
ThreeMinutes = 3 * 60 * 1000,
|
||||
FiveMinutes = 5 * 60 * 1000,
|
||||
TenMinutes = 10 * 60 * 1000,
|
||||
FifteenMinutes = 15 * 60 * 1000,
|
||||
ThirtyMinutes = 30 * 60 * 1000,
|
||||
SixtyMinutes = 60 * 60 * 1000,
|
||||
TwoHours = 2 * 60 * 60 * 1000,
|
||||
FourHours = 4 * 60 * 60 * 1000,
|
||||
EightHours = 8 * 60 * 60 * 1000,
|
||||
TwelveHours = 12 * 60 * 60 * 1000,
|
||||
OneDay = 24 * 60 * 60 * 1000
|
||||
};
|
||||
|
||||
extern LTSTIMELINE_EXPORT int numberOfZoomFactors();
|
||||
@@ -75,9 +78,9 @@ extern LTSTIMELINE_EXPORT int mediumInterval(Factor factor);
|
||||
|
||||
extern LTSTIMELINE_EXPORT int minorInterval(Factor factor);
|
||||
|
||||
}
|
||||
} // namespace Zoom
|
||||
|
||||
typedef Zoom::Factor ZoomFactor;
|
||||
typedef QVector<ZoomFactor> ZoomFactors;
|
||||
|
||||
}
|
||||
} // namespace LtsTimeline
|
||||
Executable → Regular
+443
-482
File diff suppressed because it is too large.
Load diff
Executable → Regular
+205
-118
@@ -1,27 +1,21 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "ltstimeline_export.h"
|
||||
#include "timeline_header_view.h"
|
||||
#include "timeline_model.h"
|
||||
#include "timeline_view_drag_handler.h"
|
||||
#include "timeline_view_resize_handler.h"
|
||||
#include "timeline_view_selection_handler.h"
|
||||
#include "timeline_view_track_handler.h"
|
||||
#include "timeline_header_view.h"
|
||||
#include "timeline_model.h"
|
||||
|
||||
#include "ltstimeline_export.h"
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <QLabel>
|
||||
#include <QObject>
|
||||
#include <QTreeView>
|
||||
|
||||
#include <functional>
|
||||
|
||||
class QAbstractProxyModel;
|
||||
|
||||
|
||||
namespace LtsTimeline
|
||||
{
|
||||
|
||||
@@ -31,144 +25,237 @@ class TimelineViewSelectHandler;
|
||||
class TimelineViewTrackHandler;
|
||||
class TimelineWidget;
|
||||
|
||||
|
||||
class LTSTIMELINE_EXPORT TimelineView : public QTreeView
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
friend class ItemDelegate;
|
||||
friend class TimelineHeaderView;
|
||||
friend class TimelineViewDragHandler;
|
||||
friend class TimelineViewResizeHandler;
|
||||
friend class TimelineViewSelectHandler;
|
||||
friend class TimelineViewTrackHandler;
|
||||
friend class TimelineWidget;
|
||||
friend class ItemDelegate;
|
||||
friend class TimelineHeaderView;
|
||||
friend class TimelineViewDragHandler;
|
||||
friend class TimelineViewResizeHandler;
|
||||
friend class TimelineViewSelectHandler;
|
||||
friend class TimelineViewTrackHandler;
|
||||
friend class TimelineWidget;
|
||||
|
||||
public:
|
||||
static const int s_textHeight;
|
||||
public:
|
||||
static const int s_textHeight;
|
||||
|
||||
|
||||
explicit TimelineView(QWidget* parent = nullptr);
|
||||
|
||||
explicit TimelineView(QWidget *parent = nullptr);
|
||||
TimelineHeaderView* header()
|
||||
{
|
||||
return m_header;
|
||||
}
|
||||
|
||||
TimelineHeaderView *header() { return m_header; }
|
||||
void setHeader(QHeaderView *header);
|
||||
void setHeader(QHeaderView* header);
|
||||
|
||||
QAbstractItemModel *model() { return m_model; }
|
||||
TimelineModel *timelineModel() { return m_timelineModel; }
|
||||
void setModel(QAbstractItemModel *model) override;
|
||||
QAbstractItemModel* model()
|
||||
{
|
||||
return m_model;
|
||||
}
|
||||
|
||||
QAbstractProxyModel *proxyModel() { return m_proxyModel; }
|
||||
void setProxyModel(QAbstractProxyModel *proxy) noexcept(false);
|
||||
TimelineModel* timelineModel()
|
||||
{
|
||||
return m_timelineModel;
|
||||
}
|
||||
|
||||
void setItemDelegate(QAbstractItemDelegate *delegate);
|
||||
ItemDelegate *itemDelegate() const { return m_delegate; }
|
||||
void setModel(QAbstractItemModel* model) override;
|
||||
|
||||
ZoomFactor zoomFactor() const { return m_zoomFactor; }
|
||||
|
||||
QAbstractProxyModel* proxyModel()
|
||||
{
|
||||
return m_proxyModel;
|
||||
}
|
||||
|
||||
void setZoomFactor(ZoomFactor zoomFactor);
|
||||
void setProxyModel(QAbstractProxyModel* proxy) noexcept(false);
|
||||
|
||||
ZoomFactor minimumZoomFactor() const { return m_minZoomFactor; }
|
||||
void setMinimumZoomFactor(ZoomFactor zoomFactor);
|
||||
void setItemDelegate(QAbstractItemDelegate* delegate);
|
||||
|
||||
ZoomFactor maximumZoomFactor() const { return m_maxZoomFactor; }
|
||||
void setMaximumZoomFactor(ZoomFactor zoomFactor);
|
||||
ItemDelegate* itemDelegate() const
|
||||
{
|
||||
return m_delegate;
|
||||
}
|
||||
|
||||
ZoomFactor upperZoomFactor() const { return m_upperZoomFactor; }
|
||||
ZoomFactor zoomFactor() const
|
||||
{
|
||||
return m_zoomFactor;
|
||||
}
|
||||
|
||||
qint64 startTime() const { return m_startTime; }
|
||||
void setStartTime(qint64 time);
|
||||
void setZoomFactor(ZoomFactor zoomFactor);
|
||||
|
||||
qint64 currentTime() const { return m_currentTime; }
|
||||
void setCurrentTime(qint64 time);
|
||||
ZoomFactor minimumZoomFactor() const
|
||||
{
|
||||
return m_minZoomFactor;
|
||||
}
|
||||
|
||||
qint64 endTime() const { return m_startTime + m_duration; }
|
||||
void setEndTime(qint64 time);
|
||||
void setMinimumZoomFactor(ZoomFactor zoomFactor);
|
||||
|
||||
int duration() const { return m_duration; }
|
||||
void setDuration(int duration);
|
||||
ZoomFactor maximumZoomFactor() const
|
||||
{
|
||||
return m_maxZoomFactor;
|
||||
}
|
||||
|
||||
void setRange(qint64 start, qint64 end);
|
||||
void setMaximumZoomFactor(ZoomFactor zoomFactor);
|
||||
|
||||
bool isCursorTextVisible() const { return m_isCursorTextVisible; }
|
||||
void setCursorTextVisible(bool visible);
|
||||
void setCursorText(const QString &text);
|
||||
ZoomFactor upperZoomFactor() const
|
||||
{
|
||||
return m_upperZoomFactor;
|
||||
}
|
||||
|
||||
int toPixel(qint64 time) const;
|
||||
qint64 toTime(int pixel) const;
|
||||
qint64 toDuration(int pixel) const;
|
||||
int fromDuration(qint64 time) const;
|
||||
qint64 startTime() const
|
||||
{
|
||||
return m_startTime;
|
||||
}
|
||||
|
||||
const QVector<int> &selectedItemIds() const { return m_selectedItemIds; }
|
||||
bool hasSelectedItems() const { return !m_selectedItemIds.isEmpty(); }
|
||||
void clearSelectedItems();
|
||||
void selectAllItems();
|
||||
void selectItem(int itemId, bool reset = true);
|
||||
void selectItems(const QVector<int> &itemIds, bool reset = true);
|
||||
void unselectItem(int itemId);
|
||||
void setStartTime(qint64 time);
|
||||
|
||||
TimelineViewDragHandler *dragHandler() { return m_dragHandler; }
|
||||
void setDragHandler(TimelineViewDragHandler *dragHandler) { m_dragHandler = dragHandler; }
|
||||
TimelineViewResizeHandler *resizeHandler() { return m_resizeHandler; }
|
||||
void setResizeHandler(TimelineViewResizeHandler *resizeHandler) { m_resizeHandler = resizeHandler; }
|
||||
TimelineViewSelectHandler *selectHandler() { return m_selectHandler; }
|
||||
void setSelectHandler(TimelineViewSelectHandler *selectHandler) { m_selectHandler = selectHandler; }
|
||||
TimelineViewTrackHandler *trackHandler() { return m_trackHandler; }
|
||||
void setTrackHandler(TimelineViewTrackHandler *trackHandler) { m_trackHandler = trackHandler; }
|
||||
qint64 currentTime() const
|
||||
{
|
||||
return m_currentTime;
|
||||
}
|
||||
|
||||
bool isCursorWithinRange(const QPoint &pos) const { return isCursorWithinRangeX(pos.x()) && isCursorWithinRangeY(pos.y()); }
|
||||
bool isCursorWithinRangeX(int x) const;
|
||||
bool isCursorWithinRangeY(int y) const;
|
||||
void setCurrentTime(qint64 time);
|
||||
|
||||
protected:
|
||||
NGL::INGLLogger &m_logger;
|
||||
void dragEnterEvent(QDragEnterEvent *event) override;
|
||||
void dragMoveEvent(QDragMoveEvent *event) override;
|
||||
void dragLeaveEvent(QDragLeaveEvent *event) override;
|
||||
void dropEvent(QDropEvent *event) override;
|
||||
void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
void mouseMoveEvent(QMouseEvent *event) override;
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
void keyPressEvent(QKeyEvent *event) override;
|
||||
void wheelEvent(QWheelEvent *event) override;
|
||||
virtual void paintEvent(QPaintEvent *event) override;
|
||||
qint64 endTime() const
|
||||
{
|
||||
return m_startTime + m_duration;
|
||||
}
|
||||
|
||||
signals:
|
||||
void rangeChanged(qint64, qint64);
|
||||
void currentTimeChanged(qint64);
|
||||
void zoomChanged(ZoomFactor);
|
||||
void trackActivated(int);
|
||||
void selectedItemsChanged(const QVector<int> &);
|
||||
void itemActivated(int);
|
||||
void currentItemTimeChanged();
|
||||
void setEndTime(qint64 time);
|
||||
|
||||
private:
|
||||
TimelineHeaderView *m_header{nullptr};
|
||||
TimelineModel *m_timelineModel{nullptr};
|
||||
QAbstractItemModel *m_model{nullptr};
|
||||
QAbstractProxyModel *m_proxyModel{nullptr};
|
||||
ItemDelegate *m_delegate{nullptr};
|
||||
TimelineViewDragHandler *m_dragHandler{nullptr};
|
||||
TimelineViewResizeHandler *m_resizeHandler{nullptr};
|
||||
TimelineViewSelectHandler *m_selectHandler{nullptr};
|
||||
TimelineViewTrackHandler *m_trackHandler{nullptr};
|
||||
int duration() const
|
||||
{
|
||||
return m_duration;
|
||||
}
|
||||
|
||||
ZoomFactor m_zoomFactor{ZoomFactor::ThirtyMinutes};
|
||||
ZoomFactor m_upperZoomFactor{ZoomFactor::OneDay};
|
||||
ZoomFactor m_minZoomFactor{ZoomFactor::FifteenSeconds};
|
||||
ZoomFactor m_maxZoomFactor{ZoomFactor::OneDay};
|
||||
void setDuration(int duration);
|
||||
|
||||
qint64 m_startTime{-1};
|
||||
qint64 m_currentTime{-1};
|
||||
int m_duration{-1};
|
||||
void setRange(qint64 start, qint64 end);
|
||||
|
||||
bool m_isCursorTextVisible{false};
|
||||
QString m_cursorText;
|
||||
QPoint m_cursorPosition;
|
||||
bool isCursorTextVisible() const
|
||||
{
|
||||
return m_isCursorTextVisible;
|
||||
}
|
||||
|
||||
QVector<int> m_selectedItemIds;
|
||||
void setCursorTextVisible(bool visible);
|
||||
void setCursorText(const QString& text);
|
||||
|
||||
int toPixel(qint64 time) const;
|
||||
qint64 toTime(int pixel) const;
|
||||
qint64 toDuration(int pixel) const;
|
||||
int fromDuration(qint64 time) const;
|
||||
|
||||
const QVector<int>& selectedItemIds() const
|
||||
{
|
||||
return m_selectedItemIds;
|
||||
}
|
||||
|
||||
bool hasSelectedItems() const
|
||||
{
|
||||
return !m_selectedItemIds.isEmpty();
|
||||
}
|
||||
|
||||
void clearSelectedItems();
|
||||
void selectAllItems();
|
||||
void selectItem(int itemId, bool reset = true);
|
||||
void selectItems(const QVector<int>& itemIds, bool reset = true);
|
||||
void unselectItem(int itemId);
|
||||
|
||||
TimelineViewDragHandler* dragHandler()
|
||||
{
|
||||
return m_dragHandler;
|
||||
}
|
||||
|
||||
void setDragHandler(TimelineViewDragHandler* dragHandler)
|
||||
{
|
||||
m_dragHandler = dragHandler;
|
||||
}
|
||||
|
||||
TimelineViewResizeHandler* resizeHandler()
|
||||
{
|
||||
return m_resizeHandler;
|
||||
}
|
||||
|
||||
void setResizeHandler(TimelineViewResizeHandler* resizeHandler)
|
||||
{
|
||||
m_resizeHandler = resizeHandler;
|
||||
}
|
||||
|
||||
TimelineViewSelectHandler* selectHandler()
|
||||
{
|
||||
return m_selectHandler;
|
||||
}
|
||||
|
||||
void setSelectHandler(TimelineViewSelectHandler* selectHandler)
|
||||
{
|
||||
m_selectHandler = selectHandler;
|
||||
}
|
||||
|
||||
TimelineViewTrackHandler* trackHandler()
|
||||
{
|
||||
return m_trackHandler;
|
||||
}
|
||||
|
||||
void setTrackHandler(TimelineViewTrackHandler* trackHandler)
|
||||
{
|
||||
m_trackHandler = trackHandler;
|
||||
}
|
||||
|
||||
bool isCursorWithinRange(const QPoint& pos) const
|
||||
{
|
||||
return isCursorWithinRangeX(pos.x()) && isCursorWithinRangeY(pos.y());
|
||||
}
|
||||
|
||||
bool isCursorWithinRangeX(int x) const;
|
||||
bool isCursorWithinRangeY(int y) const;
|
||||
|
||||
protected:
|
||||
NGL::INGLLogger& m_logger;
|
||||
void dragEnterEvent(QDragEnterEvent* event) override;
|
||||
void dragMoveEvent(QDragMoveEvent* event) override;
|
||||
void dragLeaveEvent(QDragLeaveEvent* event) override;
|
||||
void dropEvent(QDropEvent* event) override;
|
||||
void mouseDoubleClickEvent(QMouseEvent* event) override;
|
||||
void mouseMoveEvent(QMouseEvent* event) override;
|
||||
void mousePressEvent(QMouseEvent* event) override;
|
||||
void mouseReleaseEvent(QMouseEvent* event) override;
|
||||
void keyPressEvent(QKeyEvent* event) override;
|
||||
void wheelEvent(QWheelEvent* event) override;
|
||||
virtual void paintEvent(QPaintEvent* event) override;
|
||||
|
||||
signals:
|
||||
void rangeChanged(qint64, qint64);
|
||||
void currentTimeChanged(qint64);
|
||||
void zoomChanged(ZoomFactor);
|
||||
void trackActivated(int);
|
||||
void selectedItemsChanged(const QVector<int>&);
|
||||
void itemActivated(int);
|
||||
void currentItemTimeChanged();
|
||||
|
||||
private:
|
||||
TimelineHeaderView* m_header{nullptr};
|
||||
TimelineModel* m_timelineModel{nullptr};
|
||||
QAbstractItemModel* m_model{nullptr};
|
||||
QAbstractProxyModel* m_proxyModel{nullptr};
|
||||
ItemDelegate* m_delegate{nullptr};
|
||||
TimelineViewDragHandler* m_dragHandler{nullptr};
|
||||
TimelineViewResizeHandler* m_resizeHandler{nullptr};
|
||||
TimelineViewSelectHandler* m_selectHandler{nullptr};
|
||||
TimelineViewTrackHandler* m_trackHandler{nullptr};
|
||||
|
||||
ZoomFactor m_zoomFactor{ZoomFactor::ThirtyMinutes};
|
||||
ZoomFactor m_upperZoomFactor{ZoomFactor::OneDay};
|
||||
ZoomFactor m_minZoomFactor{ZoomFactor::FifteenSeconds};
|
||||
ZoomFactor m_maxZoomFactor{ZoomFactor::OneDay};
|
||||
|
||||
qint64 m_startTime{-1};
|
||||
qint64 m_currentTime{-1};
|
||||
int m_duration{-1};
|
||||
|
||||
bool m_isCursorTextVisible{false};
|
||||
QString m_cursorText;
|
||||
QPoint m_cursorPosition;
|
||||
|
||||
QVector<int> m_selectedItemIds;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsTimeline
|
||||
Executable → Regular
+429
-420
@@ -1,506 +1,515 @@
|
||||
#include "timeline_view_drag_handler.h"
|
||||
|
||||
#include "item.h"
|
||||
#include <utility>
|
||||
#include "track.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMouseEvent>
|
||||
#include <QDebug>
|
||||
#include <QDrag>
|
||||
#include <QMimeData>
|
||||
#include <QDebug>
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <utility>
|
||||
|
||||
namespace LtsTimeline
|
||||
{
|
||||
|
||||
TimelineViewDragHandler::TimelineViewDragHandler(TimelineView *view)
|
||||
: m_view(view)
|
||||
{}
|
||||
TimelineViewDragHandler::TimelineViewDragHandler(TimelineView* view) : m_view(view) {}
|
||||
|
||||
TimelineViewDragHandler::~TimelineViewDragHandler()
|
||||
{
|
||||
m_view = nullptr;
|
||||
m_view = nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void TimelineViewDragHandler::dragEnterEvent(QDragEnterEvent *e)
|
||||
void TimelineViewDragHandler::dragEnterEvent(QDragEnterEvent* e)
|
||||
{
|
||||
if (!m_view->timelineModel()->isEditable() || e->source() != m_view || m_dragItemIds.isEmpty() || !m_dragStartIndex.isValid())
|
||||
{
|
||||
e->ignore();
|
||||
return;
|
||||
}
|
||||
if (e->mimeData()->hasFormat(Item::mimetype))
|
||||
e->acceptProposedAction();
|
||||
else
|
||||
e->ignore();
|
||||
}
|
||||
|
||||
void TimelineViewDragHandler::dragMoveEvent(QDragMoveEvent *e)
|
||||
{
|
||||
if (!m_view->timelineModel()->isEditable() || e->source() != m_view || m_dragItemIds.isEmpty() || !m_dragStartIndex.isValid())
|
||||
{
|
||||
e->ignore();
|
||||
return;
|
||||
}
|
||||
if (!e->mimeData()->hasFormat(Item::mimetype))
|
||||
return;
|
||||
|
||||
m_dragPos = e->pos();
|
||||
m_view->m_header->setHoverPosition(m_dragPos.x());
|
||||
e->setAccepted(canDragItemsTo(e->pos()));
|
||||
m_view->viewport()->update();
|
||||
}
|
||||
|
||||
void TimelineViewDragHandler::dragLeaveEvent(QDragLeaveEvent *e)
|
||||
{
|
||||
Q_UNUSED(e);
|
||||
m_dragPos = {};
|
||||
}
|
||||
|
||||
void TimelineViewDragHandler::dropEvent(QDropEvent *e)
|
||||
{
|
||||
if (!m_view->timelineModel()->isEditable() || e->source() != m_view || m_dragItemIds.isEmpty())
|
||||
{
|
||||
e->ignore();
|
||||
return;
|
||||
}
|
||||
if (!e->mimeData()->hasFormat(Item::mimetype))
|
||||
return;
|
||||
|
||||
if (!canDragItemsTo(e->pos()))
|
||||
{
|
||||
clear();
|
||||
e->acceptProposedAction();
|
||||
return;
|
||||
}
|
||||
|
||||
qint64 dt = deltaTime();
|
||||
try
|
||||
{
|
||||
for (const int &itemId : std::as_const(m_dragItemIds))
|
||||
if (!m_view->timelineModel()->isEditable() || e->source() != m_view || m_dragItemIds.isEmpty() ||
|
||||
!m_dragStartIndex.isValid())
|
||||
{
|
||||
const Item &item = m_view->timelineModel()->item(itemId);
|
||||
m_view->timelineModel()->moveItemToTrack(itemId, dragItemTrackId(item), item.startTime() + dt);
|
||||
e->ignore();
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (const QString &str) { ERROR_LOG(m_view->m_logger) << LOGFUNCTION << " " << str; }
|
||||
catch (...) { ERROR_LOG(m_view->m_logger) << LOGFUNCTION << " failed"; }
|
||||
clear();
|
||||
e->acceptProposedAction();
|
||||
if (e->mimeData()->hasFormat(Item::mimetype))
|
||||
e->acceptProposedAction();
|
||||
else
|
||||
e->ignore();
|
||||
}
|
||||
|
||||
void TimelineViewDragHandler::mouseMoveEvent(QMouseEvent *e)
|
||||
void TimelineViewDragHandler::dragMoveEvent(QDragMoveEvent* e)
|
||||
{
|
||||
if (!m_view->timelineModel()->isEditable())
|
||||
return;
|
||||
|
||||
if (e->buttons() != Qt::LeftButton)
|
||||
{
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_dragItemIds.isEmpty() || !m_dragStartIndex.isValid())
|
||||
return;
|
||||
|
||||
if ((e->pos() - m_dragStartPos).manhattanLength() < QApplication::startDragDistance())
|
||||
return;
|
||||
|
||||
|
||||
const QModelIndex index = m_view->indexAt(e->pos());
|
||||
if (!index.isValid() || index.column() == Section::eActuator)
|
||||
{
|
||||
m_view->setCursor(QCursor(Qt::ForbiddenCursor));
|
||||
return;
|
||||
}
|
||||
|
||||
m_dragPos = e->pos();
|
||||
m_view->setCursor(QCursor(canDragItemsTo(m_dragPos) ? Qt::ClosedHandCursor : Qt::ForbiddenCursor));
|
||||
if (index.data().toInt() == m_dragStartIndex.data().toInt())
|
||||
return;
|
||||
|
||||
QMimeData *mimeData = new QMimeData();
|
||||
mimeData->setData(Item::mimetype, {});
|
||||
QDrag *drag = new QDrag(m_view);
|
||||
drag->setMimeData(mimeData);
|
||||
if (drag->exec(Qt::MoveAction) == Qt::MoveAction)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineViewDragHandler::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
if (!m_view->timelineModel()->isEditable())
|
||||
return;
|
||||
|
||||
if (e->button() != Qt::LeftButton)
|
||||
return;
|
||||
|
||||
|
||||
const QModelIndex index = m_view->indexAt(e->pos());
|
||||
if (!index.isValid() || index.column() == Section::eActuator)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
Track &track = m_view->timelineModel()->track(index.data().toInt());
|
||||
Item &item = track.itemAt(m_view->toTime(e->pos().x()));
|
||||
m_dragItemIds = m_view->m_selectedItemIds;
|
||||
if (!m_dragItemIds.contains(item.id()))
|
||||
m_dragItemIds = { item.id() };
|
||||
|
||||
for (const int &itemId : m_dragItemIds)
|
||||
if (!m_view->timelineModel()->item(itemId).isEditable())
|
||||
if (!m_view->timelineModel()->isEditable() || e->source() != m_view || m_dragItemIds.isEmpty() ||
|
||||
!m_dragStartIndex.isValid())
|
||||
{
|
||||
e->ignore();
|
||||
return;
|
||||
}
|
||||
if (!e->mimeData()->hasFormat(Item::mimetype))
|
||||
return;
|
||||
|
||||
m_dragStartIndex = index;
|
||||
m_dragStartTime = m_view->toTime(e->pos().x());
|
||||
m_dragStartPos = e->pos();
|
||||
m_dragPos = m_dragStartPos;
|
||||
m_view->setCursor(QCursor(Qt::ClosedHandCursor));
|
||||
}
|
||||
catch (const QString &str) { DEBUG_LOG(m_view->m_logger) << LOGFUNCTION << " " << str; }
|
||||
catch (...) {}
|
||||
m_dragPos = e->pos();
|
||||
m_view->m_header->setHoverPosition(m_dragPos.x());
|
||||
e->setAccepted(canDragItemsTo(e->pos()));
|
||||
m_view->viewport()->update();
|
||||
}
|
||||
|
||||
void TimelineViewDragHandler::mouseReleaseEvent(QMouseEvent *e)
|
||||
void TimelineViewDragHandler::dragLeaveEvent(QDragLeaveEvent* e)
|
||||
{
|
||||
if (!m_view->timelineModel()->isEditable())
|
||||
return;
|
||||
|
||||
if (e->button() != Qt::LeftButton)
|
||||
return;
|
||||
|
||||
if (m_dragItemIds.isEmpty() || !m_dragStartIndex.isValid())
|
||||
return;
|
||||
|
||||
|
||||
const QModelIndex index = m_view->indexAt(e->pos());
|
||||
if (!index.isValid() || index.column() == Section::eActuator)
|
||||
return;
|
||||
|
||||
if (index.data().toInt() != m_dragStartIndex.data().toInt())
|
||||
return;
|
||||
|
||||
m_dragPos = e->pos();
|
||||
if (m_dragPos.x() == m_dragStartPos.x())
|
||||
{
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
if (!canMoveItemsTo(m_dragPos))
|
||||
{
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
|
||||
emit m_view->currentItemTimeChanged();
|
||||
qint64 dt = deltaTime();
|
||||
for (const int &itemId : m_dragItemIds)
|
||||
{
|
||||
Item &item = m_view->timelineModel()->item(itemId);
|
||||
m_view->timelineModel()->setItemStartTime(item, item.startTime() + dt);
|
||||
}
|
||||
clear();
|
||||
Q_UNUSED(e);
|
||||
m_dragPos = {};
|
||||
}
|
||||
|
||||
void TimelineViewDragHandler::keyPressEvent(QKeyEvent *e)
|
||||
void TimelineViewDragHandler::dropEvent(QDropEvent* e)
|
||||
{
|
||||
if (!m_view->timelineModel()->isEditable())
|
||||
return;
|
||||
if (m_view->m_selectedItemIds.isEmpty())
|
||||
return;
|
||||
if (!m_view->timelineModel()->isEditable() || e->source() != m_view || m_dragItemIds.isEmpty())
|
||||
{
|
||||
e->ignore();
|
||||
return;
|
||||
}
|
||||
if (!e->mimeData()->hasFormat(Item::mimetype))
|
||||
return;
|
||||
|
||||
if (e->key() == Qt::Key_Escape)
|
||||
{
|
||||
if (!canDragItemsTo(e->pos()))
|
||||
{
|
||||
clear();
|
||||
e->acceptProposedAction();
|
||||
return;
|
||||
}
|
||||
|
||||
qint64 dt = deltaTime();
|
||||
try
|
||||
{
|
||||
for (const int& itemId : std::as_const(m_dragItemIds))
|
||||
{
|
||||
const Item& item = m_view->timelineModel()->item(itemId);
|
||||
m_view->timelineModel()->moveItemToTrack(itemId, dragItemTrackId(item), item.startTime() + dt);
|
||||
}
|
||||
}
|
||||
catch (const QString& str)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << LOGFUNCTION << " " << str;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << LOGFUNCTION << " failed";
|
||||
}
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (e->key() != Qt::Key_Left && e->key() != Qt::Key_Right)
|
||||
return;
|
||||
|
||||
int dt = m_view->timelineModel()->snapStep();
|
||||
if (e->key() == Qt::Key_Left)
|
||||
moveItemsLeft(m_view->selectedItemIds(), QApplication::keyboardModifiers().testFlag(Qt::ControlModifier) ? -dt : -10 * dt);
|
||||
else
|
||||
moveItemsRight(m_view->selectedItemIds(), QApplication::keyboardModifiers().testFlag(Qt::ControlModifier) ? dt : 10 * dt);
|
||||
e->acceptProposedAction();
|
||||
}
|
||||
|
||||
void TimelineViewDragHandler::mouseMoveEvent(QMouseEvent* e)
|
||||
{
|
||||
if (!m_view->timelineModel()->isEditable())
|
||||
return;
|
||||
|
||||
if (e->buttons() != Qt::LeftButton)
|
||||
{
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_dragItemIds.isEmpty() || !m_dragStartIndex.isValid())
|
||||
return;
|
||||
|
||||
if ((e->pos() - m_dragStartPos).manhattanLength() < QApplication::startDragDistance())
|
||||
return;
|
||||
|
||||
const QModelIndex index = m_view->indexAt(e->pos());
|
||||
if (!index.isValid() || index.column() == Section::eActuator)
|
||||
{
|
||||
m_view->setCursor(QCursor(Qt::ForbiddenCursor));
|
||||
return;
|
||||
}
|
||||
|
||||
m_dragPos = e->pos();
|
||||
m_view->setCursor(QCursor(canDragItemsTo(m_dragPos) ? Qt::ClosedHandCursor : Qt::ForbiddenCursor));
|
||||
if (index.data().toInt() == m_dragStartIndex.data().toInt())
|
||||
return;
|
||||
|
||||
QMimeData* mimeData = new QMimeData();
|
||||
mimeData->setData(Item::mimetype, {});
|
||||
QDrag* drag = new QDrag(m_view);
|
||||
drag->setMimeData(mimeData);
|
||||
if (drag->exec(Qt::MoveAction) == Qt::MoveAction)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineViewDragHandler::mousePressEvent(QMouseEvent* e)
|
||||
{
|
||||
if (!m_view->timelineModel()->isEditable())
|
||||
return;
|
||||
|
||||
if (e->button() != Qt::LeftButton)
|
||||
return;
|
||||
|
||||
const QModelIndex index = m_view->indexAt(e->pos());
|
||||
if (!index.isValid() || index.column() == Section::eActuator)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
Track& track = m_view->timelineModel()->track(index.data().toInt());
|
||||
Item& item = track.itemAt(m_view->toTime(e->pos().x()));
|
||||
m_dragItemIds = m_view->m_selectedItemIds;
|
||||
if (!m_dragItemIds.contains(item.id()))
|
||||
m_dragItemIds = {item.id()};
|
||||
|
||||
for (const int& itemId : m_dragItemIds)
|
||||
if (!m_view->timelineModel()->item(itemId).isEditable())
|
||||
return;
|
||||
|
||||
m_dragStartIndex = index;
|
||||
m_dragStartTime = m_view->toTime(e->pos().x());
|
||||
m_dragStartPos = e->pos();
|
||||
m_dragPos = m_dragStartPos;
|
||||
m_view->setCursor(QCursor(Qt::ClosedHandCursor));
|
||||
}
|
||||
catch (const QString& str)
|
||||
{
|
||||
DEBUG_LOG(m_view->m_logger) << LOGFUNCTION << " " << str;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineViewDragHandler::mouseReleaseEvent(QMouseEvent* e)
|
||||
{
|
||||
if (!m_view->timelineModel()->isEditable())
|
||||
return;
|
||||
|
||||
if (e->button() != Qt::LeftButton)
|
||||
return;
|
||||
|
||||
if (m_dragItemIds.isEmpty() || !m_dragStartIndex.isValid())
|
||||
return;
|
||||
|
||||
const QModelIndex index = m_view->indexAt(e->pos());
|
||||
if (!index.isValid() || index.column() == Section::eActuator)
|
||||
return;
|
||||
|
||||
if (index.data().toInt() != m_dragStartIndex.data().toInt())
|
||||
return;
|
||||
|
||||
m_dragPos = e->pos();
|
||||
if (m_dragPos.x() == m_dragStartPos.x())
|
||||
{
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
if (!canMoveItemsTo(m_dragPos))
|
||||
{
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
|
||||
emit m_view->currentItemTimeChanged();
|
||||
qint64 dt = deltaTime();
|
||||
for (const int& itemId : m_dragItemIds)
|
||||
{
|
||||
Item& item = m_view->timelineModel()->item(itemId);
|
||||
m_view->timelineModel()->setItemStartTime(item, item.startTime() + dt);
|
||||
}
|
||||
clear();
|
||||
}
|
||||
|
||||
void TimelineViewDragHandler::keyPressEvent(QKeyEvent* e)
|
||||
{
|
||||
if (!m_view->timelineModel()->isEditable())
|
||||
return;
|
||||
if (m_view->m_selectedItemIds.isEmpty())
|
||||
return;
|
||||
|
||||
if (e->key() == Qt::Key_Escape)
|
||||
{
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (e->key() != Qt::Key_Left && e->key() != Qt::Key_Right)
|
||||
return;
|
||||
|
||||
int dt = m_view->timelineModel()->snapStep();
|
||||
if (e->key() == Qt::Key_Left)
|
||||
moveItemsLeft(m_view->selectedItemIds(),
|
||||
QApplication::keyboardModifiers().testFlag(Qt::ControlModifier) ? -dt : -10 * dt);
|
||||
else
|
||||
moveItemsRight(m_view->selectedItemIds(),
|
||||
QApplication::keyboardModifiers().testFlag(Qt::ControlModifier) ? dt : 10 * dt);
|
||||
}
|
||||
|
||||
bool TimelineViewDragHandler::isActive() const
|
||||
{
|
||||
return !m_dragItemIds.isEmpty() && (m_dragPos - m_dragStartPos).manhattanLength() >= QApplication::startDragDistance();
|
||||
return !m_dragItemIds.isEmpty() &&
|
||||
(m_dragPos - m_dragStartPos).manhattanLength() >= QApplication::startDragDistance();
|
||||
}
|
||||
|
||||
|
||||
int TimelineViewDragHandler::deltaX() const
|
||||
{
|
||||
if (!m_view->timelineModel()->isSnapEnabled())
|
||||
return m_dragPos.x() - m_dragStartPos.x();
|
||||
return m_view->toPixel(m_dragStartTime + deltaTime()) - m_view->toPixel(m_dragStartTime);
|
||||
if (!m_view->timelineModel()->isSnapEnabled())
|
||||
return m_dragPos.x() - m_dragStartPos.x();
|
||||
return m_view->toPixel(m_dragStartTime + deltaTime()) - m_view->toPixel(m_dragStartTime);
|
||||
}
|
||||
|
||||
int TimelineViewDragHandler::deltaY() const
|
||||
{
|
||||
|
||||
const QModelIndex dragIndex = m_view->indexAt(m_dragPos);
|
||||
if (!dragIndex.isValid())
|
||||
return m_dragPos.y() - m_dragStartPos.y();
|
||||
return m_view->visualRect(dragIndex).top() - m_view->visualRect(m_dragStartIndex).top();
|
||||
const QModelIndex dragIndex = m_view->indexAt(m_dragPos);
|
||||
if (!dragIndex.isValid())
|
||||
return m_dragPos.y() - m_dragStartPos.y();
|
||||
return m_view->visualRect(dragIndex).top() - m_view->visualRect(m_dragStartIndex).top();
|
||||
}
|
||||
|
||||
qint64 TimelineViewDragHandler::deltaTime() const
|
||||
{
|
||||
if (!m_view->timelineModel()->isSnapEnabled())
|
||||
return m_view->toTime(m_dragPos.x()) - m_view->toTime(m_dragStartPos.x());
|
||||
if (!m_view->timelineModel()->isSnapEnabled())
|
||||
return m_view->toTime(m_dragPos.x()) - m_view->toTime(m_dragStartPos.x());
|
||||
|
||||
qint64 dt = ((m_view->toTime(m_dragPos.x()) - m_dragStartTime) / m_view->timelineModel()->snapStep()) * m_view->timelineModel()->snapStep();
|
||||
int dtAbsMin = 2 * m_view->timelineModel()->snapTolerance();
|
||||
int eps = m_view->timelineModel()->snapTolerance();
|
||||
for (const int &dragItemId : m_dragItemIds)
|
||||
{
|
||||
const Item &dragItem = m_view->timelineModel()->item(dragItemId);
|
||||
qint64 start = dragItem.startTime() + dt;
|
||||
qint64 end = start + dragItem.duration();
|
||||
for (int itemId : m_view->timelineModel()->itemIds())
|
||||
qint64 dt = ((m_view->toTime(m_dragPos.x()) - m_dragStartTime) / m_view->timelineModel()->snapStep()) *
|
||||
m_view->timelineModel()->snapStep();
|
||||
int dtAbsMin = 2 * m_view->timelineModel()->snapTolerance();
|
||||
int eps = m_view->timelineModel()->snapTolerance();
|
||||
for (const int& dragItemId : m_dragItemIds)
|
||||
{
|
||||
if (m_dragItemIds.contains(itemId))
|
||||
continue;
|
||||
const Item& dragItem = m_view->timelineModel()->item(dragItemId);
|
||||
qint64 start = dragItem.startTime() + dt;
|
||||
qint64 end = start + dragItem.duration();
|
||||
for (int itemId : m_view->timelineModel()->itemIds())
|
||||
{
|
||||
if (m_dragItemIds.contains(itemId))
|
||||
continue;
|
||||
|
||||
const Item &item = m_view->timelineModel()->item(itemId);
|
||||
if (start - eps < item.startTime() + item.duration() && item.startTime() + item.duration() < start + eps)
|
||||
{
|
||||
qint64 dtCurrent = item.startTime() + item.duration() - dragItem.startTime();
|
||||
qint64 dtAbsCurrent = std::abs(dtCurrent);
|
||||
if (dtAbsCurrent < dtAbsMin)
|
||||
{
|
||||
dtAbsMin = dtAbsCurrent;
|
||||
dt = dtCurrent;
|
||||
const Item& item = m_view->timelineModel()->item(itemId);
|
||||
if (start - eps < item.startTime() + item.duration() && item.startTime() + item.duration() < start + eps)
|
||||
{
|
||||
qint64 dtCurrent = item.startTime() + item.duration() - dragItem.startTime();
|
||||
qint64 dtAbsCurrent = std::abs(dtCurrent);
|
||||
if (dtAbsCurrent < dtAbsMin)
|
||||
{
|
||||
dtAbsMin = dtAbsCurrent;
|
||||
dt = dtCurrent;
|
||||
}
|
||||
}
|
||||
else if (end - eps < item.startTime() && item.startTime() < end + eps)
|
||||
{
|
||||
qint64 dtCurrent = item.startTime() - (dragItem.startTime() + dragItem.duration());
|
||||
qint64 dtAbsCurrent = std::abs(dtCurrent);
|
||||
if (dtAbsCurrent < dtAbsMin)
|
||||
{
|
||||
dtAbsMin = dtAbsCurrent;
|
||||
dt = dtCurrent;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (end - eps < item.startTime() && item.startTime() < end + eps)
|
||||
{
|
||||
qint64 dtCurrent = item.startTime() - (dragItem.startTime() + dragItem.duration());
|
||||
qint64 dtAbsCurrent = std::abs(dtCurrent);
|
||||
if (dtAbsCurrent < dtAbsMin)
|
||||
{
|
||||
dtAbsMin = dtAbsCurrent;
|
||||
dt = dtCurrent;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return dt;
|
||||
return dt;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool TimelineViewDragHandler::canDragItemsTo(const QPoint &point) const
|
||||
bool TimelineViewDragHandler::canDragItemsTo(const QPoint& point) const
|
||||
{
|
||||
if (!m_view->timelineModel()->isEditable())
|
||||
return false;
|
||||
if (!m_view->timelineModel()->isEditable())
|
||||
return false;
|
||||
|
||||
if (m_dragItemIds.isEmpty() || !m_dragStartIndex.isValid())
|
||||
return false;
|
||||
if (m_dragItemIds.isEmpty() || !m_dragStartIndex.isValid())
|
||||
return false;
|
||||
|
||||
const QModelIndex index = m_view->indexAt(point);
|
||||
if (!index.isValid() || index.column() == Section::eActuator)
|
||||
return false;
|
||||
|
||||
const QModelIndex index = m_view->indexAt(point);
|
||||
if (!index.isValid() || index.column() == Section::eActuator)
|
||||
return false;
|
||||
if (index.data().toInt() == m_dragStartIndex.data().toInt())
|
||||
return canMoveItemsTo(point);
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
qint64 dt = deltaTime();
|
||||
for (const int& itemId : m_dragItemIds)
|
||||
{
|
||||
const Item& item = m_view->timelineModel()->item(itemId);
|
||||
int trackId = dragItemTrackId(item);
|
||||
if (trackId == 0)
|
||||
return false;
|
||||
|
||||
if (index.data().toInt() == m_dragStartIndex.data().toInt())
|
||||
return canMoveItemsTo(point);
|
||||
else
|
||||
{
|
||||
const Track& track = m_view->timelineModel()->track(trackId);
|
||||
qint64 startNew = item.startTime() + dt;
|
||||
if (!m_view->timelineModel()->canDropItem(item, track.id(), startNew))
|
||||
return false;
|
||||
|
||||
if (track.isItemsBetween(startNew, startNew + item.duration(), m_dragItemIds, true))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TimelineViewDragHandler::canMoveItemsTo(const QPoint& point) const
|
||||
{
|
||||
if (!m_view->timelineModel()->isEditable())
|
||||
return false;
|
||||
if (m_dragItemIds.isEmpty() || !m_dragStartIndex.isValid())
|
||||
return false;
|
||||
|
||||
const QModelIndex index = m_view->indexAt(point);
|
||||
if (!index.isValid() || index.column() == Section::eActuator ||
|
||||
index.data().toInt() != m_dragStartIndex.data().toInt())
|
||||
return false;
|
||||
|
||||
qint64 dt = deltaTime();
|
||||
for (const int& itemId : m_dragItemIds)
|
||||
{
|
||||
const Item& item = m_view->timelineModel()->item(itemId);
|
||||
qint64 startNew = item.startTime() + dt;
|
||||
if (!m_view->timelineModel()->canMoveItem(item, startNew))
|
||||
return false;
|
||||
|
||||
const Track& track = m_view->timelineModel()->track(item.parentTrackId());
|
||||
if (track.isItemsBetween(startNew, startNew + item.duration(), m_dragItemIds, true))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void TimelineViewDragHandler::moveItemsLeft(const QVector<int>& itemIds, int dt)
|
||||
{
|
||||
Q_ASSERT(dt < 0);
|
||||
try
|
||||
{
|
||||
qint64 dt = deltaTime();
|
||||
for (const int &itemId : m_dragItemIds)
|
||||
{
|
||||
const Item &item = m_view->timelineModel()->item(itemId);
|
||||
int trackId = dragItemTrackId(item);
|
||||
if (trackId == 0)
|
||||
return false;
|
||||
for (int itemId : itemIds)
|
||||
{
|
||||
const Item& item = m_view->timelineModel()->item(itemId);
|
||||
const Track& track = m_view->timelineModel()->track(item.parentTrackId());
|
||||
if (track.isItemsBetween(item.startTime() + dt, item.startTime() + item.duration() + dt, itemIds, true))
|
||||
{
|
||||
if (dt < -m_view->timelineModel()->snapStep())
|
||||
moveItemsLeft(itemIds, dt + m_view->timelineModel()->snapStep());
|
||||
return;
|
||||
}
|
||||
if (!m_view->timelineModel()->canMoveItem(item, item.startTime() + dt))
|
||||
{
|
||||
if (dt < -m_view->timelineModel()->snapStep())
|
||||
moveItemsLeft(itemIds, dt + m_view->timelineModel()->snapStep());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const QString& errMsg)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << LOGFUNCTION << " failed: " << errMsg;
|
||||
return;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << LOGFUNCTION << " failed";
|
||||
return;
|
||||
}
|
||||
|
||||
const Track &track = m_view->timelineModel()->track(trackId);
|
||||
qint64 startNew = item.startTime() + dt;
|
||||
if (!m_view->timelineModel()->canDropItem(item, track.id(), startNew))
|
||||
return false;
|
||||
|
||||
if (track.isItemsBetween(startNew, startNew + item.duration(), m_dragItemIds, true))
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
for (int itemId : itemIds)
|
||||
{
|
||||
Item& item = m_view->timelineModel()->item(itemId);
|
||||
m_view->timelineModel()->setItemStartTime(item, item.startTime() + dt);
|
||||
}
|
||||
}
|
||||
catch (const QString& str)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << LOGFUNCTION << " " << str;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TimelineViewDragHandler::canMoveItemsTo(const QPoint &point) const
|
||||
void TimelineViewDragHandler::moveItemsRight(const QVector<int>& itemIds, int dt)
|
||||
{
|
||||
if (!m_view->timelineModel()->isEditable())
|
||||
return false;
|
||||
if (m_dragItemIds.isEmpty() || !m_dragStartIndex.isValid())
|
||||
return false;
|
||||
Q_ASSERT(dt > 0);
|
||||
try
|
||||
{
|
||||
for (int itemId : itemIds)
|
||||
{
|
||||
const Item& item = m_view->timelineModel()->item(itemId);
|
||||
const Track& track = m_view->timelineModel()->track(item.parentTrackId());
|
||||
if (track.isItemsBetween(item.startTime() + dt, item.startTime() + item.duration() + dt, itemIds, true))
|
||||
{
|
||||
if (dt > m_view->timelineModel()->snapStep())
|
||||
moveItemsRight(itemIds, dt - m_view->timelineModel()->snapStep());
|
||||
return;
|
||||
}
|
||||
if (!m_view->timelineModel()->canMoveItem(item, item.startTime() + dt))
|
||||
{
|
||||
if (dt > m_view->timelineModel()->snapStep())
|
||||
moveItemsRight(itemIds, dt - m_view->timelineModel()->snapStep());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const QString& errMsg)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << LOGFUNCTION << " failed: " << errMsg;
|
||||
return;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << LOGFUNCTION << " failed";
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const QModelIndex index = m_view->indexAt(point);
|
||||
if (!index.isValid() || index.column() == Section::eActuator || index.data().toInt() != m_dragStartIndex.data().toInt())
|
||||
return false;
|
||||
|
||||
qint64 dt = deltaTime();
|
||||
for (const int &itemId : m_dragItemIds)
|
||||
{
|
||||
const Item &item = m_view->timelineModel()->item(itemId);
|
||||
qint64 startNew = item.startTime() + dt;
|
||||
if (!m_view->timelineModel()->canMoveItem(item, startNew))
|
||||
return false;
|
||||
|
||||
const Track &track = m_view->timelineModel()->track(item.parentTrackId());
|
||||
if (track.isItemsBetween(startNew, startNew + item.duration(), m_dragItemIds, true))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
try
|
||||
{
|
||||
for (int itemId : itemIds)
|
||||
{
|
||||
Item& item = m_view->timelineModel()->item(itemId);
|
||||
m_view->timelineModel()->setItemStartTime(item, item.startTime() + dt);
|
||||
}
|
||||
}
|
||||
catch (const QString& errMsg)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << LOGFUNCTION << " " << errMsg;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TimelineViewDragHandler::moveItemsLeft(const QVector<int> &itemIds, int dt)
|
||||
int TimelineViewDragHandler::dragItemTrackId(const Item& item) const
|
||||
{
|
||||
Q_ASSERT(dt < 0);
|
||||
try
|
||||
{
|
||||
for (int itemId : itemIds)
|
||||
int dy = deltaY();
|
||||
|
||||
const QModelIndex index = m_view->indexAt(m_dragStartPos + QPoint(0, dy));
|
||||
if (index.data().toInt() == m_dragStartIndex.data().toInt())
|
||||
return item.parentTrackId();
|
||||
|
||||
try
|
||||
{
|
||||
const Item &item = m_view->timelineModel()->item(itemId);
|
||||
const Track &track = m_view->timelineModel()->track(item.parentTrackId());
|
||||
if (track.isItemsBetween(item.startTime() + dt, item.startTime() + item.duration() + dt, itemIds, true))
|
||||
{
|
||||
if (dt < - m_view->timelineModel()->snapStep())
|
||||
moveItemsLeft(itemIds, dt + m_view->timelineModel()->snapStep());
|
||||
return;
|
||||
}
|
||||
if (!m_view->timelineModel()->canMoveItem(item, item.startTime() + dt))
|
||||
{
|
||||
if (dt < - m_view->timelineModel()->snapStep())
|
||||
moveItemsLeft(itemIds, dt + m_view->timelineModel()->snapStep());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const QString &errMsg)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << LOGFUNCTION << " failed: " << errMsg;
|
||||
return;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << LOGFUNCTION << " failed";
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
for (int itemId : itemIds)
|
||||
const QModelIndex originalIndex = m_view->timelineModel()->indexOfTrack(item.parentTrackId());
|
||||
|
||||
const QModelIndex newIndex = m_view->indexAt(m_view->visualRect(originalIndex).center() + QPoint(0, dy));
|
||||
return newIndex.data().toInt();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
Item &item = m_view->timelineModel()->item(itemId);
|
||||
m_view->timelineModel()->setItemStartTime(item, item.startTime() + dt);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
catch (const QString &str) { ERROR_LOG(m_view->m_logger) << LOGFUNCTION << " " << str; }
|
||||
catch (...) {}
|
||||
}
|
||||
|
||||
void TimelineViewDragHandler::moveItemsRight(const QVector<int> &itemIds, int dt)
|
||||
{
|
||||
Q_ASSERT(dt > 0);
|
||||
try
|
||||
{
|
||||
for (int itemId : itemIds)
|
||||
{
|
||||
const Item &item = m_view->timelineModel()->item(itemId);
|
||||
const Track &track = m_view->timelineModel()->track(item.parentTrackId());
|
||||
if (track.isItemsBetween(item.startTime() + dt, item.startTime() + item.duration() + dt, itemIds, true))
|
||||
{
|
||||
if (dt > m_view->timelineModel()->snapStep())
|
||||
moveItemsRight(itemIds, dt - m_view->timelineModel()->snapStep());
|
||||
return;
|
||||
}
|
||||
if (!m_view->timelineModel()->canMoveItem(item, item.startTime() + dt))
|
||||
{
|
||||
if (dt > m_view->timelineModel()->snapStep())
|
||||
moveItemsRight(itemIds, dt - m_view->timelineModel()->snapStep());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const QString &errMsg)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << LOGFUNCTION << " failed: " << errMsg;
|
||||
return;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << LOGFUNCTION << " failed";
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
for (int itemId : itemIds)
|
||||
{
|
||||
Item &item = m_view->timelineModel()->item(itemId);
|
||||
m_view->timelineModel()->setItemStartTime(item, item.startTime() + dt);
|
||||
}
|
||||
}
|
||||
catch (const QString &errMsg) { ERROR_LOG(m_view->m_logger) << LOGFUNCTION << " " << errMsg; }
|
||||
catch (...) {}
|
||||
}
|
||||
|
||||
|
||||
int TimelineViewDragHandler::dragItemTrackId(const Item &item) const
|
||||
{
|
||||
int dy = deltaY();
|
||||
|
||||
const QModelIndex index = m_view->indexAt(m_dragStartPos + QPoint(0, dy));
|
||||
if (index.data().toInt() == m_dragStartIndex.data().toInt())
|
||||
return item.parentTrackId();
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
const QModelIndex originalIndex = m_view->timelineModel()->indexOfTrack(item.parentTrackId());
|
||||
|
||||
const QModelIndex newIndex = m_view->indexAt(m_view->visualRect(originalIndex).center() + QPoint(0, dy));
|
||||
return newIndex.data().toInt();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineViewDragHandler::clear()
|
||||
{
|
||||
m_dragStartIndex = {};
|
||||
m_dragStartTime = -1;
|
||||
m_dragStartPos = {};
|
||||
m_dragPos = {};
|
||||
m_dragItemIds.clear();
|
||||
m_view->setCursor(QCursor(Qt::ArrowCursor));
|
||||
m_view->viewport()->update();
|
||||
m_dragStartIndex = {};
|
||||
m_dragStartTime = -1;
|
||||
m_dragStartPos = {};
|
||||
m_dragPos = {};
|
||||
m_dragItemIds.clear();
|
||||
m_view->setCursor(QCursor(Qt::ArrowCursor));
|
||||
m_view->viewport()->update();
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsTimeline
|
||||
Executable → Regular
+58
-45
@@ -1,13 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "ltstimeline_export.h"
|
||||
#include "timeline_view.h"
|
||||
|
||||
#include "ltstimeline_export.h"
|
||||
|
||||
#include <QModelIndex>
|
||||
#include <QPoint>
|
||||
#include <QVector>
|
||||
#include <QModelIndex>
|
||||
|
||||
|
||||
class QDragEnterEvent;
|
||||
class QDragMoveEvent;
|
||||
@@ -16,7 +14,6 @@ class QDropEvent;
|
||||
class QMouseEvent;
|
||||
class QKeyEvent;
|
||||
|
||||
|
||||
namespace LtsTimeline
|
||||
{
|
||||
|
||||
@@ -25,58 +22,74 @@ class Track;
|
||||
class TimelineView;
|
||||
class ItemDelegate;
|
||||
|
||||
|
||||
class LTSTIMELINE_EXPORT TimelineViewDragHandler
|
||||
{
|
||||
friend class TimelineView;
|
||||
friend class ItemDelegate;
|
||||
friend class TimelineView;
|
||||
friend class ItemDelegate;
|
||||
|
||||
public:
|
||||
explicit TimelineViewDragHandler(TimelineView *view);
|
||||
virtual ~TimelineViewDragHandler();
|
||||
public:
|
||||
explicit TimelineViewDragHandler(TimelineView* view);
|
||||
virtual ~TimelineViewDragHandler();
|
||||
|
||||
virtual void dragEnterEvent(QDragEnterEvent *e);
|
||||
virtual void dragMoveEvent(QDragMoveEvent *e);
|
||||
virtual void dragLeaveEvent(QDragLeaveEvent *e);
|
||||
virtual void dropEvent(QDropEvent *e);
|
||||
virtual void mouseMoveEvent(QMouseEvent *e);
|
||||
virtual void mousePressEvent(QMouseEvent *e);
|
||||
virtual void mouseReleaseEvent(QMouseEvent *e);
|
||||
virtual void keyPressEvent(QKeyEvent *e);
|
||||
virtual void dragEnterEvent(QDragEnterEvent* e);
|
||||
virtual void dragMoveEvent(QDragMoveEvent* e);
|
||||
virtual void dragLeaveEvent(QDragLeaveEvent* e);
|
||||
virtual void dropEvent(QDropEvent* e);
|
||||
virtual void mouseMoveEvent(QMouseEvent* e);
|
||||
virtual void mousePressEvent(QMouseEvent* e);
|
||||
virtual void mouseReleaseEvent(QMouseEvent* e);
|
||||
virtual void keyPressEvent(QKeyEvent* e);
|
||||
|
||||
virtual bool isActive() const;
|
||||
virtual bool isActive() const;
|
||||
|
||||
virtual int deltaX() const;
|
||||
virtual int deltaY() const;
|
||||
virtual qint64 deltaTime() const;
|
||||
virtual int deltaX() const;
|
||||
virtual int deltaY() const;
|
||||
virtual qint64 deltaTime() const;
|
||||
|
||||
|
||||
const QVector<int> &dragItemIds() const { return m_dragItemIds; }
|
||||
const QModelIndex &dragStartIndex() const { return m_dragStartIndex; }
|
||||
qint64 dragStartTime() const { return m_dragStartTime; }
|
||||
const QPoint &dragStartPos() const { return m_dragStartPos; }
|
||||
const QPoint &dragPos() const { return m_dragPos; }
|
||||
const QVector<int>& dragItemIds() const
|
||||
{
|
||||
return m_dragItemIds;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual bool canDragItemsTo(const QPoint &point) const;
|
||||
virtual bool canMoveItemsTo(const QPoint &point) const;
|
||||
const QModelIndex& dragStartIndex() const
|
||||
{
|
||||
return m_dragStartIndex;
|
||||
}
|
||||
|
||||
virtual void moveItemsLeft(const QVector<int> &itemIds, int dt);
|
||||
virtual void moveItemsRight(const QVector<int> &itemIds, int dt);
|
||||
qint64 dragStartTime() const
|
||||
{
|
||||
return m_dragStartTime;
|
||||
}
|
||||
|
||||
int dragItemTrackId(const Item &item) const;
|
||||
void clear();
|
||||
const QPoint& dragStartPos() const
|
||||
{
|
||||
return m_dragStartPos;
|
||||
}
|
||||
|
||||
protected:
|
||||
TimelineView *m_view{nullptr};
|
||||
QVector<int> m_dragItemIds;
|
||||
QModelIndex m_dragStartIndex;
|
||||
qint64 m_dragStartTime{-1};
|
||||
QPoint m_dragStartPos;
|
||||
QPoint m_dragPos;
|
||||
const QPoint& dragPos() const
|
||||
{
|
||||
return m_dragPos;
|
||||
}
|
||||
|
||||
int m_snapLinePos{-1};
|
||||
protected:
|
||||
virtual bool canDragItemsTo(const QPoint& point) const;
|
||||
virtual bool canMoveItemsTo(const QPoint& point) const;
|
||||
|
||||
virtual void moveItemsLeft(const QVector<int>& itemIds, int dt);
|
||||
virtual void moveItemsRight(const QVector<int>& itemIds, int dt);
|
||||
|
||||
int dragItemTrackId(const Item& item) const;
|
||||
void clear();
|
||||
|
||||
protected:
|
||||
TimelineView* m_view{nullptr};
|
||||
QVector<int> m_dragItemIds;
|
||||
QModelIndex m_dragStartIndex;
|
||||
qint64 m_dragStartTime{-1};
|
||||
QPoint m_dragStartPos;
|
||||
QPoint m_dragPos;
|
||||
|
||||
int m_snapLinePos{-1};
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsTimeline
|
||||
Executable → Regular
+223
-215
@@ -1,279 +1,287 @@
|
||||
#include "timeline_view_resize_handler.h"
|
||||
#include "timeline_view.h"
|
||||
#include "timeline_header_view.h"
|
||||
|
||||
#include "item.h"
|
||||
#include "timeline_header_view.h"
|
||||
#include "timeline_view.h"
|
||||
#include "track.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMouseEvent>
|
||||
#include <QDebug>
|
||||
|
||||
#include <QMouseEvent>
|
||||
|
||||
namespace LtsTimeline
|
||||
{
|
||||
|
||||
TimelineViewResizeHandler::TimelineViewResizeHandler(TimelineView *view)
|
||||
: m_view(view)
|
||||
{}
|
||||
TimelineViewResizeHandler::TimelineViewResizeHandler(TimelineView* view) : m_view(view) {}
|
||||
|
||||
TimelineViewResizeHandler::~TimelineViewResizeHandler()
|
||||
{
|
||||
m_view = nullptr;
|
||||
m_view = nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void TimelineViewResizeHandler::mouseMoveEvent(QMouseEvent *e)
|
||||
void TimelineViewResizeHandler::mouseMoveEvent(QMouseEvent* e)
|
||||
{
|
||||
if (!m_view->timelineModel()->isEditable())
|
||||
return;
|
||||
if (m_currentTrackId == -1 || m_currentItemId == -1 || m_resizePos == ResizePosition::eNone)
|
||||
return;
|
||||
if (!m_view->timelineModel()->item(m_currentItemId).isEditable())
|
||||
return;
|
||||
if (!m_view->timelineModel()->isEditable())
|
||||
return;
|
||||
if (m_currentTrackId == -1 || m_currentItemId == -1 || m_resizePos == ResizePosition::eNone)
|
||||
return;
|
||||
if (!m_view->timelineModel()->item(m_currentItemId).isEditable())
|
||||
return;
|
||||
|
||||
const QModelIndex index(m_view->indexAt(e->pos()));
|
||||
if (index.column() == Section::eActuator || !index.isValid())
|
||||
return;
|
||||
|
||||
const QModelIndex index(m_view->indexAt(e->pos()));
|
||||
if (index.column() == Section::eActuator || !index.isValid())
|
||||
return;
|
||||
Track& track = m_view->timelineModel()->track(index.data().toInt());
|
||||
if (track.id() != m_currentTrackId)
|
||||
return;
|
||||
|
||||
Track &track = m_view->timelineModel()->track(index.data().toInt());
|
||||
if (track.id() != m_currentTrackId)
|
||||
return;
|
||||
|
||||
qint64 time = m_view->timelineModel()->isSnapEnabled() ? globalSnapTime(e->pos().x()) : localSnapTime(e->pos().x());
|
||||
try
|
||||
{
|
||||
Item &item = m_view->timelineModel()->item(m_currentItemId);
|
||||
if (m_resizePos == ResizePosition::eStart)
|
||||
qint64 time = m_view->timelineModel()->isSnapEnabled() ? globalSnapTime(e->pos().x()) : localSnapTime(e->pos().x());
|
||||
try
|
||||
{
|
||||
if (item.startTime() == time)
|
||||
return;
|
||||
Item& item = m_view->timelineModel()->item(m_currentItemId);
|
||||
if (m_resizePos == ResizePosition::eStart)
|
||||
{
|
||||
if (item.startTime() == time)
|
||||
return;
|
||||
|
||||
if (!m_view->timelineModel()->canResizeItem(item, time, item.startTime() + item.duration() - time))
|
||||
return;
|
||||
if (!m_view->timelineModel()->canResizeItem(item, time, item.startTime() + item.duration() - time))
|
||||
return;
|
||||
|
||||
m_view->timelineModel()->setItemDuration(track, item, item.startTime() + item.duration() - time);
|
||||
m_view->timelineModel()->setItemStartTime(track, item, time);
|
||||
m_view->timelineModel()->setItemDuration(track, item, item.startTime() + item.duration() - time);
|
||||
m_view->timelineModel()->setItemStartTime(track, item, time);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.duration() == time - item.startTime())
|
||||
return;
|
||||
|
||||
if (!m_view->timelineModel()->canResizeItem(item, item.startTime(), time - item.startTime()))
|
||||
return;
|
||||
|
||||
m_view->timelineModel()->setItemDuration(track, item, time - item.startTime());
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (...)
|
||||
{
|
||||
if (item.duration() == time - item.startTime())
|
||||
return;
|
||||
|
||||
if (!m_view->timelineModel()->canResizeItem(item, item.startTime(), time - item.startTime()))
|
||||
return;
|
||||
|
||||
m_view->timelineModel()->setItemDuration(track, item, time - item.startTime());
|
||||
mouseReleaseEvent(e);
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
mouseReleaseEvent(e);
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineViewResizeHandler::mousePressEvent(QMouseEvent *e)
|
||||
void TimelineViewResizeHandler::mousePressEvent(QMouseEvent* e)
|
||||
{
|
||||
if (!m_view->timelineModel()->isEditable())
|
||||
return;
|
||||
if (!m_view->timelineModel()->isEditable())
|
||||
return;
|
||||
|
||||
if (e->button() != Qt::LeftButton)
|
||||
return;
|
||||
if (e->button() != Qt::LeftButton)
|
||||
return;
|
||||
|
||||
const QModelIndex index(m_view->indexAt(e->pos()));
|
||||
if (!index.isValid() || index.column() == Section::eActuator)
|
||||
return;
|
||||
|
||||
const QModelIndex index(m_view->indexAt(e->pos()));
|
||||
if (!index.isValid() || index.column() == Section::eActuator)
|
||||
return;
|
||||
try
|
||||
{
|
||||
const Track& track = m_view->timelineModel()->track(index.data().toInt());
|
||||
const Item& item = track.itemAt(m_view->toTime(e->pos().x()));
|
||||
if (!item.isEditable())
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
const Track &track = m_view->timelineModel()->track(index.data().toInt());
|
||||
const Item &item = track.itemAt(m_view->toTime(e->pos().x()));
|
||||
if (!item.isEditable())
|
||||
return;
|
||||
const int startPos = m_view->toPixel(item.startTime());
|
||||
const int endPos = m_view->toPixel(item.startTime() + item.duration());
|
||||
if (endPos - startPos < 15 || (startPos + 5 < e->pos().x() && e->pos().x() < endPos - 5))
|
||||
{
|
||||
m_resizePos = ResizePosition::eNone;
|
||||
return;
|
||||
}
|
||||
else if (startPos + 5 >= e->pos().x())
|
||||
m_resizePos = ResizePosition::eStart;
|
||||
else
|
||||
m_resizePos = ResizePosition::eEnd;
|
||||
|
||||
const int startPos = m_view->toPixel(item.startTime());
|
||||
const int endPos = m_view->toPixel(item.startTime() + item.duration());
|
||||
if (endPos - startPos < 15 || (startPos + 5 < e->pos().x() && e->pos().x() < endPos - 5))
|
||||
m_currentTrackId = track.id();
|
||||
m_currentItemId = item.id();
|
||||
}
|
||||
catch (const QString& str)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << str;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
m_resizePos = ResizePosition::eNone;
|
||||
return;
|
||||
}
|
||||
else if (startPos + 5 >= e->pos().x())
|
||||
m_resizePos = ResizePosition::eStart;
|
||||
else
|
||||
m_resizePos = ResizePosition::eEnd;
|
||||
|
||||
m_currentTrackId = track.id();
|
||||
m_currentItemId = item.id();
|
||||
}
|
||||
catch (const QString &str)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << str;
|
||||
}
|
||||
catch (...) {}
|
||||
}
|
||||
|
||||
void TimelineViewResizeHandler::mouseReleaseEvent(QMouseEvent *e)
|
||||
void TimelineViewResizeHandler::mouseReleaseEvent(QMouseEvent* e)
|
||||
{
|
||||
if (!m_view->timelineModel()->isEditable())
|
||||
return;
|
||||
if (!m_view->timelineModel()->isEditable())
|
||||
return;
|
||||
|
||||
if (e->button() != Qt::LeftButton)
|
||||
return;
|
||||
if (e->button() != Qt::LeftButton)
|
||||
return;
|
||||
|
||||
emit m_view->currentItemTimeChanged();
|
||||
m_view->setCursor(QCursor(Qt::ArrowCursor));
|
||||
m_currentTrackId = -1;
|
||||
m_currentItemId = -1;
|
||||
m_resizePos = ResizePosition::eNone;
|
||||
emit m_view->currentItemTimeChanged();
|
||||
m_view->setCursor(QCursor(Qt::ArrowCursor));
|
||||
m_currentTrackId = -1;
|
||||
m_currentItemId = -1;
|
||||
m_resizePos = ResizePosition::eNone;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
qint64 TimelineViewResizeHandler::localSnapTime(int pos) const
|
||||
{
|
||||
qint64 time = m_view->toTime(pos);
|
||||
if (m_currentItemId == -1 || m_resizePos == ResizePosition::eNone)
|
||||
return time;
|
||||
qint64 time = m_view->toTime(pos);
|
||||
if (m_currentItemId == -1 || m_resizePos == ResizePosition::eNone)
|
||||
return time;
|
||||
|
||||
try
|
||||
{
|
||||
Track &track = m_view->timelineModel()->track(m_currentTrackId);
|
||||
const Item ¤tItem = m_view->timelineModel()->item(m_currentItemId);
|
||||
if (m_resizePos == ResizePosition::eStart)
|
||||
try
|
||||
{
|
||||
if (time >= currentItem.startTime() + currentItem.duration())
|
||||
time = currentItem.startTime() + currentItem.duration() - m_view->timelineModel()->minimumDuration();
|
||||
else
|
||||
{
|
||||
try
|
||||
Track& track = m_view->timelineModel()->track(m_currentTrackId);
|
||||
const Item& currentItem = m_view->timelineModel()->item(m_currentItemId);
|
||||
if (m_resizePos == ResizePosition::eStart)
|
||||
{
|
||||
const Item &previous = track.previous(m_currentItemId);
|
||||
const qint64 endTime = previous.startTime() + previous.duration();
|
||||
if (time <= endTime)
|
||||
time = endTime;
|
||||
if (time >= currentItem.startTime() + currentItem.duration())
|
||||
time = currentItem.startTime() + currentItem.duration() - m_view->timelineModel()->minimumDuration();
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
const Item& previous = track.previous(m_currentItemId);
|
||||
const qint64 endTime = previous.startTime() + previous.duration();
|
||||
if (time <= endTime)
|
||||
time = endTime;
|
||||
}
|
||||
catch (const QString& str)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << str;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const QString &str)
|
||||
else
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << str;
|
||||
if (time <= currentItem.startTime())
|
||||
time = currentItem.startTime() + m_view->timelineModel()->minimumDuration();
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
Item& next = track.next(m_currentItemId);
|
||||
if (time >= next.startTime())
|
||||
time = next.startTime();
|
||||
}
|
||||
catch (const QString& str)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << str;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (...) {}
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (const QString& str)
|
||||
{
|
||||
if (time <= currentItem.startTime())
|
||||
time = currentItem.startTime() + m_view->timelineModel()->minimumDuration();
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
Item &next = track.next(m_currentItemId);
|
||||
if (time >= next.startTime())
|
||||
time = next.startTime();
|
||||
}
|
||||
catch (const QString &str)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << str;
|
||||
}
|
||||
catch (...) {}
|
||||
}
|
||||
ERROR_LOG(m_view->m_logger) << str;
|
||||
}
|
||||
}
|
||||
catch (const QString &str)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << str;
|
||||
}
|
||||
catch (...) {}
|
||||
return time;
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
return time;
|
||||
}
|
||||
|
||||
qint64 TimelineViewResizeHandler::globalSnapTime(int pos) const
|
||||
{
|
||||
qint64 tPos = (m_view->toTime(pos) / m_view->timelineModel()->snapStep()) * m_view->timelineModel()->snapStep();
|
||||
if (m_currentItemId == -1 || m_resizePos == ResizePosition::eNone)
|
||||
return tPos;
|
||||
qint64 tPos = (m_view->toTime(pos) / m_view->timelineModel()->snapStep()) * m_view->timelineModel()->snapStep();
|
||||
if (m_currentItemId == -1 || m_resizePos == ResizePosition::eNone)
|
||||
return tPos;
|
||||
|
||||
qint64 tMin = m_view->m_startTime;
|
||||
qint64 tMax = m_view->endTime();
|
||||
try
|
||||
{
|
||||
const Item &previous = m_view->timelineModel()->track(m_currentTrackId).previous(m_currentItemId);
|
||||
tMin = previous.startTime() + previous.duration();
|
||||
}
|
||||
catch (const QString &str)
|
||||
{
|
||||
DEBUG_LOG(m_view->m_logger) << str;
|
||||
}
|
||||
catch (...) {}
|
||||
try
|
||||
{
|
||||
const Item &next = m_view->timelineModel()->track(m_currentTrackId).next(m_currentItemId);
|
||||
tMax = next.startTime();
|
||||
}
|
||||
catch (const QString &str)
|
||||
{
|
||||
DEBUG_LOG(m_view->m_logger) << str;
|
||||
}
|
||||
catch (...) {}
|
||||
|
||||
qint64 time = tPos;
|
||||
try
|
||||
{
|
||||
const Item ¤tItem = m_view->timelineModel()->item(m_currentItemId);
|
||||
|
||||
int minDist = 2 * m_view->timelineModel()->snapTolerance();
|
||||
int eps = m_view->timelineModel()->snapTolerance();
|
||||
for (int itemId : m_view->timelineModel()->itemIds())
|
||||
qint64 tMin = m_view->m_startTime;
|
||||
qint64 tMax = m_view->endTime();
|
||||
try
|
||||
{
|
||||
const Item& previous = m_view->timelineModel()->track(m_currentTrackId).previous(m_currentItemId);
|
||||
tMin = previous.startTime() + previous.duration();
|
||||
}
|
||||
catch (const QString& str)
|
||||
{
|
||||
DEBUG_LOG(m_view->m_logger) << str;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
try
|
||||
{
|
||||
const Item& next = m_view->timelineModel()->track(m_currentTrackId).next(m_currentItemId);
|
||||
tMax = next.startTime();
|
||||
}
|
||||
catch (const QString& str)
|
||||
{
|
||||
DEBUG_LOG(m_view->m_logger) << str;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
if (itemId == m_currentItemId)
|
||||
continue;
|
||||
|
||||
try
|
||||
{
|
||||
const Item &item = m_view->timelineModel()->item(itemId);
|
||||
qint64 t;
|
||||
if (time - eps < item.startTime() && item.startTime() < time + eps)
|
||||
t = item.startTime();
|
||||
else if (time - eps < item.startTime() + item.duration() && item.startTime() + item.duration() < time + eps)
|
||||
t = item.startTime() + item.duration();
|
||||
else
|
||||
continue;
|
||||
|
||||
if (std::abs(t - tPos) < minDist)
|
||||
{
|
||||
if ((m_resizePos == ResizePosition::eStart && t >= currentItem.startTime() + currentItem.duration()) ||
|
||||
(m_resizePos == ResizePosition::eEnd && t <= currentItem.startTime()))
|
||||
continue;
|
||||
time = t;
|
||||
minDist = time - tPos;
|
||||
}
|
||||
}
|
||||
catch (const QString &str)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << str;
|
||||
}
|
||||
catch (...) {}
|
||||
}
|
||||
|
||||
if (m_resizePos == ResizePosition::eStart && time >= currentItem.startTime() + currentItem.duration())
|
||||
return currentItem.startTime() + currentItem.duration() - m_view->timelineModel()->minimumDuration();
|
||||
else if (m_resizePos == ResizePosition::eEnd && time <= currentItem.startTime())
|
||||
return currentItem.startTime() + m_view->timelineModel()->minimumDuration();
|
||||
}
|
||||
catch (const QString &str)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << str;
|
||||
}
|
||||
catch (...) {}
|
||||
qint64 time = tPos;
|
||||
try
|
||||
{
|
||||
const Item& currentItem = m_view->timelineModel()->item(m_currentItemId);
|
||||
|
||||
time = std::max(tMin, time);
|
||||
time = std::min(tMax, time);
|
||||
return time;
|
||||
int minDist = 2 * m_view->timelineModel()->snapTolerance();
|
||||
int eps = m_view->timelineModel()->snapTolerance();
|
||||
for (int itemId : m_view->timelineModel()->itemIds())
|
||||
{
|
||||
if (itemId == m_currentItemId)
|
||||
continue;
|
||||
|
||||
try
|
||||
{
|
||||
const Item& item = m_view->timelineModel()->item(itemId);
|
||||
qint64 t;
|
||||
if (time - eps < item.startTime() && item.startTime() < time + eps)
|
||||
t = item.startTime();
|
||||
else if (time - eps < item.startTime() + item.duration() &&
|
||||
item.startTime() + item.duration() < time + eps)
|
||||
t = item.startTime() + item.duration();
|
||||
else
|
||||
continue;
|
||||
|
||||
if (std::abs(t - tPos) < minDist)
|
||||
{
|
||||
if ((m_resizePos == ResizePosition::eStart &&
|
||||
t >= currentItem.startTime() + currentItem.duration()) ||
|
||||
(m_resizePos == ResizePosition::eEnd && t <= currentItem.startTime()))
|
||||
continue;
|
||||
time = t;
|
||||
minDist = time - tPos;
|
||||
}
|
||||
}
|
||||
catch (const QString& str)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << str;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
if (m_resizePos == ResizePosition::eStart && time >= currentItem.startTime() + currentItem.duration())
|
||||
return currentItem.startTime() + currentItem.duration() - m_view->timelineModel()->minimumDuration();
|
||||
else if (m_resizePos == ResizePosition::eEnd && time <= currentItem.startTime())
|
||||
return currentItem.startTime() + m_view->timelineModel()->minimumDuration();
|
||||
}
|
||||
catch (const QString& str)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << str;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
|
||||
time = std::max(tMin, time);
|
||||
time = std::min(tMax, time);
|
||||
return time;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsTimeline
|
||||
Executable → Regular
+20
-20
@@ -4,39 +4,39 @@
|
||||
|
||||
#include <QMouseEvent>
|
||||
|
||||
|
||||
namespace LtsTimeline
|
||||
{
|
||||
|
||||
class Track;
|
||||
class TimelineView;
|
||||
|
||||
|
||||
class LTSTIMELINE_EXPORT TimelineViewResizeHandler
|
||||
{
|
||||
|
||||
public:
|
||||
enum class ResizePosition { eNone, eStart, eEnd };
|
||||
public:
|
||||
enum class ResizePosition { eNone, eStart, eEnd };
|
||||
|
||||
explicit TimelineViewResizeHandler(TimelineView *view);
|
||||
virtual ~TimelineViewResizeHandler();
|
||||
explicit TimelineViewResizeHandler(TimelineView* view);
|
||||
virtual ~TimelineViewResizeHandler();
|
||||
|
||||
virtual void mouseMoveEvent(QMouseEvent *e);
|
||||
virtual void mousePressEvent(QMouseEvent *e);
|
||||
virtual void mouseReleaseEvent(QMouseEvent *e);
|
||||
virtual void mouseMoveEvent(QMouseEvent* e);
|
||||
virtual void mousePressEvent(QMouseEvent* e);
|
||||
virtual void mouseReleaseEvent(QMouseEvent* e);
|
||||
|
||||
virtual bool isActive() const { return m_currentTrackId != -1 && m_currentItemId != -1 && m_resizePos != ResizePosition::eNone; }
|
||||
virtual bool isActive() const
|
||||
{
|
||||
return m_currentTrackId != -1 && m_currentItemId != -1 && m_resizePos != ResizePosition::eNone;
|
||||
}
|
||||
|
||||
private:
|
||||
virtual qint64 localSnapTime(int pos) const;
|
||||
virtual qint64 globalSnapTime(int pos) const;
|
||||
|
||||
protected:
|
||||
TimelineView *m_view{nullptr};
|
||||
int m_currentTrackId{-1};
|
||||
int m_currentItemId{-1};
|
||||
ResizePosition m_resizePos{ResizePosition::eNone};
|
||||
private:
|
||||
virtual qint64 localSnapTime(int pos) const;
|
||||
virtual qint64 globalSnapTime(int pos) const;
|
||||
|
||||
protected:
|
||||
TimelineView* m_view{nullptr};
|
||||
int m_currentTrackId{-1};
|
||||
int m_currentItemId{-1};
|
||||
ResizePosition m_resizePos{ResizePosition::eNone};
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsTimeline
|
||||
Executable → Regular
+281
-268
@@ -1,321 +1,334 @@
|
||||
#include "timeline_view_selection_handler.h"
|
||||
#include <utility>
|
||||
|
||||
#include "item_delegate.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QKeyEvent>
|
||||
#include <QModelIndex>
|
||||
#include <QMouseEvent>
|
||||
#include <QSize>
|
||||
#include <QModelIndex>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace LtsTimeline
|
||||
{
|
||||
|
||||
TimelineViewSelectHandler::TimelineViewSelectHandler(TimelineView *view)
|
||||
: m_view(view)
|
||||
{
|
||||
}
|
||||
TimelineViewSelectHandler::TimelineViewSelectHandler(TimelineView* view) : m_view(view) {}
|
||||
|
||||
TimelineViewSelectHandler::~TimelineViewSelectHandler()
|
||||
{
|
||||
m_view = nullptr;
|
||||
m_view = nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void TimelineViewSelectHandler::mouseDoubleClickEvent(QMouseEvent *e)
|
||||
void TimelineViewSelectHandler::mouseDoubleClickEvent(QMouseEvent* e)
|
||||
{
|
||||
if (e->button() != Qt::LeftButton)
|
||||
return;
|
||||
|
||||
m_view->clearSelectedItems();
|
||||
|
||||
const QModelIndex index = m_view->indexAt(e->pos());
|
||||
if (!index.isValid() || index.column() == Section::eActuator)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
Track &track = m_view->timelineModel()->track(index.data().toInt());
|
||||
Item &item = track.itemAt(m_view->toTime(e->pos().x()));
|
||||
emit m_view->itemActivated(item.id());
|
||||
}
|
||||
catch (const QString &str) { DEBUG_LOG(m_view->m_logger) << LOGFUNCTION << " " << str; }
|
||||
catch (...) { ERROR_LOG(m_view->m_logger) << LOGFUNCTION << " failed"; }
|
||||
}
|
||||
|
||||
void TimelineViewSelectHandler::mouseMoveEvent(QMouseEvent *e)
|
||||
{
|
||||
if (m_isRubberBandActive)
|
||||
{
|
||||
m_view->setCursor(QCursor(Qt::CrossCursor));
|
||||
if (!m_view->isCursorWithinRangeX(e->pos().x()))
|
||||
m_rubberBand.setHeight(e->pos().y() - m_rubberBand.top());
|
||||
|
||||
|
||||
else
|
||||
m_rubberBand.setRect(
|
||||
m_rubberBand.left(), m_rubberBand.top(), e->pos().x() - m_rubberBand.left(), e->pos().y() - m_rubberBand.top()
|
||||
);
|
||||
}
|
||||
else
|
||||
m_selectedItemId = -1;
|
||||
}
|
||||
|
||||
void TimelineViewSelectHandler::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
if (e->button() != Qt::LeftButton && e->button() != Qt::RightButton)
|
||||
return;
|
||||
|
||||
|
||||
const QModelIndex index = m_view->indexAt(e->pos());
|
||||
if (index.isValid())
|
||||
{
|
||||
if (index.column() == Section::eActuator)
|
||||
{
|
||||
qWarning() << "clicked on row with actuator" << index.data().toString();
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Track &track = m_view->timelineModel()->track(index.data().toInt());
|
||||
Item &item = track.itemAt(m_view->toTime(e->pos().x()));
|
||||
if (e->button() == Qt::LeftButton)
|
||||
m_selectedItemId = item.id();
|
||||
return;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
if (QApplication::keyboardModifiers().testFlag(Qt::ControlModifier))
|
||||
if (e->button() != Qt::LeftButton)
|
||||
return;
|
||||
|
||||
if (e->button() == Qt::RightButton)
|
||||
{
|
||||
emit m_view->customContextMenuRequested(e->pos());
|
||||
return;
|
||||
}
|
||||
|
||||
m_view->clearSelectedItems();
|
||||
m_rubberBand.setLeft(e->pos().x());
|
||||
m_rubberBand.setTop(e->pos().y());
|
||||
m_rubberBand.setSize(QSize(0, 0));
|
||||
m_isRubberBandActive = true;
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning() << "TimelineViewSelectHandler::mousePressEvent: index invalid";
|
||||
}
|
||||
|
||||
if (e->button() == Qt::RightButton)
|
||||
return;
|
||||
|
||||
if (QApplication::keyboardModifiers().testFlag(Qt::ControlModifier))
|
||||
return;
|
||||
|
||||
m_view->clearSelectedItems();
|
||||
|
||||
if (!m_view->isCursorWithinRangeX(e->pos().x()))
|
||||
return;
|
||||
|
||||
m_rubberBand.setLeft(e->pos().x());
|
||||
m_rubberBand.setTop(e->pos().y());
|
||||
m_rubberBand.setSize(QSize(0, 0));
|
||||
m_isRubberBandActive = true;
|
||||
}
|
||||
|
||||
void TimelineViewSelectHandler::mouseReleaseEvent(QMouseEvent *e)
|
||||
{
|
||||
if (e->button() == Qt::RightButton)
|
||||
{
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (e->button() != Qt::LeftButton)
|
||||
return;
|
||||
|
||||
if (m_isRubberBandActive)
|
||||
{
|
||||
m_view->selectItems(getItemsWithinRubberBand());
|
||||
m_isRubberBandActive = false;
|
||||
m_rubberBand.setSize(QSize(0, 0));
|
||||
m_view->setCursor(QCursor(Qt::ArrowCursor));
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_view->clearSelectedItems();
|
||||
|
||||
const QModelIndex index = m_view->indexAt(e->pos());
|
||||
if (!index.isValid() || index.column() == Section::eActuator)
|
||||
{
|
||||
m_selectedItemId = -1;
|
||||
return;
|
||||
}
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
Track &track = m_view->timelineModel()->track(index.data().toInt());
|
||||
Item &item = track.itemAt(m_view->toTime(e->pos().x()));
|
||||
if (item.id() == m_selectedItemId)
|
||||
{
|
||||
if (QApplication::keyboardModifiers().testFlag(Qt::ControlModifier))
|
||||
{
|
||||
if (m_view->selectedItemIds().contains(m_selectedItemId))
|
||||
m_view->unselectItem(m_selectedItemId);
|
||||
else
|
||||
m_view->selectItem(m_selectedItemId, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_view->m_selectedItemIds.size() > 1 || !m_view->m_selectedItemIds.contains(m_selectedItemId))
|
||||
m_view->selectItem(m_selectedItemId);
|
||||
else
|
||||
m_view->unselectItem(m_selectedItemId);
|
||||
}
|
||||
}
|
||||
} catch (...) {}
|
||||
m_selectedItemId = -1;
|
||||
}
|
||||
Track& track = m_view->timelineModel()->track(index.data().toInt());
|
||||
Item& item = track.itemAt(m_view->toTime(e->pos().x()));
|
||||
emit m_view->itemActivated(item.id());
|
||||
}
|
||||
catch (const QString& str)
|
||||
{
|
||||
DEBUG_LOG(m_view->m_logger) << LOGFUNCTION << " " << str;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << LOGFUNCTION << " failed";
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineViewSelectHandler::keyPressEvent(QKeyEvent *e)
|
||||
void TimelineViewSelectHandler::mouseMoveEvent(QMouseEvent* e)
|
||||
{
|
||||
if (e->key() == Qt::Key_Escape)
|
||||
{
|
||||
m_selectedItemId = -1;
|
||||
m_view->clearSelectedItems();
|
||||
}
|
||||
else if (e->key() == Qt::Key_Delete)
|
||||
{
|
||||
if (!m_view->m_selectedItemIds.isEmpty())
|
||||
if (m_isRubberBandActive)
|
||||
{
|
||||
for (const int &itemId : std::as_const(m_view->m_selectedItemIds))
|
||||
{
|
||||
m_view->setCursor(QCursor(Qt::CrossCursor));
|
||||
if (!m_view->isCursorWithinRangeX(e->pos().x()))
|
||||
m_rubberBand.setHeight(e->pos().y() - m_rubberBand.top());
|
||||
|
||||
else
|
||||
m_rubberBand.setRect(m_rubberBand.left(), m_rubberBand.top(), e->pos().x() - m_rubberBand.left(),
|
||||
e->pos().y() - m_rubberBand.top());
|
||||
}
|
||||
else
|
||||
m_selectedItemId = -1;
|
||||
}
|
||||
|
||||
void TimelineViewSelectHandler::mousePressEvent(QMouseEvent* e)
|
||||
{
|
||||
if (e->button() != Qt::LeftButton && e->button() != Qt::RightButton)
|
||||
return;
|
||||
|
||||
const QModelIndex index = m_view->indexAt(e->pos());
|
||||
if (index.isValid())
|
||||
{
|
||||
if (index.column() == Section::eActuator)
|
||||
{
|
||||
qWarning() << "clicked on row with actuator" << index.data().toString();
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
m_view->timelineModel()->removeItem(itemId);
|
||||
Track& track = m_view->timelineModel()->track(index.data().toInt());
|
||||
Item& item = track.itemAt(m_view->toTime(e->pos().x()));
|
||||
if (e->button() == Qt::LeftButton)
|
||||
m_selectedItemId = item.id();
|
||||
return;
|
||||
}
|
||||
catch (const QString &str) { ERROR_LOG(m_view->m_logger) << LOGFUNCTION << " " << str; }
|
||||
catch (...) { ERROR_LOG(m_view->m_logger) << LOGFUNCTION << " failed"; }
|
||||
}
|
||||
m_view->clearSelectedItems();
|
||||
m_selectedItemId = -1;
|
||||
catch (...)
|
||||
{
|
||||
if (QApplication::keyboardModifiers().testFlag(Qt::ControlModifier))
|
||||
return;
|
||||
|
||||
if (e->button() == Qt::RightButton)
|
||||
{
|
||||
emit m_view->customContextMenuRequested(e->pos());
|
||||
return;
|
||||
}
|
||||
|
||||
m_view->clearSelectedItems();
|
||||
m_rubberBand.setLeft(e->pos().x());
|
||||
m_rubberBand.setTop(e->pos().y());
|
||||
m_rubberBand.setSize(QSize(0, 0));
|
||||
m_isRubberBandActive = true;
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (QApplication::keyboardModifiers().testFlag(Qt::ControlModifier))
|
||||
{
|
||||
try
|
||||
else
|
||||
{
|
||||
switch (e->key())
|
||||
{
|
||||
case Qt::Key_A:
|
||||
m_view->selectAllItems();
|
||||
m_selectedItemId = -1;
|
||||
break;
|
||||
|
||||
case Qt::Key_C:
|
||||
if (m_view->hasSelectedItems())
|
||||
m_view->timelineModel()->copyToClipboard(m_view->selectedItemIds());
|
||||
break;
|
||||
|
||||
case Qt::Key_X:
|
||||
if (m_view->hasSelectedItems())
|
||||
{
|
||||
m_view->timelineModel()->cutToClipboard(m_view->selectedItemIds());
|
||||
m_view->clearSelectedItems();
|
||||
}
|
||||
break;
|
||||
|
||||
case Qt::Key_V:
|
||||
if (!m_view->timelineModel()->m_clipboard.empty())
|
||||
{
|
||||
qint64 time = m_view->currentTime();
|
||||
if (m_view->m_header->isIndicatorVisible() && m_view->m_header->indicatorTime() != -1)
|
||||
time = m_view->m_header->indicatorTime();
|
||||
m_view->timelineModel()->pasteFromClipboard(time);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
qWarning() << "TimelineViewSelectHandler::mousePressEvent: index invalid";
|
||||
}
|
||||
catch (const QString &str) { ERROR_LOG(m_view->m_logger) << LOGFUNCTION << " " << str; }
|
||||
catch (...) { ERROR_LOG(m_view->m_logger) << LOGFUNCTION << " failed"; }
|
||||
}
|
||||
|
||||
if (e->button() == Qt::RightButton)
|
||||
return;
|
||||
|
||||
if (QApplication::keyboardModifiers().testFlag(Qt::ControlModifier))
|
||||
return;
|
||||
|
||||
m_view->clearSelectedItems();
|
||||
|
||||
if (!m_view->isCursorWithinRangeX(e->pos().x()))
|
||||
return;
|
||||
|
||||
m_rubberBand.setLeft(e->pos().x());
|
||||
m_rubberBand.setTop(e->pos().y());
|
||||
m_rubberBand.setSize(QSize(0, 0));
|
||||
m_isRubberBandActive = true;
|
||||
}
|
||||
|
||||
void TimelineViewSelectHandler::mouseReleaseEvent(QMouseEvent* e)
|
||||
{
|
||||
if (e->button() == Qt::RightButton)
|
||||
{
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (e->button() != Qt::LeftButton)
|
||||
return;
|
||||
|
||||
if (m_isRubberBandActive)
|
||||
{
|
||||
m_view->selectItems(getItemsWithinRubberBand());
|
||||
m_isRubberBandActive = false;
|
||||
m_rubberBand.setSize(QSize(0, 0));
|
||||
m_view->setCursor(QCursor(Qt::ArrowCursor));
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
const QModelIndex index = m_view->indexAt(e->pos());
|
||||
if (!index.isValid() || index.column() == Section::eActuator)
|
||||
{
|
||||
m_selectedItemId = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Track& track = m_view->timelineModel()->track(index.data().toInt());
|
||||
Item& item = track.itemAt(m_view->toTime(e->pos().x()));
|
||||
if (item.id() == m_selectedItemId)
|
||||
{
|
||||
if (QApplication::keyboardModifiers().testFlag(Qt::ControlModifier))
|
||||
{
|
||||
if (m_view->selectedItemIds().contains(m_selectedItemId))
|
||||
m_view->unselectItem(m_selectedItemId);
|
||||
else
|
||||
m_view->selectItem(m_selectedItemId, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_view->m_selectedItemIds.size() > 1 || !m_view->m_selectedItemIds.contains(m_selectedItemId))
|
||||
m_view->selectItem(m_selectedItemId);
|
||||
else
|
||||
m_view->unselectItem(m_selectedItemId);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
m_selectedItemId = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineViewSelectHandler::keyPressEvent(QKeyEvent* e)
|
||||
{
|
||||
if (e->key() == Qt::Key_Escape)
|
||||
{
|
||||
m_selectedItemId = -1;
|
||||
m_view->clearSelectedItems();
|
||||
}
|
||||
else if (e->key() == Qt::Key_Delete)
|
||||
{
|
||||
if (!m_view->m_selectedItemIds.isEmpty())
|
||||
{
|
||||
for (const int& itemId : std::as_const(m_view->m_selectedItemIds))
|
||||
{
|
||||
try
|
||||
{
|
||||
m_view->timelineModel()->removeItem(itemId);
|
||||
}
|
||||
catch (const QString& str)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << LOGFUNCTION << " " << str;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << LOGFUNCTION << " failed";
|
||||
}
|
||||
}
|
||||
m_view->clearSelectedItems();
|
||||
m_selectedItemId = -1;
|
||||
}
|
||||
}
|
||||
else if (QApplication::keyboardModifiers().testFlag(Qt::ControlModifier))
|
||||
{
|
||||
try
|
||||
{
|
||||
switch (e->key())
|
||||
{
|
||||
case Qt::Key_A:
|
||||
m_view->selectAllItems();
|
||||
m_selectedItemId = -1;
|
||||
break;
|
||||
|
||||
case Qt::Key_C:
|
||||
if (m_view->hasSelectedItems())
|
||||
m_view->timelineModel()->copyToClipboard(m_view->selectedItemIds());
|
||||
break;
|
||||
|
||||
case Qt::Key_X:
|
||||
if (m_view->hasSelectedItems())
|
||||
{
|
||||
m_view->timelineModel()->cutToClipboard(m_view->selectedItemIds());
|
||||
m_view->clearSelectedItems();
|
||||
}
|
||||
break;
|
||||
|
||||
case Qt::Key_V:
|
||||
if (!m_view->timelineModel()->m_clipboard.empty())
|
||||
{
|
||||
qint64 time = m_view->currentTime();
|
||||
if (m_view->m_header->isIndicatorVisible() && m_view->m_header->indicatorTime() != -1)
|
||||
time = m_view->m_header->indicatorTime();
|
||||
m_view->timelineModel()->pasteFromClipboard(time);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (const QString& str)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << LOGFUNCTION << " " << str;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << LOGFUNCTION << " failed";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool TimelineViewSelectHandler::isActive() const
|
||||
{
|
||||
if (QApplication::keyboardModifiers().testFlag(Qt::ControlModifier))
|
||||
return true;
|
||||
if (m_isRubberBandActive)
|
||||
return true;
|
||||
return m_selectedItemId != -1;
|
||||
if (QApplication::keyboardModifiers().testFlag(Qt::ControlModifier))
|
||||
return true;
|
||||
if (m_isRubberBandActive)
|
||||
return true;
|
||||
return m_selectedItemId != -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
QVector<int> TimelineViewSelectHandler::getItemsWithinRubberBand() const
|
||||
{
|
||||
const QPoint topLeft = { std::min(m_rubberBand.left(), m_rubberBand.right()), std::min(m_rubberBand.top(), m_rubberBand.bottom()) };
|
||||
const QPoint bottomRight = { std::max(m_rubberBand.left(), m_rubberBand.right()), std::max(m_rubberBand.top(), m_rubberBand.bottom()) };
|
||||
const qint64 start = m_view->toTime(topLeft.x());
|
||||
const qint64 end = m_view->toTime(bottomRight.x());
|
||||
if (start == end)
|
||||
return {};
|
||||
const QPoint topLeft = {std::min(m_rubberBand.left(), m_rubberBand.right()),
|
||||
std::min(m_rubberBand.top(), m_rubberBand.bottom())};
|
||||
const QPoint bottomRight = {std::max(m_rubberBand.left(), m_rubberBand.right()),
|
||||
std::max(m_rubberBand.top(), m_rubberBand.bottom())};
|
||||
const qint64 start = m_view->toTime(topLeft.x());
|
||||
const qint64 end = m_view->toTime(bottomRight.x());
|
||||
if (start == end)
|
||||
return {};
|
||||
|
||||
QVector<int> itemsWithinRubberBand;
|
||||
const int h = m_view->itemDelegate()->sizeHint({}, {}).height();
|
||||
for (int y = topLeft.y(); y <= bottomRight.y(); y += h)
|
||||
{
|
||||
const QPoint point = { topLeft.x(), y };
|
||||
|
||||
const QModelIndex index = m_view->indexAt(point);
|
||||
if (!index.isValid())
|
||||
continue;
|
||||
|
||||
try
|
||||
QVector<int> itemsWithinRubberBand;
|
||||
const int h = m_view->itemDelegate()->sizeHint({}, {}).height();
|
||||
for (int y = topLeft.y(); y <= bottomRight.y(); y += h)
|
||||
{
|
||||
const Track &track = m_view->timelineModel()->track(index.data().toInt());
|
||||
itemsWithinRubberBand += track.itemIdsBetween(start, end);
|
||||
}
|
||||
catch (const QString &str)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << str;
|
||||
}
|
||||
catch (...) {}
|
||||
}
|
||||
if (topLeft.y() + h > bottomRight.y())
|
||||
{
|
||||
const QPoint point = {topLeft.x(), y};
|
||||
|
||||
const QModelIndex index = m_view->indexAt(bottomRight);
|
||||
if (!index.isValid())
|
||||
return itemsWithinRubberBand;
|
||||
const QModelIndex index = m_view->indexAt(point);
|
||||
if (!index.isValid())
|
||||
continue;
|
||||
|
||||
try
|
||||
{
|
||||
const Track &track = m_view->timelineModel()->track(index.data().toInt());
|
||||
itemsWithinRubberBand += track.itemIdsBetween(start, end);
|
||||
try
|
||||
{
|
||||
const Track& track = m_view->timelineModel()->track(index.data().toInt());
|
||||
itemsWithinRubberBand += track.itemIdsBetween(start, end);
|
||||
}
|
||||
catch (const QString& str)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << str;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
catch (const QString &str)
|
||||
if (topLeft.y() + h > bottomRight.y())
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << str;
|
||||
|
||||
const QModelIndex index = m_view->indexAt(bottomRight);
|
||||
if (!index.isValid())
|
||||
return itemsWithinRubberBand;
|
||||
|
||||
try
|
||||
{
|
||||
const Track& track = m_view->timelineModel()->track(index.data().toInt());
|
||||
itemsWithinRubberBand += track.itemIdsBetween(start, end);
|
||||
}
|
||||
catch (const QString& str)
|
||||
{
|
||||
ERROR_LOG(m_view->m_logger) << str;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
catch (...) {}
|
||||
}
|
||||
return itemsWithinRubberBand;
|
||||
return itemsWithinRubberBand;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsTimeline
|
||||
Executable → Regular
+23
-24
@@ -1,48 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include "timeline_view.h"
|
||||
|
||||
#include "ltstimeline_export.h"
|
||||
#include "timeline_view.h"
|
||||
|
||||
#include <QRect>
|
||||
|
||||
|
||||
class QMouseEvent;
|
||||
class QKeyEvent;
|
||||
|
||||
|
||||
namespace LtsTimeline
|
||||
{
|
||||
|
||||
class TimelineView;
|
||||
|
||||
|
||||
class LTSTIMELINE_EXPORT TimelineViewSelectHandler
|
||||
{
|
||||
friend class TimelineView;
|
||||
friend class TimelineView;
|
||||
|
||||
public:
|
||||
explicit TimelineViewSelectHandler(TimelineView *view);
|
||||
virtual ~TimelineViewSelectHandler();
|
||||
public:
|
||||
explicit TimelineViewSelectHandler(TimelineView* view);
|
||||
virtual ~TimelineViewSelectHandler();
|
||||
|
||||
virtual void mouseDoubleClickEvent(QMouseEvent *e);
|
||||
virtual void mouseMoveEvent(QMouseEvent *e);
|
||||
virtual void mousePressEvent(QMouseEvent *e);
|
||||
virtual void mouseReleaseEvent(QMouseEvent *e);
|
||||
virtual void keyPressEvent(QKeyEvent *e);
|
||||
virtual void mouseDoubleClickEvent(QMouseEvent* e);
|
||||
virtual void mouseMoveEvent(QMouseEvent* e);
|
||||
virtual void mousePressEvent(QMouseEvent* e);
|
||||
virtual void mouseReleaseEvent(QMouseEvent* e);
|
||||
virtual void keyPressEvent(QKeyEvent* e);
|
||||
|
||||
virtual bool isActive() const;
|
||||
virtual bool isRubberBandActive() const { return m_isRubberBandActive; }
|
||||
virtual bool isActive() const;
|
||||
|
||||
protected:
|
||||
virtual QVector<int> getItemsWithinRubberBand() const;
|
||||
virtual bool isRubberBandActive() const
|
||||
{
|
||||
return m_isRubberBandActive;
|
||||
}
|
||||
|
||||
protected:
|
||||
TimelineView *m_view{nullptr};
|
||||
int m_selectedItemId{-1};
|
||||
QRect m_rubberBand;
|
||||
bool m_isRubberBandActive{false};
|
||||
protected:
|
||||
virtual QVector<int> getItemsWithinRubberBand() const;
|
||||
|
||||
protected:
|
||||
TimelineView* m_view{nullptr};
|
||||
int m_selectedItemId{-1};
|
||||
QRect m_rubberBand;
|
||||
bool m_isRubberBandActive{false};
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsTimeline
|
||||
Executable → Regular
+69
-78
@@ -1,107 +1,98 @@
|
||||
#include "timeline_view_resize_handler.h"
|
||||
#include "timeline_view.h"
|
||||
#include "timeline_header_view.h"
|
||||
#include "item.h"
|
||||
#include "timeline_header_view.h"
|
||||
#include "timeline_view.h"
|
||||
#include "timeline_view_resize_handler.h"
|
||||
#include "track.h"
|
||||
|
||||
#include <LtsWidgets/lts_message_dialog.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMouseEvent>
|
||||
#include <QDebug>
|
||||
|
||||
#include <QMouseEvent>
|
||||
|
||||
namespace LtsTimeline
|
||||
{
|
||||
|
||||
TimelineViewTrackHandler::TimelineViewTrackHandler(TimelineView *view)
|
||||
: m_view(view)
|
||||
{
|
||||
}
|
||||
TimelineViewTrackHandler::TimelineViewTrackHandler(TimelineView* view) : m_view(view) {}
|
||||
|
||||
TimelineViewTrackHandler::~TimelineViewTrackHandler()
|
||||
{
|
||||
m_view = nullptr;
|
||||
m_view = nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void TimelineViewTrackHandler::mouseDoubleClickEvent(QMouseEvent *e)
|
||||
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);
|
||||
if (e->button() != Qt::LeftButton)
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (track.hasRemoveButton())
|
||||
|
||||
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)
|
||||
{
|
||||
QRect rect = QRect(visRect.right() - buttonLength, visRect.center().y(), buttonLength, buttonLength);
|
||||
if (rect.contains(e->pos()))
|
||||
{
|
||||
m_pressedRemoveButtonIndex = index;
|
||||
if (e->button() == Qt::RightButton)
|
||||
emit m_view->customContextMenuRequested(e->pos());
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
const QModelIndex index = m_view->indexAt(e->pos());
|
||||
if (!index.isValid() || index.column() != Section::eActuator)
|
||||
return;
|
||||
|
||||
QObject::connect(msg, &LtsWidgets::LtsMessageDialogNew::yes,
|
||||
m_view, [this, index]()
|
||||
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()->onRemoveTrack(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;
|
||||
|
||||
return;
|
||||
}
|
||||
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 (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
catch (...) {}
|
||||
}
|
||||
|
||||
void TimelineViewTrackHandler::mouseReleaseEvent(QMouseEvent *e)
|
||||
void TimelineViewTrackHandler::mouseReleaseEvent(QMouseEvent* e)
|
||||
{
|
||||
Q_UNUSED(e);
|
||||
m_pressedInsertButtonIndex = {};
|
||||
m_pressedRemoveButtonIndex = {};
|
||||
Q_UNUSED(e);
|
||||
m_pressedInsertButtonIndex = {};
|
||||
m_pressedRemoveButtonIndex = {};
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsTimeline
|
||||
Executable → Regular
+20
-16
@@ -2,9 +2,8 @@
|
||||
|
||||
#include "ltstimeline_export.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <QModelIndex>
|
||||
|
||||
#include <QMouseEvent>
|
||||
|
||||
namespace LtsTimeline
|
||||
{
|
||||
@@ -12,27 +11,32 @@ namespace LtsTimeline
|
||||
class Track;
|
||||
class TimelineView;
|
||||
|
||||
|
||||
class LTSTIMELINE_EXPORT TimelineViewTrackHandler
|
||||
{
|
||||
|
||||
public:
|
||||
explicit TimelineViewTrackHandler(TimelineView *view);
|
||||
virtual ~TimelineViewTrackHandler();
|
||||
public:
|
||||
explicit TimelineViewTrackHandler(TimelineView* view);
|
||||
virtual ~TimelineViewTrackHandler();
|
||||
|
||||
virtual void mouseDoubleClickEvent(QMouseEvent *e);
|
||||
virtual void mousePressEvent(QMouseEvent *e);
|
||||
virtual void mouseReleaseEvent(QMouseEvent *e);
|
||||
virtual void mouseDoubleClickEvent(QMouseEvent* e);
|
||||
virtual void mousePressEvent(QMouseEvent* e);
|
||||
virtual void mouseReleaseEvent(QMouseEvent* e);
|
||||
|
||||
bool isInsertButtonPressed(const QModelIndex &index) const { return index == m_pressedInsertButtonIndex; }
|
||||
bool isRemoveButtonPressed(const QModelIndex &index) const { return index == m_pressedRemoveButtonIndex; }
|
||||
bool isInsertButtonPressed(const QModelIndex& index) const
|
||||
{
|
||||
return index == m_pressedInsertButtonIndex;
|
||||
}
|
||||
|
||||
protected:
|
||||
TimelineView *m_view{nullptr};
|
||||
bool isRemoveButtonPressed(const QModelIndex& index) const
|
||||
{
|
||||
return index == m_pressedRemoveButtonIndex;
|
||||
}
|
||||
|
||||
QModelIndex m_pressedInsertButtonIndex;
|
||||
QModelIndex m_pressedRemoveButtonIndex;
|
||||
protected:
|
||||
TimelineView* m_view{nullptr};
|
||||
|
||||
QModelIndex m_pressedInsertButtonIndex;
|
||||
QModelIndex m_pressedRemoveButtonIndex;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsTimeline
|
||||
Executable → Regular
+174
-208
@@ -1,23 +1,21 @@
|
||||
|
||||
|
||||
|
||||
#include "timeline_widget.h"
|
||||
#include <utility>
|
||||
#include "ui_timeline_widget.h"
|
||||
#include "timeline_view.h"
|
||||
|
||||
#include "item_delegate.h"
|
||||
#include "timeline_header_view.h"
|
||||
#include "timeline_model.h"
|
||||
#include "item_delegate.h"
|
||||
#include "timeline_view.h"
|
||||
#include "ui_timeline_widget.h"
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
|
||||
#include <QSize>
|
||||
#include <QDateTime>
|
||||
#include <QPoint>
|
||||
#include <QRect>
|
||||
#include <QSize>
|
||||
#include <QStandardItemModel>
|
||||
#include <QDateTime>
|
||||
#include <QtGlobal>
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace LtsTimeline
|
||||
{
|
||||
@@ -27,377 +25,345 @@ TimelineWidget::TimelineWidget(QWidget *parent)
|
||||
, m_ui(new Ui::Timeline)
|
||||
.getNGLLogger("Timeline.Widget"))
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
m_ui->debugWidget->hide();
|
||||
m_ui->wPlaceholder->hide();
|
||||
m_ui->pbZoomIn->setProperty("const", true);
|
||||
m_ui->pbZoomOut->setProperty("const", true);
|
||||
m_ui->cbZoom->setProperty("const", true);
|
||||
m_ui->setupUi(this);
|
||||
m_ui->debugWidget->hide();
|
||||
m_ui->wPlaceholder->hide();
|
||||
m_ui->pbZoomIn->setProperty("const", true);
|
||||
m_ui->pbZoomOut->setProperty("const", true);
|
||||
m_ui->cbZoom->setProperty("const", true);
|
||||
|
||||
connect(m_ui->cbZoom, qOverload<int>(&QComboBox::currentIndexChanged),
|
||||
this, &TimelineWidget::onZoomSelected);
|
||||
m_ui->pbZoomIn->setIcon(QIcon(QStringLiteral("icon:bgv_zoom_in.svg")));
|
||||
connect(m_ui->pbZoomIn, &QPushButton::clicked,
|
||||
this, &TimelineWidget::onZoomIn);
|
||||
m_ui->pbZoomOut->setIcon(QIcon(QStringLiteral("icon:bgv_zoom_out.svg")));
|
||||
connect(m_ui->pbZoomOut, &QPushButton::clicked,
|
||||
this, &TimelineWidget::onZoomOut);
|
||||
connect(m_ui->cbZoom, qOverload<int>(&QComboBox::currentIndexChanged), this, &TimelineWidget::onZoomSelected);
|
||||
m_ui->pbZoomIn->setIcon(QIcon(QStringLiteral("icon:bgv_zoom_in.svg")));
|
||||
connect(m_ui->pbZoomIn, &QPushButton::clicked, this, &TimelineWidget::onZoomIn);
|
||||
m_ui->pbZoomOut->setIcon(QIcon(QStringLiteral("icon:bgv_zoom_out.svg")));
|
||||
connect(m_ui->pbZoomOut, &QPushButton::clicked, this, &TimelineWidget::onZoomOut);
|
||||
|
||||
connect(m_ui->view, &TimelineView::rangeChanged, this, [this](qint64 min, qint64 max)
|
||||
{
|
||||
m_ui->slider->setRange(min / 1000, (max - m_ui->view->zoomFactor()) / 1000);
|
||||
onUpdateZoomButtons();
|
||||
});
|
||||
connect(m_ui->view, &TimelineView::currentTimeChanged, this, [this](qint64 time)
|
||||
{
|
||||
m_ui->slider->setValue(time / 1000);
|
||||
});
|
||||
connect(m_ui->view, &TimelineView::rangeChanged, this, [this](qint64 min, qint64 max) {
|
||||
m_ui->slider->setRange(min / 1000, (max - m_ui->view->zoomFactor()) / 1000);
|
||||
onUpdateZoomButtons();
|
||||
});
|
||||
connect(m_ui->view, &TimelineView::currentTimeChanged, this,
|
||||
[this](qint64 time) { m_ui->slider->setValue(time / 1000); });
|
||||
|
||||
connect(m_ui->view, &TimelineView::zoomChanged,
|
||||
this, &TimelineWidget::onZoomChanged);
|
||||
connect(m_ui->view, &TimelineView::zoomChanged, this, &TimelineWidget::onZoomChanged);
|
||||
|
||||
connect(m_ui->view->header(), &TimelineHeaderView::sectionResized,
|
||||
this, &TimelineWidget::onSectionResized);
|
||||
connect(m_ui->view->header(), &TimelineHeaderView::sectionResized, this, &TimelineWidget::onSectionResized);
|
||||
|
||||
connect(m_ui->slider, &QScrollBar::valueChanged,
|
||||
this, &TimelineWidget::onSliderValueChanged);
|
||||
connect(m_ui->slider, &QScrollBar::valueChanged, this, &TimelineWidget::onSliderValueChanged);
|
||||
|
||||
onZoomChanged(m_ui->view->zoomFactor());
|
||||
onZoomChanged(m_ui->view->zoomFactor());
|
||||
}
|
||||
|
||||
TimelineWidget::~TimelineWidget()
|
||||
{
|
||||
delete m_ui;
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
TimelineView *TimelineWidget::view()
|
||||
TimelineView* TimelineWidget::view()
|
||||
{
|
||||
return m_ui->view;
|
||||
return m_ui->view;
|
||||
}
|
||||
|
||||
|
||||
TimelineHeaderView *TimelineWidget::header()
|
||||
TimelineHeaderView* TimelineWidget::header()
|
||||
{
|
||||
return m_ui->view->header();
|
||||
return m_ui->view->header();
|
||||
}
|
||||
|
||||
|
||||
TimelineModel *TimelineWidget::timelineModel()
|
||||
TimelineModel* TimelineWidget::timelineModel()
|
||||
{
|
||||
return m_ui->view->timelineModel();
|
||||
return m_ui->view->timelineModel();
|
||||
}
|
||||
|
||||
|
||||
void TimelineWidget::setModel(QAbstractItemModel *model)
|
||||
void TimelineWidget::setModel(QAbstractItemModel* model)
|
||||
{
|
||||
m_ui->view->setModel(model);
|
||||
m_ui->view->setModel(model);
|
||||
}
|
||||
|
||||
|
||||
QScrollBar *TimelineWidget::slider()
|
||||
QScrollBar* TimelineWidget::slider()
|
||||
{
|
||||
return m_ui->slider;
|
||||
return m_ui->slider;
|
||||
}
|
||||
|
||||
|
||||
ZoomFactor TimelineWidget::zoomFactor() const
|
||||
{
|
||||
return m_ui->view->zoomFactor();
|
||||
return m_ui->view->zoomFactor();
|
||||
}
|
||||
|
||||
void TimelineWidget::setZoomFactor(ZoomFactor factor)
|
||||
{
|
||||
m_ui->view->setZoomFactor(factor);
|
||||
m_ui->view->setZoomFactor(factor);
|
||||
}
|
||||
|
||||
|
||||
ZoomFactor TimelineWidget::minimumZoomFactor() const
|
||||
{
|
||||
return m_ui->view->minimumZoomFactor();
|
||||
return m_ui->view->minimumZoomFactor();
|
||||
}
|
||||
|
||||
void TimelineWidget::setMinimumZoomFactor(ZoomFactor factor)
|
||||
{
|
||||
m_ui->view->setMinimumZoomFactor(factor);
|
||||
populateZoomFactorComboBox();
|
||||
m_ui->view->setMinimumZoomFactor(factor);
|
||||
populateZoomFactorComboBox();
|
||||
}
|
||||
|
||||
|
||||
ZoomFactor TimelineWidget::maximumZoomFactor() const
|
||||
{
|
||||
return m_ui->view->maximumZoomFactor();
|
||||
return m_ui->view->maximumZoomFactor();
|
||||
}
|
||||
|
||||
void TimelineWidget::setMaximumZoomFactor(ZoomFactor factor)
|
||||
{
|
||||
m_ui->view->setMaximumZoomFactor(factor);
|
||||
populateZoomFactorComboBox();
|
||||
m_ui->view->setMaximumZoomFactor(factor);
|
||||
populateZoomFactorComboBox();
|
||||
}
|
||||
|
||||
|
||||
qint64 TimelineWidget::startTime() const
|
||||
{
|
||||
return m_ui->view->startTime();
|
||||
return m_ui->view->startTime();
|
||||
}
|
||||
|
||||
void TimelineWidget::setStartTime(qint64 time)
|
||||
{
|
||||
m_ui->view->setStartTime(time);
|
||||
m_ui->view->setStartTime(time);
|
||||
}
|
||||
|
||||
|
||||
qint64 TimelineWidget::currentTime() const
|
||||
{
|
||||
return m_ui->view->currentTime();
|
||||
return m_ui->view->currentTime();
|
||||
}
|
||||
|
||||
void TimelineWidget::setCurrentTime(qint64 time)
|
||||
{
|
||||
m_ui->view->setCurrentTime(time);
|
||||
m_ui->view->setCurrentTime(time);
|
||||
}
|
||||
|
||||
|
||||
qint64 TimelineWidget::endTime() const
|
||||
{
|
||||
return m_ui->view->endTime();
|
||||
return m_ui->view->endTime();
|
||||
}
|
||||
|
||||
void TimelineWidget::setEndTime(qint64 time)
|
||||
{
|
||||
m_ui->view->setEndTime(time);
|
||||
m_ui->view->setEndTime(time);
|
||||
}
|
||||
|
||||
|
||||
int TimelineWidget::duration() const
|
||||
{
|
||||
return m_ui->view->duration();
|
||||
return m_ui->view->duration();
|
||||
}
|
||||
|
||||
void TimelineWidget::setDuration(int duration)
|
||||
{
|
||||
m_ui->view->setDuration(duration);
|
||||
m_ui->view->setDuration(duration);
|
||||
}
|
||||
|
||||
|
||||
bool TimelineWidget::isCursorTextVisible() const
|
||||
{
|
||||
return m_ui->view->isCursorTextVisible();
|
||||
return m_ui->view->isCursorTextVisible();
|
||||
}
|
||||
|
||||
void TimelineWidget::setCursorTextVisible(bool visible)
|
||||
{
|
||||
m_ui->view->setCursorTextVisible(visible);
|
||||
m_ui->view->setCursorTextVisible(visible);
|
||||
}
|
||||
|
||||
void TimelineWidget::setCursorText(const QString &text)
|
||||
void TimelineWidget::setCursorText(const QString& text)
|
||||
{
|
||||
m_ui->view->setCursorText(text);
|
||||
m_ui->view->setCursorText(text);
|
||||
}
|
||||
|
||||
|
||||
bool TimelineWidget::isSnapEnabled() const
|
||||
{
|
||||
return m_ui->view->timelineModel()->isSnapEnabled();
|
||||
return m_ui->view->timelineModel()->isSnapEnabled();
|
||||
}
|
||||
|
||||
void TimelineWidget::setSnapEnabled(bool enabled)
|
||||
{
|
||||
m_ui->view->timelineModel()->setSnapEnabled(enabled);
|
||||
m_ui->view->timelineModel()->setSnapEnabled(enabled);
|
||||
}
|
||||
|
||||
void TimelineWidget::enableSnap()
|
||||
{
|
||||
m_ui->view->timelineModel()->setSnapEnabled(true);
|
||||
m_ui->view->timelineModel()->setSnapEnabled(true);
|
||||
}
|
||||
|
||||
void TimelineWidget::disableSnap()
|
||||
{
|
||||
m_ui->view->timelineModel()->setSnapEnabled(false);
|
||||
m_ui->view->timelineModel()->setSnapEnabled(false);
|
||||
}
|
||||
|
||||
void TimelineWidget::triggerSnap()
|
||||
{
|
||||
m_ui->view->timelineModel()->setSnapEnabled(!m_ui->view->timelineModel()->isSnapEnabled());
|
||||
if (m_ui->debugWidget->isVisible())
|
||||
m_ui->pbDebugTriggerSnap->setText(m_ui->view->timelineModel()->isSnapEnabled() ? QStringLiteral("Disable Snap") :
|
||||
QStringLiteral("Enable Snap"));
|
||||
m_ui->view->timelineModel()->setSnapEnabled(!m_ui->view->timelineModel()->isSnapEnabled());
|
||||
if (m_ui->debugWidget->isVisible())
|
||||
m_ui->pbDebugTriggerSnap->setText(m_ui->view->timelineModel()->isSnapEnabled() ? QStringLiteral("Disable Snap")
|
||||
: QStringLiteral("Enable Snap"));
|
||||
}
|
||||
|
||||
|
||||
void TimelineWidget::setZoomInIcon(QIcon icon)
|
||||
{
|
||||
m_ui->pbZoomIn->setIcon(icon);
|
||||
m_ui->pbZoomIn->setIcon(icon);
|
||||
}
|
||||
|
||||
void TimelineWidget::setZoomOutIcon(QIcon icon)
|
||||
{
|
||||
m_ui->pbZoomOut->setIcon(icon);
|
||||
m_ui->pbZoomOut->setIcon(icon);
|
||||
}
|
||||
|
||||
|
||||
QWidget *TimelineWidget::placeholder()
|
||||
QWidget* TimelineWidget::placeholder()
|
||||
{
|
||||
if (m_ui->wPlaceholder->layout()->count() == 0)
|
||||
return nullptr;
|
||||
return m_ui->wPlaceholder->layout()->itemAt(0)->widget();
|
||||
if (m_ui->wPlaceholder->layout()->count() == 0)
|
||||
return nullptr;
|
||||
return m_ui->wPlaceholder->layout()->itemAt(0)->widget();
|
||||
}
|
||||
|
||||
void TimelineWidget::setPlaceholder(QWidget *widget)
|
||||
void TimelineWidget::setPlaceholder(QWidget* widget)
|
||||
{
|
||||
QWidget *ptr = placeholder();
|
||||
if (ptr)
|
||||
{
|
||||
if (ptr == widget)
|
||||
return;
|
||||
m_ui->wPlaceholder->layout()->removeWidget(ptr);
|
||||
delete ptr;
|
||||
}
|
||||
m_ui->wPlaceholder->layout()->addWidget(widget);
|
||||
QWidget* ptr = placeholder();
|
||||
if (ptr)
|
||||
{
|
||||
if (ptr == widget)
|
||||
return;
|
||||
m_ui->wPlaceholder->layout()->removeWidget(ptr);
|
||||
delete ptr;
|
||||
}
|
||||
m_ui->wPlaceholder->layout()->addWidget(widget);
|
||||
}
|
||||
|
||||
|
||||
void TimelineWidget::showDebugWidget()
|
||||
{
|
||||
m_ui->debugWidget->show();
|
||||
m_ui->debugWidget->show();
|
||||
|
||||
m_ui->sbDebugSnapStep->setValue(m_ui->view->timelineModel()->snapStep());
|
||||
m_ui->sbDebugSnapTol->setValue(m_ui->view->timelineModel()->snapTolerance());
|
||||
m_ui->pbDebugTriggerSnap->setText(m_ui->view->header()->isIndicatorVisible() ? QStringLiteral("Disable Snap") :
|
||||
QStringLiteral("Enable Snap"));
|
||||
m_ui->pbDebugTriggerIndicator->setText(m_ui->view->header()->isIndicatorVisible() ? QStringLiteral("Disable Indicator") :
|
||||
QStringLiteral("Enable Indicator"));
|
||||
m_ui->pbDebugTriggerHover->setText(m_ui->view->header()->isIndicatorVisible() ? QStringLiteral("Disable Hover") :
|
||||
QStringLiteral("Enable Hover"));
|
||||
m_ui->sbDebugSnapStep->setValue(m_ui->view->timelineModel()->snapStep());
|
||||
m_ui->sbDebugSnapTol->setValue(m_ui->view->timelineModel()->snapTolerance());
|
||||
m_ui->pbDebugTriggerSnap->setText(m_ui->view->header()->isIndicatorVisible() ? QStringLiteral("Disable Snap")
|
||||
: QStringLiteral("Enable Snap"));
|
||||
m_ui->pbDebugTriggerIndicator->setText(m_ui->view->header()->isIndicatorVisible()
|
||||
? QStringLiteral("Disable Indicator")
|
||||
: QStringLiteral("Enable Indicator"));
|
||||
m_ui->pbDebugTriggerHover->setText(m_ui->view->header()->isIndicatorVisible() ? QStringLiteral("Disable Hover")
|
||||
: QStringLiteral("Enable Hover"));
|
||||
|
||||
connect(m_ui->view, &TimelineView::currentTimeChanged, this, &TimelineWidget::onUpdateDebugInfo);
|
||||
connect(m_ui->view, &TimelineView::rangeChanged, this, &TimelineWidget::onUpdateDebugInfo);
|
||||
connect(m_ui->view, &TimelineView::selectedItemsChanged, this, &TimelineWidget::onUpdateDebugInfo);
|
||||
connect(m_ui->view, &TimelineView::zoomChanged, this, &TimelineWidget::onUpdateDebugInfo);
|
||||
connect(m_ui->pbDebugTriggerSnap, &QPushButton::clicked, this, &TimelineWidget::triggerSnap);
|
||||
connect(m_ui->sbDebugSnapStep, qOverload<int>(&QSpinBox::valueChanged), m_ui->view->timelineModel(), &TimelineModel::setSnapStep);
|
||||
connect(m_ui->sbDebugSnapTol, qOverload<int>(&QSpinBox::valueChanged), m_ui->view->timelineModel(), &TimelineModel::setSnapTolerance);
|
||||
connect(m_ui->pbDebugTriggerIndicator, &QPushButton::clicked, this, [this]()
|
||||
{
|
||||
m_ui->view->header()->setIndicatorVisible(!m_ui->view->header()->isIndicatorVisible());
|
||||
m_ui->pbDebugTriggerIndicator->setText(m_ui->view->header()->isIndicatorVisible() ? QStringLiteral("Disable Indicator") :
|
||||
QStringLiteral("Enable Indicator"));
|
||||
});
|
||||
connect(m_ui->pbDebugTriggerHover, &QPushButton::clicked, this, [this]()
|
||||
{
|
||||
m_ui->view->header()->setHoverVisible(!m_ui->view->header()->isHoverVisible());
|
||||
m_ui->pbDebugTriggerHover->setText(m_ui->view->header()->isHoverVisible() ? QStringLiteral("Disable Hover") :
|
||||
QStringLiteral("Enable Hover"));
|
||||
});
|
||||
connect(m_ui->view, &TimelineView::currentTimeChanged, this, &TimelineWidget::onUpdateDebugInfo);
|
||||
connect(m_ui->view, &TimelineView::rangeChanged, this, &TimelineWidget::onUpdateDebugInfo);
|
||||
connect(m_ui->view, &TimelineView::selectedItemsChanged, this, &TimelineWidget::onUpdateDebugInfo);
|
||||
connect(m_ui->view, &TimelineView::zoomChanged, this, &TimelineWidget::onUpdateDebugInfo);
|
||||
connect(m_ui->pbDebugTriggerSnap, &QPushButton::clicked, this, &TimelineWidget::triggerSnap);
|
||||
connect(m_ui->sbDebugSnapStep, qOverload<int>(&QSpinBox::valueChanged), m_ui->view->timelineModel(),
|
||||
&TimelineModel::setSnapStep);
|
||||
connect(m_ui->sbDebugSnapTol, qOverload<int>(&QSpinBox::valueChanged), m_ui->view->timelineModel(),
|
||||
&TimelineModel::setSnapTolerance);
|
||||
connect(m_ui->pbDebugTriggerIndicator, &QPushButton::clicked, this, [this]() {
|
||||
m_ui->view->header()->setIndicatorVisible(!m_ui->view->header()->isIndicatorVisible());
|
||||
m_ui->pbDebugTriggerIndicator->setText(m_ui->view->header()->isIndicatorVisible()
|
||||
? QStringLiteral("Disable Indicator")
|
||||
: QStringLiteral("Enable Indicator"));
|
||||
});
|
||||
connect(m_ui->pbDebugTriggerHover, &QPushButton::clicked, this, [this]() {
|
||||
m_ui->view->header()->setHoverVisible(!m_ui->view->header()->isHoverVisible());
|
||||
m_ui->pbDebugTriggerHover->setText(m_ui->view->header()->isHoverVisible() ? QStringLiteral("Disable Hover")
|
||||
: QStringLiteral("Enable Hover"));
|
||||
});
|
||||
|
||||
onUpdateDebugInfo();
|
||||
onUpdateDebugInfo();
|
||||
}
|
||||
|
||||
void TimelineWidget::hideDebugWidget()
|
||||
{
|
||||
m_ui->debugWidget->hide();
|
||||
disconnect(m_ui->view, &TimelineView::currentTimeChanged, this, &TimelineWidget::onUpdateDebugInfo);
|
||||
disconnect(m_ui->view, &TimelineView::rangeChanged, this, &TimelineWidget::onUpdateDebugInfo);
|
||||
disconnect(m_ui->view, &TimelineView::selectedItemsChanged, this, &TimelineWidget::onUpdateDebugInfo);
|
||||
disconnect(m_ui->view, &TimelineView::zoomChanged, this, &TimelineWidget::onUpdateDebugInfo);
|
||||
disconnect(m_ui->pbDebugTriggerSnap, &QPushButton::clicked, this, &TimelineWidget::triggerSnap);
|
||||
disconnect(m_ui->sbDebugSnapStep, qOverload<int>(&QSpinBox::valueChanged), m_ui->view->timelineModel(), &TimelineModel::setSnapStep);
|
||||
disconnect(m_ui->sbDebugSnapTol, qOverload<int>(&QSpinBox::valueChanged), m_ui->view->timelineModel(), &TimelineModel::setSnapTolerance);
|
||||
disconnect(m_ui->pbDebugTriggerIndicator);
|
||||
disconnect(m_ui->pbDebugTriggerHover);
|
||||
m_ui->debugWidget->hide();
|
||||
disconnect(m_ui->view, &TimelineView::currentTimeChanged, this, &TimelineWidget::onUpdateDebugInfo);
|
||||
disconnect(m_ui->view, &TimelineView::rangeChanged, this, &TimelineWidget::onUpdateDebugInfo);
|
||||
disconnect(m_ui->view, &TimelineView::selectedItemsChanged, this, &TimelineWidget::onUpdateDebugInfo);
|
||||
disconnect(m_ui->view, &TimelineView::zoomChanged, this, &TimelineWidget::onUpdateDebugInfo);
|
||||
disconnect(m_ui->pbDebugTriggerSnap, &QPushButton::clicked, this, &TimelineWidget::triggerSnap);
|
||||
disconnect(m_ui->sbDebugSnapStep, qOverload<int>(&QSpinBox::valueChanged), m_ui->view->timelineModel(),
|
||||
&TimelineModel::setSnapStep);
|
||||
disconnect(m_ui->sbDebugSnapTol, qOverload<int>(&QSpinBox::valueChanged), m_ui->view->timelineModel(),
|
||||
&TimelineModel::setSnapTolerance);
|
||||
disconnect(m_ui->pbDebugTriggerIndicator);
|
||||
disconnect(m_ui->pbDebugTriggerHover);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void TimelineWidget::populateZoomFactorComboBox()
|
||||
{
|
||||
disconnect(m_ui->cbZoom, qOverload<int>(&QComboBox::currentIndexChanged),
|
||||
this, &TimelineWidget::onZoomSelected);
|
||||
m_ui->cbZoom->clear();
|
||||
QVector<ZoomFactor> availableZooms = Zoom::availableZoomFactors(m_ui->view->minimumZoomFactor(), m_ui->view->upperZoomFactor());
|
||||
for (ZoomFactor factor : std::as_const(availableZooms))
|
||||
{
|
||||
m_ui->cbZoom->addItem(Zoom::toString(factor), QVariant(factor));
|
||||
if (factor == zoomFactor())
|
||||
m_ui->cbZoom->setCurrentIndex(m_ui->cbZoom->findData(static_cast<int>(zoomFactor())));
|
||||
}
|
||||
connect(m_ui->cbZoom, qOverload<int>(&QComboBox::currentIndexChanged),
|
||||
this, &TimelineWidget::onZoomSelected);
|
||||
disconnect(m_ui->cbZoom, qOverload<int>(&QComboBox::currentIndexChanged), this, &TimelineWidget::onZoomSelected);
|
||||
m_ui->cbZoom->clear();
|
||||
QVector<ZoomFactor> availableZooms =
|
||||
Zoom::availableZoomFactors(m_ui->view->minimumZoomFactor(), m_ui->view->upperZoomFactor());
|
||||
for (ZoomFactor factor : std::as_const(availableZooms))
|
||||
{
|
||||
m_ui->cbZoom->addItem(Zoom::toString(factor), QVariant(factor));
|
||||
if (factor == zoomFactor())
|
||||
m_ui->cbZoom->setCurrentIndex(m_ui->cbZoom->findData(static_cast<int>(zoomFactor())));
|
||||
}
|
||||
connect(m_ui->cbZoom, qOverload<int>(&QComboBox::currentIndexChanged), this, &TimelineWidget::onZoomSelected);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void TimelineWidget::onSectionResized(int logicalIndex, int oldSize, int newSize)
|
||||
{
|
||||
Q_UNUSED(oldSize);
|
||||
if (logicalIndex == Section::eItems)
|
||||
{
|
||||
int width = m_ui->view->verticalScrollBar()->width();
|
||||
m_ui->slider->setMinimumHeight(width);
|
||||
m_ui->slider->setMaximumHeight(width);
|
||||
m_ui->slider->setMaximumWidth(newSize);
|
||||
m_ui->slider->setMinimumWidth(newSize);
|
||||
}
|
||||
Q_UNUSED(oldSize);
|
||||
if (logicalIndex == Section::eItems)
|
||||
{
|
||||
int width = m_ui->view->verticalScrollBar()->width();
|
||||
m_ui->slider->setMinimumHeight(width);
|
||||
m_ui->slider->setMaximumHeight(width);
|
||||
m_ui->slider->setMaximumWidth(newSize);
|
||||
m_ui->slider->setMinimumWidth(newSize);
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineWidget::onSliderValueChanged(int value)
|
||||
{
|
||||
setCurrentTime(qint64(value) * 1000);
|
||||
setCurrentTime(qint64(value) * 1000);
|
||||
}
|
||||
|
||||
void TimelineWidget::onUpdateZoomButtons()
|
||||
{
|
||||
m_ui->pbZoomIn->setEnabled(zoomFactor() > minimumZoomFactor());
|
||||
m_ui->pbZoomOut->setEnabled(zoomFactor() < m_ui->view->upperZoomFactor());
|
||||
populateZoomFactorComboBox();
|
||||
m_ui->pbZoomIn->setEnabled(zoomFactor() > minimumZoomFactor());
|
||||
m_ui->pbZoomOut->setEnabled(zoomFactor() < m_ui->view->upperZoomFactor());
|
||||
populateZoomFactorComboBox();
|
||||
}
|
||||
|
||||
void TimelineWidget::onZoomChanged(ZoomFactor factor)
|
||||
{
|
||||
m_ui->slider->setMaximum((m_ui->view->endTime() - m_ui->view->zoomFactor()) / 1000);
|
||||
m_ui->slider->setPageStep(factor / 1000);
|
||||
m_ui->slider->setSingleStep(Zoom::minorInterval(factor));
|
||||
onUpdateZoomButtons();
|
||||
if (static_cast<ZoomFactor>(m_ui->cbZoom->currentData().toInt()) != factor)
|
||||
m_ui->cbZoom->setCurrentIndex(m_ui->cbZoom->findData(QVariant(factor)));
|
||||
m_ui->slider->setMaximum((m_ui->view->endTime() - m_ui->view->zoomFactor()) / 1000);
|
||||
m_ui->slider->setPageStep(factor / 1000);
|
||||
m_ui->slider->setSingleStep(Zoom::minorInterval(factor));
|
||||
onUpdateZoomButtons();
|
||||
if (static_cast<ZoomFactor>(m_ui->cbZoom->currentData().toInt()) != factor)
|
||||
m_ui->cbZoom->setCurrentIndex(m_ui->cbZoom->findData(QVariant(factor)));
|
||||
}
|
||||
|
||||
void TimelineWidget::onZoomSelected()
|
||||
{
|
||||
ZoomFactor factor = static_cast<ZoomFactor>(m_ui->cbZoom->currentData().toInt());
|
||||
if (factor != zoomFactor())
|
||||
setZoomFactor(factor);
|
||||
ZoomFactor factor = static_cast<ZoomFactor>(m_ui->cbZoom->currentData().toInt());
|
||||
if (factor != zoomFactor())
|
||||
setZoomFactor(factor);
|
||||
}
|
||||
|
||||
void TimelineWidget::onZoomIn()
|
||||
{
|
||||
setZoomFactor(Zoom::decrement(zoomFactor()));
|
||||
setZoomFactor(Zoom::decrement(zoomFactor()));
|
||||
}
|
||||
|
||||
void TimelineWidget::onZoomOut()
|
||||
{
|
||||
setZoomFactor(Zoom::increment(zoomFactor()));
|
||||
setZoomFactor(Zoom::increment(zoomFactor()));
|
||||
}
|
||||
|
||||
|
||||
void TimelineWidget::onUpdateDebugInfo()
|
||||
{
|
||||
m_ui->lblDebugStart->setText(DateTime::toString(startTime(), DateTimeFormat::DTG));
|
||||
m_ui->lblDebugEnd->setText(DateTime::toString(endTime(), DateTimeFormat::DTG));
|
||||
m_ui->lblDebugDuration->setText(QString::number(duration() / 1000) + QStringLiteral("s"));
|
||||
m_ui->lblDebugCurrent->setText(DateTime::toString(currentTime(), DateTimeFormat::DTG));
|
||||
m_ui->lblDebugSlider->setText(DateTime::toString(qint64(m_ui->slider->value()) * 1000, DateTimeFormat::DTG));
|
||||
m_ui->lblDebugZoom->setText(Zoom::toString(m_ui->view->zoomFactor()));
|
||||
QString selection;
|
||||
for (int itemId : std::as_const(m_ui->view->selectedItemIds()))
|
||||
selection += QString::number(itemId) + QStringLiteral(", ");
|
||||
if (selection.size() > 1)
|
||||
selection.chop(2);
|
||||
m_ui->lblDebugSelection->setText(selection);
|
||||
m_ui->lblDebugStart->setText(DateTime::toString(startTime(), DateTimeFormat::DTG));
|
||||
m_ui->lblDebugEnd->setText(DateTime::toString(endTime(), DateTimeFormat::DTG));
|
||||
m_ui->lblDebugDuration->setText(QString::number(duration() / 1000) + QStringLiteral("s"));
|
||||
m_ui->lblDebugCurrent->setText(DateTime::toString(currentTime(), DateTimeFormat::DTG));
|
||||
m_ui->lblDebugSlider->setText(DateTime::toString(qint64(m_ui->slider->value()) * 1000, DateTimeFormat::DTG));
|
||||
m_ui->lblDebugZoom->setText(Zoom::toString(m_ui->view->zoomFactor()));
|
||||
QString selection;
|
||||
for (int itemId : std::as_const(m_ui->view->selectedItemIds()))
|
||||
selection += QString::number(itemId) + QStringLiteral(", ");
|
||||
if (selection.size() > 1)
|
||||
selection.chop(2);
|
||||
m_ui->lblDebugSelection->setText(selection);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsTimeline
|
||||
Executable → Regular
+57
-65
@@ -1,27 +1,21 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "ltstimeline_export.h"
|
||||
#include "timeline_utils.h"
|
||||
|
||||
#include "ltstimeline_export.h"
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
class QScrollBar;
|
||||
class QAbstractItemModel;
|
||||
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class Timeline;
|
||||
}
|
||||
|
||||
|
||||
namespace LtsTimeline
|
||||
{
|
||||
|
||||
@@ -29,87 +23,85 @@ class TimelineView;
|
||||
class TimelineHeaderView;
|
||||
class TimelineModel;
|
||||
|
||||
|
||||
class LTSTIMELINE_EXPORT TimelineWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TimelineWidget(QWidget *parent = nullptr);
|
||||
~TimelineWidget();
|
||||
public:
|
||||
explicit TimelineWidget(QWidget* parent = nullptr);
|
||||
~TimelineWidget();
|
||||
|
||||
TimelineView *view();
|
||||
TimelineView* view();
|
||||
|
||||
TimelineHeaderView *header();
|
||||
TimelineHeaderView* header();
|
||||
|
||||
TimelineModel *timelineModel();
|
||||
void setModel(QAbstractItemModel *model);
|
||||
TimelineModel* timelineModel();
|
||||
void setModel(QAbstractItemModel* model);
|
||||
|
||||
QScrollBar *slider();
|
||||
QScrollBar* slider();
|
||||
|
||||
ZoomFactor zoomFactor() const;
|
||||
void setZoomFactor(ZoomFactor factor);
|
||||
ZoomFactor zoomFactor() const;
|
||||
void setZoomFactor(ZoomFactor factor);
|
||||
|
||||
ZoomFactor minimumZoomFactor() const;
|
||||
void setMinimumZoomFactor(ZoomFactor factor);
|
||||
ZoomFactor minimumZoomFactor() const;
|
||||
void setMinimumZoomFactor(ZoomFactor factor);
|
||||
|
||||
ZoomFactor maximumZoomFactor() const;
|
||||
void setMaximumZoomFactor(ZoomFactor factor);
|
||||
ZoomFactor maximumZoomFactor() const;
|
||||
void setMaximumZoomFactor(ZoomFactor factor);
|
||||
|
||||
qint64 startTime() const;
|
||||
void setStartTime(qint64 time);
|
||||
qint64 startTime() const;
|
||||
void setStartTime(qint64 time);
|
||||
|
||||
qint64 currentTime() const;
|
||||
void setCurrentTime(qint64 time);
|
||||
qint64 currentTime() const;
|
||||
void setCurrentTime(qint64 time);
|
||||
|
||||
qint64 endTime() const;
|
||||
void setEndTime(qint64 time);
|
||||
qint64 endTime() const;
|
||||
void setEndTime(qint64 time);
|
||||
|
||||
int duration() const;
|
||||
void setDuration(int duration);
|
||||
int duration() const;
|
||||
void setDuration(int duration);
|
||||
|
||||
bool isCursorTextVisible() const;
|
||||
void setCursorTextVisible(bool visible);
|
||||
void setCursorText(const QString &text);
|
||||
void setCursorText(const QStringList &texts);
|
||||
bool isCursorTextVisible() const;
|
||||
void setCursorTextVisible(bool visible);
|
||||
void setCursorText(const QString& text);
|
||||
void setCursorText(const QStringList& texts);
|
||||
|
||||
bool isSnapEnabled() const;
|
||||
void setSnapEnabled(bool enabled);
|
||||
void enableSnap();
|
||||
void disableSnap();
|
||||
void triggerSnap();
|
||||
bool isSnapEnabled() const;
|
||||
void setSnapEnabled(bool enabled);
|
||||
void enableSnap();
|
||||
void disableSnap();
|
||||
void triggerSnap();
|
||||
|
||||
void setZoomInIcon(QIcon icon);
|
||||
void setZoomOutIcon(QIcon icon);
|
||||
void setZoomInIcon(QIcon icon);
|
||||
void setZoomOutIcon(QIcon icon);
|
||||
|
||||
QWidget *placeholder();
|
||||
void setPlaceholder(QWidget *widget);
|
||||
QWidget* placeholder();
|
||||
void setPlaceholder(QWidget* widget);
|
||||
|
||||
void showDebugWidget();
|
||||
void hideDebugWidget();
|
||||
void showDebugWidget();
|
||||
void hideDebugWidget();
|
||||
|
||||
private:
|
||||
private:
|
||||
NGL::INGLLogger& m_logger;
|
||||
void populateZoomFactorComboBox();
|
||||
|
||||
NGL::INGLLogger &m_logger;
|
||||
void populateZoomFactorComboBox();
|
||||
public:
|
||||
void onUpdateZoomButtons();
|
||||
|
||||
public:
|
||||
void onUpdateZoomButtons();
|
||||
private slots:
|
||||
void onSectionResized(int logicalIndex, int oldSize, int newSize);
|
||||
void onSliderValueChanged(int value);
|
||||
void onZoomChanged(ZoomFactor factor);
|
||||
void onZoomSelected();
|
||||
void onZoomIn();
|
||||
void onZoomOut();
|
||||
|
||||
private slots:
|
||||
void onSectionResized(int logicalIndex, int oldSize, int newSize);
|
||||
void onSliderValueChanged(int value);
|
||||
void onZoomChanged(ZoomFactor factor);
|
||||
void onZoomSelected();
|
||||
void onZoomIn();
|
||||
void onZoomOut();
|
||||
void onUpdateDebugInfo();
|
||||
|
||||
void onUpdateDebugInfo();
|
||||
signals:
|
||||
|
||||
signals:
|
||||
|
||||
private:
|
||||
Ui::Timeline *m_ui{nullptr};
|
||||
private:
|
||||
Ui::Timeline* m_ui{nullptr};
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsTimeline
|
||||
Executable → Regular
+411
-642
File diff suppressed because it is too large.
Load diff
Executable → Regular
+235
-212
@@ -1,20 +1,15 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "item.h"
|
||||
|
||||
#include "ltstimeline_export.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QSet>
|
||||
#include <QVariant>
|
||||
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
||||
namespace LtsTimeline
|
||||
{
|
||||
class Track;
|
||||
@@ -26,238 +21,266 @@ typedef std::vector<TrackPtr> Tracks;
|
||||
typedef std::reference_wrapper<TrackPtr> TrackPtrRef;
|
||||
typedef std::vector<TrackPtrRef> TrackPtrRefs;
|
||||
|
||||
|
||||
class LTSTIMELINE_EXPORT Track
|
||||
{
|
||||
public:
|
||||
Track(const QString &text = {})
|
||||
: m_text(text)
|
||||
{}
|
||||
public:
|
||||
Track(const QString& text = {}) : m_text(text) {}
|
||||
|
||||
Track(const QString &text, int specialTrackType)
|
||||
: m_text(text)
|
||||
, m_userData(specialTrackType)
|
||||
{}
|
||||
Track(const QString& text, int specialTrackType) : m_text(text), m_userData(specialTrackType) {}
|
||||
|
||||
Track(const Track &) = delete;
|
||||
Track &operator=(const Track &) = delete;
|
||||
Track(Track &&t) noexcept = default;
|
||||
virtual ~Track() = default;
|
||||
Track(const Track&) = delete;
|
||||
Track& operator=(const Track&) = delete;
|
||||
Track(Track&& t) noexcept = default;
|
||||
virtual ~Track() = default;
|
||||
|
||||
[[deprecated("Use model's track(int) instead.")]] const Track &track(int id) const noexcept(false);
|
||||
[[deprecated("Use model's track(int) instead.")]] Track &track(int id) noexcept(false);
|
||||
[[deprecated("Use model's item(int) instead.")]] Item &item(int id) noexcept(false);
|
||||
[[deprecated("Use model's item(int) instead.")]] const Item &item(int id) const noexcept(false);
|
||||
Item &previous(int id) noexcept(false);
|
||||
Item &next(int id) noexcept(false);
|
||||
|
||||
const Item ©ItemAt(qint64 time) const noexcept(false);
|
||||
Item &itemAt(qint64 time) noexcept(false);
|
||||
const Item &itemAt(qint64 time) const noexcept(false);
|
||||
Track &trackAt(int index) noexcept(false);
|
||||
const Track &trackAt(int index) const noexcept(false);
|
||||
bool hasTrack(int id, bool recursive = false) const;
|
||||
bool hasTracks() const { return !m_childrenTracks.empty(); }
|
||||
int rowOfTrack(int id) const noexcept(false);
|
||||
const Track &parentOf(int id) const noexcept(false);
|
||||
|
||||
|
||||
const QSet<int> ©ItemIds() const { return m_copyItemIds; }
|
||||
void clearCopyItemIds() { m_copyItemIds.clear(); }
|
||||
void addCopyItemIds(const QSet<int> &ids);
|
||||
void addCopyItemId(int id);
|
||||
bool hasItems() const { return !m_items.empty(); }
|
||||
bool hasCopyItems() const { return !m_copyItemIds.empty(); }
|
||||
int itemCount() const { return m_items.size(); }
|
||||
Items &items() { return m_items; }
|
||||
const Items &items() const { return m_items; }
|
||||
int trackCount() const { return m_childrenTracks.size(); }
|
||||
Tracks &tracks() { return m_childrenTracks; }
|
||||
const Tracks &tracks() const { return m_childrenTracks; }
|
||||
QVector<int> itemIds(bool recursive = false, bool sorted = false) const;
|
||||
const QVector<int> itemIdsBetween(qint64 start, qint64 end, bool strict = false, bool complete = false, bool recursive = false, bool sorted = false, qint64 minimumDuration = 0) const;
|
||||
[[deprecated]] const QVector<int> copyItemIdsBetween(qint64 start, qint64 end, bool strict = false, bool complete = false, bool recursive = false, bool sorted = false, qint64 minimumDuration = 0) const;
|
||||
bool isItemsBetween(qint64 start, qint64 end, const QVector<int> &ignoreIds, bool strict = false, bool complete = false, bool recursive = false, qint64 minimumDuration = 0) const;
|
||||
bool isItemsBetween(qint64 start, qint64 end, int ignoreId, bool strict = false, bool complete = false, bool recursive = false, qint64 minimumDuration = 0) const;
|
||||
|
||||
|
||||
int id() const { return m_id; }
|
||||
virtual const QString text() const { return m_text; }
|
||||
int parent() const { return m_parentId; }
|
||||
int parentId() const { return m_parentId; }
|
||||
void printTrackIds(bool withItems = false, int level = 0) const;
|
||||
void removeCopyItem(int itemId) noexcept(false);
|
||||
void removeItem(int itemId) noexcept(false);
|
||||
ItemPtr takeItem(int itemId) noexcept(false);
|
||||
QVariant userData() const { return m_userData; }
|
||||
void setUserData(const QVariant &data) { m_userData = data; }
|
||||
[[deprecated("Use model's track(int) instead.")]] const Track& track(int id) const noexcept(false);
|
||||
[[deprecated("Use model's track(int) instead.")]] Track& track(int id) noexcept(false);
|
||||
[[deprecated("Use model's item(int) instead.")]] Item& item(int id) noexcept(false);
|
||||
[[deprecated("Use model's item(int) instead.")]] const Item& item(int id) const noexcept(false);
|
||||
Item& previous(int id) noexcept(false);
|
||||
Item& next(int id) noexcept(false);
|
||||
|
||||
const Item& copyItemAt(qint64 time) const noexcept(false);
|
||||
Item& itemAt(qint64 time) noexcept(false);
|
||||
const Item& itemAt(qint64 time) const noexcept(false);
|
||||
Track& trackAt(int index) noexcept(false);
|
||||
const Track& trackAt(int index) const noexcept(false);
|
||||
bool hasTrack(int id, bool recursive = false) const;
|
||||
|
||||
inline static void sort(Items &items)
|
||||
{
|
||||
std::sort(items.begin(), items.end(), [](const ItemPtr &itemA, const ItemPtr &itemB)
|
||||
bool hasTracks() const
|
||||
{
|
||||
return itemA->startTime() < itemB->startTime();
|
||||
});
|
||||
}
|
||||
return !m_childrenTracks.empty();
|
||||
}
|
||||
|
||||
int rowOfTrack(int id) const noexcept(false);
|
||||
const Track& parentOf(int id) const noexcept(false);
|
||||
|
||||
inline static void sort(ItemPtrNCVRefs &items)
|
||||
{
|
||||
std::sort(items.begin(), items.end(), [](const ItemPtrNCVRef &itemA, const ItemPtrNCVRef &itemB)
|
||||
const QSet<int>& copyItemIds() const
|
||||
{
|
||||
return itemA.get()->startTime() < itemB.get()->startTime();
|
||||
});
|
||||
}
|
||||
return m_copyItemIds;
|
||||
}
|
||||
|
||||
|
||||
inline static void sort(ItemPtrRefs &items)
|
||||
{
|
||||
std::sort(items.begin(), items.end(), [](const ItemPtrRef &itemA, const ItemPtrRef &itemB)
|
||||
void clearCopyItemIds()
|
||||
{
|
||||
return itemA.get()->startTime() < itemB.get()->startTime();
|
||||
});
|
||||
}
|
||||
m_copyItemIds.clear();
|
||||
}
|
||||
|
||||
bool hasInsertButton() const { return m_hasInsertButton; }
|
||||
void setInsertButton(bool hasButton) { m_hasInsertButton = hasButton; }
|
||||
bool hasRemoveButton() const { return m_hasRemoveButton; }
|
||||
void setRemoveButton(bool hasButton) { m_hasRemoveButton = hasButton; }
|
||||
void addCopyItemIds(const QSet<int>& ids);
|
||||
void addCopyItemId(int id);
|
||||
|
||||
|
||||
protected:
|
||||
QString m_text;
|
||||
QVariant m_userData;
|
||||
|
||||
|
||||
private:
|
||||
void removeTrack(int trackId) noexcept(false);
|
||||
void addItemPtr(ItemPtr &&itemPtr);
|
||||
|
||||
static bool isItemBetween(const Item &item, qint64 start, qint64 end, bool strict, bool complete, qint64 minimumDuration = 0);
|
||||
ItemPtrRefs _copyItems() const;
|
||||
ItemPtrRefs _items(bool recursive) const;
|
||||
ItemPtrNCVRefs _itemsNCV(bool recursive);
|
||||
ItemPtrNCVRef _itemNCV(int id) noexcept(false);
|
||||
ItemPtrRef _item(int id) const noexcept(false);
|
||||
const QVector<int> _itemIds(bool recursive) const;
|
||||
|
||||
|
||||
public:
|
||||
void clearItems() { m_items.clear(); }
|
||||
private:
|
||||
|
||||
friend class TimelineModel;
|
||||
|
||||
|
||||
void sort()
|
||||
{
|
||||
sort(m_items);
|
||||
}
|
||||
|
||||
|
||||
template <typename TrackClass>
|
||||
Track *addTrack(TrackClass &&trackClass)
|
||||
{
|
||||
TrackClass _trackClass = std::move(trackClass);
|
||||
m_childrenTracks.push_back(std::move(std::move(std::make_unique<TrackClass>(std::move(_trackClass)))));
|
||||
return m_childrenTracks.back().get();
|
||||
}
|
||||
|
||||
|
||||
template <typename TrackClass>
|
||||
[[deprecated("Use model's track(...) and call addTrack(TrackClass) directly on that track.")]]
|
||||
Track *addTrack(int parentTrackId, TrackClass &&trackClass) noexcept(false)
|
||||
{
|
||||
if (m_id == parentTrackId)
|
||||
return addTrack<TrackClass>(std::move(trackClass));
|
||||
|
||||
return track(parentTrackId).addTrack(std::move(trackClass));
|
||||
}
|
||||
|
||||
|
||||
template <typename ItemClass>
|
||||
Item *addItem(ItemClass &&itemClass)
|
||||
{
|
||||
ItemClass _itemClass(std::move(itemClass));
|
||||
|
||||
auto it = m_items.insert(std::upper_bound(m_items.begin(), m_items.end(), _itemClass.startTime(),
|
||||
[](qint64 startTime, const ItemPtr &other)
|
||||
bool hasItems() const
|
||||
{
|
||||
return (other->startTime() > startTime);
|
||||
}), std::move(std::make_unique<ItemClass>(std::move(_itemClass))));
|
||||
return !m_items.empty();
|
||||
}
|
||||
|
||||
return it->get();
|
||||
}
|
||||
|
||||
|
||||
Item *addItem(ItemPtr &&itemPtr)
|
||||
{
|
||||
auto it = m_items.insert(std::upper_bound(m_items.begin(), m_items.end(), itemPtr->startTime(),
|
||||
[](qint64 startTime, const ItemPtr &other)
|
||||
bool hasCopyItems() const
|
||||
{
|
||||
return (other->startTime() > startTime);
|
||||
}), std::move(itemPtr));
|
||||
return !m_copyItemIds.empty();
|
||||
}
|
||||
|
||||
return it->get();
|
||||
}
|
||||
|
||||
|
||||
template <typename ItemContainer>
|
||||
[[deprecated]]
|
||||
QVector<int> transformItemPtrsToIds(const ItemContainer &itemContainer) const
|
||||
{
|
||||
QVector<int> ids;
|
||||
std::transform(itemContainer.cbegin(), itemContainer.cend(), std::back_inserter(ids),
|
||||
[](const ItemPtr &itemPtr) -> int
|
||||
int itemCount() const
|
||||
{
|
||||
return itemPtr->id();
|
||||
});
|
||||
return ids;
|
||||
}
|
||||
return m_items.size();
|
||||
}
|
||||
|
||||
Items& items()
|
||||
{
|
||||
return m_items;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const Items& items() const
|
||||
{
|
||||
return m_items;
|
||||
}
|
||||
|
||||
int trackCount() const
|
||||
{
|
||||
return m_childrenTracks.size();
|
||||
}
|
||||
|
||||
int m_id { -1 };
|
||||
Tracks m_childrenTracks;
|
||||
Items m_items;
|
||||
int m_parentId { -1 };
|
||||
bool m_hasInsertButton { false };
|
||||
bool m_hasRemoveButton { false };
|
||||
Tracks& tracks()
|
||||
{
|
||||
return m_childrenTracks;
|
||||
}
|
||||
|
||||
const Tracks& tracks() const
|
||||
{
|
||||
return m_childrenTracks;
|
||||
}
|
||||
|
||||
QSet<int> m_copyItemIds;
|
||||
QVector<int> itemIds(bool recursive = false, bool sorted = false) const;
|
||||
const QVector<int> itemIdsBetween(qint64 start, qint64 end, bool strict = false, bool complete = false,
|
||||
bool recursive = false, bool sorted = false, qint64 minimumDuration = 0) const;
|
||||
[[deprecated]] const QVector<int> copyItemIdsBetween(qint64 start, qint64 end, bool strict = false,
|
||||
bool complete = false, bool recursive = false,
|
||||
bool sorted = false, qint64 minimumDuration = 0) const;
|
||||
bool isItemsBetween(qint64 start, qint64 end, const QVector<int>& ignoreIds, bool strict = false,
|
||||
bool complete = false, bool recursive = false, qint64 minimumDuration = 0) const;
|
||||
bool isItemsBetween(qint64 start, qint64 end, int ignoreId, bool strict = false, bool complete = false,
|
||||
bool recursive = false, qint64 minimumDuration = 0) const;
|
||||
|
||||
int id() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
virtual const QString text() const
|
||||
{
|
||||
return m_text;
|
||||
}
|
||||
|
||||
int parent() const
|
||||
{
|
||||
return m_parentId;
|
||||
}
|
||||
|
||||
int parentId() const
|
||||
{
|
||||
return m_parentId;
|
||||
}
|
||||
|
||||
void printTrackIds(bool withItems = false, int level = 0) const;
|
||||
void removeCopyItem(int itemId) noexcept(false);
|
||||
void removeItem(int itemId) noexcept(false);
|
||||
ItemPtr takeItem(int itemId) noexcept(false);
|
||||
|
||||
QVariant userData() const
|
||||
{
|
||||
return m_userData;
|
||||
}
|
||||
|
||||
void setUserData(const QVariant& data)
|
||||
{
|
||||
m_userData = data;
|
||||
}
|
||||
|
||||
inline static void sort(Items& items)
|
||||
{
|
||||
std::sort(items.begin(), items.end(),
|
||||
[](const ItemPtr& itemA, const ItemPtr& itemB) { return itemA->startTime() < itemB->startTime(); });
|
||||
}
|
||||
|
||||
inline static void sort(ItemPtrNCVRefs& items)
|
||||
{
|
||||
std::sort(items.begin(), items.end(), [](const ItemPtrNCVRef& itemA, const ItemPtrNCVRef& itemB) {
|
||||
return itemA.get()->startTime() < itemB.get()->startTime();
|
||||
});
|
||||
}
|
||||
|
||||
inline static void sort(ItemPtrRefs& items)
|
||||
{
|
||||
std::sort(items.begin(), items.end(), [](const ItemPtrRef& itemA, const ItemPtrRef& itemB) {
|
||||
return itemA.get()->startTime() < itemB.get()->startTime();
|
||||
});
|
||||
}
|
||||
|
||||
bool hasInsertButton() const
|
||||
{
|
||||
return m_hasInsertButton;
|
||||
}
|
||||
|
||||
void setInsertButton(bool hasButton)
|
||||
{
|
||||
m_hasInsertButton = hasButton;
|
||||
}
|
||||
|
||||
bool hasRemoveButton() const
|
||||
{
|
||||
return m_hasRemoveButton;
|
||||
}
|
||||
|
||||
void setRemoveButton(bool hasButton)
|
||||
{
|
||||
m_hasRemoveButton = hasButton;
|
||||
}
|
||||
|
||||
protected:
|
||||
QString m_text;
|
||||
QVariant m_userData;
|
||||
|
||||
private:
|
||||
void removeTrack(int trackId) noexcept(false);
|
||||
void addItemPtr(ItemPtr&& itemPtr);
|
||||
|
||||
static bool isItemBetween(const Item& item, qint64 start, qint64 end, bool strict, bool complete,
|
||||
qint64 minimumDuration = 0);
|
||||
ItemPtrRefs _copyItems() const;
|
||||
ItemPtrRefs _items(bool recursive) const;
|
||||
ItemPtrNCVRefs _itemsNCV(bool recursive);
|
||||
ItemPtrNCVRef _itemNCV(int id) noexcept(false);
|
||||
ItemPtrRef _item(int id) const noexcept(false);
|
||||
const QVector<int> _itemIds(bool recursive) const;
|
||||
|
||||
public:
|
||||
void clearItems()
|
||||
{
|
||||
m_items.clear();
|
||||
}
|
||||
|
||||
private:
|
||||
friend class TimelineModel;
|
||||
|
||||
void sort()
|
||||
{
|
||||
sort(m_items);
|
||||
}
|
||||
|
||||
template <typename TrackClass> Track* addTrack(TrackClass&& trackClass)
|
||||
{
|
||||
TrackClass _trackClass = std::move(trackClass);
|
||||
m_childrenTracks.push_back(std::move(std::move(std::make_unique<TrackClass>(std::move(_trackClass)))));
|
||||
return m_childrenTracks.back().get();
|
||||
}
|
||||
|
||||
template <typename TrackClass>
|
||||
[[deprecated("Use model's track(...) and call addTrack(TrackClass) directly on that track.")]] Track*
|
||||
addTrack(int parentTrackId, TrackClass&& trackClass) noexcept(false)
|
||||
{
|
||||
if (m_id == parentTrackId)
|
||||
return addTrack<TrackClass>(std::move(trackClass));
|
||||
|
||||
return track(parentTrackId).addTrack(std::move(trackClass));
|
||||
}
|
||||
|
||||
template <typename ItemClass> Item* addItem(ItemClass&& itemClass)
|
||||
{
|
||||
ItemClass _itemClass(std::move(itemClass));
|
||||
|
||||
auto it = m_items.insert(
|
||||
std::upper_bound(m_items.begin(), m_items.end(), _itemClass.startTime(),
|
||||
[](qint64 startTime, const ItemPtr& other) { return (other->startTime() > startTime); }),
|
||||
std::move(std::make_unique<ItemClass>(std::move(_itemClass))));
|
||||
|
||||
return it->get();
|
||||
}
|
||||
|
||||
Item* addItem(ItemPtr&& itemPtr)
|
||||
{
|
||||
auto it = m_items.insert(
|
||||
std::upper_bound(m_items.begin(), m_items.end(), itemPtr->startTime(),
|
||||
[](qint64 startTime, const ItemPtr& other) { return (other->startTime() > startTime); }),
|
||||
std::move(itemPtr));
|
||||
|
||||
return it->get();
|
||||
}
|
||||
|
||||
template <typename ItemContainer>
|
||||
[[deprecated]] QVector<int> transformItemPtrsToIds(const ItemContainer& itemContainer) const
|
||||
{
|
||||
QVector<int> ids;
|
||||
std::transform(itemContainer.cbegin(), itemContainer.cend(), std::back_inserter(ids),
|
||||
[](const ItemPtr& itemPtr) -> int { return itemPtr->id(); });
|
||||
return ids;
|
||||
}
|
||||
|
||||
int m_id{-1};
|
||||
Tracks m_childrenTracks;
|
||||
Items m_items;
|
||||
int m_parentId{-1};
|
||||
bool m_hasInsertButton{false};
|
||||
bool m_hasRemoveButton{false};
|
||||
|
||||
QSet<int> m_copyItemIds;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace LtsTimeline
|
||||
Reference in new issue
Block a user