Clean QT Input UI
This commit is contained in:
@@ -71,7 +71,7 @@ SettingsInput::SettingsInput(QWidget *parent)
|
|||||||
|
|
||||||
// Make a working copy of acc_keys so we can check for dupes later without getting
|
// Make a working copy of acc_keys so we can check for dupes later without getting
|
||||||
// confused
|
// confused
|
||||||
for(int x=0;x<NUM_ACCELS;x++) {
|
for(int x = 0; x < NUM_ACCELS; x++) {
|
||||||
strcpy(acc_keys_t[x].name, acc_keys[x].name);
|
strcpy(acc_keys_t[x].name, acc_keys[x].name);
|
||||||
strcpy(acc_keys_t[x].desc, acc_keys[x].desc);
|
strcpy(acc_keys_t[x].desc, acc_keys[x].desc);
|
||||||
strcpy(acc_keys_t[x].seq, acc_keys[x].seq);
|
strcpy(acc_keys_t[x].seq, acc_keys[x].seq);
|
||||||
@@ -82,7 +82,6 @@ SettingsInput::SettingsInput(QWidget *parent)
|
|||||||
onCurrentMachineChanged(machine);
|
onCurrentMachineChanged(machine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SettingsInput::~SettingsInput()
|
SettingsInput::~SettingsInput()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
@@ -95,7 +94,7 @@ SettingsInput::save()
|
|||||||
joystick_type = ui->comboBoxJoystick->currentData().toInt();
|
joystick_type = ui->comboBoxJoystick->currentData().toInt();
|
||||||
|
|
||||||
// Copy accelerators from working set to global set
|
// Copy accelerators from working set to global set
|
||||||
for(int x=0;x<NUM_ACCELS;x++) {
|
for(int x = 0; x < NUM_ACCELS; x++) {
|
||||||
strcpy(acc_keys[x].name, acc_keys_t[x].name);
|
strcpy(acc_keys[x].name, acc_keys_t[x].name);
|
||||||
strcpy(acc_keys[x].desc, acc_keys_t[x].desc);
|
strcpy(acc_keys[x].desc, acc_keys_t[x].desc);
|
||||||
strcpy(acc_keys[x].seq, acc_keys_t[x].seq);
|
strcpy(acc_keys[x].seq, acc_keys_t[x].seq);
|
||||||
@@ -115,13 +114,11 @@ SettingsInput::onCurrentMachineChanged(int machineId)
|
|||||||
int selectedRow = 0;
|
int selectedRow = 0;
|
||||||
for (int i = 0; i < mouse_get_ndev(); ++i) {
|
for (int i = 0; i < mouse_get_ndev(); ++i) {
|
||||||
const auto *dev = mouse_get_device(i);
|
const auto *dev = mouse_get_device(i);
|
||||||
if ((i == MOUSE_TYPE_INTERNAL) && (machine_has_flags(machineId, MACHINE_MOUSE) == 0)) {
|
if ((i == MOUSE_TYPE_INTERNAL) && (machine_has_flags(machineId, MACHINE_MOUSE) == 0))
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
if (device_is_valid(dev, machineId) == 0) {
|
if (device_is_valid(dev, machineId) == 0)
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
QString name = DeviceConfig::DeviceName(dev, mouse_get_internal_name(i), 0);
|
QString name = DeviceConfig::DeviceName(dev, mouse_get_internal_name(i), 0);
|
||||||
int row = mouseModel->rowCount();
|
int row = mouseModel->rowCount();
|
||||||
@@ -131,10 +128,9 @@ SettingsInput::onCurrentMachineChanged(int machineId)
|
|||||||
mouseModel->setData(idx, name, Qt::DisplayRole);
|
mouseModel->setData(idx, name, Qt::DisplayRole);
|
||||||
mouseModel->setData(idx, i, Qt::UserRole);
|
mouseModel->setData(idx, i, Qt::UserRole);
|
||||||
|
|
||||||
if (i == mouse_type) {
|
if (i == mouse_type)
|
||||||
selectedRow = row - removeRows;
|
selectedRow = row - removeRows;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
mouseModel->removeRows(0, removeRows);
|
mouseModel->removeRows(0, removeRows);
|
||||||
ui->comboBoxMouse->setCurrentIndex(selectedRow);
|
ui->comboBoxMouse->setCurrentIndex(selectedRow);
|
||||||
|
|
||||||
@@ -145,9 +141,8 @@ SettingsInput::onCurrentMachineChanged(int machineId)
|
|||||||
selectedRow = 0;
|
selectedRow = 0;
|
||||||
while (joyName) {
|
while (joyName) {
|
||||||
int row = Models::AddEntry(joystickModel, tr(joyName).toUtf8().data(), i);
|
int row = Models::AddEntry(joystickModel, tr(joyName).toUtf8().data(), i);
|
||||||
if (i == joystick_type) {
|
if (i == joystick_type)
|
||||||
selectedRow = row - removeRows;
|
selectedRow = row - removeRows;
|
||||||
}
|
|
||||||
|
|
||||||
++i;
|
++i;
|
||||||
joyName = joystick_get_name(i);
|
joyName = joystick_get_name(i);
|
||||||
@@ -159,8 +154,7 @@ SettingsInput::onCurrentMachineChanged(int machineId)
|
|||||||
void
|
void
|
||||||
SettingsInput::refreshInputList()
|
SettingsInput::refreshInputList()
|
||||||
{
|
{
|
||||||
|
for (int x = 0; x < NUM_ACCELS; x++) {
|
||||||
for (int x=0;x<NUM_ACCELS;x++) {
|
|
||||||
ui->tableKeys->setItem(x, 0, new QTableWidgetItem(tr(acc_keys_t[x].desc)));
|
ui->tableKeys->setItem(x, 0, new QTableWidgetItem(tr(acc_keys_t[x].desc)));
|
||||||
ui->tableKeys->setItem(x, 1, new QTableWidgetItem(QKeySequence(acc_keys_t[x].seq, QKeySequence::PortableText).toString(QKeySequence::NativeText)));
|
ui->tableKeys->setItem(x, 1, new QTableWidgetItem(QKeySequence(acc_keys_t[x].seq, QKeySequence::PortableText).toString(QKeySequence::NativeText)));
|
||||||
ui->tableKeys->setItem(x, 2, new QTableWidgetItem(acc_keys_t[x].name));
|
ui->tableKeys->setItem(x, 2, new QTableWidgetItem(acc_keys_t[x].name));
|
||||||
@@ -172,13 +166,10 @@ SettingsInput::on_tableKeys_currentCellChanged(int currentRow, int currentColumn
|
|||||||
{
|
{
|
||||||
// Enable/disable bind/clear buttons if user clicked valid row
|
// Enable/disable bind/clear buttons if user clicked valid row
|
||||||
QTableWidgetItem *cell = ui->tableKeys->item(currentRow,1);
|
QTableWidgetItem *cell = ui->tableKeys->item(currentRow,1);
|
||||||
if (!cell)
|
if (!cell) {
|
||||||
{
|
|
||||||
ui->pushButtonBind->setEnabled(false);
|
ui->pushButtonBind->setEnabled(false);
|
||||||
ui->pushButtonClearBind->setEnabled(false);
|
ui->pushButtonClearBind->setEnabled(false);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
ui->pushButtonBind->setEnabled(true);
|
ui->pushButtonBind->setEnabled(true);
|
||||||
ui->pushButtonClearBind->setEnabled(true);
|
ui->pushButtonClearBind->setEnabled(true);
|
||||||
}
|
}
|
||||||
@@ -189,20 +180,20 @@ SettingsInput::on_tableKeys_cellDoubleClicked(int row, int col)
|
|||||||
{
|
{
|
||||||
// Edit bind
|
// Edit bind
|
||||||
QTableWidgetItem *cell = ui->tableKeys->item(row,1);
|
QTableWidgetItem *cell = ui->tableKeys->item(row,1);
|
||||||
if (!cell) return;
|
if (!cell)
|
||||||
|
return;
|
||||||
|
|
||||||
QKeySequence keyseq = KeyBinder::BindKey(this, cell->text());
|
QKeySequence keyseq = KeyBinder::BindKey(this, cell->text());
|
||||||
if (keyseq != false) {
|
if (keyseq != false) {
|
||||||
// If no change was made, don't change anything.
|
// If no change was made, don't change anything.
|
||||||
if (keyseq.toString(QKeySequence::NativeText) == cell->text()) return;
|
if (keyseq.toString(QKeySequence::NativeText) == cell->text())
|
||||||
|
return;
|
||||||
|
|
||||||
// Otherwise, check for conflicts.
|
// Otherwise, check for conflicts.
|
||||||
// Check against the *working* copy - NOT the one in use by the app,
|
// Check against the *working* copy - NOT the one in use by the app,
|
||||||
// so we don't test against shortcuts the user already changed.
|
// so we don't test against shortcuts the user already changed.
|
||||||
for(int x=0;x<NUM_ACCELS;x++)
|
for(int x = 0; x < NUM_ACCELS; x++) {
|
||||||
{
|
if(QString::fromStdString(acc_keys_t[x].seq) == keyseq.toString(QKeySequence::PortableText)) {
|
||||||
if(QString::fromStdString(acc_keys_t[x].seq) == keyseq.toString(QKeySequence::PortableText))
|
|
||||||
{
|
|
||||||
// That key is already in use
|
// That key is already in use
|
||||||
main_window->showMessage(MBX_ANSI & MBX_INFO, "Bind conflict", "This key combo is already in use", false);
|
main_window->showMessage(MBX_ANSI & MBX_INFO, "Bind conflict", "This key combo is already in use", false);
|
||||||
return;
|
return;
|
||||||
@@ -213,7 +204,8 @@ SettingsInput::on_tableKeys_cellDoubleClicked(int row, int col)
|
|||||||
|
|
||||||
// Find the correct accelerator key entry
|
// Find the correct accelerator key entry
|
||||||
int accKeyID = FindAccelerator(ui->tableKeys->item(row,2)->text().toUtf8().constData());
|
int accKeyID = FindAccelerator(ui->tableKeys->item(row,2)->text().toUtf8().constData());
|
||||||
if (accKeyID < 0) return; // this should never happen
|
if (accKeyID < 0)
|
||||||
|
return; // this should never happen
|
||||||
|
|
||||||
// Make the change
|
// Make the change
|
||||||
cell->setText(keyseq.toString(QKeySequence::NativeText));
|
cell->setText(keyseq.toString(QKeySequence::NativeText));
|
||||||
@@ -228,7 +220,8 @@ SettingsInput::on_pushButtonBind_clicked()
|
|||||||
{
|
{
|
||||||
// Edit bind
|
// Edit bind
|
||||||
QTableWidgetItem *cell = ui->tableKeys->currentItem();
|
QTableWidgetItem *cell = ui->tableKeys->currentItem();
|
||||||
if (!cell) return;
|
if (!cell)
|
||||||
|
return;
|
||||||
|
|
||||||
on_tableKeys_cellDoubleClicked(cell->row(), cell->column());
|
on_tableKeys_cellDoubleClicked(cell->row(), cell->column());
|
||||||
}
|
}
|
||||||
@@ -238,12 +231,14 @@ SettingsInput::on_pushButtonClearBind_clicked()
|
|||||||
{
|
{
|
||||||
// Wipe bind
|
// Wipe bind
|
||||||
QTableWidgetItem *cell = ui->tableKeys->item(ui->tableKeys->currentRow(), 1);
|
QTableWidgetItem *cell = ui->tableKeys->item(ui->tableKeys->currentRow(), 1);
|
||||||
if (!cell) return;
|
if (!cell)
|
||||||
|
return;
|
||||||
|
|
||||||
cell->setText("");
|
cell->setText("");
|
||||||
// Find the correct accelerator key entry
|
// Find the correct accelerator key entry
|
||||||
int accKeyID = FindAccelerator(ui->tableKeys->item(cell->row(),2)->text().toUtf8().constData());
|
int accKeyID = FindAccelerator(ui->tableKeys->item(cell->row(),2)->text().toUtf8().constData());
|
||||||
if (accKeyID < 0) return; // this should never happen
|
if (accKeyID < 0)
|
||||||
|
return; // this should never happen
|
||||||
|
|
||||||
// Make the change
|
// Make the change
|
||||||
cell->setText("");
|
cell->setText("");
|
||||||
@@ -263,9 +258,9 @@ SettingsInput::on_comboBoxJoystick_currentIndexChanged(int index)
|
|||||||
int joystickId = ui->comboBoxJoystick->currentData().toInt();
|
int joystickId = ui->comboBoxJoystick->currentData().toInt();
|
||||||
for (int i = 0; i < MAX_JOYSTICKS; ++i) {
|
for (int i = 0; i < MAX_JOYSTICKS; ++i) {
|
||||||
auto *btn = findChild<QPushButton *>(QString("pushButtonJoystick%1").arg(i + 1));
|
auto *btn = findChild<QPushButton *>(QString("pushButtonJoystick%1").arg(i + 1));
|
||||||
if (btn == nullptr) {
|
if (btn == nullptr)
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
btn->setEnabled(joystick_get_max_joysticks(joystickId) > i);
|
btn->setEnabled(joystick_get_max_joysticks(joystickId) > i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -283,9 +278,8 @@ get_axis(JoystickConfiguration &jc, int axis, int joystick_nr)
|
|||||||
int axis_sel = jc.selectedAxis(axis);
|
int axis_sel = jc.selectedAxis(axis);
|
||||||
int nr_axes = plat_joystick_state[joystick_state[0][joystick_nr].plat_joystick_nr - 1].nr_axes;
|
int nr_axes = plat_joystick_state[joystick_state[0][joystick_nr].plat_joystick_nr - 1].nr_axes;
|
||||||
|
|
||||||
if (axis_sel < nr_axes) {
|
if (axis_sel < nr_axes)
|
||||||
return axis_sel;
|
return axis_sel;
|
||||||
}
|
|
||||||
|
|
||||||
axis_sel -= nr_axes;
|
axis_sel -= nr_axes;
|
||||||
if (axis_sel & 1)
|
if (axis_sel & 1)
|
||||||
|
|||||||
@@ -26,17 +26,20 @@ public slots:
|
|||||||
void onCurrentMachineChanged(int machineId);
|
void onCurrentMachineChanged(int machineId);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_pushButtonConfigureMouse_clicked();
|
|
||||||
void on_comboBoxJoystick_currentIndexChanged(int index);
|
|
||||||
void on_comboBoxMouse_currentIndexChanged(int index);
|
void on_comboBoxMouse_currentIndexChanged(int index);
|
||||||
|
void on_pushButtonConfigureMouse_clicked();
|
||||||
|
|
||||||
|
void on_comboBoxJoystick_currentIndexChanged(int index);
|
||||||
void on_pushButtonJoystick1_clicked();
|
void on_pushButtonJoystick1_clicked();
|
||||||
void on_pushButtonJoystick2_clicked();
|
void on_pushButtonJoystick2_clicked();
|
||||||
void on_pushButtonJoystick3_clicked();
|
void on_pushButtonJoystick3_clicked();
|
||||||
void on_pushButtonJoystick4_clicked();
|
void on_pushButtonJoystick4_clicked();
|
||||||
|
|
||||||
void on_tableKeys_cellDoubleClicked(int row, int col);
|
void on_tableKeys_cellDoubleClicked(int row, int col);
|
||||||
void on_tableKeys_currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn);
|
void on_tableKeys_currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn);
|
||||||
void on_pushButtonBind_clicked();
|
|
||||||
void on_pushButtonClearBind_clicked();
|
void on_pushButtonClearBind_clicked();
|
||||||
|
void on_pushButtonBind_clicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::SettingsInput *ui;
|
Ui::SettingsInput *ui;
|
||||||
|
|||||||
@@ -23,6 +23,13 @@
|
|||||||
<property name="rightMargin">
|
<property name="rightMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="labelMouse">
|
||||||
|
<property name="text">
|
||||||
|
<string>Mouse:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item row="0" column="1" colspan="2">
|
<item row="0" column="1" colspan="2">
|
||||||
<widget class="QComboBox" name="comboBoxMouse">
|
<widget class="QComboBox" name="comboBoxMouse">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
@@ -36,75 +43,6 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="3">
|
|
||||||
<widget class="QPushButton" name="pushButtonJoystick4">
|
|
||||||
<property name="text">
|
|
||||||
<string>Joystick 4...</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="2">
|
|
||||||
<widget class="QPushButton" name="pushButtonJoystick3">
|
|
||||||
<property name="text">
|
|
||||||
<string>Joystick 3...</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="5" column="3">
|
|
||||||
<widget class="QPushButton" name="pushButtonBind">
|
|
||||||
<property name="enabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Bind</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0">
|
|
||||||
<widget class="QPushButton" name="pushButtonJoystick1">
|
|
||||||
<property name="text">
|
|
||||||
<string>Joystick 1...</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1" colspan="2">
|
|
||||||
<widget class="QComboBox" name="comboBoxJoystick">
|
|
||||||
<property name="maxVisibleItems">
|
|
||||||
<number>30</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QLabel" name="label">
|
|
||||||
<property name="text">
|
|
||||||
<string>Mouse:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="5" column="2">
|
|
||||||
<widget class="QPushButton" name="pushButtonClearBind">
|
|
||||||
<property name="enabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Clear binding</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
|
||||||
<widget class="QLabel" name="label_2">
|
|
||||||
<property name="text">
|
|
||||||
<string>Joystick:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="1">
|
|
||||||
<widget class="QPushButton" name="pushButtonJoystick2">
|
|
||||||
<property name="text">
|
|
||||||
<string>Joystick 2...</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="3">
|
<item row="0" column="3">
|
||||||
<widget class="QPushButton" name="pushButtonConfigureMouse">
|
<widget class="QPushButton" name="pushButtonConfigureMouse">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
@@ -118,8 +56,50 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="labelJoystick">
|
||||||
|
<property name="text">
|
||||||
|
<string>Joystick:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1" colspan="2">
|
||||||
|
<widget class="QComboBox" name="comboBoxJoystick">
|
||||||
|
<property name="maxVisibleItems">
|
||||||
|
<number>30</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QPushButton" name="pushButtonJoystick1">
|
||||||
|
<property name="text">
|
||||||
|
<string>Joystick 1...</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QPushButton" name="pushButtonJoystick2">
|
||||||
|
<property name="text">
|
||||||
|
<string>Joystick 2...</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="2">
|
||||||
|
<widget class="QPushButton" name="pushButtonJoystick3">
|
||||||
|
<property name="text">
|
||||||
|
<string>Joystick 3...</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="3">
|
||||||
|
<widget class="QPushButton" name="pushButtonJoystick4">
|
||||||
|
<property name="text">
|
||||||
|
<string>Joystick 4...</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item row="3" column="0">
|
<item row="3" column="0">
|
||||||
<widget class="QLabel" name="label_3">
|
<widget class="QLabel" name="labelKeys">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Key Bindings:</string>
|
<string>Key Bindings:</string>
|
||||||
</property>
|
</property>
|
||||||
@@ -144,6 +124,26 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="5" column="2">
|
||||||
|
<widget class="QPushButton" name="pushButtonClearBind">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Clear binding</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="5" column="3">
|
||||||
|
<widget class="QPushButton" name="pushButtonBind">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Bind</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
|||||||
Reference in New Issue
Block a user