From 6093aa1bb03b03331cc2f48d8f6b749f8817c016 Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Mon, 17 Nov 2014 15:51:33 +0100 Subject: [PATCH 1/2] [Qt, OSX] QProgressBar CPU-Issue workaround fixes #5295 --- src/qt/bitcoingui.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 450b83a8c..06e53ea1e 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -58,6 +58,20 @@ #include #endif +#ifdef Q_OS_MAC +#include + +// workaround for Qt OSX Bug: +// https://bugreports.qt-project.org/browse/QTBUG-15631 +// QProgressBar uses around 10% CPU even when app is in background +class QProgressBarMac : public QProgressBar +{ + bool event(QEvent *e) { + return (e->type() != QEvent::StyleAnimationUpdate) ? QProgressBar::event(e) : false; + } +}; +#endif + const QString BitcoinGUI::DEFAULT_WALLET = "~Default"; BitcoinGUI::BitcoinGUI(const NetworkStyle *networkStyle, QWidget *parent) : @@ -190,7 +204,11 @@ BitcoinGUI::BitcoinGUI(const NetworkStyle *networkStyle, QWidget *parent) : // Progress bar and label for blocks download progressBarLabel = new QLabel(); progressBarLabel->setVisible(false); +#ifdef Q_OS_MAC + progressBar = new QProgressBarMac(); +#else progressBar = new QProgressBar(); +#endif progressBar->setAlignment(Qt::AlignCenter); progressBar->setVisible(false); From 0ceab00d16a1d23da06a748889db25662b16bfb3 Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Tue, 18 Nov 2014 09:55:39 +0100 Subject: [PATCH 2/2] [Qt, OSX] move QProgressBarMac to guiutil.h --- src/qt/bitcoingui.cpp | 20 +------------------- src/qt/guiutil.h | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 06e53ea1e..6a457d361 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -58,20 +58,6 @@ #include #endif -#ifdef Q_OS_MAC -#include - -// workaround for Qt OSX Bug: -// https://bugreports.qt-project.org/browse/QTBUG-15631 -// QProgressBar uses around 10% CPU even when app is in background -class QProgressBarMac : public QProgressBar -{ - bool event(QEvent *e) { - return (e->type() != QEvent::StyleAnimationUpdate) ? QProgressBar::event(e) : false; - } -}; -#endif - const QString BitcoinGUI::DEFAULT_WALLET = "~Default"; BitcoinGUI::BitcoinGUI(const NetworkStyle *networkStyle, QWidget *parent) : @@ -204,11 +190,7 @@ BitcoinGUI::BitcoinGUI(const NetworkStyle *networkStyle, QWidget *parent) : // Progress bar and label for blocks download progressBarLabel = new QLabel(); progressBarLabel->setVisible(false); -#ifdef Q_OS_MAC - progressBar = new QProgressBarMac(); -#else - progressBar = new QProgressBar(); -#endif + progressBar = new GUIUtil::ProgressBar(); progressBar->setAlignment(Qt::AlignCenter); progressBar->setVisible(false); diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index 5666744bd..a6ecfbcc8 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -7,9 +7,11 @@ #include "amount.h" +#include #include #include #include +#include #include #include @@ -186,6 +188,21 @@ namespace GUIUtil /* Format a CNodeCombinedStats.dPingTime into a user-readable string or display N/A, if 0*/ QString formatPingTime(double dPingTime); + +#ifdef Q_OS_MAC + // workaround for Qt OSX Bug: + // https://bugreports.qt-project.org/browse/QTBUG-15631 + // QProgressBar uses around 10% CPU even when app is in background + class ProgressBar : public QProgressBar + { + bool event(QEvent *e) { + return (e->type() != QEvent::StyleAnimationUpdate) ? QProgressBar::event(e) : false; + } + }; +#else + typedef QProgressBar ProgressBar; +#endif + } // namespace GUIUtil #endif // BITCOIN_QT_GUIUTIL_H