<table><tr><td style="">rjvbb requested changes to this revision.<br />rjvbb added a comment.<br />This revision now requires changes to proceed.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D15625">View Revision</a></tr></table><br /><div><div><p>It works and can go in with just one minor change request.</p>
<p>I still need the fallback protection though. I added some additional debug output (see below) which shows what is really going on for me: maximumWidth is calculated to be 0. I haven't tried to figure out if that's an anomaly, but it explains why I'm getting only small items.</p>
<p>This happens only with my QtCurve style; if you want to bite in deeper I can share my settings (and fonts, if needed).</p>
<div class="remarkup-code-block" style="margin: 12px 0;" data-code-lang="diff" data-sigil="remarkup-code-block"><pre class="remarkup-code" style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; padding: 12px; margin: 0; background: rgba(71, 87, 120, 0.08);"><span style="color: #000080">diff --git a/kdevplatform/sublime/ideallayout.cpp b/kdevplatform/sublime/ideallayout.cpp</span>
<span style="color: #000080">index 8bc43479197dfb1b018b780c116034c3f1fc7e69..4157743641fc8024e1d5b8813ccac52b66e71a5c 100644</span>
<span style="color: #a00000">--- a/kdevplatform/sublime/ideallayout.cpp</span>
<span style="color: #00a000">+++ b/kdevplatform/sublime/ideallayout.cpp</span>
<span style="color: #800080">@@ -22,6 +22,8 @@</span>
#include "ideallayout.h"
<span style="color: #00a000">+#include <debug.h></span>
<span style="color: #00a000">+</span>
#include <QStyle>
#include <QWidget>
<span style="color: #800080">@@ -202,25 +204,36 @@ int IdealButtonBarLayout::doVerticalLayout(const QRect &rect, bool updateGeometr</span>
return x + currentLineWidth + r;
}
<span style="color: #a00000">- const bool shrink = rect.height() < sizeHint().height();</span>
<span style="color: #00a000">+ bool shrink = rect.height() < sizeHint().height();</span>
<span style="color: #a00000">- const int maximumHeight = rect.height() / _items.size();</span>
<span style="color: #00a000">+ // space left per button after removing available space for buttonSpacing</span>
<span style="color: #00a000">+ const int maximumHeight = (rect.height() - buttonSpacing * (_items.size() - 1)) / _items.size();</span>
int shrinkedHeight = -1;
if (shrink) {
int smallItemCount = 0;
<span style="color: #a00000">- const int surplus = std::accumulate(_items.begin(), _items.end(), 0, [maximumHeight, &smallItemCount](int acc, QLayoutItem* item) {</span>
<span style="color: #00a000">+ int minHeight = _items.at(0)->sizeHint().height();</span>
<span style="color: #00a000">+ const int surplus = std::accumulate(_items.begin(), _items.end(), 0, [maximumHeight, &smallItemCount, &minHeight](int acc, QLayoutItem* item) {</span>
const int itemHeight = item->sizeHint().height();
if (itemHeight <= maximumHeight) {
acc += maximumHeight - itemHeight;
++smallItemCount;
}
<span style="color: #00a000">+ if (itemHeight < minHeight) {</span>
<span style="color: #00a000">+ minHeight = itemHeight;</span>
<span style="color: #00a000">+ }</span>
return acc;
});
<span style="color: #a00000">- Q_ASSERT(_items.size() != smallItemCount); // should be true since rect.width != sizeHint.width</span>
<span style="color: #a00000">- // evenly distribute surplus height over large items</span>
<span style="color: #a00000">- shrinkedHeight = maximumHeight + surplus / (_items.size() - smallItemCount);</span>
<span style="color: #00a000">+ // Sanity check to prevent against a divide-by-zero due to some latent miscalculations</span>
<span style="color: #00a000">+ if (_items.size() != smallItemCount) {</span>
<span style="color: #00a000">+ // evenly distribute surplus height over large items</span>
<span style="color: #00a000">+ shrinkedHeight = maximumHeight + surplus / (_items.size() - smallItemCount);</span>
<span style="color: #00a000">+ } else {</span>
<span style="color: #00a000">+ qCDebug(SUBLIME) << "Expected at least one large item, none found, possible erraneous shrink predicate or sizeHint";</span>
<span style="color: #00a000">+ qCDebug(SUBLIME) << "\tthreshold height=" << maximumHeight << "min width found:" << minHeight;</span>
<span style="color: #00a000">+ shrink = false;</span>
<span style="color: #00a000">+ }</span>
}
for (QLayoutItem* item : _items) {
<span style="color: #800080">@@ -260,25 +273,36 @@ int IdealButtonBarLayout::doHorizontalLayout(const QRect &rect, bool updateGeome</span>
return y + currentLineHeight + b;
}
<span style="color: #a00000">- const bool shrink = rect.width() < sizeHint().width();</span>
<span style="color: #00a000">+ bool shrink = rect.width() < sizeHint().width();</span>
<span style="color: #a00000">- const int maximumWidth = rect.width() / _items.size();</span>
<span style="color: #00a000">+ // space left per button after removing available space for buttonSpacing</span>
<span style="color: #00a000">+ const int maximumWidth = (rect.width() - buttonSpacing * (_items.size() - 1)) / _items.size();</span>
int shrinkedWidth = -1;
if (shrink) {
int smallItemCount = 0;
<span style="color: #a00000">- const int surplus = std::accumulate(_items.begin(), _items.end(), 0, [maximumWidth, &smallItemCount](int acc, QLayoutItem* item) {</span>
<span style="color: #00a000">+ int minWidth = _items.at(0)->sizeHint().width();</span>
<span style="color: #00a000">+ const int surplus = std::accumulate(_items.begin(), _items.end(), 0, [maximumWidth, &smallItemCount, &minWidth](int acc, QLayoutItem* item) {</span>
const int itemWidth = item->sizeHint().width();
if (itemWidth <= maximumWidth) {
acc += maximumWidth - itemWidth;
++smallItemCount;
}
<span style="color: #00a000">+ if (itemWidth < minWidth) {</span>
<span style="color: #00a000">+ minWidth = itemWidth;</span>
<span style="color: #00a000">+ }</span>
return acc;
});
<span style="color: #a00000">- Q_ASSERT(_items.size() != smallItemCount); // should be true since rect.width != sizeHint.width</span>
<span style="color: #a00000">- // evenly distribute surplus width on the large items</span>
<span style="color: #a00000">- shrinkedWidth = maximumWidth + surplus / (_items.size() - smallItemCount);</span>
<span style="color: #00a000">+ // Sanity check to prevent against a divide-by-zero due to some latent miscalculations</span>
<span style="color: #00a000">+ if (_items.size() != smallItemCount) {</span>
<span style="color: #00a000">+ // evenly distribute surplus width on the large items</span>
<span style="color: #00a000">+ shrinkedWidth = maximumWidth + surplus / (_items.size() - smallItemCount);</span>
<span style="color: #00a000">+ } else {</span>
<span style="color: #00a000">+ qCDebug(SUBLIME) << "Expected at least one large item, none found, possible erraneous shrink predicate or sizeHint";</span>
<span style="color: #00a000">+ qCDebug(SUBLIME) << "\tthreshold width=" << maximumWidth << "min width found:" << minWidth;</span>
<span style="color: #00a000">+ shrink = false;</span>
<span style="color: #00a000">+ }</span>
}
for (QLayoutItem* item : _items) {</pre></div></div></div><br /><div><strong>INLINE COMMENTS</strong><div><div style="margin: 6px 0 12px 0;"><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D15625#inline-84922">View Inline</a><span style="color: #4b4d51; font-weight: bold;">ideallayout.cpp:293</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="p">}</span> <span style="color: #aa4000">else</span> <span class="p">{</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="n">qCWarning</span><span class="p">(</span><span class="n">SUBLIME</span><span class="p">)</span> <span style="color: #aa2211"><<</span> <span style="color: #766510">"Expected at least one large item, none found, possible erraneous shrink predicate or sizeHint"</span><span class="p">;</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="n">shrink</span> <span style="color: #aa2211">=</span> <span style="color: #304a96">false</span><span class="p">;</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">Please make this a qCDebug; no need to bother the user with this information because it will be printed really lots of times if the situation arises.</p></div></div></div></div></div><br /><div><strong>REPOSITORY</strong><div><div>R32 KDevelop</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D15625">https://phabricator.kde.org/D15625</a></div></div><br /><div><strong>To: </strong>amhndu, KDevelop, kossebau, rjvbb<br /><strong>Cc: </strong>kossebau, rjvbb, kdevelop-devel, glebaccon, antismap, iodelay, vbspam, geetamc, Pilzschaf, akshaydeo, surgenight, arrowd<br /></div>