Remember selected effect in stack, prepare for drag & drop

parent a949fbaa
......@@ -106,7 +106,7 @@ void TreeItem::moveChild(int ix, std::shared_ptr<TreeItem> child)
{
if (auto ptr = m_model.lock()) {
auto childPtr = child->m_parentItem.lock();
if (childPtr && childPtr->getId() == m_id) {
if (childPtr && childPtr->getId() != m_id) {
childPtr->removeChild(child);
} else {
// deletion of child
......
......@@ -145,3 +145,19 @@ void EffectStackModel::importEffects(int cid, std::shared_ptr<EffectStackModel>s
}
}
void EffectStackModel::setActiveEffect(int ix)
{
auto ptr = m_service.lock();
if (ptr) {
ptr->set("kdenlive:activeeffect", ix);
}
}
int EffectStackModel::getActiveEffect() const
{
auto ptr = m_service.lock();
if (ptr) {
return ptr->get_int("kdenlive:activeeffect");
}
return -1;
}
......@@ -64,6 +64,9 @@ public:
/* @brief Move an effect in the stack */
void moveEffect(int destRow, std::shared_ptr<EffectItemModel> effect);
void setActiveEffect(int ix);
int getActiveEffect() const;
public slots:
/* @brief Delete an effect from the stack */
void removeEffect(std::shared_ptr<EffectItemModel> effect);
......
......@@ -68,7 +68,7 @@ CollapsibleEffectView::CollapsibleEffectView(std::shared_ptr<EffectItemModel> ef
decoframe->setObjectName(QStringLiteral("decoframegroup"));
}
filterWheelEvent = true;
decoframe->setProperty("active", true);
//decoframe->setProperty("active", true);
//m_info.fromString(effect.attribute(QStringLiteral("kdenlive_info")));
// setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont));
buttonUp->setIcon(KoIconUtils::themedIcon(QStringLiteral("kdenlive-up")));
......@@ -288,6 +288,12 @@ bool CollapsibleEffectView::isEnabled() const
return m_enabledButton->isActive();
}
void CollapsibleEffectView::slotActivateEffect(QModelIndex ix)
{
decoframe->setProperty("active", ix.row() == m_model->row());
decoframe->setStyleSheet(decoframe->styleSheet());
}
void CollapsibleEffectView::setActive(bool activate)
{
/*
......@@ -310,6 +316,22 @@ void CollapsibleEffectView::setActive(bool activate)
*/
}
void CollapsibleEffectView::mousePressEvent(QMouseEvent *e)
{
m_dragStart = e->globalPos();
emit activateEffect(m_model);
QWidget::mousePressEvent(e);
}
void CollapsibleEffectView::mouseMoveEvent(QMouseEvent *e)
{
if ((e->globalPos() - m_dragStart).manhattanLength() < QApplication::startDragDistance()) {
QPixmap pix = frame->grab();
emit startDrag(pix, m_model);
}
QWidget::mouseMoveEvent(e);
}
void CollapsibleEffectView::mouseDoubleClickEvent(QMouseEvent *event)
{
if (frame->underMouse() && collapseButton->isEnabled()) {
......@@ -322,8 +344,9 @@ void CollapsibleEffectView::mouseDoubleClickEvent(QMouseEvent *event)
void CollapsibleEffectView::mouseReleaseEvent(QMouseEvent *event)
{
m_dragStart = QPoint();
if (!decoframe->property("active").toBool()) {
emit activateEffect(effectIndex());
//emit activateEffect(effectIndex());
}
QWidget::mouseReleaseEvent(event);
}
......@@ -671,7 +694,7 @@ void CollapsibleEffectView::dropEvent(QDropEvent *event)
if (event->source()->objectName() == QStringLiteral("ParameterContainer")) {
return;
}
emit activateEffect(effectIndex());
//emit activateEffect(effectIndex());
QString itemData = event->mimeData()->data(QStringLiteral("kdenlive/geometry"));
importKeyframes(itemData);
return;
......
......@@ -95,6 +95,7 @@ public slots:
void slotDisable(bool disable);
void slotResetEffect();
void importKeyframes(const QString &keyframes);
void slotActivateEffect(QModelIndex ix);
private slots:
void setWidgetHeight(qreal value);
......@@ -135,11 +136,14 @@ private:
KDualAction *m_enabledButton;
QLabel *m_colorIcon;
QPixmap m_iconPix;
QPoint m_dragStart;
/** @brief Check if collapsed state changed and inform MLT. */
void updateCollapsedState();
protected:
void mouseDoubleClickEvent(QMouseEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void dragEnterEvent(QDragEnterEvent *event) override;
void dragLeaveEvent(QDragLeaveEvent *event) override;
......@@ -151,7 +155,6 @@ signals:
void effectStateChanged(bool, int ix, MonitorSceneType effectNeedsMonitorScene);
void deleteEffect(std::shared_ptr<EffectItemModel> effect);
void moveEffect(int destRow, std::shared_ptr<EffectItemModel> effect);
void activateEffect(int);
void checkMonitorPosition(int);
void seekTimeline(int);
/** @brief Start an MLT filter job on this clip. */
......@@ -165,6 +168,8 @@ signals:
void deleteGroup(const QDomDocument &);
void importClipKeyframes(GraphicsRectItem, ItemInfo, QDomElement, const QMap<QString, QString> &keyframes = QMap<QString, QString>());
void switchHeight(std::shared_ptr<EffectItemModel> model, int height);
void startDrag(QPixmap, std::shared_ptr<EffectItemModel> effectModel);
void activateEffect(std::shared_ptr<EffectItemModel> effectModel);
};
#endif
......@@ -31,15 +31,16 @@
#include <QMimeData>
#include <QFontDatabase>
#include <QTreeView>
#include <QDrag>
WidgetDelegate::WidgetDelegate(QObject *parent) :
QItemDelegate(parent)
QStyledItemDelegate(parent)
{
}
QSize WidgetDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QSize s = QItemDelegate::sizeHint(option, index);
QSize s = QStyledItemDelegate::sizeHint(option, index);
if (m_height.contains(index)) {
s.setHeight(m_height.value(index));
}
......@@ -52,7 +53,16 @@ void WidgetDelegate::setHeight(const QModelIndex &index, int height)
emit sizeHintChanged(index);
}
void WidgetDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyleOptionViewItem opt(option);
initStyleOption(&opt, index);
QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
// QRect r = QStyle::alignedRect(opt.direction, Qt::AlignVCenter | Qt::AlignLeft, opt.decorationSize, r1);
style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
}
EffectStackView::EffectStackView(QWidget *parent) : QWidget(parent)
, m_thumbnailer(new AssetIconProvider(true))
......@@ -116,22 +126,50 @@ void EffectStackView::loadEffects(int start, int end)
if (end == -1) {
end = max;
}
int active = m_model->getActiveEffect();
for (int i = 0; i < end; i++) {
std::shared_ptr<EffectItemModel> effectModel = m_model->getEffect(i);
QSize size;
QImage effectIcon = m_thumbnailer->requestImage(effectModel->getAssetId(), &size, QSize(QStyle::PM_SmallIconSize,QStyle::PM_SmallIconSize));
CollapsibleEffectView *view = new CollapsibleEffectView(effectModel, effectIcon, this);
qDebug()<<"__ADDING EFFECT: "<<effectModel->filter().get("id")<<", ACT: "<<active;
if (i == active) {
view->slotActivateEffect(m_model->getIndexFromItem(effectModel));
}
view->buttonUp->setEnabled(i > 0);
view->buttonDown->setEnabled(i < max - 1);
connect(view, &CollapsibleEffectView::deleteEffect, m_model.get(), &EffectStackModel::removeEffect);
connect(view, &CollapsibleEffectView::moveEffect, m_model.get(), &EffectStackModel::moveEffect);
connect(view, &CollapsibleEffectView::switchHeight, this, &EffectStackView::slotAdjustDelegate);
connect(view, &CollapsibleEffectView::startDrag, this, &EffectStackView::slotStartDrag);
connect(view, &CollapsibleEffectView::activateEffect, this, &EffectStackView::slotActivateEffect);
connect(this, &EffectStackView::doActivateEffect, view, &CollapsibleEffectView::slotActivateEffect);
QModelIndex ix = m_model->getIndexFromItem(effectModel);
m_effectsTree->setIndexWidget(ix, view);
}
}
void EffectStackView::slotActivateEffect(std::shared_ptr<EffectItemModel> effectModel)
{
m_model->setActiveEffect(effectModel->row());
QModelIndex activeIx = m_model->getIndexFromItem(effectModel);
emit doActivateEffect(activeIx);
}
void EffectStackView::slotStartDrag(QPixmap pix, std::shared_ptr<EffectItemModel> effectModel)
{
auto *drag = new QDrag(this);
drag->setPixmap(pix);
auto *mime = new QMimeData;
mime->setData(QStringLiteral("kdenlive/effectslist"), effectModel->getAssetId().toUtf8());
// Assign ownership of the QMimeData object to the QDrag object.
drag->setMimeData(mime);
// Start the drag and drop operation
drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
}
void EffectStackView::slotAdjustDelegate(std::shared_ptr<EffectItemModel> effectModel, int height)
{
QModelIndex ix = m_model->getIndexFromItem(effectModel);
......@@ -152,9 +190,3 @@ void EffectStackView::unsetModel(bool reset)
}
}
void EffectStackView::mousePressEvent(QMouseEvent *e)
{
//m_dragPoint = e->globalPos();
//e->accept();
qDebug()<<"*** EFFECT STACK CLICK";
}
......@@ -24,7 +24,7 @@
#include <QWidget>
#include <memory>
#include <QItemDelegate>
#include <QStyledItemDelegate>
class QVBoxLayout;
class QTreeView;
......@@ -34,13 +34,14 @@ class EffectStackModel;
class EffectItemModel;
class AssetIconProvider;
class WidgetDelegate : public QItemDelegate
class WidgetDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
explicit WidgetDelegate(QObject *parent = nullptr);
void setHeight(const QModelIndex &index, int height);
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
private:
QMap<QModelIndex, int> m_height;
......@@ -59,7 +60,6 @@ public:
protected:
void dragEnterEvent(QDragEnterEvent *event) override;
void dropEvent(QDropEvent *event) override;
void mousePressEvent(QMouseEvent *e) override;
private:
QVBoxLayout *m_lay;
......@@ -73,7 +73,11 @@ private:
private slots:
void refresh(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
void slotAdjustDelegate(std::shared_ptr<EffectItemModel> effectModel, int height);
void slotStartDrag(QPixmap pix, std::shared_ptr<EffectItemModel> effectModel);
void slotActivateEffect(std::shared_ptr<EffectItemModel> effectModel);
signals:
void doActivateEffect(QModelIndex);
};
#endif
......
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