2017-06-13 15:16:41 +00:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2017-06-13 15:16:41 +00:00
|
|
|
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/Config/Mapping/IOWindow.h"
|
2017-06-13 15:16:41 +00:00
|
|
|
|
2019-03-02 20:47:26 +00:00
|
|
|
#include <optional>
|
2017-06-13 15:16:41 +00:00
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
#include <QComboBox>
|
|
|
|
#include <QDialogButtonBox>
|
2019-01-06 23:15:00 +00:00
|
|
|
#include <QHeaderView>
|
|
|
|
#include <QItemDelegate>
|
2017-06-13 15:16:41 +00:00
|
|
|
#include <QLabel>
|
2019-03-02 20:47:26 +00:00
|
|
|
#include <QLineEdit>
|
2019-01-06 23:15:00 +00:00
|
|
|
#include <QPainter>
|
2017-06-13 15:16:41 +00:00
|
|
|
#include <QPlainTextEdit>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QSlider>
|
|
|
|
#include <QSpinBox>
|
2019-01-06 23:15:00 +00:00
|
|
|
#include <QTableWidget>
|
2017-06-13 15:16:41 +00:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
#include "Core/Core.h"
|
2018-05-28 01:48:04 +00:00
|
|
|
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/Config/Mapping/MappingCommon.h"
|
2019-01-06 23:15:00 +00:00
|
|
|
#include "DolphinQt/Config/Mapping/MappingIndicator.h"
|
|
|
|
#include "DolphinQt/Config/Mapping/MappingWidget.h"
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/Config/Mapping/MappingWindow.h"
|
|
|
|
#include "DolphinQt/QtUtils/BlockUserInputFilter.h"
|
2019-01-06 23:15:00 +00:00
|
|
|
#include "DolphinQt/QtUtils/ModalMessageBox.h"
|
2021-05-20 22:33:38 +00:00
|
|
|
#include "DolphinQt/Settings.h"
|
2018-05-28 01:48:04 +00:00
|
|
|
|
2017-06-13 15:16:41 +00:00
|
|
|
#include "InputCommon/ControlReference/ControlReference.h"
|
2019-03-02 16:10:26 +00:00
|
|
|
#include "InputCommon/ControlReference/ExpressionParser.h"
|
2017-06-13 15:16:41 +00:00
|
|
|
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
|
|
|
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
|
|
|
|
|
|
|
constexpr int SLIDER_TICK_COUNT = 100;
|
|
|
|
|
2019-03-02 16:10:26 +00:00
|
|
|
namespace
|
|
|
|
{
|
2019-03-02 20:47:26 +00:00
|
|
|
// TODO: Make sure these functions return colors that will be visible in the current theme.
|
2019-03-02 16:10:26 +00:00
|
|
|
QTextCharFormat GetSpecialCharFormat()
|
|
|
|
{
|
|
|
|
QTextCharFormat format;
|
|
|
|
format.setFontWeight(QFont::Weight::Bold);
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
|
|
|
QTextCharFormat GetLiteralCharFormat()
|
|
|
|
{
|
|
|
|
QTextCharFormat format;
|
|
|
|
format.setForeground(QBrush{Qt::darkMagenta});
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
|
|
|
QTextCharFormat GetInvalidCharFormat()
|
|
|
|
{
|
|
|
|
QTextCharFormat format;
|
|
|
|
format.setUnderlineStyle(QTextCharFormat::WaveUnderline);
|
|
|
|
format.setUnderlineColor(Qt::darkRed);
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
|
|
|
QTextCharFormat GetControlCharFormat()
|
|
|
|
{
|
|
|
|
QTextCharFormat format;
|
|
|
|
format.setForeground(QBrush{Qt::darkGreen});
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
|
|
|
QTextCharFormat GetVariableCharFormat()
|
|
|
|
{
|
|
|
|
QTextCharFormat format;
|
2019-10-12 16:41:02 +00:00
|
|
|
format.setForeground(QBrush{Qt::darkYellow});
|
2019-03-02 16:10:26 +00:00
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
2019-04-04 22:35:49 +00:00
|
|
|
QTextCharFormat GetBarewordCharFormat()
|
2019-03-02 16:10:26 +00:00
|
|
|
{
|
|
|
|
QTextCharFormat format;
|
2019-10-12 16:41:02 +00:00
|
|
|
format.setForeground(QBrush{Qt::darkBlue});
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
|
|
|
QTextCharFormat GetCommentCharFormat()
|
|
|
|
{
|
|
|
|
QTextCharFormat format;
|
|
|
|
format.setForeground(QBrush{Qt::darkGray});
|
2019-03-02 16:10:26 +00:00
|
|
|
return format;
|
|
|
|
}
|
2019-03-02 20:47:26 +00:00
|
|
|
} // namespace
|
2019-03-02 16:10:26 +00:00
|
|
|
|
2020-11-08 00:10:26 +00:00
|
|
|
ControlExpressionSyntaxHighlighter::ControlExpressionSyntaxHighlighter(QTextDocument* parent)
|
|
|
|
: QSyntaxHighlighter(parent)
|
2019-03-02 16:10:26 +00:00
|
|
|
{
|
2019-03-02 20:47:26 +00:00
|
|
|
}
|
2019-03-02 16:10:26 +00:00
|
|
|
|
2021-02-04 04:11:38 +00:00
|
|
|
void QComboBoxWithMouseWheelDisabled::wheelEvent(QWheelEvent* event)
|
|
|
|
{
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
|
2019-10-12 16:41:02 +00:00
|
|
|
void ControlExpressionSyntaxHighlighter::highlightBlock(const QString&)
|
2019-03-02 20:47:26 +00:00
|
|
|
{
|
|
|
|
// TODO: This is going to result in improper highlighting with non-ascii characters:
|
2019-10-12 16:41:02 +00:00
|
|
|
ciface::ExpressionParser::Lexer lexer(document()->toPlainText().toStdString());
|
2019-03-02 16:10:26 +00:00
|
|
|
|
2019-03-02 20:47:26 +00:00
|
|
|
std::vector<ciface::ExpressionParser::Token> tokens;
|
|
|
|
const auto tokenize_status = lexer.Tokenize(tokens);
|
2019-03-02 16:10:26 +00:00
|
|
|
|
2019-03-02 20:47:26 +00:00
|
|
|
using ciface::ExpressionParser::TokenType;
|
2019-03-02 16:10:26 +00:00
|
|
|
|
2019-10-12 16:41:02 +00:00
|
|
|
const auto set_block_format = [this](int start, int count, const QTextCharFormat& format) {
|
|
|
|
if (start + count <= currentBlock().position() ||
|
|
|
|
start >= currentBlock().position() + currentBlock().length())
|
|
|
|
{
|
|
|
|
// This range is not within the current block.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int block_start = start - currentBlock().position();
|
|
|
|
|
|
|
|
if (block_start < 0)
|
|
|
|
{
|
|
|
|
count += block_start;
|
|
|
|
block_start = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
setFormat(block_start, count, format);
|
|
|
|
};
|
|
|
|
|
2019-03-02 20:47:26 +00:00
|
|
|
for (auto& token : tokens)
|
|
|
|
{
|
|
|
|
std::optional<QTextCharFormat> char_format;
|
|
|
|
|
|
|
|
switch (token.type)
|
2019-03-02 16:10:26 +00:00
|
|
|
{
|
2019-03-02 20:47:26 +00:00
|
|
|
case TokenType::TOK_INVALID:
|
|
|
|
char_format = GetInvalidCharFormat();
|
|
|
|
break;
|
|
|
|
case TokenType::TOK_LPAREN:
|
|
|
|
case TokenType::TOK_RPAREN:
|
|
|
|
case TokenType::TOK_COMMA:
|
|
|
|
char_format = GetSpecialCharFormat();
|
|
|
|
break;
|
|
|
|
case TokenType::TOK_LITERAL:
|
|
|
|
char_format = GetLiteralCharFormat();
|
|
|
|
break;
|
|
|
|
case TokenType::TOK_CONTROL:
|
|
|
|
char_format = GetControlCharFormat();
|
|
|
|
break;
|
2019-04-04 22:35:49 +00:00
|
|
|
case TokenType::TOK_BAREWORD:
|
|
|
|
char_format = GetBarewordCharFormat();
|
2019-03-02 20:47:26 +00:00
|
|
|
break;
|
|
|
|
case TokenType::TOK_VARIABLE:
|
|
|
|
char_format = GetVariableCharFormat();
|
|
|
|
break;
|
2019-10-12 16:41:02 +00:00
|
|
|
case TokenType::TOK_COMMENT:
|
|
|
|
char_format = GetCommentCharFormat();
|
|
|
|
break;
|
2019-03-02 20:47:26 +00:00
|
|
|
default:
|
|
|
|
if (token.IsBinaryOperator())
|
2019-10-12 16:41:02 +00:00
|
|
|
char_format = GetSpecialCharFormat();
|
2019-03-02 20:47:26 +00:00
|
|
|
break;
|
2019-03-02 16:10:26 +00:00
|
|
|
}
|
2019-03-02 20:47:26 +00:00
|
|
|
|
|
|
|
if (char_format.has_value())
|
2019-10-12 16:41:02 +00:00
|
|
|
set_block_format(int(token.string_position), int(token.string_length), *char_format);
|
2019-03-02 16:10:26 +00:00
|
|
|
}
|
|
|
|
|
2019-10-12 16:41:02 +00:00
|
|
|
// This doesn't need to be run for every "block", but it works.
|
2020-11-08 00:10:26 +00:00
|
|
|
if (ciface::ExpressionParser::ParseStatus::Successful == tokenize_status)
|
2019-03-02 20:47:26 +00:00
|
|
|
{
|
2019-10-12 16:41:02 +00:00
|
|
|
ciface::ExpressionParser::RemoveInertTokens(&tokens);
|
2019-03-02 20:47:26 +00:00
|
|
|
const auto parse_status = ciface::ExpressionParser::ParseTokens(tokens);
|
|
|
|
|
|
|
|
if (ciface::ExpressionParser::ParseStatus::Successful != parse_status.status)
|
|
|
|
{
|
|
|
|
const auto token = *parse_status.token;
|
2019-10-12 16:41:02 +00:00
|
|
|
set_block_format(int(token.string_position), int(token.string_length),
|
|
|
|
GetInvalidCharFormat());
|
2019-03-02 20:47:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-02 16:10:26 +00:00
|
|
|
|
2019-01-06 23:15:00 +00:00
|
|
|
class InputStateDelegate : public QItemDelegate
|
|
|
|
{
|
|
|
|
public:
|
2020-11-22 02:33:36 +00:00
|
|
|
explicit InputStateDelegate(IOWindow* parent, int column,
|
|
|
|
std::function<ControlState(int row)> state_evaluator);
|
2019-01-06 23:15:00 +00:00
|
|
|
|
|
|
|
void paint(QPainter* painter, const QStyleOptionViewItem& option,
|
|
|
|
const QModelIndex& index) const override;
|
|
|
|
|
|
|
|
private:
|
2020-11-22 02:33:36 +00:00
|
|
|
std::function<ControlState(int row)> m_state_evaluator;
|
|
|
|
int m_column;
|
|
|
|
};
|
|
|
|
|
|
|
|
class InputStateLineEdit : public QLineEdit
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit InputStateLineEdit(std::function<ControlState()> state_evaluator);
|
|
|
|
void SetShouldPaintStateIndicator(bool value);
|
|
|
|
void paintEvent(QPaintEvent* event) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::function<ControlState()> m_state_evaluator;
|
2021-09-04 04:43:19 +00:00
|
|
|
bool m_should_paint_state_indicator = false;
|
2019-01-06 23:15:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
IOWindow::IOWindow(MappingWidget* parent, ControllerEmu::EmulatedController* controller,
|
2017-06-13 15:16:41 +00:00
|
|
|
ControlReference* ref, IOWindow::Type type)
|
2020-11-08 00:10:26 +00:00
|
|
|
: QDialog(parent), m_reference(ref), m_original_expression(ref->GetExpression()),
|
|
|
|
m_controller(controller), m_type(type)
|
2017-06-13 15:16:41 +00:00
|
|
|
{
|
|
|
|
CreateMainLayout();
|
2018-05-05 00:29:16 +00:00
|
|
|
|
2019-01-06 23:15:00 +00:00
|
|
|
connect(parent, &MappingWidget::Update, this, &IOWindow::Update);
|
2021-05-20 22:33:38 +00:00
|
|
|
connect(parent->GetParent(), &MappingWindow::ConfigChanged, this, &IOWindow::ConfigChanged);
|
|
|
|
connect(&Settings::Instance(), &Settings::ConfigChanged, this, &IOWindow::ConfigChanged);
|
2019-01-06 23:15:00 +00:00
|
|
|
|
2017-06-13 15:16:41 +00:00
|
|
|
setWindowTitle(type == IOWindow::Type::Input ? tr("Configure Input") : tr("Configure Output"));
|
2018-05-05 00:29:16 +00:00
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
2017-06-13 15:16:41 +00:00
|
|
|
|
2019-03-15 01:27:49 +00:00
|
|
|
ConfigChanged();
|
2019-01-27 16:35:29 +00:00
|
|
|
|
|
|
|
ConnectWidgets();
|
2017-06-13 15:16:41 +00:00
|
|
|
}
|
|
|
|
|
2021-05-20 22:33:38 +00:00
|
|
|
std::shared_ptr<ciface::Core::Device> IOWindow::GetSelectedDevice() const
|
2019-01-06 23:15:00 +00:00
|
|
|
{
|
|
|
|
return m_selected_device;
|
|
|
|
}
|
|
|
|
|
2017-06-13 15:16:41 +00:00
|
|
|
void IOWindow::CreateMainLayout()
|
|
|
|
{
|
|
|
|
m_main_layout = new QVBoxLayout();
|
|
|
|
|
|
|
|
m_devices_combo = new QComboBox();
|
2019-01-06 23:15:00 +00:00
|
|
|
m_option_list = new QTableWidget();
|
2017-06-13 15:16:41 +00:00
|
|
|
m_select_button = new QPushButton(tr("Select"));
|
2019-10-18 17:26:03 +00:00
|
|
|
m_detect_button = new QPushButton(tr("Detect"), this);
|
|
|
|
m_test_button = new QPushButton(tr("Test"), this);
|
2017-06-13 15:16:41 +00:00
|
|
|
m_button_box = new QDialogButtonBox();
|
|
|
|
m_clear_button = new QPushButton(tr("Clear"));
|
|
|
|
m_range_slider = new QSlider(Qt::Horizontal);
|
|
|
|
m_range_spinbox = new QSpinBox();
|
|
|
|
|
2020-11-22 02:33:36 +00:00
|
|
|
m_parse_text = new InputStateLineEdit([this] {
|
|
|
|
const auto lock = m_controller->GetStateLock();
|
|
|
|
return m_reference->GetState<ControlState>();
|
|
|
|
});
|
2019-03-02 20:47:26 +00:00
|
|
|
m_parse_text->setReadOnly(true);
|
|
|
|
|
2019-03-02 16:10:26 +00:00
|
|
|
m_expression_text = new QPlainTextEdit();
|
|
|
|
m_expression_text->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
|
2020-11-08 00:10:26 +00:00
|
|
|
new ControlExpressionSyntaxHighlighter(m_expression_text->document());
|
2019-03-02 16:10:26 +00:00
|
|
|
|
2021-05-20 22:33:38 +00:00
|
|
|
m_operators_combo = new QComboBoxWithMouseWheelDisabled(this);
|
2019-01-27 16:35:29 +00:00
|
|
|
m_operators_combo->addItem(tr("Operators"));
|
|
|
|
m_operators_combo->insertSeparator(1);
|
|
|
|
if (m_type == Type::Input)
|
|
|
|
{
|
|
|
|
m_operators_combo->addItem(tr("! Not"));
|
|
|
|
m_operators_combo->addItem(tr("* Multiply"));
|
|
|
|
m_operators_combo->addItem(tr("/ Divide"));
|
|
|
|
m_operators_combo->addItem(tr("% Modulo"));
|
|
|
|
m_operators_combo->addItem(tr("+ Add"));
|
|
|
|
m_operators_combo->addItem(tr("- Subtract"));
|
|
|
|
m_operators_combo->addItem(tr("> Greater-than"));
|
|
|
|
m_operators_combo->addItem(tr("< Less-than"));
|
|
|
|
m_operators_combo->addItem(tr("& And"));
|
2019-10-20 14:51:19 +00:00
|
|
|
m_operators_combo->addItem(tr("^ Xor"));
|
2019-01-27 16:35:29 +00:00
|
|
|
}
|
|
|
|
m_operators_combo->addItem(tr("| Or"));
|
2021-03-11 22:01:18 +00:00
|
|
|
m_operators_combo->addItem(tr("$ User Variable"));
|
2019-01-27 16:35:29 +00:00
|
|
|
if (m_type == Type::Input)
|
|
|
|
{
|
|
|
|
m_operators_combo->addItem(tr(", Comma"));
|
|
|
|
}
|
|
|
|
|
2021-02-04 04:11:38 +00:00
|
|
|
m_functions_combo = new QComboBoxWithMouseWheelDisabled(this);
|
2019-01-27 16:35:29 +00:00
|
|
|
m_functions_combo->addItem(tr("Functions"));
|
|
|
|
m_functions_combo->insertSeparator(1);
|
2019-04-04 22:35:49 +00:00
|
|
|
m_functions_combo->addItem(QStringLiteral("if"));
|
|
|
|
m_functions_combo->addItem(QStringLiteral("timer"));
|
|
|
|
m_functions_combo->addItem(QStringLiteral("toggle"));
|
|
|
|
m_functions_combo->addItem(QStringLiteral("deadzone"));
|
|
|
|
m_functions_combo->addItem(QStringLiteral("smooth"));
|
|
|
|
m_functions_combo->addItem(QStringLiteral("hold"));
|
|
|
|
m_functions_combo->addItem(QStringLiteral("tap"));
|
|
|
|
m_functions_combo->addItem(QStringLiteral("relative"));
|
|
|
|
m_functions_combo->addItem(QStringLiteral("pulse"));
|
2020-08-02 19:42:18 +00:00
|
|
|
m_functions_combo->addItem(QStringLiteral("sin"));
|
|
|
|
m_functions_combo->addItem(QStringLiteral("cos"));
|
|
|
|
m_functions_combo->addItem(QStringLiteral("tan"));
|
|
|
|
m_functions_combo->addItem(QStringLiteral("asin"));
|
|
|
|
m_functions_combo->addItem(QStringLiteral("acos"));
|
|
|
|
m_functions_combo->addItem(QStringLiteral("atan"));
|
|
|
|
m_functions_combo->addItem(QStringLiteral("atan2"));
|
|
|
|
m_functions_combo->addItem(QStringLiteral("sqrt"));
|
|
|
|
m_functions_combo->addItem(QStringLiteral("pow"));
|
|
|
|
m_functions_combo->addItem(QStringLiteral("min"));
|
|
|
|
m_functions_combo->addItem(QStringLiteral("max"));
|
|
|
|
m_functions_combo->addItem(QStringLiteral("clamp"));
|
2019-01-27 16:35:29 +00:00
|
|
|
|
2021-03-11 22:01:18 +00:00
|
|
|
m_variables_combo = new QComboBoxWithMouseWheelDisabled(this);
|
|
|
|
m_variables_combo->addItem(tr("User Variables"));
|
|
|
|
m_variables_combo->setToolTip(
|
|
|
|
tr("User defined variables usable in the control expression.\nYou can use them to save or "
|
|
|
|
"retrieve values between\ninputs and outputs of the same parent controller."));
|
|
|
|
m_variables_combo->insertSeparator(m_variables_combo->count());
|
|
|
|
m_variables_combo->addItem(tr("Reset Values"));
|
|
|
|
m_variables_combo->insertSeparator(m_variables_combo->count());
|
|
|
|
|
2017-06-13 15:16:41 +00:00
|
|
|
// Devices
|
|
|
|
m_main_layout->addWidget(m_devices_combo);
|
|
|
|
|
|
|
|
// Range
|
|
|
|
auto* range_hbox = new QHBoxLayout();
|
|
|
|
range_hbox->addWidget(new QLabel(tr("Range")));
|
|
|
|
range_hbox->addWidget(m_range_slider);
|
|
|
|
range_hbox->addWidget(m_range_spinbox);
|
|
|
|
m_range_slider->setMinimum(-500);
|
|
|
|
m_range_slider->setMaximum(500);
|
|
|
|
m_range_spinbox->setMinimum(-500);
|
|
|
|
m_range_spinbox->setMaximum(500);
|
2018-05-08 23:54:47 +00:00
|
|
|
m_main_layout->addLayout(range_hbox);
|
2017-06-13 15:16:41 +00:00
|
|
|
|
2019-01-06 23:15:00 +00:00
|
|
|
// Options (Buttons, Outputs) and action buttons
|
|
|
|
|
2020-02-07 02:34:27 +00:00
|
|
|
m_option_list->setTabKeyNavigation(false);
|
|
|
|
|
2019-01-06 23:15:00 +00:00
|
|
|
if (m_type == Type::Input)
|
|
|
|
{
|
|
|
|
m_option_list->setColumnCount(2);
|
|
|
|
m_option_list->setColumnWidth(1, 64);
|
|
|
|
m_option_list->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Fixed);
|
|
|
|
|
2020-11-22 02:33:36 +00:00
|
|
|
m_option_list->setItemDelegate(new InputStateDelegate(this, 1, [&](int row) {
|
2021-05-20 22:33:38 +00:00
|
|
|
std::lock_guard lock(m_selected_device_mutex);
|
2020-11-22 02:33:36 +00:00
|
|
|
// Clamp off negative values but allow greater than one in the text display.
|
|
|
|
return std::max(GetSelectedDevice()->Inputs()[row]->GetState(), 0.0);
|
|
|
|
}));
|
2019-01-06 23:15:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_option_list->setColumnCount(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_option_list->horizontalHeader()->hide();
|
|
|
|
m_option_list->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
|
|
|
|
m_option_list->verticalHeader()->hide();
|
|
|
|
m_option_list->verticalHeader()->setDefaultSectionSize(
|
|
|
|
m_option_list->verticalHeader()->minimumSectionSize());
|
|
|
|
m_option_list->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
|
m_option_list->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
m_option_list->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
|
2017-06-13 15:16:41 +00:00
|
|
|
auto* hbox = new QHBoxLayout();
|
|
|
|
auto* button_vbox = new QVBoxLayout();
|
|
|
|
hbox->addWidget(m_option_list, 8);
|
|
|
|
hbox->addLayout(button_vbox, 1);
|
|
|
|
|
|
|
|
button_vbox->addWidget(m_select_button);
|
2019-11-08 23:45:43 +00:00
|
|
|
|
2017-06-13 15:16:41 +00:00
|
|
|
if (m_type == Type::Input)
|
|
|
|
{
|
2019-11-08 23:45:43 +00:00
|
|
|
m_test_button->hide();
|
|
|
|
button_vbox->addWidget(m_detect_button);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_detect_button->hide();
|
|
|
|
button_vbox->addWidget(m_test_button);
|
2017-06-13 15:16:41 +00:00
|
|
|
}
|
|
|
|
|
2021-03-11 22:01:18 +00:00
|
|
|
button_vbox->addWidget(m_variables_combo);
|
|
|
|
|
2019-11-08 23:45:43 +00:00
|
|
|
button_vbox->addWidget(m_operators_combo);
|
|
|
|
|
|
|
|
if (m_type == Type::Input)
|
|
|
|
button_vbox->addWidget(m_functions_combo);
|
|
|
|
else
|
|
|
|
m_functions_combo->hide();
|
|
|
|
|
2017-06-13 15:16:41 +00:00
|
|
|
m_main_layout->addLayout(hbox, 2);
|
|
|
|
m_main_layout->addWidget(m_expression_text, 1);
|
2019-03-02 20:47:26 +00:00
|
|
|
m_main_layout->addWidget(m_parse_text);
|
2017-06-13 15:16:41 +00:00
|
|
|
|
|
|
|
// Button Box
|
|
|
|
m_main_layout->addWidget(m_button_box);
|
|
|
|
m_button_box->addButton(m_clear_button, QDialogButtonBox::ActionRole);
|
|
|
|
m_button_box->addButton(QDialogButtonBox::Ok);
|
|
|
|
|
|
|
|
setLayout(m_main_layout);
|
|
|
|
}
|
|
|
|
|
2019-03-15 01:27:49 +00:00
|
|
|
void IOWindow::ConfigChanged()
|
2017-06-13 15:16:41 +00:00
|
|
|
{
|
2019-04-27 15:51:57 +00:00
|
|
|
const QSignalBlocker blocker(this);
|
2021-05-20 22:33:38 +00:00
|
|
|
const auto lock = ControllerEmu::EmulatedController::GetStateLock();
|
2020-11-22 02:33:36 +00:00
|
|
|
|
|
|
|
// ensure m_parse_text is in the right state
|
|
|
|
UpdateExpression(m_reference->GetExpression(), UpdateMode::Force);
|
2019-03-15 01:27:49 +00:00
|
|
|
|
2017-06-08 02:02:16 +00:00
|
|
|
m_expression_text->setPlainText(QString::fromStdString(m_reference->GetExpression()));
|
2018-09-03 16:03:26 +00:00
|
|
|
m_expression_text->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor);
|
2017-06-13 15:16:41 +00:00
|
|
|
m_range_spinbox->setValue(m_reference->range * SLIDER_TICK_COUNT);
|
|
|
|
m_range_slider->setValue(m_reference->range * SLIDER_TICK_COUNT);
|
|
|
|
|
2021-05-20 22:33:38 +00:00
|
|
|
if (m_devq.ToString().empty())
|
|
|
|
m_devq = m_controller->GetDefaultDevice();
|
2017-06-13 15:16:41 +00:00
|
|
|
|
|
|
|
UpdateDeviceList();
|
|
|
|
}
|
|
|
|
|
2019-01-06 23:15:00 +00:00
|
|
|
void IOWindow::Update()
|
|
|
|
{
|
|
|
|
m_option_list->viewport()->update();
|
2020-11-22 02:33:36 +00:00
|
|
|
m_parse_text->update();
|
2019-01-06 23:15:00 +00:00
|
|
|
}
|
|
|
|
|
2017-06-13 15:16:41 +00:00
|
|
|
void IOWindow::ConnectWidgets()
|
|
|
|
{
|
2019-01-27 16:35:29 +00:00
|
|
|
connect(m_select_button, &QPushButton::clicked, [this] { AppendSelectedOption(); });
|
2021-05-20 22:33:38 +00:00
|
|
|
connect(&Settings::Instance(), &Settings::ReleaseDevices, this, &IOWindow::ReleaseDevices);
|
|
|
|
connect(&Settings::Instance(), &Settings::DevicesChanged, this, &IOWindow::UpdateDeviceList);
|
2017-06-13 15:16:41 +00:00
|
|
|
|
2019-02-28 00:10:18 +00:00
|
|
|
connect(m_detect_button, &QPushButton::clicked, this, &IOWindow::OnDetectButtonPressed);
|
|
|
|
connect(m_test_button, &QPushButton::clicked, this, &IOWindow::OnTestButtonPressed);
|
2017-06-13 15:16:41 +00:00
|
|
|
|
|
|
|
connect(m_button_box, &QDialogButtonBox::clicked, this, &IOWindow::OnDialogButtonPressed);
|
|
|
|
connect(m_devices_combo, &QComboBox::currentTextChanged, this, &IOWindow::OnDeviceChanged);
|
2019-07-30 13:35:46 +00:00
|
|
|
connect(m_range_spinbox, qOverload<int>(&QSpinBox::valueChanged), this,
|
2017-06-13 15:16:41 +00:00
|
|
|
&IOWindow::OnRangeChanged);
|
2019-01-27 16:35:29 +00:00
|
|
|
|
2020-11-22 03:00:28 +00:00
|
|
|
connect(m_expression_text, &QPlainTextEdit::textChanged,
|
|
|
|
[this] { UpdateExpression(m_expression_text->toPlainText().toStdString()); });
|
2019-01-27 16:35:29 +00:00
|
|
|
|
2021-03-11 22:01:18 +00:00
|
|
|
connect(m_variables_combo, qOverload<int>(&QComboBox::activated), [this](int index) {
|
|
|
|
if (index == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Reset button. 1 and 3 are separators.
|
|
|
|
if (index == 2)
|
|
|
|
{
|
|
|
|
const auto lock = ControllerEmu::EmulatedController::GetStateLock();
|
|
|
|
m_controller->ResetExpressionVariables();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_expression_text->insertPlainText(QLatin1Char('$') + m_variables_combo->currentText());
|
|
|
|
}
|
|
|
|
|
|
|
|
m_variables_combo->setCurrentIndex(0);
|
|
|
|
});
|
|
|
|
|
2019-07-30 13:35:46 +00:00
|
|
|
connect(m_operators_combo, qOverload<int>(&QComboBox::activated), [this](int index) {
|
2021-03-11 22:01:18 +00:00
|
|
|
if (index == 0)
|
2019-01-27 16:35:29 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
m_expression_text->insertPlainText(m_operators_combo->currentText().left(1));
|
|
|
|
|
|
|
|
m_operators_combo->setCurrentIndex(0);
|
|
|
|
});
|
|
|
|
|
2019-07-30 13:35:46 +00:00
|
|
|
connect(m_functions_combo, qOverload<int>(&QComboBox::activated), [this](int index) {
|
2021-03-11 22:01:18 +00:00
|
|
|
if (index == 0)
|
2019-01-27 16:35:29 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
m_expression_text->insertPlainText(m_functions_combo->currentText() + QStringLiteral("()"));
|
|
|
|
|
|
|
|
m_functions_combo->setCurrentIndex(0);
|
|
|
|
});
|
2020-11-08 00:10:26 +00:00
|
|
|
|
|
|
|
// revert the expression when the window closes without using the OK button
|
|
|
|
connect(this, &IOWindow::finished, [this] { UpdateExpression(m_original_expression); });
|
2017-06-13 15:16:41 +00:00
|
|
|
}
|
|
|
|
|
2019-01-27 16:35:29 +00:00
|
|
|
void IOWindow::AppendSelectedOption()
|
2017-06-13 15:16:41 +00:00
|
|
|
{
|
2021-05-20 22:33:38 +00:00
|
|
|
if (m_option_list->currentRow() < 0)
|
2017-06-13 15:16:41 +00:00
|
|
|
return;
|
|
|
|
|
2019-01-27 16:35:29 +00:00
|
|
|
m_expression_text->insertPlainText(MappingCommon::GetExpressionForControl(
|
2021-05-20 22:33:38 +00:00
|
|
|
m_option_list->item(m_option_list->currentRow(), 0)->text(), m_devq,
|
|
|
|
m_controller->GetDefaultDevice()));
|
2017-06-13 15:16:41 +00:00
|
|
|
}
|
|
|
|
|
2021-05-20 22:33:38 +00:00
|
|
|
void IOWindow::OnDeviceChanged()
|
2017-06-13 15:16:41 +00:00
|
|
|
{
|
2021-05-20 22:33:38 +00:00
|
|
|
const std::string device_name =
|
|
|
|
m_devices_combo->count() > 0 ? m_devices_combo->currentData().toString().toStdString() : "";
|
|
|
|
m_devq.FromString(device_name);
|
2017-06-13 15:16:41 +00:00
|
|
|
UpdateOptionList();
|
|
|
|
}
|
|
|
|
|
|
|
|
void IOWindow::OnDialogButtonPressed(QAbstractButton* button)
|
|
|
|
{
|
|
|
|
if (button == m_clear_button)
|
|
|
|
{
|
|
|
|
m_expression_text->clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-20 22:33:38 +00:00
|
|
|
const auto lock = ControllerEmu::EmulatedController::GetStateLock();
|
2020-11-08 00:10:26 +00:00
|
|
|
|
|
|
|
UpdateExpression(m_expression_text->toPlainText().toStdString());
|
2019-01-27 16:35:29 +00:00
|
|
|
|
|
|
|
if (ciface::ExpressionParser::ParseStatus::SyntaxError == m_reference->GetParseStatus())
|
|
|
|
{
|
2019-01-06 23:15:00 +00:00
|
|
|
ModalMessageBox::warning(this, tr("Error"), tr("The expression contains a syntax error."));
|
2019-01-27 16:35:29 +00:00
|
|
|
}
|
2021-09-27 18:28:08 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// must be the OK button
|
2021-09-27 18:29:34 +00:00
|
|
|
m_original_expression = m_reference->GetExpression();
|
2021-09-27 18:28:08 +00:00
|
|
|
accept();
|
|
|
|
}
|
2017-06-13 15:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IOWindow::OnDetectButtonPressed()
|
|
|
|
{
|
2019-02-28 00:10:18 +00:00
|
|
|
const auto expression =
|
|
|
|
MappingCommon::DetectExpression(m_detect_button, g_controller_interface, {m_devq.ToString()},
|
|
|
|
m_devq, MappingCommon::Quote::Off);
|
2017-06-13 15:16:41 +00:00
|
|
|
|
2019-02-28 00:10:18 +00:00
|
|
|
if (expression.isEmpty())
|
|
|
|
return;
|
2017-06-13 15:16:41 +00:00
|
|
|
|
2019-02-28 00:10:18 +00:00
|
|
|
const auto list = m_option_list->findItems(expression, Qt::MatchFixedString);
|
2017-06-13 15:16:41 +00:00
|
|
|
|
2021-05-20 22:33:38 +00:00
|
|
|
// Try to select the first. If this fails, the last selected item would still appear as such
|
2019-02-28 00:10:18 +00:00
|
|
|
if (!list.empty())
|
|
|
|
m_option_list->setCurrentItem(list[0]);
|
|
|
|
}
|
2017-06-27 06:23:22 +00:00
|
|
|
|
2019-02-28 00:10:18 +00:00
|
|
|
void IOWindow::OnTestButtonPressed()
|
|
|
|
{
|
|
|
|
MappingCommon::TestOutput(m_test_button, static_cast<OutputReference*>(m_reference));
|
2017-06-13 15:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IOWindow::OnRangeChanged(int value)
|
|
|
|
{
|
|
|
|
m_reference->range = static_cast<double>(value) / SLIDER_TICK_COUNT;
|
|
|
|
m_range_spinbox->setValue(m_reference->range * SLIDER_TICK_COUNT);
|
|
|
|
m_range_slider->setValue(m_reference->range * SLIDER_TICK_COUNT);
|
|
|
|
}
|
|
|
|
|
2021-05-20 22:33:38 +00:00
|
|
|
void IOWindow::ReleaseDevices()
|
|
|
|
{
|
|
|
|
std::lock_guard lock(m_selected_device_mutex);
|
|
|
|
m_selected_device = nullptr;
|
|
|
|
}
|
|
|
|
|
2017-06-13 15:16:41 +00:00
|
|
|
void IOWindow::UpdateOptionList()
|
|
|
|
{
|
2021-05-20 22:33:38 +00:00
|
|
|
std::lock_guard lock(m_selected_device_mutex);
|
2019-01-06 23:15:00 +00:00
|
|
|
m_selected_device = g_controller_interface.FindDevice(m_devq);
|
|
|
|
m_option_list->setRowCount(0);
|
2017-06-13 15:16:41 +00:00
|
|
|
|
2019-01-06 23:15:00 +00:00
|
|
|
if (m_selected_device == nullptr)
|
2018-05-10 19:12:19 +00:00
|
|
|
return;
|
|
|
|
|
2017-06-13 15:16:41 +00:00
|
|
|
if (m_reference->IsInput())
|
|
|
|
{
|
2019-01-06 23:15:00 +00:00
|
|
|
int row = 0;
|
|
|
|
for (const auto* input : m_selected_device->Inputs())
|
2017-06-13 15:16:41 +00:00
|
|
|
{
|
2019-01-06 23:15:00 +00:00
|
|
|
m_option_list->insertRow(row);
|
|
|
|
m_option_list->setItem(row, 0,
|
|
|
|
new QTableWidgetItem(QString::fromStdString(input->GetName())));
|
|
|
|
++row;
|
2017-06-13 15:16:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-06 23:15:00 +00:00
|
|
|
int row = 0;
|
|
|
|
for (const auto* output : m_selected_device->Outputs())
|
2017-06-13 15:16:41 +00:00
|
|
|
{
|
2019-01-06 23:15:00 +00:00
|
|
|
m_option_list->insertRow(row);
|
|
|
|
m_option_list->setItem(row, 0,
|
|
|
|
new QTableWidgetItem(QString::fromStdString(output->GetName())));
|
|
|
|
++row;
|
2017-06-13 15:16:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IOWindow::UpdateDeviceList()
|
|
|
|
{
|
2021-05-20 22:33:38 +00:00
|
|
|
const QSignalBlocker blocker(m_devices_combo);
|
|
|
|
|
|
|
|
const auto previous_device_name = m_devices_combo->currentData().toString().toStdString();
|
|
|
|
|
2017-06-13 15:16:41 +00:00
|
|
|
m_devices_combo->clear();
|
|
|
|
|
2021-05-20 22:33:38 +00:00
|
|
|
// Default to the default device or to the first device if there isn't a default.
|
|
|
|
// Try to the keep the previous selected device, mark it as disconnected if it's gone, as it could
|
|
|
|
// reconnect soon after if this is a devices refresh and it would be annoying to lose the value.
|
|
|
|
const auto default_device_name = m_controller->GetDefaultDevice().ToString();
|
|
|
|
int default_device_index = -1;
|
|
|
|
int previous_device_index = -1;
|
2019-03-15 01:27:49 +00:00
|
|
|
for (const auto& name : g_controller_interface.GetAllDeviceStrings())
|
2021-05-20 22:33:38 +00:00
|
|
|
{
|
|
|
|
QString qname = QString();
|
|
|
|
if (name == default_device_name)
|
|
|
|
{
|
|
|
|
default_device_index = m_devices_combo->count();
|
|
|
|
// Specify "default" even if we only have one device
|
|
|
|
qname.append(QLatin1Char{'['} + tr("default") + QStringLiteral("] "));
|
|
|
|
}
|
|
|
|
if (name == previous_device_name)
|
|
|
|
{
|
|
|
|
previous_device_index = m_devices_combo->count();
|
|
|
|
}
|
|
|
|
qname.append(QString::fromStdString(name));
|
|
|
|
m_devices_combo->addItem(qname, QString::fromStdString(name));
|
|
|
|
}
|
2017-06-13 15:16:41 +00:00
|
|
|
|
2021-05-20 22:33:38 +00:00
|
|
|
if (previous_device_index >= 0)
|
|
|
|
{
|
|
|
|
m_devices_combo->setCurrentIndex(previous_device_index);
|
|
|
|
}
|
|
|
|
else if (!previous_device_name.empty())
|
|
|
|
{
|
|
|
|
const QString qname = QString::fromStdString(previous_device_name);
|
|
|
|
QString adjusted_qname;
|
|
|
|
if (previous_device_name == default_device_name)
|
|
|
|
{
|
|
|
|
adjusted_qname.append(QLatin1Char{'['} + tr("default") + QStringLiteral("] "));
|
|
|
|
}
|
|
|
|
adjusted_qname.append(QLatin1Char{'['} + tr("disconnected") + QStringLiteral("] "))
|
|
|
|
.append(qname);
|
|
|
|
m_devices_combo->addItem(adjusted_qname, qname);
|
|
|
|
m_devices_combo->setCurrentIndex(m_devices_combo->count() - 1);
|
|
|
|
}
|
|
|
|
else if (default_device_index >= 0)
|
|
|
|
{
|
|
|
|
m_devices_combo->setCurrentIndex(default_device_index);
|
|
|
|
}
|
|
|
|
else if (m_devices_combo->count() > 0)
|
|
|
|
{
|
|
|
|
m_devices_combo->setCurrentIndex(0);
|
|
|
|
}
|
|
|
|
// The device object might have changed so we need to always refresh it
|
|
|
|
OnDeviceChanged();
|
2017-06-13 15:16:41 +00:00
|
|
|
}
|
2019-01-06 23:15:00 +00:00
|
|
|
|
2020-11-22 02:33:36 +00:00
|
|
|
void IOWindow::UpdateExpression(std::string new_expression, UpdateMode mode)
|
2020-11-08 00:10:26 +00:00
|
|
|
{
|
|
|
|
const auto lock = m_controller->GetStateLock();
|
2020-11-22 02:33:36 +00:00
|
|
|
if (mode != UpdateMode::Force && new_expression == m_reference->GetExpression())
|
2020-11-08 00:10:26 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
const auto error = m_reference->SetExpression(std::move(new_expression));
|
|
|
|
const auto status = m_reference->GetParseStatus();
|
|
|
|
m_controller->UpdateSingleControlReference(g_controller_interface, m_reference);
|
|
|
|
|
2021-03-11 22:01:18 +00:00
|
|
|
// This is the only place where we need to update the user variables. Keep the first 4 items.
|
|
|
|
while (m_variables_combo->count() > 4)
|
|
|
|
{
|
|
|
|
m_variables_combo->removeItem(m_variables_combo->count() - 1);
|
|
|
|
}
|
|
|
|
for (const auto& expression : m_controller->GetExpressionVariables())
|
|
|
|
{
|
|
|
|
m_variables_combo->addItem(QString::fromStdString(expression.first));
|
|
|
|
}
|
|
|
|
|
2020-11-08 00:10:26 +00:00
|
|
|
if (error)
|
2020-11-22 02:33:36 +00:00
|
|
|
{
|
|
|
|
m_parse_text->SetShouldPaintStateIndicator(false);
|
2020-11-08 00:10:26 +00:00
|
|
|
m_parse_text->setText(QString::fromStdString(*error));
|
2020-11-22 02:33:36 +00:00
|
|
|
}
|
2020-11-08 00:10:26 +00:00
|
|
|
else if (status == ciface::ExpressionParser::ParseStatus::EmptyExpression)
|
2020-11-22 02:33:36 +00:00
|
|
|
{
|
|
|
|
m_parse_text->SetShouldPaintStateIndicator(false);
|
2020-11-08 00:10:26 +00:00
|
|
|
m_parse_text->setText(QString());
|
2020-11-22 02:33:36 +00:00
|
|
|
}
|
2020-11-08 00:10:26 +00:00
|
|
|
else if (status != ciface::ExpressionParser::ParseStatus::Successful)
|
2020-11-22 02:33:36 +00:00
|
|
|
{
|
|
|
|
m_parse_text->SetShouldPaintStateIndicator(false);
|
2020-11-08 00:10:26 +00:00
|
|
|
m_parse_text->setText(tr("Invalid Expression."));
|
2020-11-22 02:33:36 +00:00
|
|
|
}
|
2020-11-08 00:10:26 +00:00
|
|
|
else
|
2020-11-22 02:33:36 +00:00
|
|
|
{
|
|
|
|
m_parse_text->SetShouldPaintStateIndicator(true);
|
|
|
|
m_parse_text->setText(QString());
|
|
|
|
}
|
2020-11-08 00:10:26 +00:00
|
|
|
}
|
|
|
|
|
2020-11-22 02:33:36 +00:00
|
|
|
InputStateDelegate::InputStateDelegate(IOWindow* parent, int column,
|
|
|
|
std::function<ControlState(int row)> state_evaluator)
|
|
|
|
: QItemDelegate(parent), m_state_evaluator(std::move(state_evaluator)), m_column(column)
|
2019-01-06 23:15:00 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-11-22 02:33:36 +00:00
|
|
|
InputStateLineEdit::InputStateLineEdit(std::function<ControlState()> state_evaluator)
|
|
|
|
: m_state_evaluator(std::move(state_evaluator))
|
2019-01-06 23:15:00 +00:00
|
|
|
{
|
2020-11-22 02:33:36 +00:00
|
|
|
}
|
2019-01-06 23:15:00 +00:00
|
|
|
|
2020-11-22 02:33:36 +00:00
|
|
|
static void PaintStateIndicator(QPainter& painter, const QRect& region, ControlState state)
|
|
|
|
{
|
|
|
|
const QString state_string = QString::number(state, 'g', 4);
|
2019-01-06 23:15:00 +00:00
|
|
|
|
2020-11-22 02:33:36 +00:00
|
|
|
QRect meter_region = region;
|
|
|
|
meter_region.setWidth(region.width() * std::clamp(state, 0.0, 1.0));
|
2019-01-06 23:15:00 +00:00
|
|
|
|
|
|
|
// Create a temporary indicator object to retreive color constants.
|
2020-02-23 19:34:05 +00:00
|
|
|
MappingIndicator indicator;
|
2019-01-06 23:15:00 +00:00
|
|
|
|
|
|
|
// Normal text.
|
2020-11-22 02:33:36 +00:00
|
|
|
painter.setPen(indicator.GetTextColor());
|
|
|
|
painter.drawText(region, Qt::AlignCenter, state_string);
|
2019-01-06 23:15:00 +00:00
|
|
|
|
|
|
|
// Input state meter.
|
2020-11-22 02:33:36 +00:00
|
|
|
painter.fillRect(meter_region, indicator.GetAdjustedInputColor());
|
2019-01-06 23:15:00 +00:00
|
|
|
|
|
|
|
// Text on top of meter.
|
2020-11-22 02:33:36 +00:00
|
|
|
painter.setPen(indicator.GetAltTextColor());
|
|
|
|
painter.setClipping(true);
|
|
|
|
painter.setClipRect(meter_region);
|
|
|
|
painter.drawText(region, Qt::AlignCenter, state_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputStateDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option,
|
|
|
|
const QModelIndex& index) const
|
|
|
|
{
|
|
|
|
QItemDelegate::paint(painter, option, index);
|
|
|
|
|
|
|
|
if (index.column() != m_column)
|
|
|
|
return;
|
2019-01-06 23:15:00 +00:00
|
|
|
|
2020-11-22 02:33:36 +00:00
|
|
|
painter->save();
|
|
|
|
PaintStateIndicator(*painter, option.rect, m_state_evaluator(index.row()));
|
2019-01-06 23:15:00 +00:00
|
|
|
painter->restore();
|
|
|
|
}
|
2020-11-22 02:33:36 +00:00
|
|
|
|
|
|
|
void InputStateLineEdit::SetShouldPaintStateIndicator(bool value)
|
|
|
|
{
|
|
|
|
m_should_paint_state_indicator = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputStateLineEdit::paintEvent(QPaintEvent* event)
|
|
|
|
{
|
|
|
|
QLineEdit::paintEvent(event);
|
|
|
|
|
|
|
|
if (!m_should_paint_state_indicator)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QPainter painter(this);
|
|
|
|
PaintStateIndicator(painter, this->rect(), m_state_evaluator());
|
|
|
|
}
|