Skip to content

Commit

Permalink
Qt: Improve binding widget tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Dec 8, 2024
1 parent 2999f15 commit b6eb41e
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/duckstation-qt/inputbindingwidgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "core/host.h"

#include "common/bitutils.h"
#include "common/string_util.h"

#include <QtCore/QTimer>
#include <QtGui/QKeyEvent>
Expand Down Expand Up @@ -61,26 +62,22 @@ void InputBindingWidget::initialize(SettingsInterface* sif, InputBindingInfo::Ty

void InputBindingWidget::updateText()
{
static constexpr const char* help_text =
QT_TR_NOOP("Left-click to change binding.\nShift-click to set multiple bindings.");
static constexpr const char* help_clear_text = QT_TR_NOOP("Right-click to remove binding.");

if (m_bindings.empty())
{
setText(QString());
setToolTip(QStringLiteral("%1\n\n%2").arg(tr("No binding set.")).arg(tr(help_text)));
}
else if (m_bindings.size() > 1)
{
setText(tr("%n bindings", "", static_cast<int>(m_bindings.size())));

// keep the full thing for the tooltip
std::stringstream ss;
bool first = true;
for (const std::string& binding : m_bindings)
{
if (first)
first = false;
else
ss << "\n";
ss << binding;
}
setToolTip(QString::fromStdString(ss.str()));
const QString qss = QString::fromStdString(StringUtil::JoinString(m_bindings.begin(), m_bindings.end(), "\n"));
setToolTip(QStringLiteral("%1\n\n%2\n%3").arg(qss).arg(tr(help_text)).arg(help_clear_text));
}
else
{
Expand All @@ -93,6 +90,7 @@ void InputBindingWidget::updateText()
if (binding_text.length() > 35)
binding_text = binding_text.left(35).append(QStringLiteral("..."));
setText(binding_text);
setToolTip(QStringLiteral("%1\n\n%2\n%3").arg(binding_text).arg(tr(help_text)).arg(tr(help_clear_text)));
}
}

Expand Down

0 comments on commit b6eb41e

Please sign in to comment.