Fix crash and inconsistencies in color wheel resize. Related to #453

parent d0b3896e
......@@ -93,8 +93,8 @@ void AssetParameterView::setModel(const std::shared_ptr<AssetParameterModel> &mo
connect(w, &AbstractParamWidget::valuesChanged, this, &AssetParameterView::commitMultipleChanges);
connect(w, &AbstractParamWidget::valueChanged, this, &AssetParameterView::commitChanges);
m_lay->addWidget(w);
connect(w, &AbstractParamWidget::updateHeight, [&, w]() {
setFixedHeight(w->height() + m_lay->contentsMargins().bottom());
connect(w, &AbstractParamWidget::updateHeight, [&, w](int h) {
setFixedHeight(h + m_lay->contentsMargins().bottom());
emit updateHeight();
});
m_widgets.push_back(w);
......@@ -382,3 +382,4 @@ QMenu *AssetParameterView::presetMenu()
{
return m_presetMenu;
}
......@@ -62,7 +62,7 @@ signals:
void disableCurrentFilter(bool);
void seekToPos(int);
void updateHeight();
void updateHeight(int height = -1);
public slots:
/** @brief Toggle the comments on or off
......
......@@ -33,7 +33,7 @@ LumaLiftGainParam::LumaLiftGainParam(std::shared_ptr<AssetParameterModel> model,
: AbstractParamWidget(std::move(model), index, parent)
{
m_flowLayout = new FlowLayout(this, 2, 2, 2);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
m_locale.setNumberOptions(QLocale::OmitGroupSeparator);
m_lift = new ColorWheel(QStringLiteral("lift"), i18n("Lift"), NegQColor(), this);
m_lift->setFactorDefaultZero(LIFT_FACTOR, 0, 0.5);
......@@ -110,9 +110,10 @@ void LumaLiftGainParam::updateEffect(QDomElement &effect)
void LumaLiftGainParam::resizeEvent(QResizeEvent *ev)
{
setFixedHeight(m_flowLayout->miniHeight());
QWidget::resizeEvent(ev);
emit updateHeight();
if (height() != m_flowLayout->miniHeight()) {
emit updateHeight(m_flowLayout->miniHeight());
}
}
void LumaLiftGainParam::slotShowComment(bool) {}
......
......@@ -87,7 +87,7 @@ CollapsibleEffectView::CollapsibleEffectView(const std::shared_ptr<EffectItemMod
// checkAll->setToolTip(i18n("Enable/Disable all effects"));
// buttonShowComments->setIcon(QIcon::fromTheme("help-about"));
// buttonShowComments->setToolTip(i18n("Show additional information for the parameters"));
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
m_collapse = new KDualAction(i18n("Collapse Effect"), i18n("Expand Effect"), this);
m_collapse->setActiveIcon(QIcon::fromTheme(QStringLiteral("arrow-right")));
collapseButton->setDefaultAction(m_collapse);
......
......@@ -291,18 +291,15 @@ void EffectStackView::slotStartDrag(const QPixmap &pix, const std::shared_ptr<Ef
void EffectStackView::slotAdjustDelegate(const std::shared_ptr<EffectItemModel> &effectModel, int height)
{
qDebug() << "MUTEX LOCK!!!!!!!!!!!! adjustdelegate: " << height;
//QMutexLocker lock(&m_mutex);
if (!m_model) {
return;
}
QModelIndex ix = m_model->getIndexFromItem(effectModel);
auto *del = static_cast<WidgetDelegate *>(m_effectsTree->itemDelegate(ix));
if (del) {
//QMutexLocker lock(&m_mutex);
del->setHeight(ix, height);
updateTreeHeight();
}
qDebug() << "MUTEX UNLOCK!!!!!!!!!!!! adjustdelegate";
}
void EffectStackView::refresh(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
......
......@@ -40,13 +40,14 @@
#include "flowlayout.h"
#include <QWidget>
#include <QDebug>
#include <QtMath>
FlowLayout::FlowLayout(QWidget *parent, int margin, int hSpacing, int vSpacing)
: QLayout(parent)
, m_hSpace(hSpacing)
, m_vSpace(vSpacing)
, m_mini(0)
, m_triggerLayout(false)
, m_minimumSize(300, 200)
{
setContentsMargins(margin, margin, margin, margin);
}
......@@ -112,38 +113,23 @@ Qt::Orientations FlowLayout::expandingDirections() const
bool FlowLayout::hasHeightForWidth() const
{
return true;
}
int FlowLayout::heightForWidth(int width) const
{
int height = doLayout(QRect(0, 0, width, 0), true);
return height;
return false;
}
void FlowLayout::setGeometry(const QRect &rect)
{
QLayout::setGeometry(rect);
doLayout(rect, false);
QLayout::setGeometry(rect);
}
QSize FlowLayout::sizeHint() const
{
return minimumSize();
return m_minimumSize;
}
QSize FlowLayout::minimumSize() const
{
QSize size;
for (QLayoutItem *item : m_itemList) {
size = size.expandedTo(item->minimumSize());
}
size += QSize(2 * margin(), 2 * margin());
if (m_mini > 0) {
size.setHeight(m_mini);
}
return size;
return m_minimumSize;
}
int FlowLayout::doLayout(const QRect &rect, bool testOnly) const
......@@ -153,40 +139,31 @@ int FlowLayout::doLayout(const QRect &rect, bool testOnly) const
QRect effectiveRect = rect.adjusted(+left, +top, -right, -bottom);
int x = effectiveRect.x();
int y = effectiveRect.y();
int lineHeight = 0;
int hPos = 0;
int itemCount = 0;
int allowedWidth = effectiveRect.width();
if (m_itemList.isEmpty()) {
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());
int realWidth = rect.width() / columns - horizontalSpacing();
int totalHeight = y - rect.y() + bottom + qCeil((double)m_itemList.size() / columns) * (realWidth + verticalSpacing());
for (QLayoutItem *item : m_itemList) {
// We consider all items have the same dimensions
QWidget *wid = item->widget();
int spaceX = horizontalSpacing();
if (spaceX == -1) spaceX = wid->style()->layoutSpacing(QSizePolicy::Frame, QSizePolicy::Frame, Qt::Horizontal);
int spaceY = verticalSpacing();
if (spaceY == -1) spaceY = wid->style()->layoutSpacing(QSizePolicy::Frame, QSizePolicy::Frame, Qt::Vertical);
int optimumItemWidth = item->sizeHint().width() + spaceX;
int horizontalCount = qMin(count(), qMax(1, qRound((double)allowedWidth / optimumItemWidth)));
//QSize hint = item->sizeHint();
QSize hint = QSize(qMin(wid->maximumWidth(), allowedWidth / horizontalCount), qMin(wid->maximumWidth(), allowedWidth / horizontalCount));
wid = item->widget();
QSize hint = QSize(qMin(wid->maximumWidth(), realWidth), qMin(wid->maximumWidth(), realWidth));
if (!testOnly) {
item->setGeometry(QRect(QPoint(x, y), hint));
}
hPos ++;
itemCount++;
if (itemCount < count()) {
hPos = hPos % horizontalCount;
if (hPos == 0 && itemCount > 0) {
y += lineHeight + spaceY;
x = effectiveRect.x();
} else {
x += hint.width();
}
}
lineHeight = qMax(lineHeight, hint.height());
//qDebug()<<"=== ITEM: "<<itemCount<<", POS: "<<x<<"x"<<y<<", SIZE: "<<hint;
x = effectiveRect.x() + (itemCount % columns) * (realWidth + horizontalSpacing());
y = effectiveRect.y() + qFloor((double) itemCount / columns) * (realWidth + verticalSpacing());
}
m_mini = y + lineHeight - rect.y() + bottom;
return m_mini;
m_minimumSize = QSize(rect.width(), totalHeight);
return totalHeight;
}
int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const
{
......@@ -203,6 +180,6 @@ int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const
int FlowLayout::miniHeight() const
{
return m_mini;
return m_minimumSize.height();
}
......@@ -44,6 +44,8 @@
#include <QLayout>
#include <QRect>
#include <QStyle>
#include <QMutex>
class FlowLayout : public QLayout
{
public:
......@@ -56,7 +58,6 @@ public:
int verticalSpacing() const;
Qt::Orientations expandingDirections() const override;
bool hasHeightForWidth() const override;
int heightForWidth(int) const override;
int count() const override;
QLayoutItem *itemAt(int index) const override;
QSize minimumSize() const override;
......@@ -73,9 +74,7 @@ private:
int m_vSpace;
protected:
mutable int m_mini;
mutable bool m_triggerLayout;
mutable QSize m_minimumSize;
};
#endif // FLOWLAYOUT_H
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