Skip to content

Commit 37436a2

Browse files
committed
updates that look ok on windows
note it is a must to go back to fusion style as there are bugs with the win11 style, especially related to item views
1 parent 73ab24c commit 37436a2

4 files changed

Lines changed: 30 additions & 31 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: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414

1515
#include "buttondelegate.h"
16+
#include "common/utility.h"
1617
#include "commonstrings.h"
1718

1819
#include "iconresources.h"
@@ -26,23 +27,27 @@
2627
#include <QTreeView>
2728
namespace 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

src/gui/FoldersGui/buttondelegate.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ 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;
@@ -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)