From 7246965e00e1ffb5b91517aa6d58e17a664d6454 Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Wed, 17 Feb 2021 15:47:54 +0300 Subject: [PATCH] Adopt better method for setting custom pos using the pos dropdown Make it actually work properly --- include/courtroom.h | 2 +- src/courtroom.cpp | 46 +++++++++++++++------------------------------ 2 files changed, 16 insertions(+), 32 deletions(-) diff --git a/include/courtroom.h b/include/courtroom.h index d1395e1..98d4df9 100644 --- a/include/courtroom.h +++ b/include/courtroom.h @@ -581,7 +581,6 @@ private: QString current_background = "default"; QString current_side = ""; - int temp_side_index = -1; QBrush free_brush; QBrush lfp_brush; @@ -835,6 +834,7 @@ private slots: void on_emote_dropdown_changed(int p_index); void on_pos_dropdown_changed(int p_index); + void on_pos_dropdown_changed(QString p_text); void on_pos_remove_clicked(); void on_iniswap_dropdown_changed(int p_index); diff --git a/src/courtroom.cpp b/src/courtroom.cpp index c98d663..ed70288 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -308,6 +308,8 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() connect(ui_pos_dropdown, SIGNAL(currentIndexChanged(int)), this, SLOT(on_pos_dropdown_changed(int))); + connect(ui_pos_dropdown, SIGNAL(editTextChanged(QString)), this, + SLOT(on_pos_dropdown_changed(QString))); connect(ui_pos_remove, SIGNAL(clicked()), this, SLOT(on_pos_remove_clicked())); connect(ui_iniswap_dropdown, SIGNAL(currentIndexChanged(int)), this, @@ -728,6 +730,7 @@ void Courtroom::set_widgets() set_size_and_pos(ui_pos_dropdown, "pos_dropdown"); ui_pos_dropdown->setEditable(true); + ui_pos_dropdown->setInsertPolicy(QComboBox::NoInsert); ui_pos_dropdown->setToolTip( tr("Set your character's supplementary background.")); @@ -1322,15 +1325,8 @@ void Courtroom::set_side(QString p_side, bool block_signals) } } // We will only get there if we failed the last step - if (block_signals) - ui_pos_dropdown->blockSignals(true); - if (temp_side_index > -1) - ui_pos_dropdown->removeItem(temp_side_index); - ui_pos_dropdown->addItem(f_side); - temp_side_index = ui_pos_dropdown->count()-1; - ui_pos_dropdown->setCurrentIndex(temp_side_index); - if (block_signals) - ui_pos_dropdown->blockSignals(false); + ui_pos_dropdown->setEditText(f_side); + ui_pos_remove->show(); } void Courtroom::set_pos_dropdown(QStringList pos_dropdowns) @@ -1338,13 +1334,11 @@ void Courtroom::set_pos_dropdown(QStringList pos_dropdowns) // Block the signals to prevent setCurrentIndex from triggering a pos change ui_pos_dropdown->blockSignals(true); pos_dropdown_list = pos_dropdowns; - temp_side_index = -1; ui_pos_dropdown->clear(); ui_pos_dropdown->addItems(pos_dropdown_list); - // Custom pos if (current_side != "" && !pos_dropdown_list.contains(current_side)) { - ui_pos_dropdown->addItem(current_side); - temp_side_index = ui_pos_dropdown->count() - 1; + ui_pos_dropdown->setEditText(current_side); + ui_pos_remove->show(); } // Unblock the signals so the element can be used for setting pos again ui_pos_dropdown->blockSignals(false); @@ -4281,37 +4275,27 @@ void Courtroom::on_pos_dropdown_changed(int p_index) { if (p_index < 0) return; + on_pos_dropdown_changed(ui_pos_dropdown->itemText(p_index)); +} +void Courtroom::on_pos_dropdown_changed(QString p_text) +{ toggle_judge_buttons(false); - QString f_pos = ui_pos_dropdown->itemText(p_index); - - if (f_pos == "") - return; - - if (f_pos == "jud") + if (p_text == "jud") toggle_judge_buttons(true); - + ui_pos_remove->show(); - current_side = f_pos; + current_side = p_text; // YEAH SENDING LIKE 20 PACKETS IF THE USER SCROLLS THROUGH, GREAT IDEA // how about this instead - set_side(f_pos); - if (temp_side_index > -1 && p_index == temp_side_index) { - ui_pos_dropdown->removeItem(temp_side_index); - temp_side_index = -1; - } + set_side(p_text); } void Courtroom::on_pos_remove_clicked() { - if (temp_side_index > -1) { - ui_pos_dropdown->removeItem(temp_side_index); - temp_side_index = -1; - } - QString default_side = ao_app->get_char_side(current_char); for (int i = 0; i < ui_pos_dropdown->count(); ++i) {