Fix progress bars positioning in Qt client on Mac (#4489)

This is a workaround for QTBUG-67830, where progress bars seem to be drawn
regardless of style option's rect top-left coordinates.
This commit is contained in:
Mike Gelfand 2022-12-28 06:46:23 -08:00 committed by GitHub
parent 5ce503f1ab
commit 3510439c78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 3 deletions

View File

@ -8,6 +8,7 @@
#include "FileTreeDelegate.h"
#include "FileTreeModel.h"
#include "StyleHelper.h"
QSize FileTreeDelegate::sizeHint(QStyleOptionViewItem const& item, QModelIndex const& index) const
{
@ -58,7 +59,7 @@ void FileTreeDelegate::paint(QPainter* painter, QStyleOptionViewItem const& opti
p.textVisible = true;
p.progress = static_cast<int>(100.0 * index.data().toDouble());
p.text = QStringLiteral("%1%").arg(p.progress);
style->drawControl(QStyle::CE_ProgressBar, &p, painter);
StyleHelper::drawProgressBar(*style, *painter, p);
}
else if (column == FileTreeModel::COL_WANTED)
{

View File

@ -3,6 +3,9 @@
// or any future license endorsed by Mnemosyne LLC.
// License text can be found in the licenses/ folder.
#include <QPainter>
#include <QStyleOptionProgressBar>
#include "StyleHelper.h"
QIcon::Mode StyleHelper::getIconMode(QStyle::State const& state)
@ -19,3 +22,20 @@ QIcon::Mode StyleHelper::getIconMode(QStyle::State const& state)
return QIcon::Normal;
}
void StyleHelper::drawProgressBar(QStyle const& style, QPainter& painter, QStyleOptionProgressBar const& option)
{
// Workaround for https://bugreports.qt.io/browse/QTBUG-67830
#ifdef Q_OS_DARWIN
auto my_option = option;
my_option.rect.translate(-option.rect.topLeft());
painter.save();
painter.translate(option.rect.topLeft());
style.drawControl(QStyle::CE_ProgressBar, &my_option, &painter);
painter.restore();
#else
style.drawControl(QStyle::CE_ProgressBar, &option, &painter);
#endif
}

View File

@ -8,8 +8,13 @@
#include <QIcon>
#include <QStyle>
class QPainter;
class QStyleOptionProgressBar;
class StyleHelper
{
public:
static QIcon::Mode getIconMode(QStyle::State const& state);
static void drawProgressBar(QStyle const& style, QPainter& painter, QStyleOptionProgressBar const& option);
};

View File

@ -17,6 +17,7 @@
#include "Formatter.h"
#include "IconCache.h"
#include "StyleHelper.h"
#include "Torrent.h"
#include "TorrentDelegate.h"
#include "TorrentModel.h"
@ -600,7 +601,7 @@ void TorrentDelegate::drawTorrent(QPainter* painter, QStyleOptionViewItem const&
progress_bar_style_.state = progress_bar_state;
setProgressBarPercentDone(option, tor);
style->drawControl(QStyle::CE_ProgressBar, &progress_bar_style_, painter);
StyleHelper::drawProgressBar(*style, *painter, progress_bar_style_);
painter->restore();
}

View File

@ -21,6 +21,7 @@
#include <libtransmission/utils.h>
#include "StyleHelper.h"
#include "Torrent.h"
#include "TorrentDelegateMin.h"
#include "TorrentModel.h"
@ -288,7 +289,7 @@ void TorrentDelegateMin::drawTorrent(QPainter* painter, QStyleOptionViewItem con
progress_bar_style_.textVisible = true;
progress_bar_style_.textAlignment = Qt::AlignCenter;
setProgressBarPercentDone(option, tor);
style->drawControl(QStyle::CE_ProgressBar, &progress_bar_style_, painter);
StyleHelper::drawProgressBar(*style, *painter, progress_bar_style_);
painter->restore();
}