Commit 0f45483c authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Preliminary implementation of Bin clip hover seeking (using shift+hover)

Related to #287
parent 3799402b
Pipeline #5180 passed with stage
in 34 minutes and 31 seconds
......@@ -205,6 +205,7 @@ public:
decoWidth += r.width() + textMargin;
r.setWidth(r.height() * pix.width() / pix.height());
painter->drawPixmap(r, pix, QRect(0, 0, pix.width(), pix.height()));
m_thumbRect = r;
}
int mid = (int)((r1.height() / 2));
r1.adjust(decoWidth, 0, 0, -mid);
......@@ -305,11 +306,20 @@ public:
QStyledItemDelegate::paint(painter, option, index);
}
}
int getFrame(QModelIndex index, int mouseX)
{
int type = index.data(AbstractProjectItem::ItemTypeRole).toInt();
if (type != AbstractProjectItem::ClipItem || mouseX < m_thumbRect.x() || mouseX > m_thumbRect.right()) {
return 0;
}
return 100 * (mouseX - m_thumbRect.x()) / m_thumbRect.width();
}
private:
mutable bool m_editorOpen{false};
mutable QRect m_audioDragRect;
mutable QRect m_videoDragRect;
mutable QRect m_thumbRect;
double m_dar{1.778};
public:
......@@ -374,6 +384,13 @@ void MyTreeView::mouseMoveEvent(QMouseEvent *event)
if (distance >= QApplication::startDragDistance()) {
dragged = performDrag();
}
} else if (event->modifiers() == Qt::ShiftModifier) {
QModelIndex index = indexAt(event->pos());
if (index.isValid()) {
QAbstractItemDelegate *del = itemDelegate(index);
int frame = static_cast<BinItemDelegate *>(del)->getFrame(index, event->pos().x());
emit displayBinFrame(index, frame);
}
}
if (!dragged) {
QTreeView::mouseMoveEvent(event);
......@@ -1375,6 +1392,7 @@ void Bin::slotInitView(QAction *action)
view->setWordWrap(true);
connect(m_proxyModel, &QAbstractItemModel::layoutAboutToBeChanged, this, &Bin::slotSetSorting);
connect(view, &MyTreeView::updateDragMode, m_itemModel.get(), &ProjectItemModel::setDragType, Qt::DirectConnection);
connect(view, &MyTreeView::displayBinFrame, this, &Bin::showBinFrame);
m_proxyModel->setDynamicSortFilter(true);
if (!m_headerInfo.isEmpty()) {
view->header()->restoreState(m_headerInfo);
......@@ -3170,3 +3188,14 @@ void Bin::adjustProjectProfileToItem()
}
}
}
void Bin::showBinFrame(QModelIndex ix, int frame)
{
std::shared_ptr<AbstractProjectItem> item = m_itemModel->getBinItemByIndex(m_proxyModel->mapToSource(ix));
if (item && item->itemType() == AbstractProjectItem::ClipItem) {
auto clip = std::static_pointer_cast<ProjectClip>(item);
if (clip) {
clip->getThumbFromPercent(frame);
}
}
}
......@@ -108,6 +108,7 @@ private:
signals:
void focusView();
void updateDragMode(PlaylistState::ClipState type);
void displayBinFrame(QModelIndex ix, int frame);
};
class SmallJobLabel : public QPushButton
......@@ -312,6 +313,9 @@ private slots:
* this is a workaround foq Qt bug 54676
*/
void showClearButton(bool show);
/** @brief Display a defined frame in bin clip thumbnail
*/
void showBinFrame(QModelIndex ix, int frame);
public slots:
void slotRemoveInvalidClip(const QString &id, bool replace, const QString &errorMessage);
......
......@@ -1395,3 +1395,18 @@ void ProjectClip::updateZones()
QJsonDocument json(list);
setProducerProperty(QStringLiteral("kdenlive:clipzones"), QString(json.toJson()));
}
void ProjectClip::getThumbFromPercent(int percent)
{
// extract a maximum of 25 frames for bin preview
percent /= 4;
int framePos = getFramePlaytime() * percent / 25;
if (ThumbnailCache::get()->hasThumbnail(m_binId, framePos)) {
setThumbnail(ThumbnailCache::get()->getThumbnail(m_binId, framePos));
} else {
// Generate percent thumbs
//TODO: Generate bin cache whithout creating a job for each thumb
pCore->jobManager()->startJob<ThumbJob>({m_binId}, -1, QString(), 150, framePos, true, false);
}
}
......@@ -220,6 +220,9 @@ public:
/** @brief Saves the subclips data as json
*/
void updateZones();
/** @brief Display Bin thumbnail given a percent
*/
void getThumbFromPercent(int percent);
protected:
friend class ClipModel;
......
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