aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCrystalwarrior <varsash@gmail.com>2021-02-17 15:47:54 +0300
committerCrystalwarrior <varsash@gmail.com>2021-02-17 15:47:54 +0300
commit7246965e00e1ffb5b91517aa6d58e17a664d6454 (patch)
tree79acfe0d03d55884d2de698e4ff192e00c1b108b
parentf881df241533dafc214f72983d9c6e1c59837891 (diff)
Adopt better method for setting custom pos using the pos dropdown
Make it actually work properly
-rw-r--r--include/courtroom.h2
-rw-r--r--src/courtroom.cpp46
2 files changed, 16 insertions, 32 deletions
diff --git a/include/courtroom.h b/include/courtroom.h
index d1395e1b..98d4df9f 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 c98d6635..ed70288c 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) {