Skip to content

Commit 303063b

Browse files
authored
refactor: [DC-292] improve the ... paints on folder "more" button (#12635)
* switched to using icon again * went back to fusion style on windows due to bugs in win11 style
1 parent 9098e19 commit 303063b

4 files changed

Lines changed: 43 additions & 22 deletions

File tree

src/gui/FoldersGui/accountfoldersview.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ void AccountFoldersView::buildView()
121121

122122
FolderItemDelegate *delegate = new FolderItemDelegate(_treeView->indentation(), _treeView);
123123
_treeView->setItemDelegateForColumn(0, delegate);
124-
// note this is not the normal ellipses character, it's vertically centered instead of positioned at font baseline. This is better
125-
// for this button than normal ellipses. We also have an elipses icon (core/more.svg) but it looks quite bad in the button so text it is
126-
ButtonDelegate *buttonDel = new ButtonDelegate("", _treeView);
124+
ButtonDelegate *buttonDel = new ButtonDelegate(_treeView);
127125
buttonDel->setMenu(_itemMenu);
128126
_treeView->setItemDelegateForColumn(1, buttonDel);
129127

src/gui/FoldersGui/buttondelegate.cpp

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,42 @@
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-
2528
namespace 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));

src/gui/FoldersGui/buttondelegate.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ namespace OCC {
2424
class ButtonDelegate : public QItemDelegate
2525
{
2626
public:
27-
ButtonDelegate(const QString &text, QAbstractItemView *parent);
27+
ButtonDelegate(QAbstractItemView *parent);
2828

2929
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
3030
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
3131

3232
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
33-
// void closeEditor()
33+
3434
void destroyEditor(QWidget *editor, const QModelIndex &index) const override;
3535
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
3636

@@ -39,7 +39,7 @@ class ButtonDelegate : public QItemDelegate
3939

4040
private:
4141
QPushButton *_button = nullptr;
42-
QString _buttonText;
4342
bool _clickThrough = false;
43+
inline static const int _targetIconSize = 18;
4444
};
4545
}

src/libsync/platform_win.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <QIcon>
2424
#include <QLoggingCategory>
2525
#include <QQuickStyle>
26+
#include <QStyleFactory>
2627

2728

2829
#include <chrono>
@@ -69,6 +70,9 @@ void WinPlatform::setApplication(QCoreApplication *application)
6970

7071
if (auto guiApp = qobject_cast<QGuiApplication *>(application)) {
7172
// let qt pick which style for windows instead of hard coding it.
73+
// nope - unfortunately win11 style is full of bugs. Set it back to fusion until we can update qt lib which
74+
// allegedly has fixes for win 11 style.
75+
QApplication::setStyle(QStyleFactory::create("Fusion"));
7276
// can't set quick style to anything other than fusion or it will crash on start
7377
// qml is going away so no, I am not going to take the time to find out how to load the other default windows
7478
// styles for qml. Frankly I'm pretty shocked it doesn't just work naturally the way normal style does.

0 commit comments

Comments
 (0)