Commit 1c134a91 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle

Improve effects layouts.

Related to #818
parent 07b8fffa
......@@ -66,7 +66,6 @@ CollapsibleEffectView::CollapsibleEffectView(const std::shared_ptr<EffectItemMod
m_regionEffect = true;
decoframe->setObjectName(QStringLiteral("decoframegroup"));
}
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
buttonUp->setIcon(QIcon::fromTheme(QStringLiteral("kdenlive-up")));
buttonUp->setToolTip(i18n("Move effect up"));
buttonDown->setIcon(QIcon::fromTheme(QStringLiteral("kdenlive-down")));
......
......@@ -97,6 +97,7 @@ EffectStackView::EffectStackView(AssetPanel *parent)
m_effectsTree->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
m_effectsTree->setHeaderHidden(true);
m_effectsTree->setRootIsDecorated(false);
m_effectsTree->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
QString style = QStringLiteral("QTreeView {border: none;}");
// m_effectsTree->viewport()->setAutoFillBackground(false);
m_effectsTree->setStyleSheet(style);
......@@ -189,6 +190,7 @@ void EffectStackView::setModel(std::shared_ptr<EffectStackModel> model, const QS
disconnect(&m_timerHeight, &QTimer::timeout, this, &EffectStackView::updateTreeHeight);
m_mutex.lock();
unsetModel(false);
m_effectsTree->setFixedHeight(0);
m_model = std::move(model);
m_sourceFrameSize = frameSize;
m_effectsTree->setModel(m_model.get());
......@@ -233,7 +235,6 @@ void EffectStackView::loadEffects()
updateTreeHeight();
return;
}
connect(&m_timerHeight, &QTimer::timeout, this, &EffectStackView::updateTreeHeight);
int active = qBound(0, m_model->getActiveEffect(), max - 1);
QModelIndex activeIndex;
for (int i = 0; i < max; i++) {
......@@ -277,6 +278,7 @@ void EffectStackView::loadEffects()
if (activeIndex.isValid()) {
doActivateEffect(active, activeIndex, true);
}
connect(&m_timerHeight, &QTimer::timeout, this, &EffectStackView::updateTreeHeight);
qDebug() << "MUTEX UNLOCK!!!!!!!!!!!! loadEffects";
}
......@@ -297,9 +299,10 @@ void EffectStackView::updateTreeHeight()
totalHeight += w->height();
}
}
m_effectsTree->setFixedHeight(totalHeight);
emit scrollView(m_effectsTree->visualRect(m_effectsTree->currentIndex()));
m_scrollTimer.start();
if (totalHeight != m_effectsTree->height()) {
m_effectsTree->setFixedHeight(totalHeight);
m_scrollTimer.start();
}
}
void EffectStackView::slotActivateEffect(const std::shared_ptr<EffectItemModel> &effectModel)
......@@ -342,7 +345,7 @@ void EffectStackView::slotAdjustDelegate(const std::shared_ptr<EffectItemModel>
QModelIndex ix = m_model->getIndexFromItem(effectModel);
if (ix.isValid()) {
auto *del = static_cast<WidgetDelegate *>(m_effectsTree->itemDelegate(ix));
if (del) {
if (del && del->height(ix) != newHeight) {
del->setHeight(ix, newHeight);
m_timerHeight.start();
}
......@@ -462,6 +465,15 @@ void EffectStackView::doActivateEffect(int row, QModelIndex activeIx, bool force
if (w) {
w->slotActivateEffect(true);
}
if (force && row > 0) {
// Some effects have a complex timed layout, so we need to wait a bit before getting the correct position for the effect
QTimer::singleShot(100, this, &EffectStackView::slotFocusEffect);
}
}
void EffectStackView::slotFocusEffect()
{
emit scrollView(m_effectsTree->visualRect(m_effectsTree->currentIndex()));
}
void EffectStackView::slotSaveStack()
......
......@@ -106,6 +106,7 @@ private slots:
void loadEffects();
void updateTreeHeight();
void doActivateEffect(int row, QModelIndex ix, bool force = false);
void slotFocusEffect();
/** @brief Save current effect stack
*/
void slotSaveStack();
......
......@@ -55,6 +55,7 @@ FlowLayout::FlowLayout(QWidget *parent, int margin, int hSpacing, int vSpacing)
FlowLayout::FlowLayout(int margin, int hSpacing, int vSpacing)
: m_hSpace(hSpacing)
, m_vSpace(vSpacing)
, m_minimumSize(200, 200)
{
setContentsMargins(margin, margin, margin, margin);
}
......@@ -108,7 +109,7 @@ QLayoutItem *FlowLayout::takeAt(int index)
Qt::Orientations FlowLayout::expandingDirections() const
{
return nullptr;
return Qt::Horizontal | Qt::Vertical;
}
bool FlowLayout::hasHeightForWidth() const
......@@ -124,6 +125,9 @@ int FlowLayout::heightForWidth(int width) const
void FlowLayout::setGeometry(const QRect &rect)
{
if (m_itemList.size() < 3) {
return;
}
doLayout(rect, false);
QLayout::setGeometry(rect);
}
......@@ -142,12 +146,12 @@ int FlowLayout::doLayout(const QRect &rect, bool testOnly) const
{
QMargins mrg = contentsMargins();
QRect effectiveRect = rect.adjusted(mrg.left(), mrg.top(), -mrg.right(), -mrg.bottom());
if (m_itemList.isEmpty() || effectiveRect.width() <= 0) {
return 0;
}
int x = effectiveRect.x();
int y = effectiveRect.y();
int itemCount = 0;
if (m_itemList.isEmpty() || effectiveRect.width() <= 0 || effectiveRect.height() <= 0) {
return 0;
}
QWidget *wid = m_itemList.at(0)->widget();
QSize min = wid->minimumSize();
int columns = qMin(qFloor((double)rect.width() / min.width()), m_itemList.size());
......@@ -155,13 +159,12 @@ int FlowLayout::doLayout(const QRect &rect, bool testOnly) const
int realWidth = rect.width() / columns - horizontalSpacing();
int totalHeight = y - rect.y() + mrg.bottom() + qCeil((double)m_itemList.size() / columns) * (realWidth + verticalSpacing());
m_minimumSize = QSize(rect.width(), totalHeight);
QSize hint = QSize(qMin(wid->maximumWidth(), realWidth), qMin(wid->maximumWidth(), realWidth));
if (testOnly) {
return totalHeight;
}
for (QLayoutItem *item : m_itemList) {
// We consider all items have the same dimensions
wid = item->widget();
QSize hint = QSize(qMin(wid->maximumWidth(), realWidth), qMin(wid->maximumWidth(), realWidth));
item->setGeometry(QRect(QPoint(x, y), hint));
itemCount++;
//qDebug()<<"=== ITEM: "<<itemCount<<", POS: "<<x<<"x"<<y<<", SIZE: "<<hint;
......
  • This commit doesn't seem to solve the issue with LFG layout (at least on my machine), but it makes all the other effects disappear. I tried to revert to the previous commit to test and the effects show up.

    For some reason the color wheels are a bit too big and on the default layout become too far apart for some reason. This at least for a FHD display.

  • I was testing if for some reason was only broken for old projects, and not for newly added effects, but the behaviour is even more strange. I tried with a random selection of effects, and for some reason Grain, for example, made all the effects appear. It wasn't a specific number of effects (that could show some issue with an index counter, for example), but that specific effect. Maybe the kind of effect triggers something in the algorithm to show/draw all the effects?

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