- 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>
172 lines
5.6 KiB
C++
172 lines
5.6 KiB
C++
|
|
|
|
#include "item_delegate.h"
|
|
|
|
#include "item.h"
|
|
#include "timeline_view.h"
|
|
#include "track.h"
|
|
|
|
#include <QDebug>
|
|
#include <QGuiApplication>
|
|
#include <QModelIndex>
|
|
#include <QPainter>
|
|
#include <QRect>
|
|
|
|
namespace LtsTimeline
|
|
{
|
|
|
|
ItemDelegate::ItemDelegate(TimelineView* parent)
|
|
: QStyledItemDelegate(parent), m_view(parent), m_pushButton(new QPushButton), m_pushButtonPressed(new QPushButton)
|
|
{
|
|
m_pushButtonPressed->setDown(true);
|
|
}
|
|
|
|
ItemDelegate::~ItemDelegate()
|
|
{
|
|
m_pushButton->deleteLater();
|
|
m_pushButton = nullptr;
|
|
m_pushButtonPressed->deleteLater();
|
|
m_pushButtonPressed = nullptr;
|
|
}
|
|
|
|
QSize ItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
|
|
{
|
|
Q_UNUSED(option);
|
|
Q_UNUSED(index);
|
|
return QSize(100, 50);
|
|
}
|
|
|
|
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);
|
|
painter->restore();
|
|
return;
|
|
}
|
|
|
|
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
|