Commit 7bffc9fa authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Project bin:when hover seek is enabled, restore thumb after seeking, set thumb with shift+seek

parent 273f1238
......@@ -375,9 +375,12 @@ public:
int getFrame(QModelIndex index, int mouseX)
{
int type = index.data(AbstractProjectItem::ItemTypeRole).toInt();
if ((type != AbstractProjectItem::ClipItem && type != AbstractProjectItem::SubClipItem) || mouseX < m_thumbRect.x() || mouseX > m_thumbRect.right()) {
if ((type != AbstractProjectItem::ClipItem && type != AbstractProjectItem::SubClipItem)) {
return 0;
}
if (mouseX < m_thumbRect.x() || mouseX > m_thumbRect.right()) {
return -1;
}
return 100 * (mouseX - m_thumbRect.x()) / m_thumbRect.width();
}
......@@ -578,20 +581,34 @@ void MyListView::mouseMoveEvent(QMouseEvent *event)
{
QModelIndex index = indexAt(event->pos());
if (index.isValid()) {
QAbstractItemDelegate *del = itemDelegate(index);
if (KdenliveSettings::hoverPreview()) {
QAbstractItemDelegate *del = itemDelegate(index);
if (del) {
auto delegate = static_cast<BinListItemDelegate *>(del);
QRect vRect = visualRect(index);
int frame = delegate->getFrame(index, event->pos().x() - vRect.x());
emit displayBinFrame(index, frame);
if (vRect.contains(event->pos())) {
int frame = delegate->getFrame(index, event->pos().x() - vRect.x());
emit displayBinFrame(index, frame, event->modifiers() & Qt::ShiftModifier);
}
} else {
qDebug()<<"<<< NO DELEGATE!!!";
}
if (m_lastHoveredItem != index) {
if (m_lastHoveredItem.isValid()) {
emit displayBinFrame(m_lastHoveredItem, -1);
}
m_lastHoveredItem = index;
}
pCore->window()->showKeyBinding(i18n("<b>Shift+seek</b> over thumbnail to set default thumbnail, <b>F2</b> to rename selected item"));
} else {
pCore->window()->showKeyBinding(i18n("<b>F2</b> to rename selected item"));
}
pCore->window()->showKeyBinding(i18n("<b>F2</b> to rename selected item"));
} else {
pCore->window()->showKeyBinding();
if (m_lastHoveredItem.isValid()) {
emit displayBinFrame(m_lastHoveredItem, -1);
m_lastHoveredItem = QModelIndex();
}
}
QListView::mouseMoveEvent(event);
}
......@@ -652,10 +669,24 @@ void MyTreeView::mouseMoveEvent(QMouseEvent *event)
if (KdenliveSettings::hoverPreview()) {
QAbstractItemDelegate *del = itemDelegate(index);
int frame = static_cast<BinItemDelegate *>(del)->getFrame(index, event->pos().x());
emit displayBinFrame(index, frame);
if (frame >= 0) {
emit displayBinFrame(index, frame, event->modifiers() & Qt::ShiftModifier);
if (m_lastHoveredItem != index) {
if (m_lastHoveredItem.isValid()) {
emit displayBinFrame(m_lastHoveredItem, -1);
}
m_lastHoveredItem = index;
}
}
pCore->window()->showKeyBinding(i18n("<b>Shift+seek</b> over thumbnail to set default thumbnail, <b>F2</b> to rename selected item"));
} else {
pCore->window()->showKeyBinding(i18n("<b>F2</b> to rename selected item"));
}
pCore->window()->showKeyBinding(i18n("<b>F2</b> to rename selected item"));
} else {
if (m_lastHoveredItem.isValid()) {
emit displayBinFrame(m_lastHoveredItem, -1);
m_lastHoveredItem = QModelIndex();
}
pCore->window()->showKeyBinding();
}
}
......@@ -3886,7 +3917,7 @@ void Bin::slotRefreshClipThumbnail(const QString &id)
if (!clip) {
return;
}
clip->reloadProducer(true);
ClipLoadTask::start({ObjectType::BinClip,id.toInt()}, QDomElement(), true, -1, -1, this);
}
void Bin::slotAddClipExtraData(const QString &id, const QString &key, const QString &clipData, QUndoCommand *groupCommand)
......@@ -4268,7 +4299,7 @@ void Bin::adjustProjectProfileToItem()
}
}
void Bin::showBinFrame(QModelIndex ix, int frame)
void Bin::showBinFrame(QModelIndex ix, int frame, bool storeFrame)
{
std::shared_ptr<AbstractProjectItem> item = m_itemModel->getBinItemByIndex(m_proxyModel->mapToSource(ix));
if (item) {
......@@ -4279,7 +4310,7 @@ void Bin::showBinFrame(QModelIndex ix, int frame)
if (item->itemType() == AbstractProjectItem::ClipItem) {
auto clip = std::static_pointer_cast<ProjectClip>(item);
if (clip && (clip->clipType() == ClipType::AV || clip->clipType() == ClipType::Video || clip->clipType() == ClipType::Playlist)) {
clip->getThumbFromPercent(frame);
clip->getThumbFromPercent(frame, storeFrame);
}
} else if (item->itemType() == AbstractProjectItem::SubClipItem) {
auto clip = std::static_pointer_cast<ProjectSubClip>(item);
......
......@@ -93,11 +93,12 @@ protected:
signals:
void focusView();
void updateDragMode(PlaylistState::ClipState type);
void displayBinFrame(QModelIndex ix, int frame);
void displayBinFrame(QModelIndex ix, int frame, bool storeFrame = false);
void processDragEnd();
private:
QPoint m_startPos;
PlaylistState::ClipState m_dragType;
QModelIndex m_lastHoveredItem;
};
/** @class MyTreeView
......@@ -126,6 +127,7 @@ protected slots:
private:
QPoint m_startPos;
PlaylistState::ClipState m_dragType;
QModelIndex m_lastHoveredItem;
bool m_editing;
bool performDrag();
bool isEditing() const;
......@@ -133,7 +135,7 @@ private:
signals:
void focusView();
void updateDragMode(PlaylistState::ClipState type);
void displayBinFrame(QModelIndex ix, int frame);
void displayBinFrame(QModelIndex ix, int frame, bool storeFrame = false);
void processDragEnd();
void selectCurrent();
void editingChanged();
......@@ -404,7 +406,7 @@ private slots:
void showClearButton(bool show);
/** @brief Display a defined frame in bin clip thumbnail
*/
void showBinFrame(QModelIndex ix, int frame);
void showBinFrame(QModelIndex ix, int frame, bool storeFrame = false);
/** @brief Switch a tag on/off on current selection
*/
void switchTag(const QString &tag, bool add);
......
......@@ -1793,9 +1793,16 @@ void ProjectClip::updateZones()
}
void ProjectClip::getThumbFromPercent(int percent)
void ProjectClip::getThumbFromPercent(int percent, bool storeFrame)
{
// extract a maximum of 30 frames for bin preview
if (percent < 0) {
if (hasProducerProperty(QStringLiteral("kdenlive:thumbnailFrame"))) {
int framePos = qMax(0, getProducerIntProperty(QStringLiteral("kdenlive:thumbnailFrame")));
setThumbnail(ThumbnailCache::get()->getThumbnail(m_binId, framePos), -1, -1);
}
return;
}
int duration = getFramePlaytime();
int steps = qCeil(qMax(pCore->getCurrentFps(), double(duration) / 30));
int framePos = duration * percent / 100;
......@@ -1806,6 +1813,9 @@ void ProjectClip::getThumbFromPercent(int percent)
// Generate percent thumbs
CacheTask::start({ObjectType::BinClip,m_binId.toInt()}, 30, 0, 0, this);
}
if (storeFrame) {
setProducerProperty(QStringLiteral("kdenlive:thumbnailFrame"), framePos);
}
}
void ProjectClip::setRating(uint rating)
......
......@@ -216,7 +216,7 @@ public:
void updateZones();
/** @brief Display Bin thumbnail given a percent
*/
void getThumbFromPercent(int percent);
void getThumbFromPercent(int percent, bool storeFrame = false);
/** @brief Return audio cache for a stream
*/
const QVector <uint8_t> audioFrameCache(int stream = -1);
......
......@@ -200,6 +200,10 @@ bool ProjectSubClip::hasAudioAndVideo() const
void ProjectSubClip::getThumbFromPercent(int percent)
{
// extract a maximum of 30 frames for bin preview
if (percent < 0) {
setThumbnail(ThumbnailCache::get()->getThumbnail(m_binId, m_inPoint));
return;
}
int duration = m_outPoint - m_inPoint;
int steps = qCeil(qMax(pCore->getCurrentFps(), double(duration) / 30));
int framePos = duration * percent / 100;
......
......@@ -443,6 +443,15 @@ int ClipController::getFramePlaytime() const
return m_masterProducer->get_length();
}
bool ClipController::hasProducerProperty(const QString &name) const
{
QReadLocker lock(&m_producerLock);
if (m_properties == nullptr) {
return false;
}
return m_properties->property_exists(name.toUtf8().constData());
}
QString ClipController::getProducerProperty(const QString &name) const
{
QReadLocker lock(&m_producerLock);
......
......@@ -132,6 +132,7 @@ public:
* @param name name o the property
*/
QMap<QString, QString> currentProperties(const QMap<QString, QString> &props);
bool hasProducerProperty(const QString &name) const;
QString getProducerProperty(const QString &key) const;
int getProducerIntProperty(const QString &key) const;
qint64 getProducerInt64Property(const QString &key) const;
......
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