Cleanup effectstack layout. Fixes !58 #294

parent 4d8790ba
......@@ -41,7 +41,7 @@ KeyframeView::KeyframeView(std::shared_ptr<KeyframeModelList> model, int duratio
{
setMouseTracking(true);
setMinimumSize(QSize(150, 20));
setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum));
setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred));
setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont));
QPalette p = palette();
KColorScheme scheme(p.currentColorGroup(), KColorScheme::Window);
......
......@@ -55,6 +55,7 @@ void AssetParameterView::setModel(const std::shared_ptr<AssetParameterModel> &mo
unsetModel();
QMutexLocker lock(&m_lock);
m_model = model;
setSizePolicy(QSizePolicy::Preferred, addSpacer ? QSizePolicy::Preferred : QSizePolicy::Fixed);
const QString paramTag = model->getAssetId();
QDir dir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/effects/presets/"));
const QString presetFile = dir.absoluteFilePath(QString("%1.json").arg(paramTag));
......@@ -88,8 +89,13 @@ 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());
emit updateHeight();
});
m_widgets.push_back(w);
} else {
int minHeight = 0;
for (int i = 0; i < model->rowCount(); ++i) {
QModelIndex index = model->index(i, 0);
auto type = model->data(index, AssetParameterModel::TypeRole).value<ParamType>();
......@@ -101,15 +107,18 @@ void AssetParameterView::setModel(const std::shared_ptr<AssetParameterModel> &mo
} else {
auto w = AbstractParamWidget::construct(model, index, frameSize, this);
connect(this, &AssetParameterView::initKeyframeView, w, &AbstractParamWidget::slotInitMonitor);
if (type == ParamType::KeyframeParam || type == ParamType::AnimatedRect || type == ParamType::Roto_spline) {
m_mainKeyframeWidget = static_cast<KeyframeWidget *>(w);
}
connect(w, &AbstractParamWidget::valueChanged, this, &AssetParameterView::commitChanges);
connect(w, &AbstractParamWidget::seekToPos, this, &AssetParameterView::seekToPos);
m_lay->addWidget(w);
if (type == ParamType::KeyframeParam || type == ParamType::AnimatedRect || type == ParamType::Roto_spline) {
m_mainKeyframeWidget = static_cast<KeyframeWidget *>(w);
} else {
minHeight += w->minimumHeight();
}
m_widgets.push_back(w);
}
}
setMinimumHeight(m_mainKeyframeWidget ? m_mainKeyframeWidget->minimumHeight() + minHeight : minHeight);
}
if (addSpacer) {
m_lay->addStretch();
......@@ -294,6 +303,8 @@ void AssetParameterView::toggleKeyframes(bool enable)
{
if (m_mainKeyframeWidget) {
m_mainKeyframeWidget->showKeyframes(enable);
setFixedHeight(contentHeight());
emit updateHeight();
}
}
......
......@@ -109,6 +109,7 @@ signals:
void initKeyframeView(bool active);
/** @brief clear and refill the effect presets */
void updatePresets(const QString &presetName = QString());
void updateHeight();
};
#endif
......@@ -62,6 +62,7 @@ signals:
void disableCurrentFilter(bool);
void seekToPos(int);
void updateHeight();
public slots:
/** @brief Toggle the comments on or off
......
......@@ -26,7 +26,7 @@ BoolParamWidget::BoolParamWidget(std::shared_ptr<AssetParameterModel> model, QMo
: AbstractParamWidget(std::move(model), index, parent)
{
setupUi(this);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
// setup the comment
QString comment = m_model->data(m_index, AssetParameterModel::CommentRole).toString();
setToolTip(comment);
......@@ -35,6 +35,7 @@ BoolParamWidget::BoolParamWidget(std::shared_ptr<AssetParameterModel> model, QMo
// setup the name
m_labelName->setText(m_model->data(m_index, Qt::DisplayRole).toString());
setMinimumHeight(m_labelName->sizeHint().height());
// set check state
slotRefresh();
......
......@@ -76,6 +76,7 @@ ButtonParamWidget::ButtonParamWidget(std::shared_ptr<AssetParameterModel> model,
//layout->setSpacing(0);
m_button = new QPushButton(m_displayConditional ? m_buttonName : m_alternatebuttonName, this);
layout->addWidget(m_button);
setMinimumHeight(m_button->sizeHint().height());
// emit the signal of the base class when appropriate
connect(this->m_button, &QPushButton::clicked, [&, filterData, filterAddedParams]() {
......
......@@ -43,6 +43,7 @@ ClickableLabelParamWidget::ClickableLabelParamWidget(std::shared_ptr<AssetParame
m_label = new QLabel(this);
m_label->setWordWrap(true);
layout->addWidget(m_label);
setMinimumHeight(m_label->sizeHint().height());
connect(m_label, &QLabel::linkActivated, [&](const QString &result) {
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(result);
......
......@@ -127,6 +127,7 @@ ColorEditWidget::ColorEditWidget(std::shared_ptr<AssetParameterModel> model, QMo
// setup comment
setToolTip(comment);
setMinimumHeight(m_button->sizeHint().height());
}
void ColorEditWidget::slotShowComment(bool) {}
......
......@@ -90,10 +90,10 @@ ColorWheel::ColorWheel(QString id, QString name, NegQColor color, QWidget *paren
{
QFontInfo info(font());
m_unitSize = info.pixelSize();
m_initialSize = QSize(m_unitSize * 11.5, m_unitSize * 11);
m_initialSize = QSize(m_unitSize * 11, m_unitSize * 11);
m_sliderWidth = m_unitSize * 1.5;
resize(m_initialSize);
setMinimumSize(100, 100);
setMinimumSize(m_initialSize * .4);
setMaximumSize(m_initialSize);
setCursor(Qt::CrossCursor);
}
......@@ -153,11 +153,11 @@ NegQColor ColorWheel::colorForPoint(const QPointF &point)
QSize ColorWheel::sizeHint() const
{
return {width(), height()};
return m_initialSize * .8;
}
QSize ColorWheel::minimumSizeHint() const
{
return {100, 100};
return m_initialSize * .4;
}
void ColorWheel::mousePressEvent(QMouseEvent *event)
......
......@@ -48,6 +48,7 @@ DoubleParamWidget::DoubleParamWidget(std::shared_ptr<AssetParameterModel> model,
// Construct object
m_doubleWidget = new DoubleWidget(name, value, min, max, factor, defaultValue, comment, -1, suffix, decimals, this);
m_lay->addWidget(m_doubleWidget);
setMinimumHeight(m_doubleWidget->height());
// Connect signal
connect(m_doubleWidget, &DoubleWidget::valueChanged, [this, locale](double val) { emit valueChanged(m_index, locale.toString(val), true); });
......
......@@ -36,7 +36,7 @@ FontParamWidget::FontParamWidget(std::shared_ptr<AssetParameterModel> model, QMo
// set check state
slotRefresh();
setMinimumHeight(fontfamilywidget->sizeHint().height());
// emit the signal of the base class when appropriate
connect(this->fontfamilywidget, &QFontComboBox::currentFontChanged, [this](const QFont &font) { emit valueChanged(m_index, font.family(), true); });
}
......
......@@ -51,8 +51,10 @@ KeyframeWidget::KeyframeWidget(std::shared_ptr<AssetParameterModel> model, QMode
, m_monitorHelper(nullptr)
, m_neededScene(MonitorSceneType::MonitorSceneDefault)
, m_sourceFrameSize(frameSize.isValid() && !frameSize.isNull() ? frameSize : pCore->getCurrentFrameSize())
, m_baseHeight(0)
, m_addedHeight(0)
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
m_lay = new QVBoxLayout(this);
m_lay->setContentsMargins(2, 2, 2, 0);
m_lay->setSpacing(0);
......@@ -170,6 +172,8 @@ KeyframeWidget::KeyframeWidget(std::shared_ptr<AssetParameterModel> model, QMode
connect(m_buttonAddDelete, &QAbstractButton::pressed, m_keyframeview, &KeyframeView::slotAddRemove);
connect(m_buttonPrevious, &QAbstractButton::pressed, m_keyframeview, &KeyframeView::slotGoToPrev);
connect(m_buttonNext, &QAbstractButton::pressed, m_keyframeview, &KeyframeView::slotGoToNext);
m_baseHeight = m_keyframeview->minimumHeight() + m_toolbar->sizeHint().height() + 2;
setFixedHeight(m_baseHeight);
addParameter(index);
connect(monitor, &Monitor::seekToNextKeyframe, m_keyframeview, &KeyframeView::slotGoToNext, Qt::UniqueConnection);
......@@ -388,6 +392,8 @@ void KeyframeWidget::addParameter(const QPersistentModelIndex &index)
if (paramWidget) {
m_parameters[index] = paramWidget;
m_lay->addWidget(paramWidget);
m_addedHeight += paramWidget->minimumHeight();
setFixedHeight(m_baseHeight + m_addedHeight);
}
}
......@@ -448,8 +454,12 @@ bool KeyframeWidget::keyframesVisible() const
void KeyframeWidget::showKeyframes(bool enable)
{
if (enable && m_toolbar->isVisible()) {
return;
}
m_toolbar->setVisible(enable);
m_keyframeview->setVisible(enable);
setFixedHeight(m_addedHeight + (enable ? m_baseHeight : 0));
}
void KeyframeWidget::slotCopyKeyframes()
......
......@@ -97,6 +97,8 @@ private:
QSize m_sourceFrameSize;
void connectMonitor(bool active);
std::unordered_map<QPersistentModelIndex, QWidget *> m_parameters;
int m_baseHeight;
int m_addedHeight;
signals:
void addIndex(QPersistentModelIndex ix);
......
......@@ -50,6 +50,7 @@ KeywordParamWidget::KeywordParamWidget(std::shared_ptr<AssetParameterModel> mode
comboboxwidget->setCurrentIndex(0);
// set check state
slotRefresh();
setMinimumHeight(comboboxwidget->sizeHint().height());
// emit the signal of the base class when appropriate
connect(lineeditwidget, &QLineEdit::editingFinished, [this]() {
......
......@@ -37,8 +37,9 @@ ListParamWidget::ListParamWidget(std::shared_ptr<AssetParameterModel> model, QMo
setToolTip(comment);
m_labelComment->setText(comment);
m_widgetComment->setHidden(true);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
m_list->setIconSize(QSize(50, 30));
setMinimumHeight(m_list->sizeHint().height());
// setup the name
m_labelName->setText(m_model->data(m_index, Qt::DisplayRole).toString());
slotRefresh();
......
......@@ -32,11 +32,8 @@ static const double GAIN_FACTOR = 4.0;
LumaLiftGainParam::LumaLiftGainParam(std::shared_ptr<AssetParameterModel> model, QModelIndex index, QWidget *parent)
: AbstractParamWidget(std::move(model), index, parent)
{
auto *flowLayout = new FlowLayout(this, 2, 2, 2);
/*QVBoxLayout *layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
*/
m_flowLayout = new FlowLayout(this, 2, 2, 2);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
m_locale.setNumberOptions(QLocale::OmitGroupSeparator);
m_lift = new ColorWheel(QStringLiteral("lift"), i18n("Lift"), NegQColor(), this);
m_lift->setFactorDefaultZero(LIFT_FACTOR, 0, 0.5);
......@@ -54,10 +51,10 @@ LumaLiftGainParam::LumaLiftGainParam(std::shared_ptr<AssetParameterModel> model,
indexes.insert(name, local_index);
}
flowLayout->addWidget(m_lift);
flowLayout->addWidget(m_gamma);
flowLayout->addWidget(m_gain);
setLayout(flowLayout);
m_flowLayout->addWidget(m_lift);
m_flowLayout->addWidget(m_gamma);
m_flowLayout->addWidget(m_gain);
setLayout(m_flowLayout);
slotRefresh();
connect(this, &LumaLiftGainParam::liftChanged, [this, indexes]() {
......@@ -111,11 +108,17 @@ void LumaLiftGainParam::updateEffect(QDomElement &effect)
}
}
void LumaLiftGainParam::resizeEvent(QResizeEvent *ev)
{
setFixedHeight(m_flowLayout->miniHeight());
QWidget::resizeEvent(ev);
emit updateHeight();
}
void LumaLiftGainParam::slotShowComment(bool) {}
void LumaLiftGainParam::slotRefresh()
{
qDebug() << "//REFRESHING WIDGET START--------------__";
QMap<QString, double> values;
for (int i = 0; i < m_model->rowCount(); ++i) {
QModelIndex local_index = m_model->index(i, 0);
......@@ -131,9 +134,7 @@ void LumaLiftGainParam::slotRefresh()
NegQColor gain = NegQColor::fromRgbF(values.value(QStringLiteral("gain_r")) / GAIN_FACTOR, values.value(QStringLiteral("gain_g")) / GAIN_FACTOR,
values.value(QStringLiteral("gain_b")) / GAIN_FACTOR);
qDebug() << "//REFRESHING WIDGET START 2--------------__";
m_lift->setColor(lift);
m_gamma->setColor(gamma);
m_gain->setColor(gain);
qDebug() << "//REFRESHING WIDGET START DONE--------------__";
}
......@@ -26,6 +26,7 @@
#include <QWidget>
class ColorWheel;
class FlowLayout;
/**
* @class LumaLiftGainParam
......@@ -49,6 +50,10 @@ private:
ColorWheel *m_lift;
ColorWheel *m_gamma;
ColorWheel *m_gain;
FlowLayout *m_flowLayout;
protected:
void resizeEvent(QResizeEvent *ev) override;
signals:
/** @brief Emitted whenever a different color was chosen. */
......
......@@ -44,6 +44,7 @@ PositionEditWidget::PositionEditWidget(std::shared_ptr<AssetParameterModel> mode
layout->addWidget(m_display);
m_inverted = m_model->data(m_index, AssetParameterModel::DefaultRole).toInt() < 0;
slotRefresh();
setMinimumHeight(m_display->sizeHint().height());
connect(m_slider, &QAbstractSlider::valueChanged, m_display, static_cast<void (TimecodeDisplay::*)(int)>(&TimecodeDisplay::setValue));
connect(m_display, &TimecodeDisplay::timeCodeEditingFinished, m_slider, &QAbstractSlider::setValue);
......
......@@ -36,6 +36,7 @@ SwitchParamWidget::SwitchParamWidget(std::shared_ptr<AssetParameterModel> model,
// setup the name
m_labelName->setText(m_model->data(m_index, Qt::DisplayRole).toString());
setMinimumHeight(m_labelName->sizeHint().height());
// set check state
slotRefresh();
......
......@@ -43,6 +43,7 @@ UrlParamWidget::UrlParamWidget(std::shared_ptr<AssetParameterModel> model, QMode
// setup the name
label->setText(m_model->data(m_index, Qt::DisplayRole).toString());
setMinimumHeight(urlwidget->sizeHint().height());
// set check state
slotRefresh();
......
......@@ -63,7 +63,7 @@ CollapsibleEffectView::CollapsibleEffectView(const std::shared_ptr<EffectItemMod
decoframe->setObjectName(QStringLiteral("decoframegroup"));
}
filterWheelEvent = true;
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
// decoframe->setProperty("active", true);
// m_info.fromString(effect.attribute(QStringLiteral("kdenlive_info")));
// setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont));
......@@ -132,23 +132,22 @@ CollapsibleEffectView::CollapsibleEffectView(const std::shared_ptr<EffectItemMod
// Color thumb
m_colorIcon->setPixmap(QPixmap::fromImage(icon));
title->setText(effectName);
frame->setMinimumHeight(title->sizeHint().height());
m_view = new AssetParameterView(this);
const std::shared_ptr<AssetParameterModel> effectParamModel = std::static_pointer_cast<AssetParameterModel>(effectModel);
m_view->setModel(effectParamModel, frameSize);
connect(m_view, &AssetParameterView::seekToPos, this, &AbstractCollapsibleWidget::seekToPos);
connect(m_view, &AssetParameterView::updateHeight, this, &CollapsibleEffectView::updateHeight);
connect(this, &CollapsibleEffectView::refresh, m_view, &AssetParameterView::slotRefresh);
m_keyframesButton->setVisible(m_view->keyframesAllowed());
auto *lay = new QVBoxLayout(widgetFrame);
lay->setContentsMargins(0, 0, 0, 2);
lay->setContentsMargins(0, 0, 0, 0);
lay->setSpacing(0);
lay->addWidget(m_view);
connect(m_keyframesButton, &QToolButton::toggled, [this](bool toggle) {
m_view->toggleKeyframes(toggle);
// We need to switch twice to get a correct resize
slotSwitch(!m_model->isCollapsed());
slotSwitch(!m_model->isCollapsed());
});
lay->addWidget(m_view);
if (!effectParamModel->hasMoreThanOneKeyframe()) {
// No keyframe or only one, allow hiding
bool hideByDefault = effectParamModel->data(effectParamModel->index(0, 0), AssetParameterModel::HideKeyframesFirstRole).toBool();
......@@ -212,7 +211,7 @@ CollapsibleEffectView::CollapsibleEffectView(const std::shared_ptr<EffectItemMod
cb->setFocusPolicy(Qt::StrongFocus);
}
m_collapse->setActive(m_model->isCollapsed());
slotSwitch(m_model->isCollapsed());
QMetaObject::invokeMethod(this, "slotSwitch", Qt::QueuedConnection, Q_ARG(bool, m_model->isCollapsed()));
}
CollapsibleEffectView::~CollapsibleEffectView()
......@@ -464,27 +463,23 @@ void CollapsibleEffectView::slotResetEffect()
m_view->resetValues();
}
void CollapsibleEffectView::slotSwitch(bool collapse)
{
widgetFrame->setFixedHeight(collapse ? 0 : m_view->sizeHint().height());
setFixedHeight(widgetFrame->height() + frame->height() + (2 * decoframe->lineWidth()));
// m_view->setVisible(!collapse);
emit switchHeight(m_model, height());
m_model->setCollapsed(collapse);
}
void CollapsibleEffectView::animationChanged(const QVariant &geom)
void CollapsibleEffectView::updateHeight()
{
parentWidget()->setFixedHeight(geom.toRect().height());
if (m_view->height() == widgetFrame->height()) {
return;
}
widgetFrame->setFixedHeight(m_collapse->isActive() ? 0 : m_view->height());
setFixedHeight(widgetFrame->height() + frame->minimumHeight() + 2 * (contentsMargins().top() + decoframe->lineWidth()));
emit switchHeight(m_model, height());
}
void CollapsibleEffectView::animationFinished()
void CollapsibleEffectView::slotSwitch(bool collapse)
{
if (m_collapse->isActive()) {
widgetFrame->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
} else {
widgetFrame->setFixedHeight(m_view->contentHeight());
}
widgetFrame->setFixedHeight(collapse ? 0 : m_view->height());
setFixedHeight(widgetFrame->height() + frame->minimumHeight() + 2 * (contentsMargins().top() + decoframe->lineWidth()));
emit switchHeight(m_model, height());
m_model->setCollapsed(collapse);
}
void CollapsibleEffectView::setGroupIndex(int ix)
......
......@@ -90,10 +90,10 @@ public slots:
void slotResetEffect();
void importKeyframes(const QString &keyframes);
void slotActivateEffect(QModelIndex ix);
void updateHeight();
private slots:
void setWidgetHeight(qreal value);
void animationFinished();
void enableView(bool enabled);
private slots:
......@@ -108,7 +108,6 @@ 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:
AssetParameterView *m_view;
......
......@@ -189,7 +189,7 @@ void EffectStackView::setModel(std::shared_ptr<EffectStackModel> model, const QS
void EffectStackView::loadEffects()
{
qDebug() << "MUTEX LOCK!!!!!!!!!!!! loadEffects: ";
QMutexLocker lock(&m_mutex);
//QMutexLocker lock(&m_mutex);
int max = m_model->rowCount();
if (max == 0) {
// blank stack
......@@ -242,13 +242,17 @@ void EffectStackView::updateTreeHeight()
{
// For some reason, the treeview height does not update correctly, so enforce it
int totalHeight = 0;
m_mutex.lock();
for (int j = 0; j < m_model->rowCount(); j++) {
std::shared_ptr<AbstractEffectItem> item2 = m_model->getEffectStackRow(j);
std::shared_ptr<EffectItemModel> eff = std::static_pointer_cast<EffectItemModel>(item2);
QModelIndex idx = m_model->getIndexFromItem(eff);
auto w = m_effectsTree->indexWidget(idx);
totalHeight += w->height();
if (w) {
totalHeight += w->height();
}
}
m_mutex.unlock();
setMinimumHeight(totalHeight);
}
......@@ -288,11 +292,13 @@ 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);
//QMutexLocker lock(&m_mutex);
QModelIndex ix = m_model->getIndexFromItem(effectModel);
auto *del = static_cast<WidgetDelegate *>(m_effectsTree->itemDelegate(ix));
del->setHeight(ix, height);
updateTreeHeight();
if (del) {
del->setHeight(ix, height);
updateTreeHeight();
}
qDebug() << "MUTEX UNLOCK!!!!!!!!!!!! adjustdelegate";
}
......
......@@ -384,7 +384,7 @@ int TimelineModel::getTrackSortValue(int trackId, int separated) const
return -trackPos;
}
}
return isAudio ? 2 * trackPos : 2 * (vCount + 1 - trackPos) + 1;//((aCount * trackPos) - 1) : (vCount + 1 - trackPos) * 2;
return isAudio ? 2 * trackPos : 2 * (vCount + 1 - trackPos) + 1;
}
QList<int> TimelineModel::getLowerTracksId(int trackId, TrackType type) const
......
......@@ -45,6 +45,8 @@ FlowLayout::FlowLayout(QWidget *parent, int margin, int hSpacing, int vSpacing)
: QLayout(parent)
, m_hSpace(hSpacing)
, m_vSpace(vSpacing)
, m_mini(0)
, m_triggerLayout(false)
{
setContentsMargins(margin, margin, margin, margin);
}
......@@ -138,6 +140,9 @@ QSize FlowLayout::minimumSize() const
}
size += QSize(2 * margin(), 2 * margin());
if (m_mini > 0) {
size.setHeight(m_mini);
}
return size;
}
......@@ -149,29 +154,39 @@ int FlowLayout::doLayout(const QRect &rect, bool testOnly) const
int x = effectiveRect.x();
int y = effectiveRect.y();
int lineHeight = 0;
int hPos = 0;
int itemCount = 0;
int allowedWidth = effectiveRect.width();
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::PushButton, QSizePolicy::PushButton, Qt::Horizontal);
if (spaceX == -1) spaceX = wid->style()->layoutSpacing(QSizePolicy::Frame, QSizePolicy::Frame, Qt::Horizontal);
int spaceY = verticalSpacing();
if (spaceY == -1) spaceY = wid->style()->layoutSpacing(QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Vertical);
int nextX = x + item->sizeHint().width() + spaceX;
if (nextX - spaceX > effectiveRect.right() && lineHeight > 0) {
x = effectiveRect.x();
y = y + lineHeight + spaceY;
nextX = x + item->sizeHint().width() + spaceX;
lineHeight = 0;
}
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));
if (!testOnly) {
item->setGeometry(QRect(QPoint(x, y), item->sizeHint()));
item->setGeometry(QRect(QPoint(x, y), hint));
}
x = nextX;
lineHeight = qMax(lineHeight, item->sizeHint().height());
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());
}
return y + lineHeight - rect.y() + bottom;
m_mini = y + lineHeight - rect.y() + bottom;
return m_mini;
}
int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const
{
......@@ -185,3 +200,9 @@ int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const
}
return static_cast<QLayout *>(parent)->spacing();
}