[Qt] Show ModalOverlay by pressing the progress bar, disabled show() in sync mode

This commit is contained in:
Jonas Schnelli 2016-12-05 09:26:43 +01:00
parent d04aebaec7
commit 89a3723bdc
No known key found for this signature in database
GPG key ID: 29D4BCB6416F53EC
5 changed files with 46 additions and 19 deletions

View file

@ -46,7 +46,6 @@
#include <QMenuBar> #include <QMenuBar>
#include <QMessageBox> #include <QMessageBox>
#include <QMimeData> #include <QMimeData>
#include <QProgressBar>
#include <QProgressDialog> #include <QProgressDialog>
#include <QSettings> #include <QSettings>
#include <QShortcut> #include <QShortcut>
@ -251,6 +250,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle *
if(enableWallet) { if(enableWallet) {
connect(walletFrame, SIGNAL(requestedSyncWarningInfo()), this, SLOT(showModalOverlay())); connect(walletFrame, SIGNAL(requestedSyncWarningInfo()), this, SLOT(showModalOverlay()));
connect(labelBlocksIcon, SIGNAL(clicked(QPoint)), this, SLOT(showModalOverlay())); connect(labelBlocksIcon, SIGNAL(clicked(QPoint)), this, SLOT(showModalOverlay()));
connect(progressBar, SIGNAL(clicked(QPoint)), this, SLOT(showModalOverlay()));
} }
#endif #endif
} }
@ -1138,8 +1138,8 @@ void BitcoinGUI::setTrayIconVisible(bool fHideTrayIcon)
void BitcoinGUI::showModalOverlay() void BitcoinGUI::showModalOverlay()
{ {
if (modalOverlay) if (modalOverlay && (progressBar->isVisible() || modalOverlay->isLayerVisible()))
modalOverlay->showHide(false, true); modalOverlay->toggleVisibility();
} }
static bool ThreadSafeMessageBox(BitcoinGUI *gui, const std::string& message, const std::string& caption, unsigned int style) static bool ThreadSafeMessageBox(BitcoinGUI *gui, const std::string& message, const std::string& caption, unsigned int style)

View file

@ -988,7 +988,12 @@ QString formateNiceTimeOffset(qint64 secs)
return timeBehindText; return timeBehindText;
} }
void ClickableLabel::mousePressEvent(QMouseEvent *event) void ClickableLabel::mouseReleaseEvent(QMouseEvent *event)
{
Q_EMIT clicked(event->pos());
}
void ClickableProgressBar::mouseReleaseEvent(QMouseEvent *event)
{ {
Q_EMIT clicked(event->pos()); Q_EMIT clicked(event->pos());
} }

View file

@ -202,20 +202,6 @@ namespace GUIUtil
QString formateNiceTimeOffset(qint64 secs); QString formateNiceTimeOffset(qint64 secs);
#if defined(Q_OS_MAC) && QT_VERSION >= 0x050000
// 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
class ClickableLabel : public QLabel class ClickableLabel : public QLabel
{ {
Q_OBJECT Q_OBJECT
@ -226,8 +212,35 @@ namespace GUIUtil
*/ */
void clicked(const QPoint& point); void clicked(const QPoint& point);
protected: protected:
void mousePressEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event);
}; };
class ClickableProgressBar : public QProgressBar
{
Q_OBJECT
Q_SIGNALS:
/** Emitted when the progressbar is clicked. The relative mouse coordinates of the click are
* passed to the signal.
*/
void clicked(const QPoint& point);
protected:
void mouseReleaseEvent(QMouseEvent *event);
};
#if defined(Q_OS_MAC) && QT_VERSION >= 0x050000
// 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 ClickableProgressBar
{
bool event(QEvent *e) {
return (e->type() != QEvent::StyleAnimationUpdate) ? QProgressBar::event(e) : false;
}
};
#else
typedef ClickableProgressBar ProgressBar;
#endif
} // namespace GUIUtil } // namespace GUIUtil

View file

@ -137,6 +137,13 @@ void ModalOverlay::tipUpdate(int count, const QDateTime& blockDate, double nVeri
} }
} }
void ModalOverlay::toggleVisibility()
{
showHide(layerIsVisible, true);
if (!layerIsVisible)
userClosed = true;
}
void ModalOverlay::showHide(bool hide, bool userRequested) void ModalOverlay::showHide(bool hide, bool userRequested)
{ {
if ( (layerIsVisible && !hide) || (!layerIsVisible && hide) || (!hide && userClosed && !userRequested)) if ( (layerIsVisible && !hide) || (!layerIsVisible && hide) || (!hide && userClosed && !userRequested))

View file

@ -25,9 +25,11 @@ public Q_SLOTS:
void tipUpdate(int count, const QDateTime& blockDate, double nVerificationProgress); void tipUpdate(int count, const QDateTime& blockDate, double nVerificationProgress);
void setKnownBestHeight(int count, const QDateTime& blockDate); void setKnownBestHeight(int count, const QDateTime& blockDate);
void toggleVisibility();
// will show or hide the modal layer // will show or hide the modal layer
void showHide(bool hide = false, bool userRequested = false); void showHide(bool hide = false, bool userRequested = false);
void closeClicked(); void closeClicked();
bool isLayerVisible() { return layerIsVisible; }
protected: protected:
bool eventFilter(QObject * obj, QEvent * ev); bool eventFilter(QObject * obj, QEvent * ev);