Qt: set up taskbar progress for the gs_frame

This commit is contained in:
Megamouse 2018-06-08 15:20:18 +02:00 committed by kd-11
parent b9b6bd85a6
commit 17250bc2d4
2 changed files with 127 additions and 0 deletions

View File

@ -62,6 +62,32 @@ gs_frame::gs_frame(const QString& title, const QRect& geometry, QIcon appIcon, b
// Change cursor when in fullscreen.
connect(this, &QWindow::visibilityChanged, this, &gs_frame::HandleCursor);
#ifdef _WIN32
m_tb_button = new QWinTaskbarButton();
m_tb_progress = m_tb_button->progress();
m_tb_progress->setRange(0, m_gauge_max);
m_tb_progress->setVisible(false);
#elif HAVE_QTDBUS
UpdateProgress(0);
m_progress_value = 0;
#endif
}
gs_frame::~gs_frame()
{
#ifdef _WIN32
if (m_tb_progress)
{
m_tb_progress->hide();
}
if (m_tb_button)
{
m_tb_button->deleteLater();
}
#elif HAVE_QTDBUS
UpdateProgress(0, false);
#endif
}
void gs_frame::paintEvent(QPaintEvent *event)
@ -159,6 +185,15 @@ void gs_frame::show()
setVisibility(FullScreen);
}
});
#ifdef _WIN32
// if we do this before show, the QWinTaskbarProgress won't show
if (m_tb_button)
{
m_tb_button->setWindow(this);
m_tb_progress->show();
}
#endif
}
display_handle_t gs_frame::handle() const
@ -381,3 +416,66 @@ wm_event gs_frame::get_default_wm_event() const
{
return (m_user_interaction_active) ? wm_event::geometry_change_in_progress : wm_event::none;
}
void gs_frame::progress_reset()
{
#ifdef _WIN32
if (m_tb_progress)
{
m_tb_progress->reset();
}
#elif HAVE_QTDBUS
UpdateProgress(0);
#endif
}
void gs_frame::progress_increment(int delta)
{
if (delta == 0)
{
return;
}
#ifdef _WIN32
if (m_tb_progress)
{
m_tb_progress->setValue(m_tb_progress->value() + delta);
}
#elif HAVE_QTDBUS
m_progress_value += delta;
UpdateProgress(m_progress_value);
#endif
}
void gs_frame::progress_set_limit(int limit)
{
#ifdef _WIN32
if (m_tb_progress)
{
m_tb_progress->setMaximum(limit);
}
#elif HAVE_QTDBUS
m_gauge_max = limit;
#endif
}
#ifdef HAVE_QTDBUS
void gs_frame::UpdateProgress(int progress, bool disable)
{
QDBusMessage message = QDBusMessage::createSignal
(
QStringLiteral("/"),
QStringLiteral("com.canonical.Unity.LauncherEntry"),
QStringLiteral("Update")
);
QVariantMap properties;
if (disable)
properties.insert(QStringLiteral("progress-visible"), false);
else
properties.insert(QStringLiteral("progress-visible"), true);
//Progress takes a value from 0.0 to 0.1
properties.insert(QStringLiteral("progress"), (double)progress / (double)m_gauge_max);
message << QStringLiteral("application://rpcs3.desktop") << properties;
QDBusConnection::sessionBus().send(message);
}
#endif

View File

@ -6,10 +6,31 @@
#include <QWidget>
#include <QWindow>
#ifdef _WIN32
#include <QWinTaskbarProgress>
#include <QWinTaskbarButton>
#include <QWinTHumbnailToolbar>
#include <QWinTHumbnailToolbutton>
#elif HAVE_QTDBUS
#include <QtDBus/QDBusMessage>
#include <QtDBus/QDBusConnection>
#endif
class gs_frame : public QWindow, public GSFrameBase
{
Q_OBJECT
private:
// taskbar progress
int m_gauge_max = 100;
#ifdef _WIN32
QWinTaskbarButton* m_tb_button = nullptr;
QWinTaskbarProgress* m_tb_progress = nullptr;
#elif HAVE_QTDBUS
int m_progress_value = 0;
void UpdateProgress(int progress, bool disable = false);
#endif
u64 m_frames = 0;
QString m_windowTitle;
bool m_show_fps;
@ -22,12 +43,19 @@ class gs_frame : public QWindow, public GSFrameBase
public:
gs_frame(const QString& title, const QRect& geometry, QIcon appIcon, bool disableMouse);
~gs_frame();
draw_context_t make_context() override;
void set_current(draw_context_t context) override;
void delete_context(draw_context_t context) override;
wm_event get_default_wm_event() const override;
// taskbar progress
void progress_reset();
void progress_increment(int delta);
void progress_set_limit(int limit);
protected:
virtual void paintEvent(QPaintEvent *event);
virtual void showEvent(QShowEvent *event) override;
@ -51,6 +79,7 @@ protected:
bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
bool event(QEvent* ev) override;
private Q_SLOTS:
void HandleCursor(QWindow::Visibility visibility);
};