Changeset View
Changeset View
Standalone View
Standalone View
src/kgoldrunner.cpp
Show All 19 Lines | |||||
20 | #include "kgoldrunner.h" | 20 | #include "kgoldrunner.h" | ||
21 | 21 | | |||
22 | #include <QAction> | 22 | #include <QAction> | ||
23 | #include <QApplication> | 23 | #include <QApplication> | ||
24 | #include <QDesktopWidget> | 24 | #include <QDesktopWidget> | ||
25 | #include <QIcon> | 25 | #include <QIcon> | ||
26 | #include <QKeyEvent> | 26 | #include <QKeyEvent> | ||
27 | #include <QKeySequence> | 27 | #include <QKeySequence> | ||
28 | #include <QSignalMapper> | | |||
29 | #include <QShortcut> | 28 | #include <QShortcut> | ||
30 | 29 | | |||
31 | #include <KActionCollection> | 30 | #include <KActionCollection> | ||
32 | #include <KConfig> | 31 | #include <KConfig> | ||
33 | #include <KConfigGroup> | 32 | #include <KConfigGroup> | ||
34 | #include <KIO/MkpathJob> | 33 | #include <KIO/MkpathJob> | ||
35 | #include <KLocalizedString> | 34 | #include <KLocalizedString> | ||
36 | #include <KSharedConfig> | 35 | #include <KSharedConfig> | ||
▲ Show 20 Lines • Show All 143 Lines • ▼ Show 20 Line(s) | |||||
180 | } | 179 | } | ||
181 | 180 | | |||
182 | void KGoldrunner::setupActions() | 181 | void KGoldrunner::setupActions() | ||
183 | { | 182 | { | ||
184 | /**************************************************************************/ | 183 | /**************************************************************************/ | ||
185 | /****************************** GAME MENU ******************************/ | 184 | /****************************** GAME MENU ******************************/ | ||
186 | /**************************************************************************/ | 185 | /**************************************************************************/ | ||
187 | 186 | | |||
188 | QSignalMapper * gameMapper = new QSignalMapper (this); | | |||
189 | connect (gameMapper, static_cast<void(QSignalMapper::*)(int)>(&QSignalMapper::mapped), game, &KGrGame::gameActions); | | |||
190 | tempMapper = gameMapper; | | |||
191 | | ||||
192 | // New Game... | 187 | // New Game... | ||
193 | // Load Saved Game... | 188 | // Load Saved Game... | ||
194 | // -------------------------- | 189 | // -------------------------- | ||
195 | 190 | | |||
196 | QAction * a = KStandardGameAction::gameNew (gameMapper, SLOT(map()), this); | 191 | QAction * a = KStandardGameAction::gameNew (this, nullptr, nullptr); | ||
197 | actionCollection()->addAction (a->objectName(), a); | 192 | actionCollection()->addAction (a->objectName(), a); | ||
198 | gameMapper->setMapping (a, NEW); | 193 | connect (a, &QAction::triggered, this, [this] { game->gameActions(NEW); }); | ||
199 | a->setText (i18n ("&New Game...")); | 194 | a->setText (i18n ("&New Game...")); | ||
200 | 195 | | |||
201 | a = gameAction (QStringLiteral("next_level"), NEXT_LEVEL, | 196 | a = gameAction (QStringLiteral("next_level"), NEXT_LEVEL, | ||
202 | i18n ("Pla&y Next Level"), | 197 | i18n ("Pla&y Next Level"), | ||
203 | i18n ("Play next level."), | 198 | i18n ("Play next level."), | ||
204 | i18n ("Try the next level in the game " | 199 | i18n ("Try the next level in the game " | ||
205 | "you are playing."), | 200 | "you are playing."), | ||
206 | Qt::Key_Y); | 201 | Qt::Key_Y); | ||
207 | 202 | | |||
208 | a = KStandardGameAction::load (gameMapper, SLOT(map()), this); | 203 | a = KStandardGameAction::load (this, nullptr, nullptr); | ||
209 | actionCollection()->addAction (a->objectName(), a); | 204 | actionCollection()->addAction (a->objectName(), a); | ||
210 | gameMapper->setMapping (a, LOAD); | 205 | connect (a, &QAction::triggered, this, [this] { game->gameActions(LOAD); }); | ||
211 | a->setText (i18n ("&Load Saved Game...")); | 206 | a->setText (i18n ("&Load Saved Game...")); | ||
212 | 207 | | |||
213 | // Save Game... | 208 | // Save Game... | ||
214 | // Save Solution... | 209 | // Save Solution... | ||
215 | // -------------------------- | 210 | // -------------------------- | ||
216 | 211 | | |||
217 | saveGame = KStandardGameAction::save (gameMapper, SLOT(map()), this); | 212 | saveGame = KStandardGameAction::save (this, nullptr, nullptr); | ||
218 | actionCollection()->addAction (saveGame->objectName(), saveGame); | 213 | actionCollection()->addAction (saveGame->objectName(), saveGame); | ||
219 | gameMapper->setMapping (saveGame, SAVE_GAME); | 214 | connect (saveGame, &QAction::triggered, this, [this] { game->gameActions(SAVE_GAME); }); | ||
220 | saveGame->setText (i18n ("&Save Game...")); | 215 | saveGame->setText (i18n ("&Save Game...")); | ||
221 | actionCollection()->setDefaultShortcut(saveGame, Qt::Key_S); // Alternate key. | 216 | actionCollection()->setDefaultShortcut(saveGame, Qt::Key_S); // Alternate key. | ||
222 | 217 | | |||
223 | // The name of the solution-file is 'sol_<prefix>.txt', where <prefix> is | 218 | // The name of the solution-file is 'sol_<prefix>.txt', where <prefix> is | ||
224 | // the unique prefix belonging to the game involved (eg. plws, tute, etc.). | 219 | // the unique prefix belonging to the game involved (eg. plws, tute, etc.). | ||
225 | a = gameAction (QStringLiteral("save_solution"), SAVE_SOLUTION, | 220 | a = gameAction (QStringLiteral("save_solution"), SAVE_SOLUTION, | ||
226 | i18n ("Save A Solution..."), | 221 | i18n ("Save A Solution..."), | ||
227 | i18n ("Save A Solution..."), | 222 | i18n ("Save A Solution..."), | ||
228 | i18n ("Save a solution for a level into a file " | 223 | i18n ("Save a solution for a level into a file " | ||
229 | "called 'sol_<prefix>.txt' in your " | 224 | "called 'sol_<prefix>.txt' in your " | ||
230 | "user's data directory..."), | 225 | "user's data directory..."), | ||
231 | Qt::ShiftModifier + Qt::Key_S); | 226 | Qt::ShiftModifier + Qt::Key_S); | ||
232 | 227 | | |||
233 | // Pause | 228 | // Pause | ||
234 | // Show High Scores | 229 | // Show High Scores | ||
235 | // Get a Hint | 230 | // Get a Hint | ||
236 | // Kill the Hero | 231 | // Kill the Hero | ||
237 | // -------------------------- | 232 | // -------------------------- | ||
238 | 233 | | |||
239 | myPause = KStandardGameAction::pause (gameMapper, SLOT(map()), this); | 234 | myPause = KStandardGameAction::pause (this, nullptr, nullptr); | ||
240 | actionCollection()->addAction (myPause->objectName(), myPause); | 235 | actionCollection()->addAction (myPause->objectName(), myPause); | ||
241 | gameMapper->setMapping (myPause, PAUSE); | 236 | connect (myPause, &QAction::triggered, this, [this] { game->gameActions(PAUSE); }); | ||
242 | // QAction * myPause gets QAction::shortcut(), returning 1 OR 2 shortcuts. | 237 | // QAction * myPause gets QAction::shortcut(), returning 1 OR 2 shortcuts. | ||
243 | QList<QKeySequence> pauseShortcut = { myPause->shortcut(), Qt::Key_Escape }; | 238 | QList<QKeySequence> pauseShortcut = { myPause->shortcut(), Qt::Key_Escape }; | ||
244 | myPause->setShortcuts (pauseShortcut); | 239 | myPause->setShortcuts (pauseShortcut); | ||
245 | 240 | | |||
246 | highScore = KStandardGameAction::highscores (gameMapper, SLOT(map()), this); | 241 | highScore = KStandardGameAction::highscores (this, nullptr, nullptr); | ||
247 | actionCollection()->addAction (highScore->objectName(), highScore); | 242 | actionCollection()->addAction (highScore->objectName(), highScore); | ||
248 | gameMapper->setMapping (highScore, HIGH_SCORE); | 243 | connect (highScore, &QAction::triggered, this, [this] { game->gameActions(HIGH_SCORE); }); | ||
249 | 244 | | |||
250 | hintAction = KStandardGameAction::hint (gameMapper, SLOT (map()), this); | 245 | hintAction = KStandardGameAction::hint (this, nullptr, nullptr); | ||
251 | actionCollection()->addAction (hintAction->objectName(), hintAction); | 246 | actionCollection()->addAction (hintAction->objectName(), hintAction); | ||
252 | gameMapper->setMapping (hintAction, HINT); | 247 | connect (hintAction, &QAction::triggered, this, [this] { game->gameActions(HINT); }); | ||
253 | 248 | | |||
254 | a = KStandardGameAction::demo (gameMapper, SLOT (map()), this); | 249 | a = KStandardGameAction::demo (this, nullptr, nullptr); | ||
255 | actionCollection()->addAction (a->objectName(), a); | 250 | actionCollection()->addAction (a->objectName(), a); | ||
256 | gameMapper->setMapping (a, DEMO); | 251 | connect (a, &QAction::triggered, this, [this] { game->gameActions(DEMO); }); | ||
257 | 252 | | |||
258 | a = KStandardGameAction::solve (gameMapper, SLOT (map()), this); | 253 | a = KStandardGameAction::solve (this, nullptr, nullptr); | ||
259 | actionCollection()->addAction (a->objectName(), a); | 254 | actionCollection()->addAction (a->objectName(), a); | ||
260 | gameMapper->setMapping (a, SOLVE); | 255 | connect (a, &QAction::triggered, this, [this] { game->gameActions(SOLVE); }); | ||
261 | a->setText (i18n ("&Show A Solution")); | 256 | a->setText (i18n ("&Show A Solution")); | ||
262 | a->setToolTip (i18n ("Show how to win this level.")); | 257 | a->setToolTip (i18n ("Show how to win this level.")); | ||
263 | a->setWhatsThis (i18n ("Play a recording of how to win this level, if " | 258 | a->setWhatsThis (i18n ("Play a recording of how to win this level, if " | ||
264 | "there is one available.")); | 259 | "there is one available.")); | ||
265 | 260 | | |||
266 | a = gameAction (QStringLiteral("instant_replay"), INSTANT_REPLAY, | 261 | a = gameAction (QStringLiteral("instant_replay"), INSTANT_REPLAY, | ||
267 | i18n ("&Instant Replay"), | 262 | i18n ("&Instant Replay"), | ||
268 | i18n ("Instant replay."), | 263 | i18n ("Instant replay."), | ||
Show All 26 Lines | |||||
295 | // Quit | 290 | // Quit | ||
296 | // -------------------------- | 291 | // -------------------------- | ||
297 | 292 | | |||
298 | KStandardGameAction::quit (this, SLOT (close()), actionCollection()); | 293 | KStandardGameAction::quit (this, SLOT (close()), actionCollection()); | ||
299 | 294 | | |||
300 | /**************************************************************************/ | 295 | /**************************************************************************/ | ||
301 | /*************************** GAME EDITOR MENU **************************/ | 296 | /*************************** GAME EDITOR MENU **************************/ | ||
302 | /**************************************************************************/ | 297 | /**************************************************************************/ | ||
303 | | ||||
304 | QSignalMapper * editMapper = new QSignalMapper (this); | | |||
305 | connect (editMapper, static_cast<void(QSignalMapper::*)(int)>(&QSignalMapper::mapped), game, &KGrGame::editActions); | | |||
306 | tempMapper = editMapper; | | |||
307 | | ||||
308 | // Create a Level | 298 | // Create a Level | ||
309 | // Edit a Level... | 299 | // Edit a Level... | ||
310 | // -------------------------- | 300 | // -------------------------- | ||
311 | 301 | | |||
312 | QAction * ed = editAction (QStringLiteral("create_level"), CREATE_LEVEL, | 302 | QAction * ed = editAction (QStringLiteral("create_level"), CREATE_LEVEL, | ||
313 | i18n ("&Create Level"), | 303 | i18n ("&Create Level"), | ||
314 | i18n ("Create level."), | 304 | i18n ("Create level."), | ||
315 | i18n ("Create a completely new level.")); | 305 | i18n ("Create a completely new level.")); | ||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | |||||
375 | connect (themes, &QAction::triggered, this, &KGoldrunner::changeTheme); | 365 | connect (themes, &QAction::triggered, this, &KGoldrunner::changeTheme); | ||
376 | 366 | | |||
377 | // Show/Exit Full Screen Mode | 367 | // Show/Exit Full Screen Mode | ||
378 | KToggleFullScreenAction * fullScreen = KStandardAction::fullScreen | 368 | KToggleFullScreenAction * fullScreen = KStandardAction::fullScreen | ||
379 | (this, &KGoldrunner::viewFullScreen, this, this); | 369 | (this, &KGoldrunner::viewFullScreen, this, this); | ||
380 | actionCollection()->addAction (fullScreen->objectName(), fullScreen); | 370 | actionCollection()->addAction (fullScreen->objectName(), fullScreen); | ||
381 | 371 | | |||
382 | // Other settings are handled by KGrGame. | 372 | // Other settings are handled by KGrGame. | ||
383 | QSignalMapper * settingMapper = new QSignalMapper (this); | | |||
384 | connect (settingMapper, static_cast<void(QSignalMapper::*)(int)>(&QSignalMapper::mapped), game, &KGrGame::settings); | | |||
385 | tempMapper = settingMapper; | | |||
386 | 373 | | |||
387 | #ifdef KGAUDIO_BACKEND_OPENAL | 374 | #ifdef KGAUDIO_BACKEND_OPENAL | ||
388 | // Sound effects on/off | 375 | // Sound effects on/off | ||
389 | settingAction (QStringLiteral("options_sounds"), PLAY_SOUNDS, | 376 | settingAction (QStringLiteral("options_sounds"), PLAY_SOUNDS, | ||
390 | i18n ("&Play Sounds"), | 377 | i18n ("&Play Sounds"), | ||
391 | i18n ("Play sound effects."), | 378 | i18n ("Play sound effects."), | ||
392 | i18n ("Play sound effects during the game.")); | 379 | i18n ("Play sound effects during the game.")); | ||
393 | 380 | | |||
▲ Show 20 Lines • Show All 118 Lines • ▼ Show 20 Line(s) | 497 | KStandardAction::keyBindings ( | |||
512 | actionCollection()); | 499 | actionCollection()); | ||
513 | 500 | | |||
514 | /**************************************************************************/ | 501 | /**************************************************************************/ | ||
515 | /************************** KEYSTROKE ACTIONS **************************/ | 502 | /************************** KEYSTROKE ACTIONS **************************/ | ||
516 | /**************************************************************************/ | 503 | /**************************************************************************/ | ||
517 | 504 | | |||
518 | // Two-handed KB controls and alternate one-handed controls for the hero. | 505 | // Two-handed KB controls and alternate one-handed controls for the hero. | ||
519 | 506 | | |||
520 | QSignalMapper * kbMapper = new QSignalMapper (this); | | |||
521 | connect (kbMapper, static_cast<void(QSignalMapper::*)(int)>(&QSignalMapper::mapped), [&](int dirn) { game->kbControl(dirn); } ); | | |||
522 | tempMapper = kbMapper; | | |||
523 | | ||||
524 | // The actions for the movement keys are created but disabled. This lets | 507 | // The actions for the movement keys are created but disabled. This lets | ||
525 | // keyPressEvent() come through, instead of a signal, while still allowing | 508 | // keyPressEvent() come through, instead of a signal, while still allowing | ||
526 | // Settings->Configure Keys to change the key mappings. The keyPressEvent() | 509 | // Settings->Configure Keys to change the key mappings. The keyPressEvent() | ||
527 | // call is needed so that the key can be identified and matched to the | 510 | // call is needed so that the key can be identified and matched to the | ||
528 | // corresponding keyReleaseEvent() call and make the hold-key option | 511 | // corresponding keyReleaseEvent() call and make the hold-key option | ||
529 | // work correctly when two keys are held down simultaneously. | 512 | // work correctly when two keys are held down simultaneously. | ||
530 | 513 | | |||
531 | keyControl (QStringLiteral("stop"), i18n ("Stop"), Qt::Key_Space, STAND); | 514 | keyControl (QStringLiteral("stop"), i18n ("Stop"), Qt::Key_Space, STAND); | ||
Show All 21 Lines | |||||
553 | // on or off during gameplay and printing the states of runners or tiles. | 536 | // on or off during gameplay and printing the states of runners or tiles. | ||
554 | 537 | | |||
555 | KConfigGroup debugGroup (KSharedConfig::openConfig(), "Debugging"); | 538 | KConfigGroup debugGroup (KSharedConfig::openConfig(), "Debugging"); | ||
556 | bool addDebuggingShortcuts = debugGroup.readEntry | 539 | bool addDebuggingShortcuts = debugGroup.readEntry | ||
557 | ("DebuggingShortcuts", false); // Get debug option. | 540 | ("DebuggingShortcuts", false); // Get debug option. | ||
558 | if (! addDebuggingShortcuts) | 541 | if (! addDebuggingShortcuts) | ||
559 | return; | 542 | return; | ||
560 | 543 | | |||
561 | QSignalMapper * dbgMapper = new QSignalMapper (this); | 544 | keyControlDebug (QStringLiteral("do_step"), i18n ("Do a Step"), Qt::Key_Period, DO_STEP); | ||
562 | connect (dbgMapper, static_cast<void(QSignalMapper::*)(int)>(&QSignalMapper::mapped), game, &KGrGame::dbgControl); | 545 | keyControlDebug (QStringLiteral("bug_fix"), i18n ("Test Bug Fix"), Qt::Key_B, BUG_FIX); | ||
563 | tempMapper = dbgMapper; | 546 | keyControlDebug (QStringLiteral("show_positions"), i18n ("Show Positions"), Qt::Key_W, S_POSNS); | ||
564 | 547 | keyControlDebug (QStringLiteral("logging"), i18n ("Start Logging"), Qt::Key_G, LOGGING); | |||
565 | keyControl (QStringLiteral("do_step"), i18n ("Do a Step"), Qt::Key_Period, DO_STEP); | 548 | keyControlDebug (QStringLiteral("show_hero"), i18n ("Show Hero"), Qt::Key_E, S_HERO); | ||
566 | keyControl (QStringLiteral("bug_fix"), i18n ("Test Bug Fix"), Qt::Key_B, BUG_FIX); | 549 | keyControlDebug (QStringLiteral("show_obj"), i18n ("Show Object"), Qt::Key_Slash, S_OBJ); | ||
567 | keyControl (QStringLiteral("show_positions"), i18n ("Show Positions"), Qt::Key_W, S_POSNS); | 550 | | ||
568 | keyControl (QStringLiteral("logging"), i18n ("Start Logging"), Qt::Key_G, LOGGING); | 551 | keyControlDebug (QStringLiteral("show_enemy_0"), i18n ("Show Enemy") + QLatin1Char('0'), Qt::Key_0, ENEMY_0); | ||
569 | keyControl (QStringLiteral("show_hero"), i18n ("Show Hero"), Qt::Key_E, S_HERO); | 552 | keyControlDebug (QStringLiteral("show_enemy_1"), i18n ("Show Enemy") + QLatin1Char('1'), Qt::Key_1, ENEMY_1); | ||
570 | keyControl (QStringLiteral("show_obj"), i18n ("Show Object"), Qt::Key_Slash, S_OBJ); | 553 | keyControlDebug (QStringLiteral("show_enemy_2"), i18n ("Show Enemy") + QLatin1Char('2'), Qt::Key_2, ENEMY_2); | ||
571 | 554 | keyControlDebug (QStringLiteral("show_enemy_3"), i18n ("Show Enemy") + QLatin1Char('3'), Qt::Key_3, ENEMY_3); | |||
572 | keyControl (QStringLiteral("show_enemy_0"), i18n ("Show Enemy") + QLatin1Char('0'), Qt::Key_0, ENEMY_0); | 555 | keyControlDebug (QStringLiteral("show_enemy_4"), i18n ("Show Enemy") + QLatin1Char('4'), Qt::Key_4, ENEMY_4); | ||
573 | keyControl (QStringLiteral("show_enemy_1"), i18n ("Show Enemy") + QLatin1Char('1'), Qt::Key_1, ENEMY_1); | 556 | keyControlDebug (QStringLiteral("show_enemy_5"), i18n ("Show Enemy") + QLatin1Char('5'), Qt::Key_5, ENEMY_5); | ||
574 | keyControl (QStringLiteral("show_enemy_2"), i18n ("Show Enemy") + QLatin1Char('2'), Qt::Key_2, ENEMY_2); | 557 | keyControlDebug (QStringLiteral("show_enemy_6"), i18n ("Show Enemy") + QLatin1Char('6'), Qt::Key_6, ENEMY_6); | ||
575 | keyControl (QStringLiteral("show_enemy_3"), i18n ("Show Enemy") + QLatin1Char('3'), Qt::Key_3, ENEMY_3); | | |||
576 | keyControl (QStringLiteral("show_enemy_4"), i18n ("Show Enemy") + QLatin1Char('4'), Qt::Key_4, ENEMY_4); | | |||
577 | keyControl (QStringLiteral("show_enemy_5"), i18n ("Show Enemy") + QLatin1Char('5'), Qt::Key_5, ENEMY_5); | | |||
578 | keyControl (QStringLiteral("show_enemy_6"), i18n ("Show Enemy") + QLatin1Char('6'), Qt::Key_6, ENEMY_6); | | |||
579 | } | 558 | } | ||
580 | 559 | | |||
581 | QAction * KGoldrunner::gameAction (const QString & name, | 560 | QAction * KGoldrunner::gameAction (const QString & name, | ||
582 | const int code, | 561 | const int code, | ||
583 | const QString & text, | 562 | const QString & text, | ||
584 | const QString & toolTip, | 563 | const QString & toolTip, | ||
585 | const QString & whatsThis, | 564 | const QString & whatsThis, | ||
586 | const QKeySequence & key) | 565 | const QKeySequence & key) | ||
587 | { | 566 | { | ||
588 | QAction * ga = actionCollection()->addAction (name); | 567 | QAction * ga = actionCollection()->addAction (name); | ||
589 | ga->setText (text); | 568 | ga->setText (text); | ||
590 | ga->setToolTip (toolTip); | 569 | ga->setToolTip (toolTip); | ||
591 | ga->setWhatsThis (whatsThis); | 570 | ga->setWhatsThis (whatsThis); | ||
592 | if (! key.isEmpty()) { | 571 | if (! key.isEmpty()) { | ||
593 | actionCollection()->setDefaultShortcut(ga, key); | 572 | actionCollection()->setDefaultShortcut(ga, key); | ||
594 | } | 573 | } | ||
595 | connect (ga, &QAction::triggered, tempMapper, static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map)); | 574 | connect (ga, &QAction::triggered, this, [this, code] { game->gameActions(code); }); | ||
596 | tempMapper->setMapping (ga, code); | | |||
597 | return ga; | 575 | return ga; | ||
598 | } | 576 | } | ||
599 | 577 | | |||
600 | QAction * KGoldrunner::editAction (const QString & name, | 578 | QAction * KGoldrunner::editAction (const QString & name, | ||
601 | const int code, | 579 | const int code, | ||
602 | const QString & text, | 580 | const QString & text, | ||
603 | const QString & toolTip, | 581 | const QString & toolTip, | ||
604 | const QString & whatsThis) | 582 | const QString & whatsThis) | ||
605 | { | 583 | { | ||
606 | QAction * ed = actionCollection()->addAction (name); | 584 | QAction * ed = actionCollection()->addAction (name); | ||
607 | ed->setText (text); | 585 | ed->setText (text); | ||
608 | ed->setToolTip (toolTip); | 586 | ed->setToolTip (toolTip); | ||
609 | ed->setWhatsThis (whatsThis); | 587 | ed->setWhatsThis (whatsThis); | ||
610 | connect (ed, &QAction::triggered, tempMapper, static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map)); | 588 | connect (ed, &QAction::triggered, this, [this, code] { game->editActions(code); }); | ||
611 | tempMapper->setMapping (ed, code); | | |||
612 | return ed; | 589 | return ed; | ||
613 | } | 590 | } | ||
614 | 591 | | |||
615 | KToggleAction * KGoldrunner::settingAction (const QString & name, | 592 | KToggleAction * KGoldrunner::settingAction (const QString & name, | ||
616 | const int code, | 593 | const int code, | ||
617 | const QString & text, | 594 | const QString & text, | ||
618 | const QString & toolTip, | 595 | const QString & toolTip, | ||
619 | const QString & whatsThis) | 596 | const QString & whatsThis) | ||
620 | { | 597 | { | ||
621 | KToggleAction * s = new KToggleAction (text, this); | 598 | KToggleAction * s = new KToggleAction (text, this); | ||
622 | actionCollection()->addAction (name, s); | 599 | actionCollection()->addAction (name, s); | ||
623 | s->setToolTip (toolTip); | 600 | s->setToolTip (toolTip); | ||
624 | s->setWhatsThis (whatsThis); | 601 | s->setWhatsThis (whatsThis); | ||
625 | connect (s, &QAction::triggered, tempMapper, static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map)); | 602 | connect (s, &QAction::triggered, this, [this, code] { game->settings(code); }); | ||
626 | tempMapper->setMapping (s, code); | | |||
627 | return s; | 603 | return s; | ||
628 | } | 604 | } | ||
629 | 605 | | |||
630 | KToggleAction * KGoldrunner::editToolbarAction (const QString & name, | 606 | KToggleAction * KGoldrunner::editToolbarAction (const QString & name, | ||
631 | const char code, | 607 | const char code, | ||
632 | const QString & shortText, | 608 | const QString & shortText, | ||
633 | const QString & text, | 609 | const QString & text, | ||
634 | const QString & toolTip, | 610 | const QString & toolTip, | ||
635 | const QString & whatsThis) | 611 | const QString & whatsThis) | ||
636 | { | 612 | { | ||
637 | int mapCode = code; | | |||
638 | KToggleAction * ed = new KToggleAction (text, this); | 613 | KToggleAction * ed = new KToggleAction (text, this); | ||
639 | actionCollection()->addAction (name, ed); | 614 | actionCollection()->addAction (name, ed); | ||
640 | ed->setIconText (shortText); | 615 | ed->setIconText (shortText); | ||
641 | ed->setToolTip (toolTip); | 616 | ed->setToolTip (toolTip); | ||
642 | ed->setWhatsThis (whatsThis); | 617 | ed->setWhatsThis (whatsThis); | ||
643 | connect (ed, &QAction::triggered, tempMapper, static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map)); | 618 | connect (ed, &QAction::triggered, this, [this, code] { game->editToolbarActions(code); }); | ||
644 | tempMapper->setMapping (ed, mapCode); | | |||
645 | return ed; | 619 | return ed; | ||
646 | } | 620 | } | ||
647 | 621 | | |||
648 | void KGoldrunner::keyControl (const QString & name, const QString & text, | 622 | void KGoldrunner::keyControl (const QString & name, const QString & text, | ||
649 | const QKeySequence & shortcut, const int code, | 623 | const QKeySequence & shortcut, const int code, | ||
650 | const bool mover) | 624 | const bool mover) | ||
651 | { | 625 | { | ||
652 | QAction * a = actionCollection()->addAction (name); | 626 | QAction * a = actionCollection()->addAction (name); | ||
653 | a->setText (text); | 627 | a->setText (text); | ||
654 | actionCollection()->setDefaultShortcut(a, shortcut); | 628 | actionCollection()->setDefaultShortcut(a, shortcut); | ||
655 | a->setAutoRepeat (false); // Avoid repeats of signals by QAction. | 629 | a->setAutoRepeat (false); // Avoid repeats of signals by QAction. | ||
656 | 630 | | |||
657 | // If this is a move-key, let keyPressEvent() through, instead of signal. | 631 | // If this is a move-key, let keyPressEvent() through, instead of signal. | ||
658 | if (mover) { | 632 | if (mover) { | ||
659 | a->setEnabled (false); | 633 | a->setEnabled (false); | ||
660 | addAction (a); | 634 | addAction (a); | ||
661 | return; | 635 | return; | ||
662 | } | 636 | } | ||
663 | 637 | | |||
664 | connect (a, &QAction::triggered, tempMapper, static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map)); | 638 | connect (a, &QAction::triggered, this, [this, code] { game->kbControl(code); }); | ||
665 | tempMapper->setMapping (a, code); | 639 | addAction (a); | ||
640 | } | ||||
641 | | ||||
642 | void KGoldrunner::keyControlDebug (const QString & name, const QString & text, | ||||
643 | const QKeySequence & shortcut, const int code, | ||||
644 | const bool mover) | ||||
645 | { | ||||
646 | QAction * a = actionCollection()->addAction (name); | ||||
647 | a->setText (text); | ||||
648 | actionCollection()->setDefaultShortcut(a, shortcut); | ||||
649 | a->setAutoRepeat (false); // Avoid repeats of signals by QAction. | ||||
650 | | ||||
651 | // If this is a move-key, let keyPressEvent() through, instead of signal. | ||||
652 | if (mover) { | ||||
653 | a->setEnabled (false); | ||||
654 | addAction (a); | ||||
655 | return; | ||||
656 | } | ||||
657 | | ||||
658 | connect (a, &QAction::triggered, this, [this, code] { game->dbgControl(code); }); | ||||
666 | addAction (a); | 659 | addAction (a); | ||
667 | } | 660 | } | ||
668 | 661 | | |||
669 | void KGoldrunner::setUpKeyboardControl() | 662 | void KGoldrunner::setUpKeyboardControl() | ||
670 | { | 663 | { | ||
671 | // This is needed to ensure that the press and release of Up, Down, Left and | 664 | // This is needed to ensure that the press and release of Up, Down, Left and | ||
672 | // Right keys (arrow-keys) are all received as required. | 665 | // Right keys (arrow-keys) are all received as required. | ||
673 | // | 666 | // | ||
▲ Show 20 Lines • Show All 244 Lines • ▼ Show 20 Line(s) | |||||
918 | } | 911 | } | ||
919 | 912 | | |||
920 | /******************************************************************************/ | 913 | /******************************************************************************/ | ||
921 | /********************** MAKE A TOOLBAR FOR THE EDITOR **********************/ | 914 | /********************** MAKE A TOOLBAR FOR THE EDITOR **********************/ | ||
922 | /******************************************************************************/ | 915 | /******************************************************************************/ | ||
923 | 916 | | |||
924 | void KGoldrunner::setupEditToolbarActions() | 917 | void KGoldrunner::setupEditToolbarActions() | ||
925 | { | 918 | { | ||
926 | QSignalMapper * editToolbarMapper = new QSignalMapper (this); | | |||
927 | connect (editToolbarMapper, static_cast<void(QSignalMapper::*)(int)>(&QSignalMapper::mapped), game, &KGrGame::editToolbarActions); | | |||
928 | tempMapper = editToolbarMapper; | | |||
929 | | ||||
930 | QAction * ed = editAction (QStringLiteral("edit_hint"), EDIT_HINT, | 919 | QAction * ed = editAction (QStringLiteral("edit_hint"), EDIT_HINT, | ||
931 | i18n ("Edit Name/Hint"), | 920 | i18n ("Edit Name/Hint"), | ||
932 | i18n ("Edit level name or hint"), | 921 | i18n ("Edit level name or hint"), | ||
933 | i18n ("Edit text for the name or hint " | 922 | i18n ("Edit text for the name or hint " | ||
934 | "of a level")); | 923 | "of a level")); | ||
935 | ed->setIcon (QIcon::fromTheme( QStringLiteral( "games-hint" ))); | 924 | ed->setIcon (QIcon::fromTheme( QStringLiteral( "games-hint" ))); | ||
936 | ed->setIconText (i18n ("Name/Hint")); | 925 | ed->setIconText (i18n ("Name/Hint")); | ||
937 | 926 | | |||
▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines |