1313 */
1414
1515#include " buttondelegate.h"
16+ #include " common/utility.h"
1617#include " commonstrings.h"
1718
1819#include " iconresources.h"
2627#include < QTreeView>
2728namespace OCC {
2829
29- ButtonDelegate::ButtonDelegate (const QString &text, QAbstractItemView *parent)
30+ ButtonDelegate::ButtonDelegate (QAbstractItemView *parent)
3031 : QItemDelegate{parent}
31- , _buttonText(text)
3232{
33- // note we will update the widget parent in the first createEditor as that passes the correct parent for the pop
3433 // we can't really get the "right" parent here, and reusing the button is simpler and I'd guess slightly more efficient
35- // than creating it over and over in create editor.
34+ // than creating it over and over in createEditor.
35+ // note we update the widget parent in the first call to createEditor as that passes the correct parent
36+ // Not a leak!
37+ _button = new QPushButton ();
38+
39+ // on mac set the button to flat to get rid of crazy attempt to make it look "3d" or something
40+ if (Utility::isMac ())
41+ _button->setFlat (true );
3642
37- // _button = new QPushButton(_buttonText);
3843 // this is so shady: if I set the icon to 24x24 it still comes out at around 18x18
39- // note the button height is actually 32 so I don't understand what the issue is.
40- // this can only be identified by trial and error as the pixmap set on the button knows it's size (whatever I give it),
41- // but it does not match the de facto painted size in the button.
42- // I can't find the prop for how that works so will go with this for now
43- // True test is whether it also works on windows. I expect it does not .
44- QIcon elipsesIcon = IconResources::getCoreIcon ( " more " ). pixmap ( 18 , 18 );
45- _button = new QPushButton ( " " );
44+ // note the button height is actually 32 so I don't understand what the issue is if it's 24x24 .
45+ // the target size could only be identified by trial and error so far.
46+ // To get a more robust impl, the only option I have found for getting the actual size of the button icon (maybe!)
47+ // requires getting it from the style option in play, which needs a call button->initializeStyleOption.
48+ // This function is protected so I'm not going crazy with that yet .
49+ // so far this impl works on both win and mac so I'm leaving it with the "hack" for now.
50+ QIcon elipsesIcon = IconResources::getCoreIcon ( " more " ). pixmap (_targetIconSize, _targetIconSize );
4651 _button->setIcon (elipsesIcon);
4752 _button->setObjectName (" buttonDelegateButton" );
4853 _button->setFocusPolicy (Qt::StrongFocus);
@@ -66,21 +71,13 @@ void ButtonDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option
6671 // this is a top level row (invalid parent index)
6772 // AND
6873 // the button is not visible OR it's visible but somewhere else, most likely in another row
74+ // the idea is we *don't* want to paint the placeholder if the button is actually there, as it bleeds through
75+ // (button->setAutoFillBackground(true) is not an option as it has undesired side effects)
6976 if (!index.parent ().isValid () && (!_button->isVisible () || !option.rect .contains (_button->pos ()))) {
70- // for reasons I can't even guess, the icon on the button is smaller than the requested 24x24.
71- // so eyeball and hardcode the placeholder size so it's not too big.
72- int placeholderSize = 18 ;
73- /* QStyleOptionButton buttonStyle;
74- _button->initStyleOption(&buttonStyle); -> nope! this is protected, naturally.
75- QSize optionSize = buttonStyle.iconSize; // this is -1, -1
76- // qDebug() << "option size = " << optionSize;
77- // option.icon.actualSize(optionSize);
78- qDebug() << "option size = " << optionSize;
79- */
80- int xpos = option.rect .left () + (option.rect .width () - placeholderSize) / 2 ;
81- int ypos = option.rect .top () + (option.rect .height () - placeholderSize) / 2 ;
82- QPixmap ellipses = IconResources::getCoreIcon (" more" ).pixmap (placeholderSize, placeholderSize);
83- QRect target (xpos, ypos, placeholderSize, placeholderSize);
77+ int xpos = option.rect .left () + (option.rect .width () - _targetIconSize) / 2 ;
78+ int ypos = option.rect .top () + (option.rect .height () - _targetIconSize) / 2 ;
79+ QPixmap ellipses = IconResources::getCoreIcon (" more" ).pixmap (_targetIconSize, _targetIconSize);
80+ QRect target (xpos, ypos, _targetIconSize, _targetIconSize);
8481 painter->drawPixmap (target, ellipses);
8582 }
8683
0 commit comments