Author: sveinung Date: Sun Oct 9 17:27:35 2016 New Revision: 34072 URL: http://svn.gna.org/viewcvs/freeciv?rev=34072&view=rev Log: ruledit: support changing action enabler action.
See patch #7785 Modified: trunk/tools/ruledit/tab_enablers.cpp trunk/tools/ruledit/tab_enablers.h Modified: trunk/tools/ruledit/tab_enablers.cpp URL: http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/tab_enablers.cpp?rev=34072&r1=34071&r2=34072&view=diff ============================================================================== --- trunk/tools/ruledit/tab_enablers.cpp (original) +++ trunk/tools/ruledit/tab_enablers.cpp Sun Oct 9 17:27:35 2016 @@ -65,8 +65,23 @@ label = new QLabel(QString::fromUtf8(R__("Type"))); label->setParent(this); enabler_layout->addWidget(label, 0, 0); - type = new QLabel(); - enabler_layout->addWidget(type, 0, 2); + + type_button = new QToolButton(); + type_menu = new QMenu(); + + action_iterate(act) { + type_menu->addAction(action_id_rule_name(act)); + } action_iterate_end; + + connect(type_menu, SIGNAL(triggered(QAction *)), + this, SLOT(edit_type(QAction *))); + + type_button->setToolButtonStyle(Qt::ToolButtonTextOnly); + type_button->setPopupMode(QToolButton::MenuButtonPopup); + + type_button->setMenu(type_menu); + + enabler_layout->addWidget(type_button, 0, 2); reqs_button = new QPushButton(QString::fromUtf8(R__("Actor Requirements")), this); connect(reqs_button, SIGNAL(pressed()), this, SLOT(edit_actor_reqs())); @@ -129,9 +144,9 @@ if (selected != nullptr) { QString dispn = QString::fromUtf8(action_rule_name(enabler_get_action(enabler))); - type->setText(dispn); + type_button->setText(dispn); } else { - type->setText("None"); + type_button->setText("None"); } } @@ -203,6 +218,26 @@ } /************************************************************************** + User selected action to enable +**************************************************************************/ +void tab_enabler::edit_type(QAction *action) +{ + struct action *paction; + + paction = action_by_rule_name(action->text().toUtf8().data()); + + if (selected != nullptr && paction != nullptr) { + /* Must remove and add back because enablers are stored by action. */ + action_enabler_remove(selected); + selected->action = paction->id; + action_enabler_add(selected); + + update_enabler_info(selected); + refresh(); + } +} + +/************************************************************************** User wants to edit target reqs **************************************************************************/ void tab_enabler::edit_target_reqs() Modified: trunk/tools/ruledit/tab_enablers.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/tab_enablers.h?rev=34072&r1=34071&r2=34072&view=diff ============================================================================== --- trunk/tools/ruledit/tab_enablers.h (original) +++ trunk/tools/ruledit/tab_enablers.h Sun Oct 9 17:27:35 2016 @@ -24,7 +24,9 @@ class QLabel; class QLineEdit; class QListWidget; +class QMenu; class QRadioButton; +class QToolButton; class ruledit_gui; @@ -41,7 +43,8 @@ void update_enabler_info(struct action_enabler *enabler); bool initialize_new_enabler(struct action_enabler *enabler); - QLabel *type; + QToolButton *type_button; + QMenu *type_menu; QListWidget *enabler_list; struct action_enabler *selected; @@ -50,6 +53,7 @@ void select_enabler(); void add_now(); void delete_now(); + void edit_type(QAction *action); void edit_target_reqs(); void edit_actor_reqs(); }; _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits