Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Switch effectstack to QTreeView

parent 04cb3f06
......@@ -46,7 +46,6 @@ AssetPanel::AssetPanel(QWidget *parent)
m_lay->addWidget(m_assetTitle);
m_lay->addWidget(m_transitionWidget);
m_lay->addWidget(m_effectStackWidget);
m_lay->addStretch();
m_transitionWidget->setVisible(false);
updatePalette();
}
......
......@@ -66,8 +66,7 @@ void EffectStackModel::appendEffect(const QString &effectId, int cid)
void EffectStackModel::moveEffect(int destRow, std::shared_ptr<EffectItemModel> effect)
{
QModelIndex ix = getIndexFromItem(effect);
int currentRow = effect->row();
//effect->unplant(m_service);
QModelIndex ix2 = ix;
rootItem->moveChild(destRow, effect);
QList < std::shared_ptr<EffectItemModel> > effects;
for (int i = destRow; i < rootItem->childCount(); i++) {
......@@ -78,9 +77,12 @@ void EffectStackModel::moveEffect(int destRow, std::shared_ptr<EffectItemModel>
for (int i = 0; i < effects.count(); i++) {
auto eff = effects.at(i);
eff->plant(m_service);
if (i == effects.count() - 1) {
ix2 = getIndexFromItem(eff);
}
}
pCore->refreshProjectItem(effect->getParentId());
emit dataChanged(ix, ix, QVector<int>());
emit dataChanged(ix, ix2, QVector<int>());
}
Fun EffectStackModel::deleteEffect_lambda(std::shared_ptr<EffectItemModel> effect, int cid, bool isAudio)
......@@ -90,7 +92,6 @@ Fun EffectStackModel::deleteEffect_lambda(std::shared_ptr<EffectItemModel> effec
QModelIndex ix = this->getIndexFromItem(effect);
this->rootItem->removeChild(effect);
effect->unplant(this->m_service);
this->dataChanged(ix, ix, QVector<int>());
if (!isAudio) {
pCore->refreshProjectItem(cid);
}
......@@ -108,6 +109,7 @@ Fun EffectStackModel::addEffect_lambda(std::shared_ptr<EffectItemModel> effect,
effect->setEffectStackEnabled(m_effectStackEnabled);
QModelIndex ix = this->getIndexFromItem(effect);
connect(effect.get(), &EffectItemModel::dataChanged, this, &EffectStackModel::dataChanged);
// Required to build the effect view
this->dataChanged(ix, ix, QVector<int>());
if (!isAudio) {
pCore->refreshProjectItem(cid);
......
......@@ -406,19 +406,28 @@ void CollapsibleEffectView::slotResetEffect()
void CollapsibleEffectView::slotSwitch(bool expand)
{
slotShow(expand);
if (!expand) {
emit switchHeight(m_model, expand ? frame->height() : frame->height() + m_view->contentHeight());
setFixedHeight(expand ? frame->height() : frame->height() + m_view->contentHeight());
widgetFrame->setVisible(!expand);
/*if (!expand) {
widgetFrame->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
widgetFrame->setFixedHeight(m_view->contentHeight());
} else {
widgetFrame->setFixedHeight(QWIDGETSIZE_MAX);
}
const QRect final_geometry = expand ? QRect(QPoint(0, - m_view->height()), m_view->size()) : QRect(widgetFrame->rect().topLeft(), m_view->size());
QPropertyAnimation *anim = new QPropertyAnimation(m_view, "geometry", this);
}*/
/*const QRect final_geometry = expand ? QRect(0, 0, width(), title->height()) : QRect(rect().topLeft(), size());
QPropertyAnimation *anim = new QPropertyAnimation(this, "geometry", this);
anim->setDuration(200);
anim->setEasingCurve(QEasingCurve::InOutQuad);
anim->setEndValue(final_geometry);
//connect(anim, SIGNAL(valueChanged(const QVariant &)), SLOT(animationChanged(const QVariant &)));
connect(anim, SIGNAL(finished()), SLOT(animationFinished()));
anim->start(QPropertyAnimation::DeleteWhenStopped);
anim->start(QPropertyAnimation::DeleteWhenStopped);*/
}
void CollapsibleEffectView::animationChanged(const QVariant &geom)
{
parentWidget()->setFixedHeight(geom.toRect().height());
}
void CollapsibleEffectView::animationFinished()
......
......@@ -113,6 +113,7 @@ private slots:
/** @brief A sub effect parameter was changed */
void slotUpdateRegionEffectParams(const QDomElement & /*old*/, const QDomElement & /*e*/, int /*ix*/);
void prepareImportClipKeyframes();
void animationChanged(const QVariant &geom);
private:
ParameterContainer *m_paramWidget;
......@@ -125,7 +126,6 @@ private:
QDomElement m_original_effect;
QList<QDomElement> m_subEffects;
QMenu *m_menu;
QPoint m_clickPoint;
EffectInfo m_info;
bool m_isMovable;
/** @brief True if this is a region effect, which behaves in a special way, like a group. */
......@@ -164,6 +164,7 @@ signals:
void createRegion(int, const QUrl &);
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);
};
#endif
......@@ -30,15 +30,47 @@
#include <QDragEnterEvent>
#include <QMimeData>
#include <QFontDatabase>
#include <QTreeView>
WidgetDelegate::WidgetDelegate(QObject *parent) :
QItemDelegate(parent)
{
}
QSize WidgetDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QSize s = QItemDelegate::sizeHint(option, index);
if (m_height.contains(index)) {
s.setHeight(m_height.value(index));
}
return s;
}
void WidgetDelegate::setHeight(const QModelIndex &index, int height)
{
m_height[index] = height;
emit sizeHintChanged(index);
}
EffectStackView::EffectStackView(QWidget *parent) : QWidget(parent)
, m_thumbnailer(new AssetIconProvider(true))
{
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
m_lay = new QVBoxLayout(this);
m_lay->setContentsMargins(0, 0, 0, 0);
m_lay->setSpacing(2);
m_lay->setSpacing(0);
setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont));
setAcceptDrops(true);
m_effectsTree = new QTreeView(this);
m_effectsTree->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
m_effectsTree->setHeaderHidden(true);
m_effectsTree->setRootIsDecorated(false);
QString style = QStringLiteral("QTreeView {border: none;}");
//m_effectsTree->viewport()->setAutoFillBackground(false);
m_effectsTree->setStyleSheet(style);
m_lay->addWidget(m_effectsTree);
}
EffectStackView::~EffectStackView()
......@@ -67,14 +99,24 @@ void EffectStackView::setModel(std::shared_ptr<EffectStackModel>model)
{
unsetModel();
m_model = model;
m_effectsTree->setModel(m_model.get());
m_effectsTree->setItemDelegateForColumn(0, new WidgetDelegate(this));
m_effectsTree->setColumnHidden(1, true);
m_effectsTree->setAcceptDrops(true);
m_effectsTree->setDragDropMode(QAbstractItemView::DragDrop);
m_effectsTree->setDragEnabled(true);
m_effectsTree->setUniformRowHeights(false);
loadEffects();
connect(m_model.get(), &EffectStackModel::dataChanged, this, &EffectStackView::refresh);
}
void EffectStackView::loadEffects()
void EffectStackView::loadEffects(int start, int end)
{
int max = m_model->rowCount();
for (int i = 0; i < max; i++) {
if (end == -1) {
end = max;
}
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));
......@@ -83,32 +125,36 @@ void EffectStackView::loadEffects()
view->buttonDown->setEnabled(i < max - 1);
connect(view, &CollapsibleEffectView::deleteEffect, m_model.get(), &EffectStackModel::removeEffect);
connect(view, &CollapsibleEffectView::moveEffect, m_model.get(), &EffectStackModel::moveEffect);
m_lay->addWidget(view);
m_widgets.push_back(view);
connect(view, &CollapsibleEffectView::switchHeight, this, &EffectStackView::slotAdjustDelegate);
QModelIndex ix = m_model->getIndexFromItem(effectModel);
m_effectsTree->setIndexWidget(ix, view);
}
m_lay->addStretch();
}
void EffectStackView::slotAdjustDelegate(std::shared_ptr<EffectItemModel> effectModel, int height)
{
QModelIndex ix = m_model->getIndexFromItem(effectModel);
WidgetDelegate *del = static_cast <WidgetDelegate *>(m_effectsTree->itemDelegate(ix));
del->setHeight(ix, height);
}
void EffectStackView::refresh(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
{
unsetModel(false);
loadEffects();
loadEffects(topLeft.row(), bottomRight.row() + 1);
}
void EffectStackView::unsetModel(bool reset)
{
// clear layout
m_widgets.clear();
QLayoutItem *child;
while ((child = m_lay->takeAt(0)) != nullptr) {
delete child->widget();
delete child->spacerItem();
}
// Release ownership of smart pointer
if (reset) {
m_model.reset();
}
}
void EffectStackView::mousePressEvent(QMouseEvent *e)
{
//m_dragPoint = e->globalPos();
//e->accept();
qDebug()<<"*** EFFECT STACK CLICK";
}
......@@ -24,14 +24,28 @@
#include <QWidget>
#include <memory>
#include <QItemDelegate>
class QVBoxLayout;
class QTreeView;
class CollapsibleEffectView;
class AssetParameterModel;
class EffectStackModel;
class EffectItemModel;
class AssetIconProvider;
class WidgetDelegate : public QItemDelegate
{
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;
private:
QMap<QModelIndex, int> m_height;
};
class EffectStackView : public QWidget
{
Q_OBJECT
......@@ -43,19 +57,22 @@ public:
void unsetModel(bool reset = true);
protected:
void dragEnterEvent(QDragEnterEvent *event);
void dropEvent(QDropEvent *event);
void dragEnterEvent(QDragEnterEvent *event) override;
void dropEvent(QDropEvent *event) override;
void mousePressEvent(QMouseEvent *e) override;
private:
QVBoxLayout *m_lay;
QTreeView *m_effectsTree;
std::shared_ptr<EffectStackModel> m_model;
std::vector<CollapsibleEffectView *> m_widgets;
AssetIconProvider *m_thumbnailer;
const QString getStyleSheet();
void loadEffects();
void loadEffects(int start = 0, int end = -1);
private slots:
void refresh(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
void slotAdjustDelegate(std::shared_ptr<EffectItemModel> effectModel, int height);
};
......
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