Review Request 128201: Improved StatusbarProgressDidget that looks better on OS X and Linux

René J.V. Bertin rjvbertin at gmail.com
Mon Jun 20 08:15:34 UTC 2016



> On June 19, 2016, 9:19 p.m., David Faure wrote:
> > OK forget trying to match the objectname of a widget's style. I would still do the "runtime check" on sizeHint (as you do) in all cases, which almost removes the need for objectname comparisons.
> 
> René J.V. Bertin wrote:
>     Would you want me to initialise `maximumHeight` from `m_pProgressBar->`*sizeHint*`().height()`, which would give a whopping big button like in https://git.reviewboard.kde.org/r/128201/file/3134/ ? 
>     
>     I could however initialise `maximumHeight` from `m_pProgressBar->minimumSizeHint().height` everywhere except when `macWidgetStyle` (in that case I'd use `sizeHint().height()`). That way, `maximumHeight` won't change compared to its current value; presumably because all other styles I tried (Breeze, Oxygen, QtCurve, Fusion, Windows) set the progressbar height to the font label height plus a bit of margin.
>     
>     However, this doesn't remove the need for the first `macWidgetStyle` check, and I also don't see how I could get rid of the 2nd check reliably. I could do
>     
>     ```
>         if (maximumHeight > fontMetrics.height() + 2) {
>             m_pButton->setMaximumWidth( m_pButton->iconSize().width() + 4 );
>         } else {
>             m_pButton->setAttribute( Qt::WA_LayoutUsesWidgetRect, true );
>             stack->setMaximumHeight( maximumHeight );
>         }
>     ```
>     
>     instead of the current
>     
>     ```
>         if (macWidgetStyle) {
>             m_pButton->setMaximumWidth( m_pButton->iconSize().width() + 4 );
>         } else {
>             m_pButton->setAttribute( Qt::WA_LayoutUsesWidgetRect, true );
>             stack->setMaximumHeight( maximumHeight );
>         }
>     ```
>     
>     but I don't find that more readable, the need for different treatment isn't a direct cause of the height difference, and as I said before, we cannot be certain that the height comparison is only true with the macintosh style. 
>     
>     Am I overlooking something?
> 
> David Faure wrote:
>     I thought simply something like
>         int maximumHeight = qMin(fontMetrics().height(), m_pProgressBar->sizeHint().height() - 8)
>     on all platforms, and applying that height to both button and label?
>     
>     (the 8 is from the sizeHint code).
>     
>     Calling minimumSizeHint on a progressbar isn't really useful, it's the same as fontMetrics().height() + 2, which is what the old code did, no?
> 
> René J.V. Bertin wrote:
>     Yes, minimumSizeHint() returns the same as fontMetrics().height + 2, but you can also say that sizeHint().height == fontMetrics().height + 8. For the styles we've tested and except for OS X where sizeHint().height == fontMetrics().height + 4, apparently. So with all those other styles your qMin would be comparing 2 equal values. With the `macintosh` style I get `maximumHeight=m_pProgressBar->sizeHint().height()==20` regardless of font size (which is almost impossible to vary with the native style anyway) and this is in fact what `maximumHeight` should be set to even if it happens to be larger.
>     
>     You could do
>     
>     int maximumHeight = m_pProgressBar->sizeHint().height() - (macWidgetStyle ? 0 : 6)
>     
>     That always returns 20 with the mac style, and something font-dependent with the other styles.
>     but then you still need the if(macWidgetStyle)/else block for the style specific icon sizing and button form.
>     
>     I've reorganised the code more or less following these considerations. In the end it seems I can do without a 2nd macWidgetStyle test because the order of operations matters less than I thought.
> 
> David Faure wrote:
>     I don't see what makes you say "sizeHint().height == fontMetrics().height + 8.".
>     
>     The QProgressBar code says
>     ```
>     QSize QProgressBar::sizeHint() const
>     {
>         ensurePolished();
>         QFontMetrics fm = fontMetrics();
>         QStyleOptionProgressBar opt;
>         initStyleOption(&opt);
>         int cw = style()->pixelMetric(QStyle::PM_ProgressBarChunkWidth, &opt, this);
>         QSize size = QSize(qMax(9, cw) * 7 + fm.width(QLatin1Char('0')) * 4, fm.height() + 8);
>         if (opt.orientation == Qt::Vertical)
>             size = size.transposed();
>         return style()->sizeFromContents(QStyle::CT_ProgressBar, &opt, size, this);
>     }
>     ```
>     and CT_ProgressBar returns a fixed value on Mac (1), independent from the input "size", I thought this was what this is all about.
>     
>     (1) qt_mac_aqua_get_metric(kThemeMetricNormalProgressBarThickness) + qt_mac_aqua_get_metric(kThemeMetricSmallProgressBarShadowOutset);

> I don't see what makes you say "sizeHint().height == fontMetrics().height + 8.".

>From a post far above:
```
QtCurve:
maximumHeight= 18 progBar height= 30 sizeHint: QSize(91, 24) minSizeHint: QSize(91, 18)
new? progBar height= 30 sizeHint: QSize(91, 24) minSizeHint: QSize(91, 18)
Breeze:
maximumHeight= 18 progBar height= 30 sizeHint: QSize(91, 24) minSizeHint: QSize(91, 18)
new? progBar height= 30 sizeHint: QSize(91, 24) minSizeHint: QSize(91, 18)
Oxygen:
maximumHeight= 18 progBar height= 30 sizeHint: QSize(91, 24) minSizeHint: QSize(91, 18)
new? progBar height= 30 sizeHint: QSize(91, 24) minSizeHint: QSize(91, 18)

```

where `maximumHeight=fontMetrics().height()+2`. In my book `24 - (18-2)` is still 8 ;)
I have since confirmed that for Fusion and "Windows" too. Empirically; as you know from `QProgressBar::sizeHint()` the style has the last word. I would have tried to understand that from the code if the observation didn't seem so logical: all those styles display the actual progress with a text label in or next to the progressbar so the bar's height has to be coupled to the text height.

