198 lines
7.0 KiB
C++
198 lines
7.0 KiB
C++
// This file is part of c-evo-evo.
|
|
//
|
|
// This software is governed by the CeCILL license under French law and
|
|
// abiding by the rules of distribution of free software. You can use,
|
|
// modify and/or redistribute the software under the terms of the CeCILL
|
|
// license as circulated by CEA, CNRS and INRIA at the following URL
|
|
// "http://www.cecill.info".
|
|
//
|
|
// As a counterpart to the access to the source code and rights to copy,
|
|
// modify and redistribute granted by the license, users are provided only
|
|
// with a limited warranty and the software's author, the holder of the
|
|
// economic rights, and the successive licensors have only limited
|
|
// liability.
|
|
//
|
|
// In this respect, the user's attention is drawn to the risks associated
|
|
// with loading, using, modifying and/or developing or reproducing the
|
|
// software by the user in light of its specific status of free software,
|
|
// that may mean that it is complicated to manipulate, and that also
|
|
// therefore means that it is reserved for developers and experienced
|
|
// professionals having in-depth computer knowledge. Users are therefore
|
|
// encouraged to load and test the software's suitability as regards their
|
|
// requirements in conditions enabling the security of their systems and/or
|
|
// data to be ensured and, more generally, to use and operate it in the
|
|
// same conditions as regards security.
|
|
//
|
|
// The fact that you are presently reading this means that you have had
|
|
// knowledge of the CeCILL license and that you accept its terms.
|
|
|
|
#pragma once
|
|
|
|
#include <QKeySequence>
|
|
#include <QString>
|
|
#include <QStringList>
|
|
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
class QSettings;
|
|
|
|
namespace Cevo {
|
|
namespace KeyBindings {
|
|
|
|
// TKeyBinding equivalent. ShortCut/ShortCut2 are represented as
|
|
// QKeySequence rather than Delphi's packed-Word TShortCut - the only
|
|
// persisted form is always the human-readable text produced by
|
|
// shortCutToText()/textToShortCut() below, so there is no binary format to
|
|
// stay bit-compatible with.
|
|
class KeyBinding {
|
|
public:
|
|
QString shortName;
|
|
QString fullName;
|
|
QKeySequence shortCut;
|
|
QKeySequence shortCut2;
|
|
QKeySequence defaultShortCut;
|
|
QKeySequence defaultShortCut2;
|
|
|
|
bool test(const QKeySequence &aShortCut) const;
|
|
void assign(const KeyBinding &source);
|
|
void setDefault();
|
|
};
|
|
|
|
// TKeyBindings equivalent: an owning, ordered list of KeyBindings.
|
|
// Composition over std::vector<std::unique_ptr<KeyBinding>>, same pattern
|
|
// as Brains/GraphicSets.
|
|
class KeyBindingList {
|
|
public:
|
|
KeyBinding &addItem(const QString &shortName, const QString &fullName, const QKeySequence &shortCut,
|
|
const QKeySequence &shortCut2 = QKeySequence());
|
|
KeyBinding &addItem(const QString &shortName, const QString &fullName, const QString &shortCutText,
|
|
const QString &shortCutText2 = QString());
|
|
KeyBinding *search(const QString &shortName) const;
|
|
|
|
// Registry.pas's TRegistry is Windows-only; QSettings is the natural,
|
|
// already cross-platform Qt equivalent used in its place. `group`
|
|
// replaces LoadFromRegistry/SaveToRegistry's `Key` path argument.
|
|
void loadFromSettings(QSettings &settings, const QString &group);
|
|
void saveToSettings(QSettings &settings, const QString &group) const;
|
|
|
|
QStringList toDisplayStrings() const;
|
|
void assign(const KeyBindingList &source);
|
|
void resetToDefault();
|
|
void removeShortCut(const QKeySequence &shortCut);
|
|
void sortAlpha();
|
|
|
|
int count() const { return static_cast<int>(m_items.size()); }
|
|
KeyBinding &operator[](int index) { return *m_items[static_cast<std::size_t>(index)]; }
|
|
const KeyBinding &operator[](int index) const { return *m_items[static_cast<std::size_t>(index)]; }
|
|
|
|
private:
|
|
std::vector<std::unique_ptr<KeyBinding>> m_items;
|
|
};
|
|
|
|
// Parses LCL-style shortcut text ("Ctrl+Q", "F1", "NumPlus", "Ctrl+Num1",
|
|
// "PgDn", ...) into a QKeySequence; shortCutToText() is its inverse.
|
|
QKeySequence textToShortCut(const QString &text);
|
|
QString shortCutToText(const QKeySequence &shortCut);
|
|
|
|
extern KeyBindingList keyBindings;
|
|
|
|
extern KeyBinding *bEndTurn;
|
|
extern KeyBinding *bHelp;
|
|
extern KeyBinding *bUnitStat;
|
|
extern KeyBinding *bCityStat;
|
|
extern KeyBinding *bScienceStat;
|
|
extern KeyBinding *bEUnitStat;
|
|
extern KeyBinding *bDiagram;
|
|
extern KeyBinding *bWonders;
|
|
extern KeyBinding *bShips;
|
|
extern KeyBinding *bNations;
|
|
extern KeyBinding *bEmpire;
|
|
extern KeyBinding *bFullScreen;
|
|
extern KeyBinding *bResign;
|
|
extern KeyBinding *bRandomMap;
|
|
extern KeyBinding *bFillMap;
|
|
extern KeyBinding *bDisbandUnit;
|
|
extern KeyBinding *bFortify;
|
|
extern KeyBinding *bCenterUnit;
|
|
extern KeyBinding *bStay;
|
|
extern KeyBinding *bNoOrders;
|
|
extern KeyBinding *bPrevUnit;
|
|
extern KeyBinding *bNextUnit;
|
|
extern KeyBinding *bCancel;
|
|
extern KeyBinding *bPillage;
|
|
extern KeyBinding *bSelectTransport;
|
|
extern KeyBinding *bTechTree;
|
|
extern KeyBinding *bWait;
|
|
extern KeyBinding *bJump;
|
|
extern KeyBinding *bMapBtn0;
|
|
extern KeyBinding *bMapBtn1;
|
|
extern KeyBinding *bMapBtn4;
|
|
extern KeyBinding *bMapBtn5;
|
|
extern KeyBinding *bMapBtn6;
|
|
extern KeyBinding *bSetDebugMap0;
|
|
extern KeyBinding *bSetDebugMap1;
|
|
extern KeyBinding *bSetDebugMap2;
|
|
extern KeyBinding *bSetDebugMap3;
|
|
extern KeyBinding *bSetDebugMap4;
|
|
extern KeyBinding *bSetDebugMap5;
|
|
extern KeyBinding *bSetDebugMap6;
|
|
extern KeyBinding *bSetDebugMap7;
|
|
extern KeyBinding *bSetDebugMap8;
|
|
extern KeyBinding *bSetDebugMap9;
|
|
extern KeyBinding *bDebugMap;
|
|
extern KeyBinding *bLocCodes;
|
|
extern KeyBinding *bLogDlg;
|
|
extern KeyBinding *bNames;
|
|
extern KeyBinding *bRun;
|
|
extern KeyBinding *bTestMapRepaint;
|
|
extern KeyBinding *bSetViewpoint0;
|
|
extern KeyBinding *bSetViewpoint1;
|
|
extern KeyBinding *bSetViewpoint2;
|
|
extern KeyBinding *bSetViewpoint3;
|
|
extern KeyBinding *bSetViewpoint4;
|
|
extern KeyBinding *bSetViewpoint5;
|
|
extern KeyBinding *bSetViewpoint6;
|
|
extern KeyBinding *bSetViewpoint7;
|
|
extern KeyBinding *bSetViewpoint8;
|
|
extern KeyBinding *bSetViewpoint9;
|
|
extern KeyBinding *bAirBase;
|
|
extern KeyBinding *bBuildCity;
|
|
extern KeyBinding *bEnhance;
|
|
extern KeyBinding *bGoOn;
|
|
extern KeyBinding *bHome;
|
|
extern KeyBinding *bFarmClearIrrigation;
|
|
extern KeyBinding *bLoad;
|
|
extern KeyBinding *bAfforestMine;
|
|
extern KeyBinding *bCanal;
|
|
extern KeyBinding *bTrans;
|
|
extern KeyBinding *bPollution;
|
|
extern KeyBinding *bRailRoad;
|
|
extern KeyBinding *bUnload;
|
|
extern KeyBinding *bRecover;
|
|
extern KeyBinding *bUtilize;
|
|
extern KeyBinding *bUnitMoveLeftDown;
|
|
extern KeyBinding *bUnitMoveDown;
|
|
extern KeyBinding *bUnitMoveRightDown;
|
|
extern KeyBinding *bUnitMoveRight;
|
|
extern KeyBinding *bUnitMoveRightUp;
|
|
extern KeyBinding *bUnitMoveUp;
|
|
extern KeyBinding *bUnitMoveLeftUp;
|
|
extern KeyBinding *bUnitMoveLeft;
|
|
extern KeyBinding *bMapMoveLeftDown;
|
|
extern KeyBinding *bMapMoveDown;
|
|
extern KeyBinding *bMapMoveRightDown;
|
|
extern KeyBinding *bMapMoveRight;
|
|
extern KeyBinding *bMapMoveRightUp;
|
|
extern KeyBinding *bMapMoveUp;
|
|
extern KeyBinding *bMapMoveLeftUp;
|
|
extern KeyBinding *bMapMoveLeft;
|
|
|
|
// Populates keyBindings and all the b* globals above (Pascal's
|
|
// `initialization` section). done() frees them (`finalization`).
|
|
void init();
|
|
void done();
|
|
|
|
} // namespace KeyBindings
|
|
} // namespace Cevo
|