Freeciv-3.1
Loading...
Searching...
No Matches
shortcuts.cpp
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18
19// Qt
20#include <QDialog>
21#include <QDialogButtonBox>
22#include <QGridLayout>
23#include <QLabel>
24#include <QMouseEvent>
25#include <QLineEdit>
26#include <QScrollArea>
27#include <QSettings>
28#include <QVBoxLayout>
29#include <QWidget>
30
31// client
32#include "options.h"
33
34// gui-qt
35#include "fc_client.h"
36#include "shortcuts.h"
37
38extern "C" void real_menus_init();
39
40static QHash<int, const char *> key_map;
41static QString button_name(Qt::MouseButton bt);
42static QMap<shortcut_id, fc_shortcut*>* hash_copy(QMap<shortcut_id, fc_shortcut*> *h);
44QMap<shortcut_id, fc_shortcut*> fc_shortcuts::hash = QMap<shortcut_id, fc_shortcut*>();
45
46enum {
52};
53
54static bool use_default_shortcuts = false;
55
57
59 {SC_SCROLL_MAP, 0, Qt::RightButton, Qt::NoModifier, "Scroll map" },
60 {SC_CENTER_VIEW, Qt::Key_C, Qt::AllButtons, Qt::NoModifier,
61 _("Center View") },
62 {SC_FULLSCREEN, Qt::Key_Return, Qt::AllButtons, Qt::AltModifier,
63 _("Fullscreen") },
64 {SC_MINIMAP, Qt::Key_H, Qt::AllButtons, Qt::ShiftModifier,
65 _("Show minimap") },
66 {SC_CITY_OUTPUT, Qt::Key_V, Qt::AllButtons, Qt::ControlModifier,
67 _("City Output") },
68 {SC_MAP_GRID, Qt::Key_G, Qt::AllButtons, Qt::ControlModifier,
69 _("Map Grid") },
70 {SC_NAT_BORDERS, Qt::Key_B, Qt::AllButtons, Qt::ControlModifier,
71 _("National Borders") },
72 {SC_QUICK_BUY, 0, Qt::LeftButton, Qt::ControlModifier | Qt::ShiftModifier,
73 _("Quick buy from map") },
74 {SC_QUICK_SELECT, 0, Qt::LeftButton, Qt::ControlModifier,
75 _("Quick production select from map") },
76 {SC_SELECT_BUTTON, 0, Qt::LeftButton, Qt::NoModifier,
77 _("Select button") },
78 {SC_ADJUST_WORKERS, 0, Qt::LeftButton,
79 Qt::MetaModifier | Qt::ControlModifier, _("Adjust workers") },
80 {SC_APPEND_FOCUS, 0, Qt::LeftButton, Qt::MetaModifier,
81 _("Append focus") },
82 {SC_POPUP_INFO, 0, Qt::MiddleButton, Qt::NoModifier,
83 _("Popup tile info") },
84 {SC_WAKEUP_SENTRIES, 0, Qt::MiddleButton, Qt::ControlModifier,
85 _("Wakeup sentries") },
86 {SC_MAKE_LINK, 0, Qt::RightButton, Qt::ControlModifier | Qt::AltModifier,
87 _("Show link to tile") },
88 {SC_PASTE_PROD, 0, Qt::RightButton,
89 Qt::ShiftModifier | Qt::ControlModifier, _("Paste production") },
90 {SC_COPY_PROD, 0, Qt::RightButton,
91 Qt::ShiftModifier, _("Copy production") },
92 {SC_HIDE_WORKERS, 0, Qt::RightButton,
93 Qt::ShiftModifier | Qt::AltModifier, _("Show/hide workers") },
94 {SC_SHOW_UNITS, Qt::Key_Space, Qt::AllButtons, Qt::ControlModifier,
95 _("Units selection (for tile under mouse position)") },
96 {SC_TRADE_ROUTES, Qt::Key_D, Qt::AllButtons, Qt::ControlModifier,
97 _("City Trade Routes") },
98 {SC_CITY_PROD, Qt::Key_P, Qt::AllButtons, Qt::ControlModifier,
99 _("City Production Levels") },
100 {SC_CITY_NAMES, Qt::Key_N, Qt::AllButtons, Qt::ControlModifier,
101 _("City Names") },
102 {SC_DONE_MOVING, Qt::Key_Space, Qt::AllButtons, Qt::NoModifier,
103 _("Done Moving") },
104 {SC_GOTOAIRLIFT, Qt::Key_T, Qt::AllButtons, Qt::NoModifier,
105 _("Go to/Airlift to City...") },
106 {SC_AUTOEXPLORE, Qt::Key_X, Qt::AllButtons, Qt::NoModifier,
107 _("Auto Explore") },
108 {SC_PATROL, Qt::Key_Q, Qt::AllButtons, Qt::NoModifier,
109 _("Patrol") },
110 {SC_UNSENTRY_TILE, Qt::Key_D, Qt::AllButtons,
111 Qt::ShiftModifier | Qt::ControlModifier, _("Unsentry All On Tile") },
112 {SC_DO, Qt::Key_D, Qt::AllButtons, Qt::NoModifier, _("Do...") },
113 {SC_UPGRADE_UNIT, Qt::Key_U, Qt::AllButtons, Qt::ShiftModifier,
114 _("Upgrade") },
115 {SC_SETHOME, Qt::Key_H, Qt::AllButtons, Qt::NoModifier,
116 _("Set Home City") },
117 {SC_BUILDMINE, Qt::Key_M, Qt::AllButtons, Qt::NoModifier,
118 _("Build Mine") },
119 {SC_PLANT, Qt::Key_M, Qt::AllButtons, Qt::ShiftModifier,
120 _("Plant") },
121 {SC_BUILDIRRIGATION, Qt::Key_I, Qt::AllButtons, Qt::NoModifier,
122 _("Build Irrigation") },
123 {SC_CULTIVATE, Qt::Key_I, Qt::AllButtons, Qt::ShiftModifier,
124 _("Cultivate") },
125 {SC_BUILDROAD, Qt::Key_R, Qt::AllButtons, Qt::NoModifier,
126 _("Build Road") },
127 {SC_BUILDCITY, Qt::Key_B, Qt::AllButtons, Qt::NoModifier,
128 _("Build City") },
129 {SC_SENTRY, Qt::Key_S, Qt::AllButtons, Qt::NoModifier,
130 _("Sentry") },
131 {SC_FORTIFY, Qt::Key_F, Qt::AllButtons, Qt::NoModifier,
132 _("Fortify") },
133 {SC_GOTO, Qt::Key_G, Qt::AllButtons, Qt::NoModifier,
134 _("Go to Tile") },
135 {SC_WAIT, Qt::Key_W, Qt::AllButtons, Qt::NoModifier,
136 _("Wait") },
137 {SC_TRANSFORM, Qt::Key_O, Qt::AllButtons, Qt::NoModifier,
138 _("Transform") },
139 {SC_NUKE, Qt::Key_N, Qt::AllButtons, Qt::ShiftModifier,
140 _("Explode Nuclear") },
141 {SC_BOARD, Qt::Key_L, Qt::AllButtons, Qt::NoModifier,
142 _("Load") },
143 {SC_DEBOARD, Qt::Key_U, Qt::AllButtons, Qt::NoModifier,
144 _("Unload") },
145 {SC_BUY_MAP, 0, Qt::BackButton, Qt::NoModifier,
146 _("Quick buy current production from map") },
147 {SC_IFACE_LOCK, Qt::Key_L, Qt::AllButtons, Qt::ControlModifier
148 | Qt::ShiftModifier, _("Lock/unlock interface") },
149 {SC_AUTOMATE, Qt::Key_A, Qt::AllButtons, Qt::NoModifier,
150 _("Auto worker") },
151 {SC_PARADROP, Qt::Key_P, Qt::AllButtons, Qt::NoModifier,
152 _("Paradrop/clean pollution") },
153 {SC_POPUP_COMB_INF, Qt::Key_F1, Qt::AllButtons, Qt::ControlModifier,
154 _("Popup combat information") },
155 {SC_RELOAD_THEME, Qt::Key_F5, Qt::AllButtons, Qt::ControlModifier
156 | Qt::ShiftModifier, _("Reload theme") },
157 {SC_RELOAD_TILESET, Qt::Key_F6, Qt::AllButtons, Qt::ControlModifier
158 | Qt::ShiftModifier, _("Reload tileset") },
159 {SC_SHOW_FULLBAR, Qt::Key_F, Qt::AllButtons, Qt::ControlModifier,
160 _("Toggle city full bar visibility") },
161 {SC_ZOOM_IN, Qt::Key_Plus, Qt::AllButtons, Qt::NoModifier,
162 _("Reload zoomed in tileset") },
163 {SC_ZOOM_OUT, Qt::Key_Minus, Qt::AllButtons, Qt::NoModifier,
164 _("Reload zoomed out tileset") },
165 {SC_LOAD_LUA, Qt::Key_J, Qt::AllButtons, Qt::ControlModifier
166 | Qt::ShiftModifier, _("Load Lua script") },
167 {SC_RELOAD_LUA, Qt::Key_K, Qt::AllButtons, Qt::ControlModifier
168 | Qt::ShiftModifier, _("Load last loaded Lua script") },
169 {SC_ZOOM_RESET, Qt::Key_Backspace, Qt::AllButtons, Qt::ControlModifier,
170 _("Reload tileset with default scale") },
171 {SC_GOBUILDCITY, Qt::Key_B, Qt::AllButtons, Qt::ShiftModifier,
172 _("Go And Build City") },
173 {SC_GOJOINCITY, Qt::Key_J, Qt::AllButtons, Qt::ShiftModifier,
174 _("Go And Join City") },
175 {SC_STACK_SIZE, Qt::Key_Plus, Qt::AllButtons, Qt::ControlModifier,
176 _("Unit Stack Size") }
177};
178
179
180/**********************************************************************/
184{
185 QString ret, m, bn, k;
186
187 if (sc == nullptr) {
188 return "";
189 }
190 if (sc->mod != Qt::NoModifier) {
191 m = QKeySequence(sc->mod).toString(QKeySequence::NativeText);
192 }
193 if (sc->mouse != Qt::AllButtons) {
194 bn = button_name(sc->mouse);
195 }
196 if (sc->key != 0) {
197 k = QKeySequence(sc->key).toString(QKeySequence::NativeText);
198 }
199 ret = m + bn + k;
200
201 return ret;
202}
203
204/**********************************************************************/
211
212/**********************************************************************/
216{
217 qDeleteAll(hash.begin(), hash.end());
218 hash.clear();
219}
220
221
222/**********************************************************************/
226{
227 fc_shortcut *s;
228 s = hash.value(id);
229 return s->str;
230}
231
232/**********************************************************************/
236{
237 fc_shortcut *s;
238 s = hash.value(id);
239 return s;
240}
241
242/**********************************************************************/
249
250/**********************************************************************/
254{
256
257 sc = hash.value(s->id);
258 sc->key = s->key;
259 sc->mod = s->mod;
260 sc->mouse = s->mouse;
261}
262
263/**********************************************************************/
267{
268 if (m_instance) {
269 delete m_instance;
270 m_instance = nullptr;
271 }
272}
273
274/**********************************************************************/
278{
279 if (!m_instance) {
281 }
282
283 return m_instance;
284}
285
286/**********************************************************************/
291{
292 return m_instance != nullptr;
293}
294
295/**********************************************************************/
299{
300 int i;
301 bool suc = false;
302
303 hash.clear();
304
305 if (read) {
306 suc = read_shortcuts();
307 }
308
309 for (i = 0 ; i < num_shortcuts; i++) {
310 fc_shortcut *s = nullptr;
311
312 if (suc) {
313 s = fc_shortcuts::hash.value(static_cast<shortcut_id>(i + 1));
314 }
315 if (s == nullptr) {
316 s = new fc_shortcut();
317 s->id = default_shortcuts[i].id;
318 s->key = default_shortcuts[i].key;
320 s->mod = default_shortcuts[i].mod;
321 s->str = default_shortcuts[i].str;
322 hash.insert(default_shortcuts[i].id, s);
323 }
324 }
325}
326
327/**********************************************************************/
330fc_shortcut_popup::fc_shortcut_popup(QWidget *parent): QDialog()
331{
332 QVBoxLayout *vb = new QVBoxLayout;
333 setParent(parent);
334 setAttribute(Qt::WA_DeleteOnClose);
335 setWindowFlags(Qt::Popup);
336 vb->addWidget(&edit);
337 setLayout(vb);
338 sc = nullptr;
339}
340
341/**********************************************************************/
345{
346 setContextMenuPolicy(Qt::NoContextMenu);
347 setWindowModality(Qt::WindowModal);
348}
349
350/**********************************************************************/
354{
356 shc.mouse = event->button();
357 shc.mod = event->modifiers();
358 fcp = reinterpret_cast<fc_shortcut_popup *>(parentWidget());
359 fcp->sc->mouse = shc.mouse;
360 fcp->sc->mod = shc.mod;
361 fcp->sc->key = 0;
362 parentWidget()->close();
363}
364
365/**********************************************************************/
369{
371
372 shc.key = event->key();
373 shc.mod = event->modifiers();
374 fcp = reinterpret_cast<fc_shortcut_popup *>(parentWidget());
375 fcp->sc->mouse = Qt::AllButtons;
376 fcp->sc->key = shc.key;
377 fcp->sc->mod = shc.mod;
378 parentWidget()->close();
379}
380
381/**********************************************************************/
385{
386 QPoint p(50, 20);
387 edit.setReadOnly(true);
388 edit.setFocus();
389 setWindowModality(Qt::WindowModal);
390 sc = s;
391 move(QCursor::pos() - p);
392 show();
393}
394
395/**********************************************************************/
398void fc_shortcut_popup::closeEvent(QCloseEvent *ev)
399{
400 fc_sc_button *scp;
401
402 if (sc != nullptr) {
403 if (!check_if_exist()) {
404 scp = reinterpret_cast<fc_sc_button *>(parentWidget());
405 scp->setText(shortcut_to_string(scp->sc));
407 }
408 }
409
410 QDialog::closeEvent(ev);
411}
412
413/**********************************************************************/
418{
419 fc_shortcut *fsc;
420 QString desc;
421 int id = 0;
422
423 desc = "";
424 if (sc != nullptr) {
425 foreach (fsc, fc_shortcuts::sc()->hash) {
426 if (id == 0) {
427 id++;
428 continue;
429 }
430 if (*sc == *fsc) {
431 desc = fc_shortcuts::sc()->get_desc(static_cast<shortcut_id>(id + 1));
432 }
433 id++;
434 }
435 if (desc.isEmpty()) {
436 desc = gui()->menu_bar->shortcut_exist(sc);
437 }
438 if (!desc.isEmpty()) {
439 fc_sc_button *fsb;
440 fsb = qobject_cast<fc_sc_button*>(parentWidget());
441 fsb->show_info(desc);
442 return true;
443 }
444 }
445
446 return false;
447}
448
449/**********************************************************************/
452QString button_name(Qt::MouseButton bt)
453{
454 switch (bt) {
455 case Qt::NoButton:
456 return _("NoButton");
457 case Qt::LeftButton:
458 return _("LeftButton");
459 case Qt::RightButton:
460 return _("RightButton");
461 case Qt::MiddleButton:
462 return _("MiddleButton");
463 case Qt::BackButton:
464 return _("BackButton");
465 case Qt::ForwardButton:
466 return _("ForwardButton");
467 case Qt::TaskButton:
468 return _("TaskButton");
469 case Qt::ExtraButton4:
470 return _("ExtraButton4");
471 case Qt::ExtraButton5:
472 return _("ExtraButton5");
473 case Qt::ExtraButton6:
474 return _("ExtraButton6");
475 case Qt::ExtraButton7:
476 return _("ExtraButton7");
477 case Qt::ExtraButton8:
478 return _("ExtraButton8");
479 case Qt::ExtraButton9:
480 return _("ExtraButton9");
481 case Qt::ExtraButton10:
482 return _("ExtraButton10");
483 case Qt::ExtraButton11:
484 return _("ExtraButton11");
485 case Qt::ExtraButton12:
486 return _("ExtraButton12");
487 case Qt::ExtraButton13:
488 return _("ExtraButton13");
489 case Qt::ExtraButton14:
490 return _("ExtraButton14");
491 case Qt::ExtraButton15:
492 return _("ExtraButton15");
493 case Qt::ExtraButton16:
494 return _("ExtraButton16");
495 case Qt::ExtraButton17:
496 return _("ExtraButton17");
497 case Qt::ExtraButton18:
498 return _("ExtraButton18");
499 case Qt::ExtraButton19:
500 return _("ExtraButton19");
501 case Qt::ExtraButton20:
502 return _("ExtraButton20");
503 case Qt::ExtraButton21:
504 return _("ExtraButton21");
505 case Qt::ExtraButton22:
506 return _("ExtraButton22");
507 case Qt::ExtraButton23:
508 return _("ExtraButton23");
509 case Qt::ExtraButton24:
510 return _("ExtraButton24");
511 default:
512 return "";
513 }
514}
515
516/**********************************************************************/
520{
521 sc = new fc_shortcut;
522}
523
524/**********************************************************************/
528{
529 sc_orig = s;
530 sc = new fc_shortcut;
531 sc->id = sc_orig->id;
532 sc->key = sc_orig->key;
533 sc->mouse = sc_orig->mouse;
534 sc->mod = sc_orig->mod;
535 sc->str = sc_orig->str;
536 setText(shortcut_to_string(sc));
537}
538
539/**********************************************************************/
543{
545 popup_error();
546}
547
548/**********************************************************************/
552{
553 hud_message_box *scinfo;
554 QList<fc_shortcut_popup *> fsb_list;
555 QString title;
556
557 /* wait until shortcut popup is destroyed */
558 fsb_list = findChildren<fc_shortcut_popup *>();
559 if (fsb_list.count() > 0) {
560 QTimer::singleShot(20, this, SLOT(popup_error()));
561 return;
562 }
563
564 /* TRANS: Given shortcut(%1) is already assigned */
565 title = QString(_("%1 is already assigned to"))
566 .arg(shortcut_to_string(sc));
567 scinfo = new hud_message_box(gui()->central_wdg);
568 scinfo->setStandardButtons(QMessageBox::Ok);
569 scinfo->setDefaultButton(QMessageBox::Ok);
571 scinfo->setAttribute(Qt::WA_DeleteOnClose);
572 scinfo->show();
573}
574
575/**********************************************************************/
579 : QDialog(parent)
580{
581 setWindowTitle(_("Shortcuts options"));
583 init();
584}
585
586/**********************************************************************/
592
593/**********************************************************************/
597{
598 fc_shortcut *sc;
599 QPushButton *but;
600 QScrollArea *scroll;
601 QSize size;
602 QString desc;
603 QWidget *widget;
605
606 widget = new QWidget(this);
607 scroll = new QScrollArea(this);
608 scroll->setWidgetResizable(true);
609 scroll_layout = new QVBoxLayout;
610 main_layout = new QVBoxLayout;
611 foreach (sc, fc_shortcuts::sc()->hash) {
612 id = fc_shortcuts::sc()->get_id(sc);
613 desc = fc_shortcuts::sc()->get_desc(id);
614 add_option(sc);
615 }
616 widget->setProperty("doomed", true);
617 widget->setLayout(scroll_layout);
618 scroll->setWidget(widget);
619 main_layout->addWidget(scroll);
620
621 button_box = new QDialogButtonBox();
622 but = new QPushButton(style()->standardIcon(QStyle::SP_DialogCancelButton),
623 _("Cancel"));
624 button_box->addButton(but, QDialogButtonBox::ActionRole);
625 QObject::connect(but, &QPushButton::clicked, [this]() {
627 });
628
629 but = new QPushButton(style()->standardIcon(QStyle::SP_DialogResetButton),
630 _("Reset"));
631 button_box->addButton(but, QDialogButtonBox::ResetRole);
632 QObject::connect(but, &QPushButton::clicked, [this]() {
634 });
635
636 but = new QPushButton(style()->standardIcon(QStyle::SP_DialogApplyButton),
637 _("Apply"));
638 button_box->addButton(but, QDialogButtonBox::ActionRole);
639 QObject::connect(but, &QPushButton::clicked, [this]() {
641 });
642
643 but = new QPushButton(style()->standardIcon(QStyle::SP_DialogSaveButton),
644 _("Save"));
645 button_box->addButton(but, QDialogButtonBox::ActionRole);
646 QObject::connect(but, &QPushButton::clicked, [this]() {
648 });
649
650 but = new QPushButton(style()->standardIcon(QStyle::SP_DialogOkButton),
651 _("Ok"));
652 button_box->addButton(but, QDialogButtonBox::ActionRole);
653 QObject::connect(but, &QPushButton::clicked, [this]() {
655 });
656
657 main_layout->addWidget(button_box);
658 setLayout(main_layout);
659 size = sizeHint();
660 size.setWidth(size.width() + 10
661 + style()->pixelMetric(QStyle::PM_ScrollBarExtent));
662 resize(size);
663 setAttribute(Qt::WA_DeleteOnClose);
664}
665
666/**********************************************************************/
670{
671 QHBoxLayout *hb;
672 QLabel *l;
673
674 l = new QLabel(sc->str);
675 hb = new QHBoxLayout();
676
677 fc_sc_button *fb = new fc_sc_button(sc);
678 connect(fb, &QAbstractButton::clicked, this, &fc_shortcuts_dialog::edit_shortcut);
679
680 hb->addWidget(l, 1, Qt::AlignLeft);
681 hb->addStretch();
682 hb->addWidget(fb, 1, Qt::AlignRight);
683
684 scroll_layout->addLayout(hb);
685}
686
687/**********************************************************************/
691{
692 fc_sc_button *pb;
693 pb = qobject_cast<fc_sc_button *>(sender());
695 sb->run(pb->sc);
696}
697
698/**********************************************************************/
702{
703 QLayout *layout;
704 QLayoutItem *item;
705 QWidget *widget;
706
708 while ((item = layout->takeAt(0))) {
709 if (item->layout() != nullptr) {
710 // Nothing
711 } else if ((widget = item->widget()) != nullptr) {
712 widget->hide();
713 delete widget;
714 } else {
715 delete item;
716 }
717 }
718 delete main_layout;
719 init();
720}
721
722/**********************************************************************/
726{
727 switch (response) {
728 case RESPONSE_APPLY:
730 gui()->menuBar()->setVisible(true);
731 break;
732 case RESPONSE_CANCEL:
734 fc_shortcuts::hash.detach();
735 close();
736 break;
737 case RESPONSE_OK:
739 gui()->menuBar()->setVisible(true);
740 close();
741 break;
742 case RESPONSE_SAVE:
744 break;
745 case RESPONSE_RESET:
747 refresh();
748 break;
749 }
750}
751
752/**********************************************************************/
756{
758 sh->show();
759}
760
761/**********************************************************************/
764QMap<shortcut_id, fc_shortcut *> *hash_copy(QMap<shortcut_id, fc_shortcut *> *h)
765{
766 QMap<shortcut_id, fc_shortcut*> *new_hash;
767 fc_shortcut *s;
768 fc_shortcut *sc;
769 int i;
771 new_hash = new QMap<shortcut_id, fc_shortcut*>;
772
773 for (i = 1 ; i < num_shortcuts + 1; i++) {
774 sc = new fc_shortcut();
775 id = static_cast<shortcut_id>(i);
776 s = h->value(id);
777 sc->id = id;
778 sc->key = s->key;
779 sc->mouse = s->mouse;
780 sc->mod = s->mod;
781 sc->str = s->str;
782 new_hash->insert(sc->id, sc);
783 }
784
785 return new_hash;
786}
787
788/**********************************************************************/
792{
793 fc_shortcut *sc;
794 QMap<shortcut_id, fc_shortcut*> h = fc_shortcuts::hash;
795 // This can't be shared between freeciv versions as shortcut
796 // ids can change incompatible way between versions.
797 QString sname = "freeciv-qt-client-sc-"
798 + QString::number(MAJOR_NEW_OPTION_FILE_NAME) + "."
799 + QString::number(MINOR_NEW_OPTION_FILE_NAME);
800 QSettings s(QSettings::IniFormat, QSettings::UserScope,
801 sname);
802
804 // Shortcuts not even initialized yet. Happens e.g. when we quit from
805 // the main menu without ever visiting the game.
806 return;
807 }
808
809 s.beginWriteArray("Shortcuts");
810 for (int i = 0; i < num_shortcuts; ++i) {
811 s.setArrayIndex(i);
812 sc = h.value(static_cast<shortcut_id>(i + 1));
813 s.setValue("id", sc->id);
814 s.setValue("key", sc->key);
815 s.setValue("mouse", sc->mouse);
816 s.setValue("mod", QVariant(sc->mod));
817 }
818 s.endArray();
819}
820
821/**********************************************************************/
825{
826 int num, i;
827 fc_shortcut *sc;
828
830 return false;
831 }
832
833 QString sname = "freeciv-qt-client-sc-"
834 + QString::number(MAJOR_NEW_OPTION_FILE_NAME) + "."
835 + QString::number(MINOR_NEW_OPTION_FILE_NAME);
836 QSettings s(QSettings::IniFormat, QSettings::UserScope,
837 sname);
838
839 num = s.beginReadArray("Shortcuts");
840 if (num == num_shortcuts) {
841 for (i = 0; i < num_shortcuts; ++i) {
842 s.setArrayIndex(i);
843 sc = new fc_shortcut();
844 sc->id = static_cast<shortcut_id>(s.value("id").toInt());
845 sc->key = s.value("key").toInt();
846 sc->mouse = static_cast<Qt::MouseButton>(s.value("mouse").toInt());
847 sc->mod = static_cast<Qt::KeyboardModifiers>(s.value("mod").toInt());
848 sc->str = default_shortcuts[i].str;
849 fc_shortcuts::hash.insert(sc->id, sc);
850 }
851 } else {
852 s.endArray();
853
854 return false;
855 }
856 s.endArray();
857
858 return true;
859}
860
861/**********************************************************************/
865{
867}
#define str
Definition astring.c:76
fc_shortcut * sc_orig
Definition shortcuts.h:180
void show_info(QString str)
void popup_error()
fc_shortcut * sc
Definition shortcuts.h:179
QString err_message
Definition shortcuts.h:175
void closeEvent(QCloseEvent *)
fc_shortcut * sc
Definition shortcuts.h:161
void run(fc_shortcut *s)
fc_shortcut_popup(QWidget *parent)
virtual ~fc_shortcuts_dialog()
void add_option(fc_shortcut *sc)
void apply_option(int response)
fc_shortcuts_dialog(QWidget *parent=0)
QDialogButtonBox * button_box
Definition shortcuts.h:194
QVBoxLayout * scroll_layout
Definition shortcuts.h:193
QMap< shortcut_id, fc_shortcut * > * hashcopy
Definition shortcuts.h:195
QVBoxLayout * main_layout
Definition shortcuts.h:192
static fc_shortcuts * m_instance
Definition shortcuts.h:122
static QMap< shortcut_id, fc_shortcut * > hash
Definition shortcuts.h:129
static fc_shortcuts * sc()
static void init_default(bool read)
static void drop()
QString get_desc(shortcut_id id)
fc_shortcut * get_shortcut(shortcut_id id)
static bool is_instantiated()
void set_shortcut(fc_shortcut *sc)
shortcut_id get_id(fc_shortcut *sc)
int set_text_title(QString s1, QString s2, bool return_exec=false)
void mousePressEvent(QMouseEvent *event)
fc_shortcut shc
Definition shortcuts.h:146
void keyReleaseEvent(QKeyEvent *event)
int int id
Definition editgui_g.h:28
enum event_type event
Definition events.c:81
#define _(String)
Definition fcintl.h:67
static PangoLayout * layout
Definition canvas.c:331
void real_menus_init(void)
Definition menu.c:2841
@ RESPONSE_SAVE
Definition optiondlg.c:66
@ RESPONSE_APPLY
Definition optiondlg.c:63
@ RESPONSE_CANCEL
Definition optiondlg.c:61
@ RESPONSE_OK
Definition optiondlg.c:62
@ RESPONSE_RESET
Definition optiondlg.c:64
const char * title
Definition repodlgs.c:1313
static GHashTable * hash
Definition wldlg.c:320
static mpgui * gui
Definition mpgui_qt.cpp:52
#define MAJOR_NEW_OPTION_FILE_NAME
Definition options.h:37
#define MINOR_NEW_OPTION_FILE_NAME
Definition options.h:41
static QHash< int, const char * > key_map
Definition shortcuts.cpp:40
void popup_shortcuts_dialog()
fc_shortcut default_shortcuts[]
Definition shortcuts.cpp:58
bool read_shortcuts()
void shortcutreset()
QString shortcut_to_string(fc_shortcut *sc)
static QMap< shortcut_id, fc_shortcut * > * hash_copy(QMap< shortcut_id, fc_shortcut * > *h)
void real_menus_init()
Definition menu.c:2841
static bool use_default_shortcuts
Definition shortcuts.cpp:54
static QString button_name(Qt::MouseButton bt)
void write_shortcuts()
static int num_shortcuts
Definition shortcuts.cpp:56
@ RESPONSE_SAVE
Definition shortcuts.cpp:51
@ RESPONSE_APPLY
Definition shortcuts.cpp:49
@ RESPONSE_CANCEL
Definition shortcuts.cpp:47
@ RESPONSE_OK
Definition shortcuts.cpp:48
@ RESPONSE_RESET
Definition shortcuts.cpp:50
shortcut_id
Definition shortcuts.h:33
@ SC_PARADROP
Definition shortcuts.h:82
@ SC_UPGRADE_UNIT
Definition shortcuts.h:63
@ SC_BUILDIRRIGATION
Definition shortcuts.h:67
@ SC_BUILDCITY
Definition shortcuts.h:70
@ SC_DONE_MOVING
Definition shortcuts.h:57
@ SC_BUILDROAD
Definition shortcuts.h:69
@ SC_UNSENTRY_TILE
Definition shortcuts.h:61
@ SC_CULTIVATE
Definition shortcuts.h:68
@ SC_DO
Definition shortcuts.h:62
@ SC_CENTER_VIEW
Definition shortcuts.h:36
@ SC_POPUP_COMB_INF
Definition shortcuts.h:83
@ SC_SENTRY
Definition shortcuts.h:71
@ SC_GOBUILDCITY
Definition shortcuts.h:92
@ SC_NUKE
Definition shortcuts.h:76
@ SC_HIDE_WORKERS
Definition shortcuts.h:52
@ SC_AUTOEXPLORE
Definition shortcuts.h:59
@ SC_POPUP_INFO
Definition shortcuts.h:47
@ SC_SETHOME
Definition shortcuts.h:64
@ SC_RELOAD_LUA
Definition shortcuts.h:90
@ SC_PLANT
Definition shortcuts.h:66
@ SC_BUILDMINE
Definition shortcuts.h:65
@ SC_FULLSCREEN
Definition shortcuts.h:37
@ SC_TRADE_ROUTES
Definition shortcuts.h:54
@ SC_CITY_OUTPUT
Definition shortcuts.h:39
@ SC_TRANSFORM
Definition shortcuts.h:75
@ SC_STACK_SIZE
Definition shortcuts.h:94
@ SC_SHOW_UNITS
Definition shortcuts.h:53
@ SC_PASTE_PROD
Definition shortcuts.h:50
@ SC_WAKEUP_SENTRIES
Definition shortcuts.h:48
@ SC_MAKE_LINK
Definition shortcuts.h:49
@ SC_FORTIFY
Definition shortcuts.h:72
@ SC_APPEND_FOCUS
Definition shortcuts.h:46
@ SC_ZOOM_IN
Definition shortcuts.h:87
@ SC_GOJOINCITY
Definition shortcuts.h:93
@ SC_MAP_GRID
Definition shortcuts.h:40
@ SC_MINIMAP
Definition shortcuts.h:38
@ SC_QUICK_BUY
Definition shortcuts.h:42
@ SC_CITY_PROD
Definition shortcuts.h:55
@ SC_RELOAD_THEME
Definition shortcuts.h:84
@ SC_PATROL
Definition shortcuts.h:60
@ SC_GOTO
Definition shortcuts.h:73
@ SC_RELOAD_TILESET
Definition shortcuts.h:85
@ SC_BUY_MAP
Definition shortcuts.h:79
@ SC_SCROLL_MAP
Definition shortcuts.h:35
@ SC_GOTOAIRLIFT
Definition shortcuts.h:58
@ SC_WAIT
Definition shortcuts.h:74
@ SC_QUICK_SELECT
Definition shortcuts.h:43
@ SC_IFACE_LOCK
Definition shortcuts.h:80
@ SC_DEBOARD
Definition shortcuts.h:78
@ SC_ZOOM_RESET
Definition shortcuts.h:91
@ SC_ZOOM_OUT
Definition shortcuts.h:88
@ SC_ADJUST_WORKERS
Definition shortcuts.h:45
@ SC_SELECT_BUTTON
Definition shortcuts.h:44
@ SC_AUTOMATE
Definition shortcuts.h:81
@ SC_CITY_NAMES
Definition shortcuts.h:56
@ SC_COPY_PROD
Definition shortcuts.h:51
@ SC_LOAD_LUA
Definition shortcuts.h:89
@ SC_BOARD
Definition shortcuts.h:77
@ SC_NAT_BORDERS
Definition shortcuts.h:41
@ SC_SHOW_FULLBAR
Definition shortcuts.h:86
bool read_shortcuts()
QString shortcut_to_string(fc_shortcut *sc)
#define SC_NUM_SHORTCUTS
Definition shortcuts.h:97
void write_shortcuts()
size_t size
Definition specvec.h:72
QString str
Definition shortcuts.h:109
Qt::KeyboardModifiers mod
Definition shortcuts.h:108
Qt::MouseButton mouse
Definition shortcuts.h:107
shortcut_id id
Definition shortcuts.h:105
Definition climisc.h:82
#define show(id)
Definition widget.h:235