Skip to content

Commit

Permalink
[Qt] Show ModalOverlay by pressing the progress bar, disabled show() …
Browse files Browse the repository at this point in the history
…in sync mode
  • Loading branch information
jonasschnelli committed Dec 5, 2016
1 parent d04aeba commit 89a3723
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
#include <QMenuBar>
#include <QMessageBox>
#include <QMimeData>
#include <QProgressBar>
#include <QProgressDialog>
#include <QSettings>
#include <QShortcut>
Expand Down Expand Up @@ -251,6 +250,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle *
if(enableWallet) {
connect(walletFrame, SIGNAL(requestedSyncWarningInfo()), this, SLOT(showModalOverlay()));
connect(labelBlocksIcon, SIGNAL(clicked(QPoint)), this, SLOT(showModalOverlay()));
connect(progressBar, SIGNAL(clicked(QPoint)), this, SLOT(showModalOverlay()));
}
#endif
}
Expand Down Expand Up @@ -1138,8 +1138,8 @@ void BitcoinGUI::setTrayIconVisible(bool fHideTrayIcon)

void BitcoinGUI::showModalOverlay()
{
if (modalOverlay)
modalOverlay->showHide(false, true);
if (modalOverlay && (progressBar->isVisible() || modalOverlay->isLayerVisible()))
modalOverlay->toggleVisibility();
}

static bool ThreadSafeMessageBox(BitcoinGUI *gui, const std::string& message, const std::string& caption, unsigned int style)
Expand Down
7 changes: 6 additions & 1 deletion src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,12 @@ QString formateNiceTimeOffset(qint64 secs)
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());
}
Expand Down
43 changes: 28 additions & 15 deletions src/qt/guiutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,20 +202,6 @@ namespace GUIUtil

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
{
Q_OBJECT
Expand All @@ -226,8 +212,35 @@ namespace GUIUtil
*/
void clicked(const QPoint& point);
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

Expand Down
7 changes: 7 additions & 0 deletions src/qt/modaloverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
if ( (layerIsVisible && !hide) || (!layerIsVisible && hide) || (!hide && userClosed && !userRequested))
Expand Down
2 changes: 2 additions & 0 deletions src/qt/modaloverlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ public Q_SLOTS:
void tipUpdate(int count, const QDateTime& blockDate, double nVerificationProgress);
void setKnownBestHeight(int count, const QDateTime& blockDate);

void toggleVisibility();
// will show or hide the modal layer
void showHide(bool hide = false, bool userRequested = false);
void closeClicked();
bool isLayerVisible() { return layerIsVisible; }

protected:
bool eventFilter(QObject * obj, QEvent * ev);
Expand Down

0 comments on commit 89a3723

Please sign in to comment.