mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
Merge pull request #13753 from JoshuaVandaele/netplay-hoverblur
ClickBlurLabel: Create a label which is blurred until it is clicked
This commit is contained in:
66
Source/Core/DolphinQt/NetPlay/ClickBlurLabel.cpp
Normal file
66
Source/Core/DolphinQt/NetPlay/ClickBlurLabel.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
// Copyright 2025 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "DolphinQt/NetPlay/ClickBlurLabel.h"
|
||||
|
||||
#include <QChar>
|
||||
#include <QGraphicsBlurEffect>
|
||||
#include <QLabel>
|
||||
#include <QMouseEvent>
|
||||
#include <QStackedWidget>
|
||||
#include <QString>
|
||||
#include <QWidget>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/Random.h"
|
||||
|
||||
ClickBlurLabel::ClickBlurLabel(QWidget* parent)
|
||||
: QStackedWidget(parent), m_normal_label(new QLabel(this)), m_blurred_label(new QLabel(this))
|
||||
{
|
||||
setCursor(Qt::PointingHandCursor);
|
||||
|
||||
// We use a QStackedWidget with a pre-blurred label instead of applying QGraphicsBlurEffect on
|
||||
// click, because creating the blur effect on demand can cause a visible delay on lower-end
|
||||
// hardware.
|
||||
auto* blur = new QGraphicsBlurEffect(m_blurred_label);
|
||||
blur->setBlurRadius(7);
|
||||
m_blurred_label->setGraphicsEffect(blur);
|
||||
|
||||
// We don't want to take up more space than the labels take
|
||||
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
|
||||
addWidget(m_blurred_label);
|
||||
addWidget(m_normal_label);
|
||||
}
|
||||
|
||||
void ClickBlurLabel::setText(const QString& text)
|
||||
{
|
||||
if (this->text() == text)
|
||||
return;
|
||||
|
||||
m_normal_label->setText(text);
|
||||
m_blurred_label->setText(GenerateBlurredText(text));
|
||||
}
|
||||
|
||||
void ClickBlurLabel::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
int current = currentIndex();
|
||||
setCurrentIndex(current == 0 ? 1 : 0);
|
||||
QWidget::mousePressEvent(event);
|
||||
}
|
||||
|
||||
QString ClickBlurLabel::GenerateBlurredText(const QString& text)
|
||||
{
|
||||
QString blurred_text;
|
||||
blurred_text.reserve(text.size());
|
||||
for (const QChar& c : text)
|
||||
{
|
||||
if (c.isLetter())
|
||||
blurred_text += QChar((c.isUpper() ? 'A' : 'a') + (Common::Random::GenerateValue<u8>() % 26));
|
||||
else if (c.isDigit())
|
||||
blurred_text += QChar('0' + (Common::Random::GenerateValue<u8>() % 10));
|
||||
else
|
||||
blurred_text += c;
|
||||
}
|
||||
return blurred_text;
|
||||
}
|
29
Source/Core/DolphinQt/NetPlay/ClickBlurLabel.h
Normal file
29
Source/Core/DolphinQt/NetPlay/ClickBlurLabel.h
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright 2025 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QLabel>
|
||||
#include <QStackedWidget>
|
||||
#include <QWidget>
|
||||
|
||||
class ClickBlurLabel final : public QStackedWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ClickBlurLabel(QWidget* parent = nullptr);
|
||||
|
||||
void setText(const QString& text);
|
||||
|
||||
QString text() const { return m_normal_label->text(); }
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent* event) override;
|
||||
|
||||
private:
|
||||
// Generates text that "looks correct" but is actually gibberish.
|
||||
static QString GenerateBlurredText(const QString& text);
|
||||
|
||||
QLabel* m_normal_label;
|
||||
QLabel* m_blurred_label;
|
||||
};
|
@ -48,6 +48,7 @@
|
||||
#include "Core/System.h"
|
||||
|
||||
#include "DolphinQt/NetPlay/ChunkedProgressDialog.h"
|
||||
#include "DolphinQt/NetPlay/ClickBlurLabel.h"
|
||||
#include "DolphinQt/NetPlay/GameDigestDialog.h"
|
||||
#include "DolphinQt/NetPlay/GameListDialog.h"
|
||||
#include "DolphinQt/NetPlay/PadMappingDialog.h"
|
||||
@ -287,7 +288,7 @@ void NetPlayDialog::CreatePlayersLayout()
|
||||
{
|
||||
m_players_box = new QGroupBox(tr("Players"));
|
||||
m_room_box = new QComboBox;
|
||||
m_hostcode_label = new QLabel;
|
||||
m_hostcode_label = new ClickBlurLabel;
|
||||
m_hostcode_action_button = new QPushButton(tr("Copy"));
|
||||
m_players_list = new QTableWidget;
|
||||
m_kick_button = new QPushButton(tr("Kick Player"));
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "Common/Lazy.h"
|
||||
#include "Core/NetPlayClient.h"
|
||||
#include "DolphinQt/GameList/GameListModel.h"
|
||||
#include "DolphinQt/NetPlay/ClickBlurLabel.h"
|
||||
#include "VideoCommon/OnScreenDisplay.h"
|
||||
|
||||
class BootSessionData;
|
||||
@ -127,7 +128,7 @@ private:
|
||||
// Players
|
||||
QGroupBox* m_players_box;
|
||||
QComboBox* m_room_box;
|
||||
QLabel* m_hostcode_label;
|
||||
ClickBlurLabel* m_hostcode_label;
|
||||
QPushButton* m_hostcode_action_button;
|
||||
QTableWidget* m_players_list;
|
||||
QPushButton* m_kick_button;
|
||||
|
Reference in New Issue
Block a user