| 62 | } |
| 63 | |
| 64 | void InputBindingWidget::updateText() |
| 65 | { |
| 66 | const QString binding_tip(tr("\n\nLeft click to assign a new button\nShift + left click for additional bindings")); |
| 67 | const QString binding_clear_tip(tr("\nRight click to clear binding")); |
| 68 | |
| 69 | if (m_bindings_ui.empty()) |
| 70 | { |
| 71 | setText(QString()); |
| 72 | |
| 73 | setToolTip(tr("No bindings registered") + binding_tip); |
| 74 | } |
| 75 | else if (m_bindings_ui.size() > 1) |
| 76 | { |
| 77 | setText(tr("%n bindings", "", static_cast<int>(m_bindings_ui.size()))); |
| 78 | |
| 79 | // keep the full thing for the tooltip |
| 80 | std::stringstream ss; |
| 81 | bool first = true; |
| 82 | for (const std::string& binding : m_bindings_ui) |
| 83 | { |
| 84 | if (first) |
| 85 | first = false; |
| 86 | else |
| 87 | ss << "\n"; |
| 88 | ss << binding; |
| 89 | } |
| 90 | setToolTip(QString::fromStdString(ss.str()) + binding_tip + binding_clear_tip); |
| 91 | } |
| 92 | else |
| 93 | { |
| 94 | QString binding_text(QString::fromStdString(m_bindings_ui[0])); |
| 95 | setToolTip(binding_text + binding_tip + binding_clear_tip); |
| 96 | |
| 97 | // fix up accelerators, and if it's too long, ellipsise it |
| 98 | if (binding_text.contains('&')) |
| 99 | binding_text = binding_text.replace(QStringLiteral("&"), QStringLiteral("&&")); |
| 100 | if (binding_text.length() > 35) |
| 101 | binding_text = binding_text.left(35).append(QStringLiteral("...")); |
| 102 | setText(binding_text); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | bool InputBindingWidget::eventFilter(QObject* watched, QEvent* event) |
| 107 | { |