| 4 | #include <QMessageBox> |
| 5 | |
| 6 | QMenuEditor::QMenuEditor(QWidget *parent) : |
| 7 | QWidget(parent), |
| 8 | ui(new Ui::menueditor) |
| 9 | { |
| 10 | ui->setupUi(this); |
| 11 | connect(ui->button_remove, &QToolButton::clicked, [this] { |
| 12 | int toBeRemoved = ui->list_target->currentRow(); |
| 13 | QList<QAction*> &list = mTarget; |
| 14 | |
| 15 | if ( toBeRemoved >= 0 && toBeRemoved < list.size()) |
| 16 | { |
| 17 | list.removeAt(toBeRemoved); |
| 18 | populateList(mTarget, ui->list_target); |
| 19 | ui->list_target->setCurrentRow(toBeRemoved - 1); |
| 20 | } |
| 21 | |
| 22 | emit targetChanged(); |
| 23 | }); |
| 24 | |
| 25 | connect(ui->button_insert, &QToolButton::clicked, [this] { |
| 26 | if (ui->list_source->currentItem() == nullptr) |
| 27 | { |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | bool success = insertAction(ui->list_source->currentItem()->data(Qt::UserRole).value<QAction*>()); |
| 32 | |
| 33 | if (!success) |
| 34 | { |
| 35 | QMessageBox::warning(this, "Error", "Item already inserted"); |
| 36 | } |
| 37 | |
| 38 | emit targetChanged(); |
| 39 | }); |
| 40 | |
| 41 | connect(ui->button_up, &QToolButton::clicked, [this] { |
| 42 | int curr_index = ui->list_target->currentRow(); |
| 43 | |
| 44 | QList<QAction*> &list = mTarget; |
| 45 | |
| 46 | if ( curr_index < 1 || curr_index >= list.size()) |
| 47 | { |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | qSwap(list[curr_index], list[curr_index - 1]); |
| 52 | |
| 53 | populateList(mTarget, ui->list_target); |
| 54 | ui->list_target->setCurrentRow(curr_index - 1); |
| 55 | emit targetChanged(); |
| 56 | }); |
| 57 | |
| 58 | connect(ui->button_down, &QToolButton::clicked, [this] { |
| 59 | int curr_index = ui->list_target->currentRow(); |
| 60 | |
| 61 | QList<QAction*> &list = mTarget; |
| 62 | |
| 63 | if ( curr_index < 0 || curr_index >= list.size() - 1 ) |