Author: mir3x Date: Sun Nov 27 14:23:42 2016 New Revision: 34641 URL: http://svn.gna.org/viewcvs/freeciv?rev=34641&view=rev Log: Qt client - added shortcut checker for duplicates
See patch #8028 Modified: branches/S2_6/client/gui-qt/menu.cpp branches/S2_6/client/gui-qt/menu.h branches/S2_6/client/gui-qt/shortcuts.cpp branches/S2_6/client/gui-qt/shortcuts.h Modified: branches/S2_6/client/gui-qt/menu.cpp URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/menu.cpp?rev=34641&r1=34640&r2=34641&view=diff ============================================================================== --- branches/S2_6/client/gui-qt/menu.cpp (original) +++ branches/S2_6/client/gui-qt/menu.cpp Sun Nov 27 14:23:42 2016 @@ -1470,6 +1470,29 @@ } /**************************************************************************** + Returns string assigned to shortcut or empty string if doesnt exist +****************************************************************************/ +QString mr_menu::shortcut_exist(fc_shortcut *fcs) +{ + QList<QMenu*> menu_list; + QMenu *m; + QKeySequence seq; + QAction* a; + + seq = QKeySequence(shortcut_to_string(fcs)); + menu_list = findChildren<QMenu *>(); + foreach (m, menu_list) { + foreach (a, m->actions()) { + if (a->shortcut() == seq && fcs->mouse == Qt::AllButtons) { + return a->text(); + } + } + } + + return QString(); +} + +/**************************************************************************** Returns string bounded to given shortcut ****************************************************************************/ QString mr_menu::shortcut_2_menustring(int sid) Modified: branches/S2_6/client/gui-qt/menu.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/menu.h?rev=34641&r1=34640&r2=34641&view=diff ============================================================================== --- branches/S2_6/client/gui-qt/menu.h (original) +++ branches/S2_6/client/gui-qt/menu.h Sun Nov 27 14:23:42 2016 @@ -33,6 +33,7 @@ class QPushButton; class QSignalMapper; class QScrollArea; +class fc_shortcut; void qt_start_turn(); @@ -263,6 +264,7 @@ void update_airlift_menu(); void set_tile_for_order(struct tile *ptile); void execute_shortcut(int sid); + QString shortcut_exist(fc_shortcut *fcs); QString shortcut_2_menustring(int sid); QAction *minimap_status; QAction *lock_status; Modified: branches/S2_6/client/gui-qt/shortcuts.cpp URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/shortcuts.cpp?rev=34641&r1=34640&r2=34641&view=diff ============================================================================== --- branches/S2_6/client/gui-qt/shortcuts.cpp (original) +++ branches/S2_6/client/gui-qt/shortcuts.cpp Sun Nov 27 14:23:42 2016 @@ -271,6 +271,7 @@ { QVBoxLayout *vb = new QVBoxLayout; setParent(parent); + setAttribute(Qt::WA_DeleteOnClose); setWindowFlags(Qt::Popup); vb->addWidget(&edit); setLayout(vb); @@ -338,12 +339,50 @@ { fc_sc_button *scp; if (sc != nullptr) { - scp = reinterpret_cast<fc_sc_button *>(parentWidget()); - scp->setText(shortcut_to_string(scp->sc)); - fc_shortcuts::sc()->set_shortcut(sc); + if (check_if_exist() == false) { + scp = reinterpret_cast<fc_sc_button *>(parentWidget()); + scp->setText(shortcut_to_string(scp->sc)); + fc_shortcuts::sc()->set_shortcut(sc); + } } QDialog::closeEvent(ev); +} + +/************************************************************************** + Checks is shortcut is already assigned and popups hud box then + or return false if is not assigned +**************************************************************************/ +bool fc_shortcut_popup::check_if_exist() +{ + fc_shortcut *fsc; + QString desc; + int id = 0; + + desc = ""; + if (sc != nullptr) { + foreach (fsc, fc_shortcuts::sc()->hash) { + if (id == 0) { + id++; + continue; + } + if (*sc == *fsc) { + desc = fc_shortcuts::sc()->get_desc(static_cast<shortcut_id>(id + 1)); + } + id++; + } + if (desc.isEmpty() == true) { + desc = gui()->menu_bar->shortcut_exist(sc); + } + if (desc.isEmpty() == false) { + fc_sc_button *fsb; + fsb = qobject_cast<fc_sc_button*>(parentWidget()); + fsb->show_info(desc); + return true; + } + } + + return false; } @@ -428,10 +467,48 @@ **************************************************************************/ fc_sc_button::fc_sc_button(fc_shortcut *s): QPushButton() { - sc = s; + sc_orig = s; + sc = new fc_shortcut; + sc->id = sc_orig->id; + sc->key = sc_orig->key; + sc->mouse = sc_orig->mouse; + sc->mod = sc_orig->mod; + sc->str = sc_orig->str; setText(shortcut_to_string(sc)); } +/************************************************************************** + Executes slot to show information about assigned shortcut +**************************************************************************/ +void fc_sc_button::show_info(QString str) +{ + err_message = str; + popup_error(); +} + +/************************************************************************** + Shows information about assigned shortcut +**************************************************************************/ +void fc_sc_button::popup_error() +{ + hud_message_box scinfo(gui()->central_wdg); + QList<fc_shortcut_popup *> fsb_list; + QString title; + /* wait until shortcut popup is destroyed */ + fsb_list = findChildren<fc_shortcut_popup *>(); + if (fsb_list.count() > 0) { + QTimer::singleShot(20, this, SLOT(popup_error())); + return; + } + + /* TRANS: Given shortcut(%1) is already assigned */ + title = QString(_("%1 is already assigned to")) + .arg(shortcut_to_string(sc)); + scinfo.setStandardButtons(QMessageBox::Ok); + scinfo.setDefaultButton(QMessageBox::Ok); + scinfo.set_text_title(err_message, title); + scinfo.exec(); +} /************************************************************************** Contructor for shortcut dialog **************************************************************************/ Modified: branches/S2_6/client/gui-qt/shortcuts.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/shortcuts.h?rev=34641&r1=34640&r2=34641&view=diff ============================================================================== --- branches/S2_6/client/gui-qt/shortcuts.h (original) +++ branches/S2_6/client/gui-qt/shortcuts.h Sun Nov 27 14:23:42 2016 @@ -90,6 +90,9 @@ Qt::MouseButton mouse; Qt::KeyboardModifiers mod; QString str; + bool operator==(const fc_shortcut& a) const { + return ((key == a.key) && (mouse == a.mouse) && (mod == a.mod)); + } }; /************************************************************************** @@ -138,6 +141,7 @@ protected: void closeEvent(QCloseEvent*); private: + bool check_if_exist(); line_edit edit; }; @@ -147,10 +151,15 @@ class fc_sc_button : public QPushButton { Q_OBJECT + QString err_message; public: fc_sc_button(); fc_sc_button(fc_shortcut *s); fc_shortcut *sc; + fc_shortcut *sc_orig; + void show_info(QString str); +private slots: + void popup_error(); }; /************************************************************************** _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits