Add Audio/Video drag icons in icon view.

CCBUG: 415454
parent 48069b06
Pipeline #12374 passed with stage
in 20 minutes and 11 seconds
......@@ -283,7 +283,7 @@ public:
}
}
} else {
// Folder or Folder Up items
// Folder
int decoWidth = 0;
if (opt.decorationSize.height() > 0) {
r.setWidth(r.height() * m_dar);
......@@ -338,17 +338,56 @@ public:
connect(this, &QStyledItemDelegate::closeEditor, [&]() { m_editorOpen = false; });
}
void setDar(double dar) { m_dar = dar; }
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override
{
Q_UNUSED(model);
Q_UNUSED(option);
Q_UNUSED(index);
if (event->type() == QEvent::MouseButtonPress) {
auto *me = (QMouseEvent *)event;
if (m_audioDragRect.contains(me->pos())) {
dragType = PlaylistState::AudioOnly;
} else if (m_videoDragRect.contains(me->pos())) {
dragType = PlaylistState::VideoOnly;
} else {
dragType = PlaylistState::Disabled;
}
}
event->ignore();
return false;
}
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
{
if (!index.data().isNull()) {
QStyleOptionViewItem opt = option;
QStyleOptionViewItem opt(option);
initStyleOption(&opt, index);
QStyledItemDelegate::paint(painter, option, index);
int adjust = (opt.rect.width() - opt.decorationSize.width()) / 2;
QRect rect(0, 0, opt.rect.width(), opt.rect.height());
QRect rect(opt.rect.x(), opt.rect.y(), opt.decorationSize.width(), opt.decorationSize.height());
m_thumbRect = adjust > 0 && adjust < rect.width() ? rect.adjusted(adjust, 0, -adjust, 0) : rect;
QStyledItemDelegate::paint(painter, option, index);
// Add audio/video icons for selective drag
int cType = index.data(AbstractProjectItem::ClipType).toInt();
bool hasAudioAndVideo = index.data(AbstractProjectItem::ClipHasAudioAndVideo).toBool();
if (hasAudioAndVideo && (cType == ClipType::AV || cType == ClipType::Playlist) && (opt.state & QStyle::State_MouseOver)) {
QRect thumbRect = m_thumbRect;
int iconSize = painter->boundingRect(thumbRect, Qt::AlignLeft, QStringLiteral("O")).height();
thumbRect.setLeft(opt.rect.right() - iconSize - 4);
thumbRect.setWidth(iconSize);
thumbRect.setBottom(m_thumbRect.top() + iconSize);
QIcon aDrag = QIcon::fromTheme(QStringLiteral("audio-volume-medium"));
m_audioDragRect = thumbRect;
aDrag.paint(painter, m_audioDragRect, Qt::AlignRight);
m_videoDragRect = m_audioDragRect;
m_videoDragRect.moveTop(thumbRect.bottom());
QIcon vDrag = QIcon::fromTheme(QStringLiteral("kdenlive-show-video"));
vDrag.paint(painter, m_videoDragRect, Qt::AlignRight);
} else {
//m_audioDragRect = QRect();
//m_videoDragRect = QRect();
}
}
}
......@@ -394,6 +433,22 @@ void MyListView::focusInEvent(QFocusEvent *event)
}
}
void MyListView::mousePressEvent(QMouseEvent *event)
{
QListView::mousePressEvent(event);
if (event->button() == Qt::LeftButton) {
m_startPos = event->pos();
QModelIndex ix = indexAt(m_startPos);
if (ix.isValid()) {
QAbstractItemDelegate *del = itemDelegate(ix);
m_dragType = static_cast<BinListItemDelegate *>(del)->dragType;
} else {
m_dragType = PlaylistState::Disabled;
}
emit updateDragMode(m_dragType);
}
}
void MyListView::mouseMoveEvent(QMouseEvent *event)
{
if (event->modifiers() == Qt::ShiftModifier) {
......@@ -1498,6 +1553,7 @@ void Bin::slotInitView(QAction *action)
} else if (m_listType == BinIconView) {
m_itemView->setItemDelegate(m_binListViewDelegate);
auto *view = static_cast<MyListView *>(m_itemView);
connect(view, &MyListView::updateDragMode, m_itemModel.get(), &ProjectItemModel::setDragType, Qt::DirectConnection);
view->setGridSize(QSize(zoom.width() * 1.2, zoom.width()));
connect(view, &MyListView::focusView, this, &Bin::slotGotFocus);
connect(view, &MyListView::displayBinFrame, this, &Bin::showBinFrame);
......
......@@ -72,12 +72,16 @@ public:
explicit MyListView(QWidget *parent = nullptr);
protected:
void mousePressEvent(QMouseEvent *event) override;
void focusInEvent(QFocusEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
signals:
void focusView();
void updateDragMode(ClipType::ProducerType type);
void updateDragMode(PlaylistState::ClipState type);
void displayBinFrame(QModelIndex ix, int frame);
private:
QPoint m_startPos;
PlaylistState::ClipState m_dragType;
};
class MyTreeView : public QTreeView
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment