Skip to content

Commit 7246965

Browse files
Adopt better method for setting custom pos using the pos dropdown
Make it actually work properly
1 parent f881df2 commit 7246965

2 files changed

Lines changed: 16 additions & 32 deletions

File tree

include/courtroom.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,6 @@ class Courtroom : public QMainWindow {
581581

582582
QString current_background = "default";
583583
QString current_side = "";
584-
int temp_side_index = -1;
585584

586585
QBrush free_brush;
587586
QBrush lfp_brush;
@@ -835,6 +834,7 @@ private slots:
835834

836835
void on_emote_dropdown_changed(int p_index);
837836
void on_pos_dropdown_changed(int p_index);
837+
void on_pos_dropdown_changed(QString p_text);
838838
void on_pos_remove_clicked();
839839

840840
void on_iniswap_dropdown_changed(int p_index);

src/courtroom.cpp

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
308308

309309
connect(ui_pos_dropdown, SIGNAL(currentIndexChanged(int)), this,
310310
SLOT(on_pos_dropdown_changed(int)));
311+
connect(ui_pos_dropdown, SIGNAL(editTextChanged(QString)), this,
312+
SLOT(on_pos_dropdown_changed(QString)));
311313
connect(ui_pos_remove, SIGNAL(clicked()), this, SLOT(on_pos_remove_clicked()));
312314

313315
connect(ui_iniswap_dropdown, SIGNAL(currentIndexChanged(int)), this,
@@ -728,6 +730,7 @@ void Courtroom::set_widgets()
728730

729731
set_size_and_pos(ui_pos_dropdown, "pos_dropdown");
730732
ui_pos_dropdown->setEditable(true);
733+
ui_pos_dropdown->setInsertPolicy(QComboBox::NoInsert);
731734
ui_pos_dropdown->setToolTip(
732735
tr("Set your character's supplementary background."));
733736

@@ -1322,29 +1325,20 @@ void Courtroom::set_side(QString p_side, bool block_signals)
13221325
}
13231326
}
13241327
// We will only get there if we failed the last step
1325-
if (block_signals)
1326-
ui_pos_dropdown->blockSignals(true);
1327-
if (temp_side_index > -1)
1328-
ui_pos_dropdown->removeItem(temp_side_index);
1329-
ui_pos_dropdown->addItem(f_side);
1330-
temp_side_index = ui_pos_dropdown->count()-1;
1331-
ui_pos_dropdown->setCurrentIndex(temp_side_index);
1332-
if (block_signals)
1333-
ui_pos_dropdown->blockSignals(false);
1328+
ui_pos_dropdown->setEditText(f_side);
1329+
ui_pos_remove->show();
13341330
}
13351331

13361332
void Courtroom::set_pos_dropdown(QStringList pos_dropdowns)
13371333
{
13381334
// Block the signals to prevent setCurrentIndex from triggering a pos change
13391335
ui_pos_dropdown->blockSignals(true);
13401336
pos_dropdown_list = pos_dropdowns;
1341-
temp_side_index = -1;
13421337
ui_pos_dropdown->clear();
13431338
ui_pos_dropdown->addItems(pos_dropdown_list);
1344-
// Custom pos
13451339
if (current_side != "" && !pos_dropdown_list.contains(current_side)) {
1346-
ui_pos_dropdown->addItem(current_side);
1347-
temp_side_index = ui_pos_dropdown->count() - 1;
1340+
ui_pos_dropdown->setEditText(current_side);
1341+
ui_pos_remove->show();
13481342
}
13491343
// Unblock the signals so the element can be used for setting pos again
13501344
ui_pos_dropdown->blockSignals(false);
@@ -4281,37 +4275,27 @@ void Courtroom::on_pos_dropdown_changed(int p_index)
42814275
{
42824276
if (p_index < 0)
42834277
return;
4278+
on_pos_dropdown_changed(ui_pos_dropdown->itemText(p_index));
4279+
}
42844280

4281+
void Courtroom::on_pos_dropdown_changed(QString p_text)
4282+
{
42854283
toggle_judge_buttons(false);
42864284

4287-
QString f_pos = ui_pos_dropdown->itemText(p_index);
4288-
4289-
if (f_pos == "")
4290-
return;
4291-
4292-
if (f_pos == "jud")
4285+
if (p_text == "jud")
42934286
toggle_judge_buttons(true);
4294-
4287+
42954288
ui_pos_remove->show();
42964289

4297-
current_side = f_pos;
4290+
current_side = p_text;
42984291

42994292
// YEAH SENDING LIKE 20 PACKETS IF THE USER SCROLLS THROUGH, GREAT IDEA
43004293
// how about this instead
4301-
set_side(f_pos);
4302-
if (temp_side_index > -1 && p_index == temp_side_index) {
4303-
ui_pos_dropdown->removeItem(temp_side_index);
4304-
temp_side_index = -1;
4305-
}
4294+
set_side(p_text);
43064295
}
43074296

43084297
void Courtroom::on_pos_remove_clicked()
43094298
{
4310-
if (temp_side_index > -1) {
4311-
ui_pos_dropdown->removeItem(temp_side_index);
4312-
temp_side_index = -1;
4313-
}
4314-
43154299
QString default_side = ao_app->get_char_side(current_char);
43164300

43174301
for (int i = 0; i < ui_pos_dropdown->count(); ++i) {

0 commit comments

Comments
 (0)