> I thought this was what this is all about.

Not only. This is about a TaskbarProgressWidget that looks correct with all styles, and even if `CT_ProgressBar returns a fixed value on Mac` is a main aspect in that question, it is not the only one that needs to be considered. The icon size could be made to depend solely on `maximumHeight`, but I don't see how I could take the other decision with only that criterium. If `sizeHint().height()` depends on font size it can take on the macintosh style value with any of the other widget styles depending on font size.

I'll have a look later today how the widget looks when I set it up identically with the other styles (= a flat button sized exactly to a slightly larger icon) and post screenshots if that looks OK.


- René J.V.


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://git.reviewboard.kde.org/r/128201/#review96725
-----------------------------------------------------------


On June 19, 2016, 3:12 p.m., René J.V. Bertin wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://git.reviewboard.kde.org/r/128201/
> -----------------------------------------------------------
> 
> (Updated June 19, 2016, 3:12 p.m.)
> 
> 
> Review request for KDevelop and David Faure.
> 
> 
> Repository: kdevplatform
> 
> 
> Description
> -------
> 
> I came across this old bit of code, judging from the use of the deprecated `Q_OS_MAC` token. 
> Some quick testing suggests that using `WA_LayoutUsesWidgetRect` achieves what I think is the intended effect without platform-specific code. (That platform test ought really check for using the `macintosh` widget style btw, rather than "are we running on OS X").
> 
> 
> Diffs
> -----
> 
>   shell/progresswidget/statusbarprogresswidget.cpp 1a32ea8 
> 
> Diff: https://git.reviewboard.kde.org/r/128201/diff/
> 
> 
> Testing
> -------
> 
> For now only on OS X, with the native theme as well as QtCurve, Breeze and Oxygen.
> 
> 
> File Attachments
> ----------------
> 
> OS X/Mac native *without* the patch
>   https://git.reviewboard.kde.org/media/uploaded/files/2016/06/16/1498e8dc-4541-473b-b6db-2c2ae138cbc3__Screen_Shot_2016-06-17_at_00.17.17.png
> stock widget under Linux (same layout using Breeze)
>   https://git.reviewboard.kde.org/media/uploaded/files/2016/06/17/dd352994-1753-4b33-a0d2-cd2a3132df48__progress-stock.png
> OS X/native with the new patch
>   https://git.reviewboard.kde.org/media/uploaded/files/2016/06/18/8e6a0761-b760-4f41-be67-7f9ba7318349__Screen_Shot_2016-06-18_at_19.21.52.png
> OS X using QtCurve with the new patch
>   https://git.reviewboard.kde.org/media/uploaded/files/2016/06/18/3535be4c-3034-493d-88c0-61ab9a13844d__Screen_Shot_2016-06-18_at_19.24.46.png
> Linux, Breeze, new patch
>   https://git.reviewboard.kde.org/media/uploaded/files/2016/06/18/359d5f57-bdaa-45a7-a0b0-6acb5609459f__Screen_Shot_2016-06-18_at_19.16.19.png
> Linux, QtCurve, new patch
>   https://git.reviewboard.kde.org/media/uploaded/files/2016/06/18/f5eb0902-884a-47e5-bf84-a3581a21bece__Screen_Shot_2016-06-18_at_19.14.17.png
> Linux, Oxygen, new patch
>   https://git.reviewboard.kde.org/media/uploaded/files/2016/06/18/536d4f09-8409-4eb4-80ca-27d3f744d6a0__Screen_Shot_2016-06-18_at_19.16.56.png
> Linux, Breeze + Breeze icons, new patch
>   https://git.reviewboard.kde.org/media/uploaded/files/2016/06/19/ee2d687e-69ea-493f-9ae4-87d90be614e2__progress-patched-breeze.png
> Linux, QtCurve + Breeze icons, new patch
>   https://git.reviewboard.kde.org/media/uploaded/files/2016/06/19/7e3cfc5c-cb80-491c-b4d2-4d6f9c839a48__progress-patched-qtcurve.png
> Linux,Oxygen+Breeze icons, new patch
>   https://git.reviewboard.kde.org/media/uploaded/files/2016/06/19/0b10d97d-3ba6-4d05-a663-3a03e29bc1c9__progress-patched-oxygen.png
> Linux, Breeze, new patch with maximumHeight from progressBar->sizeHint().height()
>   https://git.reviewboard.kde.org/media/uploaded/files/2016/06/19/2a5b48bf-38f1-4ba9-a291-5de65537f8e1__progress-patched-breeze2.png
> 
> 
> Thanks,
> 
> René J.V. Bertin
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20160620/ca7277dc/attachment-0001.html>


More information about the KDevelop-devel mailing list