diff options
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/gui/models/keylistmodel.h | 86 | ||||
-rw-r--r-- | src/gui/widgets/tabs/setup_input.cpp | 57 |
4 files changed, 95 insertions, 50 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 785c949b2..34084e026 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -151,6 +151,7 @@ SET(SRCS gui/models/iconsmodel.h gui/models/ignorechoiceslistmodel.h gui/models/itemsmodel.h + gui/models/keylistmodel.h gui/widgets/flowcontainer.cpp gui/widgets/flowcontainer.h gui/widgets/tabs/gmtab.cpp diff --git a/src/Makefile.am b/src/Makefile.am index fe24cbf11..7961a343f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -242,6 +242,7 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ gui/models/iconsmodel.h \ gui/models/ignorechoiceslistmodel.h \ gui/models/itemsmodel.h \ + gui/models/keylistmodel.h \ gui/widgets/flowcontainer.cpp \ gui/widgets/flowcontainer.h \ gui/widgets/tabs/gmtab.cpp \ diff --git a/src/gui/models/keylistmodel.h b/src/gui/models/keylistmodel.h new file mode 100644 index 000000000..17d17acd4 --- /dev/null +++ b/src/gui/models/keylistmodel.h @@ -0,0 +1,86 @@ +/* + * Custom keyboard shortcuts configuration + * Copyright (C) 2007 Joshua Langley <joshlangley@optusnet.com.au> + * Copyright (C) 2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_MODELS_KEYLISTMODEL_H +#define GUI_MODELS_KEYLISTMODEL_H + +#include "gui/setupactiondata.h" + +#include "gui/models/listmodel.h" + +#include "debug.h" + +/** + * The list model for key function list. + * + * \ingroup Interface + */ +class KeyListModel final : public ListModel +{ + public: + KeyListModel() : + mDataNum(0), + mSelectedData(0), + mSize(0) + { + } + + A_DELETE_COPY(KeyListModel) + + /** + * Returns the number of elements in container. + */ + int getNumberOfElements() override final + { return mSize; } + + /** + * Returns element from container. + */ + std::string getElementAt(int i) override final + { return setupActionData[mSelectedData][i].text; } + + /** + * Sets element from container. + */ + void setElementAt(const int i, const std::string &caption) + { setupActionData[mSelectedData][i].text = caption; } + + void setSize(const int size) + { mSize = size; } + + void setDataNum(const int num) + { mDataNum = num; } + + void setSelectedData(const int i) + { mSelectedData = i; } + + int getSelectedData() const A_WARN_UNUSED + { return mSelectedData; } + + private: + int mDataNum; + int mSelectedData; + int mSize; +}; + +#endif // GUI_MODELS_KEYLISTMODEL_H diff --git a/src/gui/widgets/tabs/setup_input.cpp b/src/gui/widgets/tabs/setup_input.cpp index a22392fca..f2651e086 100644 --- a/src/gui/widgets/tabs/setup_input.cpp +++ b/src/gui/widgets/tabs/setup_input.cpp @@ -29,7 +29,6 @@ #include "input/keyboardconfig.h" #include "gui/gui.h" -#include "gui/setupactiondata.h" #include "gui/windows/okdialog.h" @@ -40,60 +39,14 @@ #include "gui/widgets/scrollarea.h" #include "gui/widgets/tabstrip.h" -#include "gui/models/listmodel.h" +#include "gui/models/keylistmodel.h" #include "utils/delete2.h" #include "debug.h" -static int selectedData = 0; static const int setupGroups = 9; -/** - * The list model for key function list. - * - * \ingroup Interface - */ -class KeyListModel final : public ListModel -{ - public: - KeyListModel() : - mDataNum(0), - mSize(0) - { - } - - A_DELETE_COPY(KeyListModel) - - /** - * Returns the number of elements in container. - */ - int getNumberOfElements() override final - { return mSize; } - - /** - * Returns element from container. - */ - std::string getElementAt(int i) override final - { return setupActionData[selectedData][i].text; } - - /** - * Sets element from container. - */ - void setElementAt(const int i, const std::string &caption) - { setupActionData[selectedData][i].text = caption; } - - void setSize(const int size) - { mSize = size; } - - void setDataNum(const int num) - { mDataNum = num; } - - private: - int mDataNum; - int mSize; -}; - Setup_Input::Setup_Input(const Widget2 *const widget) : SetupTab(widget), mKeyListModel(new KeyListModel), @@ -117,7 +70,7 @@ Setup_Input::Setup_Input(const Widget2 *const widget) : // TRANSLATORS: setting tab name setName(_("Input")); - selectedData = 0; + mKeyListModel->setSelectedData(0); for (int f = 0; f < setupGroups; f ++) { @@ -214,6 +167,7 @@ void Setup_Input::cancel() void Setup_Input::action(const ActionEvent &event) { const std::string &id = event.getId(); + const int selectedData = mKeyListModel->getSelectedData(); if (event.getSource() == mKeyList) { @@ -294,7 +248,7 @@ void Setup_Input::action(const ActionEvent &event) } if (pages[k] && str + pages[k] == id) { - selectedData = k; + mKeyListModel->setSelectedData(k); mKeyListModel->setSize(mActionDataSize[k]); refreshKeys(); mKeyList->setSelected(0); @@ -304,6 +258,7 @@ void Setup_Input::action(const ActionEvent &event) void Setup_Input::refreshAssignedKey(const int index) { + const int selectedData = mKeyListModel->getSelectedData(); const SetupActionData &key = setupActionData[selectedData][index]; if (key.actionId == static_cast<int>(Input::KEY_NO_VALUE)) { @@ -336,6 +291,7 @@ void Setup_Input::newKeyCallback(const int index) int Setup_Input::keyToSetupData(const int index) const { + const int selectedData = mKeyListModel->getSelectedData(); for (int i = 0; i < mActionDataSize[selectedData]; i++) { const SetupActionData &key = setupActionData[selectedData][i]; @@ -362,6 +318,7 @@ std::string Setup_Input::keyToString(const int index) const void Setup_Input::refreshKeys() { + const int selectedData = mKeyListModel->getSelectedData(); for (int i = 0; i < mActionDataSize[selectedData]; i++) refreshAssignedKey(i); } |