| 815 | } |
| 816 | |
| 817 | void NetHackQtMenuWindow::ToggleSelect(int row, bool already_toggled) |
| 818 | { |
| 819 | if (itemlist[row].Selectable()) { |
| 820 | QCheckBox *cb = dynamic_cast<QCheckBox *> (table->cellWidget(row, 1)); |
| 821 | if (cb == NULL) |
| 822 | return; |
| 823 | |
| 824 | if (how == PICK_ONE) { |
| 825 | // explicitly picking a preselected item in a pick-one menu |
| 826 | // chooses that item rather than toggling preselection off; |
| 827 | // by clearing whole menu, the code below will select item #row |
| 828 | ChooseNone(); |
| 829 | already_toggled = false; |
| 830 | // FIXME? this won't handle a pending count properly; |
| 831 | // are there any pick-one menus with preselected choice |
| 832 | // where a count is useful? |
| 833 | } else { |
| 834 | itemlist[row].preselected = false; // flag is now out-of-date |
| 835 | } |
| 836 | |
| 837 | QTableWidgetItem *countfield = table->item(row, 0); |
| 838 | if (!counting) { |
| 839 | if (!already_toggled) |
| 840 | cb->setChecked((cb->checkState() == Qt::Unchecked)); // toggle |
| 841 | itemlist[row].selected = (cb->checkState() != Qt::Unchecked); |
| 842 | if (countfield != NULL) |
| 843 | countfield->setText(""); |
| 844 | } else { |
| 845 | long amt = 1L; |
| 846 | if (countfield != NULL) { |
| 847 | countfield->setText(countstr); // store in item(row,0) |
| 848 | amt = count(row); // fetch item(row,0) as a number |
| 849 | QString Amt = ""; |
| 850 | if (amt > 0L) |
| 851 | Amt = nh_qsprintf("%*ld", countdigits, amt); |
| 852 | countfield->setText(Amt); // store right-justified value |
| 853 | } |
| 854 | ClearCount(); // blank out 'countstr' and reset 'counting' |
| 855 | |
| 856 | // TODO: use a custom icon for check mark, like tty's '#' vs '+' |
| 857 | // [maybe not necessary since unlike tty menus, count is visible] |
| 858 | |
| 859 | // uncheck if count is explicitly 0, otherwise check |
| 860 | cb->setChecked((amt > 0L)); |
| 861 | itemlist[row].selected = (cb->checkState() != Qt::Unchecked); |
| 862 | |
| 863 | // if this count is larger than the biggest we've seen |
| 864 | // so far, it might need more digits to render; if so, |
| 865 | // all pending counts should be reformatted with new width |
| 866 | if (amt > biggestcount) |
| 867 | UpdateCountColumn(amt); |
| 868 | } |
| 869 | |
| 870 | if (how == PICK_ONE && isSelected(row)) |
| 871 | accept(); |
| 872 | else |
| 873 | table->repaint(); |
| 874 | } |
nothing calls this directly
no test coverage detected