1313 */
1414
1515#include " buttondelegate.h"
16+ #include " common/utility.h"
1617#include " commonstrings.h"
1718
19+ #include " iconresources.h"
20+
1821#include < QAbstractItemView>
1922#include < QEvent>
2023#include < QPainter>
2124#include < QPushButton>
2225#include < QStandardItemModel>
26+ #include < QStyleOptionButton>
2327#include < QTreeView>
24-
2528namespace OCC {
2629
27- ButtonDelegate::ButtonDelegate (const QString &text, QAbstractItemView *parent)
30+ ButtonDelegate::ButtonDelegate (QAbstractItemView *parent)
2831 : QItemDelegate{parent}
29- , _buttonText(text)
3032{
31- // note we will update the widget parent in the first createEditor as that passes the correct parent for the pop
3233 // we can't really get the "right" parent here, and reusing the button is simpler and I'd guess slightly more efficient
33- // than creating it over and over in create editor.
34-
35- _button = new QPushButton (_buttonText);
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 );
42+
43+ // this is so shady: if I set the icon to 24x24 it still comes out at around 18x18
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);
51+ _button->setIcon (elipsesIcon);
3652 _button->setObjectName (" buttonDelegateButton" );
3753 _button->setFocusPolicy (Qt::StrongFocus);
3854 _button->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
@@ -50,16 +66,19 @@ void ButtonDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option
5066 drawBackground (painter, opt, index);
5167
5268 painter->save ();
53- // this rigamarole is "needed" because if I set the button to autoFillBackground (which is super normal) there are weird artifacts of
54- // the window color above and below the button. No idea. This is on mac at least. The fix is to not paint the text dots if the button
55- // is showing on the current cell, as if we paint them there is bleed through visibility of the text under the button since we apparently
56- // autoFillBackground has to be off :/
69+
70+ // the test here for painting the button placeholder:
71+ // this is a top level row (invalid parent index)
72+ // AND
73+ // 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)
5776 if (!index.parent ().isValid () && (!_button->isVisible () || !option.rect .contains (_button->pos ()))) {
58- QFont f = painter-> font () ;
59- f. setBold ( true ) ;
60- f. setPixelSize ( 18 );
61- painter-> setFont (f );
62- painter->drawText (option. rect , Qt::AlignCenter, _buttonText );
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 );
81+ painter->drawPixmap (target, ellipses );
6382 }
6483
6584 painter->setPen (QPen (QBrush (" #807F7F7F" ), 1 ));
0 commit comments